Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e128001 authored by David Su's avatar David Su
Browse files

Make WifiScanner#getAvailableChannels() @SystemApi

While here removed some redundant comments.

Bug: 129008573
Test: atest FrameworksWifiApiTests
Change-Id: Id6ca5cf4547ff7321805ad671b9e25dab9953cd3
parent 9fc76a34
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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<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);
+1 −1
Original line number Diff line number Diff line
@@ -26,5 +26,5 @@ interface IWifiScanner
{
    Messenger getMessenger();

    Bundle getAvailableChannels(int band);
    Bundle getAvailableChannels(int band, String packageName);
}
+38 −15
Original line number Diff line number Diff line
@@ -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<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;