summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java38
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java5
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java39
3 files changed, 72 insertions, 10 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
index 985789858..38e2eaf86 100644
--- a/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ScanRequestProxyTest.java
@@ -66,6 +66,11 @@ public class ScanRequestProxyTest {
add(new WifiScanner.ScanSettings.HiddenNetwork("test_ssid_2"));
}};
+ private static final List<WifiScanner.ScanSettings.HiddenNetwork> TEST_HIDDEN_NETWORKS_LIST_NS =
+ new ArrayList<WifiScanner.ScanSettings.HiddenNetwork>() {{
+ add(new WifiScanner.ScanSettings.HiddenNetwork("test_ssid_3"));
+ add(new WifiScanner.ScanSettings.HiddenNetwork("test_ssid_4"));
+ }};
@Mock private Context mContext;
@Mock private AppOpsManager mAppOps;
@@ -77,6 +82,8 @@ public class ScanRequestProxyTest {
@Mock private WifiMetrics mWifiMetrics;
@Mock private Clock mClock;
@Mock private FrameworkFacade mFrameworkFacade;
+ @Mock private WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
+
private ArgumentCaptor<WorkSource> mWorkSourceArgumentCaptor =
ArgumentCaptor.forClass(WorkSource.class);
private ArgumentCaptor<WifiScanner.ScanSettings> mScanSettingsArgumentCaptor =
@@ -98,7 +105,11 @@ public class ScanRequestProxyTest {
MockitoAnnotations.initMocks(this);
when(mWifiInjector.getWifiScanner()).thenReturn(mWifiScanner);
+ when(mWifiInjector.getWifiNetworkSuggestionsManager())
+ .thenReturn(mWifiNetworkSuggestionsManager);
when(mWifiConfigManager.retrieveHiddenNetworkList()).thenReturn(TEST_HIDDEN_NETWORKS_LIST);
+ when(mWifiNetworkSuggestionsManager.retrieveHiddenNetworkList())
+ .thenReturn(TEST_HIDDEN_NETWORKS_LIST_NS);
doNothing().when(mWifiScanner).registerScanListener(
mGlobalScanListenerArgumentCaptor.capture());
doNothing().when(mWifiScanner).startScan(
@@ -106,7 +117,8 @@ public class ScanRequestProxyTest {
mScanRequestListenerArgumentCaptor.capture(),
mWorkSourceArgumentCaptor.capture());
- mInOrder = inOrder(mWifiScanner, mWifiConfigManager, mContext);
+ mInOrder = inOrder(mWifiScanner, mWifiConfigManager,
+ mContext, mWifiNetworkSuggestionsManager);
mTestScanDatas1 =
ScanTestUtil.createScanDatas(new int[][]{{ 2417, 2427, 5180, 5170 }},
new int[]{0},
@@ -205,8 +217,8 @@ public class ScanRequestProxyTest {
mInOrder.verify(mWifiScanner).registerScanListener(any());
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
- new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
+ assertEquals(mWorkSourceArgumentCaptor.getValue(),
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false, true);
}
@@ -222,10 +234,11 @@ public class ScanRequestProxyTest {
assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1));
mInOrder.verify(mWifiConfigManager, never()).retrieveHiddenNetworkList();
+ mInOrder.verify(mWifiNetworkSuggestionsManager, never()).retrieveHiddenNetworkList();
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
- new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
+ assertEquals(mWorkSourceArgumentCaptor.getValue(),
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), false);
verify(mWifiMetrics).incrementExternalAppOneshotScanRequestsCount();
@@ -242,11 +255,13 @@ public class ScanRequestProxyTest {
validateScanAvailableBroadcastSent(true);
assertTrue(mScanRequestProxy.startScan(TEST_UID, TEST_PACKAGE_NAME_1));
+
mInOrder.verify(mWifiConfigManager).retrieveHiddenNetworkList();
+ mInOrder.verify(mWifiNetworkSuggestionsManager).retrieveHiddenNetworkList();
mInOrder.verify(mWifiScanner).startScan(any(), any(), any());
- assertTrue(mWorkSourceArgumentCaptor.getValue().equals(
- new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1)));
+ assertEquals(mWorkSourceArgumentCaptor.getValue(),
+ new WorkSource(TEST_UID, TEST_PACKAGE_NAME_1));
validateScanSettings(mScanSettingsArgumentCaptor.getValue(), true);
verify(mWifiMetrics).incrementExternalAppOneshotScanRequestsCount();
@@ -860,12 +875,15 @@ public class ScanRequestProxyTest {
}
assertEquals(WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN
| WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT, scanSettings.reportEvents);
+ List<WifiScanner.ScanSettings.HiddenNetwork> hiddenNetworkList =
+ new ArrayList<>();
+ hiddenNetworkList.addAll(TEST_HIDDEN_NETWORKS_LIST);
+ hiddenNetworkList.addAll(TEST_HIDDEN_NETWORKS_LIST_NS);
if (expectHiddenNetworks) {
assertNotNull(scanSettings.hiddenNetworks);
- assertEquals(TEST_HIDDEN_NETWORKS_LIST.size(), scanSettings.hiddenNetworks.length);
+ assertEquals(hiddenNetworkList.size(), scanSettings.hiddenNetworks.length);
for (int i = 0; i < scanSettings.hiddenNetworks.length; i++) {
- validateHiddenNetworkInList(scanSettings.hiddenNetworks[i],
- TEST_HIDDEN_NETWORKS_LIST);
+ validateHiddenNetworkInList(scanSettings.hiddenNetworks[i], hiddenNetworkList);
}
} else {
assertNull(scanSettings.hiddenNetworks);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index 7f6c1bcaf..c1686b48d 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -96,6 +96,10 @@ public class WifiConnectivityManagerTest {
mWifiConnectivityHelper = mockWifiConnectivityHelper();
mWifiNS = mockWifiNetworkSelector();
when(mWifiInjector.getWifiScanner()).thenReturn(mWifiScanner);
+ when(mWifiInjector.getWifiNetworkSuggestionsManager())
+ .thenReturn(mWifiNetworkSuggestionsManager);
+ when(mWifiNetworkSuggestionsManager.retrieveHiddenNetworkList())
+ .thenReturn(new ArrayList<>());
mWifiConnectivityManager = createConnectivityManager();
verify(mWifiConfigManager).setOnSavedNetworkUpdateListener(anyObject());
mWifiConnectivityManager.setTrustedConnectionAllowed(true);
@@ -140,6 +144,7 @@ public class WifiConnectivityManagerTest {
@Mock private CarrierNetworkConfig mCarrierNetworkConfig;
@Mock private WifiMetrics mWifiMetrics;
@Mock private WifiNetworkScoreCache mScoreCache;
+ @Mock private WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
@Captor ArgumentCaptor<ScanResult> mCandidateScanResultCaptor;
@Captor ArgumentCaptor<ArrayList<String>> mBssidBlacklistCaptor;
@Captor ArgumentCaptor<ArrayList<String>> mSsidWhitelistCaptor;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 97a183370..d0d792541 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -48,6 +48,7 @@ import android.net.MacAddress;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkSuggestion;
+import android.net.wifi.WifiScanner;
import android.os.Handler;
import android.os.UserHandle;
import android.os.test.TestLooper;
@@ -2009,6 +2010,44 @@ public class WifiNetworkSuggestionsManagerTest {
}
/**
+ * Verify get hidden networks from All user approve network suggestions
+ */
+ @Test
+ public void testGetHiddenNetworks() {
+
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ WifiNetworkSuggestion hiddenNetworkSuggestion1 = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createPskHiddenNetwork(), true, false, TEST_UID_1,
+ TEST_PACKAGE_1);
+ WifiNetworkSuggestion hiddenNetworkSuggestion2 = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createPskHiddenNetwork(), true, false, TEST_UID_2,
+ TEST_PACKAGE_2);
+ List<WifiNetworkSuggestion> networkSuggestionList1 =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion);
+ add(hiddenNetworkSuggestion1);
+ }};
+ List<WifiNetworkSuggestion> networkSuggestionList2 =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(hiddenNetworkSuggestion2);
+ }};
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
+ TEST_PACKAGE_1));
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2,
+ TEST_PACKAGE_2));
+ mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1);
+ mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(false, TEST_PACKAGE_2);
+ List<WifiScanner.ScanSettings.HiddenNetwork> hiddenNetworks =
+ mWifiNetworkSuggestionsManager.retrieveHiddenNetworkList();
+ assertEquals(1, hiddenNetworks.size());
+ assertEquals(hiddenNetworkSuggestion1.wifiConfiguration.SSID, hiddenNetworks.get(0).ssid);
+ }
+
+ /**
* Creates a scan detail corresponding to the provided network values.
*/
private ScanDetail createScanDetailForNetwork(WifiConfiguration configuration) {