Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19a569ab authored by Todd Kennedy's avatar Todd Kennedy
Browse files

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
parent 152cc76b
Loading
Loading
Loading
Loading
+15 −3
Original line number Original line Diff line number Diff line
@@ -5646,9 +5646,11 @@ public class PackageManagerService extends IPackageManager.Stub
    private int checkUidPermissionImpl(String permName, int uid) {
    private int checkUidPermissionImpl(String permName, int uid) {
        synchronized (mPackages) {
        synchronized (mPackages) {
            final String[] packageNames = getPackagesForUid(uid);
            final String[] packageNames = getPackagesForUid(uid);
            final PackageParser.Package pkg = (packageNames != null && packageNames.length > 0)
            PackageParser.Package pkg = null;
                    ? mPackages.get(packageNames[0])
            final int N = packageNames == null ? 0 : packageNames.length;
                    : null;
            for (int i = 0; pkg == null && i < N; i++) {
                pkg = mPackages.get(packageNames[i]);
            }
            // Additional logs for b/111075456; ignore system UIDs
            // Additional logs for b/111075456; ignore system UIDs
            if (pkg == null && UserHandle.getAppId(uid) >= Process.FIRST_APPLICATION_UID) {
            if (pkg == null && UserHandle.getAppId(uid) >= Process.FIRST_APPLICATION_UID) {
                if (packageNames == null || packageNames.length < 2) {
                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
    @Override
    public String[] getPackagesForUid(int uid) {
    public String[] getPackagesForUid(int uid) {
        return getPackagesForUid_debug(uid, false);
        return getPackagesForUid_debug(uid, false);