2/n: Add face to ChooseLock*

Bug: 110589286

Test: manual
Test: make -j56 RunSettingsRoboTests
Test: setting up new fingerprint still works
Change-Id: I1b7d2bb6bb417dae2c99e5abeb68d3f694cb3cb8
This commit is contained in:
Kevin Chyn
2018-06-28 14:59:38 -07:00
parent 4882e875ae
commit 81dc0295d7
13 changed files with 383 additions and 48 deletions

View File

@@ -16,12 +16,14 @@
package com.android.settings.password;
import static android.content.pm.PackageManager.FEATURE_FACE;
import static android.content.pm.PackageManager.FEATURE_FINGERPRINT;
import static com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment
.HIDE_DISABLED_PREFS;
import static com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment
.MINIMUM_QUALITY_KEY;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT;
import static com.android.settings.password.ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE;
import static com.google.common.truth.Truth.assertThat;
@@ -36,6 +38,7 @@ import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
@@ -53,12 +56,15 @@ public final class SetNewPasswordControllerTest {
private static final int CURRENT_USER_ID = 101;
private static final long FINGERPRINT_CHALLENGE = -9876512313131L;
private static final long FACE_CHALLENGE = 1352057789L;
@Mock
private PackageManager mPackageManager;
@Mock
private FingerprintManager mFingerprintManager;
@Mock
private FaceManager mFaceManager;
@Mock
private DevicePolicyManager mDevicePolicyManager;
@Mock
private SetNewPasswordController.Ui mUi;
@@ -69,10 +75,14 @@ public final class SetNewPasswordControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mSetNewPasswordController = new SetNewPasswordController(
CURRENT_USER_ID, mPackageManager, mFingerprintManager, mDevicePolicyManager, mUi);
CURRENT_USER_ID, mPackageManager, mFingerprintManager, mFaceManager,
mDevicePolicyManager, mUi);
when(mFingerprintManager.preEnroll()).thenReturn(FINGERPRINT_CHALLENGE);
when(mPackageManager.hasSystemFeature(eq(FEATURE_FINGERPRINT))).thenReturn(true);
when(mFaceManager.preEnroll()).thenReturn(FACE_CHALLENGE);
when(mPackageManager.hasSystemFeature(eq(FEATURE_FACE))).thenReturn(true);
}
@Test
@@ -95,6 +105,26 @@ public final class SetNewPasswordControllerTest {
compareFingerprintExtras(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithFace() {
// GIVEN the device supports face.
when(mFaceManager.isHardwareDetected()).thenReturn(true);
// GIVEN there are no enrolled face.
when(mFaceManager.hasEnrolledFaces(CURRENT_USER_ID)).thenReturn(false);
// GIVEN DPC does not disallow face for keyguard usage.
when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
.thenReturn(0);
// WHEN the controller dispatches a set new password intent.
mSetNewPasswordController.dispatchSetNewPasswordIntent();
// THEN the choose lock activity is launched with face extras.
ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class);
verify(mUi).launchChooseLock(bundleArgumentCaptor.capture());
// THEN the extras have all values for face setup.
compareFaceExtras(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFingerprint_noFingerprintFeature() {
// GIVEN the device does NOT support fingerprint feature.
@@ -109,6 +139,20 @@ public final class SetNewPasswordControllerTest {
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFace_no_FaceFeature() {
// GIVEN the device does NOT support face feature.
when(mPackageManager.hasSystemFeature(eq(FEATURE_FACE))).thenReturn(false);
// WHEN the controller dispatches a set new password intent.
mSetNewPasswordController.dispatchSetNewPasswordIntent();
// THEN the choose lock activity is launched without face extras.
ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class);
verify(mUi).launchChooseLock(bundleArgumentCaptor.capture());
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFingerprint_noFingerprintSensor() {
// GIVEN the device does NOT support fingerprint.
@@ -128,6 +172,25 @@ public final class SetNewPasswordControllerTest {
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFace_noFaceSensor() {
// GIVEN the device does NOT support face.
when(mFaceManager.isHardwareDetected()).thenReturn(false);
// GIVEN there are no enrolled face.
when(mFaceManager.hasEnrolledFaces(CURRENT_USER_ID)).thenReturn(false);
// GIVEN DPC does not disallow face for keyguard usage.
when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
.thenReturn(0);
// WHEN the controller dispatches a set new password intent.
mSetNewPasswordController.dispatchSetNewPasswordIntent();
// THEN the choose lock activity is launched without a bundle contains user id only.
ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class);
verify(mUi).launchChooseLock(bundleArgumentCaptor.capture());
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFingerprint_hasFingerprintEnrolled() {
// GIVEN the device supports fingerprint.
@@ -147,6 +210,25 @@ public final class SetNewPasswordControllerTest {
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFace_hasFaceEnrolled() {
// GIVEN the device supports face.
when(mFaceManager.isHardwareDetected()).thenReturn(true);
// GIVEN there are no enrolled face.
when(mFaceManager.hasEnrolledFaces(CURRENT_USER_ID)).thenReturn(true);
// GIVEN DPC does not disallow face for keyguard usage.
when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
.thenReturn(0);
// WHEN the controller dispatches a set new password intent.
mSetNewPasswordController.dispatchSetNewPasswordIntent();
// THEN the choose lock activity is launched without a bundle contains user id only.
ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class);
verify(mUi).launchChooseLock(bundleArgumentCaptor.capture());
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFingerprint_deviceAdminDisallowFingerprintForKeyguard() {
// GIVEN the device supports fingerprint.
@@ -166,6 +248,25 @@ public final class SetNewPasswordControllerTest {
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
@Test
public void launchChooseLockWithoutFace_deviceAdminDisallowFaceForKeyguard() {
// GIVEN the device supports face.
when(mFaceManager.isHardwareDetected()).thenReturn(true);
// GIVEN there is an enrolled face.
when(mFaceManager.hasEnrolledFaces(CURRENT_USER_ID)).thenReturn(true);
// GIVEN DPC disallows face for keyguard usage.
when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(ComponentName.class)))
.thenReturn(DevicePolicyManager.KEYGUARD_DISABLE_FACE);
// WHEN the controller dispatches a set new password intent.
mSetNewPasswordController.dispatchSetNewPasswordIntent();
// THEN the choose lock activity is launched without a bundle contains user id only.
ArgumentCaptor<Bundle> bundleArgumentCaptor = ArgumentCaptor.forClass(Bundle.class);
verify(mUi).launchChooseLock(bundleArgumentCaptor.capture());
assertBundleContainsUserIdOnly(bundleArgumentCaptor.getValue());
}
private void compareFingerprintExtras(Bundle actualBundle) {
assertEquals(
"Password quality must be something in order to config fingerprint.",
@@ -190,6 +291,30 @@ public final class SetNewPasswordControllerTest {
actualBundle.getInt(Intent.EXTRA_USER_ID));
}
private void compareFaceExtras(Bundle actualBundle) {
assertEquals(
"Password quality must be something in order to config face.",
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING,
actualBundle.getInt(MINIMUM_QUALITY_KEY));
assertTrue(
"All disabled preference should be removed.",
actualBundle.getBoolean(HIDE_DISABLED_PREFS));
assertTrue(
"There must be a face challenge.",
actualBundle.getBoolean(EXTRA_KEY_HAS_CHALLENGE));
assertEquals(
"The face challenge must come from the FaceManager",
FACE_CHALLENGE,
actualBundle.getLong(EXTRA_KEY_CHALLENGE));
assertTrue(
"The request must be a face set up request.",
actualBundle.getBoolean(EXTRA_KEY_FOR_FACE));
assertEquals(
"User id must be equaled to the input one.",
CURRENT_USER_ID,
actualBundle.getInt(Intent.EXTRA_USER_ID));
}
private void assertBundleContainsUserIdOnly(Bundle actualBundle) {
assertThat(actualBundle.size()).isEqualTo(1);
assertThat(actualBundle.getInt(Intent.EXTRA_USER_ID)).isEqualTo(CURRENT_USER_ID);