2018-06-02 22:00:52 +08:00
|
|
|
package com.topjohnwu.magisk.utils;
|
|
|
|
|
2018-07-27 04:48:32 +08:00
|
|
|
import android.content.Context;
|
|
|
|
|
2018-07-31 17:42:35 +08:00
|
|
|
import com.topjohnwu.magisk.Const;
|
2018-07-31 17:41:54 +08:00
|
|
|
import com.topjohnwu.magisk.Data;
|
2018-07-27 04:48:32 +08:00
|
|
|
import com.topjohnwu.magisk.R;
|
|
|
|
import com.topjohnwu.superuser.BusyBox;
|
2018-06-02 22:00:52 +08:00
|
|
|
import com.topjohnwu.superuser.Shell;
|
2018-07-31 03:51:11 +08:00
|
|
|
import com.topjohnwu.superuser.ShellUtils;
|
2018-06-02 22:00:52 +08:00
|
|
|
import com.topjohnwu.superuser.io.SuFile;
|
|
|
|
|
2018-07-27 04:48:32 +08:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
2018-09-10 02:27:45 -04:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2018-07-27 04:48:32 +08:00
|
|
|
public class RootUtils extends Shell.Initializer {
|
|
|
|
|
|
|
|
static {
|
|
|
|
BusyBox.BB_PATH = new File(Const.BUSYBOX_PATH);
|
2018-06-02 22:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void uninstallPkg(String pkg) {
|
2018-07-27 04:48:32 +08:00
|
|
|
Shell.su("db_clean " + Const.USER_ID, "pm uninstall " + pkg).exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInit(Context context, @NonNull Shell shell) {
|
2018-08-29 13:31:26 -04:00
|
|
|
Shell.Job job = shell.newJob();
|
2018-07-27 04:48:32 +08:00
|
|
|
if (shell.isRoot()) {
|
2018-11-15 01:36:03 -05:00
|
|
|
if (!new SuFile("/sbin/.magisk").exists())
|
|
|
|
job.add("ln -s /sbin/.core /sbin/.magisk");
|
|
|
|
|
2018-08-29 13:31:26 -04:00
|
|
|
InputStream magiskUtils = context.getResources().openRawResource(R.raw.util_functions);
|
|
|
|
InputStream managerUtils = context.getResources().openRawResource(R.raw.utils);
|
|
|
|
job.add(magiskUtils).add(managerUtils);
|
2018-07-31 03:51:11 +08:00
|
|
|
|
|
|
|
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk");
|
2018-11-15 01:36:03 -05:00
|
|
|
SuFile file = new SuFile("/sbin/.magisk/img");
|
2018-07-31 03:51:11 +08:00
|
|
|
if (file.exists()) {
|
|
|
|
Const.MAGISK_PATH = file;
|
|
|
|
} else if ((file = new SuFile("/dev/magisk/img")).exists()) {
|
|
|
|
Const.MAGISK_PATH = file;
|
|
|
|
} else {
|
|
|
|
Const.MAGISK_PATH = new SuFile("/magisk");
|
|
|
|
}
|
|
|
|
Const.MAGISK_HOST_FILE = new SuFile(Const.MAGISK_PATH + "/.core/hosts");
|
|
|
|
|
2018-07-31 17:41:54 +08:00
|
|
|
Data.loadMagiskInfo();
|
2018-08-29 13:31:26 -04:00
|
|
|
} else {
|
|
|
|
InputStream nonroot = context.getResources().openRawResource(R.raw.nonroot_utils);
|
|
|
|
job.add(nonroot);
|
2018-07-27 04:48:32 +08:00
|
|
|
}
|
2018-08-29 13:31:26 -04:00
|
|
|
|
2018-09-20 16:21:22 -04:00
|
|
|
job.add("mount_partitions", "get_flags", "run_migrations", "export BOOTMODE=true").exec();
|
2018-08-29 13:31:26 -04:00
|
|
|
|
|
|
|
Data.keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
|
|
|
|
Data.keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
|
2018-07-27 04:48:32 +08:00
|
|
|
return true;
|
2018-06-02 22:00:52 +08:00
|
|
|
}
|
|
|
|
}
|