Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 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; |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 20 | |
Sunny Goyal | 8600a3f | 2018-08-15 12:48:01 -0700 | [diff] [blame] | 21 | import androidx.annotation.IntDef; |
| 22 | import androidx.annotation.Nullable; |
| 23 | |
Kunhung Li | 166842e | 2020-05-13 19:19:06 +0800 | [diff] [blame^] | 24 | import com.android.wallpaper.module.WallpaperPersister.Destination; |
| 25 | |
Santiago Etchebehere | e6d69b5 | 2019-06-14 18:42:46 -0700 | [diff] [blame] | 26 | import java.util.List; |
| 27 | |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 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 |
| 44 | int getWallpaperPresentationMode(); |
| 45 | |
| 46 | /** |
| 47 | * Sets the presentation mode of the current wallpaper. |
| 48 | */ |
| 49 | void setWallpaperPresentationMode(@PresentationMode int presentationMode); |
| 50 | |
| 51 | /** |
| 52 | * Returns the home attributions as a list. |
| 53 | */ |
| 54 | List<String> getHomeWallpaperAttributions(); |
| 55 | |
| 56 | /** |
| 57 | * Sets the attributions for the current home wallpaper. Clears existing attributions if any |
| 58 | * exist. |
| 59 | */ |
| 60 | void setHomeWallpaperAttributions(List<String> attributions); |
| 61 | |
| 62 | /** |
| 63 | * Returns the home wallpaper's action URL or null if there is none. |
| 64 | */ |
| 65 | String getHomeWallpaperActionUrl(); |
| 66 | |
| 67 | /** |
| 68 | * Sets the home wallpaper's action URL. |
| 69 | */ |
| 70 | void setHomeWallpaperActionUrl(String actionUrl); |
| 71 | |
| 72 | /** |
Santiago Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 73 | * Returns the resource id for the home wallpaper's action label. |
| 74 | */ |
| 75 | int getHomeWallpaperActionLabelRes(); |
| 76 | |
| 77 | /** |
| 78 | * Sets the resource id for the home wallpaper's action label. |
| 79 | */ |
| 80 | void setHomeWallpaperActionLabelRes(int resId); |
| 81 | |
| 82 | /** |
| 83 | * Returns the resource id for the home wallpaper's action icon. |
| 84 | */ |
| 85 | int getHomeWallpaperActionIconRes(); |
| 86 | |
| 87 | /** |
| 88 | * Sets the resource id for the home wallpaper's action icon. |
| 89 | */ |
| 90 | void setHomeWallpaperActionIconRes(int resId); |
| 91 | |
| 92 | /** |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 93 | * Returns the home wallpaper's base image URL or if there is none. |
| 94 | */ |
| 95 | String getHomeWallpaperBaseImageUrl(); |
| 96 | |
| 97 | /** |
| 98 | * Sets the home wallpaper's base image URL. |
| 99 | */ |
| 100 | void setHomeWallpaperBaseImageUrl(String baseImageUrl); |
| 101 | |
| 102 | /** |
| 103 | * Returns the home wallpaper's collection ID or null if there is none. |
| 104 | */ |
| 105 | String getHomeWallpaperCollectionId(); |
| 106 | |
| 107 | /** |
| 108 | * Sets the home wallpaper's collection ID. |
| 109 | */ |
| 110 | void setHomeWallpaperCollectionId(String collectionId); |
| 111 | |
| 112 | /** |
Santiago Etchebehere | e6d69b5 | 2019-06-14 18:42:46 -0700 | [diff] [blame] | 113 | * Returns the home wallpaper's backing file name if there's one or null. |
| 114 | */ |
| 115 | String getHomeWallpaperBackingFileName(); |
| 116 | |
| 117 | /** |
| 118 | * Sets the home wallpaper's backing file name |
| 119 | */ |
| 120 | void setHomeWallpaperBackingFileName(String fileName); |
| 121 | |
| 122 | /** |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 123 | * Removes all home metadata from SharedPreferences. |
| 124 | */ |
| 125 | void clearHomeWallpaperMetadata(); |
| 126 | |
| 127 | /** |
| 128 | * Returns the home wallpaper's bitmap hash code or 0 if there is none. |
| 129 | */ |
| 130 | long getHomeWallpaperHashCode(); |
| 131 | |
| 132 | /** |
| 133 | * Sets the home wallpaper's bitmap hash code if it is an individual image. |
| 134 | */ |
| 135 | void setHomeWallpaperHashCode(long hashCode); |
| 136 | |
| 137 | /** |
| 138 | * Gets the home wallpaper's package name, which is present for live wallpapers. |
| 139 | */ |
| 140 | String getHomeWallpaperPackageName(); |
| 141 | |
| 142 | /** |
| 143 | * Sets the home wallpaper's package name, which is present for live wallpapers. |
| 144 | */ |
| 145 | void setHomeWallpaperPackageName(String packageName); |
| 146 | |
| 147 | /** |
Kunhung Li | 3e50fd2 | 2020-05-12 20:46:18 +0800 | [diff] [blame] | 148 | * Gets the home wallpaper's service name, which is present for live wallpapers. |
| 149 | */ |
| 150 | String getHomeWallpaperServiceName(); |
| 151 | |
| 152 | /** |
| 153 | * Sets the home wallpaper's service name, which is present for live wallpapers. |
| 154 | */ |
| 155 | void setHomeWallpaperServiceName(String serviceName); |
| 156 | |
| 157 | /** |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 158 | * Gets the home wallpaper's ID, which is provided by WallpaperManager for static wallpapers. |
| 159 | */ |
| 160 | @TargetApi(Build.VERSION_CODES.N) |
| 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) |
| 167 | void setHomeWallpaperManagerId(int homeWallpaperId); |
| 168 | |
| 169 | /** |
| 170 | * Gets the home wallpaper's remote identifier. |
| 171 | */ |
| 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 | */ |
| 179 | void setHomeWallpaperRemoteId(String wallpaperRemoteId); |
| 180 | |
| 181 | /** |
| 182 | * Returns the lock wallpaper's action URL or null if there is none. |
| 183 | */ |
| 184 | String getLockWallpaperActionUrl(); |
| 185 | |
| 186 | /** |
| 187 | * Sets the lock wallpaper's action URL. |
| 188 | */ |
| 189 | void setLockWallpaperActionUrl(String actionUrl); |
| 190 | |
| 191 | /** |
Santiago Etchebehere | d1bd509 | 2018-04-18 16:03:30 -0700 | [diff] [blame] | 192 | * Returns the resource id for the lock wallpaper's action label. |
| 193 | */ |
| 194 | int getLockWallpaperActionLabelRes(); |
| 195 | |
| 196 | /** |
| 197 | * Sets the resource id for the lock wallpaper's action label. |
| 198 | */ |
| 199 | void setLockWallpaperActionLabelRes(int resId); |
| 200 | |
| 201 | /** |
| 202 | * Returns the resource id for the lock wallpaper's action icon. |
| 203 | */ |
| 204 | int getLockWallpaperActionIconRes(); |
| 205 | |
| 206 | /** |
| 207 | * Sets the resource id for the lock wallpaper's action icon. |
| 208 | */ |
| 209 | void setLockWallpaperActionIconRes(int resId); |
| 210 | |
| 211 | /** |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 212 | * Returns the lock wallpaper's collection ID or null if there is none. |
| 213 | */ |
| 214 | String getLockWallpaperCollectionId(); |
| 215 | |
| 216 | /** |
| 217 | * Sets the lock wallpaper's collection ID. |
| 218 | */ |
| 219 | void setLockWallpaperCollectionId(String collectionId); |
| 220 | |
| 221 | /** |
Santiago Etchebehere | e6d69b5 | 2019-06-14 18:42:46 -0700 | [diff] [blame] | 222 | * Returns the home wallpaper's backing file name if there's one or null. |
| 223 | */ |
| 224 | String getLockWallpaperBackingFileName(); |
| 225 | |
| 226 | /** |
| 227 | * Sets the home wallpaper's backing file name |
| 228 | */ |
| 229 | void setLockWallpaperBackingFileName(String fileName); |
| 230 | |
| 231 | /** |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 232 | * Returns the lock screen attributions as a list. |
| 233 | */ |
| 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 | */ |
| 242 | void setLockWallpaperAttributions(List<String> attributions); |
| 243 | |
| 244 | /** |
| 245 | * Removes all lock screen metadata from SharedPreferences. |
| 246 | */ |
| 247 | void clearLockWallpaperMetadata(); |
| 248 | |
| 249 | /** |
| 250 | * Returns the lock screen wallpaper's bitmap hash code or 0 if there is none. |
| 251 | */ |
| 252 | long getLockWallpaperHashCode(); |
| 253 | |
| 254 | /** |
| 255 | * Sets the lock screen wallpaper's bitmap hash code if it is an individual image. |
| 256 | */ |
| 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) |
| 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) |
| 269 | void setLockWallpaperId(int lockWallpaperId); |
| 270 | |
| 271 | /** |
“Chuck | 2c8626f | 2020-03-22 03:47:59 +0800 | [diff] [blame] | 272 | * Gets the lock wallpaper's remote identifier. |
| 273 | */ |
| 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 | */ |
| 281 | void setLockWallpaperRemoteId(String wallpaperRemoteId); |
| 282 | |
| 283 | /** |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 284 | * Persists the timestamp of a daily wallpaper rotation that just occurred. |
| 285 | */ |
| 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 | */ |
| 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 |
| 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 |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 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 | */ |
| 381 | long getLastSyncTimestamp(); |
| 382 | |
| 383 | /** |
| 384 | * Sets the timestamp of the latest sync received or sent. |
| 385 | */ |
| 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 | */ |
| 394 | void setPendingWallpaperSetStatusSync(@PendingWallpaperSetStatus int setStatus); |
| 395 | |
| 396 | /** |
| 397 | * Gets the status of whether a wallpaper is currently pending being set. |
| 398 | */ |
| 399 | @PendingWallpaperSetStatus |
| 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 | */ |
| 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 | */ |
| 414 | void setPendingDailyWallpaperUpdateStatusSync( |
| 415 | @PendingDailyWallpaperUpdateStatus int updateStatus); |
| 416 | |
| 417 | /** |
| 418 | * Returns whether a daily wallpaper update is pending. |
| 419 | */ |
| 420 | @PendingDailyWallpaperUpdateStatus |
| 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 | */ |
| 427 | void setPendingDailyWallpaperUpdateStatus(@PendingDailyWallpaperUpdateStatus int updateStatus); |
| 428 | |
| 429 | /** |
| 430 | * Increments the number of consecutive days daily rotation has failed. |
| 431 | */ |
| 432 | void incrementNumDaysDailyRotationFailed(); |
| 433 | |
| 434 | /** |
| 435 | * Gets the number of days daily rotation failed. |
| 436 | */ |
| 437 | int getNumDaysDailyRotationFailed(); |
| 438 | |
| 439 | /** |
| 440 | * Resets the consecutive number of days daily rotation failed to 0. |
| 441 | */ |
| 442 | void resetNumDaysDailyRotationFailed(); |
| 443 | |
| 444 | /** |
| 445 | * Increments the number of consecutive days daily rotation was not attempted. |
| 446 | */ |
| 447 | void incrementNumDaysDailyRotationNotAttempted(); |
| 448 | |
| 449 | /** |
| 450 | * Gets the number ofconsecutive days daily rotation was not attempted. |
| 451 | */ |
| 452 | int getNumDaysDailyRotationNotAttempted(); |
| 453 | |
| 454 | /** |
| 455 | * Resets the consecutive number of days daily rotation was not attempted to 0. |
| 456 | */ |
| 457 | void resetNumDaysDailyRotationNotAttempted(); |
| 458 | |
| 459 | /** |
Kunhung Li | 166842e | 2020-05-13 19:19:06 +0800 | [diff] [blame^] | 460 | * Return the count of wallpaper picker launch. |
| 461 | */ |
| 462 | int getAppLaunchCount(); |
| 463 | |
| 464 | /** |
| 465 | * Return the date for the first time to launch wallpaper picker. |
| 466 | */ |
| 467 | int getFirstLaunchDateSinceSetup(); |
| 468 | |
| 469 | /** |
| 470 | * Increments the number of wallpaper picker launch. |
| 471 | */ |
| 472 | void incrementAppLaunched(); |
| 473 | |
| 474 | /** |
| 475 | * Returns the date for the first time to apply a wallpaper. |
| 476 | */ |
| 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 | */ |
| 486 | void updateDailyWallpaperSet(@Destination int destination, String collectionId, |
| 487 | String wallpaperId); |
| 488 | |
| 489 | /** |
Jon Miranda | 16ea1b1 | 2017-12-12 14:52:48 -0800 | [diff] [blame] | 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 | } |