diff --git a/app/src/main/java/com/topjohnwu/magisk/App.java b/app/src/main/java/com/topjohnwu/magisk/App.java index b3de6b3ae..da3535832 100644 --- a/app/src/main/java/com/topjohnwu/magisk/App.java +++ b/app/src/main/java/com/topjohnwu/magisk/App.java @@ -20,6 +20,7 @@ import java.util.concurrent.ThreadPoolExecutor; public class App extends Application { public static App self; + public static Context deContext; public static ThreadPoolExecutor THREAD_POOL; // Global resources @@ -39,16 +40,17 @@ public class App extends Application { protected void attachBaseContext(Context base) { super.attachBaseContext(base); self = this; + deContext = base; - Context de = this; if (Build.VERSION.SDK_INT >= 24) { - de = createDeviceProtectedStorageContext(); - de.moveSharedPreferencesFrom(this, PreferenceManager.getDefaultSharedPreferencesName(base)); + deContext = base.createDeviceProtectedStorageContext(); + deContext.moveSharedPreferencesFrom(base, + PreferenceManager.getDefaultSharedPreferencesName(base)); } - prefs = PreferenceManager.getDefaultSharedPreferences(de); - mDB = new MagiskDB(this); + prefs = PreferenceManager.getDefaultSharedPreferences(deContext); + mDB = new MagiskDB(base); - Networking.init(this); + Networking.init(base); LocaleManager.setLocale(this); } diff --git a/app/src/main/java/com/topjohnwu/magisk/Config.java b/app/src/main/java/com/topjohnwu/magisk/Config.java index 76672af68..c1519ca51 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Config.java +++ b/app/src/main/java/com/topjohnwu/magisk/Config.java @@ -147,15 +147,15 @@ public class Config { // Flush prefs to disk App app = App.self; app.prefs.edit().commit(); - File xml = new File(app.getFilesDir().getParent() + "/shared_prefs", + File xml = new File(App.deContext.getFilesDir().getParent() + "/shared_prefs", app.getPackageName() + "_preferences.xml"); - Shell.su(Utils.fmt("cat %s > /data/user/0/%s", xml, Const.MANAGER_CONFIGS)).exec(); + Shell.su(Utils.fmt("cat %s > /data/adb/%s", xml, Const.MANAGER_CONFIGS)).exec(); } public static void initialize() { SharedPreferences pref = App.self.prefs; SharedPreferences.Editor editor = pref.edit(); - SuFile config = new SuFile("/data/user/0/" + Const.MANAGER_CONFIGS); + SuFile config = new SuFile("/data/adb/" + Const.MANAGER_CONFIGS); if (config.exists()) { try { SuFileInputStream is = new SuFileInputStream(config); diff --git a/app/src/main/java/com/topjohnwu/magisk/SuRequestActivity.java b/app/src/main/java/com/topjohnwu/magisk/SuRequestActivity.java index 67b636c06..787b93005 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SuRequestActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SuRequestActivity.java @@ -23,7 +23,6 @@ import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.container.Policy; import com.topjohnwu.magisk.utils.FingerprintHelper; import com.topjohnwu.magisk.utils.SuConnector; -import com.topjohnwu.magisk.utils.Utils; import java.io.IOException; @@ -76,7 +75,7 @@ public class SuRequestActivity extends BaseActivity { PackageManager pm = getPackageManager(); app.mDB.clearOutdated(); - timeoutPrefs = Utils.getDEContext().getSharedPreferences("su_timeout", 0); + timeoutPrefs = App.deContext.getSharedPreferences("su_timeout", 0); // Get policy Intent intent = getIntent(); diff --git a/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java b/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java index 7cb8f2a9c..229cee471 100644 --- a/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java +++ b/app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java @@ -73,7 +73,7 @@ public abstract class MagiskInstaller { public MagiskInstaller(List out, List err) { console = out; logs = err; - installDir = new File(Utils.getDEContext().getFilesDir().getParent(), "install"); + installDir = new File(App.deContext.getFilesDir().getParent(), "install"); Shell.sh("rm -rf " + installDir).exec(); installDir.mkdirs(); } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index d2cb23f54..1154839dd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -8,7 +8,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; -import android.os.Build; import android.provider.OpenableColumns; import android.widget.Toast; @@ -116,11 +115,6 @@ public class Utils { Config.Value.MULTIUSER_MODE_OWNER_MANAGED); } - public static Context getDEContext() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? - App.self.createDeviceProtectedStorageContext() : App.self; - } - public static void reboot() { Shell.su("/system/bin/reboot" + (Config.recovery ? " recovery" : "")).submit(); }