Fix issues of repackaging with multiuser

This commit is contained in:
topjohnwu 2017-12-08 23:38:03 +08:00
parent c461fc6daa
commit aa75c8e5e4
6 changed files with 20 additions and 23 deletions

View File

@ -116,8 +116,8 @@ public class MagiskManager extends Application {
} else {
String pkg = suDB.getStrings(Const.Key.SU_REQUESTER, null);
if (pkg != null) {
Shell.su_raw("pm uninstall " + pkg);
suDB.setStrings(Const.Key.SU_REQUESTER, null);
Shell.su_raw("pm uninstall " + pkg);
}
}

View File

@ -47,9 +47,7 @@ public class SplashActivity extends Activity {
}
mm.loadMagiskInfo();
if (Utils.itemExist(Const.MANAGER_CONFIGS)) {
Utils.loadPrefs();
}
Utils.loadPrefs();
LoadModules loadModuleTask = new LoadModules();

View File

@ -123,9 +123,7 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
// Install the application
List<String> ret = Shell.su(String.format(Locale.US,
"pm install --user %d %s >/dev/null && echo true || echo false",
mm.userId, repack));
List<String> ret = Shell.su(Utils.fmt("pm install %s >/dev/null && echo true || echo false", repack));
repack.delete();
if (!Utils.isValidShellResponse(ret) || !Boolean.parseBoolean(ret.get(0)))
return false;

View File

@ -188,8 +188,9 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
// Patch boot image
shell.run(console, logs,
"cd " + install,
"KEEPFORCEENCRYPT=" + mKeepEnc + " KEEPVERITY=" + mKeepVerity + " HIGHCOMP=" + highCompression +
" sh update-binary indep boot_patch.sh " + boot + " || echo 'Failed!'");
Utils.fmt("KEEPFORCEENCRYPT=%b KEEPVERITY=%b HIGHCOMP=%b " +
"sh update-binary indep boot_patch.sh %s || echo 'Failed!'",
mKeepEnc, mKeepVerity, highCompression, boot));
if (TextUtils.equals(console.get(console.size() - 1), "Failed!"))
return false;

View File

@ -25,7 +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 final String MANAGER_CONFIGS = ".tmp.magisk.config";
public static String BUSYBOX_PATH() {
if (Utils.itemExist("/sbin/.core/busybox/busybox")) {

View File

@ -46,25 +46,21 @@ public class Utils {
public static boolean isDownloading = false;
public static boolean itemExist(String path) {
String command = "[ -e " + path + " ] && echo true || echo false";
List<String> ret = Shell.su(command);
List<String> ret = Shell.su(fmt("[ -e %s ] && echo true || echo false", path));
return isValidShellResponse(ret) && Boolean.parseBoolean(ret.get(0));
}
public static void createFile(String path) {
String folder = path.substring(0, path.lastIndexOf('/'));
String command = "mkdir -p " + folder + " 2>/dev/null; touch " + path + " 2>/dev/null;";
Shell.su_raw(command);
Shell.su_raw(fmt("mkdir -p %s 2>/dev/null; touch %s 2>/dev/null", folder, path));
}
public static void removeItem(String path) {
String command = "rm -rf " + path + " 2>/dev/null";
Shell.su_raw(command);
Shell.su_raw(fmt("rm -rf %s 2>/dev/null", path));
}
public static List<String> readFile(String path) {
String command = "cat " + path + " | sed '$a\\ ' | sed '$d'";
return Shell.su(command);
return Shell.su(fmt("cat %s | sed '$a\\ ' | sed '$d'", path));
}
public static void dlAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
@ -256,16 +252,16 @@ public class Utils {
}
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);
String json = gson.toJson(MagiskManager.get().prefs.getAll(), new TypeToken<Map<String, ?>>(){}.getType());
Shell.su(fmt("for usr in /data/user/*; do echo '%s' > ${usr}/%s; done", json, Const.MANAGER_CONFIGS));
}
public static void loadPrefs() {
List<String> ret = Utils.readFile(Const.MANAGER_CONFIGS);
String config = fmt("/data/user/%d/%s", MagiskManager.get().userId, Const.MANAGER_CONFIGS);
List<String> ret = readFile(config);
if (isValidShellResponse(ret)) {
removeItem(Const.MANAGER_CONFIGS);
removeItem(config);
SharedPreferences.Editor editor = MagiskManager.get().prefs.edit();
String json = ret.get(0);
Gson gson = new Gson();
@ -286,4 +282,8 @@ public class Utils {
MagiskManager.get().loadConfig();
}
}
public static String fmt(String fmt, Object... args) {
return String.format(Locale.US, fmt, args);
}
}