diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt index 0a6043793ef66..769494a588425 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/common/MediaTttUtils.kt @@ -27,10 +27,11 @@ import com.android.systemui.common.shared.model.Icon /** Utility methods for media tap-to-transfer. */ class MediaTttUtils { companion object { - // Used in CTS tests UpdateMediaTapToTransferSenderDisplayTest and - // UpdateMediaTapToTransferReceiverDisplayTest - const val WINDOW_TITLE = "Media Transfer Chip View" - const val WAKE_REASON = "MEDIA_TRANSFER_ACTIVATED" + const val WINDOW_TITLE_SENDER = "Media Transfer Chip View (Sender)" + const val WINDOW_TITLE_RECEIVER = "Media Transfer Chip View (Receiver)" + + const val WAKE_REASON_SENDER = "MEDIA_TRANSFER_ACTIVATED_SENDER" + const val WAKE_REASON_RECEIVER = "MEDIA_TRANSFER_ACTIVATED_RECEIVER" /** * Returns the information needed to display the icon in [Icon] form. diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt index dc794e66b918f..7dd9fb4b9cd51 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt @@ -40,7 +40,6 @@ import com.android.systemui.media.taptotransfer.common.MediaTttLogger import com.android.systemui.media.taptotransfer.common.MediaTttUtils import com.android.systemui.statusbar.CommandQueue import com.android.systemui.statusbar.policy.ConfigurationController -import com.android.systemui.temporarydisplay.DEFAULT_TIMEOUT_MILLIS import com.android.systemui.temporarydisplay.TemporaryViewDisplayController import com.android.systemui.temporarydisplay.TemporaryViewInfo import com.android.systemui.util.animation.AnimationUtil.Companion.frames @@ -78,8 +77,6 @@ class MediaTttChipControllerReceiver @Inject constructor( configurationController, powerManager, R.layout.media_ttt_chip_receiver, - MediaTttUtils.WINDOW_TITLE, - MediaTttUtils.WAKE_REASON, ) { @SuppressLint("WrongConstant") // We're allowed to use LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS override val windowLayoutParams = commonWindowLayoutParams.apply { @@ -231,7 +228,7 @@ class MediaTttChipControllerReceiver @Inject constructor( data class ChipReceiverInfo( val routeInfo: MediaRoute2Info, val appIconDrawableOverride: Drawable?, - val appNameOverride: CharSequence? -) : TemporaryViewInfo { - override fun getTimeoutMs() = DEFAULT_TIMEOUT_MILLIS -} + val appNameOverride: CharSequence?, + override val windowTitle: String = MediaTttUtils.WINDOW_TITLE_RECEIVER, + override val wakeReason: String = MediaTttUtils.WAKE_REASON_RECEIVER, +) : TemporaryViewInfo() diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt index 6e596ee1f473b..af7317c208abc 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/ChipStateSender.kt @@ -43,7 +43,7 @@ enum class ChipStateSender( @StringRes val stringResId: Int?, val transferStatus: TransferStatus, val endItem: SenderEndItem?, - val timeout: Long = DEFAULT_TIMEOUT_MILLIS + val timeout: Int = DEFAULT_TIMEOUT_MILLIS, ) { /** * A state representing that the two devices are close but not close enough to *start* a cast to @@ -223,6 +223,6 @@ sealed class SenderEndItem { // Give the Transfer*Triggered states a longer timeout since those states represent an active // process and we should keep the user informed about it as long as possible (but don't allow it to // continue indefinitely). -private const val TRANSFER_TRIGGERED_TIMEOUT_MILLIS = 30000L +private const val TRANSFER_TRIGGERED_TIMEOUT_MILLIS = 30000 private const val TAG = "ChipStateSender" diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt index 1fa8faeecd827..d1ea2d0c83bdb 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt @@ -159,6 +159,9 @@ constructor( } }, vibrationEffect = chipStateSender.transferStatus.vibrationEffect, + windowTitle = MediaTttUtils.WINDOW_TITLE_SENDER, + wakeReason = MediaTttUtils.WAKE_REASON_SENDER, + timeoutMs = chipStateSender.timeout, ) } diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt index d5d904c50f209..a7ac8d48df79c 100644 --- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt +++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt @@ -45,11 +45,6 @@ import com.android.systemui.util.concurrency.DelayableExecutor * * The generic type T is expected to contain all the information necessary for the subclasses to * display the view in a certain state, since they receive in [updateView]. - * - * @property windowTitle the title to use for the window that displays the temporary view. Should be - * normally cased, like "Window Title". - * @property wakeReason a string used for logging if we needed to wake the screen in order to - * display the temporary view. Should be screaming snake cased, like WAKE_REASON. */ abstract class TemporaryViewDisplayController( internal val context: Context, @@ -60,8 +55,6 @@ abstract class TemporaryViewDisplayController() + verify(windowManager).addView(any(), capture(windowParamsCaptor)) + assertThat(windowParamsCaptor.value!!.title).isEqualTo("Fake Window Title") } @Test @@ -110,7 +118,7 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() { } @Test - fun displayView_twice_viewNotAddedTwice() { + fun displayView_twiceWithSameWindowTitle_viewNotAddedTwice() { underTest.displayView(getState()) reset(windowManager) @@ -118,6 +126,32 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() { verify(windowManager, never()).addView(any(), any()) } + @Test + fun displayView_twiceWithDifferentWindowTitles_oldViewRemovedNewViewAdded() { + underTest.displayView( + ViewInfo( + name = "name", + windowTitle = "First Fake Window Title", + ) + ) + + underTest.displayView( + ViewInfo( + name = "name", + windowTitle = "Second Fake Window Title", + ) + ) + + val viewCaptor = argumentCaptor() + val windowParamsCaptor = argumentCaptor() + + verify(windowManager, times(2)).addView(capture(viewCaptor), capture(windowParamsCaptor)) + + assertThat(windowParamsCaptor.allValues[0].title).isEqualTo("First Fake Window Title") + assertThat(windowParamsCaptor.allValues[1].title).isEqualTo("Second Fake Window Title") + verify(windowManager).removeView(viewCaptor.allValues[0]) + } + @Test fun displayView_viewDoesNotDisappearsBeforeTimeout() { val state = getState() @@ -232,8 +266,6 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() { configurationController, powerManager, R.layout.chipbar, - "Window Title", - "WAKE_REASON", ) { var mostRecentViewInfo: ViewInfo? = null @@ -250,9 +282,12 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() { } } - inner class ViewInfo(val name: String) : TemporaryViewInfo { - override fun getTimeoutMs() = 1L - } + inner class ViewInfo( + val name: String, + override val windowTitle: String = "Window Title", + override val wakeReason: String = "WAKE_REASON", + override val timeoutMs: Int = 1 + ) : TemporaryViewInfo() } private const val TIMEOUT_MS = 10000L diff --git a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt index 9fbf159ec3483..ce64d3a64b238 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/temporarydisplay/chipbar/ChipbarCoordinatorTest.kt @@ -105,7 +105,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { val drawable = context.getDrawable(R.drawable.ic_celebration)!! underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Loaded(drawable, contentDescription = ContentDescription.Loaded("loadedCD")), Text.Loaded("text"), endItem = null, @@ -121,7 +121,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { fun displayView_resourceIcon_correctlyRendered() { val contentDescription = ContentDescription.Resource(R.string.controls_error_timeout) underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.drawable.ic_cake, contentDescription), Text.Loaded("text"), endItem = null, @@ -136,7 +136,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { @Test fun displayView_loadedText_correctlyRendered() { underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("display view text here"), endItem = null, @@ -149,7 +149,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { @Test fun displayView_resourceText_correctlyRendered() { underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Resource(R.string.screenrecord_start_error), endItem = null, @@ -163,7 +163,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { @Test fun displayView_endItemNull_correctlyRendered() { underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("text"), endItem = null, @@ -179,7 +179,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { @Test fun displayView_endItemLoading_correctlyRendered() { underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("text"), endItem = ChipbarEndItem.Loading, @@ -195,7 +195,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { @Test fun displayView_endItemError_correctlyRendered() { underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("text"), endItem = ChipbarEndItem.Error, @@ -211,7 +211,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { @Test fun displayView_endItemButton_correctlyRendered() { underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("text"), endItem = @@ -237,7 +237,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { val buttonClickListener = View.OnClickListener { isClicked = true } underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("text"), endItem = @@ -260,7 +260,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { val buttonClickListener = View.OnClickListener { isClicked = true } underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("text"), endItem = @@ -279,7 +279,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { @Test fun displayView_vibrationEffect_doubleClickEffect() { underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Resource(R.id.check_box, null), Text.Loaded("text"), endItem = null, @@ -296,7 +296,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { val drawable = context.getDrawable(R.drawable.ic_celebration)!! underTest.displayView( - ChipbarInfo( + createChipbarInfo( Icon.Loaded(drawable, contentDescription = ContentDescription.Loaded("loadedCD")), Text.Loaded("title text"), endItem = ChipbarEndItem.Loading, @@ -314,7 +314,7 @@ class ChipbarCoordinatorTest : SysuiTestCase() { // WHEN the view is updated val newDrawable = context.getDrawable(R.drawable.ic_cake)!! underTest.updateView( - ChipbarInfo( + createChipbarInfo( Icon.Loaded(newDrawable, ContentDescription.Loaded("new CD")), Text.Loaded("new title text"), endItem = ChipbarEndItem.Error, @@ -331,6 +331,23 @@ class ChipbarCoordinatorTest : SysuiTestCase() { assertThat(chipbarView.getEndButton().visibility).isEqualTo(View.GONE) } + private fun createChipbarInfo( + startIcon: Icon, + text: Text, + endItem: ChipbarEndItem?, + vibrationEffect: VibrationEffect? = null, + ): ChipbarInfo { + return ChipbarInfo( + startIcon, + text, + endItem, + vibrationEffect, + windowTitle = WINDOW_TITLE, + wakeReason = WAKE_REASON, + timeoutMs = TIMEOUT, + ) + } + private fun ViewGroup.getStartIconView() = this.requireViewById(R.id.start_icon) private fun ViewGroup.getChipText(): String = @@ -350,3 +367,5 @@ class ChipbarCoordinatorTest : SysuiTestCase() { } private const val TIMEOUT = 10000 +private const val WINDOW_TITLE = "Test Chipbar Window Title" +private const val WAKE_REASON = "TEST_CHIPBAR_WAKE_REASON"