Disable SIM On/Off operation when device is in Satellite Enabled Mode

Cherry-picking ag/26965536 into the 24D1-dev branch caused conflicts. Therefore, manually create this CL to migrate the MobileNetworkSwitchController to Kotlin and utilize Compose.

Bug: 315928920
Test: atest, manual
Change-Id: I215b5a4615a3b3da6fc160f76c85c814210cc3ef
Merged-In: I7aaaf43b4c449129197e7cc92565d274ffdd2d8c
This commit is contained in:
Samuel Huang
2024-04-16 08:42:08 +00:00
parent 67df73a1fd
commit 316e7bf3e6
13 changed files with 603 additions and 543 deletions

View File

@@ -20,10 +20,12 @@ import android.content.Context
import android.os.OutcomeReceiver
import android.telephony.satellite.SatelliteManager
import android.telephony.satellite.SatelliteManager.SatelliteException
import android.telephony.satellite.SatelliteModemStateCallback
import androidx.test.core.app.ApplicationProvider
import com.android.settings.network.SatelliteManagerUtil.requestIsEnabled
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
import org.junit.Assert.assertTrue
@@ -42,7 +44,7 @@ import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class SatelliteManagerUtilTest {
class SatelliteRepositoryTest {
@JvmField
@Rule
@@ -57,10 +59,15 @@ class SatelliteManagerUtilTest {
@Mock
private lateinit var mockExecutor: Executor
private lateinit var repository: SatelliteRepository
@Before
fun setUp() {
`when`(this.spyContext.getSystemService(SatelliteManager::class.java))
.thenReturn(mockSatelliteManager)
repository = SatelliteRepository(spyContext)
}
@Test
@@ -78,7 +85,7 @@ class SatelliteManagerUtilTest {
}
val result: ListenableFuture<Boolean> =
requestIsEnabled(spyContext, mockExecutor)
repository.requestIsEnabled(mockExecutor)
assertTrue(result.get())
}
@@ -98,7 +105,7 @@ class SatelliteManagerUtilTest {
}
val result: ListenableFuture<Boolean> =
requestIsEnabled(spyContext, mockExecutor)
repository.requestIsEnabled(mockExecutor)
assertFalse(result.get())
}
@@ -117,7 +124,7 @@ class SatelliteManagerUtilTest {
null
}
val result = requestIsEnabled(spyContext, mockExecutor)
val result = repository.requestIsEnabled(mockExecutor)
assertFalse(result.get())
}
@@ -126,8 +133,52 @@ class SatelliteManagerUtilTest {
fun requestIsEnabled_nullSatelliteManager() = runBlocking {
`when`(spyContext.getSystemService(SatelliteManager::class.java)).thenReturn(null)
val result: ListenableFuture<Boolean> = requestIsEnabled(spyContext, mockExecutor)
val result: ListenableFuture<Boolean> = repository.requestIsEnabled(mockExecutor)
assertFalse(result.get())
}
}
@Test
fun getIsModemEnabledFlow_isSatelliteEnabledState() = 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 flow = repository.getIsModemEnabledFlow()
assertThat(flow.first()).isTrue()
}
@Test
fun getIsModemEnabledFlow_isSatelliteDisabledState() = 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 flow = repository.getIsModemEnabledFlow()
assertThat(flow.first()).isFalse()
}
@Test
fun getIsModemEnabledFlow_nullSatelliteManager() = runBlocking {
`when`(spyContext.getSystemService(SatelliteManager::class.java)).thenReturn(null)
val flow = repository.getIsModemEnabledFlow()
assertThat(flow.first()).isFalse()
}
}