ApplicationInfo.java revision 1edab2b551995a8df25f4b533405d6003b8b8b66
1package 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
61     * applications don't specify it in their manifest
62     */
63    public String manageSpaceActivityName;
64
65    /**
66     * 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    /**
77     * 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    /**
107     * Value for {@link #flags}: set to true if this application holds the
108     * {@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
127    /**
128     * Value for {@link #flags}: this is set if this application has been
129     * install as an update to a built-in system application.
130     */
131    public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
132
133    /**
134     * 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.
137     */
138    public static final int FLAG_TEST_ONLY = 1<<8;
139
140    /**
141     * Value for {@link #flags}: true when the application's window can be
142     * reduced in size for smaller screens.  Corresponds to
143     * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
144     * android:smallScreens}.
145     */
146    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;
163
164    /**
165     * 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    /**
173     * 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    /**
181     * Value for {@link #flags}: this is false if the application has set
182     * its android:allowBackup to false, true otherwise.
183     *
184     * {@hide}
185     */
186    public static final int FLAG_ALLOW_BACKUP = 1<<14;
187
188    /**
189     * Value for {@link #flags}: this is false if the application has set
190     * its android:killAfterRestore to false, true otherwise.
191     *
192     * <p>If android:allowBackup is set to false or no android:backupAgent
193     * is specified, this flag will be ignored.
194     *
195     * {@hide}
196     */
197    public static final int FLAG_KILL_AFTER_RESTORE = 1<<15;
198
199    /**
200     * Value for {@link #flags}: this is true if the application has set
201     * its android:restoreNeedsApplication to true, false otherwise.
202     *
203     * <p>If android:allowBackup is set to false or no android:backupAgent
204     * is specified, this flag will be ignored.
205     *
206     * {@hide}
207     */
208    public static final int FLAG_RESTORE_NEEDS_APPLICATION = 1<<16;
209
210    /**
211     * Value for {@link #flags}: this is true if the application has set
212     * its android:neverEncrypt to true, false otherwise. It is used to specify
213     * that this package specifically "opts-out" of a secured file system solution,
214     * and will always store its data in-the-clear.
215     *
216     * {@hide}
217     */
218    public static final int FLAG_NEVER_ENCRYPT = 1<<17;
219
220    /**
221     * Value for {@link #flags}: Set to true if the application has been
222     * installed using the forward lock option.
223     *
224     * {@hide}
225     */
226    public static final int FLAG_FORWARD_LOCK = 1<<18;
227
228    /**
229     * Value for {@link #flags}: Set to true if the application is
230     * currently installed on the sdcard.
231     *
232     * {@hide}
233     */
234    public static final int FLAG_ON_SDCARD = 1<<19;
235
236    /**
237     * Value for {@link #flags}: Set to true if the application is
238     * native-debuggable, i.e. embeds a gdbserver binary in its .apk
239     *
240     * {@hide}
241     */
242    public static final int FLAG_NATIVE_DEBUGGABLE = 1<<20;
243
244    /**
245     * Flags associated with the application.  Any combination of
246     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
247     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
248     * {@link #FLAG_ALLOW_TASK_REPARENTING}
249     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
250     * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
251     * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
252     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS},
253     * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}
254     */
255    public int flags = 0;
256
257    /**
258     * Full path to the location of this package.
259     */
260    public String sourceDir;
261
262    /**
263     * Full path to the location of the publicly available parts of this
264     * package (i.e. the primary resource package and manifest).  For
265     * non-forward-locked apps this will be the same as {@link #sourceDir).
266     */
267    public String publicSourceDir;
268
269    /**
270     * Full paths to the locations of extra resource packages this application
271     * uses. This field is only used if there are extra resource packages,
272     * otherwise it is null.
273     */
274    public String[] resourceDirs;
275
276    /**
277     * Paths to all shared libraries this application is linked against.  This
278     * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
279     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
280     * the structure.
281     */
282    public String[] sharedLibraryFiles;
283
284    /**
285     * Full path to a directory assigned to the package for its persistent
286     * data.
287     */
288    public String dataDir;
289
290    /**
291     * The kernel user-ID that has been assigned to this application;
292     * currently this is not a unique ID (multiple applications can have
293     * the same uid).
294     */
295    public int uid;
296
297    /**
298     * The minimum SDK version this application targets.  It may run on earlier
299     * versions, but it knows how to work with any new behavior added at this
300     * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
301     * if this is a development build and the app is targeting that.  You should
302     * compare that this number is >= the SDK version number at which your
303     * behavior was introduced.
304     */
305    public int targetSdkVersion;
306
307    /**
308     * When false, indicates that all components within this application are
309     * considered disabled, regardless of their individually set enabled status.
310     */
311    public boolean enabled = true;
312
313    public void dump(Printer pw, String prefix) {
314        super.dumpFront(pw, prefix);
315        if (className != null) {
316            pw.println(prefix + "className=" + className);
317        }
318        if (permission != null) {
319            pw.println(prefix + "permission=" + permission);
320        }
321        pw.println(prefix + "uid=" + uid + " taskAffinity=" + taskAffinity);
322        if (theme != 0) {
323            pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
324        }
325        pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
326                + " processName=" + processName);
327        pw.println(prefix + "sourceDir=" + sourceDir);
328        pw.println(prefix + "publicSourceDir=" + publicSourceDir);
329        pw.println(prefix + "resourceDirs=" + resourceDirs);
330        pw.println(prefix + "dataDir=" + dataDir);
331        if (sharedLibraryFiles != null) {
332            pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
333        }
334        pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion);
335        if (manageSpaceActivityName != null) {
336            pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
337        }
338        if (descriptionRes != 0) {
339            pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
340        }
341        super.dumpBack(pw, prefix);
342    }
343
344    public static class DisplayNameComparator
345            implements Comparator<ApplicationInfo> {
346        public DisplayNameComparator(PackageManager pm) {
347            mPM = pm;
348        }
349
350        public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
351            CharSequence  sa = mPM.getApplicationLabel(aa);
352            if (sa == null) {
353                sa = aa.packageName;
354            }
355            CharSequence  sb = mPM.getApplicationLabel(ab);
356            if (sb == null) {
357                sb = ab.packageName;
358            }
359
360            return sCollator.compare(sa.toString(), sb.toString());
361        }
362
363        private final Collator   sCollator = Collator.getInstance();
364        private PackageManager   mPM;
365    }
366
367    public ApplicationInfo() {
368    }
369
370    public ApplicationInfo(ApplicationInfo orig) {
371        super(orig);
372        taskAffinity = orig.taskAffinity;
373        permission = orig.permission;
374        processName = orig.processName;
375        className = orig.className;
376        theme = orig.theme;
377        flags = orig.flags;
378        sourceDir = orig.sourceDir;
379        publicSourceDir = orig.publicSourceDir;
380        resourceDirs = orig.resourceDirs;
381        sharedLibraryFiles = orig.sharedLibraryFiles;
382        dataDir = orig.dataDir;
383        uid = orig.uid;
384        targetSdkVersion = orig.targetSdkVersion;
385        enabled = orig.enabled;
386        manageSpaceActivityName = orig.manageSpaceActivityName;
387        descriptionRes = orig.descriptionRes;
388    }
389
390
391    public String toString() {
392        return "ApplicationInfo{"
393            + Integer.toHexString(System.identityHashCode(this))
394            + " " + packageName + "}";
395    }
396
397    public int describeContents() {
398        return 0;
399    }
400
401    public void writeToParcel(Parcel dest, int parcelableFlags) {
402        super.writeToParcel(dest, parcelableFlags);
403        dest.writeString(taskAffinity);
404        dest.writeString(permission);
405        dest.writeString(processName);
406        dest.writeString(className);
407        dest.writeInt(theme);
408        dest.writeInt(flags);
409        dest.writeString(sourceDir);
410        dest.writeString(publicSourceDir);
411        dest.writeStringArray(resourceDirs);
412        dest.writeStringArray(sharedLibraryFiles);
413        dest.writeString(dataDir);
414        dest.writeInt(uid);
415        dest.writeInt(targetSdkVersion);
416        dest.writeInt(enabled ? 1 : 0);
417        dest.writeString(manageSpaceActivityName);
418        dest.writeString(backupAgentName);
419        dest.writeInt(descriptionRes);
420    }
421
422    public static final Parcelable.Creator<ApplicationInfo> CREATOR
423            = new Parcelable.Creator<ApplicationInfo>() {
424        public ApplicationInfo createFromParcel(Parcel source) {
425            return new ApplicationInfo(source);
426        }
427        public ApplicationInfo[] newArray(int size) {
428            return new ApplicationInfo[size];
429        }
430    };
431
432    private ApplicationInfo(Parcel source) {
433        super(source);
434        taskAffinity = source.readString();
435        permission = source.readString();
436        processName = source.readString();
437        className = source.readString();
438        theme = source.readInt();
439        flags = source.readInt();
440        sourceDir = source.readString();
441        publicSourceDir = source.readString();
442        resourceDirs = source.readStringArray();
443        sharedLibraryFiles = source.readStringArray();
444        dataDir = source.readString();
445        uid = source.readInt();
446        targetSdkVersion = source.readInt();
447        enabled = source.readInt() != 0;
448        manageSpaceActivityName = source.readString();
449        backupAgentName = source.readString();
450        descriptionRes = source.readInt();
451    }
452
453    /**
454     * Retrieve the textual description of the application.  This
455     * will call back on the given PackageManager to load the description from
456     * the application.
457     *
458     * @param pm A PackageManager from which the label can be loaded; usually
459     * the PackageManager from which you originally retrieved this item.
460     *
461     * @return Returns a CharSequence containing the application's description.
462     * If there is no description, null is returned.
463     */
464    public CharSequence loadDescription(PackageManager pm) {
465        if (descriptionRes != 0) {
466            CharSequence label = pm.getText(packageName, descriptionRes, null);
467            if (label != null) {
468                return label;
469            }
470        }
471        return null;
472    }
473
474    /**
475     * Disable compatibility mode
476     *
477     * @hide
478     */
479    public void disableCompatibilityMode() {
480        flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
481                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
482                FLAG_SUPPORTS_SCREEN_DENSITIES);
483    }
484}
485