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 ) { logNotifPostednull34 fun logNotifPosted(key: String) { 35 buffer.log(TAG, INFO, { 36 str1 = key 37 }, { 38 "POSTED $str1" 39 }) 40 } 41 logNotifGroupPostednull42 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 logNotifUpdatednull51 fun logNotifUpdated(key: String) { 52 buffer.log(TAG, INFO, { 53 str1 = key 54 }, { 55 "UPDATED $str1" 56 }) 57 } 58 logNotifRemovednull59 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 logNotifReleasednull68 fun logNotifReleased(key: String) { 69 buffer.log(TAG, INFO, { 70 str1 = key 71 }, { 72 "RELEASED $str1" 73 }) 74 } 75 logNotifDismissednull76 fun logNotifDismissed(key: String) { 77 buffer.log(TAG, INFO, { 78 str1 = key 79 }, { 80 "DISMISSED $str1" 81 }) 82 } 83 logChildDismissednull84 fun logChildDismissed(entry: NotificationEntry) { 85 buffer.log(TAG, DEBUG, { 86 str1 = entry.key 87 }, { 88 "CHILD DISMISSED (inferred): $str1" 89 }) 90 } 91 logDismissAllnull92 fun logDismissAll(userId: Int) { 93 buffer.log(TAG, INFO, { 94 int1 = userId 95 }, { 96 "DISMISS ALL notifications for user $int1" 97 }) 98 } 99 logDismissOnAlreadyCanceledEntrynull100 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 logNotifDismissedInterceptednull108 fun logNotifDismissedIntercepted(key: String) { 109 buffer.log(TAG, INFO, { 110 str1 = key 111 }, { 112 "DISMISS INTERCEPTED $str1" 113 }) 114 } 115 logNotifClearAllDismissalInterceptednull116 fun logNotifClearAllDismissalIntercepted(key: String) { 117 buffer.log(TAG, INFO, { 118 str1 = key 119 }, { 120 "CLEAR ALL DISMISSAL INTERCEPTED $str1" 121 }) 122 } 123 logNoNotificationToRemoveWithKeynull124 fun logNoNotificationToRemoveWithKey(key: String) { 125 buffer.log(TAG, ERROR, { 126 str1 = key 127 }, { 128 "No notification to remove with key $str1" 129 }) 130 } 131 logRankingMissingnull132 fun logRankingMissing(key: String, rankingMap: RankingMap) { 133 buffer.log(TAG, WARNING, { str1 = key }, { "Ranking update is missing ranking for $str1" }) 134 buffer.log(TAG, DEBUG, {}, { "Ranking map contents:" }) 135 for (entry in rankingMap.orderedKeys) { 136 buffer.log(TAG, DEBUG, { str1 = entry }, { " $str1" }) 137 } 138 } 139 logRemoteExceptionOnNotificationClearnull140 fun logRemoteExceptionOnNotificationClear(key: String, e: RemoteException) { 141 buffer.log(TAG, WTF, { 142 str1 = key 143 str2 = e.toString() 144 }, { 145 "RemoteException while attempting to clear $str1:\n$str2" 146 }) 147 } 148 logRemoteExceptionOnClearAllNotificationsnull149 fun logRemoteExceptionOnClearAllNotifications(e: RemoteException) { 150 buffer.log(TAG, WTF, { 151 str1 = e.toString() 152 }, { 153 "RemoteException while attempting to clear all notifications:\n$str1" 154 }) 155 } 156 logLifetimeExtendednull157 fun logLifetimeExtended(key: String, extender: NotifLifetimeExtender) { 158 buffer.log(TAG, INFO, { 159 str1 = key 160 str2 = extender.name 161 }, { 162 "LIFETIME EXTENDED: $str1 by $str2" 163 }) 164 } 165 logLifetimeExtensionEndednull166 fun logLifetimeExtensionEnded( 167 key: String, 168 extender: NotifLifetimeExtender, 169 totalExtenders: Int 170 ) { 171 buffer.log(TAG, INFO, { 172 str1 = key 173 str2 = extender.name 174 int1 = totalExtenders 175 }, { 176 "LIFETIME EXTENSION ENDED for $str1 by '$str2'; $int1 remaining extensions" 177 }) 178 } 179 logIgnoredErrornull180 fun logIgnoredError(message: String?) { 181 buffer.log(TAG, ERROR, { 182 str1 = message 183 }, { 184 "ERROR suppressed due to initialization forgiveness: $str1" 185 }) 186 } 187 } 188 189 private const val TAG = "NotifCollection" 190