From 27ffeb33fb60d4ee6a4c2dfd9391c8a6127dfc7c Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Thu, 6 Jul 2017 13:54:46 -0700 Subject: [PATCH] Better translatable msgs for permission requests Only for system permissions & groups for now and fall back to old system for everything else. Bug: 32070095 Test: Opened camera and saw new string Change-Id: If25308b6cd7cddccaf63ea5ed6c10c037e3c1778 --- api/system-current.txt | 2 ++ .../android/content/pm/PackageParser.java | 6 +++++ .../content/pm/PermissionGroupInfo.java | 14 ++++++++++ .../android/content/pm/PermissionInfo.java | 12 +++++++++ core/res/AndroidManifest.xml | 9 +++++++ core/res/res/values/attrs_manifest.xml | 2 ++ core/res/res/values/strings.xml | 27 +++++++++++++++++++ 7 files changed, 72 insertions(+) diff --git a/api/system-current.txt b/api/system-current.txt index d98319cc9c798..d5c6d2c2c3b22 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -11635,6 +11635,7 @@ package android.content.pm { field public int flags; field public java.lang.CharSequence nonLocalizedDescription; field public int priority; + field public int requestRes; } public class PermissionInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable { @@ -11668,6 +11669,7 @@ package android.content.pm { field public java.lang.String group; field public java.lang.CharSequence nonLocalizedDescription; field public int protectionLevel; + field public int requestRes; } public final class ProviderInfo extends android.content.pm.ComponentInfo implements android.os.Parcelable { diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java index e4f2fc1c50351..0ec691beaaf98 100644 --- a/core/java/android/content/pm/PackageParser.java +++ b/core/java/android/content/pm/PackageParser.java @@ -3132,6 +3132,8 @@ public class PackageParser { perm.info.descriptionRes = sa.getResourceId( com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, 0); + perm.info.requestRes = sa.getResourceId( + com.android.internal.R.styleable.AndroidManifestPermissionGroup_request, 0); perm.info.flags = sa.getInt( com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); perm.info.priority = sa.getInt( @@ -3186,6 +3188,9 @@ public class PackageParser { com.android.internal.R.styleable.AndroidManifestPermission_description, 0); + perm.info.requestRes = sa.getResourceId( + com.android.internal.R.styleable.AndroidManifestPermission_request, 0); + perm.info.protectionLevel = sa.getInt( com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, PermissionInfo.PROTECTION_NORMAL); @@ -3260,6 +3265,7 @@ public class PackageParser { } perm.info.descriptionRes = 0; + perm.info.requestRes = 0; perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; perm.tree = true; diff --git a/core/java/android/content/pm/PermissionGroupInfo.java b/core/java/android/content/pm/PermissionGroupInfo.java index 452bf0d2b6a10..7c4478d0b689f 100644 --- a/core/java/android/content/pm/PermissionGroupInfo.java +++ b/core/java/android/content/pm/PermissionGroupInfo.java @@ -16,6 +16,8 @@ package android.content.pm; +import android.annotation.StringRes; +import android.annotation.SystemApi; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; @@ -33,6 +35,15 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable { */ public int descriptionRes; + /** + * A string resource identifier (in the package's resources) used to request the permissions. + * From the "request" attribute or, if not set, 0. + * + * @hide + */ + @SystemApi + public @StringRes int requestRes; + /** * The description string provided in the AndroidManifest file, if any. You * probably don't want to use this, since it will be null if the description @@ -64,6 +75,7 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable { public PermissionGroupInfo(PermissionGroupInfo orig) { super(orig); descriptionRes = orig.descriptionRes; + requestRes = orig.requestRes; nonLocalizedDescription = orig.nonLocalizedDescription; flags = orig.flags; priority = orig.priority; @@ -106,6 +118,7 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable { public void writeToParcel(Parcel dest, int parcelableFlags) { super.writeToParcel(dest, parcelableFlags); dest.writeInt(descriptionRes); + dest.writeInt(requestRes); TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags); dest.writeInt(flags); dest.writeInt(priority); @@ -124,6 +137,7 @@ public class PermissionGroupInfo extends PackageItemInfo implements Parcelable { private PermissionGroupInfo(Parcel source) { super(source); descriptionRes = source.readInt(); + requestRes = source.readInt(); nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); flags = source.readInt(); priority = source.readInt(); diff --git a/core/java/android/content/pm/PermissionInfo.java b/core/java/android/content/pm/PermissionInfo.java index 694e607815465..71a6321897963 100644 --- a/core/java/android/content/pm/PermissionInfo.java +++ b/core/java/android/content/pm/PermissionInfo.java @@ -197,6 +197,15 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable { */ public int descriptionRes; + /** + * A string resource identifier (in the package's resources) used to request the permissions. + * From the "request" attribute or, if not set, 0. + * + * @hide + */ + @SystemApi + public int requestRes; + /** * The description string provided in the AndroidManifest file, if any. You * probably don't want to use this, since it will be null if the description @@ -272,6 +281,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable { flags = orig.flags; group = orig.group; descriptionRes = orig.descriptionRes; + requestRes = orig.requestRes; nonLocalizedDescription = orig.nonLocalizedDescription; } @@ -315,6 +325,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable { dest.writeInt(flags); dest.writeString(group); dest.writeInt(descriptionRes); + dest.writeInt(requestRes); TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags); } @@ -334,6 +345,7 @@ public class PermissionInfo extends PackageItemInfo implements Parcelable { flags = source.readInt(); group = source.readString(); descriptionRes = source.readInt(); + requestRes = source.readInt(); nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); } } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index a3cb35036dcd7..2907c8652ddbe 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -562,6 +562,7 @@ android:icon="@drawable/perm_group_contacts" android:label="@string/permgrouplab_contacts" android:description="@string/permgroupdesc_contacts" + android:request="@string/permgrouprequest_contacts" android:priority="100" /> access your contacts + + Allow + <b>%1$s</b> to access your contacts Location access this device\'s location + + Allow + <b>%1$s</b> to access this device\'s location Calendar access your calendar + + Allow + <b>%1$s</b> to access your calendar SMS send and view SMS messages + + Allow + <b>%1$s</b> to send and view SMS messages Storage access photos, media, and files on your device + + Allow + <b>%1$s</b> to access photos, media, and files on your device Microphone record audio + + Allow + <b>%1$s</b> to record audio Camera take pictures and record video + + Allow + <b>%1$s</b> to take pictures and record video Phone make and manage phone calls + + Allow + <b>%1$s</b> to make and manage phone calls Body Sensors access sensor data about your vital signs + + Allow + <b>%1$s</b> to access sensor data about your vital signs Retrieve window content