Merge "Add support for registering test networks with administrators."
This commit is contained in:
@@ -136,7 +136,7 @@ public class ConnectivityDiagnosticsManager {
|
|||||||
* {@link #NETWORK_VALIDATION_RESULT_PARTIALLY_VALID},
|
* {@link #NETWORK_VALIDATION_RESULT_PARTIALLY_VALID},
|
||||||
* {@link #NETWORK_VALIDATION_RESULT_SKIPPED}.
|
* {@link #NETWORK_VALIDATION_RESULT_SKIPPED}.
|
||||||
*
|
*
|
||||||
* @see android.net.NetworkCapabilities#CAPABILITY_VALIDATED
|
* @see android.net.NetworkCapabilities#NET_CAPABILITY_VALIDATED
|
||||||
*/
|
*/
|
||||||
@NetworkValidationResult
|
@NetworkValidationResult
|
||||||
public static final String KEY_NETWORK_VALIDATION_RESULT = "networkValidationResult";
|
public static final String KEY_NETWORK_VALIDATION_RESULT = "networkValidationResult";
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteException;
|
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
|
* Sets up a capability-limited, testing-only network for a given interface
|
||||||
*
|
*
|
||||||
@@ -66,11 +80,7 @@ public class TestNetworkManager {
|
|||||||
public void setupTestNetwork(
|
public void setupTestNetwork(
|
||||||
@NonNull LinkProperties lp, boolean isMetered, @NonNull IBinder binder) {
|
@NonNull LinkProperties lp, boolean isMetered, @NonNull IBinder binder) {
|
||||||
Preconditions.checkNotNull(lp, "Invalid LinkProperties");
|
Preconditions.checkNotNull(lp, "Invalid LinkProperties");
|
||||||
try {
|
setupTestNetwork(lp.getInterfaceName(), lp, isMetered, new int[0], binder);
|
||||||
mService.setupTestNetwork(lp.getInterfaceName(), lp, isMetered, binder);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,11 +92,21 @@ public class TestNetworkManager {
|
|||||||
*/
|
*/
|
||||||
@TestApi
|
@TestApi
|
||||||
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
||||||
try {
|
setupTestNetwork(iface, null, true, new int[0], binder);
|
||||||
mService.setupTestNetwork(iface, null, true, binder);
|
}
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw e.rethrowFromSystemServer();
|
/**
|
||||||
}
|
* 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.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@@ -230,6 +231,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
@Nullable LinkProperties lp,
|
@Nullable LinkProperties lp,
|
||||||
boolean isMetered,
|
boolean isMetered,
|
||||||
int callingUid,
|
int callingUid,
|
||||||
|
@NonNull int[] administratorUids,
|
||||||
@NonNull IBinder binder)
|
@NonNull IBinder binder)
|
||||||
throws RemoteException, SocketException {
|
throws RemoteException, SocketException {
|
||||||
Objects.requireNonNull(looper, "missing Looper");
|
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_SUSPENDED);
|
||||||
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
|
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED);
|
||||||
nc.setNetworkSpecifier(new StringNetworkSpecifier(iface));
|
nc.setNetworkSpecifier(new StringNetworkSpecifier(iface));
|
||||||
|
nc.setAdministratorUids(intArrayToList(administratorUids));
|
||||||
if (!isMetered) {
|
if (!isMetered) {
|
||||||
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
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);
|
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
|
* Sets up a Network with extremely limited privileges, guarded by the MANAGE_TEST_NETWORKS
|
||||||
* permission.
|
* permission.
|
||||||
@@ -301,6 +312,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
@NonNull String iface,
|
@NonNull String iface,
|
||||||
@Nullable LinkProperties lp,
|
@Nullable LinkProperties lp,
|
||||||
boolean isMetered,
|
boolean isMetered,
|
||||||
|
@NonNull int[] administratorUids,
|
||||||
@NonNull IBinder binder) {
|
@NonNull IBinder binder) {
|
||||||
enforceTestNetworkPermissions(mContext);
|
enforceTestNetworkPermissions(mContext);
|
||||||
|
|
||||||
@@ -335,6 +347,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
lp,
|
lp,
|
||||||
isMetered,
|
isMetered,
|
||||||
callingUid,
|
callingUid,
|
||||||
|
administratorUids,
|
||||||
binder);
|
binder);
|
||||||
|
|
||||||
mTestNetworkTracker.put(agent.getNetwork().netId, agent);
|
mTestNetworkTracker.put(agent.getNetwork().netId, agent);
|
||||||
|
|||||||
Reference in New Issue
Block a user