From 46e734cae9b37ec3aa8f5294b3975bcea2a0e8d5 Mon Sep 17 00:00:00 2001 From: Pinyao Ting Date: Thu, 18 Mar 2021 14:51:54 -0700 Subject: [PATCH] Fix a timing issue in unlock signal propagation in AppSearch There is a tiny gap between user unlock and when the unlock event reaches AppSearch. The fact that unlock event haven't reach AppSearch isn't suffice to say user is not unlocked. This CL added the logic to check with UM when cache misses. Bug: 151359749 Test: manual Change-Id: I49f0754d53fc4d391245917bb35b726a305e4e30 --- .../server/appsearch/AppSearchManagerService.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java b/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java index 27c9ccb2cca62..7b8857e058120 100644 --- a/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java +++ b/apex/appsearch/service/java/com/android/server/appsearch/AppSearchManagerService.java @@ -37,6 +37,7 @@ import android.os.Bundle; import android.os.ParcelableException; import android.os.RemoteException; import android.os.UserHandle; +import android.os.UserManager; import android.util.ArrayMap; import android.util.ArraySet; import android.util.Log; @@ -58,6 +59,7 @@ public class AppSearchManagerService extends SystemService { private static final String TAG = "AppSearchManagerService"; private PackageManagerInternal mPackageManagerInternal; private ImplInstanceManager mImplInstanceManager; + private UserManager mUserManager; // Cache of unlocked user ids so we don't have to query UserManager service each time. The // "locked" suffix refers to the fact that access to the field should be locked; unrelated to @@ -74,10 +76,11 @@ public class AppSearchManagerService extends SystemService { publishBinderService(Context.APP_SEARCH_SERVICE, new Stub()); mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class); mImplInstanceManager = ImplInstanceManager.getInstance(getContext()); + mUserManager = getContext().getSystemService(UserManager.class); } @Override - public void onUserUnlocked(@NonNull TargetUser user) { + public void onUserUnlocking(@NonNull TargetUser user) { synchronized (mUnlockedUserIdsLocked) { mUnlockedUserIdsLocked.add(user.getUserIdentifier()); } @@ -509,7 +512,13 @@ public class AppSearchManagerService extends SystemService { private void verifyUserUnlocked(int callingUserId) { synchronized (mUnlockedUserIdsLocked) { - if (!mUnlockedUserIdsLocked.contains(callingUserId)) { + // First, check the local copy. + if (mUnlockedUserIdsLocked.contains(callingUserId)) { + return; + } + // If the local copy says the user is locked, check with UM for the actual state, + // since the user might just have been unlocked. + if (!mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(callingUserId))) { throw new IllegalStateException( "User " + callingUserId + " is locked or not running."); }