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

Commit c28d8270 authored by Aurélien Pomini's avatar Aurélien Pomini Committed by Android (Google) Code Review
Browse files

Merge "Delete outdated bitmaps when setting a live wallpaper" into udc-qpr-dev

parents 259ee2f2 983a074c
Loading
Loading
Loading
Loading
+16 −18
Original line number Diff line number Diff line
@@ -1775,21 +1775,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
@@ -1966,10 +1968,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;
@@ -2034,9 +2033,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;
@@ -3107,9 +3104,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);
        }
    }

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