PackageInfo.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
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     * Information collected from the <application> tag, or null if
33     * there was none.
34     */
35    public ApplicationInfo applicationInfo;
36
37    /**
38     * All kernel group-IDs that have been assigned to this package.
39     * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set.
40     */
41    public int[] gids;
42
43    /**
44     * Array of all {@link android.R.styleable#AndroidManifestActivity
45     * <activity>} tags included under <application>,
46     * or null if there were none.  This is only filled in if the flag
47     * {@link PackageManager#GET_ACTIVITIES} was set.
48     */
49    public ActivityInfo[] activities;
50
51    /**
52     * Array of all {@link android.R.styleable#AndroidManifestReceiver
53     * <receiver>} tags included under <application>,
54     * or null if there were none.  This is only filled in if the flag
55     * {@link PackageManager#GET_RECEIVERS} was set.
56     */
57    public ActivityInfo[] receivers;
58
59    /**
60     * Array of all {@link android.R.styleable#AndroidManifestService
61     * <service>} tags included under <application>,
62     * or null if there were none.  This is only filled in if the flag
63     * {@link PackageManager#GET_SERVICES} was set.
64     */
65    public ServiceInfo[] services;
66
67    /**
68     * Array of all {@link android.R.styleable#AndroidManifestProvider
69     * <provider>} tags included under <application>,
70     * or null if there were none.  This is only filled in if the flag
71     * {@link PackageManager#GET_PROVIDERS} was set.
72     */
73    public ProviderInfo[] providers;
74
75    /**
76     * Array of all {@link android.R.styleable#AndroidManifestInstrumentation
77     * <instrumentation>} tags included under <manifest>,
78     * or null if there were none.  This is only filled in if the flag
79     * {@link PackageManager#GET_INSTRUMENTATION} was set.
80     */
81    public InstrumentationInfo[] instrumentation;
82
83    /**
84     * Array of all {@link android.R.styleable#AndroidManifestPermission
85     * <permission>} tags included under <manifest>,
86     * or null if there were none.  This is only filled in if the flag
87     * {@link PackageManager#GET_PERMISSIONS} was set.
88     */
89    public PermissionInfo[] permissions;
90
91    /**
92     * Array of all {@link android.R.styleable#AndroidManifestUsesPermission
93     * <uses-permission>} tags included under <manifest>,
94     * or null if there were none.  This is only filled in if the flag
95     * {@link PackageManager#GET_PERMISSIONS} was set.  This list includes
96     * all permissions requested, even those that were not granted or known
97     * by the system at install time.
98     */
99    public String[] requestedPermissions;
100
101    /**
102     * Array of all signatures read from the package file.  This is only filled
103     * in if the flag {@link PackageManager#GET_SIGNATURES} was set.
104     */
105    public Signature[] signatures;
106
107    public PackageInfo() {
108    }
109
110    public String toString() {
111        return "PackageInfo{"
112            + Integer.toHexString(System.identityHashCode(this))
113            + " " + packageName + "}";
114    }
115
116    public int describeContents() {
117        return 0;
118    }
119
120    public void writeToParcel(Parcel dest, int parcelableFlags) {
121        dest.writeString(packageName);
122        dest.writeInt(versionCode);
123        dest.writeString(versionName);
124        if (applicationInfo != null) {
125            dest.writeInt(1);
126            applicationInfo.writeToParcel(dest, parcelableFlags);
127        } else {
128            dest.writeInt(0);
129        }
130        dest.writeIntArray(gids);
131        dest.writeTypedArray(activities, parcelableFlags);
132        dest.writeTypedArray(receivers, parcelableFlags);
133        dest.writeTypedArray(services, parcelableFlags);
134        dest.writeTypedArray(providers, parcelableFlags);
135        dest.writeTypedArray(instrumentation, parcelableFlags);
136        dest.writeTypedArray(permissions, parcelableFlags);
137        dest.writeStringArray(requestedPermissions);
138        dest.writeTypedArray(signatures, parcelableFlags);
139    }
140
141    public static final Parcelable.Creator<PackageInfo> CREATOR
142            = new Parcelable.Creator<PackageInfo>() {
143        public PackageInfo createFromParcel(Parcel source) {
144            return new PackageInfo(source);
145        }
146
147        public PackageInfo[] newArray(int size) {
148            return new PackageInfo[size];
149        }
150    };
151
152    private PackageInfo(Parcel source) {
153        packageName = source.readString();
154        versionCode = source.readInt();
155        versionName = source.readString();
156        int hasApp = source.readInt();
157        if (hasApp != 0) {
158            applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);
159        }
160        gids = source.createIntArray();
161        activities = source.createTypedArray(ActivityInfo.CREATOR);
162        receivers = source.createTypedArray(ActivityInfo.CREATOR);
163        services = source.createTypedArray(ServiceInfo.CREATOR);
164        providers = source.createTypedArray(ProviderInfo.CREATOR);
165        instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR);
166        permissions = source.createTypedArray(PermissionInfo.CREATOR);
167        requestedPermissions = source.createStringArray();
168        signatures = source.createTypedArray(Signature.CREATOR);
169    }
170}
171