Merge "Add configurability of LinkProperties, meteredness for Test Networks"
This commit is contained in:
@@ -53,6 +53,26 @@ public class TestNetworkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up a capability-limited, testing-only network for a given interface
|
||||||
|
*
|
||||||
|
* @param lp The LinkProperties for the TestNetworkService to use for this test network. Note
|
||||||
|
* that the interface name and link addresses will be overwritten, and the passed-in values
|
||||||
|
* discarded.
|
||||||
|
* @param isMetered Whether or not the network should be considered metered.
|
||||||
|
* @param binder A binder object guarding the lifecycle of this test network.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up a capability-limited, testing-only network for a given interface
|
* Sets up a capability-limited, testing-only network for a given interface
|
||||||
*
|
*
|
||||||
@@ -63,7 +83,7 @@ public class TestNetworkManager {
|
|||||||
@TestApi
|
@TestApi
|
||||||
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
||||||
try {
|
try {
|
||||||
mService.setupTestNetwork(iface, binder);
|
mService.setupTestNetwork(iface, null, true, binder);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.server;
|
|||||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.INetd;
|
import android.net.INetd;
|
||||||
@@ -53,6 +54,7 @@ import java.net.Inet6Address;
|
|||||||
import java.net.InterfaceAddress;
|
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.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -226,6 +228,8 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
@NonNull Looper looper,
|
@NonNull Looper looper,
|
||||||
@NonNull Context context,
|
@NonNull Context context,
|
||||||
@NonNull String iface,
|
@NonNull String iface,
|
||||||
|
@Nullable LinkProperties lp,
|
||||||
|
boolean isMetered,
|
||||||
int callingUid,
|
int callingUid,
|
||||||
@NonNull IBinder binder)
|
@NonNull IBinder binder)
|
||||||
throws RemoteException, SocketException {
|
throws RemoteException, SocketException {
|
||||||
@@ -245,9 +249,19 @@ 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));
|
||||||
|
if (!isMetered) {
|
||||||
|
nc.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED);
|
||||||
|
}
|
||||||
|
|
||||||
// Build LinkProperties
|
// Build LinkProperties
|
||||||
LinkProperties lp = new LinkProperties();
|
if (lp == null) {
|
||||||
|
lp = new LinkProperties();
|
||||||
|
} else {
|
||||||
|
lp = new LinkProperties(lp);
|
||||||
|
// Use LinkAddress(es) from the interface itself to minimize how much the caller
|
||||||
|
// is trusted.
|
||||||
|
lp.setLinkAddresses(new ArrayList<>());
|
||||||
|
}
|
||||||
lp.setInterfaceName(iface);
|
lp.setInterfaceName(iface);
|
||||||
|
|
||||||
// Find the currently assigned addresses, and add them to LinkProperties
|
// Find the currently assigned addresses, and add them to LinkProperties
|
||||||
@@ -284,7 +298,11 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
* <p>This method provides a Network that is useful only for testing.
|
* <p>This method provides a Network that is useful only for testing.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setupTestNetwork(@NonNull String iface, @NonNull IBinder binder) {
|
public void setupTestNetwork(
|
||||||
|
@NonNull String iface,
|
||||||
|
@Nullable LinkProperties lp,
|
||||||
|
boolean isMetered,
|
||||||
|
@NonNull IBinder binder) {
|
||||||
enforceTestNetworkPermissions(mContext);
|
enforceTestNetworkPermissions(mContext);
|
||||||
|
|
||||||
checkNotNull(iface, "missing Iface");
|
checkNotNull(iface, "missing Iface");
|
||||||
@@ -315,6 +333,8 @@ class TestNetworkService extends ITestNetworkManager.Stub {
|
|||||||
mHandler.getLooper(),
|
mHandler.getLooper(),
|
||||||
mContext,
|
mContext,
|
||||||
iface,
|
iface,
|
||||||
|
lp,
|
||||||
|
isMetered,
|
||||||
callingUid,
|
callingUid,
|
||||||
binder);
|
binder);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user