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

Commit 23ceea6b authored by lucaslin's avatar lucaslin
Browse files

Use NetdUtils instead of NetworkManagementService in IpSecService

NetdUtils has the same method(e.g. setInterfaceUp) as
NetworkManagementService so using the one inside NetdUtils instead
and try to remove NetworkManagementService from IpSecService in
the following commit.

Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: I0ed8b0c678b067a655b51b938b6b40eadd985321
parent 648c2e4c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import android.util.SparseBooleanArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
import com.android.net.module.util.NetdUtils;

import libcore.io.IoUtils;

@@ -1317,7 +1318,7 @@ public class IpSecService extends IIpSecService.Stub {
            netd.ipSecAddTunnelInterface(intfName, localAddr, remoteAddr, ikey, okey, resourceId);

            Binder.withCleanCallingIdentity(() -> {
                mNetworkManager.setInterfaceUp(intfName);
                NetdUtils.setInterfaceUp(netd, intfName);
            });

            for (int selAddrFamily : ADDRESS_FAMILIES) {
+19 −2
Original line number Diff line number Diff line
@@ -16,12 +16,16 @@

package com.android.server;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.net.INetd.IF_STATE_DOWN;
import static android.net.INetd.IF_STATE_UP;
import static android.system.OsConstants.AF_INET;
import static android.system.OsConstants.AF_INET6;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
@@ -35,6 +39,7 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.net.INetd;
import android.net.InetAddresses;
import android.net.InterfaceConfigurationParcel;
import android.net.IpSecAlgorithm;
import android.net.IpSecConfig;
import android.net.IpSecManager;
@@ -133,6 +138,14 @@ public class IpSecServiceParameterizedTest {
            }
            throw new SecurityException("Unavailable permission requested");
        }

        @Override
        public int checkCallingOrSelfPermission(String permission) {
            if (android.Manifest.permission.NETWORK_STACK.equals(permission)) {
                return PERMISSION_GRANTED;
            }
            throw new UnsupportedOperationException();
        }
    };

    INetd mMockNetd;
@@ -625,7 +638,10 @@ public class IpSecServiceParameterizedTest {
    }

    private IpSecTunnelInterfaceResponse createAndValidateTunnel(
            String localAddr, String remoteAddr, String pkgName) {
            String localAddr, String remoteAddr, String pkgName) throws Exception {
        final InterfaceConfigurationParcel config = new InterfaceConfigurationParcel();
        config.flags = new String[] {IF_STATE_DOWN};
        when(mMockNetd.interfaceGetCfg(anyString())).thenReturn(config);
        IpSecTunnelInterfaceResponse createTunnelResp =
                mIpSecService.createTunnelInterface(
                        mSourceAddr, mDestinationAddr, fakeNetwork, new Binder(), pkgName);
@@ -655,7 +671,8 @@ public class IpSecServiceParameterizedTest {
                        anyInt(),
                        anyInt(),
                        anyInt());
        verify(mNetworkManager).setInterfaceUp(createTunnelResp.interfaceName);
        verify(mMockNetd).interfaceSetCfg(argThat(
                config -> Arrays.asList(config.flags).contains(IF_STATE_UP)));
    }

    @Test