Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationCustomContentMemoryVerifier.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -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. Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationCustomContentMemoryVerifierTest.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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}) Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationCustomContentMemoryVerifier.kt +1 −1 Original line number Original line Diff line number Diff line Loading @@ -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. Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationCustomContentMemoryVerifierTest.java +17 −0 Original line number Original line Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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}) Loading