2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.content.pm;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.text.TextUtils;
24 * Information you can retrieve about a particular security permission
25 * known to the system. This corresponds to information collected from the
26 * AndroidManifest.xml's <permission> tags.
28 public class PermissionInfo extends PackageItemInfo implements Parcelable {
30 * A normal application value for {@link #protectionLevel}, corresponding
31 * to the <code>normal</code> value of
32 * {@link android.R.attr#protectionLevel}.
34 public static final int PROTECTION_NORMAL = 0;
37 * Dangerous value for {@link #protectionLevel}, corresponding
38 * to the <code>dangerous</code> value of
39 * {@link android.R.attr#protectionLevel}.
41 public static final int PROTECTION_DANGEROUS = 1;
44 * System-level value for {@link #protectionLevel}, corresponding
45 * to the <code>signature</code> value of
46 * {@link android.R.attr#protectionLevel}.
48 public static final int PROTECTION_SIGNATURE = 2;
51 * System-level value for {@link #protectionLevel}, corresponding
52 * to the <code>signatureOrSystem</code> value of
53 * {@link android.R.attr#protectionLevel}.
55 public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3;
58 * The group this permission is a part of, as per
59 * {@link android.R.attr#permissionGroup}.
64 * A string resource identifier (in the package's resources) of this
65 * permission's description. From the "description" attribute or,
68 public int descriptionRes;
71 * The description string provided in the AndroidManifest file, if any. You
72 * probably don't want to use this, since it will be null if the description
73 * is in a resource. You probably want
74 * {@link PermissionInfo#loadDescription} instead.
76 public CharSequence nonLocalizedDescription;
79 * The level of access this permission is protecting, as per
80 * {@link android.R.attr#protectionLevel}. Values may be
81 * {@link #PROTECTION_NORMAL}, {@link #PROTECTION_DANGEROUS}, or
82 * {@link #PROTECTION_SIGNATURE}.
84 public int protectionLevel;
86 public PermissionInfo() {
89 public PermissionInfo(PermissionInfo orig) {
92 descriptionRes = orig.descriptionRes;
93 protectionLevel = orig.protectionLevel;
94 nonLocalizedDescription = orig.nonLocalizedDescription;
98 * Retrieve the textual description of this permission. This
99 * will call back on the given PackageManager to load the description from
102 * @param pm A PackageManager from which the label can be loaded; usually
103 * the PackageManager from which you originally retrieved this item.
105 * @return Returns a CharSequence containing the permission's description.
106 * If there is no description, null is returned.
108 public CharSequence loadDescription(PackageManager pm) {
109 if (nonLocalizedDescription != null) {
110 return nonLocalizedDescription;
112 if (descriptionRes != 0) {
113 CharSequence label = pm.getText(packageName, descriptionRes, null);
121 public String toString() {
122 return "PermissionInfo{"
123 + Integer.toHexString(System.identityHashCode(this))
127 public int describeContents() {
131 public void writeToParcel(Parcel dest, int parcelableFlags) {
132 super.writeToParcel(dest, parcelableFlags);
133 dest.writeString(group);
134 dest.writeInt(descriptionRes);
135 dest.writeInt(protectionLevel);
136 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
139 public static final Creator<PermissionInfo> CREATOR =
140 new Creator<PermissionInfo>() {
141 public PermissionInfo createFromParcel(Parcel source) {
142 return new PermissionInfo(source);
144 public PermissionInfo[] newArray(int size) {
145 return new PermissionInfo[size];
149 private PermissionInfo(Parcel source) {
151 group = source.readString();
152 descriptionRes = source.readInt();
153 protectionLevel = source.readInt();
154 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);