Ensure packages in shared user are valid
Package information is tracked by several different structures and updated in different synchronized blocks. As such, the set of packages that are part of a shared user are updated after the set of installed packages is updated. And, in some cases, a removed package will still be listed as a member of a shared user id. Before passing a package to the PermissionManager to check for permission grants, ensure the package actually exists and is known to the system. Bug: 111075456 Test: Manual. Builds and runs. Change-Id: Ibb4f44f50141d43bf2367747d6d5813648d42fd4
This commit is contained in:
@@ -5646,9 +5646,11 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
private int checkUidPermissionImpl(String permName, int uid) {
|
||||
synchronized (mPackages) {
|
||||
final String[] packageNames = getPackagesForUid(uid);
|
||||
final PackageParser.Package pkg = (packageNames != null && packageNames.length > 0)
|
||||
? mPackages.get(packageNames[0])
|
||||
: null;
|
||||
PackageParser.Package pkg = null;
|
||||
final int N = packageNames == null ? 0 : packageNames.length;
|
||||
for (int i = 0; pkg == null && i < N; i++) {
|
||||
pkg = mPackages.get(packageNames[i]);
|
||||
}
|
||||
// Additional logs for b/111075456; ignore system UIDs
|
||||
if (pkg == null && UserHandle.getAppId(uid) >= Process.FIRST_APPLICATION_UID) {
|
||||
if (packageNames == null || packageNames.length < 2) {
|
||||
@@ -6385,6 +6387,16 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <em>IMPORTANT:</em> Not all packages returned by this method may be known
|
||||
* to the system. There are two conditions in which this may occur:
|
||||
* <ol>
|
||||
* <li>The package is on adoptable storage and the device has been removed</li>
|
||||
* <li>The package is being removed and the internal structures are partially updated</li>
|
||||
* </ol>
|
||||
* The second is an artifact of the current data structures and should be fixed. See
|
||||
* b/111075456 for one such instance.
|
||||
*/
|
||||
@Override
|
||||
public String[] getPackagesForUid(int uid) {
|
||||
return getPackagesForUid_debug(uid, false);
|
||||
|
||||
Reference in New Issue
Block a user