From 88677c963879c0c65b90318b890d932192022404 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Tue, 12 Feb 2019 02:22:34 +0100 Subject: [PATCH] Send a shutdown POST request first (fixes #320) (#323) * Move notificationHandler shutdown from RestApi to SyncthingService * http/PostRequest: Add shutdown uri * Add RestApi#shutdown to post a shutdown request (fixes #320) * SyncthingService#shutdown: Send a shutdown POST request first in case the kill via shell fails (fixes #320) --- .../com/nutomic/syncthingandroid/http/PostRequest.java | 1 + .../com/nutomic/syncthingandroid/service/RestApi.java | 9 +++++++++ .../syncthingandroid/service/SyncthingService.java | 3 +++ 3 files changed, 13 insertions(+) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/http/PostRequest.java b/app/src/main/java/com/nutomic/syncthingandroid/http/PostRequest.java index 9bf439ad..576fe28e 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/http/PostRequest.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/http/PostRequest.java @@ -16,6 +16,7 @@ public class PostRequest extends ApiRequest { public static final String URI_DB_IGNORES = "/rest/db/ignores"; public static final String URI_DB_OVERRIDE = "/rest/db/override"; public static final String URI_SYSTEM_CONFIG = "/rest/system/config"; + public static final String URI_SYSTEM_SHUTDOWN = "/rest/system/shutdown"; public PostRequest(Context context, URL url, String path, String apiKey, @Nullable Map params, @Nullable String postBody, diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java index a46f5382..64260dc4 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java @@ -410,6 +410,15 @@ public class RestApi { mOnConfigChangedListener.onConfigChanged(); } + /** + * Posts shutdown request. + * This will cause SyncthingNative to exit and not restart. + */ + public void shutdown() { + new PostRequest(mContext, mUrl, PostRequest.URI_SYSTEM_SHUTDOWN, mApiKey, + null, null, null); + } + /** * Returns the version name, or a (text) error message on failure. */ 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 bdbce875..5372afed 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingService.java @@ -658,6 +658,9 @@ public class SyncthingService extends Service { } if (mRestApi != null) { + if (mSyncthingRunnable != null) { + mRestApi.shutdown(); + } mRestApi = null; }