Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1cb6c71 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Add support for registering test networks with administrators." am: 84091b4c

Change-Id: Ic6251b26fbbce029063d3f83c4fa6dbc4d01df40
parents d5d37840 84091b4c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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";
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ interface ITestNetworkManager
    TestNetworkInterface createTapInterface();

    void setupTestNetwork(in String iface, in LinkProperties lp, in boolean isMetered,
            in IBinder binder);
            in int[] administratorUids, in IBinder binder);

    void teardownTestNetwork(int netId);
}
+30 −10
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+13 −0
Original line number Diff line number Diff line
@@ -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);