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