mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-16 14:17:07 +02: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 */ }
|
} catch (PackageManager.NameNotFoundException ignored) { /* Expected */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
suDB = new SuDatabaseHelper(false);
|
suDB = SuDatabaseHelper.getSuDB(false);
|
||||||
repoDB = new RepoDatabaseHelper(this);
|
repoDB = new RepoDatabaseHelper(this);
|
||||||
defaultLocale = Locale.getDefault();
|
defaultLocale = Locale.getDefault();
|
||||||
setLocale();
|
setLocale();
|
||||||
@ -214,7 +214,7 @@ public class MagiskManager extends Application {
|
|||||||
|
|
||||||
if (suDB != null && !SuDatabaseHelper.verified) {
|
if (suDB != null && !SuDatabaseHelper.verified) {
|
||||||
suDB.close();
|
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);
|
File db = Utils.getDB(context, DB_NAME);
|
||||||
if (!verify) {
|
if (!verify) {
|
||||||
if (db.length() == 0) {
|
if (db.exists() && db.length() == 0) {
|
||||||
ce.loadMagiskInfo();
|
ce.loadMagiskInfo();
|
||||||
// Continue verification
|
// Continue verification
|
||||||
} else {
|
} else {
|
||||||
@ -108,7 +108,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
// New global su db
|
// New global su db
|
||||||
Shell.su(Utils.fmt("mkdir %s 2>/dev/null; chmod 700 %s", GLOBAL_DB.getParent(), GLOBAL_DB.getParent()));
|
Shell.su(Utils.fmt("mkdir %s 2>/dev/null; chmod 700 %s", GLOBAL_DB.getParent(), GLOBAL_DB.getParent()));
|
||||||
if (!Utils.itemExist(GLOBAL_DB)) {
|
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));
|
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));
|
verified = TextUtils.equals(Utils.checkInode(GLOBAL_DB), Utils.checkInode(db));
|
||||||
@ -125,12 +125,17 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuDatabaseHelper() {
|
public static SuDatabaseHelper getSuDB(boolean verify) {
|
||||||
this(true);
|
try {
|
||||||
}
|
return new SuDatabaseHelper(initDB(verify));
|
||||||
|
} catch(Exception e) {
|
||||||
public SuDatabaseHelper(boolean verify) {
|
// Try to catch runtime exceptions and remove all db for retry
|
||||||
this(initDB(verify));
|
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) {
|
private SuDatabaseHelper(Context context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user