blob: 0a42a6faf9f4b53d32051b846999d2de2a55bfcb [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 /**
Christopher Tate181fafa2009-05-14 11:12:14 -0700181 * Value for {@link #flags}: this is false if the application has set
182 * its android:allowBackup to false, true otherwise.
183 *
184 * {@hide}
185 */
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700186 public static final int FLAG_ALLOW_BACKUP = 1<<14;
Christopher Tate181fafa2009-05-14 11:12:14 -0700187
188 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800189 * Flags associated with the application. Any combination of
190 * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
191 * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
192 * {@link #FLAG_ALLOW_TASK_REPARENTING}
Dianne Hackborn851a5412009-05-08 12:06:44 -0700193 * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
Dianne Hackborn723738c2009-06-25 19:48:04 -0700194 * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
195 * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
Dianne Hackbornc4db95c2009-07-21 17:46:02 -0700196 * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 */
198 public int flags = 0;
199
200 /**
201 * Full path to the location of this package.
202 */
203 public String sourceDir;
204
205 /**
206 * Full path to the location of the publicly available parts of this package (i.e. the resources
207 * and manifest). For non-forward-locked apps this will be the same as {@link #sourceDir).
208 */
209 public String publicSourceDir;
210
211 /**
212 * Paths to all shared libraries this application is linked against. This
213 * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
214 * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
215 * the structure.
216 */
217 public String[] sharedLibraryFiles;
218
219 /**
220 * Full path to a directory assigned to the package for its persistent
221 * data.
222 */
223 public String dataDir;
224
225 /**
226 * The kernel user-ID that has been assigned to this application;
227 * currently this is not a unique ID (multiple applications can have
228 * the same uid).
229 */
230 public int uid;
231
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700232 /**
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700233 * The minimum SDK version this application targets. It may run on earilier
234 * versions, but it knows how to work with any new behavior added at this
235 * version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
236 * if this is a development build and the app is targeting that. You should
237 * compare that this number is >= the SDK version number at which your
238 * behavior was introduced.
239 */
240 public int targetSdkVersion;
241
242 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 * When false, indicates that all components within this application are
244 * considered disabled, regardless of their individually set enabled status.
245 */
246 public boolean enabled = true;
247
248 public void dump(Printer pw, String prefix) {
249 super.dumpFront(pw, prefix);
250 pw.println(prefix + "className=" + className);
251 pw.println(prefix + "permission=" + permission
252 + " uid=" + uid);
253 pw.println(prefix + "taskAffinity=" + taskAffinity);
254 pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
255 pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
256 + " processName=" + processName);
257 pw.println(prefix + "sourceDir=" + sourceDir);
258 pw.println(prefix + "publicSourceDir=" + publicSourceDir);
259 pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
260 pw.println(prefix + "dataDir=" + dataDir);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700261 pw.println(prefix + "targetSdkVersion=" + targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 pw.println(prefix + "enabled=" + enabled);
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700263 pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
264 pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 super.dumpBack(pw, prefix);
266 }
267
268 public static class DisplayNameComparator
269 implements Comparator<ApplicationInfo> {
270 public DisplayNameComparator(PackageManager pm) {
271 mPM = pm;
272 }
273
274 public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
275 CharSequence sa = mPM.getApplicationLabel(aa);
276 if (sa == null) {
277 sa = aa.packageName;
278 }
279 CharSequence sb = mPM.getApplicationLabel(ab);
280 if (sb == null) {
281 sb = ab.packageName;
282 }
283
284 return sCollator.compare(sa.toString(), sb.toString());
285 }
286
287 private final Collator sCollator = Collator.getInstance();
288 private PackageManager mPM;
289 }
290
291 public ApplicationInfo() {
292 }
293
294 public ApplicationInfo(ApplicationInfo orig) {
295 super(orig);
296 taskAffinity = orig.taskAffinity;
297 permission = orig.permission;
298 processName = orig.processName;
299 className = orig.className;
300 theme = orig.theme;
301 flags = orig.flags;
302 sourceDir = orig.sourceDir;
303 publicSourceDir = orig.publicSourceDir;
304 sharedLibraryFiles = orig.sharedLibraryFiles;
305 dataDir = orig.dataDir;
306 uid = orig.uid;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700307 targetSdkVersion = orig.targetSdkVersion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 enabled = orig.enabled;
309 manageSpaceActivityName = orig.manageSpaceActivityName;
310 descriptionRes = orig.descriptionRes;
311 }
312
313
314 public String toString() {
315 return "ApplicationInfo{"
316 + Integer.toHexString(System.identityHashCode(this))
317 + " " + packageName + "}";
318 }
319
320 public int describeContents() {
321 return 0;
322 }
323
324 public void writeToParcel(Parcel dest, int parcelableFlags) {
325 super.writeToParcel(dest, parcelableFlags);
326 dest.writeString(taskAffinity);
327 dest.writeString(permission);
328 dest.writeString(processName);
329 dest.writeString(className);
330 dest.writeInt(theme);
331 dest.writeInt(flags);
332 dest.writeString(sourceDir);
333 dest.writeString(publicSourceDir);
334 dest.writeStringArray(sharedLibraryFiles);
335 dest.writeString(dataDir);
336 dest.writeInt(uid);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700337 dest.writeInt(targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 dest.writeInt(enabled ? 1 : 0);
339 dest.writeString(manageSpaceActivityName);
Christopher Tate181fafa2009-05-14 11:12:14 -0700340 dest.writeString(backupAgentName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 dest.writeInt(descriptionRes);
342 }
343
344 public static final Parcelable.Creator<ApplicationInfo> CREATOR
345 = new Parcelable.Creator<ApplicationInfo>() {
346 public ApplicationInfo createFromParcel(Parcel source) {
347 return new ApplicationInfo(source);
348 }
349 public ApplicationInfo[] newArray(int size) {
350 return new ApplicationInfo[size];
351 }
352 };
353
354 private ApplicationInfo(Parcel source) {
355 super(source);
356 taskAffinity = source.readString();
357 permission = source.readString();
358 processName = source.readString();
359 className = source.readString();
360 theme = source.readInt();
361 flags = source.readInt();
362 sourceDir = source.readString();
363 publicSourceDir = source.readString();
364 sharedLibraryFiles = source.readStringArray();
365 dataDir = source.readString();
366 uid = source.readInt();
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700367 targetSdkVersion = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800368 enabled = source.readInt() != 0;
369 manageSpaceActivityName = source.readString();
Christopher Tate181fafa2009-05-14 11:12:14 -0700370 backupAgentName = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 descriptionRes = source.readInt();
372 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 /**
375 * Retrieve the textual description of the application. This
376 * will call back on the given PackageManager to load the description from
377 * the application.
378 *
379 * @param pm A PackageManager from which the label can be loaded; usually
380 * the PackageManager from which you originally retrieved this item.
381 *
382 * @return Returns a CharSequence containing the application's description.
383 * If there is no description, null is returned.
384 */
385 public CharSequence loadDescription(PackageManager pm) {
386 if (descriptionRes != 0) {
387 CharSequence label = pm.getText(packageName, descriptionRes, null);
388 if (label != null) {
389 return label;
390 }
391 }
392 return null;
393 }
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700394
395 /**
396 * Disable compatibility mode
397 *
398 * @hide
399 */
400 public void disableCompatibilityMode() {
Mitsuru Oshima69fff4a2009-07-21 09:51:05 -0700401 flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
Dianne Hackborn11b822d2009-07-21 20:03:02 -0700402 FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
403 FLAG_SUPPORTS_SCREEN_DENSITIES);
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700404 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405}