Loading core/java/android/accounts/AccountManager.java +82 −7 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.UserHandleAware; import android.app.Activity; import android.app.PropertyInvalidatedCache; import android.compat.annotation.UnsupportedAppUsage; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading Loading @@ -67,6 +68,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.Objects; /** * This class provides access to a centralized registry of the user's Loading Loading @@ -334,6 +336,68 @@ public class AccountManager { public static final String ACCOUNT_ACCESS_TOKEN_TYPE = "com.android.AccountManager.ACCOUNT_ACCESS_TOKEN_TYPE"; /** * @hide */ public static final String CACHE_KEY_USER_DATA_PROPERTY = "cache_key.system_server.account_user_data"; /** * @hide */ public static final int CACHE_USER_DATA_SIZE = 4; private static final class AccountKeyData { final public Account account; final public String key; public AccountKeyData(Account Account, String Key) { this.account = Account; this.key = Key; } @Override public boolean equals(Object o) { if (o == null) { return false; } if (o == this) { return true; } if (o.getClass() != getClass()) { return false; } AccountKeyData e = (AccountKeyData) o; return e.account.equals(account) && e.key.equals(key); } @Override public int hashCode() { return Objects.hash(account,key); } } PropertyInvalidatedCache<AccountKeyData, String> mUserDataCache = new PropertyInvalidatedCache<AccountKeyData, String>(CACHE_USER_DATA_SIZE, CACHE_KEY_USER_DATA_PROPERTY) { @Override protected String recompute(AccountKeyData accountKeyData) { Account account = accountKeyData.account; String key = accountKeyData.key; if (account == null) throw new IllegalArgumentException("account is null"); if (key == null) throw new IllegalArgumentException("key is null"); try { return mService.getUserData(account, key); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } }; @UnsupportedAppUsage private final Context mContext; private final IAccountManager mService; Loading Loading @@ -510,13 +574,7 @@ public class AccountManager { * @return The user data, null if the account, key doesn't exist, or the user is locked */ public String getUserData(final Account account, final String key) { if (account == null) throw new IllegalArgumentException("account is null"); if (key == null) throw new IllegalArgumentException("key is null"); try { return mService.getUserData(account, key); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } return mUserDataCache.query(new AccountKeyData(account,key)); } /** Loading Loading @@ -3333,4 +3391,21 @@ public class AccountManager { throw e.rethrowFromSystemServer(); } } /** * @hide * Calling this will invalidate Local Account User Data Cache which * forces the next query in any process to recompute the cache */ public static void invalidateLocalAccountUserDataCaches() { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_USER_DATA_PROPERTY); } /** * @hide * Calling this will disable user info caching. */ public void disableLocalUserInfoCaches() { mUserDataCache.disableLocal(); } } services/core/java/com/android/server/accounts/AccountManagerService.java +7 −0 Original line number Diff line number Diff line Loading @@ -1839,6 +1839,8 @@ public class AccountManagerService + account.toSafeString() + ", skipping since insertExtra failed for key " + key); return false; } else { AccountManager.invalidateLocalAccountUserDataCaches(); } } } Loading Loading @@ -2118,6 +2120,8 @@ public class AccountManagerService for (String packageName : accountRemovedReceivers) { sendAccountRemovedBroadcast(accountToRename, packageName, accounts.userId); } AccountManager.invalidateLocalAccountUserDataCaches(); } } return resultAccount; Loading Loading @@ -2385,6 +2389,8 @@ public class AccountManagerService } } AccountManager.invalidateLocalAccountUserDataCaches(); return isChanged; } Loading Loading @@ -2720,6 +2726,7 @@ public class AccountManagerService } synchronized (accounts.cacheLock) { writeUserDataIntoCacheLocked(accounts, account, key, value); AccountManager.invalidateLocalAccountUserDataCaches(); } } } Loading Loading
core/java/android/accounts/AccountManager.java +82 −7 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.annotation.SystemApi; import android.annotation.SystemService; import android.annotation.UserHandleAware; import android.app.Activity; import android.app.PropertyInvalidatedCache; import android.compat.annotation.UnsupportedAppUsage; import android.content.BroadcastReceiver; import android.content.ComponentName; Loading Loading @@ -67,6 +68,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.Objects; /** * This class provides access to a centralized registry of the user's Loading Loading @@ -334,6 +336,68 @@ public class AccountManager { public static final String ACCOUNT_ACCESS_TOKEN_TYPE = "com.android.AccountManager.ACCOUNT_ACCESS_TOKEN_TYPE"; /** * @hide */ public static final String CACHE_KEY_USER_DATA_PROPERTY = "cache_key.system_server.account_user_data"; /** * @hide */ public static final int CACHE_USER_DATA_SIZE = 4; private static final class AccountKeyData { final public Account account; final public String key; public AccountKeyData(Account Account, String Key) { this.account = Account; this.key = Key; } @Override public boolean equals(Object o) { if (o == null) { return false; } if (o == this) { return true; } if (o.getClass() != getClass()) { return false; } AccountKeyData e = (AccountKeyData) o; return e.account.equals(account) && e.key.equals(key); } @Override public int hashCode() { return Objects.hash(account,key); } } PropertyInvalidatedCache<AccountKeyData, String> mUserDataCache = new PropertyInvalidatedCache<AccountKeyData, String>(CACHE_USER_DATA_SIZE, CACHE_KEY_USER_DATA_PROPERTY) { @Override protected String recompute(AccountKeyData accountKeyData) { Account account = accountKeyData.account; String key = accountKeyData.key; if (account == null) throw new IllegalArgumentException("account is null"); if (key == null) throw new IllegalArgumentException("key is null"); try { return mService.getUserData(account, key); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } }; @UnsupportedAppUsage private final Context mContext; private final IAccountManager mService; Loading Loading @@ -510,13 +574,7 @@ public class AccountManager { * @return The user data, null if the account, key doesn't exist, or the user is locked */ public String getUserData(final Account account, final String key) { if (account == null) throw new IllegalArgumentException("account is null"); if (key == null) throw new IllegalArgumentException("key is null"); try { return mService.getUserData(account, key); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } return mUserDataCache.query(new AccountKeyData(account,key)); } /** Loading Loading @@ -3333,4 +3391,21 @@ public class AccountManager { throw e.rethrowFromSystemServer(); } } /** * @hide * Calling this will invalidate Local Account User Data Cache which * forces the next query in any process to recompute the cache */ public static void invalidateLocalAccountUserDataCaches() { PropertyInvalidatedCache.invalidateCache(CACHE_KEY_USER_DATA_PROPERTY); } /** * @hide * Calling this will disable user info caching. */ public void disableLocalUserInfoCaches() { mUserDataCache.disableLocal(); } }
services/core/java/com/android/server/accounts/AccountManagerService.java +7 −0 Original line number Diff line number Diff line Loading @@ -1839,6 +1839,8 @@ public class AccountManagerService + account.toSafeString() + ", skipping since insertExtra failed for key " + key); return false; } else { AccountManager.invalidateLocalAccountUserDataCaches(); } } } Loading Loading @@ -2118,6 +2120,8 @@ public class AccountManagerService for (String packageName : accountRemovedReceivers) { sendAccountRemovedBroadcast(accountToRename, packageName, accounts.userId); } AccountManager.invalidateLocalAccountUserDataCaches(); } } return resultAccount; Loading Loading @@ -2385,6 +2389,8 @@ public class AccountManagerService } } AccountManager.invalidateLocalAccountUserDataCaches(); return isChanged; } Loading Loading @@ -2720,6 +2726,7 @@ public class AccountManagerService } synchronized (accounts.cacheLock) { writeUserDataIntoCacheLocked(accounts, account, key, value); AccountManager.invalidateLocalAccountUserDataCaches(); } } } Loading