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

Commit a94e1aaf authored by Kevin Chyn's avatar Kevin Chyn Committed by Android (Google) Code Review
Browse files

Merge "Update FaceSettings to match mocks"

parents f2b61c9c a8843f29
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -893,6 +893,12 @@
    <string name="security_settings_face_settings_use_face_category">Use your face to</string>
    <!-- Text shown on a toggle which allows or disallows the device to use face for unlocking the device. [CHAR LIMIT=20] -->
    <string name="security_settings_face_settings_use_face_unlock_phone">Unlock your device</string>
    <!-- Text shown on a toggle which allows or disallows the device to use face authentication for apps. This will be presented to the user together with the context of security_settings_face_settings_use_face_category. [CHAR LIMIT=30] -->
    <string name="security_settings_face_settings_use_face_for_apps">App sign-in \u0026 payments</string>
    <!-- Text shown on a toggle which disables/enables face authentication, depending if the user's eyes are open. [CHAR LIMIT=30] -->
    <string name="security_settings_face_settings_require_attention">Eyes open to unlock</string>
    <!-- Text shown on the details of a toggle which disables/enables face authentication, depending if the user's eyes are open. [CHAR LIMIT=70] -->
    <string name="security_settings_face_settings_require_attention_details">When using face authentication, your eyes must be open</string>
    <!-- Button text in face settings which removes the user's faces from the device [CHAR LIMIT=20] -->
    <string name="security_settings_face_settings_remove_face_data">Remove face data</string>
    <!-- Text shown in face settings allowing the user to update/improve the enrolled face. This brings the user back to the enrollment flow. [CHAR LIMIT=30] -->
@@ -6949,7 +6955,7 @@
    <string name="keywords_payment_settings">pay, tap, payments</string>
    <string name="keywords_backup">backup, back up</string>
    <string name="keywords_assist_gesture_launch">gesture</string>
    <string name="keywords_face_unlock">face, unlock</string>
    <string name="keywords_face_unlock">face, unlock, auth, sign in</string>
    <string name="keywords_imei_info">imei, meid, min, prl version, imei sv</string>
    <string name="keywords_sim_status">network, mobile network state, service state, signal strength, mobile network type, roaming, iccid</string>
    <string name="keywords_model_and_hardware">serial number, hardware version</string>
+16 −3
Original line number Diff line number Diff line
@@ -22,21 +22,34 @@

    <com.android.settings.widget.VideoPreference
        android:key="security_settings_face_video"
        android:title="@string/summary_placeholder"
        app:animation="@raw/gesture_fingerprint_swipe"
        app:preview="@drawable/face_enroll_introduction" />
        app:preview="@drawable/face_enroll_introduction"
        app:controller="com.android.settings.widget.VideoPreferenceController"/>

    <PreferenceCategory
        android:key="security_settings_face_unlock_category"
        android:title="@string/security_settings_face_settings_use_face_category">
        <SwitchPreference
            android:key="security_settings_face_unlock"
            android:key="security_settings_face_keyguard"
            android:title="@string/security_settings_face_settings_use_face_unlock_phone"
            app:keywords="@string/keywords_face_unlock"
            app:controller="com.android.settings.biometrics.face.FaceSettingsUnlockPreferenceController"/>
            app:controller="com.android.settings.biometrics.face.FaceSettingsKeyguardPreferenceController"/>
        <SwitchPreference
            android:key="security_settings_face_app"
            android:title="@string/security_settings_face_settings_use_face_for_apps"
            app:keywords="@string/keywords_face_unlock"
            app:controller="com.android.settings.biometrics.face.FaceSettingsAppPreferenceController"/>
    </PreferenceCategory>

    <PreferenceCategory
        android:key="security_settings_face_manage_category">
        <SwitchPreference
            android:key="security_settings_face_require_attention"
            android:title="@string/security_settings_face_settings_require_attention"
            app:keywords="@string/keywords_face_unlock"
            app:controller="com.android.settings.biometrics.face.FaceSettingsAttentionPreferenceController"/>

        <Preference
            android:key="security_settings_face_improve"
            android:title="@string/security_settings_face_settings_improve_face">
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
        if (mFaceManager == null) {
            return 0;
        }
        return mFaceManager.preEnroll();
        return mFaceManager.generateChallenge();
    }

    @Override
+63 −4
Original line number Diff line number Diff line
@@ -16,11 +16,16 @@

package com.android.settings.biometrics.face;

import static android.app.Activity.RESULT_OK;

import static com.android.settings.biometrics.BiometricEnrollBase.CONFIRM_REQUEST;
import static com.android.settings.biometrics.BiometricEnrollBase.RESULT_FINISHED;

import android.content.Context;
import android.content.Intent;
import android.hardware.face.FaceManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import android.util.Log;

@@ -30,6 +35,7 @@ import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.VideoPreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
@@ -47,7 +53,11 @@ public class FaceSettings extends DashboardFragment {
    private static final String TAG = "FaceSettings";
    private static final String KEY_LAUNCHED_CONFIRM = "key_launched_confirm";

    private FaceManager mFaceManager;
    private int mUserId;
    private boolean mLaunchedConfirm;
    private byte[] mToken;
    private FaceSettingsAttentionPreferenceController mAttentionController;

    public static boolean isAvailable(Context context) {
        FaceManager manager = Utils.getFaceManagerOrNull(context);
@@ -79,31 +89,80 @@ public class FaceSettings extends DashboardFragment {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mFaceManager = getPrefContext().getSystemService(FaceManager.class);
        mUserId = getActivity().getIntent().getIntExtra(
                Intent.EXTRA_USER_ID, UserHandle.myUserId());

        if (savedInstanceState != null) {
            mLaunchedConfirm = savedInstanceState.getBoolean(KEY_LAUNCHED_CONFIRM, false);
        }

        if (!mLaunchedConfirm) {
            final long challenge = mFaceManager.generateChallenge();
            ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(getActivity(), this);
            if (!helper.launchConfirmationActivity(CONFIRM_REQUEST,
                    getString(R.string.security_settings_face_preference_title))) {
                    getString(R.string.security_settings_face_preference_title),
                    null, null, challenge, mUserId)) {
                Log.e(TAG, "Password not set");
                finish();
            }
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CONFIRM_REQUEST) {
            if (resultCode == RESULT_FINISHED || resultCode == RESULT_OK) {
                // The pin/pattern/password was set.
                if (data != null) {
                    mToken = data.getByteArrayExtra(
                            ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
                    if (mToken != null) {
                        mAttentionController.setToken(mToken);
                    }
                }
            }
        }

        if (mToken == null) {
            // Didn't get an authentication, finishing
            getActivity().finish();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (getActivity().isFinishing()) {
            final int result = mFaceManager.revokeChallenge();
            if (result < 0) {
                Log.w(TAG, "revokeChallenge failed, result: " + result);
            }
        }
    }

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
        return buildPreferenceControllers(context, getSettingsLifecycle());
        final List<AbstractPreferenceController> controllers =
                buildPreferenceControllers(context, getSettingsLifecycle());
        for (AbstractPreferenceController controller : controllers) {
            if (controller instanceof FaceSettingsAttentionPreferenceController) {
                mAttentionController = (FaceSettingsAttentionPreferenceController) controller;
                break;
            }
        }

        return controllers;
    }

    private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
            Lifecycle lifecycle) {
        final List<AbstractPreferenceController> controllers = new ArrayList<>();
        controllers.add(new FaceSettingsVideoPreferenceController(context));
        controllers.add(new FaceSettingsImprovePreferenceController(context));
        controllers.add(new FaceSettingsUnlockPreferenceController(context));
        controllers.add(new FaceSettingsKeyguardPreferenceController(context));
        controllers.add(new FaceSettingsAppPreferenceController(context));
        controllers.add(new FaceSettingsAttentionPreferenceController(context));
        controllers.add(new FaceSettingsRemoveButtonPreferenceController(context));
        controllers.add(new FaceSettingsFooterPreferenceController(context));
        return controllers;
+65 −0
Original line number Diff line number Diff line
@@ -16,21 +16,46 @@

package com.android.settings.biometrics.face;

import static android.provider.Settings.Secure.FACE_UNLOCK_APP_ENABLED;

import android.content.Context;
import android.provider.Settings;

import com.android.settings.core.TogglePreferenceController;

import com.android.settings.core.BasePreferenceController;
/**
 * Preference controller for Face settings page controlling the ability to use
 * Face authentication in apps (through BiometricPrompt).
 */
public class FaceSettingsAppPreferenceController extends TogglePreferenceController {

public class FaceSettingsVideoPreferenceController extends BasePreferenceController {
    private static final String KEY = "security_settings_face_app";

    private static final String PREF_KEY_VIDEO = "security_settings_face_video";
    private static final int ON = 1;
    private static final int OFF = 0;
    private static final int DEFAULT = ON;  // face unlock is enabled for BiometricPrompt by default

    public FaceSettingsVideoPreferenceController(Context context,
            String preferenceKey) {
    public FaceSettingsAppPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
    }

    public FaceSettingsVideoPreferenceController(Context context) {
        this(context, PREF_KEY_VIDEO);
    public FaceSettingsAppPreferenceController(Context context) {
        this(context, KEY);
    }

    @Override
    public boolean isChecked() {
        if (!FaceSettings.isAvailable(mContext)) {
            return false;
        }
        return Settings.Secure.getInt(
                mContext.getContentResolver(), FACE_UNLOCK_APP_ENABLED, DEFAULT) == ON;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        return Settings.Secure.putInt(mContext.getContentResolver(), FACE_UNLOCK_APP_ENABLED,
                isChecked ? ON : OFF);
    }

    @Override
Loading