Merge "Use the internal max faces number to check enrolled."
This commit is contained in:
@@ -26,7 +26,6 @@ import android.content.Intent;
|
||||
import android.hardware.SensorPrivacyManager;
|
||||
import android.hardware.biometrics.BiometricAuthenticator;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.hardware.face.FaceSensorPropertiesInternal;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
@@ -56,8 +55,6 @@ import com.google.android.setupcompat.template.FooterButton;
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
import com.google.android.setupdesign.span.LinkSpan;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides introductory info about face unlock and prompts the user to agree before starting face
|
||||
* enrollment.
|
||||
@@ -311,20 +308,12 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
|
||||
}
|
||||
|
||||
private boolean maxFacesEnrolled() {
|
||||
final boolean isSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
|
||||
if (mFaceManager != null) {
|
||||
final List<FaceSensorPropertiesInternal> props =
|
||||
mFaceManager.getSensorPropertiesInternal();
|
||||
// This will need to be updated for devices with multiple face sensors.
|
||||
final int max = props.get(0).maxEnrollmentsPerUser;
|
||||
final int numEnrolledFaces = mFaceManager.getEnrolledFaces(mUserId).size();
|
||||
final int maxFacesEnrollableIfSUW = getApplicationContext().getResources()
|
||||
final int maxFacesEnrollable = getApplicationContext().getResources()
|
||||
.getInteger(R.integer.suw_max_faces_enrollable);
|
||||
if (isSetupWizard) {
|
||||
return numEnrolledFaces >= maxFacesEnrollableIfSUW;
|
||||
} else {
|
||||
return numEnrolledFaces >= max;
|
||||
}
|
||||
return numEnrolledFaces >= maxFacesEnrollable;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@@ -22,13 +22,16 @@ import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.hardware.face.Face;
|
||||
import android.hardware.face.FaceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.biometrics.BiometricUtils;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
|
||||
@@ -47,6 +50,9 @@ import org.robolectric.android.controller.ActivityController;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowLockPatternUtils.class,
|
||||
@@ -77,6 +83,34 @@ public class FaceEnrollIntroductionTest {
|
||||
mActivity.mOverrideFaceManager = mFaceManager;
|
||||
}
|
||||
|
||||
private void setFaceManagerToHave(int numEnrollments) {
|
||||
List<Face> faces = new ArrayList<>();
|
||||
for (int i = 0; i < numEnrollments; i++) {
|
||||
faces.add(new Face("Face " + i /* name */, 1 /*faceId */, 1 /* deviceId */));
|
||||
}
|
||||
when(mFaceManager.getEnrolledFaces(anyInt())).thenReturn(faces);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intro_CheckCanEnroll() {
|
||||
setFaceManagerToHave(0 /* numEnrollments */);
|
||||
setupActivity(new Intent());
|
||||
mController.create();
|
||||
int result = mActivity.checkMaxEnrolled();
|
||||
|
||||
assertThat(result).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intro_CheckMaxEnrolled() {
|
||||
setFaceManagerToHave(1 /* numEnrollments */);
|
||||
setupActivity(new Intent());
|
||||
mController.create();
|
||||
int result = mActivity.checkMaxEnrolled();
|
||||
|
||||
assertThat(result).isEqualTo(R.string.face_intro_error_max);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnCreate() {
|
||||
setupActivity(new Intent());
|
||||
|
Reference in New Issue
Block a user