• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.keyguard.data.repository
18 
19 import android.content.testableContext
20 import com.android.systemui.dump.dumpManager
21 import com.android.systemui.kosmos.Kosmos
22 import com.android.systemui.kosmos.Kosmos.Fixture
23 import com.android.systemui.kosmos.testDispatcher
24 import com.android.systemui.res.R
25 import com.android.systemui.statusbar.policy.DevicePostureController
26 import com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_CLOSED
27 import com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN
28 import com.android.systemui.util.mockito.withArgCaptor
29 import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository
30 import org.mockito.ArgumentMatchers.any
31 import org.mockito.Mockito.never
32 import org.mockito.Mockito.verify
33 
<lambda>null34 val Kosmos.keyguardBypassRepository: KeyguardBypassRepository by Fixture {
35     KeyguardBypassRepository(
36         testableContext.resources,
37         biometricSettingsRepository,
38         devicePostureRepository,
39         dumpManager,
40         userAwareSecureSettingsRepository,
41         testDispatcher,
42     )
43 }
44 
configureKeyguardBypassnull45 fun Kosmos.configureKeyguardBypass(
46     isBypassAvailable: Boolean? = null,
47     faceAuthEnrolledAndEnabled: Boolean = true,
48     faceUnlockBypassOverrideConfig: Int = 0, /* FACE_UNLOCK_BYPASS_NO_OVERRIDE */
49     faceAuthPostureConfig: Int = DEVICE_POSTURE_UNKNOWN,
50 ) {
51     when (isBypassAvailable) {
52         null -> {
53             biometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(faceAuthEnrolledAndEnabled)
54             testableContext.orCreateTestableResources.addOverride(
55                 R.integer.config_face_unlock_bypass_override,
56                 faceUnlockBypassOverrideConfig,
57             )
58             testableContext.orCreateTestableResources.addOverride(
59                 R.integer.config_face_auth_supported_posture,
60                 faceAuthPostureConfig,
61             )
62         }
63         true -> {
64             biometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(true)
65             testableContext.orCreateTestableResources.addOverride(
66                 R.integer.config_face_unlock_bypass_override,
67                 1, /* FACE_UNLOCK_BYPASS_ALWAYS */
68             )
69             testableContext.orCreateTestableResources.addOverride(
70                 R.integer.config_face_auth_supported_posture,
71                 DEVICE_POSTURE_UNKNOWN,
72             )
73         }
74         false -> {
75             biometricSettingsRepository.setIsFaceAuthEnrolledAndEnabled(false)
76             testableContext.orCreateTestableResources.addOverride(
77                 R.integer.config_face_unlock_bypass_override,
78                 2, /* FACE_UNLOCK_BYPASS_NEVER */
79             )
80             testableContext.orCreateTestableResources.addOverride(
81                 R.integer.config_face_auth_supported_posture,
82                 DEVICE_POSTURE_CLOSED,
83             )
84         }
85     }
86 }
87 
verifyCallbacknull88 fun DevicePostureController.verifyCallback() =
89     withArgCaptor<DevicePostureController.Callback> {
90         verify(this@verifyCallback).addCallback(capture())
91     }
92 
verifyNoCallbacknull93 fun DevicePostureController.verifyNoCallback() =
94     verify(this@verifyNoCallback, never()).addCallback(any())
95