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

Commit 881c023d authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Create and use AuthRippleInteractor" into main

parents ef0483aa 513ef0bf
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.keyguard.LockIconView
import com.android.keyguard.LockIconViewController
import com.android.systemui.Flags.keyguardBottomAreaRefactor
import com.android.systemui.biometrics.AuthController
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor
import com.android.systemui.flags.FeatureFlagsClassic
import com.android.systemui.flags.Flags
@@ -47,10 +48,12 @@ import com.android.systemui.res.R
import com.android.systemui.statusbar.VibratorHelper
import dagger.Lazy
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope

class LockSection
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    private val windowManager: WindowManager,
    private val authController: AuthController,
    private val featureFlags: FeatureFlagsClassic,
@@ -76,6 +79,7 @@ constructor(
                        DeviceEntryIconView(context, null).apply {
                            id = R.id.device_entry_icon_view
                            DeviceEntryIconViewBinder.bind(
                                applicationScope,
                                this,
                                deviceEntryIconViewModel.get(),
                                deviceEntryForegroundViewModel.get(),
+87 −0
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.deviceentry.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.data.repository.fingerprintPropertyRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class AuthRippleInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val deviceEntrySourceInteractor = kosmos.deviceEntrySourceInteractor
    private val fingerprintPropertyRepository = kosmos.fingerprintPropertyRepository
    private val keyguardRepository = kosmos.fakeKeyguardRepository
    private val underTest = kosmos.authRippleInteractor

    @Test
    fun enteringDeviceFromDeviceEntryIcon_udfpsNotSupported_doesNotShowAuthRipple() =
        testScope.runTest {
            val showUnlockRipple by collectLastValue(underTest.showUnlockRipple)
            fingerprintPropertyRepository.supportsRearFps()
            keyguardRepository.setKeyguardDismissible(true)
            runCurrent()
            deviceEntrySourceInteractor.attemptEnterDeviceFromDeviceEntryIcon()
            assertThat(showUnlockRipple).isNull()
        }

    @Test
    fun enteringDeviceFromDeviceEntryIcon_udfpsSupported_showsAuthRipple() =
        testScope.runTest {
            val showUnlockRipple by collectLastValue(underTest.showUnlockRipple)
            fingerprintPropertyRepository.supportsUdfps()
            keyguardRepository.setKeyguardDismissible(true)
            runCurrent()
            deviceEntrySourceInteractor.attemptEnterDeviceFromDeviceEntryIcon()
            assertThat(showUnlockRipple).isEqualTo(BiometricUnlockSource.FINGERPRINT_SENSOR)
        }

    @Test
    fun faceUnlocked_showsAuthRipple() =
        testScope.runTest {
            val showUnlockRipple by collectLastValue(underTest.showUnlockRipple)
            keyguardRepository.setBiometricUnlockSource(BiometricUnlockSource.FACE_SENSOR)
            keyguardRepository.setBiometricUnlockState(BiometricUnlockModel.WAKE_AND_UNLOCK)
            assertThat(showUnlockRipple).isEqualTo(BiometricUnlockSource.FACE_SENSOR)
        }

    @Test
    fun fingerprintUnlocked_showsAuthRipple() =
        testScope.runTest {
            val showUnlockRippleFromBiometricUnlock by collectLastValue(underTest.showUnlockRipple)
            keyguardRepository.setBiometricUnlockSource(BiometricUnlockSource.FINGERPRINT_SENSOR)
            keyguardRepository.setBiometricUnlockState(BiometricUnlockModel.WAKE_AND_UNLOCK)
            assertThat(showUnlockRippleFromBiometricUnlock)
                .isEqualTo(BiometricUnlockSource.FINGERPRINT_SENSOR)
        }
}
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.deviceentry.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class DeviceEntrySourceInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val keyguardRepository = kosmos.fakeKeyguardRepository
    private val underTest = kosmos.deviceEntrySourceInteractor

    @Test
    fun deviceEntryFromFaceUnlock() =
        testScope.runTest {
            val deviceEntryFromBiometricAuthentication by
                collectLastValue(underTest.deviceEntryFromBiometricSource)
            keyguardRepository.setBiometricUnlockSource(BiometricUnlockSource.FACE_SENSOR)
            keyguardRepository.setBiometricUnlockState(BiometricUnlockModel.WAKE_AND_UNLOCK)
            runCurrent()
            assertThat(deviceEntryFromBiometricAuthentication)
                .isEqualTo(BiometricUnlockSource.FACE_SENSOR)
        }

    @Test
    fun deviceEntryFromFingerprintUnlock() = runTest {
        val deviceEntryFromBiometricAuthentication by
            collectLastValue(underTest.deviceEntryFromBiometricSource)
        keyguardRepository.setBiometricUnlockSource(BiometricUnlockSource.FINGERPRINT_SENSOR)
        keyguardRepository.setBiometricUnlockState(BiometricUnlockModel.WAKE_AND_UNLOCK)
        runCurrent()
        assertThat(deviceEntryFromBiometricAuthentication)
            .isEqualTo(BiometricUnlockSource.FINGERPRINT_SENSOR)
    }

    @Test
    fun noDeviceEntry() = runTest {
        val deviceEntryFromBiometricAuthentication by
            collectLastValue(underTest.deviceEntryFromBiometricSource)
        keyguardRepository.setBiometricUnlockSource(BiometricUnlockSource.FINGERPRINT_SENSOR)
        // doesn't dismiss keyguard:
        keyguardRepository.setBiometricUnlockState(BiometricUnlockModel.ONLY_WAKE)
        runCurrent()
        assertThat(deviceEntryFromBiometricAuthentication).isNull()
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -238,10 +238,10 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
        }

    @Test
    fun isKeyguardUnlocked() =
    fun isKeyguardDismissible() =
        testScope.runTest {
            whenever(keyguardStateController.isUnlocked).thenReturn(false)
            val isKeyguardUnlocked by collectLastValue(underTest.isKeyguardUnlocked)
            val isKeyguardUnlocked by collectLastValue(underTest.isKeyguardDismissible)

            runCurrent()
            assertThat(isKeyguardUnlocked).isFalse()
+6 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import com.android.systemui.bouncer.domain.interactor.PrimaryBouncerInteractor;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor;
import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
@@ -87,6 +88,8 @@ import java.util.function.Consumer;

import javax.inject.Inject;

import kotlinx.coroutines.ExperimentalCoroutinesApi;

/**
 * Controls when to show the LockIcon affordance (lock/unlocked icon or circle) on lock screen.
 *
@@ -717,6 +720,7 @@ public class LockIconViewController implements Dumpable {
        return mDownDetected;
    }

    @ExperimentalCoroutinesApi
    @VisibleForTesting
    protected void onLongPress() {
        cancelTouches();
@@ -727,7 +731,8 @@ public class LockIconViewController implements Dumpable {

        // pre-emptively set to true to hide view
        mIsBouncerShowing = true;
        if (mUdfpsSupported && mShowUnlockIcon && mAuthRippleController != null) {
        if (!DeviceEntryUdfpsRefactor.isEnabled()
                && mUdfpsSupported && mShowUnlockIcon && mAuthRippleController != null) {
            mAuthRippleController.showUnlockRipple(FINGERPRINT);
        }
        updateVisibility();
Loading