Show 'screen lock options' on all lock screen types

bug: 66239135
Test: Manually tested and verified, robo tests updated
Change-Id: I42ae63661b5d5061fea848e2c1e8a0c8943864e4
This commit is contained in:
Ajay Nadathur
2018-01-04 13:06:46 -08:00
parent 00dcd71297
commit a1314df69c
9 changed files with 106 additions and 86 deletions

View File

@@ -21,12 +21,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<!-- left : cancel --> <!-- left : skip -->
<Button android:id="@+id/cancel_button" <Button android:id="@+id/skip_button"
style="@style/SuwGlifButton.Secondary" style="@style/SuwGlifButton.Secondary"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/lockpassword_cancel_label" /> android:text="@string/skip_label"
android:visibility="gone" />
<!-- left : clear --> <!-- left : clear -->

View File

@@ -107,6 +107,14 @@
android:textSize="14sp" android:textSize="14sp"
android:visibility="gone"/> android:visibility="gone"/>
<Button
android:id="@+id/screen_lock_options"
style="@style/SuwGlifButton.Tertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_lock_settings_options_button_label"
android:visibility="gone" />
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient> </com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
</com.android.setupwizardlib.GlifLayout> </com.android.setupwizardlib.GlifLayout>

View File

@@ -210,7 +210,7 @@ public class ChooseLockPassword extends SettingsActivity {
private String mFirstPin; private String mFirstPin;
private RecyclerView mPasswordRestrictionView; private RecyclerView mPasswordRestrictionView;
protected boolean mIsAlphaMode; protected boolean mIsAlphaMode;
protected Button mCancelButton; protected Button mSkipButton;
private Button mClearButton; private Button mClearButton;
private Button mNextButton; private Button mNextButton;
private TextView mMessage; private TextView mMessage;
@@ -377,8 +377,8 @@ public class ChooseLockPassword extends SettingsActivity {
ViewGroup container = view.findViewById(R.id.password_container); ViewGroup container = view.findViewById(R.id.password_container);
container.setOpticalInsets(Insets.NONE); container.setOpticalInsets(Insets.NONE);
mCancelButton = (Button) view.findViewById(R.id.cancel_button); mSkipButton = (Button) view.findViewById(R.id.skip_button);
mCancelButton.setOnClickListener(this); mSkipButton.setOnClickListener(this);
mNextButton = (Button) view.findViewById(R.id.next_button); mNextButton = (Button) view.findViewById(R.id.next_button);
mNextButton.setOnClickListener(this); mNextButton.setOnClickListener(this);
mClearButton = view.findViewById(R.id.clear_button); mClearButton = view.findViewById(R.id.clear_button);
@@ -774,10 +774,6 @@ public class ChooseLockPassword extends SettingsActivity {
handleNext(); handleNext();
break; break;
case R.id.cancel_button:
getActivity().finish();
break;
case R.id.clear_button: case R.id.clear_button:
mPasswordEntry.setText(""); mPasswordEntry.setText("");
break; break;
@@ -901,7 +897,6 @@ public class ChooseLockPassword extends SettingsActivity {
} }
mClearButton.setVisibility(toVisibility(mUiStage != Stage.Introduction)); mClearButton.setVisibility(toVisibility(mUiStage != Stage.Introduction));
mCancelButton.setVisibility(toVisibility(mUiStage == Stage.Introduction));
setNextText(mUiStage.buttonText); setNextText(mUiStage.buttonText);
mPasswordEntryInputDisabler.setInputEnabled(canInput); mPasswordEntryInputDisabler.setInputEnabled(canInput);

View File

@@ -290,8 +290,6 @@ public class ChooseLockPattern extends SettingsActivity {
* The states of the left footer button. * The states of the left footer button.
*/ */
enum LeftButtonMode { enum LeftButtonMode {
Cancel(R.string.cancel, true),
CancelDisabled(R.string.cancel, false),
Retry(R.string.lockpattern_retry_button_text, true), Retry(R.string.lockpattern_retry_button_text, true),
RetryDisabled(R.string.lockpattern_retry_button_text, false), RetryDisabled(R.string.lockpattern_retry_button_text, false),
Gone(ID_EMPTY_MESSAGE, false); Gone(ID_EMPTY_MESSAGE, false);
@@ -342,7 +340,7 @@ public class ChooseLockPattern extends SettingsActivity {
R.string.lock_settings_picker_fingerprint_added_security_message, R.string.lock_settings_picker_fingerprint_added_security_message,
R.string.lockpassword_choose_your_pattern_message, R.string.lockpassword_choose_your_pattern_message,
R.string.lockpattern_recording_intro_header, R.string.lockpattern_recording_intro_header,
LeftButtonMode.Cancel, RightButtonMode.ContinueDisabled, LeftButtonMode.Gone, RightButtonMode.ContinueDisabled,
ID_EMPTY_MESSAGE, true), ID_EMPTY_MESSAGE, true),
HelpScreen( HelpScreen(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_settings_help_how_to_record, ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_settings_help_how_to_record,
@@ -360,15 +358,15 @@ public class ChooseLockPattern extends SettingsActivity {
LeftButtonMode.Retry, RightButtonMode.Continue, ID_EMPTY_MESSAGE, false), LeftButtonMode.Retry, RightButtonMode.Continue, ID_EMPTY_MESSAGE, false),
NeedToConfirm( NeedToConfirm(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_confirm, ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_confirm,
LeftButtonMode.Cancel, RightButtonMode.ConfirmDisabled, LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled,
ID_EMPTY_MESSAGE, true), ID_EMPTY_MESSAGE, true),
ConfirmWrong( ConfirmWrong(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_unlock_wrong, ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_unlock_wrong,
LeftButtonMode.Cancel, RightButtonMode.ConfirmDisabled, LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled,
ID_EMPTY_MESSAGE, true), ID_EMPTY_MESSAGE, true),
ChoiceConfirmed( ChoiceConfirmed(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_pattern_confirmed_header, ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_pattern_confirmed_header,
LeftButtonMode.Cancel, RightButtonMode.Confirm, ID_EMPTY_MESSAGE, false); LeftButtonMode.Gone, RightButtonMode.Confirm, ID_EMPTY_MESSAGE, false);
/** /**
@@ -413,7 +411,7 @@ public class ChooseLockPattern extends SettingsActivity {
private ChooseLockSettingsHelper mChooseLockSettingsHelper; private ChooseLockSettingsHelper mChooseLockSettingsHelper;
private SaveAndFinishWorker mSaveAndFinishWorker; private SaveAndFinishWorker mSaveAndFinishWorker;
private int mUserId; protected int mUserId;
private boolean mForFingerprint; private boolean mForFingerprint;
private static final String KEY_UI_STAGE = "uiStage"; private static final String KEY_UI_STAGE = "uiStage";
@@ -558,8 +556,6 @@ public class ChooseLockPattern extends SettingsActivity {
mChosenPattern = null; mChosenPattern = null;
mLockPatternView.clearPattern(); mLockPatternView.clearPattern();
updateStage(Stage.Introduction); updateStage(Stage.Introduction);
} else if (mUiStage.leftMode == LeftButtonMode.Cancel) {
getActivity().finish();
} else { } else {
throw new IllegalStateException("left footer button pressed, but stage of " + throw new IllegalStateException("left footer button pressed, but stage of " +
mUiStage + " doesn't make sense"); mUiStage + " doesn't make sense");

View File

@@ -16,6 +16,7 @@
package com.android.settings.password; package com.android.settings.password;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.app.Dialog; import android.app.Dialog;
@@ -24,6 +25,7 @@ import android.app.admin.DevicePolicyManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@@ -33,8 +35,11 @@ import android.widget.ArrayAdapter;
import android.widget.TextView; import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.setupwizardlib.util.WizardManagerHelper;
import java.util.List; import java.util.List;
@@ -60,6 +65,36 @@ public class ChooseLockTypeDialogFragment extends InstrumentedDialogFragment
public interface OnLockTypeSelectedListener { public interface OnLockTypeSelectedListener {
void onLockTypeSelected(ScreenLockType lock); void onLockTypeSelected(ScreenLockType lock);
default void startChooseLockActivity(ScreenLockType selectedLockType, Activity activity) {
Intent activityIntent = activity.getIntent();
Intent intent = new Intent(activity, SetupChooseLockGeneric.class);
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
// Copy the original extras into the new intent
if (activityIntent.hasExtra(
ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS)) {
intent.putExtras(activityIntent.getBundleExtra(
ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS));
}
intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, selectedLockType.defaultQuality);
// Propagate the fingerprint challenge
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE,
activityIntent.getBooleanExtra(
ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false));
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE,
activityIntent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0));
// The user is already given the choice of the what screen lock to set up. No need to
// show this button again.
intent.putExtra(ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
WizardManagerHelper.copyWizardManagerExtras(activityIntent, intent);
activity.startActivity(intent);
activity.finish();
}
} }
@Override @Override

View File

@@ -28,13 +28,9 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SetupRedactionInterstitial; import com.android.settings.SetupRedactionInterstitial;
import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener; import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
import com.android.setupwizardlib.util.WizardManagerHelper;
/** /**
* Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure * Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure
@@ -75,9 +71,6 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment
implements OnLockTypeSelectedListener { implements OnLockTypeSelectedListener {
@VisibleForTesting
static final int REQUEST_SCREEN_LOCK_OPTIONS = 1;
@Nullable @Nullable
private Button mOptionsButton; private Button mOptionsButton;
@@ -90,8 +83,7 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
boolean anyOptionsShown = chooseLockGenericController.getVisibleScreenLockTypes( boolean anyOptionsShown = chooseLockGenericController.getVisibleScreenLockTypes(
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, false).size() > 0; DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, false).size() > 0;
boolean showOptionsButton = activity.getIntent().getBooleanExtra( boolean showOptionsButton = activity.getIntent().getBooleanExtra(
ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false); ChooseLockGeneric.ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
if (!anyOptionsShown) { if (!anyOptionsShown) {
Log.w(TAG, "Visible screen lock types is empty!"); Log.w(TAG, "Visible screen lock types is empty!");
} }
@@ -107,9 +99,10 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { switch (v.getId()) {
case R.id.screen_lock_options: case R.id.screen_lock_options:
launchChooseLockGeneric(); ChooseLockTypeDialogFragment.newInstance(mUserId)
.show(getChildFragmentManager(), null);
break; break;
case R.id.cancel_button: case R.id.skip_button:
SetupSkipDialog dialog = SetupSkipDialog.newInstance( SetupSkipDialog dialog = SetupSkipDialog.newInstance(
getActivity().getIntent() getActivity().getIntent()
.getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false)); .getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
@@ -120,11 +113,6 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
} }
} }
private void launchChooseLockGeneric() {
ChooseLockTypeDialogFragment.newInstance(mUserId)
.show(getChildFragmentManager(), null);
}
@Override @Override
protected Intent getRedactionInterstitialIntent(Context context) { protected Intent getRedactionInterstitialIntent(Context context) {
// Setup wizard's redaction interstitial is deferred to optional step. Enable that // Setup wizard's redaction interstitial is deferred to optional step. Enable that
@@ -137,57 +125,16 @@ public class SetupChooseLockPassword extends ChooseLockPassword {
public void onLockTypeSelected(ScreenLockType lock) { public void onLockTypeSelected(ScreenLockType lock) {
ScreenLockType currentLockType = mIsAlphaMode ? ScreenLockType currentLockType = mIsAlphaMode ?
ScreenLockType.PASSWORD : ScreenLockType.PIN; ScreenLockType.PASSWORD : ScreenLockType.PIN;
if (currentLockType.equals(lock)) { if (lock == currentLockType) {
// ignore same lock type.
return; return;
} }
Intent activityIntent = getActivity().getIntent(); startChooseLockActivity(lock, getActivity());
Intent intent = new Intent(getContext(), SetupChooseLockGeneric.class);
// Copy the original extras into the new intent
if (activityIntent
.hasExtra(ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS)) {
intent.putExtras(activityIntent.getBundleExtra(
ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS));
}
intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, lock.defaultQuality);
// Propagate the fingerprint challenge
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE,
activityIntent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE,
false));
intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE,
activityIntent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0));
// The user is already given the choice of the what screen lock to set up. No need to
// show this button again.
intent.putExtra(ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
WizardManagerHelper.copyWizardManagerExtras(activityIntent, intent);
startActivityForResult(intent, REQUEST_SCREEN_LOCK_OPTIONS);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_SCREEN_LOCK_OPTIONS) {
if (resultCode != Activity.RESULT_CANCELED) {
Activity activity = getActivity();
activity.setResult(resultCode, data);
activity.finish();
}
}
} }
@Override @Override
protected void updateUi() { protected void updateUi() {
super.updateUi(); super.updateUi();
if (mForFingerprint) { mSkipButton.setVisibility(mForFingerprint ? View.GONE : View.VISIBLE);
mCancelButton.setVisibility(View.GONE);
} else {
mCancelButton.setText(R.string.skip_label);
}
if (mOptionsButton != null) { if (mOptionsButton != null) {
mOptionsButton.setVisibility( mOptionsButton.setVisibility(

View File

@@ -19,7 +19,11 @@ package com.android.settings.password;
import android.app.Fragment; import android.app.Fragment;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.android.settings.R;
import com.android.settings.SetupRedactionInterstitial; import com.android.settings.SetupRedactionInterstitial;
/** /**
@@ -46,7 +50,26 @@ public class SetupChooseLockPattern extends ChooseLockPattern {
return SetupChooseLockPatternFragment.class; return SetupChooseLockPatternFragment.class;
} }
public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment { public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment
implements ChooseLockTypeDialogFragment.OnLockTypeSelectedListener {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Button optionsButton = (Button) view.findViewById(R.id.screen_lock_options);
optionsButton.setVisibility(View.VISIBLE);
optionsButton.setOnClickListener((btn) ->
ChooseLockTypeDialogFragment.newInstance(mUserId)
.show(getChildFragmentManager(), null));
}
@Override
public void onLockTypeSelected(ScreenLockType lock) {
if (ScreenLockType.PATTERN == lock) {
return;
}
startChooseLockActivity(lock, getActivity());
}
@Override @Override
protected Intent getRedactionInterstitialIntent(Context context) { protected Intent getRedactionInterstitialIntent(Context context) {

View File

@@ -21,9 +21,12 @@ import static com.google.common.truth.Truth.assertThat;
import static org.robolectric.RuntimeEnvironment.application; import static org.robolectric.RuntimeEnvironment.application;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.view.View;
import android.widget.Button;
import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment; import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment;
import com.android.settings.password.ChooseLockPattern.IntentBuilder; import com.android.settings.password.ChooseLockPattern.IntentBuilder;
@@ -40,6 +43,7 @@ import org.junit.runner.RunWith;
import org.robolectric.Robolectric; import org.robolectric.Robolectric;
import org.robolectric.Shadows; import org.robolectric.Shadows;
import org.robolectric.annotation.Config; import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowAlertDialog;
import org.robolectric.shadows.ShadowPackageManager.ComponentState; import org.robolectric.shadows.ShadowPackageManager.ComponentState;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@@ -85,6 +89,19 @@ public class SetupChooseLockPatternTest {
.isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED); .isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
} }
@Test
public void screenLockOptions_shouldBeVisible() {
Button button = mActivity.findViewById(R.id.screen_lock_options);
assertThat(button).isNotNull();
assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
button.performClick();
AlertDialog chooserDialog = ShadowAlertDialog.getLatestAlertDialog();
assertThat(chooserDialog).isNotNull();
int count = Shadows.shadowOf(chooserDialog).getAdapter().getCount();
assertThat(count).named("List items shown").isEqualTo(3);
}
private ChooseLockPatternFragment findFragment(Activity activity) { private ChooseLockPatternFragment findFragment(Activity activity) {
return (ChooseLockPatternFragment) return (ChooseLockPatternFragment)
activity.getFragmentManager().findFragmentById(R.id.main_content); activity.getFragmentManager().findFragmentById(R.id.main_content);

View File

@@ -135,11 +135,9 @@ public class SetupChooseLockPasswordTest {
fragment.onLockTypeSelected(ScreenLockType.PATTERN); fragment.onLockTypeSelected(ScreenLockType.PATTERN);
ShadowActivity shadowActivity = shadowOf(activity); ShadowActivity shadowActivity = shadowOf(activity);
IntentForResult chooseLockIntent = shadowActivity.getNextStartedActivityForResult(); final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
assertThat(chooseLockIntent).isNotNull(); assertThat(nextStartedActivity).isNotNull();
assertThat(chooseLockIntent.requestCode) assertThat(nextStartedActivity.getStringExtra("foo")).named("Foo extra")
.isEqualTo(SetupChooseLockPasswordFragment.REQUEST_SCREEN_LOCK_OPTIONS);
assertThat(chooseLockIntent.intent.getStringExtra("foo")).named("Foo extra")
.isEqualTo("bar"); .isEqualTo("bar");
} }