blob: f21612a58a53111b05b1845e00e689d3021023e9 [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 /**
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070048 * A string resource identifier (in the package's resources) used as subtitle when requesting
49 * only access while in the foreground.
50 *
51 * From the "requestDetail" attribute or, if not set, {@link
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080052 * android.content.res.Resources#ID_NULL}.
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070053 *
54 * @hide
55 */
56 @SystemApi
57 public @StringRes int requestDetailResourceId;
58
59 /**
60 * A string resource identifier (in the package's resources) used when requesting background
61 * access. Also used when requesting both foreground and background access.
62 *
63 * From the "backgroundRequest" attribute or, if not set, {@link
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080064 * android.content.res.Resources#ID_NULL}.
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070065 *
66 * @hide
67 */
68 @SystemApi
69 public @StringRes int backgroundRequestResourceId;
70
71 /**
72 * A string resource identifier (in the package's resources) used as subtitle when requesting
73 * background access.
74 *
75 * From the "backgroundRequestDetail" attribute or, if not set, {@link
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080076 * android.content.res.Resources#ID_NULL}.
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -070077 *
78 * @hide
79 */
80 @SystemApi
81 public @StringRes int backgroundRequestDetailResourceId;
82
83 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 * The description string provided in the AndroidManifest file, if any. You
85 * probably don't want to use this, since it will be null if the description
86 * is in a resource. You probably want
87 * {@link PermissionInfo#loadDescription} instead.
88 */
89 public CharSequence nonLocalizedDescription;
90
Dianne Hackbornfd5015b2012-04-30 16:33:56 -070091 /**
92 * Flag for {@link #flags}, corresponding to <code>personalInfo</code>
93 * value of {@link android.R.attr#permissionGroupFlags}.
94 */
95 public static final int FLAG_PERSONAL_INFO = 1<<0;
96
97 /**
98 * Additional flags about this group as given by
99 * {@link android.R.attr#permissionGroupFlags}.
100 */
101 public int flags;
102
103 /**
104 * Prioritization of this group, for visually sorting with other groups.
105 */
106 public int priority;
107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 public PermissionGroupInfo() {
109 }
110
111 public PermissionGroupInfo(PermissionGroupInfo orig) {
112 super(orig);
113 descriptionRes = orig.descriptionRes;
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700114 requestRes = orig.requestRes;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700115 requestDetailResourceId = orig.requestDetailResourceId;
116 backgroundRequestResourceId = orig.backgroundRequestResourceId;
117 backgroundRequestDetailResourceId = orig.backgroundRequestDetailResourceId;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 nonLocalizedDescription = orig.nonLocalizedDescription;
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700119 flags = orig.flags;
120 priority = orig.priority;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121 }
122
123 /**
124 * Retrieve the textual description of this permission. This
125 * will call back on the given PackageManager to load the description from
126 * the application.
127 *
128 * @param pm A PackageManager from which the label can be loaded; usually
129 * the PackageManager from which you originally retrieved this item.
130 *
131 * @return Returns a CharSequence containing the permission's description.
132 * If there is no description, null is returned.
133 */
134 public CharSequence loadDescription(PackageManager pm) {
135 if (nonLocalizedDescription != null) {
136 return nonLocalizedDescription;
137 }
138 if (descriptionRes != 0) {
139 CharSequence label = pm.getText(packageName, descriptionRes, null);
140 if (label != null) {
141 return label;
142 }
143 }
144 return null;
145 }
146
147 public String toString() {
148 return "PermissionGroupInfo{"
149 + Integer.toHexString(System.identityHashCode(this))
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700150 + " " + name + " flgs=0x" + Integer.toHexString(flags) + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 }
152
153 public int describeContents() {
154 return 0;
155 }
156
157 public void writeToParcel(Parcel dest, int parcelableFlags) {
158 super.writeToParcel(dest, parcelableFlags);
159 dest.writeInt(descriptionRes);
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700160 dest.writeInt(requestRes);
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700161 dest.writeInt(requestDetailResourceId);
162 dest.writeInt(backgroundRequestResourceId);
163 dest.writeInt(backgroundRequestDetailResourceId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700165 dest.writeInt(flags);
166 dest.writeInt(priority);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 }
168
169 public static final Creator<PermissionGroupInfo> CREATOR =
170 new Creator<PermissionGroupInfo>() {
171 public PermissionGroupInfo createFromParcel(Parcel source) {
172 return new PermissionGroupInfo(source);
173 }
174 public PermissionGroupInfo[] newArray(int size) {
175 return new PermissionGroupInfo[size];
176 }
177 };
178
179 private PermissionGroupInfo(Parcel source) {
180 super(source);
181 descriptionRes = source.readInt();
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700182 requestRes = source.readInt();
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700183 requestDetailResourceId = source.readInt();
184 backgroundRequestResourceId = source.readInt();
185 backgroundRequestDetailResourceId = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Dianne Hackbornfd5015b2012-04-30 16:33:56 -0700187 flags = source.readInt();
188 priority = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 }
190}