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

Commit fc43b2a0 authored by lucaslin's avatar lucaslin Committed by Chiachang Wang
Browse files

Disconnect VPN when the underlying network is lost

This commit mainly does 2 things:
1. Reset IKE state and disconnect VPN network when the underlying
   network is lost.
   - It can prevent giving a false sense of connectivity to the
     app when the VPN is not working due to losing the underlying
     network, update the state of VPN is needed.
2. Update the exception of handleSessionLost() from null to
   IkeNetworkLostException.
   - It fixes the problem that the ERROR_CODE_NETWORK_LOST will
     not be sent when the underlying network is lost.

Bug: 245250164
Bug: 223843049
Test: atest FrameworksNetTests:VpnTest
Test: Manually test with VPN on and enable airplane mode to see if
      VPN network is disconnected and brought back when default
      network is back.
Change-Id: I8f250a2956a1eea5d4a6be20e59f4437d8c8f462
parent b6574193
Loading
Loading
Loading
Loading
+36 −33
Original line number Diff line number Diff line
@@ -3210,10 +3210,7 @@ public class Vpn {
                return;
            }

            if (mSession != null && mMobikeEnabled) {
                Log.d(
                        TAG,
                        "IKE Session has mobility. Delay handleSessionLost for losing network "
            Log.d(TAG, "Schedule a delay handleSessionLost for losing network "
                            + network
                            + " on session with token "
                            + mCurrentToken);
@@ -3226,7 +3223,16 @@ public class Vpn {
                    mExecutor.schedule(
                            () -> {
                                if (isActiveToken(token)) {
                                        handleSessionLost(null /* exception */, network);
                                    handleSessionLost(new IkeNetworkLostException(network),
                                            network);

                                    synchronized (Vpn.this) {
                                        // Ignore stale runner.
                                        if (mVpnRunner != this) return;

                                        updateState(DetailedState.DISCONNECTED,
                                                "Network lost");
                                    }
                                } else {
                                    Log.d(
                                            TAG,
@@ -3241,10 +3247,7 @@ public class Vpn {
                            },
                            NETWORK_LOST_TIMEOUT_MS,
                            TimeUnit.MILLISECONDS);
            } else {
                Log.d(TAG, "Call handleSessionLost for losing network " + network);
                handleSessionLost(null /* exception */, network);
            }

        }

        private void cancelHandleNetworkLostTimeout() {