Show confirmation dialog when user tries to skip fingerprint

- After the user finished adding lock screen, if the user tries to skip
fingerprint setup, show a confirmation dialog

bug: 64092225
Test: Manually tested; robolectric tests also added
Change-Id: Iba5088a9db93153988942cf78f11077f427e50cb
This commit is contained in:
Ajay Nadathur
2017-07-31 17:18:56 -07:00
parent 882d35715e
commit bf3a135170
6 changed files with 262 additions and 2 deletions

View File

@@ -834,6 +834,12 @@
<string name="security_settings_fingerprint_enroll_introduction_cancel_setup">Skip</string>
<!-- Button text to continue to the next screen from the introduction (this string variant is used while in setup wizard) [CHAR LIMIT=22] -->
<string name="security_settings_fingerprint_enroll_introduction_continue_setup">Next</string>
<!-- Title of dialog shown when the user tries to skip setting up fingerprint after adding lock screen during initial setup. [CHAR LIMIT=30] -->
<string name="fingerprint_enroll_skip_after_adding_lock_title">Skip fingerprint setup?</string>
<!-- Body text of dialog shown when the user tries to skip setting up fingerprint after adding lock screen during initial setup [CHAR LIMIT=NONE] -->
<string name="fingerprint_enroll_skip_after_adding_lock_text">You\u2019ve chosen to use your fingerprint as one way to unlock your phone. If you skip now, you\u2019ll need to set this up later. Setup takes only a minute or so.</string>
<!-- Title of dialog shown when the user tries to skip setting up a screen lock, warning them of potential consequences of not doing so [CHAR LIMIT=30]-->
<string name="lock_screen_intro_skip_title">Skip screen lock?</string>
<!-- Dialog text shown when the user tries to skip setting up a screen lock, warning them of potential consequences of not doing so, including loss of factory reset protection. (tablet) [CHAR LIMIT=NONE] -->
<string name="lock_screen_intro_skip_dialog_text_frp" product="tablet">Device protection features won\u2019t be turned on. You won\u2019t be able to prevent others from using this tablet if it\u2019s lost, stolen or reset.</string>
<!-- Dialog text shown when the user tries to skip setting up a screen lock, warning them of potential consequences of not doing so, including loss of factory reset protection. (device) [CHAR LIMIT=NONE] -->

View File

@@ -139,14 +139,18 @@ public class FingerprintEnrollFindSensor extends FingerprintEnrollBase {
public void onClick(View v) {
switch (v.getId()) {
case R.id.skip_button:
setResult(RESULT_SKIP);
finish();
onSkipButtonClick();
break;
default:
super.onClick(v);
}
}
protected void onSkipButtonClick() {
setResult(RESULT_SKIP);
finish();
}
private void proceedToEnrolling(boolean cancelEnrollment) {
if (mSidecar != null) {
if (cancelEnrollment) {

View File

@@ -16,12 +16,21 @@
package com.android.settings.fingerprint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
import android.support.annotation.NonNull;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.password.ChooseLockSettingsHelper;
public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSensor {
@@ -42,8 +51,54 @@ public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSenso
return intent;
}
@Override
protected void onSkipButtonClick() {
new SkipFingerprintDialog().show(getFragmentManager());
}
@Override
public int getMetricsCategory() {
return MetricsEvent.FINGERPRINT_FIND_SENSOR_SETUP;
}
public static class SkipFingerprintDialog extends InstrumentedDialogFragment
implements DialogInterface.OnClickListener {
private static final String TAG_SKIP_DIALOG = "skip_dialog";
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.DIALOG_FINGERPRINT_SKIP_SETUP;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return onCreateDialogBuilder().create();
}
@NonNull
public AlertDialog.Builder onCreateDialogBuilder() {
return new AlertDialog.Builder(getContext())
.setTitle(R.string.fingerprint_enroll_skip_after_adding_lock_title)
.setPositiveButton(R.string.skip_anyway_button_label, this)
.setNegativeButton(R.string.go_back_button_label, this)
.setMessage(R.string.fingerprint_enroll_skip_after_adding_lock_text);
}
@Override
public void onClick(DialogInterface dialog, int button) {
switch (button) {
case DialogInterface.BUTTON_POSITIVE:
Activity activity = getActivity();
if (activity != null) {
activity.setResult(RESULT_SKIP);
activity.finish();
}
break;
}
}
public void show(FragmentManager manager) {
show(manager, TAG_SKIP_DIALOG);
}
}
}

View File

@@ -61,6 +61,7 @@ public class SetupSkipDialog extends InstrumentedDialogFragment
return new AlertDialog.Builder(getContext())
.setPositiveButton(R.string.skip_anyway_button_label, this)
.setNegativeButton(R.string.go_back_button_label, this)
.setTitle(R.string.lock_screen_intro_skip_title)
.setMessage(args.getBoolean(ARG_FRP_SUPPORTED) ?
R.string.lock_screen_intro_skip_dialog_text_frp :
R.string.lock_screen_intro_skip_dialog_text);

View File

@@ -0,0 +1,104 @@
/*
* Copyright (C) 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.fingerprint;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.robolectric.RuntimeEnvironment.application;
import android.app.AlertDialog;
import android.content.Intent;
import android.widget.Button;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.password.IFingerprintManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowAlertDialog;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowDynamicIndexableContentMonitor.class,
ShadowEventLogWriter.class,
ShadowUtils.class
})
public class SetupFingerprintEnrollFindSensorTest {
@Mock
private IFingerprintManager mFingerprintManager;
private SetupFingerprintEnrollFindSensor mActivity;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowUtils.setFingerprintManager(mFingerprintManager);
RuntimeEnvironment.getAppResourceLoader().getResourceIndex();
}
private void createActivity(Intent intent) {
mActivity = Robolectric.buildActivity(
SetupFingerprintEnrollFindSensor.class, intent)
.setup().get();
}
private Intent createIntent() {
return new Intent()
// Set the challenge token so the confirm screen will not be shown
.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, new byte[0]);
}
@After
public void tearDown() {
ShadowUtils.reset();
}
@Test
public void fingerprintEnroll_showsAlert_whenClickingSkip() {
createActivity(createIntent());
Button skipButton = mActivity.findViewById(R.id.skip_button);
skipButton.performClick();
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alertDialog);
ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(alertDialog);
int titleRes = R.string.fingerprint_enroll_skip_after_adding_lock_title;
assertEquals(application.getString(titleRes), shadowAlertDialog.getTitle());
}
}

View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.password;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.robolectric.RuntimeEnvironment.application;
import android.app.Activity;
import android.app.AlertDialog;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowAlertDialog;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(
manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowDynamicIndexableContentMonitor.class,
ShadowEventLogWriter.class,
ShadowUtils.class
})
public class SetupSkipDialogTest {
private Activity mActivity;
@Before
public void setUp() {
mActivity = Robolectric.setupActivity(Activity.class);
}
@Test
public void frpMessages_areShownCorrectly_whenNotSupported() {
SetupSkipDialog setupSkipDialog = SetupSkipDialog.newInstance(false);
setupSkipDialog.show(mActivity.getFragmentManager());
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alertDialog);
ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(alertDialog);
assertEquals(application.getString(R.string.lock_screen_intro_skip_title),
shadowAlertDialog.getTitle());
assertEquals(application.getString(R.string.lock_screen_intro_skip_dialog_text),
shadowAlertDialog.getMessage());
}
@Test
public void frpMessages_areShownCorrectly_whenSupported() {
SetupSkipDialog setupSkipDialog = SetupSkipDialog.newInstance(true);
setupSkipDialog.show(mActivity.getFragmentManager());
AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
assertNotNull(alertDialog);
ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(alertDialog);
assertEquals(application.getString(R.string.lock_screen_intro_skip_title),
shadowAlertDialog.getTitle());
assertEquals(application.getString(R.string.lock_screen_intro_skip_dialog_text_frp),
shadowAlertDialog.getMessage());
}
}