Commit b3bd8685 authored by Vaclav Brozek's avatar Vaclav Brozek Committed by Commit Bot

Convert ReauthenticationManager.OverrideState to @IntDef

The OverrideState enum is converted in this CL to plain integers and
@IntDef for efficiency. More context on the associated bug.

Bug: 806315
Change-Id: Ie7b5d777394ca77c9f9447d8db33754bcf9f7017
Reviewed-on: https://chromium-review.googlesource.com/889738Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532810}
parent 5e4bfc34
...@@ -26,7 +26,12 @@ import java.lang.annotation.RetentionPolicy; ...@@ -26,7 +26,12 @@ import java.lang.annotation.RetentionPolicy;
*/ */
public final class ReauthenticationManager { public final class ReauthenticationManager {
// Used for various ways to override checks provided by this class. // Used for various ways to override checks provided by this class.
public enum OverrideState { NOT_OVERRIDDEN, AVAILABLE, UNAVAILABLE } @Retention(RetentionPolicy.SOURCE)
@IntDef({OVERRIDE_STATE_NOT_OVERRIDDEN, OVERRIDE_STATE_AVAILABLE, OVERRIDE_STATE_UNAVAILABLE})
public @interface OverrideState {}
public static final int OVERRIDE_STATE_NOT_OVERRIDDEN = 0;
public static final int OVERRIDE_STATE_AVAILABLE = 1;
public static final int OVERRIDE_STATE_UNAVAILABLE = 2;
// Used to specify the scope of the reauthentication -- either to grant bulk access like, e.g., // Used to specify the scope of the reauthentication -- either to grant bulk access like, e.g.,
// exporting passwords, or just one-at-a-time, like, e.g., viewing a single password. // exporting passwords, or just one-at-a-time, like, e.g., viewing a single password.
...@@ -54,11 +59,13 @@ public final class ReauthenticationManager { ...@@ -54,11 +59,13 @@ public final class ReauthenticationManager {
// Used in tests to override the result of checking for screen lock set-up. This allows the // Used in tests to override the result of checking for screen lock set-up. This allows the
// tests to be independent of a particular device configuration. // tests to be independent of a particular device configuration.
private static OverrideState sScreenLockSetUpOverride = OverrideState.NOT_OVERRIDDEN; @OverrideState
private static int sScreenLockSetUpOverride = OVERRIDE_STATE_NOT_OVERRIDDEN;
// Used in tests to override the result of checking for availability of the screen-locking API. // Used in tests to override the result of checking for availability of the screen-locking API.
// This allows the tests to be independent of a particular device configuration. // This allows the tests to be independent of a particular device configuration.
private static OverrideState sApiOverride = OverrideState.NOT_OVERRIDDEN; @OverrideState
private static int sApiOverride = OVERRIDE_STATE_NOT_OVERRIDDEN;
// Used in tests to avoid displaying the OS reauth dialog. // Used in tests to avoid displaying the OS reauth dialog.
private static boolean sSkipSystemReauth = false; private static boolean sSkipSystemReauth = false;
...@@ -83,14 +90,14 @@ public final class ReauthenticationManager { ...@@ -83,14 +90,14 @@ public final class ReauthenticationManager {
} }
@VisibleForTesting @VisibleForTesting
public static void setScreenLockSetUpOverride(OverrideState screenLockSetUpOverride) { public static void setScreenLockSetUpOverride(@OverrideState int screenLockSetUpOverride) {
sScreenLockSetUpOverride = screenLockSetUpOverride; sScreenLockSetUpOverride = screenLockSetUpOverride;
} }
@VisibleForTesting @VisibleForTesting
public static void setApiOverride(OverrideState apiOverride) { public static void setApiOverride(@OverrideState int apiOverride) {
// Ensure that tests don't accidentally try to launch the OS-provided lock screen. // Ensure that tests don't accidentally try to launch the OS-provided lock screen.
if (apiOverride == OverrideState.AVAILABLE) { if (apiOverride == OVERRIDE_STATE_AVAILABLE) {
PasswordReauthenticationFragment.preventLockingForTesting(); PasswordReauthenticationFragment.preventLockingForTesting();
} }
...@@ -108,11 +115,11 @@ public final class ReauthenticationManager { ...@@ -108,11 +115,11 @@ public final class ReauthenticationManager {
*/ */
public static boolean isReauthenticationApiAvailable() { public static boolean isReauthenticationApiAvailable() {
switch (sApiOverride) { switch (sApiOverride) {
case NOT_OVERRIDDEN: case OVERRIDE_STATE_NOT_OVERRIDDEN:
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
case AVAILABLE: case OVERRIDE_STATE_AVAILABLE:
return true; return true;
case UNAVAILABLE: case OVERRIDE_STATE_UNAVAILABLE:
return false; return false;
} }
// This branch is not reachable. // This branch is not reachable.
...@@ -169,12 +176,12 @@ public final class ReauthenticationManager { ...@@ -169,12 +176,12 @@ public final class ReauthenticationManager {
*/ */
public static boolean isScreenLockSetUp(Context context) { public static boolean isScreenLockSetUp(Context context) {
switch (sScreenLockSetUpOverride) { switch (sScreenLockSetUpOverride) {
case NOT_OVERRIDDEN: case OVERRIDE_STATE_NOT_OVERRIDDEN:
return ((KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE)) return ((KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE))
.isKeyguardSecure(); .isKeyguardSecure();
case AVAILABLE: case OVERRIDE_STATE_AVAILABLE:
return true; return true;
case UNAVAILABLE: case OVERRIDE_STATE_UNAVAILABLE:
return false; return false;
} }
// This branch is not reachable. // This branch is not reachable.
......
...@@ -384,7 +384,7 @@ public class SavePasswordsPreferencesTest { ...@@ -384,7 +384,7 @@ public class SavePasswordsPreferencesTest {
// Ensure there are no saved passwords reported to settings. // Ensure there are no saved passwords reported to settings.
setPasswordSource(null); setPasswordSource(null);
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -409,7 +409,7 @@ public class SavePasswordsPreferencesTest { ...@@ -409,7 +409,7 @@ public class SavePasswordsPreferencesTest {
public void testExportMenuEnabled() throws Exception { public void testExportMenuEnabled() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -434,7 +434,7 @@ public class SavePasswordsPreferencesTest { ...@@ -434,7 +434,7 @@ public class SavePasswordsPreferencesTest {
@SmallTest @SmallTest
@Feature({"Preferences"}) @Feature({"Preferences"})
public void testExportMenuMissing() throws Exception { public void testExportMenuMissing() throws Exception {
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -459,9 +459,9 @@ public class SavePasswordsPreferencesTest { ...@@ -459,9 +459,9 @@ public class SavePasswordsPreferencesTest {
public void testExportTriggersSerialization() throws Exception { public void testExportTriggersSerialization() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -490,9 +490,9 @@ public class SavePasswordsPreferencesTest { ...@@ -490,9 +490,9 @@ public class SavePasswordsPreferencesTest {
public void testExportMenuItem() throws Exception { public void testExportMenuItem() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -521,9 +521,9 @@ public class SavePasswordsPreferencesTest { ...@@ -521,9 +521,9 @@ public class SavePasswordsPreferencesTest {
public void testExportMenuItemNoLock() throws Exception { public void testExportMenuItemNoLock() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.UNAVAILABLE); ReauthenticationManager.OVERRIDE_STATE_UNAVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -550,9 +550,9 @@ public class SavePasswordsPreferencesTest { ...@@ -550,9 +550,9 @@ public class SavePasswordsPreferencesTest {
public void testExportMenuItemReenabledNoLock() throws Exception { public void testExportMenuItemReenabledNoLock() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.UNAVAILABLE); ReauthenticationManager.OVERRIDE_STATE_UNAVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -582,7 +582,7 @@ public class SavePasswordsPreferencesTest { ...@@ -582,7 +582,7 @@ public class SavePasswordsPreferencesTest {
public void testExportMenuItemReenabledReauthFailure() throws Exception { public void testExportMenuItemReenabledReauthFailure() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setSkipSystemReauth(true); ReauthenticationManager.setSkipSystemReauth(true);
final Preferences preferences = final Preferences preferences =
...@@ -621,9 +621,9 @@ public class SavePasswordsPreferencesTest { ...@@ -621,9 +621,9 @@ public class SavePasswordsPreferencesTest {
public void testExportIntent() throws Exception { public void testExportIntent() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -665,9 +665,9 @@ public class SavePasswordsPreferencesTest { ...@@ -665,9 +665,9 @@ public class SavePasswordsPreferencesTest {
public void testViewPasswordNoLock() throws Exception { public void testViewPasswordNoLock() throws Exception {
setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password")); setPasswordSource(new SavedPasswordEntry("https://example.com", "test user", "password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.UNAVAILABLE); ReauthenticationManager.OVERRIDE_STATE_UNAVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -692,9 +692,9 @@ public class SavePasswordsPreferencesTest { ...@@ -692,9 +692,9 @@ public class SavePasswordsPreferencesTest {
setPasswordSource( setPasswordSource(
new SavedPasswordEntry("https://example.com", "test user", "test password")); new SavedPasswordEntry("https://example.com", "test user", "test password"));
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
final Preferences preferences = final Preferences preferences =
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
...@@ -973,9 +973,9 @@ public class SavePasswordsPreferencesTest { ...@@ -973,9 +973,9 @@ public class SavePasswordsPreferencesTest {
public void testSearchResultsPersistAfterEntryInspection() throws Exception { public void testSearchResultsPersistAfterEntryInspection() throws Exception {
setPasswordSourceWithMultipleEntries(GREEK_GODS); setPasswordSourceWithMultipleEntries(GREEK_GODS);
setPasswordExceptions(new String[] {"http://exclu.de", "http://not-inclu.de"}); setPasswordExceptions(new String[] {"http://exclu.de", "http://not-inclu.de"});
ReauthenticationManager.setApiOverride(ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.setApiOverride(ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
ReauthenticationManager.setScreenLockSetUpOverride( ReauthenticationManager.setScreenLockSetUpOverride(
ReauthenticationManager.OverrideState.AVAILABLE); ReauthenticationManager.OVERRIDE_STATE_AVAILABLE);
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(), PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
SavePasswordsPreferences.class.getName()); SavePasswordsPreferences.class.getName());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment