Fix the "Use this SIM" switch does not disable during phone calls

If the registration failed (e.g., device doesn't support satellite), SatelliteManager will not emit the current state by callback. We send `false` value by ourself to make sure the flow has initial value.

Bug: 315928920
Test: atest, manual
Change-Id: Ic87f71bc576cfb1f8e4053c5784fca401adaec08
This commit is contained in:
Samuel Huang
2024-04-26 04:08:10 +00:00
parent fea80bf236
commit 4f454b43c6
3 changed files with 38 additions and 40 deletions

View File

@@ -120,7 +120,7 @@ class SatelliteRepositoryTest {
@Test
fun requestIsSessionStarted_registerFailed() = runBlocking {
`when`(mockSatelliteManager.registerForModemStateChanged(any(), any())
).thenAnswer { invocation ->
).thenAnswer {
SatelliteManager.SATELLITE_RESULT_ERROR
}
@@ -187,7 +187,7 @@ class SatelliteRepositoryTest {
}
@Test
fun getIsModemEnabledFlow_isSatelliteEnabledState() = runBlocking {
fun getIsSessionStartedFlow_isSatelliteEnabledState() = runBlocking {
`when`(
mockSatelliteManager.registerForModemStateChanged(
any(),
@@ -199,13 +199,13 @@ class SatelliteRepositoryTest {
SatelliteManager.SATELLITE_RESULT_SUCCESS
}
val flow = repository.getIsModemEnabledFlow()
val flow = repository.getIsSessionStartedFlow()
assertThat(flow.first()).isTrue()
}
@Test
fun getIsModemEnabledFlow_isSatelliteDisabledState() = runBlocking {
fun getIsSessionStartedFlow_isSatelliteDisabledState() = runBlocking {
`when`(
mockSatelliteManager.registerForModemStateChanged(
any(),
@@ -217,16 +217,28 @@ class SatelliteRepositoryTest {
SatelliteManager.SATELLITE_RESULT_SUCCESS
}
val flow = repository.getIsModemEnabledFlow()
val flow = repository.getIsSessionStartedFlow()
assertThat(flow.first()).isFalse()
}
@Test
fun getIsModemEnabledFlow_nullSatelliteManager() = runBlocking {
fun getIsSessionStartedFlow_nullSatelliteManager() = runBlocking {
`when`(spyContext.getSystemService(SatelliteManager::class.java)).thenReturn(null)
val flow = repository.getIsModemEnabledFlow()
val flow = repository.getIsSessionStartedFlow()
assertThat(flow.first()).isFalse()
}
@Test
fun getIsSessionStartedFlow_registerFailed() = runBlocking {
`when`(mockSatelliteManager.registerForModemStateChanged(any(), any())
).thenAnswer {
SatelliteManager.SATELLITE_RESULT_ERROR
}
val flow = repository.getIsSessionStartedFlow()
assertThat(flow.first()).isFalse()
}
}