diff --git a/app/build.gradle b/app/build.gradle index d5bcd6ac6..0dc4ae60f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,7 @@ android { applicationId "com.topjohnwu.magisk" minSdkVersion 21 targetSdkVersion 27 - versionCode 66 + versionCode 68 versionName "5.4.3" ndk { moduleName 'zipadjust' @@ -55,12 +55,13 @@ repositories { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation project(':crypto') - implementation 'com.android.support:recyclerview-v7:27.0.1' - implementation 'com.android.support:cardview-v7:27.0.1' - implementation 'com.android.support:design:27.0.1' - implementation 'com.android.support:support-v4:27.0.1' + implementation 'com.android.support:recyclerview-v7:27.0.2' + implementation 'com.android.support:cardview-v7:27.0.2' + implementation 'com.android.support:design:27.0.2' + implementation 'com.android.support:support-v4:27.0.2' implementation 'com.jakewharton:butterknife:8.8.1' implementation 'com.atlassian.commonmark:commonmark:0.10.0' implementation 'org.kamranzafar:jtar:2.3' + implementation 'com.google.code.gson:gson:2.8.2' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' } diff --git a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java index eb4931669..dfd8e9e14 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -1,6 +1,7 @@ package com.topjohnwu.magisk; import android.app.Application; +import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; @@ -103,13 +104,21 @@ public class MagiskManager extends Application { suDB = new SuDatabaseHelper(); } - // If detect original package, self destruct! + // Handle duplicate package if (!getPackageName().equals(Const.ORIG_PKG_NAME)) { try { 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; - } 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); diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 9c4a3c7bc..d39d47fc3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -42,6 +42,10 @@ public class SplashActivity extends Activity { } mm.loadMagiskInfo(); + if (Utils.itemExist(Const.MANAGER_CONFIGS)) { + Utils.loadPrefs(); + } + LoadModules loadModuleTask = new LoadModules(); if (Utils.checkNetworkStatus()) { @@ -64,14 +68,6 @@ public class SplashActivity extends Activity { // Setup suDB 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 if (Const.Value.UPDATE_SERVICE_VER > mm.updateServiceVersion) { ComponentName service = new ComponentName(this, UpdateCheckService.class); diff --git a/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java b/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java index 800bb7901..3be804b5b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java @@ -131,7 +131,8 @@ public class HideManager extends ParallelTask { return false; 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; } diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java b/app/src/main/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java index 581def1c0..8a9656c77 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java @@ -20,6 +20,7 @@ public class ManagerUpdate extends BroadcastReceiver { new DownloadReceiver() { @Override public void onDownloadDone(Uri uri) { + Utils.dumpPrefs(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Intent install = new Intent(Intent.ACTION_INSTALL_PACKAGE); install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Const.java b/app/src/main/java/com/topjohnwu/magisk/utils/Const.java index c593c9ed7..dca44d1aa 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Const.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Const.java @@ -25,6 +25,7 @@ public class Const { public static final String TMP_FOLDER_PATH = "/dev/tmp"; public static final String MAGISK_LOG = "/cache/magisk.log"; 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() { if (Utils.itemExist("/sbin/.core/busybox/busybox")) { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java b/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java index d58ff5824..73f65ed6a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java @@ -240,6 +240,7 @@ public class ShowUI { mm.remoteManagerVersionString + ".apk"))) .setCancelable(true) .setPositiveButton(R.string.install, (d, i) -> { + Utils.dumpPrefs(); Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> { Intent intent = new Intent(mm, ManagerUpdate.class); intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 3430d7f2c..84e472645 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -22,6 +22,8 @@ import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.widget.Toast; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.SplashActivity; @@ -37,6 +39,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Map; public class Utils { @@ -250,4 +253,36 @@ public class Utils { float scale = context.getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5); } + + public static void dumpPrefs() { + Map prefMap = MagiskManager.get().prefs.getAll(); + Gson gson = new Gson(); + String json = gson.toJson(prefMap, new TypeToken>(){}.getType()); + Shell.su("echo '" + json + "' > " + Const.MANAGER_CONFIGS); + } + + public static void loadPrefs() { + List 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 prefMap = gson.fromJson(json, new TypeToken>(){}.getType()); + editor.clear(); + for (Map.Entry 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(); + } + } } \ No newline at end of file