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.keyguard.logging
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.keyguard.shared.model.ActiveUnlockModel
21 import com.android.systemui.keyguard.shared.model.TrustManagedModel
22 import com.android.systemui.keyguard.shared.model.TrustModel
23 import com.android.systemui.log.LogBuffer
24 import com.android.systemui.log.core.LogLevel
25 import com.android.systemui.log.core.LogLevel.DEBUG
26 import com.android.systemui.log.dagger.KeyguardUpdateMonitorLog
27 import javax.inject.Inject
28 
29 /** Logging helper for trust repository. */
30 @SysUISingleton
31 class TrustRepositoryLogger
32 @Inject
33 constructor(
34     @KeyguardUpdateMonitorLog private val logBuffer: LogBuffer,
35 ) {
onTrustChangednull36     fun onTrustChanged(
37         enabled: Boolean,
38         newlyUnlocked: Boolean,
39         userId: Int,
40         flags: Int,
41         trustGrantedMessages: List<String>?
42     ) {
43         logBuffer.log(
44             TAG,
45             DEBUG,
46             {
47                 bool1 = enabled
48                 bool2 = newlyUnlocked
49                 int1 = userId
50                 int2 = flags
51                 str1 = trustGrantedMessages?.joinToString()
52             },
53             {
54                 "onTrustChanged enabled: $bool1, newlyUnlocked: $bool2, " +
55                     "userId: $int1, flags: $int2, grantMessages: $str1"
56             }
57         )
58     }
59 
trustListenerRegisterednull60     fun trustListenerRegistered() {
61         logBuffer.log(TAG, LogLevel.VERBOSE, "TrustRepository#registerTrustListener")
62     }
63 
trustListenerUnregisterednull64     fun trustListenerUnregistered() {
65         logBuffer.log(TAG, LogLevel.VERBOSE, "TrustRepository#unregisterTrustListener")
66     }
67 
trustModelEmittednull68     fun trustModelEmitted(value: TrustModel) {
69         logBuffer.log(
70             TAG,
71             DEBUG,
72             {
73                 int1 = value.userId
74                 bool1 = value.isTrusted
75             },
76             { "trustModel emitted: userId: $int1 isTrusted: $bool1" }
77         )
78     }
79 
activeUnlockModelEmittednull80     fun activeUnlockModelEmitted(value: ActiveUnlockModel) {
81         logBuffer.log(
82             TAG,
83             LogLevel.DEBUG,
84             {
85                 int1 = value.userId
86                 bool1 = value.isRunning
87             },
88             { "activeUnlockModel emitted: userId: $int1 isRunning: $bool1" }
89         )
90     }
91 
isCurrentUserTrustednull92     fun isCurrentUserTrusted(isCurrentUserTrusted: Boolean) {
93         logBuffer.log(
94             TAG,
95             DEBUG,
96             { bool1 = isCurrentUserTrusted },
97             { "isCurrentUserTrusted emitted: $bool1" }
98         )
99     }
100 
isCurrentUserActiveUnlockRunningnull101     fun isCurrentUserActiveUnlockRunning(isCurrentUserActiveUnlockRunning: Boolean) {
102         logBuffer.log(
103             TAG,
104             LogLevel.DEBUG,
105             { bool1 = isCurrentUserActiveUnlockRunning },
106             { "isCurrentUserActiveUnlockRunning emitted: $bool1" }
107         )
108     }
109 
isCurrentUserTrustManagednull110     fun isCurrentUserTrustManaged(isTrustManaged: Boolean) {
111         logBuffer.log(TAG, DEBUG, { bool1 = isTrustManaged }, { "isTrustManaged emitted: $bool1" })
112     }
113 
onTrustManagedChangednull114     fun onTrustManagedChanged(trustManaged: Boolean, userId: Int) {
115         logBuffer.log(
116             TAG,
117             DEBUG,
118             {
119                 bool1 = trustManaged
120                 int1 = userId
121             },
122             { "onTrustManagedChanged isTrustManaged: $bool1 for user: $int1" }
123         )
124     }
125 
trustManagedModelEmittednull126     fun trustManagedModelEmitted(it: TrustManagedModel) {
127         logBuffer.log(
128             TAG,
129             DEBUG,
130             {
131                 bool1 = it.isTrustManaged
132                 int1 = it.userId
133             },
134             { "trustManagedModel emitted: userId: $int1, isTrustManaged: $bool1" }
135         )
136     }
137 
138     companion object {
139         const val TAG = "TrustRepositoryLog"
140     }
141 }
142