1 /* 2 * Copyright (C) 2007 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 19 import android.annotation.Nullable; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * Overall information about the contents of a package. This corresponds 25 * to all of the information collected from AndroidManifest.xml. 26 */ 27 public class PackageInfo implements Parcelable { 28 /** 29 * The name of this package. From the <manifest> tag's "name" 30 * attribute. 31 */ 32 public String packageName; 33 34 /** 35 * The names of any installed split APKs for this package. 36 */ 37 public String[] splitNames; 38 39 /** 40 * @deprecated Use {@link #getLongVersionCode()} instead, which includes both 41 * this and the additional 42 * {@link android.R.styleable#AndroidManifest_versionCodeMajor versionCodeMajor} attribute. 43 * The version number of this package, as specified by the <manifest> 44 * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode} 45 * attribute. 46 * @see #getLongVersionCode() 47 */ 48 @Deprecated 49 public int versionCode; 50 51 /** 52 * @hide 53 * The major version number of this package, as specified by the <manifest> 54 * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCodeMajor} 55 * attribute. 56 * @see #getLongVersionCode() 57 */ 58 public int versionCodeMajor; 59 60 /** 61 * Return {@link android.R.styleable#AndroidManifest_versionCode versionCode} and 62 * {@link android.R.styleable#AndroidManifest_versionCodeMajor versionCodeMajor} combined 63 * together as a single long value. The 64 * {@link android.R.styleable#AndroidManifest_versionCodeMajor versionCodeMajor} is placed in 65 * the upper 32 bits. 66 */ getLongVersionCode()67 public long getLongVersionCode() { 68 return composeLongVersionCode(versionCodeMajor, versionCode); 69 } 70 71 /** 72 * Set the full version code in this PackageInfo, updating {@link #versionCode} 73 * with the lower bits. 74 * @see #getLongVersionCode() 75 */ setLongVersionCode(long longVersionCode)76 public void setLongVersionCode(long longVersionCode) { 77 versionCodeMajor = (int) (longVersionCode>>32); 78 versionCode = (int) longVersionCode; 79 } 80 81 /** 82 * @hide Internal implementation for composing a minor and major version code in to 83 * a single long version code. 84 */ composeLongVersionCode(int major, int minor)85 public static long composeLongVersionCode(int major, int minor) { 86 return (((long) major) << 32) | (((long) minor) & 0xffffffffL); 87 } 88 89 /** 90 * The version name of this package, as specified by the <manifest> 91 * tag's {@link android.R.styleable#AndroidManifest_versionName versionName} 92 * attribute. 93 */ 94 public String versionName; 95 96 /** 97 * The revision number of the base APK for this package, as specified by the 98 * <manifest> tag's 99 * {@link android.R.styleable#AndroidManifest_revisionCode revisionCode} 100 * attribute. 101 */ 102 public int baseRevisionCode; 103 104 /** 105 * The revision number of any split APKs for this package, as specified by 106 * the <manifest> tag's 107 * {@link android.R.styleable#AndroidManifest_revisionCode revisionCode} 108 * attribute. Indexes are a 1:1 mapping against {@link #splitNames}. 109 */ 110 public int[] splitRevisionCodes; 111 112 /** 113 * The shared user ID name of this package, as specified by the <manifest> 114 * tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId} 115 * attribute. 116 */ 117 public String sharedUserId; 118 119 /** 120 * The shared user ID label of this package, as specified by the <manifest> 121 * tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel} 122 * attribute. 123 */ 124 public int sharedUserLabel; 125 126 /** 127 * Information collected from the <application> tag, or null if 128 * there was none. 129 */ 130 public ApplicationInfo applicationInfo; 131 132 /** 133 * The time at which the app was first installed. Units are as 134 * per {@link System#currentTimeMillis()}. 135 */ 136 public long firstInstallTime; 137 138 /** 139 * The time at which the app was last updated. Units are as 140 * per {@link System#currentTimeMillis()}. 141 */ 142 public long lastUpdateTime; 143 144 /** 145 * All kernel group-IDs that have been assigned to this package. 146 * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set. 147 */ 148 public int[] gids; 149 150 /** 151 * Array of all {@link android.R.styleable#AndroidManifestActivity 152 * <activity>} tags included under <application>, 153 * or null if there were none. This is only filled in if the flag 154 * {@link PackageManager#GET_ACTIVITIES} was set. 155 */ 156 public ActivityInfo[] activities; 157 158 /** 159 * Array of all {@link android.R.styleable#AndroidManifestReceiver 160 * <receiver>} tags included under <application>, 161 * or null if there were none. This is only filled in if the flag 162 * {@link PackageManager#GET_RECEIVERS} was set. 163 */ 164 public ActivityInfo[] receivers; 165 166 /** 167 * Array of all {@link android.R.styleable#AndroidManifestService 168 * <service>} tags included under <application>, 169 * or null if there were none. This is only filled in if the flag 170 * {@link PackageManager#GET_SERVICES} was set. 171 */ 172 public ServiceInfo[] services; 173 174 /** 175 * Array of all {@link android.R.styleable#AndroidManifestProvider 176 * <provider>} tags included under <application>, 177 * or null if there were none. This is only filled in if the flag 178 * {@link PackageManager#GET_PROVIDERS} was set. 179 */ 180 public ProviderInfo[] providers; 181 182 /** 183 * Array of all {@link android.R.styleable#AndroidManifestInstrumentation 184 * <instrumentation>} tags included under <manifest>, 185 * or null if there were none. This is only filled in if the flag 186 * {@link PackageManager#GET_INSTRUMENTATION} was set. 187 */ 188 public InstrumentationInfo[] instrumentation; 189 190 /** 191 * Array of all {@link android.R.styleable#AndroidManifestPermission 192 * <permission>} tags included under <manifest>, 193 * or null if there were none. This is only filled in if the flag 194 * {@link PackageManager#GET_PERMISSIONS} was set. 195 */ 196 public PermissionInfo[] permissions; 197 198 /** 199 * Array of all {@link android.R.styleable#AndroidManifestUsesPermission 200 * <uses-permission>} tags included under <manifest>, 201 * or null if there were none. This is only filled in if the flag 202 * {@link PackageManager#GET_PERMISSIONS} was set. This list includes 203 * all permissions requested, even those that were not granted or known 204 * by the system at install time. 205 */ 206 public String[] requestedPermissions; 207 208 /** 209 * Array of flags of all {@link android.R.styleable#AndroidManifestUsesPermission 210 * <uses-permission>} tags included under <manifest>, 211 * or null if there were none. This is only filled in if the flag 212 * {@link PackageManager#GET_PERMISSIONS} was set. Each value matches 213 * the corresponding entry in {@link #requestedPermissions}, and will have 214 * the flag {@link #REQUESTED_PERMISSION_GRANTED} set as appropriate. 215 */ 216 public int[] requestedPermissionsFlags; 217 218 /** 219 * Flag for {@link #requestedPermissionsFlags}: the requested permission 220 * is required for the application to run; the user can not optionally 221 * disable it. Currently all permissions are required. 222 * 223 * @removed We do not support required permissions. 224 */ 225 public static final int REQUESTED_PERMISSION_REQUIRED = 1<<0; 226 227 /** 228 * Flag for {@link #requestedPermissionsFlags}: the requested permission 229 * is currently granted to the application. 230 */ 231 public static final int REQUESTED_PERMISSION_GRANTED = 1<<1; 232 233 /** 234 * Array of all signatures read from the package file. This is only filled 235 * in if the flag {@link PackageManager#GET_SIGNATURES} was set. A package 236 * must be singed with at least one certificate which is at position zero. 237 * The package can be signed with additional certificates which appear as 238 * subsequent entries. 239 * 240 * <strong>Note:</strong> Signature ordering is not guaranteed to be 241 * stable which means that a package signed with certificates A and B is 242 * equivalent to being signed with certificates B and A. This means that 243 * in case multiple signatures are reported you cannot assume the one at 244 * the first position to be the same across updates. 245 * 246 * <strong>Deprecated</strong> This has been replaced by the 247 * {@link PackageInfo#signingInfo} field, which takes into 248 * account signing certificate rotation. For backwards compatibility in 249 * the event of signing certificate rotation, this will return the oldest 250 * reported signing certificate, so that an application will appear to 251 * callers as though no rotation occurred. 252 * 253 * @deprecated use {@code signingInfo} instead 254 */ 255 @Deprecated 256 public Signature[] signatures; 257 258 /** 259 * Signing information read from the package file, potentially 260 * including past signing certificates no longer used after signing 261 * certificate rotation. This is only filled in if 262 * the flag {@link PackageManager#GET_SIGNING_CERTIFICATES} was set. 263 * 264 * Use this field instead of the deprecated {@code signatures} field. 265 * See {@link SigningInfo} for more information on its contents. 266 */ 267 public SigningInfo signingInfo; 268 269 /** 270 * Application specified preferred configuration 271 * {@link android.R.styleable#AndroidManifestUsesConfiguration 272 * <uses-configuration>} tags included under <manifest>, 273 * or null if there were none. This is only filled in if the flag 274 * {@link PackageManager#GET_CONFIGURATIONS} was set. 275 */ 276 public ConfigurationInfo[] configPreferences; 277 278 /** 279 * Features that this application has requested. 280 * 281 * @see FeatureInfo#FLAG_REQUIRED 282 */ 283 public FeatureInfo[] reqFeatures; 284 285 /** 286 * Groups of features that this application has requested. 287 * Each group contains a set of features that are required. 288 * A device must match the features listed in {@link #reqFeatures} and one 289 * or more FeatureGroups in order to have satisfied the feature requirement. 290 * 291 * @see FeatureInfo#FLAG_REQUIRED 292 */ 293 public FeatureGroupInfo[] featureGroups; 294 295 /** 296 * Constant corresponding to <code>auto</code> in 297 * the {@link android.R.attr#installLocation} attribute. 298 * @hide 299 */ 300 public static final int INSTALL_LOCATION_UNSPECIFIED = -1; 301 302 /** 303 * Constant corresponding to <code>auto</code> in the 304 * {@link android.R.attr#installLocation} attribute. 305 */ 306 public static final int INSTALL_LOCATION_AUTO = 0; 307 308 /** 309 * Constant corresponding to <code>internalOnly</code> in the 310 * {@link android.R.attr#installLocation} attribute. 311 */ 312 public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1; 313 314 /** 315 * Constant corresponding to <code>preferExternal</code> in the 316 * {@link android.R.attr#installLocation} attribute. 317 */ 318 public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2; 319 320 /** 321 * The install location requested by the package. From the 322 * {@link android.R.attr#installLocation} attribute, one of 323 * {@link #INSTALL_LOCATION_AUTO}, {@link #INSTALL_LOCATION_INTERNAL_ONLY}, 324 * {@link #INSTALL_LOCATION_PREFER_EXTERNAL} 325 */ 326 public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY; 327 328 /** @hide */ 329 public boolean isStub; 330 331 /** @hide */ 332 public boolean coreApp; 333 334 /** @hide */ 335 public boolean requiredForAllUsers; 336 337 /** @hide */ 338 public String restrictedAccountType; 339 340 /** @hide */ 341 public String requiredAccountType; 342 343 /** 344 * What package, if any, this package will overlay. 345 * 346 * Package name of target package, or null. 347 * @hide 348 */ 349 public String overlayTarget; 350 351 /** 352 * The overlay category, if any, of this package 353 * 354 * @hide 355 */ 356 public String overlayCategory; 357 358 /** @hide */ 359 public int overlayPriority; 360 361 /** 362 * Whether the overlay is static, meaning it cannot be enabled/disabled at runtime. 363 */ 364 boolean mOverlayIsStatic; 365 366 /** 367 * The user-visible SDK version (ex. 26) of the framework against which the application claims 368 * to have been compiled, or {@code 0} if not specified. 369 * <p> 370 * This property is the compile-time equivalent of 371 * {@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT}. 372 * 373 * @hide For platform use only; we don't expect developers to need to read this value. 374 */ 375 public int compileSdkVersion; 376 377 /** 378 * The development codename (ex. "O", "REL") of the framework against which the application 379 * claims to have been compiled, or {@code null} if not specified. 380 * <p> 381 * This property is the compile-time equivalent of 382 * {@link android.os.Build.VERSION#CODENAME Build.VERSION.CODENAME}. 383 * 384 * @hide For platform use only; we don't expect developers to need to read this value. 385 */ 386 @Nullable 387 public String compileSdkVersionCodename; 388 PackageInfo()389 public PackageInfo() { 390 } 391 392 /** 393 * Returns true if the package is a valid Runtime Overlay package. 394 * @hide 395 */ isOverlayPackage()396 public boolean isOverlayPackage() { 397 return overlayTarget != null; 398 } 399 400 /** 401 * Returns true if the package is a valid static Runtime Overlay package. Static overlays 402 * are not updatable outside of a system update and are safe to load in the system process. 403 * @hide 404 */ isStaticOverlayPackage()405 public boolean isStaticOverlayPackage() { 406 return overlayTarget != null && mOverlayIsStatic; 407 } 408 409 @Override toString()410 public String toString() { 411 return "PackageInfo{" 412 + Integer.toHexString(System.identityHashCode(this)) 413 + " " + packageName + "}"; 414 } 415 416 @Override describeContents()417 public int describeContents() { 418 return 0; 419 } 420 421 @Override writeToParcel(Parcel dest, int parcelableFlags)422 public void writeToParcel(Parcel dest, int parcelableFlags) { 423 dest.writeString(packageName); 424 dest.writeStringArray(splitNames); 425 dest.writeInt(versionCode); 426 dest.writeInt(versionCodeMajor); 427 dest.writeString(versionName); 428 dest.writeInt(baseRevisionCode); 429 dest.writeIntArray(splitRevisionCodes); 430 dest.writeString(sharedUserId); 431 dest.writeInt(sharedUserLabel); 432 if (applicationInfo != null) { 433 dest.writeInt(1); 434 applicationInfo.writeToParcel(dest, parcelableFlags); 435 } else { 436 dest.writeInt(0); 437 } 438 dest.writeLong(firstInstallTime); 439 dest.writeLong(lastUpdateTime); 440 dest.writeIntArray(gids); 441 dest.writeTypedArray(activities, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); 442 dest.writeTypedArray(receivers, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); 443 dest.writeTypedArray(services, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); 444 dest.writeTypedArray(providers, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES); 445 dest.writeTypedArray(instrumentation, parcelableFlags); 446 dest.writeTypedArray(permissions, parcelableFlags); 447 dest.writeStringArray(requestedPermissions); 448 dest.writeIntArray(requestedPermissionsFlags); 449 dest.writeTypedArray(signatures, parcelableFlags); 450 dest.writeTypedArray(configPreferences, parcelableFlags); 451 dest.writeTypedArray(reqFeatures, parcelableFlags); 452 dest.writeTypedArray(featureGroups, parcelableFlags); 453 dest.writeInt(installLocation); 454 dest.writeInt(isStub ? 1 : 0); 455 dest.writeInt(coreApp ? 1 : 0); 456 dest.writeInt(requiredForAllUsers ? 1 : 0); 457 dest.writeString(restrictedAccountType); 458 dest.writeString(requiredAccountType); 459 dest.writeString(overlayTarget); 460 dest.writeString(overlayCategory); 461 dest.writeInt(overlayPriority); 462 dest.writeBoolean(mOverlayIsStatic); 463 dest.writeInt(compileSdkVersion); 464 dest.writeString(compileSdkVersionCodename); 465 if (signingInfo != null) { 466 dest.writeInt(1); 467 signingInfo.writeToParcel(dest, parcelableFlags); 468 } else { 469 dest.writeInt(0); 470 } 471 } 472 473 public static final Parcelable.Creator<PackageInfo> CREATOR 474 = new Parcelable.Creator<PackageInfo>() { 475 @Override 476 public PackageInfo createFromParcel(Parcel source) { 477 return new PackageInfo(source); 478 } 479 480 @Override 481 public PackageInfo[] newArray(int size) { 482 return new PackageInfo[size]; 483 } 484 }; 485 PackageInfo(Parcel source)486 private PackageInfo(Parcel source) { 487 packageName = source.readString(); 488 splitNames = source.createStringArray(); 489 versionCode = source.readInt(); 490 versionCodeMajor = source.readInt(); 491 versionName = source.readString(); 492 baseRevisionCode = source.readInt(); 493 splitRevisionCodes = source.createIntArray(); 494 sharedUserId = source.readString(); 495 sharedUserLabel = source.readInt(); 496 int hasApp = source.readInt(); 497 if (hasApp != 0) { 498 applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); 499 } 500 firstInstallTime = source.readLong(); 501 lastUpdateTime = source.readLong(); 502 gids = source.createIntArray(); 503 activities = source.createTypedArray(ActivityInfo.CREATOR); 504 receivers = source.createTypedArray(ActivityInfo.CREATOR); 505 services = source.createTypedArray(ServiceInfo.CREATOR); 506 providers = source.createTypedArray(ProviderInfo.CREATOR); 507 instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR); 508 permissions = source.createTypedArray(PermissionInfo.CREATOR); 509 requestedPermissions = source.createStringArray(); 510 requestedPermissionsFlags = source.createIntArray(); 511 signatures = source.createTypedArray(Signature.CREATOR); 512 configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR); 513 reqFeatures = source.createTypedArray(FeatureInfo.CREATOR); 514 featureGroups = source.createTypedArray(FeatureGroupInfo.CREATOR); 515 installLocation = source.readInt(); 516 isStub = source.readInt() != 0; 517 coreApp = source.readInt() != 0; 518 requiredForAllUsers = source.readInt() != 0; 519 restrictedAccountType = source.readString(); 520 requiredAccountType = source.readString(); 521 overlayTarget = source.readString(); 522 overlayCategory = source.readString(); 523 overlayPriority = source.readInt(); 524 mOverlayIsStatic = source.readBoolean(); 525 compileSdkVersion = source.readInt(); 526 compileSdkVersionCodename = source.readString(); 527 int hasSigningInfo = source.readInt(); 528 if (hasSigningInfo != 0) { 529 signingInfo = SigningInfo.CREATOR.createFromParcel(source); 530 } 531 532 // The component lists were flattened with the redundant ApplicationInfo 533 // instances omitted. Distribute the canonical one here as appropriate. 534 if (applicationInfo != null) { 535 propagateApplicationInfo(applicationInfo, activities); 536 propagateApplicationInfo(applicationInfo, receivers); 537 propagateApplicationInfo(applicationInfo, services); 538 propagateApplicationInfo(applicationInfo, providers); 539 } 540 } 541 propagateApplicationInfo(ApplicationInfo appInfo, ComponentInfo[] components)542 private void propagateApplicationInfo(ApplicationInfo appInfo, ComponentInfo[] components) { 543 if (components != null) { 544 for (ComponentInfo ci : components) { 545 ci.applicationInfo = appInfo; 546 } 547 } 548 } 549 } 550