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 | 1c77a11 | 2018-08-14 14:06:26 +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 |
| 160 | public static final int PROTECTION_FLAG_OEM = 0x4000; |
| 161 | |
| 162 | /** |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 163 | * Additional flag for {${link #protectionLevel}, corresponding |
| 164 | * to the <code>vendorPrivileged</code> value of |
| 165 | * {@link android.R.attr#protectionLevel}. |
| 166 | * |
| 167 | * @hide |
| 168 | */ |
Jiyong Park | 2f24f03 | 2017-12-08 12:25:25 +0900 | [diff] [blame] | 169 | @TestApi |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 170 | public static final int PROTECTION_FLAG_VENDOR_PRIVILEGED = 0x8000; |
| 171 | |
| 172 | /** |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 173 | * Additional flag for {@link #protectionLevel}, corresponding |
| 174 | * to the <code>text_classifier</code> value of |
| 175 | * {@link android.R.attr#protectionLevel}. |
| 176 | * |
| 177 | * @hide |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 178 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 179 | @SystemApi |
| 180 | @TestApi |
| 181 | public static final int PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER = 0x10000; |
| 182 | |
| 183 | /** @hide */ |
| 184 | @IntDef(flag = true, prefix = { "PROTECTION_FLAG_" }, value = { |
| 185 | PROTECTION_FLAG_PRIVILEGED, |
| 186 | PROTECTION_FLAG_SYSTEM, |
| 187 | PROTECTION_FLAG_DEVELOPMENT, |
| 188 | PROTECTION_FLAG_APPOP, |
| 189 | PROTECTION_FLAG_PRE23, |
| 190 | PROTECTION_FLAG_INSTALLER, |
| 191 | PROTECTION_FLAG_VERIFIER, |
| 192 | PROTECTION_FLAG_PREINSTALLED, |
| 193 | PROTECTION_FLAG_SETUP, |
| 194 | PROTECTION_FLAG_INSTANT, |
| 195 | PROTECTION_FLAG_RUNTIME_ONLY, |
| 196 | PROTECTION_FLAG_OEM, |
| 197 | PROTECTION_FLAG_VENDOR_PRIVILEGED, |
| 198 | PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER, |
| 199 | }) |
| 200 | @Retention(RetentionPolicy.SOURCE) |
| 201 | public @interface ProtectionFlags {} |
| 202 | |
| 203 | /** |
| 204 | * Mask for {@link #protectionLevel}: the basic protection type. |
| 205 | * |
| 206 | * @deprecated Use #getProtection() instead. |
| 207 | */ |
| 208 | @Deprecated |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 209 | public static final int PROTECTION_MASK_BASE = 0xf; |
| 210 | |
| 211 | /** |
| 212 | * Mask for {@link #protectionLevel}: additional flag bits. |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 213 | * |
| 214 | * @deprecated Use #getProtectionFlags() instead. |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 215 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 216 | @Deprecated |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 217 | public static final int PROTECTION_MASK_FLAGS = 0xfff0; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 218 | |
| 219 | /** |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 220 | * The level of access this permission is protecting, as per |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 221 | * {@link android.R.attr#protectionLevel}. Consists of |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 222 | * a base permission type and zero or more flags. Use the following functions |
| 223 | * to extract them. |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 224 | * |
| 225 | * <pre> |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 226 | * int basePermissionType = permissionInfo.getProtection(); |
| 227 | * int permissionFlags = permissionInfo.getProtectionFlags(); |
Peter Visontay | 51fbad5 | 2017-11-15 12:38:14 +0000 | [diff] [blame] | 228 | * </pre> |
| 229 | * |
| 230 | * <p></p>Base permission types are {@link #PROTECTION_NORMAL}, |
| 231 | * {@link #PROTECTION_DANGEROUS}, {@link #PROTECTION_SIGNATURE} |
| 232 | * and the deprecated {@link #PROTECTION_SIGNATURE_OR_SYSTEM}. |
| 233 | * Flags are listed under {@link android.R.attr#protectionLevel}. |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 234 | * |
| 235 | * @deprecated Use #getProtection() and #getProtectionFlags() instead. |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 236 | */ |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 237 | @Deprecated |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 238 | public int protectionLevel; |
| 239 | |
| 240 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | * The group this permission is a part of, as per |
| 242 | * {@link android.R.attr#permissionGroup}. |
| 243 | */ |
| 244 | public String group; |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | * Flag for {@link #flags}, corresponding to <code>costsMoney</code> |
| 248 | * value of {@link android.R.attr#permissionFlags}. |
| 249 | */ |
| 250 | public static final int FLAG_COSTS_MONEY = 1<<0; |
| 251 | |
| 252 | /** |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 253 | * Flag for {@link #flags}, corresponding to <code>removed</code> |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 254 | * value of {@link android.R.attr#permissionFlags}. |
| 255 | * @hide |
| 256 | */ |
Svet Ganov | 2a1376d | 2016-02-22 17:20:35 -0800 | [diff] [blame] | 257 | @SystemApi |
| 258 | public static final int FLAG_REMOVED = 1<<1; |
Svet Ganov | 3e0be74 | 2015-08-07 23:06:00 -0700 | [diff] [blame] | 259 | |
| 260 | /** |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 261 | * Flag for {@link #flags}, indicating that this permission has been |
| 262 | * installed into the system's globally defined permissions. |
Svetoslav Ganov | 6d2c0e5 | 2015-06-23 16:33:36 +0000 | [diff] [blame] | 263 | */ |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 264 | public static final int FLAG_INSTALLED = 1<<30; |
Svetoslav Ganov | 6d2c0e5 | 2015-06-23 16:33:36 +0000 | [diff] [blame] | 265 | |
| 266 | /** |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 267 | * Additional flags about this permission as given by |
| 268 | * {@link android.R.attr#permissionFlags}. |
| 269 | */ |
| 270 | public int flags; |
| 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | /** |
| 273 | * A string resource identifier (in the package's resources) of this |
| 274 | * permission's description. From the "description" attribute or, |
| 275 | * if not set, 0. |
| 276 | */ |
| 277 | public int descriptionRes; |
| 278 | |
| 279 | /** |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 280 | * A string resource identifier (in the package's resources) used to request the permissions. |
| 281 | * From the "request" attribute or, if not set, 0. |
| 282 | * |
| 283 | * @hide |
| 284 | */ |
| 285 | @SystemApi |
| 286 | public int requestRes; |
| 287 | |
| 288 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | * The description string provided in the AndroidManifest file, if any. You |
| 290 | * probably don't want to use this, since it will be null if the description |
| 291 | * is in a resource. You probably want |
| 292 | * {@link PermissionInfo#loadDescription} instead. |
| 293 | */ |
| 294 | public CharSequence nonLocalizedDescription; |
| 295 | |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 296 | /** @hide */ |
| 297 | public static int fixProtectionLevel(int level) { |
| 298 | if (level == PROTECTION_SIGNATURE_OR_SYSTEM) { |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 299 | level = PROTECTION_SIGNATURE | PROTECTION_FLAG_PRIVILEGED; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 300 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 301 | if ((level & PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0 |
| 302 | && (level & PROTECTION_FLAG_PRIVILEGED) == 0) { |
| 303 | // 'vendorPrivileged' must be 'privileged'. If not, |
| 304 | // drop the vendorPrivileged. |
| 305 | level = level & ~PROTECTION_FLAG_VENDOR_PRIVILEGED; |
| 306 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 307 | return level; |
| 308 | } |
| 309 | |
| 310 | /** @hide */ |
Mathew Inwood | 1c77a11 | 2018-08-14 14:06:26 +0100 | [diff] [blame] | 311 | @UnsupportedAppUsage |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 312 | public static String protectionToString(int level) { |
| 313 | String protLevel = "????"; |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 314 | switch (level & PROTECTION_MASK_BASE) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 315 | case PermissionInfo.PROTECTION_DANGEROUS: |
| 316 | protLevel = "dangerous"; |
| 317 | break; |
| 318 | case PermissionInfo.PROTECTION_NORMAL: |
| 319 | protLevel = "normal"; |
| 320 | break; |
| 321 | case PermissionInfo.PROTECTION_SIGNATURE: |
| 322 | protLevel = "signature"; |
| 323 | break; |
| 324 | case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM: |
| 325 | protLevel = "signatureOrSystem"; |
| 326 | break; |
| 327 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 328 | if ((level & PermissionInfo.PROTECTION_FLAG_PRIVILEGED) != 0) { |
Dianne Hackborn | a90c8de | 2015-07-07 17:25:25 -0700 | [diff] [blame] | 329 | protLevel += "|privileged"; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 330 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 331 | if ((level & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) { |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 332 | protLevel += "|development"; |
| 333 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 334 | if ((level & PermissionInfo.PROTECTION_FLAG_APPOP) != 0) { |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 335 | protLevel += "|appop"; |
| 336 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 337 | if ((level & PermissionInfo.PROTECTION_FLAG_PRE23) != 0) { |
Dianne Hackborn | de15eda | 2015-07-01 12:30:54 -0700 | [diff] [blame] | 338 | protLevel += "|pre23"; |
| 339 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 340 | if ((level & PermissionInfo.PROTECTION_FLAG_INSTALLER) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 341 | protLevel += "|installer"; |
| 342 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 343 | if ((level & PermissionInfo.PROTECTION_FLAG_VERIFIER) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 344 | protLevel += "|verifier"; |
| 345 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 346 | if ((level & PermissionInfo.PROTECTION_FLAG_PREINSTALLED) != 0) { |
Dianne Hackborn | cfbfafe | 2015-07-21 16:57:51 -0700 | [diff] [blame] | 347 | protLevel += "|preinstalled"; |
| 348 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 349 | if ((level & PermissionInfo.PROTECTION_FLAG_SETUP) != 0) { |
Russell Brenner | b233466 | 2016-03-23 10:16:39 -0700 | [diff] [blame] | 350 | protLevel += "|setup"; |
| 351 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 352 | if ((level & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0) { |
Todd Kennedy | c247fa1 | 2017-06-02 10:29:22 -0700 | [diff] [blame] | 353 | protLevel += "|instant"; |
Chad Brubaker | c19706a | 2016-10-13 15:44:59 -0700 | [diff] [blame] | 354 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 355 | if ((level & PermissionInfo.PROTECTION_FLAG_RUNTIME_ONLY) != 0) { |
Chad Brubaker | a5d70a1 | 2017-03-23 11:04:50 -0700 | [diff] [blame] | 356 | protLevel += "|runtime"; |
| 357 | } |
Svet Ganov | 087dce2 | 2017-09-07 15:42:16 -0700 | [diff] [blame] | 358 | if ((level & PermissionInfo.PROTECTION_FLAG_OEM) != 0) { |
| 359 | protLevel += "|oem"; |
| 360 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 361 | if ((level & PermissionInfo.PROTECTION_FLAG_VENDOR_PRIVILEGED) != 0) { |
| 362 | protLevel += "|vendorPrivileged"; |
| 363 | } |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 364 | if ((level & PermissionInfo.PROTECTION_FLAG_SYSTEM_TEXT_CLASSIFIER) != 0) { |
| 365 | protLevel += "|textClassifier"; |
| 366 | } |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 367 | return protLevel; |
| 368 | } |
| 369 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 370 | public PermissionInfo() { |
| 371 | } |
| 372 | |
| 373 | public PermissionInfo(PermissionInfo orig) { |
| 374 | super(orig); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 375 | protectionLevel = orig.protectionLevel; |
| 376 | flags = orig.flags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | group = orig.group; |
| 378 | descriptionRes = orig.descriptionRes; |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 379 | requestRes = orig.requestRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | nonLocalizedDescription = orig.nonLocalizedDescription; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Retrieve the textual description of this permission. This |
| 385 | * will call back on the given PackageManager to load the description from |
| 386 | * the application. |
| 387 | * |
| 388 | * @param pm A PackageManager from which the label can be loaded; usually |
| 389 | * the PackageManager from which you originally retrieved this item. |
| 390 | * |
| 391 | * @return Returns a CharSequence containing the permission's description. |
| 392 | * If there is no description, null is returned. |
| 393 | */ |
| 394 | public CharSequence loadDescription(PackageManager pm) { |
| 395 | if (nonLocalizedDescription != null) { |
| 396 | return nonLocalizedDescription; |
| 397 | } |
| 398 | if (descriptionRes != 0) { |
| 399 | CharSequence label = pm.getText(packageName, descriptionRes, null); |
| 400 | if (label != null) { |
| 401 | return label; |
| 402 | } |
| 403 | } |
| 404 | return null; |
| 405 | } |
| 406 | |
Makoto Onuki | 700feef | 2018-02-15 10:59:41 -0800 | [diff] [blame] | 407 | /** |
| 408 | * Return the base permission type. |
| 409 | */ |
| 410 | @Protection |
| 411 | public int getProtection() { |
| 412 | return protectionLevel & PROTECTION_MASK_BASE; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Return the additional flags in {@link #protectionLevel}. |
| 417 | */ |
| 418 | @ProtectionFlags |
| 419 | public int getProtectionFlags() { |
| 420 | return protectionLevel & ~PROTECTION_MASK_BASE; |
| 421 | } |
| 422 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 423 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | public String toString() { |
| 425 | return "PermissionInfo{" |
| 426 | + Integer.toHexString(System.identityHashCode(this)) |
| 427 | + " " + name + "}"; |
| 428 | } |
| 429 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 430 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | public int describeContents() { |
| 432 | return 0; |
| 433 | } |
| 434 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 435 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 436 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 437 | super.writeToParcel(dest, parcelableFlags); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 438 | dest.writeInt(protectionLevel); |
| 439 | dest.writeInt(flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | dest.writeString(group); |
| 441 | dest.writeInt(descriptionRes); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 442 | dest.writeInt(requestRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | TextUtils.writeToParcel(nonLocalizedDescription, dest, parcelableFlags); |
| 444 | } |
| 445 | |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 446 | /** @hide */ |
| 447 | public int calculateFootprint() { |
| 448 | int size = name.length(); |
| 449 | if (nonLocalizedLabel != null) { |
| 450 | size += nonLocalizedLabel.length(); |
| 451 | } |
| 452 | if (nonLocalizedDescription != null) { |
| 453 | size += nonLocalizedDescription.length(); |
| 454 | } |
| 455 | return size; |
| 456 | } |
| 457 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 458 | /** @hide */ |
| 459 | public boolean isAppOp() { |
| 460 | return (protectionLevel & PermissionInfo.PROTECTION_FLAG_APPOP) != 0; |
| 461 | } |
| 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | public static final Creator<PermissionInfo> CREATOR = |
| 464 | new Creator<PermissionInfo>() { |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 465 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | public PermissionInfo createFromParcel(Parcel source) { |
| 467 | return new PermissionInfo(source); |
| 468 | } |
Todd Kennedy | 91a39d1 | 2017-09-27 12:37:04 -0700 | [diff] [blame] | 469 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | public PermissionInfo[] newArray(int size) { |
| 471 | return new PermissionInfo[size]; |
| 472 | } |
| 473 | }; |
| 474 | |
| 475 | private PermissionInfo(Parcel source) { |
| 476 | super(source); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 477 | protectionLevel = source.readInt(); |
| 478 | flags = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | group = source.readString(); |
| 480 | descriptionRes = source.readInt(); |
Philip P. Moltmann | 27ffeb3 | 2017-07-06 13:54:46 -0700 | [diff] [blame] | 481 | requestRes = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | nonLocalizedDescription = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); |
| 483 | } |
| 484 | } |