mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-29 06:07:41 +00:00
More robust sudb handling
This commit is contained in:
parent
96650c06f0
commit
349b3e961b
@ -106,7 +106,7 @@ public class MagiskManager extends Application {
|
||||
} catch (PackageManager.NameNotFoundException ignored) { /* Expected */ }
|
||||
}
|
||||
|
||||
suDB = new SuDatabaseHelper(false);
|
||||
suDB = SuDatabaseHelper.getSuDB(false);
|
||||
repoDB = new RepoDatabaseHelper(this);
|
||||
defaultLocale = Locale.getDefault();
|
||||
setLocale();
|
||||
@ -214,7 +214,7 @@ public class MagiskManager extends Application {
|
||||
|
||||
if (suDB != null && !SuDatabaseHelper.verified) {
|
||||
suDB.close();
|
||||
suDB = new SuDatabaseHelper();
|
||||
suDB = SuDatabaseHelper.getSuDB(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
File db = Utils.getDB(context, DB_NAME);
|
||||
if (!verify) {
|
||||
if (db.length() == 0) {
|
||||
if (db.exists() && db.length() == 0) {
|
||||
ce.loadMagiskInfo();
|
||||
// Continue verification
|
||||
} else {
|
||||
@ -108,7 +108,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
||||
// New global su db
|
||||
Shell.su(Utils.fmt("mkdir %s 2>/dev/null; chmod 700 %s", GLOBAL_DB.getParent(), GLOBAL_DB.getParent()));
|
||||
if (!Utils.itemExist(GLOBAL_DB)) {
|
||||
Utils.javaCreateFile(db);
|
||||
context.openOrCreateDatabase(DB_NAME, 0, null).close();
|
||||
Shell.su(Utils.fmt("cp -af %s %s; rm -f %s*", db, GLOBAL_DB, db));
|
||||
}
|
||||
verified = TextUtils.equals(Utils.checkInode(GLOBAL_DB), Utils.checkInode(db));
|
||||
@ -125,12 +125,17 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
||||
return context;
|
||||
}
|
||||
|
||||
public SuDatabaseHelper() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public SuDatabaseHelper(boolean verify) {
|
||||
this(initDB(verify));
|
||||
public static SuDatabaseHelper getSuDB(boolean verify) {
|
||||
try {
|
||||
return new SuDatabaseHelper(initDB(verify));
|
||||
} catch(Exception e) {
|
||||
// Try to catch runtime exceptions and remove all db for retry
|
||||
unmntDB();
|
||||
Shell.su(Utils.fmt("rm -rf /data/user*/*/magisk.db /data/adb/magisk.db /data/user*/*/%s/databases"),
|
||||
MagiskManager.get().getPackageName());
|
||||
e.printStackTrace();
|
||||
return new SuDatabaseHelper(initDB(false));
|
||||
}
|
||||
}
|
||||
|
||||
private SuDatabaseHelper(Context context) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user