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.safetycenter;
18 
19 import static android.app.admin.DevicePolicyResources.Strings.Settings.CONNECTED_WORK_AND_PERSONAL_APPS_TITLE;
20 import static android.app.admin.DevicePolicyResources.Strings.Settings.FINGERPRINT_FOR_WORK;
21 import static android.app.admin.DevicePolicyResources.Strings.Settings.MANAGED_DEVICE_INFO;
22 import static android.app.admin.DevicePolicyResources.Strings.Settings.MANAGE_DEVICE_ADMIN_APPS;
23 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_LOCKED_NOTIFICATION_TITLE;
24 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_NOTIFICATIONS_SECTION_HEADER;
25 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_PRIVACY_POLICY_INFO;
26 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_PRIVACY_POLICY_INFO_SUMMARY;
27 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SECURITY_TITLE;
28 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_SET_UNLOCK_LAUNCH_PICKER_TITLE;
29 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_UNIFY_LOCKS_SUMMARY;
30 
31 import android.content.Context;
32 
33 import com.android.settings.R;
34 import com.android.settings.biometrics.combination.CombinedBiometricProfileStatusPreferenceController;
35 import com.android.settings.biometrics.face.FaceProfileStatusPreferenceController;
36 import com.android.settings.biometrics.fingerprint.FingerprintProfileStatusPreferenceController;
37 import com.android.settings.dashboard.DashboardFragment;
38 import com.android.settings.notification.LockScreenNotificationPreferenceController;
39 import com.android.settings.privacy.PrivacyDashboardFragment;
40 import com.android.settings.security.ChangeProfileScreenLockPreferenceController;
41 import com.android.settings.security.LockUnificationPreferenceController;
42 import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
43 import com.android.settings.widget.PreferenceCategoryController;
44 import com.android.settingslib.core.AbstractPreferenceController;
45 
46 import java.util.ArrayList;
47 import java.util.List;
48 
49 /** A class with helper method used in logic involving safety center. */
50 public final class SafetyCenterUtils {
51 
52     private static final String WORK_PROFILE_SECURITY_CATEGORY = "work_profile_category";
53     private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "privacy_lock_screen_notifications";
54     private static final String KEY_WORK_PROFILE_CATEGORY =
55             "privacy_work_profile_notifications_category";
56     private static final String KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS =
57             "privacy_lock_screen_work_profile_notifications";
58 
59     /**
60      * Returns preference controllers related to advanced security entries. This is used in {@link
61      * MoreSecurityPrivacyFragment} and {@link
62      * com.android.settings.security.SecurityAdvancedSettings}.
63      */
getControllersForAdvancedSecurity( Context context, com.android.settingslib.core.lifecycle.Lifecycle lifecycle, DashboardFragment host)64     public static List<AbstractPreferenceController> getControllersForAdvancedSecurity(
65             Context context,
66             com.android.settingslib.core.lifecycle.Lifecycle lifecycle,
67             DashboardFragment host) {
68         final List<AbstractPreferenceController> controllers = new ArrayList<>();
69         controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle));
70 
71         final List<AbstractPreferenceController> profileSecurityControllers = new ArrayList<>();
72         profileSecurityControllers.add(
73                 new ChangeProfileScreenLockPreferenceController(context, host));
74         profileSecurityControllers.add(new LockUnificationPreferenceController(context, host));
75         profileSecurityControllers.add(new FaceProfileStatusPreferenceController(
76                 context, lifecycle));
77         profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(
78                 context, lifecycle));
79         profileSecurityControllers
80                 .add(new CombinedBiometricProfileStatusPreferenceController(context, lifecycle));
81         controllers.add(new PreferenceCategoryController(context, WORK_PROFILE_SECURITY_CATEGORY)
82                 .setChildren(profileSecurityControllers));
83         controllers.addAll(profileSecurityControllers);
84         return controllers;
85     }
86 
87     /**
88      * Returns preference controllers for advanced privacy entries. This is used in {@link
89      * MoreSecurityPrivacyFragment} and {@link PrivacyDashboardFragment}.
90      */
getControllersForAdvancedPrivacy( Context context, com.android.settingslib.core.lifecycle.Lifecycle lifecycle)91     public static List<AbstractPreferenceController> getControllersForAdvancedPrivacy(
92             Context context, com.android.settingslib.core.lifecycle.Lifecycle lifecycle) {
93         final List<AbstractPreferenceController> controllers = new ArrayList<>();
94         final LockScreenNotificationPreferenceController notificationController =
95                 new LockScreenNotificationPreferenceController(
96                         context,
97                         KEY_LOCK_SCREEN_NOTIFICATIONS,
98                         KEY_WORK_PROFILE_CATEGORY,
99                         KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS);
100         if (lifecycle != null) {
101             lifecycle.addObserver(notificationController);
102         }
103         controllers.add(notificationController);
104         return controllers;
105     }
106 
107     /** Replaces relevant strings with their enterprise variants for the privacy entries. */
replaceEnterpriseStringsForPrivacyEntries( DashboardFragment dashboardFragment)108     public static void replaceEnterpriseStringsForPrivacyEntries(
109             DashboardFragment dashboardFragment) {
110         dashboardFragment.replaceEnterpriseStringTitle(
111                 "privacy_lock_screen_work_profile_notifications",
112                 WORK_PROFILE_LOCKED_NOTIFICATION_TITLE,
113                 R.string.locked_work_profile_notification_title);
114         dashboardFragment.replaceEnterpriseStringTitle(
115                 "interact_across_profiles_privacy",
116                 CONNECTED_WORK_AND_PERSONAL_APPS_TITLE,
117                 R.string.interact_across_profiles_title);
118         dashboardFragment.replaceEnterpriseStringTitle(
119                 "privacy_work_profile_notifications_category",
120                 WORK_PROFILE_NOTIFICATIONS_SECTION_HEADER,
121                 R.string.profile_section_header);
122         dashboardFragment.replaceEnterpriseStringTitle(
123                 "work_policy_info",
124                 WORK_PROFILE_PRIVACY_POLICY_INFO,
125                 R.string.work_policy_privacy_settings);
126         dashboardFragment.replaceEnterpriseStringSummary(
127                 "work_policy_info",
128                 WORK_PROFILE_PRIVACY_POLICY_INFO_SUMMARY,
129                 R.string.work_policy_privacy_settings_summary);
130     }
131 
132     /** Replaces relevant strings with their enterprise variants for the security entries. */
replaceEnterpriseStringsForSecurityEntries( DashboardFragment dashboardFragment)133     public static void replaceEnterpriseStringsForSecurityEntries(
134             DashboardFragment dashboardFragment) {
135         dashboardFragment.replaceEnterpriseStringTitle(
136                 "unlock_set_or_change_profile",
137                 WORK_PROFILE_SET_UNLOCK_LAUNCH_PICKER_TITLE,
138                 R.string.unlock_set_unlock_launch_picker_title_profile);
139         dashboardFragment.replaceEnterpriseStringSummary(
140                 "unification",
141                 WORK_PROFILE_UNIFY_LOCKS_SUMMARY,
142                 R.string.lock_settings_profile_unification_summary);
143         dashboardFragment.replaceEnterpriseStringTitle(
144                 "fingerprint_settings_profile",
145                 FINGERPRINT_FOR_WORK,
146                 R.string.security_settings_work_fingerprint_preference_title);
147         dashboardFragment.replaceEnterpriseStringTitle(
148                 "manage_device_admin", MANAGE_DEVICE_ADMIN_APPS, R.string.manage_device_admin);
149         dashboardFragment.replaceEnterpriseStringTitle(
150                 "security_category_profile",
151                 WORK_PROFILE_SECURITY_TITLE,
152                 R.string.lock_settings_profile_title);
153         dashboardFragment.replaceEnterpriseStringTitle(
154                 "enterprise_privacy", MANAGED_DEVICE_INFO, R.string.enterprise_privacy_settings);
155     }
156 
SafetyCenterUtils()157     private SafetyCenterUtils() {}
158 }
159