1 /* 2 * Copyright (C) 2021 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.parsing; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.content.pm.ArchivedPackageParcel; 22 import android.content.pm.PackageInfo; 23 import android.content.pm.SharedLibraryInfo; 24 import android.content.pm.SigningDetails; 25 import android.content.pm.VerifierInfo; 26 27 import com.android.internal.util.ArrayUtils; 28 import com.android.internal.util.CollectionUtils; 29 import com.android.internal.util.DataClass; 30 31 import java.util.ArrayList; 32 import java.util.Collections; 33 import java.util.List; 34 import java.util.Set; 35 36 /** 37 * Lightweight parsed details about a single package. 38 * 39 * @hide 40 */ 41 @DataClass(genConstructor = false, genConstDefs = false) 42 public class PackageLite { 43 /** Name of the package as used to identify it in the system */ 44 private final @NonNull String mPackageName; 45 /** 46 * Path where this package was found on disk. For monolithic packages 47 * this is path to single base APK file; for cluster packages this is 48 * path to the cluster directory. 49 */ 50 private final @NonNull String mPath; 51 /** Path of base APK */ 52 private final @NonNull String mBaseApkPath; 53 /** Paths of any split APKs, ordered by parsed splitName */ 54 private final @Nullable String[] mSplitApkPaths; 55 /** Names of any split APKs, ordered by parsed splitName */ 56 private final @Nullable String[] mSplitNames; 57 /** Dependencies of any split APKs, ordered by parsed splitName */ 58 private final @Nullable String[] mUsesSplitNames; 59 private final @Nullable String[] mConfigForSplit; 60 /** Indicate the types of the required split are necessary for base APK to run */ 61 private final @Nullable Set<String> mBaseRequiredSplitTypes; 62 /** Indicate the types of the required split are necessary for split APKs to run */ 63 private final @Nullable Set<String>[] mRequiredSplitTypes; 64 /** Split type of any split APKs, ordered by parsed splitName */ 65 private final @Nullable Set<String>[] mSplitTypes; 66 /** Major and minor version number of this package */ 67 private final int mVersionCodeMajor; 68 private final int mVersionCode; 69 private final int mTargetSdk; 70 /** Revision code of base APK */ 71 private final int mBaseRevisionCode; 72 /** Revision codes of any split APKs, ordered by parsed splitName */ 73 private final @Nullable int[] mSplitRevisionCodes; 74 /** 75 * Indicate the install location of this package 76 * 77 * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} 78 * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} 79 * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} 80 */ 81 private final int mInstallLocation; 82 /** Information about a package verifiers as used during package verification */ 83 private final @NonNull VerifierInfo[] mVerifiers; 84 /** Signing-related data of an application package */ 85 private final @NonNull SigningDetails mSigningDetails; 86 87 /** Indicate whether any split APKs that are features. Ordered by splitName */ 88 private final @Nullable boolean[] mIsFeatureSplits; 89 /** Indicate whether each split should be load into their own Context objects */ 90 private final boolean mIsolatedSplits; 91 /** 92 * Indicate whether this package requires at least one split (either feature or resource) 93 * to be present in order to function 94 */ 95 private final boolean mSplitRequired; 96 /** Indicate whether this app is coreApp */ 97 private final boolean mCoreApp; 98 /** Indicate whether this app can be debugged */ 99 private final boolean mDebuggable; 100 /** Indicate whether this app needs to be loaded into other applications' processes */ 101 private final boolean mMultiArch; 102 /** Indicate whether the 32 bit version of the ABI should be used */ 103 private final boolean mUse32bitAbi; 104 /** Indicate whether installer extracts native libraries */ 105 private final boolean mExtractNativeLibs; 106 /** Indicate whether this app is profileable by Shell */ 107 private final boolean mProfileableByShell; 108 /** 109 * Indicate whether this package wants to run the dex within its APK but not extracted 110 * or locally compiled variants. 111 */ 112 private final boolean mUseEmbeddedDex; 113 /** 114 * Indicates if this package is a sdk. 115 */ 116 private final boolean mIsSdkLibrary; 117 /** 118 * Indicates if this package is a static library. 119 */ 120 private final boolean mIsStaticLibrary; 121 122 private final @NonNull List<String> mUsesSdkLibraries; 123 124 private final @Nullable long[] mUsesSdkLibrariesVersionsMajor; 125 126 private final @Nullable String[][] mUsesSdkLibrariesCertDigests; 127 128 private final @NonNull List<String> mUsesStaticLibraries; 129 130 private final @Nullable long[] mUsesStaticLibrariesVersions; 131 132 private final @Nullable String[][] mUsesStaticLibrariesCertDigests; 133 134 private final @NonNull List<SharedLibraryInfo> mDeclaredLibraries; 135 136 /** 137 * Archival install info. 138 */ 139 private final @Nullable ArchivedPackageParcel mArchivedPackage; 140 141 /** 142 * pageSizeCompat info from manifest file 143 */ 144 private final int mPageSizeCompat; 145 PackageLite(String path, String baseApkPath, ApkLite baseApk, String[] splitNames, boolean[] isFeatureSplits, String[] usesSplitNames, String[] configForSplit, String[] splitApkPaths, int[] splitRevisionCodes, int targetSdk, Set<String>[] requiredSplitTypes, Set<String>[] splitTypes)146 public PackageLite(String path, String baseApkPath, ApkLite baseApk, 147 String[] splitNames, boolean[] isFeatureSplits, String[] usesSplitNames, 148 String[] configForSplit, String[] splitApkPaths, int[] splitRevisionCodes, 149 int targetSdk, Set<String>[] requiredSplitTypes, Set<String>[] splitTypes) { 150 // The following paths may be different from the path in ApkLite because we 151 // move or rename the APK files. Use parameters to indicate the correct paths. 152 mPath = path; 153 mBaseApkPath = baseApkPath; 154 mPackageName = baseApk.getPackageName(); 155 mVersionCode = baseApk.getVersionCode(); 156 mVersionCodeMajor = baseApk.getVersionCodeMajor(); 157 mInstallLocation = baseApk.getInstallLocation(); 158 mVerifiers = baseApk.getVerifiers(); 159 mSigningDetails = baseApk.getSigningDetails(); 160 mBaseRevisionCode = baseApk.getRevisionCode(); 161 mCoreApp = baseApk.isCoreApp(); 162 mDebuggable = baseApk.isDebuggable(); 163 mMultiArch = baseApk.isMultiArch(); 164 mUse32bitAbi = baseApk.isUse32bitAbi(); 165 mExtractNativeLibs = baseApk.isExtractNativeLibs(); 166 mIsolatedSplits = baseApk.isIsolatedSplits(); 167 mUseEmbeddedDex = baseApk.isUseEmbeddedDex(); 168 mBaseRequiredSplitTypes = baseApk.getRequiredSplitTypes(); 169 mRequiredSplitTypes = requiredSplitTypes; 170 mSplitRequired = (baseApk.isSplitRequired() || hasAnyRequiredSplitTypes()); 171 mProfileableByShell = baseApk.isProfileableByShell(); 172 mIsSdkLibrary = baseApk.isIsSdkLibrary(); 173 mUsesSdkLibraries = baseApk.getUsesSdkLibraries(); 174 mUsesSdkLibrariesVersionsMajor = baseApk.getUsesSdkLibrariesVersionsMajor(); 175 mUsesSdkLibrariesCertDigests = baseApk.getUsesSdkLibrariesCertDigests(); 176 mIsStaticLibrary = baseApk.isIsStaticLibrary(); 177 mUsesStaticLibraries = baseApk.getUsesStaticLibraries(); 178 mUsesStaticLibrariesVersions = baseApk.getUsesStaticLibrariesVersions(); 179 mUsesStaticLibrariesCertDigests = baseApk.getUsesStaticLibrariesCertDigests(); 180 mSplitNames = splitNames; 181 mSplitTypes = splitTypes; 182 mIsFeatureSplits = isFeatureSplits; 183 mUsesSplitNames = usesSplitNames; 184 mConfigForSplit = configForSplit; 185 mSplitApkPaths = splitApkPaths; 186 mSplitRevisionCodes = splitRevisionCodes; 187 mTargetSdk = targetSdk; 188 mDeclaredLibraries = baseApk.getDeclaredLibraries(); 189 mArchivedPackage = baseApk.getArchivedPackage(); 190 mPageSizeCompat = baseApk.getPageSizeCompat(); 191 } 192 193 /** 194 * Return code path to the base APK file, and split APK files if any. 195 */ getAllApkPaths()196 public List<String> getAllApkPaths() { 197 final ArrayList<String> paths = new ArrayList<>(); 198 paths.add(mBaseApkPath); 199 if (!ArrayUtils.isEmpty(mSplitApkPaths)) { 200 Collections.addAll(paths, mSplitApkPaths); 201 } 202 return paths; 203 } 204 205 /** 206 * Return {@link #mVersionCode} and {@link #mVersionCodeMajor} combined together as a 207 * single long value. The {@link #mVersionCodeMajor} is placed in the upper 32 bits. 208 */ getLongVersionCode()209 public long getLongVersionCode() { 210 return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); 211 } 212 213 /** 214 * Return if requiredSplitTypes presents in the package. 215 */ hasAnyRequiredSplitTypes()216 private boolean hasAnyRequiredSplitTypes() { 217 if (!CollectionUtils.isEmpty(mBaseRequiredSplitTypes)) { 218 return true; 219 } 220 return ArrayUtils.find(mRequiredSplitTypes, r -> !CollectionUtils.isEmpty(r)) != null; 221 } 222 223 224 225 // Code below generated by codegen v1.0.23. 226 // 227 // DO NOT MODIFY! 228 // CHECKSTYLE:OFF Generated code 229 // 230 // To regenerate run: 231 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/PackageLite.java 232 // 233 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 234 // Settings > Editor > Code Style > Formatter Control 235 //@formatter:off 236 237 238 /** 239 * Name of the package as used to identify it in the system 240 */ 241 @DataClass.Generated.Member getPackageName()242 public @NonNull String getPackageName() { 243 return mPackageName; 244 } 245 246 /** 247 * Path where this package was found on disk. For monolithic packages 248 * this is path to single base APK file; for cluster packages this is 249 * path to the cluster directory. 250 */ 251 @DataClass.Generated.Member getPath()252 public @NonNull String getPath() { 253 return mPath; 254 } 255 256 /** 257 * Path of base APK 258 */ 259 @DataClass.Generated.Member getBaseApkPath()260 public @NonNull String getBaseApkPath() { 261 return mBaseApkPath; 262 } 263 264 /** 265 * Paths of any split APKs, ordered by parsed splitName 266 */ 267 @DataClass.Generated.Member getSplitApkPaths()268 public @Nullable String[] getSplitApkPaths() { 269 return mSplitApkPaths; 270 } 271 272 /** 273 * Names of any split APKs, ordered by parsed splitName 274 */ 275 @DataClass.Generated.Member getSplitNames()276 public @Nullable String[] getSplitNames() { 277 return mSplitNames; 278 } 279 280 /** 281 * Dependencies of any split APKs, ordered by parsed splitName 282 */ 283 @DataClass.Generated.Member getUsesSplitNames()284 public @Nullable String[] getUsesSplitNames() { 285 return mUsesSplitNames; 286 } 287 288 @DataClass.Generated.Member getConfigForSplit()289 public @Nullable String[] getConfigForSplit() { 290 return mConfigForSplit; 291 } 292 293 /** 294 * Indicate the types of the required split are necessary for base APK to run 295 */ 296 @DataClass.Generated.Member getBaseRequiredSplitTypes()297 public @Nullable Set<String> getBaseRequiredSplitTypes() { 298 return mBaseRequiredSplitTypes; 299 } 300 301 /** 302 * Indicate the types of the required split are necessary for split APKs to run 303 */ 304 @DataClass.Generated.Member getRequiredSplitTypes()305 public @Nullable Set<String>[] getRequiredSplitTypes() { 306 return mRequiredSplitTypes; 307 } 308 309 /** 310 * Split type of any split APKs, ordered by parsed splitName 311 */ 312 @DataClass.Generated.Member getSplitTypes()313 public @Nullable Set<String>[] getSplitTypes() { 314 return mSplitTypes; 315 } 316 317 /** 318 * Major and minor version number of this package 319 */ 320 @DataClass.Generated.Member getVersionCodeMajor()321 public int getVersionCodeMajor() { 322 return mVersionCodeMajor; 323 } 324 325 @DataClass.Generated.Member getVersionCode()326 public int getVersionCode() { 327 return mVersionCode; 328 } 329 330 @DataClass.Generated.Member getTargetSdk()331 public int getTargetSdk() { 332 return mTargetSdk; 333 } 334 335 /** 336 * Revision code of base APK 337 */ 338 @DataClass.Generated.Member getBaseRevisionCode()339 public int getBaseRevisionCode() { 340 return mBaseRevisionCode; 341 } 342 343 /** 344 * Revision codes of any split APKs, ordered by parsed splitName 345 */ 346 @DataClass.Generated.Member getSplitRevisionCodes()347 public @Nullable int[] getSplitRevisionCodes() { 348 return mSplitRevisionCodes; 349 } 350 351 /** 352 * Indicate the install location of this package 353 * 354 * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} 355 * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} 356 * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} 357 */ 358 @DataClass.Generated.Member getInstallLocation()359 public int getInstallLocation() { 360 return mInstallLocation; 361 } 362 363 /** 364 * Information about a package verifiers as used during package verification 365 */ 366 @DataClass.Generated.Member getVerifiers()367 public @NonNull VerifierInfo[] getVerifiers() { 368 return mVerifiers; 369 } 370 371 /** 372 * Signing-related data of an application package 373 */ 374 @DataClass.Generated.Member getSigningDetails()375 public @NonNull SigningDetails getSigningDetails() { 376 return mSigningDetails; 377 } 378 379 /** 380 * Indicate whether any split APKs that are features. Ordered by splitName 381 */ 382 @DataClass.Generated.Member getIsFeatureSplits()383 public @Nullable boolean[] getIsFeatureSplits() { 384 return mIsFeatureSplits; 385 } 386 387 /** 388 * Indicate whether each split should be load into their own Context objects 389 */ 390 @DataClass.Generated.Member isIsolatedSplits()391 public boolean isIsolatedSplits() { 392 return mIsolatedSplits; 393 } 394 395 /** 396 * Indicate whether this package requires at least one split (either feature or resource) 397 * to be present in order to function 398 */ 399 @DataClass.Generated.Member isSplitRequired()400 public boolean isSplitRequired() { 401 return mSplitRequired; 402 } 403 404 /** 405 * Indicate whether this app is coreApp 406 */ 407 @DataClass.Generated.Member isCoreApp()408 public boolean isCoreApp() { 409 return mCoreApp; 410 } 411 412 /** 413 * Indicate whether this app can be debugged 414 */ 415 @DataClass.Generated.Member isDebuggable()416 public boolean isDebuggable() { 417 return mDebuggable; 418 } 419 420 /** 421 * Indicate whether this app needs to be loaded into other applications' processes 422 */ 423 @DataClass.Generated.Member isMultiArch()424 public boolean isMultiArch() { 425 return mMultiArch; 426 } 427 428 /** 429 * Indicate whether the 32 bit version of the ABI should be used 430 */ 431 @DataClass.Generated.Member isUse32bitAbi()432 public boolean isUse32bitAbi() { 433 return mUse32bitAbi; 434 } 435 436 /** 437 * Indicate whether installer extracts native libraries 438 */ 439 @DataClass.Generated.Member isExtractNativeLibs()440 public boolean isExtractNativeLibs() { 441 return mExtractNativeLibs; 442 } 443 444 /** 445 * Indicate whether this app is profileable by Shell 446 */ 447 @DataClass.Generated.Member isProfileableByShell()448 public boolean isProfileableByShell() { 449 return mProfileableByShell; 450 } 451 452 /** 453 * Indicate whether this package wants to run the dex within its APK but not extracted 454 * or locally compiled variants. 455 */ 456 @DataClass.Generated.Member isUseEmbeddedDex()457 public boolean isUseEmbeddedDex() { 458 return mUseEmbeddedDex; 459 } 460 461 /** 462 * Indicates if this package is a sdk. 463 */ 464 @DataClass.Generated.Member isIsSdkLibrary()465 public boolean isIsSdkLibrary() { 466 return mIsSdkLibrary; 467 } 468 469 /** 470 * Indicates if this package is a static library. 471 */ 472 @DataClass.Generated.Member isIsStaticLibrary()473 public boolean isIsStaticLibrary() { 474 return mIsStaticLibrary; 475 } 476 477 @DataClass.Generated.Member getUsesSdkLibraries()478 public @NonNull List<String> getUsesSdkLibraries() { 479 return mUsesSdkLibraries; 480 } 481 482 @DataClass.Generated.Member getUsesSdkLibrariesVersionsMajor()483 public @Nullable long[] getUsesSdkLibrariesVersionsMajor() { 484 return mUsesSdkLibrariesVersionsMajor; 485 } 486 487 @DataClass.Generated.Member getUsesSdkLibrariesCertDigests()488 public @Nullable String[][] getUsesSdkLibrariesCertDigests() { 489 return mUsesSdkLibrariesCertDigests; 490 } 491 492 @DataClass.Generated.Member getUsesStaticLibraries()493 public @NonNull List<String> getUsesStaticLibraries() { 494 return mUsesStaticLibraries; 495 } 496 497 @DataClass.Generated.Member getUsesStaticLibrariesVersions()498 public @Nullable long[] getUsesStaticLibrariesVersions() { 499 return mUsesStaticLibrariesVersions; 500 } 501 502 @DataClass.Generated.Member getUsesStaticLibrariesCertDigests()503 public @Nullable String[][] getUsesStaticLibrariesCertDigests() { 504 return mUsesStaticLibrariesCertDigests; 505 } 506 507 @DataClass.Generated.Member getDeclaredLibraries()508 public @NonNull List<SharedLibraryInfo> getDeclaredLibraries() { 509 return mDeclaredLibraries; 510 } 511 512 /** 513 * Archival install info. 514 */ 515 @DataClass.Generated.Member getArchivedPackage()516 public @Nullable ArchivedPackageParcel getArchivedPackage() { 517 return mArchivedPackage; 518 } 519 520 /** 521 * pageSizeCompat info from manifest file 522 */ 523 @DataClass.Generated.Member getPageSizeCompat()524 public int getPageSizeCompat() { 525 return mPageSizeCompat; 526 } 527 528 @DataClass.Generated( 529 time = 1738193799106L, 530 codegenVersion = "1.0.23", 531 sourceFile = "frameworks/base/core/java/android/content/pm/parsing/PackageLite.java", 532 inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.NonNull java.lang.String mBaseApkPath\nprivate final @android.annotation.Nullable java.lang.String[] mSplitApkPaths\nprivate final @android.annotation.Nullable java.lang.String[] mSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mUsesSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mConfigForSplit\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String> mBaseRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String>[] mRequiredSplitTypes\nprivate final @android.annotation.Nullable java.util.Set<java.lang.String>[] mSplitTypes\nprivate final int mVersionCodeMajor\nprivate final int mVersionCode\nprivate final int mTargetSdk\nprivate final int mBaseRevisionCode\nprivate final @android.annotation.Nullable int[] mSplitRevisionCodes\nprivate final int mInstallLocation\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.NonNull android.content.pm.SigningDetails mSigningDetails\nprivate final @android.annotation.Nullable boolean[] mIsFeatureSplits\nprivate final boolean mIsolatedSplits\nprivate final boolean mSplitRequired\nprivate final boolean mCoreApp\nprivate final boolean mDebuggable\nprivate final boolean mMultiArch\nprivate final boolean mUse32bitAbi\nprivate final boolean mExtractNativeLibs\nprivate final boolean mProfileableByShell\nprivate final boolean mUseEmbeddedDex\nprivate final boolean mIsSdkLibrary\nprivate final boolean mIsStaticLibrary\nprivate final @android.annotation.NonNull java.util.List<java.lang.String> mUsesSdkLibraries\nprivate final @android.annotation.Nullable long[] mUsesSdkLibrariesVersionsMajor\nprivate final @android.annotation.Nullable java.lang.String[][] mUsesSdkLibrariesCertDigests\nprivate final @android.annotation.NonNull java.util.List<java.lang.String> mUsesStaticLibraries\nprivate final @android.annotation.Nullable long[] mUsesStaticLibrariesVersions\nprivate final @android.annotation.Nullable java.lang.String[][] mUsesStaticLibrariesCertDigests\nprivate final @android.annotation.NonNull java.util.List<android.content.pm.SharedLibraryInfo> mDeclaredLibraries\nprivate final @android.annotation.Nullable android.content.pm.ArchivedPackageParcel mArchivedPackage\nprivate final int mPageSizeCompat\npublic java.util.List<java.lang.String> getAllApkPaths()\npublic long getLongVersionCode()\nprivate boolean hasAnyRequiredSplitTypes()\nclass PackageLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)") 533 @Deprecated __metadata()534 private void __metadata() {} 535 536 537 //@formatter:on 538 // End of generated code 539 540 } 541