Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.pm; |
| 18 | |
| 19 | import android.Manifest; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 20 | import android.app.DownloadManager; |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 21 | import android.app.admin.DevicePolicyManager; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 23 | import android.content.pm.ActivityInfo; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 24 | import android.content.pm.ApplicationInfo; |
| 25 | import android.content.pm.PackageManager; |
| 26 | import android.content.pm.PackageManagerInternal.PackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManagerInternal.SyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageParser; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 29 | import android.content.pm.ProviderInfo; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 30 | import android.content.pm.ResolveInfo; |
| 31 | import android.net.Uri; |
| 32 | import android.os.Build; |
| 33 | import android.os.UserHandle; |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 34 | import android.provider.CalendarContract; |
| 35 | import android.provider.ContactsContract; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 36 | import android.provider.MediaStore; |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 37 | import android.provider.Telephony.Sms.Intents; |
mariagpuyol | 2d29080 | 2016-02-23 18:06:36 -0800 | [diff] [blame] | 38 | import android.telephony.TelephonyManager; |
Svetoslav | 0e62952 | 2015-08-05 19:14:47 -0700 | [diff] [blame] | 39 | import android.security.Credentials; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 40 | import android.util.ArraySet; |
| 41 | import android.util.Log; |
| 42 | |
| 43 | import java.io.File; |
| 44 | import java.util.ArrayList; |
| 45 | import java.util.List; |
| 46 | import java.util.Set; |
| 47 | |
| 48 | import static android.os.Process.FIRST_APPLICATION_UID; |
| 49 | |
| 50 | /** |
| 51 | * This class is the policy for granting runtime permissions to |
| 52 | * platform components and default handlers in the system such |
| 53 | * that the device is usable out-of-the-box. For example, the |
| 54 | * shell UID is a part of the system and the Phone app should |
| 55 | * have phone related permission by default. |
| 56 | */ |
| 57 | final class DefaultPermissionGrantPolicy { |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 58 | private static final String TAG = "DefaultPermGrantPolicy"; // must be <= 23 chars |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 59 | private static final boolean DEBUG = false; |
| 60 | |
Jeff Sharkey | 2a9e3f8 | 2015-12-18 10:57:58 -0700 | [diff] [blame] | 61 | private static final int DEFAULT_FLAGS = PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE; |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 62 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 63 | private static final String AUDIO_MIME_TYPE = "audio/mpeg"; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 64 | |
| 65 | private static final Set<String> PHONE_PERMISSIONS = new ArraySet<>(); |
| 66 | static { |
| 67 | PHONE_PERMISSIONS.add(Manifest.permission.READ_PHONE_STATE); |
| 68 | PHONE_PERMISSIONS.add(Manifest.permission.CALL_PHONE); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 69 | PHONE_PERMISSIONS.add(Manifest.permission.READ_CALL_LOG); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 70 | PHONE_PERMISSIONS.add(Manifest.permission.WRITE_CALL_LOG); |
| 71 | PHONE_PERMISSIONS.add(Manifest.permission.ADD_VOICEMAIL); |
| 72 | PHONE_PERMISSIONS.add(Manifest.permission.USE_SIP); |
| 73 | PHONE_PERMISSIONS.add(Manifest.permission.PROCESS_OUTGOING_CALLS); |
| 74 | } |
| 75 | |
| 76 | private static final Set<String> CONTACTS_PERMISSIONS = new ArraySet<>(); |
| 77 | static { |
| 78 | CONTACTS_PERMISSIONS.add(Manifest.permission.READ_CONTACTS); |
| 79 | CONTACTS_PERMISSIONS.add(Manifest.permission.WRITE_CONTACTS); |
Svetoslav Ganov | 54a0cf1 | 2015-07-17 20:34:18 +0000 | [diff] [blame] | 80 | CONTACTS_PERMISSIONS.add(Manifest.permission.GET_ACCOUNTS); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | private static final Set<String> LOCATION_PERMISSIONS = new ArraySet<>(); |
| 84 | static { |
| 85 | LOCATION_PERMISSIONS.add(Manifest.permission.ACCESS_FINE_LOCATION); |
| 86 | LOCATION_PERMISSIONS.add(Manifest.permission.ACCESS_COARSE_LOCATION); |
| 87 | } |
| 88 | |
| 89 | private static final Set<String> CALENDAR_PERMISSIONS = new ArraySet<>(); |
| 90 | static { |
| 91 | CALENDAR_PERMISSIONS.add(Manifest.permission.READ_CALENDAR); |
| 92 | CALENDAR_PERMISSIONS.add(Manifest.permission.WRITE_CALENDAR); |
| 93 | } |
| 94 | |
| 95 | private static final Set<String> SMS_PERMISSIONS = new ArraySet<>(); |
| 96 | static { |
| 97 | SMS_PERMISSIONS.add(Manifest.permission.SEND_SMS); |
| 98 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_SMS); |
| 99 | SMS_PERMISSIONS.add(Manifest.permission.READ_SMS); |
| 100 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_WAP_PUSH); |
| 101 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_MMS); |
| 102 | SMS_PERMISSIONS.add(Manifest.permission.READ_CELL_BROADCASTS); |
| 103 | } |
| 104 | |
| 105 | private static final Set<String> MICROPHONE_PERMISSIONS = new ArraySet<>(); |
| 106 | static { |
| 107 | MICROPHONE_PERMISSIONS.add(Manifest.permission.RECORD_AUDIO); |
| 108 | } |
| 109 | |
| 110 | private static final Set<String> CAMERA_PERMISSIONS = new ArraySet<>(); |
| 111 | static { |
| 112 | CAMERA_PERMISSIONS.add(Manifest.permission.CAMERA); |
| 113 | } |
| 114 | |
| 115 | private static final Set<String> SENSORS_PERMISSIONS = new ArraySet<>(); |
| 116 | static { |
| 117 | SENSORS_PERMISSIONS.add(Manifest.permission.BODY_SENSORS); |
| 118 | } |
| 119 | |
| 120 | private static final Set<String> STORAGE_PERMISSIONS = new ArraySet<>(); |
| 121 | static { |
Svet Ganov | 975fa47 | 2015-06-22 20:45:31 -0700 | [diff] [blame] | 122 | STORAGE_PERMISSIONS.add(Manifest.permission.READ_EXTERNAL_STORAGE); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 123 | STORAGE_PERMISSIONS.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); |
| 124 | } |
| 125 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 126 | private final PackageManagerService mService; |
| 127 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 128 | private PackagesProvider mLocationPackagesProvider; |
| 129 | private PackagesProvider mVoiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 130 | private PackagesProvider mSmsAppPackagesProvider; |
| 131 | private PackagesProvider mDialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 132 | private PackagesProvider mSimCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 133 | private SyncAdapterPackagesProvider mSyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 134 | |
| 135 | public DefaultPermissionGrantPolicy(PackageManagerService service) { |
| 136 | mService = service; |
| 137 | } |
| 138 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 139 | public void setLocationPackagesProviderLPw(PackagesProvider provider) { |
| 140 | mLocationPackagesProvider = provider; |
| 141 | } |
| 142 | |
| 143 | public void setVoiceInteractionPackagesProviderLPw(PackagesProvider provider) { |
| 144 | mVoiceInteractionPackagesProvider = provider; |
| 145 | } |
| 146 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 147 | public void setSmsAppPackagesProviderLPw(PackagesProvider provider) { |
| 148 | mSmsAppPackagesProvider = provider; |
| 149 | } |
| 150 | |
| 151 | public void setDialerAppPackagesProviderLPw(PackagesProvider provider) { |
| 152 | mDialerAppPackagesProvider = provider; |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 155 | public void setSimCallManagerPackagesProviderLPw(PackagesProvider provider) { |
| 156 | mSimCallManagerPackagesProvider = provider; |
| 157 | } |
| 158 | |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 159 | public void setSyncAdapterPackagesProviderLPw(SyncAdapterPackagesProvider provider) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 160 | mSyncAdapterPackagesProvider = provider; |
| 161 | } |
| 162 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 163 | public void grantDefaultPermissions(int userId) { |
| 164 | grantPermissionsToSysComponentsAndPrivApps(userId); |
| 165 | grantDefaultSystemHandlerPermissions(userId); |
| 166 | } |
| 167 | |
| 168 | private void grantPermissionsToSysComponentsAndPrivApps(int userId) { |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 169 | Log.i(TAG, "Granting permissions to platform components for user " + userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 170 | |
| 171 | synchronized (mService.mPackages) { |
| 172 | for (PackageParser.Package pkg : mService.mPackages.values()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 173 | if (!isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) |
| 174 | || !doesPackageSupportRuntimePermissions(pkg) |
| 175 | || pkg.requestedPermissions.isEmpty()) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 176 | continue; |
| 177 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 178 | Set<String> permissions = new ArraySet<>(); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 179 | final int permissionCount = pkg.requestedPermissions.size(); |
| 180 | for (int i = 0; i < permissionCount; i++) { |
| 181 | String permission = pkg.requestedPermissions.get(i); |
| 182 | BasePermission bp = mService.mSettings.mPermissions.get(permission); |
| 183 | if (bp != null && bp.isRuntime()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 184 | permissions.add(permission); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 185 | } |
| 186 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 187 | if (!permissions.isEmpty()) { |
| 188 | grantRuntimePermissionsLPw(pkg, permissions, true, userId); |
| 189 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | private void grantDefaultSystemHandlerPermissions(int userId) { |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 195 | Log.i(TAG, "Granting permissions to default platform handlers for user " + userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 196 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 197 | final PackagesProvider locationPackagesProvider; |
| 198 | final PackagesProvider voiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 199 | final PackagesProvider smsAppPackagesProvider; |
| 200 | final PackagesProvider dialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 201 | final PackagesProvider simCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 202 | final SyncAdapterPackagesProvider syncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 203 | |
| 204 | synchronized (mService.mPackages) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 205 | locationPackagesProvider = mLocationPackagesProvider; |
| 206 | voiceInteractionPackagesProvider = mVoiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 207 | smsAppPackagesProvider = mSmsAppPackagesProvider; |
| 208 | dialerAppPackagesProvider = mDialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 209 | simCallManagerPackagesProvider = mSimCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 210 | syncAdapterPackagesProvider = mSyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 213 | String[] voiceInteractPackageNames = (voiceInteractionPackagesProvider != null) |
| 214 | ? voiceInteractionPackagesProvider.getPackages(userId) : null; |
| 215 | String[] locationPackageNames = (locationPackagesProvider != null) |
| 216 | ? locationPackagesProvider.getPackages(userId) : null; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 217 | String[] smsAppPackageNames = (smsAppPackagesProvider != null) |
| 218 | ? smsAppPackagesProvider.getPackages(userId) : null; |
| 219 | String[] dialerAppPackageNames = (dialerAppPackagesProvider != null) |
| 220 | ? dialerAppPackagesProvider.getPackages(userId) : null; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 221 | String[] simCallManagerPackageNames = (simCallManagerPackagesProvider != null) |
| 222 | ? simCallManagerPackagesProvider.getPackages(userId) : null; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 223 | String[] contactsSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? |
| 224 | syncAdapterPackagesProvider.getPackages(ContactsContract.AUTHORITY, userId) : null; |
| 225 | String[] calendarSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? |
| 226 | syncAdapterPackagesProvider.getPackages(CalendarContract.AUTHORITY, userId) : null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 227 | |
| 228 | synchronized (mService.mPackages) { |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 229 | // Installer |
| 230 | PackageParser.Package installerPackage = getSystemPackageLPr( |
| 231 | mService.mRequiredInstallerPackage); |
| 232 | if (installerPackage != null |
| 233 | && doesPackageSupportRuntimePermissions(installerPackage)) { |
| 234 | grantRuntimePermissionsLPw(installerPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 237 | // Verifier |
| 238 | PackageParser.Package verifierPackage = getSystemPackageLPr( |
| 239 | mService.mRequiredVerifierPackage); |
| 240 | if (verifierPackage != null |
| 241 | && doesPackageSupportRuntimePermissions(verifierPackage)) { |
| 242 | grantRuntimePermissionsLPw(verifierPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | cd94602 | 2015-09-12 10:19:54 -0700 | [diff] [blame] | 243 | grantRuntimePermissionsLPw(verifierPackage, PHONE_PERMISSIONS, false, userId); |
| 244 | grantRuntimePermissionsLPw(verifierPackage, SMS_PERMISSIONS, false, 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); |
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( |
| 582 | "com.android.printspooler"); |
| 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 | |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 598 | mService.mSettings.onDefaultRuntimePermissionsGrantedLPr(userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 602 | private void grantDefaultPermissionsToDefaultSystemDialerAppLPr( |
| 603 | PackageParser.Package dialerPackage, int userId) { |
| 604 | if (doesPackageSupportRuntimePermissions(dialerPackage)) { |
Anthony Hugh | d453992 | 2015-10-19 13:42:26 -0700 | [diff] [blame] | 605 | boolean isPhonePermFixed = |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 606 | mService.hasSystemFeature(PackageManager.FEATURE_WATCH, 0); |
Anthony Hugh | d453992 | 2015-10-19 13:42:26 -0700 | [diff] [blame] | 607 | grantRuntimePermissionsLPw( |
| 608 | dialerPackage, PHONE_PERMISSIONS, isPhonePermFixed, userId); |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 609 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, userId); |
| 610 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, userId); |
| 611 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, userId); |
| 612 | } |
| 613 | } |
| 614 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 615 | private void grantDefaultPermissionsToDefaultSystemSmsAppLPr( |
| 616 | PackageParser.Package smsPackage, int userId) { |
| 617 | if (doesPackageSupportRuntimePermissions(smsPackage)) { |
| 618 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, userId); |
| 619 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, userId); |
| 620 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, userId); |
| 621 | } |
| 622 | } |
| 623 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 624 | public void grantDefaultPermissionsToDefaultSmsAppLPr(String packageName, int userId) { |
| 625 | Log.i(TAG, "Granting permissions to default sms app for user:" + userId); |
| 626 | if (packageName == null) { |
| 627 | return; |
| 628 | } |
| 629 | PackageParser.Package smsPackage = getPackageLPr(packageName); |
| 630 | if (smsPackage != null && doesPackageSupportRuntimePermissions(smsPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 631 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, false, true, userId); |
| 632 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 633 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 634 | } |
| 635 | } |
| 636 | |
| 637 | public void grantDefaultPermissionsToDefaultDialerAppLPr(String packageName, int userId) { |
| 638 | Log.i(TAG, "Granting permissions to default dialer app for user:" + userId); |
| 639 | if (packageName == null) { |
| 640 | return; |
| 641 | } |
| 642 | PackageParser.Package dialerPackage = getPackageLPr(packageName); |
| 643 | if (dialerPackage != null |
| 644 | && doesPackageSupportRuntimePermissions(dialerPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 645 | grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, false, true, userId); |
| 646 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 647 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, false, true, userId); |
| 648 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 652 | private void grantDefaultPermissionsToDefaultSimCallManagerLPr( |
| 653 | PackageParser.Package simCallManagerPackage, int userId) { |
| 654 | Log.i(TAG, "Granting permissions to sim call manager for user:" + userId); |
| 655 | if (doesPackageSupportRuntimePermissions(simCallManagerPackage)) { |
| 656 | grantRuntimePermissionsLPw(simCallManagerPackage, PHONE_PERMISSIONS, userId); |
| 657 | grantRuntimePermissionsLPw(simCallManagerPackage, MICROPHONE_PERMISSIONS, userId); |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | public void grantDefaultPermissionsToDefaultSimCallManagerLPr(String packageName, int userId) { |
| 662 | if (packageName == null) { |
| 663 | return; |
| 664 | } |
| 665 | PackageParser.Package simCallManagerPackage = getPackageLPr(packageName); |
| 666 | if (simCallManagerPackage != null) { |
| 667 | grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, userId); |
| 668 | } |
| 669 | } |
| 670 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 671 | public void grantDefaultPermissionsToEnabledCarrierAppsLPr(String[] packageNames, int userId) { |
| 672 | Log.i(TAG, "Granting permissions to enabled carrier apps for user:" + userId); |
| 673 | if (packageNames == null) { |
| 674 | return; |
| 675 | } |
| 676 | for (String packageName : packageNames) { |
| 677 | PackageParser.Package carrierPackage = getSystemPackageLPr(packageName); |
| 678 | if (carrierPackage != null |
| 679 | && doesPackageSupportRuntimePermissions(carrierPackage)) { |
| 680 | grantRuntimePermissionsLPw(carrierPackage, PHONE_PERMISSIONS, userId); |
| 681 | grantRuntimePermissionsLPw(carrierPackage, LOCATION_PERMISSIONS, userId); |
Shishir Agrawal | ad63247 | 2015-07-29 16:54:07 -0700 | [diff] [blame] | 682 | grantRuntimePermissionsLPw(carrierPackage, SMS_PERMISSIONS, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | public void grantDefaultPermissionsToDefaultBrowserLPr(String packageName, int userId) { |
| 688 | Log.i(TAG, "Granting permissions to default browser for user:" + userId); |
| 689 | if (packageName == null) { |
| 690 | return; |
| 691 | } |
| 692 | PackageParser.Package browserPackage = getSystemPackageLPr(packageName); |
| 693 | if (browserPackage != null |
| 694 | && doesPackageSupportRuntimePermissions(browserPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 695 | grantRuntimePermissionsLPw(browserPackage, LOCATION_PERMISSIONS, false, false, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 699 | private PackageParser.Package getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 700 | Intent intent, int userId) { |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 701 | ResolveInfo handler = mService.resolveIntent(intent, |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 702 | intent.resolveType(mService.mContext.getContentResolver()), DEFAULT_FLAGS, userId); |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 703 | if (handler == null || handler.activityInfo == null) { |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 704 | return null; |
| 705 | } |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 706 | ActivityInfo activityInfo = handler.activityInfo; |
| 707 | if (activityInfo.packageName.equals(mService.mResolveActivity.packageName) |
| 708 | && activityInfo.name.equals(mService.mResolveActivity.name)) { |
| 709 | return null; |
Svetoslav Ganov | d2bbf1b | 2015-11-06 00:24:47 +0000 | [diff] [blame] | 710 | } |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 711 | return getSystemPackageLPr(handler.activityInfo.packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 714 | private PackageParser.Package getDefaultSystemHandlerServicePackageLPr( |
| 715 | Intent intent, int userId) { |
| 716 | List<ResolveInfo> handlers = mService.queryIntentServices(intent, |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 717 | intent.resolveType(mService.mContext.getContentResolver()), DEFAULT_FLAGS, userId); |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 718 | if (handlers == null) { |
| 719 | return null; |
| 720 | } |
| 721 | final int handlerCount = handlers.size(); |
| 722 | for (int i = 0; i < handlerCount; i++) { |
| 723 | ResolveInfo handler = handlers.get(i); |
| 724 | PackageParser.Package handlerPackage = getSystemPackageLPr( |
| 725 | handler.serviceInfo.packageName); |
| 726 | if (handlerPackage != null) { |
| 727 | return handlerPackage; |
| 728 | } |
| 729 | } |
| 730 | return null; |
| 731 | } |
| 732 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 733 | private List<PackageParser.Package> getHeadlessSyncAdapterPackagesLPr( |
| 734 | String[] syncAdapterPackageNames, int userId) { |
| 735 | List<PackageParser.Package> syncAdapterPackages = new ArrayList<>(); |
| 736 | |
| 737 | Intent homeIntent = new Intent(Intent.ACTION_MAIN); |
Svet Ganov | 05069b9 | 2015-08-01 12:19:26 -0700 | [diff] [blame] | 738 | homeIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 739 | |
| 740 | for (String syncAdapterPackageName : syncAdapterPackageNames) { |
| 741 | homeIntent.setPackage(syncAdapterPackageName); |
| 742 | |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 743 | ResolveInfo homeActivity = mService.resolveIntent(homeIntent, |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 744 | homeIntent.resolveType(mService.mContext.getContentResolver()), DEFAULT_FLAGS, |
| 745 | userId); |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 746 | if (homeActivity != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 747 | continue; |
| 748 | } |
| 749 | |
| 750 | PackageParser.Package syncAdapterPackage = getSystemPackageLPr(syncAdapterPackageName); |
| 751 | if (syncAdapterPackage != null) { |
| 752 | syncAdapterPackages.add(syncAdapterPackage); |
| 753 | } |
| 754 | } |
| 755 | |
| 756 | return syncAdapterPackages; |
| 757 | } |
| 758 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 759 | private PackageParser.Package getDefaultProviderAuthorityPackageLPr( |
| 760 | String authority, int userId) { |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 761 | ProviderInfo provider = mService.resolveContentProvider(authority, DEFAULT_FLAGS, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 762 | if (provider != null) { |
| 763 | return getSystemPackageLPr(provider.packageName); |
| 764 | } |
| 765 | return null; |
| 766 | } |
| 767 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 768 | private PackageParser.Package getPackageLPr(String packageName) { |
| 769 | return mService.mPackages.get(packageName); |
| 770 | } |
| 771 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 772 | private PackageParser.Package getSystemPackageLPr(String packageName) { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 773 | PackageParser.Package pkg = getPackageLPr(packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 774 | if (pkg != null && pkg.isSystemApp()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 775 | return !isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) ? pkg : null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 776 | } |
| 777 | return null; |
| 778 | } |
| 779 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 780 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 781 | int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 782 | grantRuntimePermissionsLPw(pkg, permissions, false, false, userId); |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 786 | boolean systemFixed, int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 787 | grantRuntimePermissionsLPw(pkg, permissions, systemFixed, false, userId); |
| 788 | } |
| 789 | |
| 790 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 791 | boolean systemFixed, boolean overrideUserChoice, int userId) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 792 | if (pkg.requestedPermissions.isEmpty()) { |
| 793 | return; |
| 794 | } |
| 795 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 796 | List<String> requestedPermissions = pkg.requestedPermissions; |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 797 | Set<String> grantablePermissions = null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 798 | |
| 799 | if (pkg.isUpdatedSystemApp()) { |
| 800 | PackageSetting sysPs = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
| 801 | if (sysPs != null) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 802 | if (sysPs.pkg.requestedPermissions.isEmpty()) { |
| 803 | return; |
| 804 | } |
| 805 | if (!requestedPermissions.equals(sysPs.pkg.requestedPermissions)) { |
| 806 | grantablePermissions = new ArraySet<>(requestedPermissions); |
| 807 | requestedPermissions = sysPs.pkg.requestedPermissions; |
| 808 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 812 | final int grantablePermissionCount = requestedPermissions.size(); |
| 813 | for (int i = 0; i < grantablePermissionCount; i++) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 814 | String permission = requestedPermissions.get(i); |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 815 | |
| 816 | // If there is a disabled system app it may request a permission the updated |
| 817 | // version ot the data partition doesn't, In this case skip the permission. |
| 818 | if (grantablePermissions != null && !grantablePermissions.contains(permission)) { |
| 819 | continue; |
| 820 | } |
| 821 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 822 | if (permissions.contains(permission)) { |
| 823 | final int flags = mService.getPermissionFlags(permission, pkg.packageName, userId); |
| 824 | |
| 825 | // If any flags are set to the permission, then it is either set in |
| 826 | // its current state by the system or device/profile owner or the user. |
| 827 | // 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] | 828 | // Unless the caller wants to override user choices. The override is |
| 829 | // to make sure we can grant the needed permission to the default |
| 830 | // sms and phone apps after the user chooses this in the UI. |
| 831 | if (flags == 0 || overrideUserChoice) { |
| 832 | // Never clobber policy or system. |
| 833 | final int fixedFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED |
| 834 | | PackageManager.FLAG_PERMISSION_POLICY_FIXED; |
| 835 | if ((flags & fixedFlags) != 0) { |
| 836 | continue; |
| 837 | } |
| 838 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 839 | mService.grantRuntimePermission(pkg.packageName, permission, userId); |
| 840 | if (DEBUG) { |
Svetoslav | 5db602f | 2015-11-02 18:40:18 -0800 | [diff] [blame] | 841 | Log.i(TAG, "Granted " + (systemFixed ? "fixed " : "not fixed ") |
| 842 | + permission + " to default handler " + pkg.packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 843 | } |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 844 | |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 845 | int newFlags = PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 846 | if (systemFixed) { |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 847 | newFlags |= PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 848 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 849 | |
| 850 | mService.updatePermissionFlags(permission, pkg.packageName, |
| 851 | newFlags, newFlags, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 852 | } |
Svetoslav | 5db602f | 2015-11-02 18:40:18 -0800 | [diff] [blame] | 853 | |
| 854 | // If a component gets a permission for being the default handler A |
| 855 | // and also default handler B, we grant the weaker grant form. |
| 856 | if ((flags & PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0 |
| 857 | && (flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0 |
| 858 | && !systemFixed) { |
| 859 | if (DEBUG) { |
| 860 | Log.i(TAG, "Granted not fixed " + permission + " to default handler " |
| 861 | + pkg.packageName); |
| 862 | } |
| 863 | mService.updatePermissionFlags(permission, pkg.packageName, |
| 864 | PackageManager.FLAG_PERMISSION_SYSTEM_FIXED, 0, userId); |
| 865 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | } |
| 869 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 870 | private boolean isSysComponentOrPersistentPlatformSignedPrivAppLPr(PackageParser.Package pkg) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 871 | if (UserHandle.getAppId(pkg.applicationInfo.uid) < FIRST_APPLICATION_UID) { |
| 872 | return true; |
| 873 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 874 | if (!pkg.isPrivilegedApp()) { |
| 875 | return false; |
| 876 | } |
| 877 | PackageSetting sysPkg = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
Svet Ganov | f443384 | 2015-11-17 11:53:18 -0800 | [diff] [blame] | 878 | if (sysPkg != null && sysPkg.pkg != null) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 879 | if ((sysPkg.pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
| 880 | return false; |
| 881 | } |
| 882 | } else if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 883 | return false; |
| 884 | } |
| 885 | return PackageManagerService.compareSignatures(mService.mPlatformPackage.mSignatures, |
| 886 | pkg.mSignatures) == PackageManager.SIGNATURE_MATCH; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | private static boolean doesPackageSupportRuntimePermissions(PackageParser.Package pkg) { |
| 890 | return pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1; |
| 891 | } |
| 892 | } |