1 /*
2  * Copyright (C) 2023 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.row
18 
19 import com.android.systemui.log.LogBuffer
20 import com.android.systemui.log.core.LogLevel
21 import com.android.systemui.log.dagger.NotifInflationLog
22 import com.android.systemui.statusbar.notification.collection.NotificationEntry
23 import com.android.systemui.statusbar.notification.logKey
24 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_ALL
25 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_CONTRACTED
26 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_EXPANDED
27 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_HEADS_UP
28 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.FLAG_CONTENT_VIEW_PUBLIC
29 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag
30 import javax.inject.Inject
31 
32 class NotificationContentInflaterLogger
33 @Inject
34 constructor(@NotifInflationLog private val buffer: LogBuffer) {
35     fun logNotBindingRowWasRemoved(entry: NotificationEntry) {
36         buffer.log(
37             TAG,
38             LogLevel.INFO,
39             { str1 = entry.logKey },
40             { "not inflating $str1: row was removed" }
41         )
42     }
43 
44     fun logBinding(entry: NotificationEntry, @InflationFlag flag: Int) {
45         buffer.log(
46             TAG,
47             LogLevel.DEBUG,
48             {
49                 str1 = entry.logKey
50                 int1 = flag
51             },
52             { "binding views ${flagToString(int1)} for $str1" }
53         )
54     }
55 
56     fun logCancelBindAbortedTask(entry: NotificationEntry) {
57         buffer.log(
58             TAG,
59             LogLevel.INFO,
60             { str1 = entry.logKey },
61             { "aborted task to cancel binding $str1" }
62         )
63     }
64 
65     fun logUnbinding(entry: NotificationEntry, @InflationFlag flag: Int) {
66         buffer.log(
67             TAG,
68             LogLevel.DEBUG,
69             {
70                 str1 = entry.logKey
71                 int1 = flag
72             },
73             { "unbinding views ${flagToString(int1)} for $str1" }
74         )
75     }
76 
77     fun logAsyncTaskProgress(entry: NotificationEntry, progress: String) {
78         buffer.log(
79             TAG,
80             LogLevel.DEBUG,
81             {
82                 str1 = entry.logKey
83                 str2 = progress
84             },
85             { "async task for $str1: $str2" }
86         )
87     }
88 
89     fun logAsyncTaskException(entry: NotificationEntry, logContext: String, exception: Throwable) {
90         buffer.log(
91             TAG,
92             LogLevel.DEBUG,
93             {
94                 str1 = entry.logKey
95                 str2 = logContext
96                 str3 = exception.stackTraceToString()
97             },
98             { "async task for $str1 got exception $str2: $str3" }
99         )
100     }
101 
102     companion object {
103         fun flagToString(@InflationFlag flag: Int): String {
104             if (flag == 0) {
105                 return "NONE"
106             }
107             if (flag == FLAG_CONTENT_VIEW_ALL) {
108                 return "ALL"
109             }
110 
111             var l = mutableListOf<String>()
112             if (flag and FLAG_CONTENT_VIEW_CONTRACTED != 0) {
113                 l.add("CONTRACTED")
114             }
115             if (flag and FLAG_CONTENT_VIEW_EXPANDED != 0) {
116                 l.add("EXPANDED")
117             }
118             if (flag and FLAG_CONTENT_VIEW_HEADS_UP != 0) {
119                 l.add("HEADS_UP")
120             }
121             if (flag and FLAG_CONTENT_VIEW_PUBLIC != 0) {
122                 l.add("PUBLIC")
123             }
124             return l.joinToString("|")
125         }
126     }
127 }
128 
129 private const val TAG = "NotificationContentInflater"
130