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:
Irfan Sheriff
2010-09-06 15:34:50 -07:00
parent 173ea0912a
commit 0859b76471
3 changed files with 24 additions and 17 deletions

View File

@ -173,6 +173,7 @@ public class WifiService extends IWifiManager.Stub {
private static final int MESSAGE_STOP_ACCESS_POINT = 7;
private static final int MESSAGE_SET_CHANNELS = 8;
private static final int MESSAGE_ENABLE_NETWORKS = 9;
private static final int MESSAGE_START_SCAN = 10;
private final WifiHandler mWifiHandler;
@ -385,23 +386,12 @@ public class WifiService extends IWifiManager.Stub {
/**
* 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();
if (mWifiHandler == null) return;
switch (mWifiStateTracker.getSupplicantState()) {
case DISCONNECTED:
case INACTIVE:
case SCANNING:
case DORMANT:
break;
default:
mWifiStateTracker.setScanResultHandling(
WifiStateTracker.SUPPL_SCAN_HANDLING_LIST_ONLY);
break;
}
return mWifiStateTracker.scan(forceActive);
Message.obtain(mWifiHandler, MESSAGE_START_SCAN, forceActive ? 1 : 0, 0).sendToTarget();
}
/**
@ -2001,6 +1991,21 @@ public class WifiService extends IWifiManager.Stub {
mWifiStateTracker.enableAllNetworks(getConfiguredNetworks());
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;
}
}
}

View File

@ -42,7 +42,7 @@ interface IWifiManager
boolean pingSupplicant();
boolean startScan(boolean forceActive);
void startScan(boolean forceActive);
List<ScanResult> getScanResults();

View File

@ -570,7 +570,8 @@ public class WifiManager {
*/
public boolean startScan() {
try {
return mService.startScan(false);
mService.startScan(false);
return true;
} catch (RemoteException e) {
return false;
}
@ -588,7 +589,8 @@ public class WifiManager {
*/
public boolean startScanActive() {
try {
return mService.startScan(true);
mService.startScan(true);
return true;
} catch (RemoteException e) {
return false;
}