From 4d5537853a9e141be4da87293de54ea7df322d6c Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Wed, 22 Jan 2020 22:52:03 +0900 Subject: [PATCH] Update NetworkInfo public API. Wifi needs to create these objects so it can include them in the broadcasts. Bug: 135998869 Test: FrameworksWifiTests Change-Id: Ic50d9b5c65e8771708620badc3bc242a8ffbb5cc Merged-In: Ic50d9b5c65e8771708620badc3bc242a8ffbb5cc --- core/java/android/net/NetworkInfo.java | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/java/android/net/NetworkInfo.java b/core/java/android/net/NetworkInfo.java index d0c5363165..08fe159b27 100644 --- a/core/java/android/net/NetworkInfo.java +++ b/core/java/android/net/NetworkInfo.java @@ -17,9 +17,11 @@ package android.net; import android.annotation.NonNull; +import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; +import android.telephony.Annotation.NetworkType; import com.android.internal.annotations.VisibleForTesting; @@ -150,10 +152,19 @@ public class NetworkInfo implements Parcelable { private boolean mIsRoaming; /** - * @hide + * Create a new instance of NetworkInfo. + * + * This may be useful for apps to write unit tests. + * + * @param type the legacy type of the network, as one of the ConnectivityManager.TYPE_* + * constants. + * @param subtype the subtype if applicable, as one of the TelephonyManager.NETWORK_TYPE_* + * constants. + * @param typeName a human-readable string for the network type, or an empty string or null. + * @param subtypeName a human-readable string for the subtype, or an empty string or null. */ - @UnsupportedAppUsage - public NetworkInfo(int type, int subtype, String typeName, String subtypeName) { + public NetworkInfo(int type, @NetworkType int subtype, + @Nullable String typeName, @Nullable String subtypeName) { if (!ConnectivityManager.isNetworkTypeValid(type) && type != ConnectivityManager.TYPE_NONE) { throw new IllegalArgumentException("Invalid network type: " + type); @@ -462,17 +473,19 @@ public class NetworkInfo implements Parcelable { /** * Sets the fine-grained state of the network. + * + * This is only useful for testing. + * * @param detailedState the {@link DetailedState}. * @param reason a {@code String} indicating the reason for the state change, * if one was supplied. May be {@code null}. * @param extraInfo an optional {@code String} providing addditional network state * information passed up from the lower networking layers. * @deprecated Use {@link NetworkCapabilities} instead. - * @hide */ @Deprecated - @UnsupportedAppUsage - public void setDetailedState(DetailedState detailedState, String reason, String extraInfo) { + public void setDetailedState(@NonNull DetailedState detailedState, @Nullable String reason, + @Nullable String extraInfo) { synchronized (this) { this.mDetailedState = detailedState; this.mState = stateMap.get(detailedState);