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

Commit fc95150f authored by Benedict Wong's avatar Benedict Wong Committed by Automerger Merge Worker
Browse files

Merge "Lazy-create IpSecTunnelInterface" am: cefc4f68 am: b8a2bb6a

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1582714

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I909388ece01647d89608bbaeb0aad3612118a080
parents b760ad1f b8a2bb6a
Loading
Loading
Loading
Loading
+22 −18
Original line number Diff line number Diff line
@@ -125,10 +125,11 @@ import java.util.concurrent.TimeUnit;
public class VcnGatewayConnection extends StateMachine {
    private static final String TAG = VcnGatewayConnection.class.getSimpleName();

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    static final InetAddress DUMMY_ADDR = InetAddresses.parseNumericAddress("192.0.2.0");

    private static final int[] MERGED_CAPABILITIES =
            new int[] {NET_CAPABILITY_NOT_METERED, NET_CAPABILITY_NOT_ROAMING};

    private static final InetAddress DUMMY_ADDR = InetAddresses.parseNumericAddress("192.0.2.0");
    private static final int ARG_NOT_PRESENT = Integer.MIN_VALUE;

    private static final String DISCONNECT_REASON_INTERNAL_ERROR = "Uncaught exception: ";
@@ -412,11 +413,11 @@ public class VcnGatewayConnection extends StateMachine {
    @NonNull private final VcnGatewayConnectionConfig mConnectionConfig;
    @NonNull private final VcnGatewayStatusCallback mGatewayStatusCallback;
    @NonNull private final Dependencies mDeps;

    @NonNull private final VcnUnderlyingNetworkTrackerCallback mUnderlyingNetworkTrackerCallback;

    @NonNull private final IpSecManager mIpSecManager;
    @NonNull private final IpSecTunnelInterface mTunnelIface;

    @Nullable private IpSecTunnelInterface mTunnelIface = null;

    /** Running state of this VcnGatewayConnection. */
    private boolean mIsRunning = true;
@@ -526,20 +527,6 @@ public class VcnGatewayConnection extends StateMachine {
                        mUnderlyingNetworkTrackerCallback);
        mIpSecManager = mVcnContext.getContext().getSystemService(IpSecManager.class);

        IpSecTunnelInterface iface;
        try {
            iface =
                    mIpSecManager.createIpSecTunnelInterface(
                            DUMMY_ADDR, DUMMY_ADDR, new Network(-1));
        } catch (IOException | ResourceUnavailableException e) {
            teardownAsynchronously();
            mTunnelIface = null;

            return;
        }

        mTunnelIface = iface;

        addState(mDisconnectedState);
        addState(mDisconnectingState);
        addState(mConnectingState);
@@ -1117,6 +1104,18 @@ public class VcnGatewayConnection extends StateMachine {
    class ConnectedState extends ConnectedStateBase {
        @Override
        protected void enterState() throws Exception {
            if (mTunnelIface == null) {
                try {
                    // Requires a real Network object in order to be created; doing this any earlier
                    // means not having a real Network object, or picking an incorrect Network.
                    mTunnelIface =
                            mIpSecManager.createIpSecTunnelInterface(
                                    DUMMY_ADDR, DUMMY_ADDR, mUnderlying.network);
                } catch (IOException | ResourceUnavailableException e) {
                    teardownAsynchronously();
                }
            }

            // Successful connection, clear failed attempt counter
            mFailedAttempts = 0;
        }
@@ -1433,6 +1432,11 @@ public class VcnGatewayConnection extends StateMachine {
        }
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    void setTunnelInterface(IpSecTunnelInterface tunnelIface) {
        mTunnelIface = tunnelIface;
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
    UnderlyingNetworkTrackerCallback getUnderlyingNetworkTrackerCallback() {
        return mUnderlyingNetworkTrackerCallback;
+11 −0
Original line number Diff line number Diff line
@@ -16,12 +16,18 @@

package com.android.server.vcn;

import static android.net.IpSecManager.IpSecTunnelInterface;

import static com.android.server.vcn.VcnGatewayConnection.DUMMY_ADDR;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;

import android.net.IpSecManager;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

@@ -37,6 +43,11 @@ public class VcnGatewayConnectionDisconnectedStateTest extends VcnGatewayConnect
    public void setUp() throws Exception {
        super.setUp();

        final IpSecTunnelInterface tunnelIface =
                mContext.getSystemService(IpSecManager.class)
                        .createIpSecTunnelInterface(
                                DUMMY_ADDR, DUMMY_ADDR, TEST_UNDERLYING_NETWORK_RECORD_1.network);
        mGatewayConnection.setTunnelInterface(tunnelIface);
        mGatewayConnection.transitionTo(mGatewayConnection.mDisconnectedState);
        mTestLooper.dispatchAll();
    }