Change new magisk database

This commit is contained in:
topjohnwu
2017-12-12 02:35:00 +08:00
parent aa75c8e5e4
commit fd6cbb138c
14 changed files with 157 additions and 186 deletions
@@ -1,6 +1,7 @@
package com.topjohnwu.magisk.utils;
import android.os.Environment;
import android.os.Process;
import java.io.File;
import java.util.Arrays;
@@ -63,6 +64,8 @@ public class Const {
"com.nianticlabs.pokemongo"
);
public static final int USER_ID = Process.myUid() / 100000;
public static class ID {
public static final int UPDATE_SERVICE_ID = 1;
public static final int FETCH_ZIP = 2;
@@ -7,6 +7,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.app.AlertDialog;
@@ -16,14 +17,13 @@ import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.SplashActivity;
import com.topjohnwu.magisk.asyncs.RestoreStockBoot;
import com.topjohnwu.magisk.asyncs.RestoreImages;
import com.topjohnwu.magisk.components.AlertDialogBuilder;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.receivers.ManagerUpdate;
import com.topjohnwu.magisk.receivers.RebootReceiver;
import java.io.File;
import java.io.FileOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -258,42 +258,35 @@ public class ShowUI {
.setTitle(R.string.uninstall_magisk_title)
.setMessage(R.string.uninstall_magisk_msg)
.setPositiveButton(R.string.complete_uninstall, (d, i) -> {
try {
InputStream in = mm.getAssets().open(Const.UNINSTALLER);
File uninstaller = new File(mm.getCacheDir(), Const.UNINSTALLER);
FileOutputStream out = new FileOutputStream(uninstaller);
byte[] bytes = new byte[1024];
int read;
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
in.close();
out.close();
in = mm.getAssets().open(Const.UTIL_FUNCTIONS);
File utils = new File(mm.getCacheDir(), Const.UTIL_FUNCTIONS);
out = new FileOutputStream(utils);
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
in.close();
out.close();
Shell.su(
"cat " + uninstaller + " > /cache/" + Const.UNINSTALLER,
"cat " + utils + " > /data/magisk/" + Const.UTIL_FUNCTIONS
);
MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
Shell.su_raw(
"sleep 5",
"pm uninstall " + mm.getApplicationInfo().packageName
);
ByteArrayOutputStream uninstaller = new ByteArrayOutputStream();
try (InputStream in = mm.getAssets().open(Const.UNINSTALLER)) {
Utils.inToOut(in, uninstaller);
} catch (IOException e) {
e.printStackTrace();
return;
}
ByteArrayOutputStream utils = new ByteArrayOutputStream();
try (InputStream in = mm.getAssets().open(Const.UTIL_FUNCTIONS)) {
Utils.inToOut(in, utils);
} catch (IOException e) {
e.printStackTrace();
return;
}
Shell.su(
Utils.fmt("echo '%s' > /cache/%s", uninstaller.toString().replace("'", "'\\''"), Const.UNINSTALLER),
Utils.fmt("echo '%s' > /data/magisk/%s", utils.toString().replace("'", "'\\''"), Const.UTIL_FUNCTIONS)
);
try {
uninstaller.close();
utils.close();
} catch (IOException ignored) {}
MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
new Handler().postDelayed(() -> Utils.uninstallPkg(mm.getPackageName()), 5000);
})
.setNeutralButton(R.string.restore_stock_boot, (d, i) -> {
new RestoreStockBoot().exec();
})
.setNegativeButton(R.string.no_thanks, null)
.setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages().exec())
.setNegativeButton(R.string.uninstall_app, (d, i) -> Utils.uninstallPkg(mm.getPackageName()))
.show();
}
}
@@ -45,24 +45,32 @@ public class Utils {
public static boolean isDownloading = false;
public static boolean itemExist(String path) {
public static boolean itemExist(Object path) {
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('/'));
Shell.su_raw(fmt("mkdir -p %s 2>/dev/null; touch %s 2>/dev/null", folder, path));
public static void createFile(Object path) {
Shell.su_raw(fmt("mkdir -p `dirname '%s'` 2>/dev/null; touch '%s' 2>/dev/null", path, path));
}
public static void removeItem(String path) {
public static void removeItem(Object path) {
Shell.su_raw(fmt("rm -rf %s 2>/dev/null", path));
}
public static List<String> readFile(String path) {
public static List<String> readFile(Object path) {
return Shell.su(fmt("cat %s | sed '$a\\ ' | sed '$d'", path));
}
public static String checkMD5(Object path) {
List<String> ret = Shell.su(fmt("md5sum %s", path));
return isValidShellResponse(ret) ? ret.get(0).split("\\s+")[0] : null;
}
public static void uninstallPkg(String pkg) {
Shell.su_raw(fmt("find /data/user*/*/%s -exec umount -l {} 2>/dev/null \\;; pm uninstall %s", pkg, pkg));
}
public static void dlAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
if (isDownloading)
return;
@@ -209,6 +217,10 @@ public class Utils {
}
}
public static File getDatabasePath(String dbName) {
return getDatabasePath(MagiskManager.get(), dbName);
}
public static File getDatabasePath(Context context, String dbName) {
return new File(context.getFilesDir().getParent() + "/databases", dbName);
}
@@ -258,7 +270,7 @@ public class Utils {
}
public static void loadPrefs() {
String config = fmt("/data/user/%d/%s", MagiskManager.get().userId, Const.MANAGER_CONFIGS);
String config = fmt("/data/user/%d/%s", Const.USER_ID, Const.MANAGER_CONFIGS);
List<String> ret = readFile(config);
if (isValidShellResponse(ret)) {
removeItem(config);