1 /*
2  * Copyright (C) 2020 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.systemui.statusbar.policy
18 
19 import com.android.systemui.log.dagger.NotificationHeadsUpLog
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel.INFO
22 import com.android.systemui.log.core.LogLevel.VERBOSE
23 import com.android.systemui.statusbar.notification.collection.NotificationEntry
24 import com.android.systemui.statusbar.notification.logKey
25 import javax.inject.Inject
26 
27 /** Logger for [HeadsUpManager]. */
28 class HeadsUpManagerLogger @Inject constructor(
29     @NotificationHeadsUpLog private val buffer: LogBuffer
30 ) {
logPackageSnoozednull31     fun logPackageSnoozed(snoozeKey: String) {
32         buffer.log(TAG, INFO, {
33             str1 = snoozeKey
34         }, {
35             "package snoozed $str1"
36         })
37     }
38 
logPackageUnsnoozednull39     fun logPackageUnsnoozed(snoozeKey: String) {
40         buffer.log(TAG, INFO, {
41             str1 = snoozeKey
42         }, {
43             "package unsnoozed $str1"
44         })
45     }
46 
logIsSnoozedReturnednull47     fun logIsSnoozedReturned(snoozeKey: String) {
48         buffer.log(TAG, INFO, {
49             str1 = snoozeKey
50         }, {
51             "package snoozed when queried $str1"
52         })
53     }
54 
logReleaseAllImmediatelynull55     fun logReleaseAllImmediately() {
56         buffer.log(TAG, INFO, { }, {
57             "release all immediately"
58         })
59     }
60 
logShowNotificationRequestnull61     fun logShowNotificationRequest(entry: NotificationEntry) {
62         buffer.log(TAG, INFO, {
63             str1 = entry.logKey
64         }, {
65             "request: show notification $str1"
66         })
67     }
68 
logShowNotificationnull69     fun logShowNotification(entry: NotificationEntry) {
70         buffer.log(TAG, INFO, {
71             str1 = entry.logKey
72         }, {
73             "show notification $str1"
74         })
75     }
76 
logAutoRemoveSchedulednull77     fun logAutoRemoveScheduled(entry: NotificationEntry, delayMillis: Long, reason: String) {
78         buffer.log(TAG, INFO, {
79             str1 = entry.logKey
80             long1 = delayMillis
81             str2 = reason
82         }, {
83             "schedule auto remove of $str1 in $long1 ms reason: $str2"
84         })
85     }
86 
logAutoRemoveRequestnull87     fun logAutoRemoveRequest(entry: NotificationEntry, reason: String) {
88         buffer.log(TAG, INFO, {
89             str1 = entry.logKey
90             str2 = reason
91         }, {
92             "request: reschedule auto remove of $str1 reason: $str2"
93         })
94     }
95 
logAutoRemoveReschedulednull96     fun logAutoRemoveRescheduled(entry: NotificationEntry, delayMillis: Long, reason: String) {
97         buffer.log(TAG, INFO, {
98             str1 = entry.logKey
99             long1 = delayMillis
100             str2 = reason
101         }, {
102             "reschedule auto remove of $str1 in $long1 ms reason: $str2"
103         })
104     }
105 
logAutoRemoveCancelRequestnull106     fun logAutoRemoveCancelRequest(entry: NotificationEntry, reason: String?) {
107         buffer.log(TAG, INFO, {
108             str1 = entry.logKey
109             str2 = reason ?: "unknown"
110         }, {
111             "request: cancel auto remove of $str1 reason: $str2"
112         })
113     }
114 
logAutoRemoveCancelednull115     fun logAutoRemoveCanceled(entry: NotificationEntry, reason: String?) {
116         buffer.log(TAG, INFO, {
117             str1 = entry.logKey
118             str2 = reason ?: "unknown"
119         }, {
120             "cancel auto remove of $str1 reason: $str2"
121         })
122     }
123 
logRemoveEntryRequestnull124     fun logRemoveEntryRequest(key: String, reason: String, isWaiting: Boolean) {
125         buffer.log(TAG, INFO, {
126             str1 = logKey(key)
127             str2 = reason
128             bool1 = isWaiting
129         }, {
130             "request: $str2 => remove entry $str1 isWaiting: $isWaiting"
131         })
132     }
133 
logRemoveEntrynull134     fun logRemoveEntry(key: String, reason: String, isWaiting: Boolean) {
135         buffer.log(TAG, INFO, {
136             str1 = logKey(key)
137             str2 = reason
138             bool1 = isWaiting
139         }, {
140             "$str2 => remove entry $str1 isWaiting: $isWaiting"
141         })
142     }
143 
logUnpinEntryRequestnull144     fun logUnpinEntryRequest(key: String) {
145         buffer.log(TAG, INFO, {
146             str1 = logKey(key)
147         }, {
148             "request: unpin entry $str1"
149         })
150     }
151 
logUnpinEntrynull152     fun logUnpinEntry(key: String) {
153         buffer.log(TAG, INFO, {
154             str1 = logKey(key)
155         }, {
156             "unpin entry $str1"
157         })
158     }
159 
logRemoveNotificationnull160     fun logRemoveNotification(key: String, releaseImmediately: Boolean, isWaiting: Boolean) {
161         buffer.log(TAG, INFO, {
162             str1 = logKey(key)
163             bool1 = releaseImmediately
164             bool2 = isWaiting
165         }, {
166             "remove notification $str1 releaseImmediately: $bool1 isWaiting: $bool2"
167         })
168     }
169 
logNotificationActuallyRemovednull170     fun logNotificationActuallyRemoved(entry: NotificationEntry) {
171         buffer.log(TAG, INFO, {
172             str1 = entry.logKey
173         }, {
174             "notification removed $str1 "
175         })
176     }
177 
logUpdateNotificationRequestnull178     fun logUpdateNotificationRequest(key: String, alert: Boolean, hasEntry: Boolean) {
179         buffer.log(TAG, INFO, {
180             str1 = logKey(key)
181             bool1 = alert
182             bool2 = hasEntry
183         }, {
184             "request: update notification $str1 alert: $bool1 hasEntry: $bool2"
185         })
186     }
187 
logUpdateNotificationnull188     fun logUpdateNotification(key: String, alert: Boolean, hasEntry: Boolean) {
189         buffer.log(TAG, INFO, {
190             str1 = logKey(key)
191             bool1 = alert
192             bool2 = hasEntry
193         }, {
194             "update notification $str1 alert: $bool1 hasEntry: $bool2"
195         })
196     }
197 
logUpdateEntrynull198     fun logUpdateEntry(entry: NotificationEntry, updatePostTime: Boolean, reason: String?) {
199         buffer.log(TAG, INFO, {
200             str1 = entry.logKey
201             bool1 = updatePostTime
202             str2 = reason ?: "unknown"
203         }, {
204             "update entry $str1 updatePostTime: $bool1 reason: $str2"
205         })
206     }
207 
logSnoozeLengthChangenull208     fun logSnoozeLengthChange(packageSnoozeLengthMs: Int) {
209         buffer.log(TAG, INFO, {
210             int1 = packageSnoozeLengthMs
211         }, {
212             "snooze length changed: ${int1}ms"
213         })
214     }
215 
logSetEntryPinnednull216     fun logSetEntryPinned(entry: NotificationEntry, isPinned: Boolean, reason: String) {
217         buffer.log(TAG, VERBOSE, {
218             str1 = entry.logKey
219             bool1 = isPinned
220             str2 = reason
221         }, {
222             "$str2 => set entry pinned $str1 pinned: $bool1"
223         })
224     }
225 
logUpdatePinnedModenull226     fun logUpdatePinnedMode(hasPinnedNotification: Boolean) {
227         buffer.log(TAG, INFO, {
228             bool1 = hasPinnedNotification
229         }, {
230             "has pinned notification changed to $bool1"
231         })
232     }
233 }
234 
235 private const val TAG = "HeadsUpManager"