Enfore cross user permission to getPackagesForUid

Apps could use getPackagesForUid with given UID to query if there
is a installed and get its package name across user. Expect for
package visibility filtering, we also need to ensure across-user
calls come with appropriate permission.

Bug: 167654926
Test: atest ApplicationVisibilityTest
Change-Id: I1172177298cd084430c612f50e4b921b92d4a1c3
This commit is contained in:
Jackal Guo
2021-01-28 16:57:35 +08:00
parent 77bb0b7291
commit 1dafc3859a

View File

@@ -3845,6 +3845,8 @@ public class PackageManagerService extends IPackageManager.Stub
final boolean isCallerInstantApp = getInstantAppPackageName(callingUid) != null; final boolean isCallerInstantApp = getInstantAppPackageName(callingUid) != null;
final int userId = UserHandle.getUserId(uid); final int userId = UserHandle.getUserId(uid);
final int appId = UserHandle.getAppId(uid); final int appId = UserHandle.getAppId(uid);
enforceCrossUserPermission(callingUid, userId,
/* requireFullPermission */ false, /* checkShell */ false, "getPackagesForUid");
return getPackagesForUidInternalBody(callingUid, userId, appId, isCallerInstantApp); return getPackagesForUidInternalBody(callingUid, userId, appId, isCallerInstantApp);
} }