private VpnProfile mNextProfile;
private volatile boolean mProfileUpdated;
private volatile boolean mTerminate;
+ private volatile boolean mIsDisconnecting;
private VpnStateService mService;
private final Object mServiceLock = new Object();
private final ServiceConnection mServiceConnection = new ServiceConnection() {
setProfile(mCurrentProfile);
setError(ErrorState.NO_ERROR);
setState(State.CONNECTING);
+ mIsDisconnecting = false;
BuilderAdapter builder = new BuilderAdapter(mCurrentProfile.getName());
initializeCharon(builder);
if (mCurrentProfile != null)
{
setState(State.DISCONNECTING);
+ mIsDisconnecting = true;
deinitializeCharon();
Log.i(TAG, "charon stopped");
mCurrentProfile = null;
if (mService != null)
{
mService.setError(error);
- mService.disconnect();
+ if (!mIsDisconnecting)
+ {
+ mService.disconnect();
+ }
}
}
}
case STATE_CHILD_SA_DOWN:
synchronized (mServiceLock)
{
- /* since this state is also reached when the SA is closed remotely,
- * we call disconnect() to make sure charon is properly deinitialized */
- if (mService != null)
+ /* if we are not actively disconnecting we assume the remote terminated
+ * the connection and call disconnect() to deinitialize charon properly */
+ if (mService != null && !mIsDisconnecting)
{
mService.disconnect();
}