From 7c4b0589049050aa55c3e5989dc6efcac84a11a4 Mon Sep 17 00:00:00 2001 From: Jakob Nixdorf Date: Thu, 30 Nov 2017 16:25:42 +0100 Subject: [PATCH] Add settings to enable screenshots (special features) --- .../flocke/andotp/Activities/MainActivity.java | 8 ++++++-- .../andotp/Activities/SettingsActivity.java | 8 ++++++++ .../flocke/andotp/Utilities/Settings.java | 4 ++++ app/src/main/res/values/settings.xml | 2 ++ app/src/main/res/values/strings_settings.xml | 5 +++++ app/src/main/res/xml/preferences_special.xml | 16 ++++++++++++++++ 6 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/xml/preferences_special.xml diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index d4a5e5ad..1e30cf1e 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -279,7 +279,10 @@ public class MainActivity extends BaseActivity super.onCreate(savedInstanceState); setTitle(R.string.app_name); - getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + + if (! settings.getScreenshotsEnabled()) + getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); @@ -434,7 +437,8 @@ public class MainActivity extends BaseActivity key.equals(getString(R.string.settings_key_thumbnail_size))) { adapter.notifyDataSetChanged(); } else if (key.equals(getString(R.string.settings_key_theme)) || - key.equals(getString(R.string.settings_key_lang))) { + key.equals(getString(R.string.settings_key_lang)) || + key.equals(getString(R.string.settings_key_enable_screenshot))) { recreate(); } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java index 6f85ccad..5f2371cd 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/SettingsActivity.java @@ -147,6 +147,8 @@ public class SettingsActivity extends BaseActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity().getBaseContext()); + addPreferencesFromResource(R.xml.preferences); // Authentication @@ -191,6 +193,12 @@ public class SettingsActivity extends BaseActivity } }); pgpKey.setDefaultUserId("Alice "); + + + if (sharedPref.contains(getString(R.string.settings_key_special_features)) && + sharedPref.getBoolean(getString(R.string.settings_key_special_features), false)) { + addPreferencesFromResource(R.xml.preferences_special); + } } } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java index 7250e15e..12996174 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java @@ -360,4 +360,8 @@ public class Settings { return context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size); } } + + public boolean getScreenshotsEnabled() { + return getBoolean(R.string.settings_key_enable_screenshot, false); + } } diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index 8fb22fbc..b8bf263c 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -34,6 +34,8 @@ pref_no_tags_toggle pref_tags_toggles + pref_enable_screenshot + none system diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index ca9b2fba..d54298f4 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -29,6 +29,8 @@ Sign encrypted backups Verify encrypted backups + Enable screenshots + Hide the OTP tokens by default, requiring them to be revealed manually @@ -48,6 +50,9 @@ Encrypted backups are only imported if they are signed with a valid key + Allow to take screenshots of the main screen + (disabled by default for security reasons) + This feature requires at least Android 5.0 (Lollipop) to work diff --git a/app/src/main/res/xml/preferences_special.xml b/app/src/main/res/xml/preferences_special.xml new file mode 100644 index 00000000..ca7c314c --- /dev/null +++ b/app/src/main/res/xml/preferences_special.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file