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.volume.shared 18 19 import com.android.settingslib.volume.shared.AudioLogger 20 import com.android.settingslib.volume.shared.AudioSharingLogger 21 import com.android.settingslib.volume.shared.model.AudioStream 22 import com.android.settingslib.volume.shared.model.AudioStreamModel 23 import com.android.systemui.dagger.SysUISingleton 24 import com.android.systemui.log.LogBuffer 25 import com.android.systemui.log.core.LogLevel 26 import com.android.systemui.log.dagger.VolumeLog 27 import javax.inject.Inject 28 29 private const val TAG = "SysUI_Volume" 30 31 /** Logs general System UI volume events. */ 32 @SysUISingleton 33 class VolumeLogger @Inject constructor(@VolumeLog private val logBuffer: LogBuffer) : 34 AudioLogger, AudioSharingLogger { 35 onSetVolumeRequestednull36 override fun onSetVolumeRequested(audioStream: AudioStream, volume: Int) { 37 logBuffer.log( 38 TAG, 39 LogLevel.DEBUG, 40 { 41 str1 = audioStream.toString() 42 int1 = volume 43 }, 44 { "Set volume: stream=$str1 volume=$int1" }, 45 ) 46 } 47 onVolumeUpdateReceivednull48 override fun onVolumeUpdateReceived(audioStream: AudioStream, model: AudioStreamModel) { 49 logBuffer.log( 50 TAG, 51 LogLevel.DEBUG, 52 { 53 str1 = audioStream.toString() 54 int1 = model.volume 55 }, 56 { "Volume update received: stream=$str1 volume=$int1" }, 57 ) 58 } 59 onAudioSharingStateChangednull60 override fun onAudioSharingStateChanged(state: Boolean) { 61 logBuffer.log( 62 TAG, 63 LogLevel.DEBUG, 64 { bool1 = state }, 65 { "Audio sharing state update: state=$bool1" }, 66 ) 67 } 68 onSecondaryGroupIdChangednull69 override fun onSecondaryGroupIdChanged(groupId: Int) { 70 logBuffer.log( 71 TAG, 72 LogLevel.DEBUG, 73 { int1 = groupId }, 74 { "Secondary group id in audio sharing update: groupId=$int1" }, 75 ) 76 } 77 onVolumeMapChangednull78 override fun onVolumeMapChanged(map: Map<Int, Int>) { 79 logBuffer.log( 80 TAG, 81 LogLevel.DEBUG, 82 { str1 = map.toString() }, 83 { "Volume map update: map=$str1" }, 84 ) 85 } 86 onSetDeviceVolumeRequestednull87 override fun onSetDeviceVolumeRequested(volume: Int) { 88 logBuffer.log(TAG, LogLevel.DEBUG, { int1 = volume }, { "Set device volume: volume=$int1" }) 89 } 90 onAudioSharingAvailabilityRequestedErrornull91 override fun onAudioSharingAvailabilityRequestedError(requestFrom: String, e: String) { 92 logBuffer.log( 93 TAG, 94 LogLevel.WARNING, 95 { 96 str1 = requestFrom 97 str1 = e 98 }, 99 { "$str1, fail to check audio sharing availability: e=$str2" }, 100 ) 101 } 102 } 103