diff --git a/app/src/full/java/com/topjohnwu/magisk/Const.java b/app/src/full/java/com/topjohnwu/magisk/Const.java index f2d00f15d..c2a4a70c0 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Const.java +++ b/app/src/full/java/com/topjohnwu/magisk/Const.java @@ -48,11 +48,6 @@ 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 HIDDEN_PATH = 1460; public static final int REMOVE_LEGACY_LINK = 1630; public static final int SEPOL_REFACTOR = 1640; public static final int FIX_ENV = 1650; diff --git a/app/src/full/java/com/topjohnwu/magisk/Data.java b/app/src/full/java/com/topjohnwu/magisk/Data.java index e02b18a98..1aa3f33e1 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Data.java +++ b/app/src/full/java/com/topjohnwu/magisk/Data.java @@ -95,8 +95,7 @@ public class Data { try { magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0]; magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V")); - String s = ShellUtils.fastCmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ? - "resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP); + String s = ShellUtils.fastCmd(("resetprop -p ") + Const.MAGISKHIDE_PROP); magiskHide = s.isEmpty() || Integer.parseInt(s) != 0; } catch (NumberFormatException ignored) {} } diff --git a/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java b/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java index 04115c751..8a0f48bb0 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java +++ b/app/src/full/java/com/topjohnwu/magisk/MagiskManager.java @@ -38,7 +38,7 @@ public class MagiskManager extends ContainerApp { Shell.Config.setInitializer(RootUtils.class); prefs = PreferenceManager.getDefaultSharedPreferences(this); - mDB = MagiskDatabaseHelper.getInstance(this); + mDB = MagiskDatabaseHelper.getInstance(); String pkg = mDB.getStrings(Const.Key.SU_MANAGER, null); if (pkg != null && getPackageName().equals(Const.ORIG_PKG_NAME)) { diff --git a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java index fecf23b00..502a4eafc 100644 --- a/app/src/full/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/MainActivity.java @@ -119,7 +119,6 @@ public class MainActivity extends BaseActivity public void checkHideSection() { Menu menu = navigationView.getMenu(); menu.findItem(R.id.magiskhide).setVisible(Shell.rootAccess() && - Data.magiskVersionCode >= Const.MAGISK_VER.UNIFIED && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)); menu.findItem(R.id.modules).setVisible(Shell.rootAccess() && Data.magiskVersionCode >= 0); menu.findItem(R.id.downloads).setVisible(Download.checkNetworkStatus(this) diff --git a/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java b/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java index 488866af1..b30559c19 100644 --- a/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java +++ b/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java @@ -38,26 +38,26 @@ public class MagiskDatabaseHelper { private static final String LOG_TABLE = "logs"; private static final String SETTINGS_TABLE = "settings"; private static final String STRINGS_TABLE = "strings"; + private static final File MANAGER_DB = + new File(Utils.fmt("/sbin/.core/db-%d/magisk.db", Const.USER_ID)); private PackageManager pm; private SQLiteDatabase db; - private MagiskManager mm; @NonNull - public static MagiskDatabaseHelper getInstance(MagiskManager mm) { + public static MagiskDatabaseHelper getInstance() { try { - return new MagiskDatabaseHelper(mm); + return new MagiskDatabaseHelper(); } catch (Exception e) { // Let's cleanup everything and try again Shell.su("db_clean '*'").exec(); - return new MagiskDatabaseHelper(mm); + return new MagiskDatabaseHelper(); } } - private MagiskDatabaseHelper(MagiskManager context) { - mm = context; - pm = mm.getPackageManager(); - db = openDatabase(mm); + private MagiskDatabaseHelper() { + pm = Data.MM().getPackageManager(); + db = openDatabase(); db.disableWriteAheadLogging(); int version = Data.magiskVersionCode >= Const.MAGISK_VER.DBVER_SIX ? DATABASE_VER : OLD_DATABASE_VER; int curVersion = db.getVersion(); @@ -71,48 +71,37 @@ public class MagiskDatabaseHelper { clearOutdated(); } - private SQLiteDatabase openDatabase(MagiskManager mm) { - final File DB_FILE = new File(Utils.fmt("/sbin/.core/db-%d/magisk.db", Const.USER_ID)); + private SQLiteDatabase openDatabase() { + MagiskManager mm = Data.MM(); Context de = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? mm.createDeviceProtectedStorageContext() : mm; - if (!DB_FILE.canWrite()) { + if (!MANAGER_DB.canWrite()) { if (!Shell.rootAccess()) { // We don't want the app to crash, create a db and return return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); } // Cleanup Shell.su("db_clean " + Const.USER_ID).exec(); - if (Data.magiskVersionCode < Const.MAGISK_VER.FBE_AWARE) { - // Super old legacy mode - return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); - } else if (Data.magiskVersionCode < Const.MAGISK_VER.HIDDEN_PATH) { - // Legacy mode with FBE aware - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - de.moveDatabaseFrom(mm, "su.db"); - } - return de.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); - } else { - // Global database - final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db"); - mm.deleteDatabase("su.db"); - de.deleteDatabase("su.db"); - if (Data.magiskVersionCode < Const.MAGISK_VER.SEPOL_REFACTOR) { - // We need some additional policies on old versions - Shell.su("db_sepatch").exec(); - } - if (!GLOBAL_DB.exists()) { - Shell.su("db_init").exec(); - SQLiteDatabase.openOrCreateDatabase(GLOBAL_DB, null).close(); - Shell.su("db_restore").exec(); - } + // Global database + final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db"); + mm.deleteDatabase("su.db"); + de.deleteDatabase("su.db"); + if (Data.magiskVersionCode < Const.MAGISK_VER.SEPOL_REFACTOR) { + // We need some additional policies on old versions + Shell.su("db_sepatch").exec(); + } + if (!GLOBAL_DB.exists()) { + Shell.su("db_init").exec(); + SQLiteDatabase.openOrCreateDatabase(GLOBAL_DB, null).close(); + Shell.su("db_restore").exec(); } Shell.su("db_setup " + Process.myUid()).exec(); } // Not using legacy mode, open the mounted global DB - return SQLiteDatabase.openOrCreateDatabase(DB_FILE, null); + return SQLiteDatabase.openOrCreateDatabase(MANAGER_DB, null); } - public void onUpgrade(SQLiteDatabase db, int oldVersion) { + private void onUpgrade(SQLiteDatabase db, int oldVersion) { if (oldVersion == 0) { createTables(db); oldVersion = 3; @@ -147,13 +136,13 @@ public class MagiskDatabaseHelper { } if (oldVersion == 5) { setSettings(Const.Key.SU_FINGERPRINT, - mm.prefs.getBoolean(Const.Key.SU_FINGERPRINT, false) ? 1 : 0); + Data.MM().prefs.getBoolean(Const.Key.SU_FINGERPRINT, false) ? 1 : 0); ++oldVersion; } } // Remove everything, we do not support downgrade - public void onDowngrade(SQLiteDatabase db) { + private void onDowngrade(SQLiteDatabase db) { Utils.toast(R.string.su_db_corrupt, Toast.LENGTH_LONG); db.execSQL("DROP TABLE IF EXISTS " + POLICY_TABLE); db.execSQL("DROP TABLE IF EXISTS " + LOG_TABLE); diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskFragment.java index c3f89a2d9..06d789f41 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/MagiskFragment.java @@ -214,11 +214,10 @@ public class MagiskFragment extends BaseFragment boolean hasNetwork = Download.checkNetworkStatus(mm); boolean hasRoot = Shell.rootAccess(); - boolean isUpToDate = Data.magiskVersionCode > Const.MAGISK_VER.UNIFIED; magiskUpdate.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); installOptionCard.setVisibility(hasNetwork ? View.VISIBLE : View.GONE); - uninstallButton.setVisibility(isUpToDate && hasRoot ? View.VISIBLE : View.GONE); + uninstallButton.setVisibility(hasRoot ? View.VISIBLE : View.GONE); coreOnlyNotice.setVisibility(mm.prefs.getBoolean(Const.Key.COREONLY, false) ? View.VISIBLE : View.GONE); int image, color; diff --git a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java index 7b1d712a1..907729f93 100644 --- a/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/fragments/SettingsFragment.java @@ -124,7 +124,7 @@ public class SettingsFragment extends PreferenceFragmentCompat fingerprint.setSummary(R.string.disable_fingerprint); } - if (Data.magiskVersionCode >= Const.MAGISK_VER.MANAGER_HIDE) { + if (Shell.rootAccess()) { if (mm.getPackageName().equals(Const.ORIG_PKG_NAME)) { hideManager.setOnPreferenceClickListener((pref) -> { PatchAPK.hideManager(requireActivity()); @@ -171,8 +171,6 @@ public class SettingsFragment extends PreferenceFragmentCompat if (!Shell.rootAccess()) { prefScreen.removePreference(magiskCategory); generalCatagory.removePreference(hideManager); - } else if (Data.magiskVersionCode < Const.MAGISK_VER.UNIFIED) { - prefScreen.removePreference(magiskCategory); } } diff --git a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java index b7d58e4eb..88247da25 100644 --- a/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java +++ b/app/src/full/java/com/topjohnwu/magisk/receivers/ShortcutReceiver.java @@ -45,8 +45,7 @@ public class ShortcutReceiver extends BroadcastReceiver { .setRank(0) .build()); } - if (root && Data.magiskVersionCode >= Const.MAGISK_VER.UNIFIED - && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) { + if (root && mm.prefs.getBoolean(Const.Key.MAGISKHIDE, false)) { shortCuts.add(new ShortcutInfo.Builder(mm, "magiskhide") .setShortLabel(mm.getString(R.string.magiskhide)) .setIntent(new Intent(mm, Data.classMap.get(SplashActivity.class))