1 /*
2  * Copyright (C) 2023 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.privatespace.onelock;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 
24 import androidx.annotation.Nullable;
25 
26 import com.android.settings.R;
27 import com.android.settings.Utils;
28 import com.android.settings.dashboard.DashboardFragment;
29 import com.android.settings.privatespace.PrivateSpaceMaintainer;
30 import com.android.settingslib.core.AbstractPreferenceController;
31 
32 import java.util.ArrayList;
33 import java.util.List;
34 
35 public class UseOneLockSettingsFragment extends DashboardFragment {
36     private static final String TAG = "UseOneLockSettings";
37     public static final int UNIFY_PRIVATE_LOCK_WITH_DEVICE_REQUEST = 1;
38     public static final int UNUNIFY_PRIVATE_LOCK_FROM_DEVICE_REQUEST = 2;
39 
40     @Override
onCreate(Bundle icicle)41     public void onCreate(Bundle icicle) {
42         if (android.os.Flags.allowPrivateProfile()
43                 && android.multiuser.Flags.enablePrivateSpaceFeatures()) {
44             super.onCreate(icicle);
45         }
46     }
47 
48     @Override
onStart()49     public void onStart() {
50         super.onStart();
51         if (PrivateSpaceMaintainer.getInstance(getContext()).isPrivateSpaceLocked()) {
52             finish();
53         }
54     }
55 
56     @Override
getMetricsCategory()57     public int getMetricsCategory() {
58         return SettingsEnums.PRIVATE_SPACE_SETTINGS;
59     }
60 
61     @Override
getPreferenceScreenResId()62     protected int getPreferenceScreenResId() {
63         return R.xml.privatespace_one_lock;
64     }
65 
66     @Override
getLogTag()67     protected String getLogTag() {
68         return TAG;
69     }
70 
71     @Override
createPreferenceControllers(Context context)72     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
73         final List<AbstractPreferenceController> controllers = new ArrayList<>();
74         controllers.add(new UseOneLockControllerSwitch(context, this));
75         controllers.add(new PrivateSpaceLockController(context, this));
76         boolean isFaceAuthAllowed = Utils.isFaceNotConvenienceBiometric(context);
77         if (Utils.isMultipleBiometricsSupported(context) && isFaceAuthAllowed) {
78             controllers.add(new FaceFingerprintUnlockController(context, getSettingsLifecycle()));
79         } else if (Utils.hasFingerprintHardware(context)) {
80             controllers.add(
81                     new PrivateSpaceFingerprintPreferenceController(
82                             context, "private_space_biometrics", getSettingsLifecycle()));
83         } else if (Utils.hasFaceHardware(context) && isFaceAuthAllowed) {
84             controllers.add(
85                     new PrivateSpaceFacePreferenceController(
86                             context, "private_space_biometrics", getSettingsLifecycle()));
87         }
88         return controllers;
89     }
90 
91     @Override
onActivityResult(int requestCode, int resultCode, @Nullable Intent data)92     public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
93         if (use(UseOneLockControllerSwitch.class)
94                 .handleActivityResult(requestCode, resultCode, data)) {
95             return;
96         }
97         super.onActivityResult(requestCode, resultCode, data);
98     }
99 }
100