summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisanobu Watanabe <hisanobu.xa.watanabe@sonymobile.com>2017-01-16 18:11:33 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-01-16 18:11:33 +0000
commitf9c48fad75c7ed650575a610ed31b901b3b00911 (patch)
tree84bde701440b9fcbc8a1c835b179371d6d395215
parentd4c48e911ecd99b8bbb0e8790b0339ae69bb9cbc (diff)
parent92d16f70d7e4ea66f648481bcbbca652b4867b49 (diff)
Merge "VPN reconnection fails after manually disabling VPN" am: ba17ea752b
am: 92d16f70d7 Change-Id: I505d89ecfd486c1a1105bb2fe847d891ed540b6d
-rw-r--r--services/core/java/com/android/server/connectivity/Vpn.java60
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 ede3bda5bea2..610a2ab5b53b 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -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");
- 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();
}
}
@@ -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,28 +1781,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();
}
}
}