Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable wakelock experimental option on Android 6+ #77

Merged
merged 1 commit into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ public void onActivityCreated(Bundle savedInstanceState) {

mRunOnMeteredWifi.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");
setPreferenceCategoryChangeListener(mCategorySyncthingOptions, this::onSyncthingPreferenceChange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.SystemClock;
Expand Down Expand Up @@ -133,13 +134,20 @@ public String run(boolean returnStdOut) throws ExecutableNotFoundException {
} catch (IOException | InterruptedException 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;
// 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();
Expand Down Expand Up @@ -263,13 +271,6 @@ private void putCustomEnvironmentVariables(Map<String, String> environment, Shar
}
}

/**
* 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
* containing the PIDs of found instances.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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_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>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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_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>

Expand Down
13 changes: 7 additions & 6 deletions app/src/main/res/xml/app_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,6 @@
android:title="@string/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
android:key="use_tor"
android:title="@string/use_tor_title"
Expand All @@ -270,6 +264,13 @@
android:title="@string/use_legacy_hashing_title"
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
Expand Down