From fd7b5f393af320c7a633c350b5cf137370b385c8 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 14 Apr 2018 15:32:37 +0800 Subject: [PATCH] Make Magisk version more clear --- src/main/java/com/topjohnwu/magisk/MagiskFragment.java | 3 ++- src/main/java/com/topjohnwu/magisk/MagiskManager.java | 2 +- src/main/java/com/topjohnwu/magisk/MainActivity.java | 2 +- .../java/com/topjohnwu/magisk/SettingsActivity.java | 4 ++-- .../magisk/database/MagiskDatabaseHelper.java | 6 +++--- .../topjohnwu/magisk/receivers/ShortcutReceiver.java | 2 +- src/main/java/com/topjohnwu/magisk/utils/Const.java | 10 ++++++++++ src/main/java/com/topjohnwu/magisk/utils/ShowUI.java | 2 +- src/main/java/com/topjohnwu/magisk/utils/Utils.java | 2 +- 9 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/topjohnwu/magisk/MagiskFragment.java b/src/main/java/com/topjohnwu/magisk/MagiskFragment.java index 65b4f26d5..a56a7b5c9 100644 --- a/src/main/java/com/topjohnwu/magisk/MagiskFragment.java +++ b/src/main/java/com/topjohnwu/magisk/MagiskFragment.java @@ -22,6 +22,7 @@ import com.topjohnwu.magisk.asyncs.CheckUpdates; import com.topjohnwu.magisk.components.AlertDialogBuilder; import com.topjohnwu.magisk.components.ExpandableView; import com.topjohnwu.magisk.components.Fragment; +import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.ShowUI; import com.topjohnwu.magisk.utils.Topic; import com.topjohnwu.magisk.utils.Utils; @@ -205,7 +206,7 @@ public class MagiskFragment extends Fragment boolean hasNetwork = Utils.checkNetworkStatus(); boolean hasRoot = Shell.rootAccess(); - boolean isUpToDate = mm.magiskVersionCode > 1300; + boolean isUpToDate = mm.magiskVersionCode > Const.MAGISK_VER.UNIFIED; magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); safetyNetCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); diff --git a/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/src/main/java/com/topjohnwu/magisk/MagiskManager.java index a9c9a2dae..70c55d7bc 100644 --- a/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -210,7 +210,7 @@ public class MagiskManager extends Shell.ContainerApp { try { magiskVersionString = Utils.cmd("magisk -v").split(":")[0]; magiskVersionCode = Integer.parseInt(Utils.cmd("magisk -V")); - String s = Utils.cmd((magiskVersionCode > 1435 ? "resetprop -p " : "getprop ") + String s = Utils.cmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ? "resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP); magiskHide = s == null || Integer.parseInt(s) != 0; } catch (Exception ignored) {} diff --git a/src/main/java/com/topjohnwu/magisk/MainActivity.java b/src/main/java/com/topjohnwu/magisk/MainActivity.java index 9f3ad3951..584dd3272 100644 --- a/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -138,7 +138,7 @@ public class MainActivity extends Activity MagiskManager mm = getMagiskManager(); Menu menu = navigationView.getMenu(); menu.findItem(R.id.magiskhide).setVisible( - Shell.rootAccess() && mm.magiskVersionCode >= 1300 + Shell.rootAccess() && mm.magiskVersionCode >= Const.MAGISK_VER.UNIFIED && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)); menu.findItem(R.id.modules).setVisible(!mm.prefs.getBoolean(Const.Key.COREONLY, false) && Shell.rootAccess() && mm.magiskVersionCode >= 0); diff --git a/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index 90dcf026a..536fb9772 100644 --- a/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -156,7 +156,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { fingerprint.setSummary(R.string.disable_fingerprint); } - if (mm.magiskVersionCode >= 1440) { + if (mm.magiskVersionCode >= Const.MAGISK_VER.MANAGER_HIDE) { if (mm.getPackageName().equals(Const.ORIG_PKG_NAME)) { hideManager.setOnPreferenceClickListener((pref) -> { new HideManager(getActivity()).exec(); @@ -194,7 +194,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber { if (!Shell.rootAccess()) { prefScreen.removePreference(magiskCategory); generalCatagory.removePreference(hideManager); - } else if (mm.magiskVersionCode < 1300) { + } else if (mm.magiskVersionCode < Const.MAGISK_VER.UNIFIED) { prefScreen.removePreference(magiskCategory); } } diff --git a/src/main/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java b/src/main/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java index ab11850e1..89b4d077d 100644 --- a/src/main/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java +++ b/src/main/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java @@ -75,10 +75,10 @@ public class MagiskDatabaseHelper { mm.loadMagiskInfo(); // Cleanup Shell.Sync.su("db_clean " + Const.USER_ID); - if (mm.magiskVersionCode < 1410) { + if (mm.magiskVersionCode < Const.MAGISK_VER.FBE_AWARE) { // Super old legacy mode return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); - } else if (mm.magiskVersionCode < 1450) { + } else if (mm.magiskVersionCode < Const.MAGISK_VER.LEGACY_GLOBAL_DB) { // Legacy mode with FBE aware if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { de.moveDatabaseFrom(mm, "su.db"); @@ -89,7 +89,7 @@ public class MagiskDatabaseHelper { final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db", true); mm.deleteDatabase("su.db"); de.deleteDatabase("su.db"); - if (mm.magiskVersionCode < 1460) { + if (mm.magiskVersionCode < Const.MAGISK_VER.HIDDEN_PATH) { // Link to new path File oldDB = new File(de.getFilesDir().getParentFile().getParentFile(), "magisk.db"); diff --git a/src/main/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java b/src/main/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java index 8dba2d7b3..175ce9df1 100644 --- a/src/main/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java +++ b/src/main/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java @@ -48,7 +48,7 @@ public class ShortcutReceiver extends BroadcastReceiver { .setIcon(Icon.createWithResource(mm, R.drawable.sc_superuser)) .build()); } - if (Shell.rootAccess() && mm.magiskVersionCode >= 1300 + if (Shell.rootAccess() && mm.magiskVersionCode >= Const.MAGISK_VER.UNIFIED && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) { shortCuts.add(new ShortcutInfo.Builder(mm, "magiskhide") .setShortLabel(mm.getString(R.string.magiskhide)) diff --git a/src/main/java/com/topjohnwu/magisk/utils/Const.java b/src/main/java/com/topjohnwu/magisk/utils/Const.java index 2a53fcf8c..7e8b8a874 100644 --- a/src/main/java/com/topjohnwu/magisk/utils/Const.java +++ b/src/main/java/com/topjohnwu/magisk/utils/Const.java @@ -69,6 +69,16 @@ public class Const { public static final int USER_ID = Process.myUid() / 100000; + public static final class MAGISK_VER { + public static final int UNIFIED = 1300; + public static final int FBE_AWARE = 1410; + public static final int RESETPROP_PERSIST = 1436; + public static final int MANAGER_HIDE = 1440; + public static final int DTBO_SUPPORT = 1446; + public static final int LEGACY_GLOBAL_DB = 1450; + public static final int HIDDEN_PATH = 1460; + } + public static class ID { public static final int UPDATE_SERVICE_ID = 1; public static final int FETCH_ZIP = 2; diff --git a/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java b/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java index 4836268e2..460314e0e 100644 --- a/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java +++ b/src/main/java/com/topjohnwu/magisk/utils/ShowUI.java @@ -268,7 +268,7 @@ public class ShowUI { Shell.Sync.su( Utils.fmt("echo '%s' > /cache/%s", uninstaller.toString().replace("'", "'\\''"), Const.UNINSTALLER), Utils.fmt("echo '%s' > %s/%s", utils.toString().replace("'", "'\\''"), - mm.magiskVersionCode >= 1464 ? "/data/adb/magisk" : "/data/magisk", Const.UTIL_FUNCTIONS) + mm.magiskVersionCode >= Const.MAGISK_VER.HIDDEN_PATH ? "/data/adb/magisk" : "/data/magisk", Const.UTIL_FUNCTIONS) ); try { uninstaller.close(); diff --git a/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 2822b47a1..c0884a098 100644 --- a/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -202,7 +202,7 @@ public class Utils { public static void patchDTBO() { MagiskManager mm = MagiskManager.get(); - if (mm.magiskVersionCode >= 1446 && !mm.keepVerity) { + if (mm.magiskVersionCode >= Const.MAGISK_VER.DTBO_SUPPORT && !mm.keepVerity) { if (ShellUtils.fastCmdResult(Shell.getShell(), "patch_dtbo_image")) { ShowUI.dtboPatchedNotification(); }