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 | cd94602 | 2015-09-12 10:19:54 -0700 | [diff] [blame] | 248 | grantRuntimePermissionsLPw(verifierPackage, PHONE_PERMISSIONS, false, userId); |
| 249 | grantRuntimePermissionsLPw(verifierPackage, SMS_PERMISSIONS, false, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | // SetupWizard |
| 253 | Intent setupIntent = new Intent(Intent.ACTION_MAIN); |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 254 | setupIntent.addCategory(Intent.CATEGORY_SETUP_WIZARD); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 255 | PackageParser.Package setupPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 256 | setupIntent, userId); |
| 257 | if (setupPackage != null |
| 258 | && doesPackageSupportRuntimePermissions(setupPackage)) { |
| 259 | grantRuntimePermissionsLPw(setupPackage, PHONE_PERMISSIONS, userId); |
| 260 | grantRuntimePermissionsLPw(setupPackage, CONTACTS_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 263 | // Camera |
| 264 | Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 265 | PackageParser.Package cameraPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 266 | cameraIntent, userId); |
| 267 | if (cameraPackage != null |
| 268 | && doesPackageSupportRuntimePermissions(cameraPackage)) { |
| 269 | grantRuntimePermissionsLPw(cameraPackage, CAMERA_PERMISSIONS, userId); |
| 270 | grantRuntimePermissionsLPw(cameraPackage, MICROPHONE_PERMISSIONS, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 271 | grantRuntimePermissionsLPw(cameraPackage, STORAGE_PERMISSIONS, userId); |
| 272 | } |
| 273 | |
| 274 | // Media provider |
| 275 | PackageParser.Package mediaStorePackage = getDefaultProviderAuthorityPackageLPr( |
| 276 | MediaStore.AUTHORITY, userId); |
| 277 | if (mediaStorePackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 278 | grantRuntimePermissionsLPw(mediaStorePackage, STORAGE_PERMISSIONS, true, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // Downloads provider |
| 282 | PackageParser.Package downloadsPackage = getDefaultProviderAuthorityPackageLPr( |
| 283 | "downloads", userId); |
| 284 | if (downloadsPackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 285 | grantRuntimePermissionsLPw(downloadsPackage, STORAGE_PERMISSIONS, true, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | // Downloads UI |
| 289 | Intent downloadsUiIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 290 | PackageParser.Package downloadsUiPackage = getDefaultSystemHandlerActivityPackageLPr( |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 291 | downloadsUiIntent, userId); |
| 292 | if (downloadsUiPackage != null |
| 293 | && doesPackageSupportRuntimePermissions(downloadsUiPackage)) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 294 | grantRuntimePermissionsLPw(downloadsUiPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 297 | // Storage provider |
| 298 | PackageParser.Package storagePackage = getDefaultProviderAuthorityPackageLPr( |
| 299 | "com.android.externalstorage.documents", userId); |
| 300 | if (storagePackage != null) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 301 | grantRuntimePermissionsLPw(storagePackage, STORAGE_PERMISSIONS, true, userId); |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Svetoslav | 0e62952 | 2015-08-05 19:14:47 -0700 | [diff] [blame] | 304 | // CertInstaller |
| 305 | Intent certInstallerIntent = new Intent(Credentials.INSTALL_ACTION); |
| 306 | PackageParser.Package certInstallerPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 307 | certInstallerIntent, userId); |
| 308 | if (certInstallerPackage != null |
| 309 | && doesPackageSupportRuntimePermissions(certInstallerPackage)) { |
| 310 | grantRuntimePermissionsLPw(certInstallerPackage, STORAGE_PERMISSIONS, true, userId); |
| 311 | } |
| 312 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 313 | // Dialer |
| 314 | if (dialerAppPackageNames == null) { |
| 315 | Intent dialerIntent = new Intent(Intent.ACTION_DIAL); |
| 316 | PackageParser.Package dialerPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 317 | dialerIntent, userId); |
| 318 | if (dialerPackage != null) { |
| 319 | grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId); |
| 320 | } |
| 321 | } else { |
| 322 | for (String dialerAppPackageName : dialerAppPackageNames) { |
| 323 | PackageParser.Package dialerPackage = getSystemPackageLPr(dialerAppPackageName); |
| 324 | if (dialerPackage != null) { |
| 325 | grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId); |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 330 | // Sim call manager |
| 331 | if (simCallManagerPackageNames != null) { |
| 332 | for (String simCallManagerPackageName : simCallManagerPackageNames) { |
| 333 | PackageParser.Package simCallManagerPackage = |
| 334 | getSystemPackageLPr(simCallManagerPackageName); |
| 335 | if (simCallManagerPackage != null) { |
| 336 | grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, |
| 337 | userId); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 342 | // SMS |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 343 | if (smsAppPackageNames == null) { |
| 344 | Intent smsIntent = new Intent(Intent.ACTION_MAIN); |
| 345 | smsIntent.addCategory(Intent.CATEGORY_APP_MESSAGING); |
| 346 | PackageParser.Package smsPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 347 | smsIntent, userId); |
| 348 | if (smsPackage != null) { |
| 349 | grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId); |
| 350 | } |
| 351 | } else { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 352 | for (String smsPackageName : smsAppPackageNames) { |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 353 | PackageParser.Package smsPackage = getSystemPackageLPr(smsPackageName); |
| 354 | if (smsPackage != null) { |
| 355 | grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 360 | // Cell Broadcast Receiver |
| 361 | Intent cbrIntent = new Intent(Intents.SMS_CB_RECEIVED_ACTION); |
| 362 | PackageParser.Package cbrPackage = |
| 363 | getDefaultSystemHandlerActivityPackageLPr(cbrIntent, userId); |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 364 | if (cbrPackage != null && doesPackageSupportRuntimePermissions(cbrPackage)) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 365 | grantRuntimePermissionsLPw(cbrPackage, SMS_PERMISSIONS, userId); |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Junda Liu | d878f53 | 2015-08-13 14:25:49 -0700 | [diff] [blame] | 368 | // Carrier Provisioning Service |
| 369 | Intent carrierProvIntent = new Intent(Intents.SMS_CARRIER_PROVISION_ACTION); |
| 370 | PackageParser.Package carrierProvPackage = |
| 371 | getDefaultSystemHandlerServicePackageLPr(carrierProvIntent, userId); |
| 372 | if (carrierProvPackage != null && doesPackageSupportRuntimePermissions(carrierProvPackage)) { |
| 373 | grantRuntimePermissionsLPw(carrierProvPackage, SMS_PERMISSIONS, false, userId); |
| 374 | } |
| 375 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 376 | // Calendar |
| 377 | Intent calendarIntent = new Intent(Intent.ACTION_MAIN); |
| 378 | calendarIntent.addCategory(Intent.CATEGORY_APP_CALENDAR); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 379 | PackageParser.Package calendarPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 380 | calendarIntent, userId); |
| 381 | if (calendarPackage != null |
| 382 | && doesPackageSupportRuntimePermissions(calendarPackage)) { |
| 383 | grantRuntimePermissionsLPw(calendarPackage, CALENDAR_PERMISSIONS, userId); |
| 384 | grantRuntimePermissionsLPw(calendarPackage, CONTACTS_PERMISSIONS, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | // Calendar provider |
| 388 | PackageParser.Package calendarProviderPackage = getDefaultProviderAuthorityPackageLPr( |
| 389 | CalendarContract.AUTHORITY, userId); |
| 390 | if (calendarProviderPackage != null) { |
| 391 | grantRuntimePermissionsLPw(calendarProviderPackage, CONTACTS_PERMISSIONS, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 392 | grantRuntimePermissionsLPw(calendarProviderPackage, CALENDAR_PERMISSIONS, |
| 393 | true, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 394 | grantRuntimePermissionsLPw(calendarProviderPackage, STORAGE_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 397 | // Calendar provider sync adapters |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 398 | List<PackageParser.Package> calendarSyncAdapters = getHeadlessSyncAdapterPackagesLPr( |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 399 | calendarSyncAdapterPackages, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 400 | final int calendarSyncAdapterCount = calendarSyncAdapters.size(); |
| 401 | for (int i = 0; i < calendarSyncAdapterCount; i++) { |
| 402 | PackageParser.Package calendarSyncAdapter = calendarSyncAdapters.get(i); |
| 403 | if (doesPackageSupportRuntimePermissions(calendarSyncAdapter)) { |
| 404 | grantRuntimePermissionsLPw(calendarSyncAdapter, CALENDAR_PERMISSIONS, userId); |
| 405 | } |
| 406 | } |
| 407 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 408 | // Contacts |
| 409 | Intent contactsIntent = new Intent(Intent.ACTION_MAIN); |
| 410 | contactsIntent.addCategory(Intent.CATEGORY_APP_CONTACTS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 411 | PackageParser.Package contactsPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 412 | contactsIntent, userId); |
| 413 | if (contactsPackage != null |
| 414 | && doesPackageSupportRuntimePermissions(contactsPackage)) { |
| 415 | grantRuntimePermissionsLPw(contactsPackage, CONTACTS_PERMISSIONS, userId); |
| 416 | grantRuntimePermissionsLPw(contactsPackage, PHONE_PERMISSIONS, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 419 | // Contacts provider sync adapters |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 420 | List<PackageParser.Package> contactsSyncAdapters = getHeadlessSyncAdapterPackagesLPr( |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 421 | contactsSyncAdapterPackages, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 422 | final int contactsSyncAdapterCount = contactsSyncAdapters.size(); |
| 423 | for (int i = 0; i < contactsSyncAdapterCount; i++) { |
| 424 | PackageParser.Package contactsSyncAdapter = contactsSyncAdapters.get(i); |
| 425 | if (doesPackageSupportRuntimePermissions(contactsSyncAdapter)) { |
| 426 | grantRuntimePermissionsLPw(contactsSyncAdapter, CONTACTS_PERMISSIONS, userId); |
| 427 | } |
| 428 | } |
| 429 | |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 430 | // Contacts provider |
| 431 | PackageParser.Package contactsProviderPackage = getDefaultProviderAuthorityPackageLPr( |
| 432 | ContactsContract.AUTHORITY, userId); |
| 433 | if (contactsProviderPackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 434 | grantRuntimePermissionsLPw(contactsProviderPackage, CONTACTS_PERMISSIONS, |
| 435 | true, userId); |
Makoto Onuki | 7a4082e | 2015-07-06 16:59:36 -0700 | [diff] [blame] | 436 | grantRuntimePermissionsLPw(contactsProviderPackage, PHONE_PERMISSIONS, |
| 437 | true, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 438 | grantRuntimePermissionsLPw(contactsProviderPackage, STORAGE_PERMISSIONS, userId); |
| 439 | } |
| 440 | |
| 441 | // Device provisioning |
| 442 | Intent deviceProvisionIntent = new Intent( |
| 443 | DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE); |
Svet Ganov | b6e0013 | 2015-06-29 20:19:25 -0700 | [diff] [blame] | 444 | PackageParser.Package deviceProvisionPackage = |
| 445 | getDefaultSystemHandlerActivityPackageLPr(deviceProvisionIntent, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 446 | if (deviceProvisionPackage != null |
| 447 | && doesPackageSupportRuntimePermissions(deviceProvisionPackage)) { |
Makoto Onuki | bc92479 | 2015-07-16 11:38:00 -0700 | [diff] [blame] | 448 | grantRuntimePermissionsLPw(deviceProvisionPackage, CONTACTS_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | // Maps |
| 452 | Intent mapsIntent = new Intent(Intent.ACTION_MAIN); |
| 453 | mapsIntent.addCategory(Intent.CATEGORY_APP_MAPS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 454 | PackageParser.Package mapsPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 455 | mapsIntent, userId); |
| 456 | if (mapsPackage != null |
| 457 | && doesPackageSupportRuntimePermissions(mapsPackage)) { |
| 458 | grantRuntimePermissionsLPw(mapsPackage, LOCATION_PERMISSIONS, userId); |
| 459 | } |
| 460 | |
Svet Ganov | 200d494 | 2015-07-01 20:46:02 -0700 | [diff] [blame] | 461 | // Gallery |
| 462 | Intent galleryIntent = new Intent(Intent.ACTION_MAIN); |
| 463 | galleryIntent.addCategory(Intent.CATEGORY_APP_GALLERY); |
| 464 | PackageParser.Package galleryPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 465 | galleryIntent, userId); |
| 466 | if (galleryPackage != null |
| 467 | && doesPackageSupportRuntimePermissions(galleryPackage)) { |
| 468 | grantRuntimePermissionsLPw(galleryPackage, STORAGE_PERMISSIONS, userId); |
| 469 | } |
| 470 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 471 | // Email |
| 472 | Intent emailIntent = new Intent(Intent.ACTION_MAIN); |
| 473 | emailIntent.addCategory(Intent.CATEGORY_APP_EMAIL); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 474 | PackageParser.Package emailPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 475 | emailIntent, userId); |
| 476 | if (emailPackage != null |
| 477 | && doesPackageSupportRuntimePermissions(emailPackage)) { |
| 478 | grantRuntimePermissionsLPw(emailPackage, CONTACTS_PERMISSIONS, userId); |
| 479 | } |
| 480 | |
| 481 | // Browser |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 482 | PackageParser.Package browserPackage = null; |
| 483 | String defaultBrowserPackage = mService.getDefaultBrowserPackageName(userId); |
| 484 | if (defaultBrowserPackage != null) { |
| 485 | browserPackage = getPackageLPr(defaultBrowserPackage); |
| 486 | } |
| 487 | if (browserPackage == null) { |
| 488 | Intent browserIntent = new Intent(Intent.ACTION_MAIN); |
| 489 | browserIntent.addCategory(Intent.CATEGORY_APP_BROWSER); |
| 490 | browserPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 491 | browserIntent, userId); |
| 492 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 493 | if (browserPackage != null |
| 494 | && doesPackageSupportRuntimePermissions(browserPackage)) { |
| 495 | grantRuntimePermissionsLPw(browserPackage, LOCATION_PERMISSIONS, userId); |
| 496 | } |
| 497 | |
| 498 | // IME |
| 499 | if (imePackageNames != null) { |
| 500 | for (String imePackageName : imePackageNames) { |
| 501 | PackageParser.Package imePackage = getSystemPackageLPr(imePackageName); |
| 502 | if (imePackage != null |
| 503 | && doesPackageSupportRuntimePermissions(imePackage)) { |
| 504 | grantRuntimePermissionsLPw(imePackage, CONTACTS_PERMISSIONS, userId); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | // Voice interaction |
| 510 | if (voiceInteractPackageNames != null) { |
| 511 | for (String voiceInteractPackageName : voiceInteractPackageNames) { |
| 512 | PackageParser.Package voiceInteractPackage = getSystemPackageLPr( |
| 513 | voiceInteractPackageName); |
| 514 | if (voiceInteractPackage != null |
| 515 | && doesPackageSupportRuntimePermissions(voiceInteractPackage)) { |
| 516 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 517 | CONTACTS_PERMISSIONS, userId); |
| 518 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 519 | CALENDAR_PERMISSIONS, userId); |
| 520 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 521 | MICROPHONE_PERMISSIONS, userId); |
| 522 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 523 | PHONE_PERMISSIONS, userId); |
| 524 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 525 | SMS_PERMISSIONS, userId); |
| 526 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 527 | LOCATION_PERMISSIONS, userId); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 532 | // Voice recognition |
| 533 | Intent voiceRecoIntent = new Intent("android.speech.RecognitionService"); |
| 534 | voiceRecoIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 535 | PackageParser.Package voiceRecoPackage = getDefaultSystemHandlerServicePackageLPr( |
| 536 | voiceRecoIntent, userId); |
| 537 | if (voiceRecoPackage != null |
| 538 | && doesPackageSupportRuntimePermissions(voiceRecoPackage)) { |
| 539 | grantRuntimePermissionsLPw(voiceRecoPackage, MICROPHONE_PERMISSIONS, userId); |
| 540 | } |
| 541 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 542 | // Location |
| 543 | if (locationPackageNames != null) { |
| 544 | for (String packageName : locationPackageNames) { |
| 545 | PackageParser.Package locationPackage = getSystemPackageLPr(packageName); |
| 546 | if (locationPackage != null |
| 547 | && doesPackageSupportRuntimePermissions(locationPackage)) { |
| 548 | grantRuntimePermissionsLPw(locationPackage, CONTACTS_PERMISSIONS, userId); |
| 549 | grantRuntimePermissionsLPw(locationPackage, CALENDAR_PERMISSIONS, userId); |
| 550 | grantRuntimePermissionsLPw(locationPackage, MICROPHONE_PERMISSIONS, userId); |
| 551 | grantRuntimePermissionsLPw(locationPackage, PHONE_PERMISSIONS, userId); |
| 552 | grantRuntimePermissionsLPw(locationPackage, SMS_PERMISSIONS, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 553 | grantRuntimePermissionsLPw(locationPackage, LOCATION_PERMISSIONS, |
| 554 | true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 555 | grantRuntimePermissionsLPw(locationPackage, CAMERA_PERMISSIONS, userId); |
| 556 | grantRuntimePermissionsLPw(locationPackage, SENSORS_PERMISSIONS, userId); |
| 557 | grantRuntimePermissionsLPw(locationPackage, STORAGE_PERMISSIONS, userId); |
| 558 | } |
| 559 | } |
| 560 | } |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 561 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 562 | // Music |
| 563 | Intent musicIntent = new Intent(Intent.ACTION_VIEW); |
| 564 | musicIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 565 | musicIntent.setDataAndType(Uri.fromFile(new File("foo.mp3")), |
| 566 | AUDIO_MIME_TYPE); |
| 567 | PackageParser.Package musicPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 568 | musicIntent, userId); |
| 569 | if (musicPackage != null |
| 570 | && doesPackageSupportRuntimePermissions(musicPackage)) { |
| 571 | grantRuntimePermissionsLPw(musicPackage, STORAGE_PERMISSIONS, userId); |
| 572 | } |
| 573 | |
Anthony Hugh | 979b81a | 2015-09-29 16:50:35 -0700 | [diff] [blame^] | 574 | // Android Wear Home |
| 575 | if (mService.hasSystemFeature(PackageManager.FEATURE_WATCH)) { |
| 576 | Intent homeIntent = new Intent(Intent.ACTION_MAIN); |
| 577 | homeIntent.addCategory(Intent.CATEGORY_HOME_MAIN); |
| 578 | |
| 579 | PackageParser.Package wearHomePackage = getDefaultSystemHandlerActivityPackageLPr( |
| 580 | homeIntent, userId); |
| 581 | |
| 582 | if (wearHomePackage != null |
| 583 | && doesPackageSupportRuntimePermissions(wearHomePackage)) { |
| 584 | grantRuntimePermissionsLPw(wearHomePackage, CONTACTS_PERMISSIONS, false, |
| 585 | userId); |
| 586 | grantRuntimePermissionsLPw(wearHomePackage, PHONE_PERMISSIONS, true, userId); |
| 587 | grantRuntimePermissionsLPw(wearHomePackage, MICROPHONE_PERMISSIONS, false, |
| 588 | userId); |
| 589 | } |
| 590 | } |
| 591 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 592 | mService.mSettings.onDefaultRuntimePermissionsGrantedLPr(userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 596 | private void grantDefaultPermissionsToDefaultSystemDialerAppLPr( |
| 597 | PackageParser.Package dialerPackage, int userId) { |
| 598 | if (doesPackageSupportRuntimePermissions(dialerPackage)) { |
| 599 | grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, userId); |
| 600 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, userId); |
| 601 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, userId); |
| 602 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, userId); |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | |
| 607 | private void grantDefaultPermissionsToDefaultSystemSmsAppLPr( |
| 608 | PackageParser.Package smsPackage, int userId) { |
| 609 | if (doesPackageSupportRuntimePermissions(smsPackage)) { |
| 610 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, userId); |
| 611 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, userId); |
| 612 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, userId); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 617 | public void grantDefaultPermissionsToDefaultSmsAppLPr(String packageName, int userId) { |
| 618 | Log.i(TAG, "Granting permissions to default sms app for user:" + userId); |
| 619 | if (packageName == null) { |
| 620 | return; |
| 621 | } |
| 622 | PackageParser.Package smsPackage = getPackageLPr(packageName); |
| 623 | if (smsPackage != null && doesPackageSupportRuntimePermissions(smsPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 624 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, false, true, userId); |
| 625 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 626 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
| 630 | public void grantDefaultPermissionsToDefaultDialerAppLPr(String packageName, int userId) { |
| 631 | Log.i(TAG, "Granting permissions to default dialer app for user:" + userId); |
| 632 | if (packageName == null) { |
| 633 | return; |
| 634 | } |
| 635 | PackageParser.Package dialerPackage = getPackageLPr(packageName); |
| 636 | if (dialerPackage != null |
| 637 | && doesPackageSupportRuntimePermissions(dialerPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 638 | grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, false, true, userId); |
| 639 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 640 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, false, true, userId); |
| 641 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 645 | private void grantDefaultPermissionsToDefaultSimCallManagerLPr( |
| 646 | PackageParser.Package simCallManagerPackage, int userId) { |
| 647 | Log.i(TAG, "Granting permissions to sim call manager for user:" + userId); |
| 648 | if (doesPackageSupportRuntimePermissions(simCallManagerPackage)) { |
| 649 | grantRuntimePermissionsLPw(simCallManagerPackage, PHONE_PERMISSIONS, userId); |
| 650 | grantRuntimePermissionsLPw(simCallManagerPackage, MICROPHONE_PERMISSIONS, userId); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | public void grantDefaultPermissionsToDefaultSimCallManagerLPr(String packageName, int userId) { |
| 655 | if (packageName == null) { |
| 656 | return; |
| 657 | } |
| 658 | PackageParser.Package simCallManagerPackage = getPackageLPr(packageName); |
| 659 | if (simCallManagerPackage != null) { |
| 660 | grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, userId); |
| 661 | } |
| 662 | } |
| 663 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 664 | public void grantDefaultPermissionsToEnabledCarrierAppsLPr(String[] packageNames, int userId) { |
| 665 | Log.i(TAG, "Granting permissions to enabled carrier apps for user:" + userId); |
| 666 | if (packageNames == null) { |
| 667 | return; |
| 668 | } |
| 669 | for (String packageName : packageNames) { |
| 670 | PackageParser.Package carrierPackage = getSystemPackageLPr(packageName); |
| 671 | if (carrierPackage != null |
| 672 | && doesPackageSupportRuntimePermissions(carrierPackage)) { |
| 673 | grantRuntimePermissionsLPw(carrierPackage, PHONE_PERMISSIONS, userId); |
| 674 | grantRuntimePermissionsLPw(carrierPackage, LOCATION_PERMISSIONS, userId); |
Shishir Agrawal | ad63247 | 2015-07-29 16:54:07 -0700 | [diff] [blame] | 675 | grantRuntimePermissionsLPw(carrierPackage, SMS_PERMISSIONS, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | public void grantDefaultPermissionsToDefaultBrowserLPr(String packageName, int userId) { |
| 681 | Log.i(TAG, "Granting permissions to default browser for user:" + userId); |
| 682 | if (packageName == null) { |
| 683 | return; |
| 684 | } |
| 685 | PackageParser.Package browserPackage = getSystemPackageLPr(packageName); |
| 686 | if (browserPackage != null |
| 687 | && doesPackageSupportRuntimePermissions(browserPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 688 | grantRuntimePermissionsLPw(browserPackage, LOCATION_PERMISSIONS, false, false, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 692 | private PackageParser.Package getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 693 | Intent intent, int userId) { |
Svetoslav | 8b24a1d | 2015-07-13 17:37:32 -0700 | [diff] [blame] | 694 | List<ResolveInfo> handlers = mService.mActivities.queryIntent(intent, |
| 695 | intent.resolveType(mService.mContext.getContentResolver()), |
| 696 | PackageManager.GET_DISABLED_COMPONENTS, userId); |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 697 | if (handlers == null) { |
| 698 | return null; |
| 699 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 700 | final int handlerCount = handlers.size(); |
| 701 | for (int i = 0; i < handlerCount; i++) { |
| 702 | ResolveInfo handler = handlers.get(i); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 703 | PackageParser.Package handlerPackage = getSystemPackageLPr( |
| 704 | handler.activityInfo.packageName); |
| 705 | if (handlerPackage != null) { |
| 706 | return handlerPackage; |
| 707 | } |
| 708 | } |
| 709 | return null; |
| 710 | } |
| 711 | |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 712 | private PackageParser.Package getDefaultSystemHandlerServicePackageLPr( |
| 713 | Intent intent, int userId) { |
| 714 | List<ResolveInfo> handlers = mService.queryIntentServices(intent, |
| 715 | intent.resolveType(mService.mContext.getContentResolver()), |
| 716 | PackageManager.GET_DISABLED_COMPONENTS, userId); |
| 717 | if (handlers == null) { |
| 718 | return null; |
| 719 | } |
| 720 | final int handlerCount = handlers.size(); |
| 721 | for (int i = 0; i < handlerCount; i++) { |
| 722 | ResolveInfo handler = handlers.get(i); |
| 723 | PackageParser.Package handlerPackage = getSystemPackageLPr( |
| 724 | handler.serviceInfo.packageName); |
| 725 | if (handlerPackage != null) { |
| 726 | return handlerPackage; |
| 727 | } |
| 728 | } |
| 729 | return null; |
| 730 | } |
| 731 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 732 | private List<PackageParser.Package> getHeadlessSyncAdapterPackagesLPr( |
| 733 | String[] syncAdapterPackageNames, int userId) { |
| 734 | List<PackageParser.Package> syncAdapterPackages = new ArrayList<>(); |
| 735 | |
| 736 | Intent homeIntent = new Intent(Intent.ACTION_MAIN); |
Svet Ganov | 05069b9 | 2015-08-01 12:19:26 -0700 | [diff] [blame] | 737 | homeIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 738 | |
| 739 | for (String syncAdapterPackageName : syncAdapterPackageNames) { |
| 740 | homeIntent.setPackage(syncAdapterPackageName); |
| 741 | |
Svetoslav | 8b24a1d | 2015-07-13 17:37:32 -0700 | [diff] [blame] | 742 | List<ResolveInfo> homeActivities = mService.mActivities.queryIntent(homeIntent, |
| 743 | homeIntent.resolveType(mService.mContext.getContentResolver()), |
| 744 | PackageManager.GET_DISABLED_COMPONENTS, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 745 | if (!homeActivities.isEmpty()) { |
| 746 | continue; |
| 747 | } |
| 748 | |
| 749 | PackageParser.Package syncAdapterPackage = getSystemPackageLPr(syncAdapterPackageName); |
| 750 | if (syncAdapterPackage != null) { |
| 751 | syncAdapterPackages.add(syncAdapterPackage); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | return syncAdapterPackages; |
| 756 | } |
| 757 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 758 | private PackageParser.Package getDefaultProviderAuthorityPackageLPr( |
| 759 | String authority, int userId) { |
| 760 | ProviderInfo provider = mService.resolveContentProvider(authority, 0, userId); |
| 761 | if (provider != null) { |
| 762 | return getSystemPackageLPr(provider.packageName); |
| 763 | } |
| 764 | return null; |
| 765 | } |
| 766 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 767 | private PackageParser.Package getPackageLPr(String packageName) { |
| 768 | return mService.mPackages.get(packageName); |
| 769 | } |
| 770 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 771 | private PackageParser.Package getSystemPackageLPr(String packageName) { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 772 | PackageParser.Package pkg = getPackageLPr(packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 773 | if (pkg != null && pkg.isSystemApp()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 774 | return !isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) ? pkg : null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 775 | } |
| 776 | return null; |
| 777 | } |
| 778 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 779 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 780 | int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 781 | grantRuntimePermissionsLPw(pkg, permissions, false, false, userId); |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 785 | boolean systemFixed, int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 786 | grantRuntimePermissionsLPw(pkg, permissions, systemFixed, false, userId); |
| 787 | } |
| 788 | |
| 789 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 790 | boolean systemFixed, boolean overrideUserChoice, int userId) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 791 | if (pkg.requestedPermissions.isEmpty()) { |
| 792 | return; |
| 793 | } |
| 794 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 795 | List<String> requestedPermissions = pkg.requestedPermissions; |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 796 | Set<String> grantablePermissions = null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 797 | |
| 798 | if (pkg.isUpdatedSystemApp()) { |
| 799 | PackageSetting sysPs = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
| 800 | if (sysPs != null) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 801 | if (sysPs.pkg.requestedPermissions.isEmpty()) { |
| 802 | return; |
| 803 | } |
| 804 | if (!requestedPermissions.equals(sysPs.pkg.requestedPermissions)) { |
| 805 | grantablePermissions = new ArraySet<>(requestedPermissions); |
| 806 | requestedPermissions = sysPs.pkg.requestedPermissions; |
| 807 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 811 | final int grantablePermissionCount = requestedPermissions.size(); |
| 812 | for (int i = 0; i < grantablePermissionCount; i++) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 813 | String permission = requestedPermissions.get(i); |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 814 | |
| 815 | // If there is a disabled system app it may request a permission the updated |
| 816 | // version ot the data partition doesn't, In this case skip the permission. |
| 817 | if (grantablePermissions != null && !grantablePermissions.contains(permission)) { |
| 818 | continue; |
| 819 | } |
| 820 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 821 | if (permissions.contains(permission)) { |
| 822 | final int flags = mService.getPermissionFlags(permission, pkg.packageName, userId); |
| 823 | |
| 824 | // If any flags are set to the permission, then it is either set in |
| 825 | // its current state by the system or device/profile owner or the user. |
| 826 | // 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] | 827 | // Unless the caller wants to override user choices. The override is |
| 828 | // to make sure we can grant the needed permission to the default |
| 829 | // sms and phone apps after the user chooses this in the UI. |
| 830 | if (flags == 0 || overrideUserChoice) { |
| 831 | // Never clobber policy or system. |
| 832 | final int fixedFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED |
| 833 | | PackageManager.FLAG_PERMISSION_POLICY_FIXED; |
| 834 | if ((flags & fixedFlags) != 0) { |
| 835 | continue; |
| 836 | } |
| 837 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 838 | mService.grantRuntimePermission(pkg.packageName, permission, userId); |
| 839 | if (DEBUG) { |
| 840 | Log.i(TAG, "Granted " + permission + " to default handler " |
| 841 | + pkg.packageName); |
| 842 | } |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 843 | |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 844 | int newFlags = PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 845 | if (systemFixed) { |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 846 | newFlags |= PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 847 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 848 | |
| 849 | mService.updatePermissionFlags(permission, pkg.packageName, |
| 850 | newFlags, newFlags, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | } |
| 854 | } |
| 855 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 856 | private boolean isSysComponentOrPersistentPlatformSignedPrivAppLPr(PackageParser.Package pkg) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 857 | if (UserHandle.getAppId(pkg.applicationInfo.uid) < FIRST_APPLICATION_UID) { |
| 858 | return true; |
| 859 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 860 | if (!pkg.isPrivilegedApp()) { |
| 861 | return false; |
| 862 | } |
| 863 | PackageSetting sysPkg = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
| 864 | if (sysPkg != null) { |
| 865 | if ((sysPkg.pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
| 866 | return false; |
| 867 | } |
| 868 | } else if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 869 | return false; |
| 870 | } |
| 871 | return PackageManagerService.compareSignatures(mService.mPlatformPackage.mSignatures, |
| 872 | pkg.mSignatures) == PackageManager.SIGNATURE_MATCH; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | private static boolean doesPackageSupportRuntimePermissions(PackageParser.Package pkg) { |
| 876 | return pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1; |
| 877 | } |
| 878 | } |