diff options
author | Roshan Pius <rpius@google.com> | 2019-11-18 08:22:16 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-11-18 11:38:02 -0800 |
commit | ce6319e03c423f4dd0e41a40027fe02d76b02599 (patch) | |
tree | 39b674d0a60c8193e172b9a0234196033f02f544 /tests | |
parent | 27c6ad5908d8c302a4ec8c4af2d90c9fdb2ba93c (diff) |
WifiNetworkFactory: Add CDM approval bypass for UI
Use the new CDM API to check if there is an approval for the request
network in CDM.
Bug: 144377829
Test: atest com.android.server.wifi.WifiNetworkFactoryTest
Change-Id: I23d9e3fdbef17a9505b05b56fd91c2eca01dd834
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index f312756dd..345672aec 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -32,6 +32,7 @@ import android.app.ActivityManager; import android.app.AlarmManager; import android.app.AlarmManager.OnAlarmListener; import android.app.AppOpsManager; +import android.companion.CompanionDeviceManager; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -124,6 +125,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { @Mock ActivityManager mActivityManager; @Mock AlarmManager mAlarmManager; @Mock AppOpsManager mAppOpsManager; + @Mock CompanionDeviceManager mCompanionDeviceManager; @Mock Clock mClock; @Mock WifiInjector mWifiInjector; @Mock WifiConnectivityManager mWifiConnectivityManager; @@ -194,9 +196,9 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { when(mWifiScanner.getSingleScanResults()).thenReturn(Collections.emptyList()); mWifiNetworkFactory = new WifiNetworkFactory(mLooper.getLooper(), mContext, - mNetworkCapabilities, mActivityManager, mAlarmManager, mAppOpsManager, mClock, - mWifiInjector, mWifiConnectivityManager, mWifiConfigManager, mWifiConfigStore, - mWifiPermissionsUtil, mWifiMetrics); + mNetworkCapabilities, mActivityManager, mAlarmManager, mAppOpsManager, + mCompanionDeviceManager, mClock, mWifiInjector, mWifiConnectivityManager, + mWifiConfigManager, mWifiConfigStore, mWifiPermissionsUtil, mWifiMetrics); ArgumentCaptor<NetworkRequestStoreData.DataSource> dataSourceArgumentCaptor = ArgumentCaptor.forClass(NetworkRequestStoreData.DataSource.class); @@ -2513,6 +2515,57 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { /** * Verify the user approval bypass for a specific request for an access point that was already + * approved previously via CDM and the scan result is present in the cached scan results. + */ + @Test + public void + testNetworkSpecifierMatchSuccessUsingLiteralSsidAndBssidMatchApprovedViaCDMWithCache() + 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 CDM approval for the scan result. + when(mCompanionDeviceManager.isDeviceAssociated( + TEST_PACKAGE_NAME_1, + 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 = + Pair.create(MacAddress.fromString(matchingScanResult.BSSID), + MacAddress.BROADCAST_ADDRESS); + WifiNetworkSpecifier specifier = new WifiNetworkSpecifier( + ssidPatternMatch, bssidPatternMatch, + WifiConfigurationTestUtil.createPskNetwork(), TEST_UID_1, TEST_PACKAGE_NAME_1); + mNetworkRequest.networkCapabilities.setNetworkSpecifier(specifier); + 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()); + // 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. */ |