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.os.UserHandle;
21 
22 import androidx.lifecycle.Lifecycle;
23 import androidx.preference.Preference;
24 
25 import com.android.settings.R;
26 
27 public class FaceProfileStatusPreferenceController extends FaceStatusPreferenceController {
28 
29     private static final String KEY_FACE_SETTINGS = "face_settings_profile";
30 
FaceProfileStatusPreferenceController(Context context)31     public FaceProfileStatusPreferenceController(Context context) {
32         super(context, KEY_FACE_SETTINGS);
33     }
34 
FaceProfileStatusPreferenceController(Context context, String key)35     public FaceProfileStatusPreferenceController(Context context, String key) {
36         super(context, key);
37     }
38 
FaceProfileStatusPreferenceController(Context context, Lifecycle lifecycle)39     public FaceProfileStatusPreferenceController(Context context, Lifecycle lifecycle) {
40         super(context, KEY_FACE_SETTINGS, lifecycle);
41     }
42 
FaceProfileStatusPreferenceController(Context context, String key, Lifecycle lifecycle)43     public FaceProfileStatusPreferenceController(Context context, String key, Lifecycle lifecycle) {
44         super(context, key, lifecycle);
45     }
46 
47     @Override
getAvailabilityStatus()48     public int getAvailabilityStatus() {
49         // Check if Face for Profile is available.
50         final int isAvailable = super.getAvailabilityStatus();
51         if (isAvailable != AVAILABLE) {
52             return isAvailable;
53         }
54         // Make the profile unsearchable so the user preference controller gets highlighted
55         // when searched for.
56         return AVAILABLE_UNSEARCHABLE;
57     }
58 
59     @Override
isUserSupported()60     protected boolean isUserSupported() {
61         return mProfileChallengeUserId != UserHandle.USER_NULL
62                 && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId);
63     }
64 
65     @Override
getUserId()66     protected int getUserId() {
67         return mProfileChallengeUserId;
68     }
69 
70     @Override
updateState(Preference preference)71     public void updateState(Preference preference) {
72         super.updateState(preference);
73         preference.setTitle(mContext.getResources().getString(
74                 R.string.security_settings_face_profile_preference_title));
75     }
76 }
77