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