Only place files in de on FDE enabled devices

This commit is contained in:
topjohnwu 2017-09-24 21:29:01 +08:00
parent 4f5c656b05
commit a3abb86daa
4 changed files with 27 additions and 21 deletions

View File

@ -138,13 +138,11 @@ public class MagiskManager extends Application {
super.onCreate(); super.onCreate();
prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (getDatabasePath(SuDatabaseHelper.DB_NAME).exists() if (getDatabasePath(SuDatabaseHelper.DB_NAME).exists()) {
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
// Don't migrate yet, wait and check Magisk version // Don't migrate yet, wait and check Magisk version
suDB = new SuDatabaseHelper(this); suDB = new SuDatabaseHelper(this);
} else { } else {
// Place the suDB in DE memory suDB = new SuDatabaseHelper(Utils.getEncContext(this));
suDB = new SuDatabaseHelper(createDeviceProtectedStorageContext());
} }
repoDB = new RepoDatabaseHelper(this); repoDB = new RepoDatabaseHelper(this);
@ -208,13 +206,13 @@ public class MagiskManager extends Application {
getMagiskInfo(); getMagiskInfo();
// Check if we need to migrate suDB // Check if we need to migrate suDB
if (magiskVersionCode >= 1410 if (getDatabasePath(SuDatabaseHelper.DB_NAME).exists() && Utils.useFDE(this)) {
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N if (magiskVersionCode >= 1410) {
&& getDatabasePath(SuDatabaseHelper.DB_NAME).exists()) { suDB.close();
suDB.close(); Context de = createDeviceProtectedStorageContext();
Context de = createDeviceProtectedStorageContext(); de.moveDatabaseFrom(this, SuDatabaseHelper.DB_NAME);
de.moveDatabaseFrom(this, SuDatabaseHelper.DB_NAME); suDB = new SuDatabaseHelper(de);
suDB = new SuDatabaseHelper(de); }
} }
new LoadLocale(this).exec(); new LoadLocale(this).exec();
@ -284,7 +282,7 @@ public class MagiskManager extends Application {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL,
getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT); getString(R.string.magisk_updates), NotificationManager.IMPORTANCE_DEFAULT);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel); getSystemService(NotificationManager.class).createNotificationChannel(channel);
} }
LoadModules loadModuleTask = new LoadModules(this); LoadModules loadModuleTask = new LoadModules(this);

View File

@ -75,14 +75,7 @@ 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; File install = new File(Utils.getEncContext(mm).getFilesDir().getParent(), "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);

View File

@ -5,6 +5,7 @@ import android.app.Activity;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
@ -15,6 +16,7 @@ import android.database.Cursor;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
@ -527,4 +529,17 @@ public class Utils {
.setNegativeButton(R.string.no_thanks, null) .setNegativeButton(R.string.no_thanks, null)
.show(); .show();
} }
public static boolean useFDE(Context context) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& context.getSystemService(DevicePolicyManager.class).getStorageEncryptionStatus()
== DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER;
}
public static Context getEncContext(Context context) {
if (useFDE(context))
return context.createDeviceProtectedStorageContext();
else
return context;
}
} }

View File

@ -7,7 +7,7 @@ buildscript {
maven { url "https://maven.google.com" } maven { url "https://maven.google.com" }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta5' classpath 'com.android.tools.build:gradle:3.0.0-beta6'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files