mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-10 03:55:53 +00:00
Disable wakelock experimental option on Android 6+ (#77)
This commit is contained in:
parent
466fc971dd
commit
2021ef6806
5 changed files with 29 additions and 21 deletions
|
@ -231,6 +231,12 @@ public class SettingsActivity extends SyncthingActivity {
|
||||||
|
|
||||||
mRunOnMeteredWifi.setEnabled(mRunOnWifi.isChecked());
|
mRunOnMeteredWifi.setEnabled(mRunOnWifi.isChecked());
|
||||||
mWifiSsidWhitelist.setEnabled(mRunOnWifi.isChecked());
|
mWifiSsidWhitelist.setEnabled(mRunOnWifi.isChecked());
|
||||||
|
/* Experimental options */
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
/* Wakelocks are only valid on Android 5 or lower. */
|
||||||
|
mUseWakelock.setEnabled(false);
|
||||||
|
mUseWakelock.setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
mCategorySyncthingOptions = findPreference("category_syncthing_options");
|
mCategorySyncthingOptions = findPreference("category_syncthing_options");
|
||||||
setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange);
|
setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
@ -133,13 +134,20 @@ public class SyncthingRunnable implements Runnable {
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
Log.w(TAG, "Failed to chmod Syncthing", e);
|
Log.w(TAG, "Failed to chmod Syncthing", e);
|
||||||
}
|
}
|
||||||
// Loop Syncthing
|
|
||||||
|
/**
|
||||||
|
* Potential fix for #498, keep the CPU running while native binary is running.
|
||||||
|
* Only valid on Android 5 or lower.
|
||||||
|
*/
|
||||||
|
PowerManager pm;
|
||||||
|
PowerManager.WakeLock wakeLock = null;
|
||||||
|
Boolean useWakeLock = mPreferences.getBoolean(Constants.PREF_USE_WAKE_LOCK, false);
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && useWakeLock) {
|
||||||
|
pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||||
|
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
|
||||||
|
}
|
||||||
|
|
||||||
Process process = null;
|
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 {
|
try {
|
||||||
if (wakeLock != null) {
|
if (wakeLock != null) {
|
||||||
wakeLock.acquire();
|
wakeLock.acquire();
|
||||||
|
@ -263,13 +271,6 @@ public class SyncthingRunnable implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the experimental setting for using wake locks has been enabled in settings.
|
|
||||||
*/
|
|
||||||
private boolean useWakeLock() {
|
|
||||||
return mPreferences.getBoolean(Constants.PREF_USE_WAKE_LOCK, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for running libsyncthing.so processes and return an array
|
* Look for running libsyncthing.so processes and return an array
|
||||||
* containing the PIDs of found instances.
|
* containing the PIDs of found instances.
|
||||||
|
|
|
@ -434,7 +434,7 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
|
||||||
|
|
||||||
<string name="keep_wakelock_while_binary_running">Prozessor wach halten während Syncthing läuft.</string>
|
<string name="keep_wakelock_while_binary_running">Prozessor wach halten während Syncthing läuft.</string>
|
||||||
|
|
||||||
<string name="keep_wakelock_while_binary_running_summary">Nutze dieses Einstellung, wenn du unerwartete Verbindungsabbrüche hast, während du im Batteriebetrieb arbeitest. Das wird zu einem erhöhten Energieverbrauch führen.</string>
|
<string name="keep_wakelock_while_binary_running_summary">Nur für Android 5 oder niedriger. Nutze diese Einstellung, wenn du unerwartete Verbindungsabbrüche hast, während du im Batteriebetrieb arbeitest. Das wird zu einem erhöhten Energieverbrauch führen.</string>
|
||||||
|
|
||||||
<string name="use_tor_title">Tor benutzen</string>
|
<string name="use_tor_title">Tor benutzen</string>
|
||||||
|
|
||||||
|
|
|
@ -438,7 +438,7 @@ Please report any problems you encounter via Github.</string>
|
||||||
|
|
||||||
<string name="keep_wakelock_while_binary_running">Keep the CPU awake while Syncthing is running</string>
|
<string name="keep_wakelock_while_binary_running">Keep the CPU awake while Syncthing is running</string>
|
||||||
|
|
||||||
<string name="keep_wakelock_while_binary_running_summary">Use this setting if you experience unexpected disconnects while operating on battery. This will result in increased battery consumption.</string>
|
<string name="keep_wakelock_while_binary_running_summary">Only for Android 5 or lower. Use this setting if you experience unexpected disconnects while operating on battery. This will result in increased battery consumption.</string>
|
||||||
|
|
||||||
<string name="use_tor_title">Use Tor</string>
|
<string name="use_tor_title">Use Tor</string>
|
||||||
|
|
||||||
|
|
|
@ -242,12 +242,6 @@
|
||||||
android:title="@string/category_experimental"
|
android:title="@string/category_experimental"
|
||||||
android:key="category_experimental">
|
android:key="category_experimental">
|
||||||
|
|
||||||
<CheckBoxPreference
|
|
||||||
android:key="wakelock_while_binary_running"
|
|
||||||
android:title="@string/keep_wakelock_while_binary_running"
|
|
||||||
android:summary="@string/keep_wakelock_while_binary_running_summary"
|
|
||||||
android:defaultValue="false" />
|
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="use_tor"
|
android:key="use_tor"
|
||||||
android:title="@string/use_tor_title"
|
android:title="@string/use_tor_title"
|
||||||
|
@ -270,6 +264,13 @@
|
||||||
android:title="@string/use_legacy_hashing_title"
|
android:title="@string/use_legacy_hashing_title"
|
||||||
android:summary="@string/use_legacy_hashing_summary" />
|
android:summary="@string/use_legacy_hashing_summary" />
|
||||||
|
|
||||||
|
<!-- Only valid for Android < 6 -->
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="wakelock_while_binary_running"
|
||||||
|
android:title="@string/keep_wakelock_while_binary_running"
|
||||||
|
android:summary="@string/keep_wakelock_while_binary_running_summary"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
|
|
Loading…
Reference in a new issue