Merge "Make WifiScanner#getAvailableChannels() @SystemApi"
diff --git a/api/system-current.txt b/api/system-current.txt
index 35b096d..9573478 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -4845,6 +4845,7 @@
   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<java.lang.Integer> 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 3984934..114c732 100644
--- a/wifi/java/android/net/wifi/IWifiScanner.aidl
+++ b/wifi/java/android/net/wifi/IWifiScanner.aidl
@@ -26,5 +26,5 @@
 {
     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 68948cb..21189a4 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.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 @@
 @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 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 @@
     }
 
     /**
-     * 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<Integer> getAvailableChannels(int band) {
+    @SystemApi
+    @Nullable
+    @RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
+    public List<Integer> 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;