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

Commit e805c9bf authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "[SB Refactor] Implement the wifi network flow using the NetworkCallback." into tm-qpr-dev

parents 28930b91 db2c8323
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -600,6 +600,9 @@ public class Utils {
     * Returns the WifiInfo for the underlying WiFi network of the VCN network, returns null if the
     * input NetworkCapabilities is not for a VCN network with underlying WiFi network.
     *
     * TODO(b/238425913): Move this method to be inside systemui not settingslib once we've migrated
     *   off of {@link WifiStatusTracker} and {@link NetworkControllerImpl}.
     *
     * @param networkCapabilities NetworkCapabilities of the network.
     */
    @Nullable
+0 −49
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.pipeline

import com.android.systemui.statusbar.pipeline.wifi.data.repository.NetworkCapabilityInfo
import kotlinx.coroutines.flow.StateFlow

/**
 * Interface exposing a flow for raw connectivity information. Clients should collect on
 * [rawConnectivityInfoFlow] to get updates on connectivity information.
 *
 * Note: [rawConnectivityInfoFlow] should be a *hot* flow, so that we only create one instance of it
 * and all clients get references to the same flow.
 *
 * This will be used for the new status bar pipeline to compile information we need to display some
 * of the icons in the RHS of the status bar.
 */
interface ConnectivityInfoCollector {
    val rawConnectivityInfoFlow: StateFlow<RawConnectivityInfo>
}

/**
 * An object containing all of the raw connectivity information.
 *
 * Importantly, all the information in this object should not be processed at all (i.e., the data
 * that we receive from callbacks should be piped straight into this object and not be filtered,
 * manipulated, or processed in any way). Instead, any listeners on
 * [ConnectivityInfoCollector.rawConnectivityInfoFlow] can do the processing.
 *
 * This allows us to keep all the processing in one place which is beneficial for logging and
 * debugging purposes.
 */
data class RawConnectivityInfo(
        val networkCapabilityInfo: Map<Int, NetworkCapabilityInfo> = emptyMap(),
)
+0 −46
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.pipeline

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.pipeline.wifi.data.repository.NetworkCapabilitiesRepo
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted.Companion.Lazily
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

/**
 * The real implementation of [ConnectivityInfoCollector] that will collect information from all the
 * relevant connectivity callbacks and compile it into [rawConnectivityInfoFlow].
 */
@SysUISingleton
class ConnectivityInfoCollectorImpl @Inject constructor(
        networkCapabilitiesRepo: NetworkCapabilitiesRepo,
        @Application scope: CoroutineScope,
) : ConnectivityInfoCollector {
    override val rawConnectivityInfoFlow: StateFlow<RawConnectivityInfo> =
            // TODO(b/238425913): Collect all the separate flows for individual raw information into
            //   this final flow.
            networkCapabilitiesRepo.dataStream
                    .map {
                        RawConnectivityInfo(networkCapabilityInfo = it)
                    }
                    .stateIn(scope, started = Lazily, initialValue = RawConnectivityInfo())
}
+3 −41
Original line number Diff line number Diff line
@@ -20,31 +20,21 @@ import android.content.Context
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.pipeline.wifi.data.repository.NetworkCapabilityInfo
import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.WifiViewModel
import javax.inject.Inject
import javax.inject.Provider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted.Companion.Lazily
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

/**
 * A processor that transforms raw connectivity information that we get from callbacks and turns it
 * into a list of displayable connectivity information.
 * A temporary object that collects on [WifiViewModel] flows for debugging purposes.
 *
 * This will be used for the new status bar pipeline to calculate the list of icons that should be
 * displayed in the RHS of the status bar.
 *
 * Anyone can listen to [processedInfoFlow] to get updates to the processed data.
 * This will eventually get migrated to a view binder that will use the flow outputs to set state on
 * views. For now, this just collects on flows so that the information gets logged.
 */
@SysUISingleton
class ConnectivityInfoProcessor @Inject constructor(
        connectivityInfoCollector: ConnectivityInfoCollector,
        context: Context,
        // TODO(b/238425913): Don't use the application scope; instead, use the status bar view's
        // scope so we only do work when there's UI that cares about it.
@@ -52,21 +42,6 @@ class ConnectivityInfoProcessor @Inject constructor(
        private val statusBarPipelineFlags: StatusBarPipelineFlags,
        private val wifiViewModelProvider: Provider<WifiViewModel>,
) : CoreStartable(context) {
    // Note: This flow will not start running until a client calls `collect` on it, which means that
    // [connectivityInfoCollector]'s flow will also not start anything until that `collect` call
    // happens.
    // TODO(b/238425913): Delete this.
    val processedInfoFlow: Flow<ProcessedConnectivityInfo> =
            if (!statusBarPipelineFlags.isNewPipelineEnabled())
                emptyFlow()
            else connectivityInfoCollector.rawConnectivityInfoFlow
                    .map { it.process() }
                    .stateIn(
                            scope,
                            started = Lazily,
                            initialValue = ProcessedConnectivityInfo()
                    )

    override fun start() {
        if (!statusBarPipelineFlags.isNewPipelineEnabled()) {
            return
@@ -77,17 +52,4 @@ class ConnectivityInfoProcessor @Inject constructor(
            wifiViewModelProvider.get().isActivityInVisible.collect { }
        }
    }

    private fun RawConnectivityInfo.process(): ProcessedConnectivityInfo {
        // TODO(b/238425913): Actually process the raw info into meaningful data.
        return ProcessedConnectivityInfo(this.networkCapabilityInfo)
    }
}

/**
 * An object containing connectivity info that has been processed into data that can be directly
 * used by the status bar (and potentially other SysUI areas) to display icons.
 */
data class ProcessedConnectivityInfo(
        val networkCapabilityInfo: Map<Int, NetworkCapabilityInfo> = emptyMap(),
)
+0 −7
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.systemui.statusbar.pipeline.dagger

import com.android.systemui.CoreStartable
import com.android.systemui.statusbar.pipeline.ConnectivityInfoCollector
import com.android.systemui.statusbar.pipeline.ConnectivityInfoCollectorImpl
import com.android.systemui.statusbar.pipeline.ConnectivityInfoProcessor
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository
import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepositoryImpl
@@ -35,11 +33,6 @@ abstract class StatusBarPipelineModule {
    @ClassKey(ConnectivityInfoProcessor::class)
    abstract fun bindConnectivityInfoProcessor(cip: ConnectivityInfoProcessor): CoreStartable

    @Binds
    abstract fun provideConnectivityInfoCollector(
            impl: ConnectivityInfoCollectorImpl
    ): ConnectivityInfoCollector

    @Binds
    abstract fun wifiRepository(impl: WifiRepositoryImpl): WifiRepository
}
Loading