summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2020-04-07 06:43:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-04-07 06:43:34 +0000
commitac8bc7c04daba9d5af676a13440e67f362d25a75 (patch)
treeb8d539d877065154515946ad307fd0b443d87eda /tests
parent8c6bbc8d45655e705bdc15182afef9830703e0e0 (diff)
parent6f39981ba5abf52c8c71ba3d9f5abef2fc6498fa (diff)
Merge "Exempt active scorer from user approval for its suggestions." into rvc-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 613508451..f51207898 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -16,8 +16,11 @@
package com.android.server.wifi;
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND_SERVICE;
+import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_SERVICE;
import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.MODE_IGNORED;
import static android.app.AppOpsManager.OPSTR_CHANGE_WIFI_STATE;
@@ -50,6 +53,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.net.NetworkScoreManager;
import android.net.util.MacAddressUtils;
import android.net.wifi.EAPConstants;
import android.net.wifi.ISuggestionConnectionStatusListener;
@@ -129,6 +133,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
private @Mock Resources mResources;
private @Mock AppOpsManager mAppOpsManager;
private @Mock NotificationManager mNotificationManger;
+ private @Mock NetworkScoreManager mNetworkScoreManager;
private @Mock PackageManager mPackageManager;
private @Mock WifiPermissionsUtil mWifiPermissionsUtil;
private @Mock WifiInjector mWifiInjector;
@@ -207,6 +212,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
.thenReturn(mNotificationManger);
+ when(mContext.getSystemService(NetworkScoreManager.class)).thenReturn(mNetworkScoreManager);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(ActivityManager.class)).thenReturn(mActivityManager);
when(mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
@@ -2651,6 +2657,50 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
validateUserApprovalNotification(TEST_APP_NAME_1);
}
+ @Test
+ public void testAddNetworkSuggestions_activeFgScorer_doesNotRequestForApproval() {
+ // Fg app
+ when(mActivityManager.getPackageImportance(any())).thenReturn(IMPORTANCE_FOREGROUND);
+ // Active scorer
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_PACKAGE_1);
+
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, true);
+ List<WifiNetworkSuggestion> networkSuggestionList =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion);
+ }};
+
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+
+ verifyZeroInteractions(mAlertDialog);
+ verifyZeroInteractions(mNotificationManger);
+ }
+
+ @Test
+ public void testAddNetworkSuggestions_activeBgScorer_doesNotRequestForApproval() {
+ // Bg app
+ when(mActivityManager.getPackageImportance(any())).thenReturn(IMPORTANCE_SERVICE);
+ // Active scorer
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_PACKAGE_1);
+
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, true);
+ List<WifiNetworkSuggestion> networkSuggestionList =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion);
+ }};
+
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+
+ verifyZeroInteractions(mAlertDialog);
+ verifyZeroInteractions(mNotificationManger);
+ }
+
/**
* Verify handling of user clicking allow on the user approval notification when first time
* add suggestions.
@@ -2685,6 +2735,26 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
verifyNoMoreInteractions(mNotificationManger);
}
+ @Test
+ public void getNetworkSuggestionsForScanDetail_exemptsActiveScorerFromUserApproval() {
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_PACKAGE_1);
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, true);
+ List<WifiNetworkSuggestion> networkSuggestionList =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion);
+ }};
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+
+ mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(
+ createScanDetailForNetwork(networkSuggestion.wifiConfiguration));
+
+ verifyZeroInteractions(mNotificationManger);
+ verifyZeroInteractions(mAlertDialog);
+ }
+
/**
* Verify handling of user clicking Disallow on the user approval notification when first time
* add suggestions.
@@ -2981,6 +3051,30 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertNull(ewns);
}
+ @Test
+ public void getNetworkSuggestionsForFqdn_activeScorer_doesNotRequestForUserApproval() {
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_PACKAGE_1);
+ PasspointConfiguration passpointConfiguration =
+ createTestConfigWithUserCredential(TEST_FQDN, TEST_FRIENDLY_NAME);
+ WifiConfiguration dummyConfiguration = createDummyWifiConfigurationForPasspoint(TEST_FQDN);
+ dummyConfiguration.FQDN = TEST_FQDN;
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(dummyConfiguration,
+ passpointConfiguration, true, false, true, true);
+ List<WifiNetworkSuggestion> networkSuggestionList = Arrays.asList(networkSuggestion);
+ dummyConfiguration.creatorUid = TEST_UID_1;
+ when(mPasspointManager.addOrUpdateProvider(any(PasspointConfiguration.class),
+ anyInt(), anyString(), eq(true), eq(true))).thenReturn(true);
+ assertEquals(mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE), WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
+
+ Set<ExtendedWifiNetworkSuggestion> ewns =
+ mWifiNetworkSuggestionsManager.getNetworkSuggestionsForFqdn(TEST_FQDN);
+
+ assertEquals(1, ewns.size());
+ verifyZeroInteractions(mAlertDialog);
+ verifyZeroInteractions(mNotificationManger);
+ }
+
/**
* Verify return true when allow user manually connect and user approved the app
*/
@@ -3675,6 +3769,24 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
assertEquals(network1.SSID, pnoNetwork.get(0).SSID);
}
+ @Test
+ public void getAllScanOptimizationSuggestionNetworks_returnsActiveScorerWithoutUserApproval() {
+ when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_PACKAGE_1);
+ WifiConfiguration network = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiNetworkSuggestion networkSuggestion =
+ new WifiNetworkSuggestion(network, null, false, false, true, true);
+ List<WifiNetworkSuggestion> networkSuggestionList = Arrays.asList(networkSuggestion);
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager
+ .add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE));
+ mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(false, TEST_PACKAGE_1);
+
+ List<WifiConfiguration> networks =
+ mWifiNetworkSuggestionsManager.getAllScanOptimizationSuggestionNetworks();
+
+ assertEquals(1, networks.size());
+ }
+
/**
* Verify if a suggestion is mostRecently connected, flag will be persist.
*/