Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46e734ca authored by Pinyao Ting's avatar Pinyao Ting
Browse files

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
parent 0c8ed4ce
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -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.");
                }