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