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