From 80d78dc92bed0873d03e357e025f994af1217577 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Mon, 29 Feb 2016 17:29:39 -0800 Subject: [PATCH] Proper grant default permissions to default SMS and Phone We grant default permissions to the default SMS and Phone apps when they are selected as such to ensure they can do their job. We don't grant default permissions to apps if the version on the system image does not declare them. This is correct for default grants on first boot or a new user creation. This is a problem for default Phone and SMS as we want to grant them the permission as a result of a deliberate user action and therefore should not care if the version on the system image declares the permission. As a result if an SMS app that ships as a stub to reduce image size is later updated to the full version and made the default SMS it would not get the default grants while an installed third-party app that did not ship on the system image would get the grants. This change ensures the default SMS and Phone get their default grants regardless whether the verion on the system image declares the permissions. bug:25288760 Change-Id: I2fecf5cbce4ebabb145a3f29abb555bcb65d54d6 --- .../server/pm/DefaultPermissionGrantPolicy.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java index 9a5a183233e2e..d6b59f9ab35a6 100644 --- a/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java +++ b/services/core/java/com/android/server/pm/DefaultPermissionGrantPolicy.java @@ -788,7 +788,7 @@ final class DefaultPermissionGrantPolicy { } private void grantRuntimePermissionsLPw(PackageParser.Package pkg, Set permissions, - boolean systemFixed, boolean overrideUserChoice, int userId) { + boolean systemFixed, boolean isDefaultPhoneOrSms, int userId) { if (pkg.requestedPermissions.isEmpty()) { return; } @@ -796,7 +796,13 @@ final class DefaultPermissionGrantPolicy { List requestedPermissions = pkg.requestedPermissions; Set grantablePermissions = null; - if (pkg.isUpdatedSystemApp()) { + // If this is the default Phone or SMS app we grant permissions regardless + // whether the version on the system image declares the permission as used since + // selecting the app as the default Phone or SMS the user makes a deliberate + // choice to grant this app the permissions needed to function. For all other + // apps, (default grants on first boot and user creation) we don't grant default + // permissions if the version on the system image does not declare them. + if (!isDefaultPhoneOrSms && pkg.isUpdatedSystemApp()) { PackageSetting sysPs = mService.mSettings.getDisabledSystemPkgLPr(pkg.packageName); if (sysPs != null) { if (sysPs.pkg.requestedPermissions.isEmpty()) { @@ -828,7 +834,7 @@ final class DefaultPermissionGrantPolicy { // Unless the caller wants to override user choices. The override is // to make sure we can grant the needed permission to the default // sms and phone apps after the user chooses this in the UI. - if (flags == 0 || overrideUserChoice) { + if (flags == 0 || isDefaultPhoneOrSms) { // Never clobber policy or system. final int fixedFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED | PackageManager.FLAG_PERMISSION_POLICY_FIXED;