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; |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
| 22 | import android.annotation.StringRes; |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 23 | import android.annotation.SystemApi; |
Jiyong Park | 2f24f03 | 2017-12-08 12:25:25 +0900 | [diff] [blame] | 24 | import android.annotation.TestApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 25 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.os.Parcel; |
| 27 | import android.os.Parcelable; |
| 28 | import android.text.TextUtils; |
| 29 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 30 | import java.lang.annotation.Retention; |
| 31 | import java.lang.annotation.RetentionPolicy; |
| 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | /** |
| 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 | */ |
| 38 | public 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 Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 61 | * @deprecated Use {@link #PROTECTION_SIGNATURE}|{@link #PROTECTION_FLAG_PRIVILEGED} |
| 62 | * instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | */ |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 64 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3; |
| 66 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 67 | /** @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | /** |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 78 | * Additional flag for {@link #protectionLevel}, corresponding |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 79 | * to the <code>privileged</code> value of |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 80 | * {@link android.R.attr#protectionLevel}. |
| 81 | */ |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 82 | 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 90 | 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 Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 100 | * Additional flag for {@link #protectionLevel}, corresponding |
Jeff Sharkey | e9b78fd | 2014-08-13 14:16:50 -0700 | [diff] [blame] | 101 | * to the <code>appop</code> value of |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 102 | * {@link android.R.attr#protectionLevel}. |
| 103 | */ |
| 104 | public static final int PROTECTION_FLAG_APPOP = 0x40; |
| 105 | |
| 106 | /** |
Dianne Hackborn | de15eda | 2015-07-01 12:30:54 -0700 | [diff] [blame] | 107 | * 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 | /** |
Svetoslav | 3e7d977 | 2015-07-06 18:31:23 -0700 | [diff] [blame] | 114 | * 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 Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 128 | * 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 Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 135 | * 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 Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Additional flag for {@link #protectionLevel}, corresponding |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 143 | * to the <code>instant</code> value of |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 144 | * {@link android.R.attr#protectionLevel}. |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 145 | */ |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 146 | public static final int PROTECTION_FLAG_INSTANT = 0x1000; |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 147 | |
Russell Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 148 | /** |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 149 | * 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 Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 156 | * 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 Karpinski | 517959e | 2019-01-15 11:26:30 +0000 | [diff] [blame] | 163 | @TestApi |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 164 | public static final int PROTECTION_FLAG_OEM = 0x4000; |
| 165 | |
| 166 | /** |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 167 | * 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 Park | 2f24f03 | 2017-12-08 12:25:25 +0900 | [diff] [blame] | 173 | @TestApi |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 174 | public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 0x8000; |
| 175 | |
| 176 | /** |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 177 | * 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 182 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 183 | @SystemApi |
| 184 | @TestApi |
| 185 | public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 0x10000; |
| 186 | |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 187 | /** |
| 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 Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 198 | /** |
| 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 Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 208 | /** |
| 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 Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 218 | /** |
| 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 Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 228 | |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 229 | /** |
| 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 Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 240 | /** @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 Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 256 | PROTECTION_FLAG_WELLBEING, |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 257 | PROTECTION_FLAG_DOCUMENTER, |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 258 | PROTECTION_FLAG_CONFIGURATOR, |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 259 | PROTECTION_FLAG_INCIDENT_REPORT_APPROVER, |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 260 | PROTECTION_FLAG_APP_PREDICTOR, |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 261 | }) |
| 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 271 | public static final int PROTECTION_MASK_BASE = 0xf; |
| 272 | |
| 273 | /** |
| 274 | * Mask for {@link #protectionLevel}: additional flag bits. |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 275 | * |
| 276 | * @deprecated Use #getProtectionFlags() instead. |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 277 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 278 | @Deprecated |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 279 | public static final int PROTECTION_MASK_FLAGS = 0xfff0; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 280 | |
| 281 | /** |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 282 | * The level of access this permission is protecting, as per |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 283 | * {@link android.R.attr#protectionLevel}. Consists of |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 284 | * a base permission type and zero or more flags. Use the following functions |
| 285 | * to extract them. |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 286 | * |
| 287 | * <pre> |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 288 | * int basePermissionType = permissionInfo.getProtection(); |
| 289 | * int permissionFlags = permissionInfo.getProtectionFlags(); |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 290 | * </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 Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 296 | * |
| 297 | * @deprecated Use #getProtection() and #getProtectionFlags() instead. |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 298 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 299 | @Deprecated |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 300 | public int protectionLevel; |
| 301 | |
| 302 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | * The group this permission is a part of, as per |
| 304 | * {@link android.R.attr#permissionGroup}. |
| 305 | */ |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 306 | public @Nullable String group; |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 307 | |
| 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 Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 315 | * Flag for {@link #flags}, corresponding to <code>removed</code> |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 316 | * value of {@link android.R.attr#permissionFlags}. |
| 317 | * @hide |
| 318 | */ |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 319 | @SystemApi |
| 320 | public static final int FLAG_REMOVED = 1<<1; |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 321 | |
| 322 | /** |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 323 | * Flag for {@link #flags}, indicating that this permission has been |
| 324 | * installed into the system's globally defined permissions. |
Svetoslav Ganov | 6d2c0e5 | 2015-06-23 16:33:36 +0000 | [diff] [blame] | 325 | */ |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 326 | public static final int FLAG_INSTALLED = 1<<30; |
Svetoslav Ganov | 6d2c0e5 | 2015-06-23 16:33:36 +0000 | [diff] [blame] | 327 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 328 | /** @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 Ganov | 6d2c0e5 | 2015-06-23 16:33:36 +0000 | [diff] [blame] | 337 | /** |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 338 | * Additional flags about this permission as given by |
| 339 | * {@link android.R.attr#permissionFlags}. |
| 340 | */ |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 341 | public @Flags int flags; |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 342 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | /** |
| 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. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 348 | public @StringRes int descriptionRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | |
| 350 | /** |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 351 | * 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. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 357 | public @StringRes int requestRes; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 358 | |
| 359 | /** |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 360 | * 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. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 372 | public final @Nullable String backgroundPermission; |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 373 | |
| 374 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | * 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. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 380 | public @Nullable CharSequence nonLocalizedDescription; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 382 | /** @hide */ |
| 383 | public static int fixProtectionLevel(int level) { |
| 384 | if (level == PROTECTION_SIGNATURE_OR_SYSTEM) { |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 385 | level = PROTECTION_SIGNATURE | PROTECTION_FLAG_PRIVILEGED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 386 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 387 | 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 Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 393 | return level; |
| 394 | } |
| 395 | |
| 396 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 397 | @UnsupportedAppUsage |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 398 | public static @NonNull String protectionToString(int level) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 399 | String protLevel = "????"; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 400 | switch (level & PROTECTION_MASK_BASE) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 401 | 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 Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 414 | if ((level & PermissionInfo.PROTECTION_FLAG_PRIVILEGED) != 0) { |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 415 | protLevel += "|privileged"; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 416 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 417 | if ((level & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 418 | protLevel += "|development"; |
| 419 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 420 | if ((level & PermissionInfo.PROTECTION_FLAG_APPOP) != 0) { |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 421 | protLevel += "|appop"; |
| 422 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 423 | if ((level & PermissionInfo.PROTECTION_FLAG_PRE23) != 0) { |
Dianne Hackborn | de15eda | 2015-07-01 12:30:54 -0700 | [diff] [blame] | 424 | protLevel += "|pre23"; |
| 425 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 426 | if ((level & PermissionInfo.PROTECTION_FLAG_INSTALLER) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 427 | protLevel += "|installer"; |
| 428 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 429 | if ((level & PermissionInfo.PROTECTION_FLAG_VERIFIER) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 430 | protLevel += "|verifier"; |
| 431 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 432 | if ((level & PermissionInfo.PROTECTION_FLAG_PREINSTALLED) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 433 | protLevel += "|preinstalled"; |
| 434 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 435 | if ((level & PermissionInfo.PROTECTION_FLAG_SETUP) != 0) { |
Russell Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 436 | protLevel += "|setup"; |
| 437 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 438 | if ((level & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 439 | protLevel += "|instant"; |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 440 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 441 | if ((level & PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) != 0) { |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 442 | protLevel += "|runtime"; |
| 443 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 444 | if ((level & PermissionInfo.PROTECTION_FLAG_OEM) != 0) { |
| 445 | protLevel += "|oem"; |
| 446 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 447 | if ((level & PermissionInfo.PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0) { |
| 448 | protLevel += "|vendorPrivileged"; |
| 449 | } |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 450 | if ((level & PermissionInfo.PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER) != 0) { |
| 451 | protLevel += "|textClassifier"; |
| 452 | } |
Varun Shah | 5f30365 | 2018-11-16 18:11:19 -0800 | [diff] [blame] | 453 | if ((level & PermissionInfo.PROTECTION_FLAG_WELLBEING) != 0) { |
| 454 | protLevel += "|wellbeing"; |
| 455 | } |
Jeff Sharkey | 15707b3 | 2018-12-10 12:08:41 -0700 | [diff] [blame] | 456 | if ((level & PermissionInfo.PROTECTION_FLAG_DOCUMENTER) != 0) { |
| 457 | protLevel += "|documenter"; |
| 458 | } |
Stanislav Zholnin | 596437f | 2018-12-28 15:34:23 +0000 | [diff] [blame] | 459 | if ((level & PROTECTION_FLAG_CONFIGURATOR) != 0) { |
| 460 | protLevel += "|configurator"; |
| 461 | } |
Joe Onorato | 5a15b55 | 2018-12-18 10:40:04 -0800 | [diff] [blame] | 462 | if ((level & PermissionInfo.PROTECTION_FLAG_INCIDENT_REPORT_APPROVER) != 0) { |
| 463 | protLevel += "|incidentReportApprover"; |
| 464 | } |
George Hodulik | cd7695d | 2019-01-29 18:17:05 -0800 | [diff] [blame] | 465 | if ((level & PermissionInfo.PROTECTION_FLAG_APP_PREDICTOR) != 0) { |
| 466 | protLevel += "|appPredictor"; |
| 467 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 468 | return protLevel; |
| 469 | } |
| 470 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 471 | /** |
| 472 | * @hide |
| 473 | */ |
| 474 | public PermissionInfo(@Nullable String backgroundPermission) { |
| 475 | this.backgroundPermission = backgroundPermission; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 478 | /** |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 491 | super(orig); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 492 | protectionLevel = orig.protectionLevel; |
| 493 | flags = orig.flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | group = orig.group; |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 495 | backgroundPermission = orig.backgroundPermission; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | descriptionRes = orig.descriptionRes; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 497 | requestRes = orig.requestRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | 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. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 512 | public @Nullable CharSequence loadDescription(@NonNull PackageManager pm) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | 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 Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 525 | /** |
| 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 Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 541 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | public String toString() { |
| 543 | return "PermissionInfo{" |
| 544 | + Integer.toHexString(System.identityHashCode(this)) |
| 545 | + " " + name + "}"; |
| 546 | } |
| 547 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 548 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | public int describeContents() { |
| 550 | return 0; |
| 551 | } |
| 552 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 553 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 555 | super.writeToParcel(dest, parcelableFlags); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 556 | dest.writeInt(protectionLevel); |
| 557 | dest.writeInt(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 558 | dest.writeString(group); |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 559 | dest.writeString(backgroundPermission); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | dest.writeInt(descriptionRes); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 561 | dest.writeInt(requestRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 562 | TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags); |
| 563 | } |
| 564 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 565 | /** @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 Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 577 | /** @hide */ |
| 578 | public boolean isAppOp() { |
| 579 | return (protectionLevel & PermissionInfo.PROTECTION_FLAG_APPOP) != 0; |
| 580 | } |
| 581 | |
Philip P. Moltmann | a4844d1 | 2019-03-02 10:17:23 -0800 | [diff] [blame] | 582 | public static final @NonNull Creator<PermissionInfo> CREATOR = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | new Creator<PermissionInfo>() { |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 584 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | public PermissionInfo createFromParcel(Parcel source) { |
| 586 | return new PermissionInfo(source); |
| 587 | } |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 588 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | public PermissionInfo[] newArray(int size) { |
| 590 | return new PermissionInfo[size]; |
| 591 | } |
| 592 | }; |
| 593 | |
| 594 | private PermissionInfo(Parcel source) { |
| 595 | super(source); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 596 | protectionLevel = source.readInt(); |
| 597 | flags = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | group = source.readString(); |
Philip P. Moltmann | 4a6dff0 | 2018-06-12 16:23:54 -0700 | [diff] [blame] | 599 | backgroundPermission = source.readString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | descriptionRes = source.readInt(); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 601 | requestRes = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 603 | } |
| 604 | } |