48 lines
1.7 KiB
Java
Raw Normal View History

2019-01-30 03:10:12 -05:00
package com.topjohnwu.magisk.utils;
2018-06-02 22:00:52 +08:00
2019-03-22 02:32:21 -04:00
import android.content.ComponentName;
2018-07-27 04:48:32 +08:00
import android.content.Context;
2019-03-07 03:41:24 -05:00
import androidx.annotation.NonNull;
2019-01-30 03:10:12 -05:00
import com.topjohnwu.magisk.Config;
import com.topjohnwu.magisk.Const;
2019-03-08 10:19:22 -05:00
import com.topjohnwu.magisk.R;
2018-06-02 22:00:52 +08:00
import com.topjohnwu.superuser.Shell;
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.InputStream;
public class RootUtils extends Shell.Initializer {
2019-03-22 02:32:21 -04:00
public static void rmAndLaunch(String rm, ComponentName component) {
Shell.su(Utils.fmt("(rm_launch %s %s)&", rm, component.flattenToString())).exec();
}
2019-04-08 15:46:44 -04:00
public static void reboot() {
Shell.su("/system/bin/reboot" + (Config.recovery ? " recovery" : "")).submit();
}
2018-07-27 04:48:32 +08:00
@Override
public boolean onInit(Context context, @NonNull Shell shell) {
Shell.Job job = shell.newJob();
2018-07-27 04:48:32 +08: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 15:49:03 -05:00
Config.loadMagiskInfo();
} else {
InputStream nonroot = context.getResources().openRawResource(R.raw.nonroot_utils);
job.add(nonroot);
2018-07-27 04:48:32 +08:00
}
job.add("mount_partitions", "get_flags", "run_migrations", "export BOOTMODE=true").exec();
2019-01-21 15:49:03 -05: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-27 04:48:32 +08:00
return true;
2018-06-02 22:00:52 +08:00
}
}