diff options
author | Christopher Tate <ctate@google.com> | 2016-07-12 17:22:17 -0700 |
---|---|---|
committer | Christopher Tate <ctate@google.com> | 2016-07-12 17:26:58 -0700 |
commit | 5f829d287f5c8cd72fee1522b8308fa459adc122 (patch) | |
tree | 903d4bf5b9f71d0c8a60ffef625c923c8bc4a621 /packages/WallpaperBackup | |
parent | dbd5480ac464579c55e7692c2e9f0bb3dcddfe17 (diff) |
Test existence of wallpaper files before backing them up
Otherwise we attempt to link a nonexistent file, which throws, and then
we abort the whole backup outright. This way, we back up exactly what is
present regardless of the presence of each file individually.
We also now make sure to reset to the factory state and then apply the
restored content from there.
Bug 30102506
Change-Id: Ia6a39114f6b84e8cc01342df3da99833d7ca8e9b
Diffstat (limited to 'packages/WallpaperBackup')
-rw-r--r-- | packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java index 97efed0130be..05207b9f6b00 100644 --- a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java +++ b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java @@ -114,13 +114,17 @@ public class WallpaperBackupAgent extends BackupAgent { imageStage.delete(); lockImageStage.delete(); - Os.link(mWallpaperInfo.getCanonicalPath(), infoStage.getCanonicalPath()); - fullBackupFile(infoStage, data); - Os.link(mWallpaperFile.getCanonicalPath(), imageStage.getCanonicalPath()); - fullBackupFile(imageStage, data); + if (mWallpaperInfo.exists()) { + Os.link(mWallpaperInfo.getCanonicalPath(), infoStage.getCanonicalPath()); + fullBackupFile(infoStage, data); + } + if (mWallpaperFile.exists()) { + Os.link(mWallpaperFile.getCanonicalPath(), imageStage.getCanonicalPath()); + fullBackupFile(imageStage, data); + } // Don't try to store the lock image if we overran our quota last time - if (!mQuotaExceeded) { + if (mLockWallpaperFile.exists() && !mQuotaExceeded) { Os.link(mLockWallpaperFile.getCanonicalPath(), lockImageStage.getCanonicalPath()); fullBackupFile(lockImageStage, data); } @@ -130,7 +134,7 @@ public class WallpaperBackupAgent extends BackupAgent { } } } catch (Exception e) { - Slog.e(TAG, "Unable to back up wallpaper: " + e.getMessage()); + Slog.e(TAG, "Unable to back up wallpaper", e); } finally { if (DEBUG) { Slog.v(TAG, "Removing backup stage links"); @@ -173,6 +177,9 @@ public class WallpaperBackupAgent extends BackupAgent { final File lockImageStage = new File (filesDir, LOCK_IMAGE_STAGE); try { + // First off, revert to the factory state + mWm.clear(WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK); + // 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. |