• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 /**
23  * Overall information about the contents of a package.  This corresponds
24  * to all of the information collected from AndroidManifest.xml.
25  */
26 public class PackageInfo implements Parcelable {
27     /**
28      * The name of this package.  From the <manifest> tag's "name"
29      * attribute.
30      */
31     public String packageName;
32 
33     /**
34      * The names of any installed split APKs for this package.
35      */
36     public String[] splitNames;
37 
38     /**
39      * The version number of this package, as specified by the <manifest>
40      * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode}
41      * attribute.
42      */
43     public int versionCode;
44 
45     /**
46      * The version name of this package, as specified by the <manifest>
47      * tag's {@link android.R.styleable#AndroidManifest_versionName versionName}
48      * attribute.
49      */
50     public String versionName;
51 
52     /**
53      * The revision number of the base APK for this package, as specified by the
54      * <manifest> tag's
55      * {@link android.R.styleable#AndroidManifest_revisionCode revisionCode}
56      * attribute.
57      */
58     public int baseRevisionCode;
59 
60     /**
61      * The revision number of any split APKs for this package, as specified by
62      * the <manifest> tag's
63      * {@link android.R.styleable#AndroidManifest_revisionCode revisionCode}
64      * attribute. Indexes are a 1:1 mapping against {@link #splitNames}.
65      */
66     public int[] splitRevisionCodes;
67 
68     /**
69      * The shared user ID name of this package, as specified by the <manifest>
70      * tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId}
71      * attribute.
72      */
73     public String sharedUserId;
74 
75     /**
76      * The shared user ID label of this package, as specified by the <manifest>
77      * tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel}
78      * attribute.
79      */
80     public int sharedUserLabel;
81 
82     /**
83      * Information collected from the <application> tag, or null if
84      * there was none.
85      */
86     public ApplicationInfo applicationInfo;
87 
88     /**
89      * The time at which the app was first installed.  Units are as
90      * per {@link System#currentTimeMillis()}.
91      */
92     public long firstInstallTime;
93 
94     /**
95      * The time at which the app was last updated.  Units are as
96      * per {@link System#currentTimeMillis()}.
97      */
98     public long lastUpdateTime;
99 
100     /**
101      * All kernel group-IDs that have been assigned to this package.
102      * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set.
103      */
104     public int[] gids;
105 
106     /**
107      * Array of all {@link android.R.styleable#AndroidManifestActivity
108      * <activity>} tags included under <application>,
109      * or null if there were none.  This is only filled in if the flag
110      * {@link PackageManager#GET_ACTIVITIES} was set.
111      */
112     public ActivityInfo[] activities;
113 
114     /**
115      * Array of all {@link android.R.styleable#AndroidManifestReceiver
116      * <receiver>} tags included under <application>,
117      * or null if there were none.  This is only filled in if the flag
118      * {@link PackageManager#GET_RECEIVERS} was set.
119      */
120     public ActivityInfo[] receivers;
121 
122     /**
123      * Array of all {@link android.R.styleable#AndroidManifestService
124      * <service>} tags included under <application>,
125      * or null if there were none.  This is only filled in if the flag
126      * {@link PackageManager#GET_SERVICES} was set.
127      */
128     public ServiceInfo[] services;
129 
130     /**
131      * Array of all {@link android.R.styleable#AndroidManifestProvider
132      * <provider>} tags included under <application>,
133      * or null if there were none.  This is only filled in if the flag
134      * {@link PackageManager#GET_PROVIDERS} was set.
135      */
136     public ProviderInfo[] providers;
137 
138     /**
139      * Array of all {@link android.R.styleable#AndroidManifestInstrumentation
140      * <instrumentation>} tags included under <manifest>,
141      * or null if there were none.  This is only filled in if the flag
142      * {@link PackageManager#GET_INSTRUMENTATION} was set.
143      */
144     public InstrumentationInfo[] instrumentation;
145 
146     /**
147      * Array of all {@link android.R.styleable#AndroidManifestPermission
148      * <permission>} tags included under <manifest>,
149      * or null if there were none.  This is only filled in if the flag
150      * {@link PackageManager#GET_PERMISSIONS} was set.
151      */
152     public PermissionInfo[] permissions;
153 
154     /**
155      * Array of all {@link android.R.styleable#AndroidManifestUsesPermission
156      * <uses-permission>} tags included under <manifest>,
157      * or null if there were none.  This is only filled in if the flag
158      * {@link PackageManager#GET_PERMISSIONS} was set.  This list includes
159      * all permissions requested, even those that were not granted or known
160      * by the system at install time.
161      */
162     public String[] requestedPermissions;
163 
164     /**
165      * Array of flags of all {@link android.R.styleable#AndroidManifestUsesPermission
166      * <uses-permission>} tags included under <manifest>,
167      * or null if there were none.  This is only filled in if the flag
168      * {@link PackageManager#GET_PERMISSIONS} was set.  Each value matches
169      * the corresponding entry in {@link #requestedPermissions}, and will have
170      * the flag {@link #REQUESTED_PERMISSION_GRANTED} set as appropriate.
171      */
172     public int[] requestedPermissionsFlags;
173 
174     /**
175      * Flag for {@link #requestedPermissionsFlags}: the requested permission
176      * is required for the application to run; the user can not optionally
177      * disable it.  Currently all permissions are required.
178      *
179      * @removed We do not support required permissions.
180      */
181     public static final int REQUESTED_PERMISSION_REQUIRED = 1<<0;
182 
183     /**
184      * Flag for {@link #requestedPermissionsFlags}: the requested permission
185      * is currently granted to the application.
186      */
187     public static final int REQUESTED_PERMISSION_GRANTED = 1<<1;
188 
189     /**
190      * Array of all signatures read from the package file. This is only filled
191      * in if the flag {@link PackageManager#GET_SIGNATURES} was set. A package
192      * must be singed with at least one certificate which is at position zero.
193      * The package can be signed with additional certificates which appear as
194      * subsequent entries.
195      *
196      * <strong>Note:</strong> Signature ordering is not guaranteed to be
197      * stable which means that a package signed with certificates A and B is
198      * equivalent to being signed with certificates B and A. This means that
199      * in case multiple signatures are reported you cannot assume the one at
200      * the first position to be the same across updates.
201      */
202     public Signature[] signatures;
203 
204     /**
205      * Application specified preferred configuration
206      * {@link android.R.styleable#AndroidManifestUsesConfiguration
207      * &lt;uses-configuration&gt;} tags included under &lt;manifest&gt;,
208      * or null if there were none. This is only filled in if the flag
209      * {@link PackageManager#GET_CONFIGURATIONS} was set.
210      */
211     public ConfigurationInfo[] configPreferences;
212 
213     /**
214      * Features that this application has requested.
215      *
216      * @see FeatureInfo#FLAG_REQUIRED
217      */
218     public FeatureInfo[] reqFeatures;
219 
220     /**
221      * Groups of features that this application has requested.
222      * Each group contains a set of features that are required.
223      * A device must match the features listed in {@link #reqFeatures} and one
224      * or more FeatureGroups in order to have satisfied the feature requirement.
225      *
226      * @see FeatureInfo#FLAG_REQUIRED
227      */
228     public FeatureGroupInfo[] featureGroups;
229 
230     /**
231      * Constant corresponding to <code>auto</code> in
232      * the {@link android.R.attr#installLocation} attribute.
233      * @hide
234      */
235     public static final int INSTALL_LOCATION_UNSPECIFIED = -1;
236 
237     /**
238      * Constant corresponding to <code>auto</code> in the
239      * {@link android.R.attr#installLocation} attribute.
240      */
241     public static final int INSTALL_LOCATION_AUTO = 0;
242 
243     /**
244      * Constant corresponding to <code>internalOnly</code> in the
245      * {@link android.R.attr#installLocation} attribute.
246      */
247     public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1;
248 
249     /**
250      * Constant corresponding to <code>preferExternal</code> in the
251      * {@link android.R.attr#installLocation} attribute.
252      */
253     public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2;
254 
255     /**
256      * The install location requested by the package. From the
257      * {@link android.R.attr#installLocation} attribute, one of
258      * {@link #INSTALL_LOCATION_AUTO}, {@link #INSTALL_LOCATION_INTERNAL_ONLY},
259      * {@link #INSTALL_LOCATION_PREFER_EXTERNAL}
260      */
261     public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY;
262 
263     /** @hide */
264     public boolean isStub;
265 
266     /** @hide */
267     public boolean coreApp;
268 
269     /** @hide */
270     public boolean requiredForAllUsers;
271 
272     /** @hide */
273     public String restrictedAccountType;
274 
275     /** @hide */
276     public String requiredAccountType;
277 
278     /**
279      * What package, if any, this package will overlay.
280      *
281      * Package name of target package, or null.
282      * @hide
283      */
284     public String overlayTarget;
285 
286     /** @hide */
287     public int overlayPriority;
288 
289 
290     /**
291      * Flag for use with {@link #overlayFlags}. Marks the overlay as static, meaning it cannot
292      * be enabled/disabled at runtime.
293      * @hide
294      */
295     public static final int FLAG_OVERLAY_STATIC = 1 << 1;
296 
297     /**
298      * Flag for use with {@link #overlayFlags}. Marks the overlay as trusted (not 3rd party).
299      * @hide
300      */
301     public static final int FLAG_OVERLAY_TRUSTED = 1 << 2;
302 
303     /**
304      * Modifiers that affect the state of this overlay. See {@link #FLAG_OVERLAY_STATIC},
305      * {@link #FLAG_OVERLAY_TRUSTED}.
306      * @hide
307      */
308     public int overlayFlags;
309 
PackageInfo()310     public PackageInfo() {
311     }
312 
313     @Override
toString()314     public String toString() {
315         return "PackageInfo{"
316             + Integer.toHexString(System.identityHashCode(this))
317             + " " + packageName + "}";
318     }
319 
320     @Override
describeContents()321     public int describeContents() {
322         return 0;
323     }
324 
325     @Override
writeToParcel(Parcel dest, int parcelableFlags)326     public void writeToParcel(Parcel dest, int parcelableFlags) {
327         dest.writeString(packageName);
328         dest.writeStringArray(splitNames);
329         dest.writeInt(versionCode);
330         dest.writeString(versionName);
331         dest.writeInt(baseRevisionCode);
332         dest.writeIntArray(splitRevisionCodes);
333         dest.writeString(sharedUserId);
334         dest.writeInt(sharedUserLabel);
335         if (applicationInfo != null) {
336             dest.writeInt(1);
337             applicationInfo.writeToParcel(dest, parcelableFlags);
338         } else {
339             dest.writeInt(0);
340         }
341         dest.writeLong(firstInstallTime);
342         dest.writeLong(lastUpdateTime);
343         dest.writeIntArray(gids);
344         dest.writeTypedArray(activities, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES);
345         dest.writeTypedArray(receivers, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES);
346         dest.writeTypedArray(services, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES);
347         dest.writeTypedArray(providers, parcelableFlags | Parcelable.PARCELABLE_ELIDE_DUPLICATES);
348         dest.writeTypedArray(instrumentation, parcelableFlags);
349         dest.writeTypedArray(permissions, parcelableFlags);
350         dest.writeStringArray(requestedPermissions);
351         dest.writeIntArray(requestedPermissionsFlags);
352         dest.writeTypedArray(signatures, parcelableFlags);
353         dest.writeTypedArray(configPreferences, parcelableFlags);
354         dest.writeTypedArray(reqFeatures, parcelableFlags);
355         dest.writeTypedArray(featureGroups, parcelableFlags);
356         dest.writeInt(installLocation);
357         dest.writeInt(isStub ? 1 : 0);
358         dest.writeInt(coreApp ? 1 : 0);
359         dest.writeInt(requiredForAllUsers ? 1 : 0);
360         dest.writeString(restrictedAccountType);
361         dest.writeString(requiredAccountType);
362         dest.writeString(overlayTarget);
363         dest.writeInt(overlayPriority);
364         dest.writeInt(overlayFlags);
365     }
366 
367     public static final Parcelable.Creator<PackageInfo> CREATOR
368             = new Parcelable.Creator<PackageInfo>() {
369         @Override
370         public PackageInfo createFromParcel(Parcel source) {
371             return new PackageInfo(source);
372         }
373 
374         @Override
375         public PackageInfo[] newArray(int size) {
376             return new PackageInfo[size];
377         }
378     };
379 
PackageInfo(Parcel source)380     private PackageInfo(Parcel source) {
381         packageName = source.readString();
382         splitNames = source.createStringArray();
383         versionCode = source.readInt();
384         versionName = source.readString();
385         baseRevisionCode = source.readInt();
386         splitRevisionCodes = source.createIntArray();
387         sharedUserId = source.readString();
388         sharedUserLabel = source.readInt();
389         int hasApp = source.readInt();
390         if (hasApp != 0) {
391             applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
392         }
393         firstInstallTime = source.readLong();
394         lastUpdateTime = source.readLong();
395         gids = source.createIntArray();
396         activities = source.createTypedArray(ActivityInfo.CREATOR);
397         receivers = source.createTypedArray(ActivityInfo.CREATOR);
398         services = source.createTypedArray(ServiceInfo.CREATOR);
399         providers = source.createTypedArray(ProviderInfo.CREATOR);
400         instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR);
401         permissions = source.createTypedArray(PermissionInfo.CREATOR);
402         requestedPermissions = source.createStringArray();
403         requestedPermissionsFlags = source.createIntArray();
404         signatures = source.createTypedArray(Signature.CREATOR);
405         configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR);
406         reqFeatures = source.createTypedArray(FeatureInfo.CREATOR);
407         featureGroups = source.createTypedArray(FeatureGroupInfo.CREATOR);
408         installLocation = source.readInt();
409         isStub = source.readInt() != 0;
410         coreApp = source.readInt() != 0;
411         requiredForAllUsers = source.readInt() != 0;
412         restrictedAccountType = source.readString();
413         requiredAccountType = source.readString();
414         overlayTarget = source.readString();
415         overlayPriority = source.readInt();
416         overlayFlags = source.readInt();
417 
418         // The component lists were flattened with the redundant ApplicationInfo
419         // instances omitted.  Distribute the canonical one here as appropriate.
420         if (applicationInfo != null) {
421             propagateApplicationInfo(applicationInfo, activities);
422             propagateApplicationInfo(applicationInfo, receivers);
423             propagateApplicationInfo(applicationInfo, services);
424             propagateApplicationInfo(applicationInfo, providers);
425         }
426     }
427 
propagateApplicationInfo(ApplicationInfo appInfo, ComponentInfo[] components)428     private void propagateApplicationInfo(ApplicationInfo appInfo, ComponentInfo[] components) {
429         if (components != null) {
430             for (ComponentInfo ci : components) {
431                 ci.applicationInfo = appInfo;
432             }
433         }
434     }
435 }
436