Merge "Make TetheringManager to system API"

This commit is contained in:
Remi NGUYEN VAN
2020-01-23 00:11:49 +00:00
committed by Android (Google) Code Review

View File

@@ -33,6 +33,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.IpSecManager.UdpEncapsulationSocket; import android.net.IpSecManager.UdpEncapsulationSocket;
import android.net.SocketKeepalive.Callback; import android.net.SocketKeepalive.Callback;
import android.net.TetheringManager.TetheringEventCallback;
import android.os.Binder; import android.os.Binder;
import android.os.Build; import android.os.Build;
import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES;
@@ -58,6 +59,7 @@ import android.util.ArrayMap;
import android.util.Log; import android.util.Log;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions; import com.android.internal.util.Preconditions;
import com.android.internal.util.Protocol; import com.android.internal.util.Protocol;
@@ -75,6 +77,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@@ -484,34 +487,35 @@ public class ConnectivityManager {
* enable if any. * enable if any.
* @hide * @hide
*/ */
public static final String EXTRA_ADD_TETHER_TYPE = TetheringManager.EXTRA_ADD_TETHER_TYPE; public static final String EXTRA_ADD_TETHER_TYPE = TetheringConstants.EXTRA_ADD_TETHER_TYPE;
/** /**
* Extra used for communicating with the TetherService. Includes the type of tethering for * Extra used for communicating with the TetherService. Includes the type of tethering for
* which to cancel provisioning. * which to cancel provisioning.
* @hide * @hide
*/ */
public static final String EXTRA_REM_TETHER_TYPE = TetheringManager.EXTRA_REM_TETHER_TYPE; public static final String EXTRA_REM_TETHER_TYPE = TetheringConstants.EXTRA_REM_TETHER_TYPE;
/** /**
* Extra used for communicating with the TetherService. True to schedule a recheck of tether * Extra used for communicating with the TetherService. True to schedule a recheck of tether
* provisioning. * provisioning.
* @hide * @hide
*/ */
public static final String EXTRA_SET_ALARM = TetheringManager.EXTRA_SET_ALARM; public static final String EXTRA_SET_ALARM = TetheringConstants.EXTRA_SET_ALARM;
/** /**
* Tells the TetherService to run a provision check now. * Tells the TetherService to run a provision check now.
* @hide * @hide
*/ */
public static final String EXTRA_RUN_PROVISION = TetheringManager.EXTRA_RUN_PROVISION; public static final String EXTRA_RUN_PROVISION = TetheringConstants.EXTRA_RUN_PROVISION;
/** /**
* Extra used for communicating with the TetherService. Contains the {@link ResultReceiver} * Extra used for communicating with the TetherService. Contains the {@link ResultReceiver}
* which will receive provisioning results. Can be left empty. * which will receive provisioning results. Can be left empty.
* @hide * @hide
*/ */
public static final String EXTRA_PROVISION_CALLBACK = TetheringManager.EXTRA_PROVISION_CALLBACK; public static final String EXTRA_PROVISION_CALLBACK =
TetheringConstants.EXTRA_PROVISION_CALLBACK;
/** /**
* The absence of a connection type. * The absence of a connection type.
@@ -2368,10 +2372,12 @@ public class ConnectivityManager {
* *
* @return an array of 0 or more Strings of tetherable interface names. * @return an array of 0 or more Strings of tetherable interface names.
* *
* @deprecated Use {@link TetheringEventCallback#onTetherableInterfacesChanged(List)} instead.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public String[] getTetherableIfaces() { public String[] getTetherableIfaces() {
return getTetheringManager().getTetherableIfaces(); return getTetheringManager().getTetherableIfaces();
} }
@@ -2381,10 +2387,12 @@ public class ConnectivityManager {
* *
* @return an array of 0 or more String of currently tethered interface names. * @return an array of 0 or more String of currently tethered interface names.
* *
* @deprecated Use {@link TetheringEventCallback#onTetherableInterfacesChanged(List)} instead.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public String[] getTetheredIfaces() { public String[] getTetheredIfaces() {
return getTetheringManager().getTetheredIfaces(); return getTetheringManager().getTetheredIfaces();
} }
@@ -2400,10 +2408,12 @@ public class ConnectivityManager {
* @return an array of 0 or more String indicating the interface names * @return an array of 0 or more String indicating the interface names
* which failed to tether. * which failed to tether.
* *
* @deprecated Use {@link TetheringEventCallback#onError(String, int)} instead.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public String[] getTetheringErroredIfaces() { public String[] getTetheringErroredIfaces() {
return getTetheringManager().getTetheringErroredIfaces(); return getTetheringManager().getTetheringErroredIfaces();
} }
@@ -2412,9 +2422,11 @@ public class ConnectivityManager {
* Get the set of tethered dhcp ranges. * Get the set of tethered dhcp ranges.
* *
* @return an array of 0 or more {@code String} of tethered dhcp ranges. * @return an array of 0 or more {@code String} of tethered dhcp ranges.
* @deprecated This API just return the default value which is not used in DhcpServer.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS) @RequiresPermission(android.Manifest.permission.NETWORK_SETTINGS)
@Deprecated
public String[] getTetheredDhcpRanges() { public String[] getTetheredDhcpRanges() {
return getTetheringManager().getTetheredDhcpRanges(); return getTetheringManager().getTetheredDhcpRanges();
} }
@@ -2467,6 +2479,7 @@ public class ConnectivityManager {
* {@hide} * {@hide}
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public int untether(String iface) { public int untether(String iface) {
return getTetheringManager().untether(iface); return getTetheringManager().untether(iface);
} }
@@ -2487,6 +2500,7 @@ public class ConnectivityManager {
* *
* @return a boolean - {@code true} indicating Tethering is supported. * @return a boolean - {@code true} indicating Tethering is supported.
* *
* @deprecated Use {@link TetheringEventCallback#onTetheringSupported(boolean)} instead.
* {@hide} * {@hide}
*/ */
@SystemApi @SystemApi
@@ -2573,9 +2587,12 @@ public class ConnectivityManager {
* {@link ConnectivityManager.TETHERING_WIFI}, * {@link ConnectivityManager.TETHERING_WIFI},
* {@link ConnectivityManager.TETHERING_USB}, or * {@link ConnectivityManager.TETHERING_USB}, or
* {@link ConnectivityManager.TETHERING_BLUETOOTH}. * {@link ConnectivityManager.TETHERING_BLUETOOTH}.
*
* @deprecated Use {@link TetheringManager#stopTethering} instead.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void stopTethering(int type) { public void stopTethering(int type) {
getTetheringManager().stopTethering(type); getTetheringManager().stopTethering(type);
@@ -2585,9 +2602,11 @@ public class ConnectivityManager {
* Callback for use with {@link registerTetheringEventCallback} to find out tethering * Callback for use with {@link registerTetheringEventCallback} to find out tethering
* upstream status. * upstream status.
* *
*@hide * @deprecated Use {@line TetheringManager#OnTetheringEventCallback} instead.
* @hide
*/ */
@SystemApi @SystemApi
@Deprecated
public abstract static class OnTetheringEventCallback { public abstract static class OnTetheringEventCallback {
/** /**
@@ -2600,6 +2619,10 @@ public class ConnectivityManager {
public void onUpstreamChanged(@Nullable Network network) {} public void onUpstreamChanged(@Nullable Network network) {}
} }
@GuardedBy("mTetheringEventCallbacks")
private final ArrayMap<OnTetheringEventCallback, TetheringEventCallback>
mTetheringEventCallbacks = new ArrayMap<>();
/** /**
* Start listening to tethering change events. Any new added callback will receive the last * Start listening to tethering change events. Any new added callback will receive the last
* tethering status right away. If callback is registered when tethering has no upstream or * tethering status right away. If callback is registered when tethering has no upstream or
@@ -2608,16 +2631,30 @@ public class ConnectivityManager {
* *
* @param executor the executor on which callback will be invoked. * @param executor the executor on which callback will be invoked.
* @param callback the callback to be called when tethering has change events. * @param callback the callback to be called when tethering has change events.
*
* @deprecated Use {@line TetheringManager#registerTetheringEventCallback} instead.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void registerTetheringEventCallback( public void registerTetheringEventCallback(
@NonNull @CallbackExecutor Executor executor, @NonNull @CallbackExecutor Executor executor,
@NonNull final OnTetheringEventCallback callback) { @NonNull final OnTetheringEventCallback callback) {
Preconditions.checkNotNull(callback, "OnTetheringEventCallback cannot be null."); Preconditions.checkNotNull(callback, "OnTetheringEventCallback cannot be null.");
getTetheringManager().registerTetheringEventCallback(executor, callback); final TetheringEventCallback tetherCallback =
new TetheringEventCallback() {
@Override
public void onUpstreamChanged(@Nullable Network network) {
callback.onUpstreamChanged(network);
}
};
synchronized (mTetheringEventCallbacks) {
mTetheringEventCallbacks.put(callback, tetherCallback);
getTetheringManager().registerTetheringEventCallback(executor, tetherCallback);
}
} }
/** /**
@@ -2625,13 +2662,21 @@ public class ConnectivityManager {
* {@link #registerTetheringEventCallback}. * {@link #registerTetheringEventCallback}.
* *
* @param callback previously registered callback. * @param callback previously registered callback.
*
* @deprecated Use {@link TetheringManager#unregisterTetheringEventCallback} instead.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void unregisterTetheringEventCallback( public void unregisterTetheringEventCallback(
@NonNull final OnTetheringEventCallback callback) { @NonNull final OnTetheringEventCallback callback) {
getTetheringManager().unregisterTetheringEventCallback(callback); Objects.requireNonNull(callback, "The callback must be non-null");
synchronized (mTetheringEventCallbacks) {
final TetheringEventCallback tetherCallback =
mTetheringEventCallbacks.remove(callback);
getTetheringManager().unregisterTetheringEventCallback(tetherCallback);
}
} }
@@ -2643,10 +2688,12 @@ public class ConnectivityManager {
* @return an array of 0 or more regular expression Strings defining * @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable usb interfaces. * what interfaces are considered tetherable usb interfaces.
* *
* @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged} instead.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public String[] getTetherableUsbRegexs() { public String[] getTetherableUsbRegexs() {
return getTetheringManager().getTetherableUsbRegexs(); return getTetheringManager().getTetherableUsbRegexs();
} }
@@ -2659,10 +2706,12 @@ public class ConnectivityManager {
* @return an array of 0 or more regular expression Strings defining * @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable wifi interfaces. * what interfaces are considered tetherable wifi interfaces.
* *
* @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged} instead.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public String[] getTetherableWifiRegexs() { public String[] getTetherableWifiRegexs() {
return getTetheringManager().getTetherableWifiRegexs(); return getTetheringManager().getTetherableWifiRegexs();
} }
@@ -2675,10 +2724,13 @@ public class ConnectivityManager {
* @return an array of 0 or more regular expression Strings defining * @return an array of 0 or more regular expression Strings defining
* what interfaces are considered tetherable bluetooth interfaces. * what interfaces are considered tetherable bluetooth interfaces.
* *
* @deprecated Use {@link TetheringEventCallback#onTetherableInterfaceRegexpsChanged(
*TetheringManager.TetheringInterfaceRegexps)} instead.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public String[] getTetherableBluetoothRegexs() { public String[] getTetherableBluetoothRegexs() {
return getTetheringManager().getTetherableBluetoothRegexs(); return getTetheringManager().getTetherableBluetoothRegexs();
} }
@@ -2705,37 +2757,104 @@ public class ConnectivityManager {
return getTetheringManager().setUsbTethering(enable); return getTetheringManager().setUsbTethering(enable);
} }
/** {@hide} */ /**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_NO_ERROR}.
* {@hide}
*/
@SystemApi @SystemApi
public static final int TETHER_ERROR_NO_ERROR = 0; @Deprecated
/** {@hide} */ public static final int TETHER_ERROR_NO_ERROR = TetheringManager.TETHER_ERROR_NO_ERROR;
public static final int TETHER_ERROR_UNKNOWN_IFACE = 1; /**
/** {@hide} */ * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNKNOWN_IFACE}.
public static final int TETHER_ERROR_SERVICE_UNAVAIL = 2; * {@hide}
/** {@hide} */ */
public static final int TETHER_ERROR_UNSUPPORTED = 3; @Deprecated
/** {@hide} */ public static final int TETHER_ERROR_UNKNOWN_IFACE =
public static final int TETHER_ERROR_UNAVAIL_IFACE = 4; TetheringManager.TETHER_ERROR_UNKNOWN_IFACE;
/** {@hide} */ /**
public static final int TETHER_ERROR_MASTER_ERROR = 5; * @deprecated Use {@link TetheringManager#TETHER_ERROR_SERVICE_UNAVAIL}.
/** {@hide} */ * {@hide}
public static final int TETHER_ERROR_TETHER_IFACE_ERROR = 6; */
/** {@hide} */ @Deprecated
public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR = 7; public static final int TETHER_ERROR_SERVICE_UNAVAIL =
/** {@hide} */ TetheringManager.TETHER_ERROR_SERVICE_UNAVAIL;
public static final int TETHER_ERROR_ENABLE_NAT_ERROR = 8; /**
/** {@hide} */ * @deprecated Use {@link TetheringManager#TETHER_ERROR_UNSUPPORTED}.
public static final int TETHER_ERROR_DISABLE_NAT_ERROR = 9; * {@hide}
/** {@hide} */ */
public static final int TETHER_ERROR_IFACE_CFG_ERROR = 10; @Deprecated
/** {@hide} */ public static final int TETHER_ERROR_UNSUPPORTED = TetheringManager.TETHER_ERROR_UNSUPPORTED;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_UNAVAIL_IFACE}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_UNAVAIL_IFACE =
TetheringManager.TETHER_ERROR_UNAVAIL_IFACE;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_MASTER_ERROR}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_MASTER_ERROR = TetheringManager.TETHER_ERROR_MASTER_ERROR;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_TETHER_IFACE_ERROR}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_TETHER_IFACE_ERROR =
TetheringManager.TETHER_ERROR_TETHER_IFACE_ERROR;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_UNTETHER_IFACE_ERROR}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_UNTETHER_IFACE_ERROR =
TetheringManager.TETHER_ERROR_UNTETHER_IFACE_ERROR;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_ENABLE_NAT_ERROR}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_ENABLE_NAT_ERROR =
TetheringManager.TETHER_ERROR_ENABLE_NAT_ERROR;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_DISABLE_NAT_ERROR}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_DISABLE_NAT_ERROR =
TetheringManager.TETHER_ERROR_DISABLE_NAT_ERROR;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_IFACE_CFG_ERROR}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_IFACE_CFG_ERROR =
TetheringManager.TETHER_ERROR_IFACE_CFG_ERROR;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_PROVISION_FAILED}.
* {@hide}
*/
@SystemApi @SystemApi
public static final int TETHER_ERROR_PROVISION_FAILED = 11; @Deprecated
/** {@hide} */ public static final int TETHER_ERROR_PROVISION_FAILED =
public static final int TETHER_ERROR_DHCPSERVER_ERROR = 12; TetheringManager.TETHER_ERROR_PROVISION_FAILED;
/** {@hide} */ /**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_DHCPSERVER_ERROR}.
* {@hide}
*/
@Deprecated
public static final int TETHER_ERROR_DHCPSERVER_ERROR =
TetheringManager.TETHER_ERROR_DHCPSERVER_ERROR;
/**
* @deprecated Use {@link TetheringManager#TETHER_ERROR_ENTITLEMENT_UNKNOWN}.
* {@hide}
*/
@SystemApi @SystemApi
public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN = 13; @Deprecated
public static final int TETHER_ERROR_ENTITLEMENT_UNKONWN =
TetheringManager.TETHER_ERROR_ENTITLEMENT_UNKNOWN;
/** /**
* Get a more detailed error code after a Tethering or Untethering * Get a more detailed error code after a Tethering or Untethering
@@ -2745,10 +2864,12 @@ public class ConnectivityManager {
* @return error The error code of the last error tethering or untethering the named * @return error The error code of the last error tethering or untethering the named
* interface * interface
* *
* @deprecated Use {@link TetheringEventCallback#onError(String, int)} instead.
* {@hide} * {@hide}
*/ */
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE) @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public int getLastTetherError(String iface) { public int getLastTetherError(String iface) {
return getTetheringManager().getLastTetherError(iface); return getTetheringManager().getLastTetherError(iface);
} }
@@ -2766,9 +2887,12 @@ public class ConnectivityManager {
/** /**
* Callback for use with {@link #getLatestTetheringEntitlementResult} to find out whether * Callback for use with {@link #getLatestTetheringEntitlementResult} to find out whether
* entitlement succeeded. * entitlement succeeded.
*
* @deprecated Use {@link TetheringManager#OnTetheringEntitlementResultListener} instead.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@Deprecated
public interface OnTetheringEntitlementResultListener { public interface OnTetheringEntitlementResultListener {
/** /**
* Called to notify entitlement result. * Called to notify entitlement result.
@@ -2798,9 +2922,11 @@ public class ConnectivityManager {
* @param listener an {@link OnTetheringEntitlementResultListener} which will be called to * @param listener an {@link OnTetheringEntitlementResultListener} which will be called to
* notify the caller of the result of entitlement check. The listener may be called zero * notify the caller of the result of entitlement check. The listener may be called zero
* or one time. * or one time.
* @deprecated Use {@link TetheringManager#requestLatestTetheringEntitlementResult} instead.
* {@hide} * {@hide}
*/ */
@SystemApi @SystemApi
@Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void getLatestTetheringEntitlementResult(int type, boolean showEntitlementUi, public void getLatestTetheringEntitlementResult(int type, boolean showEntitlementUi,
@NonNull @CallbackExecutor Executor executor, @NonNull @CallbackExecutor Executor executor,