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.dagger.SysUISingleton
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel.DEBUG
22 import com.android.systemui.log.dagger.BiometricLog
23 import javax.inject.Inject
24 
25 /** Helper class for logging for [com.android.systemui.biometrics.FaceHelpMessageDeferral] */
26 @SysUISingleton
27 class FaceMessageDeferralLogger
28 @Inject
29 constructor(@BiometricLog private val logBuffer: LogBuffer) :
30     BiometricMessageDeferralLogger(logBuffer, "FaceMessageDeferralLogger")
31 
32 open class BiometricMessageDeferralLogger(
33     private val logBuffer: LogBuffer,
34     private val tag: String
35 ) {
36     fun reset() {
37         logBuffer.log(tag, DEBUG, "reset")
38     }
39 
40     fun logUpdateMessage(acquiredInfo: Int, helpString: String) {
41         logBuffer.log(
42             tag,
43             DEBUG,
44             {
45                 int1 = acquiredInfo
46                 str1 = helpString
47             },
48             { "updateMessage acquiredInfo=$int1 helpString=$str1" }
49         )
50     }
51 
52     fun logFrameIgnored(
53         acquiredInfo: Int,
54     ) {
55         logBuffer.log(tag, DEBUG, { int1 = acquiredInfo }, { "frameIgnored acquiredInfo=$int1" })
56     }
57 
58     fun logFrameProcessed(
59         acquiredInfo: Int,
60         totalFrames: Int,
61         mostFrequentAcquiredInfoToDefer: String? // may not meet the threshold
62     ) {
63         logBuffer.log(
64             tag,
65             DEBUG,
66             {
67                 int1 = acquiredInfo
68                 int2 = totalFrames
69                 str1 = mostFrequentAcquiredInfoToDefer
70             },
71             {
72                 "frameProcessed acquiredInfo=$int1 totalFrames=$int2 " +
73                     "messageToShowOnTimeout=$str1"
74             }
75         )
76     }
77 }
78