diff options
author | Roshan Pius <rpius@google.com> | 2020-03-30 22:25:40 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-03-31 14:30:28 -0700 |
commit | 7832f03e1a66dc144d8f33ed48a3405034d75762 (patch) | |
tree | 23daa4772708d12b5a2c078fd01ef995b3a66f83 /tests | |
parent | bd16d74680d652c9f48fd3dafb9149e6cedda9af (diff) |
WifiShellCommand: Add cmds for approving NetworkRequest from app
This is useful for bypassing the UI for local testing. Needs rooted
shell.
Also, added a utility method for parsing boolean params.
Bug: 152299953
Test: Manual Steps to connect to a network via network request
adb root
adb shell cmd wifi network-requests-set-user-approved android yes
abd shell cmd wifi add-request <ssid> open
abd shell cmd wifi remove-request <ssid> open
abd shell cmd wifi add-request <ssid> wpa2 <passphrase>
abd shell cmd wifi remove-request <ssid> wpa2
Change-Id: Ib59fd1869d8827cc79d99058dca4dc9c8774b954
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index afa9ffd53..684fd1449 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -2510,6 +2510,54 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { /** * Verify the user approval bypass for a specific request for an access point that was already + * approved previously via shell command and the scan result is present in the cached scan + * results. + */ + @Test + public void + testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedViaShellWithCache() + throws Exception { + // Setup scan data for WPA-PSK networks. + setupScanData(SCAN_RESULT_TYPE_WPA_PSK, + TEST_SSID_1, TEST_SSID_2, TEST_SSID_3, TEST_SSID_4); + + // Choose the matching scan result. + ScanResult matchingScanResult = mTestScanDatas[0].getResults()[0]; + + // 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 = + 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); + + // Verify we did not trigger the UI for the second request. + verify(mContext, never()).startActivityAsUser(any(), any()); + // Verify we did not trigger a scan. + verify(mWifiScanner, never()).startScan(any(), any(), any(), any()); + // 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 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. */ |