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