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

Commit 2acaeda4 authored by Adrian Roos's avatar Adrian Roos
Browse files

Fix Bitmap leaks in ImageWallpaper

Bug: 18350603
Change-Id: I42ec057cd287955dcf3c382c237806fd9d6666a7
parent a816a075
Loading
Loading
Loading
Loading
+90 −84
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ public class ImageWallpaper extends WallpaperService {

        public void trimMemory(int level) {
            if (level >= ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW &&
                    mBackground != null && mIsHwAccelerated) {
                    mBackground != null) {
                if (DEBUG) {
                    Log.d(TAG, "trimMemory");
                }
@@ -212,6 +212,7 @@ public class ImageWallpaper extends WallpaperService {
                unregisterReceiver(mReceiver);
            }
            mBackground = null;
            mWallpaperManager.forgetLoadedWallpaper();
        }

        void updateSurfaceSize(SurfaceHolder surfaceHolder) {
@@ -337,6 +338,7 @@ public class ImageWallpaper extends WallpaperService {
        }

        void drawFrame() {
            try {
                int newRotation = ((WindowManager) getSystemService(WINDOW_SERVICE)).
                        getDefaultDisplay().getRotation();

@@ -351,7 +353,8 @@ public class ImageWallpaper extends WallpaperService {
                final Rect frame = sh.getSurfaceFrame();
                final int dw = frame.width();
                final int dh = frame.height();
            boolean surfaceDimensionsChanged = dw != mLastSurfaceWidth || dh != mLastSurfaceHeight;
                boolean surfaceDimensionsChanged = dw != mLastSurfaceWidth
                        || dh != mLastSurfaceHeight;

                boolean redrawNeeded = surfaceDimensionsChanged || newRotation != mLastRotation;
                if (!redrawNeeded && !mOffsetsChanged) {
@@ -402,8 +405,10 @@ public class ImageWallpaper extends WallpaperService {
                // will remain unchanged
                final int availwUnscaled = dw - mBackground.getWidth();
                final int availhUnscaled = dh - mBackground.getHeight();
            if (availwUnscaled < 0) xPixels += (int)(availwUnscaled * (mXOffset - .5f) + .5f);
            if (availhUnscaled < 0) yPixels += (int)(availhUnscaled * (mYOffset - .5f) + .5f);
                if (availwUnscaled < 0)
                    xPixels += (int) (availwUnscaled * (mXOffset - .5f) + .5f);
                if (availhUnscaled < 0)
                    yPixels += (int) (availhUnscaled * (mYOffset - .5f) + .5f);

                mOffsetsChanged = false;
                mRedrawNeeded = false;
@@ -431,17 +436,18 @@ public class ImageWallpaper extends WallpaperService {
                    }
                } else {
                    drawWallpaperWithCanvas(sh, availw, availh, xPixels, yPixels);
                if (FIXED_SIZED_SURFACE) {
                }
            } finally {
                if (FIXED_SIZED_SURFACE && !mIsHwAccelerated) {
                    // If the surface is fixed-size, we should only need to
                    // draw it once and then we'll let the window manager
                    // position it appropriately.  As such, we no longer needed
                    // the loaded bitmap.  Yay!
                    // hw-accelerated path retains bitmap for faster rotation
                    // hw-accelerated renderer retains bitmap for faster rotation
                    mBackground = null;
                    mWallpaperManager.forgetLoadedWallpaper();
                }
            }

        }

        private void updateWallpaperLocked() {