diff --git a/java/com/google/android/apps/authenticator/AuthenticatorActivity.java b/java/com/google/android/apps/authenticator/AuthenticatorActivity.java
index 93cd0c3..bd8ac63 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;
@@ -126,6 +127,12 @@ public class AuthenticatorActivity extends TestableActivity {
*/
public static final String KEY_ONBOARDING_COMPLETED = "onboardingCompleted";
+ /**
+ * 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";
+
/** Frequency (milliseconds) with which TOTP countdown indicators are updated. */
public static final long TOTP_COUNTDOWN_REFRESH_PERIOD_MILLIS = 100L;
@@ -241,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;
@@ -288,6 +299,13 @@ public void onCreate(Bundle savedInstanceState) {
totpCounter = otpProvider.getTotpCounter();
totpClock = otpProvider.getTotpClock();
+
+ // Block screenshots
+ blockScreenshotsEnabled = preferences.getBoolean(KEY_BLOCK_SCREENSHOTS_ENABLED, true);
+ if (blockScreenshotsEnabled) {
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
+ }
+
setContentView(R.layout.main);
toolbar = (Toolbar) findViewById(R.id.authenticator_toolbar);
@@ -644,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
@@ -1296,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">
+