1/n: Make ChooseLockSettingsHelper into a builder
The multitude of slightly different launchConfirmationActivity(*) methods are a big unsustainable pyramid. It's too difficult to read, too difficult to track which clients are interested in which parameters, and too difficult to add new parameters, since we need to 1) Read through all of them and find one that's the closest 2) Try not to affect other callers, so potentially add yet another 3) Modify the internal paths, which all basically call each other until it reaches the biggest launchConfirmationActivity which has ALL of the parameters This change should have no behavioral change. Note: CredentialStorage doesn't need returnCredentials anymore as of ag/6073449 Test: make -j56 RunSettingsRoboTests Test: Manually traced code paths for each invocation. A few hidden dependencies (such as explicitly setting challenge=0 with hasChallenge=true) were found. Left them the way they were in case they were intended Test: Enroll face, fingerprint Test: Enable developer options Test: Change to PIN, Pattern, Password, then back to PIN (so each type requests confirmation) Test: adb shell am start -a android.app.action.CONFIRM_DEVICE_CREDENTIAL, authenticate Test: adb shell am start -a android.app.action.CONFIRM_FRP_CREDENTIAL (shows confirm credential screen) Fixes: 138453993 Change-Id: Ic82ef3c3ac2e14d624281921f2d816bcdacbd82b
This commit is contained in:
@@ -38,16 +38,17 @@ public class ChooseLockSettingsHelperTest {
|
||||
@Test
|
||||
public void testLaunchConfirmationActivityWithExternalAndChallenge() {
|
||||
final Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
|
||||
helper.launchConfirmationActivityWithExternalAndChallenge(
|
||||
100, // request
|
||||
"title",
|
||||
"header",
|
||||
"description",
|
||||
true, // external
|
||||
10000L,
|
||||
UserHandle.myUserId()
|
||||
);
|
||||
|
||||
ChooseLockSettingsHelper.Builder builder = new ChooseLockSettingsHelper.Builder(activity);
|
||||
builder.setRequestCode(100)
|
||||
.setTitle("title")
|
||||
.setHeader("header")
|
||||
.setDescription("description")
|
||||
.setExternal(true)
|
||||
.setChallenge(10000L)
|
||||
.setUserId(UserHandle.myUserId());
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(builder);
|
||||
helper.launch();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
Intent startedIntent = shadowActivity.getNextStartedActivity();
|
||||
@@ -73,16 +74,17 @@ public class ChooseLockSettingsHelperTest {
|
||||
@Test
|
||||
public void testLaunchConfirmationActivityInternalAndChallenge() {
|
||||
final Activity activity = Robolectric.setupActivity(Activity.class);
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
|
||||
helper.launchConfirmationActivityWithExternalAndChallenge(
|
||||
100,
|
||||
"title",
|
||||
"header",
|
||||
"description",
|
||||
false, // external
|
||||
10000L,
|
||||
UserHandle.myUserId()
|
||||
);
|
||||
|
||||
ChooseLockSettingsHelper.Builder builder = new ChooseLockSettingsHelper.Builder(activity);
|
||||
builder.setRequestCode(100)
|
||||
.setTitle("title")
|
||||
.setHeader("header")
|
||||
.setDescription("description")
|
||||
.setChallenge(10000L)
|
||||
.setUserId(UserHandle.myUserId());
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(builder);
|
||||
helper.launch();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
Intent startedIntent = shadowActivity.getNextStartedActivity();
|
||||
|
||||
@@ -109,8 +111,14 @@ public class ChooseLockSettingsHelperTest {
|
||||
Intent intent = new Intent()
|
||||
.putExtra(WizardManagerHelper.EXTRA_THEME, ThemeHelper.THEME_GLIF_V2);
|
||||
Activity activity = Robolectric.buildActivity(Activity.class, intent).get();
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(activity);
|
||||
helper.launchConfirmationActivity(123, "test title", true, 0 /* userId */);
|
||||
|
||||
ChooseLockSettingsHelper.Builder builder = new ChooseLockSettingsHelper.Builder(activity);
|
||||
builder.setRequestCode(123)
|
||||
.setTitle("test title")
|
||||
.setReturnCredentials(true)
|
||||
.setUserId(0);
|
||||
ChooseLockSettingsHelper helper = getChooseLockSettingsHelper(builder);
|
||||
helper.launch();
|
||||
|
||||
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
|
||||
IntentForResult startedActivity = shadowActivity.getNextStartedActivityForResult();
|
||||
@@ -119,12 +127,13 @@ public class ChooseLockSettingsHelperTest {
|
||||
.isEqualTo(ThemeHelper.THEME_GLIF_V2);
|
||||
}
|
||||
|
||||
private ChooseLockSettingsHelper getChooseLockSettingsHelper(Activity activity) {
|
||||
private ChooseLockSettingsHelper getChooseLockSettingsHelper(
|
||||
ChooseLockSettingsHelper.Builder builder) {
|
||||
LockPatternUtils mockLockPatternUtils = mock(LockPatternUtils.class);
|
||||
when(mockLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
|
||||
.thenReturn(DevicePolicyManager.PASSWORD_QUALITY_SOMETHING);
|
||||
|
||||
ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(activity);
|
||||
ChooseLockSettingsHelper helper = builder.build();
|
||||
helper.mLockPatternUtils = mockLockPatternUtils;
|
||||
return helper;
|
||||
}
|
||||
|
Reference in New Issue
Block a user