1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2025-01-10 20:15:54 +00:00

Disable sync if Android sync setting is disabled (fixes #588).

This commit is contained in:
Felix Ableitner 2016-08-02 19:17:22 +02:00
parent 8cb9105197
commit 2daa601e36
3 changed files with 21 additions and 2 deletions

View file

@ -12,6 +12,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<application
android:allowBackup="false"

View file

@ -2,6 +2,7 @@ package com.nutomic.syncthingandroid.syncthing;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -103,9 +104,14 @@ public class DeviceStateHolder extends BroadcastReceiver {
return mWifiSsid;
}
/**
* Determines if Syncthing should currently run.
*/
public boolean shouldRun() {
if (SyncthingService.alwaysRunInBackground(mContext)) {
// Always run, ignoring wifi/charging state.
if (!ContentResolver.getMasterSyncAutomatically()) {
return false;
}
else if (SyncthingService.alwaysRunInBackground(mContext)) {
return true;
}
else {

View file

@ -3,10 +3,12 @@ package com.nutomic.syncthingandroid.syncthing;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SyncStatusObserver;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
@ -124,6 +126,13 @@ public class SyncthingService extends Service implements
private final HashSet<OnApiChangeListener> 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() {