Loading packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt +7 −17 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.statusbar import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Point import android.graphics.Rect import android.renderscript.Allocation import android.renderscript.Element Loading @@ -26,11 +27,9 @@ import android.renderscript.RenderScript import android.renderscript.ScriptIntrinsicBlur import android.util.Log import android.util.MathUtils import android.util.Size import android.view.WindowManager import com.android.internal.annotations.VisibleForTesting import com.android.internal.graphics.ColorUtils import com.android.systemui.statusbar.notification.MediaNotificationProcessor import javax.inject.Inject import javax.inject.Singleton Loading @@ -42,9 +41,10 @@ private const val DOWNSAMPLE = 6 @Singleton class MediaArtworkProcessor @Inject constructor() { private val mTmpSize = Point() private var mArtworkCache: Bitmap? = null fun processArtwork(context: Context, artwork: Bitmap, windowType: Int): Bitmap? { fun processArtwork(context: Context, artwork: Bitmap): Bitmap? { if (mArtworkCache != null) { return mArtworkCache } Loading @@ -54,9 +54,10 @@ class MediaArtworkProcessor @Inject constructor() { var output: Allocation? = null var inBitmap: Bitmap? = null try { val size = getWindowSize(context, windowType) @Suppress("DEPRECATION") context.display?.getSize(mTmpSize) val rect = Rect(0, 0, artwork.width, artwork.height) MathUtils.fitRect(rect, Math.max(size.width / DOWNSAMPLE, size.height / DOWNSAMPLE)) MathUtils.fitRect(rect, Math.max(mTmpSize.x / DOWNSAMPLE, mTmpSize.y / DOWNSAMPLE)) inBitmap = Bitmap.createScaledBitmap(artwork, rect.width(), rect.height(), true /* filter */) // Render script blurs only support ARGB_8888, we need a conversion if we got a Loading Loading @@ -98,15 +99,4 @@ class MediaArtworkProcessor @Inject constructor() { mArtworkCache?.recycle() mArtworkCache = null } @VisibleForTesting internal fun getWindowSize(context: Context, windowType: Int): Size { val windowContext = context.display?.let { context.createDisplayContext(it) .createWindowContext(windowType, null) } ?: run { throw NullPointerException("Display is null") } val windowManager = windowContext.getSystemService(WindowManager::class.java) ?: run { throw NullPointerException("Null window manager") } return windowManager.currentWindowMetrics.size } } No newline at end of file packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ import android.provider.DeviceConfig.Properties; import android.util.ArraySet; import android.util.Log; import android.view.View; import android.view.WindowManager; import android.widget.ImageView; import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; Loading Loading @@ -674,8 +673,7 @@ public class NotificationMediaManager implements Dumpable { }; private Bitmap processArtwork(Bitmap artwork) { return mMediaArtworkProcessor.processArtwork(mContext, artwork, WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE); return mMediaArtworkProcessor.processArtwork(mContext, artwork); } @MainThread Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt +12 −12 Original line number Diff line number Diff line Loading @@ -16,14 +16,15 @@ package com.android.systemui.statusbar import com.google.common.truth.Truth.assertThat import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Point import android.testing.AndroidTestingRunner import android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before import org.junit.Test Loading @@ -31,7 +32,6 @@ import org.junit.runner.RunWith private const val WIDTH = 200 private const val HEIGHT = 200 private const val WINDOW_TYPE = TYPE_NOTIFICATION_SHADE @RunWith(AndroidTestingRunner::class) @SmallTest Loading @@ -46,10 +46,10 @@ class MediaArtworkProcessorTest : SysuiTestCase() { fun setUp() { processor = MediaArtworkProcessor() val size = processor.getWindowSize(context, WINDOW_TYPE) screenWidth = size.width screenHeight = size.height val point = Point() context.display.getSize(point) screenWidth = point.x screenHeight = point.y } @After Loading @@ -63,7 +63,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() { val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888) Canvas(artwork).drawColor(Color.BLUE) // WHEN the background is created from the artwork val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background = processor.processArtwork(context, artwork)!! // THEN the background has the size of the screen that has been downsamples assertThat(background.height).isLessThan(screenHeight) assertThat(background.width).isLessThan(screenWidth) Loading @@ -76,8 +76,8 @@ class MediaArtworkProcessorTest : SysuiTestCase() { val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888) Canvas(artwork).drawColor(Color.BLUE) // WHEN the background is processed twice val background1 = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background2 = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background1 = processor.processArtwork(context, artwork)!! val background2 = processor.processArtwork(context, artwork)!! // THEN the two bitmaps are the same // Note: This is currently broken and trying to use caching causes issues assertThat(background1).isNotSameAs(background2) Loading @@ -89,7 +89,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() { val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ALPHA_8) Canvas(artwork).drawColor(Color.BLUE) // WHEN the background is created from the artwork val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background = processor.processArtwork(context, artwork)!! // THEN the background has Config ARGB_8888 assertThat(background.config).isEqualTo(Bitmap.Config.ARGB_8888) } Loading @@ -102,7 +102,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() { // AND the artwork is recycled artwork.recycle() // WHEN the background is created from the artwork val background = processor.processArtwork(context, artwork, WINDOW_TYPE) val background = processor.processArtwork(context, artwork) // THEN the processed bitmap is null assertThat(background).isNull() } Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt +7 −17 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.statusbar import android.content.Context import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Point import android.graphics.Rect import android.renderscript.Allocation import android.renderscript.Element Loading @@ -26,11 +27,9 @@ import android.renderscript.RenderScript import android.renderscript.ScriptIntrinsicBlur import android.util.Log import android.util.MathUtils import android.util.Size import android.view.WindowManager import com.android.internal.annotations.VisibleForTesting import com.android.internal.graphics.ColorUtils import com.android.systemui.statusbar.notification.MediaNotificationProcessor import javax.inject.Inject import javax.inject.Singleton Loading @@ -42,9 +41,10 @@ private const val DOWNSAMPLE = 6 @Singleton class MediaArtworkProcessor @Inject constructor() { private val mTmpSize = Point() private var mArtworkCache: Bitmap? = null fun processArtwork(context: Context, artwork: Bitmap, windowType: Int): Bitmap? { fun processArtwork(context: Context, artwork: Bitmap): Bitmap? { if (mArtworkCache != null) { return mArtworkCache } Loading @@ -54,9 +54,10 @@ class MediaArtworkProcessor @Inject constructor() { var output: Allocation? = null var inBitmap: Bitmap? = null try { val size = getWindowSize(context, windowType) @Suppress("DEPRECATION") context.display?.getSize(mTmpSize) val rect = Rect(0, 0, artwork.width, artwork.height) MathUtils.fitRect(rect, Math.max(size.width / DOWNSAMPLE, size.height / DOWNSAMPLE)) MathUtils.fitRect(rect, Math.max(mTmpSize.x / DOWNSAMPLE, mTmpSize.y / DOWNSAMPLE)) inBitmap = Bitmap.createScaledBitmap(artwork, rect.width(), rect.height(), true /* filter */) // Render script blurs only support ARGB_8888, we need a conversion if we got a Loading Loading @@ -98,15 +99,4 @@ class MediaArtworkProcessor @Inject constructor() { mArtworkCache?.recycle() mArtworkCache = null } @VisibleForTesting internal fun getWindowSize(context: Context, windowType: Int): Size { val windowContext = context.display?.let { context.createDisplayContext(it) .createWindowContext(windowType, null) } ?: run { throw NullPointerException("Display is null") } val windowManager = windowContext.getSystemService(WindowManager::class.java) ?: run { throw NullPointerException("Null window manager") } return windowManager.currentWindowMetrics.size } } No newline at end of file
packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -42,7 +42,6 @@ import android.provider.DeviceConfig.Properties; import android.util.ArraySet; import android.util.Log; import android.view.View; import android.view.WindowManager; import android.widget.ImageView; import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; Loading Loading @@ -674,8 +673,7 @@ public class NotificationMediaManager implements Dumpable { }; private Bitmap processArtwork(Bitmap artwork) { return mMediaArtworkProcessor.processArtwork(mContext, artwork, WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE); return mMediaArtworkProcessor.processArtwork(mContext, artwork); } @MainThread Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt +12 −12 Original line number Diff line number Diff line Loading @@ -16,14 +16,15 @@ package com.android.systemui.statusbar import com.google.common.truth.Truth.assertThat import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Point import android.testing.AndroidTestingRunner import android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.google.common.truth.Truth.assertThat import org.junit.After import org.junit.Before import org.junit.Test Loading @@ -31,7 +32,6 @@ import org.junit.runner.RunWith private const val WIDTH = 200 private const val HEIGHT = 200 private const val WINDOW_TYPE = TYPE_NOTIFICATION_SHADE @RunWith(AndroidTestingRunner::class) @SmallTest Loading @@ -46,10 +46,10 @@ class MediaArtworkProcessorTest : SysuiTestCase() { fun setUp() { processor = MediaArtworkProcessor() val size = processor.getWindowSize(context, WINDOW_TYPE) screenWidth = size.width screenHeight = size.height val point = Point() context.display.getSize(point) screenWidth = point.x screenHeight = point.y } @After Loading @@ -63,7 +63,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() { val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888) Canvas(artwork).drawColor(Color.BLUE) // WHEN the background is created from the artwork val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background = processor.processArtwork(context, artwork)!! // THEN the background has the size of the screen that has been downsamples assertThat(background.height).isLessThan(screenHeight) assertThat(background.width).isLessThan(screenWidth) Loading @@ -76,8 +76,8 @@ class MediaArtworkProcessorTest : SysuiTestCase() { val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888) Canvas(artwork).drawColor(Color.BLUE) // WHEN the background is processed twice val background1 = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background2 = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background1 = processor.processArtwork(context, artwork)!! val background2 = processor.processArtwork(context, artwork)!! // THEN the two bitmaps are the same // Note: This is currently broken and trying to use caching causes issues assertThat(background1).isNotSameAs(background2) Loading @@ -89,7 +89,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() { val artwork = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ALPHA_8) Canvas(artwork).drawColor(Color.BLUE) // WHEN the background is created from the artwork val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!! val background = processor.processArtwork(context, artwork)!! // THEN the background has Config ARGB_8888 assertThat(background.config).isEqualTo(Bitmap.Config.ARGB_8888) } Loading @@ -102,7 +102,7 @@ class MediaArtworkProcessorTest : SysuiTestCase() { // AND the artwork is recycled artwork.recycle() // WHEN the background is created from the artwork val background = processor.processArtwork(context, artwork, WINDOW_TYPE) val background = processor.processArtwork(context, artwork) // THEN the processed bitmap is null assertThat(background).isNull() } Loading