From a54114f149cafdcc6e3a23db22ec2df778b50882 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 23 Aug 2022 05:09:50 -0700 Subject: [PATCH] Pre-grant permissions if possible --- .../main/java/com/topjohnwu/magisk/core/tasks/HideAPK.kt | 4 ++-- app/src/main/res/raw/manager.sh | 7 ++++--- native/src/core/scripting.cpp | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) 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 c8b874c1e..42ad4600a 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 @@ -129,7 +129,7 @@ object HideAPK { launchApp(activity, pkg) } - val cmd = "adb_pm_install $repack ${activity.applicationInfo.uid}" + val cmd = "adb_pm_install $repack $pkg" if (Shell.cmd(cmd).exec().isSuccess) return true try { @@ -177,7 +177,7 @@ object HideAPK { launchApp(activity, APPLICATION_ID) dialog.dismiss() } - val cmd = "adb_pm_install $apk ${activity.applicationInfo.uid}" + val cmd = "adb_pm_install $apk $APPLICATION_ID" if (Shell.cmd(cmd).await().isSuccess) return val success = withContext(Dispatchers.IO) { try { diff --git a/app/src/main/res/raw/manager.sh b/app/src/main/res/raw/manager.sh index 65bccf94e..611d037fd 100644 --- a/app/src/main/res/raw/manager.sh +++ b/app/src/main/res/raw/manager.sh @@ -133,11 +133,12 @@ adb_pm_install() { local tmp=/data/local/tmp/temp.apk cp -f "$1" $tmp chmod 644 $tmp - su 2000 -c pm install $tmp || pm install $tmp || su 1000 -c pm install $tmp + su 2000 -c pm install -g $tmp || pm install -g $tmp || su 1000 -c pm install -g $tmp local res=$? rm -f $tmp - # Note: change this will kill self - [ $res != 0 ] && appops set "$2" REQUEST_INSTALL_PACKAGES allow + if [ $res = 0 ]; then + appops set "$2" REQUEST_INSTALL_PACKAGES allow + fi return $res } diff --git a/native/src/core/scripting.cpp b/native/src/core/scripting.cpp index 98df02128..6d8e656b5 100644 --- a/native/src/core/scripting.cpp +++ b/native/src/core/scripting.cpp @@ -154,6 +154,7 @@ constexpr char install_script[] = R"EOF( APK=%s log -t Magisk "pm_install: $APK" log -t Magisk "pm_install: $(pm install -g -r $APK 2>&1)" +appops set com.topjohnwu.magisk REQUEST_INSTALL_PACKAGES allow rm -f $APK )EOF";