• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.dump.DumpsysTableLogger
21 import com.android.systemui.dump.Row
22 import com.android.systemui.plugins.util.RingBuffer
23 
24 /** Verbose debug information. */
25 data class KeyguardActiveUnlockModel(
26     @CurrentTimeMillisLong override var timeMillis: Long = 0L,
27     override var userId: Int = 0,
28     override var listening: Boolean = false,
29     // keep sorted
30     var awakeKeyguard: Boolean = false,
31     var authInterruptActive: Boolean = false,
32     var fpLockedOut: Boolean = false,
33     var primaryAuthRequired: Boolean = false,
34     var switchingUser: Boolean = false,
35     var triggerActiveUnlockForAssistant: Boolean = false,
36     var userCanDismissLockScreen: Boolean = false,
37 ) : KeyguardListenModel() {
38 
39     /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */
<lambda>null40     val asStringList: List<String> by lazy {
41         listOf(
42             DATE_FORMAT.format(timeMillis),
43             timeMillis.toString(),
44             userId.toString(),
45             listening.toString(),
46             // keep sorted
47             awakeKeyguard.toString(),
48             authInterruptActive.toString(),
49             fpLockedOut.toString(),
50             primaryAuthRequired.toString(),
51             switchingUser.toString(),
52             triggerActiveUnlockForAssistant.toString(),
53             userCanDismissLockScreen.toString(),
54         )
55     }
56 
57     /**
58      * [RingBuffer] to store [KeyguardActiveUnlockModel]. After the buffer is full, it will recycle
59      * old events.
60      *
61      * Do not use [append] to add new elements. Instead use [insert], as it will recycle if
62      * necessary.
63      */
64     class Buffer {
<lambda>null65         private val buffer = RingBuffer(CAPACITY) { KeyguardActiveUnlockModel() }
66 
insertnull67         fun insert(model: KeyguardActiveUnlockModel) {
68             buffer.advance().apply {
69                 timeMillis = model.timeMillis
70                 userId = model.userId
71                 listening = model.listening
72                 // keep sorted
73                 awakeKeyguard = model.awakeKeyguard
74                 authInterruptActive = model.authInterruptActive
75                 fpLockedOut = model.fpLockedOut
76                 primaryAuthRequired = model.primaryAuthRequired
77                 switchingUser = model.switchingUser
78                 triggerActiveUnlockForAssistant = model.triggerActiveUnlockForAssistant
79                 userCanDismissLockScreen = model.userCanDismissLockScreen
80             }
81         }
82 
83         /**
84          * Returns the content of the buffer (sorted from latest to newest).
85          *
86          * @see KeyguardFingerprintListenModel.asStringList
87          */
toListnull88         fun toList(): List<Row> {
89             return buffer.asSequence().map { it.asStringList }.toList()
90         }
91     }
92 
93     companion object {
94         const val CAPACITY = 20 // number of logs to retain
95 
96         /** Headers for dumping a table using [DumpsysTableLogger]. */
97         @JvmField
98         val TABLE_HEADERS =
99             listOf(
100                 "timestamp",
101                 "time_millis",
102                 "userId",
103                 "listening",
104                 // keep sorted
105                 "awakeKeyguard",
106                 "authInterruptActive",
107                 "fpLockedOut",
108                 "primaryAuthRequired",
109                 "switchingUser",
110                 "triggerActiveUnlockForAssistant",
111                 "userCanDismissLockScreen",
112             )
113     }
114 }
115