Pass VPN uid range to AutomaticOnOffKeepaliveTracker

This is a preliminary change for filtering sockets that is not
in the uid ranges for automatic on/off keepalives. This commit
itself is a no-op change to pass the uid information to
AutomaticOnOffKeepaliveTracker.

Bug: 311119352
Test: atest FrameworksNetTests
Change-Id: I7d96e7a0d3f3054d1409de350420a24378b28cdb
This commit is contained in:
Chiachang Wang
2023-11-15 07:28:01 +00:00
parent 5532b8884c
commit 59bcabe3f4
3 changed files with 30 additions and 14 deletions

View File

@@ -72,7 +72,9 @@ import android.os.Message;
import android.os.SystemClock;
import android.telephony.SubscriptionManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.ArraySet;
import android.util.Log;
import android.util.Range;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -102,7 +104,9 @@ import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
@RunWith(DevSdkIgnoreRunner.class)
@SmallTest
@@ -232,6 +236,9 @@ public class AutomaticOnOffKeepaliveTrackerTest {
private static final byte[] TEST_RESPONSE_BYTES =
HexEncoding.decode(TEST_RESPONSE_HEX.toCharArray(), false);
private static final Set<Range<Integer>> TEST_UID_RANGES =
new ArraySet<>(Arrays.asList(new Range<>(10000, 99999)));
private static class TestKeepaliveInfo {
private static List<Socket> sOpenSockets = new ArrayList<>();
@@ -409,28 +416,28 @@ public class AutomaticOnOffKeepaliveTrackerTest {
public void testIsAnyTcpSocketConnected_runOnNonHandlerThread() throws Exception {
setupResponseWithSocketExisting();
assertThrows(IllegalStateException.class,
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID));
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID, TEST_UID_RANGES));
}
@Test
public void testIsAnyTcpSocketConnected_withTargetNetId() throws Exception {
setupResponseWithSocketExisting();
assertTrue(visibleOnHandlerThread(mTestHandler,
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID)));
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID, TEST_UID_RANGES)));
}
@Test
public void testIsAnyTcpSocketConnected_withIncorrectNetId() throws Exception {
setupResponseWithSocketExisting();
assertFalse(visibleOnHandlerThread(mTestHandler,
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(OTHER_NETID)));
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(OTHER_NETID, TEST_UID_RANGES)));
}
@Test
public void testIsAnyTcpSocketConnected_noSocketExists() throws Exception {
setupResponseWithoutSocketExisting();
assertFalse(visibleOnHandlerThread(mTestHandler,
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID)));
() -> mAOOKeepaliveTracker.isAnyTcpSocketConnected(TEST_NETID, TEST_UID_RANGES)));
}
private void triggerEventKeepalive(int slot, int reason) {
@@ -474,14 +481,16 @@ public class AutomaticOnOffKeepaliveTrackerTest {
setupResponseWithoutSocketExisting();
visibleOnHandlerThread(
mTestHandler,
() -> mAOOKeepaliveTracker.handleMonitorAutomaticKeepalive(autoKi, TEST_NETID));
() -> mAOOKeepaliveTracker.handleMonitorAutomaticKeepalive(
autoKi, TEST_NETID, TEST_UID_RANGES));
}
private void doResumeKeepalive(AutomaticOnOffKeepalive autoKi) throws Exception {
setupResponseWithSocketExisting();
visibleOnHandlerThread(
mTestHandler,
() -> mAOOKeepaliveTracker.handleMonitorAutomaticKeepalive(autoKi, TEST_NETID));
() -> mAOOKeepaliveTracker.handleMonitorAutomaticKeepalive(
autoKi, TEST_NETID, TEST_UID_RANGES));
}
private void doStopKeepalive(AutomaticOnOffKeepalive autoKi) throws Exception {