• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16 
17 package com.android.settings.biometrics.face;
18 
19 import static com.android.settings.Utils.SETTINGS_PACKAGE_NAME;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 import android.view.View;
24 import android.widget.Button;
25 
26 import androidx.preference.Preference;
27 
28 import com.android.settings.R;
29 import com.android.settings.core.BasePreferenceController;
30 import com.android.settings.password.ChooseLockSettingsHelper;
31 import com.android.settingslib.widget.LayoutPreference;
32 
33 import com.google.android.setupdesign.util.ButtonStyler;
34 import com.google.android.setupdesign.util.PartnerStyleHelper;
35 
36 /**
37  * Preference controller that allows a user to enroll their face.
38  */
39 public class FaceSettingsEnrollButtonPreferenceController extends BasePreferenceController
40         implements View.OnClickListener {
41 
42     private static final String TAG = "FaceSettings/Remove";
43     static final String KEY = "security_settings_face_enroll_faces_container";
44 
45     private final Context mContext;
46 
47     private int mUserId;
48     private byte[] mToken;
49     private Button mButton;
50     private boolean mIsClicked;
51     private Listener mListener;
52 
FaceSettingsEnrollButtonPreferenceController(Context context)53     public FaceSettingsEnrollButtonPreferenceController(Context context) {
54         this(context, KEY);
55     }
56 
FaceSettingsEnrollButtonPreferenceController(Context context, String preferenceKey)57     public FaceSettingsEnrollButtonPreferenceController(Context context, String preferenceKey) {
58         super(context, preferenceKey);
59         mContext = context;
60     }
61 
62     @Override
updateState(Preference preference)63     public void updateState(Preference preference) {
64         super.updateState(preference);
65 
66         mButton = ((LayoutPreference) preference).findViewById(
67                 R.id.security_settings_face_settings_enroll_button);
68 
69         if (PartnerStyleHelper.shouldApplyPartnerResource(mButton)) {
70             ButtonStyler.applyPartnerCustomizationPrimaryButtonStyle(mContext, mButton);
71         }
72 
73         mButton.setOnClickListener(this);
74     }
75 
76     @Override
onClick(View v)77     public void onClick(View v) {
78         // If it's in multi window mode, do not start the introduction intent.
79         if (mListener != null && mListener.onShowSplitScreenDialog()) {
80             return;
81         }
82 
83         mIsClicked = true;
84         final Intent intent = new Intent();
85         intent.setClassName(SETTINGS_PACKAGE_NAME, FaceEnrollIntroduction.class.getName());
86         intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
87         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
88         if (mListener != null) {
89             mListener.onStartEnrolling(intent);
90         } else {
91             mContext.startActivity(intent);
92         }
93     }
94 
95     @Override
getAvailabilityStatus()96     public int getAvailabilityStatus() {
97         return AVAILABLE;
98     }
99 
setUserId(int userId)100     public void setUserId(int userId) {
101         mUserId = userId;
102     }
103 
setToken(byte[] token)104     public void setToken(byte[] token) {
105         mToken = token;
106     }
107 
108     // Return the click state, then clear its state.
isClicked()109     public boolean isClicked() {
110         final boolean wasClicked = mIsClicked;
111         mIsClicked = false;
112         return wasClicked;
113     }
114 
setListener(Listener listener)115     public void setListener(Listener listener) {
116         mListener = listener;
117     }
118 
119     /**
120      * Interface for registering callbacks related to the face enroll preference button.
121      */
122     public interface Listener {
123         /**
124          * Called to check whether to show dialog in split screen mode
125          * @return Whether split screen warning dialog shown.
126          */
onShowSplitScreenDialog()127         boolean onShowSplitScreenDialog();
128 
129         /**
130          * Called when the user has indicated an intent to begin enrolling a new face.
131          * @param intent The Intent that should be used to launch face enrollment.
132          */
onStartEnrolling(Intent intent)133         void onStartEnrolling(Intent intent);
134     }
135 }
136