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.server.broadcastradio; 18 19 import android.text.TextUtils; 20 import android.util.IndentingPrintWriter; 21 import android.util.LocalLog; 22 import android.util.Log; 23 24 import com.android.server.utils.Slogf; 25 26 /** 27 * Event logger to log and dump events of broadcast radio service client for HIDL and AIDL 28 * broadcast HAL. 29 */ 30 public final class RadioEventLogger { 31 private final String mTag; 32 private final boolean mDebug; 33 private final LocalLog mEventLogger; 34 RadioEventLogger(String tag, int loggerQueueSize)35 public RadioEventLogger(String tag, int loggerQueueSize) { 36 mTag = tag; 37 mDebug = Log.isLoggable(mTag, Log.DEBUG); 38 mEventLogger = new LocalLog(loggerQueueSize); 39 } 40 41 /** 42 * Log broadcast radio service event 43 * @param logFormat String format of log message 44 * @param args Arguments of log message 45 */ logRadioEvent(String logFormat, Object... args)46 public void logRadioEvent(String logFormat, Object... args) { 47 String log = TextUtils.formatSimple(logFormat, args); 48 mEventLogger.log(log); 49 if (mDebug) { 50 Slogf.d(mTag, logFormat, args); 51 } 52 } 53 54 /** 55 * Dump broadcast radio service event 56 * @param pw Indenting print writer for dump 57 */ dump(IndentingPrintWriter pw)58 public void dump(IndentingPrintWriter pw) { 59 mEventLogger.dump(pw); 60 } 61 } 62