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

Commit 7a6bbb6f authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Run the linter on WifiRepositoryImpl.

Bug: 238425913
Test: atest WifiRepositoryImplTest

Change-Id: I873e57bff94c775a06084098d47ff716211d811a
parent 4d313e1c
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -460,7 +460,6 @@
-packages/SystemUI/src/com/android/systemui/statusbar/pipeline/shared/ConnectivityPipelineLogger.kt
-packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/model/WifiActivityModel.kt
-packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/model/WifiNetworkModel.kt
-packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt
-packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/domain/interactor/WifiInteractor.kt
-packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/shared/WifiConstants.kt
-packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/ui/view/ModernStatusBarWifiView.kt
+108 −100
Original line number Diff line number Diff line
@@ -64,7 +64,9 @@ import kotlinx.coroutines.flow.stateIn
@OptIn(ExperimentalCoroutinesApi::class)
@SysUISingleton
@SuppressLint("MissingPermission")
class WifiRepositoryImpl @Inject constructor(
class WifiRepositoryImpl
@Inject
constructor(
    broadcastDispatcher: BroadcastDispatcher,
    connectivityManager: ConnectivityManager,
    logger: ConnectivityPipelineLogger,
@@ -74,9 +76,9 @@ class WifiRepositoryImpl @Inject constructor(
    wifiManager: WifiManager,
) : RealWifiRepository {

    private val wifiStateChangeEvents: Flow<Unit> = broadcastDispatcher.broadcastFlow(
        IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION)
    )
    private val wifiStateChangeEvents: Flow<Unit> =
        broadcastDispatcher
            .broadcastFlow(IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION))
            .logInputChange(logger, "WIFI_STATE_CHANGED_ACTION intent")

    private val wifiNetworkChangeEvents: MutableSharedFlow<Unit> =
@@ -101,24 +103,28 @@ class WifiRepositoryImpl @Inject constructor(
                initialValue = wifiManager.isWifiEnabled,
            )

    override val isWifiDefault: StateFlow<Boolean> = conflatedCallbackFlow {
        // Note: This callback doesn't do any logging because we already log every network change
        // in the [wifiNetwork] callback.
        val callback = object : ConnectivityManager.NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) {
    override val isWifiDefault: StateFlow<Boolean> =
        conflatedCallbackFlow {
                // Note: This callback doesn't do any logging because we already log every network
                // change in the [wifiNetwork] callback.
                val callback =
                    object : ConnectivityManager.NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) {
                        override fun onCapabilitiesChanged(
                            network: Network,
                            networkCapabilities: NetworkCapabilities
                        ) {
                // This method will always be called immediately after the network becomes the
                // default, in addition to any time the capabilities change while the network is
                // the default.
                // If this network contains valid wifi info, then wifi is the default network.
                            // This method will always be called immediately after the network
                            // becomes the default, in addition to any time the capabilities change
                            // while the network is the default.
                            // If this network contains valid wifi info, then wifi is the default
                            // network.
                            val wifiInfo = networkCapabilitiesToWifiInfo(networkCapabilities)
                            trySend(wifiInfo != null)
                        }

                        override fun onLost(network: Network) {
                // The system no longer has a default network, so wifi is definitely not default.
                            // The system no longer has a default network, so wifi is definitely not
                            // default.
                            trySend(false)
                        }
                    }
@@ -133,16 +139,14 @@ class WifiRepositoryImpl @Inject constructor(
                columnName = "isWifiDefault",
                initialValue = false,
            )
        .stateIn(
            scope,
            started = SharingStarted.WhileSubscribed(),
            initialValue = false
        )
            .stateIn(scope, started = SharingStarted.WhileSubscribed(), initialValue = false)

    override val wifiNetwork: StateFlow<WifiNetworkModel> = conflatedCallbackFlow {
    override val wifiNetwork: StateFlow<WifiNetworkModel> =
        conflatedCallbackFlow {
                var currentWifi: WifiNetworkModel = WIFI_NETWORK_DEFAULT

        val callback = object : ConnectivityManager.NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) {
                val callback =
                    object : ConnectivityManager.NetworkCallback(FLAG_INCLUDE_LOCATION_INFO) {
                        override fun onCapabilitiesChanged(
                            network: Network,
                            networkCapabilities: NetworkCapabilities
@@ -153,7 +157,8 @@ class WifiRepositoryImpl @Inject constructor(

                            val wifiInfo = networkCapabilitiesToWifiInfo(networkCapabilities)
                            if (wifiInfo?.isPrimary == true) {
                    val wifiNetworkModel = createWifiNetworkModel(
                                val wifiNetworkModel =
                                    createWifiNetworkModel(
                                        wifiInfo,
                                        network,
                                        networkCapabilities,
@@ -162,7 +167,7 @@ class WifiRepositoryImpl @Inject constructor(
                                logger.logTransformation(
                                    WIFI_NETWORK_CALLBACK_NAME,
                                    oldValue = currentWifi,
                        newValue = wifiNetworkModel
                                    newValue = wifiNetworkModel,
                                )
                                currentWifi = wifiNetworkModel
                                trySend(wifiNetworkModel)
@@ -175,12 +180,15 @@ class WifiRepositoryImpl @Inject constructor(
                            wifiNetworkChangeEvents.tryEmit(Unit)

                            val wifi = currentWifi
                if (wifi is WifiNetworkModel.Active && wifi.networkId == network.getNetId()) {
                            if (
                                wifi is WifiNetworkModel.Active &&
                                    wifi.networkId == network.getNetId()
                            ) {
                                val newNetworkModel = WifiNetworkModel.Inactive
                                logger.logTransformation(
                                    WIFI_NETWORK_CALLBACK_NAME,
                                    oldValue = wifi,
                        newValue = newNetworkModel
                                    newValue = newNetworkModel,
                                )
                                currentWifi = newNetworkModel
                                trySend(newNetworkModel)
@@ -199,13 +207,13 @@ class WifiRepositoryImpl @Inject constructor(
                initialValue = WIFI_NETWORK_DEFAULT,
            )
            // There will be multiple wifi icons in different places that will frequently
        // subscribe/unsubscribe to flows as the views attach/detach. Using [stateIn] ensures that
        // new subscribes will get the latest value immediately upon subscription. Otherwise, the
        // views could show stale data. See b/244173280.
            // subscribe/unsubscribe to flows as the views attach/detach. Using [stateIn] ensures
            // that new subscribes will get the latest value immediately upon subscription.
            // Otherwise, the views could show stale data. See b/244173280.
            .stateIn(
                scope,
                started = SharingStarted.WhileSubscribed(),
            initialValue = WIFI_NETWORK_DEFAULT
                initialValue = WIFI_NETWORK_DEFAULT,
            )

    override val wifiActivity: StateFlow<DataActivityModel> =