ApplicationInfo.java revision 11b822d2a91ea17c34c0cb1c11e80a9a30d72864
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 set
135     * its android:targetSdkVersion to something >= the current SDK version.
136     */
137    public static final int FLAG_TEST_ONLY = 1<<8;
138
139    /**
140     * Value for {@link #flags}: true when the application's window can be
141     * reduced in size for smaller screens.  Corresponds to
142     * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
143     * android:smallScreens}.
144     */
145    public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
146
147    /**
148     * Value for {@link #flags}: true when the application's window can be
149     * displayed on normal screens.  Corresponds to
150     * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
151     * android:normalScreens}.
152     */
153    public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
154
155    /**
156     * Value for {@link #flags}: true when the application's window can be
157     * increased in size for larger screens.  Corresponds to
158     * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
159     * android:smallScreens}.
160     */
161    public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
162
163    /**
164     * Value for {@link #flags}: true when the application knows how to adjust
165     * its UI for different screen sizes.  Corresponds to
166     * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
167     * android:resizeable}.
168     */
169    public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
170
171    /**
172     * Value for {@link #flags}: true when the application knows how to
173     * accomodate different screen densities.  Corresponds to
174     * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
175     * android:anyDensity}.
176     */
177    public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
178
179    /**
180     * Value for {@link #flags}: this is false if the application has set
181     * its android:allowBackup to false, true otherwise.
182     *
183     * {@hide}
184     */
185    public static final int FLAG_ALLOW_BACKUP = 1<<14;
186
187    /**
188     * Flags associated with the application.  Any combination of
189     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
190     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
191     * {@link #FLAG_ALLOW_TASK_REPARENTING}
192     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
193     * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
194     * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
195     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS}.
196     */
197    public int flags = 0;
198
199    /**
200     * Full path to the location of this package.
201     */
202    public String sourceDir;
203
204    /**
205     * Full path to the location of the publicly available parts of this package (i.e. the resources
206     * and manifest).  For non-forward-locked apps this will be the same as {@link #sourceDir).
207     */
208    public String publicSourceDir;
209
210    /**
211     * Paths to all shared libraries this application is linked against.  This
212     * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
213     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
214     * the structure.
215     */
216    public String[] sharedLibraryFiles;
217
218    /**
219     * Full path to a directory assigned to the package for its persistent
220     * data.
221     */
222    public String dataDir;
223
224    /**
225     * The kernel user-ID that has been assigned to this application;
226     * currently this is not a unique ID (multiple applications can have
227     * the same uid).
228     */
229    public int uid;
230
231    /**
232     * The minimum SDK version this application targets.  It may run on earilier
233     * versions, but it knows how to work with any new behavior added at this
234     * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
235     * if this is a development build and the app is targeting that.  You should
236     * compare that this number is >= the SDK version number at which your
237     * behavior was introduced.
238     */
239    public int targetSdkVersion;
240
241    /**
242     * When false, indicates that all components within this application are
243     * considered disabled, regardless of their individually set enabled status.
244     */
245    public boolean enabled = true;
246
247    public void dump(Printer pw, String prefix) {
248        super.dumpFront(pw, prefix);
249        pw.println(prefix + "className=" + className);
250        pw.println(prefix + "permission=" + permission
251                + " uid=" + uid);
252        pw.println(prefix + "taskAffinity=" + taskAffinity);
253        pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
254        pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
255                + " processName=" + processName);
256        pw.println(prefix + "sourceDir=" + sourceDir);
257        pw.println(prefix + "publicSourceDir=" + publicSourceDir);
258        pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
259        pw.println(prefix + "dataDir=" + dataDir);
260        pw.println(prefix + "targetSdkVersion=" + targetSdkVersion);
261        pw.println(prefix + "enabled=" + enabled);
262        pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
263        pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
264        super.dumpBack(pw, prefix);
265    }
266
267    public static class DisplayNameComparator
268            implements Comparator<ApplicationInfo> {
269        public DisplayNameComparator(PackageManager pm) {
270            mPM = pm;
271        }
272
273        public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
274            CharSequence  sa = mPM.getApplicationLabel(aa);
275            if (sa == null) {
276                sa = aa.packageName;
277            }
278            CharSequence  sb = mPM.getApplicationLabel(ab);
279            if (sb == null) {
280                sb = ab.packageName;
281            }
282
283            return sCollator.compare(sa.toString(), sb.toString());
284        }
285
286        private final Collator   sCollator = Collator.getInstance();
287        private PackageManager   mPM;
288    }
289
290    public ApplicationInfo() {
291    }
292
293    public ApplicationInfo(ApplicationInfo orig) {
294        super(orig);
295        taskAffinity = orig.taskAffinity;
296        permission = orig.permission;
297        processName = orig.processName;
298        className = orig.className;
299        theme = orig.theme;
300        flags = orig.flags;
301        sourceDir = orig.sourceDir;
302        publicSourceDir = orig.publicSourceDir;
303        sharedLibraryFiles = orig.sharedLibraryFiles;
304        dataDir = orig.dataDir;
305        uid = orig.uid;
306        targetSdkVersion = orig.targetSdkVersion;
307        enabled = orig.enabled;
308        manageSpaceActivityName = orig.manageSpaceActivityName;
309        descriptionRes = orig.descriptionRes;
310    }
311
312
313    public String toString() {
314        return "ApplicationInfo{"
315            + Integer.toHexString(System.identityHashCode(this))
316            + " " + packageName + "}";
317    }
318
319    public int describeContents() {
320        return 0;
321    }
322
323    public void writeToParcel(Parcel dest, int parcelableFlags) {
324        super.writeToParcel(dest, parcelableFlags);
325        dest.writeString(taskAffinity);
326        dest.writeString(permission);
327        dest.writeString(processName);
328        dest.writeString(className);
329        dest.writeInt(theme);
330        dest.writeInt(flags);
331        dest.writeString(sourceDir);
332        dest.writeString(publicSourceDir);
333        dest.writeStringArray(sharedLibraryFiles);
334        dest.writeString(dataDir);
335        dest.writeInt(uid);
336        dest.writeInt(targetSdkVersion);
337        dest.writeInt(enabled ? 1 : 0);
338        dest.writeString(manageSpaceActivityName);
339        dest.writeString(backupAgentName);
340        dest.writeInt(descriptionRes);
341    }
342
343    public static final Parcelable.Creator<ApplicationInfo> CREATOR
344            = new Parcelable.Creator<ApplicationInfo>() {
345        public ApplicationInfo createFromParcel(Parcel source) {
346            return new ApplicationInfo(source);
347        }
348        public ApplicationInfo[] newArray(int size) {
349            return new ApplicationInfo[size];
350        }
351    };
352
353    private ApplicationInfo(Parcel source) {
354        super(source);
355        taskAffinity = source.readString();
356        permission = source.readString();
357        processName = source.readString();
358        className = source.readString();
359        theme = source.readInt();
360        flags = source.readInt();
361        sourceDir = source.readString();
362        publicSourceDir = source.readString();
363        sharedLibraryFiles = source.readStringArray();
364        dataDir = source.readString();
365        uid = source.readInt();
366        targetSdkVersion = source.readInt();
367        enabled = source.readInt() != 0;
368        manageSpaceActivityName = source.readString();
369        backupAgentName = source.readString();
370        descriptionRes = source.readInt();
371    }
372
373    /**
374     * Retrieve the textual description of the application.  This
375     * will call back on the given PackageManager to load the description from
376     * the application.
377     *
378     * @param pm A PackageManager from which the label can be loaded; usually
379     * the PackageManager from which you originally retrieved this item.
380     *
381     * @return Returns a CharSequence containing the application's description.
382     * If there is no description, null is returned.
383     */
384    public CharSequence loadDescription(PackageManager pm) {
385        if (descriptionRes != 0) {
386            CharSequence label = pm.getText(packageName, descriptionRes, null);
387            if (label != null) {
388                return label;
389            }
390        }
391        return null;
392    }
393
394    /**
395     * Disable compatibility mode
396     *
397     * @hide
398     */
399    public void disableCompatibilityMode() {
400        flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
401                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
402                FLAG_SUPPORTS_SCREEN_DENSITIES);
403    }
404}
405