ApplicationInfo.java revision a96cbb435d7b2197ab2b61fd98d14cbd6e0c5c3d
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     * application's dont specify it in their manifest
62     */
63    public String manageSpaceActivityName;
64
65    /**
66     * Value for {@link #flags}: if set, this application is installed in the
67     * device's system image.
68     */
69    public static final int FLAG_SYSTEM = 1<<0;
70
71    /**
72     * Value for {@link #flags}: set to true if this application would like to
73     * allow debugging of its
74     * code, even when installed on a non-development system.  Comes
75     * from {@link android.R.styleable#AndroidManifestApplication_debuggable
76     * android:debuggable} of the &lt;application&gt; tag.
77     */
78    public static final int FLAG_DEBUGGABLE = 1<<1;
79
80    /**
81     * Value for {@link #flags}: set to true if this application has code
82     * associated with it.  Comes
83     * from {@link android.R.styleable#AndroidManifestApplication_hasCode
84     * android:hasCode} of the &lt;application&gt; tag.
85     */
86    public static final int FLAG_HAS_CODE = 1<<2;
87
88    /**
89     * Value for {@link #flags}: set to true if this application is persistent.
90     * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
91     * android:persistent} of the &lt;application&gt; tag.
92     */
93    public static final int FLAG_PERSISTENT = 1<<3;
94
95    /**
96     * Value for {@link #flags}: set to true iif this application holds the
97     * {@link android.Manifest.permission#FACTORY_TEST} permission and the
98     * device is running in factory test mode.
99     */
100    public static final int FLAG_FACTORY_TEST = 1<<4;
101
102    /**
103     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
104     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
105     * android:allowTaskReparenting} of the &lt;application&gt; tag.
106     */
107    public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
108
109    /**
110     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
111     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
112     * android:allowClearUserData} of the &lt;application&gt; tag.
113     */
114    public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
115
116    /**
117     * Value for {@link #flags}: this is set if this application has been
118     * install as an update to a built-in system application.
119     */
120    public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
121
122    /**
123     * Value for {@link #flags}: this is set of the application has set
124     * its android:targetSdkVersion to something >= the current SDK version.
125     */
126    public static final int FLAG_TEST_ONLY = 1<<8;
127
128    /**
129     * Flags associated with the application.  Any combination of
130     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
131     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
132     * {@link #FLAG_ALLOW_TASK_REPARENTING}
133     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
134     * {@link #FLAG_TEST_ONLY}.
135     */
136    public int flags = 0;
137
138    /**
139     * Full path to the location of this package.
140     */
141    public String sourceDir;
142
143    /**
144     * Full path to the location of the publicly available parts of this package (i.e. the resources
145     * and manifest).  For non-forward-locked apps this will be the same as {@link #sourceDir).
146     */
147    public String publicSourceDir;
148
149    /**
150     * Paths to all shared libraries this application is linked against.  This
151     * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
152     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
153     * the structure.
154     */
155    public String[] sharedLibraryFiles;
156
157    /**
158     * Full path to a directory assigned to the package for its persistent
159     * data.
160     */
161    public String dataDir;
162
163    /**
164     * The kernel user-ID that has been assigned to this application;
165     * currently this is not a unique ID (multiple applications can have
166     * the same uid).
167     */
168    public int uid;
169
170
171    /**
172     * The list of densities in DPI that application supprots. This
173     * field is only set if the {@link PackageManager#GET_SUPPORTS_DENSITIES} flag was
174     * used when retrieving the structure.
175     */
176    public int[] supportsDensities;
177
178    /**
179     * The minimum SDK version this application targets.  It may run on earilier
180     * versions, but it knows how to work with any new behavior added at this
181     * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
182     * if this is a development build and the app is targeting that.  You should
183     * compare that this number is >= the SDK version number at which your
184     * behavior was introduced.
185     */
186    public int targetSdkVersion;
187
188    /**
189     * When false, indicates that all components within this application are
190     * considered disabled, regardless of their individually set enabled status.
191     */
192    public boolean enabled = true;
193
194    public void dump(Printer pw, String prefix) {
195        super.dumpFront(pw, prefix);
196        pw.println(prefix + "className=" + className);
197        pw.println(prefix + "permission=" + permission
198                + " uid=" + uid);
199        pw.println(prefix + "taskAffinity=" + taskAffinity);
200        pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
201        pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
202                + " processName=" + processName);
203        pw.println(prefix + "sourceDir=" + sourceDir);
204        pw.println(prefix + "publicSourceDir=" + publicSourceDir);
205        pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
206        pw.println(prefix + "dataDir=" + dataDir);
207        pw.println(prefix + "targetSdkVersion=" + targetSdkVersion);
208        pw.println(prefix + "enabled=" + enabled);
209        pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
210        pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
211        pw.println(prefix + "supportsDensities=" + supportsDensities);
212        super.dumpBack(pw, prefix);
213    }
214
215    public static class DisplayNameComparator
216            implements Comparator<ApplicationInfo> {
217        public DisplayNameComparator(PackageManager pm) {
218            mPM = pm;
219        }
220
221        public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
222            CharSequence  sa = mPM.getApplicationLabel(aa);
223            if (sa == null) {
224                sa = aa.packageName;
225            }
226            CharSequence  sb = mPM.getApplicationLabel(ab);
227            if (sb == null) {
228                sb = ab.packageName;
229            }
230
231            return sCollator.compare(sa.toString(), sb.toString());
232        }
233
234        private final Collator   sCollator = Collator.getInstance();
235        private PackageManager   mPM;
236    }
237
238    public ApplicationInfo() {
239    }
240
241    public ApplicationInfo(ApplicationInfo orig) {
242        super(orig);
243        taskAffinity = orig.taskAffinity;
244        permission = orig.permission;
245        processName = orig.processName;
246        className = orig.className;
247        theme = orig.theme;
248        flags = orig.flags;
249        sourceDir = orig.sourceDir;
250        publicSourceDir = orig.publicSourceDir;
251        sharedLibraryFiles = orig.sharedLibraryFiles;
252        dataDir = orig.dataDir;
253        uid = orig.uid;
254        targetSdkVersion = orig.targetSdkVersion;
255        enabled = orig.enabled;
256        manageSpaceActivityName = orig.manageSpaceActivityName;
257        descriptionRes = orig.descriptionRes;
258        supportsDensities = orig.supportsDensities;
259    }
260
261
262    public String toString() {
263        return "ApplicationInfo{"
264            + Integer.toHexString(System.identityHashCode(this))
265            + " " + packageName + "}";
266    }
267
268    public int describeContents() {
269        return 0;
270    }
271
272    public void writeToParcel(Parcel dest, int parcelableFlags) {
273        super.writeToParcel(dest, parcelableFlags);
274        dest.writeString(taskAffinity);
275        dest.writeString(permission);
276        dest.writeString(processName);
277        dest.writeString(className);
278        dest.writeInt(theme);
279        dest.writeInt(flags);
280        dest.writeString(sourceDir);
281        dest.writeString(publicSourceDir);
282        dest.writeStringArray(sharedLibraryFiles);
283        dest.writeString(dataDir);
284        dest.writeInt(uid);
285        dest.writeInt(targetSdkVersion);
286        dest.writeInt(enabled ? 1 : 0);
287        dest.writeString(manageSpaceActivityName);
288        dest.writeInt(descriptionRes);
289        dest.writeIntArray(supportsDensities);
290    }
291
292    public static final Parcelable.Creator<ApplicationInfo> CREATOR
293            = new Parcelable.Creator<ApplicationInfo>() {
294        public ApplicationInfo createFromParcel(Parcel source) {
295            return new ApplicationInfo(source);
296        }
297        public ApplicationInfo[] newArray(int size) {
298            return new ApplicationInfo[size];
299        }
300    };
301
302    private ApplicationInfo(Parcel source) {
303        super(source);
304        taskAffinity = source.readString();
305        permission = source.readString();
306        processName = source.readString();
307        className = source.readString();
308        theme = source.readInt();
309        flags = source.readInt();
310        sourceDir = source.readString();
311        publicSourceDir = source.readString();
312        sharedLibraryFiles = source.readStringArray();
313        dataDir = source.readString();
314        uid = source.readInt();
315        targetSdkVersion = source.readInt();
316        enabled = source.readInt() != 0;
317        manageSpaceActivityName = source.readString();
318        descriptionRes = source.readInt();
319        supportsDensities = source.createIntArray();
320    }
321
322    /**
323     * Retrieve the textual description of the application.  This
324     * will call back on the given PackageManager to load the description from
325     * the application.
326     *
327     * @param pm A PackageManager from which the label can be loaded; usually
328     * the PackageManager from which you originally retrieved this item.
329     *
330     * @return Returns a CharSequence containing the application's description.
331     * If there is no description, null is returned.
332     */
333    public CharSequence loadDescription(PackageManager pm) {
334        if (descriptionRes != 0) {
335            CharSequence label = pm.getText(packageName, descriptionRes, null);
336            if (label != null) {
337                return label;
338            }
339        }
340        return null;
341    }
342}
343