From 6f77442d76c4c3ec13394c603973bafb60a3fd73 Mon Sep 17 00:00:00 2001 From: lucaslin Date: Mon, 29 Mar 2021 18:56:47 +0800 Subject: [PATCH] Add new network capabilities to support automotive head unit via USB - Add a new transport type for USB and a new network capability to support automotive head unit. - In order to pass DnsManagerTest#testTransportTypesEqual, Android.bp needs to link to dnsresolver_aidl_interface-V8-java. That test checks whether the TRANSPORT types defined in NetworkCapabilities are the same as IDnsResolver.aidl. (clean cherry-pick of change in downstream branch history, original change ID before project move: Iec2df09a776d779108f95098e01b7ffdf6f8867a) Bug: 181742019 Test: atest FrameworksNetTests Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f Change-Id: Ie438ec68577ebdaaf990795fa27f1169b0105411 --- framework/api/current.txt | 2 ++ .../src/android/net/NetworkCapabilities.java | 25 ++++++++++++++++--- service/Android.bp | 2 +- .../android/net/util/KeepaliveUtilsTest.kt | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/framework/api/current.txt b/framework/api/current.txt index 7692e30c31..715a532b60 100644 --- a/framework/api/current.txt +++ b/framework/api/current.txt @@ -310,6 +310,7 @@ package android.net { field public static final int NET_CAPABILITY_ENTERPRISE = 29; // 0x1d field public static final int NET_CAPABILITY_FOREGROUND = 19; // 0x13 field public static final int NET_CAPABILITY_FOTA = 3; // 0x3 + field public static final int NET_CAPABILITY_HEAD_UNIT = 32; // 0x20 field public static final int NET_CAPABILITY_IA = 7; // 0x7 field public static final int NET_CAPABILITY_IMS = 4; // 0x4 field public static final int NET_CAPABILITY_INTERNET = 12; // 0xc @@ -333,6 +334,7 @@ package android.net { field public static final int TRANSPORT_CELLULAR = 0; // 0x0 field public static final int TRANSPORT_ETHERNET = 3; // 0x3 field public static final int TRANSPORT_LOWPAN = 6; // 0x6 + field public static final int TRANSPORT_USB = 8; // 0x8 field public static final int TRANSPORT_VPN = 4; // 0x4 field public static final int TRANSPORT_WIFI = 1; // 0x1 field public static final int TRANSPORT_WIFI_AWARE = 5; // 0x5 diff --git a/framework/src/android/net/NetworkCapabilities.java b/framework/src/android/net/NetworkCapabilities.java index 3a07db370f..ec71d3d65a 100644 --- a/framework/src/android/net/NetworkCapabilities.java +++ b/framework/src/android/net/NetworkCapabilities.java @@ -262,6 +262,7 @@ public final class NetworkCapabilities implements Parcelable { NET_CAPABILITY_ENTERPRISE, NET_CAPABILITY_VSIM, NET_CAPABILITY_BIP, + NET_CAPABILITY_HEAD_UNIT, }) public @interface NetCapability { } @@ -495,8 +496,13 @@ public final class NetworkCapabilities implements Parcelable { @SystemApi public static final int NET_CAPABILITY_BIP = 31; + /** + * Indicates that this network is connected to an automotive head unit. + */ + public static final int NET_CAPABILITY_HEAD_UNIT = 32; + private static final int MIN_NET_CAPABILITY = NET_CAPABILITY_MMS; - private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_BIP; + private static final int MAX_NET_CAPABILITY = NET_CAPABILITY_HEAD_UNIT; /** * Network capabilities that are expected to be mutable, i.e., can change while a particular @@ -514,7 +520,10 @@ public final class NetworkCapabilities implements Parcelable { | (1 << NET_CAPABILITY_NOT_SUSPENDED) | (1 << NET_CAPABILITY_PARTIAL_CONNECTIVITY) | (1 << NET_CAPABILITY_TEMPORARILY_NOT_METERED) - | (1 << NET_CAPABILITY_NOT_VCN_MANAGED); + | (1 << NET_CAPABILITY_NOT_VCN_MANAGED) + // The value of NET_CAPABILITY_HEAD_UNIT is 32, which cannot use int to do bit shift, + // otherwise there will be an overflow. Use long to do bit shift instead. + | (1L << NET_CAPABILITY_HEAD_UNIT); /** * Network capabilities that are not allowed in NetworkRequests. This exists because the @@ -868,6 +877,7 @@ public final class NetworkCapabilities implements Parcelable { TRANSPORT_WIFI_AWARE, TRANSPORT_LOWPAN, TRANSPORT_TEST, + TRANSPORT_USB, }) public @interface Transport { } @@ -914,10 +924,15 @@ public final class NetworkCapabilities implements Parcelable { @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) public static final int TRANSPORT_TEST = 7; + /** + * Indicates this network uses a USB transport. + */ + public static final int TRANSPORT_USB = 8; + /** @hide */ public static final int MIN_TRANSPORT = TRANSPORT_CELLULAR; /** @hide */ - public static final int MAX_TRANSPORT = TRANSPORT_TEST; + public static final int MAX_TRANSPORT = TRANSPORT_USB; /** @hide */ public static boolean isValidTransport(@Transport int transportType) { @@ -932,7 +947,8 @@ public final class NetworkCapabilities implements Parcelable { "VPN", "WIFI_AWARE", "LOWPAN", - "TEST" + "TEST", + "USB" }; /** @@ -2121,6 +2137,7 @@ public final class NetworkCapabilities implements Parcelable { case NET_CAPABILITY_ENTERPRISE: return "ENTERPRISE"; case NET_CAPABILITY_VSIM: return "VSIM"; case NET_CAPABILITY_BIP: return "BIP"; + case NET_CAPABILITY_HEAD_UNIT: return "HEAD_UNIT"; default: return Integer.toString(capability); } } diff --git a/service/Android.bp b/service/Android.bp index 848de12e80..7fe0e2b382 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -65,7 +65,7 @@ java_library { "ServiceConnectivityResources", ], static_libs: [ - "dnsresolver_aidl_interface-V7-java", + "dnsresolver_aidl_interface-V8-java", "modules-utils-os", "net-utils-device-common", "net-utils-framework-common", diff --git a/tests/unit/java/android/net/util/KeepaliveUtilsTest.kt b/tests/unit/java/android/net/util/KeepaliveUtilsTest.kt index 40f39a4549..9203f8f6cf 100644 --- a/tests/unit/java/android/net/util/KeepaliveUtilsTest.kt +++ b/tests/unit/java/android/net/util/KeepaliveUtilsTest.kt @@ -104,7 +104,7 @@ class KeepaliveUtilsTest { // Check valid customization generates expected array. val validRes = arrayOf("0,3", "1,0", "4,4") - val expectedValidRes = intArrayOf(3, 0, 0, 0, 4, 0, 0, 0) + val expectedValidRes = intArrayOf(3, 0, 0, 0, 4, 0, 0, 0, 0) val mockContext = getMockedContextWithStringArrayRes( R.array.config_networkSupportedKeepaliveCount,