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.annotations; 18 19 import java.lang.annotation.ElementType; 20 import java.lang.annotation.Retention; 21 import java.lang.annotation.RetentionPolicy; 22 import java.lang.annotation.Target; 23 24 /** 25 * The annotation that generates boilerplate code required by {@link android.os.IpcDataCache} 26 * Instead of implementing IpcDataCache and adding the same code into multiple places within the 27 * same class, annotating method with CachedProperty generate the property and making sure it is 28 * thread safe if property is defined as static. 29 * 30 * To use this annotation on method, owning class needs to be annotated with 31 * {@link com.android.internal.annotations.CachedPropertyDefaults} 32 * 33 * <p>Need static IpcDataCache use @CachedProperty() or @CachedProperty(modifiers = 34 * {Modifier.STATIC}) in front of a method which calls a binder. 35 * 36 * <p>Need NON-static IpcDataCache use @CachedProperty(modifiers = {}) in front of a method which 37 * calls a binder. 38 * 39 * <p>Need to change the max capacity of cache or give custom API name use @CachedProperty( 40 * modifiers = {}, max = 1, apiName = "my_unique_key") in front of a method which calls a binder. 41 */ 42 @Retention(RetentionPolicy.SOURCE) 43 @Target({ElementType.METHOD}) 44 public @interface CachedProperty { 45 /** 46 * The module under which the cache is registered {@link android.os.IpcDataCache.Config#module}. 47 * There are some well-known modules (such as {@link android.os.IpcDataCache.MODULE_SYSTEM} 48 * but any string is permitted. New modules needs to be registered. 49 * When the module is empty, then the module will be the same value as defined in 50 * CachedPropertyDefaults. 51 */ module()52 String module() default ""; 53 54 /** 55 * The name of the {@link android.os.IpcDataCache.Config#api} 56 * When the api is empty, the api name will be the same value as defined in 57 * class level annotation {@link com.android.internal.annotations.CachedPropertyDefaults}. 58 */ api()59 String api() default ""; 60 61 /** 62 * The maximum number of entries in the cache {@link android.os.IpcDataCache.Config#maxEntries} 63 * When the value is -1, the value will be the same value as defined in 64 * class level annotation {@link com.android.internal.annotations.CachedPropertyDefaults}. 65 */ max()66 int max() default -1; 67 68 /** 69 * Specify modifiers for generating cached property. By default it will be static property. 70 */ mods()71 CacheModifier[] mods() default { CacheModifier.STATIC }; 72 } 73