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