• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.media.controls.shared
18 
19 import com.android.internal.logging.InstanceId
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.log.LogBuffer
22 import com.android.systemui.log.core.LogLevel
23 import com.android.systemui.log.dagger.MediaLog
24 import javax.inject.Inject
25 
26 /** A buffered log for media loading events. */
27 @SysUISingleton
28 class MediaLogger @Inject constructor(@MediaLog private val buffer: LogBuffer) {
29 
logMediaLoadednull30     fun logMediaLoaded(instanceId: InstanceId, active: Boolean, reason: String) {
31         buffer.log(
32             TAG,
33             LogLevel.DEBUG,
34             {
35                 str1 = instanceId.toString()
36                 bool1 = active
37                 str2 = reason
38             },
39             { "add media $str1, active: $bool1, reason: $str2" },
40         )
41     }
42 
logMediaRemovednull43     fun logMediaRemoved(instanceId: InstanceId, reason: String) {
44         buffer.log(
45             TAG,
46             LogLevel.DEBUG,
47             {
48                 str1 = instanceId.toString()
49                 str2 = reason
50             },
51             { "removing media $str1, reason: $str2" },
52         )
53     }
54 
logRecommendationLoadednull55     fun logRecommendationLoaded(key: String, isActive: Boolean, reason: String) {
56         buffer.log(
57             TAG,
58             LogLevel.DEBUG,
59             {
60                 str1 = key
61                 bool1 = isActive
62                 str2 = reason
63             },
64             { "add recommendation $str1, active $bool1, reason: $str2" },
65         )
66     }
67 
logRecommendationRemovednull68     fun logRecommendationRemoved(key: String, immediately: Boolean, reason: String) {
69         buffer.log(
70             TAG,
71             LogLevel.DEBUG,
72             {
73                 str1 = key
74                 bool1 = immediately
75                 str2 = reason
76             },
77             { "removing recommendation $str1, immediate=$bool1, reason: $str2" },
78         )
79     }
80 
logMediaCardAddednull81     fun logMediaCardAdded(instanceId: InstanceId) {
82         buffer.log(
83             TAG,
84             LogLevel.DEBUG,
85             { str1 = instanceId.toString() },
86             { "adding media card $str1 to carousel" },
87         )
88     }
89 
logMediaCardRemovednull90     fun logMediaCardRemoved(instanceId: InstanceId) {
91         buffer.log(
92             TAG,
93             LogLevel.DEBUG,
94             { str1 = instanceId.toString() },
95             { "removing media card $str1 from carousel" },
96         )
97     }
98 
logMediaRecommendationCardAddednull99     fun logMediaRecommendationCardAdded(key: String) {
100         buffer.log(
101             TAG,
102             LogLevel.DEBUG,
103             { str1 = key },
104             { "adding recommendation card $str1 to carousel" },
105         )
106     }
107 
logMediaRecommendationCardRemovednull108     fun logMediaRecommendationCardRemoved(key: String) {
109         buffer.log(
110             TAG,
111             LogLevel.DEBUG,
112             { str1 = key },
113             { "removing recommendation card $str1 from carousel" },
114         )
115     }
116 
logDuplicateMediaNotificationnull117     fun logDuplicateMediaNotification(key: String) {
118         buffer.log(
119             TAG,
120             LogLevel.DEBUG,
121             { str1 = key },
122             { "duplicate media notification $str1 posted" },
123         )
124     }
125 
logMediaControlIsBoundnull126     fun logMediaControlIsBound(
127         instanceId: InstanceId,
128         artistName: CharSequence,
129         title: CharSequence,
130     ) {
131         buffer.log(
132             TAG,
133             LogLevel.DEBUG,
134             {
135                 str1 = instanceId.toString()
136                 str2 = artistName.toString()
137                 str3 = title.toString()
138             },
139             { "binding media control, instance id= $str1, artist= $str2, title= $str3" },
140         )
141     }
142 
logMedia3UnsupportedCommandnull143     fun logMedia3UnsupportedCommand(command: String) {
144         buffer.log(TAG, LogLevel.DEBUG, { str1 = command }, { "Unsupported media3 command $str1" })
145     }
146 
logCreateFailednull147     fun logCreateFailed(pkg: String, method: String) {
148         buffer.log(
149             TAG,
150             LogLevel.DEBUG,
151             {
152                 str1 = pkg
153                 str2 = method
154             },
155             { "Controller create failed for $str1 ($str2)" },
156         )
157     }
158 
logReleaseFailednull159     fun logReleaseFailed(pkg: String, cause: String) {
160         buffer.log(
161             TAG,
162             LogLevel.DEBUG,
163             {
164                 str1 = pkg
165                 str2 = cause
166             },
167             { "Controller release failed for $str1 ($str2)" },
168         )
169     }
170 
171     companion object {
172         private const val TAG = "MediaLog"
173     }
174 }
175