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

Commit 0dfc2769 authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Stay in face settings unless the user explicitly backs out

Bug: 130898604

Test: Builds
Change-Id: I7159c3a6259d298f78b8328b2c6974ba46fb56f9
parent 5c2842c1
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2019 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
  -->
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/security_settings_face_settings_enroll_button"
        android:layout_marginStart="@dimen/screen_margin_sides"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:text="@string/security_settings_face_settings_enroll"/>

</LinearLayout>
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -948,6 +948,8 @@
    <string name="security_settings_face_settings_require_confirmation_details">When authenticating in apps, always require confirmation</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>
    <!-- Button text in face settings which lets the user enroll their face [CHAR LIMIT=40] -->
    <string name="security_settings_face_settings_enroll">Set up face authentication</string>
    <!-- Text shown in face settings explaining what your face can be used for. [CHAR LIMIT=NONE] -->
    <string name="security_settings_face_settings_footer">Your face can be used to unlock your device and access apps.
        <annotation id="url">Learn more</annotation></string>
+5 −0
Original line number Diff line number Diff line
@@ -61,6 +61,11 @@
            android:key="security_settings_face_delete_faces_container"
            android:selectable="false"
            android:layout="@layout/face_remove_button" />

        <com.android.settingslib.widget.LayoutPreference
            android:key="security_settings_face_enroll_faces_container"
            android:selectable="false"
            android:layout="@layout/face_enroll_button " />
    </PreferenceCategory>

    <PreferenceCategory
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ public abstract class BiometricEnrollBase extends InstrumentedActivity {
    public static final int BIOMETRIC_FIND_SENSOR_REQUEST = 2;
    public static final int LEARN_MORE_REQUEST = 3;
    public static final int CONFIRM_REQUEST = 4;
    public static final int ENROLLING = 5;
    public static final int ENROLL_REQUEST = 5;

    protected boolean mLaunchedConfirmLock;
    protected byte[] mToken;
+37 −2
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.util.Log;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
@@ -60,12 +62,23 @@ public class FaceSettings extends DashboardFragment {
    private byte[] mToken;
    private FaceSettingsAttentionPreferenceController mAttentionController;
    private FaceSettingsRemoveButtonPreferenceController mRemoveController;
    private FaceSettingsEnrollButtonPreferenceController mEnrollController;
    private List<AbstractPreferenceController> mControllers;

    private List<Preference> mTogglePreferences;
    private Preference mRemoveButton;
    private Preference mEnrollButton;

    private final FaceSettingsRemoveButtonPreferenceController.Listener mRemovalListener = () -> {
        if (getActivity() != null) {
            getActivity().finish();

        // Disable the toggles until the user re-enrolls
        for (Preference preference : mTogglePreferences) {
            preference.setEnabled(false);
        }

        // Hide the "remove" button and show the "set up face authentication" button.
        mRemoveButton.setVisible(false);
        mEnrollButton.setVisible(true);
    };

    public static boolean isAvailable(Context context) {
@@ -103,10 +116,22 @@ public class FaceSettings extends DashboardFragment {
        mUserId = getActivity().getIntent().getIntExtra(
                Intent.EXTRA_USER_ID, UserHandle.myUserId());

        Preference keyguardPref = findPreference(FaceSettingsKeyguardPreferenceController.KEY);
        Preference appPref = findPreference(FaceSettingsAppPreferenceController.KEY);
        Preference attentionPref = findPreference(FaceSettingsAttentionPreferenceController.KEY);
        Preference confirmPref = findPreference(FaceSettingsConfirmPreferenceController.KEY);
        mTogglePreferences = new ArrayList<>(
                Arrays.asList(keyguardPref, appPref, attentionPref, confirmPref));

        mRemoveButton = findPreference(FaceSettingsRemoveButtonPreferenceController.KEY);
        mEnrollButton = findPreference(FaceSettingsEnrollButtonPreferenceController.KEY);

        // There is no better way to do this :/
        for (AbstractPreferenceController controller : mControllers) {
            if (controller instanceof  FaceSettingsPreferenceController) {
                ((FaceSettingsPreferenceController) controller).setUserId(mUserId);
            } else if (controller instanceof FaceSettingsEnrollButtonPreferenceController) {
                ((FaceSettingsEnrollButtonPreferenceController) controller).setUserId(mUserId);
            }
        }
        mRemoveController.setUserId(mUserId);
@@ -137,7 +162,12 @@ public class FaceSettings extends DashboardFragment {
        super.onResume();
        if (mToken != null) {
            mAttentionController.setToken(mToken);
            mEnrollController.setToken(mToken);
        }

        final boolean hasEnrolled = mFaceManager.hasEnrolledTemplates(mUserId);
        mEnrollButton.setVisible(!hasEnrolled);
        mRemoveButton.setVisible(hasEnrolled);
    }

    @Override
@@ -152,6 +182,7 @@ public class FaceSettings extends DashboardFragment {
                            ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN);
                    if (mToken != null) {
                        mAttentionController.setToken(mToken);
                        mEnrollController.setToken(mToken);
                    }
                }
            }
@@ -188,6 +219,9 @@ public class FaceSettings extends DashboardFragment {
                mRemoveController = (FaceSettingsRemoveButtonPreferenceController) controller;
                mRemoveController.setListener(mRemovalListener);
                mRemoveController.setActivity((SettingsActivity) getActivity());
            } else if (controller instanceof FaceSettingsEnrollButtonPreferenceController) {
                mEnrollController = (FaceSettingsEnrollButtonPreferenceController) controller;
                mEnrollController.setActivity((SettingsActivity) getActivity());
            }
        }

@@ -204,6 +238,7 @@ public class FaceSettings extends DashboardFragment {
        controllers.add(new FaceSettingsRemoveButtonPreferenceController(context));
        controllers.add(new FaceSettingsFooterPreferenceController(context));
        controllers.add(new FaceSettingsConfirmPreferenceController(context));
        controllers.add(new FaceSettingsEnrollButtonPreferenceController(context));
        return controllers;
    }

Loading