Mark TestNetworkManager as module API

The API surface is planned to move to the Connectivity module, meaning
that it will be maintained across multiple Android releases.
This is incompatible with TestApi semantics, which are designed to be
removable across releases. Effectively the APIs become System/module
API, so mark them as such considering that TestApi is not supported by
modules.

Test: m
Bug: 174436414
Change-Id: Icd32fcbb65e9a4bb2b67cb9da7c971281be0781a
This commit is contained in:
Remi NGUYEN VAN
2021-01-12 15:59:10 +09:00
parent 539dbe61c5
commit 8700d3345b
4 changed files with 55 additions and 28 deletions

View File

@@ -20,6 +20,22 @@ package android.net {
field public final int sndWnd;
}
public final class TestNetworkInterface implements android.os.Parcelable {
ctor public TestNetworkInterface(@NonNull android.os.ParcelFileDescriptor, @NonNull String);
method public int describeContents();
method @NonNull public android.os.ParcelFileDescriptor getFileDescriptor();
method @NonNull public String getInterfaceName();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.net.TestNetworkInterface> CREATOR;
}
public class TestNetworkManager {
method @NonNull public android.net.TestNetworkInterface createTapInterface();
method @NonNull public android.net.TestNetworkInterface createTunInterface(@NonNull java.util.Collection<android.net.LinkAddress>);
method public void setupTestNetwork(@NonNull String, @NonNull android.os.IBinder);
method public void teardownTestNetwork(@NonNull android.net.Network);
}
}
package android.os {

View File

@@ -1001,22 +1001,6 @@ package android.net {
method public static void setServiceForTest(@Nullable android.os.IBinder);
}
public final class TestNetworkInterface implements android.os.Parcelable {
ctor public TestNetworkInterface(android.os.ParcelFileDescriptor, String);
method public int describeContents();
method public android.os.ParcelFileDescriptor getFileDescriptor();
method public String getInterfaceName();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.net.TestNetworkInterface> CREATOR;
}
public class TestNetworkManager {
method public android.net.TestNetworkInterface createTapInterface();
method public android.net.TestNetworkInterface createTunInterface(@NonNull android.net.LinkAddress[]);
method public void setupTestNetwork(@NonNull String, @NonNull android.os.IBinder);
method public void teardownTestNetwork(@NonNull android.net.Network);
}
public class TrafficStats {
method public static long getLoopbackRxBytes();
method public static long getLoopbackRxPackets();

View File

@@ -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) {

View File

@@ -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();