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 41 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 66 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 83 fun logUpdateDeviceEntryIndication( 84 animate: Boolean, 85 visible: Boolean, 86 dozing: Boolean, 87 ) { 88 buffer.log( 89 KeyguardIndicationController.TAG, 90 LogLevel.DEBUG, 91 { 92 bool1 = animate 93 bool2 = visible 94 bool3 = dozing 95 }, 96 { "updateDeviceEntryIndication animate:$bool1 visible:$bool2 dozing $bool3" } 97 ) 98 } 99 100 fun logUpdateBatteryIndication( 101 powerIndication: String, 102 pluggedIn: Boolean, 103 ) { 104 buffer.log( 105 KeyguardIndicationController.TAG, 106 LogLevel.DEBUG, 107 { 108 str1 = powerIndication 109 bool1 = pluggedIn 110 }, 111 { "updateBatteryIndication powerIndication:$str1 pluggedIn:$bool1" } 112 ) 113 } 114 115 fun logKeyguardSwitchIndication( 116 type: Int, 117 message: String?, 118 ) { 119 buffer.log( 120 KeyguardIndicationController.TAG, 121 LogLevel.DEBUG, 122 { 123 int1 = type 124 str1 = message 125 }, 126 { "keyguardSwitchIndication ${getKeyguardSwitchIndicationNonSensitiveLog(int1, str1)}" } 127 ) 128 } 129 130 fun logRefreshBatteryInfo( 131 isChargingOrFull: Boolean, 132 powerPluggedIn: Boolean, 133 batteryLevel: Int, 134 batteryOverheated: Boolean 135 ) { 136 buffer.log( 137 KeyguardIndicationController.TAG, 138 LogLevel.DEBUG, 139 { 140 bool1 = isChargingOrFull 141 bool2 = powerPluggedIn 142 bool3 = batteryOverheated 143 int1 = batteryLevel 144 }, 145 { 146 "refreshBatteryInfo isChargingOrFull:$bool1 powerPluggedIn:$bool2" + 147 " batteryOverheated:$bool3 batteryLevel:$int1" 148 } 149 ) 150 } 151 152 fun getKeyguardSwitchIndicationNonSensitiveLog(type: Int, message: String?): String { 153 // only show the battery string. other strings may contain sensitive info 154 return if (type == KeyguardIndicationRotateTextViewController.INDICATION_TYPE_BATTERY) { 155 "type=${KeyguardIndicationRotateTextViewController.indicationTypeToString(type)}" + 156 " message=$message" 157 } else { 158 "type=${KeyguardIndicationRotateTextViewController.indicationTypeToString(type)}" 159 } 160 } 161 162 fun notShowingUnlockRipple(keyguardNotShowing: Boolean, unlockNotAllowed: Boolean) { 163 buffer.log( 164 AuthRippleController.TAG, 165 LogLevel.DEBUG, 166 { 167 bool1 = keyguardNotShowing 168 bool2 = unlockNotAllowed 169 }, 170 { "Not showing unlock ripple: keyguardNotShowing: $bool1, unlockNotAllowed: $bool2" } 171 ) 172 } 173 174 fun showingUnlockRippleAt(x: Int, y: Int, context: String) { 175 buffer.log( 176 AuthRippleController.TAG, 177 LogLevel.DEBUG, 178 { 179 int1 = x 180 int2 = y 181 str1 = context 182 }, 183 { "Showing unlock ripple with center (x, y): ($int1, $int2), context: $str1" } 184 ) 185 } 186 } 187