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

Commit 6235bfc6 authored by Chandru S's avatar Chandru S
Browse files

Remove sceneInteractor and deviceEntry dependencies from BouncerInteractor and...

Remove sceneInteractor and deviceEntry dependencies from BouncerInteractor and AuthenticationInteractor

Summary of changes:
  - BouncerInteractor does not have the responsibility of handling scene transitions, it is now managed only by SceneContainerStartable
  - Eagerly start State flows in DeviceEntryInteractor as there are non collecting consumers for the flow.
  - Remove Swipe as an AuthenticationMethod, no authentication flow cares specifically about Swipe.
  - Expose Swipe "authentication" method through DeviceEntryInteractor#canSwipeToEnter
  - Change usages of Swipe "authentication" method to DeviceEntry.canSwipeToEnter

Test: all affected unit tests
Bug: 310005730
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: Ie89c0217b9302826ef4e637fecb4f229f9a8acaa
parent 27cb2531
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import com.android.internal.logging.nano.MetricsProto
import com.android.internal.logging.testing.FakeMetricsLogger
import com.android.internal.util.EmergencyAffordanceManager
import com.android.systemui.SysuiTestCase
import com.android.systemui.authentication.data.model.AuthenticationMethodModel
import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.Flags.REFACTOR_GETCURRENTUSER
import com.android.systemui.log.table.TableLogBuffer
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import com.android.internal.widget.LockPatternChecker
import com.android.internal.widget.LockPatternUtils
import com.android.internal.widget.LockscreenCredential
import com.android.keyguard.KeyguardSecurityModel
import com.android.systemui.authentication.data.model.AuthenticationMethodModel
import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
import com.android.systemui.authentication.shared.model.AuthenticationResultModel
import com.android.systemui.authentication.shared.model.AuthenticationThrottlingModel
import com.android.systemui.broadcast.BroadcastDispatcher
+9 −39
Original line number Diff line number Diff line
@@ -19,15 +19,13 @@ package com.android.systemui.authentication.domain.interactor
import com.android.app.tracing.TraceUtils.Companion.withContext
import com.android.internal.widget.LockPatternView
import com.android.internal.widget.LockscreenCredential
import com.android.systemui.authentication.data.model.AuthenticationMethodModel as DataLayerAuthenticationMethodModel
import com.android.systemui.authentication.data.repository.AuthenticationRepository
import com.android.systemui.authentication.domain.model.AuthenticationMethodModel as DomainLayerAuthenticationMethodModel
import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
import com.android.systemui.authentication.shared.model.AuthenticationPatternCoordinate
import com.android.systemui.authentication.shared.model.AuthenticationThrottlingModel
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository
import com.android.systemui.user.data.repository.UserRepository
import com.android.systemui.util.time.SystemClock
import javax.inject.Inject
@@ -63,7 +61,6 @@ constructor(
    private val repository: AuthenticationRepository,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val userRepository: UserRepository,
    private val deviceEntryRepository: DeviceEntryRepository,
    private val clock: SystemClock,
) {
    /**
@@ -84,8 +81,7 @@ constructor(
     * `true` even when the lockscreen is showing and still needs to be dismissed by the user to
     * proceed.
     */
    val authenticationMethod: Flow<DomainLayerAuthenticationMethodModel> =
        repository.authenticationMethod.map { rawModel -> rawModel.toDomainLayer() }
    val authenticationMethod: Flow<AuthenticationMethodModel> = repository.authenticationMethod

    /** The current authentication throttling state, only meaningful if [isThrottled] is `true`. */
    val throttling: StateFlow<AuthenticationThrottlingModel> = repository.throttling
@@ -171,17 +167,8 @@ constructor(
     * The flow should be used for code that wishes to stay up-to-date its logic as the
     * authentication changes over time and this method should be used for simple code that only
     * needs to check the current value.
     *
     * Note: this layer adds the synthetic authentication method of "swipe" which is special. When
     * the current authentication method is "swipe", the user does not need to complete any
     * authentication challenge to unlock the device; they just need to dismiss the lockscreen to
     * get past it. This also means that the value of `DeviceEntryInteractor#isUnlocked` remains
     * `true` even when the lockscreen is showing and still needs to be dismissed by the user to
     * proceed.
     */
    suspend fun getAuthenticationMethod(): DomainLayerAuthenticationMethodModel {
        return repository.getAuthenticationMethod().toDomainLayer()
    }
    suspend fun getAuthenticationMethod() = repository.getAuthenticationMethod()

    /**
     * Attempts to authenticate the user and unlock the device.
@@ -211,13 +198,13 @@ constructor(
                // attempt.
                isThrottled.value -> true
                // The pattern is too short; skip the attempt.
                authMethod == DomainLayerAuthenticationMethodModel.Pattern &&
                authMethod == AuthenticationMethodModel.Pattern &&
                    input.size < repository.minPatternLength -> true
                // Auto-confirm attempt when the feature is not enabled; skip the attempt.
                tryAutoConfirm && !isAutoConfirmEnabled.value -> true
                // Auto-confirm should skip the attempt if the pin entered is too short.
                tryAutoConfirm &&
                    authMethod == DomainLayerAuthenticationMethodModel.Pin &&
                    authMethod == AuthenticationMethodModel.Pin &&
                    input.size < repository.getPinLength() -> true
                else -> false
            }
@@ -303,15 +290,15 @@ constructor(
        }
    }

    private fun DomainLayerAuthenticationMethodModel.createCredential(
    private fun AuthenticationMethodModel.createCredential(
        input: List<Any>
    ): LockscreenCredential? {
        return when (this) {
            is DomainLayerAuthenticationMethodModel.Pin ->
            is AuthenticationMethodModel.Pin ->
                LockscreenCredential.createPin(input.joinToString(""))
            is DomainLayerAuthenticationMethodModel.Password ->
            is AuthenticationMethodModel.Password ->
                LockscreenCredential.createPassword(input.joinToString(""))
            is DomainLayerAuthenticationMethodModel.Pattern ->
            is AuthenticationMethodModel.Pattern ->
                LockscreenCredential.createPattern(
                    input
                        .map { it as AuthenticationPatternCoordinate }
@@ -321,23 +308,6 @@ constructor(
        }
    }

    private suspend fun DataLayerAuthenticationMethodModel.toDomainLayer():
        DomainLayerAuthenticationMethodModel {
        return when (this) {
            is DataLayerAuthenticationMethodModel.None ->
                if (deviceEntryRepository.isInsecureLockscreenEnabled()) {
                    DomainLayerAuthenticationMethodModel.Swipe
                } else {
                    DomainLayerAuthenticationMethodModel.None
                }
            is DataLayerAuthenticationMethodModel.Pin -> DomainLayerAuthenticationMethodModel.Pin
            is DataLayerAuthenticationMethodModel.Password ->
                DomainLayerAuthenticationMethodModel.Password
            is DataLayerAuthenticationMethodModel.Pattern ->
                DomainLayerAuthenticationMethodModel.Pattern
        }
    }

    companion object {
        const val TAG = "AuthenticationInteractor"
    }
+0 −40
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.authentication.domain.model

/** Enumerates all known authentication methods. */
sealed class AuthenticationMethodModel(
    /**
     * Whether the authentication method is considered to be "secure".
     *
     * "Secure" authentication methods require authentication to unlock the device. Non-secure auth
     * methods simply require user dismissal.
     */
    open val isSecure: Boolean,
) {
    /** There is no authentication method on the device. We shouldn't even show the lock screen. */
    object None : AuthenticationMethodModel(isSecure = false)

    /** The most basic authentication method. The lock screen can be swiped away when displayed. */
    object Swipe : AuthenticationMethodModel(isSecure = false)

    object Pin : AuthenticationMethodModel(isSecure = true)

    object Password : AuthenticationMethodModel(isSecure = true)

    object Pattern : AuthenticationMethodModel(isSecure = true)
}
+6 −3
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package com.android.systemui.authentication.data.model
package com.android.systemui.authentication.shared.model

/** Enumerates all known authentication methods. */
sealed class AuthenticationMethodModel(
@@ -26,7 +26,10 @@ sealed class AuthenticationMethodModel(
     */
    open val isSecure: Boolean,
) {
    /** There is no authentication method on the device. We shouldn't even show the lock screen. */
    /**
     * Device doesn't use a secure authentication method. Either there is no lockscreen or the lock
     * screen can be swiped away when displayed.
     */
    object None : AuthenticationMethodModel(isSecure = false)

    object Pin : AuthenticationMethodModel(isSecure = true)
Loading