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 package com.android.launcher3.taskbar
17 
18 import android.app.KeyguardManager
19 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BACK_DISABLED
20 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BOUNCER_SHOWING
21 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_DEVICE_DOZING
22 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING
23 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED
24 import org.junit.Before
25 import org.junit.Test
26 import org.mockito.kotlin.any
27 import org.mockito.kotlin.mock
28 import org.mockito.kotlin.never
29 import org.mockito.kotlin.times
30 import org.mockito.kotlin.verify
31 import org.mockito.kotlin.whenever
32 
33 class TaskbarKeyguardControllerTest : TaskbarBaseTestCase() {
34 
35     private val baseDragLayer: TaskbarDragLayer = mock()
36     private val keyguardManager: KeyguardManager = mock()
37 
38     @Before
setupnull39     override fun setup() {
40         super.setup()
41         whenever(taskbarActivityContext.getSystemService(KeyguardManager::class.java))
42             .thenReturn(keyguardManager)
43         whenever(baseDragLayer.childCount).thenReturn(0)
44         whenever(taskbarActivityContext.dragLayer).thenReturn(baseDragLayer)
45 
46         taskbarKeyguardController = TaskbarKeyguardController(taskbarActivityContext)
47         taskbarKeyguardController.init(navbarButtonsViewController)
48     }
49 
50     @Test
uninterestingFlags_noActionsnull51     fun uninterestingFlags_noActions() {
52         setFlags(0)
53         verify(navbarButtonsViewController, never()).setKeyguardVisible(any(), any())
54     }
55 
56     @Test
keyguardShowingnull57     fun keyguardShowing() {
58         setFlags(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING)
59         verify(navbarButtonsViewController, times(1))
60             .setKeyguardVisible(true /*isKeyguardVisible*/, false /*isKeyguardOccluded*/)
61     }
62 
63     @Test
dozingShowingnull64     fun dozingShowing() {
65         setFlags(SYSUI_STATE_DEVICE_DOZING)
66         verify(navbarButtonsViewController, times(1))
67             .setKeyguardVisible(true /*isKeyguardVisible*/, false /*isKeyguardOccluded*/)
68     }
69 
70     @Test
keyguardOccludednull71     fun keyguardOccluded() {
72         setFlags(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED)
73         verify(navbarButtonsViewController, times(1))
74             .setKeyguardVisible(false /*isKeyguardVisible*/, true /*isKeyguardOccluded*/)
75     }
76 
77     @Test
keyguardOccludedAndDozingnull78     fun keyguardOccludedAndDozing() {
79         setFlags(SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED.or(SYSUI_STATE_DEVICE_DOZING))
80         verify(navbarButtonsViewController, times(1))
81             .setKeyguardVisible(true /*isKeyguardVisible*/, true /*isKeyguardOccluded*/)
82     }
83 
84     @Test
deviceInsecure_hideBackForBouncernull85     fun deviceInsecure_hideBackForBouncer() {
86         whenever(keyguardManager.isDeviceSecure).thenReturn(false)
87         setFlags(SYSUI_STATE_BOUNCER_SHOWING)
88 
89         verify(navbarButtonsViewController, times(1)).setBackForBouncer(false)
90     }
91 
92     @Test
deviceSecure_showBackForBouncernull93     fun deviceSecure_showBackForBouncer() {
94         whenever(keyguardManager.isDeviceSecure).thenReturn(true)
95         setFlags(SYSUI_STATE_BOUNCER_SHOWING)
96 
97         verify(navbarButtonsViewController, times(1)).setBackForBouncer(true)
98     }
99 
100     @Test
backDisabled_hideBackForBouncernull101     fun backDisabled_hideBackForBouncer() {
102         whenever(keyguardManager.isDeviceSecure).thenReturn(true)
103         setFlags(SYSUI_STATE_BACK_DISABLED.or(SYSUI_STATE_BOUNCER_SHOWING))
104 
105         verify(navbarButtonsViewController, times(1)).setBackForBouncer(false)
106     }
107 
setFlagsnull108     private fun setFlags(flags: Long) {
109         taskbarKeyguardController.updateStateForSysuiFlags(flags)
110     }
111 }
112