summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVarun Anand <vaanand@google.com>2020-04-03 14:15:04 -0700
committerVarun Anand <vaanand@google.com>2020-04-06 11:51:39 -0700
commit6f39981ba5abf52c8c71ba3d9f5abef2fc6498fa (patch)
treeb13cae8252fde86f519342c42f85d31ba7a4ad49 /tests
parentbb96a3d98cd5411a7d2d81acf409711e1984aa22 (diff)
Exempt active scorer from user approval for its suggestions.
Note, I'm adding a method to PerAppInfo that encapsulates all the exemptions (currently based on carrier privileges and active scorer). This is to keep the surface area of changes to a minimum (in future) whenever exemptions need to be modified. Fixes: 152335546 Test: atest com.android.server.wifi Test: manually verified that active scorer is exempted. Change-Id: Iffe5edfd1824d0c1fbbb93430714a9f372be3643
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 e9bb940be..5bc4d3366 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;
@@ -128,6 +132,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;
@@ -206,6 +211,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))
@@ -2587,6 +2593,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.
@@ -2621,6 +2671,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.
@@ -2917,6 +2987,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
*/
@@ -3622,6 +3716,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.
*/