1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.content.pm; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Overall information about the contents of a package. This corresponds 24 * to all of the information collected from AndroidManifest.xml. 25 */ 26 public class PackageInfo implements Parcelable { 27 /** 28 * The name of this package. From the <manifest> tag's "name" 29 * attribute. 30 */ 31 public String packageName; 32 33 /** 34 * The version number of this package, as specified by the <manifest> 35 * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode} 36 * attribute. 37 */ 38 public int versionCode; 39 40 /** 41 * The version name of this package, as specified by the <manifest> 42 * tag's {@link android.R.styleable#AndroidManifest_versionName versionName} 43 * attribute. 44 */ 45 public String versionName; 46 47 /** 48 * The shared user ID name of this package, as specified by the <manifest> 49 * tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId} 50 * attribute. 51 */ 52 public String sharedUserId; 53 54 /** 55 * The shared user ID label of this package, as specified by the <manifest> 56 * tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel} 57 * attribute. 58 */ 59 public int sharedUserLabel; 60 61 /** 62 * Information collected from the <application> tag, or null if 63 * there was none. 64 */ 65 public ApplicationInfo applicationInfo; 66 67 /** 68 * The time at which the app was first installed. Units are as 69 * per {@link System#currentTimeMillis()}. 70 */ 71 public long firstInstallTime; 72 73 /** 74 * The time at which the app was last updated. Units are as 75 * per {@link System#currentTimeMillis()}. 76 */ 77 public long lastUpdateTime; 78 79 /** 80 * All kernel group-IDs that have been assigned to this package. 81 * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set. 82 */ 83 public int[] gids; 84 85 /** 86 * Array of all {@link android.R.styleable#AndroidManifestActivity 87 * <activity>} tags included under <application>, 88 * or null if there were none. This is only filled in if the flag 89 * {@link PackageManager#GET_ACTIVITIES} was set. 90 */ 91 public ActivityInfo[] activities; 92 93 /** 94 * Array of all {@link android.R.styleable#AndroidManifestReceiver 95 * <receiver>} tags included under <application>, 96 * or null if there were none. This is only filled in if the flag 97 * {@link PackageManager#GET_RECEIVERS} was set. 98 */ 99 public ActivityInfo[] receivers; 100 101 /** 102 * Array of all {@link android.R.styleable#AndroidManifestService 103 * <service>} tags included under <application>, 104 * or null if there were none. This is only filled in if the flag 105 * {@link PackageManager#GET_SERVICES} was set. 106 */ 107 public ServiceInfo[] services; 108 109 /** 110 * Array of all {@link android.R.styleable#AndroidManifestProvider 111 * <provider>} tags included under <application>, 112 * or null if there were none. This is only filled in if the flag 113 * {@link PackageManager#GET_PROVIDERS} was set. 114 */ 115 public ProviderInfo[] providers; 116 117 /** 118 * Array of all {@link android.R.styleable#AndroidManifestInstrumentation 119 * <instrumentation>} tags included under <manifest>, 120 * or null if there were none. This is only filled in if the flag 121 * {@link PackageManager#GET_INSTRUMENTATION} was set. 122 */ 123 public InstrumentationInfo[] instrumentation; 124 125 /** 126 * Array of all {@link android.R.styleable#AndroidManifestPermission 127 * <permission>} tags included under <manifest>, 128 * or null if there were none. This is only filled in if the flag 129 * {@link PackageManager#GET_PERMISSIONS} was set. 130 */ 131 public PermissionInfo[] permissions; 132 133 /** 134 * Array of all {@link android.R.styleable#AndroidManifestUsesPermission 135 * <uses-permission>} tags included under <manifest>, 136 * or null if there were none. This is only filled in if the flag 137 * {@link PackageManager#GET_PERMISSIONS} was set. This list includes 138 * all permissions requested, even those that were not granted or known 139 * by the system at install time. 140 */ 141 public String[] requestedPermissions; 142 143 /** 144 * Array of all signatures read from the package file. This is only filled 145 * in if the flag {@link PackageManager#GET_SIGNATURES} was set. 146 */ 147 public Signature[] signatures; 148 149 /** 150 * Application specified preferred configuration 151 * {@link android.R.styleable#AndroidManifestUsesConfiguration 152 * <uses-configuration>} tags included under <manifest>, 153 * or null if there were none. This is only filled in if the flag 154 * {@link PackageManager#GET_CONFIGURATIONS} was set. 155 */ 156 public ConfigurationInfo[] configPreferences; 157 158 /** 159 * The features that this application has said it requires. 160 */ 161 public FeatureInfo[] reqFeatures; 162 163 /** 164 * Constant corresponding to <code>auto</code> in 165 * the {@link android.R.attr#installLocation} attribute. 166 * @hide 167 */ 168 public static final int INSTALL_LOCATION_UNSPECIFIED = -1; 169 /** 170 * Constant corresponding to <code>auto</code> in 171 * the {@link android.R.attr#installLocation} attribute. 172 * @hide 173 */ 174 public static final int INSTALL_LOCATION_AUTO = 0; 175 /** 176 * Constant corresponding to <code>internalOnly</code> in 177 * the {@link android.R.attr#installLocation} attribute. 178 * @hide 179 */ 180 public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1; 181 /** 182 * Constant corresponding to <code>preferExternal</code> in 183 * the {@link android.R.attr#installLocation} attribute. 184 * @hide 185 */ 186 public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2; 187 /** 188 * The install location requested by the activity. From the 189 * {@link android.R.attr#installLocation} attribute, one of 190 * {@link #INSTALL_LOCATION_AUTO}, 191 * {@link #INSTALL_LOCATION_INTERNAL_ONLY}, 192 * {@link #INSTALL_LOCATION_PREFER_EXTERNAL} 193 * @hide 194 */ 195 public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY; 196 197 public PackageInfo() { 198 } 199 200 public String toString() { 201 return "PackageInfo{" 202 + Integer.toHexString(System.identityHashCode(this)) 203 + " " + packageName + "}"; 204 } 205 206 public int describeContents() { 207 return 0; 208 } 209 210 public void writeToParcel(Parcel dest, int parcelableFlags) { 211 dest.writeString(packageName); 212 dest.writeInt(versionCode); 213 dest.writeString(versionName); 214 dest.writeString(sharedUserId); 215 dest.writeInt(sharedUserLabel); 216 if (applicationInfo != null) { 217 dest.writeInt(1); 218 applicationInfo.writeToParcel(dest, parcelableFlags); 219 } else { 220 dest.writeInt(0); 221 } 222 dest.writeLong(firstInstallTime); 223 dest.writeLong(lastUpdateTime); 224 dest.writeIntArray(gids); 225 dest.writeTypedArray(activities, parcelableFlags); 226 dest.writeTypedArray(receivers, parcelableFlags); 227 dest.writeTypedArray(services, parcelableFlags); 228 dest.writeTypedArray(providers, parcelableFlags); 229 dest.writeTypedArray(instrumentation, parcelableFlags); 230 dest.writeTypedArray(permissions, parcelableFlags); 231 dest.writeStringArray(requestedPermissions); 232 dest.writeTypedArray(signatures, parcelableFlags); 233 dest.writeTypedArray(configPreferences, parcelableFlags); 234 dest.writeTypedArray(reqFeatures, parcelableFlags); 235 dest.writeInt(installLocation); 236 } 237 238 public static final Parcelable.Creator<PackageInfo> CREATOR 239 = new Parcelable.Creator<PackageInfo>() { 240 public PackageInfo createFromParcel(Parcel source) { 241 return new PackageInfo(source); 242 } 243 244 public PackageInfo[] newArray(int size) { 245 return new PackageInfo[size]; 246 } 247 }; 248 249 private PackageInfo(Parcel source) { 250 packageName = source.readString(); 251 versionCode = source.readInt(); 252 versionName = source.readString(); 253 sharedUserId = source.readString(); 254 sharedUserLabel = source.readInt(); 255 int hasApp = source.readInt(); 256 if (hasApp != 0) { 257 applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); 258 } 259 firstInstallTime = source.readLong(); 260 lastUpdateTime = source.readLong(); 261 gids = source.createIntArray(); 262 activities = source.createTypedArray(ActivityInfo.CREATOR); 263 receivers = source.createTypedArray(ActivityInfo.CREATOR); 264 services = source.createTypedArray(ServiceInfo.CREATOR); 265 providers = source.createTypedArray(ProviderInfo.CREATOR); 266 instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR); 267 permissions = source.createTypedArray(PermissionInfo.CREATOR); 268 requestedPermissions = source.createStringArray(); 269 signatures = source.createTypedArray(Signature.CREATOR); 270 configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR); 271 reqFeatures = source.createTypedArray(FeatureInfo.CREATOR); 272 installLocation = source.readInt(); 273 } 274 } 275