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 ) : KeyguardListenModel() { 53 54 /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */ <lambda>null55 val asStringList: List<String> by lazy { 56 listOf( 57 DATE_FORMAT.format(timeMillis), 58 timeMillis.toString(), 59 userId.toString(), 60 listening.toString(), 61 // keep sorted 62 allowOnCurrentOccludingActivity.toString(), 63 alternateBouncerShowing.toString(), 64 biometricEnabledForUser.toString(), 65 biometricPromptShowing.toString(), 66 bouncerIsOrWillShow.toString(), 67 canSkipBouncer.toString(), 68 credentialAttempted.toString(), 69 deviceInteractive.toString(), 70 dreaming.toString(), 71 fingerprintDisabled.toString(), 72 fingerprintLockedOut.toString(), 73 goingToSleep.toString(), 74 keyguardGoingAway.toString(), 75 keyguardIsVisible.toString(), 76 keyguardOccluded.toString(), 77 occludingAppRequestingFp.toString(), 78 shouldListenForFingerprintAssistant.toString(), 79 strongerAuthRequired.toString(), 80 switchingUser.toString(), 81 systemUser.toString(), 82 udfps.toString(), 83 userDoesNotHaveTrust.toString(), 84 ) 85 } 86 87 /** 88 * [RingBuffer] to store [KeyguardFingerprintListenModel]. After the buffer is full, it will 89 * recycle old events. 90 * 91 * Do not use [append] to add new elements. Instead use [insert], as it will recycle if 92 * necessary. 93 */ 94 class Buffer { <lambda>null95 private val buffer = RingBuffer(CAPACITY) { KeyguardFingerprintListenModel() } 96 insertnull97 fun insert(model: KeyguardFingerprintListenModel) { 98 buffer.advance().apply { 99 timeMillis = model.timeMillis 100 userId = model.userId 101 listening = model.listening 102 // keep sorted 103 allowOnCurrentOccludingActivity = model.allowOnCurrentOccludingActivity 104 alternateBouncerShowing = model.alternateBouncerShowing 105 biometricEnabledForUser = model.biometricEnabledForUser 106 biometricPromptShowing = model.biometricPromptShowing 107 bouncerIsOrWillShow = model.bouncerIsOrWillShow 108 canSkipBouncer = model.canSkipBouncer 109 credentialAttempted = model.credentialAttempted 110 deviceInteractive = model.deviceInteractive 111 dreaming = model.dreaming 112 fingerprintDisabled = model.fingerprintDisabled 113 fingerprintLockedOut = model.fingerprintLockedOut 114 goingToSleep = model.goingToSleep 115 keyguardGoingAway = model.keyguardGoingAway 116 keyguardIsVisible = model.keyguardIsVisible 117 keyguardOccluded = model.keyguardOccluded 118 occludingAppRequestingFp = model.occludingAppRequestingFp 119 shouldListenForFingerprintAssistant = model.shouldListenForFingerprintAssistant 120 strongerAuthRequired = model.strongerAuthRequired 121 switchingUser = model.switchingUser 122 systemUser = model.systemUser 123 udfps = model.udfps 124 userDoesNotHaveTrust = model.userDoesNotHaveTrust 125 } 126 } 127 128 /** 129 * Returns the content of the buffer (sorted from latest to newest). 130 * 131 * @see KeyguardFingerprintListenModel.asStringList 132 */ toListnull133 fun toList(): List<Row> { 134 return buffer.asSequence().map { it.asStringList }.toList() 135 } 136 } 137 138 companion object { 139 const val CAPACITY = 20 // number of logs to retain 140 141 /** Headers for dumping a table using [DumpsysTableLogger]. */ 142 @JvmField 143 val TABLE_HEADERS = 144 listOf( 145 "timestamp", 146 "time_millis", 147 "userId", 148 "listening", 149 // keep sorted 150 "allowOnCurrentOccludingActivity", 151 "alternateBouncerShowing", 152 "biometricAllowedForUser", 153 "biometricPromptShowing", 154 "bouncerIsOrWillShow", 155 "canSkipBouncer", 156 "credentialAttempted", 157 "deviceInteractive", 158 "dreaming", 159 "fingerprintDisabled", 160 "fingerprintLockedOut", 161 "goingToSleep", 162 "keyguardGoingAway", 163 "keyguardIsVisible", 164 "keyguardOccluded", 165 "occludingAppRequestingFp", 166 "shouldListenSidFingerprintState", 167 "shouldListenForFingerprintAssistant", 168 "strongAuthRequired", 169 "switchingUser", 170 "systemUser", 171 "underDisplayFingerprint", 172 "userDoesNotHaveTrust", 173 ) 174 } 175 } 176