Merge "Fix face re-enroll stuck for work profile" into udc-qpr-dev am: 14b115177c

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23591204

Change-Id: I6b745a87a4a20ca01bb55cc0a5e921c12f1fcc23
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Wenhui Yang
2023-06-13 01:48:41 +00:00
committed by Automerger Merge Worker
2 changed files with 48 additions and 2 deletions

View File

@@ -120,6 +120,8 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
protected void onCreate(Bundle savedInstanceState) {
mFaceManager = getFaceManager();
super.onCreate(savedInstanceState);
if (savedInstanceState == null
&& !WizardManagerHelper.isAnySetupWizard(getIntent())
&& !getIntent().getBooleanExtra(EXTRA_FROM_SETTINGS_SUMMARY, false)
@@ -130,8 +132,6 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
finish();
}
super.onCreate(savedInstanceState);
// Wait super::onCreated() then return because SuperNotCalledExceptio will be thrown
// if we don't wait for it.
if (isFinishing()) {

View File

@@ -40,6 +40,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.hardware.face.Face;
import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorProperties;
@@ -116,6 +117,7 @@ public class FaceEnrollIntroductionTest {
private FaceEnrollIntroduction mSpyActivity;
private FakeFeatureFactory mFakeFeatureFactory;
private ShadowUserManager mUserManager;
private Resources mResources;
enum GateKeeperAction {CALL_SUPER, RETURN_BYTE_ARRAY, THROW_CREDENTIAL_NOT_MATCH}
@@ -245,6 +247,14 @@ public class FaceEnrollIntroductionTest {
when(mFaceManager.getEnrolledFaces(anyInt())).thenReturn(faces);
}
private void setFaceManagerToHaveWithUserId(int numEnrollments, int userId) {
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(userId)).thenReturn(faces);
}
@Test
public void intro_CheckCanEnroll() {
setFaceManagerToHave(0 /* numEnrollments */);
@@ -546,4 +556,40 @@ public class FaceEnrollIntroductionTest {
assertThat(mActivity.getPostureCallback()).isNull();
}
@Test
public void testFaceEnrollIntroduction_maxFacesNotEnrolled_addUserProfile() {
// Enroll a face for one user
setFaceManagerToHaveWithUserId(1, 0);
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = spy(mContext.getResources());
when(mResources.getInteger(R.integer.suw_max_faces_enrollable)).thenReturn(1);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, new Intent());
mActivity = (TestFaceEnrollIntroduction) mController.get();
mController.create();
// The maximum number of faces is already enrolled
int result = mActivity.checkMaxEnrolled();
assertThat(result).isEqualTo(R.string.face_intro_error_max);
// Add another user profile
mUserManager.addUser(10, "", 0);
final Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_USER_ID, 10);
when(mResources.getInteger(R.integer.suw_max_faces_enrollable)).thenReturn(2);
mController = Robolectric.buildActivity(TestFaceEnrollIntroduction.class, intent);
mActivity = (TestFaceEnrollIntroduction) mController.get();
mController.create();
// The maximum number of faces hasn't been enrolled, so a new face
// can be enrolled for the added user profile
result = mActivity.checkMaxEnrolled();
assertThat(result).isEqualTo(0);
}
}