From 92d3c1e6535e3cfd84f8a42599eda82e9dc16b3b Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Thu, 12 Jan 2017 14:35:32 -0800 Subject: [PATCH] [Fingerprint] Don't show warning dialog if screen lock is set up If the keyguard is already secure (i.e. if the backup screen lock is already set up), do not show the skip dialog which warns user about the danger of not having a screen lock. Bug: 34129157 Test: adb shell am instrument -w com.android.settings.tests.unit Change-Id: I6f777631487de89ab25a08ea017dd6194dde464d --- .../SetupFingerprintEnrollIntroduction.java | 15 ++- ...etupFingerprintEnrollIntroductionTest.java | 109 ++++++++++++++++++ 2 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 tests/unit/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java diff --git a/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java b/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java index 546fc0e29e4..3951aff7826 100644 --- a/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java +++ b/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroduction.java @@ -16,6 +16,7 @@ package com.android.settings.fingerprint; +import android.app.KeyguardManager; import android.content.Intent; import android.content.res.Resources; import android.os.UserHandle; @@ -83,9 +84,17 @@ public class SetupFingerprintEnrollIntroduction extends FingerprintEnrollIntrodu @Override protected void onCancelButtonClick() { - SetupSkipDialog dialog = SetupSkipDialog.newInstance( - getIntent().getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false)); - dialog.show(getFragmentManager()); + KeyguardManager keyguardManager = getSystemService(KeyguardManager.class); + if (keyguardManager.isKeyguardSecure()) { + // If the keyguard is already set up securely (maybe the user added a backup screen + // lock and skipped fingerprint), return RESULT_SKIP directly. + setResult(RESULT_SKIP); + finish(); + } else { + SetupSkipDialog dialog = SetupSkipDialog.newInstance( + getIntent().getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false)); + dialog.show(getFragmentManager()); + } } @Override diff --git a/tests/unit/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java b/tests/unit/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java new file mode 100644 index 00000000000..8afed185cb2 --- /dev/null +++ b/tests/unit/src/com/android/settings/fingerprint/SetupFingerprintEnrollIntroductionTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * 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.mockito.Mockito.doReturn; + +import android.app.KeyguardManager; +import android.content.Context; +import android.content.ContextWrapper; +import android.content.Intent; +import android.test.ActivityUnitTestCase; +import android.view.View; +import android.widget.Button; + +import com.android.settings.R; + +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +public class SetupFingerprintEnrollIntroductionTest + extends ActivityUnitTestCase { + + private TestContext mContext; + + @Mock + private KeyguardManager mKeyguardManager; + + private SetupFingerprintEnrollIntroduction mActivity; + + public SetupFingerprintEnrollIntroductionTest() { + super(SetupFingerprintEnrollIntroduction.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + MockitoAnnotations.initMocks(this); + mContext = new TestContext(getInstrumentation().getTargetContext()); + setActivityContext(mContext); + + getInstrumentation().runOnMainSync(() -> { + final Intent intent = new Intent(); + mActivity = startActivity(intent, + null /* savedInstanceState */, null /* lastNonConfigurationInstance */); + }); + } + + public void testKeyguardNotSecure_shouldShowSkipDialog() { + doReturn(false).when(mKeyguardManager).isKeyguardSecure(); + + getInstrumentation().runOnMainSync(() -> { + getInstrumentation().callActivityOnCreate(mActivity, null); + getInstrumentation().callActivityOnResume(mActivity); + + final Button skipButton = + (Button) mActivity.findViewById(R.id.fingerprint_cancel_button); + assertEquals(View.VISIBLE, skipButton.getVisibility()); + skipButton.performClick(); + }); + + assertFalse(isFinishCalled()); + } + + public void testKeyguardSecure_shouldNotShowSkipDialog() { + doReturn(true).when(mKeyguardManager).isKeyguardSecure(); + + getInstrumentation().runOnMainSync(() -> { + getInstrumentation().callActivityOnCreate(mActivity, null); + getInstrumentation().callActivityOnResume(mActivity); + + final Button skipButton = + (Button) mActivity.findViewById(R.id.fingerprint_cancel_button); + assertEquals(View.VISIBLE, skipButton.getVisibility()); + skipButton.performClick(); + }); + + assertTrue(isFinishCalled()); + } + + public class TestContext extends ContextWrapper { + + public TestContext(Context base) { + super(base); + } + + @Override + public Object getSystemService(String name) { + if (Context.KEYGUARD_SERVICE.equals(name)) { + return mKeyguardManager; + } + return super.getSystemService(name); + } + } +}