[XFRM_MSG_GETSA] Fix the class names and code locations

- Change class names to start with Xfrm or StructXfrm for consistency
  with other messages and structs
- Create xfrm sub-folder for xfrm messages
- Add "finals" to input parameters

Bug: 308011229
Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.netlink
      (new tests added)
Change-Id: Id6d34b4549bbc1890b3f4dd9f1638977f66e3236
diff --git a/staticlibs/Android.bp b/staticlibs/Android.bp
index 6325b46..9f1debc 100644
--- a/staticlibs/Android.bp
+++ b/staticlibs/Android.bp
@@ -191,7 +191,7 @@
 java_library {
     name: "net-utils-device-common-netlink",
     srcs: [
-        "device/com/android/net/module/util/netlink/*.java",
+        "device/com/android/net/module/util/netlink/**/*.java",
     ],
     sdk_version: "module_current",
     min_sdk_version: "30",
diff --git a/staticlibs/device/com/android/net/module/util/netlink/IpSecStructXfrmAddressT.java b/staticlibs/device/com/android/net/module/util/netlink/xfrm/StructXfrmAddressT.java
similarity index 86%
rename from staticlibs/device/com/android/net/module/util/netlink/IpSecStructXfrmAddressT.java
rename to staticlibs/device/com/android/net/module/util/netlink/xfrm/StructXfrmAddressT.java
index 4c19887..cef1f56 100644
--- a/staticlibs/device/com/android/net/module/util/netlink/IpSecStructXfrmAddressT.java
+++ b/staticlibs/device/com/android/net/module/util/netlink/xfrm/StructXfrmAddressT.java
@@ -13,7 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.android.net.module.util.netlink;
+package com.android.net.module.util.netlink.xfrm;
+
+import static com.android.net.module.util.NetworkStackConstants.IPV4_ADDR_LEN;
 
 import android.system.OsConstants;
 
@@ -41,21 +43,19 @@
  *
  * @hide
  */
-public class IpSecStructXfrmAddressT extends Struct {
-    private static final int IPV4_ADDRESS_LEN = 4;
-
+public class StructXfrmAddressT extends Struct {
     public static final int STRUCT_SIZE = 16;
 
     @Field(order = 0, type = Type.ByteArray, arraysize = STRUCT_SIZE)
     public final byte[] address;
 
     // Constructor that allows Strutc.parse(Class<T>, ByteBuffer) to work
-    public IpSecStructXfrmAddressT(@NonNull byte[] address) {
+    public StructXfrmAddressT(@NonNull final byte[] address) {
         this.address = address.clone();
     }
 
     // Constructor to build a new message
-    public IpSecStructXfrmAddressT(@NonNull InetAddress inetAddress) {
+    public StructXfrmAddressT(@NonNull final InetAddress inetAddress) {
         this.address = new byte[STRUCT_SIZE];
         final byte[] addressBytes = inetAddress.getAddress();
         System.arraycopy(addressBytes, 0, address, 0, addressBytes.length);
@@ -67,7 +67,7 @@
         if (family == OsConstants.AF_INET6) {
             addressBytes = this.address;
         } else if (family == OsConstants.AF_INET) {
-            addressBytes = new byte[IPV4_ADDRESS_LEN];
+            addressBytes = new byte[IPV4_ADDR_LEN];
             System.arraycopy(this.address, 0, addressBytes, 0, addressBytes.length);
         } else {
             throw new IllegalArgumentException("Invalid IP family " + family);
diff --git a/staticlibs/device/com/android/net/module/util/netlink/IpSecStructXfrmUsersaId.java b/staticlibs/device/com/android/net/module/util/netlink/xfrm/StructXfrmUsersaId.java
similarity index 76%
rename from staticlibs/device/com/android/net/module/util/netlink/IpSecStructXfrmUsersaId.java
rename to staticlibs/device/com/android/net/module/util/netlink/xfrm/StructXfrmUsersaId.java
index 6f7b656..5ebc69c 100644
--- a/staticlibs/device/com/android/net/module/util/netlink/IpSecStructXfrmUsersaId.java
+++ b/staticlibs/device/com/android/net/module/util/netlink/xfrm/StructXfrmUsersaId.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.net.module.util.netlink;
+package com.android.net.module.util.netlink.xfrm;
 
 import androidx.annotation.NonNull;
 
@@ -40,7 +40,7 @@
  *
  * @hide
  */
-public class IpSecStructXfrmUsersaId extends Struct {
+public class StructXfrmUsersaId extends Struct {
     public static final int STRUCT_SIZE = 24;
 
     @Field(order = 0, type = Type.ByteArray, arraysize = 16)
@@ -55,23 +55,23 @@
     @Field(order = 3, type = Type.U8, padding = 1)
     public final short proto;
 
-    @Computed private final IpSecStructXfrmAddressT mDestXfrmAddressT;
+    @Computed private final StructXfrmAddressT mDestXfrmAddressT;
 
     // Constructor that allows Strutc.parse(Class<T>, ByteBuffer) to work
-    public IpSecStructXfrmUsersaId(
-            @NonNull byte[] nestedStructDAddr, long spi, int family, short proto) {
+    public StructXfrmUsersaId(
+            @NonNull final byte[] nestedStructDAddr, long spi, int family, short proto) {
         this.nestedStructDAddr = nestedStructDAddr.clone();
         this.spi = spi;
         this.family = family;
         this.proto = proto;
 
-        mDestXfrmAddressT = new IpSecStructXfrmAddressT(this.nestedStructDAddr);
+        mDestXfrmAddressT = new StructXfrmAddressT(this.nestedStructDAddr);
     }
 
     // Constructor to build a new message
-    public IpSecStructXfrmUsersaId(
-            @NonNull InetAddress destAddress, long spi, int family, short proto) {
-        this(new IpSecStructXfrmAddressT(destAddress).writeToBytes(), spi, family, proto);
+    public StructXfrmUsersaId(
+            @NonNull final InetAddress destAddress, long spi, int family, short proto) {
+        this(new StructXfrmAddressT(destAddress).writeToBytes(), spi, family, proto);
     }
 
     /** Return the destination address */
diff --git a/staticlibs/device/com/android/net/module/util/netlink/IpSecXfrmNetlinkMessage.java b/staticlibs/device/com/android/net/module/util/netlink/xfrm/XfrmNetlinkMessage.java
similarity index 81%
rename from staticlibs/device/com/android/net/module/util/netlink/IpSecXfrmNetlinkMessage.java
rename to staticlibs/device/com/android/net/module/util/netlink/xfrm/XfrmNetlinkMessage.java
index 8ad784b..ee34e57 100644
--- a/staticlibs/device/com/android/net/module/util/netlink/IpSecXfrmNetlinkMessage.java
+++ b/staticlibs/device/com/android/net/module/util/netlink/xfrm/XfrmNetlinkMessage.java
@@ -14,21 +14,24 @@
  * limitations under the License.
  */
 
-package com.android.net.module.util.netlink;
+package com.android.net.module.util.netlink.xfrm;
 
 import androidx.annotation.NonNull;
 
+import com.android.net.module.util.netlink.NetlinkMessage;
+import com.android.net.module.util.netlink.StructNlMsgHdr;
+
 /** Base calss for XFRM netlink messages */
 // Developer notes: The Linux kernel includes a number of XFRM structs that are not standard netlink
 // attributes (e.g., xfrm_usersa_id). These structs are unlikely to change size, so this XFRM
 // netlink message implementation assumes their sizes will remain stable. If any non-attribute
 // struct size changes, it should be caught by CTS and then developers should add
 // kernel-version-based behvaiours.
-public abstract class IpSecXfrmNetlinkMessage extends NetlinkMessage {
+public abstract class XfrmNetlinkMessage extends NetlinkMessage {
     // TODO: STOPSHIP: b/308011229 Remove it when OsConstants.IPPROTO_ESP is exposed
     public static final int IPPROTO_ESP = 50;
 
-    public IpSecXfrmNetlinkMessage(@NonNull StructNlMsgHdr header) {
+    public XfrmNetlinkMessage(@NonNull final StructNlMsgHdr header) {
         super(header);
     }
 
diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/IpSecStructXfrmUsersaIdTest.java b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/xfrm/StructXfrmUsersaIdTest.java
similarity index 84%
rename from staticlibs/tests/unit/src/com/android/net/module/util/netlink/IpSecStructXfrmUsersaIdTest.java
rename to staticlibs/tests/unit/src/com/android/net/module/util/netlink/xfrm/StructXfrmUsersaIdTest.java
index 4266f68..52fd591 100644
--- a/staticlibs/tests/unit/src/com/android/net/module/util/netlink/IpSecStructXfrmUsersaIdTest.java
+++ b/staticlibs/tests/unit/src/com/android/net/module/util/netlink/xfrm/StructXfrmUsersaIdTest.java
@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-package com.android.net.module.util.netlink;
+package com.android.net.module.util.netlink.xfrm;
 
-import static com.android.net.module.util.netlink.IpSecXfrmNetlinkMessage.IPPROTO_ESP;
+import static com.android.net.module.util.netlink.xfrm.XfrmNetlinkMessage.IPPROTO_ESP;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
@@ -38,7 +38,7 @@
 
 @RunWith(AndroidJUnit4.class)
 @SmallTest
-public class IpSecStructXfrmUsersaIdTest {
+public class StructXfrmUsersaIdTest {
     private static final String EXPECTED_HEX_STRING =
             "C0000201000000000000000000000000" + "7768440002003200";
     private static final byte[] EXPECTED_HEX = HexDump.hexStringToByteArray(EXPECTED_HEX_STRING);
@@ -50,8 +50,7 @@
 
     @Test
     public void testEncode() throws Exception {
-        final IpSecStructXfrmUsersaId struct =
-                new IpSecStructXfrmUsersaId(DEST_ADDRESS, SPI, FAMILY, PROTO);
+        final StructXfrmUsersaId struct = new StructXfrmUsersaId(DEST_ADDRESS, SPI, FAMILY, PROTO);
 
         ByteBuffer buffer = ByteBuffer.allocate(EXPECTED_HEX.length);
         buffer.order(ByteOrder.nativeOrder());
@@ -65,8 +64,8 @@
         final ByteBuffer buffer = ByteBuffer.wrap(EXPECTED_HEX);
         buffer.order(ByteOrder.nativeOrder());
 
-        final IpSecStructXfrmUsersaId struct =
-                IpSecStructXfrmUsersaId.parse(IpSecStructXfrmUsersaId.class, buffer);
+        final StructXfrmUsersaId struct =
+                StructXfrmUsersaId.parse(StructXfrmUsersaId.class, buffer);
 
         assertEquals(DEST_ADDRESS, struct.getDestAddress());
         assertEquals(SPI, struct.spi);