1 /* 2 * Copyright (C) 2023 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.wm.shell.util 18 19 import android.util.Log 20 import com.android.internal.protolog.common.IProtoLogGroup 21 import com.android.internal.protolog.common.ProtoLog 22 23 /** 24 * Log messages using an API similar to [com.android.internal.protolog.common.ProtoLog]. Useful for 25 * logging from Kotlin classes as ProtoLog does not have support for Kotlin. 26 * 27 * All messages are logged to logcat if logging is enabled for that [IProtoLogGroup]. 28 */ 29 // TODO(b/168581922): remove once ProtoLog adds support for Kotlin 30 class KtProtoLog { 31 companion object { 32 /** @see [com.android.internal.protolog.common.ProtoLog.d] */ dnull33 fun d(group: IProtoLogGroup, messageString: String, vararg args: Any) { 34 if (group.isLogToLogcat) { 35 Log.d(group.tag, String.format(messageString, *args)) 36 } 37 } 38 39 /** @see [com.android.internal.protolog.common.ProtoLog.v] */ vnull40 fun v(group: IProtoLogGroup, messageString: String, vararg args: Any) { 41 if (group.isLogToLogcat) { 42 Log.v(group.tag, String.format(messageString, *args)) 43 } 44 } 45 46 /** @see [com.android.internal.protolog.common.ProtoLog.i] */ inull47 fun i(group: IProtoLogGroup, messageString: String, vararg args: Any) { 48 if (group.isLogToLogcat) { 49 Log.i(group.tag, String.format(messageString, *args)) 50 } 51 } 52 53 /** @see [com.android.internal.protolog.common.ProtoLog.w] */ wnull54 fun w(group: IProtoLogGroup, messageString: String, vararg args: Any) { 55 if (group.isLogToLogcat) { 56 Log.w(group.tag, String.format(messageString, *args)) 57 } 58 } 59 60 /** @see [com.android.internal.protolog.common.ProtoLog.e] */ enull61 fun e(group: IProtoLogGroup, messageString: String, vararg args: Any) { 62 if (group.isLogToLogcat) { 63 Log.e(group.tag, String.format(messageString, *args)) 64 } 65 } 66 67 /** @see [com.android.internal.protolog.common.ProtoLog.wtf] */ wtfnull68 fun wtf(group: IProtoLogGroup, messageString: String, vararg args: Any) { 69 if (group.isLogToLogcat) { 70 Log.wtf(group.tag, String.format(messageString, *args)) 71 } 72 } 73 } 74 } 75