blob: 6a41f334827dd97f7e9f11d4ebe9f3a4729fb45c [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;
Philip P. Moltmanna4844d12019-03-02 10:17:23 -080020import android.annotation.NonNull;
21import android.annotation.Nullable;
22import android.annotation.StringRes;
Svet Ganov2a1376d2016-02-22 17:20:35 -080023import android.annotation.SystemApi;
Jiyong Park2f24f032017-12-08 12:25:25 +090024import android.annotation.TestApi;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010025import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.os.Parcel;
27import android.os.Parcelable;
28import android.text.TextUtils;
29
Makoto Onuki700feef2018-02-15 10:59:41 -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 * known to the system. This corresponds to information collected from the
36 * AndroidManifest.xml's <permission> tags.
37 */
38public class PermissionInfo extends PackageItemInfo implements Parcelable {
39 /**
40 * A normal application value for {@link #protectionLevel}, corresponding
41 * to the <code>normal</code> value of
42 * {@link android.R.attr#protectionLevel}.
43 */
44 public static final int PROTECTION_NORMAL = 0;
45
46 /**
47 * Dangerous value for {@link #protectionLevel}, corresponding
48 * to the <code>dangerous</code> value of
49 * {@link android.R.attr#protectionLevel}.
50 */
51 public static final int PROTECTION_DANGEROUS = 1;
52
53 /**
54 * System-level value for {@link #protectionLevel}, corresponding
55 * to the <code>signature</code> value of
56 * {@link android.R.attr#protectionLevel}.
57 */
58 public static final int PROTECTION_SIGNATURE = 2;
59
60 /**
Dianne Hackborna90c8de2015-07-07 17:25:25 -070061 * @deprecated Use {@link #PROTECTION_SIGNATURE}|{@link #PROTECTION_FLAG_PRIVILEGED}
62 * instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 */
Dianne Hackborna90c8de2015-07-07 17:25:25 -070064 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3;
66
Makoto Onuki700feef2018-02-15 10:59:41 -080067 /** @hide */
68 @IntDef(flag = false, prefix = { "PROTECTION_" }, value = {
69 PROTECTION_NORMAL,
70 PROTECTION_DANGEROUS,
71 PROTECTION_SIGNATURE,
72 PROTECTION_SIGNATURE_OR_SYSTEM,
73 })
74 @Retention(RetentionPolicy.SOURCE)
75 public @interface Protection {}
76
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 /**
Dianne Hackborne639da72012-02-21 15:11:13 -080078 * Additional flag for {@link #protectionLevel}, corresponding
Dianne Hackborna90c8de2015-07-07 17:25:25 -070079 * to the <code>privileged</code> value of
Dianne Hackborne639da72012-02-21 15:11:13 -080080 * {@link android.R.attr#protectionLevel}.
81 */
Dianne Hackborna90c8de2015-07-07 17:25:25 -070082 public static final int PROTECTION_FLAG_PRIVILEGED = 0x10;
83
84 /**
85 * @deprecated Old name for {@link #PROTECTION_FLAG_PRIVILEGED}, which
86 * is now very confusing because it only applies to privileged apps, not all
87 * apps on the system image.
88 */
89 @Deprecated
Dianne Hackborne639da72012-02-21 15:11:13 -080090 public static final int PROTECTION_FLAG_SYSTEM = 0x10;
91
92 /**
93 * Additional flag for {@link #protectionLevel}, corresponding
94 * to the <code>development</code> value of
95 * {@link android.R.attr#protectionLevel}.
96 */
97 public static final int PROTECTION_FLAG_DEVELOPMENT = 0x20;
98
99 /**
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -0700100 * Additional flag for {@link #protectionLevel}, corresponding
Jeff Sharkeye9b78fd2014-08-13 14:16:50 -0700101 * to the <code>appop</code> value of
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -0700102 * {@link android.R.attr#protectionLevel}.
103 */
104 public static final int PROTECTION_FLAG_APPOP = 0x40;
105
106 /**
Dianne Hackbornde15eda2015-07-01 12:30:54 -0700107 * Additional flag for {@link #protectionLevel}, corresponding
108 * to the <code>pre23</code> value of
109 * {@link android.R.attr#protectionLevel}.
110 */
111 public static final int PROTECTION_FLAG_PRE23 = 0x80;
112
113 /**
Svetoslav3e7d9772015-07-06 18:31:23 -0700114 * Additional flag for {@link #protectionLevel}, corresponding
115 * to the <code>installer</code> value of
116 * {@link android.R.attr#protectionLevel}.
117 */
118 public static final int PROTECTION_FLAG_INSTALLER = 0x100;
119
120 /**
121 * Additional flag for {@link #protectionLevel}, corresponding
122 * to the <code>verifier</code> value of
123 * {@link android.R.attr#protectionLevel}.
124 */
125 public static final int PROTECTION_FLAG_VERIFIER = 0x200;
126
127 /**
Dianne Hackborna90c8de2015-07-07 17:25:25 -0700128 * Additional flag for {@link #protectionLevel}, corresponding
129 * to the <code>preinstalled</code> value of
130 * {@link android.R.attr#protectionLevel}.
131 */
132 public static final int PROTECTION_FLAG_PREINSTALLED = 0x400;
133
134 /**
Russell Brennerb2334662016-03-23 10:16:39 -0700135 * Additional flag for {@link #protectionLevel}, corresponding
136 * to the <code>setup</code> value of
137 * {@link android.R.attr#protectionLevel}.
138 */
139 public static final int PROTECTION_FLAG_SETUP = 0x800;
140
Chad Brubakerc19706a2016-10-13 15:44:59 -0700141 /**
142 * Additional flag for {@link #protectionLevel}, corresponding
Todd Kennedyc247fa12017-06-02 10:29:22 -0700143 * to the <code>instant</code> value of
Chad Brubakerc19706a2016-10-13 15:44:59 -0700144 * {@link android.R.attr#protectionLevel}.
Chad Brubakerc19706a2016-10-13 15:44:59 -0700145 */
Todd Kennedyc247fa12017-06-02 10:29:22 -0700146 public static final int PROTECTION_FLAG_INSTANT = 0x1000;
Chad Brubakerc19706a2016-10-13 15:44:59 -0700147
Russell Brennerb2334662016-03-23 10:16:39 -0700148 /**
Chad Brubakera5d70a12017-03-23 11:04:50 -0700149 * Additional flag for {@link #protectionLevel}, corresponding
150 * to the <code>runtime</code> value of
151 * {@link android.R.attr#protectionLevel}.
152 */
153 public static final int PROTECTION_FLAG_RUNTIME_ONLY = 0x2000;
154
155 /**
Svet Ganov087dce22017-09-07 15:42:16 -0700156 * Additional flag for {@link #protectionLevel}, corresponding
157 * to the <code>oem</code> value of
158 * {@link android.R.attr#protectionLevel}.
159 *
160 * @hide
161 */
162 @SystemApi
Michal Karpinski517959e2019-01-15 11:26:30 +0000163 @TestApi
Svet Ganov087dce22017-09-07 15:42:16 -0700164 public static final int PROTECTION_FLAG_OEM = 0x4000;
165
166 /**
Jiyong Park002fdbd2017-02-13 20:50:31 +0900167 * Additional flag for {${link #protectionLevel}, corresponding
168 * to the <code>vendorPrivileged</code> value of
169 * {@link android.R.attr#protectionLevel}.
170 *
171 * @hide
172 */
Jiyong Park2f24f032017-12-08 12:25:25 +0900173 @TestApi
Jiyong Park002fdbd2017-02-13 20:50:31 +0900174 public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 0x8000;
175
176 /**
Makoto Onuki700feef2018-02-15 10:59:41 -0800177 * Additional flag for {@link #protectionLevel}, corresponding
178 * to the <code>text_classifier</code> value of
179 * {@link android.R.attr#protectionLevel}.
180 *
181 * @hide
Dianne Hackborne639da72012-02-21 15:11:13 -0800182 */
Makoto Onuki700feef2018-02-15 10:59:41 -0800183 @SystemApi
184 @TestApi
185 public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 0x10000;
186
Varun Shah5f303652018-11-16 18:11:19 -0800187 /**
188 * Additional flag for {${link #protectionLevel}, corresponding
189 * to the <code>wellbeing</code> value of
190 * {@link android.R.attr#protectionLevel}.
191 *
192 * @hide
193 */
194 @SystemApi
195 @TestApi
196 public static final int PROTECTION_FLAG_WELLBEING = 0x20000;
197
Jeff Sharkey15707b32018-12-10 12:08:41 -0700198 /**
199 * Additional flag for {@link #protectionLevel}, corresponding to the
200 * {@code documenter} value of {@link android.R.attr#protectionLevel}.
201 *
202 * @hide
203 */
204 @SystemApi
205 @TestApi
206 public static final int PROTECTION_FLAG_DOCUMENTER = 0x40000;
207
Stanislav Zholnin596437f2018-12-28 15:34:23 +0000208 /**
209 * Additional flag for {@link #protectionLevel}, corresponding to the
210 * {@code configurator} value of {@link android.R.attr#protectionLevel}.
211 *
212 * @hide
213 */
214 @SystemApi
215 @TestApi
216 public static final int PROTECTION_FLAG_CONFIGURATOR = 0x80000;
217
Joe Onorato5a15b552018-12-18 10:40:04 -0800218 /**
219 * Additional flag for {${link #protectionLevel}, corresponding
220 * to the <code>incident_report_approver</code> value of
221 * {@link android.R.attr#protectionLevel}.
222 *
223 * @hide
224 */
225 @SystemApi
226 @TestApi
227 public static final int PROTECTION_FLAG_INCIDENT_REPORT_APPROVER = 0x100000;
Jeff Sharkey15707b32018-12-10 12:08:41 -0700228
George Hodulikcd7695d2019-01-29 18:17:05 -0800229 /**
230 * Additional flag for {@link #protectionLevel}, corresponding
231 * to the <code>app_predictor</code> value of
232 * {@link android.R.attr#protectionLevel}.
233 *
234 * @hide
235 */
236 @SystemApi
237 @TestApi
238 public static final int PROTECTION_FLAG_APP_PREDICTOR = 0x200000;
239
Makoto Onuki700feef2018-02-15 10:59:41 -0800240 /** @hide */
241 @IntDef(flag = true, prefix = { "PROTECTION_FLAG_" }, value = {
242 PROTECTION_FLAG_PRIVILEGED,
243 PROTECTION_FLAG_SYSTEM,
244 PROTECTION_FLAG_DEVELOPMENT,
245 PROTECTION_FLAG_APPOP,
246 PROTECTION_FLAG_PRE23,
247 PROTECTION_FLAG_INSTALLER,
248 PROTECTION_FLAG_VERIFIER,
249 PROTECTION_FLAG_PREINSTALLED,
250 PROTECTION_FLAG_SETUP,
251 PROTECTION_FLAG_INSTANT,
252 PROTECTION_FLAG_RUNTIME_ONLY,
253 PROTECTION_FLAG_OEM,
254 PROTECTION_FLAG_VENDOR_PRIVILEGED,
255 PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER,
Varun Shah5f303652018-11-16 18:11:19 -0800256 PROTECTION_FLAG_WELLBEING,
Jeff Sharkey15707b32018-12-10 12:08:41 -0700257 PROTECTION_FLAG_DOCUMENTER,
Stanislav Zholnin596437f2018-12-28 15:34:23 +0000258 PROTECTION_FLAG_CONFIGURATOR,
Joe Onorato5a15b552018-12-18 10:40:04 -0800259 PROTECTION_FLAG_INCIDENT_REPORT_APPROVER,
George Hodulikcd7695d2019-01-29 18:17:05 -0800260 PROTECTION_FLAG_APP_PREDICTOR,
Makoto Onuki700feef2018-02-15 10:59:41 -0800261 })
262 @Retention(RetentionPolicy.SOURCE)
263 public @interface ProtectionFlags {}
264
265 /**
266 * Mask for {@link #protectionLevel}: the basic protection type.
267 *
268 * @deprecated Use #getProtection() instead.
269 */
270 @Deprecated
Dianne Hackborne639da72012-02-21 15:11:13 -0800271 public static final int PROTECTION_MASK_BASE = 0xf;
272
273 /**
274 * Mask for {@link #protectionLevel}: additional flag bits.
Makoto Onuki700feef2018-02-15 10:59:41 -0800275 *
276 * @deprecated Use #getProtectionFlags() instead.
Dianne Hackborne639da72012-02-21 15:11:13 -0800277 */
Makoto Onuki700feef2018-02-15 10:59:41 -0800278 @Deprecated
Chad Brubakerc19706a2016-10-13 15:44:59 -0700279 public static final int PROTECTION_MASK_FLAGS = 0xfff0;
Dianne Hackborne639da72012-02-21 15:11:13 -0800280
281 /**
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700282 * The level of access this permission is protecting, as per
Peter Visontay51fbad52017-11-15 12:38:14 +0000283 * {@link android.R.attr#protectionLevel}. Consists of
Makoto Onuki700feef2018-02-15 10:59:41 -0800284 * a base permission type and zero or more flags. Use the following functions
285 * to extract them.
Peter Visontay51fbad52017-11-15 12:38:14 +0000286 *
287 * <pre>
Makoto Onuki700feef2018-02-15 10:59:41 -0800288 * int basePermissionType = permissionInfo.getProtection();
289 * int permissionFlags = permissionInfo.getProtectionFlags();
Peter Visontay51fbad52017-11-15 12:38:14 +0000290 * </pre>
291 *
292 * <p></p>Base permission types are {@link #PROTECTION_NORMAL},
293 * {@link #PROTECTION_DANGEROUS}, {@link #PROTECTION_SIGNATURE}
294 * and the deprecated {@link #PROTECTION_SIGNATURE_OR_SYSTEM}.
295 * Flags are listed under {@link android.R.attr#protectionLevel}.
Makoto Onuki700feef2018-02-15 10:59:41 -0800296 *
297 * @deprecated Use #getProtection() and #getProtectionFlags() instead.
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700298 */
Makoto Onuki700feef2018-02-15 10:59:41 -0800299 @Deprecated
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700300 public int protectionLevel;
301
302 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 * The group this permission is a part of, as per
304 * {@link android.R.attr#permissionGroup}.
305 */
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800306 public @Nullable String group;
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700307
308 /**
309 * Flag for {@link #flags}, corresponding to <code>costsMoney</code>
310 * value of {@link android.R.attr#permissionFlags}.
311 */
312 public static final int FLAG_COSTS_MONEY = 1<<0;
313
314 /**
Svet Ganov2a1376d2016-02-22 17:20:35 -0800315 * Flag for {@link #flags}, corresponding to <code>removed</code>
Svet Ganov3e0be742015-08-07 23:06:00 -0700316 * value of {@link android.R.attr#permissionFlags}.
317 * @hide
318 */
Svet Ganov2a1376d2016-02-22 17:20:35 -0800319 @SystemApi
320 public static final int FLAG_REMOVED = 1<<1;
Svet Ganov3e0be742015-08-07 23:06:00 -0700321
322 /**
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700323 * Flag for {@link #flags}, indicating that this permission has been
324 * installed into the system's globally defined permissions.
Svetoslav Ganov6d2c0e52015-06-23 16:33:36 +0000325 */
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700326 public static final int FLAG_INSTALLED = 1<<30;
Svetoslav Ganov6d2c0e52015-06-23 16:33:36 +0000327
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800328 /** @hide */
329 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
330 FLAG_COSTS_MONEY,
331 FLAG_INSTALLED,
332 FLAG_REMOVED
333 })
334 @Retention(RetentionPolicy.SOURCE)
335 public @interface Flags {}
336
Svetoslav Ganov6d2c0e52015-06-23 16:33:36 +0000337 /**
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700338 * Additional flags about this permission as given by
339 * {@link android.R.attr#permissionFlags}.
340 */
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800341 public @Flags int flags;
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 /**
344 * A string resource identifier (in the package's resources) of this
345 * permission's description. From the "description" attribute or,
346 * if not set, 0.
347 */
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800348 public @StringRes int descriptionRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349
350 /**
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700351 * A string resource identifier (in the package's resources) used to request the permissions.
352 * From the "request" attribute or, if not set, 0.
353 *
354 * @hide
355 */
356 @SystemApi
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800357 public @StringRes int requestRes;
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700358
359 /**
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700360 * Some permissions only grant access while the app is in foreground. Some of these permissions
361 * allow to add background capabilities by adding another permission.
362 *
363 * If this is such a permission, this is the name of the permission adding the background
364 * access.
365 *
366 * From the "backgroundPermission" attribute or, if not set null
367 *
368 * @hide
369 */
370 @SystemApi
371 @TestApi
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800372 public final @Nullable String backgroundPermission;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700373
374 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 * The description string provided in the AndroidManifest file, if any. You
376 * probably don't want to use this, since it will be null if the description
377 * is in a resource. You probably want
378 * {@link PermissionInfo#loadDescription} instead.
379 */
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800380 public @Nullable CharSequence nonLocalizedDescription;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381
Dianne Hackborne639da72012-02-21 15:11:13 -0800382 /** @hide */
383 public static int fixProtectionLevel(int level) {
384 if (level == PROTECTION_SIGNATURE_OR_SYSTEM) {
Dianne Hackborna90c8de2015-07-07 17:25:25 -0700385 level = PROTECTION_SIGNATURE | PROTECTION_FLAG_PRIVILEGED;
Dianne Hackborne639da72012-02-21 15:11:13 -0800386 }
Jiyong Park002fdbd2017-02-13 20:50:31 +0900387 if ((level & PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0
388 && (level & PROTECTION_FLAG_PRIVILEGED) == 0) {
389 // 'vendorPrivileged' must be 'privileged'. If not,
390 // drop the vendorPrivileged.
391 level = level & ~PROTECTION_FLAG_VENDOR_PRIVILEGED;
392 }
Dianne Hackborne639da72012-02-21 15:11:13 -0800393 return level;
394 }
395
396 /** @hide */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100397 @UnsupportedAppUsage
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800398 public static @NonNull String protectionToString(int level) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800399 String protLevel = "????";
Svet Ganov087dce22017-09-07 15:42:16 -0700400 switch (level & PROTECTION_MASK_BASE) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800401 case PermissionInfo.PROTECTION_DANGEROUS:
402 protLevel = "dangerous";
403 break;
404 case PermissionInfo.PROTECTION_NORMAL:
405 protLevel = "normal";
406 break;
407 case PermissionInfo.PROTECTION_SIGNATURE:
408 protLevel = "signature";
409 break;
410 case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM:
411 protLevel = "signatureOrSystem";
412 break;
413 }
Svet Ganov087dce22017-09-07 15:42:16 -0700414 if ((level & PermissionInfo.PROTECTION_FLAG_PRIVILEGED) != 0) {
Dianne Hackborna90c8de2015-07-07 17:25:25 -0700415 protLevel += "|privileged";
Dianne Hackborne639da72012-02-21 15:11:13 -0800416 }
Svet Ganov087dce22017-09-07 15:42:16 -0700417 if ((level & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) {
Dianne Hackborne639da72012-02-21 15:11:13 -0800418 protLevel += "|development";
419 }
Svet Ganov087dce22017-09-07 15:42:16 -0700420 if ((level & PermissionInfo.PROTECTION_FLAG_APPOP) != 0) {
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -0700421 protLevel += "|appop";
422 }
Svet Ganov087dce22017-09-07 15:42:16 -0700423 if ((level & PermissionInfo.PROTECTION_FLAG_PRE23) != 0) {
Dianne Hackbornde15eda2015-07-01 12:30:54 -0700424 protLevel += "|pre23";
425 }
Svet Ganov087dce22017-09-07 15:42:16 -0700426 if ((level & PermissionInfo.PROTECTION_FLAG_INSTALLER) != 0) {
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700427 protLevel += "|installer";
428 }
Svet Ganov087dce22017-09-07 15:42:16 -0700429 if ((level & PermissionInfo.PROTECTION_FLAG_VERIFIER) != 0) {
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700430 protLevel += "|verifier";
431 }
Svet Ganov087dce22017-09-07 15:42:16 -0700432 if ((level & PermissionInfo.PROTECTION_FLAG_PREINSTALLED) != 0) {
Dianne Hackborncfbfafe2015-07-21 16:57:51 -0700433 protLevel += "|preinstalled";
434 }
Svet Ganov087dce22017-09-07 15:42:16 -0700435 if ((level & PermissionInfo.PROTECTION_FLAG_SETUP) != 0) {
Russell Brennerb2334662016-03-23 10:16:39 -0700436 protLevel += "|setup";
437 }
Svet Ganov087dce22017-09-07 15:42:16 -0700438 if ((level & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0) {
Todd Kennedyc247fa12017-06-02 10:29:22 -0700439 protLevel += "|instant";
Chad Brubakerc19706a2016-10-13 15:44:59 -0700440 }
Svet Ganov087dce22017-09-07 15:42:16 -0700441 if ((level & PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) != 0) {
Chad Brubakera5d70a12017-03-23 11:04:50 -0700442 protLevel += "|runtime";
443 }
Svet Ganov087dce22017-09-07 15:42:16 -0700444 if ((level & PermissionInfo.PROTECTION_FLAG_OEM) != 0) {
445 protLevel += "|oem";
446 }
Jiyong Park002fdbd2017-02-13 20:50:31 +0900447 if ((level & PermissionInfo.PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0) {
448 protLevel += "|vendorPrivileged";
449 }
Makoto Onuki700feef2018-02-15 10:59:41 -0800450 if ((level & PermissionInfo.PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER) != 0) {
451 protLevel += "|textClassifier";
452 }
Varun Shah5f303652018-11-16 18:11:19 -0800453 if ((level & PermissionInfo.PROTECTION_FLAG_WELLBEING) != 0) {
454 protLevel += "|wellbeing";
455 }
Jeff Sharkey15707b32018-12-10 12:08:41 -0700456 if ((level & PermissionInfo.PROTECTION_FLAG_DOCUMENTER) != 0) {
457 protLevel += "|documenter";
458 }
Stanislav Zholnin596437f2018-12-28 15:34:23 +0000459 if ((level & PROTECTION_FLAG_CONFIGURATOR) != 0) {
460 protLevel += "|configurator";
461 }
Joe Onorato5a15b552018-12-18 10:40:04 -0800462 if ((level & PermissionInfo.PROTECTION_FLAG_INCIDENT_REPORT_APPROVER) != 0) {
463 protLevel += "|incidentReportApprover";
464 }
George Hodulikcd7695d2019-01-29 18:17:05 -0800465 if ((level & PermissionInfo.PROTECTION_FLAG_APP_PREDICTOR) != 0) {
466 protLevel += "|appPredictor";
467 }
Dianne Hackborne639da72012-02-21 15:11:13 -0800468 return protLevel;
469 }
470
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800471 /**
472 * @hide
473 */
474 public PermissionInfo(@Nullable String backgroundPermission) {
475 this.backgroundPermission = backgroundPermission;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 }
477
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800478 /**
479 * @deprecated Should only be created by the system.
480 */
481 @Deprecated
482 public PermissionInfo() {
483 this((String) null);
484 }
485
486 /**
487 * @deprecated Should only be created by the system.
488 */
489 @Deprecated
490 public PermissionInfo(@NonNull PermissionInfo orig) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 super(orig);
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700492 protectionLevel = orig.protectionLevel;
493 flags = orig.flags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 group = orig.group;
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700495 backgroundPermission = orig.backgroundPermission;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 descriptionRes = orig.descriptionRes;
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700497 requestRes = orig.requestRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 nonLocalizedDescription = orig.nonLocalizedDescription;
499 }
500
501 /**
502 * Retrieve the textual description of this permission. This
503 * will call back on the given PackageManager to load the description from
504 * the application.
505 *
506 * @param pm A PackageManager from which the label can be loaded; usually
507 * the PackageManager from which you originally retrieved this item.
508 *
509 * @return Returns a CharSequence containing the permission's description.
510 * If there is no description, null is returned.
511 */
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800512 public @Nullable CharSequence loadDescription(@NonNull PackageManager pm) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800513 if (nonLocalizedDescription != null) {
514 return nonLocalizedDescription;
515 }
516 if (descriptionRes != 0) {
517 CharSequence label = pm.getText(packageName, descriptionRes, null);
518 if (label != null) {
519 return label;
520 }
521 }
522 return null;
523 }
524
Makoto Onuki700feef2018-02-15 10:59:41 -0800525 /**
526 * Return the base permission type.
527 */
528 @Protection
529 public int getProtection() {
530 return protectionLevel & PROTECTION_MASK_BASE;
531 }
532
533 /**
534 * Return the additional flags in {@link #protectionLevel}.
535 */
536 @ProtectionFlags
537 public int getProtectionFlags() {
538 return protectionLevel & ~PROTECTION_MASK_BASE;
539 }
540
Todd Kennedy91a39d12017-09-27 12:37:04 -0700541 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800542 public String toString() {
543 return "PermissionInfo{"
544 + Integer.toHexString(System.identityHashCode(this))
545 + " " + name + "}";
546 }
547
Todd Kennedy91a39d12017-09-27 12:37:04 -0700548 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 public int describeContents() {
550 return 0;
551 }
552
Todd Kennedy91a39d12017-09-27 12:37:04 -0700553 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 public void writeToParcel(Parcel dest, int parcelableFlags) {
555 super.writeToParcel(dest, parcelableFlags);
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700556 dest.writeInt(protectionLevel);
557 dest.writeInt(flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 dest.writeString(group);
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700559 dest.writeString(backgroundPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 dest.writeInt(descriptionRes);
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700561 dest.writeInt(requestRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags);
563 }
564
Todd Kennedy91a39d12017-09-27 12:37:04 -0700565 /** @hide */
566 public int calculateFootprint() {
567 int size = name.length();
568 if (nonLocalizedLabel != null) {
569 size += nonLocalizedLabel.length();
570 }
571 if (nonLocalizedDescription != null) {
572 size += nonLocalizedDescription.length();
573 }
574 return size;
575 }
576
Todd Kennedyc8423932017-10-05 08:58:36 -0700577 /** @hide */
578 public boolean isAppOp() {
579 return (protectionLevel & PermissionInfo.PROTECTION_FLAG_APPOP) != 0;
580 }
581
Philip P. Moltmanna4844d12019-03-02 10:17:23 -0800582 public static final @NonNull Creator<PermissionInfo> CREATOR =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 new Creator<PermissionInfo>() {
Todd Kennedy91a39d12017-09-27 12:37:04 -0700584 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 public PermissionInfo createFromParcel(Parcel source) {
586 return new PermissionInfo(source);
587 }
Todd Kennedy91a39d12017-09-27 12:37:04 -0700588 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 public PermissionInfo[] newArray(int size) {
590 return new PermissionInfo[size];
591 }
592 };
593
594 private PermissionInfo(Parcel source) {
595 super(source);
Dianne Hackborn2ca2c872012-09-16 16:03:36 -0700596 protectionLevel = source.readInt();
597 flags = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 group = source.readString();
Philip P. Moltmann4a6dff02018-06-12 16:23:54 -0700599 backgroundPermission = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 descriptionRes = source.readInt();
Philip P. Moltmann27ffeb32017-07-06 13:54:46 -0700601 requestRes = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 }
604}