From 976d4e05c248789f33b2a65fbfcad42e4522f35a Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Thu, 31 Jan 2019 23:51:39 +0100 Subject: [PATCH] Fix deferred native shutdown not working during State.STARTING (fixes #290) (#296) Remove SyncthingService#mDestroyScheduled --- .../service/SyncthingService.java | 31 ++----------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java index 0dd44c350..9c9f92e86 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java @@ -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. */ @@ -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(); @@ -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(); }