The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Jiyong Park | 2f24f03 | 2017-12-08 12:25:25 +0900 | [diff] [blame] | 21 | import android.annotation.TestApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 22 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.os.Parcel; |
| 24 | import android.os.Parcelable; |
| 25 | import android.text.TextUtils; |
| 26 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 27 | import java.lang.annotation.Retention; |
| 28 | import java.lang.annotation.RetentionPolicy; |
| 29 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | /** |
| 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 | */ |
| 35 | public 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 Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 58 | * @deprecated Use {@link #PROTECTION_SIGNATURE}|{@link #PROTECTION_FLAG_PRIVILEGED} |
| 59 | * instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | */ |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 61 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3; |
| 63 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 64 | /** @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | /** |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 75 | * Additional flag for {@link #protectionLevel}, corresponding |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 76 | * to the <code>privileged</code> value of |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 77 | * {@link android.R.attr#protectionLevel}. |
| 78 | */ |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 79 | 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 87 | 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 Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 97 | * Additional flag for {@link #protectionLevel}, corresponding |
Jeff Sharkey | e9b78fd | 2014-08-13 14:16:50 -0700 | [diff] [blame] | 98 | * to the <code>appop</code> value of |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 99 | * {@link android.R.attr#protectionLevel}. |
| 100 | */ |
| 101 | public static final int PROTECTION_FLAG_APPOP = 0x40; |
| 102 | |
| 103 | /** |
Dianne Hackborn | de15eda | 2015-07-01 12:30:54 -0700 | [diff] [blame] | 104 | * 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 | /** |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 111 | * 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 Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 125 | * 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 Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 132 | * 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 Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 138 | /** |
| 139 | * Additional flag for {@link #protectionLevel}, corresponding |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 140 | * to the <code>instant</code> value of |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 141 | * {@link android.R.attr#protectionLevel}. |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 142 | */ |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 143 | public static final int PROTECTION_FLAG_INSTANT = 0x1000; |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 144 | |
Russell Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 145 | /** |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 146 | * 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 Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 153 | * 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 Karpinski | 517959e | 2019-01-15 11:26:30 +0000 | [diff] [blame] | 160 | @TestApi |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 161 | public static final int PROTECTION_FLAG_OEM = 0x4000; |
| 162 | |
| 163 | /** |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 164 | * 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 Park | 2f24f03 | 2017-12-08 12:25:25 +0900 | [diff] [blame] | 170 | @TestApi |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 171 | public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 0x8000; |
| 172 | |
| 173 | /** |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 174 | * 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 179 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 180 | @SystemApi |
| 181 | @TestApi |
| 182 | public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 0x10000; |
| 183 | |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 184 | /** |
| 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 Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 195 | /** |
| 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 Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 205 | /** |
| 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 Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 215 | /** |
| 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 Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 225 | |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 226 | /** |
| 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 Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 237 | /** @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 Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 253 | PROTECTION_FLAG_WELLBEING, |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 254 | PROTECTION_FLAG_DOCUMENTER, |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 255 | PROTECTION_FLAG_CONFIGURATOR, |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 256 | PROTECTION_FLAG_INCIDENT_REPORT_APPROVER, |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 257 | PROTECTION_FLAG_APP_PREDICTOR, |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 258 | }) |
| 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 268 | public static final int PROTECTION_MASK_BASE = 0xf; |
| 269 | |
| 270 | /** |
| 271 | * Mask for {@link #protectionLevel}: additional flag bits. |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 272 | * |
| 273 | * @deprecated Use #getProtectionFlags() instead. |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 274 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 275 | @Deprecated |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 276 | public static final int PROTECTION_MASK_FLAGS = 0xfff0; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 277 | |
| 278 | /** |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 279 | * The level of access this permission is protecting, as per |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 280 | * {@link android.R.attr#protectionLevel}. Consists of |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 281 | * a base permission type and zero or more flags. Use the following functions |
| 282 | * to extract them. |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 283 | * |
| 284 | * <pre> |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 285 | * int basePermissionType = permissionInfo.getProtection(); |
| 286 | * int permissionFlags = permissionInfo.getProtectionFlags(); |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 287 | * </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 Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 293 | * |
| 294 | * @deprecated Use #getProtection() and #getProtectionFlags() instead. |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 295 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 296 | @Deprecated |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 297 | public int protectionLevel; |
| 298 | |
| 299 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | * The group this permission is a part of, as per |
| 301 | * {@link android.R.attr#permissionGroup}. |
| 302 | */ |
| 303 | public String group; |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 304 | |
| 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 Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 312 | * Flag for {@link #flags}, corresponding to <code>removed</code> |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 313 | * value of {@link android.R.attr#permissionFlags}. |
| 314 | * @hide |
| 315 | */ |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 316 | @SystemApi |
| 317 | public static final int FLAG_REMOVED = 1<<1; |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 318 | |
| 319 | /** |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 320 | * Flag for {@link #flags}, indicating that this permission has been |
| 321 | * installed into the system's globally defined permissions. |
Svetoslav Ganov | 6d2c0e5 | 2015-06-23 16:33:36 +0000 | [diff] [blame] | 322 | */ |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 323 | public static final int FLAG_INSTALLED = 1<<30; |
Svetoslav Ganov | 6d2c0e5 | 2015-06-23 16:33:36 +0000 | [diff] [blame] | 324 | |
| 325 | /** |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 326 | * Additional flags about this permission as given by |
| 327 | * {@link android.R.attr#permissionFlags}. |
| 328 | */ |
| 329 | public int flags; |
| 330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | /** |
| 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. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 339 | * 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. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 348 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 363 | * 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 370 | /** @hide */ |
| 371 | public static int fixProtectionLevel(int level) { |
| 372 | if (level == PROTECTION_SIGNATURE_OR_SYSTEM) { |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 373 | level = PROTECTION_SIGNATURE | PROTECTION_FLAG_PRIVILEGED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 374 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 375 | 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 381 | return level; |
| 382 | } |
| 383 | |
| 384 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 385 | @UnsupportedAppUsage |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 386 | public static String protectionToString(int level) { |
| 387 | String protLevel = "????"; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 388 | switch (level & PROTECTION_MASK_BASE) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 389 | 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 Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 402 | if ((level & PermissionInfo.PROTECTION_FLAG_PRIVILEGED) != 0) { |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 403 | protLevel += "|privileged"; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 404 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 405 | if ((level & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 406 | protLevel += "|development"; |
| 407 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 408 | if ((level & PermissionInfo.PROTECTION_FLAG_APPOP) != 0) { |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 409 | protLevel += "|appop"; |
| 410 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 411 | if ((level & PermissionInfo.PROTECTION_FLAG_PRE23) != 0) { |
Dianne Hackborn | de15eda | 2015-07-01 12:30:54 -0700 | [diff] [blame] | 412 | protLevel += "|pre23"; |
| 413 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 414 | if ((level & PermissionInfo.PROTECTION_FLAG_INSTALLER) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 415 | protLevel += "|installer"; |
| 416 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 417 | if ((level & PermissionInfo.PROTECTION_FLAG_VERIFIER) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 418 | protLevel += "|verifier"; |
| 419 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 420 | if ((level & PermissionInfo.PROTECTION_FLAG_PREINSTALLED) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 421 | protLevel += "|preinstalled"; |
| 422 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 423 | if ((level & PermissionInfo.PROTECTION_FLAG_SETUP) != 0) { |
Russell Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 424 | protLevel += "|setup"; |
| 425 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 426 | if ((level & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 427 | protLevel += "|instant"; |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 428 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 429 | if ((level & PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) != 0) { |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 430 | protLevel += "|runtime"; |
| 431 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 432 | if ((level & PermissionInfo.PROTECTION_FLAG_OEM) != 0) { |
| 433 | protLevel += "|oem"; |
| 434 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 435 | if ((level & PermissionInfo.PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0) { |
| 436 | protLevel += "|vendorPrivileged"; |
| 437 | } |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 438 | if ((level & PermissionInfo.PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER) != 0) { |
| 439 | protLevel += "|textClassifier"; |
| 440 | } |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 441 | if ((level & PermissionInfo.PROTECTION_FLAG_WELLBEING) != 0) { |
| 442 | protLevel += "|wellbeing"; |
| 443 | } |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 444 | if ((level & PermissionInfo.PROTECTION_FLAG_DOCUMENTER) != 0) { |
| 445 | protLevel += "|documenter"; |
| 446 | } |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 447 | if ((level & PROTECTION_FLAG_CONFIGURATOR) != 0) { |
| 448 | protLevel += "|configurator"; |
| 449 | } |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 450 | if ((level & PermissionInfo.PROTECTION_FLAG_INCIDENT_REPORT_APPROVER) != 0) { |
| 451 | protLevel += "|incidentReportApprover"; |
| 452 | } |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 453 | if ((level & PermissionInfo.PROTECTION_FLAG_APP_PREDICTOR) != 0) { |
| 454 | protLevel += "|appPredictor"; |
| 455 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 456 | return protLevel; |
| 457 | } |
| 458 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | public PermissionInfo() { |
| 460 | } |
| 461 | |
| 462 | public PermissionInfo(PermissionInfo orig) { |
| 463 | super(orig); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 464 | protectionLevel = orig.protectionLevel; |
| 465 | flags = orig.flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | group = orig.group; |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 467 | backgroundPermission = orig.backgroundPermission; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | descriptionRes = orig.descriptionRes; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 469 | requestRes = orig.requestRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | 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 Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 497 | /** |
| 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 Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 513 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | public String toString() { |
| 515 | return "PermissionInfo{" |
| 516 | + Integer.toHexString(System.identityHashCode(this)) |
| 517 | + " " + name + "}"; |
| 518 | } |
| 519 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 520 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 521 | public int describeContents() { |
| 522 | return 0; |
| 523 | } |
| 524 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 525 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 527 | super.writeToParcel(dest, parcelableFlags); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 528 | dest.writeInt(protectionLevel); |
| 529 | dest.writeInt(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | dest.writeString(group); |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 531 | dest.writeString(backgroundPermission); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | dest.writeInt(descriptionRes); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 533 | dest.writeInt(requestRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags); |
| 535 | } |
| 536 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 537 | /** @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 Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 549 | /** @hide */ |
| 550 | public boolean isAppOp() { |
| 551 | return (protectionLevel & PermissionInfo.PROTECTION_FLAG_APPOP) != 0; |
| 552 | } |
| 553 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | public static final Creator<PermissionInfo> CREATOR = |
| 555 | new Creator<PermissionInfo>() { |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 556 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | public PermissionInfo createFromParcel(Parcel source) { |
| 558 | return new PermissionInfo(source); |
| 559 | } |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 560 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | public PermissionInfo[] newArray(int size) { |
| 562 | return new PermissionInfo[size]; |
| 563 | } |
| 564 | }; |
| 565 | |
| 566 | private PermissionInfo(Parcel source) { |
| 567 | super(source); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 568 | protectionLevel = source.readInt(); |
| 569 | flags = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | group = source.readString(); |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 571 | backgroundPermission = source.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | descriptionRes = source.readInt(); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 573 | requestRes = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 574 | nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | } |
| 576 | } |