Fix Settings crash on non face service support devices am: e85d588904 am: d4ce5542fd

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

Change-Id: Ifaeb7fe69a6a486c8b73e8043308416479d3b0d7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
lbill
2023-04-17 18:46:17 +00:00
committed by Automerger Merge Worker
2 changed files with 88 additions and 21 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.biometrics.face;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.biometrics.SensorProperties;
import android.hardware.face.FaceManager;
import android.hardware.face.FaceSensorPropertiesInternal;
@@ -49,32 +50,17 @@ public class FaceSettingsFooterPreferenceController extends BasePreferenceContro
public FaceSettingsFooterPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mProvider = FeatureFactory.getFactory(context).getFaceFeatureProvider();
FaceManager faceManager = context.getSystemService(FaceManager.class);
faceManager.addAuthenticatorsRegisteredCallback(
new IFaceAuthenticatorsRegisteredCallback.Stub() {
@Override
public void onAllAuthenticatorsRegistered(
@NonNull List<FaceSensorPropertiesInternal> sensors) {
if (sensors.isEmpty()) {
Log.e(TAG, "No sensors");
return;
}
boolean isFaceStrong = sensors.get(0).sensorStrength
== SensorProperties.STRENGTH_STRONG;
if (mIsFaceStrong == isFaceStrong) {
return;
}
mIsFaceStrong = isFaceStrong;
updateState(mPreference);
}
});
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(mPreferenceKey);
if (screen.getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) {
addAuthenticatorsRegisteredCallback(screen.getContext());
} else {
Log.w(TAG, "Not support FEATURE_FACE");
}
}
@Override
@@ -105,4 +91,27 @@ public class FaceSettingsFooterPreferenceController extends BasePreferenceContro
preference.setTitle(AnnotationSpan.linkify(
mContext.getText(footerRes), linkInfo));
}
private void addAuthenticatorsRegisteredCallback(Context context) {
final FaceManager faceManager = context.getSystemService(FaceManager.class);
faceManager.addAuthenticatorsRegisteredCallback(
new IFaceAuthenticatorsRegisteredCallback.Stub() {
@Override
public void onAllAuthenticatorsRegistered(
@NonNull List<FaceSensorPropertiesInternal> sensors) {
if (sensors.isEmpty()) {
Log.e(TAG, "No sensors");
return;
}
boolean isFaceStrong = sensors.get(0).sensorStrength
== SensorProperties.STRENGTH_STRONG;
if (mIsFaceStrong == isFaceStrong) {
return;
}
mIsFaceStrong = isFaceStrong;
updateState(mPreference);
}
});
}
}