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

Commit 983a074c authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Delete outdated bitmaps when setting a live wallpaper

Also, refactor (very slightly) with a "clearWallpaperBitmap" method.
This is a prerequisite to make Backup & Restore work well.
This will make sure getWallpaperFile() always return null for live
wallpapers, which is what we expect.

Flag: lockscreen-lwp
Bug: 283091821
Test: atest WallpaperManagerTest
Change-Id: I3a5b226f866d3662946e0229fc4120ea7fa0fb1b
parent 94862db1
Loading
Loading
Loading
Loading
+16 −18
Original line number Diff line number Diff line
@@ -1774,21 +1774,23 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            if (record.exists()) {
                Slog.w(TAG, "User:" + userID + ", wallpaper tyep = " + type
                        + ", wallpaper fail detect!! reset to default wallpaper");
                clearWallpaperData(userID, type);
                clearWallpaperBitmaps(userID, type);
                record.delete();
            }
        });
    }

    private void clearWallpaperData(int userID, int wallpaperType) {
    private void clearWallpaperBitmaps(int userID, int wallpaperType) {
        final WallpaperData wallpaper = new WallpaperData(userID, wallpaperType);
        if (wallpaper.sourceExists()) {
            wallpaper.wallpaperFile.delete();
        }
        if (wallpaper.cropExists()) {
            wallpaper.cropFile.delete();
        clearWallpaperBitmaps(wallpaper);
    }

    private boolean clearWallpaperBitmaps(WallpaperData wallpaper) {
        boolean sourceExists = wallpaper.sourceExists();
        boolean cropExists = wallpaper.cropExists();
        if (sourceExists) wallpaper.wallpaperFile.delete();
        if (cropExists) wallpaper.cropFile.delete();
        return sourceExists || cropExists;
    }

    @Override
@@ -1965,10 +1967,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub

        // files from the previous static wallpaper may still be stored in memory.
        // delete them in order to show the default wallpaper.
        if (wallpaper.wallpaperFile.exists()) {
            wallpaper.wallpaperFile.delete();
            wallpaper.cropFile.delete();
        }
        clearWallpaperBitmaps(wallpaper);

        bindWallpaperComponentLocked(mImageWallpaper, true, false, fallback, reply);
        if ((wallpaper.mWhich & FLAG_SYSTEM) != 0) mHomeWallpaperWaitingForUnlock = true;
@@ -2033,9 +2032,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub

        final long ident = Binder.clearCallingIdentity();
        try {
            if (wallpaper.wallpaperFile.exists()) {
                wallpaper.wallpaperFile.delete();
                wallpaper.cropFile.delete();
            if (clearWallpaperBitmaps(wallpaper)) {
                if (which == FLAG_LOCK) {
                    mLockWallpaperMap.remove(userId);
                    final IWallpaperManagerCallback cb = mKeyguardListener;
@@ -3104,9 +3101,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
            }
        } catch (ErrnoException e) {
            Slog.e(TAG, "Can't migrate system wallpaper: " + e.getMessage());
            lockWP.wallpaperFile.delete();
            lockWP.cropFile.delete();
            return;
            clearWallpaperBitmaps(lockWP);
        }
    }

@@ -3248,6 +3243,9 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                            });
                        }
                    }
                    if (!mImageWallpaper.equals(newWallpaper.wallpaperComponent)) {
                        clearWallpaperBitmaps(newWallpaper);
                    }
                    newWallpaper.wallpaperId = makeWallpaperIdLocked();
                    notifyCallbacksLocked(newWallpaper);
                    shouldNotifyColors = true;