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