1 /* 2 * Copyright (C) 2019 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.testing; 17 18 import androidx.annotation.Nullable; 19 20 import com.android.wallpaper.module.WallpaperPreferences; 21 22 import java.util.ArrayList; 23 import java.util.Arrays; 24 import java.util.List; 25 26 /** 27 * Test implementation of the WallpaperPreferences interface. Just keeps prefs in memory. 28 */ 29 public class TestWallpaperPreferences implements WallpaperPreferences { 30 31 @PresentationMode 32 private int mWallpaperPresentationMode; 33 34 private List<String> mHomeScreenAttributions; 35 private long mHomeScreenBitmapHashCode; 36 private int mHomeWallpaperManagerId; 37 private String mHomeScreenPackageName; 38 private String mHomeActionUrl; 39 private String mHomeBaseImageUrl; 40 private String mHomeCollectionId; 41 private String mHomeWallpaperRemoteId; 42 43 private List<String> mLockScreenAttributions; 44 private long mLockScreenBitmapHashCode; 45 private int mLockWallpaperManagerId; 46 private String mLockActionUrl; 47 private String mLockCollectionId; 48 49 private List<Long> mDailyRotations; 50 private long mDailyWallpaperEnabledTimestamp; 51 private long mLastDailyLogTimestamp; 52 private long mLastAppActiveTimestamp; 53 private int mLastDailyWallpaperRotationStatus; 54 private long mLastDailyWallpaperRotationStatusTimestamp; 55 private long mLastSyncTimestamp; 56 @PendingWallpaperSetStatus 57 private int mPendingWallpaperSetStatus; 58 @PendingDailyWallpaperUpdateStatus 59 private int mPendingDailyWallpaperUpdateStatus; 60 private int mNumDaysDailyRotationFailed; 61 private int mNumDaysDailyRotationNotAttempted; 62 private int mHomeWallpaperActionLabelRes; 63 private int mHomeWallpaperActionIconRes; 64 private int mLockWallpaperActionLabelRes; 65 private int mLockWallpaperActionIconRes; 66 TestWallpaperPreferences()67 public TestWallpaperPreferences() { 68 mWallpaperPresentationMode = WallpaperPreferences.PRESENTATION_MODE_STATIC; 69 mHomeScreenAttributions = Arrays.asList("Android wallpaper"); 70 mHomeScreenBitmapHashCode = 0; 71 mHomeWallpaperManagerId = 0; 72 73 mLockScreenAttributions = Arrays.asList("Android wallpaper"); 74 mLockScreenBitmapHashCode = 0; 75 mLockWallpaperManagerId = 0; 76 77 mDailyRotations = new ArrayList<>(); 78 mDailyWallpaperEnabledTimestamp = -1; 79 mLastDailyLogTimestamp = -1; 80 mLastDailyWallpaperRotationStatus = -1; 81 mLastDailyWallpaperRotationStatusTimestamp = 0; 82 mLastSyncTimestamp = 0; 83 mPendingWallpaperSetStatus = WALLPAPER_SET_NOT_PENDING; 84 } 85 86 @Override getWallpaperPresentationMode()87 public int getWallpaperPresentationMode() { 88 return mWallpaperPresentationMode; 89 } 90 91 @Override setWallpaperPresentationMode(@resentationMode int presentationMode)92 public void setWallpaperPresentationMode(@PresentationMode int presentationMode) { 93 mWallpaperPresentationMode = presentationMode; 94 } 95 96 @Override getHomeWallpaperAttributions()97 public List<String> getHomeWallpaperAttributions() { 98 return mHomeScreenAttributions; 99 } 100 101 @Override setHomeWallpaperAttributions(List<String> attributions)102 public void setHomeWallpaperAttributions(List<String> attributions) { 103 mHomeScreenAttributions = attributions; 104 } 105 106 @Override getHomeWallpaperActionUrl()107 public String getHomeWallpaperActionUrl() { 108 return mHomeActionUrl; 109 } 110 111 @Override setHomeWallpaperActionUrl(String actionUrl)112 public void setHomeWallpaperActionUrl(String actionUrl) { 113 mHomeActionUrl = actionUrl; 114 } 115 116 @Override getHomeWallpaperActionLabelRes()117 public int getHomeWallpaperActionLabelRes() { 118 return mHomeWallpaperActionLabelRes; 119 } 120 121 @Override setHomeWallpaperActionLabelRes(int resId)122 public void setHomeWallpaperActionLabelRes(int resId) { 123 mHomeWallpaperActionLabelRes = resId; 124 } 125 126 @Override getHomeWallpaperActionIconRes()127 public int getHomeWallpaperActionIconRes() { 128 return mHomeWallpaperActionIconRes; 129 } 130 131 @Override setHomeWallpaperActionIconRes(int resId)132 public void setHomeWallpaperActionIconRes(int resId) { 133 mHomeWallpaperActionIconRes = resId; 134 } 135 136 @Override getHomeWallpaperBaseImageUrl()137 public String getHomeWallpaperBaseImageUrl() { 138 return mHomeBaseImageUrl; 139 } 140 141 @Override setHomeWallpaperBaseImageUrl(String baseImageUrl)142 public void setHomeWallpaperBaseImageUrl(String baseImageUrl) { 143 mHomeBaseImageUrl = baseImageUrl; 144 } 145 146 @Override getHomeWallpaperCollectionId()147 public String getHomeWallpaperCollectionId() { 148 return mHomeCollectionId; 149 } 150 151 @Override setHomeWallpaperCollectionId(String collectionId)152 public void setHomeWallpaperCollectionId(String collectionId) { 153 mHomeCollectionId = collectionId; 154 } 155 156 @Override getHomeWallpaperBackingFileName()157 public String getHomeWallpaperBackingFileName() { 158 return null; 159 } 160 161 @Override setHomeWallpaperBackingFileName(String fileName)162 public void setHomeWallpaperBackingFileName(String fileName) { 163 164 } 165 166 @Override clearHomeWallpaperMetadata()167 public void clearHomeWallpaperMetadata() { 168 mHomeScreenAttributions = null; 169 mWallpaperPresentationMode = WallpaperPreferences.PRESENTATION_MODE_STATIC; 170 mHomeScreenBitmapHashCode = 0; 171 mHomeScreenPackageName = null; 172 mHomeWallpaperManagerId = 0; 173 } 174 175 @Override getHomeWallpaperHashCode()176 public long getHomeWallpaperHashCode() { 177 return mHomeScreenBitmapHashCode; 178 } 179 180 @Override setHomeWallpaperHashCode(long hashCode)181 public void setHomeWallpaperHashCode(long hashCode) { 182 mHomeScreenBitmapHashCode = hashCode; 183 } 184 185 @Override getHomeWallpaperPackageName()186 public String getHomeWallpaperPackageName() { 187 return mHomeScreenPackageName; 188 } 189 190 @Override setHomeWallpaperPackageName(String packageName)191 public void setHomeWallpaperPackageName(String packageName) { 192 mHomeScreenPackageName = packageName; 193 } 194 195 @Override getHomeWallpaperManagerId()196 public int getHomeWallpaperManagerId() { 197 return mHomeWallpaperManagerId; 198 } 199 200 @Override setHomeWallpaperManagerId(int homeWallpaperId)201 public void setHomeWallpaperManagerId(int homeWallpaperId) { 202 mHomeWallpaperManagerId = homeWallpaperId; 203 } 204 205 @Override getHomeWallpaperRemoteId()206 public String getHomeWallpaperRemoteId() { 207 return mHomeWallpaperRemoteId; 208 } 209 210 @Override setHomeWallpaperRemoteId(String wallpaperRemoteId)211 public void setHomeWallpaperRemoteId(String wallpaperRemoteId) { 212 mHomeWallpaperRemoteId = wallpaperRemoteId; 213 } 214 215 @Override getLockWallpaperAttributions()216 public List<String> getLockWallpaperAttributions() { 217 return mLockScreenAttributions; 218 } 219 220 @Override setLockWallpaperAttributions(List<String> attributions)221 public void setLockWallpaperAttributions(List<String> attributions) { 222 mLockScreenAttributions = attributions; 223 } 224 225 @Override getLockWallpaperActionUrl()226 public String getLockWallpaperActionUrl() { 227 return mLockActionUrl; 228 } 229 230 @Override setLockWallpaperActionUrl(String actionUrl)231 public void setLockWallpaperActionUrl(String actionUrl) { 232 mLockActionUrl = actionUrl; 233 } 234 235 @Override getLockWallpaperActionLabelRes()236 public int getLockWallpaperActionLabelRes() { 237 return mLockWallpaperActionLabelRes; 238 } 239 240 @Override setLockWallpaperActionLabelRes(int resId)241 public void setLockWallpaperActionLabelRes(int resId) { 242 mLockWallpaperActionLabelRes = resId; 243 } 244 245 @Override getLockWallpaperActionIconRes()246 public int getLockWallpaperActionIconRes() { 247 return mLockWallpaperActionIconRes; 248 } 249 250 @Override setLockWallpaperActionIconRes(int resId)251 public void setLockWallpaperActionIconRes(int resId) { 252 mLockWallpaperActionIconRes = resId; 253 } 254 255 @Override getLockWallpaperCollectionId()256 public String getLockWallpaperCollectionId() { 257 return mLockCollectionId; 258 } 259 260 @Override setLockWallpaperCollectionId(String collectionId)261 public void setLockWallpaperCollectionId(String collectionId) { 262 mLockCollectionId = collectionId; 263 } 264 265 @Override getLockWallpaperBackingFileName()266 public String getLockWallpaperBackingFileName() { 267 return null; 268 } 269 270 @Override setLockWallpaperBackingFileName(String fileName)271 public void setLockWallpaperBackingFileName(String fileName) { 272 273 } 274 275 @Override clearLockWallpaperMetadata()276 public void clearLockWallpaperMetadata() { 277 mLockScreenAttributions = null; 278 mLockScreenBitmapHashCode = 0; 279 mLockWallpaperManagerId = 0; 280 } 281 282 @Override getLockWallpaperHashCode()283 public long getLockWallpaperHashCode() { 284 return mLockScreenBitmapHashCode; 285 } 286 287 @Override setLockWallpaperHashCode(long hashCode)288 public void setLockWallpaperHashCode(long hashCode) { 289 mLockScreenBitmapHashCode = hashCode; 290 } 291 292 @Override getLockWallpaperId()293 public int getLockWallpaperId() { 294 return mLockWallpaperManagerId; 295 } 296 297 @Override setLockWallpaperId(int lockWallpaperId)298 public void setLockWallpaperId(int lockWallpaperId) { 299 mLockWallpaperManagerId = lockWallpaperId; 300 } 301 302 @Override addDailyRotation(long timestamp)303 public void addDailyRotation(long timestamp) { 304 mDailyRotations.add(timestamp); 305 } 306 307 @Override getLastDailyRotationTimestamp()308 public long getLastDailyRotationTimestamp() { 309 if (mDailyRotations.size() == 0) { 310 return -1; 311 } 312 313 return mDailyRotations.get(mDailyRotations.size() - 1); 314 } 315 316 @Override getDailyRotationsInLastWeek()317 public List<Long> getDailyRotationsInLastWeek() { 318 return mDailyRotations; 319 } 320 321 @Nullable 322 @Override getDailyRotationsPreviousDay()323 public List<Long> getDailyRotationsPreviousDay() { 324 return null; 325 } 326 327 @Override getDailyWallpaperEnabledTimestamp()328 public long getDailyWallpaperEnabledTimestamp() { 329 return mDailyWallpaperEnabledTimestamp; 330 } 331 332 @Override setDailyWallpaperEnabledTimestamp(long timestamp)333 public void setDailyWallpaperEnabledTimestamp(long timestamp) { 334 mDailyWallpaperEnabledTimestamp = timestamp; 335 } 336 337 @Override clearDailyRotations()338 public void clearDailyRotations() { 339 mDailyRotations.clear(); 340 } 341 342 @Override getLastDailyLogTimestamp()343 public long getLastDailyLogTimestamp() { 344 return mLastDailyLogTimestamp; 345 } 346 347 @Override setLastDailyLogTimestamp(long timestamp)348 public void setLastDailyLogTimestamp(long timestamp) { 349 mLastDailyLogTimestamp = timestamp; 350 } 351 352 @Override getLastAppActiveTimestamp()353 public long getLastAppActiveTimestamp() { 354 return mLastAppActiveTimestamp; 355 } 356 357 @Override setLastAppActiveTimestamp(long timestamp)358 public void setLastAppActiveTimestamp(long timestamp) { 359 mLastAppActiveTimestamp = timestamp; 360 } 361 362 @Override setDailyWallpaperRotationStatus(int status, long timestamp)363 public void setDailyWallpaperRotationStatus(int status, long timestamp) { 364 mLastDailyWallpaperRotationStatus = status; 365 mLastDailyWallpaperRotationStatusTimestamp = timestamp; 366 } 367 368 @Override getDailyWallpaperLastRotationStatus()369 public int getDailyWallpaperLastRotationStatus() { 370 return mLastDailyWallpaperRotationStatus; 371 } 372 373 @Override getDailyWallpaperLastRotationStatusTimestamp()374 public long getDailyWallpaperLastRotationStatusTimestamp() { 375 return mLastDailyWallpaperRotationStatusTimestamp; 376 } 377 378 @Override getLastSyncTimestamp()379 public long getLastSyncTimestamp() { 380 return mLastSyncTimestamp; 381 } 382 383 @Override setLastSyncTimestamp(long timestamp)384 public void setLastSyncTimestamp(long timestamp) { 385 mLastSyncTimestamp = timestamp; 386 } 387 388 @Override setPendingWallpaperSetStatusSync(@endingWallpaperSetStatus int setStatus)389 public void setPendingWallpaperSetStatusSync(@PendingWallpaperSetStatus int setStatus) { 390 mPendingWallpaperSetStatus = setStatus; 391 } 392 393 @Override getPendingWallpaperSetStatus()394 public int getPendingWallpaperSetStatus() { 395 return mPendingWallpaperSetStatus; 396 } 397 398 @Override setPendingWallpaperSetStatus(@endingWallpaperSetStatus int setStatus)399 public void setPendingWallpaperSetStatus(@PendingWallpaperSetStatus int setStatus) { 400 mPendingWallpaperSetStatus = setStatus; 401 } 402 403 @Override setPendingDailyWallpaperUpdateStatusSync( @endingDailyWallpaperUpdateStatus int updateStatus)404 public void setPendingDailyWallpaperUpdateStatusSync( 405 @PendingDailyWallpaperUpdateStatus int updateStatus) { 406 mPendingDailyWallpaperUpdateStatus = updateStatus; 407 } 408 409 @Override getPendingDailyWallpaperUpdateStatus()410 public int getPendingDailyWallpaperUpdateStatus() { 411 return mPendingDailyWallpaperUpdateStatus; 412 } 413 414 @Override setPendingDailyWallpaperUpdateStatus( @endingDailyWallpaperUpdateStatus int updateStatus)415 public void setPendingDailyWallpaperUpdateStatus( 416 @PendingDailyWallpaperUpdateStatus int updateStatus) { 417 mPendingDailyWallpaperUpdateStatus = updateStatus; 418 } 419 420 @Override incrementNumDaysDailyRotationFailed()421 public void incrementNumDaysDailyRotationFailed() { 422 mNumDaysDailyRotationFailed++; 423 } 424 425 @Override getNumDaysDailyRotationFailed()426 public int getNumDaysDailyRotationFailed() { 427 return mNumDaysDailyRotationFailed; 428 } 429 setNumDaysDailyRotationFailed(int days)430 public void setNumDaysDailyRotationFailed(int days) { 431 mNumDaysDailyRotationFailed = days; 432 } 433 434 @Override resetNumDaysDailyRotationFailed()435 public void resetNumDaysDailyRotationFailed() { 436 mNumDaysDailyRotationFailed = 0; 437 } 438 439 @Override incrementNumDaysDailyRotationNotAttempted()440 public void incrementNumDaysDailyRotationNotAttempted() { 441 mNumDaysDailyRotationNotAttempted++; 442 } 443 444 @Override getNumDaysDailyRotationNotAttempted()445 public int getNumDaysDailyRotationNotAttempted() { 446 return mNumDaysDailyRotationNotAttempted; 447 } 448 setNumDaysDailyRotationNotAttempted(int days)449 public void setNumDaysDailyRotationNotAttempted(int days) { 450 mNumDaysDailyRotationNotAttempted = days; 451 } 452 453 @Override resetNumDaysDailyRotationNotAttempted()454 public void resetNumDaysDailyRotationNotAttempted() { 455 mNumDaysDailyRotationNotAttempted = 0; 456 } 457 } 458