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