PackageInfo.java revision 15a4d2ffd04dc6c70f2cd17dae12ac6bc14c69ab
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
17package android.content.pm;
18
19import android.os.Parcel;
20import 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 */
26public 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 version number of this package, as specified by the <manifest>
35     * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode}
36     * attribute.
37     */
38    public int versionCode;
39
40    /**
41     * The version name of this package, as specified by the <manifest>
42     * tag's {@link android.R.styleable#AndroidManifest_versionName versionName}
43     * attribute.
44     */
45    public String versionName;
46
47    /**
48     * The shared user ID name of this package, as specified by the <manifest>
49     * tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId}
50     * attribute.
51     */
52    public String sharedUserId;
53
54    /**
55     * The shared user ID label of this package, as specified by the <manifest>
56     * tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel}
57     * attribute.
58     */
59    public int sharedUserLabel;
60
61    /**
62     * Information collected from the <application> tag, or null if
63     * there was none.
64     */
65    public ApplicationInfo applicationInfo;
66
67    /**
68     * All kernel group-IDs that have been assigned to this package.
69     * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set.
70     */
71    public int[] gids;
72
73    /**
74     * Array of all {@link android.R.styleable#AndroidManifestActivity
75     * <activity>} tags included under <application>,
76     * or null if there were none.  This is only filled in if the flag
77     * {@link PackageManager#GET_ACTIVITIES} was set.
78     */
79    public ActivityInfo[] activities;
80
81    /**
82     * Array of all {@link android.R.styleable#AndroidManifestReceiver
83     * <receiver>} tags included under <application>,
84     * or null if there were none.  This is only filled in if the flag
85     * {@link PackageManager#GET_RECEIVERS} was set.
86     */
87    public ActivityInfo[] receivers;
88
89    /**
90     * Array of all {@link android.R.styleable#AndroidManifestService
91     * <service>} tags included under <application>,
92     * or null if there were none.  This is only filled in if the flag
93     * {@link PackageManager#GET_SERVICES} was set.
94     */
95    public ServiceInfo[] services;
96
97    /**
98     * Array of all {@link android.R.styleable#AndroidManifestProvider
99     * <provider>} tags included under <application>,
100     * or null if there were none.  This is only filled in if the flag
101     * {@link PackageManager#GET_PROVIDERS} was set.
102     */
103    public ProviderInfo[] providers;
104
105    /**
106     * Array of all {@link android.R.styleable#AndroidManifestInstrumentation
107     * <instrumentation>} tags included under <manifest>,
108     * or null if there were none.  This is only filled in if the flag
109     * {@link PackageManager#GET_INSTRUMENTATION} was set.
110     */
111    public InstrumentationInfo[] instrumentation;
112
113    /**
114     * Array of all {@link android.R.styleable#AndroidManifestPermission
115     * <permission>} tags included under <manifest>,
116     * or null if there were none.  This is only filled in if the flag
117     * {@link PackageManager#GET_PERMISSIONS} was set.
118     */
119    public PermissionInfo[] permissions;
120
121    /**
122     * Array of all {@link android.R.styleable#AndroidManifestUsesPermission
123     * <uses-permission>} tags included under <manifest>,
124     * or null if there were none.  This is only filled in if the flag
125     * {@link PackageManager#GET_PERMISSIONS} was set.  This list includes
126     * all permissions requested, even those that were not granted or known
127     * by the system at install time.
128     */
129    public String[] requestedPermissions;
130
131    /**
132     * Array of all signatures read from the package file.  This is only filled
133     * in if the flag {@link PackageManager#GET_SIGNATURES} was set.
134     */
135    public Signature[] signatures;
136
137    /**
138     * Application specified preferred configuration
139     * {@link android.R.styleable#AndroidManifestUsesConfiguration
140     * <uses-configuration>} tags included under <manifest>,
141     * or null if there were none. This is only filled in if the flag
142     * {@link PackageManager#GET_CONFIGURATIONS} was set.
143     */
144    public ConfigurationInfo[] configPreferences;
145
146    /**
147     * The features that this application has said it requires.
148     */
149    public FeatureInfo[] reqFeatures;
150
151    /**
152     * Constant corresponding to <code>auto</code> in
153     * the {@link android.R.attr#installLocation} attribute.
154     * @hide
155     */
156    public static final int INSTALL_LOCATION_AUTO = 0;
157    /**
158     * Constant corresponding to <code>internalOnly</code> in
159     * the {@link android.R.attr#installLocation} attribute.
160     * @hide
161     */
162    public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1;
163    /**
164     * Constant corresponding to <code>preferExternal</code> in
165     * the {@link android.R.attr#installLocation} attribute.
166     * @hide
167     */
168    public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2;
169    /**
170     * The install location requested by the activity.  From the
171     * {@link android.R.attr#installLocation} attribute, one of
172     * {@link #INSTALL_LOCATION_AUTO},
173     * {@link #INSTALL_LOCATION_INTERNAL_ONLY},
174     * {@link #INSTALL_LOCATION_PREFER_EXTERNAL}
175     * @hide
176     */
177    public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY;
178
179    public PackageInfo() {
180    }
181
182    public String toString() {
183        return "PackageInfo{"
184            + Integer.toHexString(System.identityHashCode(this))
185            + " " + packageName + "}";
186    }
187
188    public int describeContents() {
189        return 0;
190    }
191
192    public void writeToParcel(Parcel dest, int parcelableFlags) {
193        dest.writeString(packageName);
194        dest.writeInt(versionCode);
195        dest.writeString(versionName);
196        dest.writeString(sharedUserId);
197        dest.writeInt(sharedUserLabel);
198        if (applicationInfo != null) {
199            dest.writeInt(1);
200            applicationInfo.writeToParcel(dest, parcelableFlags);
201        } else {
202            dest.writeInt(0);
203        }
204        dest.writeIntArray(gids);
205        dest.writeTypedArray(activities, parcelableFlags);
206        dest.writeTypedArray(receivers, parcelableFlags);
207        dest.writeTypedArray(services, parcelableFlags);
208        dest.writeTypedArray(providers, parcelableFlags);
209        dest.writeTypedArray(instrumentation, parcelableFlags);
210        dest.writeTypedArray(permissions, parcelableFlags);
211        dest.writeStringArray(requestedPermissions);
212        dest.writeTypedArray(signatures, parcelableFlags);
213        dest.writeTypedArray(configPreferences, parcelableFlags);
214        dest.writeTypedArray(reqFeatures, parcelableFlags);
215        dest.writeInt(installLocation);
216    }
217
218    public static final Parcelable.Creator<PackageInfo> CREATOR
219            = new Parcelable.Creator<PackageInfo>() {
220        public PackageInfo createFromParcel(Parcel source) {
221            return new PackageInfo(source);
222        }
223
224        public PackageInfo[] newArray(int size) {
225            return new PackageInfo[size];
226        }
227    };
228
229    private PackageInfo(Parcel source) {
230        packageName = source.readString();
231        versionCode = source.readInt();
232        versionName = source.readString();
233        sharedUserId = source.readString();
234        sharedUserLabel = source.readInt();
235        int hasApp = source.readInt();
236        if (hasApp != 0) {
237            applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
238        }
239        gids = source.createIntArray();
240        activities = source.createTypedArray(ActivityInfo.CREATOR);
241        receivers = source.createTypedArray(ActivityInfo.CREATOR);
242        services = source.createTypedArray(ServiceInfo.CREATOR);
243        providers = source.createTypedArray(ProviderInfo.CREATOR);
244        instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR);
245        permissions = source.createTypedArray(PermissionInfo.CREATOR);
246        requestedPermissions = source.createStringArray();
247        signatures = source.createTypedArray(Signature.CREATOR);
248        configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR);
249        reqFeatures = source.createTypedArray(FeatureInfo.CREATOR);
250        installLocation = source.readInt();
251    }
252}
253