1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar 18 19 import android.testing.TestableLooper 20 import android.view.View 21 import androidx.test.ext.junit.runners.AndroidJUnit4 22 import androidx.test.filters.SmallTest 23 import com.android.systemui.flags.Flags.LOCKSCREEN_WALLPAPER_DREAM_ENABLED 24 import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BIOMETRIC_MESSAGE 25 import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BIOMETRIC_MESSAGE_FOLLOW_UP 26 import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController.INDICATION_TYPE_TRUST 27 import kotlinx.coroutines.Dispatchers 28 import kotlinx.coroutines.flow.MutableStateFlow 29 import kotlinx.coroutines.runBlocking 30 import org.junit.Test 31 import org.junit.runner.RunWith 32 import org.mockito.Mockito.times 33 import org.mockito.Mockito.verify 34 import org.mockito.kotlin.whenever 35 36 @RunWith(AndroidJUnit4::class) 37 @SmallTest 38 @TestableLooper.RunWithLooper(setAsMainLooper = true) 39 class KeyguardIndicationControllerWithCoroutinesTest : KeyguardIndicationControllerBaseTest() { 40 @Test testIndicationAreaVisibility_onLockscreenHostedDreamStateChangednull41 fun testIndicationAreaVisibility_onLockscreenHostedDreamStateChanged() = 42 runBlocking(IMMEDIATE) { 43 // GIVEN starting state for keyguard indication and wallpaper dream enabled 44 createController() 45 mFlags.set(LOCKSCREEN_WALLPAPER_DREAM_ENABLED, true) 46 mController.setVisible(true) 47 48 // THEN indication area is visible 49 verify(mIndicationArea, times(2)).visibility = View.VISIBLE 50 51 // WHEN the device is dreaming with lockscreen hosted dream 52 mController.mIsActiveDreamLockscreenHostedCallback.accept( 53 true /* isActiveDreamLockscreenHosted */ 54 ) 55 mExecutor.runAllReady() 56 57 // THEN the indication area is hidden 58 verify(mIndicationArea).visibility = View.GONE 59 60 // WHEN the device stops dreaming with lockscreen hosted dream 61 mController.mIsActiveDreamLockscreenHostedCallback.accept( 62 false /* isActiveDreamLockscreenHosted */ 63 ) 64 mExecutor.runAllReady() 65 66 // THEN indication area is set visible 67 verify(mIndicationArea, times(3)).visibility = View.VISIBLE 68 } 69 70 @Test onTrustAgentErrorMessageDelayed_fingerprintEngagednull71 fun onTrustAgentErrorMessageDelayed_fingerprintEngaged() { 72 createController() 73 mController.setVisible(true) 74 75 // GIVEN fingerprint is engaged 76 whenever(mDeviceEntryFingerprintAuthInteractor.isEngaged).thenReturn(MutableStateFlow(true)) 77 78 // WHEN a trust agent error message arrives 79 mKeyguardUpdateMonitorCallback.onTrustAgentErrorMessage("testMessage") 80 mExecutor.runAllReady() 81 82 // THEN no message shows immediately since fingerprint is engaged 83 verifyNoMessage(INDICATION_TYPE_TRUST) 84 verifyNoMessage(INDICATION_TYPE_BIOMETRIC_MESSAGE) 85 verifyNoMessage(INDICATION_TYPE_BIOMETRIC_MESSAGE_FOLLOW_UP) 86 87 // WHEN fingerprint is no longer engaged 88 whenever(mDeviceEntryFingerprintAuthInteractor.isEngaged) 89 .thenReturn(MutableStateFlow(false)) 90 mController.mIsFingerprintEngagedCallback.accept(false) 91 mExecutor.runAllReady() 92 93 // THEN the message will show 94 verifyIndicationShown(INDICATION_TYPE_BIOMETRIC_MESSAGE, "testMessage") 95 } 96 97 companion object { 98 private val IMMEDIATE = Dispatchers.Main.immediate 99 } 100 } 101