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; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 20 | import android.annotation.NonNull; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 21 | import android.app.DownloadManager; |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 22 | import android.app.admin.DevicePolicyManager; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 23 | import android.content.Intent; |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 24 | import android.content.pm.ActivityInfo; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 25 | import android.content.pm.ApplicationInfo; |
| 26 | import android.content.pm.PackageManager; |
| 27 | import android.content.pm.PackageManagerInternal.PackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManagerInternal.SyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 29 | import android.content.pm.PackageParser; |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 30 | import android.content.pm.ProviderInfo; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 31 | import android.content.pm.ResolveInfo; |
| 32 | import android.net.Uri; |
| 33 | import android.os.Build; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 34 | import android.os.Environment; |
| 35 | import android.os.Handler; |
| 36 | import android.os.Message; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 37 | import android.os.UserHandle; |
Daniel Nishi | 8d9d0fec | 2016-07-13 14:24:31 -0700 | [diff] [blame] | 38 | import android.os.storage.StorageManager; |
Philip P. Moltmann | 66c9659 | 2016-02-24 11:32:43 -0800 | [diff] [blame] | 39 | import android.print.PrintManager; |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 40 | import android.provider.CalendarContract; |
| 41 | import android.provider.ContactsContract; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 42 | import android.provider.MediaStore; |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 43 | import android.provider.Telephony.Sms.Intents; |
mariagpuyol | 2d29080 | 2016-02-23 18:06:36 -0800 | [diff] [blame] | 44 | import android.telephony.TelephonyManager; |
Svetoslav | 0e62952 | 2015-08-05 19:14:47 -0700 | [diff] [blame] | 45 | import android.security.Credentials; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 46 | import android.util.ArrayMap; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 47 | import android.util.ArraySet; |
| 48 | import android.util.Log; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 49 | import android.util.Slog; |
| 50 | import android.util.Xml; |
| 51 | import com.android.internal.util.XmlUtils; |
| 52 | import org.xmlpull.v1.XmlPullParser; |
| 53 | import org.xmlpull.v1.XmlPullParserException; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 54 | |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 55 | import java.io.BufferedInputStream; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 56 | import java.io.File; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 57 | import java.io.FileInputStream; |
| 58 | import java.io.IOException; |
| 59 | import java.io.InputStream; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 60 | import java.util.ArrayList; |
| 61 | import java.util.List; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 62 | import java.util.Map; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 63 | import java.util.Set; |
| 64 | |
| 65 | import static android.os.Process.FIRST_APPLICATION_UID; |
| 66 | |
| 67 | /** |
| 68 | * This class is the policy for granting runtime permissions to |
| 69 | * platform components and default handlers in the system such |
| 70 | * that the device is usable out-of-the-box. For example, the |
| 71 | * shell UID is a part of the system and the Phone app should |
| 72 | * have phone related permission by default. |
| 73 | */ |
| 74 | final class DefaultPermissionGrantPolicy { |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 75 | private static final String TAG = "DefaultPermGrantPolicy"; // must be <= 23 chars |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 76 | private static final boolean DEBUG = false; |
| 77 | |
Jeff Sharkey | 8a372a0 | 2016-03-16 16:25:45 -0600 | [diff] [blame] | 78 | private static final int DEFAULT_FLAGS = PackageManager.MATCH_DIRECT_BOOT_AWARE |
| 79 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE; |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 80 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 81 | private static final String AUDIO_MIME_TYPE = "audio/mpeg"; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 82 | |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 83 | private static final String TAG_EXCEPTIONS = "exceptions"; |
| 84 | private static final String TAG_EXCEPTION = "exception"; |
| 85 | private static final String TAG_PERMISSION = "permission"; |
| 86 | private static final String ATTR_PACKAGE = "package"; |
| 87 | private static final String ATTR_NAME = "name"; |
| 88 | private static final String ATTR_FIXED = "fixed"; |
| 89 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 90 | private static final Set<String> PHONE_PERMISSIONS = new ArraySet<>(); |
| 91 | static { |
| 92 | PHONE_PERMISSIONS.add(Manifest.permission.READ_PHONE_STATE); |
| 93 | PHONE_PERMISSIONS.add(Manifest.permission.CALL_PHONE); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 94 | PHONE_PERMISSIONS.add(Manifest.permission.READ_CALL_LOG); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 95 | PHONE_PERMISSIONS.add(Manifest.permission.WRITE_CALL_LOG); |
| 96 | PHONE_PERMISSIONS.add(Manifest.permission.ADD_VOICEMAIL); |
| 97 | PHONE_PERMISSIONS.add(Manifest.permission.USE_SIP); |
| 98 | PHONE_PERMISSIONS.add(Manifest.permission.PROCESS_OUTGOING_CALLS); |
| 99 | } |
| 100 | |
| 101 | private static final Set<String> CONTACTS_PERMISSIONS = new ArraySet<>(); |
| 102 | static { |
| 103 | CONTACTS_PERMISSIONS.add(Manifest.permission.READ_CONTACTS); |
| 104 | CONTACTS_PERMISSIONS.add(Manifest.permission.WRITE_CONTACTS); |
Svetoslav Ganov | 54a0cf1 | 2015-07-17 20:34:18 +0000 | [diff] [blame] | 105 | CONTACTS_PERMISSIONS.add(Manifest.permission.GET_ACCOUNTS); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | private static final Set<String> LOCATION_PERMISSIONS = new ArraySet<>(); |
| 109 | static { |
| 110 | LOCATION_PERMISSIONS.add(Manifest.permission.ACCESS_FINE_LOCATION); |
| 111 | LOCATION_PERMISSIONS.add(Manifest.permission.ACCESS_COARSE_LOCATION); |
| 112 | } |
| 113 | |
| 114 | private static final Set<String> CALENDAR_PERMISSIONS = new ArraySet<>(); |
| 115 | static { |
| 116 | CALENDAR_PERMISSIONS.add(Manifest.permission.READ_CALENDAR); |
| 117 | CALENDAR_PERMISSIONS.add(Manifest.permission.WRITE_CALENDAR); |
| 118 | } |
| 119 | |
| 120 | private static final Set<String> SMS_PERMISSIONS = new ArraySet<>(); |
| 121 | static { |
| 122 | SMS_PERMISSIONS.add(Manifest.permission.SEND_SMS); |
| 123 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_SMS); |
| 124 | SMS_PERMISSIONS.add(Manifest.permission.READ_SMS); |
| 125 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_WAP_PUSH); |
| 126 | SMS_PERMISSIONS.add(Manifest.permission.RECEIVE_MMS); |
| 127 | SMS_PERMISSIONS.add(Manifest.permission.READ_CELL_BROADCASTS); |
| 128 | } |
| 129 | |
| 130 | private static final Set<String> MICROPHONE_PERMISSIONS = new ArraySet<>(); |
| 131 | static { |
| 132 | MICROPHONE_PERMISSIONS.add(Manifest.permission.RECORD_AUDIO); |
| 133 | } |
| 134 | |
| 135 | private static final Set<String> CAMERA_PERMISSIONS = new ArraySet<>(); |
| 136 | static { |
| 137 | CAMERA_PERMISSIONS.add(Manifest.permission.CAMERA); |
| 138 | } |
| 139 | |
| 140 | private static final Set<String> SENSORS_PERMISSIONS = new ArraySet<>(); |
| 141 | static { |
| 142 | SENSORS_PERMISSIONS.add(Manifest.permission.BODY_SENSORS); |
| 143 | } |
| 144 | |
| 145 | private static final Set<String> STORAGE_PERMISSIONS = new ArraySet<>(); |
| 146 | static { |
Svet Ganov | 975fa47 | 2015-06-22 20:45:31 -0700 | [diff] [blame] | 147 | STORAGE_PERMISSIONS.add(Manifest.permission.READ_EXTERNAL_STORAGE); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 148 | STORAGE_PERMISSIONS.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); |
| 149 | } |
| 150 | |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 151 | private static final int MSG_READ_DEFAULT_PERMISSION_EXCEPTIONS = 1; |
| 152 | |
Pierre-Laurent Coirier | 87e0371 | 2016-02-26 12:07:41 -0500 | [diff] [blame] | 153 | private static final String ACTION_TWINNING = |
| 154 | "com.google.android.clockwork.intent.TWINNING_SETTINGS"; |
Dan Aminzade | f8d60b1 | 2016-09-13 10:50:09 -0700 | [diff] [blame] | 155 | private static final String ACTION_TRACK = "com.android.fitness.TRACK"; |
Pierre-Laurent Coirier | 87e0371 | 2016-02-26 12:07:41 -0500 | [diff] [blame] | 156 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 157 | private final PackageManagerService mService; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 158 | private final Handler mHandler; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 159 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 160 | private PackagesProvider mLocationPackagesProvider; |
| 161 | private PackagesProvider mVoiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 162 | private PackagesProvider mSmsAppPackagesProvider; |
| 163 | private PackagesProvider mDialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 164 | private PackagesProvider mSimCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 165 | private SyncAdapterPackagesProvider mSyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 166 | |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 167 | private ArrayMap<String, List<DefaultPermissionGrant>> mGrantExceptions; |
| 168 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 169 | public DefaultPermissionGrantPolicy(PackageManagerService service) { |
| 170 | mService = service; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 171 | mHandler = new Handler(mService.mHandlerThread.getLooper()) { |
| 172 | @Override |
| 173 | public void handleMessage(Message msg) { |
| 174 | if (msg.what == MSG_READ_DEFAULT_PERMISSION_EXCEPTIONS) { |
| 175 | synchronized (mService.mPackages) { |
| 176 | if (mGrantExceptions == null) { |
| 177 | mGrantExceptions = readDefaultPermissionExceptionsLPw(); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | }; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 185 | public void setLocationPackagesProviderLPw(PackagesProvider provider) { |
| 186 | mLocationPackagesProvider = provider; |
| 187 | } |
| 188 | |
| 189 | public void setVoiceInteractionPackagesProviderLPw(PackagesProvider provider) { |
| 190 | mVoiceInteractionPackagesProvider = provider; |
| 191 | } |
| 192 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 193 | public void setSmsAppPackagesProviderLPw(PackagesProvider provider) { |
| 194 | mSmsAppPackagesProvider = provider; |
| 195 | } |
| 196 | |
| 197 | public void setDialerAppPackagesProviderLPw(PackagesProvider provider) { |
| 198 | mDialerAppPackagesProvider = provider; |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 201 | public void setSimCallManagerPackagesProviderLPw(PackagesProvider provider) { |
| 202 | mSimCallManagerPackagesProvider = provider; |
| 203 | } |
| 204 | |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 205 | public void setSyncAdapterPackagesProviderLPw(SyncAdapterPackagesProvider provider) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 206 | mSyncAdapterPackagesProvider = provider; |
| 207 | } |
| 208 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 209 | public void grantDefaultPermissions(int userId) { |
| 210 | grantPermissionsToSysComponentsAndPrivApps(userId); |
| 211 | grantDefaultSystemHandlerPermissions(userId); |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 212 | grantDefaultPermissionExceptions(userId); |
| 213 | } |
| 214 | |
| 215 | public void scheduleReadDefaultPermissionExceptions() { |
| 216 | mHandler.sendEmptyMessage(MSG_READ_DEFAULT_PERMISSION_EXCEPTIONS); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | private void grantPermissionsToSysComponentsAndPrivApps(int userId) { |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 220 | Log.i(TAG, "Granting permissions to platform components for user " + userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 221 | |
| 222 | synchronized (mService.mPackages) { |
| 223 | for (PackageParser.Package pkg : mService.mPackages.values()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 224 | if (!isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) |
| 225 | || !doesPackageSupportRuntimePermissions(pkg) |
| 226 | || pkg.requestedPermissions.isEmpty()) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 227 | continue; |
| 228 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 229 | Set<String> permissions = new ArraySet<>(); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 230 | final int permissionCount = pkg.requestedPermissions.size(); |
| 231 | for (int i = 0; i < permissionCount; i++) { |
| 232 | String permission = pkg.requestedPermissions.get(i); |
| 233 | BasePermission bp = mService.mSettings.mPermissions.get(permission); |
| 234 | if (bp != null && bp.isRuntime()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 235 | permissions.add(permission); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 236 | } |
| 237 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 238 | if (!permissions.isEmpty()) { |
| 239 | grantRuntimePermissionsLPw(pkg, permissions, true, userId); |
| 240 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | private void grantDefaultSystemHandlerPermissions(int userId) { |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 246 | Log.i(TAG, "Granting permissions to default platform handlers for user " + userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 247 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 248 | final PackagesProvider locationPackagesProvider; |
| 249 | final PackagesProvider voiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 250 | final PackagesProvider smsAppPackagesProvider; |
| 251 | final PackagesProvider dialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 252 | final PackagesProvider simCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 253 | final SyncAdapterPackagesProvider syncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 254 | |
| 255 | synchronized (mService.mPackages) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 256 | locationPackagesProvider = mLocationPackagesProvider; |
| 257 | voiceInteractionPackagesProvider = mVoiceInteractionPackagesProvider; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 258 | smsAppPackagesProvider = mSmsAppPackagesProvider; |
| 259 | dialerAppPackagesProvider = mDialerAppPackagesProvider; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 260 | simCallManagerPackagesProvider = mSimCallManagerPackagesProvider; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 261 | syncAdapterPackagesProvider = mSyncAdapterPackagesProvider; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 264 | String[] voiceInteractPackageNames = (voiceInteractionPackagesProvider != null) |
| 265 | ? voiceInteractionPackagesProvider.getPackages(userId) : null; |
| 266 | String[] locationPackageNames = (locationPackagesProvider != null) |
| 267 | ? locationPackagesProvider.getPackages(userId) : null; |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 268 | String[] smsAppPackageNames = (smsAppPackagesProvider != null) |
| 269 | ? smsAppPackagesProvider.getPackages(userId) : null; |
| 270 | String[] dialerAppPackageNames = (dialerAppPackagesProvider != null) |
| 271 | ? dialerAppPackagesProvider.getPackages(userId) : null; |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 272 | String[] simCallManagerPackageNames = (simCallManagerPackagesProvider != null) |
| 273 | ? simCallManagerPackagesProvider.getPackages(userId) : null; |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 274 | String[] contactsSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? |
| 275 | syncAdapterPackagesProvider.getPackages(ContactsContract.AUTHORITY, userId) : null; |
| 276 | String[] calendarSyncAdapterPackages = (syncAdapterPackagesProvider != null) ? |
| 277 | syncAdapterPackagesProvider.getPackages(CalendarContract.AUTHORITY, userId) : null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 278 | |
| 279 | synchronized (mService.mPackages) { |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 280 | // Installer |
| 281 | PackageParser.Package installerPackage = getSystemPackageLPr( |
| 282 | mService.mRequiredInstallerPackage); |
| 283 | if (installerPackage != null |
| 284 | && doesPackageSupportRuntimePermissions(installerPackage)) { |
| 285 | grantRuntimePermissionsLPw(installerPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 288 | // Verifier |
| 289 | PackageParser.Package verifierPackage = getSystemPackageLPr( |
| 290 | mService.mRequiredVerifierPackage); |
| 291 | if (verifierPackage != null |
| 292 | && doesPackageSupportRuntimePermissions(verifierPackage)) { |
| 293 | grantRuntimePermissionsLPw(verifierPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | cd94602 | 2015-09-12 10:19:54 -0700 | [diff] [blame] | 294 | grantRuntimePermissionsLPw(verifierPackage, PHONE_PERMISSIONS, false, userId); |
| 295 | grantRuntimePermissionsLPw(verifierPackage, SMS_PERMISSIONS, false, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | // SetupWizard |
Russell Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 299 | PackageParser.Package setupPackage = getSystemPackageLPr( |
| 300 | mService.mSetupWizardPackage); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 301 | if (setupPackage != null |
| 302 | && doesPackageSupportRuntimePermissions(setupPackage)) { |
| 303 | grantRuntimePermissionsLPw(setupPackage, PHONE_PERMISSIONS, userId); |
| 304 | grantRuntimePermissionsLPw(setupPackage, CONTACTS_PERMISSIONS, userId); |
Svetoslav Ganov | c5603cc7 | 2016-01-06 13:33:30 -0800 | [diff] [blame] | 305 | grantRuntimePermissionsLPw(setupPackage, LOCATION_PERMISSIONS, userId); |
Steven Ng | 76bcfb2 | 2016-02-03 11:53:25 +0000 | [diff] [blame] | 306 | grantRuntimePermissionsLPw(setupPackage, CAMERA_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 309 | // Camera |
| 310 | Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 311 | PackageParser.Package cameraPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 312 | cameraIntent, userId); |
| 313 | if (cameraPackage != null |
| 314 | && doesPackageSupportRuntimePermissions(cameraPackage)) { |
| 315 | grantRuntimePermissionsLPw(cameraPackage, CAMERA_PERMISSIONS, userId); |
| 316 | grantRuntimePermissionsLPw(cameraPackage, MICROPHONE_PERMISSIONS, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 317 | grantRuntimePermissionsLPw(cameraPackage, STORAGE_PERMISSIONS, userId); |
| 318 | } |
| 319 | |
| 320 | // Media provider |
| 321 | PackageParser.Package mediaStorePackage = getDefaultProviderAuthorityPackageLPr( |
| 322 | MediaStore.AUTHORITY, userId); |
| 323 | if (mediaStorePackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 324 | grantRuntimePermissionsLPw(mediaStorePackage, STORAGE_PERMISSIONS, true, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // Downloads provider |
| 328 | PackageParser.Package downloadsPackage = getDefaultProviderAuthorityPackageLPr( |
| 329 | "downloads", userId); |
| 330 | if (downloadsPackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 331 | grantRuntimePermissionsLPw(downloadsPackage, STORAGE_PERMISSIONS, true, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // Downloads UI |
| 335 | Intent downloadsUiIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 336 | PackageParser.Package downloadsUiPackage = getDefaultSystemHandlerActivityPackageLPr( |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 337 | downloadsUiIntent, userId); |
| 338 | if (downloadsUiPackage != null |
| 339 | && doesPackageSupportRuntimePermissions(downloadsUiPackage)) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 340 | grantRuntimePermissionsLPw(downloadsUiPackage, STORAGE_PERMISSIONS, true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 343 | // Storage provider |
| 344 | PackageParser.Package storagePackage = getDefaultProviderAuthorityPackageLPr( |
| 345 | "com.android.externalstorage.documents", userId); |
| 346 | if (storagePackage != null) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 347 | grantRuntimePermissionsLPw(storagePackage, STORAGE_PERMISSIONS, true, userId); |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Svetoslav | 0e62952 | 2015-08-05 19:14:47 -0700 | [diff] [blame] | 350 | // CertInstaller |
| 351 | Intent certInstallerIntent = new Intent(Credentials.INSTALL_ACTION); |
| 352 | PackageParser.Package certInstallerPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 353 | certInstallerIntent, userId); |
| 354 | if (certInstallerPackage != null |
| 355 | && doesPackageSupportRuntimePermissions(certInstallerPackage)) { |
| 356 | grantRuntimePermissionsLPw(certInstallerPackage, STORAGE_PERMISSIONS, true, userId); |
| 357 | } |
| 358 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 359 | // Dialer |
| 360 | if (dialerAppPackageNames == null) { |
| 361 | Intent dialerIntent = new Intent(Intent.ACTION_DIAL); |
| 362 | PackageParser.Package dialerPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 363 | dialerIntent, userId); |
| 364 | if (dialerPackage != null) { |
| 365 | grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId); |
| 366 | } |
| 367 | } else { |
| 368 | for (String dialerAppPackageName : dialerAppPackageNames) { |
| 369 | PackageParser.Package dialerPackage = getSystemPackageLPr(dialerAppPackageName); |
| 370 | if (dialerPackage != null) { |
| 371 | grantDefaultPermissionsToDefaultSystemDialerAppLPr(dialerPackage, userId); |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 376 | // Sim call manager |
| 377 | if (simCallManagerPackageNames != null) { |
| 378 | for (String simCallManagerPackageName : simCallManagerPackageNames) { |
| 379 | PackageParser.Package simCallManagerPackage = |
| 380 | getSystemPackageLPr(simCallManagerPackageName); |
| 381 | if (simCallManagerPackage != null) { |
| 382 | grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, |
| 383 | userId); |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 388 | // SMS |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 389 | if (smsAppPackageNames == null) { |
| 390 | Intent smsIntent = new Intent(Intent.ACTION_MAIN); |
| 391 | smsIntent.addCategory(Intent.CATEGORY_APP_MESSAGING); |
| 392 | PackageParser.Package smsPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 393 | smsIntent, userId); |
| 394 | if (smsPackage != null) { |
| 395 | grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId); |
| 396 | } |
| 397 | } else { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 398 | for (String smsPackageName : smsAppPackageNames) { |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 399 | PackageParser.Package smsPackage = getSystemPackageLPr(smsPackageName); |
| 400 | if (smsPackage != null) { |
| 401 | grantDefaultPermissionsToDefaultSystemSmsAppLPr(smsPackage, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 402 | } |
| 403 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 406 | // Cell Broadcast Receiver |
| 407 | Intent cbrIntent = new Intent(Intents.SMS_CB_RECEIVED_ACTION); |
| 408 | PackageParser.Package cbrPackage = |
| 409 | getDefaultSystemHandlerActivityPackageLPr(cbrIntent, userId); |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 410 | if (cbrPackage != null && doesPackageSupportRuntimePermissions(cbrPackage)) { |
Svet Ganov | 52153f4 | 2015-08-11 08:59:12 -0700 | [diff] [blame] | 411 | grantRuntimePermissionsLPw(cbrPackage, SMS_PERMISSIONS, userId); |
Jack Yu | ed79bf5 | 2015-07-06 17:23:52 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Junda Liu | d878f53 | 2015-08-13 14:25:49 -0700 | [diff] [blame] | 414 | // Carrier Provisioning Service |
| 415 | Intent carrierProvIntent = new Intent(Intents.SMS_CARRIER_PROVISION_ACTION); |
| 416 | PackageParser.Package carrierProvPackage = |
| 417 | getDefaultSystemHandlerServicePackageLPr(carrierProvIntent, userId); |
| 418 | if (carrierProvPackage != null && doesPackageSupportRuntimePermissions(carrierProvPackage)) { |
| 419 | grantRuntimePermissionsLPw(carrierProvPackage, SMS_PERMISSIONS, false, userId); |
| 420 | } |
| 421 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 422 | // Calendar |
| 423 | Intent calendarIntent = new Intent(Intent.ACTION_MAIN); |
| 424 | calendarIntent.addCategory(Intent.CATEGORY_APP_CALENDAR); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 425 | PackageParser.Package calendarPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 426 | calendarIntent, userId); |
| 427 | if (calendarPackage != null |
| 428 | && doesPackageSupportRuntimePermissions(calendarPackage)) { |
| 429 | grantRuntimePermissionsLPw(calendarPackage, CALENDAR_PERMISSIONS, userId); |
| 430 | grantRuntimePermissionsLPw(calendarPackage, CONTACTS_PERMISSIONS, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | // Calendar provider |
| 434 | PackageParser.Package calendarProviderPackage = getDefaultProviderAuthorityPackageLPr( |
| 435 | CalendarContract.AUTHORITY, userId); |
| 436 | if (calendarProviderPackage != null) { |
| 437 | grantRuntimePermissionsLPw(calendarProviderPackage, CONTACTS_PERMISSIONS, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 438 | grantRuntimePermissionsLPw(calendarProviderPackage, CALENDAR_PERMISSIONS, |
| 439 | true, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 440 | grantRuntimePermissionsLPw(calendarProviderPackage, STORAGE_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 443 | // Calendar provider sync adapters |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 444 | List<PackageParser.Package> calendarSyncAdapters = getHeadlessSyncAdapterPackagesLPr( |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 445 | calendarSyncAdapterPackages, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 446 | final int calendarSyncAdapterCount = calendarSyncAdapters.size(); |
| 447 | for (int i = 0; i < calendarSyncAdapterCount; i++) { |
| 448 | PackageParser.Package calendarSyncAdapter = calendarSyncAdapters.get(i); |
| 449 | if (doesPackageSupportRuntimePermissions(calendarSyncAdapter)) { |
| 450 | grantRuntimePermissionsLPw(calendarSyncAdapter, CALENDAR_PERMISSIONS, userId); |
| 451 | } |
| 452 | } |
| 453 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 454 | // Contacts |
| 455 | Intent contactsIntent = new Intent(Intent.ACTION_MAIN); |
| 456 | contactsIntent.addCategory(Intent.CATEGORY_APP_CONTACTS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 457 | PackageParser.Package contactsPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 458 | contactsIntent, userId); |
| 459 | if (contactsPackage != null |
| 460 | && doesPackageSupportRuntimePermissions(contactsPackage)) { |
| 461 | grantRuntimePermissionsLPw(contactsPackage, CONTACTS_PERMISSIONS, userId); |
| 462 | grantRuntimePermissionsLPw(contactsPackage, PHONE_PERMISSIONS, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 463 | } |
| 464 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 465 | // Contacts provider sync adapters |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 466 | List<PackageParser.Package> contactsSyncAdapters = getHeadlessSyncAdapterPackagesLPr( |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 467 | contactsSyncAdapterPackages, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 468 | final int contactsSyncAdapterCount = contactsSyncAdapters.size(); |
| 469 | for (int i = 0; i < contactsSyncAdapterCount; i++) { |
| 470 | PackageParser.Package contactsSyncAdapter = contactsSyncAdapters.get(i); |
| 471 | if (doesPackageSupportRuntimePermissions(contactsSyncAdapter)) { |
| 472 | grantRuntimePermissionsLPw(contactsSyncAdapter, CONTACTS_PERMISSIONS, userId); |
| 473 | } |
| 474 | } |
| 475 | |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 476 | // Contacts provider |
| 477 | PackageParser.Package contactsProviderPackage = getDefaultProviderAuthorityPackageLPr( |
| 478 | ContactsContract.AUTHORITY, userId); |
| 479 | if (contactsProviderPackage != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 480 | grantRuntimePermissionsLPw(contactsProviderPackage, CONTACTS_PERMISSIONS, |
| 481 | true, userId); |
Makoto Onuki | 7a4082e | 2015-07-06 16:59:36 -0700 | [diff] [blame] | 482 | grantRuntimePermissionsLPw(contactsProviderPackage, PHONE_PERMISSIONS, |
| 483 | true, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 484 | grantRuntimePermissionsLPw(contactsProviderPackage, STORAGE_PERMISSIONS, userId); |
| 485 | } |
| 486 | |
| 487 | // Device provisioning |
| 488 | Intent deviceProvisionIntent = new Intent( |
| 489 | DevicePolicyManager.ACTION_PROVISION_MANAGED_DEVICE); |
Svet Ganov | b6e0013 | 2015-06-29 20:19:25 -0700 | [diff] [blame] | 490 | PackageParser.Package deviceProvisionPackage = |
| 491 | getDefaultSystemHandlerActivityPackageLPr(deviceProvisionIntent, userId); |
Dianne Hackborn | 388cd2c | 2015-06-26 17:32:36 -0700 | [diff] [blame] | 492 | if (deviceProvisionPackage != null |
| 493 | && doesPackageSupportRuntimePermissions(deviceProvisionPackage)) { |
Makoto Onuki | bc92479 | 2015-07-16 11:38:00 -0700 | [diff] [blame] | 494 | grantRuntimePermissionsLPw(deviceProvisionPackage, CONTACTS_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | // Maps |
| 498 | Intent mapsIntent = new Intent(Intent.ACTION_MAIN); |
| 499 | mapsIntent.addCategory(Intent.CATEGORY_APP_MAPS); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 500 | PackageParser.Package mapsPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 501 | mapsIntent, userId); |
| 502 | if (mapsPackage != null |
| 503 | && doesPackageSupportRuntimePermissions(mapsPackage)) { |
| 504 | grantRuntimePermissionsLPw(mapsPackage, LOCATION_PERMISSIONS, userId); |
| 505 | } |
| 506 | |
Svet Ganov | 200d494 | 2015-07-01 20:46:02 -0700 | [diff] [blame] | 507 | // Gallery |
| 508 | Intent galleryIntent = new Intent(Intent.ACTION_MAIN); |
| 509 | galleryIntent.addCategory(Intent.CATEGORY_APP_GALLERY); |
| 510 | PackageParser.Package galleryPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 511 | galleryIntent, userId); |
| 512 | if (galleryPackage != null |
| 513 | && doesPackageSupportRuntimePermissions(galleryPackage)) { |
| 514 | grantRuntimePermissionsLPw(galleryPackage, STORAGE_PERMISSIONS, userId); |
| 515 | } |
| 516 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 517 | // Email |
| 518 | Intent emailIntent = new Intent(Intent.ACTION_MAIN); |
| 519 | emailIntent.addCategory(Intent.CATEGORY_APP_EMAIL); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 520 | PackageParser.Package emailPackage = getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 521 | emailIntent, userId); |
| 522 | if (emailPackage != null |
| 523 | && doesPackageSupportRuntimePermissions(emailPackage)) { |
| 524 | grantRuntimePermissionsLPw(emailPackage, CONTACTS_PERMISSIONS, userId); |
Svetoslav Ganov | 9df80d2 | 2016-07-25 18:27:41 -0700 | [diff] [blame] | 525 | grantRuntimePermissionsLPw(emailPackage, CALENDAR_PERMISSIONS, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | // Browser |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 529 | PackageParser.Package browserPackage = null; |
| 530 | String defaultBrowserPackage = mService.getDefaultBrowserPackageName(userId); |
| 531 | if (defaultBrowserPackage != null) { |
| 532 | browserPackage = getPackageLPr(defaultBrowserPackage); |
| 533 | } |
| 534 | if (browserPackage == null) { |
| 535 | Intent browserIntent = new Intent(Intent.ACTION_MAIN); |
| 536 | browserIntent.addCategory(Intent.CATEGORY_APP_BROWSER); |
| 537 | browserPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 538 | browserIntent, userId); |
| 539 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 540 | if (browserPackage != null |
| 541 | && doesPackageSupportRuntimePermissions(browserPackage)) { |
| 542 | grantRuntimePermissionsLPw(browserPackage, LOCATION_PERMISSIONS, userId); |
| 543 | } |
| 544 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 545 | // Voice interaction |
| 546 | if (voiceInteractPackageNames != null) { |
| 547 | for (String voiceInteractPackageName : voiceInteractPackageNames) { |
| 548 | PackageParser.Package voiceInteractPackage = getSystemPackageLPr( |
| 549 | voiceInteractPackageName); |
| 550 | if (voiceInteractPackage != null |
| 551 | && doesPackageSupportRuntimePermissions(voiceInteractPackage)) { |
| 552 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 553 | CONTACTS_PERMISSIONS, userId); |
| 554 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 555 | CALENDAR_PERMISSIONS, userId); |
| 556 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 557 | MICROPHONE_PERMISSIONS, userId); |
| 558 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 559 | PHONE_PERMISSIONS, userId); |
| 560 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 561 | SMS_PERMISSIONS, userId); |
| 562 | grantRuntimePermissionsLPw(voiceInteractPackage, |
| 563 | LOCATION_PERMISSIONS, userId); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 568 | // Voice recognition |
| 569 | Intent voiceRecoIntent = new Intent("android.speech.RecognitionService"); |
| 570 | voiceRecoIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 571 | PackageParser.Package voiceRecoPackage = getDefaultSystemHandlerServicePackageLPr( |
| 572 | voiceRecoIntent, userId); |
| 573 | if (voiceRecoPackage != null |
| 574 | && doesPackageSupportRuntimePermissions(voiceRecoPackage)) { |
| 575 | grantRuntimePermissionsLPw(voiceRecoPackage, MICROPHONE_PERMISSIONS, userId); |
| 576 | } |
| 577 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 578 | // Location |
| 579 | if (locationPackageNames != null) { |
| 580 | for (String packageName : locationPackageNames) { |
| 581 | PackageParser.Package locationPackage = getSystemPackageLPr(packageName); |
| 582 | if (locationPackage != null |
| 583 | && doesPackageSupportRuntimePermissions(locationPackage)) { |
| 584 | grantRuntimePermissionsLPw(locationPackage, CONTACTS_PERMISSIONS, userId); |
| 585 | grantRuntimePermissionsLPw(locationPackage, CALENDAR_PERMISSIONS, userId); |
| 586 | grantRuntimePermissionsLPw(locationPackage, MICROPHONE_PERMISSIONS, userId); |
| 587 | grantRuntimePermissionsLPw(locationPackage, PHONE_PERMISSIONS, userId); |
| 588 | grantRuntimePermissionsLPw(locationPackage, SMS_PERMISSIONS, userId); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 589 | grantRuntimePermissionsLPw(locationPackage, LOCATION_PERMISSIONS, |
| 590 | true, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 591 | grantRuntimePermissionsLPw(locationPackage, CAMERA_PERMISSIONS, userId); |
| 592 | grantRuntimePermissionsLPw(locationPackage, SENSORS_PERMISSIONS, userId); |
| 593 | grantRuntimePermissionsLPw(locationPackage, STORAGE_PERMISSIONS, userId); |
| 594 | } |
| 595 | } |
| 596 | } |
Jeff Davidson | 2a88031 | 2015-06-22 16:54:34 -0700 | [diff] [blame] | 597 | |
Jeff Sharkey | 7186dd3 | 2015-06-30 17:32:45 -0700 | [diff] [blame] | 598 | // Music |
| 599 | Intent musicIntent = new Intent(Intent.ACTION_VIEW); |
| 600 | musicIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 601 | musicIntent.setDataAndType(Uri.fromFile(new File("foo.mp3")), |
| 602 | AUDIO_MIME_TYPE); |
| 603 | PackageParser.Package musicPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 604 | musicIntent, userId); |
| 605 | if (musicPackage != null |
| 606 | && doesPackageSupportRuntimePermissions(musicPackage)) { |
| 607 | grantRuntimePermissionsLPw(musicPackage, STORAGE_PERMISSIONS, userId); |
| 608 | } |
| 609 | |
Dan Aminzade | f8d60b1 | 2016-09-13 10:50:09 -0700 | [diff] [blame] | 610 | // Watches |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 611 | if (mService.hasSystemFeature(PackageManager.FEATURE_WATCH, 0)) { |
Dan Aminzade | f8d60b1 | 2016-09-13 10:50:09 -0700 | [diff] [blame] | 612 | // Home application on watches |
Anthony Hugh | 979b81a | 2015-09-29 16:50:35 -0700 | [diff] [blame] | 613 | Intent homeIntent = new Intent(Intent.ACTION_MAIN); |
| 614 | homeIntent.addCategory(Intent.CATEGORY_HOME_MAIN); |
| 615 | |
| 616 | PackageParser.Package wearHomePackage = getDefaultSystemHandlerActivityPackageLPr( |
| 617 | homeIntent, userId); |
| 618 | |
| 619 | if (wearHomePackage != null |
| 620 | && doesPackageSupportRuntimePermissions(wearHomePackage)) { |
| 621 | grantRuntimePermissionsLPw(wearHomePackage, CONTACTS_PERMISSIONS, false, |
| 622 | userId); |
| 623 | grantRuntimePermissionsLPw(wearHomePackage, PHONE_PERMISSIONS, true, userId); |
| 624 | grantRuntimePermissionsLPw(wearHomePackage, MICROPHONE_PERMISSIONS, false, |
| 625 | userId); |
Anthony Hugh | 90814f0 | 2015-10-21 11:41:34 -0700 | [diff] [blame] | 626 | grantRuntimePermissionsLPw(wearHomePackage, LOCATION_PERMISSIONS, false, |
| 627 | userId); |
Anthony Hugh | 979b81a | 2015-09-29 16:50:35 -0700 | [diff] [blame] | 628 | } |
Pierre-Laurent Coirier | 87e0371 | 2016-02-26 12:07:41 -0500 | [diff] [blame] | 629 | |
Dan Aminzade | f8d60b1 | 2016-09-13 10:50:09 -0700 | [diff] [blame] | 630 | // Twinning on watches |
Pierre-Laurent Coirier | 87e0371 | 2016-02-26 12:07:41 -0500 | [diff] [blame] | 631 | Intent twinningIntent = new Intent(ACTION_TWINNING); |
| 632 | PackageParser.Package twinningPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 633 | twinningIntent, userId); |
| 634 | |
| 635 | if (twinningPackage != null |
| 636 | && doesPackageSupportRuntimePermissions(twinningPackage)) { |
| 637 | grantRuntimePermissionsLPw(twinningPackage, PHONE_PERMISSIONS, false, userId); |
| 638 | grantRuntimePermissionsLPw(twinningPackage, SMS_PERMISSIONS, false, userId); |
| 639 | } |
Dan Aminzade | f8d60b1 | 2016-09-13 10:50:09 -0700 | [diff] [blame] | 640 | |
| 641 | // Fitness tracking on watches |
| 642 | Intent trackIntent = new Intent(ACTION_TRACK); |
| 643 | PackageParser.Package trackPackage = getDefaultSystemHandlerActivityPackageLPr( |
| 644 | trackIntent, userId); |
| 645 | if (trackPackage != null |
| 646 | && doesPackageSupportRuntimePermissions(trackPackage)) { |
| 647 | grantRuntimePermissionsLPw(trackPackage, SENSORS_PERMISSIONS, false, userId); |
| 648 | grantRuntimePermissionsLPw(trackPackage, LOCATION_PERMISSIONS, false, userId); |
| 649 | } |
Anthony Hugh | 979b81a | 2015-09-29 16:50:35 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Philip P. Moltmann | 9896326 | 2015-12-16 16:57:05 -0800 | [diff] [blame] | 652 | // Print Spooler |
| 653 | PackageParser.Package printSpoolerPackage = getSystemPackageLPr( |
Philip P. Moltmann | 66c9659 | 2016-02-24 11:32:43 -0800 | [diff] [blame] | 654 | PrintManager.PRINT_SPOOLER_PACKAGE_NAME); |
Philip P. Moltmann | 9896326 | 2015-12-16 16:57:05 -0800 | [diff] [blame] | 655 | if (printSpoolerPackage != null |
| 656 | && doesPackageSupportRuntimePermissions(printSpoolerPackage)) { |
| 657 | grantRuntimePermissionsLPw(printSpoolerPackage, LOCATION_PERMISSIONS, true, userId); |
| 658 | } |
| 659 | |
mariagpuyol | 2d29080 | 2016-02-23 18:06:36 -0800 | [diff] [blame] | 660 | // EmergencyInfo |
| 661 | Intent emergencyInfoIntent = new Intent(TelephonyManager.ACTION_EMERGENCY_ASSISTANCE); |
| 662 | PackageParser.Package emergencyInfoPckg = getDefaultSystemHandlerActivityPackageLPr( |
| 663 | emergencyInfoIntent, userId); |
| 664 | if (emergencyInfoPckg != null |
| 665 | && doesPackageSupportRuntimePermissions(emergencyInfoPckg)) { |
| 666 | grantRuntimePermissionsLPw(emergencyInfoPckg, CONTACTS_PERMISSIONS, true, userId); |
| 667 | grantRuntimePermissionsLPw(emergencyInfoPckg, PHONE_PERMISSIONS, true, userId); |
| 668 | } |
| 669 | |
Martijn Coenen | 284b165 | 2016-03-30 13:46:39 +0200 | [diff] [blame] | 670 | // NFC Tag viewer |
| 671 | Intent nfcTagIntent = new Intent(Intent.ACTION_VIEW); |
| 672 | nfcTagIntent.setType("vnd.android.cursor.item/ndef_msg"); |
| 673 | PackageParser.Package nfcTagPkg = getDefaultSystemHandlerActivityPackageLPr( |
| 674 | nfcTagIntent, userId); |
| 675 | if (nfcTagPkg != null |
| 676 | && doesPackageSupportRuntimePermissions(nfcTagPkg)) { |
| 677 | grantRuntimePermissionsLPw(nfcTagPkg, CONTACTS_PERMISSIONS, false, userId); |
| 678 | grantRuntimePermissionsLPw(nfcTagPkg, PHONE_PERMISSIONS, false, userId); |
| 679 | } |
Daniel Nishi | 8d9d0fec | 2016-07-13 14:24:31 -0700 | [diff] [blame] | 680 | |
| 681 | // Storage Manager |
| 682 | Intent storageManagerIntent = new Intent(StorageManager.ACTION_MANAGE_STORAGE); |
| 683 | PackageParser.Package storageManagerPckg = getDefaultSystemHandlerActivityPackageLPr( |
| 684 | storageManagerIntent, userId); |
| 685 | if (storageManagerPckg != null |
| 686 | && doesPackageSupportRuntimePermissions(storageManagerPckg)) { |
| 687 | grantRuntimePermissionsLPw(storageManagerPckg, STORAGE_PERMISSIONS, true, userId); |
| 688 | } |
Svet Ganov | ba3ba81 | 2015-06-26 10:54:06 -0700 | [diff] [blame] | 689 | mService.mSettings.onDefaultRuntimePermissionsGrantedLPr(userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 693 | private void grantDefaultPermissionsToDefaultSystemDialerAppLPr( |
| 694 | PackageParser.Package dialerPackage, int userId) { |
| 695 | if (doesPackageSupportRuntimePermissions(dialerPackage)) { |
Anthony Hugh | d453992 | 2015-10-19 13:42:26 -0700 | [diff] [blame] | 696 | boolean isPhonePermFixed = |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 697 | mService.hasSystemFeature(PackageManager.FEATURE_WATCH, 0); |
Anthony Hugh | d453992 | 2015-10-19 13:42:26 -0700 | [diff] [blame] | 698 | grantRuntimePermissionsLPw( |
| 699 | dialerPackage, PHONE_PERMISSIONS, isPhonePermFixed, userId); |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 700 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, userId); |
| 701 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, userId); |
| 702 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, userId); |
Usman Abdullah | a2b109a | 2016-07-12 13:27:20 -0700 | [diff] [blame] | 703 | grantRuntimePermissionsLPw(dialerPackage, CAMERA_PERMISSIONS, userId); |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Svetoslav | a5a0d94 | 2015-07-01 19:49:58 -0700 | [diff] [blame] | 707 | private void grantDefaultPermissionsToDefaultSystemSmsAppLPr( |
| 708 | PackageParser.Package smsPackage, int userId) { |
| 709 | if (doesPackageSupportRuntimePermissions(smsPackage)) { |
| 710 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, userId); |
| 711 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, userId); |
| 712 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, userId); |
| 713 | } |
| 714 | } |
| 715 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 716 | public void grantDefaultPermissionsToDefaultSmsAppLPr(String packageName, int userId) { |
| 717 | Log.i(TAG, "Granting permissions to default sms app for user:" + userId); |
| 718 | if (packageName == null) { |
| 719 | return; |
| 720 | } |
| 721 | PackageParser.Package smsPackage = getPackageLPr(packageName); |
| 722 | if (smsPackage != null && doesPackageSupportRuntimePermissions(smsPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 723 | grantRuntimePermissionsLPw(smsPackage, PHONE_PERMISSIONS, false, true, userId); |
| 724 | grantRuntimePermissionsLPw(smsPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 725 | grantRuntimePermissionsLPw(smsPackage, SMS_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
| 729 | public void grantDefaultPermissionsToDefaultDialerAppLPr(String packageName, int userId) { |
| 730 | Log.i(TAG, "Granting permissions to default dialer app for user:" + userId); |
| 731 | if (packageName == null) { |
| 732 | return; |
| 733 | } |
| 734 | PackageParser.Package dialerPackage = getPackageLPr(packageName); |
| 735 | if (dialerPackage != null |
| 736 | && doesPackageSupportRuntimePermissions(dialerPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 737 | grantRuntimePermissionsLPw(dialerPackage, PHONE_PERMISSIONS, false, true, userId); |
| 738 | grantRuntimePermissionsLPw(dialerPackage, CONTACTS_PERMISSIONS, false, true, userId); |
| 739 | grantRuntimePermissionsLPw(dialerPackage, SMS_PERMISSIONS, false, true, userId); |
| 740 | grantRuntimePermissionsLPw(dialerPackage, MICROPHONE_PERMISSIONS, false, true, userId); |
Usman Abdullah | a2b109a | 2016-07-12 13:27:20 -0700 | [diff] [blame] | 741 | grantRuntimePermissionsLPw(dialerPackage, CAMERA_PERMISSIONS, false, true, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Sailesh Nepal | cf85562 | 2015-07-28 19:22:14 -0700 | [diff] [blame] | 745 | private void grantDefaultPermissionsToDefaultSimCallManagerLPr( |
| 746 | PackageParser.Package simCallManagerPackage, int userId) { |
| 747 | Log.i(TAG, "Granting permissions to sim call manager for user:" + userId); |
| 748 | if (doesPackageSupportRuntimePermissions(simCallManagerPackage)) { |
| 749 | grantRuntimePermissionsLPw(simCallManagerPackage, PHONE_PERMISSIONS, userId); |
| 750 | grantRuntimePermissionsLPw(simCallManagerPackage, MICROPHONE_PERMISSIONS, userId); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | public void grantDefaultPermissionsToDefaultSimCallManagerLPr(String packageName, int userId) { |
| 755 | if (packageName == null) { |
| 756 | return; |
| 757 | } |
| 758 | PackageParser.Package simCallManagerPackage = getPackageLPr(packageName); |
| 759 | if (simCallManagerPackage != null) { |
| 760 | grantDefaultPermissionsToDefaultSimCallManagerLPr(simCallManagerPackage, userId); |
| 761 | } |
| 762 | } |
| 763 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 764 | public void grantDefaultPermissionsToEnabledCarrierAppsLPr(String[] packageNames, int userId) { |
| 765 | Log.i(TAG, "Granting permissions to enabled carrier apps for user:" + userId); |
| 766 | if (packageNames == null) { |
| 767 | return; |
| 768 | } |
| 769 | for (String packageName : packageNames) { |
| 770 | PackageParser.Package carrierPackage = getSystemPackageLPr(packageName); |
| 771 | if (carrierPackage != null |
| 772 | && doesPackageSupportRuntimePermissions(carrierPackage)) { |
| 773 | grantRuntimePermissionsLPw(carrierPackage, PHONE_PERMISSIONS, userId); |
| 774 | grantRuntimePermissionsLPw(carrierPackage, LOCATION_PERMISSIONS, userId); |
Shishir Agrawal | ad63247 | 2015-07-29 16:54:07 -0700 | [diff] [blame] | 775 | grantRuntimePermissionsLPw(carrierPackage, SMS_PERMISSIONS, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | public void grantDefaultPermissionsToDefaultBrowserLPr(String packageName, int userId) { |
| 781 | Log.i(TAG, "Granting permissions to default browser for user:" + userId); |
| 782 | if (packageName == null) { |
| 783 | return; |
| 784 | } |
| 785 | PackageParser.Package browserPackage = getSystemPackageLPr(packageName); |
| 786 | if (browserPackage != null |
| 787 | && doesPackageSupportRuntimePermissions(browserPackage)) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 788 | grantRuntimePermissionsLPw(browserPackage, LOCATION_PERMISSIONS, false, false, userId); |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 792 | private PackageParser.Package getDefaultSystemHandlerActivityPackageLPr( |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 793 | Intent intent, int userId) { |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 794 | ResolveInfo handler = mService.resolveIntent(intent, |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 795 | intent.resolveType(mService.mContext.getContentResolver()), DEFAULT_FLAGS, userId); |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 796 | if (handler == null || handler.activityInfo == null) { |
Svet Ganov | 50a8bf4 | 2015-07-15 11:04:18 -0700 | [diff] [blame] | 797 | return null; |
| 798 | } |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 799 | ActivityInfo activityInfo = handler.activityInfo; |
| 800 | if (activityInfo.packageName.equals(mService.mResolveActivity.packageName) |
| 801 | && activityInfo.name.equals(mService.mResolveActivity.name)) { |
| 802 | return null; |
Svetoslav Ganov | d2bbf1b | 2015-11-06 00:24:47 +0000 | [diff] [blame] | 803 | } |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 804 | return getSystemPackageLPr(handler.activityInfo.packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 807 | private PackageParser.Package getDefaultSystemHandlerServicePackageLPr( |
| 808 | Intent intent, int userId) { |
| 809 | List<ResolveInfo> handlers = mService.queryIntentServices(intent, |
Jeff Sharkey | d589663 | 2016-03-04 16:16:00 -0700 | [diff] [blame] | 810 | intent.resolveType(mService.mContext.getContentResolver()), DEFAULT_FLAGS, userId) |
| 811 | .getList(); |
Svetoslav | c6ab8b9 | 2015-07-22 17:34:12 -0700 | [diff] [blame] | 812 | if (handlers == null) { |
| 813 | return null; |
| 814 | } |
| 815 | final int handlerCount = handlers.size(); |
| 816 | for (int i = 0; i < handlerCount; i++) { |
| 817 | ResolveInfo handler = handlers.get(i); |
| 818 | PackageParser.Package handlerPackage = getSystemPackageLPr( |
| 819 | handler.serviceInfo.packageName); |
| 820 | if (handlerPackage != null) { |
| 821 | return handlerPackage; |
| 822 | } |
| 823 | } |
| 824 | return null; |
| 825 | } |
| 826 | |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 827 | private List<PackageParser.Package> getHeadlessSyncAdapterPackagesLPr( |
| 828 | String[] syncAdapterPackageNames, int userId) { |
| 829 | List<PackageParser.Package> syncAdapterPackages = new ArrayList<>(); |
| 830 | |
| 831 | Intent homeIntent = new Intent(Intent.ACTION_MAIN); |
Svet Ganov | 05069b9 | 2015-08-01 12:19:26 -0700 | [diff] [blame] | 832 | homeIntent.addCategory(Intent.CATEGORY_LAUNCHER); |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 833 | |
| 834 | for (String syncAdapterPackageName : syncAdapterPackageNames) { |
| 835 | homeIntent.setPackage(syncAdapterPackageName); |
| 836 | |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 837 | ResolveInfo homeActivity = mService.resolveIntent(homeIntent, |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 838 | homeIntent.resolveType(mService.mContext.getContentResolver()), DEFAULT_FLAGS, |
| 839 | userId); |
Svetoslav | 5d05bbe | 2015-11-05 16:33:02 -0800 | [diff] [blame] | 840 | if (homeActivity != null) { |
Svetoslav | 0010b70 | 2015-06-30 18:05:26 -0700 | [diff] [blame] | 841 | continue; |
| 842 | } |
| 843 | |
| 844 | PackageParser.Package syncAdapterPackage = getSystemPackageLPr(syncAdapterPackageName); |
| 845 | if (syncAdapterPackage != null) { |
| 846 | syncAdapterPackages.add(syncAdapterPackage); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | return syncAdapterPackages; |
| 851 | } |
| 852 | |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 853 | private PackageParser.Package getDefaultProviderAuthorityPackageLPr( |
| 854 | String authority, int userId) { |
Jeff Sharkey | ba51235 | 2015-11-12 20:17:45 -0800 | [diff] [blame] | 855 | ProviderInfo provider = mService.resolveContentProvider(authority, DEFAULT_FLAGS, userId); |
Dianne Hackborn | ca8e6da | 2015-06-24 15:19:17 -0700 | [diff] [blame] | 856 | if (provider != null) { |
| 857 | return getSystemPackageLPr(provider.packageName); |
| 858 | } |
| 859 | return null; |
| 860 | } |
| 861 | |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 862 | private PackageParser.Package getPackageLPr(String packageName) { |
| 863 | return mService.mPackages.get(packageName); |
| 864 | } |
| 865 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 866 | private PackageParser.Package getSystemPackageLPr(String packageName) { |
Svetoslav | cdfd230 | 2015-06-25 19:07:31 -0700 | [diff] [blame] | 867 | PackageParser.Package pkg = getPackageLPr(packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 868 | if (pkg != null && pkg.isSystemApp()) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 869 | return !isSysComponentOrPersistentPlatformSignedPrivAppLPr(pkg) ? pkg : null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 870 | } |
| 871 | return null; |
| 872 | } |
| 873 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 874 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 875 | int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 876 | grantRuntimePermissionsLPw(pkg, permissions, false, false, userId); |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
| 880 | boolean systemFixed, int userId) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 881 | grantRuntimePermissionsLPw(pkg, permissions, systemFixed, false, userId); |
| 882 | } |
| 883 | |
| 884 | private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set<String> permissions, |
Svetoslav Ganov | 80d78dc | 2016-02-29 17:29:39 -0800 | [diff] [blame] | 885 | boolean systemFixed, boolean isDefaultPhoneOrSms, int userId) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 886 | if (pkg.requestedPermissions.isEmpty()) { |
| 887 | return; |
| 888 | } |
| 889 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 890 | List<String> requestedPermissions = pkg.requestedPermissions; |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 891 | Set<String> grantablePermissions = null; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 892 | |
Svetoslav Ganov | 80d78dc | 2016-02-29 17:29:39 -0800 | [diff] [blame] | 893 | // If this is the default Phone or SMS app we grant permissions regardless |
| 894 | // whether the version on the system image declares the permission as used since |
| 895 | // selecting the app as the default Phone or SMS the user makes a deliberate |
| 896 | // choice to grant this app the permissions needed to function. For all other |
| 897 | // apps, (default grants on first boot and user creation) we don't grant default |
| 898 | // permissions if the version on the system image does not declare them. |
| 899 | if (!isDefaultPhoneOrSms && pkg.isUpdatedSystemApp()) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 900 | PackageSetting sysPs = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
| 901 | if (sysPs != null) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 902 | if (sysPs.pkg.requestedPermissions.isEmpty()) { |
| 903 | return; |
| 904 | } |
| 905 | if (!requestedPermissions.equals(sysPs.pkg.requestedPermissions)) { |
| 906 | grantablePermissions = new ArraySet<>(requestedPermissions); |
| 907 | requestedPermissions = sysPs.pkg.requestedPermissions; |
| 908 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 912 | final int grantablePermissionCount = requestedPermissions.size(); |
| 913 | for (int i = 0; i < grantablePermissionCount; i++) { |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 914 | String permission = requestedPermissions.get(i); |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 915 | |
| 916 | // If there is a disabled system app it may request a permission the updated |
| 917 | // version ot the data partition doesn't, In this case skip the permission. |
| 918 | if (grantablePermissions != null && !grantablePermissions.contains(permission)) { |
| 919 | continue; |
| 920 | } |
| 921 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 922 | if (permissions.contains(permission)) { |
| 923 | final int flags = mService.getPermissionFlags(permission, pkg.packageName, userId); |
| 924 | |
| 925 | // If any flags are set to the permission, then it is either set in |
| 926 | // its current state by the system or device/profile owner or the user. |
| 927 | // 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] | 928 | // Unless the caller wants to override user choices. The override is |
| 929 | // to make sure we can grant the needed permission to the default |
| 930 | // sms and phone apps after the user chooses this in the UI. |
Svetoslav Ganov | 80d78dc | 2016-02-29 17:29:39 -0800 | [diff] [blame] | 931 | if (flags == 0 || isDefaultPhoneOrSms) { |
Svet Ganov | 4bb5187 | 2015-07-16 18:56:16 -0700 | [diff] [blame] | 932 | // Never clobber policy or system. |
| 933 | final int fixedFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED |
| 934 | | PackageManager.FLAG_PERMISSION_POLICY_FIXED; |
| 935 | if ((flags & fixedFlags) != 0) { |
| 936 | continue; |
| 937 | } |
| 938 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 939 | mService.grantRuntimePermission(pkg.packageName, permission, userId); |
| 940 | if (DEBUG) { |
Svetoslav | 5db602f | 2015-11-02 18:40:18 -0800 | [diff] [blame] | 941 | Log.i(TAG, "Granted " + (systemFixed ? "fixed " : "not fixed ") |
| 942 | + permission + " to default handler " + pkg.packageName); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 943 | } |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 944 | |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 945 | int newFlags = PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 946 | if (systemFixed) { |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 947 | newFlags |= PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
Svet Ganov | 6a166af | 2015-06-30 10:15:44 -0700 | [diff] [blame] | 948 | } |
Svet Ganov | 77ab6a8 | 2015-07-03 12:03:02 -0700 | [diff] [blame] | 949 | |
| 950 | mService.updatePermissionFlags(permission, pkg.packageName, |
| 951 | newFlags, newFlags, userId); |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 952 | } |
Svetoslav | 5db602f | 2015-11-02 18:40:18 -0800 | [diff] [blame] | 953 | |
| 954 | // If a component gets a permission for being the default handler A |
| 955 | // and also default handler B, we grant the weaker grant form. |
| 956 | if ((flags & PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0 |
| 957 | && (flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0 |
| 958 | && !systemFixed) { |
| 959 | if (DEBUG) { |
| 960 | Log.i(TAG, "Granted not fixed " + permission + " to default handler " |
| 961 | + pkg.packageName); |
| 962 | } |
| 963 | mService.updatePermissionFlags(permission, pkg.packageName, |
| 964 | PackageManager.FLAG_PERMISSION_SYSTEM_FIXED, 0, userId); |
| 965 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 966 | } |
| 967 | } |
| 968 | } |
| 969 | |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 970 | private boolean isSysComponentOrPersistentPlatformSignedPrivAppLPr(PackageParser.Package pkg) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 971 | if (UserHandle.getAppId(pkg.applicationInfo.uid) < FIRST_APPLICATION_UID) { |
| 972 | return true; |
| 973 | } |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 974 | if (!pkg.isPrivilegedApp()) { |
| 975 | return false; |
| 976 | } |
| 977 | PackageSetting sysPkg = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); |
Svet Ganov | f443384 | 2015-11-17 11:53:18 -0800 | [diff] [blame] | 978 | if (sysPkg != null && sysPkg.pkg != null) { |
Svetoslav | 4aa9797 | 2015-07-29 14:00:18 -0700 | [diff] [blame] | 979 | if ((sysPkg.pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
| 980 | return false; |
| 981 | } |
| 982 | } else if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) { |
Svet Ganov | 824d453 | 2015-07-10 18:25:48 -0700 | [diff] [blame] | 983 | return false; |
| 984 | } |
| 985 | return PackageManagerService.compareSignatures(mService.mPlatformPackage.mSignatures, |
| 986 | pkg.mSignatures) == PackageManager.SIGNATURE_MATCH; |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 989 | private void grantDefaultPermissionExceptions(int userId) { |
| 990 | synchronized (mService.mPackages) { |
| 991 | mHandler.removeMessages(MSG_READ_DEFAULT_PERMISSION_EXCEPTIONS); |
| 992 | |
| 993 | if (mGrantExceptions == null) { |
| 994 | mGrantExceptions = readDefaultPermissionExceptionsLPw(); |
| 995 | } |
| 996 | |
| 997 | // mGrantExceptions is null only before the first read and then |
| 998 | // it serves as a cache of the default grants that should be |
| 999 | // performed for every user. If there is an entry then the app |
| 1000 | // is on the system image and supports runtime permissions. |
| 1001 | Set<String> permissions = null; |
| 1002 | final int exceptionCount = mGrantExceptions.size(); |
| 1003 | for (int i = 0; i < exceptionCount; i++) { |
| 1004 | String packageName = mGrantExceptions.keyAt(i); |
| 1005 | PackageParser.Package pkg = getSystemPackageLPr(packageName); |
| 1006 | List<DefaultPermissionGrant> permissionGrants = mGrantExceptions.valueAt(i); |
| 1007 | final int permissionGrantCount = permissionGrants.size(); |
| 1008 | for (int j = 0; j < permissionGrantCount; j++) { |
| 1009 | DefaultPermissionGrant permissionGrant = permissionGrants.get(j); |
| 1010 | if (permissions == null) { |
| 1011 | permissions = new ArraySet<>(); |
| 1012 | } else { |
| 1013 | permissions.clear(); |
| 1014 | } |
| 1015 | permissions.add(permissionGrant.name); |
| 1016 | grantRuntimePermissionsLPw(pkg, permissions, false, |
| 1017 | permissionGrant.fixed, userId); |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | private @NonNull ArrayMap<String, List<DefaultPermissionGrant>> |
| 1024 | readDefaultPermissionExceptionsLPw() { |
| 1025 | File dir = new File(Environment.getRootDirectory(), "etc/default-permissions"); |
| 1026 | if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) { |
| 1027 | return new ArrayMap<>(0); |
| 1028 | } |
| 1029 | |
| 1030 | File[] files = dir.listFiles(); |
| 1031 | if (files == null) { |
| 1032 | return new ArrayMap<>(0); |
| 1033 | } |
| 1034 | |
| 1035 | ArrayMap<String, List<DefaultPermissionGrant>> grantExceptions = new ArrayMap<>(); |
| 1036 | |
| 1037 | // Iterate over the files in the directory and scan .xml files |
| 1038 | for (File file : files) { |
| 1039 | if (!file.getPath().endsWith(".xml")) { |
| 1040 | Slog.i(TAG, "Non-xml file " + file + " in " + dir + " directory, ignoring"); |
| 1041 | continue; |
| 1042 | } |
| 1043 | if (!file.canRead()) { |
| 1044 | Slog.w(TAG, "Default permissions file " + file + " cannot be read"); |
| 1045 | continue; |
| 1046 | } |
| 1047 | try ( |
| 1048 | InputStream str = new BufferedInputStream(new FileInputStream(file)) |
| 1049 | ) { |
| 1050 | XmlPullParser parser = Xml.newPullParser(); |
| 1051 | parser.setInput(str, null); |
| 1052 | parse(parser, grantExceptions); |
| 1053 | } catch (XmlPullParserException | IOException e) { |
| 1054 | Slog.w(TAG, "Error reading default permissions file " + file, e); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | return grantExceptions; |
| 1059 | } |
| 1060 | |
| 1061 | private void parse(XmlPullParser parser, Map<String, List<DefaultPermissionGrant>> |
| 1062 | outGrantExceptions) throws IOException, XmlPullParserException { |
| 1063 | final int outerDepth = parser.getDepth(); |
| 1064 | int type; |
| 1065 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1066 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1067 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1068 | continue; |
| 1069 | } |
| 1070 | if (TAG_EXCEPTIONS.equals(parser.getName())) { |
| 1071 | parseExceptions(parser, outGrantExceptions); |
| 1072 | } else { |
| 1073 | Log.e(TAG, "Unknown tag " + parser.getName()); |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | private void parseExceptions(XmlPullParser parser, Map<String, List<DefaultPermissionGrant>> |
| 1079 | outGrantExceptions) throws IOException, XmlPullParserException { |
| 1080 | final int outerDepth = parser.getDepth(); |
| 1081 | int type; |
| 1082 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1083 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1084 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1085 | continue; |
| 1086 | } |
| 1087 | if (TAG_EXCEPTION.equals(parser.getName())) { |
| 1088 | String packageName = parser.getAttributeValue(null, ATTR_PACKAGE); |
| 1089 | |
| 1090 | List<DefaultPermissionGrant> packageExceptions = |
| 1091 | outGrantExceptions.get(packageName); |
| 1092 | if (packageExceptions == null) { |
| 1093 | // The package must be on the system image |
| 1094 | PackageParser.Package pkg = getSystemPackageLPr(packageName); |
| 1095 | if (pkg == null) { |
| 1096 | Log.w(TAG, "Unknown package:" + packageName); |
| 1097 | XmlUtils.skipCurrentTag(parser); |
Stuart Scott | 434c8db | 2016-09-21 14:04:22 -0700 | [diff] [blame] | 1098 | continue; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | // The package must support runtime permissions |
| 1102 | if (!doesPackageSupportRuntimePermissions(pkg)) { |
| 1103 | Log.w(TAG, "Skipping non supporting runtime permissions package:" |
| 1104 | + packageName); |
| 1105 | XmlUtils.skipCurrentTag(parser); |
Stuart Scott | 434c8db | 2016-09-21 14:04:22 -0700 | [diff] [blame] | 1106 | continue; |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 1107 | } |
| 1108 | packageExceptions = new ArrayList<>(); |
| 1109 | outGrantExceptions.put(packageName, packageExceptions); |
| 1110 | } |
| 1111 | |
| 1112 | parsePermission(parser, packageExceptions); |
| 1113 | } else { |
| 1114 | Log.e(TAG, "Unknown tag " + parser.getName() + "under <exceptions>"); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | private void parsePermission(XmlPullParser parser, List<DefaultPermissionGrant> |
| 1120 | outPackageExceptions) throws IOException, XmlPullParserException { |
| 1121 | final int outerDepth = parser.getDepth(); |
| 1122 | int type; |
| 1123 | while ((type = parser.next()) != XmlPullParser.END_DOCUMENT |
| 1124 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 1125 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 1126 | continue; |
| 1127 | } |
| 1128 | |
| 1129 | if (TAG_PERMISSION.contains(parser.getName())) { |
| 1130 | String name = parser.getAttributeValue(null, ATTR_NAME); |
| 1131 | if (name == null) { |
| 1132 | Log.w(TAG, "Mandatory name attribute missing for permission tag"); |
| 1133 | XmlUtils.skipCurrentTag(parser); |
| 1134 | continue; |
| 1135 | } |
| 1136 | |
| 1137 | final boolean fixed = XmlUtils.readBooleanAttribute(parser, ATTR_FIXED); |
| 1138 | |
| 1139 | DefaultPermissionGrant exception = new DefaultPermissionGrant(name, fixed); |
| 1140 | outPackageExceptions.add(exception); |
| 1141 | } else { |
| 1142 | Log.e(TAG, "Unknown tag " + parser.getName() + "under <exception>"); |
| 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1147 | private static boolean doesPackageSupportRuntimePermissions(PackageParser.Package pkg) { |
| 1148 | return pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1; |
| 1149 | } |
Svet Ganov | 59020bf | 2016-08-18 12:32:35 -0700 | [diff] [blame] | 1150 | |
| 1151 | private static final class DefaultPermissionGrant { |
| 1152 | final String name; |
| 1153 | final boolean fixed; |
| 1154 | |
| 1155 | public DefaultPermissionGrant(String name, boolean fixed) { |
| 1156 | this.name = name; |
| 1157 | this.fixed = fixed; |
| 1158 | } |
| 1159 | } |
Svet Ganov | adc1cf4 | 2015-06-15 16:36:24 -0700 | [diff] [blame] | 1160 | } |