From 035f80d7c75b282f33ab10a33a3019f614ffd67d Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Wed, 27 Mar 2013 15:20:08 -0700 Subject: [PATCH] Add buildPermissionRequestIntent to PackageManager Add the buildPermissionRequestIntent API to PackageManager. This allows an app to request an Intent which, when passed to startActivityForResult, will prompt the user to approve permissions for an app. Currently, the API is @hide. It will be unhidden in a future change. Change-Id: I4ec677002afa799a6eb5c2657c28452c91012436 --- .../android/content/pm/PackageManager.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 0bea13818057e..e183bf3c4291d 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -1263,6 +1263,23 @@ public abstract class PackageManager { public static final String EXTRA_VERIFICATION_VERSION_CODE = "android.content.pm.extra.VERIFICATION_VERSION_CODE"; + /** + * The action used to request that the user approve a permission request + * from the application. + * + * @hide + */ + public static final String ACTION_REQUEST_PERMISSION + = "android.content.pm.action.REQUEST_PERMISSION"; + + /** + * Extra field name for the list of permissions, which the user must approve. + * + * @hide + */ + public static final String EXTRA_REQUEST_PERMISSION_PERMISSION_LIST + = "android.content.pm.extra.PERMISSION_LIST"; + /** * Retrieve overall information about an application package that is * installed on the system. @@ -1734,6 +1751,30 @@ public abstract class PackageManager { */ public abstract void removePermission(String name); + /** + * Returns an {@link Intent} suitable for passing to {@code startActivityForResult} + * which prompts the user to grant {@code permissions} to this application. + * @hide + * + * @throws NullPointerException if {@code permissions} is {@code null}. + * @throws IllegalArgumentException if {@code permissions} contains {@code null}. + */ + public Intent buildPermissionRequestIntent(String... permissions) { + if (permissions == null) { + throw new NullPointerException("permissions cannot be null"); + } + for (String permission : permissions) { + if (permission == null) { + throw new IllegalArgumentException("permissions cannot contain null"); + } + } + + Intent i = new Intent(ACTION_REQUEST_PERMISSION); + i.putExtra(EXTRA_REQUEST_PERMISSION_PERMISSION_LIST, permissions); + i.setPackage("com.android.packageinstaller"); + return i; + } + /** * Grant a permission to an application which the application does not * already have. The permission must have been requested by the application,