ApplicationInfo.java revision 3de55bcd34afd5871816526294f9514d1adf3fe5
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; 21import android.util.Printer; 22 23import java.text.Collator; 24import java.util.Comparator; 25 26/** 27 * Information you can retrieve about a particular application. This 28 * corresponds to information collected from the AndroidManifest.xml's 29 * <application> tag. 30 */ 31public class ApplicationInfo extends PackageItemInfo implements Parcelable { 32 33 /** 34 * Default task affinity of all activities in this application. See 35 * {@link ActivityInfo#taskAffinity} for more information. This comes 36 * from the "taskAffinity" attribute. 37 */ 38 public String taskAffinity; 39 40 /** 41 * Optional name of a permission required to be able to access this 42 * application's components. From the "permission" attribute. 43 */ 44 public String permission; 45 46 /** 47 * The name of the process this application should run in. From the 48 * "process" attribute or, if not set, the same as 49 * <var>packageName</var>. 50 */ 51 public String processName; 52 53 /** 54 * Class implementing the Application object. From the "class" 55 * attribute. 56 */ 57 public String className; 58 59 /** 60 * A style resource identifier (in the package's resources) of the 61 * description of an application. From the "description" attribute 62 * or, if not set, 0. 63 */ 64 public int descriptionRes; 65 66 /** 67 * A style resource identifier (in the package's resources) of the 68 * default visual theme of the application. From the "theme" attribute 69 * or, if not set, 0. 70 */ 71 public int theme; 72 73 /** 74 * Class implementing the Application's manage space 75 * functionality. From the "manageSpaceActivity" 76 * attribute. This is an optional attribute and will be null if 77 * applications don't specify it in their manifest 78 */ 79 public String manageSpaceActivityName; 80 81 /** 82 * Class implementing the Application's backup functionality. From 83 * the "backupAgent" attribute. This is an optional attribute and 84 * will be null if the application does not specify it in its manifest. 85 * 86 * <p>If android:allowBackup is set to false, this attribute is ignored. 87 */ 88 public String backupAgentName; 89 90 /** 91 * Value for {@link #flags}: if set, this application is installed in the 92 * device's system image. 93 */ 94 public static final int FLAG_SYSTEM = 1<<0; 95 96 /** 97 * Value for {@link #flags}: set to true if this application would like to 98 * allow debugging of its 99 * code, even when installed on a non-development system. Comes 100 * from {@link android.R.styleable#AndroidManifestApplication_debuggable 101 * android:debuggable} of the <application> tag. 102 */ 103 public static final int FLAG_DEBUGGABLE = 1<<1; 104 105 /** 106 * Value for {@link #flags}: set to true if this application has code 107 * associated with it. Comes 108 * from {@link android.R.styleable#AndroidManifestApplication_hasCode 109 * android:hasCode} of the <application> tag. 110 */ 111 public static final int FLAG_HAS_CODE = 1<<2; 112 113 /** 114 * Value for {@link #flags}: set to true if this application is persistent. 115 * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent 116 * android:persistent} of the <application> tag. 117 */ 118 public static final int FLAG_PERSISTENT = 1<<3; 119 120 /** 121 * Value for {@link #flags}: set to true if this application holds the 122 * {@link android.Manifest.permission#FACTORY_TEST} permission and the 123 * device is running in factory test mode. 124 */ 125 public static final int FLAG_FACTORY_TEST = 1<<4; 126 127 /** 128 * Value for {@link #flags}: default value for the corresponding ActivityInfo flag. 129 * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting 130 * android:allowTaskReparenting} of the <application> tag. 131 */ 132 public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5; 133 134 /** 135 * Value for {@link #flags}: default value for the corresponding ActivityInfo flag. 136 * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData 137 * android:allowClearUserData} of the <application> tag. 138 */ 139 public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6; 140 141 /** 142 * Value for {@link #flags}: this is set if this application has been 143 * install as an update to a built-in system application. 144 */ 145 public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7; 146 147 /** 148 * Value for {@link #flags}: this is set of the application has specified 149 * {@link android.R.styleable#AndroidManifestApplication_testOnly 150 * android:testOnly} to be true. 151 */ 152 public static final int FLAG_TEST_ONLY = 1<<8; 153 154 /** 155 * Value for {@link #flags}: true when the application's window can be 156 * reduced in size for smaller screens. Corresponds to 157 * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens 158 * android:smallScreens}. 159 */ 160 public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9; 161 162 /** 163 * Value for {@link #flags}: true when the application's window can be 164 * displayed on normal screens. Corresponds to 165 * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens 166 * android:normalScreens}. 167 */ 168 public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10; 169 170 /** 171 * Value for {@link #flags}: true when the application's window can be 172 * increased in size for larger screens. Corresponds to 173 * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens 174 * android:smallScreens}. 175 */ 176 public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11; 177 178 /** 179 * Value for {@link #flags}: true when the application knows how to adjust 180 * its UI for different screen sizes. Corresponds to 181 * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable 182 * android:resizeable}. 183 */ 184 public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12; 185 186 /** 187 * Value for {@link #flags}: true when the application knows how to 188 * accomodate different screen densities. Corresponds to 189 * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity 190 * android:anyDensity}. 191 */ 192 public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13; 193 194 /** 195 * Value for {@link #flags}: set to true if this application would like to 196 * request the VM to operate under the safe mode. Comes from 197 * {@link android.R.styleable#AndroidManifestApplication_safeMode 198 * android:safeMode} of the <application> tag. 199 */ 200 public static final int FLAG_VM_SAFE_MODE = 1<<14; 201 202 /** 203 * Value for {@link #flags}: set to <code>false</code> if the application does not wish 204 * to permit any OS-driven backups of its data; <code>true</code> otherwise. 205 * 206 * <p>Comes from the 207 * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup} 208 * attribute of the <application> tag. 209 */ 210 public static final int FLAG_ALLOW_BACKUP = 1<<15; 211 212 /** 213 * Value for {@link #flags}: set to <code>false</code> if the application must be kept 214 * in memory following a full-system restore operation; <code>true</code> otherwise. 215 * Ordinarily, during a full system restore operation each application is shut down 216 * following execution of its agent's onRestore() method. Setting this attribute to 217 * <code>false</code> prevents this. Most applications will not need to set this attribute. 218 * 219 * <p>If 220 * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup} 221 * is set to <code>false</code> or no 222 * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent} 223 * is specified, this flag will be ignored. 224 * 225 * <p>Comes from the 226 * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore} 227 * attribute of the <application> tag. 228 */ 229 public static final int FLAG_KILL_AFTER_RESTORE = 1<<16; 230 231 /** 232 * Value for {@link #flags}: Set to <code>true</code> if the application's backup 233 * agent claims to be able to handle restore data even "from the future," 234 * i.e. from versions of the application with a versionCode greater than 235 * the one currently installed on the device. <i>Use with caution!</i> By default 236 * this attribute is <code>false</code> and the Backup Manager will ensure that data 237 * from "future" versions of the application are never supplied during a restore operation. 238 * 239 * <p>If 240 * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup} 241 * is set to <code>false</code> or no 242 * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent} 243 * is specified, this flag will be ignored. 244 * 245 * <p>Comes from the 246 * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion} 247 * attribute of the <application> tag. 248 */ 249 public static final int FLAG_RESTORE_ANY_VERSION = 1<<17; 250 251 /** 252 * Value for {@link #flags}: this is true if the application has set 253 * its android:neverEncrypt to true, false otherwise. It is used to specify 254 * that this package specifically "opts-out" of a secured file system solution, 255 * and will always store its data in-the-clear. 256 * 257 * {@hide} 258 */ 259 public static final int FLAG_NEVER_ENCRYPT = 1<<18; 260 261 /** 262 * Value for {@link #flags}: Set to true if the application has been 263 * installed using the forward lock option. 264 * 265 * {@hide} 266 */ 267 public static final int FLAG_FORWARD_LOCK = 1<<19; 268 269 /** 270 * Value for {@link #flags}: Set to true if the application is 271 * currently installed on the sdcard. 272 * 273 * {@hide} 274 */ 275 public static final int FLAG_EXTERNAL_STORAGE = 1<<20; 276 277 /** 278 * Value for {@link #flags}: Set to true if the application is 279 * native-debuggable, i.e. embeds a gdbserver binary in its .apk 280 * 281 * {@hide} 282 */ 283 public static final int FLAG_NATIVE_DEBUGGABLE = 1<<21; 284 285 /** 286 * Flags associated with the application. Any combination of 287 * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE}, 288 * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and 289 * {@link #FLAG_ALLOW_TASK_REPARENTING} 290 * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP}, 291 * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS}, 292 * {@link #FLAG_SUPPORTS_NORMAL_SCREENS}, 293 * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS}, 294 * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE} 295 */ 296 public int flags = 0; 297 298 /** 299 * Full path to the location of this package. 300 */ 301 public String sourceDir; 302 303 /** 304 * Full path to the location of the publicly available parts of this 305 * package (i.e. the primary resource package and manifest). For 306 * non-forward-locked apps this will be the same as {@link #sourceDir). 307 */ 308 public String publicSourceDir; 309 310 /** 311 * Full paths to the locations of extra resource packages this application 312 * uses. This field is only used if there are extra resource packages, 313 * otherwise it is null. 314 * 315 * {@hide} 316 */ 317 public String[] resourceDirs; 318 319 /** 320 * Paths to all shared libraries this application is linked against. This 321 * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES 322 * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving 323 * the structure. 324 */ 325 public String[] sharedLibraryFiles; 326 327 /** 328 * Full path to a directory assigned to the package for its persistent 329 * data. 330 */ 331 public String dataDir; 332 333 /** 334 * The kernel user-ID that has been assigned to this application; 335 * currently this is not a unique ID (multiple applications can have 336 * the same uid). 337 */ 338 public int uid; 339 340 /** 341 * The minimum SDK version this application targets. It may run on earlier 342 * versions, but it knows how to work with any new behavior added at this 343 * version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT} 344 * if this is a development build and the app is targeting that. You should 345 * compare that this number is >= the SDK version number at which your 346 * behavior was introduced. 347 */ 348 public int targetSdkVersion; 349 350 /** 351 * When false, indicates that all components within this application are 352 * considered disabled, regardless of their individually set enabled status. 353 */ 354 public boolean enabled = true; 355 356 public void dump(Printer pw, String prefix) { 357 super.dumpFront(pw, prefix); 358 if (className != null) { 359 pw.println(prefix + "className=" + className); 360 } 361 if (permission != null) { 362 pw.println(prefix + "permission=" + permission); 363 } 364 pw.println(prefix + "uid=" + uid + " taskAffinity=" + taskAffinity); 365 if (theme != 0) { 366 pw.println(prefix + "theme=0x" + Integer.toHexString(theme)); 367 } 368 pw.println(prefix + "flags=0x" + Integer.toHexString(flags) 369 + " processName=" + processName); 370 pw.println(prefix + "sourceDir=" + sourceDir); 371 pw.println(prefix + "publicSourceDir=" + publicSourceDir); 372 pw.println(prefix + "resourceDirs=" + resourceDirs); 373 pw.println(prefix + "dataDir=" + dataDir); 374 if (sharedLibraryFiles != null) { 375 pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles); 376 } 377 pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion); 378 if (manageSpaceActivityName != null) { 379 pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName); 380 } 381 if (descriptionRes != 0) { 382 pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes)); 383 } 384 super.dumpBack(pw, prefix); 385 } 386 387 public static class DisplayNameComparator 388 implements Comparator<ApplicationInfo> { 389 public DisplayNameComparator(PackageManager pm) { 390 mPM = pm; 391 } 392 393 public final int compare(ApplicationInfo aa, ApplicationInfo ab) { 394 CharSequence sa = mPM.getApplicationLabel(aa); 395 if (sa == null) { 396 sa = aa.packageName; 397 } 398 CharSequence sb = mPM.getApplicationLabel(ab); 399 if (sb == null) { 400 sb = ab.packageName; 401 } 402 403 return sCollator.compare(sa.toString(), sb.toString()); 404 } 405 406 private final Collator sCollator = Collator.getInstance(); 407 private PackageManager mPM; 408 } 409 410 public ApplicationInfo() { 411 } 412 413 public ApplicationInfo(ApplicationInfo orig) { 414 super(orig); 415 taskAffinity = orig.taskAffinity; 416 permission = orig.permission; 417 processName = orig.processName; 418 className = orig.className; 419 theme = orig.theme; 420 flags = orig.flags; 421 sourceDir = orig.sourceDir; 422 publicSourceDir = orig.publicSourceDir; 423 resourceDirs = orig.resourceDirs; 424 sharedLibraryFiles = orig.sharedLibraryFiles; 425 dataDir = orig.dataDir; 426 uid = orig.uid; 427 targetSdkVersion = orig.targetSdkVersion; 428 enabled = orig.enabled; 429 manageSpaceActivityName = orig.manageSpaceActivityName; 430 descriptionRes = orig.descriptionRes; 431 } 432 433 434 public String toString() { 435 return "ApplicationInfo{" 436 + Integer.toHexString(System.identityHashCode(this)) 437 + " " + packageName + "}"; 438 } 439 440 public int describeContents() { 441 return 0; 442 } 443 444 public void writeToParcel(Parcel dest, int parcelableFlags) { 445 super.writeToParcel(dest, parcelableFlags); 446 dest.writeString(taskAffinity); 447 dest.writeString(permission); 448 dest.writeString(processName); 449 dest.writeString(className); 450 dest.writeInt(theme); 451 dest.writeInt(flags); 452 dest.writeString(sourceDir); 453 dest.writeString(publicSourceDir); 454 dest.writeStringArray(resourceDirs); 455 dest.writeStringArray(sharedLibraryFiles); 456 dest.writeString(dataDir); 457 dest.writeInt(uid); 458 dest.writeInt(targetSdkVersion); 459 dest.writeInt(enabled ? 1 : 0); 460 dest.writeString(manageSpaceActivityName); 461 dest.writeString(backupAgentName); 462 dest.writeInt(descriptionRes); 463 } 464 465 public static final Parcelable.Creator<ApplicationInfo> CREATOR 466 = new Parcelable.Creator<ApplicationInfo>() { 467 public ApplicationInfo createFromParcel(Parcel source) { 468 return new ApplicationInfo(source); 469 } 470 public ApplicationInfo[] newArray(int size) { 471 return new ApplicationInfo[size]; 472 } 473 }; 474 475 private ApplicationInfo(Parcel source) { 476 super(source); 477 taskAffinity = source.readString(); 478 permission = source.readString(); 479 processName = source.readString(); 480 className = source.readString(); 481 theme = source.readInt(); 482 flags = source.readInt(); 483 sourceDir = source.readString(); 484 publicSourceDir = source.readString(); 485 resourceDirs = source.readStringArray(); 486 sharedLibraryFiles = source.readStringArray(); 487 dataDir = source.readString(); 488 uid = source.readInt(); 489 targetSdkVersion = source.readInt(); 490 enabled = source.readInt() != 0; 491 manageSpaceActivityName = source.readString(); 492 backupAgentName = source.readString(); 493 descriptionRes = source.readInt(); 494 } 495 496 /** 497 * Retrieve the textual description of the application. This 498 * will call back on the given PackageManager to load the description from 499 * the application. 500 * 501 * @param pm A PackageManager from which the label can be loaded; usually 502 * the PackageManager from which you originally retrieved this item. 503 * 504 * @return Returns a CharSequence containing the application's description. 505 * If there is no description, null is returned. 506 */ 507 public CharSequence loadDescription(PackageManager pm) { 508 if (descriptionRes != 0) { 509 CharSequence label = pm.getText(packageName, descriptionRes, null); 510 if (label != null) { 511 return label; 512 } 513 } 514 return null; 515 } 516 517 /** 518 * Disable compatibility mode 519 * 520 * @hide 521 */ 522 public void disableCompatibilityMode() { 523 flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS | 524 FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS | 525 FLAG_SUPPORTS_SCREEN_DENSITIES); 526 } 527} 528