summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-05-11 15:07:05 -0700
committerRoshan Pius <rpius@google.com>2020-05-13 09:51:05 -0700
commitfdec8fe5462205c8ecfd55c015d0f0773d2ae15a (patch)
treef3fc9aaf61a88d0bebfa3145a70e0d8790efe66d /tests
parent61c22b90db0d4be53a23ca85938ea014e388bb2d (diff)
WifiNetworkFactory: Trigger connection immediately if pre-approved
If a network is pre-approved for an app (either by the user or via CompanionDeviceManager), we currently issue a scan to ensure that the network is around if there is no fresh cached results. This causes us to bring up the UI (since we don't want to scan on behalf of the apps without UI attribution). Instead, if the network requested was already pre-approved, directly trigger a connection. This will ensure that the platform does not need to trigger a scan for finding the requested network. So, there is no need to bring up the UI for apps triggering connection to networks which have been pre-approved Bug: 155218555 Test: atest com.android.server.wifi Test: act.py -c wifi_manager_cross.config -tb dut-name -tc WifiNetworkRequestTest Change-Id: If1baf014bf8b5e8cbfa326660b9a401486d7bab6
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java139
1 files changed, 5 insertions, 134 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
index 17159b5e7..25aaeffd6 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
@@ -86,7 +86,6 @@ import org.xmlpull.v1.XmlSerializer;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -2095,50 +2094,6 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
}
/**
- * Verify the user approval bypass for a specific request for an access point that was already
- * approved previously with no cached scan results matching.
- */
- @Test
- public void testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedWithNoCache()
- throws Exception {
- // 1. First request (no user approval bypass)
- sendNetworkRequestAndSetupForConnectionStatus();
-
- mWifiNetworkFactory.removeCallback(TEST_CALLBACK_IDENTIFIER);
- reset(mNetworkRequestMatchCallback, mWifiScanner, mAlarmManager, mClientModeImpl);
-
- // 2. Second request for the same access point (user approval bypass).
- ScanResult matchingScanResult = mTestScanDatas[0].getResults()[0];
- PatternMatcher ssidPatternMatch =
- new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL);
- Pair<MacAddress, MacAddress> bssidPatternMatch =
- Pair.create(MacAddress.fromString(matchingScanResult.BSSID),
- MacAddress.BROADCAST_ADDRESS);
- attachWifiNetworkSpecifierAndAppInfo(
- ssidPatternMatch, bssidPatternMatch,
- WifiConfigurationTestUtil.createPskNetwork(), TEST_UID_1, TEST_PACKAGE_NAME_1);
- mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0);
-
- validateUiStartParams(true);
-
- mWifiNetworkFactory.addCallback(mAppBinder, mNetworkRequestMatchCallback,
- TEST_CALLBACK_IDENTIFIER);
- // Trigger scan results & ensure we triggered a connect.
- verify(mWifiScanner).startScan(any(), any(), mScanListenerArgumentCaptor.capture(), any());
- ScanListener scanListener = mScanListenerArgumentCaptor.getValue();
- assertNotNull(scanListener);
- scanListener.onResults(mTestScanDatas);
-
- // Verify we did not trigger the match callback.
- verify(mNetworkRequestMatchCallback, never()).onMatch(anyList());
- // Verify that we sent a connection attempt to ClientModeImpl
- verify(mClientModeImpl).connect(eq(null), anyInt(),
- any(Binder.class), mConnectListenerArgumentCaptor.capture(), anyInt(), anyInt());
-
- verify(mWifiMetrics).incrementNetworkRequestApiNumUserApprovalBypass();
- }
-
- /**
* Verify that we don't bypass user approval for a specific request for an access point that was
* approved previously, but then the user forgot it sometime after.
*/
@@ -2401,13 +2356,8 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0);
mWifiNetworkFactory.addCallback(mAppBinder, mNetworkRequestMatchCallback,
TEST_CALLBACK_IDENTIFIER);
- // Trigger scan results & ensure we triggered a connect.
- setupScanData(SCAN_RESULT_TYPE_WPA_PSK,
- TEST_SSID_1, TEST_SSID_2, TEST_SSID_3, TEST_SSID_4);
- verify(mWifiScanner).startScan(any(), any(), mScanListenerArgumentCaptor.capture(), any());
- ScanListener scanListener = mScanListenerArgumentCaptor.getValue();
- assertNotNull(scanListener);
- scanListener.onResults(mTestScanDatas);
+ // Ensure we triggered a connect without issuing any scans.
+ verify(mWifiScanner, never()).startScan(any(), any(), any(), any());
// Verify we did not trigger the match callback.
verify(mNetworkRequestMatchCallback, never()).onMatch(anyList());
@@ -2450,7 +2400,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
* approved previously and the scan result is present in the cached scan results.
*/
@Test
- public void testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedWithCache()
+ public void testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApproved()
throws Exception {
// 1. First request (no user approval bypass)
sendNetworkRequestAndSetupForConnectionStatus();
@@ -2460,11 +2410,6 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
// 2. Second request for the same access point (user approval bypass).
ScanResult matchingScanResult = mTestScanDatas[0].getResults()[0];
- // simulate no cache expiry
- when(mClock.getElapsedSinceBootMillis()).thenReturn(0L);
- // Simulate the cached results matching.
- when(mWifiScanner.getSingleScanResults())
- .thenReturn(Arrays.asList(mTestScanDatas[0].getResults()));
PatternMatcher ssidPatternMatch =
new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL);
@@ -2495,7 +2440,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
*/
@Test
public void
- testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedViaCDMWithCache()
+ testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedViaCDM()
throws Exception {
// Setup scan data for WPA-PSK networks.
setupScanData(SCAN_RESULT_TYPE_WPA_PSK,
@@ -2510,12 +2455,6 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
MacAddress.fromString(matchingScanResult.BSSID),
UserHandle.getUserHandleForUid(TEST_UID_1))).thenReturn(true);
- // simulate no cache expiry
- when(mClock.getElapsedSinceBootMillis()).thenReturn(0L);
- // Simulate the cached results matching.
- when(mWifiScanner.getSingleScanResults())
- .thenReturn(Arrays.asList(mTestScanDatas[0].getResults()));
-
PatternMatcher ssidPatternMatch =
new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL);
Pair<MacAddress, MacAddress> bssidPatternMatch =
@@ -2546,7 +2485,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
*/
@Test
public void
- testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedViaShellWithCache()
+ testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedViaShell()
throws Exception {
// Setup scan data for WPA-PSK networks.
setupScanData(SCAN_RESULT_TYPE_WPA_PSK,
@@ -2558,12 +2497,6 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
// Setup shell approval for the scan result.
mWifiNetworkFactory.setUserApprovedApp(TEST_PACKAGE_NAME_1, true);
- // simulate no cache expiry
- when(mClock.getElapsedSinceBootMillis()).thenReturn(0L);
- // Simulate the cached results matching.
- when(mWifiScanner.getSingleScanResults())
- .thenReturn(Arrays.asList(mTestScanDatas[0].getResults()));
-
PatternMatcher ssidPatternMatch =
new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL);
Pair<MacAddress, MacAddress> bssidPatternMatch =
@@ -2588,68 +2521,6 @@ public class WifiNetworkFactoryTest extends WifiBaseTest {
}
/**
- * Verify the user approval bypass for a specific request for an access point that was already
- * approved previously and the scan result is present in the cached scan results, but the
- * results are stale.
- */
- @Test
- public void
- testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedWithStaleCache()
- throws Exception {
- // 1. First request (no user approval bypass)
- sendNetworkRequestAndSetupForConnectionStatus();
-
- mWifiNetworkFactory.removeCallback(TEST_CALLBACK_IDENTIFIER);
- reset(mNetworkRequestMatchCallback, mWifiScanner, mAlarmManager, mClientModeImpl);
-
- long scanResultsTimestampInUs = 39484839202L;
- mTestScanDatas[0].getResults()[0].timestamp = scanResultsTimestampInUs;
- mTestScanDatas[0].getResults()[1].timestamp = scanResultsTimestampInUs;
- mTestScanDatas[0].getResults()[2].timestamp = scanResultsTimestampInUs;
- mTestScanDatas[0].getResults()[3].timestamp = scanResultsTimestampInUs;
-
- // 2. Second request for the same access point (user approval bypass).
- ScanResult matchingScanResult = mTestScanDatas[0].getResults()[0];
- // simulate cache expiry
- when(mClock.getElapsedSinceBootMillis())
- .thenReturn(Long.valueOf(
- scanResultsTimestampInUs / 1000
- + WifiNetworkFactory.CACHED_SCAN_RESULTS_MAX_AGE_IN_MILLIS + 1));
- // Simulate the cached results matching.
- when(mWifiScanner.getSingleScanResults())
- .thenReturn(Arrays.asList(mTestScanDatas[0].getResults()));
-
- PatternMatcher ssidPatternMatch =
- new PatternMatcher(TEST_SSID_1, PatternMatcher.PATTERN_LITERAL);
- Pair<MacAddress, MacAddress> bssidPatternMatch =
- Pair.create(MacAddress.fromString(matchingScanResult.BSSID),
- MacAddress.BROADCAST_ADDRESS);
- attachWifiNetworkSpecifierAndAppInfo(
- ssidPatternMatch, bssidPatternMatch,
- WifiConfigurationTestUtil.createPskNetwork(), TEST_UID_1, TEST_PACKAGE_NAME_1);
- mWifiNetworkFactory.needNetworkFor(mNetworkRequest, 0);
-
- // Ensure we brought up the UI while the scan is ongoing.
- validateUiStartParams(true);
-
- mWifiNetworkFactory.addCallback(mAppBinder, mNetworkRequestMatchCallback,
- TEST_CALLBACK_IDENTIFIER);
- // Trigger scan results & ensure we triggered a connect.
- verify(mWifiScanner).startScan(any(), any(), mScanListenerArgumentCaptor.capture(), any());
- ScanListener scanListener = mScanListenerArgumentCaptor.getValue();
- assertNotNull(scanListener);
- scanListener.onResults(mTestScanDatas);
-
- // Verify we did not trigger the match callback.
- verify(mNetworkRequestMatchCallback, never()).onMatch(anyList());
- // Verify that we sent a connection attempt to ClientModeImpl
- verify(mClientModeImpl).connect(eq(null), anyInt(),
- any(Binder.class), mConnectListenerArgumentCaptor.capture(), anyInt(), anyInt());
-
- 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.
*/