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

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

WallpaperColors.fromDrawable Drawable mutation

WallpaperColors.fromDrawable should never mutate Drawable bounds

Test: tests/app/src/android/app/cts/WallpaperColorsTest.java
Change-Id: I7467033c6a4e587b04e60423ceec3404b980cdf2
Fixes: 73506557
parent 9bbd9661
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
@@ -107,6 +108,11 @@ public final class WallpaperColors implements Parcelable {
     * @param drawable Source where to extract from.
     */
    public static WallpaperColors fromDrawable(Drawable drawable) {
        if (drawable == null) {
            throw new IllegalArgumentException("Drawable cannot be null");
        }

        Rect initialBounds = drawable.copyBounds();
        int width = drawable.getIntrinsicWidth();
        int height = drawable.getIntrinsicHeight();

@@ -126,6 +132,7 @@ public final class WallpaperColors implements Parcelable {
        final WallpaperColors colors = WallpaperColors.fromBitmap(bitmap);
        bitmap.recycle();

        drawable.setBounds(initialBounds);
        return colors;
    }