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