1 /*
2  * Copyright (C) 2022 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.render
18 
19 import com.android.systemui.log.dagger.NotificationLog
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel
22 import com.android.systemui.statusbar.notification.NotifPipelineFlags
23 import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection
24 import com.android.systemui.util.Compile
25 import javax.inject.Inject
26 
27 class NodeSpecBuilderLogger @Inject constructor(
28     notifPipelineFlags: NotifPipelineFlags,
29     @NotificationLog private val buffer: LogBuffer
30 ) {
31     private val devLoggingEnabled by lazy { notifPipelineFlags.isDevLoggingEnabled() }
32 
33     fun logBuildNodeSpec(
34         oldSections: Set<NotifSection?>,
35         newHeaders: Map<NotifSection?, NodeController?>,
36         newCounts: Map<NotifSection?, Int>,
37         newSectionOrder: List<NotifSection?>
38     ) {
39         if (!(Compile.IS_DEBUG && devLoggingEnabled))
40             return
41 
42         buffer.log(TAG, LogLevel.DEBUG, {
43             int1 = newSectionOrder.size
44         }, { "buildNodeSpec finished with $int1 sections" })
45 
46         for (section in newSectionOrder) {
47             buffer.log(TAG, LogLevel.DEBUG, {
48                 str1 = section?.sectioner?.name ?: "(null)"
49                 str2 = newHeaders[section]?.nodeLabel ?: "(none)"
50                 int1 = newCounts[section] ?: -1
51             }, {
52                 "  section $str1 has header $str2, $int1 entries"
53             })
54         }
55 
56         for (section in oldSections - newSectionOrder.toSet()) {
57             buffer.log(TAG, LogLevel.DEBUG, {
58                 str1 = section?.sectioner?.name ?: "(null)"
59             }, {
60                 "  section $str1 was removed since last run"
61             })
62         }
63     }
64 }
65 
66 private const val TAG = "NodeSpecBuilder"