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 android.provider.Settings.Secure.FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION; 20 21 import android.content.Context; 22 import android.hardware.face.FaceManager; 23 import android.provider.Settings; 24 25 import androidx.preference.Preference; 26 27 import com.android.settings.Utils; 28 29 /** 30 * Preference controller giving the user an option to always require confirmation. 31 */ 32 public class FaceSettingsConfirmPreferenceController extends FaceSettingsPreferenceController { 33 34 static final String KEY = "security_settings_face_require_confirmation"; 35 36 private static final int ON = 1; 37 private static final int OFF = 0; 38 private static final int DEFAULT = OFF; 39 40 private FaceManager mFaceManager; 41 FaceSettingsConfirmPreferenceController(Context context)42 public FaceSettingsConfirmPreferenceController(Context context) { 43 this(context, KEY); 44 } 45 FaceSettingsConfirmPreferenceController(Context context, String preferenceKey)46 public FaceSettingsConfirmPreferenceController(Context context, 47 String preferenceKey) { 48 super(context, preferenceKey); 49 mFaceManager = Utils.getFaceManagerOrNull(context); 50 } 51 52 @Override isChecked()53 public boolean isChecked() { 54 return Settings.Secure.getIntForUser(mContext.getContentResolver(), 55 FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, DEFAULT, getUserId()) == ON; 56 } 57 58 @Override setChecked(boolean isChecked)59 public boolean setChecked(boolean isChecked) { 60 return Settings.Secure.putIntForUser(mContext.getContentResolver(), 61 FACE_UNLOCK_ALWAYS_REQUIRE_CONFIRMATION, isChecked ? ON : OFF, getUserId()); 62 } 63 64 @Override updateState(Preference preference)65 public void updateState(Preference preference) { 66 super.updateState(preference); 67 if (!FaceSettings.isFaceHardwareDetected(mContext)) { 68 preference.setEnabled(false); 69 } else if (!mFaceManager.hasEnrolledTemplates(getUserId())) { 70 preference.setEnabled(false); 71 } else { 72 preference.setEnabled(true); 73 } 74 } 75 76 @Override getAvailabilityStatus()77 public int getAvailabilityStatus() { 78 return AVAILABLE; 79 } 80 } 81