Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd59a27f authored by Chris Tate's avatar Chris Tate Committed by Android (Google) Code Review
Browse files

Merge "Check system & lock wallpaper backup eligibility independently" into nyc-mr1-dev

parents fd97e7bc 61722661
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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());
        }
+39 −44
Original line number Diff line number Diff line
@@ -114,12 +114,6 @@ 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);
@@ -131,6 +125,9 @@ public class WallpaperBackupAgent extends BackupAgent {
            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.
                ParcelFileDescriptor lockFd = mWm.getWallpaperFile(FLAG_LOCK, UserHandle.USER_SYSTEM);
@@ -140,16 +137,19 @@ public class WallpaperBackupAgent extends BackupAgent {
            if (DEBUG) {
                Slog.v(TAG, "sysGen=" + sysGeneration + " : sysChanged=" + sysChanged);
                Slog.v(TAG, "lockGen=" + lockGeneration + " : lockChanged=" + lockChanged);
                    Slog.v(TAG, "hasLockWallpaper=" + hasLockWallpaper);
                Slog.v(TAG, "sysEligble=" + sysEligible);
                Slog.v(TAG, "lockEligible=" + lockEligible);
            }
                if (mWallpaperInfo.exists()) {

            // 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);
                }
                fullBackupFile(infoStage, data);
            }
                if (mWallpaperFile.exists()) {
            if (sysEligible && mWallpaperFile.exists()) {
                if (sysChanged || !imageStage.exists()) {
                    if (DEBUG) Slog.v(TAG, "New system wallpaper; copying");
                    FileUtils.copyFileOrThrow(mWallpaperFile, imageStage);
@@ -159,7 +159,7 @@ public class WallpaperBackupAgent extends BackupAgent {
            }

            // Don't try to store the lock image if we overran our quota last time
                if (hasLockWallpaper && mLockWallpaperFile.exists() && !mQuotaExceeded) {
            if (lockEligible && hasLockWallpaper && mLockWallpaperFile.exists() && !mQuotaExceeded) {
                if (lockChanged || !lockImageStage.exists()) {
                    if (DEBUG) Slog.v(TAG, "New lock wallpaper; copying");
                    FileUtils.copyFileOrThrow(mLockWallpaperFile, lockImageStage);
@@ -167,11 +167,6 @@ public class WallpaperBackupAgent extends BackupAgent {
                fullBackupFile(lockImageStage, data);
                prefs.edit().putInt(LOCK_GENERATION, lockGeneration).apply();
            }
            } else {
                if (DEBUG) {
                    Slog.v(TAG, "Wallpaper not backup-eligible; writing no data");
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Unable to back up wallpaper", e);
        } finally {
+4 −2
Original line number Diff line number Diff line
@@ -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;
    }