diff options
4 files changed, 46 insertions, 49 deletions
diff --git a/core/java/android/app/IWallpaperManager.aidl b/core/java/android/app/IWallpaperManager.aidl index db7d54bd40cf..ec22ff65a5f8 100644 --- a/core/java/android/app/IWallpaperManager.aidl +++ b/core/java/android/app/IWallpaperManager.aidl @@ -128,7 +128,7 @@ interface IWallpaperManager { /* * Backup: is the current system wallpaper image eligible for off-device backup? */ - boolean isWallpaperBackupEligible(int userId); + boolean isWallpaperBackupEligible(int which, int userId); /* * Keyguard: register a callback for being notified that lock-state relevant diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java index 20cbde176368..6e4466238af2 100644 --- a/core/java/android/app/WallpaperManager.java +++ b/core/java/android/app/WallpaperManager.java @@ -1680,13 +1680,13 @@ public class WallpaperManager { * Only the OS itself may use this method. * @hide */ - public boolean isWallpaperBackupEligible() { + public boolean isWallpaperBackupEligible(int which) { if (sGlobals.mService == null) { Log.w(TAG, "WallpaperService not running"); throw new RuntimeException(new DeadSystemException()); } try { - return sGlobals.mService.isWallpaperBackupEligible(mContext.getUserId()); + return sGlobals.mService.isWallpaperBackupEligible(which, mContext.getUserId()); } catch (RemoteException e) { Log.e(TAG, "Exception querying wallpaper backup eligibility: " + e.getMessage()); } diff --git a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java index 25530c4196b0..242eca8898ce 100644 --- a/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java +++ b/packages/WallpaperBackup/src/com/android/wallpaperbackup/WallpaperBackupAgent.java @@ -114,22 +114,19 @@ public class WallpaperBackupAgent extends BackupAgent { touch.close(); fullBackupFile(empty, data); - // only back up the wallpaper if we've been told it's allowed - if (mWm.isWallpaperBackupEligible()) { - if (DEBUG) { - Slog.v(TAG, "Wallpaper is backup-eligible"); - } + SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); + final int lastSysGeneration = prefs.getInt(SYSTEM_GENERATION, -1); + final int lastLockGeneration = prefs.getInt(LOCK_GENERATION, -1); - SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); - final int lastSysGeneration = prefs.getInt(SYSTEM_GENERATION, -1); - final int lastLockGeneration = prefs.getInt(LOCK_GENERATION, -1); + final int sysGeneration = + mWm.getWallpaperIdForUser(FLAG_SYSTEM, UserHandle.USER_SYSTEM); + final int lockGeneration = + mWm.getWallpaperIdForUser(FLAG_LOCK, UserHandle.USER_SYSTEM); + final boolean sysChanged = (sysGeneration != lastSysGeneration); + final boolean lockChanged = (lockGeneration != lastLockGeneration); - final int sysGeneration = - mWm.getWallpaperIdForUser(FLAG_SYSTEM, UserHandle.USER_SYSTEM); - final int lockGeneration = - mWm.getWallpaperIdForUser(FLAG_LOCK, UserHandle.USER_SYSTEM); - final boolean sysChanged = (sysGeneration != lastSysGeneration); - final boolean lockChanged = (lockGeneration != lastLockGeneration); + final boolean sysEligible = mWm.isWallpaperBackupEligible(FLAG_SYSTEM); + final boolean lockEligible = mWm.isWallpaperBackupEligible(FLAG_LOCK); // There might be a latent lock wallpaper file present but unused: don't // include it in the backup if that's the case. @@ -137,40 +134,38 @@ public class WallpaperBackupAgent extends BackupAgent { final boolean hasLockWallpaper = (lockFd != null); IoUtils.closeQuietly(lockFd); - if (DEBUG) { - Slog.v(TAG, "sysGen=" + sysGeneration + " : sysChanged=" + sysChanged); - Slog.v(TAG, "lockGen=" + lockGeneration + " : lockChanged=" + lockChanged); - Slog.v(TAG, "hasLockWallpaper=" + hasLockWallpaper); - } - if (mWallpaperInfo.exists()) { - if (sysChanged || lockChanged || !infoStage.exists()) { - if (DEBUG) Slog.v(TAG, "New wallpaper configuration; copying"); - FileUtils.copyFileOrThrow(mWallpaperInfo, infoStage); - } - fullBackupFile(infoStage, data); + if (DEBUG) { + Slog.v(TAG, "sysGen=" + sysGeneration + " : sysChanged=" + sysChanged); + Slog.v(TAG, "lockGen=" + lockGeneration + " : lockChanged=" + lockChanged); + Slog.v(TAG, "sysEligble=" + sysEligible); + Slog.v(TAG, "lockEligible=" + lockEligible); + } + + // only back up the wallpapers if we've been told they're eligible + if ((sysEligible || lockEligible) && mWallpaperInfo.exists()) { + if (sysChanged || lockChanged || !infoStage.exists()) { + if (DEBUG) Slog.v(TAG, "New wallpaper configuration; copying"); + FileUtils.copyFileOrThrow(mWallpaperInfo, infoStage); } - if (mWallpaperFile.exists()) { - if (sysChanged || !imageStage.exists()) { - if (DEBUG) Slog.v(TAG, "New system wallpaper; copying"); - FileUtils.copyFileOrThrow(mWallpaperFile, imageStage); - } - fullBackupFile(imageStage, data); - prefs.edit().putInt(SYSTEM_GENERATION, sysGeneration).apply(); + fullBackupFile(infoStage, data); + } + if (sysEligible && mWallpaperFile.exists()) { + if (sysChanged || !imageStage.exists()) { + if (DEBUG) Slog.v(TAG, "New system wallpaper; copying"); + FileUtils.copyFileOrThrow(mWallpaperFile, imageStage); } + fullBackupFile(imageStage, data); + prefs.edit().putInt(SYSTEM_GENERATION, sysGeneration).apply(); + } - // Don't try to store the lock image if we overran our quota last time - if (hasLockWallpaper && mLockWallpaperFile.exists() && !mQuotaExceeded) { - if (lockChanged || !lockImageStage.exists()) { - if (DEBUG) Slog.v(TAG, "New lock wallpaper; copying"); - FileUtils.copyFileOrThrow(mLockWallpaperFile, lockImageStage); - } - fullBackupFile(lockImageStage, data); - prefs.edit().putInt(LOCK_GENERATION, lockGeneration).apply(); - } - } else { - if (DEBUG) { - Slog.v(TAG, "Wallpaper not backup-eligible; writing no data"); + // Don't try to store the lock image if we overran our quota last time + if (lockEligible && hasLockWallpaper && mLockWallpaperFile.exists() && !mQuotaExceeded) { + if (lockChanged || !lockImageStage.exists()) { + if (DEBUG) Slog.v(TAG, "New lock wallpaper; copying"); + FileUtils.copyFileOrThrow(mLockWallpaperFile, lockImageStage); } + fullBackupFile(lockImageStage, data); + prefs.edit().putInt(LOCK_GENERATION, lockGeneration).apply(); } } catch (Exception e) { Slog.e(TAG, "Unable to back up wallpaper", e); diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 74a6131b11eb..71660280162d 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -1753,12 +1753,14 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { } @Override - public boolean isWallpaperBackupEligible(int userId) { + public boolean isWallpaperBackupEligible(int which, int userId) { if (Binder.getCallingUid() != Process.SYSTEM_UID) { throw new SecurityException("Only the system may call isWallpaperBackupEligible"); } - WallpaperData wallpaper = getWallpaperSafeLocked(userId, FLAG_SYSTEM); + WallpaperData wallpaper = (which == FLAG_LOCK) + ? mWallpaperMap.get(userId) + : mLockWallpaperMap.get(userId); return (wallpaper != null) ? wallpaper.allowBackup : false; } |