Merge "Address comments at aosp/2361702"
This commit is contained in:
@@ -8854,6 +8854,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
}
|
||||
|
||||
private void updateProfileAllowedNetworks() {
|
||||
// Netd command is not implemented before U.
|
||||
if (!SdkLevel.isAtLeastU()) return;
|
||||
|
||||
ensureRunningOnConnectivityServiceThread();
|
||||
final ArrayList<NativeUidRangeConfig> configs = new ArrayList<>();
|
||||
final List<UserHandle> users = mContext.getSystemService(UserManager.class)
|
||||
@@ -8884,8 +8887,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||
mNetd.setNetworkAllowlist(configs.toArray(new NativeUidRangeConfig[0]));
|
||||
} catch (ServiceSpecificException e) {
|
||||
// Has the interface disappeared since the network was built?
|
||||
Log.wtf(TAG, "Unexpected ServiceSpecificException", e);
|
||||
} catch (RemoteException e) {
|
||||
// Netd died. This usually causes a runtime restart anyway.
|
||||
// Netd died. This will cause a runtime restart anyway.
|
||||
Log.wtf(TAG, "Unexpected RemoteException", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10478,7 +10478,11 @@ public class ConnectivityServiceTest {
|
||||
verify(mMockNetd, times(1)).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(),
|
||||
eq(Integer.toString(TRANSPORT_CELLULAR)));
|
||||
verify(mMockNetd).networkDestroy(cellNetId);
|
||||
verify(mMockNetd).setNetworkAllowlist(any());
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
verify(mMockNetd).setNetworkAllowlist(any());
|
||||
} else {
|
||||
verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
verifyNoMoreInteractions(mMockNetd);
|
||||
verifyNoMoreInteractions(mClatCoordinator);
|
||||
reset(mMockNetd);
|
||||
@@ -10519,7 +10523,11 @@ public class ConnectivityServiceTest {
|
||||
verify(mMockNetd).idletimerRemoveInterface(eq(MOBILE_IFNAME), anyInt(),
|
||||
eq(Integer.toString(TRANSPORT_CELLULAR)));
|
||||
verify(mMockNetd).networkDestroy(cellNetId);
|
||||
verify(mMockNetd).setNetworkAllowlist(any());
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
verify(mMockNetd).setNetworkAllowlist(any());
|
||||
} else {
|
||||
verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
verifyNoMoreInteractions(mMockNetd);
|
||||
verifyNoMoreInteractions(mClatCoordinator);
|
||||
|
||||
@@ -15830,7 +15838,11 @@ public class ConnectivityServiceTest {
|
||||
mCellAgent.getNetwork().netId,
|
||||
toUidRangeStableParcels(allowedRanges),
|
||||
0 /* subPriority */);
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[] { config1User });
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config1User});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
doReturn(asList(PRIMARY_USER_HANDLE, SECONDARY_USER_HANDLE))
|
||||
.when(mUserManager).getUserHandles(anyBoolean());
|
||||
@@ -15844,7 +15856,11 @@ public class ConnectivityServiceTest {
|
||||
mCellAgent.getNetwork().netId,
|
||||
toUidRangeStableParcels(allowedRanges),
|
||||
0 /* subPriority */);
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[] { config2Users });
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{config2Users});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -15871,8 +15887,12 @@ public class ConnectivityServiceTest {
|
||||
mCellAgent.getNetwork().netId,
|
||||
allowAllUidRangesParcel,
|
||||
0 /* subPriority */);
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellAllAllowedConfig});
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellAllAllowedConfig});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
// Verify the same uid ranges are also applied for enterprise network.
|
||||
final TestNetworkAgentWrapper enterpriseAgent = makeEnterpriseNetworkAgent(
|
||||
@@ -15886,9 +15906,13 @@ public class ConnectivityServiceTest {
|
||||
// making the order of the list undeterministic. Thus, verify this in order insensitive way.
|
||||
final ArgumentCaptor<NativeUidRangeConfig[]> configsCaptor = ArgumentCaptor.forClass(
|
||||
NativeUidRangeConfig[].class);
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig));
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig));
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
// Setup profile preference which only applies to test app uid on the managed profile.
|
||||
ProfileNetworkPreference.Builder prefBuilder = new ProfileNetworkPreference.Builder();
|
||||
@@ -15916,24 +15940,36 @@ public class ConnectivityServiceTest {
|
||||
mCellAgent.getNetwork().netId,
|
||||
excludeAppRangesParcel,
|
||||
0 /* subPriority */);
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(cellExcludeAppConfig, enterpriseAllAllowedConfig));
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(cellExcludeAppConfig, enterpriseAllAllowedConfig));
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
// Verify unset by giving all allowed set for all users when the preference got removed.
|
||||
mCm.setProfileNetworkPreference(testHandle, PROFILE_NETWORK_PREFERENCE_ENTERPRISE,
|
||||
r -> r.run(), listener);
|
||||
listener.expectOnComplete();
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig));
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(cellAllAllowedConfig, enterpriseAllAllowedConfig));
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
// Verify issuing with cellular set only when a network with enterprise capability
|
||||
// disconnects.
|
||||
enterpriseAgent.disconnect();
|
||||
waitForIdle();
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellAllAllowedConfig});
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellAllAllowedConfig});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -15953,7 +15989,11 @@ public class ConnectivityServiceTest {
|
||||
List.of(prefBuilder.build()),
|
||||
r -> r.run(), listener);
|
||||
listener.expectOnComplete();
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{});
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
// Start with 1 default network, which should be restricted since the blocking
|
||||
// preference is already set.
|
||||
@@ -15977,8 +16017,12 @@ public class ConnectivityServiceTest {
|
||||
mCellAgent.getNetwork().netId,
|
||||
excludeAppRangesParcel,
|
||||
0 /* subPriority */);
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellExcludeAppConfig});
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellExcludeAppConfig});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
// Verify enterprise network is not blocked for test app.
|
||||
final TestNetworkAgentWrapper enterpriseAgent = makeEnterpriseNetworkAgent(
|
||||
@@ -15997,19 +16041,31 @@ public class ConnectivityServiceTest {
|
||||
// making the order of the list undeterministic. Thus, verify this in order insensitive way.
|
||||
final ArgumentCaptor<NativeUidRangeConfig[]> configsCaptor = ArgumentCaptor.forClass(
|
||||
NativeUidRangeConfig[].class);
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(enterpriseAllAllowedConfig, cellExcludeAppConfig));
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(configsCaptor.capture());
|
||||
assertContainsAll(List.of(configsCaptor.getValue()),
|
||||
List.of(enterpriseAllAllowedConfig, cellExcludeAppConfig));
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
// Verify issuing with cellular set only when enterprise network disconnects.
|
||||
enterpriseAgent.disconnect();
|
||||
waitForIdle();
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellExcludeAppConfig});
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(
|
||||
new NativeUidRangeConfig[]{cellExcludeAppConfig});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
|
||||
mCellAgent.disconnect();
|
||||
waitForIdle();
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{});
|
||||
if (SdkLevel.isAtLeastU()) {
|
||||
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{});
|
||||
} else {
|
||||
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user