summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkFactory.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java61
2 files changed, 57 insertions, 13 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java
index be6ac6473..4b5866b44 100644
--- a/service/java/com/android/server/wifi/WifiNetworkFactory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java
@@ -428,7 +428,12 @@ public class WifiNetworkFactory extends NetworkFactory {
new NetworkFactoryUserSelectionCallback(mActiveSpecificNetworkRequest));
} catch (RemoteException e) {
Log.e(TAG, "Unable to invoke user selection registration callback " + callback, e);
+ return;
}
+
+ // If we are already in the midst of processing a request, send matching callbacks
+ // immediately on registering the callback.
+ sendNetworkRequestMatchCallbacksForActiveRequest(mActiveMatchedScanResults);
}
/**
@@ -981,6 +986,7 @@ public class WifiNetworkFactory extends NetworkFactory {
mConnectedSpecificNetworkRequestSpecifier = mActiveSpecificNetworkRequestSpecifier;
mActiveSpecificNetworkRequest = null;
mActiveSpecificNetworkRequestSpecifier = null;
+ mActiveMatchedScanResults = null;
mPendingConnectionSuccess = false;
// Cancel connection timeout alarm.
cancelConnectionTimeout();
@@ -1127,7 +1133,8 @@ public class WifiNetworkFactory extends NetworkFactory {
}
private void sendNetworkRequestMatchCallbacksForActiveRequest(
- List<ScanResult> matchedScanResults) {
+ @Nullable List<ScanResult> matchedScanResults) {
+ if (matchedScanResults == null || matchedScanResults.isEmpty()) return;
if (mRegisteredCallbacks.getNumCallbacks() == 0) {
Log.e(TAG, "No callback registered for sending network request matches. "
+ "Ignoring...");
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
index 36b820290..222c4953a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
@@ -954,13 +954,8 @@ public class WifiNetworkFactoryTest {
verifyPeriodicScans(0, PERIODIC_SCAN_INTERVAL_MS);
- ArgumentCaptor<List<ScanResult>> matchedScanResultsCaptor =
- ArgumentCaptor.forClass(List.class);
- verify(mNetworkRequestMatchCallback).onMatch(matchedScanResultsCaptor.capture());
-
- assertNotNull(matchedScanResultsCaptor.getValue());
// We expect no network match in this case.
- assertEquals(0, matchedScanResultsCaptor.getValue().size());
+ verify(mNetworkRequestMatchCallback, never()).onMatch(any());
// Don't increment metrics until we have a match
verify(mWifiMetrics, never()).incrementNetworkRequestApiMatchSizeHistogram(anyInt());
@@ -999,13 +994,8 @@ public class WifiNetworkFactoryTest {
verifyPeriodicScans(0, PERIODIC_SCAN_INTERVAL_MS);
- ArgumentCaptor<List<ScanResult>> matchedScanResultsCaptor =
- ArgumentCaptor.forClass(List.class);
- verify(mNetworkRequestMatchCallback).onMatch(matchedScanResultsCaptor.capture());
-
- assertNotNull(matchedScanResultsCaptor.getValue());
// We expect no network match in this case.
- assertEquals(0, matchedScanResultsCaptor.getValue().size());
+ verify(mNetworkRequestMatchCallback, never()).onMatch(any());
}
/**
@@ -2552,6 +2542,53 @@ public class WifiNetworkFactoryTest {
verify(mWifiMetrics).incrementNetworkRequestApiNumUserApprovalBypass();
}
+ /**
+ * Verify network specifier matching for a specifier containing a specific SSID match using
+ * 4 WPA_PSK scan results, each with unique SSID when the UI callback registration is delayed.
+ */
+ @Test
+ public void testNetworkSpecifierMatchSuccessUsingLiteralSsidMatchCallbackRegistrationDelayed()
+ throws Exception {
+ // Setup scan data for open networks.
+ setupScanData(SCAN_RESULT_TYPE_WPA_PSK,
+ TEST_SSID_1, TEST_SSID_2, TEST_SSID_3, TEST_SSID_4);
+
+ // Setup network specifier for open networks.
+ PatternMatcher ssidPatternMatch =
+ new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL);
+ Pair<MacAddress, MacAddress> bssidPatternMatch =
+ Pair.create(MacAddress.ALL_ZEROS_ADDRESS, MacAddress.ALL_ZEROS_ADDRESS);
+ WifiConfiguration wifiConfiguration = new WifiConfiguration();
+ wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
+ WifiNetworkSpecifier specifier = new WifiNetworkSpecifier(
+ ssidPatternMatch, bssidPatternMatch, wifiConfiguration, TEST_UID_1,
+ TEST_PACKAGE_NAME_1);
+
+ mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier);
+ mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0);
+
+ validateUiStartParams(true);
+
+ verifyPeriodicScans(0, PERIODIC_SCAN_INTERVAL_MS);
+
+ // Ensure we did not send any match callbacks, until the callback is registered
+ verify(mNetworkRequestMatchCallback, never()).onMatch(any());
+
+ // Register the callback & ensure we triggered the on match callback.
+ mWifiNetworkFactory.addCallback(mAppBinder, mNetworkRequestMatchCallback,
+ TEST_CALLBACK_IDENTIFIER);
+ ArgumentCaptor<List<ScanResult>> matchedScanResultsCaptor =
+ ArgumentCaptor.forClass(List.class);
+ verify(mNetworkRequestMatchCallback).onMatch(matchedScanResultsCaptor.capture());
+
+ assertNotNull(matchedScanResultsCaptor.getValue());
+ // We only expect 1 network match in this case.
+ validateScanResults(matchedScanResultsCaptor.getValue(), mTestScanDatas[0].getResults()[0]);
+
+ verify(mWifiMetrics).incrementNetworkRequestApiMatchSizeHistogram(
+ matchedScanResultsCaptor.getValue().size());
+ }
+
private Messenger sendNetworkRequestAndSetupForConnectionStatus() throws RemoteException {
return sendNetworkRequestAndSetupForConnectionStatus(TEST_SSID_1);
}