Add a "Screen security" option that determines whether FLAG_SECURE is set

This commit is contained in:
Alexander Bakker 2018-05-11 19:33:20 +02:00
parent 4b9ec0cc9c
commit 9b6da0d3e3
7 changed files with 37 additions and 27 deletions

View file

@ -16,7 +16,9 @@ public abstract class AegisActivity extends AppCompatActivity {
_app = (AegisApplication) getApplication();
// set FLAG_SECURE on the window of every AegisActivity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
if (_app.getPreferences().getBoolean("pref_secure_screen", true)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
// set the theme
_darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);

View file

@ -55,7 +55,9 @@ public class IntroActivity extends AppIntro implements DerivationTask.Callback {
_app = (AegisApplication) getApplication();
// set FLAG_SECURE on the window of every IntroActivity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
if (_app.getPreferences().getBoolean("pref_secure_screen", true)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
showSkipButton(false);
//showPagerIndicator(false);

View file

@ -192,13 +192,9 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
private void onPreferencesResult(int resultCode, Intent data) {
// refresh the entire key profile list if needed
if (data.getBooleanExtra("needsReload", false)) {
_keyProfileView.clearKeys();
for (DatabaseEntry entry : _db.getKeys()) {
_keyProfileView.addKey(new KeyProfile(entry));
}
}
if (data.getBooleanExtra("needsRefresh", false)) {
if (data.getBooleanExtra("needsRecreate", false)) {
recreate();
} else if (data.getBooleanExtra("needsRefresh", false)) {
boolean showIssuer = _app.getPreferences().getBoolean("pref_issuer", false);
_keyProfileView.setShowIssuer(showIssuer);
}
@ -343,12 +339,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
protected void onResume() {
super.onResume();
boolean darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);
if (darkMode != isDark()) {
setPreferredTheme(darkMode);
recreate();
}
// refresh all codes to prevent showing old ones
_keyProfileView.refresh();
}

View file

@ -11,6 +11,8 @@ import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.support.v7.app.AlertDialog;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import java.io.FileNotFoundException;
@ -49,15 +51,6 @@ public class PreferencesFragment extends PreferenceFragment {
// while the user provides credentials to decrypt it
private DatabaseImporter _converter;
private void setResult() {
getActivity().setResult(Activity.RESULT_OK, _result);
}
private void finish() {
setResult();
getActivity().finish();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -67,12 +60,13 @@ public class PreferencesFragment extends PreferenceFragment {
_db = app.getDatabaseManager();
// set the result intent in advance
setResult();
getActivity().setResult(Activity.RESULT_OK, _result);
Preference darkModePreference = findPreference("pref_dark_mode");
darkModePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
_result.putExtra("needsRecreate", true);
Toast.makeText(getActivity(), "Dark mode setting will be applied after closing this screen", Toast.LENGTH_SHORT).show();
return true;
}
@ -128,6 +122,21 @@ public class PreferencesFragment extends PreferenceFragment {
return true;
}
});
Preference screenPreference = findPreference("pref_secure_screen");
screenPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
_result.putExtra("needsRecreate", true);
Window window = getActivity().getWindow();
if ((boolean)newValue) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
return true;
}
});
}
@Override
@ -260,7 +269,7 @@ public class PreferencesFragment extends PreferenceFragment {
return;
}
_result.putExtra("needsReload", true);
_result.putExtra("needsRecreate", true);
Toast.makeText(getActivity(), String.format(Locale.getDefault(), "Imported %d entries", entries.size()), Toast.LENGTH_LONG).show();
}

View file

@ -88,7 +88,7 @@ public class ScannerActivity extends AegisActivity implements ZXingScannerView.R
}
@Override
protected void setPreferredTheme(boolean nightMode) {
protected void setPreferredTheme(boolean darkMode) {
}

View file

@ -20,6 +20,8 @@
<string name="pref_import_summary">Import a database</string>
<string name="pref_export_title">Export</string>
<string name="pref_export_summary">Export the database</string>
<string name="pref_secure_screen_title">Screen security</string>
<string name="pref_secure_screen_summary">Block screenshots and other attempts to capture the screen within the app</string>
<string name="fingerprint_hint">Touch sensor</string>
<string name="fingerprint_not_recognized">Fingerprint not recognized. Try again</string>

View file

@ -19,6 +19,11 @@
<PreferenceCategory
android:title="Security">
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_secure_screen"
android:title="@string/pref_secure_screen_title"
android:summary="@string/pref_secure_screen_summary"/>
<EditTextPreference
android:key="pref_timeout"
android:title="@string/pref_timeout_title"