1 /*
2  * Copyright (C) 2018 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.privacy;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.provider.SearchIndexableResource;
22 import android.view.View;
23 
24 import androidx.annotation.VisibleForTesting;
25 
26 import com.android.settings.R;
27 import com.android.settings.dashboard.DashboardFragment;
28 import com.android.settings.notification.LockScreenNotificationPreferenceController;
29 import com.android.settings.search.BaseSearchIndexProvider;
30 import com.android.settingslib.core.AbstractPreferenceController;
31 import com.android.settingslib.core.lifecycle.Lifecycle;
32 import com.android.settingslib.search.SearchIndexable;
33 
34 import java.util.ArrayList;
35 import java.util.List;
36 
37 @SearchIndexable
38 public class PrivacyDashboardFragment extends DashboardFragment {
39     private static final String TAG = "PrivacyDashboardFrag";
40     private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "privacy_lock_screen_notifications";
41     private static final String KEY_WORK_PROFILE_CATEGORY =
42             "privacy_work_profile_notifications_category";
43     private static final String KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS =
44             "privacy_lock_screen_work_profile_notifications";
45 
46     @VisibleForTesting
47     View mProgressHeader;
48     @VisibleForTesting
49     View mProgressAnimation;
50 
51     @Override
getMetricsCategory()52     public int getMetricsCategory() {
53         return SettingsEnums.TOP_LEVEL_PRIVACY;
54     }
55 
56     @Override
getLogTag()57     protected String getLogTag() {
58         return TAG;
59     }
60 
61     @Override
getPreferenceScreenResId()62     protected int getPreferenceScreenResId() {
63         return R.xml.privacy_dashboard_settings;
64     }
65 
66     @Override
getHelpResource()67     public int getHelpResource() {
68         return R.string.help_url_privacy_dashboard;
69     }
70 
71     @Override
createPreferenceControllers(Context context)72     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
73         return buildPreferenceControllers(context, getSettingsLifecycle());
74     }
75 
buildPreferenceControllers( Context context, Lifecycle lifecycle)76     private static List<AbstractPreferenceController> buildPreferenceControllers(
77             Context context, Lifecycle lifecycle) {
78         final List<AbstractPreferenceController> controllers = new ArrayList<>();
79         final LockScreenNotificationPreferenceController notificationController =
80                 new LockScreenNotificationPreferenceController(context,
81                         KEY_LOCK_SCREEN_NOTIFICATIONS,
82                         KEY_WORK_PROFILE_CATEGORY,
83                         KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS);
84         if (lifecycle != null) {
85             lifecycle.addObserver(notificationController);
86         }
87         controllers.add(notificationController);
88 
89         return controllers;
90 
91     }
92 
93     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
94             new BaseSearchIndexProvider() {
95                 @Override
96                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
97                         boolean enabled) {
98                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
99 
100                     final SearchIndexableResource sir = new SearchIndexableResource(context);
101                     sir.xmlResId = R.xml.privacy_dashboard_settings;
102                     result.add(sir);
103                     return result;
104                 }
105 
106                 @Override
107                 public List<AbstractPreferenceController> createPreferenceControllers(
108                         Context context) {
109                     return buildPreferenceControllers(context, null);
110                 }
111             };
112 }
113