Merge "Add support for registering test networks with administrators." into rvc-dev
This commit is contained in:
@@ -136,7 +136,7 @@ public class ConnectivityDiagnosticsManager {
|
||||
* {@link #NETWORK_VALIDATION_RESULT_PARTIALLY_VALID},
|
||||
* {@link #NETWORK_VALIDATION_RESULT_SKIPPED}.
|
||||
*
|
||||
* @see android.net.NetworkCapabilities#CAPABILITY_VALIDATED
|
||||
* @see android.net.NetworkCapabilities#NET_CAPABILITY_VALIDATED
|
||||
*/
|
||||
@NetworkValidationResult
|
||||
public static final String KEY_NETWORK_VALIDATION_RESULT = "networkValidationResult";
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package android.net;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.TestApi;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
@@ -53,6 +54,19 @@ public class TestNetworkManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTestNetwork(
|
||||
@NonNull String iface,
|
||||
@Nullable LinkProperties lp,
|
||||
boolean isMetered,
|
||||
@NonNull int[] administratorUids,
|
||||
@NonNull IBinder binder) {
|
||||
try {
|
||||
mService.setupTestNetwork(iface, lp, isMetered, administratorUids, binder);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a capability-limited, testing-only network for a given interface
|
||||
*
|
||||
@@ -66,11 +80,7 @@ public class TestNetworkManager {
|
||||
public void setupTestNetwork(
|
||||
@NonNull LinkProperties lp, boolean isMetered, @NonNull IBinder binder) {
|
||||
Preconditions.checkNotNull(lp, "Invalid LinkProperties");
|
||||
try {
|
||||
mService.setupTestNetwork(lp.getInterfaceName(), lp, isMetered, binder);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
setupTestNetwork(lp.getInterfaceName(), lp, isMetered, new int[0], binder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,11 +92,21 @@ public class TestNetworkManager {
|
||||
*/
|
||||
@TestApi
|
||||
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
||||
try {
|
||||
mService.setupTestNetwork(iface, null, true, binder);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
setupTestNetwork(iface, null, true, new int[0], binder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a capability-limited, testing-only network for a given interface with the given
|
||||
* administrator UIDs.
|
||||
*
|
||||
* @param iface the name of the interface to be used for the Network LinkProperties.
|
||||
* @param administratorUids The administrator UIDs to be used for the test-only network
|
||||
* @param binder A binder object guarding the lifecycle of this test network.
|
||||
* @hide
|
||||
*/
|
||||
public void setupTestNetwork(
|
||||
@NonNull String iface, @NonNull int[] administratorUids, @NonNull IBinder binder) {
|
||||
setupTestNetwork(iface, null, true, administratorUids, binder);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,6 +53,7 @@ import java.net.InterfaceAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -230,6 +231,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
||||
@Nullable LinkProperties lp,
|
||||
boolean isMetered,
|
||||
int callingUid,
|
||||
@NonNull int[] administratorUids,
|
||||
@NonNull IBinder binder)
|
||||
throws RemoteException, SocketException {
|
||||
Objects.requireNonNull(looper, "missing Looper");
|
||||
@@ -248,6 +250,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
||||
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED);
|
||||
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
|
||||
nc.setNetworkSpecifier(new StringNetworkSpecifier(iface));
|
||||
nc.setAdministratorUids(intArrayToList(administratorUids));
|
||||
if (!isMetered) {
|
||||
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
||||
}
|
||||
@@ -290,6 +293,14 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
||||
return new TestNetworkAgent(looper, context, ni, nc, lp, callingUid, binder);
|
||||
}
|
||||
|
||||
private List<Integer> intArrayToList(@NonNull int[] array) {
|
||||
final List<Integer> list = new ArrayList<>(array.length);
|
||||
for (final int i : array) {
|
||||
list.add(i);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a Network with extremely limited privileges, guarded by the MANAGE_TEST_NETWORKS
|
||||
* permission.
|
||||
@@ -301,6 +312,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
||||
@NonNull String iface,
|
||||
@Nullable LinkProperties lp,
|
||||
boolean isMetered,
|
||||
@NonNull int[] administratorUids,
|
||||
@NonNull IBinder binder) {
|
||||
enforceTestNetworkPermissions(mContext);
|
||||
|
||||
@@ -335,6 +347,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
||||
lp,
|
||||
isMetered,
|
||||
callingUid,
|
||||
administratorUids,
|
||||
binder);
|
||||
|
||||
mTestNetworkTracker.put(agent.getNetwork().netId, agent);
|
||||
|
||||
Reference in New Issue
Block a user