From eabef8f33c121a03c2e55088b6e143eefc94944a Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 9 Dec 2022 17:09:34 +0000 Subject: [PATCH] Replace KeyguardListenQueue with DumpsysTableLogger Test: manually check dumpsys & bugreport Fixes: 261993577 Change-Id: Ic12b64925982c0bc0af7f988ccbbf31a51a76850 --- .../keyguard/KeyguardActiveUnlockModel.kt | 114 ++++++++++++ .../keyguard/KeyguardFaceListenModel.kt | 162 +++++++++++++++++ .../KeyguardFingerprintListenModel.kt | 166 ++++++++++++++++++ .../android/keyguard/KeyguardListenModel.kt | 99 +++-------- .../android/keyguard/KeyguardListenQueue.kt | 73 -------- .../keyguard/KeyguardUpdateMonitor.java | 62 ++++--- .../keyguard/KeyguardListenQueueTest.kt | 105 ----------- 7 files changed, 498 insertions(+), 283 deletions(-) create mode 100644 packages/SystemUI/src/com/android/keyguard/KeyguardActiveUnlockModel.kt create mode 100644 packages/SystemUI/src/com/android/keyguard/KeyguardFaceListenModel.kt create mode 100644 packages/SystemUI/src/com/android/keyguard/KeyguardFingerprintListenModel.kt delete mode 100644 packages/SystemUI/src/com/android/keyguard/KeyguardListenQueue.kt delete mode 100644 packages/SystemUI/tests/src/com/android/keyguard/KeyguardListenQueueTest.kt diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardActiveUnlockModel.kt b/packages/SystemUI/src/com/android/keyguard/KeyguardActiveUnlockModel.kt new file mode 100644 index 0000000000000..3a89c13ddd641 --- /dev/null +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardActiveUnlockModel.kt @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.keyguard + +import android.annotation.CurrentTimeMillisLong +import com.android.systemui.dump.DumpsysTableLogger +import com.android.systemui.dump.Row +import com.android.systemui.plugins.util.RingBuffer + +/** Verbose debug information. */ +data class KeyguardActiveUnlockModel( + @CurrentTimeMillisLong override var timeMillis: Long = 0L, + override var userId: Int = 0, + override var listening: Boolean = false, + // keep sorted + var awakeKeyguard: Boolean = false, + var authInterruptActive: Boolean = false, + var fpLockedOut: Boolean = false, + var primaryAuthRequired: Boolean = false, + var switchingUser: Boolean = false, + var triggerActiveUnlockForAssistant: Boolean = false, + var userCanDismissLockScreen: Boolean = false, +) : KeyguardListenModel() { + + /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */ + val asStringList: List by lazy { + listOf( + DATE_FORMAT.format(timeMillis), + timeMillis.toString(), + userId.toString(), + listening.toString(), + // keep sorted + awakeKeyguard.toString(), + authInterruptActive.toString(), + fpLockedOut.toString(), + primaryAuthRequired.toString(), + switchingUser.toString(), + triggerActiveUnlockForAssistant.toString(), + userCanDismissLockScreen.toString(), + ) + } + + /** + * [RingBuffer] to store [KeyguardActiveUnlockModel]. After the buffer is full, it will recycle + * old events. + * + * Do not use [append] to add new elements. Instead use [insert], as it will recycle if + * necessary. + */ + class Buffer { + private val buffer = RingBuffer(CAPACITY) { KeyguardActiveUnlockModel() } + + fun insert(model: KeyguardActiveUnlockModel) { + buffer.advance().apply { + timeMillis = model.timeMillis + userId = model.userId + listening = model.listening + // keep sorted + awakeKeyguard = model.awakeKeyguard + authInterruptActive = model.authInterruptActive + fpLockedOut = model.fpLockedOut + primaryAuthRequired = model.primaryAuthRequired + switchingUser = model.switchingUser + triggerActiveUnlockForAssistant = model.triggerActiveUnlockForAssistant + userCanDismissLockScreen = model.userCanDismissLockScreen + } + } + + /** + * Returns the content of the buffer (sorted from latest to newest). + * + * @see KeyguardFingerprintListenModel.asStringList + */ + fun toList(): List { + return buffer.asSequence().map { it.asStringList }.toList() + } + } + + companion object { + const val CAPACITY = 20 // number of logs to retain + + /** Headers for dumping a table using [DumpsysTableLogger]. */ + @JvmField + val TABLE_HEADERS = + listOf( + "timestamp", + "time_millis", + "userId", + "listening", + // keep sorted + "awakeKeyguard", + "authInterruptActive", + "fpLockedOut", + "primaryAuthRequired", + "switchingUser", + "triggerActiveUnlockForAssistant", + "userCanDismissLockScreen", + ) + } +} diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardFaceListenModel.kt b/packages/SystemUI/src/com/android/keyguard/KeyguardFaceListenModel.kt new file mode 100644 index 0000000000000..deead1959b8ae --- /dev/null +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardFaceListenModel.kt @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.keyguard + +import android.annotation.CurrentTimeMillisLong +import com.android.systemui.dump.DumpsysTableLogger +import com.android.systemui.dump.Row +import com.android.systemui.plugins.util.RingBuffer + +/** Verbose debug information associated. */ +data class KeyguardFaceListenModel( + @CurrentTimeMillisLong override var timeMillis: Long = 0L, + override var userId: Int = 0, + override var listening: Boolean = false, + // keep sorted + var authInterruptActive: Boolean = false, + var biometricSettingEnabledForUser: Boolean = false, + var bouncerFullyShown: Boolean = false, + var faceAndFpNotAuthenticated: Boolean = false, + var faceAuthAllowed: Boolean = false, + var faceDisabled: Boolean = false, + var faceLockedOut: Boolean = false, + var goingToSleep: Boolean = false, + var keyguardAwake: Boolean = false, + var keyguardGoingAway: Boolean = false, + var listeningForFaceAssistant: Boolean = false, + var occludingAppRequestingFaceAuth: Boolean = false, + var primaryUser: Boolean = false, + var secureCameraLaunched: Boolean = false, + var supportsDetect: Boolean = false, + var switchingUser: Boolean = false, + var udfpsBouncerShowing: Boolean = false, + var udfpsFingerDown: Boolean = false, + var userNotTrustedOrDetectionIsNeeded: Boolean = false, +) : KeyguardListenModel() { + + /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */ + val asStringList: List by lazy { + listOf( + DATE_FORMAT.format(timeMillis), + timeMillis.toString(), + userId.toString(), + listening.toString(), + // keep sorted + authInterruptActive.toString(), + biometricSettingEnabledForUser.toString(), + bouncerFullyShown.toString(), + faceAndFpNotAuthenticated.toString(), + faceAuthAllowed.toString(), + faceDisabled.toString(), + faceLockedOut.toString(), + goingToSleep.toString(), + keyguardAwake.toString(), + keyguardGoingAway.toString(), + listeningForFaceAssistant.toString(), + occludingAppRequestingFaceAuth.toString(), + primaryUser.toString(), + secureCameraLaunched.toString(), + supportsDetect.toString(), + switchingUser.toString(), + udfpsBouncerShowing.toString(), + udfpsFingerDown.toString(), + userNotTrustedOrDetectionIsNeeded.toString(), + ) + } + + /** + * [RingBuffer] to store [KeyguardFaceListenModel]. After the buffer is full, it will recycle + * old events. + * + * Do not use [append] to add new elements. Instead use [insert], as it will recycle if + * necessary. + */ + class Buffer { + private val buffer = RingBuffer(CAPACITY) { KeyguardFaceListenModel() } + + fun insert(model: KeyguardFaceListenModel) { + buffer.advance().apply { + timeMillis = model.timeMillis + userId = model.userId + listening = model.listening + // keep sorted + biometricSettingEnabledForUser = model.biometricSettingEnabledForUser + bouncerFullyShown = model.bouncerFullyShown + faceAndFpNotAuthenticated = model.faceAndFpNotAuthenticated + faceAuthAllowed = model.faceAuthAllowed + faceDisabled = model.faceDisabled + faceLockedOut = model.faceLockedOut + goingToSleep = model.goingToSleep + keyguardAwake = model.keyguardAwake + goingToSleep = model.goingToSleep + keyguardGoingAway = model.keyguardGoingAway + listeningForFaceAssistant = model.listeningForFaceAssistant + occludingAppRequestingFaceAuth = model.occludingAppRequestingFaceAuth + primaryUser = model.primaryUser + secureCameraLaunched = model.secureCameraLaunched + supportsDetect = model.supportsDetect + switchingUser = model.switchingUser + udfpsBouncerShowing = model.udfpsBouncerShowing + switchingUser = model.switchingUser + udfpsFingerDown = model.udfpsFingerDown + userNotTrustedOrDetectionIsNeeded = model.userNotTrustedOrDetectionIsNeeded + } + } + /** + * Returns the content of the buffer (sorted from latest to newest). + * + * @see KeyguardFingerprintListenModel.asStringList + */ + fun toList(): List { + return buffer.asSequence().map { it.asStringList }.toList() + } + } + + companion object { + const val CAPACITY = 40 // number of logs to retain + + /** Headers for dumping a table using [DumpsysTableLogger]. */ + @JvmField + val TABLE_HEADERS = + listOf( + "timestamp", + "time_millis", + "userId", + "listening", + // keep sorted + "authInterruptActive", + "biometricSettingEnabledForUser", + "bouncerFullyShown", + "faceAndFpNotAuthenticated", + "faceAuthAllowed", + "faceDisabled", + "faceLockedOut", + "goingToSleep", + "keyguardAwake", + "keyguardGoingAway", + "listeningForFaceAssistant", + "occludingAppRequestingFaceAuth", + "primaryUser", + "secureCameraLaunched", + "supportsDetect", + "switchingUser", + "udfpsBouncerShowing", + "udfpsFingerDown", + "userNotTrustedOrDetectionIsNeeded", + ) + } +} diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardFingerprintListenModel.kt b/packages/SystemUI/src/com/android/keyguard/KeyguardFingerprintListenModel.kt new file mode 100644 index 0000000000000..998dc09aa5ab9 --- /dev/null +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardFingerprintListenModel.kt @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.keyguard + +import android.annotation.CurrentTimeMillisLong +import com.android.systemui.dump.DumpsysTableLogger +import com.android.systemui.dump.Row +import com.android.systemui.plugins.util.RingBuffer + +/** Verbose debug information. */ +data class KeyguardFingerprintListenModel( + @CurrentTimeMillisLong override var timeMillis: Long = 0L, + override var userId: Int = 0, + override var listening: Boolean = false, + // keepSorted + var biometricEnabledForUser: Boolean = false, + var bouncerIsOrWillShow: Boolean = false, + var canSkipBouncer: Boolean = false, + var credentialAttempted: Boolean = false, + var deviceInteractive: Boolean = false, + var dreaming: Boolean = false, + var fingerprintDisabled: Boolean = false, + var fingerprintLockedOut: Boolean = false, + var goingToSleep: Boolean = false, + var keyguardGoingAway: Boolean = false, + var keyguardIsVisible: Boolean = false, + var keyguardOccluded: Boolean = false, + var occludingAppRequestingFp: Boolean = false, + var primaryUser: Boolean = false, + var shouldListenSfpsState: Boolean = false, + var shouldListenForFingerprintAssistant: Boolean = false, + var strongerAuthRequired: Boolean = false, + var switchingUser: Boolean = false, + var udfps: Boolean = false, + var userDoesNotHaveTrust: Boolean = false, +) : KeyguardListenModel() { + + /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */ + val asStringList: List by lazy { + listOf( + DATE_FORMAT.format(timeMillis), + timeMillis.toString(), + userId.toString(), + listening.toString(), + // keep sorted + biometricEnabledForUser.toString(), + bouncerIsOrWillShow.toString(), + canSkipBouncer.toString(), + credentialAttempted.toString(), + deviceInteractive.toString(), + dreaming.toString(), + fingerprintDisabled.toString(), + fingerprintLockedOut.toString(), + goingToSleep.toString(), + keyguardGoingAway.toString(), + keyguardIsVisible.toString(), + keyguardOccluded.toString(), + occludingAppRequestingFp.toString(), + primaryUser.toString(), + shouldListenSfpsState.toString(), + shouldListenForFingerprintAssistant.toString(), + strongerAuthRequired.toString(), + switchingUser.toString(), + udfps.toString(), + userDoesNotHaveTrust.toString(), + ) + } + + /** + * [RingBuffer] to store [KeyguardFingerprintListenModel]. After the buffer is full, it will + * recycle old events. + * + * Do not use [append] to add new elements. Instead use [insert], as it will recycle if + * necessary. + */ + class Buffer { + private val buffer = RingBuffer(CAPACITY) { KeyguardFingerprintListenModel() } + + fun insert(model: KeyguardFingerprintListenModel) { + buffer.advance().apply { + timeMillis = model.timeMillis + userId = model.userId + listening = model.listening + // keep sorted + biometricEnabledForUser = model.biometricEnabledForUser + bouncerIsOrWillShow = model.bouncerIsOrWillShow + canSkipBouncer = model.canSkipBouncer + credentialAttempted = model.credentialAttempted + deviceInteractive = model.deviceInteractive + dreaming = model.dreaming + fingerprintDisabled = model.fingerprintDisabled + fingerprintLockedOut = model.fingerprintLockedOut + goingToSleep = model.goingToSleep + keyguardGoingAway = model.keyguardGoingAway + keyguardIsVisible = model.keyguardIsVisible + keyguardOccluded = model.keyguardOccluded + occludingAppRequestingFp = model.occludingAppRequestingFp + primaryUser = model.primaryUser + shouldListenSfpsState = model.shouldListenSfpsState + shouldListenForFingerprintAssistant = model.shouldListenForFingerprintAssistant + strongerAuthRequired = model.strongerAuthRequired + switchingUser = model.switchingUser + udfps = model.udfps + userDoesNotHaveTrust = model.userDoesNotHaveTrust + } + } + + /** + * Returns the content of the buffer (sorted from latest to newest). + * + * @see KeyguardFingerprintListenModel.asStringList + */ + fun toList(): List { + return buffer.asSequence().map { it.asStringList }.toList() + } + } + + companion object { + const val CAPACITY = 20 // number of logs to retain + + /** Headers for dumping a table using [DumpsysTableLogger]. */ + @JvmField + val TABLE_HEADERS = + listOf( + "timestamp", + "time_millis", + "userId", + "listening", + // keep sorted + "biometricAllowedForUser", + "bouncerIsOrWillShow", + "canSkipBouncer", + "credentialAttempted", + "deviceInteractive", + "dreaming", + "fingerprintDisabled", + "fingerprintLockedOut", + "goingToSleep", + "keyguardGoingAway", + "keyguardIsVisible", + "keyguardOccluded", + "occludingAppRequestingFp", + "primaryUser", + "shouldListenSidFingerprintState", + "shouldListenForFingerprintAssistant", + "strongAuthRequired", + "switchingUser", + "underDisplayFingerprint", + "userDoesNotHaveTrust", + ) + } +} diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardListenModel.kt b/packages/SystemUI/src/com/android/keyguard/KeyguardListenModel.kt index 52ca1668e4c90..1296cf3b1f33a 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardListenModel.kt +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardListenModel.kt @@ -1,87 +1,32 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.android.keyguard -import android.annotation.CurrentTimeMillisLong +import java.text.SimpleDateFormat +import java.util.Locale /** Verbose logging for various keyguard listening states. */ sealed class KeyguardListenModel { /** Timestamp of the state change. */ - abstract val timeMillis: Long + abstract var timeMillis: Long /** Current user. */ - abstract val userId: Int + abstract var userId: Int /** If keyguard is listening for the modality represented by this model. */ - abstract val listening: Boolean + abstract var listening: Boolean } -/** - * Verbose debug information associated with [KeyguardUpdateMonitor.shouldListenForFingerprint]. - */ -data class KeyguardFingerprintListenModel( - @CurrentTimeMillisLong override val timeMillis: Long, - override val userId: Int, - override val listening: Boolean, - // keep sorted - val biometricEnabledForUser: Boolean, - val bouncerIsOrWillShow: Boolean, - val canSkipBouncer: Boolean, - val credentialAttempted: Boolean, - val deviceInteractive: Boolean, - val dreaming: Boolean, - val fingerprintDisabled: Boolean, - val fingerprintLockedOut: Boolean, - val goingToSleep: Boolean, - val keyguardGoingAway: Boolean, - val keyguardIsVisible: Boolean, - val keyguardOccluded: Boolean, - val occludingAppRequestingFp: Boolean, - val primaryUser: Boolean, - val shouldListenSfpsState: Boolean, - val shouldListenForFingerprintAssistant: Boolean, - val strongerAuthRequired: Boolean, - val switchingUser: Boolean, - val udfps: Boolean, - val userDoesNotHaveTrust: Boolean -) : KeyguardListenModel() -/** - * Verbose debug information associated with [KeyguardUpdateMonitor.shouldListenForFace]. - */ -data class KeyguardFaceListenModel( - @CurrentTimeMillisLong override val timeMillis: Long, - override val userId: Int, - override val listening: Boolean, - // keep sorted - val authInterruptActive: Boolean, - val biometricSettingEnabledForUser: Boolean, - val bouncerFullyShown: Boolean, - val faceAndFpNotAuthenticated: Boolean, - val faceAuthAllowed: Boolean, - val faceDisabled: Boolean, - val faceLockedOut: Boolean, - val goingToSleep: Boolean, - val keyguardAwake: Boolean, - val keyguardGoingAway: Boolean, - val listeningForFaceAssistant: Boolean, - val occludingAppRequestingFaceAuth: Boolean, - val primaryUser: Boolean, - val secureCameraLaunched: Boolean, - val supportsDetect: Boolean, - val switchingUser: Boolean, - val udfpsBouncerShowing: Boolean, - val udfpsFingerDown: Boolean, - val userNotTrustedOrDetectionIsNeeded: Boolean, - ) : KeyguardListenModel() -/** - * Verbose debug information associated with [KeyguardUpdateMonitor.shouldTriggerActiveUnlock]. - */ -data class KeyguardActiveUnlockModel( - @CurrentTimeMillisLong override val timeMillis: Long, - override val userId: Int, - override val listening: Boolean, - // keep sorted - val awakeKeyguard: Boolean, - val authInterruptActive: Boolean, - val fpLockedOut: Boolean, - val primaryAuthRequired: Boolean, - val switchingUser: Boolean, - val triggerActiveUnlockForAssistant: Boolean, - val userCanDismissLockScreen: Boolean -) : KeyguardListenModel() +val DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardListenQueue.kt b/packages/SystemUI/src/com/android/keyguard/KeyguardListenQueue.kt deleted file mode 100644 index 210f5e7639116..0000000000000 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardListenQueue.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.keyguard - -import androidx.annotation.VisibleForTesting -import java.io.PrintWriter -import java.text.DateFormat -import java.text.SimpleDateFormat -import java.util.Date -import java.util.Locale -import kotlin.collections.ArrayDeque - -private val DEFAULT_FORMATTING = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US) - -/** Queue for verbose logging checks for the listening state. */ -class KeyguardListenQueue( - val sizePerModality: Int = 20 -) { - private val faceQueue = ArrayDeque() - private val fingerprintQueue = ArrayDeque() - private val activeUnlockQueue = ArrayDeque() - - @get:VisibleForTesting val models: List - get() = faceQueue + fingerprintQueue + activeUnlockQueue - - /** Push a [model] to the queue (will be logged until the queue exceeds [sizePerModality]). */ - fun add(model: KeyguardListenModel) { - val queue = when (model) { - is KeyguardFaceListenModel -> faceQueue.apply { add(model) } - is KeyguardFingerprintListenModel -> fingerprintQueue.apply { add(model) } - is KeyguardActiveUnlockModel -> activeUnlockQueue.apply { add(model) } - } - - if (queue.size > sizePerModality) { - queue.removeFirstOrNull() - } - } - - /** Print verbose logs via the [writer]. */ - @JvmOverloads - fun print(writer: PrintWriter, dateFormat: DateFormat = DEFAULT_FORMATTING) { - val stringify: (KeyguardListenModel) -> String = { model -> - " ${dateFormat.format(Date(model.timeMillis))} $model" - } - - writer.println(" Face listen results (last ${faceQueue.size} calls):") - for (model in faceQueue) { - writer.println(stringify(model)) - } - writer.println(" Fingerprint listen results (last ${fingerprintQueue.size} calls):") - for (model in fingerprintQueue) { - writer.println(stringify(model)) - } - writer.println(" Active unlock triggers (last ${activeUnlockQueue.size} calls):") - for (model in activeUnlockQueue) { - writer.println(stringify(model)) - } - } -} diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 71d5bf57baf60..217b8fff9b509 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -146,6 +146,7 @@ import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dagger.qualifiers.Background; import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dump.DumpManager; +import com.android.systemui.dump.DumpsysTableLogger; import com.android.systemui.log.SessionTracker; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.settings.UserTracker; @@ -461,14 +462,18 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab private final SparseBooleanArray mBiometricEnabledForUser = new SparseBooleanArray(); private final Map mSecondaryLockscreenRequirement = new HashMap<>(); + private final KeyguardFingerprintListenModel.Buffer mFingerprintListenBuffer = + new KeyguardFingerprintListenModel.Buffer(); + private final KeyguardFaceListenModel.Buffer mFaceListenBuffer = + new KeyguardFaceListenModel.Buffer(); + private final KeyguardActiveUnlockModel.Buffer mActiveUnlockTriggerBuffer = + new KeyguardActiveUnlockModel.Buffer(); + @VisibleForTesting SparseArray mUserFingerprintAuthenticated = new SparseArray<>(); @VisibleForTesting SparseArray mUserFaceAuthenticated = new SparseArray<>(); - // Keep track of recent calls to shouldListenFor*() for debugging. - private final KeyguardListenQueue mListenModels = new KeyguardListenQueue(); - private static int sCurrentUser; public synchronized static void setCurrentUser(int currentUser) { @@ -2635,7 +2640,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab && !mSecureCameraLaunched; // Aggregate relevant fields for debug logging. - maybeLogListenerModelData( + logListenerModelData( new KeyguardActiveUnlockModel( System.currentTimeMillis(), user, @@ -2716,7 +2721,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab boolean shouldListen = shouldListenKeyguardState && shouldListenUserState && shouldListenBouncerState && shouldListenUdfpsState && shouldListenSideFpsState; - maybeLogListenerModelData( + logListenerModelData( new KeyguardFingerprintListenModel( System.currentTimeMillis(), user, @@ -2801,7 +2806,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab && !mGoingToSleep; // Aggregate relevant fields for debug logging. - maybeLogListenerModelData( + logListenerModelData( new KeyguardFaceListenModel( System.currentTimeMillis(), user, @@ -2829,28 +2834,14 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab return shouldListen; } - private void maybeLogListenerModelData(@NonNull KeyguardListenModel model) { + private void logListenerModelData(@NonNull KeyguardListenModel model) { mLogger.logKeyguardListenerModel(model); - - if (model instanceof KeyguardActiveUnlockModel) { - mListenModels.add(model); - return; - } - - // Add model data to the historical buffer. - final boolean notYetRunning = - (model instanceof KeyguardFaceListenModel - && mFaceRunningState != BIOMETRIC_STATE_RUNNING) - || (model instanceof KeyguardFingerprintListenModel - && mFingerprintRunningState != BIOMETRIC_STATE_RUNNING); - final boolean running = - (model instanceof KeyguardFaceListenModel - && mFaceRunningState == BIOMETRIC_STATE_RUNNING) - || (model instanceof KeyguardFingerprintListenModel - && mFingerprintRunningState == BIOMETRIC_STATE_RUNNING); - if (notYetRunning && model.getListening() - || running && !model.getListening()) { - mListenModels.add(model); + if (model instanceof KeyguardFingerprintListenModel) { + mFingerprintListenBuffer.insert((KeyguardFingerprintListenModel) model); + } else if (model instanceof KeyguardActiveUnlockModel) { + mActiveUnlockTriggerBuffer.insert((KeyguardActiveUnlockModel) model); + } else if (model instanceof KeyguardFaceListenModel) { + mFaceListenBuffer.insert((KeyguardFaceListenModel) model); } } @@ -3923,6 +3914,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab pw.println(" mSfpsRequireScreenOnToAuthPrefEnabled=" + mSfpsRequireScreenOnToAuthPrefEnabled); } + new DumpsysTableLogger( + "KeyguardFingerprintListen", + KeyguardFingerprintListenModel.TABLE_HEADERS, + mFingerprintListenBuffer.toList() + ).printTableData(pw); } if (mFaceManager != null && mFaceManager.isHardwareDetected()) { final int userId = mUserTracker.getUserId(); @@ -3948,7 +3944,17 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab pw.println(" mSecureCameraLaunched=" + mSecureCameraLaunched); pw.println(" mPrimaryBouncerFullyShown=" + mPrimaryBouncerFullyShown); pw.println(" mNeedsSlowUnlockTransition=" + mNeedsSlowUnlockTransition); + new DumpsysTableLogger( + "KeyguardFaceListen", + KeyguardFaceListenModel.TABLE_HEADERS, + mFaceListenBuffer.toList() + ).printTableData(pw); } - mListenModels.print(pw); + + new DumpsysTableLogger( + "KeyguardActiveUnlockTriggers", + KeyguardActiveUnlockModel.TABLE_HEADERS, + mActiveUnlockTriggerBuffer.toList() + ).printTableData(pw); } } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardListenQueueTest.kt b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardListenQueueTest.kt deleted file mode 100644 index fa8c8982bccb5..0000000000000 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardListenQueueTest.kt +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.keyguard - -import android.testing.AndroidTestingRunner -import androidx.test.filters.SmallTest -import com.android.systemui.SysuiTestCase -import com.google.common.truth.Truth.assertThat -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidTestingRunner::class) -@SmallTest -class KeyguardListenQueueTest : SysuiTestCase() { - - @Test - fun testQueueIsBounded() { - val size = 5 - val queue = KeyguardListenQueue(sizePerModality = size) - - val fingerprints = List(100) { fingerprintModel(it) } - fingerprints.forEach { queue.add(it) } - - assertThat(queue.models).containsExactlyElementsIn(fingerprints.takeLast(size)) - - val faces = List(100) { faceModel(it) } - faces.forEach { queue.add(it) } - - assertThat(queue.models).containsExactlyElementsIn( - faces.takeLast(size) + fingerprints.takeLast(5) - ) - - repeat(100) { - queue.add(faceModel(-1)) - queue.add(fingerprintModel(-1)) - } - assertThat(queue.models).hasSize(2 * size) - assertThat(queue.models.count { it.userId == -1 }).isEqualTo(2 * size) - } -} - -private fun fingerprintModel(user: Int) = KeyguardFingerprintListenModel( - timeMillis = System.currentTimeMillis(), - userId = user, - listening = false, - biometricEnabledForUser = false, - bouncerIsOrWillShow = false, - canSkipBouncer = false, - credentialAttempted = false, - deviceInteractive = false, - dreaming = false, - fingerprintDisabled = false, - fingerprintLockedOut = false, - goingToSleep = false, - keyguardGoingAway = false, - keyguardIsVisible = false, - keyguardOccluded = false, - occludingAppRequestingFp = false, - primaryUser = false, - shouldListenSfpsState = false, - shouldListenForFingerprintAssistant = false, - strongerAuthRequired = false, - switchingUser = false, - udfps = false, - userDoesNotHaveTrust = false -) - -private fun faceModel(user: Int) = KeyguardFaceListenModel( - timeMillis = System.currentTimeMillis(), - userId = user, - listening = false, - authInterruptActive = false, - biometricSettingEnabledForUser = false, - bouncerFullyShown = false, - faceAndFpNotAuthenticated = false, - faceAuthAllowed = true, - faceDisabled = false, - faceLockedOut = false, - goingToSleep = false, - keyguardAwake = false, - keyguardGoingAway = false, - listeningForFaceAssistant = false, - occludingAppRequestingFaceAuth = false, - primaryUser = false, - secureCameraLaunched = false, - supportsDetect = true, - switchingUser = false, - udfpsBouncerShowing = false, - udfpsFingerDown = false, - userNotTrustedOrDetectionIsNeeded = false -)