From 6e86a3441838b18c3276e50b8075d881efe145b4 Mon Sep 17 00:00:00 2001 From: Joakim Uddholm Date: Thu, 20 Feb 2020 00:45:44 +0100 Subject: [PATCH 1/3] block screenshots in the main list view. Fixes #50 --- .../android/apps/authenticator/AuthenticatorActivity.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/java/com/google/android/apps/authenticator/AuthenticatorActivity.java b/java/com/google/android/apps/authenticator/AuthenticatorActivity.java index 93cd0c3..1cf1d5f 100644 --- a/java/com/google/android/apps/authenticator/AuthenticatorActivity.java +++ b/java/com/google/android/apps/authenticator/AuthenticatorActivity.java @@ -56,6 +56,7 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; +import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.widget.AbsListView; import android.widget.AdapterView; @@ -288,6 +289,10 @@ public void onCreate(Bundle savedInstanceState) { totpCounter = otpProvider.getTotpCounter(); totpClock = otpProvider.getTotpClock(); + + // Block screenshots + getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + setContentView(R.layout.main); toolbar = (Toolbar) findViewById(R.id.authenticator_toolbar); From aa644ce51eb3a0f49d1a9026024f884e7bbaa455 Mon Sep 17 00:00:00 2001 From: Joakim Uddholm Date: Thu, 20 Feb 2020 01:28:11 +0100 Subject: [PATCH 2/3] add toggleable setting. Restart activity when it changes. --- .../authenticator/AuthenticatorActivity.java | 32 ++++++++++++++++--- .../authenticator/res/xml/preferences.xml | 4 +++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/java/com/google/android/apps/authenticator/AuthenticatorActivity.java b/java/com/google/android/apps/authenticator/AuthenticatorActivity.java index 1cf1d5f..9c2e9b8 100644 --- a/java/com/google/android/apps/authenticator/AuthenticatorActivity.java +++ b/java/com/google/android/apps/authenticator/AuthenticatorActivity.java @@ -127,6 +127,12 @@ public class AuthenticatorActivity extends TestableActivity { */ public static final String KEY_ONBOARDING_COMPLETED = "onboardingCompleted"; + /** + * Key under which {@link #onboardingCompleted} is stored to know if user has completed the first + * onboarding experience or not. + */ + public static final String KEY_BLOCK_SCREENSHOTS_ENABLED = "blockScreenshotsEnabled"; + /** Frequency (milliseconds) with which TOTP countdown indicators are updated. */ public static final long TOTP_COUNTDOWN_REFRESH_PERIOD_MILLIS = 100L; @@ -242,6 +248,10 @@ public class AuthenticatorActivity extends TestableActivity { @VisibleForTesting boolean onboardingCompleted; + /** Whether screenshots should be blocked. */ + @VisibleForTesting + boolean blockScreenshotsEnabled; + /** Contains the bottom sheet instance showed when user click the red FAB */ @VisibleForTesting BottomSheetDialog bottomSheetDialog; @@ -291,7 +301,10 @@ public void onCreate(Bundle savedInstanceState) { // Block screenshots - getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + blockScreenshotsEnabled = preferences.getBoolean(KEY_BLOCK_SCREENSHOTS_ENABLED, true); + if (blockScreenshotsEnabled) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + } setContentView(R.layout.main); @@ -649,9 +662,14 @@ protected void onStart() { protected void onResume() { super.onResume(); Log.i(getString(R.string.app_name), LOCAL_TAG + ": onResume"); + boolean currentlyBlockingScreenshots = blockScreenshotsEnabled; + blockScreenshotsEnabled = preferences.getBoolean(KEY_BLOCK_SCREENSHOTS_ENABLED, true); darkModeEnabled = preferences.getBoolean(KEY_DARK_MODE_ENABLED, false); onboardingCompleted = preferences.getBoolean(KEY_ONBOARDING_COMPLETED, false); refreshToolbarAndStatusBarStyle(); + if (currentlyBlockingScreenshots != blockScreenshotsEnabled) { + restartActivity(); + } } @Override @@ -1301,15 +1319,19 @@ private void displayHowItWorksInstructions() { startActivity(intent); } + private void restartActivity() { + finish(); + overridePendingTransition(0, 0); + startActivity(new Intent(this, getClass())); + overridePendingTransition(0, 0); + } + private void switchUiMode() { darkModeEnabled = !darkModeEnabled; preferences.edit().putBoolean(KEY_DARK_MODE_ENABLED, darkModeEnabled).commit(); // Restart the activity to apply new theme. Here we try to remove the fade animation to help // users feel the app just do some light refreshing. - finish(); - overridePendingTransition(0, 0); - startActivity(new Intent(this, getClass())); - overridePendingTransition(0, 0); + restartActivity(); } private void showSettings() { diff --git a/java/com/google/android/apps/authenticator/res/xml/preferences.xml b/java/com/google/android/apps/authenticator/res/xml/preferences.xml index 8b45d54..8bd79e8 100644 --- a/java/com/google/android/apps/authenticator/res/xml/preferences.xml +++ b/java/com/google/android/apps/authenticator/res/xml/preferences.xml @@ -29,4 +29,8 @@ android:persistent="false"> + From 0ebe47cd87ab4b791b4bd7ab9f8ac6861aec060f Mon Sep 17 00:00:00 2001 From: Joakim Uddholm Date: Fri, 13 Mar 2020 10:05:41 +0100 Subject: [PATCH 3/3] Update KEY_BLOCK_SCREENSHOTS_ENABLED comment --- .../android/apps/authenticator/AuthenticatorActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/com/google/android/apps/authenticator/AuthenticatorActivity.java b/java/com/google/android/apps/authenticator/AuthenticatorActivity.java index 9c2e9b8..bd8ac63 100644 --- a/java/com/google/android/apps/authenticator/AuthenticatorActivity.java +++ b/java/com/google/android/apps/authenticator/AuthenticatorActivity.java @@ -128,8 +128,8 @@ public class AuthenticatorActivity extends TestableActivity { public static final String KEY_ONBOARDING_COMPLETED = "onboardingCompleted"; /** - * Key under which {@link #onboardingCompleted} is stored to know if user has completed the first - * onboarding experience or not. + * Key under which {@link #blockScreenshotsEnabled} is stored to know if screenshots should be + * blocked or not. */ public static final String KEY_BLOCK_SCREENSHOTS_ENABLED = "blockScreenshotsEnabled";