blob: 123d9b7b8a3cced7412569b5e676160901e95605 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001package android.content.pm;
2
3import android.os.Parcel;
4import android.os.Parcelable;
5import android.util.Printer;
6
7import java.text.Collator;
8import java.util.Comparator;
9
10/**
11 * Information you can retrieve about a particular application. This
12 * corresponds to information collected from the AndroidManifest.xml's
13 * <application> tag.
14 */
15public class ApplicationInfo extends PackageItemInfo implements Parcelable {
16
17 /**
18 * Default task affinity of all activities in this application. See
19 * {@link ActivityInfo#taskAffinity} for more information. This comes
20 * from the "taskAffinity" attribute.
21 */
22 public String taskAffinity;
23
24 /**
25 * Optional name of a permission required to be able to access this
26 * application's components. From the "permission" attribute.
27 */
28 public String permission;
29
30 /**
31 * The name of the process this application should run in. From the
32 * "process" attribute or, if not set, the same as
33 * <var>packageName</var>.
34 */
35 public String processName;
36
37 /**
38 * Class implementing the Application object. From the "class"
39 * attribute.
40 */
41 public String className;
42
43 /**
44 * A style resource identifier (in the package's resources) of the
45 * description of an application. From the "description" attribute
46 * or, if not set, 0.
47 */
48 public int descriptionRes;
49
50 /**
51 * A style resource identifier (in the package's resources) of the
52 * default visual theme of the application. From the "theme" attribute
53 * or, if not set, 0.
54 */
55 public int theme;
56
57 /**
58 * Class implementing the Application's manage space
59 * functionality. From the "manageSpaceActivity"
60 * attribute. This is an optional attribute and will be null if
Christopher Tate181fafa2009-05-14 11:12:14 -070061 * applications don't specify it in their manifest
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 */
63 public String manageSpaceActivityName;
64
65 /**
Christopher Tate181fafa2009-05-14 11:12:14 -070066 * Class implementing the Application's backup functionality. From
67 * the "backupAgent" attribute. This is an optional attribute and
68 * will be null if the application does not specify it in its manifest.
69 *
70 * <p>If android:allowBackup is set to false, this attribute is ignored.
71 *
72 * {@hide}
73 */
74 public String backupAgentName;
75
76 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 * Value for {@link #flags}: if set, this application is installed in the
78 * device's system image.
79 */
80 public static final int FLAG_SYSTEM = 1<<0;
81
82 /**
83 * Value for {@link #flags}: set to true if this application would like to
84 * allow debugging of its
85 * code, even when installed on a non-development system. Comes
86 * from {@link android.R.styleable#AndroidManifestApplication_debuggable
87 * android:debuggable} of the &lt;application&gt; tag.
88 */
89 public static final int FLAG_DEBUGGABLE = 1<<1;
90
91 /**
92 * Value for {@link #flags}: set to true if this application has code
93 * associated with it. Comes
94 * from {@link android.R.styleable#AndroidManifestApplication_hasCode
95 * android:hasCode} of the &lt;application&gt; tag.
96 */
97 public static final int FLAG_HAS_CODE = 1<<2;
98
99 /**
100 * Value for {@link #flags}: set to true if this application is persistent.
101 * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
102 * android:persistent} of the &lt;application&gt; tag.
103 */
104 public static final int FLAG_PERSISTENT = 1<<3;
105
106 /**
Christopher Tate181fafa2009-05-14 11:12:14 -0700107 * Value for {@link #flags}: set to true if this application holds the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 * {@link android.Manifest.permission#FACTORY_TEST} permission and the
109 * device is running in factory test mode.
110 */
111 public static final int FLAG_FACTORY_TEST = 1<<4;
112
113 /**
114 * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
115 * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
116 * android:allowTaskReparenting} of the &lt;application&gt; tag.
117 */
118 public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
119
120 /**
121 * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
122 * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
123 * android:allowClearUserData} of the &lt;application&gt; tag.
124 */
125 public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800127 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700128 * Value for {@link #flags}: this is set if this application has been
129 * install as an update to a built-in system application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 */
131 public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700132
133 /**
Dianne Hackborn7f205432009-07-28 00:13:47 -0700134 * Value for {@link #flags}: this is set of the application has specified
135 * {@link android.R.styleable#AndroidManifestApplication_testOnly
136 * android:testOnly} to be true.
Dianne Hackborn851a5412009-05-08 12:06:44 -0700137 */
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700138 public static final int FLAG_TEST_ONLY = 1<<8;
Dianne Hackbornade3eca2009-05-11 18:54:45 -0700139
140 /**
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700141 * Value for {@link #flags}: true when the application's window can be
Dianne Hackborn723738c2009-06-25 19:48:04 -0700142 * reduced in size for smaller screens. Corresponds to
143 * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
144 * android:smallScreens}.
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700145 */
Dianne Hackborn723738c2009-06-25 19:48:04 -0700146 public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
147
148 /**
149 * Value for {@link #flags}: true when the application's window can be
150 * displayed on normal screens. Corresponds to
151 * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
152 * android:normalScreens}.
153 */
154 public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
155
156 /**
157 * Value for {@link #flags}: true when the application's window can be
158 * increased in size for larger screens. Corresponds to
159 * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
160 * android:smallScreens}.
161 */
162 public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700163
164 /**
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700165 * Value for {@link #flags}: true when the application knows how to adjust
166 * its UI for different screen sizes. Corresponds to
167 * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
168 * android:resizeable}.
169 */
170 public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
171
172 /**
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700173 * Value for {@link #flags}: true when the application knows how to
174 * accomodate different screen densities. Corresponds to
175 * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
176 * android:anyDensity}.
177 */
178 public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
179
180 /**
Ben Cheng23085b72010-02-08 16:06:32 -0800181 * Value for {@link #flags}: set to true if this application would like to
182 * request the VM to operate under the safe mode. Comes from
183 * {@link android.R.styleable#AndroidManifestApplication_safeMode
184 * android:safeMode} of the &lt;application&gt; tag.
185 */
186 public static final int FLAG_VM_SAFE_MODE = 1<<14;
187
188 /**
Christopher Tate181fafa2009-05-14 11:12:14 -0700189 * Value for {@link #flags}: this is false if the application has set
190 * its android:allowBackup to false, true otherwise.
191 *
192 * {@hide}
193 */
Ben Cheng23085b72010-02-08 16:06:32 -0800194 public static final int FLAG_ALLOW_BACKUP = 1<<15;
Christopher Tate5e1ab332009-09-01 20:32:49 -0700195
196 /**
197 * Value for {@link #flags}: this is false if the application has set
198 * its android:killAfterRestore to false, true otherwise.
199 *
200 * <p>If android:allowBackup is set to false or no android:backupAgent
201 * is specified, this flag will be ignored.
202 *
203 * {@hide}
204 */
Ben Cheng23085b72010-02-08 16:06:32 -0800205 public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
Christopher Tate5e1ab332009-09-01 20:32:49 -0700206
207 /**
208 * Value for {@link #flags}: this is true if the application has set
209 * its android:restoreNeedsApplication to true, false otherwise.
210 *
211 * <p>If android:allowBackup is set to false or no android:backupAgent
212 * is specified, this flag will be ignored.
213 *
214 * {@hide}
215 */
Ben Cheng23085b72010-02-08 16:06:32 -0800216 public static final int FLAG_RESTORE_NEEDS_APPLICATION = 1<<17;
Christopher Tate5e1ab332009-09-01 20:32:49 -0700217
Christopher Tate181fafa2009-05-14 11:12:14 -0700218 /**
Oscar Montemayor1874aa42009-11-10 18:35:33 -0800219 * Value for {@link #flags}: this is true if the application has set
220 * its android:neverEncrypt to true, false otherwise. It is used to specify
221 * that this package specifically "opts-out" of a secured file system solution,
222 * and will always store its data in-the-clear.
223 *
224 * {@hide}
225 */
Ben Cheng23085b72010-02-08 16:06:32 -0800226 public static final int FLAG_NEVER_ENCRYPT = 1<<18;
Oscar Montemayor1874aa42009-11-10 18:35:33 -0800227
228 /**
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800229 * Value for {@link #flags}: Set to true if the application has been
230 * installed using the forward lock option.
231 *
232 * {@hide}
233 */
Ben Cheng23085b72010-02-08 16:06:32 -0800234 public static final int FLAG_FORWARD_LOCK = 1<<19;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800235
236 /**
237 * Value for {@link #flags}: Set to true if the application is
238 * currently installed on the sdcard.
239 *
240 * {@hide}
241 */
Ben Cheng23085b72010-02-08 16:06:32 -0800242 public static final int FLAG_ON_SDCARD = 1<<20;
Suchi Amalapurapuaf8e9f42010-01-12 10:17:28 -0800243
244 /**
David 'Digit' Turner1edab2b2010-01-21 15:15:23 -0800245 * Value for {@link #flags}: Set to true if the application is
246 * native-debuggable, i.e. embeds a gdbserver binary in its .apk
247 *
248 * {@hide}
249 */
Ben Cheng23085b72010-02-08 16:06:32 -0800250 public static final int FLAG_NATIVE_DEBUGGABLE = 1<<21;
David 'Digit' Turner1edab2b2010-01-21 15:15:23 -0800251
252 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 * Flags associated with the application. Any combination of
254 * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
255 * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
256 * {@link #FLAG_ALLOW_TASK_REPARENTING}
Dianne Hackborn851a5412009-05-08 12:06:44 -0700257 * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
Dianne Hackborn723738c2009-06-25 19:48:04 -0700258 * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
259 * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
Christopher Tate5e1ab332009-09-01 20:32:49 -0700260 * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS},
Ben Cheng23085b72010-02-08 16:06:32 -0800261 * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 */
263 public int flags = 0;
264
265 /**
266 * Full path to the location of this package.
267 */
268 public String sourceDir;
269
270 /**
Kenny Rootd1ab0162010-01-21 17:27:14 -0800271 * Full path to the location of the publicly available parts of this
272 * package (i.e. the primary resource package and manifest). For
273 * non-forward-locked apps this will be the same as {@link #sourceDir).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 */
275 public String publicSourceDir;
276
277 /**
Kenny Rootd1ab0162010-01-21 17:27:14 -0800278 * Full paths to the locations of extra resource packages this application
279 * uses. This field is only used if there are extra resource packages,
280 * otherwise it is null.
Kenny Rootace5a3f2010-02-05 12:59:28 -0800281 *
282 * {@hide}
Kenny Rootd1ab0162010-01-21 17:27:14 -0800283 */
284 public String[] resourceDirs;
285
286 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 * Paths to all shared libraries this application is linked against. This
288 * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
289 * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
290 * the structure.
291 */
292 public String[] sharedLibraryFiles;
293
294 /**
295 * Full path to a directory assigned to the package for its persistent
296 * data.
297 */
298 public String dataDir;
299
300 /**
301 * The kernel user-ID that has been assigned to this application;
302 * currently this is not a unique ID (multiple applications can have
303 * the same uid).
304 */
305 public int uid;
306
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700307 /**
Dianne Hackborn3b3e1452009-09-24 19:22:12 -0700308 * The minimum SDK version this application targets. It may run on earlier
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700309 * versions, but it knows how to work with any new behavior added at this
310 * version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
311 * if this is a development build and the app is targeting that. You should
312 * compare that this number is >= the SDK version number at which your
313 * behavior was introduced.
314 */
315 public int targetSdkVersion;
316
317 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 * When false, indicates that all components within this application are
319 * considered disabled, regardless of their individually set enabled status.
320 */
321 public boolean enabled = true;
322
323 public void dump(Printer pw, String prefix) {
324 super.dumpFront(pw, prefix);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800325 if (className != null) {
326 pw.println(prefix + "className=" + className);
327 }
328 if (permission != null) {
329 pw.println(prefix + "permission=" + permission);
330 }
331 pw.println(prefix + "uid=" + uid + " taskAffinity=" + taskAffinity);
332 if (theme != 0) {
333 pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
336 + " processName=" + processName);
337 pw.println(prefix + "sourceDir=" + sourceDir);
338 pw.println(prefix + "publicSourceDir=" + publicSourceDir);
Kenny Rootd1ab0162010-01-21 17:27:14 -0800339 pw.println(prefix + "resourceDirs=" + resourceDirs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 pw.println(prefix + "dataDir=" + dataDir);
Dianne Hackborn12527f92009-11-11 17:39:50 -0800341 if (sharedLibraryFiles != null) {
342 pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
343 }
344 pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion);
345 if (manageSpaceActivityName != null) {
346 pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
347 }
348 if (descriptionRes != 0) {
349 pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
350 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 super.dumpBack(pw, prefix);
352 }
353
354 public static class DisplayNameComparator
355 implements Comparator<ApplicationInfo> {
356 public DisplayNameComparator(PackageManager pm) {
357 mPM = pm;
358 }
359
360 public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
361 CharSequence sa = mPM.getApplicationLabel(aa);
362 if (sa == null) {
363 sa = aa.packageName;
364 }
365 CharSequence sb = mPM.getApplicationLabel(ab);
366 if (sb == null) {
367 sb = ab.packageName;
368 }
369
370 return sCollator.compare(sa.toString(), sb.toString());
371 }
372
373 private final Collator sCollator = Collator.getInstance();
374 private PackageManager mPM;
375 }
376
377 public ApplicationInfo() {
378 }
379
380 public ApplicationInfo(ApplicationInfo orig) {
381 super(orig);
382 taskAffinity = orig.taskAffinity;
383 permission = orig.permission;
384 processName = orig.processName;
385 className = orig.className;
386 theme = orig.theme;
387 flags = orig.flags;
388 sourceDir = orig.sourceDir;
389 publicSourceDir = orig.publicSourceDir;
Kenny Rootd1ab0162010-01-21 17:27:14 -0800390 resourceDirs = orig.resourceDirs;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 sharedLibraryFiles = orig.sharedLibraryFiles;
392 dataDir = orig.dataDir;
393 uid = orig.uid;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700394 targetSdkVersion = orig.targetSdkVersion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 enabled = orig.enabled;
396 manageSpaceActivityName = orig.manageSpaceActivityName;
397 descriptionRes = orig.descriptionRes;
398 }
399
400
401 public String toString() {
402 return "ApplicationInfo{"
403 + Integer.toHexString(System.identityHashCode(this))
404 + " " + packageName + "}";
405 }
406
407 public int describeContents() {
408 return 0;
409 }
410
411 public void writeToParcel(Parcel dest, int parcelableFlags) {
412 super.writeToParcel(dest, parcelableFlags);
413 dest.writeString(taskAffinity);
414 dest.writeString(permission);
415 dest.writeString(processName);
416 dest.writeString(className);
417 dest.writeInt(theme);
418 dest.writeInt(flags);
419 dest.writeString(sourceDir);
420 dest.writeString(publicSourceDir);
Kenny Rootd1ab0162010-01-21 17:27:14 -0800421 dest.writeStringArray(resourceDirs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 dest.writeStringArray(sharedLibraryFiles);
423 dest.writeString(dataDir);
424 dest.writeInt(uid);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700425 dest.writeInt(targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 dest.writeInt(enabled ? 1 : 0);
427 dest.writeString(manageSpaceActivityName);
Christopher Tate181fafa2009-05-14 11:12:14 -0700428 dest.writeString(backupAgentName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 dest.writeInt(descriptionRes);
430 }
431
432 public static final Parcelable.Creator<ApplicationInfo> CREATOR
433 = new Parcelable.Creator<ApplicationInfo>() {
434 public ApplicationInfo createFromParcel(Parcel source) {
435 return new ApplicationInfo(source);
436 }
437 public ApplicationInfo[] newArray(int size) {
438 return new ApplicationInfo[size];
439 }
440 };
441
442 private ApplicationInfo(Parcel source) {
443 super(source);
444 taskAffinity = source.readString();
445 permission = source.readString();
446 processName = source.readString();
447 className = source.readString();
448 theme = source.readInt();
449 flags = source.readInt();
450 sourceDir = source.readString();
451 publicSourceDir = source.readString();
Kenny Rootd1ab0162010-01-21 17:27:14 -0800452 resourceDirs = source.readStringArray();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 sharedLibraryFiles = source.readStringArray();
454 dataDir = source.readString();
455 uid = source.readInt();
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700456 targetSdkVersion = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 enabled = source.readInt() != 0;
458 manageSpaceActivityName = source.readString();
Christopher Tate181fafa2009-05-14 11:12:14 -0700459 backupAgentName = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460 descriptionRes = source.readInt();
461 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 /**
464 * Retrieve the textual description of the application. This
465 * will call back on the given PackageManager to load the description from
466 * the application.
467 *
468 * @param pm A PackageManager from which the label can be loaded; usually
469 * the PackageManager from which you originally retrieved this item.
470 *
471 * @return Returns a CharSequence containing the application's description.
472 * If there is no description, null is returned.
473 */
474 public CharSequence loadDescription(PackageManager pm) {
475 if (descriptionRes != 0) {
476 CharSequence label = pm.getText(packageName, descriptionRes, null);
477 if (label != null) {
478 return label;
479 }
480 }
481 return null;
482 }
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700483
484 /**
485 * Disable compatibility mode
486 *
487 * @hide
488 */
489 public void disableCompatibilityMode() {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700490 flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700491 FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
492 FLAG_SUPPORTS_SCREEN_DENSITIES);
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700493 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494}