Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Block screenshots #112

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
android:persistent="false">
<intent android:action="com.google.android.apps.authenticator.settings.ABOUT" />
</PreferenceScreen>
<SwitchPreference
android:defaultValue="true"
android:key="blockScreenshotsEnabled"
android:title="Block Screenshots" />
</PreferenceScreen>