diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 9bf714de..a710a159 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -10,6 +10,7 @@
+
()); // default to empty list
mUseRoot = (CheckBoxPreference) findPreference(SyncthingService.PREF_USE_ROOT);
+ mKeepWakelock = (CheckBoxPreference) findPreference(SyncthingService.PREF_USE_WAKE_LOCK);
Preference appVersion = screen.findPreference(APP_VERSION_KEY);
mOptionsScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_OPTIONS_KEY);
mGuiScreen = (PreferenceScreen) screen.findPreference(SYNCTHING_GUI_KEY);
@@ -153,6 +155,7 @@ public class SettingsFragment extends PreferenceFragment
mSyncOnlyWifi.setOnPreferenceChangeListener(this);
mSyncOnlyOnSSIDs.setOnPreferenceChangeListener(this);
mUseRoot.setOnPreferenceClickListener(this);
+ mKeepWakelock.setOnPreferenceClickListener(this);
screen.findPreference(EXPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(IMPORT_CONFIG).setOnPreferenceClickListener(this);
screen.findPreference(SYNCTHING_RESET).setOnPreferenceClickListener(this);
@@ -358,6 +361,9 @@ public class SettingsFragment extends PreferenceFragment
mSyncthingService.getApi().requireRestart(getActivity());
}
return true;
+ case SyncthingService.PREF_USE_WAKE_LOCK:
+ mSyncthingService.getApi().requireRestart(getActivity());
+ return true;
case EXPORT_CONFIG:
new AlertDialog.Builder(getActivity())
.setMessage(R.string.dialog_confirm_export)
diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java
index fbdad329..2a6990c9 100644
--- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java
+++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingRunnable.java
@@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Environment;
+import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
@@ -95,7 +96,14 @@ public class SyncthingRunnable implements Runnable {
}
// Loop Syncthing
Process process = null;
+ // Potential fix for #498, keep the CPU running while native binary is running
+ PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
+ PowerManager.WakeLock wakeLock = useWakeLock()
+ ? pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG)
+ : null;
try {
+ if (wakeLock != null)
+ wakeLock.acquire();
// Loop to handle Syncthing restarts (these always have an error code of 3).
do {
ProcessBuilder pb = (useRoot())
@@ -132,6 +140,8 @@ public class SyncthingRunnable implements Runnable {
} catch (IOException | InterruptedException e) {
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
} finally {
+ if (wakeLock != null)
+ wakeLock.release();
if (process != null)
process.destroy();
if (ret != 0) {
@@ -149,6 +159,14 @@ public class SyncthingRunnable implements Runnable {
return sp.getBoolean(SyncthingService.PREF_USE_ROOT, false) && Shell.SU.available();
}
+ /**
+ * Returns true if the experimental setting for using wake locks has been enabled in settings.
+ */
+ private boolean useWakeLock() {
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
+ return sp.getBoolean(SyncthingService.PREF_USE_WAKE_LOCK, false);
+ }
+
/**
* Look for a running libsyncthing.so process and nice its IO.
*/
diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java
index 0b7fa3cf..8d9a5b2d 100644
--- a/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java
+++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/SyncthingService.java
@@ -94,6 +94,7 @@ public class SyncthingService extends Service implements
public static final String PREF_SYNC_ONLY_CHARGING = "sync_only_charging";
public static final String PREF_USE_ROOT = "use_root";
private static final String PREF_NOTIFICATION_TYPE = "notification_type";
+ public static final String PREF_USE_WAKE_LOCK = "wakelock_while_binary_running";
private static final int NOTIFICATION_ACTIVE = 1;
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 73e526aa..1ea8781d 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -296,6 +296,12 @@ Please report any problems you encounter via Github.
Export Configuration
+ Experimental
+
+ Keep the CPU awake while Syncthing is running
+
+ Use this setting if you experience unexpected disconnects while operating on battery. This will result in increased battery consumption.
+
Config was exported to %1$s
diff --git a/src/main/res/xml/app_settings.xml b/src/main/res/xml/app_settings.xml
index 3a43cfec..4585d008 100644
--- a/src/main/res/xml/app_settings.xml
+++ b/src/main/res/xml/app_settings.xml
@@ -147,6 +147,18 @@
android:title="@string/streset_title"
android:singleLine="true" />
+
+
+
+
+
+