• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.biometrics.AuthRippleController
20 import com.android.systemui.keyguard.KeyguardIndicationRotateTextViewController
21 import com.android.systemui.log.LogBuffer
22 import com.android.systemui.log.core.LogLevel
23 import com.android.systemui.log.dagger.KeyguardLog
24 import com.android.systemui.statusbar.KeyguardIndicationController
25 import com.google.errorprone.annotations.CompileTimeConstant
26 import javax.inject.Inject
27 
28 private const val BIO_TAG = "KeyguardLog"
29 
30 /**
31  * Generic logger for keyguard that's wrapping [LogBuffer]. This class should be used for adding
32  * temporary logs or logs for smaller classes when creating whole new [LogBuffer] wrapper might be
33  * an overkill.
34  */
35 class KeyguardLogger
36 @Inject
37 constructor(
38     @KeyguardLog val buffer: LogBuffer,
39 ) {
40     @JvmOverloads
lognull41     fun log(
42         tag: String,
43         level: LogLevel,
44         @CompileTimeConstant msg: String,
45         ex: Throwable? = null,
46     ) = buffer.log(tag, level, msg, ex)
47 
48     fun log(
49         tag: String,
50         level: LogLevel,
51         @CompileTimeConstant msg: String,
52         arg: Any,
53     ) {
54         buffer.log(
55             tag,
56             level,
57             {
58                 str1 = msg
59                 str2 = arg.toString()
60             },
61             { "$str1: $str2" }
62         )
63     }
64 
65     @JvmOverloads
logBiometricMessagenull66     fun logBiometricMessage(
67         @CompileTimeConstant context: String,
68         msgId: Int? = null,
69         msg: String? = null
70     ) {
71         buffer.log(
72             BIO_TAG,
73             LogLevel.DEBUG,
74             {
75                 str1 = context
76                 str2 = "$msgId"
77                 str3 = msg
78             },
79             { "$str1 msgId: $str2 msg: $str3" }
80         )
81     }
82 
delayShowingTrustAgentErrornull83     fun delayShowingTrustAgentError(
84         msg: CharSequence,
85         fpEngaged: Boolean,
86         faceRunning: Boolean,
87     ) {
88         buffer.log(
89             BIO_TAG,
90             LogLevel.DEBUG,
91             {
92                 str1 = msg.toString()
93                 bool1 = fpEngaged
94                 bool2 = faceRunning
95             },
96             { "Delay showing trustAgentError:$str1. fpEngaged:$bool1 faceRunning:$bool2 " }
97         )
98     }
99 
logUpdateDeviceEntryIndicationnull100     fun logUpdateDeviceEntryIndication(
101         animate: Boolean,
102         visible: Boolean,
103         dozing: Boolean,
104     ) {
105         buffer.log(
106             KeyguardIndicationController.TAG,
107             LogLevel.DEBUG,
108             {
109                 bool1 = animate
110                 bool2 = visible
111                 bool3 = dozing
112             },
113             { "updateDeviceEntryIndication animate:$bool1 visible:$bool2 dozing $bool3" }
114         )
115     }
116 
logUpdateLockScreenUserLockedMsgnull117     fun logUpdateLockScreenUserLockedMsg(
118         userId: Int,
119         userUnlocked: Boolean,
120         encryptedOrLockdown: Boolean,
121     ) {
122         buffer.log(
123             KeyguardIndicationController.TAG,
124             LogLevel.DEBUG,
125             {
126                 int1 = userId
127                 bool1 = userUnlocked
128                 bool2 = encryptedOrLockdown
129             },
130             {
131                 "updateLockScreenUserLockedMsg userId=$int1 " +
132                     "userUnlocked:$bool1 encryptedOrLockdown:$bool2"
133             }
134         )
135     }
136 
logDropFaceMessagenull137     fun logDropFaceMessage(
138         message: CharSequence,
139         followUpMessage: CharSequence?,
140     ) {
141         buffer.log(
142             KeyguardIndicationController.TAG,
143             LogLevel.DEBUG,
144             {
145                 str1 = message.toString()
146                 str2 = followUpMessage?.toString()
147             },
148             { "droppingFaceMessage message=$str1 followUpMessage:$str2" }
149         )
150     }
151 
logUpdateBatteryIndicationnull152     fun logUpdateBatteryIndication(
153         powerIndication: String,
154         pluggedIn: Boolean,
155     ) {
156         buffer.log(
157             KeyguardIndicationController.TAG,
158             LogLevel.DEBUG,
159             {
160                 str1 = powerIndication
161                 bool1 = pluggedIn
162             },
163             { "updateBatteryIndication powerIndication:$str1 pluggedIn:$bool1" }
164         )
165     }
166 
logKeyguardSwitchIndicationnull167     fun logKeyguardSwitchIndication(
168         type: Int,
169         message: String?,
170     ) {
171         buffer.log(
172             KeyguardIndicationController.TAG,
173             LogLevel.DEBUG,
174             {
175                 int1 = type
176                 str1 = message
177             },
178             { "keyguardSwitchIndication ${getKeyguardSwitchIndicationNonSensitiveLog(int1, str1)}" }
179         )
180     }
181 
logRefreshBatteryInfonull182     fun logRefreshBatteryInfo(
183         isChargingOrFull: Boolean,
184         powerPluggedIn: Boolean,
185         batteryLevel: Int,
186         batteryOverheated: Boolean
187     ) {
188         buffer.log(
189             KeyguardIndicationController.TAG,
190             LogLevel.DEBUG,
191             {
192                 bool1 = isChargingOrFull
193                 bool2 = powerPluggedIn
194                 bool3 = batteryOverheated
195                 int1 = batteryLevel
196             },
197             {
198                 "refreshBatteryInfo isChargingOrFull:$bool1 powerPluggedIn:$bool2" +
199                     " batteryOverheated:$bool3 batteryLevel:$int1"
200             }
201         )
202     }
203 
getKeyguardSwitchIndicationNonSensitiveLognull204     fun getKeyguardSwitchIndicationNonSensitiveLog(type: Int, message: String?): String {
205         // only show the battery string. other strings may contain sensitive info
206         return if (type == KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY) {
207             "type=${KeyguardIndicationRotateTextViewController.indicationTypeToString(type)}" +
208                 " message=$message"
209         } else {
210             "type=${KeyguardIndicationRotateTextViewController.indicationTypeToString(type)}"
211         }
212     }
213 
notShowingUnlockRipplenull214     fun notShowingUnlockRipple(keyguardNotShowing: Boolean, unlockNotAllowed: Boolean) {
215         buffer.log(
216             AuthRippleController.TAG,
217             LogLevel.DEBUG,
218             {
219                 bool1 = keyguardNotShowing
220                 bool2 = unlockNotAllowed
221             },
222             { "Not showing unlock ripple: keyguardNotShowing: $bool1, unlockNotAllowed: $bool2" }
223         )
224     }
225 
showingUnlockRippleAtnull226     fun showingUnlockRippleAt(x: Int, y: Int, context: String) {
227         buffer.log(
228             AuthRippleController.TAG,
229             LogLevel.DEBUG,
230             {
231                 int1 = x
232                 int2 = y
233                 str1 = context
234             },
235             { "Showing unlock ripple with center (x, y): ($int1, $int2), context: $str1" }
236         )
237     }
238 }
239