mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-11-12 22:43:35 +00:00
Support migrating settings after repackage
This commit is contained in:
@@ -25,6 +25,7 @@ public class Const {
|
||||
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
||||
public static final String MAGISK_LOG = "/cache/magisk.log";
|
||||
public static final File EXTERNAL_PATH = new File(Environment.getExternalStorageDirectory(), "MagiskManager");
|
||||
public static final String MANAGER_CONFIGS = "/data/.tmp.magisk.config";
|
||||
|
||||
public static String BUSYBOX_PATH() {
|
||||
if (Utils.itemExist("/sbin/.core/busybox/busybox")) {
|
||||
|
||||
@@ -240,6 +240,7 @@ public class ShowUI {
|
||||
mm.remoteManagerVersionString + ".apk")))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.install, (d, i) -> {
|
||||
Utils.dumpPrefs();
|
||||
Utils.runWithPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, () -> {
|
||||
Intent intent = new Intent(mm, ManagerUpdate.class);
|
||||
intent.putExtra(Const.Key.INTENT_SET_LINK, mm.managerLink);
|
||||
|
||||
@@ -22,6 +22,8 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.SplashActivity;
|
||||
@@ -37,6 +39,7 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class Utils {
|
||||
|
||||
@@ -250,4 +253,36 @@ public class Utils {
|
||||
float scale = context.getResources().getDisplayMetrics().density;
|
||||
return (int) (dp * scale + 0.5);
|
||||
}
|
||||
|
||||
public static void dumpPrefs() {
|
||||
Map<String, ?> prefMap = MagiskManager.get().prefs.getAll();
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(prefMap, new TypeToken<Map<String, ?>>(){}.getType());
|
||||
Shell.su("echo '" + json + "' > " + Const.MANAGER_CONFIGS);
|
||||
}
|
||||
|
||||
public static void loadPrefs() {
|
||||
List<String> ret = Utils.readFile(Const.MANAGER_CONFIGS);
|
||||
if (isValidShellResponse(ret)) {
|
||||
removeItem(Const.MANAGER_CONFIGS);
|
||||
SharedPreferences.Editor editor = MagiskManager.get().prefs.edit();
|
||||
String json = ret.get(0);
|
||||
Gson gson = new Gson();
|
||||
Map<String, ?> prefMap = gson.fromJson(json, new TypeToken<Map<String, ?>>(){}.getType());
|
||||
editor.clear();
|
||||
for (Map.Entry<String, ?> entry : prefMap.entrySet()) {
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof String) {
|
||||
editor.putString(entry.getKey(), (String) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
editor.putBoolean(entry.getKey(), (boolean) value);
|
||||
} else if (value instanceof Integer) {
|
||||
editor.putInt(entry.getKey(), (int) value);
|
||||
}
|
||||
}
|
||||
editor.remove(Const.Key.ETAG_KEY);
|
||||
editor.apply();
|
||||
MagiskManager.get().loadConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user