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 android.content.Context;
20 import android.content.Intent;
21 import android.view.View;
22 import android.widget.Button;
23 
24 import androidx.preference.Preference;
25 
26 import com.android.settings.R;
27 import com.android.settings.SettingsActivity;
28 import com.android.settings.core.BasePreferenceController;
29 import com.android.settings.password.ChooseLockSettingsHelper;
30 import com.android.settingslib.widget.LayoutPreference;
31 
32 /**
33  * Preference controller that allows a user to enroll their face.
34  */
35 public class FaceSettingsEnrollButtonPreferenceController extends BasePreferenceController
36         implements View.OnClickListener {
37 
38     private static final String TAG = "FaceSettings/Remove";
39     static final String KEY = "security_settings_face_enroll_faces_container";
40 
41     private int mUserId;
42     private byte[] mToken;
43     private SettingsActivity mActivity;
44     private Button mButton;
45     private boolean mIsClicked;
46 
FaceSettingsEnrollButtonPreferenceController(Context context)47     public FaceSettingsEnrollButtonPreferenceController(Context context) {
48         this(context, KEY);
49     }
50 
FaceSettingsEnrollButtonPreferenceController(Context context, String preferenceKey)51     public FaceSettingsEnrollButtonPreferenceController(Context context,
52             String preferenceKey) {
53         super(context, preferenceKey);
54     }
55 
56     @Override
updateState(Preference preference)57     public void updateState(Preference preference) {
58         super.updateState(preference);
59 
60         mButton = ((LayoutPreference) preference)
61                 .findViewById(R.id.security_settings_face_settings_enroll_button);
62         mButton.setOnClickListener(this);
63     }
64 
65     @Override
onClick(View v)66     public void onClick(View v) {
67         mIsClicked = true;
68         final Intent intent = new Intent();
69         intent.setClassName("com.android.settings", FaceEnrollIntroduction.class.getName());
70         intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
71         intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
72         mContext.startActivity(intent);
73     }
74 
75     @Override
getAvailabilityStatus()76     public int getAvailabilityStatus() {
77         return AVAILABLE;
78     }
79 
setUserId(int userId)80     public void setUserId(int userId) {
81         mUserId = userId;
82     }
83 
setToken(byte[] token)84     public void setToken(byte[] token) {
85         mToken = token;
86     }
87 
88     // Return the click state, then clear its state.
isClicked()89     public boolean isClicked() {
90         final boolean wasClicked = mIsClicked;
91         mIsClicked = false;
92         return wasClicked;
93     }
94 
setActivity(SettingsActivity activity)95     public void setActivity(SettingsActivity activity) {
96         mActivity = activity;
97     }
98 }
99