From 3e7d47a09dfe7e7be8598e55775e49f8b6c5a10b Mon Sep 17 00:00:00 2001 From: Collin Fijalkovich Date: Fri, 15 May 2020 17:01:45 -0700 Subject: [PATCH] Cache isUserUnlockingOrUnlocked Binder calls isUserUnlocked and isUserUnlockingOrUnlocked share the same service-side dependencies, so we can add a cache to the client-side of transaction and hook into the isUserUnlocked cache invalidation infrastructure. Bug: 140788621 Test: atest CtsMultiUserHostTestCases while validating cache operations. Change-Id: Icf11b1e777936ec9922ce4a47f8cfccbd22ad5ef --- core/java/android/os/UserManager.java | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 25bf430434224..199b4ab4c3d06 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -2210,6 +2210,20 @@ public class UserManager { } }; + // Uses IS_USER_UNLOCKED_PROPERTY for invalidation as the APIs have the same dependencies. + private final PropertyInvalidatedCache mIsUserUnlockingOrUnlockedCache = + new PropertyInvalidatedCache( + 32, CACHE_KEY_IS_USER_UNLOCKED_PROPERTY) { + @Override + protected Boolean recompute(Integer query) { + try { + return mService.isUserUnlockingOrUnlocked(query); + } catch (RemoteException re) { + throw re.rethrowFromSystemServer(); + } + } + }; + /** {@hide} */ @UnsupportedAppUsage @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, @@ -2221,6 +2235,7 @@ public class UserManager { /** {@hide} */ public void disableIsUserUnlockedCache() { mIsUserUnlockedCache.disableLocal(); + mIsUserUnlockingOrUnlockedCache.disableLocal(); } /** {@hide} */ @@ -2257,11 +2272,7 @@ public class UserManager { @RequiresPermission(anyOf = {Manifest.permission.MANAGE_USERS, Manifest.permission.INTERACT_ACROSS_USERS}, conditional = true) public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) { - try { - return mService.isUserUnlockingOrUnlocked(userId); - } catch (RemoteException re) { - throw re.rethrowFromSystemServer(); - } + return mIsUserUnlockingOrUnlockedCache.query(userId); } /**