Fix state when connection toggle is tapped twice #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #15. When tapping the toggle in rapid succession,
NebulaVpnService.onStartCommandis called twice, in serial. Thismethod includes logic to show an error to the user if they somehow
attempt to connect to a service while already connected.
However, this method of showing an error message (calling
announceExit) sends a signal toMainActivitytelling it the servicehas exited, and that it should set the UI state to "Disconnected." It
does not actually disconnect the service at this point, resulting in a
state mismatch in which you cannot actually disconnect the service.
The solution in this commit is to remove this signalling and simply
return out of
onStartCommandto avoid processing the start requesttwice.
Another potential solution is to call
sendSimple(MSG_IS_RUNNING, 1)before returning, which would ensure that the UI is synchronized with
the service state at this point, however I have no reason to believe it
could get out of sync aside from the processing delay.