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.app.WallpaperColors; 20 import android.graphics.Bitmap; 21 import android.os.Build; 22 23 import androidx.annotation.IntDef; 24 import androidx.annotation.NonNull; 25 import androidx.annotation.Nullable; 26 27 import com.android.wallpaper.model.LiveWallpaperInfo; 28 import com.android.wallpaper.model.WallpaperInfo; 29 import com.android.wallpaper.module.WallpaperPersister.Destination; 30 31 import java.util.List; 32 33 /** 34 * Interface for persisting and retrieving wallpaper specific preferences. 35 */ 36 public 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 getWallpaperPresentationMode()49 int getWallpaperPresentationMode(); 50 51 /** 52 * Sets the presentation mode of the current wallpaper. 53 */ setWallpaperPresentationMode(@resentationMode int presentationMode)54 void setWallpaperPresentationMode(@PresentationMode int presentationMode); 55 56 /** 57 * Returns the home attributions as a list. 58 */ getHomeWallpaperAttributions()59 List<String> getHomeWallpaperAttributions(); 60 61 /** 62 * Sets the attributions for the current home wallpaper. Clears existing attributions if any 63 * exist. 64 */ setHomeWallpaperAttributions(List<String> attributions)65 void setHomeWallpaperAttributions(List<String> attributions); 66 67 /** 68 * Returns the home wallpaper's action URL or null if there is none. 69 */ getHomeWallpaperActionUrl()70 String getHomeWallpaperActionUrl(); 71 72 /** 73 * Sets the home wallpaper's action URL. 74 */ setHomeWallpaperActionUrl(String actionUrl)75 void setHomeWallpaperActionUrl(String actionUrl); 76 77 /** 78 * Returns the resource id for the home wallpaper's action label. 79 */ getHomeWallpaperActionLabelRes()80 int getHomeWallpaperActionLabelRes(); 81 82 /** 83 * Sets the resource id for the home wallpaper's action label. 84 */ setHomeWallpaperActionLabelRes(int resId)85 void setHomeWallpaperActionLabelRes(int resId); 86 87 /** 88 * Returns the resource id for the home wallpaper's action icon. 89 */ getHomeWallpaperActionIconRes()90 int getHomeWallpaperActionIconRes(); 91 92 /** 93 * Sets the resource id for the home wallpaper's action icon. 94 */ setHomeWallpaperActionIconRes(int resId)95 void setHomeWallpaperActionIconRes(int resId); 96 97 /** 98 * Returns the home wallpaper's base image URL or if there is none. 99 */ getHomeWallpaperBaseImageUrl()100 String getHomeWallpaperBaseImageUrl(); 101 102 /** 103 * Sets the home wallpaper's base image URL. 104 */ setHomeWallpaperBaseImageUrl(String baseImageUrl)105 void setHomeWallpaperBaseImageUrl(String baseImageUrl); 106 107 /** 108 * Returns the home wallpaper's collection ID or null if there is none. 109 */ getHomeWallpaperCollectionId()110 String getHomeWallpaperCollectionId(); 111 112 /** 113 * Sets the home wallpaper's collection ID. 114 */ setHomeWallpaperCollectionId(String collectionId)115 void setHomeWallpaperCollectionId(String collectionId); 116 117 /** 118 * Returns the home wallpaper's backing file name if there's one or null. 119 */ getHomeWallpaperBackingFileName()120 String getHomeWallpaperBackingFileName(); 121 122 /** 123 * Sets the home wallpaper's backing file name 124 */ setHomeWallpaperBackingFileName(String fileName)125 void setHomeWallpaperBackingFileName(String fileName); 126 127 /** 128 * Removes all home metadata from SharedPreferences. 129 */ clearHomeWallpaperMetadata()130 void clearHomeWallpaperMetadata(); 131 132 /** 133 * Returns the home wallpaper's bitmap hash code or 0 if there is none. 134 */ getHomeWallpaperHashCode()135 long getHomeWallpaperHashCode(); 136 137 /** 138 * Sets the home wallpaper's bitmap hash code if it is an individual image. 139 */ setHomeWallpaperHashCode(long hashCode)140 void setHomeWallpaperHashCode(long hashCode); 141 142 /** 143 * Gets the home wallpaper's package name, which is present for live wallpapers. 144 */ getHomeWallpaperPackageName()145 String getHomeWallpaperPackageName(); 146 147 /** 148 * Sets the home wallpaper's package name, which is present for live wallpapers. 149 */ setHomeWallpaperPackageName(String packageName)150 void setHomeWallpaperPackageName(String packageName); 151 152 /** 153 * Gets the home wallpaper's service name, which is present for live wallpapers. 154 */ getHomeWallpaperServiceName()155 String getHomeWallpaperServiceName(); 156 157 /** 158 * Sets the home wallpaper's service name, which is present for live wallpapers. 159 */ setHomeWallpaperServiceName(String serviceName)160 void setHomeWallpaperServiceName(String serviceName); 161 162 /** 163 * Gets the home wallpaper's ID, which is provided by WallpaperManager for static wallpapers. 164 */ 165 @TargetApi(Build.VERSION_CODES.N) getHomeWallpaperManagerId()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) setHomeWallpaperManagerId(int homeWallpaperId)172 void setHomeWallpaperManagerId(int homeWallpaperId); 173 174 /** 175 * Gets the home wallpaper's remote identifier. 176 */ getHomeWallpaperRemoteId()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 */ setHomeWallpaperRemoteId(String wallpaperRemoteId)184 void setHomeWallpaperRemoteId(String wallpaperRemoteId); 185 186 /** 187 * Returns the lock wallpaper's action URL or null if there is none. 188 */ getLockWallpaperActionUrl()189 String getLockWallpaperActionUrl(); 190 191 /** 192 * Sets the lock wallpaper's action URL. 193 */ setLockWallpaperActionUrl(String actionUrl)194 void setLockWallpaperActionUrl(String actionUrl); 195 196 /** 197 * Returns the resource id for the lock wallpaper's action label. 198 */ getLockWallpaperActionLabelRes()199 int getLockWallpaperActionLabelRes(); 200 201 /** 202 * Sets the resource id for the lock wallpaper's action label. 203 */ setLockWallpaperActionLabelRes(int resId)204 void setLockWallpaperActionLabelRes(int resId); 205 206 /** 207 * Returns the resource id for the lock wallpaper's action icon. 208 */ getLockWallpaperActionIconRes()209 int getLockWallpaperActionIconRes(); 210 211 /** 212 * Sets the resource id for the lock wallpaper's action icon. 213 */ setLockWallpaperActionIconRes(int resId)214 void setLockWallpaperActionIconRes(int resId); 215 216 /** 217 * Returns the lock wallpaper's collection ID or null if there is none. 218 */ getLockWallpaperCollectionId()219 String getLockWallpaperCollectionId(); 220 221 /** 222 * Sets the lock wallpaper's collection ID. 223 */ setLockWallpaperCollectionId(String collectionId)224 void setLockWallpaperCollectionId(String collectionId); 225 226 /** 227 * Returns the home wallpaper's backing file name if there's one or null. 228 */ getLockWallpaperBackingFileName()229 String getLockWallpaperBackingFileName(); 230 231 /** 232 * Sets the home wallpaper's backing file name 233 */ setLockWallpaperBackingFileName(String fileName)234 void setLockWallpaperBackingFileName(String fileName); 235 236 /** 237 * Returns the lock screen attributions as a list. 238 */ getLockWallpaperAttributions()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 */ setLockWallpaperAttributions(List<String> attributions)247 void setLockWallpaperAttributions(List<String> attributions); 248 249 /** 250 * Removes all lock screen metadata from SharedPreferences. 251 */ clearLockWallpaperMetadata()252 void clearLockWallpaperMetadata(); 253 254 /** 255 * Returns the lock screen wallpaper's bitmap hash code or 0 if there is none. 256 */ getLockWallpaperHashCode()257 long getLockWallpaperHashCode(); 258 259 /** 260 * Sets the lock screen wallpaper's bitmap hash code if it is an individual image. 261 */ setLockWallpaperHashCode(long hashCode)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) getLockWallpaperId()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) setLockWallpaperId(int lockWallpaperId)274 void setLockWallpaperId(int lockWallpaperId); 275 276 /** 277 * Gets the lock wallpaper's remote identifier. 278 */ getLockWallpaperRemoteId()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 */ setLockWallpaperRemoteId(String wallpaperRemoteId)286 void setLockWallpaperRemoteId(String wallpaperRemoteId); 287 288 /** 289 * Persists the timestamp of a daily wallpaper rotation that just occurred. 290 */ addDailyRotation(long timestamp)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 */ getLastDailyRotationTimestamp()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 getDailyRotationsInLastWeek()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 getDailyRotationsPreviousDay()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 */ getDailyWallpaperEnabledTimestamp()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 */ setDailyWallpaperEnabledTimestamp(long timestamp)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 */ clearDailyRotations()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 */ getLastDailyLogTimestamp()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 */ setLastDailyLogTimestamp(long timestamp)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 */ getLastAppActiveTimestamp()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 */ setLastAppActiveTimestamp(long timestamp)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 */ setDailyWallpaperRotationStatus(int status, long timestamp)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 */ getDailyWallpaperLastRotationStatus()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 */ getDailyWallpaperLastRotationStatusTimestamp()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 */ getLastSyncTimestamp()386 long getLastSyncTimestamp(); 387 388 /** 389 * Sets the timestamp of the latest sync received or sent. 390 */ setLastSyncTimestamp(long timestamp)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 */ setPendingWallpaperSetStatusSync(@endingWallpaperSetStatus int setStatus)399 void setPendingWallpaperSetStatusSync(@PendingWallpaperSetStatus int setStatus); 400 401 /** 402 * Gets the status of whether a wallpaper is currently pending being set. 403 */ 404 @PendingWallpaperSetStatus getPendingWallpaperSetStatus()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 */ setPendingWallpaperSetStatus(@endingWallpaperSetStatus int setStatus)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 */ setPendingDailyWallpaperUpdateStatusSync( @endingDailyWallpaperUpdateStatus int updateStatus)419 void setPendingDailyWallpaperUpdateStatusSync( 420 @PendingDailyWallpaperUpdateStatus int updateStatus); 421 422 /** 423 * Returns whether a daily wallpaper update is pending. 424 */ 425 @PendingDailyWallpaperUpdateStatus getPendingDailyWallpaperUpdateStatus()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 */ setPendingDailyWallpaperUpdateStatus(@endingDailyWallpaperUpdateStatus int updateStatus)432 void setPendingDailyWallpaperUpdateStatus(@PendingDailyWallpaperUpdateStatus int updateStatus); 433 434 /** 435 * Increments the number of consecutive days daily rotation has failed. 436 */ incrementNumDaysDailyRotationFailed()437 void incrementNumDaysDailyRotationFailed(); 438 439 /** 440 * Gets the number of days daily rotation failed. 441 */ getNumDaysDailyRotationFailed()442 int getNumDaysDailyRotationFailed(); 443 444 /** 445 * Resets the consecutive number of days daily rotation failed to 0. 446 */ resetNumDaysDailyRotationFailed()447 void resetNumDaysDailyRotationFailed(); 448 449 /** 450 * Increments the number of consecutive days daily rotation was not attempted. 451 */ incrementNumDaysDailyRotationNotAttempted()452 void incrementNumDaysDailyRotationNotAttempted(); 453 454 /** 455 * Gets the number ofconsecutive days daily rotation was not attempted. 456 */ getNumDaysDailyRotationNotAttempted()457 int getNumDaysDailyRotationNotAttempted(); 458 459 /** 460 * Resets the consecutive number of days daily rotation was not attempted to 0. 461 */ resetNumDaysDailyRotationNotAttempted()462 void resetNumDaysDailyRotationNotAttempted(); 463 464 /** 465 * Return the count of wallpaper picker launch. 466 */ getAppLaunchCount()467 int getAppLaunchCount(); 468 469 /** 470 * Return the date for the first time to launch wallpaper picker. 471 */ getFirstLaunchDateSinceSetup()472 int getFirstLaunchDateSinceSetup(); 473 474 /** 475 * Increments the number of wallpaper picker launch. 476 */ incrementAppLaunched()477 void incrementAppLaunched(); 478 479 /** 480 * Returns the date for the first time to apply a wallpaper. 481 */ getFirstWallpaperApplyDateSinceSetup()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 */ updateDailyWallpaperSet(@estination int destination, String collectionId, String wallpaperId)491 void updateDailyWallpaperSet(@Destination int destination, String collectionId, 492 String wallpaperId); 493 494 /** 495 * 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 } 520 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 */ storeLatestHomeWallpaper(String wallpaperId, @NonNull LiveWallpaperInfo wallpaper, WallpaperColors colors)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 */ storeLatestHomeWallpaper(String wallpaperId, @NonNull WallpaperInfo wallpaper, @NonNull Bitmap croppedWallpaperBitmap, WallpaperColors colors)539 default void storeLatestHomeWallpaper(String wallpaperId, @NonNull WallpaperInfo wallpaper, 540 @NonNull Bitmap croppedWallpaperBitmap, WallpaperColors colors) { 541 // Do nothing in the default case. 542 } 543 544 /** 545 * Stores the given static wallpaper data in the recent wallpapers list. 546 * @param wallpaperId unique identifier for this wallpaper 547 * @param attributions List of attribution items. 548 * @param actionUrl The action or "explore" URL for the wallpaper. 549 * @param collectionId identifier of this wallpaper's collection. 550 * @param croppedWallpaperBitmap wallpaper bitmap exactly as applied to WallaperManager 551 * @param colors {@link WallpaperColors} to be used as placeholder for quickswitching 552 */ storeLatestHomeWallpaper(String wallpaperId, List<String> attributions, String actionUrl, String collectionId, @NonNull Bitmap croppedWallpaperBitmap, WallpaperColors colors)553 default void storeLatestHomeWallpaper(String wallpaperId, List<String> attributions, 554 String actionUrl, String collectionId, 555 @NonNull Bitmap croppedWallpaperBitmap, WallpaperColors colors) { 556 // Do nothing in the default case. 557 } 558 } 559