Remove per-user preference when the user is removed

Test: new test for this
Change-Id: I335e82e29ec8f4c8da9def8b40153858cfd5bacb
This commit is contained in:
Chalard Jean
2021-03-09 21:09:20 +09:00
parent cc9ad15cd2
commit 6bb468c476
2 changed files with 31 additions and 1 deletions

View File

@@ -5124,6 +5124,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
private void onUserRemoved(UserHandle user) {
mPermissionMonitor.onUserRemoved(user);
// If there was a network preference for this user, remove it.
handleSetProfileNetworkPreference(new ProfileNetworkPreferences.Preference(user, null),
null /* listener */);
if (mOemNetworkPreferences.getNetworkPreferences().size() > 0) {
handleSetOemNetworkPreference(mOemNetworkPreferences, null);
}
@@ -9237,7 +9240,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
// touched on the handler thread, it's theoretically not impossible that it has changed
// since.
if (!mOemNetworkPreferences.isEmpty()) {
logwtf("handleSetProfileNetworkPreference, but OEM network preferences not empty");
// This may happen on a device with an OEM preference set when a user is removed.
// In this case, it's safe to ignore. In particular this happens in the tests.
loge("handleSetProfileNetworkPreference, but OEM network preferences not empty");
return;
}

View File

@@ -11488,6 +11488,31 @@ public class ConnectivityServiceTest {
// Other callbacks will be unregistered by tearDown()
}
@Test
public void testProfilePreferenceRemovedUponUserRemoved() throws Exception {
final InOrder inOrder = inOrder(mMockNetd);
final UserHandle testHandle = setupEnterpriseNetwork();
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
mCellNetworkAgent.connect(true);
final TestOnCompleteListener listener = new TestOnCompleteListener();
mCm.setProfileNetworkPreference(testHandle, PROFILE_NETWORK_PREFERENCE_ENTERPRISE,
r -> r.run(), listener);
listener.expectOnComplete();
inOrder.verify(mMockNetd).networkCreatePhysical(mCellNetworkAgent.getNetwork().netId,
INetd.PERMISSION_NONE);
inOrder.verify(mMockNetd).networkAddUidRanges(mCellNetworkAgent.getNetwork().netId,
uidRangeFor(testHandle));
final Intent removedIntent = new Intent(ACTION_USER_REMOVED);
removedIntent.putExtra(Intent.EXTRA_USER, testHandle);
processBroadcast(removedIntent);
inOrder.verify(mMockNetd).networkRemoveUidRanges(mCellNetworkAgent.getNetwork().netId,
uidRangeFor(testHandle));
}
/**
* Make sure that OEM preference and per-profile preference can't be used at the same
* time and throw ISE if tried