Merge "Adjust polling interval for auto on/off keepalives"
This commit is contained in:
@@ -28,8 +28,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.longThat;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -57,6 +57,7 @@ import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.SystemClock;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -94,6 +95,7 @@ public class AutomaticOnOffKeepaliveTrackerTest {
|
||||
private static final int NETID_MASK = 0xffff;
|
||||
private static final int TIMEOUT_MS = 30_000;
|
||||
private static final int MOCK_RESOURCE_ID = 5;
|
||||
private static final int TEST_KEEPALIVE_INTERVAL_SEC = 10;
|
||||
private AutomaticOnOffKeepaliveTracker mAOOKeepaliveTracker;
|
||||
private HandlerThread mHandlerThread;
|
||||
|
||||
@@ -334,9 +336,13 @@ public class AutomaticOnOffKeepaliveTrackerTest {
|
||||
final KeepalivePacketData kpd = new NattKeepalivePacketData(srcAddress, srcPort,
|
||||
dstAddress, dstPort, new byte[] {1});
|
||||
final KeepaliveInfo ki = mKeepaliveTracker.new KeepaliveInfo(cb, nai, kpd,
|
||||
10 /* interval */, KeepaliveInfo.TYPE_NATT, fd);
|
||||
TEST_KEEPALIVE_INTERVAL_SEC, KeepaliveInfo.TYPE_NATT, fd);
|
||||
mKeepaliveTracker.setReturnedKeepaliveInfo(ki);
|
||||
|
||||
// Mock elapsed real time to verify the alarm timer.
|
||||
final long time = SystemClock.elapsedRealtime();
|
||||
doReturn(time).when(mDependencies).getElapsedRealtime();
|
||||
|
||||
mAOOKeepaliveTracker.startNattKeepalive(nai, fd, 10 /* intervalSeconds */, cb,
|
||||
srcAddress.toString(), srcPort, dstAddress.toString(), dstPort,
|
||||
true /* automaticOnOffKeepalives */, underpinnedNetwork);
|
||||
@@ -344,8 +350,11 @@ public class AutomaticOnOffKeepaliveTrackerTest {
|
||||
|
||||
final ArgumentCaptor<AlarmManager.OnAlarmListener> listenerCaptor =
|
||||
ArgumentCaptor.forClass(AlarmManager.OnAlarmListener.class);
|
||||
verify(mAlarmManager).setExact(eq(AlarmManager.ELAPSED_REALTIME), anyLong(),
|
||||
any(), listenerCaptor.capture(), eq(mTestHandler));
|
||||
// The alarm timer should be smaller than the keepalive delay. Verify the alarm trigger time
|
||||
// is higher than base time but smaller than the keepalive delay.
|
||||
verify(mAlarmManager).setExact(eq(AlarmManager.ELAPSED_REALTIME),
|
||||
longThat(t -> t > time + 1000L && t < time + TEST_KEEPALIVE_INTERVAL_SEC * 1000L),
|
||||
any() /* tag */, listenerCaptor.capture(), eq(mTestHandler));
|
||||
final AlarmManager.OnAlarmListener listener = listenerCaptor.getValue();
|
||||
|
||||
// For realism, the listener should be posted on the handler
|
||||
|
||||
Reference in New Issue
Block a user