[BiometricsV2] Refine fingerprint activities
Seperate FingerprintEnrollmentActivity to another InternalActivity and SetupActivity. InternalActivity is used for FingerprintSettings. SetupActivity is used for setupwizard flow. Bug: 284248001 Test: atest FingerprintEnrollmentActivityTest Test: atest for biometrics/biometrics2 in unit tests Test: settingRoboTest for biometrics Change-Id: I9fb5dc34300060b9ccf857a3335b81a5d4bf5c7b
This commit is contained in:
@@ -32,6 +32,7 @@ import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.Until;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
@@ -47,18 +48,21 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class FingerprintEnrollmentActivityTest {
|
||||
|
||||
private static final String TAG = "FingerprintEnrollmentActivityTest";
|
||||
|
||||
private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
|
||||
private static final String ACTIVITY_CLASS_NAME =
|
||||
"com.android.settings.biometrics2.ui.view.FingerprintEnrollmentActivity";
|
||||
private static final String SUW_ACTIVITY_CLASS_NAME = ACTIVITY_CLASS_NAME + "$SetupActivity";
|
||||
private static final String EXTRA_IS_SETUP_FLOW = "isSetupFlow";
|
||||
private static final String EXTRA_SKIP_INTRO = "skip_intro";
|
||||
private static final String EXTRA_SKIP_FIND_SENSOR = "skip_find_sensor";
|
||||
private static final String EXTRA_FROM_SETTINGS_SUMMARY = "from_settings_summary";
|
||||
private static final String EXTRA_PAGE_TRANSITION_TYPE = "page_transition_type";
|
||||
private static final String EXTRA_KEY_GK_PW_HANDLE = "gk_pw_handle";
|
||||
private static final String TEST_PIN = "1234";
|
||||
@@ -83,7 +87,6 @@ public class FingerprintEnrollmentActivityTest {
|
||||
@Before
|
||||
public void setUp() throws InterruptedException {
|
||||
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
|
||||
mContext = InstrumentationRegistry.getContext();
|
||||
|
||||
// Stop every test if it is not a fingerprint device
|
||||
@@ -121,6 +124,13 @@ public class FingerprintEnrollmentActivityTest {
|
||||
assertThat(mFingerprintPropCallbackLaunched).isTrue();
|
||||
|
||||
mDevice.pressHome();
|
||||
|
||||
// Stop settings before performing test
|
||||
try {
|
||||
mDevice.executeShellCommand("am force-stop " + SETTINGS_PACKAGE_NAME);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Fail to stop settings app", e);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -131,7 +141,7 @@ public class FingerprintEnrollmentActivityTest {
|
||||
|
||||
@Test
|
||||
public void testIntroChooseLock() {
|
||||
final Intent intent = newActivityIntent();
|
||||
final Intent intent = newActivityIntent(false);
|
||||
mContext.startActivity(intent);
|
||||
assertThat(mDevice.wait(Until.hasObject(By.text("Choose your backup screen lock method")),
|
||||
IDLE_TIMEOUT)).isTrue();
|
||||
@@ -371,7 +381,7 @@ public class FingerprintEnrollmentActivityTest {
|
||||
@Test
|
||||
public void testIntroCheckPin() {
|
||||
LockScreenUtil.setLockscreen(LockScreenUtil.LockscreenType.PIN, TEST_PIN, true);
|
||||
final Intent intent = newActivityIntent();
|
||||
final Intent intent = newActivityIntent(false);
|
||||
mContext.startActivity(intent);
|
||||
assertThat(mDevice.wait(Until.hasObject(By.text("Enter your device PIN to continue")),
|
||||
IDLE_TIMEOUT)).isTrue();
|
||||
@@ -552,7 +562,7 @@ public class FingerprintEnrollmentActivityTest {
|
||||
|
||||
// Back to home
|
||||
mDevice.waitForWindowUpdate("com.android.settings", IDLE_TIMEOUT);
|
||||
assertThat(mDevice.findObject(By.text(DO_IT_LATER))).isNull();
|
||||
assertThat(mDevice.wait(Until.gone(By.text(DO_IT_LATER)), IDLE_TIMEOUT)).isTrue();
|
||||
}
|
||||
|
||||
private void launchIntroWithGkPwHandle(boolean isSuw) {
|
||||
@@ -560,10 +570,7 @@ public class FingerprintEnrollmentActivityTest {
|
||||
final LockscreenCredential lockscreenCredential = LockscreenCredential.createPin(TEST_PIN);
|
||||
final int userId = UserHandle.myUserId();
|
||||
final LockPatternChecker.OnVerifyCallback onVerifyCallback = (response, timeoutMs) -> {
|
||||
final Intent intent = newActivityIntent();
|
||||
if (isSuw) {
|
||||
intent.putExtra(EXTRA_IS_SETUP_FLOW, true);
|
||||
}
|
||||
final Intent intent = newActivityIntent(isSuw);
|
||||
intent.putExtra(EXTRA_KEY_GK_PW_HANDLE, response.getGatekeeperPasswordHandle());
|
||||
mContext.startActivity(intent);
|
||||
};
|
||||
@@ -576,7 +583,7 @@ public class FingerprintEnrollmentActivityTest {
|
||||
final LockscreenCredential lockscreenCredential = LockscreenCredential.createPin(TEST_PIN);
|
||||
final int userId = UserHandle.myUserId();
|
||||
final LockPatternChecker.OnVerifyCallback onVerifyCallback = (response, timeoutMs) -> {
|
||||
final Intent intent = newActivityIntent();
|
||||
final Intent intent = newActivityIntent(false);
|
||||
intent.putExtra(EXTRA_SKIP_INTRO, true);
|
||||
intent.putExtra(EXTRA_KEY_GK_PW_HANDLE, response.getGatekeeperPasswordHandle());
|
||||
mContext.startActivity(intent);
|
||||
@@ -590,7 +597,7 @@ public class FingerprintEnrollmentActivityTest {
|
||||
final LockscreenCredential lockscreenCredential = LockscreenCredential.createPin(TEST_PIN);
|
||||
final int userId = UserHandle.myUserId();
|
||||
final LockPatternChecker.OnVerifyCallback onVerifyCallback = (response, timeoutMs) -> {
|
||||
final Intent intent = newActivityIntent();
|
||||
final Intent intent = newActivityIntent(false);
|
||||
intent.putExtra(EXTRA_SKIP_FIND_SENSOR, true);
|
||||
intent.putExtra(EXTRA_KEY_GK_PW_HANDLE, response.getGatekeeperPasswordHandle());
|
||||
mContext.startActivity(intent);
|
||||
@@ -600,14 +607,16 @@ public class FingerprintEnrollmentActivityTest {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Intent newActivityIntent() {
|
||||
private Intent newActivityIntent(boolean isSuw) {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(SETTINGS_PACKAGE_NAME, ACTIVITY_CLASS_NAME);
|
||||
intent.putExtra(EXTRA_FROM_SETTINGS_SUMMARY, true);
|
||||
intent.setClassName(SETTINGS_PACKAGE_NAME,
|
||||
isSuw ? SUW_ACTIVITY_CLASS_NAME : ACTIVITY_CLASS_NAME);
|
||||
if (isSuw) {
|
||||
intent.putExtra(EXTRA_IS_SETUP_FLOW, true);
|
||||
}
|
||||
intent.putExtra(EXTRA_PAGE_TRANSITION_TYPE, 1);
|
||||
intent.putExtra(Intent.EXTRA_USER_ID, mContext.getUserId());
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
return intent;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.biometrics2.ui.model;
|
||||
|
||||
import static com.android.settings.biometrics.BiometricEnrollActivity.EXTRA_SKIP_INTRO;
|
||||
import static com.android.settings.biometrics2.ui.model.EnrollmentRequest.EXTRA_SKIP_FIND_SENSOR;
|
||||
|
||||
import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_DEFERRED_SETUP;
|
||||
import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_PORTAL_SETUP;
|
||||
import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SETUP_FLOW;
|
||||
import static com.google.android.setupcompat.util.WizardManagerHelper.EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class EnrollmentRequestTest {
|
||||
|
||||
@NonNull
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Test
|
||||
public void testIsSuw() {
|
||||
// Default false
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, true).isSuw()).isFalse();
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, false).isSuw()).isFalse();
|
||||
|
||||
final Intent trueIntent = new Intent();
|
||||
trueIntent.putExtra(EXTRA_IS_SETUP_FLOW, true);
|
||||
assertThat(new EnrollmentRequest(trueIntent, mContext, true).isSuw()).isTrue();
|
||||
assertThat(new EnrollmentRequest(trueIntent, mContext, false).isSuw()).isFalse();
|
||||
|
||||
final Intent falseIntent = new Intent();
|
||||
trueIntent.putExtra(EXTRA_IS_SETUP_FLOW, false);
|
||||
assertThat(new EnrollmentRequest(falseIntent, mContext, true).isSuw()).isFalse();
|
||||
assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSuw()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAfterSuwOrSuwSuggestedAction() {
|
||||
// Default false
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, true)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
|
||||
final Intent deferredTrueIntent = new Intent();
|
||||
deferredTrueIntent.putExtra(EXTRA_IS_DEFERRED_SETUP, true);
|
||||
assertThat(new EnrollmentRequest(deferredTrueIntent, mContext, true)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isTrue();
|
||||
assertThat(new EnrollmentRequest(deferredTrueIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
|
||||
final Intent deferredFalseIntent = new Intent();
|
||||
deferredFalseIntent.putExtra(EXTRA_IS_DEFERRED_SETUP, false);
|
||||
assertThat(new EnrollmentRequest(deferredFalseIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
assertThat(new EnrollmentRequest(deferredFalseIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
|
||||
final Intent portalTrueIntent = new Intent();
|
||||
portalTrueIntent.putExtra(EXTRA_IS_PORTAL_SETUP, true);
|
||||
assertThat(new EnrollmentRequest(portalTrueIntent, mContext, true)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isTrue();
|
||||
assertThat(new EnrollmentRequest(portalTrueIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
|
||||
final Intent portalFalseIntent = new Intent();
|
||||
portalFalseIntent.putExtra(EXTRA_IS_PORTAL_SETUP, false);
|
||||
assertThat(new EnrollmentRequest(portalFalseIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
assertThat(new EnrollmentRequest(portalFalseIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
|
||||
final Intent suggestedTrueIntent = new Intent();
|
||||
suggestedTrueIntent.putExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, true);
|
||||
assertThat(new EnrollmentRequest(suggestedTrueIntent, mContext, true)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isTrue();
|
||||
assertThat(new EnrollmentRequest(suggestedTrueIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
|
||||
final Intent suggestedFalseIntent = new Intent();
|
||||
suggestedFalseIntent.putExtra(EXTRA_IS_SUW_SUGGESTED_ACTION_FLOW, false);
|
||||
assertThat(new EnrollmentRequest(suggestedFalseIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
assertThat(new EnrollmentRequest(suggestedFalseIntent, mContext, false)
|
||||
.isAfterSuwOrSuwSuggestedAction()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSuwExtras_inSuw() {
|
||||
final Intent suwIntent = new Intent();
|
||||
suwIntent.putExtra(EXTRA_IS_SETUP_FLOW, true);
|
||||
final EnrollmentRequest setupRequest = new EnrollmentRequest(suwIntent, mContext, true);
|
||||
|
||||
final Bundle bundle = setupRequest.getSuwExtras();
|
||||
assertThat(bundle).isNotNull();
|
||||
assertThat(bundle.size()).isAtLeast(1);
|
||||
assertThat(bundle.getBoolean(EXTRA_IS_SETUP_FLOW)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSuwExtras_notInSuw() {
|
||||
final Intent suwIntent = new Intent();
|
||||
suwIntent.putExtra(EXTRA_IS_SETUP_FLOW, true);
|
||||
final EnrollmentRequest setupRequest = new EnrollmentRequest(suwIntent, mContext, false);
|
||||
|
||||
final Bundle bundle = setupRequest.getSuwExtras();
|
||||
assertThat(bundle).isNotNull();
|
||||
assertThat(bundle.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSkipIntro() {
|
||||
// Default false
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, true).isSkipIntro()).isFalse();
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, false).isSkipIntro()).isFalse();
|
||||
|
||||
final Intent trueIntent = new Intent();
|
||||
trueIntent.putExtra(EXTRA_SKIP_INTRO, true);
|
||||
assertThat(new EnrollmentRequest(trueIntent, mContext, true).isSkipIntro()).isTrue();
|
||||
assertThat(new EnrollmentRequest(trueIntent, mContext, false).isSkipIntro()).isTrue();
|
||||
|
||||
final Intent falseIntent = new Intent();
|
||||
falseIntent.putExtra(EXTRA_SKIP_INTRO, false);
|
||||
assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipIntro()).isFalse();
|
||||
assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipIntro()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSkipFindSensor() {
|
||||
// Default false
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, true).isSkipFindSensor())
|
||||
.isFalse();
|
||||
assertThat(new EnrollmentRequest(new Intent(), mContext, false).isSkipFindSensor())
|
||||
.isFalse();
|
||||
|
||||
final Intent trueIntent = new Intent();
|
||||
trueIntent.putExtra(EXTRA_SKIP_FIND_SENSOR, true);
|
||||
assertThat(new EnrollmentRequest(trueIntent, mContext, true).isSkipFindSensor()).isTrue();
|
||||
assertThat(new EnrollmentRequest(trueIntent, mContext, false).isSkipFindSensor()).isTrue();
|
||||
|
||||
final Intent falseIntent = new Intent();
|
||||
falseIntent.putExtra(EXTRA_SKIP_FIND_SENSOR, false);
|
||||
assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipFindSensor())
|
||||
.isFalse();
|
||||
assertThat(new EnrollmentRequest(falseIntent, mContext, false).isSkipFindSensor())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class FingerprintEnrollFinishViewModelTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mApplication = ApplicationProvider.getApplicationContext();
|
||||
mRequest = new EnrollmentRequest(new Intent(), mApplication);
|
||||
mRequest = new EnrollmentRequest(new Intent(), mApplication, true);
|
||||
mViewModel = new FingerprintEnrollFinishViewModel(mApplication, USER_ID, mRequest,
|
||||
newFingerprintRepository(mFingerprintManager, TYPE_UDFPS_OPTICAL, MAX_ENROLLABLE));
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class EnrollmentRequestUtils {
|
||||
if (!TextUtils.isEmpty(theme)) {
|
||||
i.putExtra(EXTRA_THEME, theme);
|
||||
}
|
||||
return new EnrollmentRequest(i, context);
|
||||
return new EnrollmentRequest(i, context, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user