Loading packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt +17 −5 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.log.table.TableLogBuffer import com.android.systemui.log.table.logDiffsForTable Loading @@ -48,6 +49,7 @@ import com.android.systemui.statusbar.pipeline.wifi.shared.WifiInputLogger import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel import java.util.concurrent.Executor import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.awaitClose Loading @@ -60,7 +62,9 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.withContext /** Real implementation of [WifiRepository]. */ @Suppress("EXPERIMENTAL_IS_NOT_ENABLED") Loading @@ -76,8 +80,9 @@ constructor( logger: WifiInputLogger, @WifiTableLog wifiTableLogBuffer: TableLogBuffer, @Main mainExecutor: Executor, @Background private val bgDispatcher: CoroutineDispatcher, @Application scope: CoroutineScope, wifiManager: WifiManager, private val wifiManager: WifiManager, ) : RealWifiRepository { private val wifiStateChangeEvents: Flow<Unit> = Loading @@ -93,20 +98,25 @@ constructor( // have changed. override val isWifiEnabled: StateFlow<Boolean> = merge(wifiNetworkChangeEvents, wifiStateChangeEvents) .mapLatest { wifiManager.isWifiEnabled } .onStart { emit(Unit) } .mapLatest { isWifiEnabled() } .distinctUntilChanged() .logDiffsForTable( wifiTableLogBuffer, columnPrefix = "", columnName = "isEnabled", initialValue = wifiManager.isWifiEnabled, initialValue = false, ) .stateIn( scope = scope, started = SharingStarted.WhileSubscribed(), initialValue = wifiManager.isWifiEnabled, started = SharingStarted.Eagerly, initialValue = false, ) // [WifiManager.isWifiEnabled] is a blocking IPC call, so fetch it in the background. private suspend fun isWifiEnabled(): Boolean = withContext(bgDispatcher) { wifiManager.isWifiEnabled } override val isWifiDefault: StateFlow<Boolean> = connectivityRepository.defaultConnections // TODO(b/274493701): Should wifi be considered default if it's carrier merged? Loading Loading @@ -289,6 +299,7 @@ constructor( private val logger: WifiInputLogger, @WifiTableLog private val wifiTableLogBuffer: TableLogBuffer, @Main private val mainExecutor: Executor, @Background private val bgDispatcher: CoroutineDispatcher, @Application private val scope: CoroutineScope, ) { fun create(wifiManager: WifiManager): WifiRepositoryImpl { Loading @@ -299,6 +310,7 @@ constructor( logger, wifiTableLogBuffer, mainExecutor, bgDispatcher, scope, wifiManager, ) Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt +1 −0 Original line number Diff line number Diff line Loading @@ -159,6 +159,7 @@ class MobileConnectionsRepositoryTest : SysuiTestCase() { mock(), mock(), FakeExecutor(FakeSystemClock()), dispatcher, testScope.backgroundScope, mock(), ) Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/WifiRepositorySwitcherTest.kt +1 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ class WifiRepositorySwitcherTest : SysuiTestCase() { logger, tableLogger, mainExecutor, testDispatcher, testScope.backgroundScope, wifiManager, ) Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt +3 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,8 @@ class WifiRepositoryImplTest : SysuiTestCase() { private lateinit var executor: Executor private lateinit var connectivityRepository: ConnectivityRepository private val testScope = TestScope(UnconfinedTestDispatcher()) private val dispatcher = UnconfinedTestDispatcher() private val testScope = TestScope(dispatcher) @Before fun setUp() { Loading Loading @@ -1301,6 +1302,7 @@ class WifiRepositoryImplTest : SysuiTestCase() { logger, tableLogger, executor, dispatcher, testScope.backgroundScope, wifiManager, ) Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImpl.kt +17 −5 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.log.table.TableLogBuffer import com.android.systemui.log.table.logDiffsForTable Loading @@ -48,6 +49,7 @@ import com.android.systemui.statusbar.pipeline.wifi.shared.WifiInputLogger import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel import java.util.concurrent.Executor import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.awaitClose Loading @@ -60,7 +62,9 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.withContext /** Real implementation of [WifiRepository]. */ @Suppress("EXPERIMENTAL_IS_NOT_ENABLED") Loading @@ -76,8 +80,9 @@ constructor( logger: WifiInputLogger, @WifiTableLog wifiTableLogBuffer: TableLogBuffer, @Main mainExecutor: Executor, @Background private val bgDispatcher: CoroutineDispatcher, @Application scope: CoroutineScope, wifiManager: WifiManager, private val wifiManager: WifiManager, ) : RealWifiRepository { private val wifiStateChangeEvents: Flow<Unit> = Loading @@ -93,20 +98,25 @@ constructor( // have changed. override val isWifiEnabled: StateFlow<Boolean> = merge(wifiNetworkChangeEvents, wifiStateChangeEvents) .mapLatest { wifiManager.isWifiEnabled } .onStart { emit(Unit) } .mapLatest { isWifiEnabled() } .distinctUntilChanged() .logDiffsForTable( wifiTableLogBuffer, columnPrefix = "", columnName = "isEnabled", initialValue = wifiManager.isWifiEnabled, initialValue = false, ) .stateIn( scope = scope, started = SharingStarted.WhileSubscribed(), initialValue = wifiManager.isWifiEnabled, started = SharingStarted.Eagerly, initialValue = false, ) // [WifiManager.isWifiEnabled] is a blocking IPC call, so fetch it in the background. private suspend fun isWifiEnabled(): Boolean = withContext(bgDispatcher) { wifiManager.isWifiEnabled } override val isWifiDefault: StateFlow<Boolean> = connectivityRepository.defaultConnections // TODO(b/274493701): Should wifi be considered default if it's carrier merged? Loading Loading @@ -289,6 +299,7 @@ constructor( private val logger: WifiInputLogger, @WifiTableLog private val wifiTableLogBuffer: TableLogBuffer, @Main private val mainExecutor: Executor, @Background private val bgDispatcher: CoroutineDispatcher, @Application private val scope: CoroutineScope, ) { fun create(wifiManager: WifiManager): WifiRepositoryImpl { Loading @@ -299,6 +310,7 @@ constructor( logger, wifiTableLogBuffer, mainExecutor, bgDispatcher, scope, wifiManager, ) Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/mobile/data/repository/prod/MobileConnectionsRepositoryTest.kt +1 −0 Original line number Diff line number Diff line Loading @@ -159,6 +159,7 @@ class MobileConnectionsRepositoryTest : SysuiTestCase() { mock(), mock(), FakeExecutor(FakeSystemClock()), dispatcher, testScope.backgroundScope, mock(), ) Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/WifiRepositorySwitcherTest.kt +1 −0 Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ class WifiRepositorySwitcherTest : SysuiTestCase() { logger, tableLogger, mainExecutor, testDispatcher, testScope.backgroundScope, wifiManager, ) Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/pipeline/wifi/data/repository/prod/WifiRepositoryImplTest.kt +3 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,8 @@ class WifiRepositoryImplTest : SysuiTestCase() { private lateinit var executor: Executor private lateinit var connectivityRepository: ConnectivityRepository private val testScope = TestScope(UnconfinedTestDispatcher()) private val dispatcher = UnconfinedTestDispatcher() private val testScope = TestScope(dispatcher) @Before fun setUp() { Loading Loading @@ -1301,6 +1302,7 @@ class WifiRepositoryImplTest : SysuiTestCase() { logger, tableLogger, executor, dispatcher, testScope.backgroundScope, wifiManager, ) Loading