Merge "Disconnect VPN when the underlying network is lost"
This commit is contained in:
@@ -3210,41 +3210,44 @@ public class Vpn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSession != null && mMobikeEnabled) {
|
Log.d(TAG, "Schedule a delay handleSessionLost for losing network "
|
||||||
Log.d(
|
+ network
|
||||||
TAG,
|
+ " on session with token "
|
||||||
"IKE Session has mobility. Delay handleSessionLost for losing network "
|
+ mCurrentToken);
|
||||||
+ network
|
|
||||||
+ " on session with token "
|
|
||||||
+ mCurrentToken);
|
|
||||||
|
|
||||||
final int token = mCurrentToken;
|
final int token = mCurrentToken;
|
||||||
// Delay the teardown in case a new network will be available soon. For example,
|
// Delay the teardown in case a new network will be available soon. For example,
|
||||||
// during handover between two WiFi networks, Android will disconnect from the
|
// during handover between two WiFi networks, Android will disconnect from the
|
||||||
// first WiFi and then connects to the second WiFi.
|
// first WiFi and then connects to the second WiFi.
|
||||||
mScheduledHandleNetworkLostFuture =
|
mScheduledHandleNetworkLostFuture =
|
||||||
mExecutor.schedule(
|
mExecutor.schedule(
|
||||||
() -> {
|
() -> {
|
||||||
if (isActiveToken(token)) {
|
if (isActiveToken(token)) {
|
||||||
handleSessionLost(null /* exception */, network);
|
handleSessionLost(new IkeNetworkLostException(network),
|
||||||
} else {
|
network);
|
||||||
Log.d(
|
|
||||||
TAG,
|
synchronized (Vpn.this) {
|
||||||
"Scheduled handleSessionLost fired for "
|
// Ignore stale runner.
|
||||||
+ "obsolete token "
|
if (mVpnRunner != this) return;
|
||||||
+ token);
|
|
||||||
|
updateState(DetailedState.DISCONNECTED,
|
||||||
|
"Network lost");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"Scheduled handleSessionLost fired for "
|
||||||
|
+ "obsolete token "
|
||||||
|
+ token);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset mScheduledHandleNetworkLostFuture since it's
|
||||||
|
// already run on executor thread.
|
||||||
|
mScheduledHandleNetworkLostFuture = null;
|
||||||
|
},
|
||||||
|
NETWORK_LOST_TIMEOUT_MS,
|
||||||
|
TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
// Reset mScheduledHandleNetworkLostFuture since it's
|
|
||||||
// already run on executor thread.
|
|
||||||
mScheduledHandleNetworkLostFuture = null;
|
|
||||||
},
|
|
||||||
NETWORK_LOST_TIMEOUT_MS,
|
|
||||||
TimeUnit.MILLISECONDS);
|
|
||||||
} else {
|
|
||||||
Log.d(TAG, "Call handleSessionLost for losing network " + network);
|
|
||||||
handleSessionLost(null /* exception */, network);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancelHandleNetworkLostTimeout() {
|
private void cancelHandleNetworkLostTimeout() {
|
||||||
|
|||||||
Reference in New Issue
Block a user