diff options
5 files changed, 36 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 973b659d2..1d6c9d4af 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -227,7 +227,16 @@ public class WifiNative { * Returns an empty ArrayList on failure. */ public ArrayList<ScanDetail> getScanResults() { - return mWificondControl.getScanResults(); + return mWificondControl.getScanResults(WificondControl.SCAN_TYPE_SINGLE_SCAN); + } + + /** + * Fetch the latest scan result from kernel via wificond. + * @return Returns an ArrayList of ScanDetail. + * Returns an empty ArrayList on failure. + */ + public ArrayList<ScanDetail> getPnoScanResults() { + return mWificondControl.getScanResults(WificondControl.SCAN_TYPE_PNO_SCAN); } /** diff --git a/service/java/com/android/server/wifi/WificondControl.java b/service/java/com/android/server/wifi/WificondControl.java index 005f36042..70ecabccf 100644 --- a/service/java/com/android/server/wifi/WificondControl.java +++ b/service/java/com/android/server/wifi/WificondControl.java @@ -51,6 +51,13 @@ public class WificondControl { private boolean mVerboseLoggingEnabled = false; private static final String TAG = "WificondControl"; + + /* Get scan results for a single scan */ + public static final int SCAN_TYPE_SINGLE_SCAN = 0; + + /* Get scan results for Pno Scan */ + public static final int SCAN_TYPE_PNO_SCAN = 1; + private WifiInjector mWifiInjector; private WifiMonitor mWifiMonitor; private final CarrierNetworkConfig mCarrierNetworkConfig; @@ -334,14 +341,19 @@ public class WificondControl { * @return Returns an ArrayList of ScanDetail. * Returns an empty ArrayList on failure. */ - public ArrayList<ScanDetail> getScanResults() { + public ArrayList<ScanDetail> getScanResults(int scanType) { ArrayList<ScanDetail> results = new ArrayList<>(); if (mWificondScanner == null) { Log.e(TAG, "No valid wificond scanner interface handler"); return results; } try { - NativeScanResult[] nativeResults = mWificondScanner.getScanResults(); + NativeScanResult[] nativeResults; + if (scanType == SCAN_TYPE_SINGLE_SCAN) { + nativeResults = mWificondScanner.getScanResults(); + } else { + nativeResults = mWificondScanner.getPnoScanResults(); + } for (NativeScanResult result : nativeResults) { WifiSsid wifiSsid = WifiSsid.createFromByteArray(result.ssid); String bssid; diff --git a/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java b/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java index 84105ee61..12a0bdee0 100644 --- a/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java +++ b/service/java/com/android/server/wifi/scanner/WificondScannerImpl.java @@ -538,7 +538,7 @@ public class WificondScannerImpl extends WifiScannerImpl implements Handler.Call // got a scan before we started scanning or after scan was canceled return; } - mNativeScanResults = mWifiNative.getScanResults(); + mNativeScanResults = mWifiNative.getPnoScanResults(); List<ScanResult> hwPnoScanResults = new ArrayList<>(); int numFilteredScanResults = 0; for (int i = 0; i < mNativeScanResults.size(); ++i) { diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java index 4dfa4cd75..164f75999 100644 --- a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java @@ -460,7 +460,8 @@ public class WificondControlTest { assertTrue(mWificondControl.tearDownInterfaces()); // getScanResults should fail. - assertEquals(0, mWificondControl.getScanResults().size()); + assertEquals(0, + mWificondControl.getScanResults(WificondControl.SCAN_TYPE_SINGLE_SCAN).size()); } /** @@ -475,7 +476,8 @@ public class WificondControlTest { NativeScanResult[] mockScanResults = {MOCK_NATIVE_SCAN_RESULT}; when(scanner.getScanResults()).thenReturn(mockScanResults); - ArrayList<ScanDetail> returnedScanResults = mWificondControl.getScanResults(); + ArrayList<ScanDetail> returnedScanResults = mWificondControl.getScanResults( + WificondControl.SCAN_TYPE_SINGLE_SCAN); // The test IEs {@link #TEST_INFO_ELEMENT} doesn't contained RSN IE, which means non-EAP // AP. So verify carrier network is not checked, since EAP is currently required for a // carrier network. @@ -522,7 +524,8 @@ public class WificondControlTest { .thenReturn(eapType); when(mCarrierNetworkConfig.getCarrierName(new String(nativeScanResult.ssid))) .thenReturn(carrierName); - ArrayList<ScanDetail> returnedScanResults = mWificondControl.getScanResults(); + ArrayList<ScanDetail> returnedScanResults = mWificondControl.getScanResults( + WificondControl.SCAN_TYPE_SINGLE_SCAN); assertEquals(1, returnedScanResults.size()); // Verify returned scan result. ScanResult scanResult = returnedScanResults.get(0).getScanResult(); @@ -535,7 +538,8 @@ public class WificondControlTest { // AP not associated with a carrier network. when(mCarrierNetworkConfig.isCarrierNetwork(new String(nativeScanResult.ssid))) .thenReturn(false); - returnedScanResults = mWificondControl.getScanResults(); + returnedScanResults = mWificondControl.getScanResults( + WificondControl.SCAN_TYPE_SINGLE_SCAN); assertEquals(1, returnedScanResults.size()); // Verify returned scan result. scanResult = returnedScanResults.get(0).getScanResult(); 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 c63a9a042..974cf6635 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WificondPnoScannerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WificondPnoScannerTest.java @@ -429,6 +429,7 @@ public class WificondPnoScannerTest { expectHwDisconnectedPnoScanStart(order, pnoSettings); // Setup scan results + when(mWifiNative.getPnoScanResults()).thenReturn(scanResults.getScanDetailArrayList()); when(mWifiNative.getScanResults()).thenReturn(scanResults.getScanDetailArrayList()); // Notify scan has finished @@ -451,6 +452,7 @@ public class WificondPnoScannerTest { order.verify(mWifiNative).scan(eq(expectedScanFreqs), any(Set.class)); + when(mWifiNative.getPnoScanResults()).thenReturn(scanResults.getScanDetailArrayList()); when(mWifiNative.getScanResults()).thenReturn(scanResults.getScanDetailArrayList()); // Notify scan has finished @@ -478,6 +480,7 @@ public class WificondPnoScannerTest { // Setup scan results when(mWifiNative.getScanResults()).thenReturn(scanResults.getScanDetailArrayList()); + when(mWifiNative.getPnoScanResults()).thenReturn(scanResults.getScanDetailArrayList()); // Notify scan has finished mWifiMonitor.sendMessage(mWifiNative.getInterfaceName(), WifiMonitor.SCAN_RESULTS_EVENT); |