From f9729cdca447e9742cc5d1d7311a03bdaef033aa Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 11 Jul 2019 17:06:49 +0200 Subject: [PATCH] Added setting for biometric inactivity period --- FAQ.md | 3 ++- .../faircode/email/FragmentOptionsMisc.java | 27 ++++++++++++++++++- .../main/java/eu/faircode/email/Helper.java | 11 +++----- .../main/res/layout/fragment_options_misc.xml | 24 ++++++++++++++++- app/src/main/res/values/strings.xml | 17 ++++++++++++ 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/FAQ.md b/FAQ.md index 672d0b7286..3abab91aa5 100644 --- a/FAQ.md +++ b/FAQ.md @@ -1901,7 +1901,8 @@ for a list of privacy friendly email providers with advantages and disadvantages If your device has a biometric sensor, for example a fingerprint sensor, you can enable/disable biometric authentication in the navigation (hamburger) menu of the setup screen. When enabled FairEmail will require biometric authentication after a period of inactivity or after the screen has been turned off while FairEmail was running. -Activity is navigation within FairEmail, for example opening a conversation thread. The inactivity period length is the same as the screen timeout. +Activity is navigation within FairEmail, for example opening a conversation thread. +The inactivity period duration can be configured in the miscellaneous settings. When biometric authentication is enabled new message notifications will not show any content and FairEmail won't be visible on the Android recents screen. Biometric authentication is meant to prevent others from seeing your messages only. diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index e931df79cb..edb3ba6cec 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -31,8 +31,10 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.Button; import android.widget.CompoundButton; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; @@ -51,6 +53,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swSubscriptions; private TextView tvSubscriptionPro; private SwitchCompat swSubscribedOnly; + private Spinner spBiometricsTimeout; private SwitchCompat swEnglish; private SwitchCompat swWatchdog; private SwitchCompat swUpdates; @@ -66,7 +69,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private Group grpDebug; private final static String[] RESET_OPTIONS = new String[]{ - "badge", "subscriptions", "subscribed_only", "english", "watchdog", "updates", "crash_reports", "debug" + "badge", "subscriptions", "subscribed_only", "biometrics_timeout", "english", "watchdog", "updates", "crash_reports", "debug" }; private final static String[] RESET_QUESTIONS = new String[]{ @@ -87,6 +90,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swSubscriptions = view.findViewById(R.id.swSubscriptions); tvSubscriptionPro = view.findViewById(R.id.tvSubscriptionPro); swSubscribedOnly = view.findViewById(R.id.swSubscribedOnly); + spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout); swEnglish = view.findViewById(R.id.swEnglish); swWatchdog = view.findViewById(R.id.swWatchdog); swUpdates = view.findViewById(R.id.swUpdates); @@ -132,6 +136,19 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc } }); + spBiometricsTimeout.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + int[] values = getResources().getIntArray(R.array.biometricsTimeoutValues); + prefs.edit().putInt("biometrics_timeout", values[position]).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("biometrics_timeout").apply(); + } + }); + swEnglish.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { @@ -274,6 +291,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swSubscriptions.setEnabled(pro); swSubscribedOnly.setChecked(prefs.getBoolean("subscribed_only", false)); + int biometrics_timeout = prefs.getInt("biometrics_timeout", 2); + int[] biometricTimeoutValues = getResources().getIntArray(R.array.biometricsTimeoutValues); + for (int pos = 0; pos < biometricTimeoutValues.length; pos++) + if (biometricTimeoutValues[pos] == biometrics_timeout) { + spBiometricsTimeout.setSelection(pos); + break; + } + swEnglish.setChecked(prefs.getBoolean("english", false)); swWatchdog.setChecked(prefs.getBoolean("watchdog", true)); swUpdates.setChecked(prefs.getBoolean("updates", true)); diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 39e309538e..8144bc4571 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -21,7 +21,6 @@ package eu.faircode.email; import android.app.Dialog; import android.content.ActivityNotFoundException; -import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -37,7 +36,6 @@ import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Parcel; -import android.provider.Settings; import android.text.Spannable; import android.text.Spanned; import android.text.format.DateUtils; @@ -663,17 +661,14 @@ public class Helper { static boolean shouldAuthenticate(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean biometrics = prefs.getBoolean("biometrics", false); + long biometrics_timeout = prefs.getInt("biometrics_timeout", 2) * 60 * 1000L; if (biometrics) { - ContentResolver resolver = context.getContentResolver(); - int screen_timeout = Settings.System.getInt(resolver, Settings.System.SCREEN_OFF_TIMEOUT, -1); - Log.i("Screen timeout=" + screen_timeout); - long now = new Date().getTime(); long last_authentication = prefs.getLong("last_authentication", 0); - Log.i("Authentication valid until=" + new Date(last_authentication + screen_timeout)); + Log.i("Authentication valid until=" + new Date(last_authentication + biometrics_timeout)); - if (last_authentication + screen_timeout < now) + if (last_authentication + biometrics_timeout < now) return true; prefs.edit().putLong("last_authentication", now).apply(); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 35bd8edddf..069f61ea2c 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -85,6 +85,28 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swSubscribedOnly" /> + + + + Show launcher icon with number of new messages Manage folder subscriptions Synchronize subscribed folders only + Biometric authentication timeout Force English language Periodically check if FairEmail is still active Check for updates @@ -851,6 +852,22 @@ Bcc + + 1 + 2 + 5 + 10 + 20 + + + + One minute + 2 minutes + 5 minutes + 10 minutes + 20 minutes + + @color/red @color/pink