blob: 2a2cf93de29994ad857ae2bb5b741c391d383194 [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 /**
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700140 * Value for {@link #flags}: true when the application's window can be
141 * expanded over default window size in target density (320x480 for
142 * 1.0 density, 480x720 for 1.5 density etc)
143 */
144 public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<9;
145
146 /**
Christopher Tate181fafa2009-05-14 11:12:14 -0700147 * Value for {@link #flags}: this is false if the application has set
148 * its android:allowBackup to false, true otherwise.
149 *
150 * {@hide}
151 */
152 public static final int FLAG_ALLOW_BACKUP = 1<<10;
153
154 /**
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700155 * Indicates that the application supports any densities;
156 * {@hide}
157 */
158 public static final int ANY_DENSITY = -1;
159 private static final int[] ANY_DENSITIES_ARRAY = { ANY_DENSITY };
160
161 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 * Flags associated with the application. Any combination of
163 * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
164 * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
165 * {@link #FLAG_ALLOW_TASK_REPARENTING}
Dianne Hackborn851a5412009-05-08 12:06:44 -0700166 * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700167 * {@link #FLAG_TEST_ONLY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 */
169 public int flags = 0;
170
171 /**
172 * Full path to the location of this package.
173 */
174 public String sourceDir;
175
176 /**
177 * Full path to the location of the publicly available parts of this package (i.e. the resources
178 * and manifest). For non-forward-locked apps this will be the same as {@link #sourceDir).
179 */
180 public String publicSourceDir;
181
182 /**
183 * Paths to all shared libraries this application is linked against. This
184 * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
185 * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
186 * the structure.
187 */
188 public String[] sharedLibraryFiles;
189
190 /**
191 * Full path to a directory assigned to the package for its persistent
192 * data.
193 */
194 public String dataDir;
195
196 /**
197 * The kernel user-ID that has been assigned to this application;
198 * currently this is not a unique ID (multiple applications can have
199 * the same uid).
200 */
201 public int uid;
202
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700203 /**
204 * The list of densities in DPI that application supprots. This
205 * field is only set if the {@link PackageManager#GET_SUPPORTS_DENSITIES} flag was
206 * used when retrieving the structure.
207 */
208 public int[] supportsDensities;
209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 /**
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700211 * The minimum SDK version this application targets. It may run on earilier
212 * versions, but it knows how to work with any new behavior added at this
213 * version. Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
214 * if this is a development build and the app is targeting that. You should
215 * compare that this number is >= the SDK version number at which your
216 * behavior was introduced.
217 */
218 public int targetSdkVersion;
219
220 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * When false, indicates that all components within this application are
222 * considered disabled, regardless of their individually set enabled status.
223 */
224 public boolean enabled = true;
225
226 public void dump(Printer pw, String prefix) {
227 super.dumpFront(pw, prefix);
228 pw.println(prefix + "className=" + className);
229 pw.println(prefix + "permission=" + permission
230 + " uid=" + uid);
231 pw.println(prefix + "taskAffinity=" + taskAffinity);
232 pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
233 pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
234 + " processName=" + processName);
235 pw.println(prefix + "sourceDir=" + sourceDir);
236 pw.println(prefix + "publicSourceDir=" + publicSourceDir);
237 pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
238 pw.println(prefix + "dataDir=" + dataDir);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700239 pw.println(prefix + "targetSdkVersion=" + targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 pw.println(prefix + "enabled=" + enabled);
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700241 pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
242 pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
243 pw.println(prefix + "supportsDensities=" + supportsDensities);
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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 }
292
293
294 public String toString() {
295 return "ApplicationInfo{"
296 + Integer.toHexString(System.identityHashCode(this))
297 + " " + packageName + "}";
298 }
299
300 public int describeContents() {
301 return 0;
302 }
303
304 public void writeToParcel(Parcel dest, int parcelableFlags) {
305 super.writeToParcel(dest, parcelableFlags);
306 dest.writeString(taskAffinity);
307 dest.writeString(permission);
308 dest.writeString(processName);
309 dest.writeString(className);
310 dest.writeInt(theme);
311 dest.writeInt(flags);
312 dest.writeString(sourceDir);
313 dest.writeString(publicSourceDir);
314 dest.writeStringArray(sharedLibraryFiles);
315 dest.writeString(dataDir);
316 dest.writeInt(uid);
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700317 dest.writeInt(targetSdkVersion);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 dest.writeInt(enabled ? 1 : 0);
319 dest.writeString(manageSpaceActivityName);
Christopher Tate181fafa2009-05-14 11:12:14 -0700320 dest.writeString(backupAgentName);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 dest.writeInt(descriptionRes);
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700322 dest.writeIntArray(supportsDensities);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 }
324
325 public static final Parcelable.Creator<ApplicationInfo> CREATOR
326 = new Parcelable.Creator<ApplicationInfo>() {
327 public ApplicationInfo createFromParcel(Parcel source) {
328 return new ApplicationInfo(source);
329 }
330 public ApplicationInfo[] newArray(int size) {
331 return new ApplicationInfo[size];
332 }
333 };
334
335 private ApplicationInfo(Parcel source) {
336 super(source);
337 taskAffinity = source.readString();
338 permission = source.readString();
339 processName = source.readString();
340 className = source.readString();
341 theme = source.readInt();
342 flags = source.readInt();
343 sourceDir = source.readString();
344 publicSourceDir = source.readString();
345 sharedLibraryFiles = source.readStringArray();
346 dataDir = source.readString();
347 uid = source.readInt();
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700348 targetSdkVersion = source.readInt();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800349 enabled = source.readInt() != 0;
350 manageSpaceActivityName = source.readString();
Christopher Tate181fafa2009-05-14 11:12:14 -0700351 backupAgentName = source.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 descriptionRes = source.readInt();
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700353 supportsDensities = source.createIntArray();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 }
Mitsuru Oshima8d112672009-04-27 12:01:23 -0700355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800356 /**
357 * Retrieve the textual description of the application. This
358 * will call back on the given PackageManager to load the description from
359 * the application.
360 *
361 * @param pm A PackageManager from which the label can be loaded; usually
362 * the PackageManager from which you originally retrieved this item.
363 *
364 * @return Returns a CharSequence containing the application's description.
365 * If there is no description, null is returned.
366 */
367 public CharSequence loadDescription(PackageManager pm) {
368 if (descriptionRes != 0) {
369 CharSequence label = pm.getText(packageName, descriptionRes, null);
370 if (label != null) {
371 return label;
372 }
373 }
374 return null;
375 }
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700376
377 /**
378 * Disable compatibility mode
379 *
380 * @hide
381 */
382 public void disableCompatibilityMode() {
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700383 flags |= FLAG_SUPPORTS_LARGE_SCREENS;
Mitsuru Oshimae5fb3282009-06-09 21:16:08 -0700384 supportsDensities = ANY_DENSITIES_ARRAY;
385 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386}