Debian Codegraph @

core/java/android/content/pm/PermissionGroupInfo.java

raw symbols SCIP
1 /*
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
17 package android.content.pm;
18
19 import static android.content.res.Resources.ID_NULL;
20
21 import android.annotation.IntDef;
22 import android.annotation.NonNull;
23 import android.annotation.Nullable;
24 import android.annotation.StringRes;
25 import android.annotation.SystemApi;
26 import android.os.Parcel;
27 import android.os.Parcelable;
28 import android.text.TextUtils;
29
30 import java.lang.annotation.Retention;
31 import java.lang.annotation.RetentionPolicy;
32
33 /**
34 * Information you can retrieve about a particular security permission
35 * group known to the system. This corresponds to information collected from the
36 * AndroidManifest.xml's <permission-group> tags.
37 */
38 public class PermissionGroupInfo extends PackageItemInfo implements Parcelable {
39 /**
40 * A string resource identifier (in the package's resources) of this
41 * permission's description. From the "description" attribute or,
42 * if not set, 0.
43 */
44 public @StringRes int descriptionRes;
45
46 /**
47 * A string resource identifier (in the package's resources) used to request the permissions.
48 * From the "request" attribute or, if not set, 0.
49 *
50 * @hide
51 */
52 @SystemApi
53 public @StringRes int requestRes;
54
55 /**
56 * A string resource identifier (in the package's resources) used as subtitle when requesting
57 * only access while in the foreground.
58 *
59 * From the "requestDetail" attribute or, if not set, {@link
60 * android.content.res.Resources#ID_NULL}.
61 *
62 * @hide
63 */
64 @SystemApi
65 public final @StringRes int requestDetailResourceId;
66
67 /**
68 * A string resource identifier (in the package's resources) used when requesting background
69 * access. Also used when requesting both foreground and background access.
70 *
71 * From the "backgroundRequest" attribute or, if not set, {@link
72 * android.content.res.Resources#ID_NULL}.
73 *
74 * @hide
75 */
76 @SystemApi
77 public final @StringRes int backgroundRequestResourceId;
78
79 /**
80 * A string resource identifier (in the package's resources) used as subtitle when requesting
81 * background access.
82 *
83 * From the "backgroundRequestDetail" attribute or, if not set, {@link
84 * android.content.res.Resources#ID_NULL}.
85 *
86 * @hide
87 */
88 @SystemApi
89 public final @StringRes int backgroundRequestDetailResourceId;
90
91 /**
92 * The description string provided in the AndroidManifest file, if any. You
93 * probably don't want to use this, since it will be null if the description
94 * is in a resource. You probably want
95 * {@link PermissionInfo#loadDescription} instead.
96 */
97 public @Nullable CharSequence nonLocalizedDescription;
98
99 /**
100 * Flag for {@link #flags}, corresponding to <code>personalInfo</code>
101 * value of {@link android.R.attr#permissionGroupFlags}.
102 */
103 public static final int FLAG_PERSONAL_INFO = 1<<0;
104
105 /** @hide */
106 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
107 FLAG_PERSONAL_INFO,
108 })
109 @Retention(RetentionPolicy.SOURCE)
110 public @interface Flags {}
111
112 /**
113 * Additional flags about this group as given by
114 * {@link android.R.attr#permissionGroupFlags}.
115 */
116 public @Flags int flags;
117
118 /**
119 * Prioritization of this group, for visually sorting with other groups.
120 */
121 public int priority;
122
123 /**
124 * @hide
125 */
126 public PermissionGroupInfo(@StringRes int requestDetailResourceId,
127 @StringRes int backgroundRequestResourceId,
128 @StringRes int backgroundRequestDetailResourceId) {
129 this.requestDetailResourceId = requestDetailResourceId;
130 this.backgroundRequestResourceId = backgroundRequestResourceId;
131 this.backgroundRequestDetailResourceId = backgroundRequestDetailResourceId;
132 }
133
134 /**
135 * @deprecated Should only be created by the system.
136 */
137 @Deprecated
138 public PermissionGroupInfo() {
139 this(ID_NULL, ID_NULL, ID_NULL);
140 }
141
142 /**
143 * @deprecated Should only be created by the system.
144 */
145 @Deprecated
146 public PermissionGroupInfo(@NonNull PermissionGroupInfo orig) {
147 super(orig);
148 descriptionRes = orig.descriptionRes;
149 requestRes = orig.requestRes;
150 requestDetailResourceId = orig.requestDetailResourceId;
151 backgroundRequestResourceId = orig.backgroundRequestResourceId;
152 backgroundRequestDetailResourceId = orig.backgroundRequestDetailResourceId;
153 nonLocalizedDescription = orig.nonLocalizedDescription;
154 flags = orig.flags;
155 priority = orig.priority;
156 }
157
158 /**
159 * Retrieve the textual description of this permission. This
160 * will call back on the given PackageManager to load the description from
161 * the application.
162 *
163 * @param pm A PackageManager from which the label can be loaded; usually
164 * the PackageManager from which you originally retrieved this item.
165 *
166 * @return Returns a CharSequence containing the permission's description.
167 * If there is no description, null is returned.
168 */
169 public @Nullable CharSequence loadDescription(@NonNull PackageManager pm) {
170 if (nonLocalizedDescription != null) {
171 return nonLocalizedDescription;
172 }
173 if (descriptionRes != 0) {
174 CharSequence label = pm.getText(packageName, descriptionRes, null);
175 if (label != null) {
176 return label;
177 }
178 }
179 return null;
180 }
181
182 public String toString() {
183 return "PermissionGroupInfo{"
184 + Integer.toHexString(System.identityHashCode(this))
185 + " " + name + " flgs=0x" + Integer.toHexString(flags) + "}";
186 }
187
188 public int describeContents() {
189 return 0;
190 }
191
192 public void writeToParcel(Parcel dest, int parcelableFlags) {
193 super.writeToParcel(dest, parcelableFlags);
194 dest.writeInt(descriptionRes);
195 dest.writeInt(requestRes);
196 dest.writeInt(requestDetailResourceId);
197 dest.writeInt(backgroundRequestResourceId);
198 dest.writeInt(backgroundRequestDetailResourceId);
199 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
200 dest.writeInt(flags);
201 dest.writeInt(priority);
202 }
203
204 public static final @NonNull Creator<PermissionGroupInfo> CREATOR =
205 new Creator<PermissionGroupInfo>() {
206 public PermissionGroupInfo createFromParcel(Parcel source) {
207 return new PermissionGroupInfo(source);
208 }
209 public PermissionGroupInfo[] newArray(int size) {
210 return new PermissionGroupInfo[size];
211 }
212 };
213
214 private PermissionGroupInfo(Parcel source) {
215 super(source);
216 descriptionRes = source.readInt();
217 requestRes = source.readInt();
218 requestDetailResourceId = source.readInt();
219 backgroundRequestResourceId = source.readInt();
220 backgroundRequestDetailResourceId = source.readInt();
221 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
222 flags = source.readInt();
223 priority = source.readInt();
224 }
225 }