public class WifiScanner extends Object
Context.getSystemService(Context
.WIFI_SCANNING_SERVICE)
.Modifier and Type | Field and Description |
---|---|
static int |
CMD_AP_FOUND |
static int |
CMD_AP_LOST |
static int |
CMD_CONFIGURE_WIFI_CHANGE |
static int |
CMD_DEREGISTER_SCAN_LISTENER |
static int |
CMD_FULL_SCAN_RESULT |
static int |
CMD_GET_SCAN_RESULTS |
static int |
CMD_OP_FAILED |
static int |
CMD_OP_SUCCEEDED |
static int |
CMD_PERIOD_CHANGED |
static int |
CMD_PNO_NETWORK_FOUND |
static int |
CMD_REGISTER_SCAN_LISTENER |
static int |
CMD_RESET_HOTLIST |
static int |
CMD_SCAN |
static int |
CMD_SCAN_RESULT |
static int |
CMD_SET_HOTLIST |
static int |
CMD_SINGLE_SCAN_COMPLETED |
static int |
CMD_START_BACKGROUND_SCAN |
static int |
CMD_START_PNO_SCAN |
static int |
CMD_START_SINGLE_SCAN |
static int |
CMD_START_TRACKING_CHANGE |
static int |
CMD_STOP_BACKGROUND_SCAN |
static int |
CMD_STOP_PNO_SCAN |
static int |
CMD_STOP_SINGLE_SCAN |
static int |
CMD_STOP_TRACKING_CHANGE |
static int |
CMD_WIFI_CHANGE_DETECTED |
static int |
CMD_WIFI_CHANGES_STABILIZED |
static String |
GET_AVAILABLE_CHANNELS_EXTRA |
static int |
MAX_SCAN_PERIOD_MS
Maximum supported scanning period
|
static int |
MIN_SCAN_PERIOD_MS
Minimum supported scanning period
|
static String |
PNO_PARAMS_PNO_SETTINGS_KEY |
static String |
PNO_PARAMS_SCAN_SETTINGS_KEY |
static int |
REASON_DUPLICATE_REQEUST
An outstanding request with the same listener hasn't finished yet.
|
static int |
REASON_INVALID_LISTENER
Invalid listener
|
static int |
REASON_INVALID_REQUEST
Invalid request
|
static int |
REASON_NOT_AUTHORIZED
Invalid request
|
static int |
REASON_SUCCEEDED
No Error
|
static int |
REASON_UNSPECIFIED
Unknown error
|
static int |
REPORT_EVENT_AFTER_BUFFER_FULL
Deprecated.
It is not supported anymore.
|
static int |
REPORT_EVENT_AFTER_EACH_SCAN
reports
WifiScanner.ScanListener.onResults(android.net.wifi.WifiScanner.ScanData[]) after each scan |
static int |
REPORT_EVENT_FULL_SCAN_RESULT
reports
WifiScanner.ScanListener.onFullResult(android.net.wifi.ScanResult) whenever each beacon is discovered |
static int |
REPORT_EVENT_NO_BATCH
Do not place scans in the chip's scan history buffer
|
static String |
SCAN_PARAMS_SCAN_SETTINGS_KEY |
static String |
SCAN_PARAMS_WORK_SOURCE_KEY |
static int |
WIFI_BAND_24_GHZ
2.4 GHz band
|
static int |
WIFI_BAND_5_GHZ
5 GHz band excluding DFS channels
|
static int |
WIFI_BAND_5_GHZ_DFS_ONLY
DFS channels from 5 GHz band only
|
static int |
WIFI_BAND_5_GHZ_WITH_DFS
5 GHz band including DFS channels
|
static int |
WIFI_BAND_BOTH
Both 2.4 GHz band and 5 GHz band; no DFS channels
|
static int |
WIFI_BAND_BOTH_WITH_DFS
Both 2.4 GHz band and 5 GHz band; with DFS channels
|
static int |
WIFI_BAND_UNSPECIFIED
no band specified; use channel list instead
|
Constructor and Description |
---|
WifiScanner(Context context,
IWifiScanner service,
Looper looper)
Create a new WifiScanner instance.
|
Modifier and Type | Method and Description |
---|---|
void |
configureWifiChange(int rssiSampleSize,
int lostApSampleSize,
int unchangedSampleSize,
int minApsBreachingThreshold,
int periodInMs,
WifiScanner.BssidInfo[] bssidInfos)
configure WifiChange detection
|
void |
configureWifiChange(WifiScanner.WifiChangeSettings settings) |
void |
deregisterScanListener(WifiScanner.ScanListener listener)
Deregister a listener for ongoing single scans
|
List<Integer> |
getAvailableChannels(int band)
gives you all the possible channels; channel is specified as an
integer with frequency in MHz i.e. channel 1 is 2412
|
boolean |
getScanResults()
reports currently available scan results on appropriate listeners
|
void |
registerScanListener(WifiScanner.ScanListener listener)
Register a listener that will receive results from all single scans
Either the onSuccess/onFailure will be called once when the listener is registered.
|
void |
startBackgroundScan(WifiScanner.ScanSettings settings,
WifiScanner.ScanListener listener)
start wifi scan in background
|
void |
startBackgroundScan(WifiScanner.ScanSettings settings,
WifiScanner.ScanListener listener,
WorkSource workSource)
start wifi scan in background
|
void |
startConnectedPnoScan(WifiScanner.ScanSettings scanSettings,
WifiScanner.PnoSettings pnoSettings,
WifiScanner.PnoScanListener listener)
Start wifi connected PNO scan
|
void |
startDisconnectedPnoScan(WifiScanner.ScanSettings scanSettings,
WifiScanner.PnoSettings pnoSettings,
WifiScanner.PnoScanListener listener)
Start wifi disconnected PNO scan
|
void |
startScan(WifiScanner.ScanSettings settings,
WifiScanner.ScanListener listener)
starts a single scan and reports results asynchronously
|
void |
startScan(WifiScanner.ScanSettings settings,
WifiScanner.ScanListener listener,
WorkSource workSource)
starts a single scan and reports results asynchronously
|
void |
startTrackingBssids(WifiScanner.BssidInfo[] bssidInfos,
int apLostThreshold,
WifiScanner.BssidListener listener)
set interesting access points to find
|
void |
startTrackingWifiChange(WifiScanner.WifiChangeListener listener)
track changes in wifi environment
|
void |
stopBackgroundScan(WifiScanner.ScanListener listener)
stop an ongoing wifi scan
|
void |
stopPnoScan(WifiScanner.ScanListener listener)
Stop an ongoing wifi PNO scan
|
void |
stopScan(WifiScanner.ScanListener listener)
stops an ongoing single shot scan; only useful after
startScan(android.net.wifi.WifiScanner.ScanSettings, android.net.wifi.WifiScanner.ScanListener) if onResults()
hasn't been called on the listener, ignored otherwise |
void |
stopTrackingBssids(WifiScanner.BssidListener listener)
remove tracking of interesting access points
|
void |
stopTrackingWifiChange(WifiScanner.WifiChangeListener listener)
stop tracking changes in wifi environment
|
public static final int WIFI_BAND_UNSPECIFIED
public static final int WIFI_BAND_24_GHZ
public static final int WIFI_BAND_5_GHZ
public static final int WIFI_BAND_5_GHZ_DFS_ONLY
public static final int WIFI_BAND_5_GHZ_WITH_DFS
public static final int WIFI_BAND_BOTH
public static final int WIFI_BAND_BOTH_WITH_DFS
public static final int MIN_SCAN_PERIOD_MS
public static final int MAX_SCAN_PERIOD_MS
public static final int REASON_SUCCEEDED
public static final int REASON_UNSPECIFIED
public static final int REASON_INVALID_LISTENER
public static final int REASON_INVALID_REQUEST
public static final int REASON_NOT_AUTHORIZED
public static final int REASON_DUPLICATE_REQEUST
public static final String GET_AVAILABLE_CHANNELS_EXTRA
@Deprecated public static final int REPORT_EVENT_AFTER_BUFFER_FULL
WifiScanner.ScanListener.onResults(android.net.wifi.WifiScanner.ScanData[])
when underlying buffers are full
this is simply the lack of the REPORT_EVENT_AFTER_EACH_SCAN
flagpublic static final int REPORT_EVENT_AFTER_EACH_SCAN
WifiScanner.ScanListener.onResults(android.net.wifi.WifiScanner.ScanData[])
after each scanpublic static final int REPORT_EVENT_FULL_SCAN_RESULT
WifiScanner.ScanListener.onFullResult(android.net.wifi.ScanResult)
whenever each beacon is discoveredpublic static final int REPORT_EVENT_NO_BATCH
public static final String SCAN_PARAMS_SCAN_SETTINGS_KEY
public static final String SCAN_PARAMS_WORK_SOURCE_KEY
public static final String PNO_PARAMS_PNO_SETTINGS_KEY
public static final String PNO_PARAMS_SCAN_SETTINGS_KEY
public static final int CMD_SCAN
public static final int CMD_START_BACKGROUND_SCAN
public static final int CMD_STOP_BACKGROUND_SCAN
public static final int CMD_GET_SCAN_RESULTS
public static final int CMD_SCAN_RESULT
public static final int CMD_SET_HOTLIST
public static final int CMD_RESET_HOTLIST
public static final int CMD_AP_FOUND
public static final int CMD_AP_LOST
public static final int CMD_START_TRACKING_CHANGE
public static final int CMD_STOP_TRACKING_CHANGE
public static final int CMD_CONFIGURE_WIFI_CHANGE
public static final int CMD_WIFI_CHANGE_DETECTED
public static final int CMD_WIFI_CHANGES_STABILIZED
public static final int CMD_OP_SUCCEEDED
public static final int CMD_OP_FAILED
public static final int CMD_PERIOD_CHANGED
public static final int CMD_FULL_SCAN_RESULT
public static final int CMD_START_SINGLE_SCAN
public static final int CMD_STOP_SINGLE_SCAN
public static final int CMD_SINGLE_SCAN_COMPLETED
public static final int CMD_START_PNO_SCAN
public static final int CMD_STOP_PNO_SCAN
public static final int CMD_PNO_NETWORK_FOUND
public static final int CMD_REGISTER_SCAN_LISTENER
public static final int CMD_DEREGISTER_SCAN_LISTENER
public WifiScanner(Context context, IWifiScanner service, Looper looper)
Context.getSystemService()
to retrieve
the standard Context.WIFI_SERVICE
.context
- the application contextservice
- the Binder interfacelooper
- the Looper used to deliver callbackspublic List<Integer> getAvailableChannels(int band)
public void registerScanListener(WifiScanner.ScanListener listener)
listener
- specifies the object to report events to. This object is also treated as a
key for this request, and must also be specified to cancel the request.
Multiple requests should also not share this object.
public void deregisterScanListener(WifiScanner.ScanListener listener)
listener
- specifies which scan to cancel; must be same object as passed in registerScanListener(android.net.wifi.WifiScanner.ScanListener)
public void startBackgroundScan(WifiScanner.ScanSettings settings, WifiScanner.ScanListener listener)
settings
- specifies various parameters for the scan; for more information look at
ScanSettings
listener
- specifies the object to report events to. This object is also treated as a
key for this scan, and must also be specified to cancel the scan. Multiple
scans should also not share this object.public void startBackgroundScan(WifiScanner.ScanSettings settings, WifiScanner.ScanListener listener, WorkSource workSource)
settings
- specifies various parameters for the scan; for more information look at
ScanSettings
workSource
- WorkSource to blame for power usagelistener
- specifies the object to report events to. This object is also treated as a
key for this scan, and must also be specified to cancel the scan. Multiple
scans should also not share this object.public void stopBackgroundScan(WifiScanner.ScanListener listener)
listener
- specifies which scan to cancel; must be same object as passed in startBackgroundScan(android.net.wifi.WifiScanner.ScanSettings, android.net.wifi.WifiScanner.ScanListener)
public boolean getScanResults()
public void startScan(WifiScanner.ScanSettings settings, WifiScanner.ScanListener listener)
settings
- specifies various parameters for the scan; for more information look at
ScanSettings
listener
- specifies the object to report events to. This object is also treated as a
key for this scan, and must also be specified to cancel the scan. Multiple
scans should also not share this object.public void startScan(WifiScanner.ScanSettings settings, WifiScanner.ScanListener listener, WorkSource workSource)
settings
- specifies various parameters for the scan; for more information look at
ScanSettings
workSource
- WorkSource to blame for power usagelistener
- specifies the object to report events to. This object is also treated as a
key for this scan, and must also be specified to cancel the scan. Multiple
scans should also not share this object.public void stopScan(WifiScanner.ScanListener listener)
startScan(android.net.wifi.WifiScanner.ScanSettings, android.net.wifi.WifiScanner.ScanListener)
if onResults()
hasn't been called on the listener, ignored otherwiselistener
- public void startConnectedPnoScan(WifiScanner.ScanSettings scanSettings, WifiScanner.PnoSettings pnoSettings, WifiScanner.PnoScanListener listener)
scanSettings
- specifies various parameters for the scan; for more information look at
ScanSettings
pnoSettings
- specifies various parameters for PNO; for more information look at
WifiScanner.PnoSettings
listener
- specifies the object to report events to. This object is also treated as a
key for this scan, and must also be specified to cancel the scan. Multiple
scans should also not share this object.
public void startDisconnectedPnoScan(WifiScanner.ScanSettings scanSettings, WifiScanner.PnoSettings pnoSettings, WifiScanner.PnoScanListener listener)
scanSettings
- specifies various parameters for the scan; for more information look at
ScanSettings
pnoSettings
- specifies various parameters for PNO; for more information look at
WifiScanner.PnoSettings
listener
- specifies the object to report events to. This object is also treated as a
key for this scan, and must also be specified to cancel the scan. Multiple
scans should also not share this object.
public void stopPnoScan(WifiScanner.ScanListener listener)
listener
- specifies which scan to cancel; must be same object as passed in startPnoScan(android.net.wifi.WifiScanner.ScanSettings, android.net.wifi.WifiScanner.PnoSettings, int)
TODO(rpius): Check if we can remove pnoSettings param in stop.
public void configureWifiChange(int rssiSampleSize, int lostApSampleSize, int unchangedSampleSize, int minApsBreachingThreshold, int periodInMs, WifiScanner.BssidInfo[] bssidInfos)
rssiSampleSize
- number of samples used for RSSI averaginglostApSampleSize
- number of samples to confirm an access point's lossunchangedSampleSize
- number of samples to confirm there are no changesminApsBreachingThreshold
- minimum number of access points that need to be
out of range to detect WifiChangeperiodInMs
- indicates period of scan to find changesbssidInfos
- access points to watchpublic void startTrackingWifiChange(WifiScanner.WifiChangeListener listener)
listener
- object to report events on; this object must be unique and must also be
provided on stopTrackingWifiChange(android.net.wifi.WifiScanner.WifiChangeListener)
public void stopTrackingWifiChange(WifiScanner.WifiChangeListener listener)
listener
- object that was provided to report events on stopTrackingWifiChange(android.net.wifi.WifiScanner.WifiChangeListener)
public void configureWifiChange(WifiScanner.WifiChangeSettings settings)
public void startTrackingBssids(WifiScanner.BssidInfo[] bssidInfos, int apLostThreshold, WifiScanner.BssidListener listener)
bssidInfos
- access points of interestapLostThreshold
- number of scans needed to indicate that AP is lostlistener
- object provided to report events on; this object must be unique and must
also be provided on stopTrackingBssids(android.net.wifi.WifiScanner.BssidListener)
public void stopTrackingBssids(WifiScanner.BssidListener listener)
listener
- same object provided in startTrackingBssids(android.net.wifi.WifiScanner.BssidInfo[], int, android.net.wifi.WifiScanner.BssidListener)