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.notification.collection.notifcollection 18 19 import android.os.RemoteException 20 import android.service.notification.NotificationListenerService.RankingMap 21 import com.android.systemui.log.LogBuffer 22 import com.android.systemui.log.LogLevel.DEBUG 23 import com.android.systemui.log.LogLevel.ERROR 24 import com.android.systemui.log.LogLevel.INFO 25 import com.android.systemui.log.LogLevel.WARNING 26 import com.android.systemui.log.LogLevel.WTF 27 import com.android.systemui.log.dagger.NotificationLog 28 import com.android.systemui.statusbar.notification.collection.NotificationEntry 29 import javax.inject.Inject 30 31 class NotifCollectionLogger @Inject constructor( 32 @NotificationLog private val buffer: LogBuffer 33 ) { 34 fun logNotifPosted(key: String) { 35 buffer.log(TAG, INFO, { 36 str1 = key 37 }, { 38 "POSTED $str1" 39 }) 40 } 41 42 fun logNotifGroupPosted(groupKey: String, batchSize: Int) { 43 buffer.log(TAG, INFO, { 44 str1 = groupKey 45 int1 = batchSize 46 }, { 47 "POSTED GROUP $str1 ($int1 events)" 48 }) 49 } 50 51 fun logNotifUpdated(key: String) { 52 buffer.log(TAG, INFO, { 53 str1 = key 54 }, { 55 "UPDATED $str1" 56 }) 57 } 58 59 fun logNotifRemoved(key: String, reason: Int) { 60 buffer.log(TAG, INFO, { 61 str1 = key 62 int1 = reason 63 }, { 64 "REMOVED $str1 reason=$int1" 65 }) 66 } 67 68 fun logNotifReleased(key: String) { 69 buffer.log(TAG, INFO, { 70 str1 = key 71 }, { 72 "RELEASED $str1" 73 }) 74 } 75 76 fun logNotifDismissed(key: String) { 77 buffer.log(TAG, INFO, { 78 str1 = key 79 }, { 80 "DISMISSED $str1" 81 }) 82 } 83 84 fun logChildDismissed(entry: NotificationEntry) { 85 buffer.log(TAG, DEBUG, { 86 str1 = entry.key 87 }, { 88 "CHILD DISMISSED (inferred): $str1" 89 }) 90 } 91 92 fun logDismissAll(userId: Int) { 93 buffer.log(TAG, INFO, { 94 int1 = userId 95 }, { 96 "DISMISS ALL notifications for user $int1" 97 }) 98 } 99 100 fun logDismissOnAlreadyCanceledEntry(entry: NotificationEntry) { 101 buffer.log(TAG, DEBUG, { 102 str1 = entry.key 103 }, { 104 "Dismiss on $str1, which was already canceled. Trying to remove..." 105 }) 106 } 107 108 fun logNotifDismissedIntercepted(key: String) { 109 buffer.log(TAG, INFO, { 110 str1 = key 111 }, { 112 "DISMISS INTERCEPTED $str1" 113 }) 114 } 115 116 fun logNotifClearAllDismissalIntercepted(key: String) { 117 buffer.log(TAG, INFO, { 118 str1 = key 119 }, { 120 "CLEAR ALL DISMISSAL INTERCEPTED $str1" 121 }) 122 } 123 124 fun logNotifInternalUpdate(key: String, name: String, reason: String) { 125 buffer.log(TAG, INFO, { 126 str1 = key 127 str2 = name 128 str3 = reason 129 }, { 130 "UPDATED INTERNALLY $str1 BY $str2 BECAUSE $str3" 131 }) 132 } 133 134 fun logNotifInternalUpdateFailed(key: String, name: String, reason: String) { 135 buffer.log(TAG, INFO, { 136 str1 = key 137 str2 = name 138 str3 = reason 139 }, { 140 "FAILED INTERNAL UPDATE $str1 BY $str2 BECAUSE $str3" 141 }) 142 } 143 144 fun logNoNotificationToRemoveWithKey(key: String) { 145 buffer.log(TAG, ERROR, { 146 str1 = key 147 }, { 148 "No notification to remove with key $str1" 149 }) 150 } 151 152 fun logRankingMissing(key: String, rankingMap: RankingMap) { 153 buffer.log(TAG, WARNING, { str1 = key }, { "Ranking update is missing ranking for $str1" }) 154 buffer.log(TAG, DEBUG, {}, { "Ranking map contents:" }) 155 for (entry in rankingMap.orderedKeys) { 156 buffer.log(TAG, DEBUG, { str1 = entry }, { " $str1" }) 157 } 158 } 159 160 fun logRemoteExceptionOnNotificationClear(key: String, e: RemoteException) { 161 buffer.log(TAG, WTF, { 162 str1 = key 163 str2 = e.toString() 164 }, { 165 "RemoteException while attempting to clear $str1:\n$str2" 166 }) 167 } 168 169 fun logRemoteExceptionOnClearAllNotifications(e: RemoteException) { 170 buffer.log(TAG, WTF, { 171 str1 = e.toString() 172 }, { 173 "RemoteException while attempting to clear all notifications:\n$str1" 174 }) 175 } 176 177 fun logLifetimeExtended(key: String, extender: NotifLifetimeExtender) { 178 buffer.log(TAG, INFO, { 179 str1 = key 180 str2 = extender.name 181 }, { 182 "LIFETIME EXTENDED: $str1 by $str2" 183 }) 184 } 185 186 fun logLifetimeExtensionEnded( 187 key: String, 188 extender: NotifLifetimeExtender, 189 totalExtenders: Int 190 ) { 191 buffer.log(TAG, INFO, { 192 str1 = key 193 str2 = extender.name 194 int1 = totalExtenders 195 }, { 196 "LIFETIME EXTENSION ENDED for $str1 by '$str2'; $int1 remaining extensions" 197 }) 198 } 199 200 fun logIgnoredError(message: String?) { 201 buffer.log(TAG, ERROR, { 202 str1 = message 203 }, { 204 "ERROR suppressed due to initialization forgiveness: $str1" 205 }) 206 } 207 } 208 209 private const val TAG = "NotifCollection" 210