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