summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNate Jiang <qiangjiang@google.com>2021-01-06 20:00:50 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-01-06 20:00:50 +0000
commitb8635032d43878f174ebdee58c685bbf1eb2cd3f (patch)
treed0c1bbaf491be5218dfbb784cf426be3e7bf9f76 /tests
parent1969c2ac7014f61b86daea4557581201e143cbe5 (diff)
parent1ffc81e5470b3e98f86ac04a7e4f9daec89768b3 (diff)
[Suggestion] Check foreground user for API call am: 1ffc81e547
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/net/wifi/+/13287824 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ib84cdfd305f0dfde0cf1ae63a6397a31af5a8577
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java71
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java10
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java53
4 files changed, 127 insertions, 24 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index d2584adbc..9d96116eb 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -222,6 +222,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
.thenReturn(false);
when(mWifiInjector.getMacAddressUtil()).thenReturn(mMacAddressUtil);
when(mWifiInjector.getWifiMetrics()).thenReturn(mWifiMetrics);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(anyInt())).thenReturn(true);
when(mMacAddressUtil.calculatePersistentMac(any(), any())).thenReturn(TEST_RANDOMIZED_MAC);
when(mWifiScoreCard.lookupNetwork(any())).thenReturn(mPerNetwork);
@@ -2912,6 +2913,8 @@ public class WifiConfigManagerTest extends WifiBaseTest {
setupStoreDataForUserRead(user2Networks, new HashMap<>());
// Now switch the user to user 2 and ensure that user 1's private network has been removed.
when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user1Network.creatorUid))
+ .thenReturn(false);
Set<Integer> removedNetworks = mWifiConfigManager.handleUserSwitch(user2);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
assertTrue((removedNetworks.size() == 1) && (removedNetworks.contains(user1NetworkId)));
@@ -2991,7 +2994,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
public void testHandleUserSwitchPushesOtherPrivateNetworksToSharedStore() throws Exception {
int user1 = TEST_DEFAULT_USER;
int user2 = TEST_DEFAULT_USER + 1;
- setupUserProfiles(user2);
+ setupUserProfiles(user1);
int appId = 674;
@@ -3029,6 +3032,8 @@ public class WifiConfigManagerTest extends WifiBaseTest {
}
};
setupStoreDataForUserRead(userNetworks, new HashMap<>());
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user2Network.creatorUid))
+ .thenReturn(false);
mWifiConfigManager.handleUserUnlock(user1);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
// Capture the written data for the user 1 and ensure that it corresponds to what was
@@ -3043,6 +3048,10 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// Now switch the user to user2 and ensure that user 2's private network has been moved to
// the user store.
when(mUserManager.isUserUnlockingOrUnlocked(UserHandle.of(user2))).thenReturn(true);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user1Network.creatorUid))
+ .thenReturn(true).thenReturn(false);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user2Network.creatorUid))
+ .thenReturn(false).thenReturn(true);
mWifiConfigManager.handleUserSwitch(user2);
// Set the expected network list before comparing. user1Network should be in shared data.
// Note: In the real world, user1Network will no longer be visible now because it should
@@ -3107,6 +3116,8 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// Unlock the owner of the legacy Passpoint configuration, verify it is removed from
// the configured networks (migrated to PasspointManager).
setupStoreDataForUserRead(new ArrayList<WifiConfiguration>(), new HashMap<>());
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(passpointConfig.creatorUid))
+ .thenReturn(false);
mWifiConfigManager.handleUserUnlock(user1);
verify(mWifiConfigStore).switchUserStoresAndRead(any(List.class));
Pair<List<WifiConfiguration>, List<WifiConfiguration>> writtenNetworkList =
@@ -3234,7 +3245,8 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// Ensure that we have 2 networks in the database before the stop.
assertEquals(2, mWifiConfigManager.getConfiguredNetworks().size());
-
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(user1Network.creatorUid))
+ .thenReturn(false);
mWifiConfigManager.handleUserStop(user1);
// Ensure that we only have 1 shared network in the database after the stop.
@@ -3436,6 +3448,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
int creatorUid = UserHandle.getUid(user2, 674);
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(creatorUid)).thenReturn(false);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(creatorUid)).thenReturn(false);
// Create a network for user2 try adding it. This should be rejected.
final WifiConfiguration user2Network = WifiConfigurationTestUtil.createPskNetwork();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 38a0026df..fd27dcc06 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -66,6 +66,7 @@ import android.net.wifi.hotspot2.pps.HomeSp;
import android.os.Handler;
import android.os.IBinder;
import android.os.UserHandle;
+import android.os.UserManager;
import android.os.test.TestLooper;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
@@ -150,6 +151,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
private @Mock Notification.Builder mNotificationBuilder;
private @Mock Notification mNotification;
private @Mock LruConnectionTracker mLruConnectionTracker;
+ private @Mock UserManager mUserManager;
private TestLooper mLooper;
private ArgumentCaptor<AppOpsManager.OnOpChangedListener> mAppOpChangedListenerCaptor =
ArgumentCaptor.forClass(AppOpsManager.OnOpChangedListener.class);
@@ -216,6 +218,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
when(mActivityManager.isLowRamDevice()).thenReturn(false);
when(mActivityManager.getPackageImportance(any())).thenReturn(
IMPORTANCE_FOREGROUND_SERVICE);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(anyInt())).thenReturn(true);
// setup resource strings for notification.
when(mResources.getString(eq(R.string.wifi_suggestion_title), anyString()))
@@ -560,7 +563,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
TEST_PACKAGE_1, TEST_FEATURE));
assertEquals(WifiConfiguration.METERED_OVERRIDE_METERED,
mWifiNetworkSuggestionsManager
- .get(TEST_PACKAGE_1).get(0).wifiConfiguration.meteredOverride);
+ .get(TEST_PACKAGE_1, TEST_UID_1).get(0).wifiConfiguration.meteredOverride);
// Verify we did not update config in WCM.
verify(mWifiConfigManager, never()).addOrUpdateNetwork(any(), anyInt(), any());
}
@@ -607,7 +610,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
TEST_PACKAGE_1, TEST_FEATURE));
assertEquals(WifiConfiguration.METERED_OVERRIDE_METERED,
mWifiNetworkSuggestionsManager
- .get(TEST_PACKAGE_1).get(0).wifiConfiguration.meteredOverride);
+ .get(TEST_PACKAGE_1, TEST_UID_1).get(0).wifiConfiguration.meteredOverride);
verify(mWifiMetrics, never()).incrementNetworkSuggestionApiUsageNumOfAppInType(anyInt());
// Verify we did update config in WCM.
ArgumentCaptor<WifiConfiguration> configCaptor =
@@ -1066,7 +1069,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
public void testOnNetworkConnectionSuccessWithOneMatch() throws Exception {
assertTrue(mWifiNetworkSuggestionsManager
.registerSuggestionConnectionStatusListener(mBinder, mListener,
- NETWORK_CALLBACK_ID, TEST_PACKAGE_1));
+ NETWORK_CALLBACK_ID, TEST_PACKAGE_1, TEST_UID_1));
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, true);
List<WifiNetworkSuggestion> networkSuggestionList =
@@ -1103,7 +1106,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
public void testOnNetworkConnectionSuccessWithOneMatchFromCarrierPrivilegedApp() {
assertTrue(mWifiNetworkSuggestionsManager
.registerSuggestionConnectionStatusListener(mBinder, mListener,
- NETWORK_CALLBACK_ID, TEST_PACKAGE_1));
+ NETWORK_CALLBACK_ID, TEST_PACKAGE_1, TEST_UID_1));
when(mWifiCarrierInfoManager.getCarrierIdForPackageWithCarrierPrivileges(TEST_PACKAGE_1))
.thenReturn(TEST_CARRIER_ID);
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
@@ -1138,6 +1141,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
mWifiNetworkSuggestionsManager.remove(networkSuggestionList, TEST_UID_1,
TEST_PACKAGE_1));
verify(mWifiConfigManager).removeSuggestionConfiguredNetwork(anyString());
+ mInorder.verify(mWifiPermissionsUtil).doesUidBelongToCurrentUser(eq(TEST_UID_1));
// Verify no more broadcast were sent out.
mInorder.verifyNoMoreInteractions();
@@ -1152,7 +1156,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
public void testOnSavedOpenNetworkConnectionSuccessWithMultipleMatch() throws Exception {
assertTrue(mWifiNetworkSuggestionsManager
.registerSuggestionConnectionStatusListener(mBinder, mListener,
- NETWORK_CALLBACK_ID, TEST_PACKAGE_1));
+ NETWORK_CALLBACK_ID, TEST_PACKAGE_1, TEST_UID_1));
when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1))
.thenReturn(true);
WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
@@ -1199,7 +1203,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
ArgumentCaptor.forClass(IBinder.DeathRecipient.class);
assertTrue(mWifiNetworkSuggestionsManager
.registerSuggestionConnectionStatusListener(mBinder, mListener,
- NETWORK_CALLBACK_ID, TEST_PACKAGE_1));
+ NETWORK_CALLBACK_ID, TEST_PACKAGE_1, TEST_UID_1));
verify(mBinder).linkToDeath(drCaptor.capture(), anyInt());
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, true);
@@ -1249,7 +1253,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
public void testOnNetworkConnectionFailureWithOneMatch() throws Exception {
assertTrue(mWifiNetworkSuggestionsManager
.registerSuggestionConnectionStatusListener(mBinder, mListener,
- NETWORK_CALLBACK_ID, TEST_PACKAGE_1));
+ NETWORK_CALLBACK_ID, TEST_PACKAGE_1, TEST_UID_1));
WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, true);
List<WifiNetworkSuggestion> networkSuggestionList =
@@ -2467,7 +2471,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
public void testGetNetworkSuggestions() {
// test App never suggested.
List<WifiNetworkSuggestion> storedNetworkSuggestionListPerApp =
- mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1);
+ mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1);
assertEquals(storedNetworkSuggestionListPerApp.size(), 0);
// App add network suggestions then get stored suggestions.
@@ -2489,7 +2493,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
TEST_PACKAGE_1, TEST_FEATURE));
mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1);
storedNetworkSuggestionListPerApp =
- mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1);
+ mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1);
assertEquals(new HashSet<>(networkSuggestionList),
new HashSet<>(storedNetworkSuggestionListPerApp));
@@ -2498,7 +2502,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_UID_1,
TEST_PACKAGE_1));
storedNetworkSuggestionListPerApp =
- mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1);
+ mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1);
assertEquals(storedNetworkSuggestionListPerApp.size(), 0);
}
@@ -3222,7 +3226,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE);
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_NOT_ALLOWED, status);
verify(mNotificationManger, never()).notify(anyInt(), any());
- assertEquals(0, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1).size());
+ assertEquals(0, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1).size());
verify(mWifiMetrics, never()).incrementNetworkSuggestionApiUsageNumOfAppInType(anyInt());
}
@@ -3246,7 +3250,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE);
assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, status);
verify(mNotificationManger, never()).notify(anyInt(), any());
- assertEquals(1, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1).size());
+ assertEquals(1, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1).size());
verify(mWifiMetrics).incrementNetworkSuggestionApiUsageNumOfAppInType(
WifiNetworkSuggestionsManager.APP_TYPE_CARRIER_PRIVILEGED);
}
@@ -3271,7 +3275,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE);
assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS);
verify(mNotificationManger, never()).notify(anyInt(), any());
- assertEquals(1, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1).size());
+ assertEquals(1, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1).size());
}
/**
@@ -3333,7 +3337,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
when(mWifiCarrierInfoManager.getCarrierIdForPackageWithCarrierPrivileges(TEST_PACKAGE_1))
.thenReturn(TelephonyManager.UNKNOWN_CARRIER_ID);
mWifiNetworkSuggestionsManager.resetCarrierPrivilegedApps();
- assertEquals(0, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1).size());
+ assertEquals(0, mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1).size());
verify(mWifiConfigManager, times(2)).saveToStore(true);
status = mWifiNetworkSuggestionsManager
.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE);
@@ -4033,7 +4037,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
public void testUnregisterSuggestionConnectionStatusListenerNeverRegistered() {
int listenerIdentifier = 1234;
mWifiNetworkSuggestionsManager.unregisterSuggestionConnectionStatusListener(
- listenerIdentifier, TEST_PACKAGE_1);
+ listenerIdentifier, TEST_PACKAGE_1, TEST_UID_1);
}
/**
@@ -4084,6 +4088,43 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
}
/**
+ * Verify when calling API from background user will fail.
+ */
+ @Test
+ public void testCallingFromBackgroundUserWillFailed() {
+ WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion(
+ wifiConfiguration, null, false, false, true, true);
+
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(Arrays.asList(networkSuggestion), TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+ // When switch the user to background
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(TEST_UID_1)).thenReturn(false);
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL,
+ mWifiNetworkSuggestionsManager.add(Arrays.asList(networkSuggestion), TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_INTERNAL,
+ mWifiNetworkSuggestionsManager.remove(Arrays.asList(networkSuggestion), TEST_UID_1,
+ TEST_PACKAGE_1));
+ assertTrue(mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1).isEmpty());
+ assertFalse(mWifiNetworkSuggestionsManager.registerSuggestionConnectionStatusListener(
+ mBinder, mListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_1, TEST_UID_1));
+
+ // When switch the user back to foreground
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(TEST_UID_1)).thenReturn(true);
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(Arrays.asList(networkSuggestion), TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+ assertFalse(mWifiNetworkSuggestionsManager.get(TEST_PACKAGE_1, TEST_UID_1).isEmpty());
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.remove(Arrays.asList(networkSuggestion), TEST_UID_1,
+ TEST_PACKAGE_1));
+ assertTrue(mWifiNetworkSuggestionsManager.registerSuggestionConnectionStatusListener(
+ mBinder, mListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_1, TEST_UID_1));
+ }
+
+ /**
* Helper function for creating a test configuration with user credential.
*
* @return {@link PasspointConfiguration}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index 6d1ae2927..55f35e380 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -4587,12 +4587,12 @@ public class WifiServiceImplTest extends WifiBaseTest {
@Test
public void testGetNetworkSuggestions() {
List<WifiNetworkSuggestion> testList = new ArrayList<>();
- when(mWifiNetworkSuggestionsManager.get(anyString())).thenReturn(testList);
+ when(mWifiNetworkSuggestionsManager.get(anyString(), anyInt())).thenReturn(testList);
mLooper.startAutoDispatch();
assertEquals(testList, mWifiServiceImpl.getNetworkSuggestions(TEST_PACKAGE_NAME));
mLooper.stopAutoDispatchAndIgnoreExceptions();
- verify(mWifiNetworkSuggestionsManager).get(eq(TEST_PACKAGE_NAME));
+ verify(mWifiNetworkSuggestionsManager).get(eq(TEST_PACKAGE_NAME), anyInt());
}
/**
@@ -4607,7 +4607,7 @@ public class WifiServiceImplTest extends WifiBaseTest {
assertTrue(mWifiServiceImpl.getNetworkSuggestions(TEST_PACKAGE_NAME).isEmpty());
mLooper.stopAutoDispatchAndIgnoreExceptions();
- verify(mWifiNetworkSuggestionsManager, never()).get(eq(TEST_PACKAGE_NAME));
+ verify(mWifiNetworkSuggestionsManager, never()).get(eq(TEST_PACKAGE_NAME), anyInt());
}
/**
@@ -5389,12 +5389,12 @@ public class WifiServiceImplTest extends WifiBaseTest {
mLooper.dispatchAll();
verify(mWifiNetworkSuggestionsManager).registerSuggestionConnectionStatusListener(
eq(mAppBinder), eq(mSuggestionConnectionStatusListener), eq(NETWORK_CALLBACK_ID),
- eq(TEST_PACKAGE_NAME));
+ eq(TEST_PACKAGE_NAME), anyInt());
mWifiServiceImpl.unregisterSuggestionConnectionStatusListener(NETWORK_CALLBACK_ID,
TEST_PACKAGE_NAME);
mLooper.dispatchAll();
verify(mWifiNetworkSuggestionsManager).unregisterSuggestionConnectionStatusListener(
- eq(NETWORK_CALLBACK_ID), eq(TEST_PACKAGE_NAME));
+ eq(NETWORK_CALLBACK_ID), eq(TEST_PACKAGE_NAME), anyInt());
}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
index dbc38d493..ad207bfe2 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java
@@ -99,6 +99,7 @@ import com.android.server.wifi.hotspot2.anqp.OsuProviderInfo;
import com.android.server.wifi.proto.nano.WifiMetricsProto.UserActionEvent;
import com.android.server.wifi.util.InformationElementUtil;
import com.android.server.wifi.util.InformationElementUtil.RoamingConsortium;
+import com.android.server.wifi.util.WifiPermissionsUtil;
import org.junit.Before;
import org.junit.Test;
@@ -188,6 +189,7 @@ public class PasspointManagerTest extends WifiBaseTest {
@Mock TelephonyManager mTelephonyManager;
@Mock SubscriptionManager mSubscriptionManager;
@Mock WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager;
+ @Mock WifiPermissionsUtil mWifiPermissionsUtil;
Handler mHandler;
TestLooper mLooper;
@@ -216,6 +218,7 @@ public class PasspointManagerTest extends WifiBaseTest {
when(mWifiInjector.getClientModeImpl()).thenReturn(mClientModeImpl);
when(mWifiInjector.getWifiNetworkSuggestionsManager())
.thenReturn(mWifiNetworkSuggestionsManager);
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(anyInt())).thenReturn(true);
mWifiCarrierInfoManager = new WifiCarrierInfoManager(mTelephonyManager,
mSubscriptionManager, mWifiInjector, mock(FrameworkFacade.class),
mock(WifiContext.class), mWifiConfigStore, mock(Handler.class), mWifiMetrics);
@@ -223,7 +226,7 @@ public class PasspointManagerTest extends WifiBaseTest {
mHandler = new Handler(mLooper.getLooper());
mManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative,
mWifiKeyStore, mClock, mObjectFactory, mWifiConfigManager,
- mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager);
+ mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager, mWifiPermissionsUtil);
ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks =
ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class);
verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class),
@@ -520,6 +523,29 @@ public class PasspointManagerTest extends WifiBaseTest {
}
/**
+ * Verify that adding a provider from a background user will fail.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void addProviderWithBackgroundUser() throws Exception {
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(anyInt())).thenReturn(false);
+
+ PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN,
+ TEST_FRIENDLY_NAME);
+ PasspointProvider provider = createMockProvider(config);
+ when(provider.getPackageName()).thenReturn(TEST_PACKAGE);
+ when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
+ eq(mWifiCarrierInfoManager), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(false))).thenReturn(provider);
+ assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID,
+ TEST_PACKAGE, false, true));
+
+ verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
+ verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess();
+ }
+
+ /**
* Verify that adding a user saved provider with a valid configuration and user credential will
* succeed.
*
@@ -749,7 +775,7 @@ public class PasspointManagerTest extends WifiBaseTest {
.thenReturn(true);
PasspointManager ut = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative,
mWifiKeyStore, mClock, spyFactory, mWifiConfigManager,
- mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager);
+ mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager, mWifiPermissionsUtil);
assertTrue(ut.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE,
true, true));
@@ -1895,6 +1921,29 @@ public class PasspointManagerTest extends WifiBaseTest {
}
/**
+ * Verify that removing a provider from a background user will fail.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void removeProviderWithBackgroundUser() throws Exception {
+ PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN,
+ TEST_FRIENDLY_NAME);
+ PasspointProvider provider = createMockProvider(config);
+ when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore),
+ eq(mWifiCarrierInfoManager), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE),
+ eq(false))).thenReturn(provider);
+ assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE,
+ false, true));
+ verifyInstalledConfig(config);
+ verify(mWifiMetrics).incrementNumPasspointProviderInstallation();
+ verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess();
+
+ when(mWifiPermissionsUtil.doesUidBelongToCurrentUser(anyInt())).thenReturn(false);
+ assertFalse(mManager.removeProvider(TEST_CREATOR_UID, false, null, TEST_FQDN));
+ }
+
+ /**
* Verify that adding a suggestion provider with a valid configuration and user credential will
* succeed.
*