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