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.internal.annotations.VisibleForTesting;
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.settingslib.core.AbstractPreferenceController;
28 import com.android.settingslib.search.SearchIndexable;
29 
30 import java.util.List;
31 
32 @SearchIndexable
33 public class EnterprisePrivacySettings extends DashboardFragment {
34 
35     static final String TAG = "EnterprisePrivacySettings";
36 
37     @VisibleForTesting
38     PrivacySettingsPreference mPrivacySettingsPreference;
39 
40     @Override
onAttach(Context context)41     public void onAttach(Context context) {
42         mPrivacySettingsPreference =
43                 PrivacySettingsPreferenceFactory.createPrivacySettingsPreference(context);
44 
45         super.onAttach(context);
46     }
47 
48     @Override
onDetach()49     public void onDetach() {
50         mPrivacySettingsPreference = null;
51         super.onDetach();
52     }
53 
54     @Override
getMetricsCategory()55     public int getMetricsCategory() {
56         return SettingsEnums.ENTERPRISE_PRIVACY_SETTINGS;
57     }
58 
59     @Override
getLogTag()60     protected String getLogTag() {
61         return TAG;
62     }
63 
64     @Override
getPreferenceScreenResId()65     protected int getPreferenceScreenResId() {
66         return mPrivacySettingsPreference.getPreferenceScreenResId();
67     }
68 
69     @Override
createPreferenceControllers(Context context)70     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
71         return mPrivacySettingsPreference.createPreferenceControllers(true /* async */);
72     }
73 
isPageEnabled(Context context)74     public static boolean isPageEnabled(Context context) {
75         return FeatureFactory.getFactory(context)
76                 .getEnterprisePrivacyFeatureProvider(context)
77                 .hasDeviceOwner();
78     }
79 
80     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
81             new BaseSearchIndexProvider() {
82 
83                 private PrivacySettingsPreference mPrivacySettingsPreference;
84 
85                 @Override
86                 protected boolean isPageSearchEnabled(Context context) {
87                     return isPageEnabled(context);
88                 }
89 
90                 @Override
91                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
92                         boolean enabled) {
93                     mPrivacySettingsPreference =
94                             PrivacySettingsPreferenceFactory.createPrivacySettingsPreference(
95                                     context);
96                     return mPrivacySettingsPreference.getXmlResourcesToIndex();
97                 }
98 
99                 @Override
100                 public List<AbstractPreferenceController> createPreferenceControllers(
101                         Context context) {
102                     mPrivacySettingsPreference =
103                             PrivacySettingsPreferenceFactory.createPrivacySettingsPreference(
104                                     context);
105                     return mPrivacySettingsPreference.createPreferenceControllers(
106                             false /* async */);
107                 }
108             };
109 }
110