Magisk/app-core/src/main/java/com/topjohnwu/magisk/utils/RootUtils.java

43 lines
1.5 KiB
Java
Raw Normal View History

2019-01-30 09:10:12 +01:00
package com.topjohnwu.magisk.utils;
2018-06-02 16:00:52 +02:00
2018-07-26 22:48:32 +02:00
import android.content.Context;
2019-01-30 09:10:12 +01:00
import com.topjohnwu.magisk.Config;
import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.core.R;
2018-06-02 16:00:52 +02:00
import com.topjohnwu.superuser.Shell;
import com.topjohnwu.superuser.ShellUtils;
2018-06-02 16:00:52 +02:00
import com.topjohnwu.superuser.io.SuFile;
2018-07-26 22:48:32 +02:00
import java.io.InputStream;
2018-09-10 08:27:45 +02:00
import androidx.annotation.NonNull;
2018-07-26 22:48:32 +02:00
public class RootUtils extends Shell.Initializer {
public static void rmAndLaunch(String rm, String launch) {
Shell.su(Utils.fmt("(rm_launch %d %s %s)&", Const.USER_ID, rm, launch)).exec();
}
2018-07-26 22:48:32 +02:00
@Override
public boolean onInit(Context context, @NonNull Shell shell) {
Shell.Job job = shell.newJob();
2018-07-26 22:48:32 +02:00
if (shell.isRoot()) {
job.add(context.getResources().openRawResource(R.raw.util_functions))
.add(context.getResources().openRawResource(R.raw.utils));
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk");
2019-01-21 21:49:03 +01:00
Config.loadMagiskInfo();
} else {
InputStream nonroot = context.getResources().openRawResource(R.raw.nonroot_utils);
job.add(nonroot);
2018-07-26 22:48:32 +02:00
}
job.add("mount_partitions", "get_flags", "run_migrations", "export BOOTMODE=true").exec();
2019-01-21 21:49:03 +01:00
Config.keepVerity = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPVERITY"));
Config.keepEnc = Boolean.parseBoolean(ShellUtils.fastCmd("echo $KEEPFORCEENCRYPT"));
Config.recovery = Boolean.parseBoolean(ShellUtils.fastCmd("echo $RECOVERYMODE"));
2018-07-26 22:48:32 +02:00
return true;
2018-06-02 16:00:52 +02:00
}
}