mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 08:11:17 +00:00
Added option to configure battery saving mode behaviour (fixes #741)
This commit is contained in:
parent
64e51ffe42
commit
8463c19416
4 changed files with 19 additions and 5 deletions
|
@ -95,7 +95,8 @@ public class DeviceStateHolder extends BroadcastReceiver {
|
||||||
|
|
||||||
public void updateWifiSsid() {
|
public void updateWifiSsid() {
|
||||||
mWifiSsid = null;
|
mWifiSsid = null;
|
||||||
WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
WifiManager wifiManager =
|
||||||
|
(WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||||
// may be null, if WiFi has been turned off in meantime
|
// may be null, if WiFi has been turned off in meantime
|
||||||
if (wifiInfo != null) {
|
if (wifiInfo != null) {
|
||||||
|
@ -112,12 +113,14 @@ public class DeviceStateHolder extends BroadcastReceiver {
|
||||||
*/
|
*/
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
public boolean shouldRun() {
|
public boolean shouldRun() {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||||
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && pm.isPowerSaveMode()) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP &&
|
||||||
|
prefs.getBoolean("respect_battery_saving", true) &&
|
||||||
|
pm.isPowerSaveMode()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (SyncthingService.alwaysRunInBackground(mContext)) {
|
else if (SyncthingService.alwaysRunInBackground(mContext)) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
|
||||||
// Check wifi/charging state against preferences and start if ok.
|
// Check wifi/charging state against preferences and start if ok.
|
||||||
boolean prefStopMobileData = prefs.getBoolean(SyncthingService.PREF_SYNC_ONLY_WIFI, false);
|
boolean prefStopMobileData = prefs.getBoolean(SyncthingService.PREF_SYNC_ONLY_WIFI, false);
|
||||||
boolean prefStopNotCharging = prefs.getBoolean(SyncthingService.PREF_SYNC_ONLY_CHARGING, false);
|
boolean prefStopNotCharging = prefs.getBoolean(SyncthingService.PREF_SYNC_ONLY_CHARGING, false);
|
||||||
|
|
|
@ -89,6 +89,7 @@ public class SyncthingService extends Service implements
|
||||||
public static final String PREF_SYNC_ONLY_WIFI = "sync_only_wifi";
|
public static final String PREF_SYNC_ONLY_WIFI = "sync_only_wifi";
|
||||||
public static final String PREF_SYNC_ONLY_WIFI_SSIDS = "sync_only_wifi_ssids_set";
|
public static final String PREF_SYNC_ONLY_WIFI_SSIDS = "sync_only_wifi_ssids_set";
|
||||||
public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
|
public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
|
||||||
|
public static final String PREF_RESPECT_BATTERY_SAVING = "respect_battery_saving";
|
||||||
public static final String PREF_USE_ROOT = "use_root";
|
public static final String PREF_USE_ROOT = "use_root";
|
||||||
private static final String PREF_NOTIFICATION_TYPE = "notification_type";
|
private static final String PREF_NOTIFICATION_TYPE = "notification_type";
|
||||||
public static final String PREF_USE_WAKE_LOCK = "wakelock_while_binary_running";
|
public static final String PREF_USE_WAKE_LOCK = "wakelock_while_binary_running";
|
||||||
|
@ -197,7 +198,7 @@ public class SyncthingService extends Service implements
|
||||||
* Depending on the result, syncthing is started or stopped, and {@link #onApiChange()} is
|
* Depending on the result, syncthing is started or stopped, and {@link #onApiChange()} is
|
||||||
* called.
|
* called.
|
||||||
*/
|
*/
|
||||||
public void updateState() {
|
private void updateState() {
|
||||||
// Start syncthing.
|
// Start syncthing.
|
||||||
if (mDeviceStateHolder.shouldRun()) {
|
if (mDeviceStateHolder.shouldRun()) {
|
||||||
if (mCurrentState == State.ACTIVE || mCurrentState == State.STARTING) {
|
if (mCurrentState == State.ACTIVE || mCurrentState == State.STARTING) {
|
||||||
|
@ -291,9 +292,10 @@ public class SyncthingService extends Service implements
|
||||||
if (key.equals(PREF_NOTIFICATION_TYPE) || key.equals(PREF_FOREGROUND_SERVICE))
|
if (key.equals(PREF_NOTIFICATION_TYPE) || key.equals(PREF_FOREGROUND_SERVICE))
|
||||||
updateNotification();
|
updateNotification();
|
||||||
else if (key.equals(PREF_SYNC_ONLY_CHARGING) || key.equals(PREF_SYNC_ONLY_WIFI)
|
else if (key.equals(PREF_SYNC_ONLY_CHARGING) || key.equals(PREF_SYNC_ONLY_WIFI)
|
||||||
|| key.equals(PREF_SYNC_ONLY_WIFI_SSIDS))
|
|| key.equals(PREF_SYNC_ONLY_WIFI_SSIDS) || key.equals(PREF_RESPECT_BATTERY_SAVING)) {
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the native binary.
|
* Starts the native binary.
|
||||||
|
|
|
@ -250,6 +250,9 @@ Please report any problems you encounter via Github.</string>
|
||||||
|
|
||||||
<string name="sync_only_wifi_ssids_wifi_turn_on_wifi">Please turn on WiFi to select networks.</string>
|
<string name="sync_only_wifi_ssids_wifi_turn_on_wifi">Please turn on WiFi to select networks.</string>
|
||||||
|
|
||||||
|
<string name="respect_battery_saving_title">Respect Android battery saving setting</string>
|
||||||
|
<string name="respect_battery_saving_summary">Disable Syncthing if battery saving is active</string>
|
||||||
|
|
||||||
<string name="advanced_folder_picker">Use advanced Folder Picker</string>
|
<string name="advanced_folder_picker">Use advanced Folder Picker</string>
|
||||||
|
|
||||||
<string name="advanced_folder_picker_summary">Select any folder on the device for syncing</string>
|
<string name="advanced_folder_picker_summary">Select any folder on the device for syncing</string>
|
||||||
|
|
|
@ -24,6 +24,12 @@
|
||||||
android:key="sync_only_wifi_ssids_set"
|
android:key="sync_only_wifi_ssids_set"
|
||||||
android:title="@string/sync_only_wifi_ssids" />
|
android:title="@string/sync_only_wifi_ssids" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="respect_battery_saving"
|
||||||
|
android:title="@string/respect_battery_saving_title"
|
||||||
|
android:summary="@string/respect_battery_saving_summary"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
|
|
Loading…
Reference in a new issue