blob: e24523406ab8d9c4d3c17252fb068a1c55fbbdf6 [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
Makoto Onuki700feef2018-02-15 10:59:41 -080019import android.annotation.IntDef;
Svet Ganov2a1376d2016-02-22 17:20:35 -080020import android.annotation.SystemApi;
Jiyong Park2f24f032017-12-08 12:25:25 +090021import android.annotation.TestApi;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010022import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.os.Parcel;
24import android.os.Parcelable;
25import android.text.TextUtils;
26
Makoto Onuki700feef2018-02-15 10:59:41 -080027import java.lang.annotation.Retention;
28import java.lang.annotation.RetentionPolicy;
29
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030/**
31 * Information you can retrieve about a particular security permission
32 * known to the system. This corresponds to information collected from the
33 * AndroidManifest.xml's <permission> tags.
34 */
35public class PermissionInfo extends PackageItemInfo implements Parcelable {
36 /**
37 * A normal application value for {@link #protectionLevel}, corresponding
38 * to the <code>normal</code> value of
39 * {@link android.R.attr#protectionLevel}.
40 */
41 public static final int PROTECTION_NORMAL = 0;
42
43 /**
44 * Dangerous value for {@link #protectionLevel}, corresponding
45 * to the <code>dangerous</code> value of
46 * {@link android.R.attr#protectionLevel}.
47 */
48 public static final int PROTECTION_DANGEROUS = 1;
49
50 /**
51 * System-level value for {@link #protectionLevel}, corresponding
52 * to the <code>signature</code> value of
53 * {@link android.R.attr#protectionLevel}.
54 */
55 public static final int PROTECTION_SIGNATURE = 2;
56
57 /**
Dianne Hackborna90c8de2015-07-07 17:25:25 -070058 * @deprecated Use {@link #PROTECTION_SIGNATURE}|{@link #PROTECTION_FLAG_PRIVILEGED}
59 * instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 */
Dianne Hackborna90c8de2015-07-07 17:25:25 -070061 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3;
63
Makoto Onuki700feef2018-02-15 10:59:41 -080064 /** @hide */
65 @IntDef(flag = false, prefix = { "PROTECTION_" }, value = {
66 PROTECTION_NORMAL,
67 PROTECTION_DANGEROUS,
68 PROTECTION_SIGNATURE,
69 PROTECTION_SIGNATURE_OR_SYSTEM,
70 })
71 @Retention(RetentionPolicy.SOURCE)
72 public @interface Protection {}
73
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 /**
Dianne Hackborne639da72012-02-21 15:11:13 -080075 * Additional flag for {@link #protectionLevel}, corresponding
Dianne Hackborna90c8de2015-07-07 17:25:25 -070076 * to the <code>privileged</code> value of
Dianne Hackborne639da72012-02-21 15:11:13 -080077 * {@link android.R.attr#protectionLevel}.
78 */
Dianne Hackborna90c8de2015-07-07 17:25:25 -070079 public static final int PROTECTION_FLAG_PRIVILEGED = 0x10;
80
81 /**
82 * @deprecated Old name for {@link #PROTECTION_FLAG_PRIVILEGED}, which
83 * is now very confusing because it only applies to privileged apps, not all
84 * apps on the system image.
85 */
86 @Deprecated
Dianne Hackborne639da72012-02-21 15:11:13 -080087 public static final int PROTECTION_FLAG_SYSTEM = 0x10;
88
89 /**
90 * Additional flag for {@link #protectionLevel}, corresponding
91 * to the <code>development</code> value of
92 * {@link android.R.attr#protectionLevel}.
93 */
94 public static final int PROTECTION_FLAG_DEVELOPMENT = 0x20;
95
96 /**
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -070097 * Additional flag for {@link #protectionLevel}, corresponding
Jeff Sharkeye9b78fd2014-08-13 14:16:50 -070098 * to the <code>appop</code> value of
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -070099 * {@link android.R.attr#protectionLevel}.
100 */
101 public static final int PROTECTION_FLAG_APPOP = 0x40;
102
103 /**
Dianne Hackbornde15eda2015-07-01 12:30:54 -0700104 * Additional flag for {@link #protectionLevel}, corresponding
105 * to the <code>pre23</code> value of
106 * {@link android.R.attr#protectionLevel}.
107 */
108 public static final int PROTECTION_FLAG_PRE23 = 0x80;
109
110 /**
Svetoslav3e7d9772015-07-06 18:31:23 -0700111 * Additional flag for {@link #protectionLevel}, corresponding
112 * to the <code>installer</code> value of
113 * {@link android.R.attr#protectionLevel}.
114 */
115 public static final int PROTECTION_FLAG_INSTALLER = 0x100;
116
117 /**
118 * Additional flag for {@link #protectionLevel}, corresponding
119 * to the <code>verifier</code> value of
120 * {@link android.R.attr#protectionLevel}.
121 */
122 public static final int PROTECTION_FLAG_VERIFIER = 0x200;
123
124 /**
Dianne Hackborna90c8de2015-07-07 17:25:25 -0700125 * Additional flag for {@link #protectionLevel}, corresponding
126 * to the <code>preinstalled</code> value of
127 * {@link android.R.attr#protectionLevel}.
128 */
129 public static final int PROTECTION_FLAG_PREINSTALLED = 0x400;
130
131 /**
Russell Brennerb2334662016-03-23 10:16:39 -0700132 * Additional flag for {@link #protectionLevel}, corresponding
133 * to the <code>setup</code> value of
134 * {@link android.R.attr#protectionLevel}.
135 */
136 public static final int PROTECTION_FLAG_SETUP = 0x800;
137
Chad Brubakerc19706a2016-10-13 15:44:59 -0700138 /**
139 * Additional flag for {@link #protectionLevel}, corresponding
Todd Kennedyc247fa12017-06-02 10:29:22 -0700140 * to the <code>instant</code> value of
Chad Brubakerc19706a2016-10-13 15:44:59 -0700141 * {@link android.R.attr#protectionLevel}.
Chad Brubakerc19706a2016-10-13 15:44:59 -0700142 */
Todd Kennedyc247fa12017-06-02 10:29:22 -0700143 public static final int PROTECTION_FLAG_INSTANT = 0x1000;
Chad Brubakerc19706a2016-10-13 15:44:59 -0700144
Russell Brennerb2334662016-03-23 10:16:39 -0700145 /**
Chad Brubakera5d70a12017-03-23 11:04:50 -0700146 * Additional flag for {@link #protectionLevel}, corresponding
147 * to the <code>runtime</code> value of
148 * {@link android.R.attr#protectionLevel}.
149 */
150 public static final int PROTECTION_FLAG_RUNTIME_ONLY = 0x2000;
151
152 /**
Svet Ganov087dce22017-09-07 15:42:16 -0700153 * Additional flag for {@link #protectionLevel}, corresponding
154 * to the <code>oem</code> value of
155 * {@link android.R.attr#protectionLevel}.
156 *
157 * @hide
158 */
159 @SystemApi
Michal Karpinski517959e2019-01-15 11:26:30 +0000160 @TestApi
Svet Ganov087dce22017-09-07 15:42:16 -0700161 public static final int PROTECTION_FLAG_OEM = 0x4000;
162
163 /**
Jiyong Park002fdbd2017-02-13 20:50:31 +0900164 * Additional flag for {${link #protectionLevel}, corresponding
165 * to the <code>vendorPrivileged</code> value of
166 * {@link android.R.attr#protectionLevel}.
167 *
168 * @hide
169 */
Jiyong Park2f24f032017-12-08 12:25:25 +0900170 @TestApi
Jiyong Park002fdbd2017-02-13 20:50:31 +0900171 public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 0x8000;
172
173 /**
Makoto Onuki700feef2018-02-15 10:59:41 -0800174 * Additional flag for {@link #protectionLevel}, corresponding
175 * to the <code>text_classifier</code> value of
176 * {@link android.R.attr#protectionLevel}.
177 *
178 * @hide
Dianne Hackborne639da72012-02-21 15:11:13 -0800179 */
Makoto Onuki700feef2018-02-15 10:59:41 -0800180 @SystemApi
181 @TestApi
182 public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 0x10000;
183
Varun Shah5f303652018-11-16 18:11:19 -0800184 /**
185 * Additional flag for {${link #protectionLevel}, corresponding
186 * to the <code>wellbeing</code> value of
187 * {@link android.R.attr#protectionLevel}.
188 *
189 * @hide
190 */
191 @SystemApi
192 @TestApi
193 public static final int PROTECTION_FLAG_WELLBEING = 0x20000;
194
Jeff Sharkey15707b32018-12-10 12:08:41 -0700195 /**
196 * Additional flag for {@link #protectionLevel}, corresponding to the
197 * {@code documenter} value of {@link android.R.attr#protectionLevel}.
198 *
199 * @hide
200 */
201 @SystemApi
202 @TestApi
203 public static final int PROTECTION_FLAG_DOCUMENTER = 0x40000;
204
Stanislav Zholnin596437f2018-12-28 15:34:23 +0000205 /**
206 * Additional flag for {@link #protectionLevel}, corresponding to the
207 * {@code configurator} value of {@link android.R.attr#protectionLevel}.
208 *
209 * @hide
210 */
211 @SystemApi
212 @TestApi
213 public static final int PROTECTION_FLAG_CONFIGURATOR = 0x80000;
214
Joe Onorato5a15b552018-12-18 10:40:04 -0800215 /**
216 * Additional flag for {${link #protectionLevel}, corresponding
217 * to the <code>incident_report_approver</code> value of
218 * {@link android.R.attr#protectionLevel}.
219 *
220 * @hide
221 */
222 @SystemApi
223 @TestApi
224 public static final int PROTECTION_FLAG_INCIDENT_REPORT_APPROVER = 0x100000;
Jeff Sharkey15707b32018-12-10 12:08:41 -0700225
George Hodulikcd7695d2019-01-29 18:17:05 -0800226 /**
227 * Additional flag for {@link #protectionLevel}, corresponding
228 * to the <code>app_predictor</code> value of
229 * {@link android.R.attr#protectionLevel}.
230 *
231 * @hide
232 */
233 @SystemApi
234 @TestApi
235 public static final int PROTECTION_FLAG_APP_PREDICTOR = 0x200000;
236
Makoto Onuki700feef2018-02-15 10:59:41 -0800237 /** @hide */
238 @IntDef(flag = true, prefix = { "PROTECTION_FLAG_" }, value = {
239 PROTECTION_FLAG_PRIVILEGED,
240 PROTECTION_FLAG_SYSTEM,
241 PROTECTION_FLAG_DEVELOPMENT,
242 PROTECTION_FLAG_APPOP,
243 PROTECTION_FLAG_PRE23,
244 PROTECTION_FLAG_INSTALLER,
245 PROTECTION_FLAG_VERIFIER,
246 PROTECTION_FLAG_PREINSTALLED,
247 PROTECTION_FLAG_SETUP,
248 PROTECTION_FLAG_INSTANT,
249 PROTECTION_FLAG_RUNTIME_ONLY,
250 PROTECTION_FLAG_OEM,
251 PROTECTION_FLAG_VENDOR_PRIVILEGED,
252 PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER,
Varun Shah5f303652018-11-16 18:11:19 -0800253 PROTECTION_FLAG_WELLBEING,
Jeff Sharkey15707b32018-12-10 12:08:41 -0700254 PROTECTION_FLAG_DOCUMENTER,
Stanislav Zholnin596437f2018-12-28 15:34:23 +0000255 PROTECTION_FLAG_CONFIGURATOR,
Joe Onorato5a15b552018-12-18 10:40:04 -0800256 PROTECTION_FLAG_INCIDENT_REPORT_APPROVER,
George Hodulikcd7695d2019-01-29 18:17:05 -0800257 PROTECTION_FLAG_APP_PREDICTOR,
Makoto Onuki700feef2018-02-15 10:59:41 -0800258 })
259 @Retention(RetentionPolicy.SOURCE)
260 public @interface ProtectionFlags {}
261
262 /**
263 * Mask for {@link #protectionLevel}: the basic protection type.
264 *
265 * @deprecated Use #getProtection() instead.
266 */
267 @Deprecated
Dianne Hackborne639da72012-02-21 15:11:13 -0800268 public static final int PROTECTION_MASK_BASE = 0xf;
269
270 /**
271 * Mask for {@link #protectionLevel}: additional flag bits.
Makoto Onuki700feef2018-02-15 10:59:41 -0800272 *
273 * @deprecated Use #getProtectionFlags() instead.
Dianne Hackborne639da72012-02-21 15:11:13 -0800274 */
Makoto Onuki700feef2018-02-15 10:59:41 -0800275 @Deprecated
Chad Brubakerc19706a2016-10-13 15:44:59 -0700276 public static final int PROTECTION_MASK_FLAGS = 0xfff0;
Dianne Hackborne639da72012-02-21 15:11:13 -0800277
278 /**
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700279 * The level of access this permission is protecting, as per
Peter Visontay51fbad52017-11-15 12:38:14 +0000280 * {@link android.R.attr#protectionLevel}. Consists of
Makoto Onuki700feef2018-02-15 10:59:41 -0800281 * a base permission type and zero or more flags. Use the following functions
282 * to extract them.
Peter Visontay51fbad52017-11-15 12:38:14 +0000283 *
284 * <pre>
Makoto Onuki700feef2018-02-15 10:59:41 -0800285 * int basePermissionType = permissionInfo.getProtection();
286 * int permissionFlags = permissionInfo.getProtectionFlags();
Peter Visontay51fbad52017-11-15 12:38:14 +0000287 * </pre>
288 *
289 * <p></p>Base permission types are {@link #PROTECTION_NORMAL},
290 * {@link #PROTECTION_DANGEROUS}, {@link #PROTECTION_SIGNATURE}
291 * and the deprecated {@link #PROTECTION_SIGNATURE_OR_SYSTEM}.
292 * Flags are listed under {@link android.R.attr#protectionLevel}.
Makoto Onuki700feef2018-02-15 10:59:41 -0800293 *
294 * @deprecated Use #getProtection() and #getProtectionFlags() instead.
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700295 */
Makoto Onuki700feef2018-02-15 10:59:41 -0800296 @Deprecated
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700297 public int protectionLevel;
298
299 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 * The group this permission is a part of, as per
301 * {@link android.R.attr#permissionGroup}.
302 */
303 public String group;
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700304
305 /**
306 * Flag for {@link #flags}, corresponding to <code>costsMoney</code>
307 * value of {@link android.R.attr#permissionFlags}.
308 */
309 public static final int FLAG_COSTS_MONEY = 1<<0;
310
311 /**
Svet Ganov2a1376d2016-02-22 17:20:35 -0800312 * Flag for {@link #flags}, corresponding to <code>removed</code>
Svet Ganov3e0be742015-08-07 23:06:00 -0700313 * value of {@link android.R.attr#permissionFlags}.
314 * @hide
315 */
Svet Ganov2a1376d2016-02-22 17:20:35 -0800316 @SystemApi
317 public static final int FLAG_REMOVED = 1<<1;
Svet Ganov3e0be742015-08-07 23:06:00 -0700318
319 /**
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700320 * Flag for {@link #flags}, indicating that this permission has been
321 * installed into the system's globally defined permissions.
Svetoslav Ganov6d2c0e52015-06-23 16:33:36 +0000322 */
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700323 public static final int FLAG_INSTALLED = 1<<30;
Svetoslav Ganov6d2c0e52015-06-23 16:33:36 +0000324
325 /**
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700326 * Additional flags about this permission as given by
327 * {@link android.R.attr#permissionFlags}.
328 */
329 public int flags;
330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 /**
332 * A string resource identifier (in the package's resources) of this
333 * permission's description. From the "description" attribute or,
334 * if not set, 0.
335 */
336 public int descriptionRes;
337
338 /**
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700339 * A string resource identifier (in the package's resources) used to request the permissions.
340 * From the "request" attribute or, if not set, 0.
341 *
342 * @hide
343 */
344 @SystemApi
345 public int requestRes;
346
347 /**
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700348 * Some permissions only grant access while the app is in foreground. Some of these permissions
349 * allow to add background capabilities by adding another permission.
350 *
351 * If this is such a permission, this is the name of the permission adding the background
352 * access.
353 *
354 * From the "backgroundPermission" attribute or, if not set null
355 *
356 * @hide
357 */
358 @SystemApi
359 @TestApi
360 public String backgroundPermission;
361
362 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 * The description string provided in the AndroidManifest file, if any. You
364 * probably don't want to use this, since it will be null if the description
365 * is in a resource. You probably want
366 * {@link PermissionInfo#loadDescription} instead.
367 */
368 public CharSequence nonLocalizedDescription;
369
Dianne Hackborne639da72012-02-21 15:11:13 -0800370 /** @hide */
371 public static int fixProtectionLevel(int level) {
372 if (level == PROTECTION_SIGNATURE_OR_SYSTEM) {
Dianne Hackborna90c8de2015-07-07 17:25:25 -0700373 level = PROTECTION_SIGNATURE | PROTECTION_FLAG_PRIVILEGED;
Dianne Hackborne639da72012-02-21 15:11:13 -0800374 }
Jiyong Park002fdbd2017-02-13 20:50:31 +0900375 if ((level & PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0
376 && (level & PROTECTION_FLAG_PRIVILEGED) == 0) {
377 // 'vendorPrivileged' must be 'privileged'. If not,
378 // drop the vendorPrivileged.
379 level = level & ~PROTECTION_FLAG_VENDOR_PRIVILEGED;
380 }
Dianne Hackborne639da72012-02-21 15:11:13 -0800381 return level;
382 }
383
384 /** @hide */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100385 @UnsupportedAppUsage
Dianne Hackborne639da72012-02-21 15:11:13 -0800386 public static String protectionToString(int level) {
387 String protLevel = "????";
Svet Ganov087dce22017-09-07 15:42:16 -0700388 switch (level & PROTECTION_MASK_BASE) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800389 case PermissionInfo.PROTECTION_DANGEROUS:
390 protLevel = "dangerous";
391 break;
392 case PermissionInfo.PROTECTION_NORMAL:
393 protLevel = "normal";
394 break;
395 case PermissionInfo.PROTECTION_SIGNATURE:
396 protLevel = "signature";
397 break;
398 case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM:
399 protLevel = "signatureOrSystem";
400 break;
401 }
Svet Ganov087dce22017-09-07 15:42:16 -0700402 if ((level & PermissionInfo.PROTECTION_FLAG_PRIVILEGED) != 0) {
Dianne Hackborna90c8de2015-07-07 17:25:25 -0700403 protLevel += "|privileged";
Dianne Hackborne639da72012-02-21 15:11:13 -0800404 }
Svet Ganov087dce22017-09-07 15:42:16 -0700405 if ((level & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800406 protLevel += "|development";
407 }
Svet Ganov087dce22017-09-07 15:42:16 -0700408 if ((level & PermissionInfo.PROTECTION_FLAG_APPOP) != 0) {
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -0700409 protLevel += "|appop";
410 }
Svet Ganov087dce22017-09-07 15:42:16 -0700411 if ((level & PermissionInfo.PROTECTION_FLAG_PRE23) != 0) {
Dianne Hackbornde15eda2015-07-01 12:30:54 -0700412 protLevel += "|pre23";
413 }
Svet Ganov087dce22017-09-07 15:42:16 -0700414 if ((level & PermissionInfo.PROTECTION_FLAG_INSTALLER) != 0) {
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700415 protLevel += "|installer";
416 }
Svet Ganov087dce22017-09-07 15:42:16 -0700417 if ((level & PermissionInfo.PROTECTION_FLAG_VERIFIER) != 0) {
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700418 protLevel += "|verifier";
419 }
Svet Ganov087dce22017-09-07 15:42:16 -0700420 if ((level & PermissionInfo.PROTECTION_FLAG_PREINSTALLED) != 0) {
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700421 protLevel += "|preinstalled";
422 }
Svet Ganov087dce22017-09-07 15:42:16 -0700423 if ((level & PermissionInfo.PROTECTION_FLAG_SETUP) != 0) {
Russell Brennerb2334662016-03-23 10:16:39 -0700424 protLevel += "|setup";
425 }
Svet Ganov087dce22017-09-07 15:42:16 -0700426 if ((level & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0) {
Todd Kennedyc247fa12017-06-02 10:29:22 -0700427 protLevel += "|instant";
Chad Brubakerc19706a2016-10-13 15:44:59 -0700428 }
Svet Ganov087dce22017-09-07 15:42:16 -0700429 if ((level & PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) != 0) {
Chad Brubakera5d70a12017-03-23 11:04:50 -0700430 protLevel += "|runtime";
431 }
Svet Ganov087dce22017-09-07 15:42:16 -0700432 if ((level & PermissionInfo.PROTECTION_FLAG_OEM) != 0) {
433 protLevel += "|oem";
434 }
Jiyong Park002fdbd2017-02-13 20:50:31 +0900435 if ((level & PermissionInfo.PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0) {
436 protLevel += "|vendorPrivileged";
437 }
Makoto Onuki700feef2018-02-15 10:59:41 -0800438 if ((level & PermissionInfo.PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER) != 0) {
439 protLevel += "|textClassifier";
440 }
Varun Shah5f303652018-11-16 18:11:19 -0800441 if ((level & PermissionInfo.PROTECTION_FLAG_WELLBEING) != 0) {
442 protLevel += "|wellbeing";
443 }
Jeff Sharkey15707b32018-12-10 12:08:41 -0700444 if ((level & PermissionInfo.PROTECTION_FLAG_DOCUMENTER) != 0) {
445 protLevel += "|documenter";
446 }
Stanislav Zholnin596437f2018-12-28 15:34:23 +0000447 if ((level & PROTECTION_FLAG_CONFIGURATOR) != 0) {
448 protLevel += "|configurator";
449 }
Joe Onorato5a15b552018-12-18 10:40:04 -0800450 if ((level & PermissionInfo.PROTECTION_FLAG_INCIDENT_REPORT_APPROVER) != 0) {
451 protLevel += "|incidentReportApprover";
452 }
George Hodulikcd7695d2019-01-29 18:17:05 -0800453 if ((level & PermissionInfo.PROTECTION_FLAG_APP_PREDICTOR) != 0) {
454 protLevel += "|appPredictor";
455 }
Dianne Hackborne639da72012-02-21 15:11:13 -0800456 return protLevel;
457 }
458
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 public PermissionInfo() {
460 }
461
462 public PermissionInfo(PermissionInfo orig) {
463 super(orig);
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700464 protectionLevel = orig.protectionLevel;
465 flags = orig.flags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 group = orig.group;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700467 backgroundPermission = orig.backgroundPermission;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 descriptionRes = orig.descriptionRes;
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700469 requestRes = orig.requestRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 nonLocalizedDescription = orig.nonLocalizedDescription;
471 }
472
473 /**
474 * Retrieve the textual description of this permission. This
475 * will call back on the given PackageManager to load the description from
476 * the application.
477 *
478 * @param pm A PackageManager from which the label can be loaded; usually
479 * the PackageManager from which you originally retrieved this item.
480 *
481 * @return Returns a CharSequence containing the permission's description.
482 * If there is no description, null is returned.
483 */
484 public CharSequence loadDescription(PackageManager pm) {
485 if (nonLocalizedDescription != null) {
486 return nonLocalizedDescription;
487 }
488 if (descriptionRes != 0) {
489 CharSequence label = pm.getText(packageName, descriptionRes, null);
490 if (label != null) {
491 return label;
492 }
493 }
494 return null;
495 }
496
Makoto Onuki700feef2018-02-15 10:59:41 -0800497 /**
498 * Return the base permission type.
499 */
500 @Protection
501 public int getProtection() {
502 return protectionLevel & PROTECTION_MASK_BASE;
503 }
504
505 /**
506 * Return the additional flags in {@link #protectionLevel}.
507 */
508 @ProtectionFlags
509 public int getProtectionFlags() {
510 return protectionLevel & ~PROTECTION_MASK_BASE;
511 }
512
Todd Kennedy91a39d12017-09-27 12:37:04 -0700513 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 public String toString() {
515 return "PermissionInfo{"
516 + Integer.toHexString(System.identityHashCode(this))
517 + " " + name + "}";
518 }
519
Todd Kennedy91a39d12017-09-27 12:37:04 -0700520 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 public int describeContents() {
522 return 0;
523 }
524
Todd Kennedy91a39d12017-09-27 12:37:04 -0700525 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 public void writeToParcel(Parcel dest, int parcelableFlags) {
527 super.writeToParcel(dest, parcelableFlags);
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700528 dest.writeInt(protectionLevel);
529 dest.writeInt(flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 dest.writeString(group);
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700531 dest.writeString(backgroundPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 dest.writeInt(descriptionRes);
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700533 dest.writeInt(requestRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
535 }
536
Todd Kennedy91a39d12017-09-27 12:37:04 -0700537 /** @hide */
538 public int calculateFootprint() {
539 int size = name.length();
540 if (nonLocalizedLabel != null) {
541 size += nonLocalizedLabel.length();
542 }
543 if (nonLocalizedDescription != null) {
544 size += nonLocalizedDescription.length();
545 }
546 return size;
547 }
548
Todd Kennedyc8423932017-10-05 08:58:36 -0700549 /** @hide */
550 public boolean isAppOp() {
551 return (protectionLevel & PermissionInfo.PROTECTION_FLAG_APPOP) != 0;
552 }
553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 public static final Creator<PermissionInfo> CREATOR =
555 new Creator<PermissionInfo>() {
Todd Kennedy91a39d12017-09-27 12:37:04 -0700556 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 public PermissionInfo createFromParcel(Parcel source) {
558 return new PermissionInfo(source);
559 }
Todd Kennedy91a39d12017-09-27 12:37:04 -0700560 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 public PermissionInfo[] newArray(int size) {
562 return new PermissionInfo[size];
563 }
564 };
565
566 private PermissionInfo(Parcel source) {
567 super(source);
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700568 protectionLevel = source.readInt();
569 flags = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 group = source.readString();
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700571 backgroundPermission = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 descriptionRes = source.readInt();
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700573 requestRes = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576}