diff options
| -rw-r--r-- | packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java | 16 | ||||
| -rw-r--r-- | packages/WallpaperBackup/test/src/com/android/wallpaperbackup/WallpaperBackupAgentTest.java | 15 |
2 files changed, 19 insertions, 12 deletions
diff --git a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java index 308e2cf01787..2ea6b51fc369 100644 --- a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java +++ b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java @@ -359,11 +359,12 @@ public class WallpaperBackupAgent extends BackupAgent { final File infoStage = new File(filesDir, WALLPAPER_INFO_STAGE); final File imageStage = new File(filesDir, SYSTEM_WALLPAPER_STAGE); final File lockImageStage = new File(filesDir, LOCK_WALLPAPER_STAGE); + boolean lockImageStageExists = lockImageStage.exists(); // If we restored separate lock imagery, the system wallpaper should be // applied as system-only; but if there's no separate lock image, make // sure to apply the restored system wallpaper as both. - final int sysWhich = FLAG_SYSTEM | (lockImageStage.exists() ? 0 : FLAG_LOCK); + final int sysWhich = FLAG_SYSTEM | (lockImageStageExists ? 0 : FLAG_LOCK); try { // First parse the live component name so that we know for logging if we care about @@ -374,11 +375,14 @@ public class WallpaperBackupAgent extends BackupAgent { // It is valid for the imagery to be absent; it means that we were not permitted // to back up the original image on the source device, or there was no user-supplied // wallpaper image present. + restoreFromStage(imageStage, infoStage, "wp", sysWhich); - restoreFromStage(lockImageStage, infoStage, "kwp", FLAG_LOCK); + if (lockImageStageExists) { + restoreFromStage(lockImageStage, infoStage, "kwp", FLAG_LOCK); + } // And reset to the wallpaper service we should be using - updateWallpaperComponent(wpService, !lockImageStage.exists()); + updateWallpaperComponent(wpService, !lockImageStageExists); } catch (Exception e) { Slog.e(TAG, "Unable to restore wallpaper: " + e.getMessage()); mEventLogger.onRestoreException(e); @@ -437,7 +441,8 @@ public class WallpaperBackupAgent extends BackupAgent { // And log the success if ((which & FLAG_SYSTEM) > 0) { mEventLogger.onSystemImageWallpaperRestored(); - } else { + } + if ((which & FLAG_LOCK) > 0) { mEventLogger.onLockImageWallpaperRestored(); } } @@ -460,7 +465,8 @@ public class WallpaperBackupAgent extends BackupAgent { private void logRestoreError(int which, String error) { if ((which & FLAG_SYSTEM) == FLAG_SYSTEM) { mEventLogger.onSystemImageWallpaperRestoreFailed(error); - } else if ((which & FLAG_LOCK) == FLAG_LOCK) { + } + if ((which & FLAG_LOCK) == FLAG_LOCK) { mEventLogger.onLockImageWallpaperRestoreFailed(error); } } diff --git a/packages/WallpaperBackup/test/src/com/android/wallpaperbackup/WallpaperBackupAgentTest.java b/packages/WallpaperBackup/test/src/com/android/wallpaperbackup/WallpaperBackupAgentTest.java index 9b07ad41ef9a..9cb9b20f681f 100644 --- a/packages/WallpaperBackup/test/src/com/android/wallpaperbackup/WallpaperBackupAgentTest.java +++ b/packages/WallpaperBackup/test/src/com/android/wallpaperbackup/WallpaperBackupAgentTest.java @@ -649,19 +649,20 @@ public class WallpaperBackupAgentTest { } @Test - public void testOnRestore_lockWallpaperImgMissingAndNoLive_logsFailure() throws Exception { + public void testOnRestore_wallpaperImgMissingAndNoLive_logsFailure() throws Exception { mockStagedWallpaperFile(WALLPAPER_INFO_STAGE); - mockStagedWallpaperFile(SYSTEM_WALLPAPER_STAGE); mWallpaperBackupAgent.onCreate(USER_HANDLE, BackupAnnotations.BackupDestination.CLOUD, BackupAnnotations.OperationType.RESTORE); mWallpaperBackupAgent.onRestoreFinished(); - DataTypeResult result = getLoggingResult(WALLPAPER_IMG_LOCK, - mWallpaperBackupAgent.getBackupRestoreEventLogger().getLoggingResults()); - assertThat(result).isNotNull(); - assertThat(result.getFailCount()).isEqualTo(1); - assertThat(result.getErrors()).containsKey(ERROR_NO_WALLPAPER); + for (String wallpaper: List.of(WALLPAPER_IMG_LOCK, WALLPAPER_IMG_SYSTEM)) { + DataTypeResult result = getLoggingResult(wallpaper, + mWallpaperBackupAgent.getBackupRestoreEventLogger().getLoggingResults()); + assertThat(result).isNotNull(); + assertThat(result.getFailCount()).isEqualTo(1); + assertThat(result.getErrors()).containsKey(ERROR_NO_WALLPAPER); + } } @Test |