Fix repackage manager settings migration

This commit is contained in:
topjohnwu 2019-03-11 05:43:48 -04:00
parent 5111086637
commit ed11e0bff6
5 changed files with 13 additions and 18 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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();

View File

@ -73,7 +73,7 @@ public abstract class MagiskInstaller {
public MagiskInstaller(List<String> out, List<String> 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();
}

View File

@ -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();
}