Merge "VPN reconnection fails after manually disabling VPN"
This commit is contained in:
@@ -1586,9 +1586,6 @@ public class Vpn {
|
|||||||
public void exit() {
|
public void exit() {
|
||||||
// We assume that everything is reset after stopping the daemons.
|
// We assume that everything is reset after stopping the daemons.
|
||||||
interrupt();
|
interrupt();
|
||||||
for (LocalSocket socket : mSockets) {
|
|
||||||
IoUtils.closeQuietly(socket);
|
|
||||||
}
|
|
||||||
agentDisconnect();
|
agentDisconnect();
|
||||||
try {
|
try {
|
||||||
mContext.unregisterReceiver(mBroadcastReceiver);
|
mContext.unregisterReceiver(mBroadcastReceiver);
|
||||||
@@ -1601,8 +1598,26 @@ public class Vpn {
|
|||||||
Log.v(TAG, "Waiting");
|
Log.v(TAG, "Waiting");
|
||||||
synchronized (TAG) {
|
synchronized (TAG) {
|
||||||
Log.v(TAG, "Executing");
|
Log.v(TAG, "Executing");
|
||||||
execute();
|
try {
|
||||||
monitorDaemons();
|
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);
|
Log.i(TAG, "Aborting", e);
|
||||||
updateState(DetailedState.FAILED, e.getMessage());
|
updateState(DetailedState.FAILED, e.getMessage());
|
||||||
exit();
|
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
|
* Monitor the daemons we started, moving to disconnected state if the
|
||||||
* underlying services fail.
|
* underlying services fail.
|
||||||
*/
|
*/
|
||||||
private void monitorDaemons() {
|
private void monitorDaemons() throws InterruptedException{
|
||||||
if (!mNetworkInfo.isConnected()) {
|
if (!mNetworkInfo.isConnected()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
while (true) {
|
||||||
try {
|
Thread.sleep(2000);
|
||||||
while (true) {
|
for (int i = 0; i < mDaemons.length; i++) {
|
||||||
Thread.sleep(2000);
|
if (mArguments[i] != null && SystemService.isStopped(mDaemons[i])) {
|
||||||
for (int i = 0; i < mDaemons.length; i++) {
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user