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

Commit 947aaa4a authored by Yan Yan's avatar Yan Yan
Browse files

VCN: Explicitly handle IAE from updating underlying network

IpSecTunnelInterface#setUnderlyingNetwork will throw IAE when the
underlying network is not functional and has null LinkProperties.
This commit updates VCN to explicitly handle this exception, instead
relying on the mechanism for handling all uncaught exceptions.

Bug: 240112879
Test: atest CtsVcnTestCases & FrameworksVcnTests
Change-Id: I2fdf1da542eb04d56a04e04c762f8c2c19828071
parent 232000e8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1889,7 +1889,7 @@ public class VcnGatewayConnection extends StateMachine {
                    mIpSecManager.applyTunnelModeTransform(
                            tunnelIface, IpSecManager.DIRECTION_FWD, transform);
                }
            } catch (IOException e) {
            } catch (IOException | IllegalArgumentException e) {
                logInfo("Transform application failed for network " + token, e);
                sessionLost(token, e);
            }
+28 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -345,6 +346,33 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
        verify(mConnMgr).reportNetworkConnectivity(eq(mNetworkAgent.getNetwork()), eq(false));
    }

    @Test
    public void testMigrationHandleFailure() throws Exception {
        triggerChildOpened();
        mTestLooper.dispatchAll();
        assertEquals(mIkeConnectionInfo, mGatewayConnection.getIkeConnectionInfo());

        mGatewayConnection
                .getUnderlyingNetworkControllerCallback()
                .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2);

        final IkeSessionConnectionInfo newIkeConnectionInfo =
                new IkeSessionConnectionInfo(
                        TEST_ADDR_V4, TEST_ADDR_V4_2, TEST_UNDERLYING_NETWORK_RECORD_2.network);
        getIkeSessionCallback().onIkeSessionConnectionInfoChanged(newIkeConnectionInfo);
        getChildSessionCallback()
                .onIpSecTransformsMigrated(makeDummyIpSecTransform(), makeDummyIpSecTransform());

        doThrow(new IllegalArgumentException("testMigrationHandleFailure"))
                .when(mIpSecSvc)
                .setNetworkForTunnelInterface(anyInt(), any(), any());

        mTestLooper.dispatchAll();

        assertEquals(mGatewayConnection.mDisconnectingState, mGatewayConnection.getCurrentState());
        verify(mIkeSession).close();
    }

    private void triggerChildOpened() {
        triggerChildOpened(Collections.singletonList(TEST_INTERNAL_ADDR), TEST_DNS_ADDR);
    }