[Chipbar] Define #shouldIgnoreViewRemoval as a specific API on the
TemporaryViewDisplayController, instead of having subclasses just override #removeView. Bug: 245610654 Test: manual: Send a TRANSFER_TRIGGERED event then FAR_FROM_RECEIVER event and verify the chip is still displayed (i.e. the removal request is ignored) Test: MediaTttChipControllerSenderTest Test: TemporaryViewDisplayControllerTest Change-Id: I2cb907c5fb563c80c8a5720ae7f70a70e115bd2e
This commit is contained in:
@@ -195,7 +195,7 @@ class MediaTttChipControllerSender @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
override fun removeView(removalReason: String) {
|
||||
override fun shouldIgnoreViewRemoval(removalReason: String): Boolean {
|
||||
// Don't remove the chip if we're in progress or succeeded, since the user should still be
|
||||
// able to see the status of the transfer. (But do remove it if it's finally timed out.)
|
||||
val transferStatus = info?.state?.transferStatus
|
||||
@@ -207,9 +207,9 @@ class MediaTttChipControllerSender @Inject constructor(
|
||||
logger.logRemovalBypass(
|
||||
removalReason, bypassReason = "transferStatus=${transferStatus.name}"
|
||||
)
|
||||
return
|
||||
return true
|
||||
}
|
||||
super.removeView(removalReason)
|
||||
return false
|
||||
}
|
||||
|
||||
private fun Boolean.visibleIfTrue(): Int {
|
||||
|
||||
@@ -167,7 +167,11 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
|
||||
* @param removalReason a short string describing why the view was removed (timeout, state
|
||||
* change, etc.)
|
||||
*/
|
||||
open fun removeView(removalReason: String) {
|
||||
fun removeView(removalReason: String) {
|
||||
if (shouldIgnoreViewRemoval(removalReason)) {
|
||||
return
|
||||
}
|
||||
|
||||
if (view == null) { return }
|
||||
logger.logChipRemoval(removalReason)
|
||||
configurationController.removeCallback(displayScaleListener)
|
||||
@@ -178,6 +182,13 @@ abstract class TemporaryViewDisplayController<T : TemporaryViewInfo, U : Tempora
|
||||
cancelViewTimeout?.run()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a view removal request should be ignored and false otherwise.
|
||||
*
|
||||
* Allows subclasses to keep the view visible for longer in certain circumstances.
|
||||
*/
|
||||
open fun shouldIgnoreViewRemoval(removalReason: String): Boolean = false
|
||||
|
||||
/**
|
||||
* A method implemented by subclasses to update [currentView] based on [newInfo].
|
||||
*/
|
||||
|
||||
@@ -61,6 +61,8 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() {
|
||||
@Mock
|
||||
private lateinit var powerManager: PowerManager
|
||||
|
||||
private var shouldIgnoreViewRemoval: Boolean = false
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
@@ -205,6 +207,26 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() {
|
||||
verify(windowManager, never()).removeView(any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removeView_shouldIgnoreRemovalFalse_viewRemoved() {
|
||||
shouldIgnoreViewRemoval = false
|
||||
underTest.displayView(getState())
|
||||
|
||||
underTest.removeView("reason")
|
||||
|
||||
verify(windowManager).removeView(any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removeView_shouldIgnoreRemovalTrue_viewNotRemoved() {
|
||||
shouldIgnoreViewRemoval = true
|
||||
underTest.displayView(getState())
|
||||
|
||||
underTest.removeView("reason")
|
||||
|
||||
verify(windowManager, never()).removeView(any())
|
||||
}
|
||||
|
||||
private fun getState(name: String = "name") = ViewInfo(name)
|
||||
|
||||
private fun getConfigurationListener(): ConfigurationListener {
|
||||
@@ -240,6 +262,10 @@ class TemporaryViewDisplayControllerTest : SysuiTestCase() {
|
||||
super.updateView(newInfo, currentView)
|
||||
mostRecentViewInfo = newInfo
|
||||
}
|
||||
|
||||
override fun shouldIgnoreViewRemoval(removalReason: String): Boolean {
|
||||
return shouldIgnoreViewRemoval
|
||||
}
|
||||
}
|
||||
|
||||
inner class ViewInfo(val name: String) : TemporaryViewInfo {
|
||||
|
||||
Reference in New Issue
Block a user