[Media TTT] Catch if the sender chip receives an invalid constant.
Bug: 227332691 Test: atest MediaTttChipControllerSenderTest Change-Id: Ib957f96d6b8be95e2142d65f6936eff357a452f6
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user