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