[Media TTT] Catch if the sender chip receives an invalid constant.

Bug: 227332691
Test: atest MediaTttChipControllerSenderTest
Change-Id: Ib957f96d6b8be95e2142d65f6936eff357a452f6
This commit is contained in:
Caitlin Cassidy
2022-04-05 16:01:22 +00:00
parent 30deaa8bf8
commit 642c74e5ee
2 changed files with 20 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ package com.android.systemui.media.taptotransfer.sender
import android.app.StatusBarManager
import android.content.Context
import android.media.MediaRoute2Info
import android.util.Log
import android.view.View
import androidx.annotation.StringRes
import com.android.internal.logging.UiEventLogger
@@ -221,7 +222,12 @@ enum class ChipStateSender(
*/
fun getSenderStateFromId(
@StatusBarManager.MediaTransferSenderState displayState: Int,
): ChipStateSender = values().first { it.stateInt == displayState }
): ChipStateSender? = try {
values().first { it.stateInt == displayState }
} catch (e: NoSuchElementException) {
Log.e(TAG, "Could not find requested state $displayState", e)
null
}
/**
* Returns the state int from [StatusBarManager] associated with the given sender state
@@ -238,3 +244,5 @@ enum class ChipStateSender(
// 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 = 15000L
private const val TAG = "ChipStateSender"

View File

@@ -276,6 +276,17 @@ class MediaTttChipControllerSenderTest : SysuiTestCase() {
verify(windowManager).removeView(viewCaptor.value)
}
@Test
fun commandQueueCallback_invalidStateParam_noChipShown() {
commandQueueCallback.updateMediaTapToTransferSenderDisplay(
100,
routeInfo,
null
)
verify(windowManager, never()).addView(any(), any())
}
@Test
fun receivesNewStateFromCommandQueue_isLogged() {
commandQueueCallback.updateMediaTapToTransferSenderDisplay(