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

Commit 9fc295d6 authored by Evan Laird's avatar Evan Laird
Browse files

[Sat] Replace device provisioned check with satellite provisioned

While the DeviceBasedSatelliteInteractor was using the device
provisioned state (i.e., has setupwizard been completed) as the signal
on whether or not to show the icon (when all other conditions are met),
the better signal here is to use SatelliteManager's satellite
provisioning state.

This CL implements the callback for `SatelliteProvisionStateCallback` in
the same manner as the other callbacks, and replaces the usages of the
device provisioning state with the satellite provisioning state

Test: DeviceBasedSatelliteRepositoryImplTest
Test: DeviceBasedSatelliteViewModelTest
Test: DeviceBasedSatelliteInteractorTest
Bug: 341371444
Flag: NONE bugfix
Change-Id: Ib0f5bbf2aa37ffcc25cf8462f9834e5f05cf908f
parent 99bc70c0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ import kotlinx.coroutines.flow.StateFlow
 * given mobile data subscription.
 */
interface DeviceBasedSatelliteRepository {
    /** The current status of satellite provisioning. If not false, we don't want to show an icon */
    val isSatelliteProvisioned: StateFlow<Boolean>

    /** See [SatelliteConnectionState] for available states */
    val connectionState: StateFlow<SatelliteConnectionState>

+5 −0
Original line number Diff line number Diff line
@@ -97,6 +97,11 @@ constructor(
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), realImpl)

    override val isSatelliteProvisioned: StateFlow<Boolean> =
        activeRepo
            .flatMapLatest { it.isSatelliteProvisioned }
            .stateIn(scope, SharingStarted.WhileSubscribed(), realImpl.isSatelliteProvisioned.value)

    override val connectionState: StateFlow<SatelliteConnectionState> =
        activeRepo
            .flatMapLatest { it.connectionState }
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ constructor(
) : DeviceBasedSatelliteRepository {
    private var demoCommandJob: Job? = null

    override val isSatelliteProvisioned = MutableStateFlow(true)
    override val connectionState = MutableStateFlow(SatelliteConnectionState.Unknown)
    override val signalStrength = MutableStateFlow(0)
    override val isSatelliteAllowedForCurrentLocation = MutableStateFlow(true)
+38 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.telephony.satellite.NtnSignalStrengthCallback
import android.telephony.satellite.SatelliteManager
import android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS
import android.telephony.satellite.SatelliteModemStateCallback
import android.telephony.satellite.SatelliteProvisionStateCallback
import android.telephony.satellite.SatelliteSupportedStateCallback
import androidx.annotation.VisibleForTesting
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
@@ -337,6 +338,43 @@ constructor(
            }
        }

    override val isSatelliteProvisioned: StateFlow<Boolean> =
        satelliteSupport
            .whenSupported(
                supported = ::satelliteProvisioned,
                orElse = flowOf(false),
                retrySignal = telephonyProcessCrashedEvent,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), false)

    private fun satelliteProvisioned(sm: SupportedSatelliteManager): Flow<Boolean> =
        conflatedCallbackFlow {
            val callback = SatelliteProvisionStateCallback { provisioned ->
                logBuffer.i {
                    "onSatelliteProvisionStateChanged: " +
                        if (provisioned) "provisioned" else "not provisioned"
                }
                trySend(provisioned)
            }

            var registered = false
            try {
                sm.registerForProvisionStateChanged(
                    bgDispatcher.asExecutor(),
                    callback,
                )
                registered = true
            } catch (e: Exception) {
                logBuffer.e("error registering for provisioning state callback", e)
            }

            awaitClose {
                if (registered) {
                    sm.unregisterForProvisionStateChanged(callback)
                }
            }
        }

    /**
     * Signal that we should start polling [checkIsSatelliteAllowed]. We only need to poll if there
     * are active listeners to [isSatelliteAllowedForCurrentLocation]
+1 −3
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import com.android.systemui.statusbar.pipeline.satellite.data.DeviceBasedSatelli
import com.android.systemui.statusbar.pipeline.satellite.shared.model.SatelliteConnectionState
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractor
import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel
import com.android.systemui.statusbar.policy.domain.interactor.DeviceProvisioningInteractor
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -45,7 +44,6 @@ class DeviceBasedSatelliteInteractor
constructor(
    val repo: DeviceBasedSatelliteRepository,
    iconsInteractor: MobileIconsInteractor,
    deviceProvisioningInteractor: DeviceProvisioningInteractor,
    wifiInteractor: WifiInteractor,
    @Application scope: CoroutineScope,
    @DeviceBasedSatelliteInputLog private val logBuffer: LogBuffer,
@@ -78,7 +76,7 @@ constructor(
            }
            .stateIn(scope, SharingStarted.WhileSubscribed(), 0)

    val isDeviceProvisioned: Flow<Boolean> = deviceProvisioningInteractor.isDeviceProvisioned
    val isSatelliteProvisioned = repo.isSatelliteProvisioned

    val isWifiActive: Flow<Boolean> =
        wifiInteractor.wifiNetwork.map { it is WifiNetworkModel.Active }
Loading