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.SettingsActivity; 30 import com.android.settings.core.BasePreferenceController; 31 import com.android.settings.password.ChooseLockSettingsHelper; 32 import com.android.settingslib.widget.LayoutPreference; 33 34 import com.google.android.setupdesign.util.ButtonStyler; 35 import com.google.android.setupdesign.util.PartnerStyleHelper; 36 37 /** 38 * Preference controller that allows a user to enroll their face. 39 */ 40 public class FaceSettingsEnrollButtonPreferenceController extends BasePreferenceController 41 implements View.OnClickListener { 42 43 private static final String TAG = "FaceSettings/Remove"; 44 static final String KEY = "security_settings_face_enroll_faces_container"; 45 46 private final Context mContext; 47 48 private int mUserId; 49 private byte[] mToken; 50 private SettingsActivity mActivity; 51 private Button mButton; 52 private boolean mIsClicked; 53 private Listener mListener; 54 FaceSettingsEnrollButtonPreferenceController(Context context)55 public FaceSettingsEnrollButtonPreferenceController(Context context) { 56 this(context, KEY); 57 } 58 FaceSettingsEnrollButtonPreferenceController(Context context, String preferenceKey)59 public FaceSettingsEnrollButtonPreferenceController(Context context, String preferenceKey) { 60 super(context, preferenceKey); 61 mContext = context; 62 } 63 64 @Override updateState(Preference preference)65 public void updateState(Preference preference) { 66 super.updateState(preference); 67 68 mButton = ((LayoutPreference) preference).findViewById( 69 R.id.security_settings_face_settings_enroll_button); 70 71 if (PartnerStyleHelper.shouldApplyPartnerResource(mButton)) { 72 ButtonStyler.applyPartnerCustomizationPrimaryButtonStyle(mContext, mButton); 73 } 74 75 mButton.setOnClickListener(this); 76 } 77 78 @Override onClick(View v)79 public void onClick(View v) { 80 mIsClicked = true; 81 final Intent intent = new Intent(); 82 intent.setClassName(SETTINGS_PACKAGE_NAME, FaceEnrollIntroduction.class.getName()); 83 intent.putExtra(Intent.EXTRA_USER_ID, mUserId); 84 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken); 85 if (mListener != null) { 86 mListener.onStartEnrolling(intent); 87 } else { 88 mContext.startActivity(intent); 89 } 90 } 91 92 @Override getAvailabilityStatus()93 public int getAvailabilityStatus() { 94 return AVAILABLE; 95 } 96 setUserId(int userId)97 public void setUserId(int userId) { 98 mUserId = userId; 99 } 100 setToken(byte[] token)101 public void setToken(byte[] token) { 102 mToken = token; 103 } 104 105 // Return the click state, then clear its state. isClicked()106 public boolean isClicked() { 107 final boolean wasClicked = mIsClicked; 108 mIsClicked = false; 109 return wasClicked; 110 } 111 setActivity(SettingsActivity activity)112 public void setActivity(SettingsActivity activity) { 113 mActivity = activity; 114 } 115 setListener(Listener listener)116 public void setListener(Listener listener) { 117 mListener = listener; 118 } 119 120 /** 121 * Interface for registering callbacks related to the face enroll preference button. 122 */ 123 public interface Listener { 124 /** 125 * Called when the user has indicated an intent to begin enrolling a new face. 126 * @param intent The Intent that should be used to launch face enrollment. 127 */ onStartEnrolling(Intent intent)128 void onStartEnrolling(Intent intent); 129 } 130 } 131