Speed up startup time
This commit is contained in:
parent
23f697d62b
commit
4601989d4a
@ -113,13 +113,15 @@ public class FlashActivity extends Activity {
|
||||
case Const.Value.FLASH_ZIP:
|
||||
new FlashZip(this, uri, console, logs).exec();
|
||||
break;
|
||||
case Const.Value.PATCH_BOOT:
|
||||
new InstallMagisk(this, console, logs, uri, (Uri) intent.getParcelableExtra(Const.Key.FLASH_SET_BOOT))
|
||||
.exec();
|
||||
break;
|
||||
case Const.Value.FLASH_MAGISK:
|
||||
new InstallMagisk(this, console, logs, uri, intent.getStringExtra(Const.Key.FLASH_SET_BOOT))
|
||||
.exec();
|
||||
new InstallMagisk(this, console, logs, uri, InstallMagisk.DIRECT_MODE).exec();
|
||||
break;
|
||||
case Const.Value.FLASH_SECOND_SLOT:
|
||||
new InstallMagisk(this, console, logs, uri, InstallMagisk.SECOND_SLOT_MODE).exec();
|
||||
break;
|
||||
case Const.Value.PATCH_BOOT:
|
||||
new InstallMagisk(this, console, logs, uri,
|
||||
intent.getParcelableExtra(Const.Key.FLASH_SET_BOOT)).exec();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ public class MagiskManager extends Application implements Shell.Container {
|
||||
public String remoteManagerVersionString;
|
||||
public int remoteManagerVersionCode = -1;
|
||||
public String managerLink;
|
||||
public String bootBlock = null;
|
||||
public boolean keepVerity = false;
|
||||
public boolean keepEnc = false;
|
||||
|
||||
@ -193,8 +192,6 @@ public class MagiskManager extends Application implements Shell.Container {
|
||||
"resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP);
|
||||
magiskHide = s == null || Integer.parseInt(s) != 0;
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
bootBlock = ShellUtils.fastCmd("echo \"$BOOTIMAGE\"");
|
||||
}
|
||||
|
||||
public void getDefaultInstallFlags() {
|
||||
|
@ -60,8 +60,6 @@ public class SplashActivity extends Activity {
|
||||
mm.setupUpdateCheck();
|
||||
// Fire asynctasks
|
||||
loadModuleTask.exec();
|
||||
// Check dtbo status
|
||||
RootUtils.patchDTBO();
|
||||
}
|
||||
|
||||
// Write back default values
|
||||
|
@ -39,8 +39,9 @@ import java.util.List;
|
||||
public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
||||
|
||||
private static final int PATCH_MODE = 0;
|
||||
private static final int DIRECT_MODE = 1;
|
||||
public static final int DIRECT_MODE = 1;
|
||||
private static final int FIX_ENV_MODE = 2;
|
||||
public static final int SECOND_SLOT_MODE = 3;
|
||||
|
||||
private Uri bootUri, mZip;
|
||||
private List<String> console, logs;
|
||||
@ -57,22 +58,16 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
||||
mode = FIX_ENV_MODE;
|
||||
}
|
||||
|
||||
private InstallMagisk(Activity context, List<String> console, List<String> logs, Uri zip) {
|
||||
public InstallMagisk(Activity context, List<String> console, List<String> logs, Uri zip, int mode) {
|
||||
this(context, zip);
|
||||
this.console = console;
|
||||
this.logs = logs;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public InstallMagisk(FlashActivity context, List<String> console, List<String> logs, Uri zip, Uri boot) {
|
||||
this(context, console, logs, zip);
|
||||
this(context, console, logs, zip, PATCH_MODE);
|
||||
bootUri = boot;
|
||||
mode = PATCH_MODE;
|
||||
}
|
||||
|
||||
public InstallMagisk(FlashActivity context, List<String> console, List<String> logs, Uri zip, String boot) {
|
||||
this(context, console, logs, zip);
|
||||
mBoot = boot;
|
||||
mode = DIRECT_MODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -209,6 +204,7 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
||||
console.add(" " + dest + " ");
|
||||
console.add("*********************************");
|
||||
break;
|
||||
case SECOND_SLOT_MODE:
|
||||
case DIRECT_MODE:
|
||||
String binPath = mm.remoteMagiskVersionCode >= Const.MAGISK_VER.HIDDEN_PATH ?
|
||||
"/data/adb/magisk" : "/data/magisk";
|
||||
@ -237,11 +233,32 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
|
||||
installDir.mkdirs();
|
||||
}
|
||||
|
||||
if (mode == PATCH_MODE) {
|
||||
mBoot = new File(installDir, "boot.img").getAbsolutePath();
|
||||
if (!dumpBoot())
|
||||
return false;
|
||||
switch (mode) {
|
||||
case PATCH_MODE:
|
||||
mBoot = new File(installDir, "boot.img").getAbsolutePath();
|
||||
if (!dumpBoot())
|
||||
return false;
|
||||
break;
|
||||
case DIRECT_MODE:
|
||||
console.add("- Detecting ramdisk/boot image");
|
||||
mBoot = ShellUtils.fastCmd("find_boot_image", "echo \"$BOOTIMAGE\"");
|
||||
break;
|
||||
case SECOND_SLOT_MODE:
|
||||
console.add("- Detecting ramdisk/boot image");
|
||||
char slot[] = ShellUtils.fastCmd("echo $SLOT").toCharArray();
|
||||
if (slot[1] == 'a') slot[1] = 'b';
|
||||
else slot[1] = 'a';
|
||||
mBoot = ShellUtils.fastCmd("SLOT=" + String.valueOf(slot),
|
||||
"find_boot_image", "echo \"$BOOTIMAGE\"");
|
||||
Shell.Async.su("mount_partitions");
|
||||
break;
|
||||
}
|
||||
if (mBoot == null) {
|
||||
console.add("- Unable to detect ramdisk/boot image");
|
||||
return false;
|
||||
}
|
||||
|
||||
console.add("- Use ramdisk/boot image: " + mBoot);
|
||||
|
||||
List<String> abis = Arrays.asList(Build.SUPPORTED_ABIS);
|
||||
String arch;
|
||||
|
@ -9,7 +9,8 @@ import com.topjohnwu.magisk.services.OnBootIntentService;
|
||||
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
|
||||
private void startIntentService(Context context) {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(new Intent(context, OnBootIntentService.class));
|
||||
} else {
|
||||
@ -17,9 +18,4 @@ public class BootReceiver extends BroadcastReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
startIntentService(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.R;
|
||||
import com.topjohnwu.magisk.utils.Const;
|
||||
import com.topjohnwu.magisk.utils.RootUtils;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
import com.topjohnwu.superuser.Shell;
|
||||
|
||||
public class OnBootIntentService extends IntentService {
|
||||
|
||||
@ -22,12 +20,12 @@ public class OnBootIntentService extends IntentService {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(this, Const.ID.NOTIFICATION_CHANNEL);
|
||||
builder.setSmallIcon(R.drawable.ic_magisk_outline)
|
||||
.setContentTitle("onBoot")
|
||||
.setContentText("Running onBoot operations...");
|
||||
startForeground(Const.ID.ONBOOT_NOTIFICATION_ID, builder.build());
|
||||
startForeground(Const.ID.ONBOOT_NOTIFICATION_ID,
|
||||
new NotificationCompat.Builder(this, Const.ID.NOTIFICATION_CHANNEL)
|
||||
.setSmallIcon(R.drawable.ic_magisk_outline)
|
||||
.setContentTitle("onBoot")
|
||||
.setContentText("Running onBoot operations...")
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,11 +38,7 @@ public class OnBootIntentService extends IntentService {
|
||||
* Check for dtbo status every boot time, and prompt user
|
||||
* to reboot if dtbo wasn't patched and patched by Magisk Manager.
|
||||
* */
|
||||
MagiskManager mm = Utils.getMagiskManager(this);
|
||||
mm.loadMagiskInfo();
|
||||
mm.getDefaultInstallFlags();
|
||||
if (Shell.rootAccess()) {
|
||||
RootUtils.patchDTBO();
|
||||
}
|
||||
MagiskManager.get().loadMagiskInfo();
|
||||
RootUtils.patchDTBO();
|
||||
}
|
||||
}
|
||||
|
@ -8,16 +8,18 @@ import com.topjohnwu.superuser.io.SuFile;
|
||||
public class RootUtils {
|
||||
|
||||
public static void init() {
|
||||
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk");
|
||||
SuFile file = new SuFile("/sbin/.core/img");
|
||||
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");
|
||||
if (Shell.rootAccess()) {
|
||||
Const.MAGISK_DISABLE_FILE = new SuFile("/cache/.disable_magisk");
|
||||
SuFile file = new SuFile("/sbin/.core/img");
|
||||
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");
|
||||
}
|
||||
Const.MAGISK_HOST_FILE = new SuFile(Const.MAGISK_PATH + "/.core/hosts");
|
||||
}
|
||||
|
||||
public static void uninstallPkg(String pkg) {
|
||||
@ -25,10 +27,11 @@ public class RootUtils {
|
||||
}
|
||||
|
||||
public static void patchDTBO() {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
if (mm.magiskVersionCode >= Const.MAGISK_VER.DTBO_SUPPORT && !mm.keepVerity) {
|
||||
if (ShellUtils.fastCmdResult(Shell.getShell(), "patch_dtbo_image")) {
|
||||
ShowUI.dtboPatchedNotification();
|
||||
if (Shell.rootAccess()) {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
if (mm.magiskVersionCode >= Const.MAGISK_VER.DTBO_SUPPORT) {
|
||||
if (Boolean.parseBoolean(ShellUtils.fastCmd("mm_patch_dtbo")))
|
||||
ShowUI.dtboPatchedNotification();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,6 @@ public class ShellInitializer extends Shell.Initializer {
|
||||
}
|
||||
shell.run(null, null,
|
||||
"mount_partitions",
|
||||
"find_boot_image",
|
||||
"find_dtbo_image",
|
||||
"get_flags",
|
||||
"run_migrations");
|
||||
return true;
|
||||
|
@ -137,17 +137,15 @@ public class ShowUI {
|
||||
if (Shell.rootAccess()) {
|
||||
options.add(mm.getString(R.string.direct_install));
|
||||
}
|
||||
String s = ShellUtils.fastCmd("echo $SLOT");
|
||||
if (s != null) {
|
||||
String s = ShellUtils.fastCmd("grep_prop ro.build.ab_update");
|
||||
if (s != null && Boolean.parseBoolean(s)) {
|
||||
options.add(mm.getString(R.string.install_second_slot));
|
||||
}
|
||||
char[] slot = s == null ? null : s.toCharArray();
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(R.string.select_method)
|
||||
.setItems(
|
||||
options.toArray(new String [0]),
|
||||
(dialog, idx) -> {
|
||||
String boot;
|
||||
DownloadReceiver receiver = null;
|
||||
switch (idx) {
|
||||
case 1:
|
||||
@ -191,41 +189,23 @@ public class ShowUI {
|
||||
};
|
||||
break;
|
||||
case 2:
|
||||
boot = mm.bootBlock;
|
||||
if (boot == null)
|
||||
return;
|
||||
receiver = new DownloadReceiver() {
|
||||
@Override
|
||||
public void onDownloadDone(Context context, Uri uri) {
|
||||
Intent intent = new Intent(mm, FlashActivity.class);
|
||||
intent.setData(uri)
|
||||
.putExtra(Const.Key.FLASH_SET_BOOT, boot)
|
||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
|
||||
intent.setData(uri).putExtra(Const.Key.FLASH_ACTION,
|
||||
Const.Value.FLASH_MAGISK);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
};
|
||||
break;
|
||||
case 3:
|
||||
assert (slot != null);
|
||||
// Choose the other slot
|
||||
if (slot[1] == 'a') slot[1] = 'b';
|
||||
else slot[1] = 'a';
|
||||
// Then find the boot image again
|
||||
boot = ShellUtils.fastCmd(
|
||||
"SLOT=" + String.valueOf(slot),
|
||||
"find_boot_image",
|
||||
"echo \"$BOOTIMAGE\""
|
||||
);
|
||||
Shell.Async.su("mount_partitions");
|
||||
if (boot == null)
|
||||
return;
|
||||
receiver = new DownloadReceiver() {
|
||||
@Override
|
||||
public void onDownloadDone(Context context, Uri uri) {
|
||||
Intent intent = new Intent(mm, FlashActivity.class);
|
||||
intent.setData(uri)
|
||||
.putExtra(Const.Key.FLASH_SET_BOOT, boot)
|
||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_MAGISK);
|
||||
intent.setData(uri).putExtra(Const.Key.FLASH_ACTION,
|
||||
Const.Value.FLASH_SECOND_SLOT);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
@ -39,7 +39,16 @@ db_setup() {
|
||||
|
||||
env_check() {
|
||||
for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do
|
||||
[ -e /data/adb/magisk/$file ] || return 1
|
||||
[ -f /data/adb/magisk/$file ] || return 1
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
mm_patch_dtbo() {
|
||||
if $KEEPVERITY; then
|
||||
echo false
|
||||
else
|
||||
find_dtbo_image
|
||||
patch_dtbo_image >/dev/null 2>&1 && echo true || echo false
|
||||
fi
|
||||
}
|
||||
|
@ -153,6 +153,7 @@ public class Const {
|
||||
public static final String FLASH_ZIP = "flash";
|
||||
public static final String PATCH_BOOT = "patch";
|
||||
public static final String FLASH_MAGISK = "magisk";
|
||||
public static final String FLASH_SECOND_SLOT = "slot";
|
||||
public static final int[] timeoutList = {0, -1, 10, 20, 30, 60};
|
||||
public static final int ORDER_NAME = 0;
|
||||
public static final int ORDER_DATE = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user