Fix face re-enroll stuck for work profile
Call super.onCreate(savedInstanceState) first to pass the correct userId in maxFacesEnrolled. Test: Manual - delete face unlock for work and re-enroll and observe face unlock can be enrolled successfully Test: atest FaceEnrollIntroductionTest Fixes: 284819031 Change-Id: Ic1620c0ca3ca9adc61f5281abd34471f0c1b3f97
This commit is contained in:
@@ -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()) {
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user