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

Commit 44383520 authored by Aaron Liu's avatar Aaron Liu Committed by Automerger Merge Worker
Browse files

Merge "Move sidefps bouncer logic into interactor." into tm-qpr-dev am: e871505c

parents 9255a0f3 e871505c
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -492,12 +492,14 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
            case MotionEvent.ACTION_MOVE:
                mVelocityTracker.addMovement(event);
                int pointerIndex = event.findPointerIndex(mActivePointerId);
                if (pointerIndex != -1) {
                    float y = event.getY(pointerIndex);
                    if (mLastTouchY != -1) {
                        float dy = y - mLastTouchY;
                        setTranslationY(getTranslationY() + dy * TOUCH_Y_MULTIPLIER);
                    }
                    mLastTouchY = y;
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
+13 −48
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.keyguard;

import static android.app.StatusBarManager.SESSION_KEYGUARD;
import static android.hardware.biometrics.BiometricSourceType.FINGERPRINT;

import static com.android.keyguard.KeyguardSecurityContainer.BOUNCER_DISMISS_BIOMETRIC;
import static com.android.keyguard.KeyguardSecurityContainer.BOUNCER_DISMISS_EXTENDED_ACCESS;
@@ -36,7 +35,6 @@ import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.hardware.biometrics.BiometricOverlayConstants;
import android.hardware.biometrics.BiometricSourceType;
import android.media.AudioManager;
import android.metrics.LogMaker;
import android.os.SystemClock;
@@ -320,7 +318,6 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
                    KeyguardSecurityContainerController.this.onDensityOrFontScaleChanged();
                }
            };
    private boolean mBouncerVisible = false;
    private final KeyguardUpdateMonitorCallback mKeyguardUpdateMonitorCallback =
            new KeyguardUpdateMonitorCallback() {
                @Override
@@ -355,19 +352,6 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
                public void onDevicePolicyManagerStateChanged() {
                    showPrimarySecurityScreen(false);
                }

                @Override
                public void onBiometricRunningStateChanged(boolean running,
                        BiometricSourceType biometricSourceType) {
                    if (biometricSourceType == FINGERPRINT) {
                        updateSideFpsVisibility();
                    }
                }

                @Override
                public void onStrongAuthStateChanged(int userId) {
                    updateSideFpsVisibility();
                }
            };

    @Inject
@@ -459,35 +443,24 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
            getCurrentSecurityController().onPause();
        }
        mView.onPause();
        // It might happen that onStartingToHide is not called when the device is locked while on
        // bouncer.
        setBouncerVisible(false);
        mView.clearFocus();
    }

    private void updateSideFpsVisibility() {
    /**
     * Shows and hides the side finger print sensor animation.
     *
     * @param isVisible sets whether we show or hide the side fps animation
     */
    public void updateSideFpsVisibility(boolean isVisible) {
        if (!mSideFpsController.isPresent()) {
            return;
        }
        final boolean sfpsEnabled = getResources().getBoolean(
                R.bool.config_show_sidefps_hint_on_bouncer);
        final boolean fpsDetectionRunning = mUpdateMonitor.isFingerprintDetectionRunning();
        final boolean isUnlockingWithFpAllowed =
                mUpdateMonitor.isUnlockingWithFingerprintAllowed();

        boolean toShow = mBouncerVisible && sfpsEnabled && fpsDetectionRunning
                && isUnlockingWithFpAllowed;

        if (DEBUG) {
            Log.d(TAG, "sideFpsToShow=" + toShow + ", "
                    + "mBouncerVisible=" + mBouncerVisible + ", "
                    + "configEnabled=" + sfpsEnabled + ", "
                    + "fpsDetectionRunning=" + fpsDetectionRunning + ", "
                    + "isUnlockingWithFpAllowed=" + isUnlockingWithFpAllowed);
        }
        if (toShow) {
            mSideFpsController.get().show(SideFpsUiRequestSource.PRIMARY_BOUNCER,
                    BiometricOverlayConstants.REASON_AUTH_KEYGUARD);
        if (isVisible) {
            mSideFpsController.get().show(
                    SideFpsUiRequestSource.PRIMARY_BOUNCER,
                    BiometricOverlayConstants.REASON_AUTH_KEYGUARD
            );
        } else {
            mSideFpsController.get().hide(SideFpsUiRequestSource.PRIMARY_BOUNCER);
        }
@@ -636,7 +609,6 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
            SysUiStatsLog.write(SysUiStatsLog.KEYGUARD_BOUNCER_STATE_CHANGED, state);

            getCurrentSecurityController().onResume(reason);
            updateSideFpsVisibility();
        }
        mView.onResume(
                mSecurityModel.getSecurityMode(KeyguardUpdateMonitor.getCurrentUser()),
@@ -690,22 +662,15 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
        if (mCurrentSecurityMode != SecurityMode.None) {
            getCurrentSecurityController().onStartingToHide();
        }
        setBouncerVisible(false);
    }

    /** Called when the bouncer changes visibility. */
    public void onBouncerVisibilityChanged(@View.Visibility int visibility) {
        setBouncerVisible(visibility == View.VISIBLE);
        if (visibility == View.INVISIBLE) {
    public void onBouncerVisibilityChanged(boolean isVisible) {
        if (!isVisible) {
            mView.resetScale();
        }
    }

    private void setBouncerVisible(boolean visible) {
        mBouncerVisible = visible;
        updateSideFpsVisibility();
    }

    /**
     * Shows the next security screen if there is one.
     * @param authenticated true if the user entered the correct authentication
+11 −10
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ interface KeyguardBouncerRepository {
     */
    val panelExpansionAmount: StateFlow<Float>
    val keyguardPosition: StateFlow<Float>
    val onScreenTurnedOff: StateFlow<Boolean>
    val isBackButtonEnabled: StateFlow<Boolean?>
    /** Determines if user is already unlocked */
    val keyguardAuthenticated: StateFlow<Boolean?>
@@ -70,6 +69,8 @@ interface KeyguardBouncerRepository {
    val bouncerErrorMessage: CharSequence?
    val alternateBouncerVisible: StateFlow<Boolean>
    val alternateBouncerUIAvailable: StateFlow<Boolean>
    val sideFpsShowing: StateFlow<Boolean>

    var lastAlternateBouncerVisibleTime: Long

    fun setPrimaryScrimmed(isScrimmed: Boolean)
@@ -98,11 +99,11 @@ interface KeyguardBouncerRepository {

    fun setIsBackButtonEnabled(isBackButtonEnabled: Boolean)

    fun setOnScreenTurnedOff(onScreenTurnedOff: Boolean)

    fun setAlternateVisible(isVisible: Boolean)

    fun setAlternateBouncerUIAvailable(isAvailable: Boolean)

    fun setSideFpsShowing(isShowing: Boolean)
}

@SysUISingleton
@@ -142,8 +143,6 @@ constructor(
    override val panelExpansionAmount = _panelExpansionAmount.asStateFlow()
    private val _keyguardPosition = MutableStateFlow(0f)
    override val keyguardPosition = _keyguardPosition.asStateFlow()
    private val _onScreenTurnedOff = MutableStateFlow(false)
    override val onScreenTurnedOff = _onScreenTurnedOff.asStateFlow()
    private val _isBackButtonEnabled = MutableStateFlow<Boolean?>(null)
    override val isBackButtonEnabled = _isBackButtonEnabled.asStateFlow()
    private val _keyguardAuthenticated = MutableStateFlow<Boolean?>(null)
@@ -165,6 +164,8 @@ constructor(
    private val _alternateBouncerUIAvailable = MutableStateFlow(false)
    override val alternateBouncerUIAvailable: StateFlow<Boolean> =
        _alternateBouncerUIAvailable.asStateFlow()
    private val _sideFpsShowing = MutableStateFlow(false)
    override val sideFpsShowing: StateFlow<Boolean> = _sideFpsShowing.asStateFlow()

    init {
        setUpLogging()
@@ -235,8 +236,8 @@ constructor(
        _isBackButtonEnabled.value = isBackButtonEnabled
    }

    override fun setOnScreenTurnedOff(onScreenTurnedOff: Boolean) {
        _onScreenTurnedOff.value = onScreenTurnedOff
    override fun setSideFpsShowing(isShowing: Boolean) {
        _sideFpsShowing.value = isShowing
    }

    /** Sets up logs for state flows. */
@@ -276,9 +277,6 @@ constructor(
            .map { it.toInt() }
            .logDiffsForTable(buffer, "", "KeyguardPosition", -1)
            .launchIn(applicationScope)
        onScreenTurnedOff
            .logDiffsForTable(buffer, "", "OnScreenTurnedOff", false)
            .launchIn(applicationScope)
        isBackButtonEnabled
            .filterNotNull()
            .logDiffsForTable(buffer, "", "IsBackButtonEnabled", false)
@@ -293,6 +291,9 @@ constructor(
        alternateBouncerUIAvailable
            .logDiffsForTable(buffer, "", "IsAlternateBouncerUIAvailable", false)
            .launchIn(applicationScope)
        sideFpsShowing
            .logDiffsForTable(buffer, "", "isSideFpsShowing", false)
            .launchIn(applicationScope)
    }

    companion object {
+58 −8
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.keyguard.domain.interactor

import android.content.Context
import android.content.res.ColorStateList
import android.hardware.biometrics.BiometricSourceType
import android.os.Handler
@@ -23,9 +24,13 @@ import android.os.Trace
import android.os.UserHandle
import android.os.UserManager
import android.view.View
import android.util.Log
import com.android.keyguard.KeyguardConstants
import com.android.keyguard.KeyguardSecurityModel
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.DejankUtils
import com.android.systemui.R
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
@@ -62,8 +67,9 @@ constructor(
    private val primaryBouncerCallbackInteractor: PrimaryBouncerCallbackInteractor,
    private val falsingCollector: FalsingCollector,
    private val dismissCallbackRegistry: DismissCallbackRegistry,
    private val context: Context,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    keyguardBypassController: KeyguardBypassController,
    keyguardUpdateMonitor: KeyguardUpdateMonitor,
) {
    /** Whether we want to wait for face auth. */
    private val primaryBouncerFaceDelay =
@@ -90,7 +96,6 @@ constructor(
    }

    val keyguardAuthenticated: Flow<Boolean> = repository.keyguardAuthenticated.filterNotNull()
    val screenTurnedOff: Flow<Unit> = repository.onScreenTurnedOff.filter { it }.map {}
    val show: Flow<KeyguardBouncerModel> = repository.primaryBouncerShow.filterNotNull()
    val hide: Flow<Unit> = repository.primaryBouncerHide.filter { it }.map {}
    val startingToHide: Flow<Unit> = repository.primaryBouncerStartingToHide.filter { it }.map {}
@@ -115,6 +120,24 @@ constructor(
        }
    /** Allow for interaction when just about fully visible */
    val isInteractable: Flow<Boolean> = bouncerExpansion.map { it > 0.9 }
    val sideFpsShowing: Flow<Boolean> = repository.sideFpsShowing

    init {
        keyguardUpdateMonitor.registerCallback(
            object : KeyguardUpdateMonitorCallback() {
                override fun onBiometricRunningStateChanged(
                    running: Boolean,
                    biometricSourceType: BiometricSourceType?
                ) {
                    updateSideFpsVisibility()
                }

                override fun onStrongAuthStateChanged(userId: Int) {
                    updateSideFpsVisibility()
                }
            }
        )
    }

    // TODO(b/243685699): Move isScrimmed logic to data layer.
    // TODO(b/243695312): Encapsulate all of the show logic for the bouncer.
@@ -122,7 +145,6 @@ constructor(
    @JvmOverloads
    fun show(isScrimmed: Boolean) {
        // Reset some states as we show the bouncer.
        repository.setOnScreenTurnedOff(false)
        repository.setKeyguardAuthenticated(null)
        repository.setPrimaryHide(false)
        repository.setPrimaryStartingToHide(false)
@@ -262,11 +284,6 @@ constructor(
        repository.setKeyguardAuthenticated(strongAuth)
    }

    /** Tell the bouncer the screen has turned off. */
    fun onScreenTurnedOff() {
        repository.setOnScreenTurnedOff(true)
    }

    /** Update the position of the bouncer when showing. */
    fun setKeyguardPosition(position: Float) {
        repository.setKeyguardPosition(position)
@@ -301,6 +318,35 @@ constructor(
        repository.setPrimaryStartDisappearAnimation(finishRunnable)
    }

    /** Determine whether to show the side fps animation. */
    fun updateSideFpsVisibility() {
        val sfpsEnabled: Boolean =
            context.resources.getBoolean(R.bool.config_show_sidefps_hint_on_bouncer)
        val fpsDetectionRunning: Boolean = keyguardUpdateMonitor.isFingerprintDetectionRunning
        val isUnlockingWithFpAllowed: Boolean =
            keyguardUpdateMonitor.isUnlockingWithFingerprintAllowed
        val bouncerVisible = repository.primaryBouncerVisible.value
        val toShow =
            (repository.primaryBouncerVisible.value &&
                sfpsEnabled &&
                fpsDetectionRunning &&
                isUnlockingWithFpAllowed &&
                !isAnimatingAway())

        if (KeyguardConstants.DEBUG) {
            Log.d(
                TAG,
                ("sideFpsToShow=$toShow\n" +
                    "bouncerVisible=$bouncerVisible\n" +
                    "configEnabled=$sfpsEnabled\n" +
                    "fpsDetectionRunning=$fpsDetectionRunning\n" +
                    "isUnlockingWithFpAllowed=$isUnlockingWithFpAllowed\n" +
                    "isAnimatingAway=${isAnimatingAway()}")
            )
        }
        repository.setSideFpsShowing(toShow)
    }

    /** Returns whether bouncer is fully showing. */
    fun isFullyShowing(): Boolean {
        return (repository.primaryBouncerShowingSoon.value ||
@@ -344,4 +390,8 @@ constructor(
        DejankUtils.removeCallbacks(showRunnable)
        mainHandler.removeCallbacks(showRunnable)
    }

    companion object {
        private const val TAG = "PrimaryBouncerInteractor"
    }
}
+17 −8
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardBouncerViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.ActivityStarter
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch

@@ -121,7 +122,6 @@ object KeyguardBouncerViewBinder {
                    launch {
                        viewModel.hide.collect {
                            securityContainerController.cancelDismissAction()
                            securityContainerController.onPause()
                            securityContainerController.reset()
                        }
                    }
@@ -155,12 +155,17 @@ object KeyguardBouncerViewBinder {

                    launch {
                        viewModel.isBouncerVisible.collect { isVisible ->
                            val visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
                            view.visibility = visibility
                            securityContainerController.onBouncerVisibilityChanged(visibility)
                            view.visibility = if (isVisible) View.VISIBLE else View.INVISIBLE
                            securityContainerController.onBouncerVisibilityChanged(isVisible)
                        }
                    }

                    launch {
                        viewModel.isBouncerVisible
                            .filter { !it }
                            .collect { securityContainerController.onPause() }
                    }

                    launch {
                        viewModel.isInteractable.collect { isInteractable ->
                            securityContainerController.setInteractable(isInteractable)
@@ -204,11 +209,15 @@ object KeyguardBouncerViewBinder {
                    }

                    launch {
                        viewModel.screenTurnedOff.collect {
                            if (view.visibility == View.VISIBLE) {
                                securityContainerController.onPause()
                        viewModel.shouldUpdateSideFps.collect {
                            viewModel.updateSideFpsVisibility()
                        }
                    }

                    launch {
                        viewModel.sideFpsShowing.collect {
                            securityContainerController.updateSideFpsVisibility(it)
                        }
                    }
                    awaitCancellation()
                } finally {
Loading