diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 34caa376fb..e96fd0f5dd 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -205,6 +205,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swIdleDone; private SwitchCompat swLogarithmicBackoff; private SwitchCompat swExactAlarms; + private SwitchCompat swOpWakelock; private SwitchCompat swInfra; private SwitchCompat swDupMsgId; private EditText etKeywords; @@ -261,7 +262,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "use_modseq", "uid_command", "perform_expunge", "uid_expunge", "auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop", "use_top", "keep_alive_poll", "empty_pool", "idle_done", "logarithmic_backoff", - "exact_alarms", "infra", "dkim_verify", "dup_msgids", "global_keywords", "test_iab" + "exact_alarms", "op_wakelock", "infra", "dkim_verify", "dup_msgids", "global_keywords", "test_iab" }; private final static String[] RESET_QUESTIONS = new String[]{ @@ -416,6 +417,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swIdleDone = view.findViewById(R.id.swIdleDone); swLogarithmicBackoff = view.findViewById(R.id.swLogarithmicBackoff); swExactAlarms = view.findViewById(R.id.swExactAlarms); + swOpWakelock = view.findViewById(R.id.swOpWakelock); swInfra = view.findViewById(R.id.swInfra); swDupMsgId = view.findViewById(R.id.swDupMsgId); etKeywords = view.findViewById(R.id.etKeywords); @@ -1426,6 +1428,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + swOpWakelock.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("op_wakelock", checked).apply(); + } + }); + swInfra.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -2126,6 +2135,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swIdleDone.setChecked(prefs.getBoolean("idle_done", true)); swLogarithmicBackoff.setChecked(prefs.getBoolean("logarithmic_backoff", true)); swExactAlarms.setChecked(prefs.getBoolean("exact_alarms", true)); + swOpWakelock.setChecked(prefs.getBoolean("op_wakelock", false)); swInfra.setChecked(prefs.getBoolean("infra", false)); swDupMsgId.setChecked(prefs.getBoolean("dup_msgids", false)); etKeywords.setText(prefs.getString("global_keywords", null)); diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index f0839bd0aa..20388622f2 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -2083,8 +2083,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences public void run() { super.run(); - long start = new Date().getTime(); long timeout = 0; + boolean op_wakelock = prefs.getBoolean("op_wakelock", false); + + long start = new Date().getTime(); try { List partition; synchronized (partitions) { @@ -2122,7 +2124,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences else timeout += WAKELOCK_OPERATION_MAX; // -> 10 seconds - wlOperations.acquire(timeout); + if (op_wakelock) + wlOperations.acquire(timeout); + else + wlOperations.acquire(); Log.i(account.name + "/" + folder.name + " executing partition=" + key + @@ -2255,11 +2260,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences else Log.e(ex); } finally { - if (!wlOperations.isHeld()) { - long elapsed = new Date().getTime() - start; - EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Debug, - key + " prematurely released" + - " elapsed=" + elapsed + " timeout=" + timeout); + long elapsed = new Date().getTime() - start; + if (!wlOperations.isHeld() || elapsed > timeout) { + String msg = key + " prematurely released" + + " elapsed=" + elapsed + + " timeout=" + timeout + + " enforced=" + op_wakelock + + " held=" + wlOperations.isHeld() + + " host=" + account.host; + Log.e(msg); + EntityLog.log(ServiceSynchronize.this, EntityLog.Type.Debug, msg); } wlOperations.release(); } diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 44d80e8ef9..f8263bee37 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -1490,12 +1490,24 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="12dp" + android:checked="true" android:text="@string/title_advanced_exact_alarms" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvLogarithmicBackoffHint" app:switchPadding="12dp" /> + + Poll on keep-alive Empty connection pool Use exact timers + Operation wakelock timeout Show infrastructure Duplicates by message ID Global keywords