[Media TTT] Use a default name if blank string is given

Adds a default device name if the given routeInfo name is blank. Name
routeInfo builder does not accept empty or null string. Checking if the
name is blank should be fair enough in order to provide a reasonable string.

Bug: 261491161
Test: atest MediaTttSenderCoordinatorTest
Change-Id: Ibf38af23990d6ccf8f81eb6bcebc2ef0cf3f5d48
This commit is contained in:
Michael Mikhail
2023-01-04 16:09:06 +00:00
parent c9e3c70735
commit 7f9b571df7
3 changed files with 45 additions and 1 deletions

View File

@@ -2364,6 +2364,8 @@
<string name="media_transfer_failed">Something went wrong. Try again.</string>
<!-- Text to indicate that a media transfer is currently in-progress, aka loading. [CHAR LIMIT=NONE] -->
<string name="media_transfer_loading">Loading</string>
<!-- Default name of the device. [CHAR LIMIT=30] -->
<string name="media_ttt_default_device_type">tablet</string>
<!-- Error message indicating that a control timed out while waiting for an update [CHAR_LIMIT=30] -->
<string name="controls_error_timeout">Inactive, check app</string>

View File

@@ -150,7 +150,12 @@ constructor(
logger: MediaTttLogger<ChipbarInfo>,
): ChipbarInfo {
val packageName = routeInfo.clientPackageName
val otherDeviceName = routeInfo.name.toString()
val otherDeviceName =
if (routeInfo.name.isBlank()) {
context.getString(R.string.media_ttt_default_device_type)
} else {
routeInfo.name.toString()
}
return ChipbarInfo(
// Display the app's icon as the start icon

View File

@@ -205,6 +205,21 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
verify(vibratorHelper).vibrate(any<VibrationEffect>())
}
@Test
fun commandQueueCallback_almostCloseToStartCast_deviceNameBlank_showsDefaultDeviceName() {
commandQueueCallback.updateMediaTapToTransferSenderDisplay(
StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_ALMOST_CLOSE_TO_START_CAST,
routeInfoWithBlankDeviceName,
null,
)
val chipbarView = getChipbarView()
assertThat(chipbarView.getChipText())
.contains(context.getString(R.string.media_ttt_default_device_type))
assertThat(chipbarView.getChipText())
.isNotEqualTo(ChipStateSender.ALMOST_CLOSE_TO_START_CAST.getExpectedStateText())
}
@Test
fun commandQueueCallback_almostCloseToEndCast_triggersCorrectChip() {
commandQueueCallback.updateMediaTapToTransferSenderDisplay(
@@ -247,6 +262,21 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
verify(vibratorHelper).vibrate(any<VibrationEffect>())
}
@Test
fun commandQueueCallback_transferToReceiverTriggered_deviceNameBlank_showsDefaultDeviceName() {
commandQueueCallback.updateMediaTapToTransferSenderDisplay(
StatusBarManager.MEDIA_TRANSFER_SENDER_STATE_TRANSFER_TO_RECEIVER_TRIGGERED,
routeInfoWithBlankDeviceName,
null,
)
val chipbarView = getChipbarView()
assertThat(chipbarView.getChipText())
.contains(context.getString(R.string.media_ttt_default_device_type))
assertThat(chipbarView.getChipText())
.isNotEqualTo(ChipStateSender.TRANSFER_TO_RECEIVER_TRIGGERED.getExpectedStateText())
}
@Test
fun commandQueueCallback_transferToThisDeviceTriggered_triggersCorrectChip() {
commandQueueCallback.updateMediaTapToTransferSenderDisplay(
@@ -934,6 +964,7 @@ class MediaTttSenderCoordinatorTest : SysuiTestCase() {
private const val APP_NAME = "Fake app name"
private const val OTHER_DEVICE_NAME = "My Tablet"
private const val BLANK_DEVICE_NAME = " "
private const val PACKAGE_NAME = "com.android.systemui"
private const val TIMEOUT = 10000
@@ -942,3 +973,9 @@ private val routeInfo =
.addFeature("feature")
.setClientPackageName(PACKAGE_NAME)
.build()
private val routeInfoWithBlankDeviceName =
MediaRoute2Info.Builder("id", BLANK_DEVICE_NAME)
.addFeature("feature")
.setClientPackageName(PACKAGE_NAME)
.build()