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