Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87823b47 authored by Evan Laird's avatar Evan Laird
Browse files

[Sat] Consider satellite not-supported if service throws

In the case where SatelliteManager throws an exception when calling
`requestIsSatelliteSupported`, consider the feature to be unavailable.

Test: DeviceBasedSatelliteRepositoryImplTest
Bug: 311417356
Flag: ACONFIG com.android.internal.telephony.flags.oem_enabled_satellite_flag DEVELOPMENT
Change-Id: I90b9e4ab89b702a4262d2abe746392dd1eda7890
parent 8d1c9d10
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.OutcomeReceiver
import android.telephony.satellite.NtnSignalStrengthCallback
import android.telephony.satellite.SatelliteManager
import android.telephony.satellite.SatelliteModemStateCallback
import androidx.annotation.VisibleForTesting
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -62,8 +63,10 @@ private typealias SupportedSatelliteManager = SatelliteManager
/**
 * "Supported" here means supported by the device. The value of this should be stable during the
 * process lifetime.
 *
 * @VisibleForTesting
 */
private sealed interface SatelliteSupport {
sealed interface SatelliteSupport {
    /** Not yet fetched */
    data object Unknown : SatelliteSupport

@@ -132,7 +135,8 @@ constructor(

    // Some calls into satellite manager will throw exceptions if it is not supported.
    // This is never expected to change after boot, but may need to be retried in some cases
    private val satelliteSupport: MutableStateFlow<SatelliteSupport> = MutableStateFlow(Unknown)
    @get:VisibleForTesting
    val satelliteSupport: MutableStateFlow<SatelliteSupport> = MutableStateFlow(Unknown)

    init {
        satelliteManager = satelliteManagerOpt.getOrNull()
@@ -244,7 +248,11 @@ constructor(
                    }
                }

            try {
                requestIsSatelliteSupported(bgDispatcher.asExecutor(), cb)
            } catch (e: Exception) {
                continuation.resume(NotSupported)
            }
        }

    companion object {
+22 −0
Original line number Diff line number Diff line
@@ -99,6 +99,28 @@ class DeviceBasedSatelliteRepositoryImplTest : SysuiTestCase() {
            assertThat(allowed).isFalse()
        }

    @Test
    fun satelliteManagerThrows_checkSupportDoesNotCrash() =
        testScope.runTest {
            whenever(satelliteManager.requestIsSatelliteSupported(any(), any()))
                .thenThrow(IllegalStateException())

            systemClock.setUptimeMillis(Process.getStartUptimeMillis() + MIN_UPTIME)

            underTest =
                DeviceBasedSatelliteRepositoryImpl(
                    Optional.of(satelliteManager),
                    dispatcher,
                    testScope.backgroundScope,
                    systemClock,
                )

            runCurrent()

            // Creating the repo does not crash, and we consider the feature not to be supported
            assertThat(underTest.satelliteSupport.value).isEqualTo(SatelliteSupport.NotSupported)
        }

    @Test
    fun connectionState_mapsFromSatelliteModemState() =
        testScope.runTest {