From 5e1280017a98b5424c0dd364c31714de331a3121 Mon Sep 17 00:00:00 2001 From: David Su Date: Mon, 21 Oct 2019 14:31:53 -0700 Subject: [PATCH] Make WifiScanner#getAvailableChannels() @SystemApi While here removed some redundant comments. Bug: 129008573 Test: atest FrameworksWifiApiTests Change-Id: Id6ca5cf4547ff7321805ad671b9e25dab9953cd3 --- api/system-current.txt | 1 + wifi/java/android/net/wifi/IWifiScanner.aidl | 2 +- wifi/java/android/net/wifi/WifiScanner.java | 53 ++++++++++++++------ 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/api/system-current.txt b/api/system-current.txt index 295fef142c89e..1f7337cac804c 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4836,6 +4836,7 @@ package android.net.wifi { public class WifiScanner { method @Deprecated public void configureWifiChange(int, int, int, int, int, android.net.wifi.WifiScanner.BssidInfo[]); method @Deprecated public void configureWifiChange(android.net.wifi.WifiScanner.WifiChangeSettings); + method @Nullable @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public java.util.List getAvailableChannels(int); method @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public boolean getScanResults(); method @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startBackgroundScan(android.net.wifi.WifiScanner.ScanSettings, android.net.wifi.WifiScanner.ScanListener); method @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) public void startBackgroundScan(android.net.wifi.WifiScanner.ScanSettings, android.net.wifi.WifiScanner.ScanListener, android.os.WorkSource); diff --git a/wifi/java/android/net/wifi/IWifiScanner.aidl b/wifi/java/android/net/wifi/IWifiScanner.aidl index 398493439bbed..114c7320bc3a8 100644 --- a/wifi/java/android/net/wifi/IWifiScanner.aidl +++ b/wifi/java/android/net/wifi/IWifiScanner.aidl @@ -26,5 +26,5 @@ interface IWifiScanner { Messenger getMessenger(); - Bundle getAvailableChannels(int band); + Bundle getAvailableChannels(int band, String packageName); } diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java index 68948cbbe7a95..21189a411d948 100644 --- a/wifi/java/android/net/wifi/WifiScanner.java +++ b/wifi/java/android/net/wifi/WifiScanner.java @@ -17,7 +17,9 @@ package android.net.wifi; import android.Manifest; +import android.annotation.IntDef; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SuppressLint; import android.annotation.SystemApi; @@ -39,6 +41,8 @@ import com.android.internal.util.AsyncChannel; import com.android.internal.util.Preconditions; import com.android.internal.util.Protocol; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -51,26 +55,38 @@ import java.util.List; @SystemService(Context.WIFI_SCANNING_SERVICE) public class WifiScanner { - /** no band specified; use channel list instead */ - public static final int WIFI_BAND_UNSPECIFIED = 0; /* not specified */ + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(prefix = {"WIFI_BAND_"}, value = { + WIFI_BAND_UNSPECIFIED, + WIFI_BAND_24_GHZ, + WIFI_BAND_5_GHZ, + WIFI_BAND_BOTH, + WIFI_BAND_5_GHZ_DFS_ONLY, + WIFI_BAND_24_GHZ_WITH_5GHZ_DFS, + WIFI_BAND_5_GHZ_WITH_DFS, + WIFI_BAND_BOTH_WITH_DFS}) + public @interface WifiBand {} + /** no band specified; use channel list instead */ + public static final int WIFI_BAND_UNSPECIFIED = 0; /** 2.4 GHz band */ - public static final int WIFI_BAND_24_GHZ = 1; /* 2.4 GHz band */ + public static final int WIFI_BAND_24_GHZ = 1; /** 5 GHz band excluding DFS channels */ - public static final int WIFI_BAND_5_GHZ = 2; /* 5 GHz band without DFS channels */ + public static final int WIFI_BAND_5_GHZ = 2; + /** Both 2.4 GHz band and 5 GHz band; no DFS channels */ + public static final int WIFI_BAND_BOTH = 3; /** DFS channels from 5 GHz band only */ - public static final int WIFI_BAND_5_GHZ_DFS_ONLY = 4; /* 5 GHz band DFS channels */ + public static final int WIFI_BAND_5_GHZ_DFS_ONLY = 4; /** * 2.4Ghz band + DFS channels from 5 GHz band only * @hide */ public static final int WIFI_BAND_24_GHZ_WITH_5GHZ_DFS = 5; /** 5 GHz band including DFS channels */ - public static final int WIFI_BAND_5_GHZ_WITH_DFS = 6; /* 5 GHz band with DFS channels */ - /** Both 2.4 GHz band and 5 GHz band; no DFS channels */ - public static final int WIFI_BAND_BOTH = 3; /* both bands without DFS channels */ + public static final int WIFI_BAND_5_GHZ_WITH_DFS = 6; /** Both 2.4 GHz band and 5 GHz band; with DFS channels */ - public static final int WIFI_BAND_BOTH_WITH_DFS = 7; /* both bands with DFS channels */ + public static final int WIFI_BAND_BOTH_WITH_DFS = 7; /** * Max band value * @hide @@ -78,9 +94,9 @@ public class WifiScanner { public static final int WIFI_BAND_MAX = 8; /** Minimum supported scanning period */ - public static final int MIN_SCAN_PERIOD_MS = 1000; /* minimum supported period */ + public static final int MIN_SCAN_PERIOD_MS = 1000; /** Maximum supported scanning period */ - public static final int MAX_SCAN_PERIOD_MS = 1024000; /* maximum supported period */ + public static final int MAX_SCAN_PERIOD_MS = 1024000; /** No Error */ public static final int REASON_SUCCEEDED = 0; @@ -109,13 +125,20 @@ public class WifiScanner { } /** - * gives you all the possible channels; channel is specified as an - * integer with frequency in MHz i.e. channel 1 is 2412 + * Returns a list of all the possible channels for the given band(s). + * + * @param band one of the WifiScanner#WIFI_BAND_* constants, e.g. {@link #WIFI_BAND_24_GHZ} + * @return a list of all the frequencies, in MHz, for the given band(s) e.g. channel 1 is + * 2412, or null if an error occurred. + * * @hide */ - public List getAvailableChannels(int band) { + @SystemApi + @Nullable + @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE) + public List getAvailableChannels(@WifiBand int band) { try { - Bundle bundle = mService.getAvailableChannels(band); + Bundle bundle = mService.getAvailableChannels(band, mContext.getOpPackageName()); return bundle.getIntegerArrayList(GET_AVAILABLE_CHANNELS_EXTRA); } catch (RemoteException e) { return null;