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 android.processor.property_cache.test; 18 19 import com.android.internal.annotations.CacheModifier; 20 import com.android.internal.annotations.CachedProperty; 21 import com.android.internal.annotations.CachedPropertyDefaults; 22 23 import java.util.Date; 24 25 @CachedPropertyDefaults(max = 4, module = "bluetooth") 26 public class Custom { 27 BirthdayManagerService mService = new BirthdayManagerService(); 28 Object mCache = new CustomCache(); 29 Custom()30 public Custom() { 31 CustomCache.initCache(); 32 } 33 34 /** 35 * Testing custom class values to generate static IpcDataCache 36 * 37 * @param userId - user Id 38 * @return birthday date of given user Id 39 */ 40 @CachedProperty() getBirthday(int userId)41 public Date getBirthday(int userId) { 42 return CustomCache.getBirthday(mService::getBirthday, userId); 43 } 44 45 /** 46 * Testing custom class values to generate static IpcDataCache 47 * 48 * @param userId - user Id 49 * @return number of days till birthday of given user Id 50 */ 51 @CachedProperty(mods = {CacheModifier.STATIC}) getDaysTillBirthday(int userId)52 public int getDaysTillBirthday(int userId) { 53 return CustomCache.getDaysTillBirthday(mService::getDaysTillBirthday, userId); 54 } 55 56 /** 57 * Testing custom class values to generate non-static IpcDataCache 58 * 59 * @param userId - user Id 60 * @return number of days since birthday of given user Id 61 */ 62 @CachedProperty(mods = {}) getDaysSinceBirthday(int userId)63 public int getDaysSinceBirthday(int userId) { 64 return ((CustomCache) mCache).getDaysSinceBirthday(mService::getDaysSinceBirthday, userId); 65 } 66 67 /** 68 * Testing custom class values to generate static IpcDataCache with max capasity of 1 69 * 70 * @return number of days till birthay of current user 71 */ 72 @CachedProperty(mods = {CacheModifier.STATIC}, max = 1) getDaysTillMyBirthday()73 public int getDaysTillMyBirthday() { 74 return CustomCache.getDaysTillMyBirthday((Void) -> mService.getDaysTillMyBirthday()); 75 } 76 77 /** 78 * Testing custom class values to generate static IpcDataCache with max capasity of 1 and custom 79 * api 80 * 81 * @return number of days since birthay of current user 82 */ 83 @CachedProperty(mods = {}, max = 1, api = "my_unique_key") getDaysSinceMyBirthday()84 public int getDaysSinceMyBirthday() { 85 return ((CustomCache) mCache).getDaysSinceMyBirthday( 86 (Void) -> mService.getDaysSinceMyBirthday()); 87 } 88 89 /** 90 * Testing custom class values to generate static IpcDataCache with custom module name 91 * 92 * @return birthday wishes of given user Id 93 */ 94 @CachedProperty(module = "telephony") getBirthdayWishesFromUser(int userId)95 public String getBirthdayWishesFromUser(int userId) { 96 return CustomCache.getBirthdayWishesFromUser(mService::getBirthdayWishesFromUser, 97 userId); 98 } 99 100 class BirthdayManagerService { 101 int mDaysTillBirthday = 182; 102 getBirthday(int userId)103 public Date getBirthday(int userId) { 104 return new Date(2024, 6, 1 + userId); 105 } 106 getDaysTillBirthday(int userId)107 public int getDaysTillBirthday(int userId) { 108 return mDaysTillBirthday + userId; 109 } 110 getDaysSinceBirthday(int userId)111 public int getDaysSinceBirthday(int userId) { 112 return 365 - getDaysTillBirthday(userId); 113 } 114 getDaysTillMyBirthday()115 public int getDaysTillMyBirthday() { 116 return 0; 117 } 118 getDaysSinceMyBirthday()119 public int getDaysSinceMyBirthday() { 120 return 365; 121 } 122 getBirthdayWishesFromUser(int userId)123 public String getBirthdayWishesFromUser(int userId) { 124 return "Happy Birthday!\n- " + userId; 125 } 126 } 127 } 128