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.pipeline 18 19 import android.media.session.PlaybackState 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.MediaTimeoutListenerLog 24 import javax.inject.Inject 25 26 private const val TAG = "MediaTimeout" 27 28 /** A buffered log for [MediaTimeoutListener] events */ 29 @SysUISingleton 30 class MediaTimeoutLogger 31 @Inject 32 constructor(@MediaTimeoutListenerLog private val buffer: LogBuffer) { logReuseListenernull33 fun logReuseListener(key: String) = 34 buffer.log(TAG, LogLevel.DEBUG, { str1 = key }, { "reuse listener: $str1" }) 35 logMigrateListenernull36 fun logMigrateListener(oldKey: String?, newKey: String?, hadListener: Boolean) = 37 buffer.log( 38 TAG, 39 LogLevel.DEBUG, 40 { 41 str1 = oldKey 42 str2 = newKey 43 bool1 = hadListener 44 }, <lambda>null45 { "migrate from $str1 to $str2, had listener? $bool1" } 46 ) 47 logUpdateListenernull48 fun logUpdateListener(key: String, wasPlaying: Boolean) = 49 buffer.log( 50 TAG, 51 LogLevel.DEBUG, 52 { 53 str1 = key 54 bool1 = wasPlaying 55 }, <lambda>null56 { "updating $str1, was playing? $bool1" } 57 ) 58 logDelayedUpdatenull59 fun logDelayedUpdate(key: String) = 60 buffer.log( 61 TAG, 62 LogLevel.DEBUG, 63 { str1 = key }, <lambda>null64 { "deliver delayed playback state for $str1" } 65 ) 66 logSessionDestroyednull67 fun logSessionDestroyed(key: String) = 68 buffer.log(TAG, LogLevel.DEBUG, { str1 = key }, { "session destroyed $str1" }) 69 logPlaybackStatenull70 fun logPlaybackState(key: String, state: PlaybackState?) = 71 buffer.log( 72 TAG, 73 LogLevel.VERBOSE, 74 { 75 str1 = key 76 str2 = state?.toString() 77 }, <lambda>null78 { "state update: key=$str1 state=$str2" } 79 ) 80 logStateCallbacknull81 fun logStateCallback(key: String) = 82 buffer.log(TAG, LogLevel.VERBOSE, { str1 = key }, { "dispatching state update for $key" }) 83 logScheduleTimeoutnull84 fun logScheduleTimeout(key: String, playing: Boolean, resumption: Boolean) = 85 buffer.log( 86 TAG, 87 LogLevel.DEBUG, 88 { 89 str1 = key 90 bool1 = playing 91 bool2 = resumption 92 }, <lambda>null93 { "schedule timeout $str1, playing=$bool1 resumption=$bool2" } 94 ) 95 logCancelIgnorednull96 fun logCancelIgnored(key: String) = 97 buffer.log(TAG, LogLevel.DEBUG, { str1 = key }, { "cancellation already exists for $str1" }) 98 logTimeoutnull99 fun logTimeout(key: String) = 100 buffer.log(TAG, LogLevel.DEBUG, { str1 = key }, { "execute timeout for $str1" }) 101 logTimeoutCancellednull102 fun logTimeoutCancelled(key: String, reason: String) = 103 buffer.log( 104 TAG, 105 LogLevel.VERBOSE, 106 { 107 str1 = key 108 str2 = reason 109 }, <lambda>null110 { "timeout cancelled for $str1, reason: $str2" } 111 ) 112 logRecommendationTimeoutSchedulednull113 fun logRecommendationTimeoutScheduled(key: String, timeout: Long) = 114 buffer.log( 115 TAG, 116 LogLevel.VERBOSE, 117 { 118 str1 = key 119 long1 = timeout 120 }, <lambda>null121 { "recommendation timeout scheduled for $str1 in $long1 ms" } 122 ) 123 } 124