Add uid check for getAppProcess

This commit is contained in:
vvb2060 2022-05-07 16:59:58 +08:00 committed by John Wu
parent 0b8577d02b
commit 0469f0b5ae

View File

@ -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()
}