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.domain.resume 18 19 import android.content.ComponentName 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.MediaBrowserLog 24 import javax.inject.Inject 25 26 /** A logger for events in [ResumeMediaBrowser]. */ 27 @SysUISingleton 28 class ResumeMediaBrowserLogger @Inject constructor(@MediaBrowserLog private val buffer: LogBuffer) { 29 /** Logs that we've initiated a connection to a [android.media.browse.MediaBrowser]. */ logConnectionnull30 fun logConnection(componentName: ComponentName, reason: String) = 31 buffer.log( 32 TAG, 33 LogLevel.DEBUG, 34 { 35 str1 = componentName.toShortString() 36 str2 = reason 37 }, <lambda>null38 { "Connecting browser for component $str1 due to $str2" } 39 ) 40 41 /** Logs that we've disconnected from a [android.media.browse.MediaBrowser]. */ logDisconnectnull42 fun logDisconnect(componentName: ComponentName) = 43 buffer.log( 44 TAG, 45 LogLevel.DEBUG, 46 { str1 = componentName.toShortString() }, <lambda>null47 { "Disconnecting browser for component $str1" } 48 ) 49 50 /** 51 * Logs that we received a [android.media.session.MediaController.Callback.onSessionDestroyed] 52 * event. 53 * 54 * @param isBrowserConnected true if there's a currently connected 55 * 56 * ``` 57 * [android.media.browse.MediaBrowser] and false otherwise. 58 * @param componentName 59 * ``` 60 * 61 * the component name for the [ResumeMediaBrowser] that triggered this log. 62 */ logSessionDestroyednull63 fun logSessionDestroyed(isBrowserConnected: Boolean, componentName: ComponentName) = 64 buffer.log( 65 TAG, 66 LogLevel.DEBUG, 67 { 68 bool1 = isBrowserConnected 69 str1 = componentName.toShortString() 70 }, <lambda>null71 { "Session destroyed. Active browser = $bool1. Browser component = $str1." } 72 ) 73 } 74 75 private const val TAG = "MediaBrowser" 76