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

Commit 2b9ba7a1 authored by lucaslin's avatar lucaslin Committed by Lucas Lin
Browse files

Remove unused INetworkManagementService from IpSecService

IpSecService is no longer using any methods of
INetworkManagementService, so remove it from IpSecService
and related files.

Bug: 170598012
Test: atest FrameworksNetTests
Change-Id: I852e3a534e0ffd26b4b22420754f3ec8a6f153ad
parent 97759380
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import android.net.TrafficStats;
import android.net.util.NetdService;
import android.os.Binder;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceSpecificException;
@@ -116,9 +115,6 @@ public class IpSecService extends IIpSecService.Stub {
    /* Binder context for this service */
    private final Context mContext;

    /* NetworkManager instance */
    private final INetworkManagementService mNetworkManager;

    /**
     * The next non-repeating global ID for tracking resources between users, this service, and
     * kernel data structures. Accessing this variable is not thread safe, so it is only read or
@@ -997,13 +993,13 @@ public class IpSecService extends IIpSecService.Stub {
     *
     * @param context Binder context for this service
     */
    private IpSecService(Context context, INetworkManagementService networkManager) {
        this(context, networkManager, IpSecServiceConfiguration.GETSRVINSTANCE);
    private IpSecService(Context context) {
        this(context, IpSecServiceConfiguration.GETSRVINSTANCE);
    }

    static IpSecService create(Context context, INetworkManagementService networkManager)
    static IpSecService create(Context context)
            throws InterruptedException {
        final IpSecService service = new IpSecService(context, networkManager);
        final IpSecService service = new IpSecService(context);
        service.connectNativeNetdService();
        return service;
    }
@@ -1017,11 +1013,9 @@ public class IpSecService extends IIpSecService.Stub {

    /** @hide */
    @VisibleForTesting
    public IpSecService(Context context, INetworkManagementService networkManager,
            IpSecServiceConfiguration config) {
    public IpSecService(Context context, IpSecServiceConfiguration config) {
        this(
                context,
                networkManager,
                config,
                (fd, uid) -> {
                    try {
@@ -1035,10 +1029,9 @@ public class IpSecService extends IIpSecService.Stub {

    /** @hide */
    @VisibleForTesting
    public IpSecService(Context context, INetworkManagementService networkManager,
            IpSecServiceConfiguration config, UidFdTagger uidFdTagger) {
    public IpSecService(Context context, IpSecServiceConfiguration config,
            UidFdTagger uidFdTagger) {
        mContext = context;
        mNetworkManager = Objects.requireNonNull(networkManager);
        mSrvConfig = config;
        mUidFdTagger = uidFdTagger;
    }
+1 −1
Original line number Diff line number Diff line
@@ -1532,7 +1532,7 @@ public final class SystemServer {

            t.traceBegin("StartIpSecService");
            try {
                ipSecService = IpSecService.create(context, networkManagement);
                ipSecService = IpSecService.create(context);
                ServiceManager.addService(Context.IPSEC_SERVICE, ipSecService);
            } catch (Throwable e) {
                reportWtf("starting IpSec Service", e);
+1 −4
Original line number Diff line number Diff line
@@ -51,7 +51,6 @@ import android.net.IpSecUdpEncapResponse;
import android.net.LinkAddress;
import android.net.Network;
import android.os.Binder;
import android.os.INetworkManagementService;
import android.os.ParcelFileDescriptor;
import android.system.Os;
import android.test.mock.MockContext;
@@ -149,7 +148,6 @@ public class IpSecServiceParameterizedTest {
    };

    INetd mMockNetd;
    INetworkManagementService mNetworkManager;
    PackageManager mMockPkgMgr;
    IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
    IpSecService mIpSecService;
@@ -175,10 +173,9 @@ public class IpSecServiceParameterizedTest {
    @Before
    public void setUp() throws Exception {
        mMockNetd = mock(INetd.class);
        mNetworkManager = mock(INetworkManagementService.class);
        mMockPkgMgr = mock(PackageManager.class);
        mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
        mIpSecService = new IpSecService(mMockContext, mNetworkManager, mMockIpSecSrvConfig);
        mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);

        // Injecting mock netd
        when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
+1 −3
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import static org.mockito.Mockito.verify;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.RemoteException;

import androidx.test.filters.SmallTest;
@@ -62,8 +61,7 @@ public class IpSecServiceRefcountedResourceTest {
    public void setUp() throws Exception {
        mMockContext = mock(Context.class);
        mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
        mIpSecService = new IpSecService(
                mMockContext, mock(INetworkManagementService.class), mMockIpSecSrvConfig);
        mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
    }

    private void assertResourceState(
+3 −6
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import android.net.IpSecManager;
import android.net.IpSecSpiResponse;
import android.net.IpSecUdpEncapResponse;
import android.os.Binder;
import android.os.INetworkManagementService;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.system.ErrnoException;
@@ -116,7 +115,6 @@ public class IpSecServiceTest {
    }

    Context mMockContext;
    INetworkManagementService mMockNetworkManager;
    INetd mMockNetd;
    IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
    IpSecService mIpSecService;
@@ -124,10 +122,9 @@ public class IpSecServiceTest {
    @Before
    public void setUp() throws Exception {
        mMockContext = mock(Context.class);
        mMockNetworkManager = mock(INetworkManagementService.class);
        mMockNetd = mock(INetd.class);
        mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
        mIpSecService = new IpSecService(mMockContext, mMockNetworkManager, mMockIpSecSrvConfig);
        mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);

        // Injecting mock netd
        when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
@@ -135,7 +132,7 @@ public class IpSecServiceTest {

    @Test
    public void testIpSecServiceCreate() throws InterruptedException {
        IpSecService ipSecSrv = IpSecService.create(mMockContext, mMockNetworkManager);
        IpSecService ipSecSrv = IpSecService.create(mMockContext);
        assertNotNull(ipSecSrv);
    }

@@ -608,7 +605,7 @@ public class IpSecServiceTest {
    public void testOpenUdpEncapSocketTagsSocket() throws Exception {
        IpSecService.UidFdTagger mockTagger = mock(IpSecService.UidFdTagger.class);
        IpSecService testIpSecService = new IpSecService(
                mMockContext, mMockNetworkManager, mMockIpSecSrvConfig, mockTagger);
                mMockContext, mMockIpSecSrvConfig, mockTagger);

        IpSecUdpEncapResponse udpEncapResp =
                testIpSecService.openUdpEncapsulationSocket(0, new Binder());