From 2daa601e363efad61e96229c10c19f1ed3c298fb Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 2 Aug 2016 19:17:22 +0200 Subject: [PATCH] Disable sync if Android sync setting is disabled (fixes #588). --- src/main/AndroidManifest.xml | 1 + .../syncthing/DeviceStateHolder.java | 10 ++++++++-- .../syncthingandroid/syncthing/SyncthingService.java | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index c20520c9..e2ea9e1d 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + mOnApiChangeListeners = new HashSet<>(); + private final SyncStatusObserver mSyncStatusObserver = new SyncStatusObserver() { + @Override + public void onStatusChanged(int i) { + updateState(); + } + }; + /** * INIT: Service is starting up and initializing. * STARTING: Syncthing binary is starting (but the API is not yet ready). @@ -314,6 +323,8 @@ public class SyncthingService extends Service implements registerReceiver(mDeviceStateHolder, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); new StartupTask(sp.getString("gui_user",""), sp.getString("gui_password","")).execute(); sp.registerOnSharedPreferenceChangeListener(this); + ContentResolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS, + mSyncStatusObserver); } /** @@ -420,6 +431,7 @@ public class SyncthingService extends Service implements SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); sp.unregisterOnSharedPreferenceChangeListener(this); + ContentResolver.removeStatusChangeListener(mSyncStatusObserver); } private void shutdown() {