mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-02-04 08:11:37 +00:00
Disable sync if Android sync setting is disabled (fixes #588).
This commit is contained in:
parent
8cb9105197
commit
2daa601e36
3 changed files with 21 additions and 2 deletions
|
@ -12,6 +12,7 @@
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.nutomic.syncthingandroid.syncthing;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -103,9 +104,14 @@ public class DeviceStateHolder extends BroadcastReceiver {
|
||||||
return mWifiSsid;
|
return mWifiSsid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if Syncthing should currently run.
|
||||||
|
*/
|
||||||
public boolean shouldRun() {
|
public boolean shouldRun() {
|
||||||
if (SyncthingService.alwaysRunInBackground(mContext)) {
|
if (!ContentResolver.getMasterSyncAutomatically()) {
|
||||||
// Always run, ignoring wifi/charging state.
|
return false;
|
||||||
|
}
|
||||||
|
else if (SyncthingService.alwaysRunInBackground(mContext)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -3,10 +3,12 @@ package com.nutomic.syncthingandroid.syncthing;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.SyncStatusObserver;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
@ -124,6 +126,13 @@ public class SyncthingService extends Service implements
|
||||||
private final HashSet<OnApiChangeListener> mOnApiChangeListeners =
|
private final HashSet<OnApiChangeListener> mOnApiChangeListeners =
|
||||||
new HashSet<>();
|
new HashSet<>();
|
||||||
|
|
||||||
|
private final SyncStatusObserver mSyncStatusObserver = new SyncStatusObserver() {
|
||||||
|
@Override
|
||||||
|
public void onStatusChanged(int i) {
|
||||||
|
updateState();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INIT: Service is starting up and initializing.
|
* INIT: Service is starting up and initializing.
|
||||||
* STARTING: Syncthing binary is starting (but the API is not yet ready).
|
* 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));
|
registerReceiver(mDeviceStateHolder, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
new StartupTask(sp.getString("gui_user",""), sp.getString("gui_password","")).execute();
|
new StartupTask(sp.getString("gui_user",""), sp.getString("gui_password","")).execute();
|
||||||
sp.registerOnSharedPreferenceChangeListener(this);
|
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);
|
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
sp.unregisterOnSharedPreferenceChangeListener(this);
|
sp.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
ContentResolver.removeStatusChangeListener(mSyncStatusObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shutdown() {
|
private void shutdown() {
|
||||||
|
|
Loading…
Reference in a new issue