From f47d83448c89de1257996b60754b03b3741b2305 Mon Sep 17 00:00:00 2001 From: markchien Date: Thu, 19 Mar 2020 13:37:43 +0800 Subject: [PATCH] TetheringManager API clean up Per API review: - @IntDef defined on the type integer parameter - have getters on each parameter that is set in the TetheringRequest.Builder - new added API should not be deprecated Below APIs is moved from system-current to module-lib-current that only plafrom code(e.g. ConnectivityManager and Settings) can use them. TetheringRequest. onTetherableInterfaceRegexpsChanged, TetheringInterfaceRegexps: Only platform code can use them because interfaces by regular expressions are a mechanism which is planning to be deprecated. Also rename some constants for easier to understand. Bug: 149858697 Bug: 151243337 Test: m doc-comment-check-docs atest TetheringTests Change-Id: I45cb21d5bc919f6d32c42650326597d5173ea028 Merged-In: Idd041f0fbeca411ea23e49786a50dd7feb77ef45 --- .../java/android/net/ConnectivityManager.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 629de1dfde..df92be8ceb 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -2488,13 +2488,13 @@ public class ConnectivityManager { } @Override - public void onTetheringFailed(final int resultCode) { + public void onTetheringFailed(final int error) { callback.onTetheringFailed(); } }; final TetheringRequest request = new TetheringRequest.Builder(type) - .setSilentProvisioning(!showProvisioningUi).build(); + .setShouldShowEntitlementUi(showProvisioningUi).build(); mTetheringManager.startTethering(request, executor, tetheringCallback); } @@ -2714,11 +2714,12 @@ public class ConnectivityManager { public static final int TETHER_ERROR_UNAVAIL_IFACE = TetheringManager.TETHER_ERROR_UNAVAIL_IFACE; /** - * @deprecated Use {@link TetheringManager#TETHER_ERROR_MASTER_ERROR}. + * @deprecated Use {@link TetheringManager#TETHER_ERROR_INTERNAL_ERROR}. * {@hide} */ @Deprecated - public static final int TETHER_ERROR_MASTER_ERROR = TetheringManager.TETHER_ERROR_MASTER_ERROR; + public static final int TETHER_ERROR_MASTER_ERROR = + TetheringManager.TETHER_ERROR_INTERNAL_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_TETHER_IFACE_ERROR}. * {@hide} @@ -2734,19 +2735,19 @@ public class ConnectivityManager { public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = TetheringManager.TETHER_ERROR_UNTETHER_IFACE_ERROR; /** - * @deprecated Use {@link TetheringManager#TETHER_ERROR_ENABLE_NAT_ERROR}. + * @deprecated Use {@link TetheringManager#TETHER_ERROR_ENABLE_FORWARDING_ERROR}. * {@hide} */ @Deprecated public static final int TETHER_ERROR_ENABLE_NAT_ERROR = - TetheringManager.TETHER_ERROR_ENABLE_NAT_ERROR; + TetheringManager.TETHER_ERROR_ENABLE_FORWARDING_ERROR; /** - * @deprecated Use {@link TetheringManager#TETHER_ERROR_DISABLE_NAT_ERROR}. + * @deprecated Use {@link TetheringManager#TETHER_ERROR_DISABLE_FORWARDING_ERROR}. * {@hide} */ @Deprecated public static final int TETHER_ERROR_DISABLE_NAT_ERROR = - TetheringManager.TETHER_ERROR_DISABLE_NAT_ERROR; + TetheringManager.TETHER_ERROR_DISABLE_FORWARDING_ERROR; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_IFACE_CFG_ERROR}. * {@hide} @@ -2755,13 +2756,13 @@ public class ConnectivityManager { public static final int TETHER_ERROR_IFACE_CFG_ERROR = TetheringManager.TETHER_ERROR_IFACE_CFG_ERROR; /** - * @deprecated Use {@link TetheringManager#TETHER_ERROR_PROVISION_FAILED}. + * @deprecated Use {@link TetheringManager#TETHER_ERROR_PROVISIONING_FAILED}. * {@hide} */ @SystemApi @Deprecated public static final int TETHER_ERROR_PROVISION_FAILED = - TetheringManager.TETHER_ERROR_PROVISION_FAILED; + TetheringManager.TETHER_ERROR_PROVISIONING_FAILED; /** * @deprecated Use {@link TetheringManager#TETHER_ERROR_DHCPSERVER_ERROR}. * {@hide} @@ -2793,7 +2794,14 @@ public class ConnectivityManager { @UnsupportedAppUsage @Deprecated public int getLastTetherError(String iface) { - return mTetheringManager.getLastTetherError(iface); + int error = mTetheringManager.getLastTetherError(iface); + if (error == TetheringManager.TETHER_ERROR_UNKNOWN_TYPE) { + // TETHER_ERROR_UNKNOWN_TYPE was introduced with TetheringManager and has never been + // returned by ConnectivityManager. Convert it to the legacy TETHER_ERROR_UNKNOWN_IFACE + // instead. + error = TetheringManager.TETHER_ERROR_UNKNOWN_IFACE; + } + return error; } /** @hide */