blob: 7c4478d0b689fab354d9a5afd1630a196a20cfb1 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
17package android.content.pm;
18
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -070019import android.annotation.StringRes;
20import android.annotation.SystemApi;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.os.Parcel;
22import android.os.Parcelable;
23import android.text.TextUtils;
24
25/**
26 * Information you can retrieve about a particular security permission
27 * group known to the system. This corresponds to information collected from the
28 * AndroidManifest.xml's <permission-group> tags.
29 */
30public class PermissionGroupInfo extends PackageItemInfo implements Parcelable {
31 /**
32 * A string resource identifier (in the package's resources) of this
33 * permission's description. From the "description" attribute or,
34 * if not set, 0.
35 */
36 public int descriptionRes;
37
38 /**
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -070039 * A string resource identifier (in the package's resources) used to request the permissions.
40 * From the "request" attribute or, if not set, 0.
41 *
42 * @hide
43 */
44 @SystemApi
45 public @StringRes int requestRes;
46
47 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 * The description string provided in the AndroidManifest file, if any. You
49 * probably don't want to use this, since it will be null if the description
50 * is in a resource. You probably want
51 * {@link PermissionInfo#loadDescription} instead.
52 */
53 public CharSequence nonLocalizedDescription;
54
Dianne Hackbornfd5015b2012-04-30 16:33:56 -070055 /**
56 * Flag for {@link #flags}, corresponding to <code>personalInfo</code>
57 * value of {@link android.R.attr#permissionGroupFlags}.
58 */
59 public static final int FLAG_PERSONAL_INFO = 1<<0;
60
61 /**
62 * Additional flags about this group as given by
63 * {@link android.R.attr#permissionGroupFlags}.
64 */
65 public int flags;
66
67 /**
68 * Prioritization of this group, for visually sorting with other groups.
69 */
70 public int priority;
71
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 public PermissionGroupInfo() {
73 }
74
75 public PermissionGroupInfo(PermissionGroupInfo orig) {
76 super(orig);
77 descriptionRes = orig.descriptionRes;
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -070078 requestRes = orig.requestRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 nonLocalizedDescription = orig.nonLocalizedDescription;
Dianne Hackbornfd5015b2012-04-30 16:33:56 -070080 flags = orig.flags;
81 priority = orig.priority;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080082 }
83
84 /**
85 * Retrieve the textual description of this permission. This
86 * will call back on the given PackageManager to load the description from
87 * the application.
88 *
89 * @param pm A PackageManager from which the label can be loaded; usually
90 * the PackageManager from which you originally retrieved this item.
91 *
92 * @return Returns a CharSequence containing the permission's description.
93 * If there is no description, null is returned.
94 */
95 public CharSequence loadDescription(PackageManager pm) {
96 if (nonLocalizedDescription != null) {
97 return nonLocalizedDescription;
98 }
99 if (descriptionRes != 0) {
100 CharSequence label = pm.getText(packageName, descriptionRes, null);
101 if (label != null) {
102 return label;
103 }
104 }
105 return null;
106 }
107
108 public String toString() {
109 return "PermissionGroupInfo{"
110 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700111 + " " + name + " flgs=0x" + Integer.toHexString(flags) + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 }
113
114 public int describeContents() {
115 return 0;
116 }
117
118 public void writeToParcel(Parcel dest, int parcelableFlags) {
119 super.writeToParcel(dest, parcelableFlags);
120 dest.writeInt(descriptionRes);
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700121 dest.writeInt(requestRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700123 dest.writeInt(flags);
124 dest.writeInt(priority);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 }
126
127 public static final Creator<PermissionGroupInfo> CREATOR =
128 new Creator<PermissionGroupInfo>() {
129 public PermissionGroupInfo createFromParcel(Parcel source) {
130 return new PermissionGroupInfo(source);
131 }
132 public PermissionGroupInfo[] newArray(int size) {
133 return new PermissionGroupInfo[size];
134 }
135 };
136
137 private PermissionGroupInfo(Parcel source) {
138 super(source);
139 descriptionRes = source.readInt();
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700140 requestRes = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700142 flags = source.readInt();
143 priority = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 }
145}