Make wifi scan async. (don't auto-merge)
When an entity (NLP for example) acquires a WifiLock and initiates a scan, scan can get blocked until driver starts. scan returns no useful info, scan results are broadcast when obtained. Bug: 2964633 Change-Id: Iaefc32bb6b82f0718285a18ac600e6bbbb096e77
This commit is contained in:
@ -173,6 +173,7 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
private static final int MESSAGE_STOP_ACCESS_POINT = 7;
|
private static final int MESSAGE_STOP_ACCESS_POINT = 7;
|
||||||
private static final int MESSAGE_SET_CHANNELS = 8;
|
private static final int MESSAGE_SET_CHANNELS = 8;
|
||||||
private static final int MESSAGE_ENABLE_NETWORKS = 9;
|
private static final int MESSAGE_ENABLE_NETWORKS = 9;
|
||||||
|
private static final int MESSAGE_START_SCAN = 10;
|
||||||
|
|
||||||
|
|
||||||
private final WifiHandler mWifiHandler;
|
private final WifiHandler mWifiHandler;
|
||||||
@ -385,23 +386,12 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* see {@link android.net.wifi.WifiManager#startScan()}
|
* see {@link android.net.wifi.WifiManager#startScan()}
|
||||||
* @return {@code true} if the operation succeeds
|
|
||||||
*/
|
*/
|
||||||
public boolean startScan(boolean forceActive) {
|
public void startScan(boolean forceActive) {
|
||||||
enforceChangePermission();
|
enforceChangePermission();
|
||||||
|
if (mWifiHandler == null) return;
|
||||||
|
|
||||||
switch (mWifiStateTracker.getSupplicantState()) {
|
Message.obtain(mWifiHandler, MESSAGE_START_SCAN, forceActive ? 1 : 0, 0).sendToTarget();
|
||||||
case DISCONNECTED:
|
|
||||||
case INACTIVE:
|
|
||||||
case SCANNING:
|
|
||||||
case DORMANT:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
mWifiStateTracker.setScanResultHandling(
|
|
||||||
WifiStateTracker.SUPPL_SCAN_HANDLING_LIST_ONLY);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return mWifiStateTracker.scan(forceActive);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2001,6 +1991,21 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
mWifiStateTracker.enableAllNetworks(getConfiguredNetworks());
|
mWifiStateTracker.enableAllNetworks(getConfiguredNetworks());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MESSAGE_START_SCAN:
|
||||||
|
boolean forceActive = (msg.arg1 == 1);
|
||||||
|
switch (mWifiStateTracker.getSupplicantState()) {
|
||||||
|
case DISCONNECTED:
|
||||||
|
case INACTIVE:
|
||||||
|
case SCANNING:
|
||||||
|
case DORMANT:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mWifiStateTracker.setScanResultHandling(
|
||||||
|
WifiStateTracker.SUPPL_SCAN_HANDLING_LIST_ONLY);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mWifiStateTracker.scan(forceActive);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ interface IWifiManager
|
|||||||
|
|
||||||
boolean pingSupplicant();
|
boolean pingSupplicant();
|
||||||
|
|
||||||
boolean startScan(boolean forceActive);
|
void startScan(boolean forceActive);
|
||||||
|
|
||||||
List<ScanResult> getScanResults();
|
List<ScanResult> getScanResults();
|
||||||
|
|
||||||
|
@ -570,7 +570,8 @@ public class WifiManager {
|
|||||||
*/
|
*/
|
||||||
public boolean startScan() {
|
public boolean startScan() {
|
||||||
try {
|
try {
|
||||||
return mService.startScan(false);
|
mService.startScan(false);
|
||||||
|
return true;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -588,7 +589,8 @@ public class WifiManager {
|
|||||||
*/
|
*/
|
||||||
public boolean startScanActive() {
|
public boolean startScanActive() {
|
||||||
try {
|
try {
|
||||||
return mService.startScan(true);
|
mService.startScan(true);
|
||||||
|
return true;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user