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.PackageInfo; 22 import android.content.pm.VerifierInfo; 23 24 import com.android.internal.util.ArrayUtils; 25 import com.android.internal.util.DataClass; 26 27 import java.util.ArrayList; 28 import java.util.Collections; 29 import java.util.List; 30 31 /** 32 * Lightweight parsed details about a single package. 33 * 34 * @hide 35 */ 36 @DataClass(genConstructor = false, genConstDefs = false) 37 public class PackageLite { 38 /** Name of the package as used to identify it in the system */ 39 private final @NonNull String mPackageName; 40 /** 41 * Path where this package was found on disk. For monolithic packages 42 * this is path to single base APK file; for cluster packages this is 43 * path to the cluster directory. 44 */ 45 private final @NonNull String mPath; 46 /** Path of base APK */ 47 private final @NonNull String mBaseApkPath; 48 /** Paths of any split APKs, ordered by parsed splitName */ 49 private final @Nullable String[] mSplitApkPaths; 50 /** Names of any split APKs, ordered by parsed splitName */ 51 private final @Nullable String[] mSplitNames; 52 /** Dependencies of any split APKs, ordered by parsed splitName */ 53 private final @Nullable String[] mUsesSplitNames; 54 private final @Nullable String[] mConfigForSplit; 55 /** Major and minor version number of this package */ 56 private final int mVersionCodeMajor; 57 private final int mVersionCode; 58 private final int mTargetSdk; 59 /** Revision code of base APK */ 60 private final int mBaseRevisionCode; 61 /** Revision codes of any split APKs, ordered by parsed splitName */ 62 private final @Nullable int[] mSplitRevisionCodes; 63 /** 64 * Indicate the install location of this package 65 * 66 * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} 67 * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} 68 * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} 69 */ 70 private final int mInstallLocation; 71 /** Information about a package verifiers as used during package verification */ 72 private final @NonNull VerifierInfo[] mVerifiers; 73 74 /** Indicate whether any split APKs that are features. Ordered by splitName */ 75 private final @Nullable boolean[] mIsFeatureSplits; 76 /** Indicate whether each split should be load into their own Context objects */ 77 private final boolean mIsolatedSplits; 78 /** 79 * Indicate whether this package requires at least one split (either feature or resource) 80 * to be present in order to function 81 */ 82 private final boolean mSplitRequired; 83 /** Indicate whether this app is coreApp */ 84 private final boolean mCoreApp; 85 /** Indicate whether this app can be debugged */ 86 private final boolean mDebuggable; 87 /** Indicate whether this app needs to be loaded into other applications' processes */ 88 private final boolean mMultiArch; 89 /** Indicate whether the 32 bit version of the ABI should be used */ 90 private final boolean mUse32bitAbi; 91 /** Indicate whether installer extracts native libraries */ 92 private final boolean mExtractNativeLibs; 93 /** Indicate whether this app is profileable by Shell */ 94 private final boolean mProfileableByShell; 95 /** 96 * Indicate whether this package wants to run the dex within its APK but not extracted 97 * or locally compiled variants. 98 */ 99 private final boolean mUseEmbeddedDex; 100 PackageLite(String path, String baseApkPath, ApkLite baseApk, String[] splitNames, boolean[] isFeatureSplits, String[] usesSplitNames, String[] configForSplit, String[] splitApkPaths, int[] splitRevisionCodes, int targetSdk)101 public PackageLite(String path, String baseApkPath, ApkLite baseApk, 102 String[] splitNames, boolean[] isFeatureSplits, String[] usesSplitNames, 103 String[] configForSplit, String[] splitApkPaths, int[] splitRevisionCodes, 104 int targetSdk) { 105 // The following paths may be different from the path in ApkLite because we 106 // move or rename the APK files. Use parameters to indicate the correct paths. 107 mPath = path; 108 mBaseApkPath = baseApkPath; 109 mPackageName = baseApk.getPackageName(); 110 mVersionCode = baseApk.getVersionCode(); 111 mVersionCodeMajor = baseApk.getVersionCodeMajor(); 112 mInstallLocation = baseApk.getInstallLocation(); 113 mVerifiers = baseApk.getVerifiers(); 114 mBaseRevisionCode = baseApk.getRevisionCode(); 115 mCoreApp = baseApk.isCoreApp(); 116 mDebuggable = baseApk.isDebuggable(); 117 mMultiArch = baseApk.isMultiArch(); 118 mUse32bitAbi = baseApk.isUse32bitAbi(); 119 mExtractNativeLibs = baseApk.isExtractNativeLibs(); 120 mIsolatedSplits = baseApk.isIsolatedSplits(); 121 mUseEmbeddedDex = baseApk.isUseEmbeddedDex(); 122 mSplitRequired = baseApk.isSplitRequired(); 123 mProfileableByShell = baseApk.isProfileableByShell(); 124 mSplitNames = splitNames; 125 mIsFeatureSplits = isFeatureSplits; 126 mUsesSplitNames = usesSplitNames; 127 mConfigForSplit = configForSplit; 128 mSplitApkPaths = splitApkPaths; 129 mSplitRevisionCodes = splitRevisionCodes; 130 mTargetSdk = targetSdk; 131 } 132 133 /** 134 * Return code path to the base APK file, and split APK files if any. 135 */ getAllApkPaths()136 public List<String> getAllApkPaths() { 137 final ArrayList<String> paths = new ArrayList<>(); 138 paths.add(mBaseApkPath); 139 if (!ArrayUtils.isEmpty(mSplitApkPaths)) { 140 Collections.addAll(paths, mSplitApkPaths); 141 } 142 return paths; 143 } 144 145 /** 146 * Return {@link #mVersionCode} and {@link #mVersionCodeMajor} combined together as a 147 * single long value. The {@link #mVersionCodeMajor} is placed in the upper 32 bits. 148 */ getLongVersionCode()149 public long getLongVersionCode() { 150 return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); 151 } 152 153 154 155 // Code below generated by codegen v1.0.22. 156 // 157 // DO NOT MODIFY! 158 // CHECKSTYLE:OFF Generated code 159 // 160 // To regenerate run: 161 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/PackageLite.java 162 // 163 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 164 // Settings > Editor > Code Style > Formatter Control 165 //@formatter:off 166 167 168 /** 169 * Name of the package as used to identify it in the system 170 */ 171 @DataClass.Generated.Member getPackageName()172 public @NonNull String getPackageName() { 173 return mPackageName; 174 } 175 176 /** 177 * Path where this package was found on disk. For monolithic packages 178 * this is path to single base APK file; for cluster packages this is 179 * path to the cluster directory. 180 */ 181 @DataClass.Generated.Member getPath()182 public @NonNull String getPath() { 183 return mPath; 184 } 185 186 /** 187 * Path of base APK 188 */ 189 @DataClass.Generated.Member getBaseApkPath()190 public @NonNull String getBaseApkPath() { 191 return mBaseApkPath; 192 } 193 194 /** 195 * Paths of any split APKs, ordered by parsed splitName 196 */ 197 @DataClass.Generated.Member getSplitApkPaths()198 public @Nullable String[] getSplitApkPaths() { 199 return mSplitApkPaths; 200 } 201 202 /** 203 * Names of any split APKs, ordered by parsed splitName 204 */ 205 @DataClass.Generated.Member getSplitNames()206 public @Nullable String[] getSplitNames() { 207 return mSplitNames; 208 } 209 210 /** 211 * Dependencies of any split APKs, ordered by parsed splitName 212 */ 213 @DataClass.Generated.Member getUsesSplitNames()214 public @Nullable String[] getUsesSplitNames() { 215 return mUsesSplitNames; 216 } 217 218 @DataClass.Generated.Member getConfigForSplit()219 public @Nullable String[] getConfigForSplit() { 220 return mConfigForSplit; 221 } 222 223 /** 224 * Major and minor version number of this package 225 */ 226 @DataClass.Generated.Member getVersionCodeMajor()227 public int getVersionCodeMajor() { 228 return mVersionCodeMajor; 229 } 230 231 @DataClass.Generated.Member getVersionCode()232 public int getVersionCode() { 233 return mVersionCode; 234 } 235 236 @DataClass.Generated.Member getTargetSdk()237 public int getTargetSdk() { 238 return mTargetSdk; 239 } 240 241 /** 242 * Revision code of base APK 243 */ 244 @DataClass.Generated.Member getBaseRevisionCode()245 public int getBaseRevisionCode() { 246 return mBaseRevisionCode; 247 } 248 249 /** 250 * Revision codes of any split APKs, ordered by parsed splitName 251 */ 252 @DataClass.Generated.Member getSplitRevisionCodes()253 public @Nullable int[] getSplitRevisionCodes() { 254 return mSplitRevisionCodes; 255 } 256 257 /** 258 * Indicate the install location of this package 259 * 260 * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} 261 * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} 262 * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} 263 */ 264 @DataClass.Generated.Member getInstallLocation()265 public int getInstallLocation() { 266 return mInstallLocation; 267 } 268 269 /** 270 * Information about a package verifiers as used during package verification 271 */ 272 @DataClass.Generated.Member getVerifiers()273 public @NonNull VerifierInfo[] getVerifiers() { 274 return mVerifiers; 275 } 276 277 /** 278 * Indicate whether any split APKs that are features. Ordered by splitName 279 */ 280 @DataClass.Generated.Member getIsFeatureSplits()281 public @Nullable boolean[] getIsFeatureSplits() { 282 return mIsFeatureSplits; 283 } 284 285 /** 286 * Indicate whether each split should be load into their own Context objects 287 */ 288 @DataClass.Generated.Member isIsolatedSplits()289 public boolean isIsolatedSplits() { 290 return mIsolatedSplits; 291 } 292 293 /** 294 * Indicate whether this package requires at least one split (either feature or resource) 295 * to be present in order to function 296 */ 297 @DataClass.Generated.Member isSplitRequired()298 public boolean isSplitRequired() { 299 return mSplitRequired; 300 } 301 302 /** 303 * Indicate whether this app is coreApp 304 */ 305 @DataClass.Generated.Member isCoreApp()306 public boolean isCoreApp() { 307 return mCoreApp; 308 } 309 310 /** 311 * Indicate whether this app can be debugged 312 */ 313 @DataClass.Generated.Member isDebuggable()314 public boolean isDebuggable() { 315 return mDebuggable; 316 } 317 318 /** 319 * Indicate whether this app needs to be loaded into other applications' processes 320 */ 321 @DataClass.Generated.Member isMultiArch()322 public boolean isMultiArch() { 323 return mMultiArch; 324 } 325 326 /** 327 * Indicate whether the 32 bit version of the ABI should be used 328 */ 329 @DataClass.Generated.Member isUse32bitAbi()330 public boolean isUse32bitAbi() { 331 return mUse32bitAbi; 332 } 333 334 /** 335 * Indicate whether installer extracts native libraries 336 */ 337 @DataClass.Generated.Member isExtractNativeLibs()338 public boolean isExtractNativeLibs() { 339 return mExtractNativeLibs; 340 } 341 342 /** 343 * Indicate whether this app is profileable by Shell 344 */ 345 @DataClass.Generated.Member isProfileableByShell()346 public boolean isProfileableByShell() { 347 return mProfileableByShell; 348 } 349 350 /** 351 * Indicate whether this package wants to run the dex within its APK but not extracted 352 * or locally compiled variants. 353 */ 354 @DataClass.Generated.Member isUseEmbeddedDex()355 public boolean isUseEmbeddedDex() { 356 return mUseEmbeddedDex; 357 } 358 359 @DataClass.Generated( 360 time = 1615914120261L, 361 codegenVersion = "1.0.22", 362 sourceFile = "frameworks/base/core/java/android/content/pm/parsing/PackageLite.java", 363 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 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.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\npublic java.util.List<java.lang.String> getAllApkPaths()\npublic long getLongVersionCode()\nclass PackageLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)") 364 @Deprecated __metadata()365 private void __metadata() {} 366 367 368 //@formatter:on 369 // End of generated code 370 371 } 372