1 /* 2 * Copyright (C) 2019 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.car.developeroptions.enterprise; 18 19 import android.Manifest; 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 23 import com.android.car.developeroptions.R; 24 import com.android.car.developeroptions.applications.ApplicationFeatureProvider; 25 import com.android.car.developeroptions.dashboard.DashboardFragment; 26 import com.android.car.developeroptions.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 getLogTag()42 protected String getLogTag() { 43 return TAG; 44 } 45 46 @Override getPreferenceScreenResId()47 protected int getPreferenceScreenResId() { 48 return R.xml.app_list_disclosure_settings; 49 } 50 51 @Override createPreferenceControllers(Context context)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 AdminGrantedPermission(String[] permissions)63 public AdminGrantedPermission(String[] permissions) { 64 mPermissions = permissions; 65 } 66 67 @Override buildApplicationList(Context context, ApplicationFeatureProvider.ListOfAppsCallback callback)68 public void buildApplicationList(Context context, 69 ApplicationFeatureProvider.ListOfAppsCallback callback) { 70 FeatureFactory.getFactory(context).getApplicationFeatureProvider(context) 71 .listAppsWithAdminGrantedPermissions(mPermissions, callback); 72 } 73 74 @Override getMetricsCategory()75 public int getMetricsCategory() { 76 return SettingsEnums.ENTERPRISE_PRIVACY_PERMISSIONS; 77 } 78 } 79 80 public static class AdminGrantedPermissionCamera extends AdminGrantedPermission { AdminGrantedPermissionCamera()81 public AdminGrantedPermissionCamera() { 82 super(new String[] {Manifest.permission.CAMERA}); 83 } 84 } 85 86 public static class AdminGrantedPermissionLocation extends AdminGrantedPermission { AdminGrantedPermissionLocation()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 { AdminGrantedPermissionMicrophone()94 public AdminGrantedPermissionMicrophone() { 95 super(new String[] {Manifest.permission.RECORD_AUDIO}); 96 } 97 } 98 99 public static class EnterpriseInstalledPackages extends ApplicationListFragment { EnterpriseInstalledPackages()100 public EnterpriseInstalledPackages() { 101 } 102 103 @Override getMetricsCategory()104 public int getMetricsCategory() { 105 return SettingsEnums.ENTERPRISE_PRIVACY_INSTALLED_APPS; 106 } 107 108 @Override buildApplicationList(Context context, ApplicationFeatureProvider.ListOfAppsCallback callback)109 public void buildApplicationList(Context context, 110 ApplicationFeatureProvider.ListOfAppsCallback callback) { 111 FeatureFactory.getFactory(context).getApplicationFeatureProvider(context). 112 listPolicyInstalledApps(callback); 113 } 114 } 115 } 116