blob: 8d727ed9d0b4361d73ba16562cb8d4cd56f4b9bc [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001package 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 /**
118 * Value for {@link #flags}: default value for the corresponding ActivityInfo flag.
119 * {@hide}
120 */
121 public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;
122
123 /**
124 * Flags associated with the application. Any combination of
125 * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
126 * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and
127 * {@link #FLAG_ALLOW_TASK_REPARENTING}
128 * {@link #FLAG_ALLOW_CLEAR_USER_DATA}.
129 */
130 public int flags = 0;
131
132 /**
133 * Full path to the location of this package.
134 */
135 public String sourceDir;
136
137 /**
138 * Full path to the location of the publicly available parts of this package (i.e. the resources
139 * and manifest). For non-forward-locked apps this will be the same as {@link #sourceDir).
140 */
141 public String publicSourceDir;
142
143 /**
144 * Paths to all shared libraries this application is linked against. This
145 * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
146 * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
147 * the structure.
148 */
149 public String[] sharedLibraryFiles;
150
151 /**
152 * Full path to a directory assigned to the package for its persistent
153 * data.
154 */
155 public String dataDir;
156
157 /**
158 * The kernel user-ID that has been assigned to this application;
159 * currently this is not a unique ID (multiple applications can have
160 * the same uid).
161 */
162 public int uid;
163
164 /**
165 * When false, indicates that all components within this application are
166 * considered disabled, regardless of their individually set enabled status.
167 */
168 public boolean enabled = true;
169
170 public void dump(Printer pw, String prefix) {
171 super.dumpFront(pw, prefix);
172 pw.println(prefix + "className=" + className);
173 pw.println(prefix + "permission=" + permission
174 + " uid=" + uid);
175 pw.println(prefix + "taskAffinity=" + taskAffinity);
176 pw.println(prefix + "theme=0x" + Integer.toHexString(theme));
177 pw.println(prefix + "flags=0x" + Integer.toHexString(flags)
178 + " processName=" + processName);
179 pw.println(prefix + "sourceDir=" + sourceDir);
180 pw.println(prefix + "publicSourceDir=" + publicSourceDir);
181 pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);
182 pw.println(prefix + "dataDir=" + dataDir);
183 pw.println(prefix + "enabled=" + enabled);
184 pw.println(prefix+"manageSpaceActivityName="+manageSpaceActivityName);
185 pw.println(prefix+"description=0x"+Integer.toHexString(descriptionRes));
186 super.dumpBack(pw, prefix);
187 }
188
189 public static class DisplayNameComparator
190 implements Comparator<ApplicationInfo> {
191 public DisplayNameComparator(PackageManager pm) {
192 mPM = pm;
193 }
194
195 public final int compare(ApplicationInfo aa, ApplicationInfo ab) {
196 CharSequence sa = mPM.getApplicationLabel(aa);
197 if (sa == null) {
198 sa = aa.packageName;
199 }
200 CharSequence sb = mPM.getApplicationLabel(ab);
201 if (sb == null) {
202 sb = ab.packageName;
203 }
204
205 return sCollator.compare(sa.toString(), sb.toString());
206 }
207
208 private final Collator sCollator = Collator.getInstance();
209 private PackageManager mPM;
210 }
211
212 public ApplicationInfo() {
213 }
214
215 public ApplicationInfo(ApplicationInfo orig) {
216 super(orig);
217 taskAffinity = orig.taskAffinity;
218 permission = orig.permission;
219 processName = orig.processName;
220 className = orig.className;
221 theme = orig.theme;
222 flags = orig.flags;
223 sourceDir = orig.sourceDir;
224 publicSourceDir = orig.publicSourceDir;
225 sharedLibraryFiles = orig.sharedLibraryFiles;
226 dataDir = orig.dataDir;
227 uid = orig.uid;
228 enabled = orig.enabled;
229 manageSpaceActivityName = orig.manageSpaceActivityName;
230 descriptionRes = orig.descriptionRes;
231 }
232
233
234 public String toString() {
235 return "ApplicationInfo{"
236 + Integer.toHexString(System.identityHashCode(this))
237 + " " + packageName + "}";
238 }
239
240 public int describeContents() {
241 return 0;
242 }
243
244 public void writeToParcel(Parcel dest, int parcelableFlags) {
245 super.writeToParcel(dest, parcelableFlags);
246 dest.writeString(taskAffinity);
247 dest.writeString(permission);
248 dest.writeString(processName);
249 dest.writeString(className);
250 dest.writeInt(theme);
251 dest.writeInt(flags);
252 dest.writeString(sourceDir);
253 dest.writeString(publicSourceDir);
254 dest.writeStringArray(sharedLibraryFiles);
255 dest.writeString(dataDir);
256 dest.writeInt(uid);
257 dest.writeInt(enabled ? 1 : 0);
258 dest.writeString(manageSpaceActivityName);
259 dest.writeInt(descriptionRes);
260 }
261
262 public static final Parcelable.Creator<ApplicationInfo> CREATOR
263 = new Parcelable.Creator<ApplicationInfo>() {
264 public ApplicationInfo createFromParcel(Parcel source) {
265 return new ApplicationInfo(source);
266 }
267 public ApplicationInfo[] newArray(int size) {
268 return new ApplicationInfo[size];
269 }
270 };
271
272 private ApplicationInfo(Parcel source) {
273 super(source);
274 taskAffinity = source.readString();
275 permission = source.readString();
276 processName = source.readString();
277 className = source.readString();
278 theme = source.readInt();
279 flags = source.readInt();
280 sourceDir = source.readString();
281 publicSourceDir = source.readString();
282 sharedLibraryFiles = source.readStringArray();
283 dataDir = source.readString();
284 uid = source.readInt();
285 enabled = source.readInt() != 0;
286 manageSpaceActivityName = source.readString();
287 descriptionRes = source.readInt();
288 }
289
290 /**
291 * Retrieve the textual description of the application. This
292 * will call back on the given PackageManager to load the description from
293 * the application.
294 *
295 * @param pm A PackageManager from which the label can be loaded; usually
296 * the PackageManager from which you originally retrieved this item.
297 *
298 * @return Returns a CharSequence containing the application's description.
299 * If there is no description, null is returned.
300 */
301 public CharSequence loadDescription(PackageManager pm) {
302 if (descriptionRes != 0) {
303 CharSequence label = pm.getText(packageName, descriptionRes, null);
304 if (label != null) {
305 return label;
306 }
307 }
308 return null;
309 }
310}