Trigger SafetyCenter update on each Face setting change.
Test: atest SettingsUnitTests Bug: 215518850 Change-Id: I7a55fd5368c9aad5329448732125d4e43688eced
This commit is contained in:
@@ -19,9 +19,7 @@ package com.android.settings.biometrics.face;
|
||||
import android.app.Activity;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.BiometricEnrollSidecar;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -33,7 +31,7 @@ public class FaceEnrollSidecar extends BiometricEnrollSidecar {
|
||||
|
||||
private final int[] mDisabledFeatures;
|
||||
|
||||
private FaceManager mFaceManager;
|
||||
private FaceUpdater mFaceUpdater;
|
||||
|
||||
public FaceEnrollSidecar(int[] disabledFeatures) {
|
||||
mDisabledFeatures = Arrays.copyOf(disabledFeatures, disabledFeatures.length);
|
||||
@@ -42,13 +40,13 @@ public class FaceEnrollSidecar extends BiometricEnrollSidecar {
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
mFaceManager = Utils.getFaceManagerOrNull(activity);
|
||||
mFaceUpdater = new FaceUpdater(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startEnrollment() {
|
||||
super.startEnrollment();
|
||||
mFaceManager.enroll(mUserId, mToken, mEnrollmentCancel,
|
||||
mFaceUpdater.enroll(mUserId, mToken, mEnrollmentCancel,
|
||||
mEnrollmentCallback, mDisabledFeatures);
|
||||
}
|
||||
|
||||
|
@@ -103,6 +103,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private final Context mContext;
|
||||
private final FaceManager mFaceManager;
|
||||
private final FaceUpdater mFaceUpdater;
|
||||
private final FaceManager.RemovalCallback mRemovalCallback = new FaceManager.RemovalCallback() {
|
||||
@Override
|
||||
public void onRemovalError(Face face, int errMsgId, CharSequence errString) {
|
||||
@@ -144,7 +145,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
}
|
||||
|
||||
// Remove the first/only face
|
||||
mFaceManager.remove(faces.get(0), mUserId, mRemovalCallback);
|
||||
mFaceUpdater.remove(faces.get(0), mUserId, mRemovalCallback);
|
||||
} else {
|
||||
mButton.setEnabled(true);
|
||||
mRemoving = false;
|
||||
@@ -157,6 +158,7 @@ public class FaceSettingsRemoveButtonPreferenceController extends BasePreference
|
||||
mContext = context;
|
||||
mFaceManager = context.getSystemService(FaceManager.class);
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
mFaceUpdater = new FaceUpdater(context, mFaceManager);
|
||||
}
|
||||
|
||||
public FaceSettingsRemoveButtonPreferenceController(Context context) {
|
||||
|
137
src/com/android/settings/biometrics/face/FaceUpdater.java
Normal file
137
src/com/android/settings/biometrics/face/FaceUpdater.java
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.biometrics.face;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.face.Face;
|
||||
import android.hardware.face.FaceEnrollCell;
|
||||
import android.hardware.face.FaceManager;
|
||||
import android.os.CancellationSignal;
|
||||
import android.view.Surface;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.safetycenter.BiometricsSafetySource;
|
||||
|
||||
/**
|
||||
* Responsible for making {@link FaceManager#enroll} and {@link FaceManager#remove} calls and thus
|
||||
* updating the face setting.
|
||||
*/
|
||||
public class FaceUpdater {
|
||||
|
||||
private final Context mContext;
|
||||
private final FaceManager mFaceManager;
|
||||
|
||||
public FaceUpdater(Context context) {
|
||||
mContext = context;
|
||||
mFaceManager = Utils.getFaceManagerOrNull(context);
|
||||
}
|
||||
|
||||
public FaceUpdater(Context context, FaceManager faceManager) {
|
||||
mContext = context;
|
||||
mFaceManager = faceManager;
|
||||
}
|
||||
|
||||
/** Wrapper around the {@link FaceManager#enroll} method. */
|
||||
public void enroll(int userId, byte[] hardwareAuthToken, CancellationSignal cancel,
|
||||
FaceManager.EnrollmentCallback callback, int[] disabledFeatures) {
|
||||
mFaceManager.enroll(userId, hardwareAuthToken, cancel,
|
||||
new NotifyingEnrollmentCallback(mContext, callback), disabledFeatures);
|
||||
}
|
||||
|
||||
/** Wrapper around the {@link FaceManager#enroll} method. */
|
||||
public void enroll(int userId, byte[] hardwareAuthToken, CancellationSignal cancel,
|
||||
FaceManager.EnrollmentCallback callback, int[] disabledFeatures,
|
||||
@Nullable Surface previewSurface, boolean debugConsent) {
|
||||
mFaceManager.enroll(userId, hardwareAuthToken, cancel,
|
||||
new NotifyingEnrollmentCallback(mContext, callback), disabledFeatures,
|
||||
previewSurface, debugConsent);
|
||||
}
|
||||
|
||||
/** Wrapper around the {@link FaceManager#remove} method. */
|
||||
public void remove(Face face, int userId, FaceManager.RemovalCallback callback) {
|
||||
mFaceManager.remove(face, userId, new NotifyingRemovalCallback(mContext, callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator of the {@link FaceManager.EnrollmentCallback} class that notifies other
|
||||
* interested parties that a face setting has changed.
|
||||
*/
|
||||
private static class NotifyingEnrollmentCallback
|
||||
extends FaceManager.EnrollmentCallback {
|
||||
|
||||
private final Context mContext;
|
||||
private final FaceManager.EnrollmentCallback mCallback;
|
||||
|
||||
NotifyingEnrollmentCallback(Context context,
|
||||
FaceManager.EnrollmentCallback callback) {
|
||||
mContext = context;
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentError(int errMsgId, CharSequence errString) {
|
||||
mCallback.onEnrollmentError(errMsgId, errString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
|
||||
mCallback.onEnrollmentHelp(helpMsgId, helpString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentFrame(int helpCode, @Nullable CharSequence helpMessage,
|
||||
@Nullable FaceEnrollCell cell, int stage, float pan, float tilt, float distance) {
|
||||
mCallback.onEnrollmentFrame(helpCode, helpMessage, cell, stage, pan, tilt, distance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnrollmentProgress(int remaining) {
|
||||
mCallback.onEnrollmentProgress(remaining);
|
||||
if (remaining == 0) {
|
||||
BiometricsSafetySource.sendSafetyData(mContext); // biometrics data changed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator of the {@link FaceManager.RemovalCallback} class that notifies other
|
||||
* interested parties that a face setting has changed.
|
||||
*/
|
||||
private static class NotifyingRemovalCallback extends FaceManager.RemovalCallback {
|
||||
|
||||
private final Context mContext;
|
||||
private final FaceManager.RemovalCallback mCallback;
|
||||
|
||||
NotifyingRemovalCallback(Context context, FaceManager.RemovalCallback callback) {
|
||||
mContext = context;
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovalError(Face fp, int errMsgId, CharSequence errString) {
|
||||
mCallback.onRemovalError(fp, errMsgId, errString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemovalSucceeded(@Nullable Face fp, int remaining) {
|
||||
mCallback.onRemovalSucceeded(fp, remaining);
|
||||
BiometricsSafetySource.sendSafetyData(mContext); // biometrics data changed
|
||||
}
|
||||
}
|
||||
}
|
@@ -30,6 +30,7 @@ import com.android.internal.app.AlertActivity;
|
||||
import com.android.internal.app.AlertController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.biometrics.face.FaceUpdater;
|
||||
import com.android.settings.homepage.contextualcards.slices.FaceSetupSlice;
|
||||
|
||||
/**
|
||||
@@ -43,6 +44,7 @@ public class FaceReEnrollDialog extends AlertActivity implements
|
||||
private static final String BIOMETRIC_ENROLL_ACTION = "android.settings.BIOMETRIC_ENROLL";
|
||||
|
||||
private FaceManager mFaceManager;
|
||||
private FaceUpdater mFaceUpdater;
|
||||
/**
|
||||
* The type of re-enrollment that has been requested,
|
||||
* see {@link Settings.Secure#FACE_UNLOCK_RE_ENROLL} for more details.
|
||||
@@ -67,6 +69,7 @@ public class FaceReEnrollDialog extends AlertActivity implements
|
||||
alertParams.mPositiveButtonListener = this;
|
||||
|
||||
mFaceManager = Utils.getFaceManagerOrNull(getApplicationContext());
|
||||
mFaceUpdater = new FaceUpdater(getApplicationContext(), mFaceManager);
|
||||
|
||||
final Context context = getApplicationContext();
|
||||
mReEnrollType = FaceSetupSlice.getReEnrollSetting(context, getUserId());
|
||||
@@ -96,7 +99,7 @@ public class FaceReEnrollDialog extends AlertActivity implements
|
||||
if (mFaceManager == null || !mFaceManager.hasEnrolledTemplates(userId)) {
|
||||
finish();
|
||||
}
|
||||
mFaceManager.remove(new Face("", 0, 0), userId, new FaceManager.RemovalCallback() {
|
||||
mFaceUpdater.remove(new Face("", 0, 0), userId, new FaceManager.RemovalCallback() {
|
||||
@Override
|
||||
public void onRemovalError(Face face, int errMsgId, CharSequence errString) {
|
||||
super.onRemovalError(face, errMsgId, errString);
|
||||
|
Reference in New Issue
Block a user