summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-11-21 04:56:18 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-11-21 04:56:18 +0000
commitefa1e869b9e52ee7e372dc7ae4fbbc67870295c5 (patch)
tree3d2ac96eb0e851296607b912e60e317d3396be4e /tests
parentdda5fd8b34cc817823f4cd6a597c2a14cd0aebe6 (diff)
parentce6319e03c423f4dd0e41a40027fe02d76b02599 (diff)
Merge "WifiNetworkFactory: Add CDM approval bypass for UI"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java59
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 f7cd39c43..b2f74f68f 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);
@@ -2470,6 +2472,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.
*/