1 /* 2 * Copyright (C) 2021 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.connectivity 18 19 import android.content.Intent 20 import android.os.UserManager 21 import android.provider.Settings 22 23 import com.android.wifitrackerlib.MergedCarrierEntry 24 import com.android.wifitrackerlib.WifiEntry 25 26 /** 27 * Tracks changes in access points. Allows listening for changes, scanning for new APs, 28 * and connecting to new ones. 29 */ 30 interface AccessPointController { addAccessPointCallbacknull31 fun addAccessPointCallback(callback: AccessPointCallback) 32 fun removeAccessPointCallback(callback: AccessPointCallback) 33 34 /** 35 * Request an updated list of available access points 36 * 37 * This method will trigger a call to [AccessPointCallback.onAccessPointsChanged] 38 */ 39 fun scanForAccessPoints() 40 41 /** 42 * Gets the current [MergedCarrierEntry]. If null, this call generates a call to 43 * [AccessPointCallback.onAccessPointsChanged] 44 * 45 * @return the current [MergedCarrierEntry], if one exists 46 */ 47 fun getMergedCarrierEntry(): MergedCarrierEntry? 48 49 /** @return the appropriate icon id for the given [WifiEntry]'s level */ 50 fun getIcon(ap: WifiEntry): Int 51 52 /** 53 * Connects to a [WifiEntry] if it's saved or does not require security. 54 * 55 * If the entry is not saved and requires security, will trigger 56 * [AccessPointCallback.onSettingsActivityTriggered]. 57 * 58 * @param ap 59 * @return `true` if [AccessPointCallback.onSettingsActivityTriggered] is triggered 60 */ 61 fun connect(ap: WifiEntry?): Boolean 62 63 /** 64 * `true` if the current user does not have the [UserManager.DISALLOW_CONFIG_WIFI] restriction 65 */ 66 fun canConfigWifi(): Boolean 67 68 /** 69 * `true` if the current user does not have the [UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS] 70 * restriction set 71 */ 72 fun canConfigMobileData(): Boolean 73 74 interface AccessPointCallback { 75 /** 76 * Called whenever [scanForAccessPoints] is called, or [getMergedCarrierEntry] is called 77 * with a null entry 78 * 79 * @param accessPoints the list of available access points, including the current connected 80 * one if it exists 81 */ 82 fun onAccessPointsChanged(accessPoints: List<@JvmSuppressWildcards WifiEntry>) 83 84 /** 85 * Called whenever [connecting][connect] to an unknown access point which has security. 86 * Implementers should launch the intent in the appropriate context 87 * 88 * @param settingsIntent an intent for [Settings.ACTION_WIFI_SETTINGS] with 89 * "wifi_start_connect_ssid" set as an extra 90 */ 91 fun onSettingsActivityTriggered(settingsIntent: Intent?) 92 93 /** 94 * Called whenever a Wi-Fi scan is triggered. 95 * 96 * @param isScan Whether Wi-Fi scan is triggered or not. 97 */ 98 fun onWifiScan(isScan: Boolean) 99 } 100 } 101