mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-28 16:40:53 +01:00
Added setting for biometric inactivity period
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user