Allows the caller to specify configuration by TetheringRequest am: 91c78e57df am: a64e1cce4e

Change-Id: Icb6d93cc76b7d5511ec0c556c0ed512198bfb781
This commit is contained in:
Automerger Merge Worker
2020-01-24 16:49:44 +00:00

View File

@@ -33,7 +33,9 @@ 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.StartTetheringCallback;
import android.net.TetheringManager.TetheringEventCallback; import android.net.TetheringManager.TetheringEventCallback;
import android.net.TetheringManager.TetheringRequest;
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;
@@ -2453,10 +2455,12 @@ public class ConnectivityManager {
* *
* @param iface the interface name to tether. * @param iface the interface name to tether.
* @return error a {@code TETHER_ERROR} value indicating success or failure type * @return error a {@code TETHER_ERROR} value indicating success or failure type
* @deprecated Use {@link TetheringManager#startTethering} instead
* *
* {@hide} * {@hide}
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public int tether(String iface) { public int tether(String iface) {
return getTetheringManager().tether(iface); return getTetheringManager().tether(iface);
} }
@@ -2513,9 +2517,12 @@ public class ConnectivityManager {
/** /**
* Callback for use with {@link #startTethering} to find out whether tethering succeeded. * Callback for use with {@link #startTethering} to find out whether tethering succeeded.
*
* @deprecated Use {@link TetheringManager.StartTetheringCallback} instead.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@Deprecated
public static abstract class OnStartTetheringCallback { public static abstract class OnStartTetheringCallback {
/** /**
* Called when tethering has been successfully started. * Called when tethering has been successfully started.
@@ -2532,9 +2539,12 @@ public class ConnectivityManager {
* Convenient overload for * Convenient overload for
* {@link #startTethering(int, boolean, OnStartTetheringCallback, Handler)} which passes a null * {@link #startTethering(int, boolean, OnStartTetheringCallback, Handler)} which passes a null
* handler to run on the current thread's {@link Looper}. * handler to run on the current thread's {@link Looper}.
*
* @deprecated Use {@link TetheringManager#startTethering} instead.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void startTethering(int type, boolean showProvisioningUi, public void startTethering(int type, boolean showProvisioningUi,
final OnStartTetheringCallback callback) { final OnStartTetheringCallback callback) {
@@ -2558,26 +2568,44 @@ public class ConnectivityManager {
* @param callback an {@link OnStartTetheringCallback} which will be called to notify the caller * @param callback an {@link OnStartTetheringCallback} which will be called to notify the caller
* of the result of trying to tether. * of the result of trying to tether.
* @param handler {@link Handler} to specify the thread upon which the callback will be invoked. * @param handler {@link Handler} to specify the thread upon which the callback will be invoked.
*
* @deprecated Use {@link TetheringManager#startTethering} instead.
* @hide * @hide
*/ */
@SystemApi @SystemApi
@Deprecated
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void startTethering(int type, boolean showProvisioningUi, public void startTethering(int type, boolean showProvisioningUi,
final OnStartTetheringCallback callback, Handler handler) { final OnStartTetheringCallback callback, Handler handler) {
Preconditions.checkNotNull(callback, "OnStartTetheringCallback cannot be null."); Preconditions.checkNotNull(callback, "OnStartTetheringCallback cannot be null.");
ResultReceiver wrappedCallback = new ResultReceiver(handler) { final Executor executor = new Executor() {
@Override @Override
protected void onReceiveResult(int resultCode, Bundle resultData) { public void execute(Runnable command) {
if (resultCode == TETHER_ERROR_NO_ERROR) { if (handler == null) {
callback.onTetheringStarted(); command.run();
} else { } else {
callback.onTetheringFailed(); handler.post(command);
} }
} }
}; };
getTetheringManager().startTethering(type, wrappedCallback, showProvisioningUi); final StartTetheringCallback tetheringCallback = new StartTetheringCallback() {
@Override
public void onTetheringStarted() {
callback.onTetheringStarted();
}
@Override
public void onTetheringFailed(final int resultCode) {
callback.onTetheringFailed();
}
};
final TetheringRequest request = new TetheringRequest.Builder(type)
.setSilentProvisioning(!showProvisioningUi).build();
getTetheringManager().startTethering(request, executor, tetheringCallback);
} }
/** /**
@@ -2750,10 +2778,12 @@ public class ConnectivityManager {
* *
* @param enable a boolean - {@code true} to enable tethering * @param enable a boolean - {@code true} to enable tethering
* @return error a {@code TETHER_ERROR} value indicating success or failure type * @return error a {@code TETHER_ERROR} value indicating success or failure type
* @deprecated Use {@link TetheringManager#startTethering} instead
* *
* {@hide} * {@hide}
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
@Deprecated
public int setUsbTethering(boolean enable) { public int setUsbTethering(boolean enable) {
return getTetheringManager().setUsbTethering(enable); return getTetheringManager().setUsbTethering(enable);
} }