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

Commit cd5b949f authored by Jernej Virag's avatar Jernej Virag
Browse files

Fix crash is BitmapDrawable contains null Bitmap

There seems to be a cornercase where such a BitmapDrawable can be fed to
a Notification.

Bug: 440069338
Test: newly written unit test
Flag: com.android.server.notification.notification_custom_view_uri_restriction
Change-Id: Ied5735bbba8bbe696ed0f036698032ff73578af5
parent a043ee83
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -151,7 +151,7 @@ object NotificationCustomContentMemoryVerifier {
                computeDrawableSize(drawable.foreground) +
                computeDrawableSize(drawable.foreground) +
                    computeDrawableSize(drawable.background) +
                    computeDrawableSize(drawable.background) +
                    computeDrawableSize(drawable.monochrome)
                    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 -
            // 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
            // we use the intrisic size as a proxy for how much memory rendering those will
            // take.
            // take.
+17 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,8 @@ import android.content.Context;
import android.content.pm.ProviderInfo;
import android.content.pm.ProviderInfo;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.CancellationSignal;
@@ -39,6 +41,7 @@ import android.os.Process;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.annotations.EnableFlags;
import android.view.View;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.RemoteViews;


import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -167,6 +170,20 @@ public class NotificationCustomContentMemoryVerifierTest extends SysuiTestCase {
                .isTrue();
                .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
    @Test
    @EnableCompatChanges({
    @EnableCompatChanges({
            NotificationCustomContentCompat.CHECK_SIZE_OF_INFLATED_CUSTOM_VIEWS})
            NotificationCustomContentCompat.CHECK_SIZE_OF_INFLATED_CUSTOM_VIEWS})