blob: e65e742cb6ec5ec04a9d595ff8791c7a824d8ae5 [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. Moltmann0635dab2019-03-02 11:19:03 -080019import static android.content.res.Resources.ID_NULL;
20
21import android.annotation.IntDef;
22import android.annotation.NonNull;
23import android.annotation.Nullable;
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -070024import android.annotation.StringRes;
25import android.annotation.SystemApi;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.os.Parcel;
27import android.os.Parcelable;
28import android.text.TextUtils;
29
Philip P. Moltmann0635dab2019-03-02 11:19:03 -080030import java.lang.annotation.Retention;
31import java.lang.annotation.RetentionPolicy;
32
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033/**
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 */
38public 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 */
Philip P. Moltmann0635dab2019-03-02 11:19:03 -080044 public @StringRes int descriptionRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46 /**
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -070047 * 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 /**
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070056 * 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
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080060 * android.content.res.Resources#ID_NULL}.
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070061 *
62 * @hide
63 */
64 @SystemApi
Philip P. Moltmann0635dab2019-03-02 11:19:03 -080065 public final @StringRes int requestDetailResourceId;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070066
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
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080072 * android.content.res.Resources#ID_NULL}.
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070073 *
74 * @hide
75 */
76 @SystemApi
Philip P. Moltmann0635dab2019-03-02 11:19:03 -080077 public final @StringRes int backgroundRequestResourceId;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070078
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
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080084 * android.content.res.Resources#ID_NULL}.
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070085 *
86 * @hide
87 */
88 @SystemApi
Philip P. Moltmann0635dab2019-03-02 11:19:03 -080089 public final @StringRes int backgroundRequestDetailResourceId;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070090
91 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 * 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 */
Philip P. Moltmann0635dab2019-03-02 11:19:03 -080097 public @Nullable CharSequence nonLocalizedDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098
Dianne Hackbornfd5015b2012-04-30 16:33:56 -070099 /**
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
Philip P. Moltmann0635dab2019-03-02 11:19:03 -0800105 /** @hide */
106 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
107 FLAG_PERSONAL_INFO,
108 })
109 @Retention(RetentionPolicy.SOURCE)
110 public @interface Flags {}
111
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700112 /**
113 * Additional flags about this group as given by
114 * {@link android.R.attr#permissionGroupFlags}.
115 */
Philip P. Moltmann0635dab2019-03-02 11:19:03 -0800116 public @Flags int flags;
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700117
118 /**
119 * Prioritization of this group, for visually sorting with other groups.
120 */
121 public int priority;
122
Philip P. Moltmann0635dab2019-03-02 11:19:03 -0800123 /**
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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 }
133
Philip P. Moltmann0635dab2019-03-02 11:19:03 -0800134 /**
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) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 super(orig);
148 descriptionRes = orig.descriptionRes;
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700149 requestRes = orig.requestRes;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700150 requestDetailResourceId = orig.requestDetailResourceId;
151 backgroundRequestResourceId = orig.backgroundRequestResourceId;
152 backgroundRequestDetailResourceId = orig.backgroundRequestDetailResourceId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 nonLocalizedDescription = orig.nonLocalizedDescription;
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700154 flags = orig.flags;
155 priority = orig.priority;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 }
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 */
Philip P. Moltmann0635dab2019-03-02 11:19:03 -0800169 public @Nullable CharSequence loadDescription(@NonNull PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 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))
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700185 + " " + name + " flgs=0x" + Integer.toHexString(flags) + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 }
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);
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700195 dest.writeInt(requestRes);
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700196 dest.writeInt(requestDetailResourceId);
197 dest.writeInt(backgroundRequestResourceId);
198 dest.writeInt(backgroundRequestDetailResourceId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700200 dest.writeInt(flags);
201 dest.writeInt(priority);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 }
203
Philip P. Moltmann0635dab2019-03-02 11:19:03 -0800204 public static final @NonNull Creator<PermissionGroupInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 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();
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700217 requestRes = source.readInt();
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700218 requestDetailResourceId = source.readInt();
219 backgroundRequestResourceId = source.readInt();
220 backgroundRequestDetailResourceId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700222 flags = source.readInt();
223 priority = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 }
225}