From 047454c759b46bbadb87ee3b64bf3e29afda48d6 Mon Sep 17 00:00:00 2001 From: Hisanobu Watanabe Date: Tue, 7 Jun 2016 19:55:41 +0900 Subject: VPN reconnection fails after manually disabling VPN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Bug: 28279646 Change-Id: Ie5a9497189da8c96321a220ea21ebe63e42d0751 --- .../java/com/android/server/connectivity/Vpn.java | 60 ++++++++++------------ 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java index 284618515487..32586bd60723 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -1157,9 +1157,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); @@ -1172,8 +1169,26 @@ public class Vpn { Log.v(TAG, "Waiting"); synchronized (TAG) { Log.v(TAG, "Executing"); - execute(); - monitorDaemons(); + 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(); } } @@ -1372,18 +1387,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(); - } } } @@ -1391,28 +1394,17 @@ 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++) { - if (mArguments[i] != null && SystemService.isStopped(mDaemons[i])) { - return; - } + while (true) { + Thread.sleep(2000); + for (int i = 0; i < mDaemons.length; i++) { + if (mArguments[i] != null && SystemService.isStopped(mDaemons[i])) { + return; } } - } catch (InterruptedException e) { - Log.d(TAG, "interrupted during monitorDaemons(); stopping services"); - } finally { - for (String daemon : mDaemons) { - SystemService.stop(daemon); - } - - agentDisconnect(); } } } -- cgit v1.2.3-59-g8ed1b