PackageInfo.java revision f013e1afd1e68af5e3b868c26a653bbfb39538f8
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 /** 108 * Application specified preferred configuration 109 * {@link android.R.styleable#AndroidManifestUsesConfiguration 110 * <uses-configuration>} tags included under <manifest>, 111 * or null if there were none. This is only filled in if the flag 112 * {@link PackageManager#GET_CONFIGURATIONS} was set. 113 */ 114 public ConfigurationInfo[] configPreferences; 115 116 public PackageInfo() { 117 } 118 119 public String toString() { 120 return "PackageInfo{" 121 + Integer.toHexString(System.identityHashCode(this)) 122 + " " + packageName + "}"; 123 } 124 125 public int describeContents() { 126 return 0; 127 } 128 129 public void writeToParcel(Parcel dest, int parcelableFlags) { 130 dest.writeString(packageName); 131 dest.writeInt(versionCode); 132 dest.writeString(versionName); 133 if (applicationInfo != null) { 134 dest.writeInt(1); 135 applicationInfo.writeToParcel(dest, parcelableFlags); 136 } else { 137 dest.writeInt(0); 138 } 139 dest.writeIntArray(gids); 140 dest.writeTypedArray(activities, parcelableFlags); 141 dest.writeTypedArray(receivers, parcelableFlags); 142 dest.writeTypedArray(services, parcelableFlags); 143 dest.writeTypedArray(providers, parcelableFlags); 144 dest.writeTypedArray(instrumentation, parcelableFlags); 145 dest.writeTypedArray(permissions, parcelableFlags); 146 dest.writeStringArray(requestedPermissions); 147 dest.writeTypedArray(signatures, parcelableFlags); 148 dest.writeTypedArray(configPreferences, parcelableFlags); 149 } 150 151 public static final Parcelable.Creator<PackageInfo> CREATOR 152 = new Parcelable.Creator<PackageInfo>() { 153 public PackageInfo createFromParcel(Parcel source) { 154 return new PackageInfo(source); 155 } 156 157 public PackageInfo[] newArray(int size) { 158 return new PackageInfo[size]; 159 } 160 }; 161 162 private PackageInfo(Parcel source) { 163 packageName = source.readString(); 164 versionCode = source.readInt(); 165 versionName = source.readString(); 166 int hasApp = source.readInt(); 167 if (hasApp != 0) { 168 applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); 169 } 170 gids = source.createIntArray(); 171 activities = source.createTypedArray(ActivityInfo.CREATOR); 172 receivers = source.createTypedArray(ActivityInfo.CREATOR); 173 services = source.createTypedArray(ServiceInfo.CREATOR); 174 providers = source.createTypedArray(ProviderInfo.CREATOR); 175 instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR); 176 permissions = source.createTypedArray(PermissionInfo.CREATOR); 177 requestedPermissions = source.createStringArray(); 178 signatures = source.createTypedArray(Signature.CREATOR); 179 configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR); 180 } 181} 182