Disable SIM On/Off operation when device is in a Satellite session am: c6005fb22a

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/27073216

Change-Id: I529d0a86739891873c205b3ff9eff065e50ed201
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Thomas Nguyen
2024-04-24 21:56:40 +00:00
committed by Automerger Merge Worker
3 changed files with 113 additions and 14 deletions

View File

@@ -24,7 +24,6 @@ import android.telephony.satellite.SatelliteModemStateCallback
import androidx.test.core.app.ApplicationProvider
import com.google.common.truth.Truth.assertThat
import com.google.common.util.concurrent.ListenableFuture
import java.util.concurrent.Executor
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertFalse
@@ -35,12 +34,12 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.any
import org.mockito.Mockito.`when`
import org.mockito.Mockito.*
import org.mockito.Spy
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
import org.robolectric.RobolectricTestRunner
import java.util.concurrent.Executor
@RunWith(RobolectricTestRunner::class)
@@ -90,6 +89,55 @@ class SatelliteRepositoryTest {
assertTrue(result.get())
}
@Test
fun requestIsSessionStarted_resultIsTrue() = runBlocking {
`when`(mockSatelliteManager.registerForModemStateChanged(any(), any())
).thenAnswer { invocation ->
val callback = invocation.getArgument<SatelliteModemStateCallback>(1)
callback.onSatelliteModemStateChanged(SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED)
SatelliteManager.SATELLITE_RESULT_SUCCESS
}
val result: ListenableFuture<Boolean> = repository.requestIsSessionStarted(mockExecutor)
assertTrue(result.get())
verify(mockSatelliteManager).unregisterForModemStateChanged(any())
}
@Test
fun requestIsSessionStarted_resultIsFalse() = runBlocking {
`when`(mockSatelliteManager.registerForModemStateChanged(any(), any())
).thenAnswer { invocation ->
val callback = invocation.getArgument<SatelliteModemStateCallback>(1)
callback.onSatelliteModemStateChanged(SatelliteManager.SATELLITE_MODEM_STATE_OFF)
SatelliteManager.SATELLITE_RESULT_SUCCESS
}
val result: ListenableFuture<Boolean> = repository.requestIsSessionStarted(mockExecutor)
assertFalse(result.get())
verify(mockSatelliteManager).unregisterForModemStateChanged(any())
}
@Test
fun requestIsSessionStarted_registerFailed() = runBlocking {
`when`(mockSatelliteManager.registerForModemStateChanged(any(), any())
).thenAnswer { invocation ->
SatelliteManager.SATELLITE_RESULT_ERROR
}
val result: ListenableFuture<Boolean> = repository.requestIsSessionStarted(mockExecutor)
assertFalse(result.get())
verify(mockSatelliteManager, never()).unregisterForModemStateChanged(any())
}
@Test
fun requestIsSessionStarted_nullSatelliteManager() = runBlocking {
`when`(spyContext.getSystemService(SatelliteManager::class.java)).thenReturn(null)
val result: ListenableFuture<Boolean> = repository.requestIsSessionStarted(mockExecutor)
assertFalse(result.get())
verifyNoInteractions(mockSatelliteManager)
}
@Test
fun requestIsEnabled_resultIsFalse() = runBlocking {
`when`(