Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.server.pm; |
| 18 | |
| 19 | import android.Manifest; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 20 | import android.app.DownloadManager; |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 21 | import android.app.admin.DevicePolicyManager; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 23 | import android.content.pm.ActivityInfo; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 24 | import android.content.pm.ApplicationInfo; |
| 25 | import android.content.pm.PackageManager; |
| 26 | import android.content.pm.PackageManagerInternal.PackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManagerInternal.SyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageParser; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 29 | import android.content.pm.ProviderInfo; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 30 | import android.content.pm.ResolveInfo; |
| 31 | import android.net.Uri; |
| 32 | import android.os.Build; |
| 33 | import android.os.UserHandle; |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 34 | import android.provider.CalendarContract; |
| 35 | import android.provider.ContactsContract; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 36 | import android.provider.MediaStore; |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 37 | import android.provider.Telephony.Sms.Intents; |
Svetoslav | 0e62952 | 2015-08-05 19:14:47 -0700 | [diff] [blame] | 38 | import android.security.Credentials; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 39 | import android.util.ArraySet; |
| 40 | import android.util.Log; |
| 41 | |
| 42 | import java.io.File; |
| 43 | import java.util.ArrayList; |
| 44 | import java.util.List; |
| 45 | import java.util.Set; |
| 46 | |
| 47 | import static android.os.Process.FIRST_APPLICATION_UID; |
| 48 | |
| 49 | /** |
| 50 | * This class is the policy for granting runtime permissions to |
| 51 | * platform components and default handlers in the system such |
| 52 | * that the device is usable out-of-the-box. For example, the |
| 53 | * shell UID is a part of the system and the Phone app should |
| 54 | * have phone related permission by default. |
| 55 | */ |
| 56 | final class DefaultPermissionGrantPolicy { |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 57 | private static final String TAG = "DefaultPermGrantPolicy"; // must be <= 23 chars |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 58 | private static final boolean DEBUG = false; |
| 59 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 60 | private static final String AUDIO_MIME_TYPE = "audio/mpeg"; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 61 | |
| 62 | private static final Set<String> PHONE_PERMISSIONS = new ArraySet<>(); |
| 63 | static { |
| 64 | PHONE_PERMISSIONS.add(Manifest.permission.READ_PHONE_STATE); |
| 65 | PHONE_PERMISSIONS.add(Manifest.permission.CALL_PHONE); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 66 | PHONE_PERMISSIONS.add(Manifest.permission.READ_CALL_LOG); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 67 | PHONE_PERMISSIONS.add(Manifest.permission.WRITE_CALL_LOG); |
| 68 | PHONE_PERMISSIONS.add(Manifest.permission.ADD_VOICEMAIL); |
| 69 | PHONE_PERMISSIONS.add(Manifest.permission.USE_SIP); |
| 70 | PHONE_PERMISSIONS.add(Manifest.permission.PROCESS_OUTGOING_CALLS); |
| 71 | } |
| 72 | |
| 73 | private static final Set<String> CONTACTS_PERMISSIONS = new ArraySet<>(); |
| 74 | static { |
| 75 | CONTACTS_PERMISSIONS.add(Manifest.permission.READ_CONTACTS); |
| 76 | CONTACTS_PERMISSIONS.add(Manifest.permission.WRITE_CONTACTS); |
Svetoslav Ganov | 54a0cf1 | 2015-07-17 20:34:18 +0000 | [diff] [blame] | 77 | CONTACTS_PERMISSIONS.add(Manifest.permission.GET_ACCOUNTS); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | private static final Set<String> LOCATION_PERMISSIONS = new ArraySet<>(); |
| 81 | static { |
| 82 | LOCATION_PERMISSIONS.add(Manifest.permission.ACCESS_FINE_LOCATION); |
| 83 | LOCATION_PERMISSIONS.add(Manifest.permission.ACCESS_COARSE_LOCATION); |
| 84 | } |
| 85 | |
| 86 | private static final Set<String> CALENDAR_PERMISSIONS = new ArraySet<>(); |
| 87 | static { |
| 88 | CALENDAR_PERMISSIONS.add(Manifest.permission.READ_CALENDAR); |
| 89 | CALENDAR_PERMISSIONS.add(Manifest.permission.WRITE_CALENDAR); |
| 90 | } |
| 91 | |
| 92 | private static final Set<String> SMS_PERMISSIONS = new ArraySet<>(); |
| 93 | static { |
| 94 | SMS_PERMISSIONS.add(Manifest.permission.SEND_SMS); |
| 95 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_SMS); |
| 96 | SMS_PERMISSIONS.add(Manifest.permission.READ_SMS); |
| 97 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_WAP_PUSH); |
| 98 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_MMS); |
| 99 | SMS_PERMISSIONS.add(Manifest.permission.READ_CELL_BROADCASTS); |
| 100 | } |
| 101 | |
| 102 | private static final Set<String> MICROPHONE_PERMISSIONS = new ArraySet<>(); |
| 103 | static { |
| 104 | MICROPHONE_PERMISSIONS.add(Manifest.permission.RECORD_AUDIO); |
| 105 | } |
| 106 | |
| 107 | private static final Set<String> CAMERA_PERMISSIONS = new ArraySet<>(); |
| 108 | static { |
| 109 | CAMERA_PERMISSIONS.add(Manifest.permission.CAMERA); |
| 110 | } |
| 111 | |
| 112 | private static final Set<String> SENSORS_PERMISSIONS = new ArraySet<>(); |
| 113 | static { |
| 114 | SENSORS_PERMISSIONS.add(Manifest.permission.BODY_SENSORS); |
| 115 | } |
| 116 | |
| 117 | private static final Set<String> STORAGE_PERMISSIONS = new ArraySet<>(); |
| 118 | static { |
Svet Ganov | 975fa47 | 2015-06-22 20:45:31 -0700 | [diff] [blame] | 119 | STORAGE_PERMISSIONS.add(Manifest.permission.READ_EXTERNAL_STORAGE); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 120 | STORAGE_PERMISSIONS.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); |
| 121 | } |
| 122 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 123 | private final PackageManagerService mService; |
| 124 | |
| 125 | private PackagesProvider mImePackagesProvider; |
| 126 | private PackagesProvider mLocationPackagesProvider; |
| 127 | private PackagesProvider mVoiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 128 | private PackagesProvider mSmsAppPackagesProvider; |
| 129 | private PackagesProvider mDialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 130 | private PackagesProvider mSimCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 131 | private SyncAdapterPackagesProvider mSyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 132 | |
| 133 | public DefaultPermissionGrantPolicy(PackageManagerService service) { |
| 134 | mService = service; |
| 135 | } |
| 136 | |
| 137 | public void setImePackagesProviderLPr(PackagesProvider provider) { |
| 138 | mImePackagesProvider = provider; |
| 139 | } |
| 140 | |
| 141 | public void setLocationPackagesProviderLPw(PackagesProvider provider) { |
| 142 | mLocationPackagesProvider = provider; |
| 143 | } |
| 144 | |
| 145 | public void setVoiceInteractionPackagesProviderLPw(PackagesProvider provider) { |
| 146 | mVoiceInteractionPackagesProvider = provider; |
| 147 | } |
| 148 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 149 | public void setSmsAppPackagesProviderLPw(PackagesProvider provider) { |
| 150 | mSmsAppPackagesProvider = provider; |
| 151 | } |
| 152 | |
| 153 | public void setDialerAppPackagesProviderLPw(PackagesProvider provider) { |
| 154 | mDialerAppPackagesProvider = provider; |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 157 | public void setSimCallManagerPackagesProviderLPw(PackagesProvider provider) { |
| 158 | mSimCallManagerPackagesProvider = provider; |
| 159 | } |
| 160 | |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 161 | public void setSyncAdapterPackagesProviderLPw(SyncAdapterPackagesProvider provider) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 162 | mSyncAdapterPackagesProvider = provider; |
| 163 | } |
| 164 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 165 | public void grantDefaultPermissions(int userId) { |
| 166 | grantPermissionsToSysComponentsAndPrivApps(userId); |
| 167 | grantDefaultSystemHandlerPermissions(userId); |
| 168 | } |
| 169 | |
| 170 | private void grantPermissionsToSysComponentsAndPrivApps(int userId) { |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 171 | Log.i(TAG, "Granting permissions to platform components for user " + userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 172 | |
| 173 | synchronized (mService.mPackages) { |
| 174 | for (PackageParser.Package pkg : mService.mPackages.values()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 175 | if (!isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) |
| 176 | || !doesPackageSupportRuntimePermissions(pkg) |
| 177 | || pkg.requestedPermissions.isEmpty()) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 178 | continue; |
| 179 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 180 | Set<String> permissions = new ArraySet<>(); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 181 | final int permissionCount = pkg.requestedPermissions.size(); |
| 182 | for (int i = 0; i < permissionCount; i++) { |
| 183 | String permission = pkg.requestedPermissions.get(i); |
| 184 | BasePermission bp = mService.mSettings.mPermissions.get(permission); |
| 185 | if (bp != null && bp.isRuntime()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 186 | permissions.add(permission); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 189 | if (!permissions.isEmpty()) { |
| 190 | grantRuntimePermissionsLPw(pkg, permissions, true, userId); |
| 191 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | private void grantDefaultSystemHandlerPermissions(int userId) { |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 197 | Log.i(TAG, "Granting permissions to default platform handlers for user " + userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 198 | |
| 199 | final PackagesProvider imePackagesProvider; |
| 200 | final PackagesProvider locationPackagesProvider; |
| 201 | final PackagesProvider voiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 202 | final PackagesProvider smsAppPackagesProvider; |
| 203 | final PackagesProvider dialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 204 | final PackagesProvider simCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 205 | final SyncAdapterPackagesProvider syncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 206 | |
| 207 | synchronized (mService.mPackages) { |
| 208 | imePackagesProvider = mImePackagesProvider; |
| 209 | locationPackagesProvider = mLocationPackagesProvider; |
| 210 | voiceInteractionPackagesProvider = mVoiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 211 | smsAppPackagesProvider = mSmsAppPackagesProvider; |
| 212 | dialerAppPackagesProvider = mDialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 213 | simCallManagerPackagesProvider = mSimCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 214 | syncAdapterPackagesProvider = mSyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | String[] imePackageNames = (imePackagesProvider != null) |
| 218 | ? imePackagesProvider.getPackages(userId) : null; |
| 219 | String[] voiceInteractPackageNames = (voiceInteractionPackagesProvider != null) |
| 220 | ? voiceInteractionPackagesProvider.getPackages(userId) : null; |
| 221 | String[] locationPackageNames = (locationPackagesProvider != null) |
| 222 | ? locationPackagesProvider.getPackages(userId) : null; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 223 | String[] smsAppPackageNames = (smsAppPackagesProvider != null) |
| 224 | ? smsAppPackagesProvider.getPackages(userId) : null; |
| 225 | String[] dialerAppPackageNames = (dialerAppPackagesProvider != null) |
| 226 | ? dialerAppPackagesProvider.getPackages(userId) : null; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 227 | String[] simCallManagerPackageNames = (simCallManagerPackagesProvider != null) |
| 228 | ? simCallManagerPackagesProvider.getPackages(userId) : null; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 229 | String[] contactsSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? |
| 230 | syncAdapterPackagesProvider.getPackages(ContactsContract.AUTHORITY, userId) : null; |
| 231 | String[] calendarSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? |
| 232 | syncAdapterPackagesProvider.getPackages(CalendarContract.AUTHORITY, userId) : null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 233 | |
| 234 | synchronized (mService.mPackages) { |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 235 | // Installer |
| 236 | PackageParser.Package installerPackage = getSystemPackageLPr( |
| 237 | mService.mRequiredInstallerPackage); |
| 238 | if (installerPackage != null |
| 239 | && doesPackageSupportRuntimePermissions(installerPackage)) { |
| 240 | grantRuntimePermissionsLPw(installerPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 243 | // Verifier |
| 244 | PackageParser.Package verifierPackage = getSystemPackageLPr( |
| 245 | mService.mRequiredVerifierPackage); |
| 246 | if (verifierPackage != null |
| 247 | && doesPackageSupportRuntimePermissions(verifierPackage)) { |
| 248 | grantRuntimePermissionsLPw(verifierPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | cd94602 | 2015-09-12 10:19:54 -0700 | [diff] [blame] | 249 | grantRuntimePermissionsLPw(verifierPackage, PHONE_PERMISSIONS, false, userId); |
| 250 | grantRuntimePermissionsLPw(verifierPackage, SMS_PERMISSIONS, false, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | // SetupWizard |
| 254 | Intent setupIntent = new Intent(Intent.ACTION_MAIN); |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 255 | setupIntent.addCategory(Intent.CATEGORY_SETUP_WIZARD); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 256 | PackageParser.Package setupPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 257 | setupIntent, userId); |
| 258 | if (setupPackage != null |
| 259 | && doesPackageSupportRuntimePermissions(setupPackage)) { |
| 260 | grantRuntimePermissionsLPw(setupPackage, PHONE_PERMISSIONS, userId); |
| 261 | grantRuntimePermissionsLPw(setupPackage, CONTACTS_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 264 | // Camera |
| 265 | Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 266 | PackageParser.Package cameraPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 267 | cameraIntent, userId); |
| 268 | if (cameraPackage != null |
| 269 | && doesPackageSupportRuntimePermissions(cameraPackage)) { |
| 270 | grantRuntimePermissionsLPw(cameraPackage, CAMERA_PERMISSIONS, userId); |
| 271 | grantRuntimePermissionsLPw(cameraPackage, MICROPHONE_PERMISSIONS, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 272 | grantRuntimePermissionsLPw(cameraPackage, STORAGE_PERMISSIONS, userId); |
| 273 | } |
| 274 | |
| 275 | // Media provider |
| 276 | PackageParser.Package mediaStorePackage = getDefaultProviderAuthorityPackageLPr( |
| 277 | MediaStore.AUTHORITY, userId); |
| 278 | if (mediaStorePackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 279 | grantRuntimePermissionsLPw(mediaStorePackage, STORAGE_PERMISSIONS, true, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // Downloads provider |
| 283 | PackageParser.Package downloadsPackage = getDefaultProviderAuthorityPackageLPr( |
| 284 | "downloads", userId); |
| 285 | if (downloadsPackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 286 | grantRuntimePermissionsLPw(downloadsPackage, STORAGE_PERMISSIONS, true, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // Downloads UI |
| 290 | Intent downloadsUiIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 291 | PackageParser.Package downloadsUiPackage = getDefaultSystemHandlerActivityPackageLPr( |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 292 | downloadsUiIntent, userId); |
| 293 | if (downloadsUiPackage != null |
| 294 | && doesPackageSupportRuntimePermissions(downloadsUiPackage)) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 295 | grantRuntimePermissionsLPw(downloadsUiPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 298 | // Storage provider |
| 299 | PackageParser.Package storagePackage = getDefaultProviderAuthorityPackageLPr( |
| 300 | "com.android.externalstorage.documents", userId); |
| 301 | if (storagePackage != null) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 302 | grantRuntimePermissionsLPw(storagePackage, STORAGE_PERMISSIONS, true, userId); |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Svetoslav | 0e62952 | 2015-08-05 19:14:47 -0700 | [diff] [blame] | 305 | // CertInstaller |
| 306 | Intent certInstallerIntent = new Intent(Credentials.INSTALL_ACTION); |
| 307 | PackageParser.Package certInstallerPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 308 | certInstallerIntent, userId); |
| 309 | if (certInstallerPackage != null |
| 310 | && doesPackageSupportRuntimePermissions(certInstallerPackage)) { |
| 311 | grantRuntimePermissionsLPw(certInstallerPackage, STORAGE_PERMISSIONS, true, userId); |
| 312 | } |
| 313 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 314 | // Dialer |
| 315 | if (dialerAppPackageNames == null) { |
| 316 | Intent dialerIntent = new Intent(Intent.ACTION_DIAL); |
| 317 | PackageParser.Package dialerPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 318 | dialerIntent, userId); |
| 319 | if (dialerPackage != null) { |
| 320 | grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId); |
| 321 | } |
| 322 | } else { |
| 323 | for (String dialerAppPackageName : dialerAppPackageNames) { |
| 324 | PackageParser.Package dialerPackage = getSystemPackageLPr(dialerAppPackageName); |
| 325 | if (dialerPackage != null) { |
| 326 | grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 331 | // Sim call manager |
| 332 | if (simCallManagerPackageNames != null) { |
| 333 | for (String simCallManagerPackageName : simCallManagerPackageNames) { |
| 334 | PackageParser.Package simCallManagerPackage = |
| 335 | getSystemPackageLPr(simCallManagerPackageName); |
| 336 | if (simCallManagerPackage != null) { |
| 337 | grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, |
| 338 | userId); |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 343 | // SMS |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 344 | if (smsAppPackageNames == null) { |
| 345 | Intent smsIntent = new Intent(Intent.ACTION_MAIN); |
| 346 | smsIntent.addCategory(Intent.CATEGORY_APP_MESSAGING); |
| 347 | PackageParser.Package smsPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 348 | smsIntent, userId); |
| 349 | if (smsPackage != null) { |
| 350 | grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId); |
| 351 | } |
| 352 | } else { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 353 | for (String smsPackageName : smsAppPackageNames) { |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 354 | PackageParser.Package smsPackage = getSystemPackageLPr(smsPackageName); |
| 355 | if (smsPackage != null) { |
| 356 | grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 357 | } |
| 358 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 361 | // Cell Broadcast Receiver |
| 362 | Intent cbrIntent = new Intent(Intents.SMS_CB_RECEIVED_ACTION); |
| 363 | PackageParser.Package cbrPackage = |
| 364 | getDefaultSystemHandlerActivityPackageLPr(cbrIntent, userId); |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 365 | if (cbrPackage != null && doesPackageSupportRuntimePermissions(cbrPackage)) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 366 | grantRuntimePermissionsLPw(cbrPackage, SMS_PERMISSIONS, userId); |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Junda Liu | d878f53 | 2015-08-13 14:25:49 -0700 | [diff] [blame] | 369 | // Carrier Provisioning Service |
| 370 | Intent carrierProvIntent = new Intent(Intents.SMS_CARRIER_PROVISION_ACTION); |
| 371 | PackageParser.Package carrierProvPackage = |
| 372 | getDefaultSystemHandlerServicePackageLPr(carrierProvIntent, userId); |
| 373 | if (carrierProvPackage != null && doesPackageSupportRuntimePermissions(carrierProvPackage)) { |
| 374 | grantRuntimePermissionsLPw(carrierProvPackage, SMS_PERMISSIONS, false, userId); |
| 375 | } |
| 376 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 377 | // Calendar |
| 378 | Intent calendarIntent = new Intent(Intent.ACTION_MAIN); |
| 379 | calendarIntent.addCategory(Intent.CATEGORY_APP_CALENDAR); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 380 | PackageParser.Package calendarPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 381 | calendarIntent, userId); |
| 382 | if (calendarPackage != null |
| 383 | && doesPackageSupportRuntimePermissions(calendarPackage)) { |
| 384 | grantRuntimePermissionsLPw(calendarPackage, CALENDAR_PERMISSIONS, userId); |
| 385 | grantRuntimePermissionsLPw(calendarPackage, CONTACTS_PERMISSIONS, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | // Calendar provider |
| 389 | PackageParser.Package calendarProviderPackage = getDefaultProviderAuthorityPackageLPr( |
| 390 | CalendarContract.AUTHORITY, userId); |
| 391 | if (calendarProviderPackage != null) { |
| 392 | grantRuntimePermissionsLPw(calendarProviderPackage, CONTACTS_PERMISSIONS, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 393 | grantRuntimePermissionsLPw(calendarProviderPackage, CALENDAR_PERMISSIONS, |
| 394 | true, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 395 | grantRuntimePermissionsLPw(calendarProviderPackage, STORAGE_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 398 | // Calendar provider sync adapters |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 399 | List<PackageParser.Package> calendarSyncAdapters = getHeadlessSyncAdapterPackagesLPr( |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 400 | calendarSyncAdapterPackages, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 401 | final int calendarSyncAdapterCount = calendarSyncAdapters.size(); |
| 402 | for (int i = 0; i < calendarSyncAdapterCount; i++) { |
| 403 | PackageParser.Package calendarSyncAdapter = calendarSyncAdapters.get(i); |
| 404 | if (doesPackageSupportRuntimePermissions(calendarSyncAdapter)) { |
| 405 | grantRuntimePermissionsLPw(calendarSyncAdapter, CALENDAR_PERMISSIONS, userId); |
| 406 | } |
| 407 | } |
| 408 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 409 | // Contacts |
| 410 | Intent contactsIntent = new Intent(Intent.ACTION_MAIN); |
| 411 | contactsIntent.addCategory(Intent.CATEGORY_APP_CONTACTS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 412 | PackageParser.Package contactsPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 413 | contactsIntent, userId); |
| 414 | if (contactsPackage != null |
| 415 | && doesPackageSupportRuntimePermissions(contactsPackage)) { |
| 416 | grantRuntimePermissionsLPw(contactsPackage, CONTACTS_PERMISSIONS, userId); |
| 417 | grantRuntimePermissionsLPw(contactsPackage, PHONE_PERMISSIONS, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 420 | // Contacts provider sync adapters |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 421 | List<PackageParser.Package> contactsSyncAdapters = getHeadlessSyncAdapterPackagesLPr( |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 422 | contactsSyncAdapterPackages, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 423 | final int contactsSyncAdapterCount = contactsSyncAdapters.size(); |
| 424 | for (int i = 0; i < contactsSyncAdapterCount; i++) { |
| 425 | PackageParser.Package contactsSyncAdapter = contactsSyncAdapters.get(i); |
| 426 | if (doesPackageSupportRuntimePermissions(contactsSyncAdapter)) { |
| 427 | grantRuntimePermissionsLPw(contactsSyncAdapter, CONTACTS_PERMISSIONS, userId); |
| 428 | } |
| 429 | } |
| 430 | |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 431 | // Contacts provider |
| 432 | PackageParser.Package contactsProviderPackage = getDefaultProviderAuthorityPackageLPr( |
| 433 | ContactsContract.AUTHORITY, userId); |
| 434 | if (contactsProviderPackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 435 | grantRuntimePermissionsLPw(contactsProviderPackage, CONTACTS_PERMISSIONS, |
| 436 | true, userId); |
Makoto Onuki | 7a4082e | 2015-07-06 16:59:36 -0700 | [diff] [blame] | 437 | grantRuntimePermissionsLPw(contactsProviderPackage, PHONE_PERMISSIONS, |
| 438 | true, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 439 | grantRuntimePermissionsLPw(contactsProviderPackage, STORAGE_PERMISSIONS, userId); |
| 440 | } |
| 441 | |
| 442 | // Device provisioning |
| 443 | Intent deviceProvisionIntent = new Intent( |
| 444 | DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE); |
Svet Ganov | b6e0013 | 2015-06-29 20:19:25 -0700 | [diff] [blame] | 445 | PackageParser.Package deviceProvisionPackage = |
| 446 | getDefaultSystemHandlerActivityPackageLPr(deviceProvisionIntent, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 447 | if (deviceProvisionPackage != null |
| 448 | && doesPackageSupportRuntimePermissions(deviceProvisionPackage)) { |
Makoto Onuki | bc92479 | 2015-07-16 11:38:00 -0700 | [diff] [blame] | 449 | grantRuntimePermissionsLPw(deviceProvisionPackage, CONTACTS_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | // Maps |
| 453 | Intent mapsIntent = new Intent(Intent.ACTION_MAIN); |
| 454 | mapsIntent.addCategory(Intent.CATEGORY_APP_MAPS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 455 | PackageParser.Package mapsPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 456 | mapsIntent, userId); |
| 457 | if (mapsPackage != null |
| 458 | && doesPackageSupportRuntimePermissions(mapsPackage)) { |
| 459 | grantRuntimePermissionsLPw(mapsPackage, LOCATION_PERMISSIONS, userId); |
| 460 | } |
| 461 | |
Svet Ganov | 200d494 | 2015-07-01 20:46:02 -0700 | [diff] [blame] | 462 | // Gallery |
| 463 | Intent galleryIntent = new Intent(Intent.ACTION_MAIN); |
| 464 | galleryIntent.addCategory(Intent.CATEGORY_APP_GALLERY); |
| 465 | PackageParser.Package galleryPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 466 | galleryIntent, userId); |
| 467 | if (galleryPackage != null |
| 468 | && doesPackageSupportRuntimePermissions(galleryPackage)) { |
| 469 | grantRuntimePermissionsLPw(galleryPackage, STORAGE_PERMISSIONS, userId); |
| 470 | } |
| 471 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 472 | // Email |
| 473 | Intent emailIntent = new Intent(Intent.ACTION_MAIN); |
| 474 | emailIntent.addCategory(Intent.CATEGORY_APP_EMAIL); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 475 | PackageParser.Package emailPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 476 | emailIntent, userId); |
| 477 | if (emailPackage != null |
| 478 | && doesPackageSupportRuntimePermissions(emailPackage)) { |
| 479 | grantRuntimePermissionsLPw(emailPackage, CONTACTS_PERMISSIONS, userId); |
| 480 | } |
| 481 | |
| 482 | // Browser |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 483 | PackageParser.Package browserPackage = null; |
| 484 | String defaultBrowserPackage = mService.getDefaultBrowserPackageName(userId); |
| 485 | if (defaultBrowserPackage != null) { |
| 486 | browserPackage = getPackageLPr(defaultBrowserPackage); |
| 487 | } |
| 488 | if (browserPackage == null) { |
| 489 | Intent browserIntent = new Intent(Intent.ACTION_MAIN); |
| 490 | browserIntent.addCategory(Intent.CATEGORY_APP_BROWSER); |
| 491 | browserPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 492 | browserIntent, userId); |
| 493 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 494 | if (browserPackage != null |
| 495 | && doesPackageSupportRuntimePermissions(browserPackage)) { |
| 496 | grantRuntimePermissionsLPw(browserPackage, LOCATION_PERMISSIONS, userId); |
| 497 | } |
| 498 | |
| 499 | // IME |
| 500 | if (imePackageNames != null) { |
| 501 | for (String imePackageName : imePackageNames) { |
| 502 | PackageParser.Package imePackage = getSystemPackageLPr(imePackageName); |
| 503 | if (imePackage != null |
| 504 | && doesPackageSupportRuntimePermissions(imePackage)) { |
| 505 | grantRuntimePermissionsLPw(imePackage, CONTACTS_PERMISSIONS, userId); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | // Voice interaction |
| 511 | if (voiceInteractPackageNames != null) { |
| 512 | for (String voiceInteractPackageName : voiceInteractPackageNames) { |
| 513 | PackageParser.Package voiceInteractPackage = getSystemPackageLPr( |
| 514 | voiceInteractPackageName); |
| 515 | if (voiceInteractPackage != null |
| 516 | && doesPackageSupportRuntimePermissions(voiceInteractPackage)) { |
| 517 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 518 | CONTACTS_PERMISSIONS, userId); |
| 519 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 520 | CALENDAR_PERMISSIONS, userId); |
| 521 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 522 | MICROPHONE_PERMISSIONS, userId); |
| 523 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 524 | PHONE_PERMISSIONS, userId); |
| 525 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 526 | SMS_PERMISSIONS, userId); |
| 527 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 528 | LOCATION_PERMISSIONS, userId); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 533 | // Voice recognition |
| 534 | Intent voiceRecoIntent = new Intent("android.speech.RecognitionService"); |
| 535 | voiceRecoIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 536 | PackageParser.Package voiceRecoPackage = getDefaultSystemHandlerServicePackageLPr( |
| 537 | voiceRecoIntent, userId); |
| 538 | if (voiceRecoPackage != null |
| 539 | && doesPackageSupportRuntimePermissions(voiceRecoPackage)) { |
| 540 | grantRuntimePermissionsLPw(voiceRecoPackage, MICROPHONE_PERMISSIONS, userId); |
| 541 | } |
| 542 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 543 | // Location |
| 544 | if (locationPackageNames != null) { |
| 545 | for (String packageName : locationPackageNames) { |
| 546 | PackageParser.Package locationPackage = getSystemPackageLPr(packageName); |
| 547 | if (locationPackage != null |
| 548 | && doesPackageSupportRuntimePermissions(locationPackage)) { |
| 549 | grantRuntimePermissionsLPw(locationPackage, CONTACTS_PERMISSIONS, userId); |
| 550 | grantRuntimePermissionsLPw(locationPackage, CALENDAR_PERMISSIONS, userId); |
| 551 | grantRuntimePermissionsLPw(locationPackage, MICROPHONE_PERMISSIONS, userId); |
| 552 | grantRuntimePermissionsLPw(locationPackage, PHONE_PERMISSIONS, userId); |
| 553 | grantRuntimePermissionsLPw(locationPackage, SMS_PERMISSIONS, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 554 | grantRuntimePermissionsLPw(locationPackage, LOCATION_PERMISSIONS, |
| 555 | true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 556 | grantRuntimePermissionsLPw(locationPackage, CAMERA_PERMISSIONS, userId); |
| 557 | grantRuntimePermissionsLPw(locationPackage, SENSORS_PERMISSIONS, userId); |
| 558 | grantRuntimePermissionsLPw(locationPackage, STORAGE_PERMISSIONS, userId); |
| 559 | } |
| 560 | } |
| 561 | } |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 562 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 563 | // Music |
| 564 | Intent musicIntent = new Intent(Intent.ACTION_VIEW); |
| 565 | musicIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 566 | musicIntent.setDataAndType(Uri.fromFile(new File("foo.mp3")), |
| 567 | AUDIO_MIME_TYPE); |
| 568 | PackageParser.Package musicPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 569 | musicIntent, userId); |
| 570 | if (musicPackage != null |
| 571 | && doesPackageSupportRuntimePermissions(musicPackage)) { |
| 572 | grantRuntimePermissionsLPw(musicPackage, STORAGE_PERMISSIONS, userId); |
| 573 | } |
| 574 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 575 | mService.mSettings.onDefaultRuntimePermissionsGrantedLPr(userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 579 | private void grantDefaultPermissionsToDefaultSystemDialerAppLPr( |
| 580 | PackageParser.Package dialerPackage, int userId) { |
| 581 | if (doesPackageSupportRuntimePermissions(dialerPackage)) { |
| 582 | grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, userId); |
| 583 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, userId); |
| 584 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, userId); |
| 585 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, userId); |
| 586 | } |
| 587 | } |
| 588 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 589 | private void grantDefaultPermissionsToDefaultSystemSmsAppLPr( |
| 590 | PackageParser.Package smsPackage, int userId) { |
| 591 | if (doesPackageSupportRuntimePermissions(smsPackage)) { |
| 592 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, userId); |
| 593 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, userId); |
| 594 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, userId); |
| 595 | } |
| 596 | } |
| 597 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 598 | public void grantDefaultPermissionsToDefaultSmsAppLPr(String packageName, int userId) { |
| 599 | Log.i(TAG, "Granting permissions to default sms app for user:" + userId); |
| 600 | if (packageName == null) { |
| 601 | return; |
| 602 | } |
| 603 | PackageParser.Package smsPackage = getPackageLPr(packageName); |
| 604 | if (smsPackage != null && doesPackageSupportRuntimePermissions(smsPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 605 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, false, true, userId); |
| 606 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 607 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
| 611 | public void grantDefaultPermissionsToDefaultDialerAppLPr(String packageName, int userId) { |
| 612 | Log.i(TAG, "Granting permissions to default dialer app for user:" + userId); |
| 613 | if (packageName == null) { |
| 614 | return; |
| 615 | } |
| 616 | PackageParser.Package dialerPackage = getPackageLPr(packageName); |
| 617 | if (dialerPackage != null |
| 618 | && doesPackageSupportRuntimePermissions(dialerPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 619 | grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, false, true, userId); |
| 620 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 621 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, false, true, userId); |
| 622 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 626 | private void grantDefaultPermissionsToDefaultSimCallManagerLPr( |
| 627 | PackageParser.Package simCallManagerPackage, int userId) { |
| 628 | Log.i(TAG, "Granting permissions to sim call manager for user:" + userId); |
| 629 | if (doesPackageSupportRuntimePermissions(simCallManagerPackage)) { |
| 630 | grantRuntimePermissionsLPw(simCallManagerPackage, PHONE_PERMISSIONS, userId); |
| 631 | grantRuntimePermissionsLPw(simCallManagerPackage, MICROPHONE_PERMISSIONS, userId); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | public void grantDefaultPermissionsToDefaultSimCallManagerLPr(String packageName, int userId) { |
| 636 | if (packageName == null) { |
| 637 | return; |
| 638 | } |
| 639 | PackageParser.Package simCallManagerPackage = getPackageLPr(packageName); |
| 640 | if (simCallManagerPackage != null) { |
| 641 | grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, userId); |
| 642 | } |
| 643 | } |
| 644 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 645 | public void grantDefaultPermissionsToEnabledCarrierAppsLPr(String[] packageNames, int userId) { |
| 646 | Log.i(TAG, "Granting permissions to enabled carrier apps for user:" + userId); |
| 647 | if (packageNames == null) { |
| 648 | return; |
| 649 | } |
| 650 | for (String packageName : packageNames) { |
| 651 | PackageParser.Package carrierPackage = getSystemPackageLPr(packageName); |
| 652 | if (carrierPackage != null |
| 653 | && doesPackageSupportRuntimePermissions(carrierPackage)) { |
| 654 | grantRuntimePermissionsLPw(carrierPackage, PHONE_PERMISSIONS, userId); |
| 655 | grantRuntimePermissionsLPw(carrierPackage, LOCATION_PERMISSIONS, userId); |
Shishir Agrawal | ad63247 | 2015-07-29 16:54:07 -0700 | [diff] [blame] | 656 | grantRuntimePermissionsLPw(carrierPackage, SMS_PERMISSIONS, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | public void grantDefaultPermissionsToDefaultBrowserLPr(String packageName, int userId) { |
| 662 | Log.i(TAG, "Granting permissions to default browser for user:" + userId); |
| 663 | if (packageName == null) { |
| 664 | return; |
| 665 | } |
| 666 | PackageParser.Package browserPackage = getSystemPackageLPr(packageName); |
| 667 | if (browserPackage != null |
| 668 | && doesPackageSupportRuntimePermissions(browserPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 669 | grantRuntimePermissionsLPw(browserPackage, LOCATION_PERMISSIONS, false, false, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 673 | private PackageParser.Package getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 674 | Intent intent, int userId) { |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 675 | ResolveInfo handler = mService.resolveIntent(intent, |
| 676 | intent.resolveType(mService.mContext.getContentResolver()), 0, userId); |
| 677 | if (handler == null || handler.activityInfo == null) { |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 678 | return null; |
| 679 | } |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 680 | ActivityInfo activityInfo = handler.activityInfo; |
| 681 | if (activityInfo.packageName.equals(mService.mResolveActivity.packageName) |
| 682 | && activityInfo.name.equals(mService.mResolveActivity.name)) { |
| 683 | return null; |
Svetoslav Ganov | d2bbf1b | 2015-11-06 00:24:47 +0000 | [diff] [blame] | 684 | } |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 685 | return getSystemPackageLPr(handler.activityInfo.packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 686 | } |
| 687 | |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 688 | private PackageParser.Package getDefaultSystemHandlerServicePackageLPr( |
| 689 | Intent intent, int userId) { |
| 690 | List<ResolveInfo> handlers = mService.queryIntentServices(intent, |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 691 | intent.resolveType(mService.mContext.getContentResolver()), 0, userId); |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 692 | if (handlers == null) { |
| 693 | return null; |
| 694 | } |
| 695 | final int handlerCount = handlers.size(); |
| 696 | for (int i = 0; i < handlerCount; i++) { |
| 697 | ResolveInfo handler = handlers.get(i); |
| 698 | PackageParser.Package handlerPackage = getSystemPackageLPr( |
| 699 | handler.serviceInfo.packageName); |
| 700 | if (handlerPackage != null) { |
| 701 | return handlerPackage; |
| 702 | } |
| 703 | } |
| 704 | return null; |
| 705 | } |
| 706 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 707 | private List<PackageParser.Package> getHeadlessSyncAdapterPackagesLPr( |
| 708 | String[] syncAdapterPackageNames, int userId) { |
| 709 | List<PackageParser.Package> syncAdapterPackages = new ArrayList<>(); |
| 710 | |
| 711 | Intent homeIntent = new Intent(Intent.ACTION_MAIN); |
Svet Ganov | 05069b9 | 2015-08-01 12:19:26 -0700 | [diff] [blame] | 712 | homeIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 713 | |
| 714 | for (String syncAdapterPackageName : syncAdapterPackageNames) { |
| 715 | homeIntent.setPackage(syncAdapterPackageName); |
| 716 | |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 717 | ResolveInfo homeActivity = mService.resolveIntent(homeIntent, |
| 718 | homeIntent.resolveType(mService.mContext.getContentResolver()), 0, userId); |
| 719 | if (homeActivity != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 720 | continue; |
| 721 | } |
| 722 | |
| 723 | PackageParser.Package syncAdapterPackage = getSystemPackageLPr(syncAdapterPackageName); |
| 724 | if (syncAdapterPackage != null) { |
| 725 | syncAdapterPackages.add(syncAdapterPackage); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | return syncAdapterPackages; |
| 730 | } |
| 731 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 732 | private PackageParser.Package getDefaultProviderAuthorityPackageLPr( |
| 733 | String authority, int userId) { |
| 734 | ProviderInfo provider = mService.resolveContentProvider(authority, 0, userId); |
| 735 | if (provider != null) { |
| 736 | return getSystemPackageLPr(provider.packageName); |
| 737 | } |
| 738 | return null; |
| 739 | } |
| 740 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 741 | private PackageParser.Package getPackageLPr(String packageName) { |
| 742 | return mService.mPackages.get(packageName); |
| 743 | } |
| 744 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 745 | private PackageParser.Package getSystemPackageLPr(String packageName) { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 746 | PackageParser.Package pkg = getPackageLPr(packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 747 | if (pkg != null && pkg.isSystemApp()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 748 | return !isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) ? pkg : null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 749 | } |
| 750 | return null; |
| 751 | } |
| 752 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 753 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 754 | int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 755 | grantRuntimePermissionsLPw(pkg, permissions, false, false, userId); |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 759 | boolean systemFixed, int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 760 | grantRuntimePermissionsLPw(pkg, permissions, systemFixed, false, userId); |
| 761 | } |
| 762 | |
| 763 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 764 | boolean systemFixed, boolean overrideUserChoice, int userId) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 765 | if (pkg.requestedPermissions.isEmpty()) { |
| 766 | return; |
| 767 | } |
| 768 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 769 | List<String> requestedPermissions = pkg.requestedPermissions; |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 770 | Set<String> grantablePermissions = null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 771 | |
| 772 | if (pkg.isUpdatedSystemApp()) { |
| 773 | PackageSetting sysPs = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
| 774 | if (sysPs != null) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 775 | if (sysPs.pkg.requestedPermissions.isEmpty()) { |
| 776 | return; |
| 777 | } |
| 778 | if (!requestedPermissions.equals(sysPs.pkg.requestedPermissions)) { |
| 779 | grantablePermissions = new ArraySet<>(requestedPermissions); |
| 780 | requestedPermissions = sysPs.pkg.requestedPermissions; |
| 781 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 785 | final int grantablePermissionCount = requestedPermissions.size(); |
| 786 | for (int i = 0; i < grantablePermissionCount; i++) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 787 | String permission = requestedPermissions.get(i); |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 788 | |
| 789 | // If there is a disabled system app it may request a permission the updated |
| 790 | // version ot the data partition doesn't, In this case skip the permission. |
| 791 | if (grantablePermissions != null && !grantablePermissions.contains(permission)) { |
| 792 | continue; |
| 793 | } |
| 794 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 795 | if (permissions.contains(permission)) { |
| 796 | final int flags = mService.getPermissionFlags(permission, pkg.packageName, userId); |
| 797 | |
| 798 | // If any flags are set to the permission, then it is either set in |
| 799 | // its current state by the system or device/profile owner or the user. |
| 800 | // In all these cases we do not want to clobber the current state. |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 801 | // Unless the caller wants to override user choices. The override is |
| 802 | // to make sure we can grant the needed permission to the default |
| 803 | // sms and phone apps after the user chooses this in the UI. |
| 804 | if (flags == 0 || overrideUserChoice) { |
| 805 | // Never clobber policy or system. |
| 806 | final int fixedFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED |
| 807 | | PackageManager.FLAG_PERMISSION_POLICY_FIXED; |
| 808 | if ((flags & fixedFlags) != 0) { |
| 809 | continue; |
| 810 | } |
| 811 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 812 | mService.grantRuntimePermission(pkg.packageName, permission, userId); |
| 813 | if (DEBUG) { |
Svetoslav | 5db602f | 2015-11-02 18:40:18 -0800 | [diff] [blame] | 814 | Log.i(TAG, "Granted " + (systemFixed ? "fixed " : "not fixed ") |
| 815 | + permission + " to default handler " + pkg.packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 816 | } |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 817 | |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 818 | int newFlags = PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 819 | if (systemFixed) { |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 820 | newFlags |= PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 821 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 822 | |
| 823 | mService.updatePermissionFlags(permission, pkg.packageName, |
| 824 | newFlags, newFlags, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 825 | } |
Svetoslav | 5db602f | 2015-11-02 18:40:18 -0800 | [diff] [blame] | 826 | |
| 827 | // If a component gets a permission for being the default handler A |
| 828 | // and also default handler B, we grant the weaker grant form. |
| 829 | if ((flags & PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0 |
| 830 | && (flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0 |
| 831 | && !systemFixed) { |
| 832 | if (DEBUG) { |
| 833 | Log.i(TAG, "Granted not fixed " + permission + " to default handler " |
| 834 | + pkg.packageName); |
| 835 | } |
| 836 | mService.updatePermissionFlags(permission, pkg.packageName, |
| 837 | PackageManager.FLAG_PERMISSION_SYSTEM_FIXED, 0, userId); |
| 838 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | } |
| 842 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 843 | private boolean isSysComponentOrPersistentPlatformSignedPrivAppLPr(PackageParser.Package pkg) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 844 | if (UserHandle.getAppId(pkg.applicationInfo.uid) < FIRST_APPLICATION_UID) { |
| 845 | return true; |
| 846 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 847 | if (!pkg.isPrivilegedApp()) { |
| 848 | return false; |
| 849 | } |
| 850 | PackageSetting sysPkg = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
Svet Ganov | f443384 | 2015-11-17 11:53:18 -0800 | [diff] [blame^] | 851 | if (sysPkg != null && sysPkg.pkg != null) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 852 | if ((sysPkg.pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
| 853 | return false; |
| 854 | } |
| 855 | } else if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 856 | return false; |
| 857 | } |
| 858 | return PackageManagerService.compareSignatures(mService.mPlatformPackage.mSignatures, |
| 859 | pkg.mSignatures) == PackageManager.SIGNATURE_MATCH; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | private static boolean doesPackageSupportRuntimePermissions(PackageParser.Package pkg) { |
| 863 | return pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1; |
| 864 | } |
| 865 | } |