1 /* 2 * 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.data.repository 18 19 import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel 20 import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiNetworkModel 21 import com.android.systemui.statusbar.pipeline.wifi.shared.model.WifiScanEntry 22 import kotlinx.coroutines.flow.StateFlow 23 24 /** Provides data related to the wifi state. */ 25 interface WifiRepository { 26 /** Observable for the current wifi enabled status. */ 27 val isWifiEnabled: StateFlow<Boolean> 28 29 /** Observable for the current wifi default status. */ 30 val isWifiDefault: StateFlow<Boolean> 31 32 /** Observable for the current primary wifi network. */ 33 val wifiNetwork: StateFlow<WifiNetworkModel> 34 35 /** 36 * Observable for secondary wifi networks (if any). Should specifically exclude the primary 37 * network emitted by [wifiNetwork]. 38 * 39 * This isn't used by phones/tablets, which only display the primary network, but may be used by 40 * other variants like Car. 41 */ 42 val secondaryNetworks: StateFlow<List<WifiNetworkModel>> 43 44 /** Observable for the current wifi network activity. */ 45 val wifiActivity: StateFlow<DataActivityModel> 46 47 /** 48 * The list of known wifi networks, per [WifiManager.scanResults]. This list is passively 49 * updated and does not trigger a scan. 50 */ 51 val wifiScanResults: StateFlow<List<WifiScanEntry>> 52 53 /** 54 * Returns true if the device is currently connected to a wifi network with a valid SSID and 55 * false otherwise. 56 */ isWifiConnectedWithValidSsidnull57 fun isWifiConnectedWithValidSsid(): Boolean { 58 val currentNetwork = wifiNetwork.value 59 return currentNetwork is WifiNetworkModel.Active && currentNetwork.hasValidSsid() 60 } 61 62 companion object { 63 /** Column name to use for [isWifiEnabled] for table logging. */ 64 const val COL_NAME_IS_ENABLED = "isEnabled" 65 /** Column name to use for [isWifiDefault] for table logging. */ 66 const val COL_NAME_IS_DEFAULT = "isDefault" 67 68 const val CARRIER_MERGED_INVALID_SUB_ID_REASON = 69 "Wifi network was carrier merged but had invalid sub ID" 70 } 71 } 72 73 /** 74 * A no-op interface used for Dagger bindings. 75 * 76 * [WifiRepositorySwitcher] needs to inject the "real" wifi repository, which could either be the 77 * full [WifiRepositoryImpl] or just [DisabledWifiRepository]. Having this interface lets us bind 78 * [RealWifiRepository], and then [WifiRepositorySwitcher] will automatically get the correct real 79 * repository. 80 */ 81 interface RealWifiRepository : WifiRepository 82