mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 21:45:27 +00:00
More precise sudb management
This commit is contained in:
parent
5ee49ba065
commit
a7ed6c15d3
@ -8,7 +8,7 @@ android {
|
|||||||
applicationId "com.topjohnwu.magisk"
|
applicationId "com.topjohnwu.magisk"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
versionCode 74
|
versionCode 75
|
||||||
versionName "5.4.3"
|
versionName "5.4.3"
|
||||||
ndk {
|
ndk {
|
||||||
moduleName 'zipadjust'
|
moduleName 'zipadjust'
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
### v5.4.3 (74)
|
### v5.4.3 (75)
|
||||||
- Fix dynamic resource loading, should prevent crashing when checking SafetyNet
|
- Fix dynamic resource loading, should prevent crashing when checking SafetyNet
|
||||||
- Update SignAPK to use very little RAM, should expand old device support
|
- Update SignAPK to use very little RAM, should expand old device support
|
||||||
- Support settings migration after hiding Magisk Manager
|
- Support settings migration after hiding Magisk Manager
|
||||||
@ -7,3 +7,4 @@
|
|||||||
- Add dark theme to superuser requests
|
- Add dark theme to superuser requests
|
||||||
- Properly handle new `KEEPVERITY` and `HIGHCOMP` flags for installation
|
- Properly handle new `KEEPVERITY` and `HIGHCOMP` flags for installation
|
||||||
- Adapt su database to `/data/adb/magisk.adb` and installation paths to `/data/adb`
|
- Adapt su database to `/data/adb/magisk.adb` and installation paths to `/data/adb`
|
||||||
|
- Massive improvements for repackaging Magisk Manager
|
||||||
|
@ -106,16 +106,7 @@ public class MagiskManager extends Application {
|
|||||||
} catch (PackageManager.NameNotFoundException ignored) { /* Expected */ }
|
} catch (PackageManager.NameNotFoundException ignored) { /* Expected */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
suDB = new SuDatabaseHelper(true);
|
suDB = new SuDatabaseHelper(false);
|
||||||
|
|
||||||
if (getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
|
||||||
String pkg = suDB.getStrings(Const.Key.SU_REQUESTER, null);
|
|
||||||
if (pkg != null) {
|
|
||||||
Utils.uninstallPkg(pkg);
|
|
||||||
suDB.setStrings(Const.Key.SU_REQUESTER, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repoDB = new RepoDatabaseHelper(this);
|
repoDB = new RepoDatabaseHelper(this);
|
||||||
defaultLocale = Locale.getDefault();
|
defaultLocale = Locale.getDefault();
|
||||||
setLocale();
|
setLocale();
|
||||||
@ -212,7 +203,7 @@ public class MagiskManager extends Application {
|
|||||||
keepEnc = false;
|
keepEnc = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suDB != null) {
|
if (suDB != null && !SuDatabaseHelper.verified) {
|
||||||
suDB.close();
|
suDB.close();
|
||||||
suDB = new SuDatabaseHelper();
|
suDB = new SuDatabaseHelper();
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,9 @@ public class SplashActivity extends Activity {
|
|||||||
|
|
||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager mm = getMagiskManager();
|
||||||
|
|
||||||
|
mm.loadMagiskInfo();
|
||||||
|
Utils.loadPrefs();
|
||||||
|
|
||||||
// Dynamic detect all locales
|
// Dynamic detect all locales
|
||||||
new LoadLocale().exec();
|
new LoadLocale().exec();
|
||||||
|
|
||||||
@ -45,9 +48,6 @@ public class SplashActivity extends Activity {
|
|||||||
getSystemService(NotificationManager.class).createNotificationChannel(channel);
|
getSystemService(NotificationManager.class).createNotificationChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
mm.loadMagiskInfo();
|
|
||||||
Utils.loadPrefs();
|
|
||||||
|
|
||||||
LoadModules loadModuleTask = new LoadModules();
|
LoadModules loadModuleTask = new LoadModules();
|
||||||
|
|
||||||
if (Utils.checkNetworkStatus()) {
|
if (Utils.checkNetworkStatus()) {
|
||||||
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||||||
public class SuDatabaseHelper extends SQLiteOpenHelper {
|
public class SuDatabaseHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public static final String DB_NAME = "su.db";
|
public static final String DB_NAME = "su.db";
|
||||||
|
public static boolean verified = false;
|
||||||
|
|
||||||
private static final int DATABASE_VER = 5;
|
private static final int DATABASE_VER = 5;
|
||||||
private static final String POLICY_TABLE = "policies";
|
private static final String POLICY_TABLE = "policies";
|
||||||
@ -41,7 +42,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
private static Context initDB(boolean local) {
|
private static Context initDB(boolean verify) {
|
||||||
Context context;
|
Context context;
|
||||||
MagiskManager ce = MagiskManager.get();
|
MagiskManager ce = MagiskManager.get();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
@ -61,46 +62,49 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
File db = Utils.getDatabasePath(context, DB_NAME);
|
File db = Utils.getDatabasePath(context, DB_NAME);
|
||||||
if (local && db.length() == 0) {
|
if (!verify && db.length() == 0) {
|
||||||
ce.loadMagiskInfo();
|
ce.loadMagiskInfo();
|
||||||
return initDB(false);
|
return initDB(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only care about local db (no shell involved)
|
// Only care about local db (no shell involved)
|
||||||
if (local)
|
if (!verify)
|
||||||
return context;
|
return context;
|
||||||
|
|
||||||
// We need to make sure the global db is setup properly
|
// We need to make sure the global db is setup properly
|
||||||
if (ce.magiskVersionCode >= 1464 && Shell.rootAccess()) {
|
if (ce.magiskVersionCode >= 1464 && Shell.rootAccess()) {
|
||||||
Shell.su_raw(Utils.fmt("mkdir %s; 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)) {
|
||||||
db = context.getDatabasePath(DB_NAME);
|
db = context.getDatabasePath(DB_NAME);
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
db.getParentFile().mkdirs();
|
||||||
db.createNewFile();
|
db.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the global and local db matches
|
// Make sure the global and local db is the same inode
|
||||||
if (!TextUtils.equals(Utils.checkMD5(GLOBAL_DB), Utils.checkMD5(db))) {
|
verified = TextUtils.equals(Utils.checkInode(GLOBAL_DB), Utils.checkInode(db));
|
||||||
|
if (!verified) {
|
||||||
Shell.su(Utils.fmt(
|
Shell.su(Utils.fmt(
|
||||||
"chown 0.0 %s; chmod 666 %s; chcon u:object_r:su_file:s0 %s;" +
|
"chown 0.0 %s; chmod 666 %s; chcon u:object_r:su_file:s0 %s;" +
|
||||||
"mount -o bind %s %s",
|
"mount -o bind %s %s",
|
||||||
GLOBAL_DB, GLOBAL_DB, GLOBAL_DB, GLOBAL_DB, db));
|
GLOBAL_DB, GLOBAL_DB, GLOBAL_DB, GLOBAL_DB, db));
|
||||||
|
verified = TextUtils.equals(Utils.checkInode(GLOBAL_DB), Utils.checkInode(db));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuDatabaseHelper() {
|
public SuDatabaseHelper() {
|
||||||
this(false);
|
this(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuDatabaseHelper(boolean local) {
|
public SuDatabaseHelper(boolean verify) {
|
||||||
this(initDB(local));
|
this(initDB(verify));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SuDatabaseHelper(Context context) {
|
private SuDatabaseHelper(Context context) {
|
||||||
@ -109,6 +113,14 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
pm = context.getPackageManager();
|
pm = context.getPackageManager();
|
||||||
mDb = getWritableDatabase();
|
mDb = getWritableDatabase();
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
|
if (context.getPackageName().equals(Const.ORIG_PKG_NAME)) {
|
||||||
|
String pkg = getStrings(Const.Key.SU_REQUESTER, null);
|
||||||
|
if (pkg != null) {
|
||||||
|
Utils.uninstallPkg(pkg);
|
||||||
|
setStrings(Const.Key.SU_REQUESTER, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -239,7 +239,6 @@ public class ShowUI {
|
|||||||
Utils.fmt("MagiskManager-v%s.apk", mm.remoteManagerVersionString)))
|
Utils.fmt("MagiskManager-v%s.apk", mm.remoteManagerVersionString)))
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setPositiveButton(R.string.install, (d, i) -> {
|
.setPositiveButton(R.string.install, (d, i) -> {
|
||||||
Utils.dumpPrefs();
|
|
||||||
Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
||||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
Intent intent = new Intent(mm, ManagerUpdate.class);
|
||||||
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
||||||
|
@ -62,9 +62,9 @@ public class Utils {
|
|||||||
return Shell.su(fmt("cat %s | sed '$a\\ ' | sed '$d'", path));
|
return Shell.su(fmt("cat %s | sed '$a\\ ' | sed '$d'", path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String checkMD5(Object path) {
|
public static String checkInode(Object path) {
|
||||||
List<String> ret = Shell.su(fmt("md5sum %s", path));
|
List<String> ret = Shell.su(fmt("ls -i %s", path));
|
||||||
return isValidShellResponse(ret) ? ret.get(0).split("\\s+")[0] : null;
|
return isValidShellResponse(ret) ? ret.get(0).trim().split("\\s+")[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void uninstallPkg(String pkg) {
|
public static void uninstallPkg(String pkg) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<!--Welcome Activity-->
|
<!--Welcome Activity-->
|
||||||
<string name="magiskhide" translatable="false">Απόκρυψη του Magisk</string>
|
|
||||||
<string name="modules">Modules</string>
|
<string name="modules">Modules</string>
|
||||||
|
|
||||||
<string name="downloads">Λήψεις</string>
|
<string name="downloads">Λήψεις</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user