Fix repackaging

This commit is contained in:
topjohnwu 2018-02-13 03:27:27 +08:00
parent b9e7d0faea
commit bffa837825
3 changed files with 30 additions and 15 deletions

View File

@ -96,6 +96,7 @@ public class MagiskManager extends Shell.ContainerApp {
super.onCreate(); super.onCreate();
Shell.setFlags(Shell.FLAG_MOUNT_MASTER); Shell.setFlags(Shell.FLAG_MOUNT_MASTER);
Shell.verboseLogging(BuildConfig.DEBUG);
BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH); BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH);
Shell.setInitializer(new Shell.Initializer() { Shell.setInitializer(new Shell.Initializer() {
@Override @Override
@ -125,6 +126,14 @@ public class MagiskManager extends Shell.ContainerApp {
} }
suDB = SuDatabaseHelper.getInstance(this); suDB = SuDatabaseHelper.getInstance(this);
String pkg = suDB.getStrings(Const.Key.SU_REQUESTER, Const.ORIG_PKG_NAME);
if (getPackageName().equals(Const.ORIG_PKG_NAME) && !pkg.equals(Const.ORIG_PKG_NAME)) {
suDB.setStrings(Const.Key.SU_REQUESTER, null);
Utils.uninstallPkg(pkg);
suDB = SuDatabaseHelper.getInstance(this);
}
repoDB = new RepoDatabaseHelper(this); repoDB = new RepoDatabaseHelper(this);
defaultLocale = Locale.getDefault(); defaultLocale = Locale.getDefault();
setLocale(); setLocale();

View File

@ -130,12 +130,13 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
} }
// Install the application // Install the application
if (ShellUtils.fastCmdResult(Shell.getShell(), "pm install " + repack)) if (!ShellUtils.fastCmdResult(Shell.getShell(), "pm install " + repack))
return false; return false;
repack.delete(); repack.delete();
mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg); mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
mm.suDB.flush();
Utils.dumpPrefs(); Utils.dumpPrefs();
Utils.uninstallPkg(Const.ORIG_PKG_NAME); Utils.uninstallPkg(Const.ORIG_PKG_NAME);

View File

@ -35,6 +35,7 @@ public class SuDatabaseHelper {
private PackageManager pm; private PackageManager pm;
private SQLiteDatabase mDb; private SQLiteDatabase mDb;
private File DB_FILE;
public static SuDatabaseHelper getInstance(MagiskManager mm) { public static SuDatabaseHelper getInstance(MagiskManager mm) {
try { try {
@ -66,14 +67,14 @@ public class SuDatabaseHelper {
} }
private SQLiteDatabase openDatabase(MagiskManager mm) { private SQLiteDatabase openDatabase(MagiskManager mm) {
SQLiteDatabase db = null;
String GLOBAL_DB = "/data/adb/magisk.db"; String GLOBAL_DB = "/data/adb/magisk.db";
File dbFile = new File(Utils.fmt("/sbin/.core/db-%s/magisk.db", mm.getPackageName())); DB_FILE = new File(Utils.fmt("/sbin/.core/db-%s/magisk.db", mm.getPackageName()));
Context de = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N Context de = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
? mm.createDeviceProtectedStorageContext() : mm; ? mm.createDeviceProtectedStorageContext() : mm;
if (!dbFile.exists()) { if (!DB_FILE.exists()) {
if (!Shell.rootAccess()) { if (!Shell.rootAccess()) {
// We don't want the app to crash, create a db and return // We don't want the app to crash, create a db and return
DB_FILE = mm.getDatabasePath("su.db");
return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null);
} }
mm.loadMagiskInfo(); mm.loadMagiskInfo();
@ -81,13 +82,15 @@ public class SuDatabaseHelper {
cleanup(); cleanup();
if (mm.magiskVersionCode < 1410) { if (mm.magiskVersionCode < 1410) {
// Super old legacy mode // Super old legacy mode
db = mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); DB_FILE = mm.getDatabasePath("su.db");
return mm.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null);
} else if (mm.magiskVersionCode < 1450) { } else if (mm.magiskVersionCode < 1450) {
// Legacy mode with FBE aware // Legacy mode with FBE aware
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
de.moveDatabaseFrom(mm, "su.db"); de.moveDatabaseFrom(mm, "su.db");
} }
db = de.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null); DB_FILE = de.getDatabasePath("su.db");
return de.openOrCreateDatabase("su.db", Context.MODE_PRIVATE, null);
} else { } else {
mm.deleteDatabase("su.db"); mm.deleteDatabase("su.db");
de.deleteDatabase("su.db"); de.deleteDatabase("su.db");
@ -103,18 +106,15 @@ public class SuDatabaseHelper {
"mount -o bind %s %s;" + "mount -o bind %s %s;" +
"chcon u:object_r:su_file:s0 %s/*; chown %d.%d %s;" + "chcon u:object_r:su_file:s0 %s/*; chown %d.%d %s;" +
"chmod 666 %s/*; chmod 700 %s;", "chmod 666 %s/*; chmod 700 %s;",
GLOBAL_DB, dbFile.getParent(), dbFile, dbFile, GLOBAL_DB, DB_FILE.getParent(), DB_FILE, DB_FILE,
GLOBAL_DB, dbFile, GLOBAL_DB, DB_FILE,
dbFile.getParent(), Process.myUid(), Process.myUid(), dbFile.getParent(), DB_FILE.getParent(), Process.myUid(), Process.myUid(), DB_FILE.getParent(),
dbFile.getParent(), dbFile.getParent() DB_FILE.getParent(), DB_FILE.getParent()
)); ));
} }
} }
if (db == null) { // Not using legacy mode, open the mounted global DB
// Not using legacy mode, open the mounted global DB return SQLiteDatabase.openOrCreateDatabase(DB_FILE, null);
db = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
}
return db;
} }
public void onUpgrade(SQLiteDatabase db, int oldVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion) {
@ -315,4 +315,9 @@ public class SuDatabaseHelper {
} }
return value; return value;
} }
public void flush() {
mDb.close();
mDb = SQLiteDatabase.openOrCreateDatabase(DB_FILE, null);
}
} }