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 ) {
31     fun logPackageSnoozed(snoozeKey: String) {
32         buffer.log(TAG, INFO, {
33             str1 = snoozeKey
34         }, {
35             "package snoozed $str1"
36         })
37     }
38 
39     fun logPackageUnsnoozed(snoozeKey: String) {
40         buffer.log(TAG, INFO, {
41             str1 = snoozeKey
42         }, {
43             "package unsnoozed $str1"
44         })
45     }
46 
47     fun logIsSnoozedReturned(snoozeKey: String) {
48         buffer.log(TAG, INFO, {
49             str1 = snoozeKey
50         }, {
51             "package snoozed when queried $str1"
52         })
53     }
54 
55     fun logReleaseAllImmediately() {
56         buffer.log(TAG, INFO, { }, {
57             "release all immediately"
58         })
59     }
60 
61     fun logShowNotification(entry: NotificationEntry) {
62         buffer.log(TAG, INFO, {
63             str1 = entry.logKey
64         }, {
65             "show notification $str1"
66         })
67     }
68 
69     fun logRemoveNotification(key: String, releaseImmediately: Boolean) {
70         buffer.log(TAG, INFO, {
71             str1 = logKey(key)
72             bool1 = releaseImmediately
73         }, {
74             "remove notification $str1 releaseImmediately: $bool1"
75         })
76     }
77 
78     fun logNotificationActuallyRemoved(entry: NotificationEntry) {
79         buffer.log(TAG, INFO, {
80             str1 = entry.logKey
81         }, {
82             "notification removed $str1 "
83         })
84     }
85 
86     fun logUpdateNotification(key: String, alert: Boolean, hasEntry: Boolean) {
87         buffer.log(TAG, INFO, {
88             str1 = logKey(key)
89             bool1 = alert
90             bool2 = hasEntry
91         }, {
92             "update notification $str1 alert: $bool1 hasEntry: $bool2"
93         })
94     }
95 
96     fun logUpdateEntry(entry: NotificationEntry, updatePostTime: Boolean) {
97         buffer.log(TAG, INFO, {
98             str1 = entry.logKey
99             bool1 = updatePostTime
100         }, {
101             "update entry $str1 updatePostTime: $bool1"
102         })
103     }
104 
105     fun logSnoozeLengthChange(packageSnoozeLengthMs: Int) {
106         buffer.log(TAG, INFO, {
107             int1 = packageSnoozeLengthMs
108         }, {
109             "snooze length changed: ${int1}ms"
110         })
111     }
112 
113     fun logSetEntryPinned(entry: NotificationEntry, isPinned: Boolean) {
114         buffer.log(TAG, VERBOSE, {
115             str1 = entry.logKey
116             bool1 = isPinned
117         }, {
118             "set entry pinned $str1 pinned: $bool1"
119         })
120     }
121 
122     fun logUpdatePinnedMode(hasPinnedNotification: Boolean) {
123         buffer.log(TAG, INFO, {
124             bool1 = hasPinnedNotification
125         }, {
126             "has pinned notification changed to $bool1"
127         })
128     }
129 }
130 
131 private const val TAG = "HeadsUpManager"