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

Commit 14d4959c authored by Andreas Miko's avatar Andreas Miko
Browse files

Refactor KeyguardUpdateMonitor internal references

Dependency cycles are resolved in parent commits, KeyguardUpdateMonitor
can now reference repository.

Test: None
Bug: b/303808405
Flag: b/305984787 - REFACTOR_GETCURRENTUSER (added in ag/25089323)
Change-Id: I35bcf3f4383b887d6c314dc6909d00790754f163
parent a1de09eb
Loading
Loading
Loading
Loading
+53 −45
Original line number Diff line number Diff line
@@ -186,8 +186,8 @@ import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.policy.DevicePostureController;
import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt;
import com.android.systemui.telephony.TelephonyListenerManager;
import com.android.systemui.user.domain.interactor.SelectedUserInteractor;
import com.android.systemui.util.Assert;
import com.android.systemui.util.settings.SecureSettings;

import dalvik.annotation.optimization.NeverCompile;

@@ -410,7 +410,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private final DevicePolicyManager mDevicePolicyManager;
    private final DevicePostureController mPostureController;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final SecureSettings mSecureSettings;
    private final InteractionJankMonitor mInteractionJankMonitor;
    private final LatencyTracker mLatencyTracker;
    private final StatusBarStateController mStatusBarStateController;
@@ -429,6 +428,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private final IActivityTaskManager mActivityTaskManager;
    private final WakefulnessLifecycle mWakefulness;
    private final DisplayTracker mDisplayTracker;
    private final SelectedUserInteractor mSelectedUserInteractor;
    private final LockPatternUtils mLockPatternUtils;
    @VisibleForTesting
    @DevicePostureInt
@@ -543,7 +543,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

    /**
     * @deprecated This can potentially return unexpected values in a multi user scenario
     * as this state is managed by another component. Consider using {@link UserTracker}.
     * as this state is managed by another component. Consider using {@link SelectedUserInteractor}.
     */
    @Deprecated
    public synchronized static int getCurrentUser() {
@@ -577,7 +577,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

        if (enabled) {
            String message = null;
            if (KeyguardUpdateMonitor.getCurrentUser() == userId
            if (mSelectedUserInteractor.getSelectedUserId() == userId
                    && trustGrantedMessages != null) {
                // Show the first non-empty string provided by a trust agent OR intentionally pass
                // an empty string through (to prevent the default trust agent string from showing)
@@ -590,7 +590,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            }

            mLogger.logTrustGrantedWithFlags(flags, newlyUnlocked, userId, message);
            if (userId == getCurrentUser()) {
            if (userId == mSelectedUserInteractor.getSelectedUserId()) {
                if (newlyUnlocked) {
                    // if this callback is ever removed, this should then be logged in
                    // TrustRepository
@@ -1038,7 +1038,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            mHandler.removeCallbacks(mFpCancelNotReceived);
        }
        try {
            final int userId = mUserTracker.getUserId();
            final int userId = mSelectedUserInteractor.getSelectedUserId();
            if (userId != authUserId) {
                mLogger.logFingerprintAuthForWrongUser(authUserId);
                return;
@@ -1127,8 +1127,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            lockedOutStateChanged = !mFingerprintLockedOutPermanent;
            mFingerprintLockedOutPermanent = true;
            mLogger.d("Fingerprint permanently locked out - requiring stronger auth");
            mLockPatternUtils.requireStrongAuth(
                    STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, getCurrentUser());
            mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_LOCKOUT,
                    mSelectedUserInteractor.getSelectedUserId());
        }

        if (msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT
@@ -1309,7 +1309,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                mLogger.d("Aborted successful auth because device is going to sleep.");
                return;
            }
            final int userId = mUserTracker.getUserId();
            final int userId = mSelectedUserInteractor.getSelectedUserId();
            if (userId != authUserId) {
                mLogger.logFaceAuthForWrongUser(authUserId);
                return;
@@ -1565,7 +1565,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    @Deprecated
    public boolean getIsFaceAuthenticated() {
        boolean faceAuthenticated = false;
        BiometricAuthenticated bioFaceAuthenticated = mUserFaceAuthenticated.get(getCurrentUser());
        BiometricAuthenticated bioFaceAuthenticated =
                mUserFaceAuthenticated.get(mSelectedUserInteractor.getSelectedUserId());
        if (bioFaceAuthenticated != null) {
            faceAuthenticated = bioFaceAuthenticated.mAuthenticated;
        }
@@ -1754,9 +1755,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                cb.onStrongAuthStateChanged(userId);
            }
        }
        if (userId == getCurrentUser()) {
        if (userId == mSelectedUserInteractor.getSelectedUserId()) {
            FACE_AUTH_UPDATED_STRONG_AUTH_CHANGED.setExtraInfo(
                    mStrongAuthTracker.getStrongAuthForUser(getCurrentUser()));
                    mStrongAuthTracker.getStrongAuthForUser(
                            mSelectedUserInteractor.getSelectedUserId()));

            // Strong auth is only reset when primary auth is used to enter the device,
            // so we only check whether to stop biometric listening states here
@@ -1783,10 +1785,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                cb.onNonStrongBiometricAllowedChanged(userId);
            }
        }
        if (userId == getCurrentUser()) {
        if (userId == mSelectedUserInteractor.getSelectedUserId()) {
            FACE_AUTH_NON_STRONG_BIOMETRIC_ALLOWED_CHANGED.setExtraInfo(
                    mStrongAuthTracker.isNonStrongBiometricAllowedAfterIdleTimeout(
                            getCurrentUser()) ? -1 : 1);
                            mSelectedUserInteractor.getSelectedUserId()) ? -1 : 1);

            // This is only reset when primary auth is used to enter the device, so we only check
            // whether to stop biometric listening states here
@@ -2191,12 +2193,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }

        public boolean isUnlockingWithBiometricAllowed(boolean isStrongBiometric) {
            int userId = getCurrentUser();
            int userId = mSelectedUserInteractor.getSelectedUserId();
            return isBiometricAllowedForUser(isStrongBiometric, userId);
        }

        public boolean hasUserAuthenticatedSinceBoot() {
            int userId = getCurrentUser();
            int userId = mSelectedUserInteractor.getSelectedUserId();
            return (getStrongAuthForUser(userId)
                    & STRONG_AUTH_REQUIRED_AFTER_BOOT) == 0;
        }
@@ -2344,7 +2346,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            UserTracker userTracker,
            @Main Looper mainLooper,
            BroadcastDispatcher broadcastDispatcher,
            SecureSettings secureSettings,
            DumpManager dumpManager,
            @Background Executor backgroundExecutor,
            @Main Executor mainExecutor,
@@ -2376,7 +2377,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            TaskStackChangeListeners taskStackChangeListeners,
            IActivityTaskManager activityTaskManagerService,
            DisplayTracker displayTracker,
            WakefulnessLifecycle wakefulness) {
            WakefulnessLifecycle wakefulness,
            SelectedUserInteractor selectedUserInteractor) {
        mContext = context;
        mSubscriptionManager = subscriptionManager;
        mUserTracker = userTracker;
@@ -2392,7 +2394,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        mStatusBarState = mStatusBarStateController.getState();
        mLockPatternUtils = lockPatternUtils;
        mAuthController = authController;
        mSecureSettings = secureSettings;
        dumpManager.registerDumpable(this);
        mSensorPrivacyManager = sensorPrivacyManager;
        mActiveUnlockConfig = activeUnlockConfiguration;
@@ -2426,6 +2427,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        mWakefulness = wakefulness;
        mDisplayTracker = displayTracker;
        mDisplayTracker.addDisplayChangeCallback(mDisplayCallback, mainExecutor);
        mSelectedUserInteractor = selectedUserInteractor;

        mHandler = new Handler(mainLooper) {
            @Override
@@ -2648,7 +2650,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

        mTaskStackChangeListeners.registerTaskStackListener(mTaskStackListener);
        mIsSystemUser = mUserManager.isSystemUser();
        int user = mUserTracker.getUserId();
        int user = mSelectedUserInteractor.getSelectedUserId();
        mUserIsUnlocked.put(user, mUserManager.isUserUnlocked(user));
        mLogoutEnabled = mDevicePolicyManager.isLogoutEnabled();
        updateSecondaryLockscreenRequirement(user);
@@ -2720,7 +2722,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
     * @return true if there's at least one udfps enrolled for the current user.
     */
    public boolean isUdfpsEnrolled() {
        return mAuthController.isUdfpsEnrolled(getCurrentUser());
        return mAuthController.isUdfpsEnrolled(mSelectedUserInteractor.getSelectedUserId());
    }

    /**
@@ -2735,7 +2737,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
     * @return true if there's at least one sfps enrollment for the current user.
     */
    public boolean isSfpsEnrolled() {
        return mAuthController.isSfpsEnrolled(getCurrentUser());
        return mAuthController.isSfpsEnrolled(mSelectedUserInteractor.getSelectedUserId());
    }

    /**
@@ -2906,7 +2908,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

        if (shouldTriggerActiveUnlock()) {
            mLogger.logActiveUnlockTriggered(reason);
            mTrustManager.reportUserMayRequestUnlock(KeyguardUpdateMonitor.getCurrentUser());
            mTrustManager.reportUserMayRequestUnlock(mSelectedUserInteractor.getSelectedUserId());
        }
    }

@@ -2960,7 +2962,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

        if (allowRequest && shouldTriggerActiveUnlock()) {
            mLogger.logUserRequestedUnlock(requestOrigin, reason, dismissKeyguard);
            mTrustManager.reportUserRequestedUnlock(KeyguardUpdateMonitor.getCurrentUser(),
            mTrustManager.reportUserRequestedUnlock(mSelectedUserInteractor.getSelectedUserId(),
                    dismissKeyguard);
        }
    }
@@ -3031,7 +3033,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                && mStatusBarState != StatusBarState.SHADE_LOCKED);

        // Gates:
        final int user = getCurrentUser();
        final int user = mSelectedUserInteractor.getSelectedUserId();

        // No need to trigger active unlock if we're already unlocked or don't have
        // pin/pattern/password setup
@@ -3073,30 +3075,33 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    }

    private boolean shouldListenForFingerprintAssistant() {
        BiometricAuthenticated fingerprint = mUserFingerprintAuthenticated.get(getCurrentUser());
        BiometricAuthenticated fingerprint = mUserFingerprintAuthenticated.get(
                mSelectedUserInteractor.getSelectedUserId());
        return mAssistantVisible && mKeyguardOccluded
                && !(fingerprint != null && fingerprint.mAuthenticated)
                && !mUserHasTrust.get(getCurrentUser(), false);
                && !mUserHasTrust.get(
                        mSelectedUserInteractor.getSelectedUserId(), false);
    }

    private boolean shouldListenForFaceAssistant() {
        BiometricAuthenticated face = mUserFaceAuthenticated.get(getCurrentUser());
        BiometricAuthenticated face = mUserFaceAuthenticated.get(
                mSelectedUserInteractor.getSelectedUserId());
        return mAssistantVisible
                // There can be intermediate states where mKeyguardShowing is false but
                // mKeyguardOccluded is true, we don't want to run face auth in such a scenario.
                && (mKeyguardShowing && mKeyguardOccluded)
                && !(face != null && face.mAuthenticated)
                && !mUserHasTrust.get(getCurrentUser(), false);
                && !mUserHasTrust.get(mSelectedUserInteractor.getSelectedUserId(), false);
    }

    private boolean shouldTriggerActiveUnlockForAssistant() {
        return mAssistantVisible && mKeyguardOccluded
                && !mUserHasTrust.get(getCurrentUser(), false);
                && !mUserHasTrust.get(mSelectedUserInteractor.getSelectedUserId(), false);
    }

    @VisibleForTesting
    protected boolean shouldListenForFingerprint(boolean isUdfps) {
        final int user = getCurrentUser();
        final int user = mSelectedUserInteractor.getSelectedUserId();
        final boolean userDoesNotHaveTrust = !getUserHasTrust(user);
        final boolean shouldListenForFingerprintAssistant = shouldListenForFingerprintAssistant();
        final boolean shouldListenKeyguardState =
@@ -3185,7 +3190,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        final boolean statusBarShadeLocked = mStatusBarState == StatusBarState.SHADE_LOCKED;
        final boolean awakeKeyguard = isKeyguardVisible() && mDeviceInteractive
                && !statusBarShadeLocked;
        final int user = getCurrentUser();
        final int user = mSelectedUserInteractor.getSelectedUserId();
        final boolean faceAuthAllowed = isUnlockingWithBiometricAllowed(FACE);
        final boolean canBypass = mKeyguardBypassController != null
                && mKeyguardBypassController.canBypass();
@@ -3285,7 +3290,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    }

    private void startListeningForFingerprint() {
        final int userId = getCurrentUser();
        final int userId = mSelectedUserInteractor.getSelectedUserId();
        final boolean unlockPossible = isUnlockWithFingerprintPossible(userId);
        if (mFingerprintCancelSignal != null) {
            mLogger.logUnexpectedFpCancellationSignalState(
@@ -3332,7 +3337,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    }

    private void startListeningForFace(@NonNull FaceAuthUiEvent faceAuthUiEvent) {
        final int userId = getCurrentUser();
        final int userId = mSelectedUserInteractor.getSelectedUserId();
        final boolean unlockPossible = isUnlockWithFacePossible(userId);
        if (mFaceCancelSignal != null) {
            mLogger.logUnexpectedFaceCancellationSignalState(mFaceRunningState, unlockPossible);
@@ -3875,12 +3880,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    }

    private boolean resolveNeedsSlowUnlockTransition() {
        if (isUserUnlocked(getCurrentUser())) {
        if (isUserUnlocked(mSelectedUserInteractor.getSelectedUserId())) {
            return false;
        }
        Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
        ResolveInfo resolveInfo = mPackageManager.resolveActivityAsUser(homeIntent,
                0 /* flags */, getCurrentUser());
                0 /* flags */, mSelectedUserInteractor.getSelectedUserId());

        if (resolveInfo == null) {
            mLogger.w("resolveNeedsSlowUnlockTransition: returning false since activity could "
@@ -4066,9 +4071,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    @AnyThread
    public void setSwitchingUser(boolean switching) {
        if (switching) {
            mLogger.logUserSwitching(getCurrentUser(), "from setSwitchingUser");
            mLogger.logUserSwitching(
                    mSelectedUserInteractor.getSelectedUserId(), "from setSwitchingUser");
        } else {
            mLogger.logUserSwitchComplete(getCurrentUser(), "from setSwitchingUser");
            mLogger.logUserSwitchComplete(
                    mSelectedUserInteractor.getSelectedUserId(), "from setSwitchingUser");
        }
        mSwitchingUser = switching;
        // Since this comes in on a binder thread, we need to post it first
@@ -4443,9 +4450,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    @Override
    public void dump(@NonNull PrintWriter pw, @NonNull String[] args) {
        pw.println("KeyguardUpdateMonitor state:");
        pw.println("  getUserHasTrust()=" + getUserHasTrust(getCurrentUser()));
        pw.println("  getUserHasTrust()=" + getUserHasTrust(
                mSelectedUserInteractor.getSelectedUserId()));
        pw.println("  getUserUnlockedWithBiometric()="
                + getUserUnlockedWithBiometric(getCurrentUser()));
                + getUserUnlockedWithBiometric(mSelectedUserInteractor.getSelectedUserId()));
        pw.println("  isFaceAuthInteractorEnabled: " + isFaceAuthInteractorEnabled());
        pw.println("  SIM States:");
        for (SimData data : mSimDatas.values()) {
@@ -4463,7 +4471,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            pw.println("    " + subId + "=" + mServiceStates.get(subId));
        }
        if (isFingerprintSupported()) {
            final int userId = mUserTracker.getUserId();
            final int userId = mSelectedUserInteractor.getSelectedUserId();
            final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId);
            BiometricAuthenticated fingerprint = mUserFingerprintAuthenticated.get(userId);
            pw.println("  Fingerprint state (user=" + userId + ")");
@@ -4506,7 +4514,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    mFingerprintListenBuffer.toList()
            ).printTableData(pw);
        } else if (mFpm != null && mFingerprintSensorProperties.isEmpty()) {
            final int userId = mUserTracker.getUserId();
            final int userId = mSelectedUserInteractor.getSelectedUserId();
            pw.println("  Fingerprint state (user=" + userId + ")");
            pw.println("    mFingerprintSensorProperties.isEmpty="
                    + mFingerprintSensorProperties.isEmpty());
@@ -4520,7 +4528,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            ).printTableData(pw);
        }
        if (isFaceSupported()) {
            final int userId = mUserTracker.getUserId();
            final int userId = mSelectedUserInteractor.getSelectedUserId();
            final int strongAuthFlags = mStrongAuthTracker.getStrongAuthForUser(userId);
            BiometricAuthenticated face = mUserFaceAuthenticated.get(userId);
            pw.println("  Face authentication state (user=" + userId + ")");
@@ -4550,7 +4558,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    mFaceListenBuffer.toList()
            ).printTableData(pw);
        } else if (mFaceManager != null && mFaceSensorProperties.isEmpty()) {
            final int userId = mUserTracker.getUserId();
            final int userId = mSelectedUserInteractor.getSelectedUserId();
            pw.println("  Face state (user=" + userId + ")");
            pw.println("    mFaceSensorProperties.isEmpty="
                    + mFaceSensorProperties.isEmpty());
@@ -4564,7 +4572,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            ).printTableData(pw);
        }
        pw.println("ActiveUnlockRunning="
                + mTrustManager.isActiveUnlockRunning(KeyguardUpdateMonitor.getCurrentUser()));
                + mTrustManager.isActiveUnlockRunning(mSelectedUserInteractor.getSelectedUserId()));
        new DumpsysTableLogger(
                "KeyguardActiveUnlockTriggers",
                KeyguardActiveUnlockModel.TABLE_HEADERS,
+103 −78

File changed.

Preview size limit exceeded, changes collapsed.