Debian Codegraph @

apex/jobscheduler/service/java/com/android/server/tare/AlarmManagerEconomicPolicy.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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.server.tare;
18
19 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE_CAKES;
20 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_CTP_CAKES;
21 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP_CAKES;
22 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE_CAKES;
23 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP_CAKES;
24 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE_CAKES;
25 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP_CAKES;
26 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE_CAKES;
27 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP_CAKES;
28 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE_CAKES;
29 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP_CAKES;
30 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE_CAKES;
31 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_CTP_CAKES;
32 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE_CAKES;
33 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP_CAKES;
34 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE_CAKES;
35 import static android.app.tare.EconomyManager.DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP_CAKES;
36 import static android.app.tare.EconomyManager.DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES;
37 import static android.app.tare.EconomyManager.DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES;
38 import static android.app.tare.EconomyManager.DEFAULT_AM_MAX_SATIATED_BALANCE_CAKES;
39 import static android.app.tare.EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_EXEMPTED_CAKES;
40 import static android.app.tare.EconomyManager.DEFAULT_AM_MIN_SATIATED_BALANCE_OTHER_APP_CAKES;
41 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT_CAKES;
42 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_MAX_CAKES;
43 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING_CAKES;
44 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_INSTANT_CAKES;
45 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_MAX_CAKES;
46 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_NOTIFICATION_SEEN_ONGOING_CAKES;
47 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_INSTANT_CAKES;
48 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_MAX_CAKES;
49 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_ONGOING_CAKES;
50 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_INSTANT_CAKES;
51 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_MAX_CAKES;
52 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_TOP_ACTIVITY_ONGOING_CAKES;
53 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_INSTANT_CAKES;
54 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_MAX_CAKES;
55 import static android.app.tare.EconomyManager.DEFAULT_AM_REWARD_WIDGET_INTERACTION_ONGOING_CAKES;
56 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE;
57 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_CTP;
58 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_BASE_PRICE;
59 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP;
60 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE;
61 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP;
62 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE;
63 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP;
64 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE;
65 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP;
66 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE;
67 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP;
68 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE;
69 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_EXACT_WAKEUP_CTP;
70 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE;
71 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP;
72 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE;
73 import static android.app.tare.EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP;
74 import static android.app.tare.EconomyManager.KEY_AM_HARD_CONSUMPTION_LIMIT;
75 import static android.app.tare.EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT;
76 import static android.app.tare.EconomyManager.KEY_AM_MAX_SATIATED_BALANCE;
77 import static android.app.tare.EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED;
78 import static android.app.tare.EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP;
79 import static android.app.tare.EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT;
80 import static android.app.tare.EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX;
81 import static android.app.tare.EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING;
82 import static android.app.tare.EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_INSTANT;
83 import static android.app.tare.EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_MAX;
84 import static android.app.tare.EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_ONGOING;
85 import static android.app.tare.EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_INSTANT;
86 import static android.app.tare.EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX;
87 import static android.app.tare.EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_ONGOING;
88 import static android.app.tare.EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_INSTANT;
89 import static android.app.tare.EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_MAX;
90 import static android.app.tare.EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_ONGOING;
91 import static android.app.tare.EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_INSTANT;
92 import static android.app.tare.EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_MAX;
93 import static android.app.tare.EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_ONGOING;
94 import static android.provider.Settings.Global.TARE_ALARM_MANAGER_CONSTANTS;
95
96 import static com.android.server.tare.Modifier.COST_MODIFIER_CHARGING;
97 import static com.android.server.tare.Modifier.COST_MODIFIER_DEVICE_IDLE;
98 import static com.android.server.tare.Modifier.COST_MODIFIER_POWER_SAVE_MODE;
99 import static com.android.server.tare.Modifier.COST_MODIFIER_PROCESS_STATE;
100 import static com.android.server.tare.TareUtils.cakeToString;
101
102 import android.annotation.NonNull;
103 import android.annotation.Nullable;
104 import android.content.ContentResolver;
105 import android.provider.DeviceConfig;
106 import android.provider.Settings;
107 import android.util.IndentingPrintWriter;
108 import android.util.KeyValueListParser;
109 import android.util.Slog;
110 import android.util.SparseArray;
111
112 /**
113 * Policy defining pricing information and daily ARC requirements and suggestions for
114 * AlarmManager.
115 */
116 public class AlarmManagerEconomicPolicy extends EconomicPolicy {
117 private static final String TAG = "TARE- " + AlarmManagerEconomicPolicy.class.getSimpleName();
118
119 public static final int ACTION_ALARM_WAKEUP_EXACT_ALLOW_WHILE_IDLE =
120 TYPE_ACTION | POLICY_AM | 0;
121 public static final int ACTION_ALARM_WAKEUP_EXACT =
122 TYPE_ACTION | POLICY_AM | 1;
123 public static final int ACTION_ALARM_WAKEUP_INEXACT_ALLOW_WHILE_IDLE =
124 TYPE_ACTION | POLICY_AM | 2;
125 public static final int ACTION_ALARM_WAKEUP_INEXACT =
126 TYPE_ACTION | POLICY_AM | 3;
127 public static final int ACTION_ALARM_NONWAKEUP_EXACT_ALLOW_WHILE_IDLE =
128 TYPE_ACTION | POLICY_AM | 4;
129 public static final int ACTION_ALARM_NONWAKEUP_EXACT =
130 TYPE_ACTION | POLICY_AM | 5;
131 public static final int ACTION_ALARM_NONWAKEUP_INEXACT_ALLOW_WHILE_IDLE =
132 TYPE_ACTION | POLICY_AM | 6;
133 public static final int ACTION_ALARM_NONWAKEUP_INEXACT =
134 TYPE_ACTION | POLICY_AM | 7;
135 public static final int ACTION_ALARM_CLOCK =
136 TYPE_ACTION | POLICY_AM | 8;
137
138 private static final int[] COST_MODIFIERS = new int[]{
139 COST_MODIFIER_CHARGING,
140 COST_MODIFIER_DEVICE_IDLE,
141 COST_MODIFIER_POWER_SAVE_MODE,
142 COST_MODIFIER_PROCESS_STATE
143 };
144
145 private long mMinSatiatedBalanceExempted;
146 private long mMinSatiatedBalanceOther;
147 private long mMaxSatiatedBalance;
148 private long mInitialSatiatedConsumptionLimit;
149 private long mHardSatiatedConsumptionLimit;
150
151 private final KeyValueListParser mParser = new KeyValueListParser(',');
152 private final InternalResourceService mInternalResourceService;
153
154 private final SparseArray<Action> mActions = new SparseArray<>();
155 private final SparseArray<Reward> mRewards = new SparseArray<>();
156
157 AlarmManagerEconomicPolicy(InternalResourceService irs) {
158 super(irs);
159 mInternalResourceService = irs;
160 loadConstants("", null);
161 }
162
163 @Override
164 void setup(@NonNull DeviceConfig.Properties properties) {
165 super.setup(properties);
166 ContentResolver resolver = mInternalResourceService.getContext().getContentResolver();
167 loadConstants(Settings.Global.getString(resolver, TARE_ALARM_MANAGER_CONSTANTS),
168 properties);
169 }
170
171 @Override
172 long getMinSatiatedBalance(final int userId, @NonNull final String pkgName) {
173 if (mInternalResourceService.isPackageExempted(userId, pkgName)) {
174 return mMinSatiatedBalanceExempted;
175 }
176 // TODO: take other exemptions into account
177 return mMinSatiatedBalanceOther;
178 }
179
180 @Override
181 long getMaxSatiatedBalance() {
182 // TODO(230501287): adjust balance based on whether the app has the SCHEDULE_EXACT_ALARM
183 // permission granted. Apps without the permission granted shouldn't need a high balance
184 // since they won't be able to use exact alarms. Apps with the permission granted could
185 // have a higher balance, or perhaps just those with the USE_EXACT_ALARM permission since
186 // that is limited to specific use cases.
187 return mMaxSatiatedBalance;
188 }
189
190 @Override
191 long getInitialSatiatedConsumptionLimit() {
192 return mInitialSatiatedConsumptionLimit;
193 }
194
195 @Override
196 long getHardSatiatedConsumptionLimit() {
197 return mHardSatiatedConsumptionLimit;
198 }
199
200 @NonNull
201 @Override
202 int[] getCostModifiers() {
203 return COST_MODIFIERS;
204 }
205
206 @Nullable
207 @Override
208 Action getAction(@AppAction int actionId) {
209 return mActions.get(actionId);
210 }
211
212 @Nullable
213 @Override
214 Reward getReward(@UtilityReward int rewardId) {
215 return mRewards.get(rewardId);
216 }
217
218 private void loadConstants(String policyValuesString,
219 @Nullable DeviceConfig.Properties properties) {
220 mActions.clear();
221 mRewards.clear();
222
223 try {
224 mParser.setString(policyValuesString);
225 } catch (IllegalArgumentException e) {
226 Slog.e(TAG, "Global setting key incorrect: ", e);
227 }
228
229 mMinSatiatedBalanceExempted = getConstantAsCake(mParser, properties,
230 KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED,
231 DEFAULT_AM_MIN_SATIATED_BALANCE_EXEMPTED_CAKES);
232 mMinSatiatedBalanceOther = getConstantAsCake(mParser, properties,
233 KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP,
234 DEFAULT_AM_MIN_SATIATED_BALANCE_OTHER_APP_CAKES);
235 mMaxSatiatedBalance = getConstantAsCake(mParser, properties,
236 KEY_AM_MAX_SATIATED_BALANCE,
237 DEFAULT_AM_MAX_SATIATED_BALANCE_CAKES);
238 mInitialSatiatedConsumptionLimit = getConstantAsCake(mParser, properties,
239 KEY_AM_INITIAL_CONSUMPTION_LIMIT, DEFAULT_AM_INITIAL_CONSUMPTION_LIMIT_CAKES);
240 mHardSatiatedConsumptionLimit = Math.max(mInitialSatiatedConsumptionLimit,
241 getConstantAsCake(mParser, properties,
242 KEY_AM_HARD_CONSUMPTION_LIMIT, DEFAULT_AM_HARD_CONSUMPTION_LIMIT_CAKES));
243
244 final long exactAllowWhileIdleWakeupBasePrice = getConstantAsCake(mParser, properties,
245 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE,
246 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE_CAKES);
247
248 mActions.put(ACTION_ALARM_WAKEUP_EXACT_ALLOW_WHILE_IDLE,
249 new Action(ACTION_ALARM_WAKEUP_EXACT_ALLOW_WHILE_IDLE,
250 getConstantAsCake(mParser, properties,
251 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP,
252 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP_CAKES),
253 exactAllowWhileIdleWakeupBasePrice));
254 mActions.put(ACTION_ALARM_WAKEUP_EXACT,
255 new Action(ACTION_ALARM_WAKEUP_EXACT,
256 getConstantAsCake(mParser, properties,
257 KEY_AM_ACTION_ALARM_EXACT_WAKEUP_CTP,
258 DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_CTP_CAKES),
259 getConstantAsCake(mParser, properties,
260 KEY_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
261 DEFAULT_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE_CAKES)));
262
263 final long inexactAllowWhileIdleWakeupBasePrice =
264 getConstantAsCake(mParser, properties,
265 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE,
266 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE_CAKES);
267
268 mActions.put(ACTION_ALARM_WAKEUP_INEXACT_ALLOW_WHILE_IDLE,
269 new Action(ACTION_ALARM_WAKEUP_INEXACT_ALLOW_WHILE_IDLE,
270 getConstantAsCake(mParser, properties,
271 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP,
272 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP_CAKES),
273 inexactAllowWhileIdleWakeupBasePrice));
274 mActions.put(ACTION_ALARM_WAKEUP_INEXACT,
275 new Action(ACTION_ALARM_WAKEUP_INEXACT,
276 getConstantAsCake(mParser, properties,
277 KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP,
278 DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP_CAKES),
279 getConstantAsCake(mParser, properties,
280 KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE,
281 DEFAULT_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE_CAKES)));
282
283 final long exactAllowWhileIdleNonWakeupBasePrice = getConstantAsCake(mParser, properties,
284 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_BASE_PRICE,
285 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE_CAKES);
286 mActions.put(ACTION_ALARM_NONWAKEUP_EXACT_ALLOW_WHILE_IDLE,
287 new Action(ACTION_ALARM_NONWAKEUP_EXACT_ALLOW_WHILE_IDLE,
288 getConstantAsCake(mParser, properties,
289 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP,
290 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP_CAKES),
291 exactAllowWhileIdleNonWakeupBasePrice));
292
293 mActions.put(ACTION_ALARM_NONWAKEUP_EXACT,
294 new Action(ACTION_ALARM_NONWAKEUP_EXACT,
295 getConstantAsCake(mParser, properties,
296 KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP,
297 DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP_CAKES),
298 getConstantAsCake(mParser, properties,
299 KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE,
300 DEFAULT_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE_CAKES)));
301
302 final long inexactAllowWhileIdleNonWakeupBasePrice = getConstantAsCake(mParser, properties,
303 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE,
304 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE_CAKES);
305 final long inexactAllowWhileIdleNonWakeupCtp = getConstantAsCake(mParser, properties,
306 KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP,
307 DEFAULT_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP_CAKES);
308 mActions.put(ACTION_ALARM_NONWAKEUP_INEXACT_ALLOW_WHILE_IDLE,
309 new Action(ACTION_ALARM_NONWAKEUP_INEXACT_ALLOW_WHILE_IDLE,
310 inexactAllowWhileIdleNonWakeupCtp,
311 inexactAllowWhileIdleNonWakeupBasePrice));
312
313 mActions.put(ACTION_ALARM_NONWAKEUP_INEXACT,
314 new Action(ACTION_ALARM_NONWAKEUP_INEXACT,
315 getConstantAsCake(mParser, properties,
316 KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP,
317 DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP_CAKES),
318 getConstantAsCake(mParser, properties,
319 KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE,
320 DEFAULT_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE_CAKES)));
321 mActions.put(ACTION_ALARM_CLOCK,
322 new Action(ACTION_ALARM_CLOCK,
323 getConstantAsCake(mParser, properties,
324 KEY_AM_ACTION_ALARM_ALARMCLOCK_CTP,
325 DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_CTP_CAKES),
326 getConstantAsCake(mParser, properties,
327 KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE,
328 DEFAULT_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE_CAKES)));
329
330 mRewards.put(REWARD_TOP_ACTIVITY, new Reward(REWARD_TOP_ACTIVITY,
331 getConstantAsCake(mParser, properties,
332 KEY_AM_REWARD_TOP_ACTIVITY_INSTANT,
333 DEFAULT_AM_REWARD_TOP_ACTIVITY_INSTANT_CAKES),
334 getConstantAsCake(mParser, properties,
335 KEY_AM_REWARD_TOP_ACTIVITY_ONGOING,
336 DEFAULT_AM_REWARD_TOP_ACTIVITY_ONGOING_CAKES),
337 getConstantAsCake(mParser, properties,
338 KEY_AM_REWARD_TOP_ACTIVITY_MAX,
339 DEFAULT_AM_REWARD_TOP_ACTIVITY_MAX_CAKES)));
340 mRewards.put(REWARD_NOTIFICATION_SEEN, new Reward(REWARD_NOTIFICATION_SEEN,
341 getConstantAsCake(mParser, properties,
342 KEY_AM_REWARD_NOTIFICATION_SEEN_INSTANT,
343 DEFAULT_AM_REWARD_NOTIFICATION_SEEN_INSTANT_CAKES),
344 getConstantAsCake(mParser, properties,
345 KEY_AM_REWARD_NOTIFICATION_SEEN_ONGOING,
346 DEFAULT_AM_REWARD_NOTIFICATION_SEEN_ONGOING_CAKES),
347 getConstantAsCake(mParser, properties,
348 KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
349 DEFAULT_AM_REWARD_NOTIFICATION_SEEN_MAX_CAKES)));
350 mRewards.put(REWARD_NOTIFICATION_INTERACTION,
351 new Reward(REWARD_NOTIFICATION_INTERACTION,
352 getConstantAsCake(mParser, properties,
353 KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT,
354 DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT_CAKES),
355 getConstantAsCake(mParser, properties,
356 KEY_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING,
357 DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_ONGOING_CAKES),
358 getConstantAsCake(mParser, properties,
359 KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
360 DEFAULT_AM_REWARD_NOTIFICATION_INTERACTION_MAX_CAKES)));
361 mRewards.put(REWARD_WIDGET_INTERACTION, new Reward(REWARD_WIDGET_INTERACTION,
362 getConstantAsCake(mParser, properties,
363 KEY_AM_REWARD_WIDGET_INTERACTION_INSTANT,
364 DEFAULT_AM_REWARD_WIDGET_INTERACTION_INSTANT_CAKES),
365 getConstantAsCake(mParser, properties,
366 KEY_AM_REWARD_WIDGET_INTERACTION_ONGOING,
367 DEFAULT_AM_REWARD_WIDGET_INTERACTION_ONGOING_CAKES),
368 getConstantAsCake(mParser, properties,
369 KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
370 DEFAULT_AM_REWARD_WIDGET_INTERACTION_MAX_CAKES)));
371 mRewards.put(REWARD_OTHER_USER_INTERACTION,
372 new Reward(REWARD_OTHER_USER_INTERACTION,
373 getConstantAsCake(mParser, properties,
374 KEY_AM_REWARD_OTHER_USER_INTERACTION_INSTANT,
375 DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_INSTANT_CAKES),
376 getConstantAsCake(mParser, properties,
377 KEY_AM_REWARD_OTHER_USER_INTERACTION_ONGOING,
378 DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_ONGOING_CAKES),
379 getConstantAsCake(mParser, properties,
380 KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
381 DEFAULT_AM_REWARD_OTHER_USER_INTERACTION_MAX_CAKES)));
382 }
383
384 @Override
385 void dump(IndentingPrintWriter pw) {
386 pw.println("Min satiated balances:");
387 pw.increaseIndent();
388 pw.print("Exempted", cakeToString(mMinSatiatedBalanceExempted)).println();
389 pw.print("Other", cakeToString(mMinSatiatedBalanceOther)).println();
390 pw.decreaseIndent();
391 pw.print("Max satiated balance", cakeToString(mMaxSatiatedBalance)).println();
392 pw.print("Consumption limits: [");
393 pw.print(cakeToString(mInitialSatiatedConsumptionLimit));
394 pw.print(", ");
395 pw.print(cakeToString(mHardSatiatedConsumptionLimit));
396 pw.println("]");
397
398 pw.println();
399 pw.println("Actions:");
400 pw.increaseIndent();
401 for (int i = 0; i < mActions.size(); ++i) {
402 dumpAction(pw, mActions.valueAt(i));
403 }
404 pw.decreaseIndent();
405
406 pw.println();
407 pw.println("Rewards:");
408 pw.increaseIndent();
409 for (int i = 0; i < mRewards.size(); ++i) {
410 dumpReward(pw, mRewards.valueAt(i));
411 }
412 pw.decreaseIndent();
413 }
414 }