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 android.flags; 18 19 import android.annotation.NonNull; 20 21 /** 22 * Base class for constants read via {@link android.flags.FeatureFlags}. 23 * 24 * @param <T> The type of value that this flag stores. E.g. Boolean or String. 25 * 26 * @hide 27 */ 28 public interface Flag<T> { 29 /** The namespace for a flag. Should combine uniquely with its name. */ 30 @NonNull getNamespace()31 String getNamespace(); 32 33 /** The name of the flag. Should combine uniquely with its namespace. */ 34 @NonNull getName()35 String getName(); 36 37 /** The value of this flag if no override has been set. Null values are not supported. */ 38 @NonNull getDefault()39 T getDefault(); 40 41 /** Returns true if the value of this flag can change at runtime. */ isDynamic()42 default boolean isDynamic() { 43 return false; 44 } 45 46 /** 47 * Add human-readable details to the flag. Flag client's are not required to set this. 48 * 49 * See {@link #getLabel()}, {@link #getDescription()}, and {@link #getCategoryName()}. 50 * 51 * @return Returns `this`, to make a fluent api. 52 */ defineMetaData(String label, String description, String categoryName)53 Flag<T> defineMetaData(String label, String description, String categoryName); 54 55 /** 56 * A human-readable name for the flag. Defaults to {@link #getName()} 57 * 58 * See {@link #defineMetaData(String, String, String)} 59 */ 60 @NonNull getLabel()61 default String getLabel() { 62 return getName(); 63 } 64 65 /** 66 * A human-readable description for the flag. Defaults to null if unset. 67 * 68 * See {@link #defineMetaData(String, String, String)} 69 */ getDescription()70 default String getDescription() { 71 return null; 72 } 73 74 /** 75 * A human-readable category name for the flag. Defaults to null if unset. 76 * 77 * See {@link #defineMetaData(String, String, String)} 78 */ getCategoryName()79 default String getCategoryName() { 80 return null; 81 } 82 } 83