diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-01-16 17:51:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-01-16 17:51:06 +0000 |
commit | ba17ea752b896dfc57ec008c1fb837acc1fc804a (patch) | |
tree | c1495a46738c376ddccc8c88ea6c536ea26ac7e0 | |
parent | dc61ad0ad8455d87883768eb9146cf2dbf9ba128 (diff) | |
parent | 047454c759b46bbadb87ee3b64bf3e29afda48d6 (diff) | |
download | base-ba17ea752b896dfc57ec008c1fb837acc1fc804a.tar.gz |
Merge "VPN reconnection fails after manually disabling VPN"
-rw-r--r-- | services/core/java/com/android/server/connectivity/Vpn.java | 60 |
1 files 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 afc6247d88cc..a5876ddda745 100644 --- a/services/core/java/com/android/server/connectivity/Vpn.java +++ b/services/core/java/com/android/server/connectivity/Vpn.java @@ -1586,9 +1586,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); @@ -1601,8 +1598,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(); } } @@ -1801,18 +1816,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(); - } } } @@ -1820,28 +1823,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(); } } } |