1 /*
2  * Copyright (C) 2016 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.enterprise;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.provider.SearchIndexableResource;
22 
23 import com.android.settings.R;
24 import com.android.settings.dashboard.DashboardFragment;
25 import com.android.settings.overlay.FeatureFactory;
26 import com.android.settings.search.BaseSearchIndexProvider;
27 import com.android.settings.widget.PreferenceCategoryController;
28 import com.android.settingslib.core.AbstractPreferenceController;
29 import com.android.settingslib.search.SearchIndexable;
30 
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.List;
34 
35 @SearchIndexable
36 public class EnterprisePrivacySettings extends DashboardFragment {
37 
38     static final String TAG = "EnterprisePrivacySettings";
39 
40     @Override
getMetricsCategory()41     public int getMetricsCategory() {
42         return SettingsEnums.ENTERPRISE_PRIVACY_SETTINGS;
43     }
44 
45     @Override
getLogTag()46     protected String getLogTag() {
47         return TAG;
48     }
49 
50     @Override
getPreferenceScreenResId()51     protected int getPreferenceScreenResId() {
52         return R.xml.enterprise_privacy_settings;
53     }
54 
55     @Override
createPreferenceControllers(Context context)56     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
57         return buildPreferenceControllers(context, true /* async */);
58     }
59 
buildPreferenceControllers(Context context, boolean async)60     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
61             boolean async) {
62         final List<AbstractPreferenceController> controllers = new ArrayList<>();
63         controllers.add(new NetworkLogsPreferenceController(context));
64         controllers.add(new BugReportsPreferenceController(context));
65         controllers.add(new SecurityLogsPreferenceController(context));
66         final List<AbstractPreferenceController> exposureChangesCategoryControllers =
67                 new ArrayList<>();
68         exposureChangesCategoryControllers.add(new EnterpriseInstalledPackagesPreferenceController(
69                 context, async));
70         exposureChangesCategoryControllers.add(
71                 new AdminGrantedLocationPermissionsPreferenceController(context, async));
72         exposureChangesCategoryControllers.add(
73                 new AdminGrantedMicrophonePermissionPreferenceController(context, async));
74         exposureChangesCategoryControllers.add(new AdminGrantedCameraPermissionPreferenceController(
75                 context, async));
76         exposureChangesCategoryControllers.add(new EnterpriseSetDefaultAppsPreferenceController(
77                 context));
78         exposureChangesCategoryControllers.add(new AlwaysOnVpnCurrentUserPreferenceController(
79                 context));
80         exposureChangesCategoryControllers.add(new AlwaysOnVpnManagedProfilePreferenceController(
81                 context));
82         exposureChangesCategoryControllers.add(new ImePreferenceController(context));
83         exposureChangesCategoryControllers.add(new GlobalHttpProxyPreferenceController(context));
84         exposureChangesCategoryControllers.add(new CaCertsCurrentUserPreferenceController(context));
85         exposureChangesCategoryControllers.add(new CaCertsManagedProfilePreferenceController(
86                 context));
87         controllers.addAll(exposureChangesCategoryControllers);
88         controllers.add(new PreferenceCategoryController(context, "exposure_changes_category")
89                 .setChildren(exposureChangesCategoryControllers));
90         controllers.add(new FailedPasswordWipeCurrentUserPreferenceController(context));
91         controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(context));
92         return controllers;
93     }
94 
isPageEnabled(Context context)95     public static boolean isPageEnabled(Context context) {
96         return FeatureFactory.getFactory(context)
97                 .getEnterprisePrivacyFeatureProvider(context)
98                 .hasDeviceOwner();
99     }
100 
101     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
102             new BaseSearchIndexProvider() {
103                 @Override
104                 protected boolean isPageSearchEnabled(Context context) {
105                     return isPageEnabled(context);
106                 }
107 
108                 @Override
109                 public List<SearchIndexableResource> getXmlResourcesToIndex(
110                         Context context, boolean enabled) {
111                     final SearchIndexableResource sir = new SearchIndexableResource(context);
112                     sir.xmlResId = R.xml.enterprise_privacy_settings;
113                     return Arrays.asList(sir);
114                 }
115 
116                 @Override
117                 public List<AbstractPreferenceController> createPreferenceControllers(
118                         Context context) {
119                     return buildPreferenceControllers(context, false /* async */);
120                 }
121             };
122 }
123