From a6ba54d59de5f0e93a603b0a6dddcdc8807cfbca Mon Sep 17 00:00:00 2001 From: markchien Date: Tue, 3 Sep 2019 15:58:06 +0800 Subject: [PATCH] [Tether02] Migrate TetheringConfiguration into module TetheringConfiguration is a utility class to encapsulate the various configuration elements. Bug: 136040414 Test: -build, flash, boot -atest TetheringTests Change-Id: I9434ab213bc5e0fca59f14a6c8cea554abefc3a4 --- Android.bp | 6 +++ packages/Tethering/Android.bp | 10 ++++ .../tethering/TetheringConfiguration.java | 11 ++++- packages/Tethering/tests/unit/Android.bp | 47 +++++++++++++++++++ .../Tethering/tests/unit/AndroidManifest.xml | 26 ++++++++++ .../tethering/TetheringConfigurationTest.java | 36 +++++++------- services/core/Android.bp | 1 + services/net/Android.bp | 8 ++++ tests/net/Android.bp | 6 ++- 9 files changed, 130 insertions(+), 21 deletions(-) rename {services/core/java => packages/Tethering/src}/com/android/server/connectivity/tethering/TetheringConfiguration.java (96%) create mode 100644 packages/Tethering/tests/unit/Android.bp create mode 100644 packages/Tethering/tests/unit/AndroidManifest.xml rename {tests/net/java => packages/Tethering/tests/unit/src}/com/android/server/connectivity/tethering/TetheringConfigurationTest.java (91%) diff --git a/Android.bp b/Android.bp index 53b1a641ebc1e..0e1996253a007 100644 --- a/Android.bp +++ b/Android.bp @@ -508,6 +508,12 @@ filegroup { ], } +filegroup { + name: "framework-tethering-shared-srcs", + srcs: [ + "core/java/android/util/LocalLog.java", + ], +} // Build ext.jar // ============================================================ java_library { diff --git a/packages/Tethering/Android.bp b/packages/Tethering/Android.bp index a8d3018bc1b3b..dc88fd4014da9 100644 --- a/packages/Tethering/Android.bp +++ b/packages/Tethering/Android.bp @@ -19,6 +19,8 @@ java_defaults { platform_apis: true, srcs: [ "src/**/*.java", + ":framework-tethering-shared-srcs", + ":services-tethering-shared-srcs", ], static_libs: [ "androidx.annotation_annotation", @@ -60,3 +62,11 @@ android_app { // The permission configuration *must* be included to ensure security of the device required: ["NetworkPermissionConfig"], } + +// This group will be removed when tethering migration is done. +filegroup { + name: "tethering-services-srcs", + srcs: [ + "src/com/android/server/connectivity/tethering/TetheringConfiguration.java", + ], +} diff --git a/services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java b/packages/Tethering/src/com/android/server/connectivity/tethering/TetheringConfiguration.java similarity index 96% rename from services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java rename to packages/Tethering/src/com/android/server/connectivity/tethering/TetheringConfiguration.java index a1b94ca33944b..77097271c4542 100644 --- a/services/core/java/com/android/server/connectivity/tethering/TetheringConfiguration.java +++ b/packages/Tethering/src/com/android/server/connectivity/tethering/TetheringConfiguration.java @@ -82,7 +82,7 @@ public class TetheringConfiguration { "192.168.48.2", "192.168.48.254", "192.168.49.2", "192.168.49.254", }; - private final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"}; + private static final String[] DEFAULT_IPV4_DNS = {"8.8.4.4", "8.8.8.8"}; public final String[] tetherableUsbRegexs; public final String[] tetherableWifiRegexs; @@ -133,10 +133,12 @@ public class TetheringConfiguration { configLog.log(toString()); } + /** Check whether input interface belong to usb.*/ public boolean isUsb(String iface) { return matchesDownstreamRegexs(iface, tetherableUsbRegexs); } + /** Check whether input interface belong to wifi.*/ public boolean isWifi(String iface) { return matchesDownstreamRegexs(iface, tetherableWifiRegexs); } @@ -146,18 +148,22 @@ public class TetheringConfiguration { return matchesDownstreamRegexs(iface, tetherableWifiP2pRegexs); } + /** Check whether using legacy mode for wifi P2P. */ public boolean isWifiP2pLegacyTetheringMode() { return (tetherableWifiP2pRegexs == null || tetherableWifiP2pRegexs.length == 0); } + /** Check whether input interface belong to bluetooth.*/ public boolean isBluetooth(String iface) { return matchesDownstreamRegexs(iface, tetherableBluetoothRegexs); } + /** Check whether no ui entitlement application is available.*/ public boolean hasMobileHotspotProvisionApp() { return !TextUtils.isEmpty(provisioningAppNoUi); } + /** Does the dumping.*/ public void dump(PrintWriter pw) { pw.print("subId: "); pw.println(subId); @@ -186,6 +192,7 @@ public class TetheringConfiguration { pw.println(enableLegacyDhcpServer); } + /** Returns the string representation of this object.*/ public String toString() { final StringJoiner sj = new StringJoiner(" "); sj.add(String.format("subId:%d", subId)); @@ -210,7 +217,7 @@ public class TetheringConfiguration { if (values != null) { final StringJoiner sj = new StringJoiner(", ", "[", "]"); - for (String value : values) { sj.add(value); } + for (String value : values) sj.add(value); pw.print(sj.toString()); } else { pw.print("null"); diff --git a/packages/Tethering/tests/unit/Android.bp b/packages/Tethering/tests/unit/Android.bp new file mode 100644 index 0000000000000..089bbd31d9f33 --- /dev/null +++ b/packages/Tethering/tests/unit/Android.bp @@ -0,0 +1,47 @@ +// +// Copyright (C) 2019 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. +// + +android_test { + name: "TetheringTests", + certificate: "platform", + srcs: ["src/**/*.java"], + test_suites: ["device-tests"], + static_libs: [ + "androidx.test.rules", + "frameworks-base-testutils", + "mockito-target-extended-minus-junit4", + "TetheringApiCurrentLib", + "testables", + ], + libs: [ + "android.test.runner", + "android.test.base", + "android.test.mock", + ], + jni_libs: [ + // For mockito extended + "libdexmakerjvmtiagent", + "libstaticjvmtiagent", + ], +} + +// This group would be removed when tethering migration is done. +filegroup { + name: "tethering-tests-src", + srcs: [ + "src/com/android/server/connectivity/tethering/TetheringConfigurationTest.java", + ], +} diff --git a/packages/Tethering/tests/unit/AndroidManifest.xml b/packages/Tethering/tests/unit/AndroidManifest.xml new file mode 100644 index 0000000000000..049ff6d415f37 --- /dev/null +++ b/packages/Tethering/tests/unit/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + diff --git a/tests/net/java/com/android/server/connectivity/tethering/TetheringConfigurationTest.java b/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/TetheringConfigurationTest.java similarity index 91% rename from tests/net/java/com/android/server/connectivity/tethering/TetheringConfigurationTest.java rename to packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/TetheringConfigurationTest.java index e28296354d2a1..9f9221f3010d2 100644 --- a/tests/net/java/com/android/server/connectivity/tethering/TetheringConfigurationTest.java +++ b/packages/Tethering/tests/unit/src/com/android/server/connectivity/tethering/TetheringConfigurationTest.java @@ -24,7 +24,12 @@ import static android.net.ConnectivityManager.TYPE_WIFI; import static android.provider.Settings.Global.TETHER_ENABLE_LEGACY_DHCP_SERVER; import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; +import static com.android.internal.R.array.config_mobile_hotspot_provision_app; +import static com.android.internal.R.array.config_tether_bluetooth_regexs; +import static com.android.internal.R.array.config_tether_dhcp_range; import static com.android.internal.R.array.config_tether_upstream_types; +import static com.android.internal.R.array.config_tether_usb_regexs; +import static com.android.internal.R.array.config_tether_wifi_regexs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -86,7 +91,9 @@ public class TetheringConfigurationTest { } @Override - public Resources getResources() { return mResources; } + public Resources getResources() { + return mResources; + } @Override public Object getSystemService(String name) { @@ -105,17 +112,13 @@ public class TetheringConfigurationTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - when(mResources.getStringArray(com.android.internal.R.array.config_tether_dhcp_range)) - .thenReturn(new String[0]); - when(mResources.getStringArray(com.android.internal.R.array.config_tether_usb_regexs)) - .thenReturn(new String[0]); - when(mResources.getStringArray(com.android.internal.R.array.config_tether_wifi_regexs)) + when(mResources.getStringArray(config_tether_dhcp_range)).thenReturn(new String[0]); + when(mResources.getStringArray(config_tether_usb_regexs)).thenReturn(new String[0]); + when(mResources.getStringArray(config_tether_wifi_regexs)) .thenReturn(new String[]{ "test_wlan\\d" }); - when(mResources.getStringArray(com.android.internal.R.array.config_tether_bluetooth_regexs)) - .thenReturn(new String[0]); + when(mResources.getStringArray(config_tether_bluetooth_regexs)).thenReturn(new String[0]); when(mResources.getIntArray(config_tether_upstream_types)).thenReturn(new int[0]); - when(mResources.getStringArray( - com.android.internal.R.array.config_mobile_hotspot_provision_app)) + when(mResources.getStringArray(config_mobile_hotspot_provision_app)) .thenReturn(new String[0]); mContentResolver = new MockContentResolver(); mContentResolver.addProvider(Settings.AUTHORITY, new FakeSettingsProvider()); @@ -297,19 +300,16 @@ public class TetheringConfigurationTest { private void setUpResourceForSubId() { when(mResourcesForSubId.getStringArray( - com.android.internal.R.array.config_tether_dhcp_range)).thenReturn(new String[0]); + config_tether_dhcp_range)).thenReturn(new String[0]); when(mResourcesForSubId.getStringArray( - com.android.internal.R.array.config_tether_usb_regexs)).thenReturn(new String[0]); + config_tether_usb_regexs)).thenReturn(new String[0]); when(mResourcesForSubId.getStringArray( - com.android.internal.R.array.config_tether_wifi_regexs)) - .thenReturn(new String[]{ "test_wlan\\d" }); + config_tether_wifi_regexs)).thenReturn(new String[]{ "test_wlan\\d" }); when(mResourcesForSubId.getStringArray( - com.android.internal.R.array.config_tether_bluetooth_regexs)) - .thenReturn(new String[0]); + config_tether_bluetooth_regexs)).thenReturn(new String[0]); when(mResourcesForSubId.getIntArray(config_tether_upstream_types)).thenReturn(new int[0]); when(mResourcesForSubId.getStringArray( - com.android.internal.R.array.config_mobile_hotspot_provision_app)) - .thenReturn(PROVISIONING_APP_NAME); + config_mobile_hotspot_provision_app)).thenReturn(PROVISIONING_APP_NAME); } } diff --git a/services/core/Android.bp b/services/core/Android.bp index 16432212d8e28..58fb0bfd48e40 100644 --- a/services/core/Android.bp +++ b/services/core/Android.bp @@ -20,6 +20,7 @@ java_library_static { ":vold_aidl", ":gsiservice_aidl", ":platform-compat-config", + ":tethering-services-srcs", "java/com/android/server/EventLogTags.logtags", "java/com/android/server/am/EventLogTags.logtags", "java/com/android/server/policy/EventLogTags.logtags", diff --git a/services/net/Android.bp b/services/net/Android.bp index b0af599279451..6a871aa815438 100644 --- a/services/net/Android.bp +++ b/services/net/Android.bp @@ -18,3 +18,11 @@ filegroup { "java/android/net/netlink/*.java", ], } + +filegroup { + name: "services-tethering-shared-srcs", + srcs: [ + ":framework-annotations", + "java/android/net/util/SharedLog.java" + ], +} diff --git a/tests/net/Android.bp b/tests/net/Android.bp index beb5e0db64224..b9b2238572ac6 100644 --- a/tests/net/Android.bp +++ b/tests/net/Android.bp @@ -44,7 +44,11 @@ java_defaults { android_test { name: "FrameworksNetTests", defaults: ["FrameworksNetTests-jni-defaults"], - srcs: ["java/**/*.java", "java/**/*.kt"], + srcs: [ + ":tethering-tests-src", + "java/**/*.java", + "java/**/*.kt", + ], platform_apis: true, test_suites: ["device-tests"], certificate: "platform",