blob: f10dd5309f253ad2c16f06eb54a3bc4f7f91d903 [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 /**
134 * Value for {@link #flags}: this is set of the application has set
135 * its android:targetSdkVersion to something >= the current SDK version.
136 */
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700137 public static final int FLAG_TEST_ONLY = 1<<8;
Dianne Hackbornade3eca2009-05-11 18:54:45 -0700138
139 /**
Christopher Tate181fafa2009-05-14 11:12:14 -0700140 * Value for {@link #flags}: this is false if the application has set
141 * its android:allowBackup to false, true otherwise.
142 *
143 * {@hide}
144 */
145 public static final int FLAG_ALLOW_BACKUP = 1<<10;
146
147 /**
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700148 * Indicates that the application supports any densities;
149 * {@hide}
150 */
151 public static final int ANY_DENSITY = -1;
152 private static final int[] ANY_DENSITIES_ARRAY = { ANY_DENSITY };
153
154 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 * Flags associated with the application. Any combination of
156 * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
157 * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
158 * {@link #FLAG_ALLOW_TASK_REPARENTING}
Dianne Hackborn851a5412009-05-08 12:06:44 -0700159 * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700160 * {@link #FLAG_TEST_ONLY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 */
162 public int flags = 0;
163
164 /**
165 * Full path to the location of this package.
166 */
167 public String sourceDir;
168
169 /**
170 * Full path to the location of the publicly available parts of this package (i.e. the resources
171 * and manifest). For non-forward-locked apps this will be the same as {@link #sourceDir).
172 */
173 public String publicSourceDir;
174
175 /**
176 * Paths to all shared libraries this application is linked against. This
177 * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
178 * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
179 * the structure.
180 */
181 public String[] sharedLibraryFiles;
182
183 /**
184 * Full path to a directory assigned to the package for its persistent
185 * data.
186 */
187 public String dataDir;
188
189 /**
190 * The kernel user-ID that has been assigned to this application;
191 * currently this is not a unique ID (multiple applications can have
192 * the same uid).
193 */
194 public int uid;
195
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700196 /**
197 * The list of densities in DPI that application supprots. This
198 * field is only set if the {@link PackageManager#GET_SUPPORTS_DENSITIES} flag was
199 * used when retrieving the structure.
200 */
201 public int[] supportsDensities;
202
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 /**
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700204 * True when the application's window can be expanded over default window
205 * size in target density (320x480 for 1.0 density, 480x720 for 1.5 density etc)
206 */
207 public boolean expandable = false;
208
209 /**
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700210 * The minimum SDK version this application targets. It may run on earilier
211 * versions, but it knows how to work with any new behavior added at this
212 * version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
213 * if this is a development build and the app is targeting that. You should
214 * compare that this number is >= the SDK version number at which your
215 * behavior was introduced.
216 */
217 public int targetSdkVersion;
218
219 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 * When false, indicates that all components within this application are
221 * considered disabled, regardless of their individually set enabled status.
222 */
223 public boolean enabled = true;
224
225 public void dump(Printer pw, String prefix) {
226 super.dumpFront(pw, prefix);
227 pw.println(prefix + "className=" + className);
228 pw.println(prefix + "permission=" + permission
229 + " uid=" + uid);
230 pw.println(prefix + "taskAffinity=" + taskAffinity);
231 pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
232 pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
233 + " processName=" + processName);
234 pw.println(prefix + "sourceDir=" + sourceDir);
235 pw.println(prefix + "publicSourceDir=" + publicSourceDir);
236 pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
237 pw.println(prefix + "dataDir=" + dataDir);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700238 pw.println(prefix + "targetSdkVersion=" + targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 pw.println(prefix + "enabled=" + enabled);
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700240 pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
241 pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
242 pw.println(prefix + "supportsDensities=" + supportsDensities);
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700243 pw.println(prefix + "expandable=" + expandable);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 super.dumpBack(pw, prefix);
245 }
246
247 public static class DisplayNameComparator
248 implements Comparator<ApplicationInfo> {
249 public DisplayNameComparator(PackageManager pm) {
250 mPM = pm;
251 }
252
253 public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
254 CharSequence sa = mPM.getApplicationLabel(aa);
255 if (sa == null) {
256 sa = aa.packageName;
257 }
258 CharSequence sb = mPM.getApplicationLabel(ab);
259 if (sb == null) {
260 sb = ab.packageName;
261 }
262
263 return sCollator.compare(sa.toString(), sb.toString());
264 }
265
266 private final Collator sCollator = Collator.getInstance();
267 private PackageManager mPM;
268 }
269
270 public ApplicationInfo() {
271 }
272
273 public ApplicationInfo(ApplicationInfo orig) {
274 super(orig);
275 taskAffinity = orig.taskAffinity;
276 permission = orig.permission;
277 processName = orig.processName;
278 className = orig.className;
279 theme = orig.theme;
280 flags = orig.flags;
281 sourceDir = orig.sourceDir;
282 publicSourceDir = orig.publicSourceDir;
283 sharedLibraryFiles = orig.sharedLibraryFiles;
284 dataDir = orig.dataDir;
285 uid = orig.uid;
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700286 targetSdkVersion = orig.targetSdkVersion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 enabled = orig.enabled;
288 manageSpaceActivityName = orig.manageSpaceActivityName;
289 descriptionRes = orig.descriptionRes;
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700290 supportsDensities = orig.supportsDensities;
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700291 expandable = orig.expandable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 }
293
294
295 public String toString() {
296 return "ApplicationInfo{"
297 + Integer.toHexString(System.identityHashCode(this))
298 + " " + packageName + "}";
299 }
300
301 public int describeContents() {
302 return 0;
303 }
304
305 public void writeToParcel(Parcel dest, int parcelableFlags) {
306 super.writeToParcel(dest, parcelableFlags);
307 dest.writeString(taskAffinity);
308 dest.writeString(permission);
309 dest.writeString(processName);
310 dest.writeString(className);
311 dest.writeInt(theme);
312 dest.writeInt(flags);
313 dest.writeString(sourceDir);
314 dest.writeString(publicSourceDir);
315 dest.writeStringArray(sharedLibraryFiles);
316 dest.writeString(dataDir);
317 dest.writeInt(uid);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700318 dest.writeInt(targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 dest.writeInt(enabled ? 1 : 0);
320 dest.writeString(manageSpaceActivityName);
Christopher Tate181fafa2009-05-14 11:12:14 -0700321 dest.writeString(backupAgentName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 dest.writeInt(descriptionRes);
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700323 dest.writeIntArray(supportsDensities);
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700324 dest.writeInt(expandable ? 1 : 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 }
326
327 public static final Parcelable.Creator<ApplicationInfo> CREATOR
328 = new Parcelable.Creator<ApplicationInfo>() {
329 public ApplicationInfo createFromParcel(Parcel source) {
330 return new ApplicationInfo(source);
331 }
332 public ApplicationInfo[] newArray(int size) {
333 return new ApplicationInfo[size];
334 }
335 };
336
337 private ApplicationInfo(Parcel source) {
338 super(source);
339 taskAffinity = source.readString();
340 permission = source.readString();
341 processName = source.readString();
342 className = source.readString();
343 theme = source.readInt();
344 flags = source.readInt();
345 sourceDir = source.readString();
346 publicSourceDir = source.readString();
347 sharedLibraryFiles = source.readStringArray();
348 dataDir = source.readString();
349 uid = source.readInt();
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700350 targetSdkVersion = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351 enabled = source.readInt() != 0;
352 manageSpaceActivityName = source.readString();
Christopher Tate181fafa2009-05-14 11:12:14 -0700353 backupAgentName = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 descriptionRes = source.readInt();
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700355 supportsDensities = source.createIntArray();
Mitsuru Oshima9189cab2009-06-03 11:19:12 -0700356 expandable = source.readInt() != 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700358
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 /**
360 * Retrieve the textual description of the application. This
361 * will call back on the given PackageManager to load the description from
362 * the application.
363 *
364 * @param pm A PackageManager from which the label can be loaded; usually
365 * the PackageManager from which you originally retrieved this item.
366 *
367 * @return Returns a CharSequence containing the application's description.
368 * If there is no description, null is returned.
369 */
370 public CharSequence loadDescription(PackageManager pm) {
371 if (descriptionRes != 0) {
372 CharSequence label = pm.getText(packageName, descriptionRes, null);
373 if (label != null) {
374 return label;
375 }
376 }
377 return null;
378 }
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700379
380 /**
381 * Disable compatibility mode
382 *
383 * @hide
384 */
385 public void disableCompatibilityMode() {
386 expandable = true;
387 supportsDensities = ANY_DENSITIES_ARRAY;
388 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389}