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

Commit eb5fe1d3 authored by Beverly's avatar Beverly
Browse files

If enrolled show udfps bouncer on camera roll auth

- Add PowerManager.userActivity when user uses udfps to authenticate
so the screen won't turn off prematurely
- When the udfps-bouncer is showing, tapping outside the udfps view will
show the regular pin/pattern/password bouncer

Fixes: 184927116
Fixes: 182500156
Test: atest SystemUITests
Test: manual
  1. enroll udfps
  2. go to locked lock screen
  3. double tap power button to bring up camera
  4. tap on camera gallery (lock icon on image, bottom right)
  Observe: udfps is highlighted; tapping outside udfps area brings up
  regular bouncer

Change-Id: If01ee16647499fc2cf73afe527053cd6830a50ed
parent 8c2273ef
Loading
Loading
Loading
Loading
+30 −23
Original line number Diff line number Diff line
@@ -2009,9 +2009,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

        // TODO: Add support for multiple fingerprint sensors, b/173730729
        updateUdfpsEnrolled(getCurrentUser());
        boolean shouldListenForFingerprint =
                isUdfpsEnrolled() ? shouldListenForUdfps() : shouldListenForFingerprint();
        boolean runningOrRestarting = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING
        final boolean shouldListenForFingerprint = shouldListenForFingerprint(isUdfpsEnrolled());
        final boolean runningOrRestarting = mFingerprintRunningState == BIOMETRIC_STATE_RUNNING
                || mFingerprintRunningState == BIOMETRIC_STATE_CANCELLING_RESTARTING;
        if (runningOrRestarting && !shouldListenForFingerprint) {
            stopListeningForFingerprint();
@@ -2092,28 +2091,36 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                && !mUserHasTrust.get(getCurrentUser(), false);
    }

    private boolean shouldListenForFingerprint() {
        final boolean allowedOnBouncer =
                !(mFingerprintLockedOut && mBouncer && mCredentialAttempted);
    @VisibleForTesting
    protected boolean shouldListenForFingerprint(boolean isUdfps) {
        final boolean shouldListenKeyguardState =
                 mKeyguardIsVisible
                     || !mDeviceInteractive
                     || (mBouncer && !mKeyguardGoingAway)
                     || mGoingToSleep
                     || shouldListenForFingerprintAssistant()
                     || (mKeyguardOccluded && mIsDreaming)
                     || (isUdfps && mKeyguardOccluded);

        // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an
        // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware.
        final boolean shouldListen = (mKeyguardIsVisible || !mDeviceInteractive ||
                (mBouncer && !mKeyguardGoingAway) || mGoingToSleep ||
                shouldListenForFingerprintAssistant() || (mKeyguardOccluded && mIsDreaming))
                && !mSwitchingUser && !isFingerprintDisabled(getCurrentUser())
                && (!mKeyguardGoingAway || !mDeviceInteractive) && mIsPrimaryUser
                && allowedOnBouncer && mBiometricEnabledForUser.get(getCurrentUser());
        return shouldListen;
    }

    @VisibleForTesting
    boolean shouldListenForUdfps() {
        return shouldListenForFingerprint()
                && !mBouncer
                && !getUserCanSkipBouncer(getCurrentUser())
        final boolean shouldListenUserState =
                !mSwitchingUser
                        && !isFingerprintDisabled(getCurrentUser())
                        && (!mKeyguardGoingAway || !mDeviceInteractive)
                        && mIsPrimaryUser
                        && mBiometricEnabledForUser.get(getCurrentUser());

        final boolean shouldListenBouncerState =
                isUdfps ? !mBouncer
                        : !(mFingerprintLockedOut && mBouncer && mCredentialAttempted);

        final boolean shouldListenUdfpsState = !isUdfps
                || (!getUserCanSkipBouncer(getCurrentUser())
                && !isEncryptedOrLockdown(getCurrentUser())
                && mStrongAuthTracker.hasUserAuthenticatedSinceBoot();
                && mStrongAuthTracker.hasUserAuthenticatedSinceBoot());
        return shouldListenKeyguardState && shouldListenUserState && shouldListenBouncerState
                && shouldListenUdfpsState;
    }

    /**
@@ -3235,13 +3242,13 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
            pw.println("    disabled(DPM)=" + isFingerprintDisabled(userId));
            pw.println("    possible=" + isUnlockWithFingerprintPossible(userId));
            pw.println("    listening: actual=" + mFingerprintRunningState
                    + " expected=" + (shouldListenForFingerprint() ? 1 : 0));
                    + " expected=" + (shouldListenForFingerprint(false) ? 1 : 0));
            pw.println("    strongAuthFlags=" + Integer.toHexString(strongAuthFlags));
            pw.println("    trustManaged=" + getUserTrustIsManaged(userId));
            pw.println("    udfpsEnrolled=" + isUdfpsEnrolled());
            pw.println("    enabledByUser=" + mBiometricEnabledForUser.get(userId));
            if (isUdfpsEnrolled()) {
                pw.println("        shouldListenForUdfps=" + shouldListenForUdfps());
                pw.println("        shouldListenForUdfps=" + shouldListenForFingerprint(true));
                pw.println("        bouncerVisible=" + mBouncer);
                pw.println("        mStatusBarState="
                        + StatusBarState.toShortString(mStatusBarState));
+12 −0
Original line number Diff line number Diff line
@@ -165,6 +165,18 @@ abstract class UdfpsAnimationViewController<T extends UdfpsAnimationView>
        mView.postInvalidate();
    }

    /**
     * Whether to listen for touches outside of the view.
     */
    boolean listenForTouchesOutsideView() {
        return false;
    }

    /**
     * Called on touches outside of the view if listenForTouchesOutsideView returns true
     */
    void onTouchOutsideView() { }

    private final StatusBar.ExpansionChangedListener mStatusBarExpansionChangedListener =
            new StatusBar.ExpansionChangedListener() {
                @Override
+23 −5
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.hardware.fingerprint.IUdfpsOverlayControllerCallback;
import android.media.AudioAttributes;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
@@ -106,6 +107,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
    @NonNull private final Vibrator mVibrator;
    @NonNull private final Handler mMainHandler;
    @NonNull private final FalsingManager mFalsingManager;
    @NonNull private final PowerManager mPowerManager;
    // Currently the UdfpsController supports a single UDFPS sensor. If devices have multiple
    // sensors, this, in addition to a lot of the code here, will be updated.
    @VisibleForTesting final FingerprintSensorPropertiesInternal mSensorProps;
@@ -266,6 +268,9 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
        final boolean isFingerDown = udfpsView.isIlluminationRequested();
        boolean handled = false;
        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_OUTSIDE:
                udfpsView.onTouchOutsideView();
                break;
            case MotionEvent.ACTION_DOWN:
                // To simplify the lifecycle of the velocity tracker, make sure it's never null
                // after ACTION_DOWN, and always null after ACTION_CANCEL or ACTION_UP.
@@ -332,6 +337,8 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
                            onFingerDown((int) x, (int) y, minor, major);
                            Log.v(TAG, "onTouch | finger down: " + touchInfo);
                            mTouchLogTime = SystemClock.elapsedRealtime();
                            mPowerManager.userActivity(SystemClock.uptimeMillis(),
                                    PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0);
                            handled = true;
                        } else if (sinceLastLog >= MIN_TOUCH_LOG_INTERVAL) {
                            Log.v(TAG, "onTouch | finger move: " + touchInfo);
@@ -377,7 +384,8 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
            @NonNull DumpManager dumpManager,
            @NonNull KeyguardUpdateMonitor keyguardUpdateMonitor,
            @NonNull KeyguardViewMediator keyguardViewMediator,
            @NonNull FalsingManager falsingManager) {
            @NonNull FalsingManager falsingManager,
            @NonNull PowerManager powerManager) {
        mContext = context;
        // TODO (b/185124905): inject main handler and vibrator once done prototyping
        mMainHandler = new Handler(Looper.getMainLooper());
@@ -395,6 +403,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mKeyguardViewMediator = keyguardViewMediator;
        mFalsingManager = falsingManager;
        mPowerManager = powerManager;

        mSensorProps = findFirstUdfps();
        // At least one UDFPS sensor exists
@@ -403,10 +412,7 @@ public class UdfpsController implements DozeReceiver, HbmCallback {

        mCoreLayoutParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG,
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                getCoreLayoutParamFlags(),
                PixelFormat.TRANSLUCENT);
        mCoreLayoutParams.setTitle(TAG);
        mCoreLayoutParams.setFitInsetsTypes(0);
@@ -422,6 +428,13 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
        context.registerReceiver(mBroadcastReceiver, filter);
    }

    private int getCoreLayoutParamFlags() {
        return WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
    }

    @Nullable
    private FingerprintSensorPropertiesInternal findFirstUdfps() {
        for (FingerprintSensorPropertiesInternal props :
@@ -467,6 +480,11 @@ public class UdfpsController implements DozeReceiver, HbmCallback {
        final int paddingX = animation != null ? animation.getPaddingX() : 0;
        final int paddingY = animation != null ? animation.getPaddingY() : 0;

        mCoreLayoutParams.flags = getCoreLayoutParamFlags();
        if (animation.listenForTouchesOutsideView()) {
            mCoreLayoutParams.flags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
        }

        // Default dimensions assume portrait mode.
        mCoreLayoutParams.x = mSensorProps.sensorLocationX - mSensorProps.sensorRadius - paddingX;
        mCoreLayoutParams.y = mSensorProps.sensorLocationY - mSensorProps.sensorRadius - paddingY;
+55 −26
Original line number Diff line number Diff line
@@ -52,12 +52,13 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
    @NonNull private final KeyguardViewMediator mKeyguardViewMediator;

    @Nullable private Runnable mCancelRunnable;
    private boolean mShowBouncer;
    private boolean mShowingUdfpsBouncer;
    private boolean mQsExpanded;
    private boolean mFaceDetectRunning;
    private boolean mHintShown;
    private boolean mTransitioningFromHome;
    private int mStatusBarState;
    private boolean mKeyguardIsVisible;

    protected UdfpsKeyguardViewController(
            @NonNull UdfpsKeyguardView view,
@@ -90,8 +91,11 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
        final float dozeAmount = mStatusBarStateController.getDozeAmount();
        mStatusBarStateController.addCallback(mStateListener);
        mStateListener.onDozeAmountChanged(dozeAmount, dozeAmount);
        mStateListener.onStateChanged(mStatusBarStateController.getState());
        mAlternateAuthInterceptor.setQsExpanded(mKeyguardViewManager.isQsExpanded());
        mStatusBarState = mStatusBarStateController.getState();
        mQsExpanded = mKeyguardViewManager.isQsExpanded();
        mKeyguardIsVisible = mKeyguardUpdateMonitor.isKeyguardVisible();
        updatePauseAuth();

        mKeyguardViewManager.setAlternateAuthInterceptor(mAlternateAuthInterceptor);
    }

@@ -102,7 +106,6 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
        mFaceDetectRunning = false;

        mStatusBarStateController.removeCallback(mStateListener);
        mAlternateAuthInterceptor.hideAlternateAuthBouncer();
        mKeyguardViewManager.setAlternateAuthInterceptor(null);
        mTransitioningFromHome = false;

@@ -115,28 +118,32 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        super.dump(fd, pw, args);
        pw.println("mShowBouncer=" + mShowBouncer);
        pw.println("mShowingUdfpsBouncer=" + mShowingUdfpsBouncer);
        pw.println("mFaceDetectRunning=" + mFaceDetectRunning);
        pw.println("mTransitioningFromHomeToKeyguard=" + mTransitioningFromHome);
        pw.println("mStatusBarState" + StatusBarState.toShortString(mStatusBarState));
        pw.println("mQsExpanded=" + mQsExpanded);
        pw.println("mKeyguardVisible=" + mKeyguardIsVisible);
    }

    /**
     * Overrides non-bouncer show logic in shouldPauseAuth to still auth.
     * Overrides non-bouncer show logic in shouldPauseAuth to still show icon.
     * @return whether the udfpsBouncer has been newly shown or hidden
     */
    private void showBouncer(boolean show) {
        if (mShowBouncer == show) {
            return;
    private boolean showUdfpsBouncer(boolean show) {
        if (mShowingUdfpsBouncer == show) {
            return false;
        }

        mShowBouncer = show;
        mShowingUdfpsBouncer = show;
        updatePauseAuth();
        if (mShowBouncer) {
        if (mShowingUdfpsBouncer) {
            mView.animateUdfpsBouncer();
        } else {
            // TODO: beverlyt, we not always want to cancelPostAuthActions
            mView.animateAwayUdfpsBouncer(() -> mKeyguardViewManager.cancelPostAuthActions());
        }
        return true;
    }

    /**
@@ -145,7 +152,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
     * is expanded, so this can be overridden with the showBouncer method.
     */
    public boolean shouldPauseAuth() {
        if (mShowBouncer) {
        if (mShowingUdfpsBouncer) {
            return false;
        }

@@ -161,9 +168,36 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
            return true;
        }

        if (!mKeyguardIsVisible) {
            return true;
        }

        return false;
    }

    @Override
    public boolean listenForTouchesOutsideView() {
        return true;
    }

    @Override
    public void onTouchOutsideView() {
        maybeShowInputBouncer();
    }

    /**
     * If we were previously showing the udfps bouncer, hide it and instead show the regular
     * (pin/pattern/password) bouncer.
     *
     * Does nothing if we weren't previously showing the udfps bouncer.
     */
    private void maybeShowInputBouncer() {
        if (mShowingUdfpsBouncer) {
            mKeyguardViewManager.resetAlternateAuth(false);
            mKeyguardViewManager.showBouncer(true);
        }
    }

    private void cancelDelayedHint() {
        if (mCancelRunnable != null) {
            mCancelRunnable.run();
@@ -198,7 +232,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
            new StatusBarStateController.StateListener() {
        @Override
        public void onDozeAmountChanged(float linear, float eased) {
            if (linear != 0) showBouncer(false);
            if (linear != 0) showUdfpsBouncer(false);
            mView.onDozeAmountChanged(linear, eased);
            if (linear == 1f) {
                // transition has finished
@@ -245,33 +279,28 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
                        cancelDelayedHint();
                    }
                }

                public void onKeyguardVisibilityChangedRaw(boolean showing) {
                    mKeyguardIsVisible = showing;
                    updatePauseAuth();
                }
            };

    private final StatusBarKeyguardViewManager.AlternateAuthInterceptor mAlternateAuthInterceptor =
            new StatusBarKeyguardViewManager.AlternateAuthInterceptor() {
                @Override
                public boolean showAlternateAuthBouncer() {
                    if (mShowBouncer) {
                        return false;
                    }

                    showBouncer(true);
                    return true;
                    return showUdfpsBouncer(true);
                }

                @Override
                public boolean hideAlternateAuthBouncer() {
                    if (!mShowBouncer) {
                        return false;
                    }

                    showBouncer(false);
                    return true;
                    return showUdfpsBouncer(false);
                }

                @Override
                public boolean isShowingAlternateAuthBouncer() {
                    return mShowBouncer;
                    return mShowingUdfpsBouncer;
                }

                @Override
+4 −0
Original line number Diff line number Diff line
@@ -130,6 +130,10 @@ public class UdfpsView extends FrameLayout implements DozeReceiver, UdfpsIllumin
        }
    }

    void onTouchOutsideView() {
        mAnimationViewController.onTouchOutsideView();
    }

    void setAnimationViewController(UdfpsAnimationViewController animationViewController) {
        mAnimationViewController = animationViewController;
    }
Loading