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