Loading services/core/java/com/android/server/vcn/VcnGatewayConnection.java +22 −18 Original line number Diff line number Diff line Loading @@ -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: "; Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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; } Loading Loading @@ -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; Loading tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectedStateTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); } Loading Loading
services/core/java/com/android/server/vcn/VcnGatewayConnection.java +22 −18 Original line number Diff line number Diff line Loading @@ -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: "; Loading Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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; } Loading Loading @@ -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; Loading
tests/vcn/java/com/android/server/vcn/VcnGatewayConnectionDisconnectedStateTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); } Loading