From e603877a17f9189b00171474007849a4083f7628 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 9 May 2017 01:16:58 +0800 Subject: [PATCH] Install Magisk Manager APK with pm (Android O Compat.) --- jni/daemon/bootstages.c | 20 ++++++++++++++++++++ jni/magisk.h | 1 + 2 files changed, 21 insertions(+) diff --git a/jni/daemon/bootstages.c b/jni/daemon/bootstages.c index 586e4d10d..458ec0790 100644 --- a/jni/daemon/bootstages.c +++ b/jni/daemon/bootstages.c @@ -727,6 +727,26 @@ void late_start(int client) { LOGI("* Running module service scripts\n"); exec_module_script("service"); + // Install Magisk Manager if exists + if (access(MANAGERAPK, F_OK) == 0) { + while(1) { + sleep(5); + char *const command[] = { "sh", "-c", + "CLASSPATH=/system/framework/pm.jar " + "/system/bin/app_process /system/bin " + "com.android.commands.pm.Pm install -r " MANAGERAPK, NULL }; + int apk_res, pid; + pid = run_command(&apk_res, "/system/bin/sh", command); + waitpid(pid, NULL, 0); + fdgets(buf, PATH_MAX, apk_res); + close(apk_res); + // Keep trying until pm is started + if (strstr(buf, "Error:") == NULL) + break; + } + unlink(MANAGERAPK); + } + // All boot stage done, cleanup everything free(buf); free(buf2); diff --git a/jni/magisk.h b/jni/magisk.h index d62762544..2699737c9 100644 --- a/jni/magisk.h +++ b/jni/magisk.h @@ -34,6 +34,7 @@ #define HOSTSFILE COREDIR "/hosts" #define MAINIMG "/data/magisk.img" #define DATABIN "/data/magisk" +#define MANAGERAPK DATABIN "/magisk.apk" #define MAGISKTMP "/dev/magisk" #define MIRRDIR MAGISKTMP "/mirror" #define DUMMDIR MAGISKTMP "/dummy"