diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-09-12 04:11:30 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-09-12 04:11:30 +0000 |
commit | 059249fc5c1a9517d0aa9757a5c4897f840e46b0 (patch) | |
tree | c2753a5c0e48d6004c8f5d99f6ff54df1b05e05a | |
parent | 839ba035e71574cd32c1a5047ef3a88c1787e84d (diff) | |
parent | e9d14dc211d313ad8ac25ecd3992fd1423fb4b2e (diff) | |
download | net-aml_tet_331117000.tar.gz |
Snap for 9051176 from e9d14dc211d313ad8ac25ecd3992fd1423fb4b2e to mainline-tethering-releaseaml_tet_331117000
Change-Id: I26c131463af62610f903b7f156bdff14334b9be9
11 files changed, 103 insertions, 21 deletions
diff --git a/TEST_MAPPING b/TEST_MAPPING index 490fb5d5..55e46177 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -15,6 +15,9 @@ }, { "path": "packages/modules/Wifi/framework" + }, + { + "path": "vendor/xts/gts-tests/hostsidetests/networkstack" } ] } diff --git a/common/Android.bp b/common/Android.bp index c04d1d46..4dfc752b 100644 --- a/common/Android.bp +++ b/common/Android.bp @@ -284,7 +284,7 @@ java_library { // TODO: remove "apex_available:platform". apex_available: [ "//apex_available:platform", - "com.android.bluetooth", + "com.android.btservices", "com.android.tethering", "com.android.wifi", ], diff --git a/common/device/com/android/net/module/util/DeviceConfigUtils.java b/common/device/com/android/net/module/util/DeviceConfigUtils.java index 30a1c332..f8f250d7 100644 --- a/common/device/com/android/net/module/util/DeviceConfigUtils.java +++ b/common/device/com/android/net/module/util/DeviceConfigUtils.java @@ -259,4 +259,17 @@ public final class DeviceConfigUtils { return defaultValue; } } + + /** + * Gets int config from resources. + */ + public static int getResIntegerConfig(@NonNull final Context context, + @BoolRes int configResource, final int defaultValue) { + final Resources res = context.getResources(); + try { + return res.getInteger(configResource); + } catch (Resources.NotFoundException e) { + return defaultValue; + } + } } diff --git a/common/device/com/android/net/module/util/netlink/InetDiagMessage.java b/common/device/com/android/net/module/util/netlink/InetDiagMessage.java index a8aef7b4..eff1f25d 100644 --- a/common/device/com/android/net/module/util/netlink/InetDiagMessage.java +++ b/common/device/com/android/net/module/util/netlink/InetDiagMessage.java @@ -106,21 +106,24 @@ public class InetDiagMessage extends NetlinkMessage { return bytes; } - public StructInetDiagMsg mStructInetDiagMsg; + public StructInetDiagMsg inetDiagMsg; private InetDiagMessage(@NonNull StructNlMsgHdr header) { super(header); - mStructInetDiagMsg = new StructInetDiagMsg(); + inetDiagMsg = new StructInetDiagMsg(); } /** * Parse an inet_diag_req_v2 message from buffer. */ - @NonNull + @Nullable public static InetDiagMessage parse(@NonNull StructNlMsgHdr header, @NonNull ByteBuffer byteBuffer) { final InetDiagMessage msg = new InetDiagMessage(header); - msg.mStructInetDiagMsg = StructInetDiagMsg.parse(byteBuffer); + msg.inetDiagMsg = StructInetDiagMsg.parse(byteBuffer); + if (msg.inetDiagMsg == null) { + return null; + } return msg; } @@ -133,12 +136,15 @@ public class InetDiagMessage extends NetlinkMessage { ByteBuffer response = NetlinkSocket.recvMessage(fd, DEFAULT_RECV_BUFSIZE, TIMEOUT_MS); final NetlinkMessage nlMsg = NetlinkMessage.parse(response, NETLINK_INET_DIAG); + if (nlMsg == null) { + return INVALID_UID; + } final StructNlMsgHdr hdr = nlMsg.getHeader(); if (hdr.nlmsg_type == NetlinkConstants.NLMSG_DONE) { return INVALID_UID; } if (nlMsg instanceof InetDiagMessage) { - return ((InetDiagMessage) nlMsg).mStructInetDiagMsg.idiag_uid; + return ((InetDiagMessage) nlMsg).inetDiagMsg.idiag_uid; } return INVALID_UID; } @@ -228,7 +234,7 @@ public class InetDiagMessage extends NetlinkMessage { + "nlmsghdr{" + (mHeader == null ? "" : mHeader.toString(NETLINK_INET_DIAG)) + "}, " + "inet_diag_msg{" - + (mStructInetDiagMsg == null ? "" : mStructInetDiagMsg.toString()) + "} " + + (inetDiagMsg == null ? "" : inetDiagMsg.toString()) + "} " + "}"; } } diff --git a/common/device/com/android/net/module/util/netlink/StructInetDiagMsg.java b/common/device/com/android/net/module/util/netlink/StructInetDiagMsg.java index 205656e3..ea018cf6 100644 --- a/common/device/com/android/net/module/util/netlink/StructInetDiagMsg.java +++ b/common/device/com/android/net/module/util/netlink/StructInetDiagMsg.java @@ -16,6 +16,9 @@ package com.android.net.module.util.netlink; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import java.nio.ByteBuffer; /** @@ -40,15 +43,28 @@ import java.nio.ByteBuffer; */ public class StructInetDiagMsg { public static final int STRUCT_SIZE = 4 + StructInetDiagSockId.STRUCT_SIZE + 20; + private static final int IDIAG_SOCK_ID_OFFSET = StructNlMsgHdr.STRUCT_SIZE + 4; private static final int IDIAG_UID_OFFSET = StructNlMsgHdr.STRUCT_SIZE + 4 + StructInetDiagSockId.STRUCT_SIZE + 12; public int idiag_uid; + @NonNull + public StructInetDiagSockId id; /** * Parse inet diag netlink message from buffer. */ - public static StructInetDiagMsg parse(ByteBuffer byteBuffer) { + @Nullable + public static StructInetDiagMsg parse(@NonNull ByteBuffer byteBuffer) { + if (byteBuffer.remaining() < STRUCT_SIZE) { + return null; + } StructInetDiagMsg struct = new StructInetDiagMsg(); + final byte family = byteBuffer.get(); + byteBuffer.position(IDIAG_SOCK_ID_OFFSET); + struct.id = StructInetDiagSockId.parse(byteBuffer, family); + if (struct.id == null) { + return null; + } struct.idiag_uid = byteBuffer.getInt(IDIAG_UID_OFFSET); return struct; } @@ -57,6 +73,7 @@ public class StructInetDiagMsg { public String toString() { return "StructInetDiagMsg{ " + "idiag_uid{" + idiag_uid + "}, " + + "id{" + id + "}, " + "}"; } } diff --git a/common/device/com/android/net/module/util/netlink/StructInetDiagSockId.java b/common/device/com/android/net/module/util/netlink/StructInetDiagSockId.java index 95723cbf..648a0201 100644 --- a/common/device/com/android/net/module/util/netlink/StructInetDiagSockId.java +++ b/common/device/com/android/net/module/util/netlink/StructInetDiagSockId.java @@ -106,7 +106,7 @@ public class StructInetDiagSockId { byteBuffer.get(srcAddrByte); byteBuffer.get(dstAddrByte); } else { - Log.e(TAG, "Invalid address family: " + family); + Log.wtf(TAG, "Invalid address family: " + family); return null; } @@ -118,7 +118,7 @@ public class StructInetDiagSockId { } catch (UnknownHostException e) { // Should not happen. UnknownHostException is thrown only if addr byte array is of // illegal length. - Log.e(TAG, "Failed to parse address: " + e); + Log.wtf(TAG, "Failed to parse address: " + e); return null; } diff --git a/common/framework/com/android/net/module/util/CollectionUtils.java b/common/framework/com/android/net/module/util/CollectionUtils.java index d1728c21..7cac90d5 100644 --- a/common/framework/com/android/net/module/util/CollectionUtils.java +++ b/common/framework/com/android/net/module/util/CollectionUtils.java @@ -99,7 +99,8 @@ public final class CollectionUtils { * @return The index of the first element that matches the predicate, or -1 if none. */ @Nullable - public static <T> int indexOf(@NonNull Collection<T> elem, @NonNull Predicate<T> predicate) { + public static <T> int indexOf(@NonNull final Collection<T> elem, + @NonNull final Predicate<? super T> predicate) { int idx = 0; for (final T e : elem) { if (predicate.test(e)) return idx; @@ -222,7 +223,8 @@ public final class CollectionUtils { * @param <T> type of elements * @return true if |haystack| contains any of the |needles|, false otherwise */ - public static <T> boolean containsAny(Collection<T> haystack, Collection<? extends T> needles) { + public static <T> boolean containsAny(@NonNull final Collection<T> haystack, + @NonNull final Collection<? extends T> needles) { for (T needle : needles) { if (haystack.contains(needle)) return true; } @@ -236,7 +238,8 @@ public final class CollectionUtils { * @param <T> type of elements * @return true if |haystack| contains all of the |needles|, false otherwise */ - public static <T> boolean containsAll(Collection<T> haystack, Collection<? extends T> needles) { + public static <T> boolean containsAll(@NonNull final Collection<T> haystack, + @NonNull final Collection<? extends T> needles) { return haystack.containsAll(needles); } @@ -248,7 +251,8 @@ public final class CollectionUtils { * @return The first element matching the predicate, or null if none. */ @Nullable - public static <T> T findFirst(Collection<T> haystack, Predicate<? super T> condition) { + public static <T> T findFirst(@NonNull final Collection<T> haystack, + @NonNull final Predicate<? super T> condition) { for (T needle : haystack) { if (condition.test(needle)) return needle; } @@ -267,11 +271,24 @@ public final class CollectionUtils { // wasteful (store and reverse a copy, test all elements, or recurse to the end of the // list to test on the up path and possibly blow the call stack) @Nullable - public static <T> T findLast(List<T> haystack, Predicate<? super T> condition) { + public static <T> T findLast(@NonNull final List<T> haystack, + @NonNull final Predicate<? super T> condition) { for (int i = haystack.size() - 1; i >= 0; --i) { final T needle = haystack.get(i); if (condition.test(needle)) return needle; } return null; } + + /** + * Returns whether a collection contains an element matching a condition + * @param haystack The collection to search. + * @param condition The predicate to match. + * @param <T> The type of element in the collection. + * @return Whether the collection contains any element matching the condition. + */ + public static <T> boolean contains(@NonNull final Collection<T> haystack, + @NonNull final Predicate<? super T> condition) { + return -1 != indexOf(haystack, condition); + } } diff --git a/common/tests/unit/src/com/android/net/module/util/CollectionUtilsTest.kt b/common/tests/unit/src/com/android/net/module/util/CollectionUtilsTest.kt index 09913526..0f00d0b5 100644 --- a/common/tests/unit/src/com/android/net/module/util/CollectionUtilsTest.kt +++ b/common/tests/unit/src/com/android/net/module/util/CollectionUtilsTest.kt @@ -94,6 +94,12 @@ class CollectionUtilsTest { assertTrue(CollectionUtils.contains(arrayOf("A", "B", "C"), "C")) assertFalse(CollectionUtils.contains(arrayOf("A", "B", "C"), "D")) assertFalse(CollectionUtils.contains(null, "A")) + + val list = listOf("A", "B", "Ab", "C", "D", "E", "A", "E") + assertTrue(CollectionUtils.contains(list) { it.length == 2 }) + assertFalse(CollectionUtils.contains(list) { it.length < 1 }) + assertTrue(CollectionUtils.contains(list) { it > "A" }) + assertFalse(CollectionUtils.contains(list) { it > "F" }) } @Test diff --git a/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java b/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java index c65f7934..a8e7993a 100644 --- a/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java +++ b/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java @@ -283,4 +283,13 @@ public class DeviceConfigUtilsTest { doThrow(new Resources.NotFoundException()).when(mResources).getBoolean(someResId); assertFalse(DeviceConfigUtils.getResBooleanConfig(mContext, someResId, false)); } + + @Test + public void testGetResIntegerConfig() { + final int someResId = 1234; + doReturn(2097).when(mResources).getInteger(someResId); + assertEquals(2097, DeviceConfigUtils.getResIntegerConfig(mContext, someResId, 2098)); + doThrow(new Resources.NotFoundException()).when(mResources).getInteger(someResId); + assertEquals(2098, DeviceConfigUtils.getResIntegerConfig(mContext, someResId, 2098)); + } } diff --git a/common/tests/unit/src/com/android/net/module/util/netlink/InetDiagSocketTest.java b/common/tests/unit/src/com/android/net/module/util/netlink/InetDiagSocketTest.java index 6b1482d8..c7e2a4db 100644 --- a/common/tests/unit/src/com/android/net/module/util/netlink/InetDiagSocketTest.java +++ b/common/tests/unit/src/com/android/net/module/util/netlink/InetDiagSocketTest.java @@ -31,6 +31,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import android.net.InetAddresses; + import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -235,10 +237,10 @@ public class InetDiagSocketTest { // inet_diag_sockid "a817" + // idiag_sport = 43031 "960f" + // idiag_dport = 38415 - "fe8000000000000086c9b2fffe6aed4b" + // idiag_src = fe80::86c9:b2ff:fe6a:ed4b - "00000000000000000000ffff08080808" + // idiag_dst = 8.8.8.8 - "00000000" + // idiag_if - "ffffffffffffffff" + // idiag_cookie = INET_DIAG_NOCOOKIE + "20010db8000000000000000000000001" + // idiag_src = 2001:db8::1 + "20010db8000000000000000000000002" + // idiag_dst = 2001:db8::2 + "07000000" + // idiag_if = 7 + "5800000000000000" + // idiag_cookie = 88 "00000000" + // idiag_expires "00000000" + // idiag_rqueue "00000000" + // idiag_wqueue @@ -256,7 +258,16 @@ public class InetDiagSocketTest { assertTrue(msg instanceof InetDiagMessage); final InetDiagMessage inetDiagMsg = (InetDiagMessage) msg; - assertEquals(10147, inetDiagMsg.mStructInetDiagMsg.idiag_uid); + assertEquals(10147, inetDiagMsg.inetDiagMsg.idiag_uid); + final StructInetDiagSockId sockId = inetDiagMsg.inetDiagMsg.id; + assertEquals(43031, sockId.locSocketAddress.getPort()); + assertEquals(InetAddresses.parseNumericAddress("2001:db8::1"), + sockId.locSocketAddress.getAddress()); + assertEquals(38415, sockId.remSocketAddress.getPort()); + assertEquals(InetAddresses.parseNumericAddress("2001:db8::2"), + sockId.remSocketAddress.getAddress()); + assertEquals(7, sockId.ifIndex); + assertEquals(88, sockId.cookie); final StructNlMsgHdr hdr = inetDiagMsg.getHeader(); assertNotNull(hdr); diff --git a/common/testutils/Android.bp b/common/testutils/Android.bp index 642544ad..c9b3d070 100644 --- a/common/testutils/Android.bp +++ b/common/testutils/Android.bp @@ -80,6 +80,6 @@ java_test_host { "host/**/*.kt", ], libs: ["tradefed"], - test_suites: ["device-tests", "general-tests", "cts", "mts-networking"], + test_suites: ["ats", "device-tests", "general-tests", "cts", "mts-networking"], data: [":ConnectivityChecker"], } |