PackageInfo.java revision dbfbb17512fe6a5b3c7198d60b6a149969174a71
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 17package android.content.pm; 18 19import android.os.Parcel; 20import 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 */ 26public 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 names of any installed split APKs for this package. 35 */ 36 public String[] splitNames; 37 38 /** 39 * The version number of this package, as specified by the <manifest> 40 * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode} 41 * attribute. 42 */ 43 public int versionCode; 44 45 /** 46 * The version name of this package, as specified by the <manifest> 47 * tag's {@link android.R.styleable#AndroidManifest_versionName versionName} 48 * attribute. 49 */ 50 public String versionName; 51 52 /** 53 * The shared user ID name of this package, as specified by the <manifest> 54 * tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId} 55 * attribute. 56 */ 57 public String sharedUserId; 58 59 /** 60 * The shared user ID label of this package, as specified by the <manifest> 61 * tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel} 62 * attribute. 63 */ 64 public int sharedUserLabel; 65 66 /** 67 * Information collected from the <application> tag, or null if 68 * there was none. 69 */ 70 public ApplicationInfo applicationInfo; 71 72 /** 73 * The time at which the app was first installed. Units are as 74 * per {@link System#currentTimeMillis()}. 75 */ 76 public long firstInstallTime; 77 78 /** 79 * The time at which the app was last updated. Units are as 80 * per {@link System#currentTimeMillis()}. 81 */ 82 public long lastUpdateTime; 83 84 /** 85 * All kernel group-IDs that have been assigned to this package. 86 * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set. 87 */ 88 public int[] gids; 89 90 /** 91 * Array of all {@link android.R.styleable#AndroidManifestActivity 92 * <activity>} tags included under <application>, 93 * or null if there were none. This is only filled in if the flag 94 * {@link PackageManager#GET_ACTIVITIES} was set. 95 */ 96 public ActivityInfo[] activities; 97 98 /** 99 * Array of all {@link android.R.styleable#AndroidManifestReceiver 100 * <receiver>} tags included under <application>, 101 * or null if there were none. This is only filled in if the flag 102 * {@link PackageManager#GET_RECEIVERS} was set. 103 */ 104 public ActivityInfo[] receivers; 105 106 /** 107 * Array of all {@link android.R.styleable#AndroidManifestService 108 * <service>} tags included under <application>, 109 * or null if there were none. This is only filled in if the flag 110 * {@link PackageManager#GET_SERVICES} was set. 111 */ 112 public ServiceInfo[] services; 113 114 /** 115 * Array of all {@link android.R.styleable#AndroidManifestProvider 116 * <provider>} tags included under <application>, 117 * or null if there were none. This is only filled in if the flag 118 * {@link PackageManager#GET_PROVIDERS} was set. 119 */ 120 public ProviderInfo[] providers; 121 122 /** 123 * Array of all {@link android.R.styleable#AndroidManifestInstrumentation 124 * <instrumentation>} tags included under <manifest>, 125 * or null if there were none. This is only filled in if the flag 126 * {@link PackageManager#GET_INSTRUMENTATION} was set. 127 */ 128 public InstrumentationInfo[] instrumentation; 129 130 /** 131 * Array of all {@link android.R.styleable#AndroidManifestPermission 132 * <permission>} tags included under <manifest>, 133 * or null if there were none. This is only filled in if the flag 134 * {@link PackageManager#GET_PERMISSIONS} was set. 135 */ 136 public PermissionInfo[] permissions; 137 138 /** 139 * Array of all {@link android.R.styleable#AndroidManifestUsesPermission 140 * <uses-permission>} tags included under <manifest>, 141 * or null if there were none. This is only filled in if the flag 142 * {@link PackageManager#GET_PERMISSIONS} was set. This list includes 143 * all permissions requested, even those that were not granted or known 144 * by the system at install time. 145 */ 146 public String[] requestedPermissions; 147 148 /** 149 * Array of flags of all {@link android.R.styleable#AndroidManifestUsesPermission 150 * <uses-permission>} tags included under <manifest>, 151 * or null if there were none. This is only filled in if the flag 152 * {@link PackageManager#GET_PERMISSIONS} was set. Each value matches 153 * the corresponding entry in {@link #requestedPermissions}, and will have 154 * the flags {@link #REQUESTED_PERMISSION_REQUIRED} and 155 * {@link #REQUESTED_PERMISSION_GRANTED} set as appropriate. 156 */ 157 public int[] requestedPermissionsFlags; 158 159 /** 160 * Flag for {@link #requestedPermissionsFlags}: the requested permission 161 * is required for the application to run; the user can not optionally 162 * disable it. Currently all permissions are required. 163 */ 164 public static final int REQUESTED_PERMISSION_REQUIRED = 1<<0; 165 166 /** 167 * Flag for {@link #requestedPermissionsFlags}: the requested permission 168 * is currently granted to the application. 169 */ 170 public static final int REQUESTED_PERMISSION_GRANTED = 1<<1; 171 172 /** 173 * Array of all signatures read from the package file. This is only filled 174 * in if the flag {@link PackageManager#GET_SIGNATURES} was set. 175 */ 176 public Signature[] signatures; 177 178 /** 179 * Application specified preferred configuration 180 * {@link android.R.styleable#AndroidManifestUsesConfiguration 181 * <uses-configuration>} tags included under <manifest>, 182 * or null if there were none. This is only filled in if the flag 183 * {@link PackageManager#GET_CONFIGURATIONS} was set. 184 */ 185 public ConfigurationInfo[] configPreferences; 186 187 /** 188 * Features that this application has requested. 189 * 190 * @see FeatureInfo#FLAG_REQUIRED 191 */ 192 public FeatureInfo[] reqFeatures; 193 194 /** 195 * Groups of features that this application has requested. 196 * Each group contains a set of features that are required. 197 * A device must match the features listed in {@link #reqFeatures} and one 198 * or more FeatureGroups in order to have satisfied the feature requirement. 199 * 200 * @see FeatureInfo#FLAG_REQUIRED 201 */ 202 public FeatureGroupInfo[] featureGroups; 203 204 /** 205 * Constant corresponding to <code>auto</code> in 206 * the {@link android.R.attr#installLocation} attribute. 207 * @hide 208 */ 209 public static final int INSTALL_LOCATION_UNSPECIFIED = -1; 210 211 /** 212 * Constant corresponding to <code>auto</code> in the 213 * {@link android.R.attr#installLocation} attribute. 214 */ 215 public static final int INSTALL_LOCATION_AUTO = 0; 216 217 /** 218 * Constant corresponding to <code>internalOnly</code> in the 219 * {@link android.R.attr#installLocation} attribute. 220 */ 221 public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1; 222 223 /** 224 * Constant corresponding to <code>preferExternal</code> in the 225 * {@link android.R.attr#installLocation} attribute. 226 */ 227 public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2; 228 229 /** 230 * The install location requested by the package. From the 231 * {@link android.R.attr#installLocation} attribute, one of 232 * {@link #INSTALL_LOCATION_AUTO}, {@link #INSTALL_LOCATION_INTERNAL_ONLY}, 233 * {@link #INSTALL_LOCATION_PREFER_EXTERNAL} 234 */ 235 public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY; 236 237 /** @hide */ 238 public boolean coreApp; 239 240 /** @hide */ 241 public boolean requiredForAllUsers; 242 243 /** @hide */ 244 public String restrictedAccountType; 245 246 /** @hide */ 247 public String requiredAccountType; 248 249 /** 250 * What package, if any, this package will overlay. 251 * 252 * Package name of target package, or null. 253 * @hide 254 */ 255 public String overlayTarget; 256 257 public PackageInfo() { 258 } 259 260 public String toString() { 261 return "PackageInfo{" 262 + Integer.toHexString(System.identityHashCode(this)) 263 + " " + packageName + "}"; 264 } 265 266 public int describeContents() { 267 return 0; 268 } 269 270 public void writeToParcel(Parcel dest, int parcelableFlags) { 271 dest.writeString(packageName); 272 dest.writeStringArray(splitNames); 273 dest.writeInt(versionCode); 274 dest.writeString(versionName); 275 dest.writeString(sharedUserId); 276 dest.writeInt(sharedUserLabel); 277 if (applicationInfo != null) { 278 dest.writeInt(1); 279 applicationInfo.writeToParcel(dest, parcelableFlags); 280 } else { 281 dest.writeInt(0); 282 } 283 dest.writeLong(firstInstallTime); 284 dest.writeLong(lastUpdateTime); 285 dest.writeIntArray(gids); 286 dest.writeTypedArray(activities, parcelableFlags); 287 dest.writeTypedArray(receivers, parcelableFlags); 288 dest.writeTypedArray(services, parcelableFlags); 289 dest.writeTypedArray(providers, parcelableFlags); 290 dest.writeTypedArray(instrumentation, parcelableFlags); 291 dest.writeTypedArray(permissions, parcelableFlags); 292 dest.writeStringArray(requestedPermissions); 293 dest.writeIntArray(requestedPermissionsFlags); 294 dest.writeTypedArray(signatures, parcelableFlags); 295 dest.writeTypedArray(configPreferences, parcelableFlags); 296 dest.writeTypedArray(reqFeatures, parcelableFlags); 297 dest.writeTypedArray(featureGroups, parcelableFlags); 298 dest.writeInt(installLocation); 299 dest.writeInt(coreApp ? 1 : 0); 300 dest.writeInt(requiredForAllUsers ? 1 : 0); 301 dest.writeString(restrictedAccountType); 302 dest.writeString(requiredAccountType); 303 dest.writeString(overlayTarget); 304 } 305 306 public static final Parcelable.Creator<PackageInfo> CREATOR 307 = new Parcelable.Creator<PackageInfo>() { 308 public PackageInfo createFromParcel(Parcel source) { 309 return new PackageInfo(source); 310 } 311 312 public PackageInfo[] newArray(int size) { 313 return new PackageInfo[size]; 314 } 315 }; 316 317 private PackageInfo(Parcel source) { 318 packageName = source.readString(); 319 splitNames = source.readStringArray(); 320 versionCode = source.readInt(); 321 versionName = source.readString(); 322 sharedUserId = source.readString(); 323 sharedUserLabel = source.readInt(); 324 int hasApp = source.readInt(); 325 if (hasApp != 0) { 326 applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source); 327 } 328 firstInstallTime = source.readLong(); 329 lastUpdateTime = source.readLong(); 330 gids = source.createIntArray(); 331 activities = source.createTypedArray(ActivityInfo.CREATOR); 332 receivers = source.createTypedArray(ActivityInfo.CREATOR); 333 services = source.createTypedArray(ServiceInfo.CREATOR); 334 providers = source.createTypedArray(ProviderInfo.CREATOR); 335 instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR); 336 permissions = source.createTypedArray(PermissionInfo.CREATOR); 337 requestedPermissions = source.createStringArray(); 338 requestedPermissionsFlags = source.createIntArray(); 339 signatures = source.createTypedArray(Signature.CREATOR); 340 configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR); 341 reqFeatures = source.createTypedArray(FeatureInfo.CREATOR); 342 featureGroups = source.createTypedArray(FeatureGroupInfo.CREATOR); 343 installLocation = source.readInt(); 344 coreApp = source.readInt() != 0; 345 requiredForAllUsers = source.readInt() != 0; 346 restrictedAccountType = source.readString(); 347 requiredAccountType = source.readString(); 348 overlayTarget = source.readString(); 349 } 350} 351