From 0469f0b5aef1419b97f67146e220fe6c8c402cfa Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Sat, 7 May 2022 16:59:58 +0800 Subject: [PATCH] Add uid check for getAppProcess --- .../java/com/topjohnwu/magisk/ktx/XAndroid.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt b/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt index 91cda056c..dec856343 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ktx/XAndroid.kt @@ -269,20 +269,27 @@ fun getProperty(key: String, def: String): String { fun PackageManager.getPackageInfo(uid: Int, pid: Int): PackageInfo? { val flag = PackageManager.MATCH_UNINSTALLED_PACKAGES val pkgs = getPackagesForUid(uid) ?: throw PackageManager.NameNotFoundException() - return if (pkgs.size > 1) { - if (pid <= 0) + if (pkgs.size > 1) { + if (pid <= 0) { return null + } // Try to find package name from PID val proc = RootUtils.obj?.getAppProcess(pid) - ?: return if (uid == Process.SHELL_UID) { + if (proc == null) { + if (uid == Process.SHELL_UID) { // It is possible that some apps installed are sharing UID with shell. // We will not be able to find a package from the active process list, // because the client is forked from ADB shell, not any app process. - getPackageInfo("com.android.shell", flag) - } else null - val pkg = proc.pkgList[0] - getPackageInfo(pkg, flag) - } else { - getPackageInfo(pkgs[0], flag) + return getPackageInfo("com.android.shell", flag) + } + } else if (uid == proc.uid) { + return getPackageInfo(proc.pkgList[0], flag) + } + + return null } + if (pkgs.size == 1) { + return getPackageInfo(pkgs[0], flag) + } + throw PackageManager.NameNotFoundException() }