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

Commit 23e075cc authored by Jernej Virag's avatar Jernej Virag Committed by Android (Google) Code Review
Browse files

Merge "Fix crash is BitmapDrawable contains null Bitmap" into main

parents 2e7b1e08 cd5b949f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ object NotificationCustomContentMemoryVerifier {
                computeDrawableSize(drawable.foreground) +
                    computeDrawableSize(drawable.background) +
                    computeDrawableSize(drawable.monochrome)
            is BitmapDrawable -> drawable.bitmap.allocationByteCount
            is BitmapDrawable -> drawable?.bitmap?.allocationByteCount ?: 0 // CAN be null in prod.
            // People can sneak large drawables into those custom memory views via resources -
            // we use the intrisic size as a proxy for how much memory rendering those will
            // take.
+17 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import android.content.Context;
import android.content.pm.ProviderInfo;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.CancellationSignal;
@@ -39,6 +41,7 @@ import android.os.Process;
import android.platform.test.annotations.EnableFlags;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RemoteViews;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -167,6 +170,20 @@ public class NotificationCustomContentMemoryVerifierTest extends SysuiTestCase {
                .isTrue();
    }

    /**
     * You can create a view with `BitmapDrawable` that has a null Bitmap.
     */
    @Test
    @EnableCompatChanges({
            NotificationCustomContentCompat.CHECK_SIZE_OF_INFLATED_CUSTOM_VIEWS})
    public void computeViewHierarchyImageViewSize_nullableBitmapDrawable_doesntCrash() {
        ImageView iv = new ImageView(getContext());
        iv.setImageDrawable(new BitmapDrawable(getContext().getResources(), (Bitmap) null));
        assertThat(
                NotificationCustomContentMemoryVerifier.computeViewHierarchyImageViewSize(iv)
        ).isEqualTo(0);
    }

    @Test
    @EnableCompatChanges({
            NotificationCustomContentCompat.CHECK_SIZE_OF_INFLATED_CUSTOM_VIEWS})