diff --git a/app/shared/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java b/app/shared/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java index 3efe27d9e..22a87e402 100644 --- a/app/shared/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java +++ b/app/shared/src/main/java/com/topjohnwu/magisk/utils/APKInstall.java @@ -21,6 +21,7 @@ public class APKInstall { if (Build.VERSION.SDK_INT >= 24) { intent.setData(FileProvider.getUriForFile(c, c.getPackageName() + ".provider", apk)); } else { + //noinspection ResultOfMethodCallIgnored SetWorldReadable apk.setReadable(true, false); intent.setData(Uri.fromFile(apk)); } @@ -31,15 +32,17 @@ public class APKInstall { c.startActivity(installIntent(c, apk)); } - public static void installAndWait(Activity c, File apk, BroadcastReceiver r) { + public static void registerInstallReceiver(Context c, BroadcastReceiver r) { IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_PACKAGE_REPLACED); filter.addAction(Intent.ACTION_PACKAGE_ADDED); filter.addDataScheme("package"); c.getApplicationContext().registerReceiver(r, filter); + } + public static void installHideResult(Activity c, File apk) { Intent intent = installIntent(c, apk); intent.putExtra(Intent.EXTRA_RETURN_RESULT, true); - c.startActivityForResult(intent, 0); + c.startActivityForResult(intent, 0); // Ignore result, use install receiver } } diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt index bccf2ec47..d72617ab8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt @@ -21,6 +21,7 @@ import com.topjohnwu.magisk.utils.APKInstall import com.topjohnwu.magisk.utils.Utils import com.topjohnwu.signing.JarMap import com.topjohnwu.signing.SignApk +import com.topjohnwu.superuser.Shell import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import timber.log.Timber @@ -141,7 +142,9 @@ object HideAPK { return false // Install and auto launch app - APKInstall.installAndWait(activity, repack, WaitPackageReceiver(pkg, activity)) + APKInstall.registerInstallReceiver(activity, WaitPackageReceiver(pkg, activity)) + if (!Shell.su("adb_pm_install $repack").exec().isSuccess) + APKInstall.installHideResult(activity, repack) return true } @@ -156,6 +159,8 @@ object HideAPK { fun restore(activity: Activity) { val apk = DynAPK.current(activity) - APKInstall.installAndWait(activity, apk, WaitPackageReceiver(APPLICATION_ID, activity)) + APKInstall.registerInstallReceiver(activity, WaitPackageReceiver(APPLICATION_ID, activity)) + if (!Shell.su("adb_pm_install $apk").exec().isSuccess) + APKInstall.installHideResult(activity, apk) } }