Fix HSUM su policy lookup and manager tracking

Normalize system and shared-UID (< 10000) processes to their app ID
when evaluating su policies and uid_granted_root so policies stored by
PolicyDao.normalizeUid match across non-zero users on HSUM devices.

- Normalize eval_uid in build_su_info and uid in uid_granted_root when
  app_id < AID_APP_START.
- Ensure SECURE_DIR exists before writing settings in boot_complete(),
  seed SuMultiuserMode on HSUM, and check isHeadlessSystemUser in
  Info.showSuperUser.
- Normalize UID comparisons in PackageManager.getPackageInfo(uid, pid).
- Simplify ManagerInfo to track a single TrackedFile instead of a
  per-user BTreeMap.
- Skip negative parse_int results in deny collect_users.

Assisted-by: Gemini 4 Argon
This commit is contained in:
topjohnwu
2026-10-22 14:06:48 -07:00
committed by John Wu
parent e31ef291d4
commit e8e8c3e3f1
7 changed files with 27 additions and 19 deletions
@@ -68,7 +68,7 @@ object Info {
val isConnected = MutableLiveData(false)
val showSuperUser: Boolean get() {
return env.isActive && (Const.USER_ID == 0
return env.isActive && (Const.USER_ID == 0 || isHeadlessSystemUser
|| Config.suMultiuserMode == Config.Value.MULTIUSER_MODE_USER)
}
@@ -108,13 +108,13 @@ fun PackageManager.getPackageInfo(uid: Int, pid: Int): PackageInfo? {
// Try to find package name from PID
val proc = RootUtils.getAppProcess(pid)
if (proc == null) {
if (uid == Process.SHELL_UID) {
if (PolicyDao.normalizeUid(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.
return getPackageInfo("com.android.shell", flag)
}
} else if (uid == proc.uid) {
} else if (PolicyDao.normalizeUid(uid) == PolicyDao.normalizeUid(proc.uid)) {
return getPackageInfo(proc.pkgList[0], flag)
}