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