Use InetDiagMessage.destroyLiveTcpSocket instead of netd.socketDestroy
Netd is not updatable since it's not mainlined. To make socket destroy code updatable, the code was re-implemented in java and moved to Connectivity. Bug: 270298713 Test: atest FrameworksNetTests (cherry picked from https://android-review.googlesource.com/q/commit:93a2218e41384d106f1c14c239e1bf4795af43d5) Merged-In: I5439c0c76c42a9f738a1b25a1f62e701755cbd05 Change-Id: I5439c0c76c42a9f738a1b25a1f62e701755cbd05
This commit is contained in:
committed by
Cherrypicker Worker
parent
5572568b81
commit
a20f760cd6
@@ -1858,7 +1858,7 @@ public class ConnectivityServiceTest {
|
||||
final Context mockResContext = mock(Context.class);
|
||||
doReturn(mResources).when(mockResContext).getResources();
|
||||
ConnectivityResources.setResourcesContextForTest(mockResContext);
|
||||
mDeps = new ConnectivityServiceDependencies(mockResContext);
|
||||
mDeps = spy(new ConnectivityServiceDependencies(mockResContext));
|
||||
mAutoOnOffKeepaliveDependencies =
|
||||
new AutomaticOnOffKeepaliveTrackerDependencies(mServiceContext);
|
||||
mService = new ConnectivityService(mServiceContext,
|
||||
@@ -1921,7 +1921,8 @@ public class ConnectivityServiceTest {
|
||||
R.integer.config_networkWakeupPacketMark);
|
||||
}
|
||||
|
||||
class ConnectivityServiceDependencies extends ConnectivityService.Dependencies {
|
||||
// ConnectivityServiceDependencies is public to use Mockito.spy
|
||||
public class ConnectivityServiceDependencies extends ConnectivityService.Dependencies {
|
||||
final ConnectivityResources mConnRes;
|
||||
|
||||
ConnectivityServiceDependencies(final Context mockResContext) {
|
||||
@@ -2157,6 +2158,12 @@ public class ConnectivityServiceTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyLiveTcpSockets(final Set<Range<Integer>> ranges,
|
||||
final Set<Integer> exemptUids) {
|
||||
// This function is empty since the invocation of this method is verified by mocks
|
||||
}
|
||||
}
|
||||
|
||||
private class AutomaticOnOffKeepaliveTrackerDependencies
|
||||
@@ -12524,12 +12531,11 @@ public class ConnectivityServiceTest {
|
||||
|
||||
private void assertVpnUidRangesUpdated(boolean add, Set<UidRange> vpnRanges, int exemptUid)
|
||||
throws Exception {
|
||||
InOrder inOrder = inOrder(mMockNetd);
|
||||
ArgumentCaptor<int[]> exemptUidCaptor = ArgumentCaptor.forClass(int[].class);
|
||||
InOrder inOrder = inOrder(mMockNetd, mDeps);
|
||||
final Set<Integer> exemptUidSet = new ArraySet<>(List.of(exemptUid, Process.VPN_UID));
|
||||
|
||||
inOrder.verify(mMockNetd, times(1)).socketDestroy(eq(toUidRangeStableParcels(vpnRanges)),
|
||||
exemptUidCaptor.capture());
|
||||
assertContainsExactly(exemptUidCaptor.getValue(), Process.VPN_UID, exemptUid);
|
||||
inOrder.verify(mDeps).destroyLiveTcpSockets(UidRange.toIntRanges(vpnRanges),
|
||||
exemptUidSet);
|
||||
|
||||
if (add) {
|
||||
inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(
|
||||
@@ -12541,9 +12547,8 @@ public class ConnectivityServiceTest {
|
||||
toUidRangeStableParcels(vpnRanges), PREFERENCE_ORDER_VPN));
|
||||
}
|
||||
|
||||
inOrder.verify(mMockNetd, times(1)).socketDestroy(eq(toUidRangeStableParcels(vpnRanges)),
|
||||
exemptUidCaptor.capture());
|
||||
assertContainsExactly(exemptUidCaptor.getValue(), Process.VPN_UID, exemptUid);
|
||||
inOrder.verify(mDeps).destroyLiveTcpSockets(UidRange.toIntRanges(vpnRanges),
|
||||
exemptUidSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user