Added exact alarm debug option

pull/198/head
M66B 4 years ago
parent f595f21f61
commit c1e6d7bf34

@ -0,0 +1,43 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.core.app.AlarmManagerCompat;
import androidx.preference.PreferenceManager;
public class AlarmManagerCompatEx {
static void setAndAllowWhileIdle(
@NonNull Context context, @NonNull AlarmManager am,
int type, long trigger, @NonNull PendingIntent pi) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean exact_alarms = prefs.getBoolean("exact_alarms", false);
if (exact_alarms)
AlarmManagerCompat.setExactAndAllowWhileIdle(am, type, trigger, pi);
else
AlarmManagerCompat.setAndAllowWhileIdle(am, type, trigger, pi);
}
}

@ -40,7 +40,6 @@ import android.util.Pair;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.AlarmManagerCompat;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.Person; import androidx.core.app.Person;
import androidx.core.app.RemoteInput; import androidx.core.app.RemoteInput;
@ -1750,7 +1749,7 @@ class Core {
context, ServiceSend.PI_EXISTS, intent, PendingIntent.FLAG_UPDATE_CURRENT); context, ServiceSend.PI_EXISTS, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, piExists); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, piExists);
return; return;
} }

@ -27,7 +27,6 @@ import android.content.SharedPreferences;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.AlarmManagerCompat;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.room.ColumnInfo; import androidx.room.ColumnInfo;
import androidx.room.Entity; import androidx.room.Entity;
@ -464,7 +463,7 @@ public class EntityMessage implements Serializable {
am.cancel(pi); am.cancel(pi);
} else { } else {
Log.i("Set snooze id=" + id + " wakeup=" + new Date(wakeup)); Log.i("Set snooze id=" + id + " wakeup=" + new Date(wakeup));
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, wakeup, pi); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, wakeup, pi);
} }
} }

@ -118,6 +118,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swAuthLogin; private SwitchCompat swAuthLogin;
private SwitchCompat swAuthNtlm; private SwitchCompat swAuthNtlm;
private SwitchCompat swAuthSasl; private SwitchCompat swAuthSasl;
private SwitchCompat swExactAlarms;
private TextView tvProcessors; private TextView tvProcessors;
private TextView tvMemoryClass; private TextView tvMemoryClass;
private TextView tvMemoryUsage; private TextView tvMemoryUsage;
@ -142,7 +143,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"experiments", "wal", "query_threads", "crash_reports", "cleanup_attachments", "experiments", "wal", "query_threads", "crash_reports", "cleanup_attachments",
"protocol", "debug", "log_level", "protocol", "debug", "log_level",
"use_modseq", "perform_expunge", "use_modseq", "perform_expunge",
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl" "auth_plain", "auth_login", "auth_ntlm", "auth_sasl",
"exact_alarms"
}; };
private final static String[] RESET_QUESTIONS = new String[]{ private final static String[] RESET_QUESTIONS = new String[]{
@ -222,6 +224,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swAuthLogin = view.findViewById(R.id.swAuthLogin); swAuthLogin = view.findViewById(R.id.swAuthLogin);
swAuthNtlm = view.findViewById(R.id.swAuthNtlm); swAuthNtlm = view.findViewById(R.id.swAuthNtlm);
swAuthSasl = view.findViewById(R.id.swAuthSasl); swAuthSasl = view.findViewById(R.id.swAuthSasl);
swExactAlarms = view.findViewById(R.id.swExactAlarms);
tvProcessors = view.findViewById(R.id.tvProcessors); tvProcessors = view.findViewById(R.id.tvProcessors);
tvMemoryClass = view.findViewById(R.id.tvMemoryClass); tvMemoryClass = view.findViewById(R.id.tvMemoryClass);
tvMemoryUsage = view.findViewById(R.id.tvMemoryUsage); tvMemoryUsage = view.findViewById(R.id.tvMemoryUsage);
@ -577,6 +580,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
swExactAlarms.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("exact_alarms", checked).apply();
}
});
btnGC.setOnClickListener(new View.OnClickListener() { btnGC.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -946,6 +956,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swAuthLogin.setChecked(prefs.getBoolean("auth_login", true)); swAuthLogin.setChecked(prefs.getBoolean("auth_login", true));
swAuthNtlm.setChecked(prefs.getBoolean("auth_ntlm", true)); swAuthNtlm.setChecked(prefs.getBoolean("auth_ntlm", true));
swAuthSasl.setChecked(prefs.getBoolean("auth_sasl", true)); swAuthSasl.setChecked(prefs.getBoolean("auth_sasl", true));
swExactAlarms.setChecked(prefs.getBoolean("exact_alarms", false));
tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors())); tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors()));

@ -35,7 +35,6 @@ import android.os.PowerManager;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.app.AlarmManagerCompat;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
@ -840,7 +839,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
long trigger = System.currentTimeMillis() + delay; long trigger = System.currentTimeMillis() + delay;
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi); am.cancel(pi);
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, trigger, pi); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, trigger, pi);
} }
static void watchdog(Context context) { static void watchdog(Context context) {

@ -40,7 +40,6 @@ import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.app.AlarmManagerCompat;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.lifecycle.MediatorLiveData; import androidx.lifecycle.MediatorLiveData;
@ -150,7 +149,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
"download_headers", "download_eml", "download_headers", "download_eml",
"prefer_ip4", "standalone_vpn", "tcp_keep_alive", "ssl_harden", // force reconnect "prefer_ip4", "standalone_vpn", "tcp_keep_alive", "ssl_harden", // force reconnect
"experiments", "debug", "protocol", // force reconnect "experiments", "debug", "protocol", // force reconnect
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl" // force reconnect "auth_plain", "auth_login", "auth_ntlm", "auth_sasl", // force reconnect
"exact_alarms" // force schedule
)); ));
static final int PI_ALARM = 1; static final int PI_ALARM = 1;
@ -1900,7 +1900,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
long trigger = System.currentTimeMillis() + duration; long trigger = System.currentTimeMillis() + duration;
EntityLog.log(this, "### " + account.name + " keep alive" + EntityLog.log(this, "### " + account.name + " keep alive" +
" wait=" + account.poll_interval + " until=" + new Date(trigger)); " wait=" + account.poll_interval + " until=" + new Date(trigger));
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, trigger, pi); AlarmManagerCompatEx.setAndAllowWhileIdle(ServiceSynchronize.this, am, AlarmManager.RTC_WAKEUP, trigger, pi);
try { try {
wlAccount.release(); wlAccount.release();
@ -2108,7 +2108,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try { try {
long trigger = System.currentTimeMillis() + backoff * 1000L; long trigger = System.currentTimeMillis() + backoff * 1000L;
EntityLog.log(this, "### " + account.name + " backoff until=" + new Date(trigger)); EntityLog.log(this, "### " + account.name + " backoff until=" + new Date(trigger));
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, trigger, pi); AlarmManagerCompatEx.setAndAllowWhileIdle(ServiceSynchronize.this, am, AlarmManager.RTC_WAKEUP, trigger, pi);
try { try {
db.account().setAccountBackoff(account.id, trigger); db.account().setAccountBackoff(account.id, trigger);
@ -2451,7 +2451,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
Log.i("Schedule next=" + new Date(next)); Log.i("Schedule next=" + new Date(next));
Log.i("Schedule poll=" + poll); Log.i("Schedule poll=" + poll);
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, pi); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, pi);
if (sync & poll) { if (sync & poll) {
at = now + 30 * 1000L; at = now + 30 * 1000L;
@ -2484,10 +2484,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
EntityLog.log(context, "Poll next=" + new Date(next)); EntityLog.log(context, "Poll next=" + new Date(next));
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, piSync); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, piSync);
} }
} else } else
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, at, piSync); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, at, piSync);
} }
static long[] getSchedule(Context context) { static long[] getSchedule(Context context) {
@ -2598,7 +2598,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (next < now + WATCHDOG_INTERVAL / 5) if (next < now + WATCHDOG_INTERVAL / 5)
next += WATCHDOG_INTERVAL; next += WATCHDOG_INTERVAL;
Log.i("Sync watchdog at " + new Date(next)); Log.i("Sync watchdog at " + new Date(next));
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, pi); AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, pi);
} else } else
am.cancel(pi); am.cancel(pi);
} }

@ -601,6 +601,17 @@
app:layout_constraintTop_toBottomOf="@id/swAuthNtlm" app:layout_constraintTop_toBottomOf="@id/swAuthNtlm"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swExactAlarms"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_exact_alarms"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAuthSasl"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvProcessors" android:id="@+id/tvProcessors"
android:layout_width="0dp" android:layout_width="0dp"
@ -610,7 +621,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAuthSasl" /> app:layout_constraintTop_toBottomOf="@id/swExactAlarms" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvMemoryClass" android:id="@+id/tvMemoryClass"
@ -708,6 +719,7 @@
swQueries,tvQueriesHint,tvQueriesRemark,swWal, swQueries,tvQueriesHint,tvQueriesRemark,swWal,
swModSeq,swExpunge, swModSeq,swExpunge,
swAuthPlain,swAuthLogin,swAuthNtlm,swAuthSasl, swAuthPlain,swAuthLogin,swAuthNtlm,swAuthSasl,
swExactAlarms,
tvProcessors,tvMemoryClass,tvMemoryUsage,tvStorageUsage, tvProcessors,tvMemoryClass,tvMemoryUsage,tvStorageUsage,
tvFingerprint, tvFingerprint,
btnGC,btnCharsets,btnCiphers,btnFiles" /> btnGC,btnCharsets,btnCiphers,btnFiles" />

@ -296,6 +296,7 @@
<string name="title_advanced_receive">Receive messages for all accounts</string> <string name="title_advanced_receive">Receive messages for all accounts</string>
<string name="title_advanced_when">When</string> <string name="title_advanced_when">When</string>
<string name="title_advanced_optimize">Automatically optimize</string>
<string name="title_advanced_always">Always receive messages for these accounts</string> <string name="title_advanced_always">Always receive messages for these accounts</string>
<string name="title_advanced_schedule">Schedule</string> <string name="title_advanced_schedule">Schedule</string>
<string name="title_advanced_advanced">Advanced</string> <string name="title_advanced_advanced">Advanced</string>
@ -433,6 +434,9 @@
<string name="title_advanced_sync_on_launch">Synchronize on start</string> <string name="title_advanced_sync_on_launch">Synchronize on start</string>
<string name="title_advanced_double_back">Double \'back\' to exit</string> <string name="title_advanced_double_back">Double \'back\' to exit</string>
<string name="title_advanced_conversation_actions">Suggest actions (Android 10+)</string>
<string name="title_advanced_conversation_actions_replies">Suggest reply texts (Android 10+)</string>
<string name="title_advanced_language_detection">Detect message text language</string>
<string name="title_advanced_pull_refresh">Pull down to refresh</string> <string name="title_advanced_pull_refresh">Pull down to refresh</string>
<string name="title_advanced_autoscroll">Scroll to top on receiving new messages</string> <string name="title_advanced_autoscroll">Scroll to top on receiving new messages</string>
<string name="title_advanced_double_tap">Double tap to mark message read/unread</string> <string name="title_advanced_double_tap">Double tap to mark message read/unread</string>
@ -533,9 +537,6 @@
<string name="title_advanced_external_search">Allow other apps to search in messages</string> <string name="title_advanced_external_search">Allow other apps to search in messages</string>
<string name="title_advanced_shortcuts">Show frequently used contacts in Android share menu</string> <string name="title_advanced_shortcuts">Show frequently used contacts in Android share menu</string>
<string name="title_advanced_conversation_actions">Suggest actions (Android 10+)</string>
<string name="title_advanced_conversation_actions_replies">Suggest reply texts (Android 10+)</string>
<string name="title_advanced_language_detection">Detect message text language</string>
<string name="title_advanced_fts">Build search index</string> <string name="title_advanced_fts">Build search index</string>
<string name="title_advanced_fts_indexed">%1$d / %2$d messages indexed (%3$s)</string> <string name="title_advanced_fts_indexed">%1$d / %2$d messages indexed (%3$s)</string>
<string name="title_advanced_classification">Classify messages</string> <string name="title_advanced_classification">Classify messages</string>
@ -544,27 +545,27 @@
<string name="title_advanced_language">Language</string> <string name="title_advanced_language">Language</string>
<string name="title_advanced_language_system">System</string> <string name="title_advanced_language_system">System</string>
<string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string> <string name="title_advanced_watchdog">Periodically check if FairEmail is still active</string>
<string name="title_advanced_modseq" translatable="false">MODSEQ (debug only)</string>
<string name="title_advanced_expunge" translatable="false">EXPUNGE (debug only)</string>
<string name="title_advanced_auth_plain" translatable="false">PLAIN (debug only)</string>
<string name="title_advanced_auth_login" translatable="false">LOGIN (debug only)</string>
<string name="title_advanced_auth_ntlm" translatable="false">NTLM (debug only)</string>
<string name="title_advanced_auth_sasl" translatable="false">SASL (debug only)</string>
<string name="title_advanced_optimize">Automatically optimize</string>
<string name="title_advanced_updates">Check for GitHub updates</string> <string name="title_advanced_updates">Check for GitHub updates</string>
<string name="title_advanced_check_weekly">Check weekly instead of daily</string> <string name="title_advanced_check_weekly">Check weekly instead of daily</string>
<string name="title_advanced_experiments">Try experimental features</string> <string name="title_advanced_experiments">Try experimental features</string>
<string name="title_advanced_query_threads">Limit parallel database access</string>
<string name="title_advanced_wal">WAL (debug only)</string>
<string name="title_advanced_crash_reports">Send error reports</string> <string name="title_advanced_crash_reports">Send error reports</string>
<string name="title_advanced_protocol">Protocol logging</string>
<string name="title_advanced_log_info">Debug logging</string>
<string name="title_advanced_debug">Debug mode</string>
<string name="title_advanced_cleanup_attachments">Delete attachments of old messages</string> <string name="title_advanced_cleanup_attachments">Delete attachments of old messages</string>
<string name="title_advanced_cleanup">Cleanup</string> <string name="title_advanced_cleanup">Cleanup</string>
<string name="title_advanced_last_cleanup">Last cleanup: %1$s</string> <string name="title_advanced_last_cleanup">Last cleanup: %1$s</string>
<string name="title_advanced_app">App settings</string> <string name="title_advanced_app">App settings</string>
<string name="title_advanced_more">More options</string> <string name="title_advanced_more">More options</string>
<string name="title_advanced_protocol">Protocol logging</string>
<string name="title_advanced_log_info">Debug logging</string>
<string name="title_advanced_debug">Debug mode</string>
<string name="title_advanced_query_threads">Limit parallel database access</string>
<string name="title_advanced_wal" translatable="false">WAL (debug only)</string>
<string name="title_advanced_modseq" translatable="false">MODSEQ (debug only)</string>
<string name="title_advanced_expunge" translatable="false">EXPUNGE (debug only)</string>
<string name="title_advanced_auth_plain" translatable="false">PLAIN (debug only)</string>
<string name="title_advanced_auth_login" translatable="false">LOGIN (debug only)</string>
<string name="title_advanced_auth_ntlm" translatable="false">NTLM (debug only)</string>
<string name="title_advanced_auth_sasl" translatable="false">SASL (debug only)</string>
<string name="title_advanced_exact_alarms" translatable="false">Use exact timers (debug only)</string>
<string name="title_advanced_processors" translatable="false">Processors: %1$d</string> <string name="title_advanced_processors" translatable="false">Processors: %1$d</string>
<string name="title_advanced_memory_class" translatable="false">Memory class: %1$s/%2$s Total: %3$s</string> <string name="title_advanced_memory_class" translatable="false">Memory class: %1$s/%2$s Total: %3$s</string>
<string name="title_advanced_memory_usage" translatable="false">Memory usage: %1$s/%2$s Native: %3$s</string> <string name="title_advanced_memory_usage" translatable="false">Memory usage: %1$s/%2$s Native: %3$s</string>

Loading…
Cancel
Save