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

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

Icon: don't create Drawables with null Bitmaps

When an app passes an invalid icon into a BigPictureStyle notification,
we want to know clearly and promptly, but to log when these icon loads
fail, we need to return null instead of wrapping a null Bitmap in a
BitmapDrawable.

Bug: 335878768
Flag: ACONFIG com.android.graphics.flags.icon_load_drawable_return_null_when_uri_decode_fails START
Test: manual
Change-Id: I460ce2c8cc1353eba3e038092d4913b75675f4fb
parent 77ee346d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.graphics.drawable;
import static android.content.Context.CONTEXT_INCLUDE_CODE;
import static android.content.Context.CONTEXT_RESTRICTED;

import static com.android.graphics.flags.Flags.iconLoadDrawableReturnNullWhenUriDecodeFails;

import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.IntDef;
@@ -497,6 +499,9 @@ public final class Icon implements Parcelable {
                    final Bitmap bitmap = BitmapFactory.decodeStream(is);
                    if (bitmap == null) {
                        Log.w(TAG, "Unable to decode image from URI: " + getUriString());
                        if (iconLoadDrawableReturnNullWhenUriDecodeFails()) {
                            return null;
                        }
                    }
                    return new BitmapDrawable(context.getResources(), fixMaxBitmapSize(bitmap));
                }
@@ -507,6 +512,9 @@ public final class Icon implements Parcelable {
                    final Bitmap bitmap = BitmapFactory.decodeStream(is);
                    if (bitmap == null) {
                        Log.w(TAG, "Unable to decode image from URI: " + getUriString());
                        if (iconLoadDrawableReturnNullWhenUriDecodeFails()) {
                            return null;
                        }
                    }
                    return new AdaptiveIconDrawable(null, new BitmapDrawable(context.getResources(),
                            fixMaxBitmapSize(bitmap)));