diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt index d7f3c73a0bec0..883f8a93d9100 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsFavoritePersistenceWrapper.kt @@ -135,7 +135,7 @@ class ControlsFavoritePersistenceWrapper( } private fun parseXml(parser: XmlPullParser): List { - var type = 0 + var type: Int val infos = mutableListOf() while (parser.next().also { type = it } != XmlPullParser.END_DOCUMENT) { if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt b/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt index 89caaceebb5cd..ac5e0893b526a 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/AppAdapter.kt @@ -58,13 +58,13 @@ class AppAdapter( private var listOfServices = emptyList() private val callback = object : ControlsListingController.ControlsListingCallback { - override fun onServicesUpdated(list: List) { + override fun onServicesUpdated(candidates: List) { backgroundExecutor.execute { - val collator = Collator.getInstance(resources.getConfiguration().locale) + val collator = Collator.getInstance(resources.configuration.locales[0]) val localeComparator = compareBy(collator) { it.loadLabel() } - listOfServices = list.sortedWith(localeComparator) + listOfServices = candidates.sortedWith(localeComparator) uiExecutor.execute(::notifyDataSetChanged) } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt index 9952b976a2542..af4a977022ae9 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt @@ -70,7 +70,7 @@ class ControlsFavoritingActivity @Inject constructor( target: RecyclerView.ViewHolder ): Boolean { return currentModel?.onMoveItem( - viewHolder.adapterPosition, target.adapterPosition) != null + viewHolder.layoutPosition, target.layoutPosition) != null } override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {} diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingController.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingController.kt index d893caabdb36b..8e47f6466955c 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingController.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsListingController.kt @@ -45,6 +45,6 @@ interface ControlsListingController : @FunctionalInterface interface ControlsListingCallback { - fun onServicesUpdated(list: List) + fun onServicesUpdated(candidates: List) } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt index 98cdf288f1a1f..f4fd37557fa47 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt @@ -130,8 +130,7 @@ class ControlsUiControllerImpl @Inject constructor ( private val listingCallback = object : ControlsListingController.ControlsListingCallback { override fun onServicesUpdated(candidates: List) { bgExecutor.execute { - val collator = Collator.getInstance(context.getResources() - .getConfiguration().locale) + val collator = Collator.getInstance(context.resources.configuration.locales[0]) val localeComparator = compareBy(collator) { it.loadLabel() } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt index 071198bfd263d..d3d4287b87070 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt @@ -42,7 +42,7 @@ class DetailDialog( val intent: PendingIntent ) : Dialog(parentContext) { - lateinit var activityView: ActivityView + var activityView: ActivityView val stateCallback: ActivityView.StateCallback = object : ActivityView.StateCallback() { override fun onActivityViewReady(view: ActivityView) { @@ -61,24 +61,28 @@ class DetailDialog( override fun onTaskRemovalStarted(taskId: Int) {} } - init { - val window = getWindow() - window.requestFeature(Window.FEATURE_NO_TITLE) + @Suppress("DEPRECATION") + private fun Window.setWindowParams() { + requestFeature(Window.FEATURE_NO_TITLE) // Inflate the decor view, so the attributes below are not overwritten by the theme. - window.getDecorView() - window.getAttributes().systemUiVisibility = - (window.getAttributes().systemUiVisibility - or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - or View.SYSTEM_UI_FLAG_LAYOUT_STABLE) + decorView + attributes.systemUiVisibility = + (attributes.systemUiVisibility + or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + or View.SYSTEM_UI_FLAG_LAYOUT_STABLE) - window.setLayout(MATCH_PARENT, MATCH_PARENT) - window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) - window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN - or WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR - or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) - window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY) - window.getAttributes().setFitInsetsTypes(0 /* types */) + setLayout(MATCH_PARENT, MATCH_PARENT) + clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN + or WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR + or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) + setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY) + getAttributes().setFitInsetsTypes(0 /* types */) + } + + init { + getWindow()?.setWindowParams() setContentView(R.layout.controls_detail_dialog) @@ -89,9 +93,9 @@ class DetailDialog( } override fun show() { - val attrs = getWindow().getAttributes() - attrs.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS - getWindow().setAttributes(attrs) + val attrs = getWindow()?.attributes + attrs?.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS + getWindow()?.attributes = attrs activityView.setCallback(stateCallback) diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt index 45d73979dd680..cca56c2199726 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt @@ -60,7 +60,7 @@ class ToggleRangeBehavior : Behavior { val gestureListener = ToggleRangeGestureListener(cvh.layout) val gestureDetector = GestureDetector(context, gestureListener) - cvh.layout.setOnTouchListener({ v: View, e: MotionEvent -> + cvh.layout.setOnTouchListener { _: View, e: MotionEvent -> if (gestureDetector.onTouchEvent(e)) { return@setOnTouchListener true } @@ -72,7 +72,7 @@ class ToggleRangeBehavior : Behavior { } return@setOnTouchListener false - }) + } } override fun bind(cws: ControlWithState) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt index aaf48490d7b03..711d6a6daeef3 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt @@ -19,7 +19,6 @@ 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 @@ -27,9 +26,11 @@ 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 @@ -41,10 +42,9 @@ 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): Bitmap? { + fun processArtwork(context: Context, artwork: Bitmap, windowType: Int): Bitmap? { if (mArtworkCache != null) { return mArtworkCache } @@ -54,9 +54,9 @@ class MediaArtworkProcessor @Inject constructor() { var output: Allocation? = null var inBitmap: Bitmap? = null try { - context.display.getSize(mTmpSize) + val size = getWindowSize(context, windowType) val rect = Rect(0, 0, artwork.width, artwork.height) - MathUtils.fitRect(rect, Math.max(mTmpSize.x / DOWNSAMPLE, mTmpSize.y / DOWNSAMPLE)) + MathUtils.fitRect(rect, Math.max(size.width / DOWNSAMPLE, size.height / 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 @@ -98,4 +98,15 @@ 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 diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java index d0af106d4a0cc..d9b4e914fef1b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java @@ -44,6 +44,7 @@ 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; @@ -668,7 +669,8 @@ public class NotificationMediaManager implements Dumpable { }; private Bitmap processArtwork(Bitmap artwork) { - return mMediaArtworkProcessor.processArtwork(mContext, artwork); + return mMediaArtworkProcessor.processArtwork(mContext, artwork, + WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE); } @MainThread diff --git a/packages/SystemUI/src/com/android/systemui/util/FloatingContentCoordinator.kt b/packages/SystemUI/src/com/android/systemui/util/FloatingContentCoordinator.kt index 0487ce6ea6b52..ca4b67db0d460 100644 --- a/packages/SystemUI/src/com/android/systemui/util/FloatingContentCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/util/FloatingContentCoordinator.kt @@ -132,7 +132,6 @@ class FloatingContentCoordinator @Inject constructor() { * * @param content The content that has moved. */ - @JvmOverloads fun onContentMoved(content: FloatingContent) { // Ignore calls when we are currently resolving conflicts, since those calls are from diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt index 72e6df27a2549..a27c085e93a9a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/MediaArtworkProcessorTest.kt @@ -16,15 +16,14 @@ 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 @@ -32,6 +31,7 @@ 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 @@ -46,10 +46,10 @@ class MediaArtworkProcessorTest : SysuiTestCase() { fun setUp() { processor = MediaArtworkProcessor() - val point = Point() - context.display.getSize(point) - screenWidth = point.x - screenHeight = point.y + val size = processor.getWindowSize(context, WINDOW_TYPE) + + screenWidth = size.width + screenHeight = size.height } @After @@ -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)!! + val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!! // THEN the background has the size of the screen that has been downsamples assertThat(background.height).isLessThan(screenHeight) assertThat(background.width).isLessThan(screenWidth) @@ -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)!! - val background2 = processor.processArtwork(context, artwork)!! + val background1 = processor.processArtwork(context, artwork, WINDOW_TYPE)!! + val background2 = processor.processArtwork(context, artwork, WINDOW_TYPE)!! // THEN the two bitmaps are the same // Note: This is currently broken and trying to use caching causes issues assertThat(background1).isNotSameAs(background2) @@ -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)!! + val background = processor.processArtwork(context, artwork, WINDOW_TYPE)!! // THEN the background has Config ARGB_8888 assertThat(background.config).isEqualTo(Bitmap.Config.ARGB_8888) } @@ -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) + val background = processor.processArtwork(context, artwork, WINDOW_TYPE) // THEN the processed bitmap is null assertThat(background).isNull() }