Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88d40f1c authored by Simon Wingrove's avatar Simon Wingrove Committed by Android (Google) Code Review
Browse files

Merge "Split biometrics resource into three." into main

parents 693d6946 406b5dfa
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -809,6 +809,12 @@
    <!-- Message shown in summary field when Face Unlock is not set up. [CHAR LIMIT=54] -->
    <string name="security_settings_face_preference_summary_none">Setup needed</string>
    <!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=32] -->
    <string name="security_settings_face_preference_title_new">Face</string>
    <!-- Title shown for menu item that launches face settings or enrollment, for work profile. [CHAR LIMIT=50] -->
    <string name="security_settings_face_profile_preference_title_new">Face for work</string>
    <!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=32] -->
    <string name="private_space_face_unlock_title_new">Face for private space</string>
    <!-- Title shown for menu item that launches face settings or enrollment. [CHAR LIMIT=32] -->
    <string name="security_settings_face_preference_title">Face Unlock</string>
    <!-- Title shown for menu item that launches face settings or enrollment, for work profile [CHAR LIMIT=50] -->
    <string name="security_settings_face_profile_preference_title">Face Unlock for work</string>
@@ -938,6 +944,8 @@
    <string name="security_settings_fingerprint_settings_preferences_category">When using Fingerprint Unlock</string>
    <!-- Title shown for work menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] -->
    <string name="security_settings_work_fingerprint_preference_title">Fingerprint for work</string>
    <!-- Title shown for work menu item that launches fingerprint settings or enrollment [CHAR LIMIT=22] -->
    <string name="security_settings_work_fingerprint_preference_title_new">Fingerprint for work</string>
    <!-- Preference to check enrolled fingerprints -->
    <string name="fingerprint_check_enrolled_title">Check enrolled fingerprints</string>
    <!-- Preference to add another fingerprint -->
@@ -1381,6 +1389,8 @@
    <string name="private_space_biometric_summary">Tap to set up</string>
    <!-- Title for the Fingerprint unlock for private space preference. [CHAR LIMIT=60] -->
    <string name="private_space_fingerprint_unlock_title">Fingerprint Unlock for private space</string>
    <!-- Title for the Fingerprint unlock for private space preference. [CHAR LIMIT=60] -->
    <string name="private_space_fingerprint_unlock_title_new">Fingerprint for private space</string>
    <!-- Title for the Face unlock for private space preference. [CHAR LIMIT=60] -->
    <string name="private_space_face_unlock_title">Face Unlock for private space</string>
    <!-- Title for the Face and Fingerprint preference for private space. [CHAR LIMIT=60] -->
+41 −29
Original line number Diff line number Diff line
@@ -26,12 +26,11 @@ import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.Utils;
import com.android.settings.biometrics.ParentalControlsUtils;
import com.android.settings.flags.Flags;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;

/**
 * Utilities for face details shared between Security Settings and Safety Center.
 */
/** Utilities for face details shared between Security Settings and Safety Center. */
public class FaceStatusUtils {

    private final int mUserId;
@@ -44,9 +43,7 @@ public class FaceStatusUtils {
        mUserId = userId;
    }

    /**
     * Returns whether the face settings entity should be shown.
     */
    /** Returns whether the face settings entity should be shown. */
    public boolean isAvailable() {
        return !Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext);
    }
@@ -61,55 +58,70 @@ public class FaceStatusUtils {
                mContext, BiometricAuthenticator.TYPE_FACE);
    }

    /**
     * Returns the title of face settings entity.
     */
    /** Returns the title of face settings entity. */
    public String getTitle() {
        UserManager userManager = mContext.getSystemService(UserManager.class);
        if (userManager != null && userManager.isProfile()) {
            return mContext.getString(
                    Utils.isPrivateProfile(mUserId, mContext)
                            ? R.string.private_space_face_unlock_title
                            : R.string.security_settings_face_profile_preference_title);
                            ? getPrivateSpaceTitle()
                            : getWorkProfileTitle());
        } else {
            return mContext.getString(R.string.security_settings_face_preference_title);
            return mContext.getString(getRegularTitle());
        }
    }

    /**
     * Returns the summary of face settings entity.
     */
    private int getPrivateSpaceTitle() {
        if (Flags.biometricsOnboardingEducation()) {
            return R.string.private_space_face_unlock_title_new;
        }
        return R.string.private_space_face_unlock_title;
    }

    private int getWorkProfileTitle() {
        if (Flags.biometricsOnboardingEducation()) {
            return R.string.security_settings_face_profile_preference_title_new;
        }
        return R.string.security_settings_face_profile_preference_title;
    }

    private int getRegularTitle() {
        if (Flags.biometricsOnboardingEducation()) {
            return R.string.security_settings_face_preference_title_new;
        }
        return R.string.security_settings_face_preference_title;
    }

    /** Returns the summary of face settings entity. */
    public String getSummary() {
        if (shouldShowDisabledByAdminStr()) {
            return mContext.getString(
                    com.android.settingslib.widget.restricted.R.string.disabled_by_admin);
        } else {
            return mContext.getResources().getString(hasEnrolled()
            return mContext.getResources()
                    .getString(
                            hasEnrolled()
                                    ? R.string.security_settings_face_preference_summary
                                    : R.string.security_settings_face_preference_summary_none);
        }
    }

    /**
     * Returns the class name of the Settings page corresponding to face settings.
     */
    /** Returns the class name of the Settings page corresponding to face settings. */
    public String getSettingsClassName() {
        return hasEnrolled() ? Settings.FaceSettingsInternalActivity.class.getName()
        return hasEnrolled()
                ? Settings.FaceSettingsInternalActivity.class.getName()
                : FaceEnrollIntroductionInternal.class.getName();
    }

    /**
     * Returns whether at least one face template has been enrolled.
     */
    /** Returns whether at least one face template has been enrolled. */
    public boolean hasEnrolled() {
        return mFaceManager.hasEnrolledTemplates(mUserId);
    }

    /**
     * Indicates if the face feature is enabled or disabled by the Device Admin.
     */
    /** Indicates if the face feature is enabled or disabled by the Device Admin. */
    private boolean shouldShowDisabledByAdminStr() {
        return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
                mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
                        mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId)
                != null;
    }
}
+60 −23
Original line number Diff line number Diff line
@@ -29,7 +29,9 @@ import androidx.annotation.Nullable;

import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.flags.Flags;
import com.android.settings.safetycenter.BiometricsSafetySource;
import com.android.settings.safetycenter.FaceSafetySource;

/**
 * Responsible for making {@link FaceManager#enroll} and {@link FaceManager#remove} calls and thus
@@ -51,20 +53,43 @@ public class FaceUpdater {
    }

    /** Wrapper around the {@link FaceManager#enroll} method. */
    public void enroll(int userId, byte[] hardwareAuthToken, CancellationSignal cancel,
            FaceManager.EnrollmentCallback callback, int[] disabledFeatures, Intent intent) {
        this.enroll(userId, hardwareAuthToken, cancel,
                new NotifyingEnrollmentCallback(mContext, callback), disabledFeatures,
                null, false, intent);
    public void enroll(
            int userId,
            byte[] hardwareAuthToken,
            CancellationSignal cancel,
            FaceManager.EnrollmentCallback callback,
            int[] disabledFeatures,
            Intent intent) {
        this.enroll(
                userId,
                hardwareAuthToken,
                cancel,
                new NotifyingEnrollmentCallback(mContext, callback),
                disabledFeatures,
                null,
                false,
                intent);
    }

    /** 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, Intent intent) {
        mFaceManager.enroll(userId, hardwareAuthToken, cancel,
                new NotifyingEnrollmentCallback(mContext, callback), disabledFeatures,
                previewSurface, debugConsent, toFaceEnrollOptions(intent));
    public void enroll(
            int userId,
            byte[] hardwareAuthToken,
            CancellationSignal cancel,
            FaceManager.EnrollmentCallback callback,
            int[] disabledFeatures,
            @Nullable Surface previewSurface,
            boolean debugConsent,
            Intent intent) {
        mFaceManager.enroll(
                userId,
                hardwareAuthToken,
                cancel,
                new NotifyingEnrollmentCallback(mContext, callback),
                disabledFeatures,
                previewSurface,
                debugConsent,
                toFaceEnrollOptions(intent));
    }

    /** Wrapper around the {@link FaceManager#remove} method. */
@@ -73,17 +98,15 @@ public class FaceUpdater {
    }

    /**
     * Decorator of the {@link FaceManager.EnrollmentCallback} class that notifies other
     * interested parties that a face setting has changed.
     * 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 static class NotifyingEnrollmentCallback extends FaceManager.EnrollmentCallback {

        private final Context mContext;
        private final FaceManager.EnrollmentCallback mCallback;

        NotifyingEnrollmentCallback(Context context,
                FaceManager.EnrollmentCallback callback) {
        NotifyingEnrollmentCallback(Context context, FaceManager.EnrollmentCallback callback) {
            mContext = context;
            mCallback = callback;
        }
@@ -99,8 +122,14 @@ public class FaceUpdater {
        }

        @Override
        public void onEnrollmentFrame(int helpCode, @Nullable CharSequence helpMessage,
                @Nullable FaceEnrollCell cell, int stage, float pan, float tilt, float distance) {
        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);
        }

@@ -108,14 +137,18 @@ public class FaceUpdater {
        public void onEnrollmentProgress(int remaining) {
            mCallback.onEnrollmentProgress(remaining);
            if (remaining == 0) {
                if (Flags.biometricsOnboardingEducation()) {
                    FaceSafetySource.onBiometricsChanged(mContext);
                } else {
                    BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
                }
            }
        }
    }

    /**
     * Decorator of the {@link FaceManager.RemovalCallback} class that notifies other
     * interested parties that a face setting has 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 {

@@ -135,9 +168,13 @@ public class FaceUpdater {
        @Override
        public void onRemovalSucceeded(@Nullable Face fp, int remaining) {
            mCallback.onRemovalSucceeded(fp, remaining);
            if (Flags.biometricsOnboardingEducation()) {
                FaceSafetySource.onBiometricsChanged(mContext);
            } else {
                BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
            }
        }
    }

    private FaceEnrollOptions toFaceEnrollOptions(Intent intent) {
        final int reason = intent.getIntExtra(BiometricUtils.EXTRA_ENROLL_REASON, -1);
+40 −28
Original line number Diff line number Diff line
@@ -25,29 +25,26 @@ import android.os.UserManager;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.biometrics.ParentalControlsUtils;
import com.android.settings.flags.Flags;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.utils.StringUtil;

/**
 * Utilities for fingerprint details shared between Security Settings and Safety Center.
 */
/** Utilities for fingerprint details shared between Security Settings and Safety Center. */
public class FingerprintStatusUtils {

    private final int mUserId;
    private final Context mContext;
    private final FingerprintManager mFingerprintManager;

    public FingerprintStatusUtils(Context context, FingerprintManager fingerprintManager,
            int userId) {
    public FingerprintStatusUtils(
            Context context, FingerprintManager fingerprintManager, int userId) {
        mContext = context;
        mFingerprintManager = fingerprintManager;
        mUserId = userId;
    }

    /**
     * Returns whether the fingerprint settings entity should be shown.
     */
    /** Returns whether the fingerprint settings entity should be shown. */
    public boolean isAvailable() {
        return !Utils.isMultipleBiometricsSupported(mContext)
                && Utils.hasFingerprintHardware(mContext);
@@ -62,24 +59,42 @@ public class FingerprintStatusUtils {
        return ParentalControlsUtils.parentConsentRequired(
                mContext, BiometricAuthenticator.TYPE_FINGERPRINT);
    }
    /**
     * Returns the title of fingerprint settings entity.
     */

    /** Returns the title of fingerprint settings entity. */
    public String getTitle() {
        UserManager userManager = mContext.getSystemService(UserManager.class);
        if (userManager != null && userManager.isProfile()) {
            return mContext.getString(
                    Utils.isPrivateProfile(mUserId, mContext)
                            ? R.string.private_space_fingerprint_unlock_title
                            : R.string.security_settings_work_fingerprint_preference_title);
                            ? getPrivateSpaceTitle()
                            : getWorkProfileTitle());
        } else {
            return mContext.getString(R.string.security_settings_fingerprint_preference_title);
            return mContext.getString(getRegularTitle());
        }
    }

    /**
     * Returns the summary of fingerprint settings entity.
     */
    private int getPrivateSpaceTitle() {
        if (Flags.biometricsOnboardingEducation()) {
            return R.string.private_space_fingerprint_unlock_title_new;
        }
        return R.string.private_space_fingerprint_unlock_title;
    }

    private int getWorkProfileTitle() {
        if (Flags.biometricsOnboardingEducation()) {
            return R.string.security_settings_work_fingerprint_preference_title_new;
        }
        return R.string.security_settings_work_fingerprint_preference_title;
    }

    private int getRegularTitle() {
        if (Flags.biometricsOnboardingEducation()) {
            return R.string.security_settings_fingerprint; // doesn't have an overlay
        }
        return R.string.security_settings_fingerprint_preference_title;
    }

    /** Returns the summary of fingerprint settings entity. */
    public String getSummary() {
        if (shouldShowDisabledByAdminStr()) {
            return mContext.getString(
@@ -87,7 +102,9 @@ public class FingerprintStatusUtils {
        }
        if (hasEnrolled()) {
            final int numEnrolled = mFingerprintManager.getEnrolledFingerprints(mUserId).size();
            return StringUtil.getIcuPluralsString(mContext, numEnrolled,
            return StringUtil.getIcuPluralsString(
                    mContext,
                    numEnrolled,
                    R.string.security_settings_fingerprint_preference_summary);
        } else {
            return mContext.getString(
@@ -95,25 +112,20 @@ public class FingerprintStatusUtils {
        }
    }

    /**
     * Returns the class name of the Settings page corresponding to fingerprint settings.
     */
    /** Returns the class name of the Settings page corresponding to fingerprint settings. */
    public String getSettingsClassName() {
        return FingerprintSettings.class.getName();
    }

    /**
     * Returns whether at least one fingerprint has been enrolled.
     */
    /** Returns whether at least one fingerprint has been enrolled. */
    public boolean hasEnrolled() {
        return mFingerprintManager.hasEnrolledFingerprints(mUserId);
    }

    /**
     * Indicates if the fingerprint feature should show the "Disabled by Admin" string.
     */
    /** Indicates if the fingerprint feature should show the "Disabled by Admin" string. */
    private boolean shouldShowDisabledByAdminStr() {
        return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
                mContext, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId) != null;
                        mContext, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId)
                != null;
    }
}
+27 −10
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@ import androidx.annotation.Nullable;

import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricUtils;
import com.android.settings.flags.Flags;
import com.android.settings.safetycenter.BiometricsSafetySource;
import com.android.settings.safetycenter.FingerprintSafetySource;

/**
 * Responsible for making {@link FingerprintManager#enroll} and {@link FingerprintManager#remove}
@@ -49,11 +51,19 @@ public class FingerprintUpdater {
    }

    /** Wrapper around the {@link FingerprintManager#enroll} method. */
    public void enroll(byte [] hardwareAuthToken, CancellationSignal cancel, int userId,
    public void enroll(
            byte[] hardwareAuthToken,
            CancellationSignal cancel,
            int userId,
            FingerprintManager.EnrollmentCallback callback,
            @FingerprintManager.EnrollReason int enrollReason, Intent intent) {
        mFingerprintManager.enroll(hardwareAuthToken, cancel, userId,
                new NotifyingEnrollmentCallback(mContext, callback), enrollReason,
            @FingerprintManager.EnrollReason int enrollReason,
            Intent intent) {
        mFingerprintManager.enroll(
                hardwareAuthToken,
                cancel,
                userId,
                new NotifyingEnrollmentCallback(mContext, callback),
                enrollReason,
                toFingerprintEnrollOptions(intent));
    }

@@ -66,14 +76,13 @@ public class FingerprintUpdater {
     * Decorator of the {@link FingerprintManager.EnrollmentCallback} class that notifies other
     * interested parties that a fingerprint setting has changed.
     */
    private static class NotifyingEnrollmentCallback
            extends FingerprintManager.EnrollmentCallback {
    private static class NotifyingEnrollmentCallback extends FingerprintManager.EnrollmentCallback {

        private final Context mContext;
        private final FingerprintManager.EnrollmentCallback mCallback;

        NotifyingEnrollmentCallback(Context context,
                FingerprintManager.EnrollmentCallback callback) {
        NotifyingEnrollmentCallback(
                Context context, FingerprintManager.EnrollmentCallback callback) {
            mContext = context;
            mCallback = callback;
        }
@@ -92,9 +101,13 @@ public class FingerprintUpdater {
        public void onEnrollmentProgress(int remaining) {
            mCallback.onEnrollmentProgress(remaining);
            if (remaining == 0) {
                if (Flags.biometricsOnboardingEducation()) {
                    FingerprintSafetySource.onBiometricsChanged(mContext);
                } else {
                    BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
                }
            }
        }

        @Override
        public void onAcquired(boolean isAcquiredGood) {
@@ -139,9 +152,13 @@ public class FingerprintUpdater {
        @Override
        public void onRemovalSucceeded(@Nullable Fingerprint fp, int remaining) {
            mCallback.onRemovalSucceeded(fp, remaining);
            if (Flags.biometricsOnboardingEducation()) {
                FingerprintSafetySource.onBiometricsChanged(mContext);
            } else {
                BiometricsSafetySource.onBiometricsChanged(mContext); // biometrics data changed
            }
        }
    }

    private FingerprintEnrollOptions toFingerprintEnrollOptions(Intent intent) {
        final int reason = intent.getIntExtra(BiometricUtils.EXTRA_ENROLL_REASON, -1);
Loading