1 /*
2  * Copyright (C) 2021 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.tv.settings.enterprise;
18 
19 import android.content.Context;
20 import android.provider.SearchIndexableResource;
21 
22 import com.android.settingslib.core.AbstractPreferenceController;
23 import com.android.tv.settings.R;
24 
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.List;
28 
29 /** Privacy Settings preferences for an Enterprise device.
30  *
31  * Forked from:
32  * Settings/src/com/android/settings/enterprise/PrivacySettingsEnterprisePreference.java
33  */
34 public class PrivacySettingsEnterprisePreference implements PrivacySettingsPreference {
35     private static final String KEY_EXPOSURE_CHANGES_CATEGORY = "exposure_changes_category";
36 
37     private final Context mContext;
38 
PrivacySettingsEnterprisePreference(Context context)39     public PrivacySettingsEnterprisePreference(Context context) {
40         mContext = context.getApplicationContext();
41     }
42 
43     /**
44      * Returns the XML Res Id that is used for an Enterprise device in the Privacy Settings screen.
45      */
46     @Override
getPreferenceScreenResId()47     public int getPreferenceScreenResId() {
48         return R.xml.enterprise_privacy_settings;
49     }
50 
51     /**
52      * Returns the Enterprise XML resources to index for an Enterprise device.
53      */
54     @Override
getXmlResourcesToIndex()55     public List<SearchIndexableResource> getXmlResourcesToIndex() {
56         final SearchIndexableResource sir = new SearchIndexableResource(mContext);
57         sir.xmlResId = getPreferenceScreenResId();
58         return Collections.singletonList(sir);
59     }
60 
61     /**
62      * Returns the preference controllers used to populate the privacy preferences in the Privacy
63      * Settings screen for Enterprise devices.
64      */
65     @Override
createPreferenceControllers(boolean async)66     public List<AbstractPreferenceController> createPreferenceControllers(boolean async) {
67         final List<AbstractPreferenceController> controllers = new ArrayList<>();
68         controllers.add(new NetworkLogsPreferenceController(mContext));
69         controllers.add(new BugReportsPreferenceController(mContext));
70         controllers.add(new SecurityLogsPreferenceController(mContext));
71         final List<AbstractPreferenceController> exposureChangesCategoryControllers =
72                 new ArrayList<>();
73         exposureChangesCategoryControllers.add(new EnterpriseInstalledPackagesPreferenceController(
74                 mContext, async));
75         exposureChangesCategoryControllers.add(
76                 new AdminGrantedLocationPermissionsPreferenceController(mContext, async));
77         exposureChangesCategoryControllers.add(
78                 new AdminGrantedMicrophonePermissionPreferenceController(mContext, async));
79         exposureChangesCategoryControllers.add(new AdminGrantedCameraPermissionPreferenceController(
80                 mContext, async));
81         exposureChangesCategoryControllers.add(new EnterpriseSetDefaultAppsPreferenceController(
82                 mContext));
83         exposureChangesCategoryControllers.add(new AlwaysOnVpnCurrentUserPreferenceController(
84                 mContext));
85         exposureChangesCategoryControllers.add(new AlwaysOnVpnManagedProfilePreferenceController(
86                 mContext));
87         exposureChangesCategoryControllers.add(new ImePreferenceController(mContext));
88         exposureChangesCategoryControllers.add(new GlobalHttpProxyPreferenceController(mContext));
89         exposureChangesCategoryControllers.add(new CaCertsCurrentUserPreferenceController(
90                 mContext));
91         exposureChangesCategoryControllers.add(new CaCertsManagedProfilePreferenceController(
92                 mContext));
93         controllers.addAll(exposureChangesCategoryControllers);
94         controllers.add(new PreferenceCategoryController(mContext, KEY_EXPOSURE_CHANGES_CATEGORY)
95                 .setChildren(exposureChangesCategoryControllers));
96         controllers.add(new FailedPasswordWipeCurrentUserPreferenceController(mContext));
97         controllers.add(new FailedPasswordWipeManagedProfilePreferenceController(mContext));
98         return controllers;
99     }
100 }
101