Do not cache wildcard users (PackageManager)

Bug: 186778818

PropertyInvalidatedCache queries that contain wildcard user IDs are no
longer cached.  Some simple multi-user tests show that no current
caches use wildcard user IDs, so the change has no effect on
performance.  The bypass() mechanism is used to avoid the cache when
necessary.

Test: atest
 * FrameworksServicesTests:UserManagerServiceCreateProfileTest

Change-Id: I092d1385cc254b3f595ae3d0322f77dbaf456b65
This commit is contained in:
Lee Shombert
2021-07-20 10:52:51 -07:00
parent 83fbe443dd
commit 8d6900e011
2 changed files with 18 additions and 4 deletions

View File

@@ -1014,13 +1014,17 @@ public class ApplicationPackageManager extends PackageManager {
}
}
@Override
protected boolean bypass(Integer uid) {
return uid < 0;
}
@Override
public String queryToString(Integer uid) {
return String.format("uid=%d", uid.intValue());
}
};
@Override
public String[] getPackagesForUid(int uid) {
public String[] getPackagesForUid(@UserIdInt int uid) {
return mGetPackagesForUidCache.query(uid).value();
}
@@ -1035,7 +1039,7 @@ public class ApplicationPackageManager extends PackageManager {
}
@Override
public String getNameForUid(int uid) {
public String getNameForUid(@UserIdInt int uid) {
try {
return mPM.getNameForUid(uid);
} catch (RemoteException e) {

View File

@@ -9085,6 +9085,7 @@ public abstract class PackageManager {
private static final class ApplicationInfoQuery {
final String packageName;
final int flags;
@UserIdInt
final int userId;
ApplicationInfoQuery(@Nullable String packageName, int flags, int userId) {
@@ -9146,6 +9147,10 @@ public abstract class PackageManager {
query.packageName, query.flags, query.userId);
}
@Override
protected boolean bypass(ApplicationInfoQuery query) {
return query.userId < 0;
}
@Override
protected ApplicationInfo maybeCheckConsistency(
ApplicationInfoQuery query, ApplicationInfo proposedResult) {
// Implementing this debug check for ApplicationInfo would require a
@@ -9156,7 +9161,7 @@ public abstract class PackageManager {
/** @hide */
public static ApplicationInfo getApplicationInfoAsUserCached(
String packageName, int flags, int userId) {
String packageName, int flags, @UserIdInt int userId) {
return sApplicationInfoCache.query(
new ApplicationInfoQuery(packageName, flags, userId));
}
@@ -9188,6 +9193,7 @@ public abstract class PackageManager {
private static final class PackageInfoQuery {
final String packageName;
final int flags;
@UserIdInt
final int userId;
PackageInfoQuery(@Nullable String packageName, int flags, int userId) {
@@ -9248,6 +9254,10 @@ public abstract class PackageManager {
query.packageName, query.flags, query.userId);
}
@Override
protected boolean bypass(PackageInfoQuery query) {
return query.userId < 0;
}
@Override
protected PackageInfo maybeCheckConsistency(
PackageInfoQuery query, PackageInfo proposedResult) {
// Implementing this debug check for PackageInfo would require a
@@ -9258,7 +9268,7 @@ public abstract class PackageManager {
/** @hide */
public static PackageInfo getPackageInfoAsUserCached(
String packageName, int flags, int userId) {
String packageName, int flags, @UserIdInt int userId) {
return sPackageInfoCache.query(new PackageInfoQuery(packageName, flags, userId));
}