1 /*
2 * Copyright (C) 2024 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.logging.dagger
18
19 import com.android.app.tracing.TrackGroupUtils.trackGroup
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.log.LogBuffer
22 import com.android.systemui.log.LogBufferFactory
23 import com.android.systemui.log.dagger.NotifInflationLog
24 import com.android.systemui.log.dagger.NotifInteractionLog
25 import com.android.systemui.log.dagger.NotificationHeadsUpLog
26 import com.android.systemui.log.dagger.NotificationInterruptLog
27 import com.android.systemui.log.dagger.NotificationLockscreenLog
28 import com.android.systemui.log.dagger.NotificationLog
29 import com.android.systemui.log.dagger.NotificationRemoteInputLog
30 import com.android.systemui.log.dagger.NotificationRenderLog
31 import com.android.systemui.log.dagger.NotificationSectionLog
32 import com.android.systemui.log.dagger.SensitiveNotificationProtectionLog
33 import com.android.systemui.log.dagger.UnseenNotificationLog
34 import com.android.systemui.log.dagger.VisualStabilityLog
35 import com.android.systemui.statusbar.notification.NotifPipelineFlags
36 import com.android.systemui.statusbar.notification.promoted.PromotedNotificationLog
37 import com.android.systemui.util.Compile
38 import dagger.Module
39 import dagger.Provides
40
41 @Module
42 object NotificationsLogModule {
43 /** Provides a logging buffer for logs related to heads up presentation of notifications. */
44 @Provides
45 @SysUISingleton
46 @NotificationHeadsUpLog
provideNotificationHeadsUpLogBuffernull47 fun provideNotificationHeadsUpLogBuffer(factory: LogBufferFactory): LogBuffer {
48 return factory.create(
49 "NotifHeadsUpLog",
50 1000,
51 systraceTrackName = notifPipelineTrack("NotifHeadsUpLog"),
52 )
53 }
54
55 /** Provides a logging buffer for logs related to inflation of notifications. */
56 @Provides
57 @SysUISingleton
58 @NotifInflationLog
provideNotifInflationLogBuffernull59 fun provideNotifInflationLogBuffer(factory: LogBufferFactory): LogBuffer {
60 return factory.create(
61 "NotifInflationLog",
62 250,
63 systraceTrackName = notifPipelineTrack("NotifInflationLog"),
64 )
65 }
66
67 /** Provides a logging buffer for all logs related to the data layer of notifications. */
68 @Provides
69 @SysUISingleton
70 @NotifInteractionLog
provideNotifInteractionLogBuffernull71 fun provideNotifInteractionLogBuffer(factory: LogBufferFactory): LogBuffer {
72 return factory.create(
73 "NotifInteractionLog",
74 50,
75 systraceTrackName = notifPipelineTrack("NotifInteractionLog"),
76 )
77 }
78
79 /** Provides a logging buffer for notification interruption calculations. */
80 @Provides
81 @SysUISingleton
82 @NotificationInterruptLog
provideNotificationInterruptLogBuffernull83 fun provideNotificationInterruptLogBuffer(factory: LogBufferFactory): LogBuffer {
84 return factory.create(
85 "NotifInterruptLog",
86 100,
87 systraceTrackName = notifPipelineTrack("NotifInterruptLog"),
88 )
89 }
90
91 /** Provides a logging buffer for all logs related to notifications on the lockscreen. */
92 @Provides
93 @SysUISingleton
94 @NotificationLockscreenLog
provideNotificationLockScreenLogBuffernull95 fun provideNotificationLockScreenLogBuffer(factory: LogBufferFactory): LogBuffer {
96 return factory.create("NotifLockscreenLog", 50, false /* systrace */)
97 }
98
99 /** Provides a logging buffer for all logs related to the data layer of notifications. */
100 @Provides
101 @SysUISingleton
102 @NotificationLog
provideNotificationsLogBuffernull103 fun provideNotificationsLogBuffer(
104 factory: LogBufferFactory,
105 notifPipelineFlags: NotifPipelineFlags,
106 ): LogBuffer {
107 var maxSize = 1000
108 if (Compile.IS_DEBUG && notifPipelineFlags.isDevLoggingEnabled()) {
109 maxSize *= 10
110 }
111 return factory.create(
112 "NotifLog",
113 maxSize,
114 /* systrace= */ Compile.IS_DEBUG,
115 systraceTrackName = notifPipelineTrack("NotifLog"),
116 )
117 }
118
119 /** Provides a logging buffer for all logs related to remote input controller. */
120 @Provides
121 @SysUISingleton
122 @NotificationRemoteInputLog
provideNotificationRemoteInputLogBuffernull123 fun provideNotificationRemoteInputLogBuffer(factory: LogBufferFactory): LogBuffer {
124 return factory.create("NotifRemoteInputLog", 50, /* maxSize */ false /* systrace */)
125 }
126
127 /** Provides a logging buffer for notification rendering events. */
128 @Provides
129 @SysUISingleton
130 @NotificationRenderLog
provideNotificationRenderLogBuffernull131 fun provideNotificationRenderLogBuffer(factory: LogBufferFactory): LogBuffer {
132 return factory.create(
133 "NotifRenderLog",
134 100,
135 systraceTrackName = notifPipelineTrack("NotifRenderLog"),
136 )
137 }
138
139 /** Provides a logging buffer for all logs related to managing notification sections. */
140 @Provides
141 @SysUISingleton
142 @NotificationSectionLog
provideNotificationSectionLogBuffernull143 fun provideNotificationSectionLogBuffer(factory: LogBufferFactory): LogBuffer {
144 return factory.create("NotifSectionLog", 1000, /* maxSize */ false /* systrace */)
145 }
146
147 /** Provides a [LogBuffer] for use by promoted notifications. */
148 @Provides
149 @SysUISingleton
150 @PromotedNotificationLog
providesPromotedNotificationLognull151 fun providesPromotedNotificationLog(factory: LogBufferFactory): LogBuffer {
152 return factory.create("PromotedNotifLog", 50)
153 }
154
155 /** */
156 @Provides
157 @SysUISingleton
158 @SensitiveNotificationProtectionLog
provideSensitiveNotificationProtectionLogBuffernull159 fun provideSensitiveNotificationProtectionLogBuffer(factory: LogBufferFactory): LogBuffer {
160 return factory.create("SensitiveNotificationProtectionLog", 10)
161 }
162
163 /** Provides a logging buffer for all logs related to unseen notifications. */
164 @Provides
165 @SysUISingleton
166 @UnseenNotificationLog
provideUnseenNotificationLogBuffernull167 fun provideUnseenNotificationLogBuffer(factory: LogBufferFactory): LogBuffer {
168 return factory.create("UnseenNotifLog", 20, /* maxSize */ false /* systrace */)
169 }
170
171 /** Provides a logging buffer for all logs related to notification visual stability. */
172 @Provides
173 @SysUISingleton
174 @VisualStabilityLog
provideVisualStabilityLogBuffernull175 fun provideVisualStabilityLogBuffer(factory: LogBufferFactory): LogBuffer {
176 return factory.create("VisualStabilityLog", 50, /* maxSize */ false /* systrace */)
177 }
178 }
179
180 private const val NOTIF_PIPELINE_TRACK_GROUP_NAME = "Notification pipeline"
181
182 /**
183 * This generates a track name that is hierarcically collapsed inside
184 * [NOTIF_PIPELINE_TRACK_GROUP_NAME] in perfetto traces.
185 */
notifPipelineTracknull186 private fun notifPipelineTrack(trackName: String): String {
187 return trackGroup(NOTIF_PIPELINE_TRACK_GROUP_NAME, trackName)
188 }
189