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.PackageManager;
23 import android.content.pm.SigningDetails;
24 import android.content.pm.VerifierInfo;
25 
26 import com.android.internal.util.CollectionUtils;
27 import com.android.internal.util.DataClass;
28 
29 import java.util.List;
30 import java.util.Set;
31 
32 /**
33  * Lightweight parsed details about a single APK file.
34  *
35  * @hide
36  */
37 @DataClass(genConstructor = false, genConstDefs = false)
38 public class ApkLite {
39     /** Name of the package as used to identify it in the system */
40     private final @NonNull String mPackageName;
41     /** Path where this APK file was found on disk */
42     private final @NonNull String mPath;
43     /** Split name of this APK */
44     private final @Nullable String mSplitName;
45     /** Dependencies of the split APK */
46     /** Name of the split APK that this APK depends on */
47     private final @Nullable String mUsesSplitName;
48     /** Name of the split APK that this APK is a configuration for */
49     private final @Nullable String mConfigForSplit;
50     /** Indicate the types of the required split are necessary for this package to run */
51     private final @Nullable Set<String> mRequiredSplitTypes;
52     /** Split types of this APK */
53     private final @Nullable Set<String> mSplitTypes;
54 
55     /** Major version number of this package */
56     private final int mVersionCodeMajor;
57     /** Minor version number of this package */
58     private final int mVersionCode;
59     /** Revision code of this APK */
60     private final int mRevisionCode;
61     /**
62      * Indicate the install location of this package
63      *
64      * @see {@link PackageInfo#INSTALL_LOCATION_AUTO}
65      * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY}
66      * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL}
67      */
68     private final int mInstallLocation;
69     /** Indicate the minimum SDK version number that the app requires */
70     private final int mMinSdkVersion;
71     /** Indicate the SDK version number that the application is targeting */
72     private final int mTargetSdkVersion;
73     /** Information about a package verifiers as used during package verification */
74     private final @NonNull VerifierInfo[] mVerifiers;
75     /** Signing-related data of an application package */
76     private final @NonNull SigningDetails mSigningDetails;
77 
78     /** Indicate whether this APK is a 'feature' split */
79     private final boolean mFeatureSplit;
80     /** Indicate whether each split should be load into their own Context objects */
81     private final boolean mIsolatedSplits;
82     /**
83      * Indicate whether this package requires at least one split (either feature or resource)
84      * to be present in order to function
85      */
86     private final boolean mSplitRequired;
87     /** Indicate whether this app is coreApp */
88     private final boolean mCoreApp;
89     /** Indicate whether this app can be debugged */
90     private final boolean mDebuggable;
91     /** Indicate whether this app is profileable by Shell */
92     private final boolean mProfileableByShell;
93     /** Indicate whether this app needs to be loaded into other applications' processes */
94     private final boolean mMultiArch;
95     /** Indicate whether the 32 bit version of the ABI should be used */
96     private final boolean mUse32bitAbi;
97     /** Indicate whether installer extracts native libraries */
98     private final boolean mExtractNativeLibs;
99     /**
100      * Indicate whether this package wants to run the dex within its APK but not extracted
101      * or locally compiled variants.
102      */
103     private final boolean mUseEmbeddedDex;
104 
105     /** Name of the overlay-able set of elements package */
106     private final @Nullable String mTargetPackageName;
107     /** Indicate whether the overlay is static */
108     private final boolean mOverlayIsStatic;
109     /** Indicate the priority of this overlay package */
110     private final int mOverlayPriority;
111     /**
112      * A comma separated list of system property names to control whether the overlay should be
113      * excluded based on the system property condition.
114      */
115     private final @Nullable String mRequiredSystemPropertyName;
116     /**
117      * A comma separated list of system property values to control whether the overlay should be
118      * excluded based on the system property condition.
119      */
120     private final @Nullable String mRequiredSystemPropertyValue;
121 
122     /**
123      * Indicate the policy to deal with user data when rollback is committed
124      *
125      * @see {@link PackageManager#ROLLBACK_DATA_POLICY_RESTORE}
126      * @see {@link PackageManager#ROLLBACK_DATA_POLICY_WIPE}
127      * @see {@link PackageManager#ROLLBACK_DATA_POLICY_RETAIN}
128      */
129     private final int mRollbackDataPolicy;
130 
131     /**
132      * Indicates if this app contains a {@link android.app.admin.DeviceAdminReceiver}.
133      */
134     private final boolean mHasDeviceAdminReceiver;
135 
136     /**
137      * Indicates if this apk is a sdk.
138      */
139     private final boolean mIsSdkLibrary;
140 
ApkLite(String path, String packageName, String splitName, boolean isFeatureSplit, String configForSplit, String usesSplitName, boolean isSplitRequired, int versionCode, int versionCodeMajor, int revisionCode, int installLocation, List<VerifierInfo> verifiers, SigningDetails signingDetails, boolean coreApp, boolean debuggable, boolean profileableByShell, boolean multiArch, boolean use32bitAbi, boolean useEmbeddedDex, boolean extractNativeLibs, boolean isolatedSplits, String targetPackageName, boolean overlayIsStatic, int overlayPriority, String requiredSystemPropertyName, String requiredSystemPropertyValue, int minSdkVersion, int targetSdkVersion, int rollbackDataPolicy, Set<String> requiredSplitTypes, Set<String> splitTypes, boolean hasDeviceAdminReceiver, boolean isSdkLibrary)141     public ApkLite(String path, String packageName, String splitName, boolean isFeatureSplit,
142             String configForSplit, String usesSplitName, boolean isSplitRequired, int versionCode,
143             int versionCodeMajor, int revisionCode, int installLocation,
144             List<VerifierInfo> verifiers, SigningDetails signingDetails, boolean coreApp,
145             boolean debuggable, boolean profileableByShell, boolean multiArch, boolean use32bitAbi,
146             boolean useEmbeddedDex, boolean extractNativeLibs, boolean isolatedSplits,
147             String targetPackageName, boolean overlayIsStatic, int overlayPriority,
148             String requiredSystemPropertyName, String requiredSystemPropertyValue,
149             int minSdkVersion, int targetSdkVersion, int rollbackDataPolicy,
150             Set<String> requiredSplitTypes, Set<String> splitTypes,
151             boolean hasDeviceAdminReceiver, boolean isSdkLibrary) {
152         mPath = path;
153         mPackageName = packageName;
154         mSplitName = splitName;
155         mSplitTypes = splitTypes;
156         mFeatureSplit = isFeatureSplit;
157         mConfigForSplit = configForSplit;
158         mUsesSplitName = usesSplitName;
159         mRequiredSplitTypes = requiredSplitTypes;
160         mSplitRequired = (isSplitRequired || hasAnyRequiredSplitTypes());
161         mVersionCode = versionCode;
162         mVersionCodeMajor = versionCodeMajor;
163         mRevisionCode = revisionCode;
164         mInstallLocation = installLocation;
165         mVerifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]);
166         mSigningDetails = signingDetails;
167         mCoreApp = coreApp;
168         mDebuggable = debuggable;
169         mProfileableByShell = profileableByShell;
170         mMultiArch = multiArch;
171         mUse32bitAbi = use32bitAbi;
172         mUseEmbeddedDex = useEmbeddedDex;
173         mExtractNativeLibs = extractNativeLibs;
174         mIsolatedSplits = isolatedSplits;
175         mTargetPackageName = targetPackageName;
176         mOverlayIsStatic = overlayIsStatic;
177         mOverlayPriority = overlayPriority;
178         mRequiredSystemPropertyName = requiredSystemPropertyName;
179         mRequiredSystemPropertyValue = requiredSystemPropertyValue;
180         mMinSdkVersion = minSdkVersion;
181         mTargetSdkVersion = targetSdkVersion;
182         mRollbackDataPolicy = rollbackDataPolicy;
183         mHasDeviceAdminReceiver = hasDeviceAdminReceiver;
184         mIsSdkLibrary = isSdkLibrary;
185     }
186 
187     /**
188      * Return {@link #mVersionCode} and {@link #mVersionCodeMajor} combined together as a
189      * single long value. The {@link #mVersionCodeMajor} is placed in the upper 32 bits.
190      */
getLongVersionCode()191     public long getLongVersionCode() {
192         return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode);
193     }
194 
195     /**
196      * Return if requiredSplitTypes presents.
197      */
hasAnyRequiredSplitTypes()198     private boolean hasAnyRequiredSplitTypes() {
199         return !CollectionUtils.isEmpty(mRequiredSplitTypes);
200     }
201 
202 
203 
204     // Code below generated by codegen v1.0.23.
205     //
206     // DO NOT MODIFY!
207     // CHECKSTYLE:OFF Generated code
208     //
209     // To regenerate run:
210     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/ApkLite.java
211     //
212     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
213     //   Settings > Editor > Code Style > Formatter Control
214     //@formatter:off
215 
216 
217     /**
218      * Name of the package as used to identify it in the system
219      */
220     @DataClass.Generated.Member
getPackageName()221     public @NonNull String getPackageName() {
222         return mPackageName;
223     }
224 
225     /**
226      * Path where this APK file was found on disk
227      */
228     @DataClass.Generated.Member
getPath()229     public @NonNull String getPath() {
230         return mPath;
231     }
232 
233     /**
234      * Split name of this APK
235      */
236     @DataClass.Generated.Member
getSplitName()237     public @Nullable String getSplitName() {
238         return mSplitName;
239     }
240 
241     /**
242      * Name of the split APK that this APK depends on
243      */
244     @DataClass.Generated.Member
getUsesSplitName()245     public @Nullable String getUsesSplitName() {
246         return mUsesSplitName;
247     }
248 
249     /**
250      * Name of the split APK that this APK is a configuration for
251      */
252     @DataClass.Generated.Member
getConfigForSplit()253     public @Nullable String getConfigForSplit() {
254         return mConfigForSplit;
255     }
256 
257     /**
258      * Indicate the types of the required split are necessary for this package to run
259      */
260     @DataClass.Generated.Member
getRequiredSplitTypes()261     public @Nullable Set<String> getRequiredSplitTypes() {
262         return mRequiredSplitTypes;
263     }
264 
265     /**
266      * Split types of this APK
267      */
268     @DataClass.Generated.Member
getSplitTypes()269     public @Nullable Set<String> getSplitTypes() {
270         return mSplitTypes;
271     }
272 
273     /**
274      * Major version number of this package
275      */
276     @DataClass.Generated.Member
getVersionCodeMajor()277     public int getVersionCodeMajor() {
278         return mVersionCodeMajor;
279     }
280 
281     /**
282      * Minor version number of this package
283      */
284     @DataClass.Generated.Member
getVersionCode()285     public int getVersionCode() {
286         return mVersionCode;
287     }
288 
289     /**
290      * Revision code of this APK
291      */
292     @DataClass.Generated.Member
getRevisionCode()293     public int getRevisionCode() {
294         return mRevisionCode;
295     }
296 
297     /**
298      * Indicate the install location of this package
299      *
300      * @see {@link PackageInfo#INSTALL_LOCATION_AUTO}
301      * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY}
302      * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL}
303      */
304     @DataClass.Generated.Member
getInstallLocation()305     public int getInstallLocation() {
306         return mInstallLocation;
307     }
308 
309     /**
310      * Indicate the minimum SDK version number that the app requires
311      */
312     @DataClass.Generated.Member
getMinSdkVersion()313     public int getMinSdkVersion() {
314         return mMinSdkVersion;
315     }
316 
317     /**
318      * Indicate the SDK version number that the application is targeting
319      */
320     @DataClass.Generated.Member
getTargetSdkVersion()321     public int getTargetSdkVersion() {
322         return mTargetSdkVersion;
323     }
324 
325     /**
326      * Information about a package verifiers as used during package verification
327      */
328     @DataClass.Generated.Member
getVerifiers()329     public @NonNull VerifierInfo[] getVerifiers() {
330         return mVerifiers;
331     }
332 
333     /**
334      * Signing-related data of an application package
335      */
336     @DataClass.Generated.Member
getSigningDetails()337     public @NonNull SigningDetails getSigningDetails() {
338         return mSigningDetails;
339     }
340 
341     /**
342      * Indicate whether this APK is a 'feature' split
343      */
344     @DataClass.Generated.Member
isFeatureSplit()345     public boolean isFeatureSplit() {
346         return mFeatureSplit;
347     }
348 
349     /**
350      * Indicate whether each split should be load into their own Context objects
351      */
352     @DataClass.Generated.Member
isIsolatedSplits()353     public boolean isIsolatedSplits() {
354         return mIsolatedSplits;
355     }
356 
357     /**
358      * Indicate whether this package requires at least one split (either feature or resource)
359      * to be present in order to function
360      */
361     @DataClass.Generated.Member
isSplitRequired()362     public boolean isSplitRequired() {
363         return mSplitRequired;
364     }
365 
366     /**
367      * Indicate whether this app is coreApp
368      */
369     @DataClass.Generated.Member
isCoreApp()370     public boolean isCoreApp() {
371         return mCoreApp;
372     }
373 
374     /**
375      * Indicate whether this app can be debugged
376      */
377     @DataClass.Generated.Member
isDebuggable()378     public boolean isDebuggable() {
379         return mDebuggable;
380     }
381 
382     /**
383      * Indicate whether this app is profileable by Shell
384      */
385     @DataClass.Generated.Member
isProfileableByShell()386     public boolean isProfileableByShell() {
387         return mProfileableByShell;
388     }
389 
390     /**
391      * Indicate whether this app needs to be loaded into other applications' processes
392      */
393     @DataClass.Generated.Member
isMultiArch()394     public boolean isMultiArch() {
395         return mMultiArch;
396     }
397 
398     /**
399      * Indicate whether the 32 bit version of the ABI should be used
400      */
401     @DataClass.Generated.Member
isUse32bitAbi()402     public boolean isUse32bitAbi() {
403         return mUse32bitAbi;
404     }
405 
406     /**
407      * Indicate whether installer extracts native libraries
408      */
409     @DataClass.Generated.Member
isExtractNativeLibs()410     public boolean isExtractNativeLibs() {
411         return mExtractNativeLibs;
412     }
413 
414     /**
415      * Indicate whether this package wants to run the dex within its APK but not extracted
416      * or locally compiled variants.
417      */
418     @DataClass.Generated.Member
isUseEmbeddedDex()419     public boolean isUseEmbeddedDex() {
420         return mUseEmbeddedDex;
421     }
422 
423     /**
424      * Name of the overlay-able set of elements package
425      */
426     @DataClass.Generated.Member
getTargetPackageName()427     public @Nullable String getTargetPackageName() {
428         return mTargetPackageName;
429     }
430 
431     /**
432      * Indicate whether the overlay is static
433      */
434     @DataClass.Generated.Member
isOverlayIsStatic()435     public boolean isOverlayIsStatic() {
436         return mOverlayIsStatic;
437     }
438 
439     /**
440      * Indicate the priority of this overlay package
441      */
442     @DataClass.Generated.Member
getOverlayPriority()443     public int getOverlayPriority() {
444         return mOverlayPriority;
445     }
446 
447     /**
448      * A comma separated list of system property names to control whether the overlay should be
449      * excluded based on the system property condition.
450      */
451     @DataClass.Generated.Member
getRequiredSystemPropertyName()452     public @Nullable String getRequiredSystemPropertyName() {
453         return mRequiredSystemPropertyName;
454     }
455 
456     /**
457      * A comma separated list of system property values to control whether the overlay should be
458      * excluded based on the system property condition.
459      */
460     @DataClass.Generated.Member
getRequiredSystemPropertyValue()461     public @Nullable String getRequiredSystemPropertyValue() {
462         return mRequiredSystemPropertyValue;
463     }
464 
465     /**
466      * Indicate the policy to deal with user data when rollback is committed
467      *
468      * @see {@link PackageManager#ROLLBACK_DATA_POLICY_RESTORE}
469      * @see {@link PackageManager#ROLLBACK_DATA_POLICY_WIPE}
470      * @see {@link PackageManager#ROLLBACK_DATA_POLICY_RETAIN}
471      */
472     @DataClass.Generated.Member
getRollbackDataPolicy()473     public int getRollbackDataPolicy() {
474         return mRollbackDataPolicy;
475     }
476 
477     @DataClass.Generated.Member
isHasDeviceAdminReceiver()478     public boolean isHasDeviceAdminReceiver() {
479         return mHasDeviceAdminReceiver;
480     }
481 
482     /**
483      * Indicates if this apk is a sdk.
484      */
485     @DataClass.Generated.Member
isIsSdkLibrary()486     public boolean isIsSdkLibrary() {
487         return mIsSdkLibrary;
488     }
489 
490     @DataClass.Generated(
491             time = 1643063342990L,
492             codegenVersion = "1.0.23",
493             sourceFile = "frameworks/base/core/java/android/content/pm/parsing/ApkLite.java",
494             inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.Nullable java.lang.String mSplitName\nprivate final @android.annotation.Nullable java.lang.String mUsesSplitName\nprivate final @android.annotation.Nullable java.lang.String mConfigForSplit\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 mRevisionCode\nprivate final  int mInstallLocation\nprivate final  int mMinSdkVersion\nprivate final  int mTargetSdkVersion\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.NonNull android.content.pm.SigningDetails mSigningDetails\nprivate final  boolean mFeatureSplit\nprivate final  boolean mIsolatedSplits\nprivate final  boolean mSplitRequired\nprivate final  boolean mCoreApp\nprivate final  boolean mDebuggable\nprivate final  boolean mProfileableByShell\nprivate final  boolean mMultiArch\nprivate final  boolean mUse32bitAbi\nprivate final  boolean mExtractNativeLibs\nprivate final  boolean mUseEmbeddedDex\nprivate final @android.annotation.Nullable java.lang.String mTargetPackageName\nprivate final  boolean mOverlayIsStatic\nprivate final  int mOverlayPriority\nprivate final @android.annotation.Nullable java.lang.String mRequiredSystemPropertyName\nprivate final @android.annotation.Nullable java.lang.String mRequiredSystemPropertyValue\nprivate final  int mRollbackDataPolicy\nprivate final  boolean mHasDeviceAdminReceiver\nprivate final  boolean mIsSdkLibrary\npublic  long getLongVersionCode()\nprivate  boolean hasAnyRequiredSplitTypes()\nclass ApkLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)")
495     @Deprecated
__metadata()496     private void __metadata() {}
497 
498 
499     //@formatter:on
500     // End of generated code
501 
502 }
503