Support migrating settings after repackage
This commit is contained in:
parent
80cabb338b
commit
bb80ab4026
@ -8,7 +8,7 @@ android {
|
|||||||
applicationId "com.topjohnwu.magisk"
|
applicationId "com.topjohnwu.magisk"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
versionCode 66
|
versionCode 68
|
||||||
versionName "5.4.3"
|
versionName "5.4.3"
|
||||||
ndk {
|
ndk {
|
||||||
moduleName 'zipadjust'
|
moduleName 'zipadjust'
|
||||||
@ -55,12 +55,13 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation project(':crypto')
|
implementation project(':crypto')
|
||||||
implementation 'com.android.support:recyclerview-v7:27.0.1'
|
implementation 'com.android.support:recyclerview-v7:27.0.2'
|
||||||
implementation 'com.android.support:cardview-v7:27.0.1'
|
implementation 'com.android.support:cardview-v7:27.0.2'
|
||||||
implementation 'com.android.support:design:27.0.1'
|
implementation 'com.android.support:design:27.0.2'
|
||||||
implementation 'com.android.support:support-v4:27.0.1'
|
implementation 'com.android.support:support-v4:27.0.2'
|
||||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||||
implementation 'com.atlassian.commonmark:commonmark:0.10.0'
|
implementation 'com.atlassian.commonmark:commonmark:0.10.0'
|
||||||
implementation 'org.kamranzafar:jtar:2.3'
|
implementation 'org.kamranzafar:jtar:2.3'
|
||||||
|
implementation 'com.google.code.gson:gson:2.8.2'
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk;
|
package com.topjohnwu.magisk;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@ -103,13 +104,21 @@ public class MagiskManager extends Application {
|
|||||||
suDB = new SuDatabaseHelper();
|
suDB = new SuDatabaseHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If detect original package, self destruct!
|
// Handle duplicate package
|
||||||
if (!getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
if (!getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
||||||
try {
|
try {
|
||||||
getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0);
|
getPackageManager().getApplicationInfo(Const.ORIG_PKG_NAME, 0);
|
||||||
Shell.su(String.format(Locale.US, "pm uninstall --user %d %s", userId, getPackageName()));
|
Intent intent = getPackageManager().getLaunchIntentForPackage(Const.ORIG_PKG_NAME);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
return;
|
return;
|
||||||
} catch (PackageManager.NameNotFoundException ignored) { /* Expected*/ }
|
} catch (PackageManager.NameNotFoundException ignored) { /* Expected */ }
|
||||||
|
} else {
|
||||||
|
String pkg = suDB.getStrings(Const.Key.SU_REQUESTER, null);
|
||||||
|
if (pkg != null) {
|
||||||
|
Shell.su_raw("pm uninstall " + pkg);
|
||||||
|
suDB.setStrings(Const.Key.SU_REQUESTER, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repoDB = new RepoDatabaseHelper(this);
|
repoDB = new RepoDatabaseHelper(this);
|
||||||
|
@ -42,6 +42,10 @@ public class SplashActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mm.loadMagiskInfo();
|
mm.loadMagiskInfo();
|
||||||
|
if (Utils.itemExist(Const.MANAGER_CONFIGS)) {
|
||||||
|
Utils.loadPrefs();
|
||||||
|
}
|
||||||
|
|
||||||
LoadModules loadModuleTask = new LoadModules();
|
LoadModules loadModuleTask = new LoadModules();
|
||||||
|
|
||||||
if (Utils.checkNetworkStatus()) {
|
if (Utils.checkNetworkStatus()) {
|
||||||
@ -64,14 +68,6 @@ public class SplashActivity extends Activity {
|
|||||||
// Setup suDB
|
// Setup suDB
|
||||||
SuDatabaseHelper.setupSuDB();
|
SuDatabaseHelper.setupSuDB();
|
||||||
|
|
||||||
// Check alternative Magisk Manager
|
|
||||||
String pkg;
|
|
||||||
if (getPackageName().equals(Const.ORIG_PKG_NAME) &&
|
|
||||||
(pkg = mm.suDB.getStrings(Const.Key.SU_REQUESTER, null)) != null) {
|
|
||||||
Shell.su_raw("pm uninstall " + pkg);
|
|
||||||
mm.suDB.setStrings(Const.Key.SU_REQUESTER, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add update checking service
|
// Add update checking service
|
||||||
if (Const.Value.UPDATE_SERVICE_VER > mm.updateServiceVersion) {
|
if (Const.Value.UPDATE_SERVICE_VER > mm.updateServiceVersion) {
|
||||||
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
ComponentName service = new ComponentName(this, UpdateCheckService.class);
|
||||||
|
@ -131,7 +131,8 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
|
mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
|
||||||
Shell.su_raw(String.format(Locale.US, "pm uninstall --user %d %s", mm.userId, mm.getPackageName()));
|
Utils.dumpPrefs();
|
||||||
|
Shell.su_raw("pm uninstall " + Const.ORIG_PKG_NAME);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ public class ManagerUpdate extends BroadcastReceiver {
|
|||||||
new DownloadReceiver() {
|
new DownloadReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onDownloadDone(Uri uri) {
|
public void onDownloadDone(Uri uri) {
|
||||||
|
Utils.dumpPrefs();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE);
|
||||||
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
@ -25,6 +25,7 @@ public class Const {
|
|||||||
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
||||||
public static final String MAGISK_LOG = "/cache/magisk.log";
|
public static final String MAGISK_LOG = "/cache/magisk.log";
|
||||||
public static final File EXTERNAL_PATH = new File(Environment.getExternalStorageDirectory(), "MagiskManager");
|
public static final File EXTERNAL_PATH = new File(Environment.getExternalStorageDirectory(), "MagiskManager");
|
||||||
|
public static final String MANAGER_CONFIGS = "/data/.tmp.magisk.config";
|
||||||
|
|
||||||
public static String BUSYBOX_PATH() {
|
public static String BUSYBOX_PATH() {
|
||||||
if (Utils.itemExist("/sbin/.core/busybox/busybox")) {
|
if (Utils.itemExist("/sbin/.core/busybox/busybox")) {
|
||||||
|
@ -240,6 +240,7 @@ public class ShowUI {
|
|||||||
mm.remoteManagerVersionString + ".apk")))
|
mm.remoteManagerVersionString + ".apk")))
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.install, (d, i) -> {
|
.setPositiveButton(R.string.install, (d, i) -> {
|
||||||
|
Utils.dumpPrefs();
|
||||||
Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
||||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
Intent intent = new Intent(mm, ManagerUpdate.class);
|
||||||
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
||||||
|
@ -22,6 +22,8 @@ import android.support.v4.content.ContextCompat;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.SplashActivity;
|
import com.topjohnwu.magisk.SplashActivity;
|
||||||
@ -37,6 +39,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
@ -250,4 +253,36 @@ public class Utils {
|
|||||||
float scale = context.getResources().getDisplayMetrics().density;
|
float scale = context.getResources().getDisplayMetrics().density;
|
||||||
return (int) (dp * scale + 0.5);
|
return (int) (dp * scale + 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void dumpPrefs() {
|
||||||
|
Map<String, ?> prefMap = MagiskManager.get().prefs.getAll();
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String json = gson.toJson(prefMap, new TypeToken<Map<String, ?>>(){}.getType());
|
||||||
|
Shell.su("echo '" + json + "' > " + Const.MANAGER_CONFIGS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadPrefs() {
|
||||||
|
List<String> ret = Utils.readFile(Const.MANAGER_CONFIGS);
|
||||||
|
if (isValidShellResponse(ret)) {
|
||||||
|
removeItem(Const.MANAGER_CONFIGS);
|
||||||
|
SharedPreferences.Editor editor = MagiskManager.get().prefs.edit();
|
||||||
|
String json = ret.get(0);
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Map<String, ?> prefMap = gson.fromJson(json, new TypeToken<Map<String, ?>>(){}.getType());
|
||||||
|
editor.clear();
|
||||||
|
for (Map.Entry<String, ?> entry : prefMap.entrySet()) {
|
||||||
|
Object value = entry.getValue();
|
||||||
|
if (value instanceof String) {
|
||||||
|
editor.putString(entry.getKey(), (String) value);
|
||||||
|
} else if (value instanceof Boolean) {
|
||||||
|
editor.putBoolean(entry.getKey(), (boolean) value);
|
||||||
|
} else if (value instanceof Integer) {
|
||||||
|
editor.putInt(entry.getKey(), (int) value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor.remove(Const.Key.ETAG_KEY);
|
||||||
|
editor.apply();
|
||||||
|
MagiskManager.get().loadConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user