Home | History | Annotate | Download | only in enterprise
      1 /*
      2  * Copyright (C) 2017 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.Manifest;
     20 import android.content.Context;
     21 
     22 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
     23 import com.android.settings.R;
     24 import com.android.settings.applications.ApplicationFeatureProvider;
     25 import com.android.settings.dashboard.DashboardFragment;
     26 import com.android.settings.overlay.FeatureFactory;
     27 import com.android.settingslib.core.AbstractPreferenceController;
     28 
     29 import java.util.ArrayList;
     30 import java.util.List;
     31 
     32 /**
     33  * Base fragment for displaying a list of applications on a device.
     34  * Inner static classes are concrete implementations.
     35  */
     36 public abstract class ApplicationListFragment extends DashboardFragment
     37         implements ApplicationListPreferenceController.ApplicationListBuilder {
     38 
     39     static final String TAG = "EnterprisePrivacySettings";
     40 
     41     @Override
     42     protected String getLogTag() {
     43         return TAG;
     44     }
     45 
     46     @Override
     47     protected int getPreferenceScreenResId() {
     48         return R.xml.app_list_disclosure_settings;
     49     }
     50 
     51     @Override
     52     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
     53         final List<AbstractPreferenceController> controllers = new ArrayList<>();
     54         ApplicationListPreferenceController controller = new ApplicationListPreferenceController(
     55                 context, this, context.getPackageManager(), this);
     56         controllers.add(controller);
     57         return controllers;
     58     }
     59 
     60     private abstract static class AdminGrantedPermission extends ApplicationListFragment {
     61         private final String[] mPermissions;
     62 
     63         public AdminGrantedPermission(String[] permissions) {
     64             mPermissions = permissions;
     65         }
     66 
     67         @Override
     68         public void buildApplicationList(Context context,
     69                 ApplicationFeatureProvider.ListOfAppsCallback callback) {
     70             FeatureFactory.getFactory(context).getApplicationFeatureProvider(context)
     71                     .listAppsWithAdminGrantedPermissions(mPermissions, callback);
     72         }
     73 
     74         @Override
     75         public int getMetricsCategory() {
     76             return MetricsEvent.ENTERPRISE_PRIVACY_PERMISSIONS;
     77         }
     78     }
     79 
     80     public static class AdminGrantedPermissionCamera extends AdminGrantedPermission {
     81         public AdminGrantedPermissionCamera() {
     82             super(new String[] {Manifest.permission.CAMERA});
     83         }
     84     }
     85 
     86     public static class AdminGrantedPermissionLocation extends AdminGrantedPermission {
     87         public AdminGrantedPermissionLocation() {
     88             super(new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
     89                     Manifest.permission.ACCESS_FINE_LOCATION});
     90         }
     91     }
     92 
     93     public static class AdminGrantedPermissionMicrophone extends AdminGrantedPermission {
     94         public AdminGrantedPermissionMicrophone() {
     95             super(new String[] {Manifest.permission.RECORD_AUDIO});
     96         }
     97     }
     98 
     99     public static class EnterpriseInstalledPackages extends ApplicationListFragment {
    100         public EnterpriseInstalledPackages() {
    101         }
    102 
    103         @Override
    104         public int getMetricsCategory() {
    105             return MetricsEvent.ENTERPRISE_PRIVACY_INSTALLED_APPS;
    106         }
    107 
    108         @Override
    109         public void buildApplicationList(Context context,
    110                 ApplicationFeatureProvider.ListOfAppsCallback callback) {
    111             FeatureFactory.getFactory(context).getApplicationFeatureProvider(context).
    112                     listPolicyInstalledApps(callback);
    113         }
    114     }
    115 }
    116