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

Commit d8e12442 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Do not allow wallpapers that are too large

DisplayListCanvas, that draws Bitmaps on the Android framework,
has a bitmap size limit. Let's respect the limit to guarantee
that SystemUI won't crashloop when a bitmap is over 100MB

Test: manual, setting wallpaper
Change-Id: Iff91e73722a912efe095f80e263e160cc2456a11
Fixes: 111330638
parent dee54a44
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public final class DisplayListCanvas extends RecordingCanvas {
    // view hierarchy because display lists are generated recursively.
    private static final int POOL_LIMIT = 25;

    private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
    public static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB

    private static final SynchronizedPool<DisplayListCanvas> sPool =
            new SynchronizedPool<>(POOL_LIMIT);
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.view.Display;
import android.view.DisplayInfo;
import android.view.DisplayListCanvas;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.WindowManager;
@@ -366,7 +367,12 @@ public class ImageWallpaper extends WallpaperService {
                protected Bitmap doInBackground(Void... params) {
                    Throwable exception;
                    try {
                        return mWallpaperManager.getBitmap(true /* hardware */);
                        Bitmap wallpaper = mWallpaperManager.getBitmap(true /* hardware */);
                        if (wallpaper != null
                                && wallpaper.getByteCount() > DisplayListCanvas.MAX_BITMAP_SIZE) {
                            throw new RuntimeException("Wallpaper is too large to draw!");
                        }
                        return wallpaper;
                    } catch (RuntimeException | OutOfMemoryError e) {
                        exception = e;
                    }