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

Commit de1e4c0c authored by Julia Tuttle's avatar Julia Tuttle
Browse files

BigPictureStyle: discard empty Icon BitmapDrawables

If Icon.loadDrawable successfully opens an InputStream for an Icon's
URI, but fails to decode an image from that stream, it currently returns
a BitmapDrawable with a null Bitmap.

Right now, we treat that as a valid drawable and try to render it,
leaving a blank space in the notification where the bitmap would've gone.

Instead, when the corresponding flag is enabled, treat these empty
BitmapDrawables as if loadDrawable had returned null directly.

TODO: I dunno why but my flag isn't showing up when I build this change?

Bug: 335878768
Flag: ACONFIG android.widget.flags.big_picture_style_discard_empty_icon_bitmap_drawables START
Test: manual
Change-Id: I7adda22d97072e7d234c2c58501ad6b2334db997
parent dbec7031
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.flags.Flags;

import com.android.internal.R;

@@ -124,9 +125,14 @@ public class BigPictureNotificationImageView extends ImageView implements
    public void setImageDrawable(@Nullable Drawable drawable) {
        if (drawable instanceof BitmapDrawable bitmapDrawable) {
            if (bitmapDrawable.getBitmap() == null) {
                if (Flags.bigPictureStyleDiscardEmptyIconBitmapDrawables()) {
                    Log.e(TAG, "discarding BitmapDrawable with null Bitmap (invalid image file?)");
                    drawable = null;
                } else {
                    Log.e(TAG, "setting BitmapDrawable with null Bitmap (invalid image file?)");
                }
            }
        }

        super.setImageDrawable(drawable);
    }