From 51493e199ebf1e1191ccf652f0081d229018a11f Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Tue, 21 Mar 2017 15:55:03 -0700 Subject: Separate single scan and sched scan result handling Bug: 36479602 Test: compile, unit tests, integration test Change-Id: I066619ca7c53cf7e8e53ce776c1b419201d522f1 --- .../java/com/android/server/wifi/WifiMonitor.java | 11 ++++ .../com/android/server/wifi/WificondControl.java | 2 +- .../server/wifi/scanner/WificondScannerImpl.java | 62 +++++++++++++++++----- 3 files changed, 61 insertions(+), 14 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java index 15ec8fd77..c4f0bdedb 100644 --- a/service/java/com/android/server/wifi/WifiMonitor.java +++ b/service/java/com/android/server/wifi/WifiMonitor.java @@ -87,6 +87,9 @@ public class WifiMonitor { public static final int SUP_REQUEST_SIM_AUTH = BASE + 16; public static final int SCAN_FAILED_EVENT = BASE + 17; + /* Pno scan results are available */ + public static final int PNO_SCAN_RESULTS_EVENT = BASE + 18; + /* Indicates assoc reject event */ public static final int ASSOCIATION_REJECTION_EVENT = BASE + 43; @@ -463,6 +466,14 @@ public class WifiMonitor { sendMessage(iface, SCAN_RESULTS_EVENT); } + /** + * Broadcast pno scan result event to all the handlers registered for this event. + * @param iface Name of iface on which this occurred. + */ + public void broadcastPnoScanResultEvent(String iface) { + sendMessage(iface, PNO_SCAN_RESULTS_EVENT); + } + /** * Broadcast scan failed event to all the handlers registered for this event. * @param iface Name of iface on which this occurred. diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java index e2a08a853..c88a80426 100644 --- a/service/java/com/android/server/wifi/WificondControl.java +++ b/service/java/com/android/server/wifi/WificondControl.java @@ -87,7 +87,7 @@ public class WificondControl { @Override public void OnPnoNetworkFound() { Log.d(TAG, "Pno scan result event"); - mWifiMonitor.broadcastScanResultEvent(mClientInterfaceName); + mWifiMonitor.broadcastPnoScanResultEvent(mClientInterfaceName); } @Override diff --git a/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java b/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java index e3058b6c4..9f73a246c 100644 --- a/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java +++ b/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java @@ -144,6 +144,8 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call wifiMonitor.registerHandler(mWifiNative.getInterfaceName(), WifiMonitor.SCAN_FAILED_EVENT, mEventHandler); + wifiMonitor.registerHandler(mWifiNative.getInterfaceName(), + WifiMonitor.PNO_SCAN_RESULTS_EVENT, mEventHandler); wifiMonitor.registerHandler(mWifiNative.getInterfaceName(), WifiMonitor.SCAN_RESULTS_EVENT, mEventHandler); } @@ -502,6 +504,13 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call reportScanFailure(); processPendingScans(); break; + case WifiMonitor.PNO_SCAN_RESULTS_EVENT: + mAlarmManager.cancel(mScanTimeoutListener); + pollLatestScanDataForPno(); + // TODO(b/36276738): Remove this after we fix b/36231150. + Log.d(TAG, "processPendingScans in request of SCHED_SCAN_RESULTS_EVENT"); + processPendingScans(); + break; case WifiMonitor.SCAN_RESULTS_EVENT: mAlarmManager.cancel(mScanTimeoutListener); pollLatestScanData(); @@ -542,6 +551,46 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call } } + private void pollLatestScanDataForPno() { + synchronized (mSettingsLock) { + if (mLastScanSettings == null) { + // got a scan before we started scanning or after scan was canceled + return; + } + ArrayList nativeResults = mWifiNative.getScanResults(); + List hwPnoScanResults = new ArrayList<>(); + int numFilteredScanResults = 0; + for (int i = 0; i < nativeResults.size(); ++i) { + ScanResult result = nativeResults.get(i).getScanResult(); + long timestamp_ms = result.timestamp / 1000; // convert us -> ms + if (timestamp_ms > mLastScanSettings.startTime) { + if (mLastScanSettings.hwPnoScanActive) { + hwPnoScanResults.add(result); + } + } else { + numFilteredScanResults++; + } + } + + if (numFilteredScanResults != 0) { + Log.d(TAG, "Filtering out " + numFilteredScanResults + " pno scan results."); + } + + if (mLastScanSettings.hwPnoScanActive + && mLastScanSettings.pnoScanEventHandler != null) { + ScanResult[] pnoScanResultsArray = new ScanResult[hwPnoScanResults.size()]; + for (int i = 0; i < pnoScanResultsArray.length; ++i) { + ScanResult result = nativeResults.get(i).getScanResult(); + pnoScanResultsArray[i] = hwPnoScanResults.get(i); + } + mLastScanSettings.pnoScanEventHandler.onPnoNetworkFound(pnoScanResultsArray); + } + // mLastScanSettings is for either single/batched scan or pno scan. + // We can safely set it to null when pno scan finishes. + mLastScanSettings = null; + } + } + private void pollLatestScanData() { synchronized (mSettingsLock) { if (mLastScanSettings == null) { @@ -553,7 +602,6 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call ArrayList nativeResults = mWifiNative.getScanResults(); List singleScanResults = new ArrayList<>(); List backgroundScanResults = new ArrayList<>(); - List hwPnoScanResults = new ArrayList<>(); int numFilteredScanResults = 0; for (int i = 0; i < nativeResults.size(); ++i) { ScanResult result = nativeResults.get(i).getScanResult(); @@ -567,9 +615,6 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call result.frequency)) { singleScanResults.add(result); } - if (mLastScanSettings.hwPnoScanActive) { - hwPnoScanResults.add(result); - } } else { numFilteredScanResults++; } @@ -650,15 +695,6 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call .onScanStatus(WifiNative.WIFI_SCAN_RESULTS_AVAILABLE); } - if (mLastScanSettings.hwPnoScanActive - && mLastScanSettings.pnoScanEventHandler != null) { - ScanResult[] pnoScanResultsArray = new ScanResult[hwPnoScanResults.size()]; - for (int i = 0; i < pnoScanResultsArray.length; ++i) { - pnoScanResultsArray[i] = hwPnoScanResults.get(i); - } - mLastScanSettings.pnoScanEventHandler.onPnoNetworkFound(pnoScanResultsArray); - } - mLastScanSettings = null; } } -- cgit v1.2.3