From 6a7e6ad55ca7112444e4bc4678a19f0abc93b060 Mon Sep 17 00:00:00 2001 From: Aaron Huang Date: Wed, 14 Apr 2021 01:25:55 +0800 Subject: [PATCH] Add ConnectivityAnnotations class This change is to address API review, add respective @IntDef for network policy API. Typedef cannot be exposed as SystemApi so add ConnectivityAnnotations class and add an annotation library so that it can be used in module and platform. Bug: 183972925 Test: m, build doc target framework-doc-stubs_annotations.zip and check the APIs have an attribute IntDef annotation Change-Id: Ie3ec40cf48818edd422a4550377774eae387d3b2 --- framework/Android.bp | 16 ++++++ .../android/net/ConnectivityAnnotations.java | 51 +++++++++++++++++++ .../src/android/net/ConnectivityManager.java | 22 +------- .../net/ConnectivitySettingsManager.java | 2 +- service/Android.bp | 1 + .../android/server/ConnectivityService.java | 2 +- 6 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 framework/src/android/net/ConnectivityAnnotations.java diff --git a/framework/Android.bp b/framework/Android.bp index a75792c940..6eb83484cc 100644 --- a/framework/Android.bp +++ b/framework/Android.bp @@ -59,6 +59,22 @@ filegroup { ], } +java_library { + name: "framework-connectivity-annotations", + sdk_version: "module_current", + srcs: [ + "src/android/net/ConnectivityAnnotations.java", + ], + libs: [ + "framework-annotations-lib", + "framework-connectivity", + ], + visibility: [ + "//frameworks/base:__subpackages__", + "//packages/modules/Connectivity:__subpackages__", + ], +} + java_sdk_library { name: "framework-connectivity", sdk_version: "module_current", diff --git a/framework/src/android/net/ConnectivityAnnotations.java b/framework/src/android/net/ConnectivityAnnotations.java new file mode 100644 index 0000000000..eb1faa0aa2 --- /dev/null +++ b/framework/src/android/net/ConnectivityAnnotations.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2021 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 android.net; + +import android.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Type annotations for constants used in the connectivity API surface. + * + * The annotations are maintained in a separate class so that it can be built as + * a separate library that other modules can build against, as Typedef should not + * be exposed as SystemApi. + * + * @hide + */ +public final class ConnectivityAnnotations { + private ConnectivityAnnotations() {} + + @Retention(RetentionPolicy.SOURCE) + @IntDef(flag = true, value = { + ConnectivityManager.MULTIPATH_PREFERENCE_HANDOVER, + ConnectivityManager.MULTIPATH_PREFERENCE_RELIABILITY, + ConnectivityManager.MULTIPATH_PREFERENCE_PERFORMANCE, + }) + public @interface MultipathPreference {} + + @Retention(RetentionPolicy.SOURCE) + @IntDef(flag = false, value = { + ConnectivityManager.RESTRICT_BACKGROUND_STATUS_DISABLED, + ConnectivityManager.RESTRICT_BACKGROUND_STATUS_WHITELISTED, + ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED, + }) + public @interface RestrictBackgroundStatus {} +} diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java index df81603d00..5a53af44f5 100644 --- a/framework/src/android/net/ConnectivityManager.java +++ b/framework/src/android/net/ConnectivityManager.java @@ -40,6 +40,8 @@ import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.net.ConnectivityAnnotations.MultipathPreference; +import android.net.ConnectivityAnnotations.RestrictBackgroundStatus; import android.net.ConnectivityDiagnosticsManager.DataStallReport.DetectionMethod; import android.net.IpSecManager.UdpEncapsulationSocket; import android.net.SocketKeepalive.Callback; @@ -4799,16 +4801,6 @@ public class ConnectivityManager { MULTIPATH_PREFERENCE_RELIABILITY | MULTIPATH_PREFERENCE_PERFORMANCE; - /** @hide */ - @Retention(RetentionPolicy.SOURCE) - @IntDef(flag = true, value = { - MULTIPATH_PREFERENCE_HANDOVER, - MULTIPATH_PREFERENCE_RELIABILITY, - MULTIPATH_PREFERENCE_PERFORMANCE, - }) - public @interface MultipathPreference { - } - /** * Provides a hint to the calling application on whether it is desirable to use the * multinetwork APIs (e.g., {@link Network#openConnection}, {@link Network#bindSocket}, etc.) @@ -5030,16 +5022,6 @@ public class ConnectivityManager { public static final String ACTION_RESTRICT_BACKGROUND_CHANGED = "android.net.conn.RESTRICT_BACKGROUND_CHANGED"; - /** @hide */ - @Retention(RetentionPolicy.SOURCE) - @IntDef(flag = false, value = { - RESTRICT_BACKGROUND_STATUS_DISABLED, - RESTRICT_BACKGROUND_STATUS_WHITELISTED, - RESTRICT_BACKGROUND_STATUS_ENABLED, - }) - public @interface RestrictBackgroundStatus { - } - /** * Determines if the calling application is subject to metered network restrictions while * running on background. diff --git a/framework/src/android/net/ConnectivitySettingsManager.java b/framework/src/android/net/ConnectivitySettingsManager.java index 07754e4af2..bb2e62ef61 100644 --- a/framework/src/android/net/ConnectivitySettingsManager.java +++ b/framework/src/android/net/ConnectivitySettingsManager.java @@ -27,7 +27,7 @@ import android.annotation.Nullable; import android.annotation.SystemApi; import android.content.ContentResolver; import android.content.Context; -import android.net.ConnectivityManager.MultipathPreference; +import android.net.ConnectivityAnnotations.MultipathPreference; import android.os.Process; import android.os.UserHandle; import android.provider.Settings; diff --git a/service/Android.bp b/service/Android.bp index 813a239bda..72654260ae 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -65,6 +65,7 @@ java_library { "stable.core.platform.api.stubs", "android_system_server_stubs_current", "framework-annotations-lib", + "framework-connectivity-annotations", "framework-connectivity.impl", "framework-tethering.stubs.module_lib", "framework-wifi.stubs.module_lib", diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index ed2fe822de..6f1466ce91 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -105,12 +105,12 @@ import android.database.ContentObserver; import android.net.CaptivePortal; import android.net.CaptivePortalData; import android.net.ConnectionInfo; +import android.net.ConnectivityAnnotations.RestrictBackgroundStatus; import android.net.ConnectivityDiagnosticsManager.ConnectivityReport; import android.net.ConnectivityDiagnosticsManager.DataStallReport; import android.net.ConnectivityManager; import android.net.ConnectivityManager.BlockedReason; import android.net.ConnectivityManager.NetworkCallback; -import android.net.ConnectivityManager.RestrictBackgroundStatus; import android.net.ConnectivityResources; import android.net.ConnectivitySettingsManager; import android.net.DataStallReportParcelable;