From 3ffb814525dfecc2264da77dcefd7ef28206ea3a Mon Sep 17 00:00:00 2001 From: Xiao Ma Date: Tue, 4 Jul 2023 12:38:24 +0900 Subject: [PATCH] Remove duplicated IfaddrMsg and RtgenMsg Struct used in NetlinkUtilsTests. Bug: 263222068 Test: atest NetworkStaticLibTests Change-Id: Iea5f91e0b20db7cd4cb4451b06e713dd68e9c387 --- .../module/util/netlink/NetlinkUtilsTest.java | 39 +++---------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java index 6fbfbf91ad..32ce5214bb 100644 --- a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java +++ b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/NetlinkUtilsTest.java @@ -183,7 +183,7 @@ public class NetlinkUtilsTest { assertEquals(localAddr.getPortId(), nlmsghdr.nlmsg_pid); addrMessageCount++; - final IfaddrMsg ifaMsg = Struct.parse(IfaddrMsg.class, response); + final StructIfaddrMsg ifaMsg = Struct.parse(StructIfaddrMsg.class, response); assertTrue( "Non-IP address family: " + ifaMsg.family, ifaMsg.family == AF_INET || ifaMsg.family == AF_INET6); @@ -196,7 +196,7 @@ public class NetlinkUtilsTest { /** A convenience method to create an RTM_GETADDR request message. */ private static byte[] newGetAddrRequest(int seqNo) { - final int length = StructNlMsgHdr.STRUCT_SIZE + Struct.getSize(RtgenMsg.class); + final int length = StructNlMsgHdr.STRUCT_SIZE + Struct.getSize(StructIfaddrMsg.class); final byte[] bytes = new byte[length]; final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); byteBuffer.order(ByteOrder.nativeOrder()); @@ -208,38 +208,11 @@ public class NetlinkUtilsTest { nlmsghdr.nlmsg_seq = seqNo; nlmsghdr.pack(byteBuffer); - final RtgenMsg rtgenMsg = new RtgenMsg(); - rtgenMsg.family = (byte) AF_UNSPEC; - rtgenMsg.writeToByteBuffer(byteBuffer); + final StructIfaddrMsg addrMsg = new StructIfaddrMsg((byte) AF_UNSPEC /* family */, + (short) 0 /* prefixLen */, (short) 0 /* flags */, (short) 0 /* scope */, + 0 /* index */); + addrMsg.pack(byteBuffer); return bytes; } - - /** From uapi/linux/rtnetlink.h */ - private static class RtgenMsg extends Struct { - @Field(order = 0, type = Type.U8) - public short family; - } - - /** - * From uapi/linux/ifaddr.h - * - * Public ensures visibility to Struct class - */ - public static class IfaddrMsg extends Struct { - @Field(order = 0, type = Type.U8) - public short family; - - @Field(order = 1, type = Type.U8) - public short prefixlen; - - @Field(order = 2, type = Type.U8) - public short flags; - - @Field(order = 3, type = Type.U8) - public short scope; - - @Field(order = 4, type = Type.S32) - public int index; - } }