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