Merge "Mark TestNetworkManager as module API"
This commit is contained in:
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package android.net;
|
||||
|
||||
import android.annotation.TestApi;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Parcel;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Parcelable;
|
||||
@@ -25,9 +26,11 @@ import android.os.Parcelable;
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public final class TestNetworkInterface implements Parcelable {
|
||||
@NonNull
|
||||
private final ParcelFileDescriptor mFileDescriptor;
|
||||
@NonNull
|
||||
private final String mInterfaceName;
|
||||
|
||||
@Override
|
||||
@@ -36,29 +39,32 @@ public final class TestNetworkInterface implements Parcelable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
public void writeToParcel(@NonNull Parcel out, int flags) {
|
||||
out.writeParcelable(mFileDescriptor, PARCELABLE_WRITE_RETURN_VALUE);
|
||||
out.writeString(mInterfaceName);
|
||||
}
|
||||
|
||||
public TestNetworkInterface(ParcelFileDescriptor pfd, String intf) {
|
||||
public TestNetworkInterface(@NonNull ParcelFileDescriptor pfd, @NonNull String intf) {
|
||||
mFileDescriptor = pfd;
|
||||
mInterfaceName = intf;
|
||||
}
|
||||
|
||||
private TestNetworkInterface(Parcel in) {
|
||||
private TestNetworkInterface(@NonNull Parcel in) {
|
||||
mFileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
|
||||
mInterfaceName = in.readString();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ParcelFileDescriptor getFileDescriptor() {
|
||||
return mFileDescriptor;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getInterfaceName() {
|
||||
return mInterfaceName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static final Parcelable.Creator<TestNetworkInterface> CREATOR =
|
||||
new Parcelable.Creator<TestNetworkInterface>() {
|
||||
public TestNetworkInterface createFromParcel(Parcel in) {
|
||||
|
||||
@@ -17,18 +17,21 @@ package android.net;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.TestApi;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
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
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public class TestNetworkManager {
|
||||
/**
|
||||
* 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
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public void teardownTestNetwork(@NonNull Network network) {
|
||||
try {
|
||||
mService.teardownTestNetwork(network.netId);
|
||||
@@ -102,7 +105,7 @@ public class TestNetworkManager {
|
||||
* @param binder A binder object guarding the lifecycle of this test network.
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder 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
|
||||
* @return A ParcelFileDescriptor of the underlying TUN interface. Close this to tear down the
|
||||
* TUN interface.
|
||||
* @deprecated Use {@link #createTunInterface(Collection)} instead.
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@Deprecated
|
||||
@NonNull
|
||||
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 {
|
||||
return mService.createTunInterface(linkAddrs);
|
||||
final LinkAddress[] arr = new LinkAddress[linkAddrs.size()];
|
||||
return mService.createTunInterface(linkAddrs.toArray(arr));
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -145,7 +165,8 @@ public class TestNetworkManager {
|
||||
* TAP interface.
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
|
||||
@NonNull
|
||||
public TestNetworkInterface createTapInterface() {
|
||||
try {
|
||||
return mService.createTapInterface();
|
||||
|
||||
Reference in New Issue
Block a user