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.controller
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      */
logPotentialMemoryLeaknull34     fun logPotentialMemoryLeak(key: String) =
35         buffer.log(
36             TAG,
37             LogLevel.DEBUG,
38             { str1 = key },
<lambda>null39             {
40                 "Potential memory leak: " +
41                     "Removing control panel for $str1 from map without calling #onDestroy"
42             }
43         )
44 
logMediaLoadednull45     fun logMediaLoaded(key: String, active: Boolean) =
46         buffer.log(
47             TAG,
48             LogLevel.DEBUG,
49             {
50                 str1 = key
51                 bool1 = active
52             },
<lambda>null53             { "add player $str1, active: $bool1" }
54         )
55 
logMediaRemovednull56     fun logMediaRemoved(key: String, userInitiated: Boolean) =
57         buffer.log(
58             TAG,
59             LogLevel.DEBUG,
60             {
61                 str1 = key
62                 bool1 = userInitiated
63             },
<lambda>null64             { "removing player $str1, by user $bool1" }
65         )
66 
logRecommendationLoadednull67     fun logRecommendationLoaded(key: String, isActive: Boolean) =
68         buffer.log(
69             TAG,
70             LogLevel.DEBUG,
71             {
72                 str1 = key
73                 bool1 = isActive
74             },
<lambda>null75             { "add recommendation $str1, active $bool1" }
76         )
77 
logRecommendationRemovednull78     fun logRecommendationRemoved(key: String, immediately: Boolean) =
79         buffer.log(
80             TAG,
81             LogLevel.DEBUG,
82             {
83                 str1 = key
84                 bool1 = immediately
85             },
<lambda>null86             { "removing recommendation $str1, immediate=$bool1" }
87         )
88 
<lambda>null89     fun logCarouselHidden() = buffer.log(TAG, LogLevel.DEBUG, {}, { "hiding carousel" })
90 
<lambda>null91     fun logCarouselVisible() = buffer.log(TAG, LogLevel.DEBUG, {}, { "showing carousel" })
92 }
93 
94 private const val TAG = "MediaCarouselCtlrLog"
95