blob: e1dd60dbb15d5c31cbba7fc67bc1ca387884977c [file] [log] [blame]
Jon Miranda16ea1b12017-12-12 14:52:48 -08001/*
2 * Copyright (C) 2017 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 */
16package com.android.wallpaper.module;
17
18import android.annotation.TargetApi;
Santiago Etchebeherec320c5f2021-05-14 17:35:57 -070019import android.app.WallpaperColors;
20import android.graphics.Bitmap;
Jon Miranda16ea1b12017-12-12 14:52:48 -080021import android.os.Build;
Jon Miranda16ea1b12017-12-12 14:52:48 -080022
Sunny Goyal8600a3f2018-08-15 12:48:01 -070023import androidx.annotation.IntDef;
Santiago Etchebeherec320c5f2021-05-14 17:35:57 -070024import androidx.annotation.NonNull;
Sunny Goyal8600a3f2018-08-15 12:48:01 -070025import androidx.annotation.Nullable;
26
Santiago Etchebeherec320c5f2021-05-14 17:35:57 -070027import com.android.wallpaper.model.LiveWallpaperInfo;
28import com.android.wallpaper.model.WallpaperInfo;
Kunhung Li166842e2020-05-13 19:19:06 +080029import com.android.wallpaper.module.WallpaperPersister.Destination;
30
Santiago Etchebeheree6d69b52019-06-14 18:42:46 -070031import java.util.List;
32
Jon Miranda16ea1b12017-12-12 14:52:48 -080033/**
34 * Interface for persisting and retrieving wallpaper specific preferences.
35 */
36public interface WallpaperPreferences {
37
38 int PRESENTATION_MODE_STATIC = 1;
39 int PRESENTATION_MODE_ROTATING = 2;
40 int WALLPAPER_SET_NOT_PENDING = 0;
41 int WALLPAPER_SET_PENDING = 1;
42 int DAILY_WALLPAPER_UPDATE_NOT_PENDING = 0;
43 int DAILY_WALLPAPER_UPDATE_PENDING = 1;
44
45 /**
46 * Returns the wallpaper presentation mode.
47 */
48 @PresentationMode
49 int getWallpaperPresentationMode();
50
51 /**
52 * Sets the presentation mode of the current wallpaper.
53 */
54 void setWallpaperPresentationMode(@PresentationMode int presentationMode);
55
56 /**
57 * Returns the home attributions as a list.
58 */
59 List<String> getHomeWallpaperAttributions();
60
61 /**
62 * Sets the attributions for the current home wallpaper. Clears existing attributions if any
63 * exist.
64 */
65 void setHomeWallpaperAttributions(List<String> attributions);
66
67 /**
68 * Returns the home wallpaper's action URL or null if there is none.
69 */
70 String getHomeWallpaperActionUrl();
71
72 /**
73 * Sets the home wallpaper's action URL.
74 */
75 void setHomeWallpaperActionUrl(String actionUrl);
76
77 /**
Santiago Etchebehered1bd5092018-04-18 16:03:30 -070078 * Returns the resource id for the home wallpaper's action label.
79 */
80 int getHomeWallpaperActionLabelRes();
81
82 /**
83 * Sets the resource id for the home wallpaper's action label.
84 */
85 void setHomeWallpaperActionLabelRes(int resId);
86
87 /**
88 * Returns the resource id for the home wallpaper's action icon.
89 */
90 int getHomeWallpaperActionIconRes();
91
92 /**
93 * Sets the resource id for the home wallpaper's action icon.
94 */
95 void setHomeWallpaperActionIconRes(int resId);
96
97 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -080098 * Returns the home wallpaper's base image URL or if there is none.
99 */
100 String getHomeWallpaperBaseImageUrl();
101
102 /**
103 * Sets the home wallpaper's base image URL.
104 */
105 void setHomeWallpaperBaseImageUrl(String baseImageUrl);
106
107 /**
108 * Returns the home wallpaper's collection ID or null if there is none.
109 */
110 String getHomeWallpaperCollectionId();
111
112 /**
113 * Sets the home wallpaper's collection ID.
114 */
115 void setHomeWallpaperCollectionId(String collectionId);
116
117 /**
Santiago Etchebeheree6d69b52019-06-14 18:42:46 -0700118 * Returns the home wallpaper's backing file name if there's one or null.
119 */
120 String getHomeWallpaperBackingFileName();
121
122 /**
123 * Sets the home wallpaper's backing file name
124 */
125 void setHomeWallpaperBackingFileName(String fileName);
126
127 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -0800128 * Removes all home metadata from SharedPreferences.
129 */
130 void clearHomeWallpaperMetadata();
131
132 /**
133 * Returns the home wallpaper's bitmap hash code or 0 if there is none.
134 */
135 long getHomeWallpaperHashCode();
136
137 /**
138 * Sets the home wallpaper's bitmap hash code if it is an individual image.
139 */
140 void setHomeWallpaperHashCode(long hashCode);
141
142 /**
143 * Gets the home wallpaper's package name, which is present for live wallpapers.
144 */
145 String getHomeWallpaperPackageName();
146
147 /**
148 * Sets the home wallpaper's package name, which is present for live wallpapers.
149 */
150 void setHomeWallpaperPackageName(String packageName);
151
152 /**
Kunhung Li3e50fd22020-05-12 20:46:18 +0800153 * Gets the home wallpaper's service name, which is present for live wallpapers.
154 */
155 String getHomeWallpaperServiceName();
156
157 /**
158 * Sets the home wallpaper's service name, which is present for live wallpapers.
159 */
160 void setHomeWallpaperServiceName(String serviceName);
161
162 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -0800163 * Gets the home wallpaper's ID, which is provided by WallpaperManager for static wallpapers.
164 */
165 @TargetApi(Build.VERSION_CODES.N)
166 int getHomeWallpaperManagerId();
167
168 /**
169 * Sets the home wallpaper's ID, which is provided by WallpaperManager for static wallpapers.
170 */
171 @TargetApi(Build.VERSION_CODES.N)
172 void setHomeWallpaperManagerId(int homeWallpaperId);
173
174 /**
175 * Gets the home wallpaper's remote identifier.
176 */
177 String getHomeWallpaperRemoteId();
178
179 /**
180 * Sets the home wallpaper's remote identifier to SharedPreferences. This should be a string
181 * which uniquely identifies the currently set home wallpaper in the context of a remote wallpaper
182 * collection.
183 */
184 void setHomeWallpaperRemoteId(String wallpaperRemoteId);
185
186 /**
187 * Returns the lock wallpaper's action URL or null if there is none.
188 */
189 String getLockWallpaperActionUrl();
190
191 /**
192 * Sets the lock wallpaper's action URL.
193 */
194 void setLockWallpaperActionUrl(String actionUrl);
195
196 /**
Santiago Etchebehered1bd5092018-04-18 16:03:30 -0700197 * Returns the resource id for the lock wallpaper's action label.
198 */
199 int getLockWallpaperActionLabelRes();
200
201 /**
202 * Sets the resource id for the lock wallpaper's action label.
203 */
204 void setLockWallpaperActionLabelRes(int resId);
205
206 /**
207 * Returns the resource id for the lock wallpaper's action icon.
208 */
209 int getLockWallpaperActionIconRes();
210
211 /**
212 * Sets the resource id for the lock wallpaper's action icon.
213 */
214 void setLockWallpaperActionIconRes(int resId);
215
216 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -0800217 * Returns the lock wallpaper's collection ID or null if there is none.
218 */
219 String getLockWallpaperCollectionId();
220
221 /**
222 * Sets the lock wallpaper's collection ID.
223 */
224 void setLockWallpaperCollectionId(String collectionId);
225
226 /**
Santiago Etchebeheree6d69b52019-06-14 18:42:46 -0700227 * Returns the home wallpaper's backing file name if there's one or null.
228 */
229 String getLockWallpaperBackingFileName();
230
231 /**
232 * Sets the home wallpaper's backing file name
233 */
234 void setLockWallpaperBackingFileName(String fileName);
235
236 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -0800237 * Returns the lock screen attributions as a list.
238 */
239 List<String> getLockWallpaperAttributions();
240
241 /**
242 * Sets the attributions for the current lock screen wallpaper. Clears existing attributions if
243 * any exist.
244 *
245 * @param attributions
246 */
247 void setLockWallpaperAttributions(List<String> attributions);
248
249 /**
250 * Removes all lock screen metadata from SharedPreferences.
251 */
252 void clearLockWallpaperMetadata();
253
254 /**
255 * Returns the lock screen wallpaper's bitmap hash code or 0 if there is none.
256 */
257 long getLockWallpaperHashCode();
258
259 /**
260 * Sets the lock screen wallpaper's bitmap hash code if it is an individual image.
261 */
262 void setLockWallpaperHashCode(long hashCode);
263
264 /**
265 * Gets the lock wallpaper's ID, which is provided by WallpaperManager for static wallpapers.
266 */
267 @TargetApi(Build.VERSION_CODES.N)
268 int getLockWallpaperId();
269
270 /**
271 * Sets the lock wallpaper's ID, which is provided by WallpaperManager for static wallpapers.
272 */
273 @TargetApi(Build.VERSION_CODES.N)
274 void setLockWallpaperId(int lockWallpaperId);
275
276 /**
“Chuck2c8626f2020-03-22 03:47:59 +0800277 * Gets the lock wallpaper's remote identifier.
278 */
279 String getLockWallpaperRemoteId();
280
281 /**
282 * Sets the lock wallpaper's remote identifier to SharedPreferences. This should be a string
283 * which uniquely identifies the currently set lock wallpaper in the context of a remote
284 * wallpaper collection.
285 */
286 void setLockWallpaperRemoteId(String wallpaperRemoteId);
287
288 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -0800289 * Persists the timestamp of a daily wallpaper rotation that just occurred.
290 */
291 void addDailyRotation(long timestamp);
292
293 /**
294 * Returns the timestamp of the last wallpaper daily rotation or -1 if there has never been a
295 * daily wallpaper rotation on the user's device.
296 */
297 long getLastDailyRotationTimestamp();
298
299 /**
300 * Gets a list of the daily rotation timestamps that occurred in the last week, from least
301 * recent at the start of the list to most recent at the end of the list.
302 * The timestamps are in milliseconds since Unix epoch.
303 * If daily rotation has been enabled for less than one week, returns null instead.
304 */
305 @Nullable
306 List<Long> getDailyRotationsInLastWeek();
307
308 /**
309 * Gets a list of the daily rotation timestamps that occurred the previous day (midnight to
310 * midnight in the user's timezone). Timestamps are in milliseconds since Unix epoch. Returns null
311 * if daily rotation was enabled earlier than midnight yesterday.
312 */
313 @Nullable
314 List<Long> getDailyRotationsPreviousDay();
315
316 /**
317 * Returns the daily wallpaper enabled timestamp in milliseconds since Unix epoch, or -1 if
318 * daily wallpaper is not currently enabled.
319 */
320 long getDailyWallpaperEnabledTimestamp();
321
322 /**
323 * Persists the timestamp when daily wallpaper feature was last enabled.
324 *
325 * @param timestamp Milliseconds since Unix epoch.
326 */
327 void setDailyWallpaperEnabledTimestamp(long timestamp);
328
329 /**
330 * Clears the persisted daily rotation timestamps and the "daily wallpaper enabled" timestamp.
331 * Called if daily rotation is disabled.
332 */
333 void clearDailyRotations();
334
335 /**
336 * Returns the timestamp of the most recent daily logging event, in milliseconds since Unix
337 * epoch. Returns -1 if the very first daily logging event has not occurred yet.
338 */
339 long getLastDailyLogTimestamp();
340
341 /**
342 * Sets the timestamp of the most recent daily logging event.
343 *
344 * @param timestamp Milliseconds since Unix epoch.
345 */
346 void setLastDailyLogTimestamp(long timestamp);
347
348 /**
349 * Returns the timestamp of the last time the app was noted to be active; i.e. the last time an
350 * activity entered the foreground (milliseconds since Unix epoch).
351 */
352 long getLastAppActiveTimestamp();
353
354 /**
355 * Sets the timestamp of the last time the app was noted to be active; i.e. the last time an
356 * activity entered the foreground.
357 *
358 * @param timestamp Milliseconds since Unix epoch.
359 */
360 void setLastAppActiveTimestamp(long timestamp);
361
362 /**
363 * Sets the last rotation status for daily wallpapers with a timestamp.
364 *
365 * @param status Last status code of daily rotation.
366 * @param timestamp Milliseconds since Unix epoch.
367 */
368 void setDailyWallpaperRotationStatus(int status, long timestamp);
369
370 /**
371 * Gets the last daily wallpapers rotation status or -1 if no rotation status has ever been
372 * persisted to preferences.
373 */
374 int getDailyWallpaperLastRotationStatus();
375
376 /**
377 * Gets the timestamp of the last set daily wallpapers rotation status in milliseconds since the
378 * Unix epoch or 0 if no rotation status has ever been persisted to preferences.
379 */
380 long getDailyWallpaperLastRotationStatusTimestamp();
381
382 /**
383 * Gets the timestamp of the last time a sync occurred of wallpaper data to or from this device.
384 * Returns 0 if a sync has never occurred before.
385 */
386 long getLastSyncTimestamp();
387
388 /**
389 * Sets the timestamp of the latest sync received or sent.
390 */
391 void setLastSyncTimestamp(long timestamp);
392
393 /**
394 * Sets the status of whether a wallpaper is currently pending being set (i.e., user tapped the
395 * UI to set a wallpaper but it has not yet been actually set on the device). Does so in a
396 * synchronous manner so a caller may be assured that the underlying store has been updated when
397 * this method returns.
398 */
399 void setPendingWallpaperSetStatusSync(@PendingWallpaperSetStatus int setStatus);
400
401 /**
402 * Gets the status of whether a wallpaper is currently pending being set.
403 */
404 @PendingWallpaperSetStatus
405 int getPendingWallpaperSetStatus();
406
407 /**
408 * Sets the status of whether a wallpaper is currently pending being set (i.e., user tapped the
409 * UI to set a wallpaper but it has not yet been actually set on the device). Does so in an
410 * asynchronous manner so writing the preference to the underlying store doesn't block the calling
411 * thread.
412 */
413 void setPendingWallpaperSetStatus(@PendingWallpaperSetStatus int setStatus);
414
415 /**
416 * Sets whether a daily wallpaper update is pending. Writes status to memory and also to disk
417 * before returning.
418 */
419 void setPendingDailyWallpaperUpdateStatusSync(
420 @PendingDailyWallpaperUpdateStatus int updateStatus);
421
422 /**
423 * Returns whether a daily wallpaper update is pending.
424 */
425 @PendingDailyWallpaperUpdateStatus
426 int getPendingDailyWallpaperUpdateStatus();
427
428 /**
429 * Sets whether a daily wallpaper update is pending. Writes status to memory immediately and to
430 * disk after returning.
431 */
432 void setPendingDailyWallpaperUpdateStatus(@PendingDailyWallpaperUpdateStatus int updateStatus);
433
434 /**
435 * Increments the number of consecutive days daily rotation has failed.
436 */
437 void incrementNumDaysDailyRotationFailed();
438
439 /**
440 * Gets the number of days daily rotation failed.
441 */
442 int getNumDaysDailyRotationFailed();
443
444 /**
445 * Resets the consecutive number of days daily rotation failed to 0.
446 */
447 void resetNumDaysDailyRotationFailed();
448
449 /**
450 * Increments the number of consecutive days daily rotation was not attempted.
451 */
452 void incrementNumDaysDailyRotationNotAttempted();
453
454 /**
455 * Gets the number ofconsecutive days daily rotation was not attempted.
456 */
457 int getNumDaysDailyRotationNotAttempted();
458
459 /**
460 * Resets the consecutive number of days daily rotation was not attempted to 0.
461 */
462 void resetNumDaysDailyRotationNotAttempted();
463
464 /**
Kunhung Li166842e2020-05-13 19:19:06 +0800465 * Return the count of wallpaper picker launch.
466 */
467 int getAppLaunchCount();
468
469 /**
470 * Return the date for the first time to launch wallpaper picker.
471 */
472 int getFirstLaunchDateSinceSetup();
473
474 /**
475 * Increments the number of wallpaper picker launch.
476 */
477 void incrementAppLaunched();
478
479 /**
480 * Returns the date for the first time to apply a wallpaper.
481 */
482 int getFirstWallpaperApplyDateSinceSetup();
483
484 /**
485 * Update currently set daily wallpaper info.
486 *
487 * @param destination The wallpaper destination, 1: home, 2: lockscreen, 3: both.
488 * @param collectionId wallpaper category.
489 * @param wallpaperId wallpaper id.
490 */
491 void updateDailyWallpaperSet(@Destination int destination, String collectionId,
492 String wallpaperId);
493
494 /**
Jon Miranda16ea1b12017-12-12 14:52:48 -0800495 * The possible wallpaper presentation modes, i.e., either "static" or "rotating".
496 */
497 @IntDef({
498 PRESENTATION_MODE_STATIC,
499 PRESENTATION_MODE_ROTATING})
500 @interface PresentationMode {
501 }
502
503 /**
504 * Possible status of whether a wallpaper set operation is pending or not.
505 */
506 @IntDef({
507 WALLPAPER_SET_NOT_PENDING,
508 WALLPAPER_SET_PENDING})
509 @interface PendingWallpaperSetStatus {
510 }
511
512 /**
513 * Possible status of whether a wallpaper set operation is pending or not.
514 */
515 @IntDef({
516 DAILY_WALLPAPER_UPDATE_NOT_PENDING,
517 DAILY_WALLPAPER_UPDATE_PENDING})
518 @interface PendingDailyWallpaperUpdateStatus {
519 }
Santiago Etchebeherec320c5f2021-05-14 17:35:57 -0700520
521 /**
522 * Stores the given live wallpaper in the recent wallpapers list
523 * @param wallpaperId unique identifier for this wallpaper
524 * @param wallpaper {@link LiveWallpaperInfo} for the applied wallpaper
525 * @param colors WallpaperColors to be used as placeholder for quickswitching
526 */
527 default void storeLatestHomeWallpaper(String wallpaperId,
528 @NonNull LiveWallpaperInfo wallpaper, WallpaperColors colors) {
529 // Do nothing in the default case.
530 }
531
532 /**
533 * Stores the given static wallpaper data in the recent wallpapers list.
534 * @param wallpaperId unique identifier for this wallpaper
535 * @param wallpaper {@link WallpaperInfo} for the applied wallpaper
536 * @param croppedWallpaperBitmap wallpaper bitmap exactly as applied to WallaperManager
537 * @param colors WallpaperColors to be used as placeholder for quickswitching
538 */
539 default void storeLatestHomeWallpaper(String wallpaperId, @NonNull WallpaperInfo wallpaper,
540 @NonNull Bitmap croppedWallpaperBitmap, WallpaperColors colors) {
541 // Do nothing in the default case.
542 }
Jon Miranda16ea1b12017-12-12 14:52:48 -0800543}