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.media.controls.ui
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel
22 import com.android.systemui.log.dagger.MediaCarouselControllerLog
23 import javax.inject.Inject
24 
25 /** A debug logger for [MediaCarouselController]. */
26 @SysUISingleton
27 class MediaCarouselControllerLogger
28 @Inject
29 constructor(@MediaCarouselControllerLog private val buffer: LogBuffer) {
30     /**
31      * Log that there might be a potential memory leak for the [MediaControlPanel] and/or
32      * [MediaViewController] related to [key].
33      */
34     fun logPotentialMemoryLeak(key: String) =
35         buffer.log(
36             TAG,
37             LogLevel.DEBUG,
38             { str1 = key },
39             {
40                 "Potential memory leak: " +
41                     "Removing control panel for $str1 from map without calling #onDestroy"
42             }
43         )
44 
45     fun logMediaLoaded(key: String, active: Boolean) =
46         buffer.log(
47             TAG,
48             LogLevel.DEBUG,
49             {
50                 str1 = key
51                 bool1 = active
52             },
53             { "add player $str1, active: $bool1" }
54         )
55 
56     fun logMediaRemoved(key: String) =
57         buffer.log(TAG, LogLevel.DEBUG, { str1 = key }, { "removing player $str1" })
58 
59     fun logRecommendationLoaded(key: String, isActive: Boolean) =
60         buffer.log(
61             TAG,
62             LogLevel.DEBUG,
63             {
64                 str1 = key
65                 bool1 = isActive
66             },
67             { "add recommendation $str1, active $bool1" }
68         )
69 
70     fun logRecommendationRemoved(key: String, immediately: Boolean) =
71         buffer.log(
72             TAG,
73             LogLevel.DEBUG,
74             {
75                 str1 = key
76                 bool1 = immediately
77             },
78             { "removing recommendation $str1, immediate=$bool1" }
79         )
80 
81     fun logCarouselHidden() = buffer.log(TAG, LogLevel.DEBUG, {}, { "hiding carousel" })
82 
83     fun logCarouselVisible() = buffer.log(TAG, LogLevel.DEBUG, {}, { "showing carousel" })
84 }
85 
86 private const val TAG = "MediaCarouselCtlrLog"
87