• 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.domain.interactor
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.dagger.qualifiers.Application
21 import com.android.systemui.keyguard.data.repository.TrustRepository
22 import javax.inject.Inject
23 import kotlinx.coroutines.CoroutineScope
24 import kotlinx.coroutines.flow.StateFlow
25 import com.android.app.tracing.coroutines.launchTraced as launch
26 
27 /** Encapsulates any state relevant to trust agents and trust grants. */
28 @SysUISingleton
29 class TrustInteractor
30 @Inject
31 constructor(
32     @Application private val applicationScope: CoroutineScope,
33     private val repository: TrustRepository,
34 ) {
35     /**
36      * Whether the current user has a trust agent enabled. This is true if the user has at least one
37      * trust agent enabled in settings.
38      */
39     val isEnrolledAndEnabled: StateFlow<Boolean> = repository.isCurrentUserTrustUsuallyManaged
40 
41     /**
42      * Whether the current user's trust agent is currently allowed, this will be false if trust
43      * agent is disabled for any reason (security timeout, disabled on lock screen by opening the
44      * power menu, etc), it does not include temporary biometric lockouts.
45      */
46     val isTrustAgentCurrentlyAllowed: StateFlow<Boolean> = repository.isCurrentUserTrustManaged
47 
48     /** Whether the current user is trusted by any of the enabled trust agents. */
49     val isTrusted: StateFlow<Boolean> = repository.isCurrentUserTrusted
50 
51     /** Reports a keyguard visibility change. */
reportKeyguardShowingChangednull52     fun reportKeyguardShowingChanged() {
53         applicationScope.launch { repository.reportKeyguardShowingChanged() }
54     }
55 }
56