Merge "Mark TestNetworkManager as module API"
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import android.annotation.TestApi;
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.SystemApi;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -25,9 +26,11 @@ import android.os.Parcelable;
|
|||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@TestApi
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
public final class TestNetworkInterface implements Parcelable {
|
public final class TestNetworkInterface implements Parcelable {
|
||||||
|
@NonNull
|
||||||
private final ParcelFileDescriptor mFileDescriptor;
|
private final ParcelFileDescriptor mFileDescriptor;
|
||||||
|
@NonNull
|
||||||
private final String mInterfaceName;
|
private final String mInterfaceName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,29 +39,32 @@ public final class TestNetworkInterface implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel out, int flags) {
|
public void writeToParcel(@NonNull Parcel out, int flags) {
|
||||||
out.writeParcelable(mFileDescriptor, PARCELABLE_WRITE_RETURN_VALUE);
|
out.writeParcelable(mFileDescriptor, PARCELABLE_WRITE_RETURN_VALUE);
|
||||||
out.writeString(mInterfaceName);
|
out.writeString(mInterfaceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestNetworkInterface(ParcelFileDescriptor pfd, String intf) {
|
public TestNetworkInterface(@NonNull ParcelFileDescriptor pfd, @NonNull String intf) {
|
||||||
mFileDescriptor = pfd;
|
mFileDescriptor = pfd;
|
||||||
mInterfaceName = intf;
|
mInterfaceName = intf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TestNetworkInterface(Parcel in) {
|
private TestNetworkInterface(@NonNull Parcel in) {
|
||||||
mFileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
|
mFileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
|
||||||
mInterfaceName = in.readString();
|
mInterfaceName = in.readString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ParcelFileDescriptor getFileDescriptor() {
|
public ParcelFileDescriptor getFileDescriptor() {
|
||||||
return mFileDescriptor;
|
return mFileDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getInterfaceName() {
|
public String getInterfaceName() {
|
||||||
return mInterfaceName;
|
return mInterfaceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static final Parcelable.Creator<TestNetworkInterface> CREATOR =
|
public static final Parcelable.Creator<TestNetworkInterface> CREATOR =
|
||||||
new Parcelable.Creator<TestNetworkInterface>() {
|
new Parcelable.Creator<TestNetworkInterface>() {
|
||||||
public TestNetworkInterface createFromParcel(Parcel in) {
|
public TestNetworkInterface createFromParcel(Parcel in) {
|
||||||
|
|||||||
@@ -17,18 +17,21 @@ package android.net;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.TestApi;
|
import android.annotation.SystemApi;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
import com.android.internal.util.Preconditions;
|
import com.android.internal.util.Preconditions;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that allows creation and management of per-app, test-only networks
|
* Class that allows creation and management of per-app, test-only networks
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@TestApi
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
public class TestNetworkManager {
|
public class TestNetworkManager {
|
||||||
/**
|
/**
|
||||||
* Prefix for tun interfaces created by this class.
|
* Prefix for tun interfaces created by this class.
|
||||||
@@ -57,7 +60,7 @@ public class TestNetworkManager {
|
|||||||
* @param network The test network that should be torn down
|
* @param network The test network that should be torn down
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@TestApi
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
public void teardownTestNetwork(@NonNull Network network) {
|
public void teardownTestNetwork(@NonNull Network network) {
|
||||||
try {
|
try {
|
||||||
mService.teardownTestNetwork(network.netId);
|
mService.teardownTestNetwork(network.netId);
|
||||||
@@ -102,7 +105,7 @@ public class TestNetworkManager {
|
|||||||
* @param binder A binder object guarding the lifecycle of this test network.
|
* @param binder A binder object guarding the lifecycle of this test network.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@TestApi
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
||||||
setupTestNetwork(iface, null, true, new int[0], binder);
|
setupTestNetwork(iface, null, true, new int[0], binder);
|
||||||
}
|
}
|
||||||
@@ -127,12 +130,29 @@ public class TestNetworkManager {
|
|||||||
* @param linkAddrs an array of LinkAddresses to assign to the TUN interface
|
* @param linkAddrs an array of LinkAddresses to assign to the TUN interface
|
||||||
* @return A ParcelFileDescriptor of the underlying TUN interface. Close this to tear down the
|
* @return A ParcelFileDescriptor of the underlying TUN interface. Close this to tear down the
|
||||||
* TUN interface.
|
* TUN interface.
|
||||||
|
* @deprecated Use {@link #createTunInterface(Collection)} instead.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@TestApi
|
@Deprecated
|
||||||
|
@NonNull
|
||||||
public TestNetworkInterface createTunInterface(@NonNull LinkAddress[] linkAddrs) {
|
public TestNetworkInterface createTunInterface(@NonNull LinkAddress[] linkAddrs) {
|
||||||
|
return createTunInterface(Arrays.asList(linkAddrs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a tun interface for testing purposes
|
||||||
|
*
|
||||||
|
* @param linkAddrs an array of LinkAddresses to assign to the TUN interface
|
||||||
|
* @return A ParcelFileDescriptor of the underlying TUN interface. Close this to tear down the
|
||||||
|
* TUN interface.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
|
@NonNull
|
||||||
|
public TestNetworkInterface createTunInterface(@NonNull Collection<LinkAddress> linkAddrs) {
|
||||||
try {
|
try {
|
||||||
return mService.createTunInterface(linkAddrs);
|
final LinkAddress[] arr = new LinkAddress[linkAddrs.size()];
|
||||||
|
return mService.createTunInterface(linkAddrs.toArray(arr));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
@@ -145,7 +165,8 @@ public class TestNetworkManager {
|
|||||||
* TAP interface.
|
* TAP interface.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@TestApi
|
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||||
|
@NonNull
|
||||||
public TestNetworkInterface createTapInterface() {
|
public TestNetworkInterface createTapInterface() {
|
||||||
try {
|
try {
|
||||||
return mService.createTapInterface();
|
return mService.createTapInterface();
|
||||||
|
|||||||
Reference in New Issue
Block a user