Do not cache wildcard users (UserManager)

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: I68868b7f4142417d98b101504cb38c829b220e47
This commit is contained in:
Lee Shombert
2021-07-20 10:53:37 -07:00
parent 8d6900e011
commit f7067b2477
2 changed files with 16 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ import android.annotation.Size;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.UserHandleAware;
import android.annotation.UserIdInt;
import android.app.Activity;
import android.app.PropertyInvalidatedCache;
import android.compat.annotation.UnsupportedAppUsage;
@@ -349,6 +350,7 @@ public class AccountManager {
private static final class UserIdPackage
{
@UserIdInt
public int userId;
public String packageName;
@@ -379,7 +381,8 @@ public class AccountManager {
}
PropertyInvalidatedCache<UserIdPackage, Account[]> mAccountsForUserCache =
new PropertyInvalidatedCache<UserIdPackage, Account[]>(CACHE_ACCOUNTS_DATA_SIZE, CACHE_KEY_ACCOUNTS_DATA_PROPERTY) {
new PropertyInvalidatedCache<UserIdPackage, Account[]>(
CACHE_ACCOUNTS_DATA_SIZE, CACHE_KEY_ACCOUNTS_DATA_PROPERTY) {
@Override
protected Account[] recompute(UserIdPackage userAndPackage) {
try {
@@ -389,6 +392,10 @@ public class AccountManager {
}
}
@Override
protected boolean bypass(UserIdPackage query) {
return query.userId < 0;
}
@Override
protected boolean debugCompareQueryResults(Account[] l, Account[] r) {
if (l == r) {
return true;

View File

@@ -2491,6 +2491,10 @@ public class UserManager {
throw re.rethrowFromSystemServer();
}
}
@Override
protected boolean bypass(Integer query) {
return query < 0;
}
};
// Uses IS_USER_UNLOCKED_PROPERTY for invalidation as the APIs have the same dependencies.
@@ -2505,6 +2509,10 @@ public class UserManager {
throw re.rethrowFromSystemServer();
}
}
@Override
protected boolean bypass(Integer query) {
return query < 0;
}
};
/** {@hide} */