ApplicationInfo.java revision 1f4df90bfab8ca42eabe95f19eadff3432eee7fd
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_vmSafeMode
198     * android:vmSafeMode} 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}: set to <code>false</code> if the application does not wish
204     * to permit any OS-driven backups of its data; <code>true</code> otherwise.
205     *
206     * <p>Comes from the
207     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
208     * attribute of the &lt;application&gt; tag.
209     */
210    public static final int FLAG_ALLOW_BACKUP = 1<<15;
211
212    /**
213     * Value for {@link #flags}: set to <code>false</code> if the application must be kept
214     * in memory following a full-system restore operation; <code>true</code> otherwise.
215     * Ordinarily, during a full system restore operation each application is shut down
216     * following execution of its agent's onRestore() method.  Setting this attribute to
217     * <code>false</code> prevents this.  Most applications will not need to set this attribute.
218     *
219     * <p>If
220     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
221     * is set to <code>false</code> or no
222     * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
223     * is specified, this flag will be ignored.
224     *
225     * <p>Comes from the
226     * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore}
227     * attribute of the &lt;application&gt; tag.
228     */
229    public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;
230
231    /**
232     * Value for {@link #flags}: Set to <code>true</code> if the application's backup
233     * agent claims to be able to handle restore data even "from the future,"
234     * i.e. from versions of the application with a versionCode greater than
235     * the one currently installed on the device.  <i>Use with caution!</i>  By default
236     * this attribute is <code>false</code> and the Backup Manager will ensure that data
237     * from "future" versions of the application are never supplied during a restore operation.
238     *
239     * <p>If
240     * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup}
241     * is set to <code>false</code> or no
242     * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent}
243     * is specified, this flag will be ignored.
244     *
245     * <p>Comes from the
246     * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion}
247     * attribute of the &lt;application&gt; tag.
248     */
249    public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;
250
251    /**
252     * Value for {@link #flags}: Set to true if the application has been
253     * installed using the forward lock option.
254     *
255     * {@hide}
256     */
257    public static final int FLAG_FORWARD_LOCK = 1<<19;
258
259    /**
260     * Value for {@link #flags}: Set to true if the application is
261     * currently installed on the sdcard.
262     *
263     * {@hide}
264     */
265    public static final int FLAG_EXTERNAL_STORAGE = 1<<20;
266
267    /**
268     * Value for {@link #flags}: Set to true if the application is
269     * native-debuggable, i.e. embeds a gdbserver binary in its .apk
270     *
271     * {@hide}
272     */
273    public static final int FLAG_NATIVE_DEBUGGABLE = 1<<21;
274
275    /**
276     * Flags associated with the application.  Any combination of
277     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
278     * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
279     * {@link #FLAG_ALLOW_TASK_REPARENTING}
280     * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP},
281     * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS},
282     * {@link #FLAG_SUPPORTS_NORMAL_SCREENS},
283     * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_RESIZEABLE_FOR_SCREENS},
284     * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE}
285     */
286    public int flags = 0;
287
288    /**
289     * Full path to the location of this package.
290     */
291    public String sourceDir;
292
293    /**
294     * Full path to the location of the publicly available parts of this
295     * package (i.e. the primary resource package and manifest).  For
296     * non-forward-locked apps this will be the same as {@link #sourceDir).
297     */
298    public String publicSourceDir;
299
300    /**
301     * Full paths to the locations of extra resource packages this application
302     * uses. This field is only used if there are extra resource packages,
303     * otherwise it is null.
304     *
305     * {@hide}
306     */
307    public String[] resourceDirs;
308
309    /**
310     * Paths to all shared libraries this application is linked against.  This
311     * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
312     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
313     * the structure.
314     */
315    public String[] sharedLibraryFiles;
316
317    /**
318     * Full path to a directory assigned to the package for its persistent
319     * data.
320     */
321    public String dataDir;
322
323    /**
324     * The kernel user-ID that has been assigned to this application;
325     * currently this is not a unique ID (multiple applications can have
326     * the same uid).
327     */
328    public int uid;
329
330    /**
331     * The minimum SDK version this application targets.  It may run on earlier
332     * versions, but it knows how to work with any new behavior added at this
333     * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT}
334     * if this is a development build and the app is targeting that.  You should
335     * compare that this number is >= the SDK version number at which your
336     * behavior was introduced.
337     */
338    public int targetSdkVersion;
339
340    /**
341     * When false, indicates that all components within this application are
342     * considered disabled, regardless of their individually set enabled status.
343     */
344    public boolean enabled = true;
345
346    public void dump(Printer pw, String prefix) {
347        super.dumpFront(pw, prefix);
348        if (className != null) {
349            pw.println(prefix + "className=" + className);
350        }
351        if (permission != null) {
352            pw.println(prefix + "permission=" + permission);
353        }
354        pw.println(prefix + "uid=" + uid + " taskAffinity=" + taskAffinity);
355        if (theme != 0) {
356            pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
357        }
358        pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
359                + " processName=" + processName);
360        pw.println(prefix + "sourceDir=" + sourceDir);
361        pw.println(prefix + "publicSourceDir=" + publicSourceDir);
362        pw.println(prefix + "resourceDirs=" + resourceDirs);
363        pw.println(prefix + "dataDir=" + dataDir);
364        if (sharedLibraryFiles != null) {
365            pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
366        }
367        pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion);
368        if (manageSpaceActivityName != null) {
369            pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);
370        }
371        if (descriptionRes != 0) {
372            pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));
373        }
374        super.dumpBack(pw, prefix);
375    }
376
377    public static class DisplayNameComparator
378            implements Comparator<ApplicationInfo> {
379        public DisplayNameComparator(PackageManager pm) {
380            mPM = pm;
381        }
382
383        public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
384            CharSequence  sa = mPM.getApplicationLabel(aa);
385            if (sa == null) {
386                sa = aa.packageName;
387            }
388            CharSequence  sb = mPM.getApplicationLabel(ab);
389            if (sb == null) {
390                sb = ab.packageName;
391            }
392
393            return sCollator.compare(sa.toString(), sb.toString());
394        }
395
396        private final Collator   sCollator = Collator.getInstance();
397        private PackageManager   mPM;
398    }
399
400    public ApplicationInfo() {
401    }
402
403    public ApplicationInfo(ApplicationInfo orig) {
404        super(orig);
405        taskAffinity = orig.taskAffinity;
406        permission = orig.permission;
407        processName = orig.processName;
408        className = orig.className;
409        theme = orig.theme;
410        flags = orig.flags;
411        sourceDir = orig.sourceDir;
412        publicSourceDir = orig.publicSourceDir;
413        resourceDirs = orig.resourceDirs;
414        sharedLibraryFiles = orig.sharedLibraryFiles;
415        dataDir = orig.dataDir;
416        uid = orig.uid;
417        targetSdkVersion = orig.targetSdkVersion;
418        enabled = orig.enabled;
419        manageSpaceActivityName = orig.manageSpaceActivityName;
420        descriptionRes = orig.descriptionRes;
421    }
422
423
424    public String toString() {
425        return "ApplicationInfo{"
426            + Integer.toHexString(System.identityHashCode(this))
427            + " " + packageName + "}";
428    }
429
430    public int describeContents() {
431        return 0;
432    }
433
434    public void writeToParcel(Parcel dest, int parcelableFlags) {
435        super.writeToParcel(dest, parcelableFlags);
436        dest.writeString(taskAffinity);
437        dest.writeString(permission);
438        dest.writeString(processName);
439        dest.writeString(className);
440        dest.writeInt(theme);
441        dest.writeInt(flags);
442        dest.writeString(sourceDir);
443        dest.writeString(publicSourceDir);
444        dest.writeStringArray(resourceDirs);
445        dest.writeStringArray(sharedLibraryFiles);
446        dest.writeString(dataDir);
447        dest.writeInt(uid);
448        dest.writeInt(targetSdkVersion);
449        dest.writeInt(enabled ? 1 : 0);
450        dest.writeString(manageSpaceActivityName);
451        dest.writeString(backupAgentName);
452        dest.writeInt(descriptionRes);
453    }
454
455    public static final Parcelable.Creator<ApplicationInfo> CREATOR
456            = new Parcelable.Creator<ApplicationInfo>() {
457        public ApplicationInfo createFromParcel(Parcel source) {
458            return new ApplicationInfo(source);
459        }
460        public ApplicationInfo[] newArray(int size) {
461            return new ApplicationInfo[size];
462        }
463    };
464
465    private ApplicationInfo(Parcel source) {
466        super(source);
467        taskAffinity = source.readString();
468        permission = source.readString();
469        processName = source.readString();
470        className = source.readString();
471        theme = source.readInt();
472        flags = source.readInt();
473        sourceDir = source.readString();
474        publicSourceDir = source.readString();
475        resourceDirs = source.readStringArray();
476        sharedLibraryFiles = source.readStringArray();
477        dataDir = source.readString();
478        uid = source.readInt();
479        targetSdkVersion = source.readInt();
480        enabled = source.readInt() != 0;
481        manageSpaceActivityName = source.readString();
482        backupAgentName = source.readString();
483        descriptionRes = source.readInt();
484    }
485
486    /**
487     * Retrieve the textual description of the application.  This
488     * will call back on the given PackageManager to load the description from
489     * the application.
490     *
491     * @param pm A PackageManager from which the label can be loaded; usually
492     * the PackageManager from which you originally retrieved this item.
493     *
494     * @return Returns a CharSequence containing the application's description.
495     * If there is no description, null is returned.
496     */
497    public CharSequence loadDescription(PackageManager pm) {
498        if (descriptionRes != 0) {
499            CharSequence label = pm.getText(packageName, descriptionRes, null);
500            if (label != null) {
501                return label;
502            }
503        }
504        return null;
505    }
506
507    /**
508     * Disable compatibility mode
509     *
510     * @hide
511     */
512    public void disableCompatibilityMode() {
513        flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |
514                FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |
515                FLAG_SUPPORTS_SCREEN_DENSITIES);
516    }
517}
518