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