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

Commit 4d313e1c authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Provide a disabled wifi repo if there's no wifi manager.

This allows WifiRepositoryImpl to use a non-null WifiManager, which
removes a lot of null checks throughout the pipeline.

Bug: 238425913
Test: verify wifi icon still works
Test: verify wifi demo mode still works
Test: verify that, when WifiManager is null, the wifi icon never shows
Test: all tests in statusbar.pipeline.wifi
Change-Id: I8de76ad554769e91f1612ddfb3e9fa6dfa9bc6ed
parent b638b557
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.pipeline.dagger

import android.net.wifi.WifiManager
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.table.TableLogBuffer
@@ -35,8 +36,11 @@ import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxy
import com.android.systemui.statusbar.pipeline.mobile.util.MobileMappingsProxyImpl
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository
import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepositoryImpl
import com.android.systemui.statusbar.pipeline.wifi.data.repository.RealWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositorySwitcher
import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.DisabledWifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.prod.WifiRepositoryImpl
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractor
import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiInteractorImpl
import dagger.Binds
@@ -78,9 +82,23 @@ abstract class StatusBarPipelineModule {
    @ClassKey(MobileUiAdapter::class)
    abstract fun bindFeature(impl: MobileUiAdapter): CoreStartable

    @Module
    companion object {
        @JvmStatic
        @Provides
        @SysUISingleton
        fun provideRealWifiRepository(
            wifiManager: WifiManager?,
            disabledWifiRepository: DisabledWifiRepository,
            wifiRepositoryImplFactory: WifiRepositoryImpl.Factory,
        ): RealWifiRepository {
            // If we have a null [WifiManager], then the wifi repository should be permanently
            // disabled.
            return if (wifiManager == null) {
                disabledWifiRepository
            } else {
                wifiRepositoryImplFactory.create(wifiManager)
            }
        }

        @Provides
        @SysUISingleton
        @WifiTableLog
@@ -88,7 +106,6 @@ abstract class StatusBarPipelineModule {
            return factory.create("WifiTableLog", 100)
        }

        @JvmStatic
        @Provides
        @SysUISingleton
        @AirplaneTableLog
+31 −12
Original line number Diff line number Diff line
@@ -23,6 +23,33 @@ import com.android.systemui.log.table.Diffable
/** Provides information about the current wifi network. */
sealed class WifiNetworkModel : Diffable<WifiNetworkModel> {

    /**
     * A model representing that we couldn't fetch any wifi information.
     *
     * This is only used with [DisabledWifiRepository], where [WifiManager] is null.
     */
    object Unavailable : WifiNetworkModel() {
        override fun toString() = "WifiNetwork.Unavailable"
        override fun logDiffs(prevVal: WifiNetworkModel, row: TableRowLogger) {
            if (prevVal is Unavailable) {
                return
            }

            logFull(row)
        }

        override fun logFull(row: TableRowLogger) {
            row.logChange(COL_NETWORK_TYPE, TYPE_UNAVAILABLE)
            row.logChange(COL_NETWORK_ID, NETWORK_ID_DEFAULT)
            row.logChange(COL_VALIDATED, false)
            row.logChange(COL_LEVEL, LEVEL_DEFAULT)
            row.logChange(COL_SSID, null)
            row.logChange(COL_PASSPOINT_ACCESS_POINT, false)
            row.logChange(COL_ONLINE_SIGN_UP, false)
            row.logChange(COL_PASSPOINT_NAME, null)
        }
    }

    /** A model representing that we have no active wifi network. */
    object Inactive : WifiNetworkModel() {
        override fun toString() = "WifiNetwork.Inactive"
@@ -87,13 +114,8 @@ sealed class WifiNetworkModel : Diffable<WifiNetworkModel> {

        /**
         * The wifi signal level, guaranteed to be 0 <= level <= 4.
         *
         * Null if we couldn't fetch the level for some reason.
         *
         * TODO(b/238425913): The level will only be null if we have a null WifiManager. Is there a
         *   way we can guarantee a non-null WifiManager?
         */
        val level: Int? = null,
        val level: Int,

        /** See [android.net.wifi.WifiInfo.ssid]. */
        val ssid: String? = null,
@@ -108,7 +130,7 @@ sealed class WifiNetworkModel : Diffable<WifiNetworkModel> {
        val passpointProviderFriendlyName: String? = null,
    ) : WifiNetworkModel() {
        init {
            require(level == null || level in MIN_VALID_LEVEL..MAX_VALID_LEVEL) {
            require(level in MIN_VALID_LEVEL..MAX_VALID_LEVEL) {
                "0 <= wifi level <= 4 required; level was $level"
            }
        }
@@ -125,11 +147,7 @@ sealed class WifiNetworkModel : Diffable<WifiNetworkModel> {
                row.logChange(COL_VALIDATED, isValidated)
            }
            if (prevVal !is Active || prevVal.level != level) {
                if (level != null) {
                row.logChange(COL_LEVEL, level)
                } else {
                    row.logChange(COL_LEVEL, LEVEL_DEFAULT)
                }
            }
            if (prevVal !is Active || prevVal.ssid != ssid) {
                row.logChange(COL_SSID, ssid)
@@ -190,6 +208,7 @@ sealed class WifiNetworkModel : Diffable<WifiNetworkModel> {
}

const val TYPE_CARRIER_MERGED = "CarrierMerged"
const val TYPE_UNAVAILABLE = "Unavailable"
const val TYPE_INACTIVE = "Inactive"
const val TYPE_ACTIVE = "Active"

+10 −0
Original line number Diff line number Diff line
@@ -34,3 +34,13 @@ interface WifiRepository {
    /** Observable for the current wifi network activity. */
    val wifiActivity: StateFlow<DataActivityModel>
}

/**
 * A no-op interface used for Dagger bindings.
 *
 * [WifiRepositorySwitcher] needs to inject the "real" wifi repository, which could either be the
 * full [WifiRepositoryImpl] or just [DisabledWifiRepository]. Having this interface lets us bind
 * [RealWifiRepository], and then [WifiRepositorySwitcher] will automatically get the correct real
 * repository.
 */
interface RealWifiRepository : WifiRepository
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ import kotlinx.coroutines.flow.stateIn
class WifiRepositorySwitcher
@Inject
constructor(
    private val realImpl: WifiRepositoryImpl,
    private val realImpl: RealWifiRepository,
    private val demoImpl: DemoWifiRepository,
    private val demoModeController: DemoModeController,
    @Application scope: CoroutineScope,
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ constructor(
        WifiNetworkModel.Active(
            networkId = DEMO_NET_ID,
            isValidated = validated ?: true,
            level = level,
            level = level ?: 0,
            ssid = ssid,

            // These fields below aren't supported in demo mode, since they aren't needed to satisfy
Loading