Skip to content

Commit

Permalink
Fix deferred native shutdown not working during State.STARTING (fixes #…
Browse files Browse the repository at this point in the history
…290) (#296)

Remove SyncthingService#mDestroyScheduled
  • Loading branch information
Catfriend1 authored Jan 31, 2019
1 parent a30163e commit 976d4e0
Showing 1 changed file with 2 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ public enum State {
*/
private boolean mLastDeterminedShouldRun = false;

/**
* True if a service {@link #onDestroy} was requested while syncthing is starting,
* in that case, perform stop in {@link #onApiAvailable}.
*/
private boolean mDestroyScheduled = false;

/**
* True if the user granted the storage permission.
*/
Expand Down Expand Up @@ -594,17 +588,6 @@ private void onApiAvailable() {
mRestApi.applyCustomRunConditions(mRunConditionMonitor);
}

/**
* If the service instance got an onDestroy() event while being in
* State.STARTING we'll trigger the service onDestroy() now. this
* allows the syncthing binary to get gracefully stopped.
*/
if (mDestroyScheduled) {
mDestroyScheduled = false;
stopSelf();
return;
}

if (mEventProcessor == null) {
mEventProcessor = new EventProcessor(SyncthingService.this, mRestApi);
mEventProcessor.start();
Expand Down Expand Up @@ -633,22 +616,12 @@ public void onDestroy() {
if (mNotificationHandler != null) {
mNotificationHandler.setAppShutdownInProgress(true);
}
if (mStoragePermissionGranted) {
synchronized (mStateLock) {
if (mCurrentState == State.STARTING) {
Log.i(TAG, "Delay shutting down syncthing binary until initialisation finished");
mDestroyScheduled = true;
} else {
Log.i(TAG, "Shutting down syncthing binary immediately");
shutdown(State.DISABLED);
}
}
} else {
if (!mStoragePermissionGranted) {
// If the storage permission got revoked, we did not start the binary and
// are in State.INIT requiring an immediate shutdown of this service class.
Log.i(TAG, "Shutting down syncthing binary due to missing storage permission.");
shutdown(State.DISABLED);
}
shutdown(State.DISABLED);
super.onDestroy();
}

Expand Down

0 comments on commit 976d4e0

Please sign in to comment.