1 /* <lambda>null2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.statusbar.pipeline.wifi.domain.interactor 18 19 import android.net.wifi.WifiManager 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.statusbar.pipeline.shared.data.model.ConnectivitySlot 22 import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel 23 import com.android.systemui.statusbar.pipeline.shared.data.repository.ConnectivityRepository 24 import com.android.systemui.statusbar.pipeline.wifi.data.repository.WifiRepository 25 import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel 26 import javax.inject.Inject 27 import kotlinx.coroutines.flow.Flow 28 import kotlinx.coroutines.flow.StateFlow 29 import kotlinx.coroutines.flow.map 30 31 /** 32 * The business logic layer for the wifi icon. 33 * 34 * This interactor processes information from our data layer into information that the UI layer can 35 * use. 36 */ 37 interface WifiInteractor { 38 /** 39 * The SSID (service set identifier) of the wifi network. Null if we don't have a network, or 40 * have a network but no valid SSID. 41 */ 42 val ssid: Flow<String?> 43 44 /** Our current enabled status. */ 45 val isEnabled: Flow<Boolean> 46 47 /** Our current default status. */ 48 val isDefault: Flow<Boolean> 49 50 /** Our current wifi network. See [WifiNetworkModel]. */ 51 val wifiNetwork: Flow<WifiNetworkModel> 52 53 /** Our current wifi activity. See [DataActivityModel]. */ 54 val activity: StateFlow<DataActivityModel> 55 56 /** True if we're configured to force-hide the wifi icon and false otherwise. */ 57 val isForceHidden: Flow<Boolean> 58 } 59 60 @SysUISingleton 61 class WifiInteractorImpl 62 @Inject 63 constructor( 64 connectivityRepository: ConnectivityRepository, 65 wifiRepository: WifiRepository, 66 ) : WifiInteractor { 67 68 override val ssid: Flow<String?> = infonull69 wifiRepository.wifiNetwork.map { info -> 70 when (info) { 71 is WifiNetworkModel.Unavailable -> null 72 is WifiNetworkModel.Invalid -> null 73 is WifiNetworkModel.Inactive -> null 74 is WifiNetworkModel.CarrierMerged -> null 75 is WifiNetworkModel.Active -> 76 when { 77 info.isPasspointAccessPoint || info.isOnlineSignUpForPasspointAccessPoint -> 78 info.passpointProviderFriendlyName 79 info.ssid != WifiManager.UNKNOWN_SSID -> info.ssid 80 else -> null 81 } 82 } 83 } 84 85 override val isEnabled: Flow<Boolean> = wifiRepository.isWifiEnabled 86 87 override val isDefault: Flow<Boolean> = wifiRepository.isWifiDefault 88 89 override val wifiNetwork: Flow<WifiNetworkModel> = wifiRepository.wifiNetwork 90 91 override val activity: StateFlow<DataActivityModel> = wifiRepository.wifiActivity 92 93 override val isForceHidden: Flow<Boolean> = <lambda>null94 connectivityRepository.forceHiddenSlots.map { it.contains(ConnectivitySlot.WIFI) } 95 } 96