From eaaf7d3a83e64327fbc1ceb9ed94089f001fb319 Mon Sep 17 00:00:00 2001 From: Xiao Ma Date: Sun, 23 Jan 2022 16:14:51 +0000 Subject: [PATCH 1/2] Build ethernet framework source into framework-connectivity-tiramisu - move ethernet APIs, build it into framework-connectivity-tiramisu - start ethernet service from ConnectivityServiceInitializer - fix EthernetManager dependnecy in Tethering module - fix EthernetNetworkSpecifier dependency in framework-connectivity - fix the ethernet related config resource Bug: 210586283 Test: m Test: atest FrameworksNetTests EthernetServiceTests Ignore-AOSP-First: Topic of Ethernet Mainline has merge conflict with master, merge this CL first and cherry-pick it back. Change-Id: I54857b8517649048a343c72797668394d5225766 --- framework-t/Android.bp | 1 + framework-t/api/current.txt | 8 ++++ framework-t/api/module-lib-current.txt | 16 ++++++++ framework-t/api/system-current.txt | 39 +++++++++++++++++++ framework/Android.bp | 4 +- service-t/Android.bp | 2 + .../ConnectivityServiceInitializer.java | 28 +++++++++++++ service/Android.bp | 1 + .../res/values/config.xml | 32 +++++++++++++++ .../res/values/overlayable.xml | 3 ++ .../android/server/ConnectivityService.java | 11 +++++- .../server/ConnectivityServiceTest.java | 2 + .../android/server/LegacyTypeTrackerTest.kt | 9 +++-- 13 files changed, 150 insertions(+), 6 deletions(-) diff --git a/framework-t/Android.bp b/framework-t/Android.bp index 2ab69b8405..f46d887f78 100644 --- a/framework-t/Android.bp +++ b/framework-t/Android.bp @@ -127,6 +127,7 @@ java_sdk_library { "//frameworks/base/tests/vcn", "//frameworks/libs/net/common/testutils", "//frameworks/libs/net/common/tests:__subpackages__", + "//frameworks/opt/net/ethernet/tests:__subpackages__", "//frameworks/opt/telephony/tests/telephonytests", "//packages/modules/CaptivePortalLogin/tests", "//packages/modules/Connectivity/Tethering/tests:__subpackages__", diff --git a/framework-t/api/current.txt b/framework-t/api/current.txt index 3d6fb3e552..4fefa0a17c 100644 --- a/framework-t/api/current.txt +++ b/framework-t/api/current.txt @@ -61,6 +61,14 @@ package android.app.usage { package android.net { + public final class EthernetNetworkSpecifier extends android.net.NetworkSpecifier implements android.os.Parcelable { + ctor public EthernetNetworkSpecifier(@NonNull String); + method public int describeContents(); + method @Nullable public String getInterfaceName(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + public final class IpSecAlgorithm implements android.os.Parcelable { ctor public IpSecAlgorithm(@NonNull String, @NonNull byte[]); ctor public IpSecAlgorithm(@NonNull String, @NonNull byte[], int); diff --git a/framework-t/api/module-lib-current.txt b/framework-t/api/module-lib-current.txt index 59ca730a2e..3eca52161a 100644 --- a/framework-t/api/module-lib-current.txt +++ b/framework-t/api/module-lib-current.txt @@ -31,6 +31,22 @@ package android.net { method public static void registerServiceWrappers(); } + public class EthernetManager { + method @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) public void addInterfaceStateListener(@NonNull java.util.concurrent.Executor, @NonNull android.net.EthernetManager.InterfaceStateListener); + method public void removeInterfaceStateListener(@NonNull android.net.EthernetManager.InterfaceStateListener); + method public void setIncludeTestInterfaces(boolean); + field public static final int ROLE_CLIENT = 1; // 0x1 + field public static final int ROLE_NONE = 0; // 0x0 + field public static final int ROLE_SERVER = 2; // 0x2 + field public static final int STATE_ABSENT = 0; // 0x0 + field public static final int STATE_LINK_DOWN = 1; // 0x1 + field public static final int STATE_LINK_UP = 2; // 0x2 + } + + public static interface EthernetManager.InterfaceStateListener { + method public void onInterfaceStateChanged(@NonNull String, int, int, @Nullable android.net.IpConfiguration); + } + public class IpSecManager { field public static final int DIRECTION_FWD = 2; // 0x2 } diff --git a/framework-t/api/system-current.txt b/framework-t/api/system-current.txt index 48acaf3f7b..7378cf3cc5 100644 --- a/framework-t/api/system-current.txt +++ b/framework-t/api/system-current.txt @@ -499,6 +499,45 @@ package android.nearby { package android.net { + public class EthernetManager { + method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}) public void connectNetwork(@NonNull String, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.BiConsumer); + method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}) public void disconnectNetwork(@NonNull String, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.BiConsumer); + method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.NETWORK_STACK, android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}) public android.net.EthernetManager.TetheredInterfaceRequest requestTetheredInterface(@NonNull java.util.concurrent.Executor, @NonNull android.net.EthernetManager.TetheredInterfaceCallback); + method @RequiresPermission(anyOf={android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK, android.Manifest.permission.NETWORK_STACK, android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}) public void updateConfiguration(@NonNull String, @NonNull android.net.EthernetNetworkUpdateRequest, @Nullable java.util.concurrent.Executor, @Nullable java.util.function.BiConsumer); + } + + public static interface EthernetManager.TetheredInterfaceCallback { + method public void onAvailable(@NonNull String); + method public void onUnavailable(); + } + + public static class EthernetManager.TetheredInterfaceRequest { + method public void release(); + } + + public final class EthernetNetworkManagementException extends java.lang.RuntimeException implements android.os.Parcelable { + ctor public EthernetNetworkManagementException(@NonNull String); + method public int describeContents(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + + public final class EthernetNetworkUpdateRequest implements android.os.Parcelable { + method public int describeContents(); + method @NonNull public android.net.IpConfiguration getIpConfiguration(); + method @Nullable public android.net.NetworkCapabilities getNetworkCapabilities(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + + public static final class EthernetNetworkUpdateRequest.Builder { + ctor public EthernetNetworkUpdateRequest.Builder(); + ctor public EthernetNetworkUpdateRequest.Builder(@NonNull android.net.EthernetNetworkUpdateRequest); + method @NonNull public android.net.EthernetNetworkUpdateRequest build(); + method @NonNull public android.net.EthernetNetworkUpdateRequest.Builder setIpConfiguration(@NonNull android.net.IpConfiguration); + method @NonNull public android.net.EthernetNetworkUpdateRequest.Builder setNetworkCapabilities(@Nullable android.net.NetworkCapabilities); + } + public class IpSecManager { method @RequiresPermission(android.Manifest.permission.MANAGE_IPSEC_TUNNELS) public void applyTunnelModeTransform(@NonNull android.net.IpSecManager.IpSecTunnelInterface, int, @NonNull android.net.IpSecTransform) throws java.io.IOException; method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_IPSEC_TUNNELS) public android.net.IpSecManager.IpSecTunnelInterface createIpSecTunnelInterface(@NonNull java.net.InetAddress, @NonNull java.net.InetAddress, @NonNull android.net.Network) throws java.io.IOException, android.net.IpSecManager.ResourceUnavailableException; diff --git a/framework/Android.bp b/framework/Android.bp index 821879d3fa..f31a7d5421 100644 --- a/framework/Android.bp +++ b/framework/Android.bp @@ -86,6 +86,7 @@ java_defaults { "net-utils-device-common", ], static_libs: [ + "modules-utils-backgroundthread", "modules-utils-build", "modules-utils-preconditions", ], @@ -139,6 +140,7 @@ java_sdk_library { "//frameworks/base/tests/vcn", "//frameworks/libs/net/common/testutils", "//frameworks/libs/net/common/tests:__subpackages__", + "//frameworks/opt/net/ethernet/tests:__subpackages__", "//frameworks/opt/telephony/tests/telephonytests", "//packages/modules/CaptivePortalLogin/tests", "//packages/modules/Connectivity/Tethering/tests:__subpackages__", @@ -212,4 +214,4 @@ gensrcs { ":framework-connectivity-protos", ], output_extension: "srcjar", -} \ No newline at end of file +} diff --git a/service-t/Android.bp b/service-t/Android.bp index 3146a93892..8851554751 100644 --- a/service-t/Android.bp +++ b/service-t/Android.bp @@ -30,6 +30,7 @@ java_library { min_sdk_version: "30", srcs: [ "src/**/*.java", + ":ethernet-service-updatable-sources", ":services.connectivity-tiramisu-updatable-sources", ], libs: [ @@ -39,6 +40,7 @@ java_library { "framework-tethering.stubs.module_lib", "service-connectivity-pre-jarjar", "service-nearby-pre-jarjar", + "ServiceConnectivityResources", "unsupportedappusage", ], static_libs: [ diff --git a/service-t/src/com/android/server/ConnectivityServiceInitializer.java b/service-t/src/com/android/server/ConnectivityServiceInitializer.java index 25fe5e9080..7b1cd61480 100644 --- a/service-t/src/com/android/server/ConnectivityServiceInitializer.java +++ b/service-t/src/com/android/server/ConnectivityServiceInitializer.java @@ -21,6 +21,8 @@ import android.util.Log; import com.android.modules.utils.build.SdkLevel; import com.android.networkstack.apishim.ConstantsShim; +import com.android.server.ethernet.EthernetService; +import com.android.server.ethernet.EthernetServiceImpl; import com.android.server.nearby.NearbyService; /** @@ -29,15 +31,19 @@ import com.android.server.nearby.NearbyService; */ public final class ConnectivityServiceInitializer extends SystemService { private static final String TAG = ConnectivityServiceInitializer.class.getSimpleName(); + private final Context mContext; private final ConnectivityService mConnectivity; private final IpSecService mIpSecService; private final NsdService mNsdService; private final NearbyService mNearbyService; + private final EthernetServiceImpl mEthernetServiceImpl; public ConnectivityServiceInitializer(Context context) { super(context); + mContext = context; // Load JNI libraries used by ConnectivityService and its dependencies System.loadLibrary("service-connectivity"); + mEthernetServiceImpl = createEthernetService(context); mConnectivity = new ConnectivityService(context); mIpSecService = createIpSecService(context); mNsdService = createNsdService(context); @@ -46,6 +52,12 @@ public final class ConnectivityServiceInitializer extends SystemService { @Override public void onStart() { + if (mConnectivity.deviceSupportsEthernet(mContext)) { + Log.i(TAG, "Registering " + Context.ETHERNET_SERVICE); + publishBinderService(Context.ETHERNET_SERVICE, mEthernetServiceImpl, + /* allowIsolated= */ false); + } + Log.i(TAG, "Registering " + Context.CONNECTIVITY_SERVICE); publishBinderService(Context.CONNECTIVITY_SERVICE, mConnectivity, /* allowIsolated= */ false); @@ -65,6 +77,7 @@ public final class ConnectivityServiceInitializer extends SystemService { publishBinderService(ConstantsShim.NEARBY_SERVICE, mNearbyService, /* allowIsolated= */ false); } + } @Override @@ -72,6 +85,10 @@ public final class ConnectivityServiceInitializer extends SystemService { if (mNearbyService != null) { mNearbyService.onBootPhase(phase); } + + if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY && mEthernetServiceImpl != null) { + mEthernetServiceImpl.start(); + } } /** @@ -106,4 +123,15 @@ public final class ConnectivityServiceInitializer extends SystemService { return null; } } + + /** + * Return EthernetServiceImpl instance or null if current SDK is lower than T or Ethernet + * service isn't necessary. + */ + private EthernetServiceImpl createEthernetService(final Context context) { + if (!SdkLevel.isAtLeastT() || !mConnectivity.deviceSupportsEthernet(context)) { + return null; + } + return EthernetService.create(context); + } } diff --git a/service/Android.bp b/service/Android.bp index 744f9ba4dd..0b8b25fba8 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -114,6 +114,7 @@ java_library { "net-utils-device-common", "net-utils-device-common-bpf", "net-utils-device-common-netlink", + "net-utils-services-common", "netd-client", "networkstack-client", "PlatformProperties", diff --git a/service/ServiceConnectivityResources/res/values/config.xml b/service/ServiceConnectivityResources/res/values/config.xml index f8f86a257a..faa9998ba0 100644 --- a/service/ServiceConnectivityResources/res/values/config.xml +++ b/service/ServiceConnectivityResources/res/values/config.xml @@ -136,4 +136,36 @@ extreme adverse effects on performance of the new network. --> true + + + 524288,1048576,3145728,524288,1048576,2097152 + + + + + + + + eth\\d diff --git a/service/ServiceConnectivityResources/res/values/overlayable.xml b/service/ServiceConnectivityResources/res/values/overlayable.xml index e5010d7429..9fa6a30b5e 100644 --- a/service/ServiceConnectivityResources/res/values/overlayable.xml +++ b/service/ServiceConnectivityResources/res/values/overlayable.xml @@ -37,6 +37,9 @@ + + + diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index dd92a18768..da80e0ac9c 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -936,7 +936,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } // Ethernet is often not specified in the configs, although many devices can use it via // USB host adapters. Add it as long as the ethernet service is here. - if (ctx.getSystemService(Context.ETHERNET_SERVICE) != null) { + if (deviceSupportsEthernet(ctx)) { addSupportedType(TYPE_ETHERNET); } @@ -1621,6 +1621,15 @@ public class ConnectivityService extends IConnectivityManager.Stub mContext); } + /** + * Check whether or not the device supports Ethernet transport. + */ + public static boolean deviceSupportsEthernet(final Context context) { + final PackageManager pm = context.getPackageManager(); + return pm.hasSystemFeature(PackageManager.FEATURE_ETHERNET) + || pm.hasSystemFeature(PackageManager.FEATURE_USB_HOST); + } + private static NetworkCapabilities createDefaultNetworkCapabilitiesForUid(int uid) { return createDefaultNetworkCapabilitiesForUidRangeSet(Collections.singleton( new UidRange(uid, uid))); diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index c8dc1074be..94272b8518 100644 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -36,6 +36,7 @@ import static android.content.Intent.ACTION_USER_ADDED; import static android.content.Intent.ACTION_USER_REMOVED; import static android.content.Intent.ACTION_USER_UNLOCKED; import static android.content.pm.PackageInfo.REQUESTED_PERMISSION_GRANTED; +import static android.content.pm.PackageManager.FEATURE_ETHERNET; import static android.content.pm.PackageManager.FEATURE_WIFI; import static android.content.pm.PackageManager.FEATURE_WIFI_DIRECT; import static android.content.pm.PackageManager.GET_PERMISSIONS; @@ -1739,6 +1740,7 @@ public class ConnectivityServiceTest { mockDefaultPackages(); mockHasSystemFeature(FEATURE_WIFI, true); mockHasSystemFeature(FEATURE_WIFI_DIRECT, true); + mockHasSystemFeature(FEATURE_ETHERNET, true); doReturn(true).when(mTelephonyManager).isDataCapable(); FakeSettingsProvider.clearSettingsProvider(); diff --git a/tests/unit/java/com/android/server/LegacyTypeTrackerTest.kt b/tests/unit/java/com/android/server/LegacyTypeTrackerTest.kt index 64736f244d..7ed55e5ad3 100644 --- a/tests/unit/java/com/android/server/LegacyTypeTrackerTest.kt +++ b/tests/unit/java/com/android/server/LegacyTypeTrackerTest.kt @@ -23,6 +23,8 @@ package com.android.server import android.content.Context import android.content.pm.PackageManager +import android.content.pm.PackageManager.FEATURE_ETHERNET +import android.content.pm.PackageManager.FEATURE_USB_HOST import android.content.pm.PackageManager.FEATURE_WIFI import android.content.pm.PackageManager.FEATURE_WIFI_DIRECT import android.net.ConnectivityManager.TYPE_ETHERNET @@ -40,7 +42,6 @@ import android.net.ConnectivityManager.TYPE_VPN import android.net.ConnectivityManager.TYPE_WIFI import android.net.ConnectivityManager.TYPE_WIFI_P2P import android.net.ConnectivityManager.TYPE_WIMAX -import android.net.EthernetManager import android.net.NetworkInfo.DetailedState.CONNECTED import android.net.NetworkInfo.DetailedState.DISCONNECTED import android.os.Build @@ -82,9 +83,8 @@ class LegacyTypeTrackerTest { private val mContext = mock(Context::class.java).apply { doReturn(true).`when`(mPm).hasSystemFeature(FEATURE_WIFI) doReturn(true).`when`(mPm).hasSystemFeature(FEATURE_WIFI_DIRECT) + doReturn(true).`when`(mPm).hasSystemFeature(FEATURE_ETHERNET) doReturn(mPm).`when`(this).packageManager - doReturn(mock(EthernetManager::class.java)).`when`(this).getSystemService( - Context.ETHERNET_SERVICE) } private val mTm = mock(TelephonyManager::class.java).apply { doReturn(true).`when`(this).isDataCapable @@ -105,7 +105,8 @@ class LegacyTypeTrackerTest { @Test fun testSupportedTypes_NoEthernet() { - doReturn(null).`when`(mContext).getSystemService(Context.ETHERNET_SERVICE) + doReturn(false).`when`(mPm).hasSystemFeature(FEATURE_ETHERNET) + doReturn(false).`when`(mPm).hasSystemFeature(FEATURE_USB_HOST) assertFalse(makeTracker().isTypeSupported(TYPE_ETHERNET)) } From 47b89e9594120440367171883a9b5eb3b96b2b30 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 10 Mar 2022 17:22:41 +0900 Subject: [PATCH 2/2] Provide a stub ethernet service to build in sc-mainline-prod. This CL also creates a fake ethernet-service.jar to ensure that targets that depend on ethernet-service do not break. Because ethernet-service.jar is on the system server classpath, these classes cannot be in the com.android.server.ethernet package, otherwise ConnectivityServiceInitializer will load them instead of the real classes. Test: m Bug: 210586283 Ignore-AOSP-First: avoid merge conflicts Change-Id: I6a4a0dc68233d4229d1cae4e5b196e287ef2ed5b --- ethernet/Android.bp | 25 ++++++++++++++ .../server/ethernet/stub/EthernetService.java | 34 +++++++++++++++++++ .../ethernet/stub/EthernetServiceImpl.java | 25 ++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 ethernet/Android.bp create mode 100644 ethernet/src/com/android/server/ethernet/stub/EthernetService.java create mode 100644 ethernet/src/com/android/server/ethernet/stub/EthernetServiceImpl.java diff --git a/ethernet/Android.bp b/ethernet/Android.bp new file mode 100644 index 0000000000..36978c54be --- /dev/null +++ b/ethernet/Android.bp @@ -0,0 +1,25 @@ +// Copyright (C) 2022 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// TODO: delete once: +// - The ethernet code has been moved to p/m/C. +// - All dependencies in the tree are gone. +java_library { + name: "ethernet-service", + installable: true, + srcs: [ + "src/**/*.java", + ], +} + diff --git a/ethernet/src/com/android/server/ethernet/stub/EthernetService.java b/ethernet/src/com/android/server/ethernet/stub/EthernetService.java new file mode 100644 index 0000000000..d0010c1f9d --- /dev/null +++ b/ethernet/src/com/android/server/ethernet/stub/EthernetService.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.ethernet.stub; + +import android.content.Context; +import android.os.Binder; + +/** + * Fake EthernetService class for branches that do not have the updatable EthernetService yet, + * to allow building the T service-connectivity before sources are moved to the branch. + * TODO: Once ethernet-service is no longer on the system server + * classpath, move these files from com.android.server.ethernet.stub + * to com.android.server.ethernet. + */ +public final class EthernetService extends Binder { + /** Create instance */ + public static EthernetServiceImpl create(Context ctx) { + throw new RuntimeException("This is a stub class"); + } +} diff --git a/ethernet/src/com/android/server/ethernet/stub/EthernetServiceImpl.java b/ethernet/src/com/android/server/ethernet/stub/EthernetServiceImpl.java new file mode 100644 index 0000000000..ff7aaf9b5d --- /dev/null +++ b/ethernet/src/com/android/server/ethernet/stub/EthernetServiceImpl.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.ethernet.stub; + +/** Stub class for EthernetServiceImpl */ +public class EthernetServiceImpl { + /** Start service */ + public void start() { + throw new RuntimeException("This is a stub class"); + } +}