Move fromStableParcelable to KeepaliveController

TcpKeepaliveController is the only user of
KeepalivePacketDataUtil.fromStableParcelable. Because of
fromStableParcelable, networkstack-client needs to depend on
net-utils-framework-commonm, which pulls a lot of unnecessary classes.
This is particularly problematic considering that networkstack-client
may need to be redistributed as a prebuilt.

Move the method to TcpKeepaliveController, simplifying dependencies.
This also shows that fromStableParcelable could be removed altogether
(or moved to tests) if TcpKeepaliveController built a
TcpKeepalivePacketData class directly.

Test: atest ConnectivityCoverageTests
Change-Id: I554318f6bcd07c73d153598a0231e9fcaf912e90
This commit is contained in:
Remi NGUYEN VAN
2021-11-01 12:01:59 +09:00
parent 65571769cd
commit 5d99aa78f7
2 changed files with 88 additions and 8 deletions

View File

@@ -27,6 +27,7 @@ import android.net.util.KeepalivePacketDataUtil;
import android.os.Build;
import android.util.Log;
import com.android.server.connectivity.TcpKeepaliveController;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRunner;
@@ -81,7 +82,7 @@ public final class KeepalivePacketDataUtilTest {
testInfo.tos = tos;
testInfo.ttl = ttl;
try {
resultData = KeepalivePacketDataUtil.fromStableParcelable(testInfo);
resultData = TcpKeepaliveController.fromStableParcelable(testInfo);
} catch (InvalidPacketException e) {
fail("InvalidPacketException: " + e);
}
@@ -155,7 +156,7 @@ public final class KeepalivePacketDataUtilTest {
testInfo.ttl = ttl;
TcpKeepalivePacketData testData = null;
TcpKeepalivePacketDataParcelable resultData = null;
testData = KeepalivePacketDataUtil.fromStableParcelable(testInfo);
testData = TcpKeepaliveController.fromStableParcelable(testInfo);
resultData = KeepalivePacketDataUtil.toStableParcelable(testData);
assertArrayEquals(resultData.srcAddress, IPV4_KEEPALIVE_SRC_ADDR);
assertArrayEquals(resultData.dstAddress, IPV4_KEEPALIVE_DST_ADDR);
@@ -198,11 +199,11 @@ public final class KeepalivePacketDataUtilTest {
testParcel.ttl = ttl;
final KeepalivePacketData testData =
KeepalivePacketDataUtil.fromStableParcelable(testParcel);
TcpKeepaliveController.fromStableParcelable(testParcel);
final TcpKeepalivePacketDataParcelable parsedParcelable =
KeepalivePacketDataUtil.parseTcpKeepalivePacketData(testData);
final TcpKeepalivePacketData roundTripData =
KeepalivePacketDataUtil.fromStableParcelable(parsedParcelable);
TcpKeepaliveController.fromStableParcelable(parsedParcelable);
// Generated packet is the same, but rcvWnd / wndScale will differ if scale is non-zero
assertTrue(testData.getPacket().length > 0);
@@ -210,11 +211,11 @@ public final class KeepalivePacketDataUtilTest {
testParcel.rcvWndScale = 0;
final KeepalivePacketData noScaleTestData =
KeepalivePacketDataUtil.fromStableParcelable(testParcel);
TcpKeepaliveController.fromStableParcelable(testParcel);
final TcpKeepalivePacketDataParcelable noScaleParsedParcelable =
KeepalivePacketDataUtil.parseTcpKeepalivePacketData(noScaleTestData);
final TcpKeepalivePacketData noScaleRoundTripData =
KeepalivePacketDataUtil.fromStableParcelable(noScaleParsedParcelable);
TcpKeepaliveController.fromStableParcelable(noScaleParsedParcelable);
assertEquals(noScaleTestData, noScaleRoundTripData);
assertTrue(noScaleTestData.getPacket().length > 0);
assertArrayEquals(noScaleTestData.getPacket(), noScaleRoundTripData.getPacket());