PackageInfo.java revision 49237345d83e62fdb9eb8d50b13ad086636a04fa
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    public PackageInfo() {
136    }
137
138    public String toString() {
139        return "PackageInfo{"
140            + Integer.toHexString(System.identityHashCode(this))
141            + " " + packageName + "}";
142    }
143
144    public int describeContents() {
145        return 0;
146    }
147
148    public void writeToParcel(Parcel dest, int parcelableFlags) {
149        dest.writeString(packageName);
150        dest.writeInt(versionCode);
151        dest.writeString(versionName);
152        dest.writeString(sharedUserId);
153        dest.writeInt(sharedUserLabel);
154        if (applicationInfo != null) {
155            dest.writeInt(1);
156            applicationInfo.writeToParcel(dest, parcelableFlags);
157        } else {
158            dest.writeInt(0);
159        }
160        dest.writeIntArray(gids);
161        dest.writeTypedArray(activities, parcelableFlags);
162        dest.writeTypedArray(receivers, parcelableFlags);
163        dest.writeTypedArray(services, parcelableFlags);
164        dest.writeTypedArray(providers, parcelableFlags);
165        dest.writeTypedArray(instrumentation, parcelableFlags);
166        dest.writeTypedArray(permissions, parcelableFlags);
167        dest.writeStringArray(requestedPermissions);
168        dest.writeTypedArray(signatures, parcelableFlags);
169        dest.writeTypedArray(configPreferences, parcelableFlags);
170        dest.writeTypedArray(reqFeatures, parcelableFlags);
171    }
172
173    public static final Parcelable.Creator<PackageInfo> CREATOR
174            = new Parcelable.Creator<PackageInfo>() {
175        public PackageInfo createFromParcel(Parcel source) {
176            return new PackageInfo(source);
177        }
178
179        public PackageInfo[] newArray(int size) {
180            return new PackageInfo[size];
181        }
182    };
183
184    private PackageInfo(Parcel source) {
185        packageName = source.readString();
186        versionCode = source.readInt();
187        versionName = source.readString();
188        sharedUserId = source.readString();
189        sharedUserLabel = source.readInt();
190        int hasApp = source.readInt();
191        if (hasApp != 0) {
192            applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
193        }
194        gids = source.createIntArray();
195        activities = source.createTypedArray(ActivityInfo.CREATOR);
196        receivers = source.createTypedArray(ActivityInfo.CREATOR);
197        services = source.createTypedArray(ServiceInfo.CREATOR);
198        providers = source.createTypedArray(ProviderInfo.CREATOR);
199        instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR);
200        permissions = source.createTypedArray(PermissionInfo.CREATOR);
201        requestedPermissions = source.createStringArray();
202        signatures = source.createTypedArray(Signature.CREATOR);
203        configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR);
204        reqFeatures = source.createTypedArray(FeatureInfo.CREATOR);
205    }
206}
207