Use the internal max faces number to check enrolled.

Test: manually tested on device
Test: robotest for FaceEnrollIntroductionTest
Bug: 243759589
Change-Id: I193c7b7c49f884541bd5d8282d15bf69e46f3392
This commit is contained in:
Hao Dong
2022-11-17 20:35:52 +00:00
parent 47c0ee6b38
commit b4000fb226
2 changed files with 36 additions and 13 deletions

View File

@@ -26,7 +26,6 @@ import android.content.Intent;
import android.hardware.SensorPrivacyManager; import android.hardware.SensorPrivacyManager;
import android.hardware.biometrics.BiometricAuthenticator; import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorPropertiesInternal;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; 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.setupcompat.util.WizardManagerHelper;
import com.google.android.setupdesign.span.LinkSpan; 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 * Provides introductory info about face unlock and prompts the user to agree before starting face
* enrollment. * enrollment.
@@ -311,20 +308,12 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
} }
private boolean maxFacesEnrolled() { private boolean maxFacesEnrolled() {
final boolean isSetupWizard = WizardManagerHelper.isAnySetupWizard(getIntent());
if (mFaceManager != null) { if (mFaceManager != null) {
final List<FaceSensorPropertiesInternal> props =
mFaceManager.getSensorPropertiesInternal();
// This will need to be updated for devices with multiple face sensors. // 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 numEnrolledFaces = mFaceManager.getEnrolledFaces(mUserId).size();
final int maxFacesEnrollableIfSUW = getApplicationContext().getResources() final int maxFacesEnrollable = getApplicationContext().getResources()
.getInteger(R.integer.suw_max_faces_enrollable); .getInteger(R.integer.suw_max_faces_enrollable);
if (isSetupWizard) { return numEnrolledFaces >= maxFacesEnrollable;
return numEnrolledFaces >= maxFacesEnrollableIfSUW;
} else {
return numEnrolledFaces >= max;
}
} else { } else {
return false; return false;
} }

View File

@@ -22,13 +22,16 @@ import static com.google.common.truth.Truth.assertWithMessage;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;
import android.content.Intent; import android.content.Intent;
import android.hardware.face.Face;
import android.hardware.face.FaceManager; import android.hardware.face.FaceManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.android.settings.R;
import com.android.settings.biometrics.BiometricUtils; import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.password.ChooseLockSettingsHelper; import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.testutils.shadow.ShadowLockPatternUtils; 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.annotation.Config;
import org.robolectric.shadows.ShadowActivity; import org.robolectric.shadows.ShadowActivity;
import java.util.ArrayList;
import java.util.List;
@RunWith(RobolectricTestRunner.class) @RunWith(RobolectricTestRunner.class)
@Config(shadows = { @Config(shadows = {
ShadowLockPatternUtils.class, ShadowLockPatternUtils.class,
@@ -77,6 +83,34 @@ public class FaceEnrollIntroductionTest {
mActivity.mOverrideFaceManager = mFaceManager; 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 @Test
public void testOnCreate() { public void testOnCreate() {
setupActivity(new Intent()); setupActivity(new Intent());