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.domain.pipeline 18 19 import android.media.session.MediaController 20 import com.android.settingslib.media.MediaDevice 21 import com.android.systemui.log.LogBuffer 22 import com.android.systemui.log.core.LogLevel 23 import com.android.systemui.log.dagger.MediaDeviceLog 24 import com.android.systemui.media.controls.shared.model.MediaDeviceData 25 import javax.inject.Inject 26 27 /** A [LogBuffer] for media device changes */ 28 class MediaDeviceLogger @Inject constructor(@MediaDeviceLog private val buffer: LogBuffer) { 29 logBroadcastEventnull30 fun logBroadcastEvent(event: String, reason: Int, broadcastId: Int) { 31 buffer.log( 32 TAG, 33 LogLevel.DEBUG, 34 { 35 str1 = event 36 int1 = reason 37 int2 = broadcastId 38 }, 39 { "$str1, reason = $int1, broadcastId = $int2" } 40 ) 41 } 42 logBroadcastEventnull43 fun logBroadcastEvent(event: String, reason: Int) { 44 buffer.log( 45 TAG, 46 LogLevel.DEBUG, 47 { 48 str1 = event 49 int1 = reason 50 }, 51 { "$str1, reason = $int1" } 52 ) 53 } 54 logBroadcastMetadataChangednull55 fun logBroadcastMetadataChanged(broadcastId: Int, metadata: String) { 56 buffer.log( 57 TAG, 58 LogLevel.DEBUG, 59 { 60 int1 = broadcastId 61 str1 = metadata 62 }, 63 { "onBroadcastMetadataChanged, broadcastId = $int1, metadata = $str1" } 64 ) 65 } 66 logNewDeviceNamenull67 fun logNewDeviceName(name: String?) { 68 buffer.log(TAG, LogLevel.DEBUG, { str1 = name }, { "New device name $str1" }) 69 } 70 logLocalDevicenull71 fun logLocalDevice(sassDevice: MediaDeviceData?, connectedDevice: MediaDeviceData?) { 72 buffer.log( 73 TAG, 74 LogLevel.DEBUG, 75 { 76 str1 = sassDevice?.name?.toString() 77 str2 = connectedDevice?.name?.toString() 78 }, 79 { "Local device: $str1 or $str2" } 80 ) 81 } 82 logRemoteDevicenull83 fun logRemoteDevice(routingSessionName: CharSequence?, connectedDevice: MediaDeviceData?) { 84 buffer.log( 85 TAG, 86 LogLevel.DEBUG, 87 { 88 str1 = routingSessionName?.toString() 89 str2 = connectedDevice?.name?.toString() 90 }, 91 { "Remote device: $str1 or $str2 or unknown" } 92 ) 93 } 94 logDeviceNamenull95 fun logDeviceName( 96 device: MediaDevice?, 97 controller: MediaController?, 98 routingSessionName: CharSequence?, 99 selectedRouteName: CharSequence? 100 ) { 101 buffer.log( 102 TAG, 103 LogLevel.DEBUG, 104 { 105 str1 = "device $device, controller: $controller" 106 str2 = routingSessionName?.toString() 107 str3 = selectedRouteName?.toString() 108 }, 109 { "$str1, routingSession $str2 or selected route $str3" } 110 ) 111 } 112 113 companion object { 114 private const val TAG = "MediaDeviceLog" 115 } 116 } 117