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