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 18 19 import android.annotation.CurrentTimeMillisLong 20 import com.android.systemui.common.buffer.RingBuffer 21 import com.android.systemui.dump.DumpsysTableLogger 22 import com.android.systemui.dump.Row 23 24 /** Verbose debug information. */ 25 data class KeyguardFingerprintListenModel( 26 @CurrentTimeMillisLong override var timeMillis: Long = 0L, 27 override var userId: Int = 0, 28 override var listening: Boolean = false, 29 // keepSorted 30 var allowOnCurrentOccludingActivity: Boolean = false, 31 var alternateBouncerShowing: Boolean = false, 32 var biometricEnabledForUser: Boolean = false, 33 var biometricPromptShowing: Boolean = false, 34 var bouncerIsOrWillShow: Boolean = false, 35 var canSkipBouncer: Boolean = false, 36 var credentialAttempted: Boolean = false, 37 var deviceInteractive: Boolean = false, 38 var dreaming: Boolean = false, 39 var fingerprintDisabled: Boolean = false, 40 var fingerprintLockedOut: Boolean = false, 41 var goingToSleep: Boolean = false, 42 var keyguardGoingAway: Boolean = false, 43 var keyguardIsVisible: Boolean = false, 44 var keyguardOccluded: Boolean = false, 45 var occludingAppRequestingFp: Boolean = false, 46 var shouldListenForFingerprintAssistant: Boolean = false, 47 var strongerAuthRequired: Boolean = false, 48 var switchingUser: Boolean = false, 49 var systemUser: Boolean = false, 50 var udfps: Boolean = false, 51 var userDoesNotHaveTrust: Boolean = false, 52 var communalShowing: Boolean = false, 53 ) : KeyguardListenModel() { 54 55 /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */ <lambda>null56 val asStringList: List<String> by lazy { 57 listOf( 58 DATE_FORMAT.format(timeMillis), 59 timeMillis.toString(), 60 userId.toString(), 61 listening.toString(), 62 // keep sorted 63 allowOnCurrentOccludingActivity.toString(), 64 alternateBouncerShowing.toString(), 65 biometricEnabledForUser.toString(), 66 biometricPromptShowing.toString(), 67 bouncerIsOrWillShow.toString(), 68 canSkipBouncer.toString(), 69 credentialAttempted.toString(), 70 deviceInteractive.toString(), 71 dreaming.toString(), 72 fingerprintDisabled.toString(), 73 fingerprintLockedOut.toString(), 74 goingToSleep.toString(), 75 keyguardGoingAway.toString(), 76 keyguardIsVisible.toString(), 77 keyguardOccluded.toString(), 78 occludingAppRequestingFp.toString(), 79 shouldListenForFingerprintAssistant.toString(), 80 strongerAuthRequired.toString(), 81 switchingUser.toString(), 82 systemUser.toString(), 83 udfps.toString(), 84 userDoesNotHaveTrust.toString(), 85 communalShowing.toString(), 86 ) 87 } 88 89 /** 90 * [RingBuffer] to store [KeyguardFingerprintListenModel]. After the buffer is full, it will 91 * recycle old events. 92 * 93 * Do not use [append] to add new elements. Instead use [insert], as it will recycle if 94 * necessary. 95 */ 96 class Buffer { <lambda>null97 private val buffer = RingBuffer(CAPACITY) { KeyguardFingerprintListenModel() } 98 insertnull99 fun insert(model: KeyguardFingerprintListenModel) { 100 buffer.advance().apply { 101 timeMillis = model.timeMillis 102 userId = model.userId 103 listening = model.listening 104 // keep sorted 105 allowOnCurrentOccludingActivity = model.allowOnCurrentOccludingActivity 106 alternateBouncerShowing = model.alternateBouncerShowing 107 biometricEnabledForUser = model.biometricEnabledForUser 108 biometricPromptShowing = model.biometricPromptShowing 109 bouncerIsOrWillShow = model.bouncerIsOrWillShow 110 canSkipBouncer = model.canSkipBouncer 111 credentialAttempted = model.credentialAttempted 112 deviceInteractive = model.deviceInteractive 113 dreaming = model.dreaming 114 fingerprintDisabled = model.fingerprintDisabled 115 fingerprintLockedOut = model.fingerprintLockedOut 116 goingToSleep = model.goingToSleep 117 keyguardGoingAway = model.keyguardGoingAway 118 keyguardIsVisible = model.keyguardIsVisible 119 keyguardOccluded = model.keyguardOccluded 120 occludingAppRequestingFp = model.occludingAppRequestingFp 121 shouldListenForFingerprintAssistant = model.shouldListenForFingerprintAssistant 122 strongerAuthRequired = model.strongerAuthRequired 123 switchingUser = model.switchingUser 124 systemUser = model.systemUser 125 udfps = model.udfps 126 userDoesNotHaveTrust = model.userDoesNotHaveTrust 127 communalShowing = model.communalShowing 128 } 129 } 130 131 /** 132 * Returns the content of the buffer (sorted from latest to newest). 133 * 134 * @see KeyguardFingerprintListenModel.asStringList 135 */ toListnull136 fun toList(): List<Row> { 137 return buffer.asSequence().map { it.asStringList }.toList() 138 } 139 } 140 141 companion object { 142 const val CAPACITY = 20 // number of logs to retain 143 144 /** Headers for dumping a table using [DumpsysTableLogger]. */ 145 @JvmField 146 val TABLE_HEADERS = 147 listOf( 148 "timestamp", 149 "time_millis", 150 "userId", 151 "listening", 152 // keep sorted 153 "allowOnCurrentOccludingActivity", 154 "alternateBouncerShowing", 155 "biometricAllowedForUser", 156 "biometricPromptShowing", 157 "bouncerIsOrWillShow", 158 "canSkipBouncer", 159 "credentialAttempted", 160 "deviceInteractive", 161 "dreaming", 162 "fingerprintDisabled", 163 "fingerprintLockedOut", 164 "goingToSleep", 165 "keyguardGoingAway", 166 "keyguardIsVisible", 167 "keyguardOccluded", 168 "occludingAppRequestingFp", 169 "shouldListenSidFingerprintState", 170 "shouldListenForFingerprintAssistant", 171 "strongAuthRequired", 172 "switchingUser", 173 "systemUser", 174 "underDisplayFingerprint", 175 "userDoesNotHaveTrust", 176 "communalShowing", 177 ) 178 } 179 } 180