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.keyguard.logging 18 19 import android.content.Intent 20 import android.telephony.ServiceState 21 import android.telephony.SubscriptionInfo 22 import android.telephony.SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX 23 import android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID 24 import android.telephony.TelephonyManager 25 import com.android.systemui.log.LogBuffer 26 import com.android.systemui.log.core.LogLevel 27 import com.android.systemui.log.core.LogLevel.DEBUG 28 import com.android.systemui.log.core.LogLevel.ERROR 29 import com.android.systemui.log.core.LogLevel.INFO 30 import com.android.systemui.log.core.LogLevel.VERBOSE 31 import com.android.systemui.log.core.LogLevel.WARNING 32 import com.android.systemui.log.dagger.SimLog 33 import com.google.errorprone.annotations.CompileTimeConstant 34 import javax.inject.Inject 35 36 private const val TAG = "SimLog" 37 38 /** Helper class for logging for SIM events */ 39 class SimLogger @Inject constructor(@SimLog private val logBuffer: LogBuffer) { dnull40 fun d(@CompileTimeConstant msg: String) = log(msg, DEBUG) 41 42 fun e(@CompileTimeConstant msg: String) = log(msg, ERROR) 43 44 fun v(@CompileTimeConstant msg: String) = log(msg, VERBOSE) 45 46 fun w(@CompileTimeConstant msg: String) = log(msg, WARNING) 47 48 fun log(@CompileTimeConstant msg: String, level: LogLevel) = logBuffer.log(TAG, level, msg) 49 50 fun logInvalidSubId(subId: Int, slotId: Int) { 51 logBuffer.log( 52 TAG, 53 INFO, 54 { 55 int1 = subId 56 int2 = slotId 57 }, 58 { "Previously active subId: $int1, slotId: $int2 is now invalid, will remove" }, 59 ) 60 } 61 logServiceStateChangenull62 fun logServiceStateChange(subId: Int, serviceState: ServiceState?) { 63 logBuffer.log( 64 TAG, 65 DEBUG, 66 { 67 int1 = subId 68 str1 = "$serviceState" 69 }, 70 { "handleServiceStateChange(subId=$int1, serviceState=$str1)" }, 71 ) 72 } 73 logServiceStateIntentnull74 fun logServiceStateIntent(action: String?, serviceState: ServiceState?, subId: Int) { 75 logBuffer.log( 76 TAG, 77 VERBOSE, 78 { 79 str1 = action 80 str2 = "$serviceState" 81 int1 = subId 82 }, 83 { "action $str1 serviceState=$str2 subId=$int1" }, 84 ) 85 } 86 logServiceProvidersUpdatednull87 fun logServiceProvidersUpdated(intent: Intent) { 88 logBuffer.log( 89 TAG, 90 VERBOSE, 91 { 92 int1 = intent.getIntExtra(EXTRA_SUBSCRIPTION_INDEX, INVALID_SUBSCRIPTION_ID) 93 str1 = intent.getStringExtra(TelephonyManager.EXTRA_SPN) 94 str2 = intent.getStringExtra(TelephonyManager.EXTRA_PLMN) 95 }, 96 { "action SERVICE_PROVIDERS_UPDATED subId=$int1 spn=$str1 plmn=$str2" }, 97 ) 98 } 99 logSimStatenull100 fun logSimState(subId: Int, slotId: Int, state: String) { 101 logBuffer.log( 102 TAG, 103 DEBUG, 104 { 105 int1 = subId 106 int2 = slotId 107 str1 = state 108 }, 109 { "handleSimStateChange(subId=$int1, slotId=$int2, state=$str1)" }, 110 ) 111 } 112 logSimStateFromIntentnull113 fun logSimStateFromIntent(action: String?, extraSimState: String?, slotId: Int, subId: Int) { 114 logBuffer.log( 115 TAG, 116 VERBOSE, 117 { 118 str1 = action 119 str2 = extraSimState 120 int1 = slotId 121 int2 = subId 122 }, 123 { "action $str1 state: $str2 slotId: $int1 subid: $int2" }, 124 ) 125 } 126 logSimUnlockednull127 fun logSimUnlocked(subId: Int) { 128 logBuffer.log(TAG, VERBOSE, { int1 = subId }, { "reportSimUnlocked(subId=$int1)" }) 129 } 130 logSubInfonull131 fun logSubInfo(subInfo: SubscriptionInfo?) { 132 logBuffer.log(TAG, DEBUG, { str1 = "$subInfo" }, { "SubInfo:$str1" }) 133 } 134 } 135