mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 01:23:38 +02:00
Added option to lock on leaving app
This commit is contained in:
@@ -244,7 +244,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
||||
|
||||
visible = false;
|
||||
|
||||
if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this))
|
||||
if (!this.getClass().equals(ActivityMain.class) &&
|
||||
Helper.shouldAuthenticate(this, true))
|
||||
finishAndRemoveTask();
|
||||
}
|
||||
|
||||
@@ -258,7 +259,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
||||
public void onUserInteraction() {
|
||||
Log.d("User interaction");
|
||||
|
||||
if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this)) {
|
||||
if (!this.getClass().equals(ActivityMain.class) &&
|
||||
Helper.shouldAuthenticate(this, false)) {
|
||||
finishAndRemoveTask();
|
||||
Intent main = new Intent(this, ActivityMain.class);
|
||||
main.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
@@ -365,7 +367,8 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
|
||||
}
|
||||
|
||||
private void checkAuthentication() {
|
||||
if (!this.getClass().equals(ActivityMain.class) && Helper.shouldAuthenticate(this)) {
|
||||
if (!this.getClass().equals(ActivityMain.class) &&
|
||||
Helper.shouldAuthenticate(this, false)) {
|
||||
Intent intent = getIntent();
|
||||
finishAndRemoveTask();
|
||||
processStreams(intent);
|
||||
|
||||
@@ -231,7 +231,7 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
|
||||
}
|
||||
};
|
||||
|
||||
if (Helper.shouldAuthenticate(this))
|
||||
if (Helper.shouldAuthenticate(this, false))
|
||||
Helper.authenticate(ActivityMain.this, ActivityMain.this, null,
|
||||
new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -73,6 +73,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
|
||||
private Button btnBiometrics;
|
||||
private Spinner spBiometricsTimeout;
|
||||
private SwitchCompat swAutoLock;
|
||||
private SwitchCompat swAutoLockNav;
|
||||
private TextView tvAutoLockNavHint;
|
||||
private SwitchCompat swClientId;
|
||||
private TextView tvClientId;
|
||||
private SwitchCompat swDisplayHidden;
|
||||
@@ -97,7 +99,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
|
||||
"confirm_links", "check_links_dbl", "browse_links",
|
||||
"confirm_images", "ask_images", "html_always_images", "confirm_html", "ask_html",
|
||||
"disable_tracking", "hide_timezone",
|
||||
"pin", "biometrics", "biometrics_timeout", "autolock",
|
||||
"pin", "biometrics", "biometrics_timeout", "autolock", "autolock_nav",
|
||||
"client_id", "display_hidden", "incognito_keyboard", "secure",
|
||||
"generic_ua", "safe_browsing", "load_emoji",
|
||||
"disconnect_auto_update", "disconnect_links", "disconnect_images"
|
||||
@@ -127,6 +129,8 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
|
||||
btnBiometrics = view.findViewById(R.id.btnBiometrics);
|
||||
spBiometricsTimeout = view.findViewById(R.id.spBiometricsTimeout);
|
||||
swAutoLock = view.findViewById(R.id.swAutoLock);
|
||||
swAutoLockNav = view.findViewById(R.id.swAutoLockNav);
|
||||
tvAutoLockNavHint = view.findViewById(R.id.tvAutoLockNavHint);
|
||||
swClientId = view.findViewById(R.id.swClientId);
|
||||
tvClientId = view.findViewById(R.id.tvClientId);
|
||||
swDisplayHidden = view.findViewById(R.id.swDisplayHidden);
|
||||
@@ -286,6 +290,15 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
|
||||
}
|
||||
});
|
||||
|
||||
swAutoLockNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("autolock_nav", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
tvAutoLockNavHint.setText(getString(R.string.title_advanced_display_autolock_nav_hint, Helper.AUTOLOCK_GRACE));
|
||||
|
||||
swClientId.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -488,6 +501,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
|
||||
}
|
||||
|
||||
swAutoLock.setChecked(prefs.getBoolean("autolock", true));
|
||||
swAutoLockNav.setChecked(prefs.getBoolean("autolock_nav", false));
|
||||
|
||||
swClientId.setChecked(prefs.getBoolean("client_id", true));
|
||||
swDisplayHidden.setChecked(prefs.getBoolean("display_hidden", false));
|
||||
|
||||
@@ -158,6 +158,7 @@ public class Helper {
|
||||
static final int BUFFER_SIZE = 8192; // Same as in Files class
|
||||
static final long MIN_REQUIRED_SPACE = 250 * 1024L * 1024L;
|
||||
static final int MAX_REDIRECTS = 5; // https://www.freesoft.org/CIE/RFC/1945/46.htm
|
||||
static final int AUTOLOCK_GRACE = 7; // seconds
|
||||
|
||||
static final String PGP_BEGIN_MESSAGE = "-----BEGIN PGP MESSAGE-----";
|
||||
static final String PGP_END_MESSAGE = "-----END PGP MESSAGE-----";
|
||||
@@ -1866,7 +1867,7 @@ public class Helper {
|
||||
}
|
||||
}
|
||||
|
||||
static boolean shouldAuthenticate(Context context) {
|
||||
static boolean shouldAuthenticate(Context context, boolean pausing) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean biometrics = prefs.getBoolean("biometrics", false);
|
||||
String pin = prefs.getString("pin", null);
|
||||
@@ -1875,12 +1876,17 @@ public class Helper {
|
||||
long now = new Date().getTime();
|
||||
long last_authentication = prefs.getLong("last_authentication", 0);
|
||||
long biometrics_timeout = prefs.getInt("biometrics_timeout", 2) * 60 * 1000L;
|
||||
boolean autolock_nav = prefs.getBoolean("autolock_nav", false);
|
||||
Log.i("Authentication valid until=" + new Date(last_authentication + biometrics_timeout));
|
||||
|
||||
if (last_authentication + biometrics_timeout < now)
|
||||
return true;
|
||||
|
||||
prefs.edit().putLong("last_authentication", now).apply();
|
||||
if (autolock_nav && pausing)
|
||||
last_authentication = now - biometrics_timeout + AUTOLOCK_GRACE * 1000L;
|
||||
else
|
||||
last_authentication = now;
|
||||
prefs.edit().putLong("last_authentication", last_authentication).apply();
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -2005,7 +2011,7 @@ public class Helper {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
Log.i("Authenticate PIN dismissed");
|
||||
if (shouldAuthenticate(activity)) // Some Android versions call dismiss on OK
|
||||
if (shouldAuthenticate(activity, false)) // Some Android versions call dismiss on OK
|
||||
ApplicationEx.getMainHandler().post(cancelled);
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user