ApplicationInfo.java revision 15a4d2ffd04dc6c70f2cd17dae12ac6bc14c69ab
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.Printer;
22
23import java.text.Collator;
24import java.util.Comparator;
25
26/**
27 * Information you can retrieve about a particular application.  This
28 * corresponds to information collected from the AndroidManifest.xml's
29 * <application> tag.
30 */
31public class ApplicationInfo extends PackageItemInfo implements Parcelable {
32
33    /**
34     * Default task affinity of all activities in this application. See
35     * {@link ActivityInfo#taskAffinity} for more information.  This comes
36     * from the "taskAffinity" attribute.
37     */
38    public String taskAffinity;
39
40    /**
41     * Optional name of a permission required to be able to access this
42     * application's components.  From the "permission" attribute.
43     */
44    public String permission;
45
46    /**
47     * The name of the process this application should run in.  From the
48     * "process" attribute or, if not set, the same as
49     * <var>packageName</var>.
50     */
51    public String processName;
52
53    /**
54     * Class implementing the Application object.  From the "class"
55     * attribute.
56     */
57    public String className;
58
59    /**
60     * A style resource identifier (in the package's resources) of the
61     * description of an application.  From the "description" attribute
62     * or, if not set, 0.
63     */
64    public int descriptionRes;
65
66    /**
67     * A style resource identifier (in the package's resources) of the
68     * default visual theme of the application.  From the "theme" attribute
69     * or, if not set, 0.
70     */
71    public int theme;
72
73    /**
74     * Class implementing the Application's manage space
75     * functionality.  From the "manageSpaceActivity"
76     * attribute. This is an optional attribute and will be null if
77     * applications don't specify it in their manifest
78     */
79    public String manageSpaceActivityName;
80
81    /**
82     * Class implementing the Application's backup functionality.  From
83     * the "backupAgent" attribute.  This is an optional attribute and
84     * will be null if the application does not specify it in its manifest.
85     *
86     * <p>If android:allowBackup is set to false, this attribute is ignored.
87     */
88    public String backupAgentName;
89
90    /**
91     * Value for {@link #flags}: if set, this application is installed in the
92     * device's system image.
93     */
94    public static final int FLAG_SYSTEM = 1<<0;
95
96    /**
97     * Value for {@link #flags}: set to true if this application would like to
98     * allow debugging of its
99     * code, even when installed on a non-development system.  Comes
100     * from {@link android.R.styleable#AndroidManifestApplication_debuggable
101     * android:debuggable} of the &lt;application&gt; tag.
102     */
103    public static final int FLAG_DEBUGGABLE = 1<<1;
104
105    /**
106     * Value for {@link #flags}: set to true if this application has code
107     * associated with it.  Comes
108     * from {@link android.R.styleable#AndroidManifestApplication_hasCode
109     * android:hasCode} of the &lt;application&gt; tag.
110     */
111    public static final int FLAG_HAS_CODE = 1<<2;
112
113    /**
114     * Value for {@link #flags}: set to true if this application is persistent.
115     * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent
116     * android:persistent} of the &lt;application&gt; tag.
117     */
118    public static final int FLAG_PERSISTENT = 1<<3;
119
120    /**
121     * Value for {@link #flags}: set to true if this application holds the
122     * {@link android.Manifest.permission#FACTORY_TEST} permission and the
123     * device is running in factory test mode.
124     */
125    public static final int FLAG_FACTORY_TEST = 1<<4;
126
127    /**
128     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
129     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting
130     * android:allowTaskReparenting} of the &lt;application&gt; tag.
131     */
132    public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;
133
134    /**
135     * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
136     * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData
137     * android:allowClearUserData} of the &lt;application&gt; tag.
138     */
139    public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;
140
141    /**
142     * Value for {@link #flags}: this is set if this application has been
143     * install as an update to a built-in system application.
144     */
145    public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
146
147    /**
148     * Value for {@link #flags}: this is set of the application has specified
149     * {@link android.R.styleable#AndroidManifestApplication_testOnly
150     * android:testOnly} to be true.
151     */
152    public static final int FLAG_TEST_ONLY = 1<<8;
153
154    /**
155     * Value for {@link #flags}: true when the application's window can be
156     * reduced in size for smaller screens.  Corresponds to
157     * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens
158     * android:smallScreens}.
159     */
160    public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;
161
162    /**
163     * Value for {@link #flags}: true when the application's window can be
164     * displayed on normal screens.  Corresponds to
165     * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens
166     * android:normalScreens}.
167     */
168    public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;
169
170    /**
171     * Value for {@link #flags}: true when the application's window can be
172     * increased in size for larger screens.  Corresponds to
173     * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens
174     * android:smallScreens}.
175     */
176    public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;
177
178    /**
179     * Value for {@link #flags}: true when the application knows how to adjust
180     * its UI for different screen sizes.  Corresponds to
181     * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable
182     * android:resizeable}.
183     */
184    public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;
185
186    /**
187     * Value for {@link #flags}: true when the application knows how to
188     * accomodate different screen densities.  Corresponds to
189     * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity
190     * android:anyDensity}.
191     */
192    public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;
193
194    /**
195     * Value for {@link #flags}: set to true if this application would like to
196     * request the VM to operate under the safe mode. Comes from
197     * {@link android.R.styleable#AndroidManifestApplication_safeMode
198     * android:safeMode} of the &lt;application&gt; tag.
199     */
200    public static final int FLAG_VM_SAFE_MODE = 1<<14;
201
202    /**
203     * Value for {@link #flags}: this is false if the application has set
204     * its android:allowBackup to false, true otherwise.
205     *
206     * {@hide}
207     */
208    public static final int FLAG_ALLOW_BACKUP = 1<<15;
209
210    /**
211     * Value for {@link #flags}: this is false if the application has set
212     * its android:killAfterRestore to false, true otherwise.
213     *
214     * <p>If android:allowBackup is set to false or no android:backupAgent
215     * is specified, this flag will be ignored.
216     *
217     * {@hide}
218     */
219    public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
220
221    /**
222     * Value for {@link #flags}: this is true if the application has set
223     * its android:restoreNeedsApplication to true, false otherwise.
224     *
225     * <p>If android:allowBackup is set to false or no android:backupAgent
226     * is specified, this flag will be ignored.
227     *
228     * {@hide}
229     */
230    public static final int FLAG_RESTORE_NEEDS_APPLICATION = 1<<17;
231
232    /**
233     * Value for {@link #flags}: this is true if the application has set
234     * its android:neverEncrypt to true, false otherwise. It is used to specify
235     * that this package specifically "opts-out" of a secured file system solution,
236     * and will always store its data in-the-clear.
237     *
238     * {@hide}
239     */
240    public static final int FLAG_NEVER_ENCRYPT = 1<<18;
241
242    /**
243     * Value for {@link #flags}: Set to true if the application has been
244     * installed using the forward lock option.
245     *
246     * {@hide}
247     */
248    public static final int FLAG_FORWARD_LOCK = 1<<19;
249
250    /**
251     * Value for {@link #flags}: Set to true if the application is
252     * currently installed on the sdcard.
253     *
254     * {@hide}
255     */
256    public static final int FLAG_EXTERNAL_STORAGE = 1<<20;
257
258    /**
259     * Value for {@link #flags}: Set to true if the application is
260     * native-debuggable, i.e. embeds a gdbserver binary in its .apk
261     *
262     * {@hide}
263     */
264    public static final int FLAG_NATIVE_DEBUGGABLE = 1<<21;
265
266    /**
267     * Value for {@link #flags}: Set to true if the application's backup
268     * agent claims to be able to handle restore data even "from the future,"
269     * i.e. from versions of the application with a versionCode greater than
270     * the one currently installed on the device.
271     *
272     * <p>If android:allowBackup is set to false or no android:backupAgent
273     * is specified, this flag will be ignored.
274     *
275     * {@hide}
276     */
277    public static final int FLAG_RESTORE_ANY_VERSION = 1<<22;
278
279    /**
280     * Flags associated with the application.  Any combination of
281     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
282     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
283     * {@link #FLAG_ALLOW_TASK_REPARENTING}
284     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
285     * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
286     * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
287     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS},
288     * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE}
289     */
290    public int flags = 0;
291
292    /**
293     * Full path to the location of this package.
294     */
295    public String sourceDir;
296
297    /**
298     * Full path to the location of the publicly available parts of this
299     * package (i.e. the primary resource package and manifest).  For
300     * non-forward-locked apps this will be the same as {@link #sourceDir).
301     */
302    public String publicSourceDir;
303
304    /**
305     * Full paths to the locations of extra resource packages this application
306     * uses. This field is only used if there are extra resource packages,
307     * otherwise it is null.
308     *
309     * {@hide}
310     */
311    public String[] resourceDirs;
312
313    /**
314     * Paths to all shared libraries this application is linked against.  This
315     * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
316     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
317     * the structure.
318     */
319    public String[] sharedLibraryFiles;
320
321    /**
322     * Full path to a directory assigned to the package for its persistent
323     * data.
324     */
325    public String dataDir;
326
327    /**
328     * The kernel user-ID that has been assigned to this application;
329     * currently this is not a unique ID (multiple applications can have
330     * the same uid).
331     */
332    public int uid;
333
334    /**
335     * The minimum SDK version this application targets.  It may run on earlier
336     * versions, but it knows how to work with any new behavior added at this
337     * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
338     * if this is a development build and the app is targeting that.  You should
339     * compare that this number is >= the SDK version number at which your
340     * behavior was introduced.
341     */
342    public int targetSdkVersion;
343
344    /**
345     * When false, indicates that all components within this application are
346     * considered disabled, regardless of their individually set enabled status.
347     */
348    public boolean enabled = true;
349
350    public void dump(Printer pw, String prefix) {
351        super.dumpFront(pw, prefix);
352        if (className != null) {
353            pw.println(prefix + "className=" + className);
354        }
355        if (permission != null) {
356            pw.println(prefix + "permission=" + permission);
357        }
358        pw.println(prefix + "uid=" + uid + " taskAffinity=" + taskAffinity);
359        if (theme != 0) {
360            pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
361        }
362        pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
363                + " processName=" + processName);
364        pw.println(prefix + "sourceDir=" + sourceDir);
365        pw.println(prefix + "publicSourceDir=" + publicSourceDir);
366        pw.println(prefix + "resourceDirs=" + resourceDirs);
367        pw.println(prefix + "dataDir=" + dataDir);
368        if (sharedLibraryFiles != null) {
369            pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
370        }
371        pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion);
372        if (manageSpaceActivityName != null) {
373            pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
374        }
375        if (descriptionRes != 0) {
376            pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
377        }
378        super.dumpBack(pw, prefix);
379    }
380
381    public static class DisplayNameComparator
382            implements Comparator<ApplicationInfo> {
383        public DisplayNameComparator(PackageManager pm) {
384            mPM = pm;
385        }
386
387        public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
388            CharSequence  sa = mPM.getApplicationLabel(aa);
389            if (sa == null) {
390                sa = aa.packageName;
391            }
392            CharSequence  sb = mPM.getApplicationLabel(ab);
393            if (sb == null) {
394                sb = ab.packageName;
395            }
396
397            return sCollator.compare(sa.toString(), sb.toString());
398        }
399
400        private final Collator   sCollator = Collator.getInstance();
401        private PackageManager   mPM;
402    }
403
404    public ApplicationInfo() {
405    }
406
407    public ApplicationInfo(ApplicationInfo orig) {
408        super(orig);
409        taskAffinity = orig.taskAffinity;
410        permission = orig.permission;
411        processName = orig.processName;
412        className = orig.className;
413        theme = orig.theme;
414        flags = orig.flags;
415        sourceDir = orig.sourceDir;
416        publicSourceDir = orig.publicSourceDir;
417        resourceDirs = orig.resourceDirs;
418        sharedLibraryFiles = orig.sharedLibraryFiles;
419        dataDir = orig.dataDir;
420        uid = orig.uid;
421        targetSdkVersion = orig.targetSdkVersion;
422        enabled = orig.enabled;
423        manageSpaceActivityName = orig.manageSpaceActivityName;
424        descriptionRes = orig.descriptionRes;
425    }
426
427
428    public String toString() {
429        return "ApplicationInfo{"
430            + Integer.toHexString(System.identityHashCode(this))
431            + " " + packageName + "}";
432    }
433
434    public int describeContents() {
435        return 0;
436    }
437
438    public void writeToParcel(Parcel dest, int parcelableFlags) {
439        super.writeToParcel(dest, parcelableFlags);
440        dest.writeString(taskAffinity);
441        dest.writeString(permission);
442        dest.writeString(processName);
443        dest.writeString(className);
444        dest.writeInt(theme);
445        dest.writeInt(flags);
446        dest.writeString(sourceDir);
447        dest.writeString(publicSourceDir);
448        dest.writeStringArray(resourceDirs);
449        dest.writeStringArray(sharedLibraryFiles);
450        dest.writeString(dataDir);
451        dest.writeInt(uid);
452        dest.writeInt(targetSdkVersion);
453        dest.writeInt(enabled ? 1 : 0);
454        dest.writeString(manageSpaceActivityName);
455        dest.writeString(backupAgentName);
456        dest.writeInt(descriptionRes);
457    }
458
459    public static final Parcelable.Creator<ApplicationInfo> CREATOR
460            = new Parcelable.Creator<ApplicationInfo>() {
461        public ApplicationInfo createFromParcel(Parcel source) {
462            return new ApplicationInfo(source);
463        }
464        public ApplicationInfo[] newArray(int size) {
465            return new ApplicationInfo[size];
466        }
467    };
468
469    private ApplicationInfo(Parcel source) {
470        super(source);
471        taskAffinity = source.readString();
472        permission = source.readString();
473        processName = source.readString();
474        className = source.readString();
475        theme = source.readInt();
476        flags = source.readInt();
477        sourceDir = source.readString();
478        publicSourceDir = source.readString();
479        resourceDirs = source.readStringArray();
480        sharedLibraryFiles = source.readStringArray();
481        dataDir = source.readString();
482        uid = source.readInt();
483        targetSdkVersion = source.readInt();
484        enabled = source.readInt() != 0;
485        manageSpaceActivityName = source.readString();
486        backupAgentName = source.readString();
487        descriptionRes = source.readInt();
488    }
489
490    /**
491     * Retrieve the textual description of the application.  This
492     * will call back on the given PackageManager to load the description from
493     * the application.
494     *
495     * @param pm A PackageManager from which the label can be loaded; usually
496     * the PackageManager from which you originally retrieved this item.
497     *
498     * @return Returns a CharSequence containing the application's description.
499     * If there is no description, null is returned.
500     */
501    public CharSequence loadDescription(PackageManager pm) {
502        if (descriptionRes != 0) {
503            CharSequence label = pm.getText(packageName, descriptionRes, null);
504            if (label != null) {
505                return label;
506            }
507        }
508        return null;
509    }
510
511    /**
512     * Disable compatibility mode
513     *
514     * @hide
515     */
516    public void disableCompatibilityMode() {
517        flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
518                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
519                FLAG_SUPPORTS_SCREEN_DENSITIES);
520    }
521}
522