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.internal.protolog; 18 19 import android.annotation.NonNull; 20 21 import com.android.internal.protolog.common.IProtoLogGroup; 22 23 public class ProtoLogGroup implements IProtoLogGroup { 24 25 /** The name should be unique across the codebase. */ 26 @NonNull 27 private final String mName; 28 @NonNull 29 private final String mTag; 30 private final boolean mEnabled; 31 private boolean mLogToProto; 32 private boolean mLogToLogcat; 33 ProtoLogGroup(@onNull String name)34 public ProtoLogGroup(@NonNull String name) { 35 this(name, name); 36 } 37 ProtoLogGroup(@onNull String name, @NonNull String tag)38 public ProtoLogGroup(@NonNull String name, @NonNull String tag) { 39 this(name, tag, true); 40 } 41 ProtoLogGroup(@onNull String name, @NonNull String tag, boolean enabled)42 public ProtoLogGroup(@NonNull String name, @NonNull String tag, boolean enabled) { 43 mName = name; 44 mTag = tag; 45 mEnabled = enabled; 46 mLogToProto = enabled; 47 mLogToLogcat = enabled; 48 } 49 50 @Override isEnabled()51 public boolean isEnabled() { 52 return mEnabled; 53 } 54 55 @Deprecated 56 @Override isLogToProto()57 public boolean isLogToProto() { 58 return mLogToProto; 59 } 60 61 @Override isLogToLogcat()62 public boolean isLogToLogcat() { 63 return mLogToLogcat; 64 } 65 66 @Override 67 @NonNull getTag()68 public String getTag() { 69 return mTag; 70 } 71 72 @Deprecated 73 @Override setLogToProto(boolean logToProto)74 public void setLogToProto(boolean logToProto) { 75 mLogToProto = logToProto; 76 } 77 78 @Override setLogToLogcat(boolean logToLogcat)79 public void setLogToLogcat(boolean logToLogcat) { 80 mLogToLogcat = logToLogcat; 81 } 82 83 @Override 84 @NonNull name()85 public String name() { 86 return mName; 87 } 88 89 @Override getId()90 public int getId() { 91 return mName.hashCode(); 92 } 93 } 94