|
|
|
|
@@ -30,7 +30,6 @@ import android.compat.annotation.UnsupportedAppUsage;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.OutcomeReceiver;
|
|
|
|
|
import android.os.RemoteException;
|
|
|
|
|
|
|
|
|
|
import com.android.internal.annotations.GuardedBy;
|
|
|
|
|
@@ -41,6 +40,7 @@ import java.lang.annotation.RetentionPolicy;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
|
import java.util.function.BiConsumer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A class that manages and configures Ethernet interfaces.
|
|
|
|
|
@@ -443,45 +443,41 @@ public class EthernetManager {
|
|
|
|
|
return new TetheredInterfaceRequest(mService, cbInternal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final class NetworkInterfaceOutcomeReceiver
|
|
|
|
|
extends INetworkInterfaceOutcomeReceiver.Stub {
|
|
|
|
|
private static final class InternalNetworkManagementListener
|
|
|
|
|
extends IEthernetNetworkManagementListener.Stub {
|
|
|
|
|
@NonNull
|
|
|
|
|
private final Executor mExecutor;
|
|
|
|
|
@NonNull
|
|
|
|
|
private final OutcomeReceiver<String, EthernetNetworkManagementException> mCallback;
|
|
|
|
|
private final BiConsumer<Network, EthernetNetworkManagementException> mListener;
|
|
|
|
|
|
|
|
|
|
NetworkInterfaceOutcomeReceiver(
|
|
|
|
|
InternalNetworkManagementListener(
|
|
|
|
|
@NonNull final Executor executor,
|
|
|
|
|
@NonNull final OutcomeReceiver<String, EthernetNetworkManagementException>
|
|
|
|
|
callback) {
|
|
|
|
|
@NonNull final BiConsumer<Network, EthernetNetworkManagementException> listener) {
|
|
|
|
|
Objects.requireNonNull(executor, "Pass a non-null executor");
|
|
|
|
|
Objects.requireNonNull(callback, "Pass a non-null callback");
|
|
|
|
|
Objects.requireNonNull(listener, "Pass a non-null listener");
|
|
|
|
|
mExecutor = executor;
|
|
|
|
|
mCallback = callback;
|
|
|
|
|
mListener = listener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onResult(@NonNull String iface) {
|
|
|
|
|
mExecutor.execute(() -> mCallback.onResult(iface));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(@NonNull EthernetNetworkManagementException e) {
|
|
|
|
|
mExecutor.execute(() -> mCallback.onError(e));
|
|
|
|
|
public void onComplete(
|
|
|
|
|
@Nullable final Network network,
|
|
|
|
|
@Nullable final EthernetNetworkManagementException e) {
|
|
|
|
|
mExecutor.execute(() -> mListener.accept(network, e));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private NetworkInterfaceOutcomeReceiver makeNetworkInterfaceOutcomeReceiver(
|
|
|
|
|
private InternalNetworkManagementListener getInternalNetworkManagementListener(
|
|
|
|
|
@Nullable final Executor executor,
|
|
|
|
|
@Nullable final OutcomeReceiver<String, EthernetNetworkManagementException> callback) {
|
|
|
|
|
if (null != callback) {
|
|
|
|
|
Objects.requireNonNull(executor, "Pass a non-null executor, or a null callback");
|
|
|
|
|
@Nullable final BiConsumer<Network, EthernetNetworkManagementException> listener) {
|
|
|
|
|
if (null != listener) {
|
|
|
|
|
Objects.requireNonNull(executor, "Pass a non-null executor, or a null listener");
|
|
|
|
|
}
|
|
|
|
|
final NetworkInterfaceOutcomeReceiver proxy;
|
|
|
|
|
if (null == callback) {
|
|
|
|
|
final InternalNetworkManagementListener proxy;
|
|
|
|
|
if (null == listener) {
|
|
|
|
|
proxy = null;
|
|
|
|
|
} else {
|
|
|
|
|
proxy = new NetworkInterfaceOutcomeReceiver(executor, callback);
|
|
|
|
|
proxy = new InternalNetworkManagementListener(executor, listener);
|
|
|
|
|
}
|
|
|
|
|
return proxy;
|
|
|
|
|
}
|
|
|
|
|
@@ -496,17 +492,14 @@ public class EthernetManager {
|
|
|
|
|
* Similarly, use {@link NetworkCapabilities.Builder} to build a {@code NetworkCapabilities}
|
|
|
|
|
* object for this network to put inside the {@code request}.
|
|
|
|
|
*
|
|
|
|
|
* This function accepts an {@link OutcomeReceiver} that is called once the operation has
|
|
|
|
|
* finished execution.
|
|
|
|
|
* If non-null, the listener will be called exactly once after this is called, unless
|
|
|
|
|
* a synchronous exception was thrown.
|
|
|
|
|
*
|
|
|
|
|
* @param iface the name of the interface to act upon.
|
|
|
|
|
* @param request the {@link EthernetNetworkUpdateRequest} used to set an ethernet network's
|
|
|
|
|
* {@link StaticIpConfiguration} and {@link NetworkCapabilities} values.
|
|
|
|
|
* @param executor an {@link Executor} to execute the callback on. Optional if callback is null.
|
|
|
|
|
* @param callback an optional {@link OutcomeReceiver} to listen for completion of the
|
|
|
|
|
* operation. On success, {@link OutcomeReceiver#onResult} is called with the
|
|
|
|
|
* interface name. On error, {@link OutcomeReceiver#onError} is called with more
|
|
|
|
|
* information about the error.
|
|
|
|
|
* @param executor an {@link Executor} to execute the listener on. Optional if listener is null.
|
|
|
|
|
* @param listener an optional {@link BiConsumer} to listen for completion of the operation.
|
|
|
|
|
* @throws SecurityException if the process doesn't hold
|
|
|
|
|
* {@link android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}.
|
|
|
|
|
* @throws UnsupportedOperationException if called on a non-automotive device or on an
|
|
|
|
|
@@ -522,11 +515,11 @@ public class EthernetManager {
|
|
|
|
|
@NonNull String iface,
|
|
|
|
|
@NonNull EthernetNetworkUpdateRequest request,
|
|
|
|
|
@Nullable @CallbackExecutor Executor executor,
|
|
|
|
|
@Nullable OutcomeReceiver<String, EthernetNetworkManagementException> callback) {
|
|
|
|
|
@Nullable BiConsumer<Network, EthernetNetworkManagementException> listener) {
|
|
|
|
|
Objects.requireNonNull(iface, "iface must be non-null");
|
|
|
|
|
Objects.requireNonNull(request, "request must be non-null");
|
|
|
|
|
final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver(
|
|
|
|
|
executor, callback);
|
|
|
|
|
final InternalNetworkManagementListener proxy = getInternalNetworkManagementListener(
|
|
|
|
|
executor, listener);
|
|
|
|
|
try {
|
|
|
|
|
mService.updateConfiguration(iface, request, proxy);
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
@@ -537,17 +530,15 @@ public class EthernetManager {
|
|
|
|
|
/**
|
|
|
|
|
* Set an ethernet network's link state up.
|
|
|
|
|
*
|
|
|
|
|
* When the link is successfully turned up, the callback will be called with the network
|
|
|
|
|
* interface was torn down, if any. If any error or unexpected condition happens while the
|
|
|
|
|
* system tries to turn the interface down, the callback will be called with an appropriate
|
|
|
|
|
* exception. The callback is guaranteed to be called exactly once for each call to this method.
|
|
|
|
|
* When the link is successfully turned up, the listener will be called with the resulting
|
|
|
|
|
* network. If any error or unexpected condition happens while the system tries to turn the
|
|
|
|
|
* interface up, the listener will be called with an appropriate exception.
|
|
|
|
|
* The listener is guaranteed to be called exactly once for each call to this method, but this
|
|
|
|
|
* may take an unbounded amount of time depending on the actual network conditions.
|
|
|
|
|
*
|
|
|
|
|
* @param iface the name of the interface to act upon.
|
|
|
|
|
* @param executor an {@link Executor} to execute the callback on. Optional if callback is null.
|
|
|
|
|
* @param callback an optional {@link OutcomeReceiver} to listen for completion of the
|
|
|
|
|
* operation. On success, {@link OutcomeReceiver#onResult} is called with the
|
|
|
|
|
* interface name. On error, {@link OutcomeReceiver#onError} is called with more
|
|
|
|
|
* information about the error.
|
|
|
|
|
* @param executor an {@link Executor} to execute the listener on. Optional if listener is null.
|
|
|
|
|
* @param listener an optional {@link BiConsumer} to listen for completion of the operation.
|
|
|
|
|
* @throws SecurityException if the process doesn't hold
|
|
|
|
|
* {@link android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}.
|
|
|
|
|
* @throws UnsupportedOperationException if called on a non-automotive device.
|
|
|
|
|
@@ -562,10 +553,10 @@ public class EthernetManager {
|
|
|
|
|
public void connectNetwork(
|
|
|
|
|
@NonNull String iface,
|
|
|
|
|
@Nullable @CallbackExecutor Executor executor,
|
|
|
|
|
@Nullable OutcomeReceiver<String, EthernetNetworkManagementException> callback) {
|
|
|
|
|
@Nullable BiConsumer<Network, EthernetNetworkManagementException> listener) {
|
|
|
|
|
Objects.requireNonNull(iface, "iface must be non-null");
|
|
|
|
|
final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver(
|
|
|
|
|
executor, callback);
|
|
|
|
|
final InternalNetworkManagementListener proxy = getInternalNetworkManagementListener(
|
|
|
|
|
executor, listener);
|
|
|
|
|
try {
|
|
|
|
|
mService.connectNetwork(iface, proxy);
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
@@ -576,17 +567,14 @@ public class EthernetManager {
|
|
|
|
|
/**
|
|
|
|
|
* Set an ethernet network's link state down.
|
|
|
|
|
*
|
|
|
|
|
* When the link is successfully turned down, the callback will be called with the network
|
|
|
|
|
* interface was torn down, if any. If any error or unexpected condition happens while the
|
|
|
|
|
* system tries to turn the interface down, the callback will be called with an appropriate
|
|
|
|
|
* exception. The callback is guaranteed to be called exactly once for each call to this method.
|
|
|
|
|
* When the link is successfully turned down, the listener will be called with the network that
|
|
|
|
|
* was torn down, if any. If any error or unexpected condition happens while the system tries to
|
|
|
|
|
* turn the interface down, the listener will be called with an appropriate exception.
|
|
|
|
|
* The listener is guaranteed to be called exactly once for each call to this method.
|
|
|
|
|
*
|
|
|
|
|
* @param iface the name of the interface to act upon.
|
|
|
|
|
* @param executor an {@link Executor} to execute the callback on. Optional if callback is null.
|
|
|
|
|
* @param callback an optional {@link OutcomeReceiver} to listen for completion of the
|
|
|
|
|
* operation. On success, {@link OutcomeReceiver#onResult} is called with the
|
|
|
|
|
* interface name. On error, {@link OutcomeReceiver#onError} is called with more
|
|
|
|
|
* information about the error.
|
|
|
|
|
* @param executor an {@link Executor} to execute the listener on. Optional if listener is null.
|
|
|
|
|
* @param listener an optional {@link BiConsumer} to listen for completion of the operation.
|
|
|
|
|
* @throws SecurityException if the process doesn't hold
|
|
|
|
|
* {@link android.Manifest.permission.MANAGE_ETHERNET_NETWORKS}.
|
|
|
|
|
* @throws UnsupportedOperationException if called on a non-automotive device.
|
|
|
|
|
@@ -601,10 +589,10 @@ public class EthernetManager {
|
|
|
|
|
public void disconnectNetwork(
|
|
|
|
|
@NonNull String iface,
|
|
|
|
|
@Nullable @CallbackExecutor Executor executor,
|
|
|
|
|
@Nullable OutcomeReceiver<String, EthernetNetworkManagementException> callback) {
|
|
|
|
|
@Nullable BiConsumer<Network, EthernetNetworkManagementException> listener) {
|
|
|
|
|
Objects.requireNonNull(iface, "iface must be non-null");
|
|
|
|
|
final NetworkInterfaceOutcomeReceiver proxy = makeNetworkInterfaceOutcomeReceiver(
|
|
|
|
|
executor, callback);
|
|
|
|
|
final InternalNetworkManagementListener proxy = getInternalNetworkManagementListener(
|
|
|
|
|
executor, listener);
|
|
|
|
|
try {
|
|
|
|
|
mService.disconnectNetwork(iface, proxy);
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
|