Proper FBE support: place files in DE
This commit is contained in:
parent
0acc23e058
commit
b4ecd93f1c
@ -17,7 +17,8 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
android:directBootAware="true"
|
||||||
|
tools:ignore="UnusedAttribute">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
|
@ -136,9 +136,17 @@ public class MagiskManager extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
new File(getApplicationInfo().dataDir).mkdirs(); /* Create the app data directory */
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
if (getDatabasePath(SuDatabaseHelper.DB_NAME).exists()
|
||||||
|
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
||||||
|
// Don't migrate yet, wait and check Magisk version
|
||||||
suDB = new SuDatabaseHelper(this);
|
suDB = new SuDatabaseHelper(this);
|
||||||
|
} else {
|
||||||
|
// Place the suDB in DE memory
|
||||||
|
suDB = new SuDatabaseHelper(createDeviceProtectedStorageContext());
|
||||||
|
}
|
||||||
|
|
||||||
repoDB = new RepoDatabaseHelper(this);
|
repoDB = new RepoDatabaseHelper(this);
|
||||||
defaultLocale = Locale.getDefault();
|
defaultLocale = Locale.getDefault();
|
||||||
setLocale();
|
setLocale();
|
||||||
@ -198,6 +206,17 @@ public class MagiskManager extends Application {
|
|||||||
boolean hasNetwork = Utils.checkNetworkStatus(this);
|
boolean hasNetwork = Utils.checkNetworkStatus(this);
|
||||||
|
|
||||||
getMagiskInfo();
|
getMagiskInfo();
|
||||||
|
|
||||||
|
// Check if we need to migrate suDB
|
||||||
|
if (magiskVersionCode >= 1410
|
||||||
|
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||||
|
&& getDatabasePath(SuDatabaseHelper.DB_NAME).exists()) {
|
||||||
|
suDB.close();
|
||||||
|
Context de = createDeviceProtectedStorageContext();
|
||||||
|
de.moveDatabaseFrom(this, SuDatabaseHelper.DB_NAME);
|
||||||
|
suDB = new SuDatabaseHelper(de);
|
||||||
|
}
|
||||||
|
|
||||||
new LoadLocale(this).exec();
|
new LoadLocale(this).exec();
|
||||||
|
|
||||||
// Root actions
|
// Root actions
|
||||||
|
@ -75,7 +75,14 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
|||||||
MagiskManager mm = getMagiskManager();
|
MagiskManager mm = getMagiskManager();
|
||||||
if (mm == null) return false;
|
if (mm == null) return false;
|
||||||
|
|
||||||
File install = new File(mm.getApplicationInfo().dataDir, "install");
|
File install;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
// Need to be stored in device encrypted storage for FBE
|
||||||
|
install = new File(mm.createDeviceProtectedStorageContext().getFilesDir().getParent(),
|
||||||
|
"install");
|
||||||
|
} else {
|
||||||
|
install = new File(mm.getApplicationInfo().dataDir, "install");
|
||||||
|
}
|
||||||
getShell().sh_raw("rm -rf " + install);
|
getShell().sh_raw("rm -rf " + install);
|
||||||
|
|
||||||
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
||||||
|
@ -39,18 +39,19 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
public static final int NAMESPACE_MODE_REQUESTER = 1;
|
public static final int NAMESPACE_MODE_REQUESTER = 1;
|
||||||
public static final int NAMESPACE_MODE_ISOLATE = 2;
|
public static final int NAMESPACE_MODE_ISOLATE = 2;
|
||||||
|
|
||||||
|
public static final String DB_NAME = "su.db";
|
||||||
private static final int DATABASE_VER = 3;
|
private static final int DATABASE_VER = 3;
|
||||||
private static final String POLICY_TABLE = "policies";
|
private static final String POLICY_TABLE = "policies";
|
||||||
private static final String LOG_TABLE = "logs";
|
private static final String LOG_TABLE = "logs";
|
||||||
private static final String SETTINGS_TABLE = "settings";
|
private static final String SETTINGS_TABLE = "settings";
|
||||||
|
|
||||||
private MagiskManager magiskManager;
|
private MagiskManager mm;
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
public SuDatabaseHelper(Context context) {
|
public SuDatabaseHelper(Context context) {
|
||||||
super(context, "su.db", null, DATABASE_VER);
|
super(context, DB_NAME, null, DATABASE_VER);
|
||||||
magiskManager = Utils.getMagiskManager(context);
|
mm = Utils.getMagiskManager(context);
|
||||||
pm = context.getPackageManager();
|
pm = context.getPackageManager();
|
||||||
mDb = getWritableDatabase();
|
mDb = getWritableDatabase();
|
||||||
cleanup();
|
cleanup();
|
||||||
@ -81,10 +82,10 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
"FROM " + POLICY_TABLE + "_old");
|
"FROM " + POLICY_TABLE + "_old");
|
||||||
db.execSQL("DROP TABLE " + POLICY_TABLE + "_old");
|
db.execSQL("DROP TABLE " + POLICY_TABLE + "_old");
|
||||||
|
|
||||||
File oldDB = magiskManager.getDatabasePath("sulog.db");
|
File oldDB = mm.getDatabasePath("sulog.db");
|
||||||
if (oldDB.exists()) {
|
if (oldDB.exists()) {
|
||||||
migrateLegacyLogList(oldDB, db);
|
migrateLegacyLogList(oldDB, db);
|
||||||
magiskManager.deleteDatabase("sulog.db");
|
mm.deleteDatabase("sulog.db");
|
||||||
}
|
}
|
||||||
++oldVersion;
|
++oldVersion;
|
||||||
}
|
}
|
||||||
@ -120,7 +121,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
new String[] { String.valueOf(System.currentTimeMillis() / 1000) });
|
new String[] { String.valueOf(System.currentTimeMillis() / 1000) });
|
||||||
// Clear outdated logs
|
// Clear outdated logs
|
||||||
mDb.delete(LOG_TABLE, "time < ?", new String[] { String.valueOf(
|
mDb.delete(LOG_TABLE, "time < ?", new String[] { String.valueOf(
|
||||||
System.currentTimeMillis() - magiskManager.suLogTimeout * 86400000) });
|
System.currentTimeMillis() - mm.suLogTimeout * 86400000) });
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deletePolicy(Policy policy) {
|
public void deletePolicy(Policy policy) {
|
||||||
@ -178,7 +179,7 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
Policy policy = new Policy(c, pm);
|
Policy policy = new Policy(c, pm);
|
||||||
// The application changed UID for some reason, check user config
|
// The application changed UID for some reason, check user config
|
||||||
if (policy.info.uid != policy.uid) {
|
if (policy.info.uid != policy.uid) {
|
||||||
if (magiskManager.suReauth) {
|
if (mm.suReauth) {
|
||||||
// Reauth required, remove from DB
|
// Reauth required, remove from DB
|
||||||
deletePolicy(policy);
|
deletePolicy(policy);
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user