diff --git a/app/shared/src/main/AndroidManifest.xml b/app/shared/src/main/AndroidManifest.xml index a6180f73a..f8862c7f7 100644 --- a/app/shared/src/main/AndroidManifest.xml +++ b/app/shared/src/main/AndroidManifest.xml @@ -4,9 +4,6 @@ - - * Trigger process recreation by calling {@link #triggerRebirth} with a {@link Context} instance. - */ -public class ProcessPhoenix extends Activity { - private static final String KEY_RESTART_INTENT = "phoenix_restart_intent"; - - public static void triggerRebirth(Context context, Intent intent) { - intent.addFlags(FLAG_ACTIVITY_NEW_TASK); // In case we are called with non-Activity context. - intent.putExtra(KEY_RESTART_INTENT, getRestartIntent(context)); - context.startActivity(intent); - if (context instanceof Activity) { - ((Activity) context).finish(); - } - Runtime.getRuntime().exit(0); - } - - private static Intent getRestartIntent(Context context) { - String packageName = context.getPackageName(); - Intent defaultIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); - if (defaultIntent != null) { - defaultIntent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK); - return defaultIntent; - } - - throw new IllegalStateException(); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Intent intent = getIntent().getParcelableExtra(KEY_RESTART_INTENT); - startActivity(intent); - finish(); - Runtime.getRuntime().exit(0); - } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bd2209947..32e9dd0c5 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,6 +7,9 @@ + - - - ) { @@ -28,5 +27,3 @@ class h : GeneralReceiver() class j : DownloadService() class m : SuRequestActivity() - -class r : ProcessPhoenix() diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt index 044572a89..c1c9a16c8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/Hacks.kt @@ -16,7 +16,6 @@ import android.content.res.Configuration import android.content.res.Resources import androidx.annotation.RequiresApi import com.topjohnwu.magisk.DynAPK -import com.topjohnwu.magisk.ProcessPhoenix import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.download.DownloadService import com.topjohnwu.magisk.core.utils.refreshLocale @@ -152,8 +151,7 @@ private object ClassMap { SplashActivity::class.java to a.c::class.java, GeneralReceiver::class.java to a.h::class.java, DownloadService::class.java to a.j::class.java, - SuRequestActivity::class.java to a.m::class.java, - ProcessPhoenix::class.java to a.r::class.java + SuRequestActivity::class.java to a.m::class.java ) operator fun get(c: Class<*>) = map.getOrElse(c) { c } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt b/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt index 5f96aaaab..ff648659b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/download/ManagerUpgrade.kt @@ -3,15 +3,14 @@ package com.topjohnwu.magisk.core.download import androidx.core.net.toFile import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.DynAPK -import com.topjohnwu.magisk.ProcessPhoenix import com.topjohnwu.magisk.R import com.topjohnwu.magisk.core.Config import com.topjohnwu.magisk.core.Info import com.topjohnwu.magisk.core.download.Action.APK.Restore import com.topjohnwu.magisk.core.download.Action.APK.Upgrade -import com.topjohnwu.magisk.core.intent import com.topjohnwu.magisk.core.isRunningAsStub import com.topjohnwu.magisk.core.utils.PatchAPK +import com.topjohnwu.magisk.ktx.relaunchApp import com.topjohnwu.magisk.ktx.writeTo import com.topjohnwu.magisk.utils.APKInstall import com.topjohnwu.superuser.Shell @@ -46,7 +45,7 @@ private suspend fun DownloadService.upgrade(apk: File, id: Int) { patch(apk, id) } else { // Simply relaunch the app - ProcessPhoenix.triggerRebirth(this, intent()) + relaunchApp(this) } } else { patch(apk, id) diff --git a/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt b/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt index d13efc0f6..a500d7cb7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ktx/XSU.kt @@ -1,5 +1,7 @@ package com.topjohnwu.magisk.ktx +import android.content.Context +import com.topjohnwu.magisk.core.Const import com.topjohnwu.magisk.core.Info import com.topjohnwu.superuser.Shell import kotlinx.coroutines.Dispatchers @@ -9,4 +11,12 @@ fun reboot(reason: String = if (Info.recovery) "recovery" else "") { Shell.su("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit() } +fun relaunchApp(context: Context) { + val intent = context.packageManager.getLaunchIntentForPackage(context.packageName) ?: return + val args = mutableListOf("am", "start", "--user", Const.USER_ID.toString()) + val cmd = intent.toCommand(args).joinToString(separator = " ") + Shell.su("run_delay 1 \"$cmd\"").exec() + Runtime.getRuntime().exit(0) +} + suspend fun Shell.Job.await() = withContext(Dispatchers.IO) { exec() } diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index a8502b872..72781517e 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -2,6 +2,10 @@ # Magisk Manager internal scripts ################################## +run_delay() { + (sleep $1; $2)& +} + env_check() { for file in busybox magisk magiskboot magiskinit util_functions.sh boot_patch.sh; do [ -f $MAGISKBIN/$file ] || return 1 diff --git a/stub/src/main/AndroidManifest.xml b/stub/src/main/AndroidManifest.xml index f83aeb971..0c433ab3b 100644 --- a/stub/src/main/AndroidManifest.xml +++ b/stub/src/main/AndroidManifest.xml @@ -10,19 +10,13 @@ android:allowBackup="true" tools:ignore="AllowBackup"> - + - -