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

Commit 5d5d5fdf authored by Jackal Guo's avatar Jackal Guo
Browse files

Add the checking of the package installed state

Unless the caller wants to query the UID or GID with certain flags
and proper permission, we should only return the result within the
current userId only.

Bug: 186180067
Test: atest -p core/java/android/content/pm \
        core/java/com/android/internal/content \
	services/core/java/com/android/server/pm \
	services/tests/servicestests/src/com/android/server/pm
Change-Id: I3d7c35dc2b57037f1f8c74fcaa432481a03f7636
parent c0a44448
Loading
Loading
Loading
Loading
+9 −10
Original line number Original line Diff line number Diff line
@@ -4212,12 +4212,12 @@ public class PackageManagerService extends IPackageManager.Stub
            // reader
            // reader
            final AndroidPackage p = mPackages.get(packageName);
            final AndroidPackage p = mPackages.get(packageName);
            if (p != null && AndroidPackageUtils.isMatchForSystemOnly(p, flags)) {
            if (p != null && AndroidPackageUtils.isMatchForSystemOnly(p, flags)) {
                PackageSetting ps = getPackageSettingInternal(p.getPackageName(), callingUid);
                final PackageSetting ps = getPackageSettingInternal(p.getPackageName(), callingUid);
                if (shouldFilterApplicationLocked(ps, callingUid, userId)) {
                if (ps != null && ps.getInstalled(userId)
                    return -1;
                        && !shouldFilterApplicationLocked(ps, callingUid, userId)) {
                }
                    return UserHandle.getUid(userId, p.getUid());
                    return UserHandle.getUid(userId, p.getUid());
                }
                }
            }
            if ((flags & MATCH_KNOWN_PACKAGES) != 0) {
            if ((flags & MATCH_KNOWN_PACKAGES) != 0) {
                final PackageSetting ps = mSettings.getPackageLPr(packageName);
                final PackageSetting ps = mSettings.getPackageLPr(packageName);
                if (ps != null && ps.isMatch(flags)
                if (ps != null && ps.isMatch(flags)
@@ -7968,14 +7968,12 @@ public class PackageManagerService extends IPackageManager.Stub
        synchronized (mLock) {
        synchronized (mLock) {
            final AndroidPackage p = mPackages.get(packageName);
            final AndroidPackage p = mPackages.get(packageName);
            if (p != null && AndroidPackageUtils.isMatchForSystemOnly(p, flags)) {
            if (p != null && AndroidPackageUtils.isMatchForSystemOnly(p, flags)) {
                PackageSetting ps = getPackageSetting(p.getPackageName());
                final PackageSetting ps = getPackageSetting(p.getPackageName());
                if (shouldFilterApplicationLocked(ps, callingUid, userId)) {
                if (ps != null && ps.getInstalled(userId)
                    return null;
                        && !shouldFilterApplicationLocked(ps, callingUid, userId)) {
                }
                // TODO: Shouldn't this be checking for package installed state for userId and
                // return null?
                    return mPermissionManager.getGidsForUid(UserHandle.getUid(userId, ps.appId));
                    return mPermissionManager.getGidsForUid(UserHandle.getUid(userId, ps.appId));
                }
                }
            }
            if ((flags & MATCH_KNOWN_PACKAGES) != 0) {
            if ((flags & MATCH_KNOWN_PACKAGES) != 0) {
                final PackageSetting ps = mSettings.getPackageLPr(packageName);
                final PackageSetting ps = mSettings.getPackageLPr(packageName);
                if (ps != null && ps.isMatch(flags)
                if (ps != null && ps.isMatch(flags)
@@ -11589,6 +11587,7 @@ public class PackageManagerService extends IPackageManager.Stub
            }
            }
        }
        }
        builder.append(" to access user ");
        builder.append(" to access user ");
        builder.append(userId);
        builder.append(".");
        builder.append(".");
        return builder.toString();
        return builder.toString();
    }
    }