Exclude from recents when using biometric authentication

pull/157/head
M66B 5 years ago
parent 7d60483274
commit c758723855

@ -156,6 +156,20 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
} }
@Override
public void startActivity(Intent intent) {
if (Helper.hasAuthentication(this))
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivity(intent);
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
if (Helper.hasAuthentication(this))
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivityForResult(intent, requestCode);
}
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
Log.i("Preference " + key + "=" + prefs.getAll().get(key)); Log.i("Preference " + key + "=" + prefs.getAll().get(key));

@ -27,14 +27,13 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.util.List; import java.util.List;
public class ActivityMain extends AppCompatActivity implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener { public class ActivityMain extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
getSupportFragmentManager().addOnBackStackChangedListener(this); getSupportFragmentManager().addOnBackStackChangedListener(this);

@ -39,4 +39,18 @@ public class DialogFragmentEx extends DialogFragment {
} }
} }
} }
@Override
public void startActivity(Intent intent) {
if (Helper.hasAuthentication(getContext()))
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivity(intent);
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
if (Helper.hasAuthentication(getContext()))
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivityForResult(intent, requestCode);
}
} }

@ -53,6 +53,20 @@ public class FragmentBase extends Fragment {
updateSubtitle(); updateSubtitle();
} }
@Override
public void startActivity(Intent intent) {
if (Helper.hasAuthentication(getContext()))
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivity(intent);
}
@Override
public void startActivityForResult(Intent intent, int requestCode) {
if (Helper.hasAuthentication(getContext()))
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivityForResult(intent, requestCode);
}
protected void finish() { protected void finish() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
getFragmentManager().popBackStack(); getFragmentManager().popBackStack();

@ -655,6 +655,11 @@ public class Helper {
return Objects.equals(signed, expected); return Objects.equals(signed, expected);
} }
static boolean hasAuthentication(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean("biometrics", false);
}
static boolean shouldAuthenticate(Context context) { static boolean shouldAuthenticate(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean biometrics = prefs.getBoolean("biometrics", false); boolean biometrics = prefs.getBoolean("biometrics", false);

Loading…
Cancel
Save