Check system & lock wallpaper backup eligibility independently
Bug 30751829 Change-Id: Ic94689dd63238449222d1aea07231d9fd29fc76d
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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 (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();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
// 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();
|
||||
// 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);
|
||||
}
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
Slog.v(TAG, "Wallpaper not backup-eligible; writing no data");
|
||||
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 (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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user