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.taptotransfer.sender 18 19 import android.app.StatusBarManager 20 import com.android.internal.logging.InstanceId 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.log.LogBuffer 23 import com.android.systemui.log.core.LogLevel 24 import com.android.systemui.media.taptotransfer.common.MediaTttLoggerUtils 25 import javax.inject.Inject 26 27 /** A logger for all events related to the media tap-to-transfer sender experience. */ 28 @SysUISingleton 29 class MediaTttSenderLogger 30 @Inject 31 constructor( 32 @MediaTttSenderLogBuffer private val buffer: LogBuffer, 33 ) { 34 /** Logs a change in the chip state for the given [mediaRouteId]. */ 35 fun logStateChange( 36 stateName: String, 37 mediaRouteId: String, 38 packageName: String?, 39 ) { 40 MediaTttLoggerUtils.logStateChange(buffer, TAG, stateName, mediaRouteId, packageName) 41 } 42 43 /** Logs an error in trying to update to [displayState]. */ 44 fun logStateChangeError(@StatusBarManager.MediaTransferSenderState displayState: Int) { 45 MediaTttLoggerUtils.logStateChangeError(buffer, TAG, displayState) 46 } 47 48 /** Logs that we couldn't find information for [packageName]. */ 49 fun logPackageNotFound(packageName: String) { 50 MediaTttLoggerUtils.logPackageNotFound(buffer, TAG, packageName) 51 } 52 53 /** 54 * Logs an invalid sender state transition error in trying to update to [desiredState]. 55 * 56 * @param currentState the previous state of the chip. 57 * @param desiredState the new state of the chip. 58 */ 59 fun logInvalidStateTransitionError(currentState: String, desiredState: String) { 60 buffer.log( 61 TAG, 62 LogLevel.ERROR, 63 { 64 str1 = currentState 65 str2 = desiredState 66 }, 67 { "Cannot display state=$str2 after state=$str1; invalid transition" } 68 ) 69 } 70 71 /** 72 * Logs that a removal request has been bypassed (ignored). 73 * 74 * @param removalReason the reason that the chip removal was requested. 75 * @param bypassReason the reason that the request was bypassed. 76 */ 77 fun logRemovalBypass(removalReason: String, bypassReason: String) { 78 buffer.log( 79 TAG, 80 LogLevel.DEBUG, 81 { 82 str1 = removalReason 83 str2 = bypassReason 84 }, 85 { "Chip removal requested due to $str1; however, removal was ignored because $str2" } 86 ) 87 } 88 89 /** Logs the current contents of the state map. */ 90 fun logStateMap(map: Map<String, Pair<InstanceId, ChipStateSender>>) { 91 buffer.log( 92 TAG, 93 LogLevel.DEBUG, 94 { str1 = map.toString() }, 95 { "Current sender states: $str1" } 96 ) 97 } 98 99 /** Logs that [id] has been removed from the state map due to [reason]. */ 100 fun logStateMapRemoval(id: String, reason: String) { 101 buffer.log( 102 TAG, 103 LogLevel.DEBUG, 104 { 105 str1 = id 106 str2 = reason 107 }, 108 { "State removal: id=$str1 reason=$str2" } 109 ) 110 } 111 112 companion object { 113 private const val TAG = "MediaTttSender" 114 } 115 } 116