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

Commit 2b465d88 authored by Hisanobu Watanabe's avatar Hisanobu Watanabe Committed by Lorenzo Colitti
Browse files

VPN reconnection fails after manually disabling VPN

When disabling VPN manually, there was no trigger for ipsec-tools to
send “delete message” to VPN server. Therefore, connection information
is left in VPN server and next connection fails.

Fix this issue as below:
- Add “delete message” sending via flush in ipsec-tools when racoon
  daemon stops
- Keep daemon alive when VPN.java exit() to let it finish sending to
  VPN server
- Move close(socket) and stop(daemon) in VPN.java execute()
  and monitorDaemons() to run() to gather cleaning block.

(cherry picked from commit 047454c7)

Change-Id: Ibfbd389b17de5b5a5d23cba59c8d1e05fbe12c15
Bug: 28279646
Bug: 33467086
parent b1ccd81f
Loading
Loading
Loading
Loading
+26 −34
Original line number Diff line number Diff line
@@ -1544,9 +1544,6 @@ public class Vpn {
        public void exit() {
            // We assume that everything is reset after stopping the daemons.
            interrupt();
            for (LocalSocket socket : mSockets) {
                IoUtils.closeQuietly(socket);
            }
            agentDisconnect();
            try {
                mContext.unregisterReceiver(mBroadcastReceiver);
@@ -1559,8 +1556,26 @@ public class Vpn {
            Log.v(TAG, "Waiting");
            synchronized (TAG) {
                Log.v(TAG, "Executing");
                try {
                    execute();
                    monitorDaemons();
                    interrupted(); // Clear interrupt flag if execute called exit.
                } catch (InterruptedException e) {
                } finally {
                    for (LocalSocket socket : mSockets) {
                        IoUtils.closeQuietly(socket);
                    }
                    // This sleep is necessary for racoon to successfully complete sending delete
                    // message to server.
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException e) {
                    }
                    for (String daemon : mDaemons) {
                        SystemService.stop(daemon);
                    }
                }
                agentDisconnect();
            }
        }

@@ -1759,18 +1774,6 @@ public class Vpn {
                Log.i(TAG, "Aborting", e);
                updateState(DetailedState.FAILED, e.getMessage());
                exit();
            } finally {
                // Kill the daemons if they fail to stop.
                if (!initFinished) {
                    for (String daemon : mDaemons) {
                        SystemService.stop(daemon);
                    }
                }

                // Do not leave an unstable state.
                if (!initFinished || mNetworkInfo.getDetailedState() == DetailedState.CONNECTING) {
                    agentDisconnect();
                }
            }
        }

@@ -1778,12 +1781,10 @@ public class Vpn {
         * Monitor the daemons we started, moving to disconnected state if the
         * underlying services fail.
         */
        private void monitorDaemons() {
        private void monitorDaemons() throws InterruptedException{
            if (!mNetworkInfo.isConnected()) {
                return;
            }

            try {
            while (true) {
                Thread.sleep(2000);
                for (int i = 0; i < mDaemons.length; i++) {
@@ -1792,15 +1793,6 @@ public class Vpn {
                    }
                }
            }
            } catch (InterruptedException e) {
                Log.d(TAG, "interrupted during monitorDaemons(); stopping services");
            } finally {
                for (String daemon : mDaemons) {
                    SystemService.stop(daemon);
                }

                agentDisconnect();
            }
        }
    }
}