summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiMonitor.java11
-rw-r--r--service/java/com/android/server/wifi/WificondControl.java2
-rw-r--r--service/java/com/android/server/wifi/scanner/WificondScannerImpl.java62
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WificondControlTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/scanner/WificondPnoScannerTest.java3
6 files changed, 79 insertions, 16 deletions
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;
@@ -464,6 +467,14 @@ public class WifiMonitor {
}
/**
+ * 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
@@ -145,6 +145,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<ScanDetail> nativeResults = mWifiNative.getScanResults();
+ List<ScanResult> 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<ScanDetail> nativeResults = mWifiNative.getScanResults();
List<ScanResult> singleScanResults = new ArrayList<>();
List<ScanResult> backgroundScanResults = new ArrayList<>();
- List<ScanResult> 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;
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
index e9424223d..6e3dbbbcf 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java
@@ -291,6 +291,21 @@ public class WifiMonitorTest {
}
/**
+ * Broadcast pno scan results event test.
+ */
+ @Test
+ public void testBroadcastPnoScanResultsEvent() {
+ mWifiMonitor.registerHandler(
+ WLAN_IFACE_NAME, WifiMonitor.PNO_SCAN_RESULTS_EVENT, mHandlerSpy);
+ mWifiMonitor.broadcastPnoScanResultEvent(WLAN_IFACE_NAME);
+ mLooper.dispatchAll();
+
+ ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);
+ verify(mHandlerSpy).handleMessage(messageCaptor.capture());
+ assertEquals(WifiMonitor.PNO_SCAN_RESULTS_EVENT, messageCaptor.getValue().what);
+ }
+
+ /**
* Broadcast Scan results event test.
*/
@Test
diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java
index 93ebd0b0c..8f2994141 100644
--- a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java
@@ -592,7 +592,7 @@ public class WificondControlTest {
assertNotNull(pnoScanEvent);
pnoScanEvent.OnPnoNetworkFound();
- verify(mWifiMonitor).broadcastScanResultEvent(any(String.class));
+ verify(mWifiMonitor).broadcastPnoScanResultEvent(any(String.class));
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WificondPnoScannerTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WificondPnoScannerTest.java
index 1dd548153..24bcae296 100644
--- a/tests/wifitests/src/com/android/server/wifi/scanner/WificondPnoScannerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/scanner/WificondPnoScannerTest.java
@@ -432,7 +432,8 @@ public class WificondPnoScannerTest {
when(mWifiNative.getScanResults()).thenReturn(scanResults.getScanDetailArrayList());
// Notify scan has finished
- mWifiMonitor.sendMessage(mWifiNative.getInterfaceName(), WifiMonitor.SCAN_RESULTS_EVENT);
+ mWifiMonitor.sendMessage(mWifiNative.getInterfaceName(),
+ WifiMonitor.PNO_SCAN_RESULTS_EVENT);
assertEquals("dispatch message after results event", 1, mLooper.dispatchAll());
order.verify(eventHandler).onPnoNetworkFound(scanResults.getRawScanResults());