Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
FaceService: Allow our face unlock to be used on third-party apps
Browse files Browse the repository at this point in the history
Change-Id: Ib9041442572885ceda3afbafd23f8e89226b0364
  • Loading branch information
jhenrique09 committed Mar 20, 2022
1 parent a485745 commit d2d63bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
import java.util.Random;
import java.util.function.Function;

import com.android.internal.util.custom.faceunlock.FaceUnlockUtils;

/**
* Class that defines the states of an authentication session invoked via
* {@link android.hardware.biometrics.BiometricPrompt}, as well as all of the necessary
Expand Down Expand Up @@ -331,6 +333,9 @@ void onCookieReceived(int cookie) {
}

private boolean isConfirmationRequired(BiometricSensor sensor) {
if (sensor.modality == TYPE_FACE && FaceUnlockUtils.isFaceUnlockSupported()) {
return true;
}
return sensor.confirmationSupported()
&& (sensor.confirmationAlwaysRequired(mUserId)
|| mPreAuthInfo.confirmationRequested);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

import com.android.internal.util.custom.faceunlock.FaceUnlockUtils;

/**
* System service that arbitrates the modality for BiometricPrompt to use.
*/
Expand Down Expand Up @@ -350,10 +352,6 @@ public static class SettingObserver extends ContentObserver {
private static final boolean DEFAULT_APP_ENABLED = true;
private static final boolean DEFAULT_ALWAYS_REQUIRE_CONFIRMATION = false;

// Some devices that shipped before S already have face-specific settings. Instead of
// migrating, which is complicated, let's just keep using the existing settings.
private final boolean mUseLegacyFaceOnlySettings;

// Only used for legacy face-only devices
private final Uri FACE_UNLOCK_KEYGUARD_ENABLED =
Settings.Secure.getUriFor(Settings.Secure.FACE_UNLOCK_KEYGUARD_ENABLED);
Expand Down Expand Up @@ -393,18 +391,13 @@ public SettingObserver(Context context, Handler handler,
final boolean hasFace = context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_FACE);

// Use the legacy setting on face-only devices that shipped on or before Q
mUseLegacyFaceOnlySettings =
Build.VERSION.DEVICE_INITIAL_SDK_INT <= Build.VERSION_CODES.Q
&& hasFace && !hasFingerprint;

updateContentObserver();
}

public void updateContentObserver() {
mContentResolver.unregisterContentObserver(this);

if (mUseLegacyFaceOnlySettings) {
if (FaceUnlockUtils.isFaceUnlockSupported()) {
mContentResolver.registerContentObserver(FACE_UNLOCK_KEYGUARD_ENABLED,
false /* notifyForDescendants */,
this /* observer */,
Expand Down Expand Up @@ -474,7 +467,7 @@ public void onChange(boolean selfChange, Uri uri, int userId) {

public boolean getEnabledOnKeyguard(int userId) {
if (!mBiometricEnabledOnKeyguard.containsKey(userId)) {
if (mUseLegacyFaceOnlySettings) {
if (FaceUnlockUtils.isFaceUnlockSupported()) {
onChange(true /* selfChange */, FACE_UNLOCK_KEYGUARD_ENABLED, userId);
} else {
onChange(true /* selfChange */, BIOMETRIC_KEYGUARD_ENABLED, userId);
Expand All @@ -485,7 +478,7 @@ public boolean getEnabledOnKeyguard(int userId) {

public boolean getEnabledForApps(int userId) {
if (!mBiometricEnabledForApps.containsKey(userId)) {
if (mUseLegacyFaceOnlySettings) {
if (FaceUnlockUtils.isFaceUnlockSupported()) {
onChange(true /* selfChange */, FACE_UNLOCK_APP_ENABLED, userId);
} else {
onChange(true /* selfChange */, BIOMETRIC_APP_ENABLED, userId);
Expand Down Expand Up @@ -1483,9 +1476,6 @@ private BiometricSensor getSensorForId(int sensorId) {
}

private void dumpInternal(PrintWriter pw) {
pw.println("Legacy Settings: " + mSettingObserver.mUseLegacyFaceOnlySettings);
pw.println();

pw.println("Sensors:");
for (BiometricSensor sensor : mSensors) {
pw.println(" " + sensor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.ArrayList;
import java.util.List;

import com.android.internal.util.custom.faceunlock.FaceUnlockUtils;

/**
* Class representing the calling client's request. Additionally, derives/calculates
* preliminary info that would be useful in helping serve this request. Note that generating
Expand Down Expand Up @@ -226,6 +228,9 @@ static PreAuthInfo create(ITrustManager trustManager,

private static boolean isEnabledForApp(BiometricService.SettingObserver settingObserver,
@BiometricAuthenticator.Modality int modality, int userId) {
if (modality == TYPE_FINGERPRINT && FaceUnlockUtils.isFaceUnlockSupported()){
return true;
}
return settingObserver.getEnabledForApps(userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.annotation.Nullable;
import android.content.Context;
import android.hardware.biometrics.BiometricManager;
import android.hardware.biometrics.SensorProperties;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.hardware.biometrics.IBiometricSensorReceiver;
import android.hardware.biometrics.IBiometricService;
Expand Down Expand Up @@ -655,7 +656,7 @@ private void addAidlProviders() {

private void addCustomProviders() {
if (CustomFaceProvider.useCustomFaceUnlockService()) {
mServiceProviders.add(new CustomFaceProvider(getContext(), new FaceSensorPropertiesInternal(CustomFaceProvider.DEVICE_ID, 0, 1, new ArrayList(), 1, false, false, false), mLockoutResetDispatcher));
mServiceProviders.add(new CustomFaceProvider(getContext(), new FaceSensorPropertiesInternal(CustomFaceProvider.DEVICE_ID, SensorProperties.STRENGTH_STRONG, 1, new ArrayList(), 1, false, false, false), mLockoutResetDispatcher));
}
}

Expand Down

0 comments on commit d2d63bd

Please sign in to comment.