Merge "Address comments at aosp/2361702" am: ea5e220c90

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2445824

Change-Id: Id412efafc82d28c188f1e743915b4198cd70b002
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-02-23 12:04:01 +00:00
committed by Automerger Merge Worker
2 changed files with 88 additions and 27 deletions

View File

@@ -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);
}
}

View File

@@ -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);
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);
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 */);
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);
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 */);
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();
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();
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();
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 */);
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);
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();
if (SdkLevel.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(
new NativeUidRangeConfig[]{cellExcludeAppConfig});
} else {
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
}
mCellAgent.disconnect();
waitForIdle();
if (SdkLevel.isAtLeastU()) {
inOrder.verify(mMockNetd).setNetworkAllowlist(new NativeUidRangeConfig[]{});
} else {
inOrder.verify(mMockNetd, never()).setNetworkAllowlist(any());
}
}
/**