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

Commit e0c9d358 authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Navigate away from bouncer when the IME is hidden." into main

parents f00e30fa 3ae7e4a9
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -17,8 +17,11 @@
package com.android.systemui.bouncer.ui.composable

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imeAnimationTarget
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.LocalTextStyle
@@ -29,6 +32,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
@@ -44,6 +48,7 @@ import androidx.compose.ui.unit.dp
import com.android.systemui.bouncer.ui.viewmodel.PasswordBouncerViewModel

/** UI for the input part of a password-requiring version of the bouncer. */
@OptIn(ExperimentalLayoutApi::class)
@Composable
internal fun PasswordBouncer(
    viewModel: PasswordBouncerViewModel,
@@ -54,6 +59,10 @@ internal fun PasswordBouncer(
    val isInputEnabled: Boolean by viewModel.isInputEnabled.collectAsState()
    val animateFailure: Boolean by viewModel.animateFailure.collectAsState()

    val density = LocalDensity.current
    val isImeVisible by rememberUpdatedState(WindowInsets.imeAnimationTarget.getBottom(density) > 0)
    LaunchedEffect(isImeVisible) { viewModel.onImeVisibilityChanged(isImeVisible) }

    LaunchedEffect(Unit) {
        // When the UI comes up, request focus on the TextField to bring up the software keyboard.
        focusRequester.requestFocus()
+14 −0
Original line number Diff line number Diff line
@@ -225,6 +225,20 @@ constructor(
        repository.setMessage(errorMessage(authenticationInteractor.getAuthenticationMethod()))
    }

    /** If the bouncer is showing, hides the bouncer and return to the lockscreen scene. */
    fun hide(
        loggingReason: String,
    ) {
        if (sceneInteractor.desiredScene.value.key != SceneKey.Bouncer) {
            return
        }

        sceneInteractor.changeScene(
            scene = SceneModel(SceneKey.Lockscreen),
            loggingReason = loggingReason,
        )
    }

    private fun promptMessage(authMethod: AuthenticationMethodModel): String {
        return when (authMethod) {
            is AuthenticationMethodModel.Pin ->
+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.bouncer.ui.viewmodel

import com.android.systemui.bouncer.domain.interactor.BouncerInteractor
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -28,6 +29,7 @@ sealed class AuthMethodBouncerViewModel(
     * being able to attempt to unlock the device.
     */
    val isInputEnabled: StateFlow<Boolean>,
    private val interactor: BouncerInteractor,
) {

    private val _animateFailure = MutableStateFlow(false)
@@ -37,6 +39,9 @@ sealed class AuthMethodBouncerViewModel(
     */
    val animateFailure: StateFlow<Boolean> = _animateFailure.asStateFlow()

    /** Whether the input method editor (for example, the software keyboard) is visible. */
    private var isImeVisible: Boolean = false

    /**
     * Notifies that the failure animation has been shown. This should be called to consume a `true`
     * value in [animateFailure].
@@ -45,6 +50,21 @@ sealed class AuthMethodBouncerViewModel(
        _animateFailure.value = false
    }

    /**
     * Notifies that the input method editor (for example, the software keyboard) has been shown or
     * hidden.
     */
    fun onImeVisibilityChanged(isVisible: Boolean) {
        if (isImeVisible && !isVisible) {
            // The IME has gone from visible to invisible, dismiss the bouncer.
            interactor.hide(
                loggingReason = "IME hidden",
            )
        }

        isImeVisible = isVisible
    }

    /** Ask the UI to show the failure animation. */
    protected fun showFailureAnimation() {
        _animateFailure.value = true
+5 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ class PasswordBouncerViewModel(
) :
    AuthMethodBouncerViewModel(
        isInputEnabled = isInputEnabled,
        interactor = interactor,
    ) {

    private val _password = MutableStateFlow("")
@@ -60,6 +61,10 @@ class PasswordBouncerViewModel(
    /** Notifies that the user has pressed the key for attempting to authenticate the password. */
    fun onAuthenticateKeyPressed() {
        val password = _password.value.toCharArray().toList()
        if (password.isEmpty()) {
            return
        }

        _password.value = ""

        applicationScope.launch {
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class PatternBouncerViewModel(
) :
    AuthMethodBouncerViewModel(
        isInputEnabled = isInputEnabled,
        interactor = interactor,
    ) {

    /** The number of columns in the dot grid. */
Loading