PackageManager.java revision 49237345d83e62fdb9eb8d50b13ad086636a04fa
1/*
2 * Copyright (C) 2006 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.content.ComponentName;
20import android.content.Context;
21import android.content.Intent;
22import android.content.IntentFilter;
23import android.content.IntentSender;
24import android.content.res.Resources;
25import android.content.res.XmlResourceParser;
26import android.graphics.drawable.Drawable;
27import android.net.Uri;
28import android.util.AndroidException;
29import android.util.DisplayMetrics;
30
31import java.io.File;
32import java.util.List;
33
34/**
35 * Class for retrieving various kinds of information related to the application
36 * packages that are currently installed on the device.
37 *
38 * You can find this class through {@link Context#getPackageManager}.
39 */
40public abstract class PackageManager {
41
42    /**
43     * This exception is thrown when a given package, application, or component
44     * name can not be found.
45     */
46    public static class NameNotFoundException extends AndroidException {
47        public NameNotFoundException() {
48        }
49
50        public NameNotFoundException(String name) {
51            super(name);
52        }
53    }
54
55    /**
56     * {@link PackageInfo} flag: return information about
57     * activities in the package in {@link PackageInfo#activities}.
58     */
59    public static final int GET_ACTIVITIES              = 0x00000001;
60
61    /**
62     * {@link PackageInfo} flag: return information about
63     * intent receivers in the package in
64     * {@link PackageInfo#receivers}.
65     */
66    public static final int GET_RECEIVERS               = 0x00000002;
67
68    /**
69     * {@link PackageInfo} flag: return information about
70     * services in the package in {@link PackageInfo#services}.
71     */
72    public static final int GET_SERVICES                = 0x00000004;
73
74    /**
75     * {@link PackageInfo} flag: return information about
76     * content providers in the package in
77     * {@link PackageInfo#providers}.
78     */
79    public static final int GET_PROVIDERS               = 0x00000008;
80
81    /**
82     * {@link PackageInfo} flag: return information about
83     * instrumentation in the package in
84     * {@link PackageInfo#instrumentation}.
85     */
86    public static final int GET_INSTRUMENTATION         = 0x00000010;
87
88    /**
89     * {@link PackageInfo} flag: return information about the
90     * intent filters supported by the activity.
91     */
92    public static final int GET_INTENT_FILTERS          = 0x00000020;
93
94    /**
95     * {@link PackageInfo} flag: return information about the
96     * signatures included in the package.
97     */
98    public static final int GET_SIGNATURES          = 0x00000040;
99
100    /**
101     * {@link ResolveInfo} flag: return the IntentFilter that
102     * was matched for a particular ResolveInfo in
103     * {@link ResolveInfo#filter}.
104     */
105    public static final int GET_RESOLVED_FILTER         = 0x00000040;
106
107    /**
108     * {@link ComponentInfo} flag: return the {@link ComponentInfo#metaData}
109     * data {@link android.os.Bundle}s that are associated with a component.
110     * This applies for any API returning a ComponentInfo subclass.
111     */
112    public static final int GET_META_DATA               = 0x00000080;
113
114    /**
115     * {@link PackageInfo} flag: return the
116     * {@link PackageInfo#gids group ids} that are associated with an
117     * application.
118     * This applies for any API returning an PackageInfo class, either
119     * directly or nested inside of another.
120     */
121    public static final int GET_GIDS                    = 0x00000100;
122
123    /**
124     * {@link PackageInfo} flag: include disabled components in the returned info.
125     */
126    public static final int GET_DISABLED_COMPONENTS     = 0x00000200;
127
128    /**
129     * {@link ApplicationInfo} flag: return the
130     * {@link ApplicationInfo#sharedLibraryFiles paths to the shared libraries}
131     * that are associated with an application.
132     * This applies for any API returning an ApplicationInfo class, either
133     * directly or nested inside of another.
134     */
135    public static final int GET_SHARED_LIBRARY_FILES    = 0x00000400;
136
137    /**
138     * {@link ProviderInfo} flag: return the
139     * {@link ProviderInfo#uriPermissionPatterns URI permission patterns}
140     * that are associated with a content provider.
141     * This applies for any API returning an ProviderInfo class, either
142     * directly or nested inside of another.
143     */
144    public static final int GET_URI_PERMISSION_PATTERNS  = 0x00000800;
145    /**
146     * {@link PackageInfo} flag: return information about
147     * permissions in the package in
148     * {@link PackageInfo#permissions}.
149     */
150    public static final int GET_PERMISSIONS               = 0x00001000;
151
152    /**
153     * Flag parameter to retrieve all applications(even uninstalled ones) with data directories.
154     * This state could have resulted if applications have been deleted with flag
155     * DONT_DELETE_DATA
156     * with a possibility of being replaced or reinstalled in future
157     */
158    public static final int GET_UNINSTALLED_PACKAGES = 0x00002000;
159
160    /**
161     * {@link PackageInfo} flag: return information about
162     * hardware preferences in
163     * {@link PackageInfo#configPreferences PackageInfo.configPreferences} and
164     * requested features in {@link PackageInfo#reqFeatures
165     * PackageInfo.reqFeatures}.
166     */
167    public static final int GET_CONFIGURATIONS = 0x00004000;
168
169    /**
170     * Resolution and querying flag: if set, only filters that support the
171     * {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for
172     * matching.  This is a synonym for including the CATEGORY_DEFAULT in your
173     * supplied Intent.
174     */
175    public static final int MATCH_DEFAULT_ONLY   = 0x00010000;
176
177    /**
178     * Permission check result: this is returned by {@link #checkPermission}
179     * if the permission has been granted to the given package.
180     */
181    public static final int PERMISSION_GRANTED = 0;
182
183    /**
184     * Permission check result: this is returned by {@link #checkPermission}
185     * if the permission has not been granted to the given package.
186     */
187    public static final int PERMISSION_DENIED = -1;
188
189    /**
190     * Signature check result: this is returned by {@link #checkSignatures}
191     * if the two packages have a matching signature.
192     */
193    public static final int SIGNATURE_MATCH = 0;
194
195    /**
196     * Signature check result: this is returned by {@link #checkSignatures}
197     * if neither of the two packages is signed.
198     */
199    public static final int SIGNATURE_NEITHER_SIGNED = 1;
200
201    /**
202     * Signature check result: this is returned by {@link #checkSignatures}
203     * if the first package is not signed, but the second is.
204     */
205    public static final int SIGNATURE_FIRST_NOT_SIGNED = -1;
206
207    /**
208     * Signature check result: this is returned by {@link #checkSignatures}
209     * if the second package is not signed, but the first is.
210     */
211    public static final int SIGNATURE_SECOND_NOT_SIGNED = -2;
212
213    /**
214     * Signature check result: this is returned by {@link #checkSignatures}
215     * if both packages are signed but there is no matching signature.
216     */
217    public static final int SIGNATURE_NO_MATCH = -3;
218
219    /**
220     * Signature check result: this is returned by {@link #checkSignatures}
221     * if either of the given package names are not valid.
222     */
223    public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
224
225    public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
226    public static final int COMPONENT_ENABLED_STATE_ENABLED = 1;
227    public static final int COMPONENT_ENABLED_STATE_DISABLED = 2;
228
229    /**
230     * Flag parameter for {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} to
231     * indicate that this package should be installed as forward locked, i.e. only the app itself
232     * should have access to it's code and non-resource assets.
233     * @hide
234     */
235    public static final int INSTALL_FORWARD_LOCK = 0x00000001;
236
237    /**
238     * Flag parameter for {@link #installPackage} to indicate that you want to replace an already
239     * installed package, if one exists.
240     * @hide
241     */
242    public static final int INSTALL_REPLACE_EXISTING = 0x00000002;
243
244    /**
245     * Flag parameter for {@link #installPackage} to indicate that you want to
246     * allow test packages (those that have set android:testOnly in their
247     * manifest) to be installed.
248     * @hide
249     */
250    public static final int INSTALL_ALLOW_TEST = 0x00000004;
251
252    /**
253     * Flag parameter for
254     * {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate
255     * that you don't want to kill the app containing the component.  Be careful when you set this
256     * since changing component states can make the containing application's behavior unpredictable.
257     */
258    public static final int DONT_KILL_APP = 0x00000001;
259
260    /**
261     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
262     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} on success.
263     * @hide
264     */
265    public static final int INSTALL_SUCCEEDED = 1;
266
267    /**
268     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
269     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package is
270     * already installed.
271     * @hide
272     */
273    public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;
274
275    /**
276     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
277     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package archive
278     * file is invalid.
279     * @hide
280     */
281    public static final int INSTALL_FAILED_INVALID_APK = -2;
282
283    /**
284     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
285     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the URI passed in
286     * is invalid.
287     * @hide
288     */
289    public static final int INSTALL_FAILED_INVALID_URI = -3;
290
291    /**
292     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
293     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package manager
294     * service found that the device didn't have enough storage space to install the app.
295     * @hide
296     */
297    public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;
298
299    /**
300     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
301     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if a
302     * package is already installed with the same name.
303     * @hide
304     */
305    public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;
306
307    /**
308     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
309     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
310     * the requested shared user does not exist.
311     * @hide
312     */
313    public static final int INSTALL_FAILED_NO_SHARED_USER = -6;
314
315    /**
316     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
317     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
318     * a previously installed package of the same name has a different signature
319     * than the new package (and the old package's data was not removed).
320     * @hide
321     */
322    public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;
323
324    /**
325     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
326     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
327     * the new package is requested a shared user which is already installed on the
328     * device and does not have matching signature.
329     * @hide
330     */
331    public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;
332
333    /**
334     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
335     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
336     * the new package uses a shared library that is not available.
337     * @hide
338     */
339    public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;
340
341    /**
342     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
343     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
344     * the new package uses a shared library that is not available.
345     * @hide
346     */
347    public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;
348
349    /**
350     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
351     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
352     * the new package failed while optimizing and validating its dex files,
353     * either because there was not enough storage or the validation failed.
354     * @hide
355     */
356    public static final int INSTALL_FAILED_DEXOPT = -11;
357
358    /**
359     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
360     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
361     * the new package failed because the current SDK version is older than
362     * that required by the package.
363     * @hide
364     */
365    public static final int INSTALL_FAILED_OLDER_SDK = -12;
366
367    /**
368     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
369     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
370     * the new package failed because it contains a content provider with the
371     * same authority as a provider already installed in the system.
372     * @hide
373     */
374    public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;
375
376    /**
377     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
378     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
379     * the new package failed because the current SDK version is newer than
380     * that required by the package.
381     * @hide
382     */
383    public static final int INSTALL_FAILED_NEWER_SDK = -14;
384
385    /**
386     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
387     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
388     * the new package failed because it has specified that it is a test-only
389     * package and the caller has not supplied the {@link #INSTALL_ALLOW_TEST}
390     * flag.
391     * @hide
392     */
393    public static final int INSTALL_FAILED_TEST_ONLY = -15;
394
395    /**
396     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
397     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
398     * the package being installed contains native code, but none that is
399     * compatible with the the device's CPU_ABI.
400     * @hide
401     */
402    public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;
403
404    /**
405     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
406     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
407     * the new package uses a feature that is not available.
408     * @hide
409     */
410    public static final int INSTALL_FAILED_MISSING_FEATURE = -17;
411
412    /**
413     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
414     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
415     * if the parser was given a path that is not a file, or does not end with the expected
416     * '.apk' extension.
417     * @hide
418     */
419    public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;
420
421    /**
422     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
423     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
424     * if the parser was unable to retrieve the AndroidManifest.xml file.
425     * @hide
426     */
427    public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;
428
429    /**
430     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
431     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
432     * if the parser encountered an unexpected exception.
433     * @hide
434     */
435    public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;
436
437    /**
438     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
439     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
440     * if the parser did not find any certificates in the .apk.
441     * @hide
442     */
443    public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;
444
445    /**
446     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
447     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
448     * if the parser found inconsistent certificates on the files in the .apk.
449     * @hide
450     */
451    public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;
452
453    /**
454     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
455     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
456     * if the parser encountered a CertificateEncodingException in one of the
457     * files in the .apk.
458     * @hide
459     */
460    public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;
461
462    /**
463     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
464     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
465     * if the parser encountered a bad or missing package name in the manifest.
466     * @hide
467     */
468    public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;
469
470    /**
471     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
472     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
473     * if the parser encountered a bad shared user id name in the manifest.
474     * @hide
475     */
476    public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;
477
478    /**
479     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
480     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
481     * if the parser encountered some structural problem in the manifest.
482     * @hide
483     */
484    public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;
485
486    /**
487     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
488     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
489     * if the parser did not find any actionable tags (instrumentation or application)
490     * in the manifest.
491     * @hide
492     */
493    public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;
494
495    /**
496     * Indicates the state of installation. Used by PackageManager to
497     * figure out incomplete installations. Say a package is being installed
498     * (the state is set to PKG_INSTALL_INCOMPLETE) and remains so till
499     * the package installation is successful or unsuccesful lin which case
500     * the PackageManager will no longer maintain state information associated
501     * with the package. If some exception(like device freeze or battery being
502     * pulled out) occurs during installation of a package, the PackageManager
503     * needs this information to clean up the previously failed installation.
504     */
505    public static final int PKG_INSTALL_INCOMPLETE = 0;
506    public static final int PKG_INSTALL_COMPLETE = 1;
507
508    /**
509     * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
510     * package's data directory.
511     *
512     * @hide
513     */
514    public static final int DONT_DELETE_DATA = 0x00000001;
515
516    /**
517     * Retrieve overall information about an application package that is
518     * installed on the system.
519     *
520     * <p>Throws {@link NameNotFoundException} if a package with the given
521     * name can not be found on the system.
522     *
523     * @param packageName The full name (i.e. com.google.apps.contacts) of the
524     *                    desired package.
525
526     * @param flags Additional option flags. Use any combination of
527     * {@link #GET_ACTIVITIES},
528     * {@link #GET_GIDS},
529     * {@link #GET_CONFIGURATIONS},
530     * {@link #GET_INSTRUMENTATION},
531     * {@link #GET_PERMISSIONS},
532     * {@link #GET_PROVIDERS},
533     * {@link #GET_RECEIVERS},
534     * {@link #GET_SERVICES},
535     * {@link #GET_SIGNATURES},
536     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
537     *
538     * @return Returns a PackageInfo object containing information about the package.
539     *         If flag GET_UNINSTALLED_PACKAGES is set and  if the package is not
540     *         found in the list of installed applications, the package information is
541     *         retrieved from the list of uninstalled applications(which includes
542     *         installed applications as well as applications
543     *         with data directory ie applications which had been
544     *         deleted with DONT_DELTE_DATA flag set).
545     *
546     * @see #GET_ACTIVITIES
547     * @see #GET_GIDS
548     * @see #GET_CONFIGURATIONS
549     * @see #GET_INSTRUMENTATION
550     * @see #GET_PERMISSIONS
551     * @see #GET_PROVIDERS
552     * @see #GET_RECEIVERS
553     * @see #GET_SERVICES
554     * @see #GET_SIGNATURES
555     * @see #GET_UNINSTALLED_PACKAGES
556     *
557     */
558    public abstract PackageInfo getPackageInfo(String packageName, int flags)
559            throws NameNotFoundException;
560
561    /**
562     * Return a "good" intent to launch a front-door activity in a package,
563     * for use for example to implement an "open" button when browsing through
564     * packages.  The current implementation will look first for a main
565     * activity in the category {@link Intent#CATEGORY_INFO}, next for a
566     * main activity in the category {@link Intent#CATEGORY_LAUNCHER}, or return
567     * null if neither are found.
568     *
569     * <p>Throws {@link NameNotFoundException} if a package with the given
570     * name can not be found on the system.
571     *
572     * @param packageName The name of the package to inspect.
573     *
574     * @return Returns either a fully-qualified Intent that can be used to
575     * launch the main activity in the package, or null if the package does
576     * not contain such an activity.
577     */
578    public abstract Intent getLaunchIntentForPackage(String packageName);
579
580    /**
581     * Return an array of all of the secondary group-ids that have been
582     * assigned to a package.
583     *
584     * <p>Throws {@link NameNotFoundException} if a package with the given
585     * name can not be found on the system.
586     *
587     * @param packageName The full name (i.e. com.google.apps.contacts) of the
588     *                    desired package.
589     *
590     * @return Returns an int array of the assigned gids, or null if there
591     * are none.
592     */
593    public abstract int[] getPackageGids(String packageName)
594            throws NameNotFoundException;
595
596    /**
597     * Retrieve all of the information we know about a particular permission.
598     *
599     * <p>Throws {@link NameNotFoundException} if a permission with the given
600     * name can not be found on the system.
601     *
602     * @param name The fully qualified name (i.e. com.google.permission.LOGIN)
603     *             of the permission you are interested in.
604     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
605     * retrieve any meta-data associated with the permission.
606     *
607     * @return Returns a {@link PermissionInfo} containing information about the
608     *         permission.
609     */
610    public abstract PermissionInfo getPermissionInfo(String name, int flags)
611            throws NameNotFoundException;
612
613    /**
614     * Query for all of the permissions associated with a particular group.
615     *
616     * <p>Throws {@link NameNotFoundException} if the given group does not
617     * exist.
618     *
619     * @param group The fully qualified name (i.e. com.google.permission.LOGIN)
620     *             of the permission group you are interested in.  Use null to
621     *             find all of the permissions not associated with a group.
622     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
623     * retrieve any meta-data associated with the permissions.
624     *
625     * @return Returns a list of {@link PermissionInfo} containing information
626     * about all of the permissions in the given group.
627     */
628    public abstract List<PermissionInfo> queryPermissionsByGroup(String group,
629            int flags) throws NameNotFoundException;
630
631    /**
632     * Retrieve all of the information we know about a particular group of
633     * permissions.
634     *
635     * <p>Throws {@link NameNotFoundException} if a permission group with the given
636     * name can not be found on the system.
637     *
638     * @param name The fully qualified name (i.e. com.google.permission_group.APPS)
639     *             of the permission you are interested in.
640     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
641     * retrieve any meta-data associated with the permission group.
642     *
643     * @return Returns a {@link PermissionGroupInfo} containing information
644     * about the permission.
645     */
646    public abstract PermissionGroupInfo getPermissionGroupInfo(String name,
647            int flags) throws NameNotFoundException;
648
649    /**
650     * Retrieve all of the known permission groups in the system.
651     *
652     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
653     * retrieve any meta-data associated with the permission group.
654     *
655     * @return Returns a list of {@link PermissionGroupInfo} containing
656     * information about all of the known permission groups.
657     */
658    public abstract List<PermissionGroupInfo> getAllPermissionGroups(int flags);
659
660    /**
661     * Retrieve all of the information we know about a particular
662     * package/application.
663     *
664     * <p>Throws {@link NameNotFoundException} if an application with the given
665     * package name can not be found on the system.
666     *
667     * @param packageName The full name (i.e. com.google.apps.contacts) of an
668     *                    application.
669     * @param flags Additional option flags. Use any combination of
670     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
671     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
672     *
673     * @return  {@link ApplicationInfo} Returns ApplicationInfo object containing
674     *         information about the package.
675     *         If flag GET_UNINSTALLED_PACKAGES is set and  if the package is not
676     *         found in the list of installed applications,
677     *         the application information is retrieved from the
678     *         list of uninstalled applications(which includes
679     *         installed applications as well as applications
680     *         with data directory ie applications which had been
681     *         deleted with DONT_DELTE_DATA flag set).
682     *
683     * @see #GET_META_DATA
684     * @see #GET_SHARED_LIBRARY_FILES
685     * @see #GET_UNINSTALLED_PACKAGES
686     */
687    public abstract ApplicationInfo getApplicationInfo(String packageName,
688            int flags) throws NameNotFoundException;
689
690    /**
691     * Retrieve all of the information we know about a particular activity
692     * class.
693     *
694     * <p>Throws {@link NameNotFoundException} if an activity with the given
695     * class name can not be found on the system.
696     *
697     * @param className The full name (i.e.
698     *                  com.google.apps.contacts.ContactsList) of an Activity
699     *                  class.
700     * @param flags Additional option flags. Use any combination of
701     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
702     * to modify the data (in ApplicationInfo) returned.
703     *
704     * @return {@link ActivityInfo} containing information about the activity.
705     *
706     * @see #GET_INTENT_FILTERS
707     * @see #GET_META_DATA
708     * @see #GET_SHARED_LIBRARY_FILES
709     */
710    public abstract ActivityInfo getActivityInfo(ComponentName className,
711            int flags) throws NameNotFoundException;
712
713    /**
714     * Retrieve all of the information we know about a particular receiver
715     * class.
716     *
717     * <p>Throws {@link NameNotFoundException} if a receiver with the given
718     * class name can not be found on the system.
719     *
720     * @param className The full name (i.e.
721     *                  com.google.apps.contacts.CalendarAlarm) of a Receiver
722     *                  class.
723     * @param flags Additional option flags.  Use any combination of
724     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
725     * to modify the data returned.
726     *
727     * @return {@link ActivityInfo} containing information about the receiver.
728     *
729     * @see #GET_INTENT_FILTERS
730     * @see #GET_META_DATA
731     * @see #GET_SHARED_LIBRARY_FILES
732     */
733    public abstract ActivityInfo getReceiverInfo(ComponentName className,
734            int flags) throws NameNotFoundException;
735
736    /**
737     * Retrieve all of the information we know about a particular service
738     * class.
739     *
740     * <p>Throws {@link NameNotFoundException} if a service with the given
741     * class name can not be found on the system.
742     *
743     * @param className The full name (i.e.
744     *                  com.google.apps.media.BackgroundPlayback) of a Service
745     *                  class.
746     * @param flags Additional option flags.  Use any combination of
747     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
748     * to modify the data returned.
749     *
750     * @return ServiceInfo containing information about the service.
751     *
752     * @see #GET_META_DATA
753     * @see #GET_SHARED_LIBRARY_FILES
754     */
755    public abstract ServiceInfo getServiceInfo(ComponentName className,
756            int flags) throws NameNotFoundException;
757
758    /**
759     * Return a List of all packages that are installed
760     * on the device.
761     *
762     * @param flags Additional option flags. Use any combination of
763     * {@link #GET_ACTIVITIES},
764     * {@link #GET_GIDS},
765     * {@link #GET_CONFIGURATIONS},
766     * {@link #GET_INSTRUMENTATION},
767     * {@link #GET_PERMISSIONS},
768     * {@link #GET_PROVIDERS},
769     * {@link #GET_RECEIVERS},
770     * {@link #GET_SERVICES},
771     * {@link #GET_SIGNATURES},
772     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
773     *
774     * @return A List of PackageInfo objects, one for each package that is
775     *         installed on the device.  In the unlikely case of there being no
776     *         installed packages, an empty list is returned.
777     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
778     *         applications including those deleted with DONT_DELETE_DATA
779     *         (partially installed apps with data directory) will be returned.
780     *
781     * @see #GET_ACTIVITIES
782     * @see #GET_GIDS
783     * @see #GET_CONFIGURATIONS
784     * @see #GET_INSTRUMENTATION
785     * @see #GET_PERMISSIONS
786     * @see #GET_PROVIDERS
787     * @see #GET_RECEIVERS
788     * @see #GET_SERVICES
789     * @see #GET_SIGNATURES
790     * @see #GET_UNINSTALLED_PACKAGES
791     *
792     */
793    public abstract List<PackageInfo> getInstalledPackages(int flags);
794
795    /**
796     * Check whether a particular package has been granted a particular
797     * permission.
798     *
799     * @param permName The name of the permission you are checking for,
800     * @param pkgName The name of the package you are checking against.
801     *
802     * @return If the package has the permission, PERMISSION_GRANTED is
803     * returned.  If it does not have the permission, PERMISSION_DENIED
804     * is returned.
805     *
806     * @see #PERMISSION_GRANTED
807     * @see #PERMISSION_DENIED
808     */
809    public abstract int checkPermission(String permName, String pkgName);
810
811    /**
812     * Add a new dynamic permission to the system.  For this to work, your
813     * package must have defined a permission tree through the
814     * {@link android.R.styleable#AndroidManifestPermissionTree
815     * &lt;permission-tree&gt;} tag in its manifest.  A package can only add
816     * permissions to trees that were defined by either its own package or
817     * another with the same user id; a permission is in a tree if it
818     * matches the name of the permission tree + ".": for example,
819     * "com.foo.bar" is a member of the permission tree "com.foo".
820     *
821     * <p>It is good to make your permission tree name descriptive, because you
822     * are taking possession of that entire set of permission names.  Thus, it
823     * must be under a domain you control, with a suffix that will not match
824     * any normal permissions that may be declared in any applications that
825     * are part of that domain.
826     *
827     * <p>New permissions must be added before
828     * any .apks are installed that use those permissions.  Permissions you
829     * add through this method are remembered across reboots of the device.
830     * If the given permission already exists, the info you supply here
831     * will be used to update it.
832     *
833     * @param info Description of the permission to be added.
834     *
835     * @return Returns true if a new permission was created, false if an
836     * existing one was updated.
837     *
838     * @throws SecurityException if you are not allowed to add the
839     * given permission name.
840     *
841     * @see #removePermission(String)
842     */
843    public abstract boolean addPermission(PermissionInfo info);
844
845    /**
846     * Removes a permission that was previously added with
847     * {@link #addPermission(PermissionInfo)}.  The same ownership rules apply
848     * -- you are only allowed to remove permissions that you are allowed
849     * to add.
850     *
851     * @param name The name of the permission to remove.
852     *
853     * @throws SecurityException if you are not allowed to remove the
854     * given permission name.
855     *
856     * @see #addPermission(PermissionInfo)
857     */
858    public abstract void removePermission(String name);
859
860    /**
861     * Compare the signatures of two packages to determine if the same
862     * signature appears in both of them.  If they do contain the same
863     * signature, then they are allowed special privileges when working
864     * with each other: they can share the same user-id, run instrumentation
865     * against each other, etc.
866     *
867     * @param pkg1 First package name whose signature will be compared.
868     * @param pkg2 Second package name whose signature will be compared.
869     * @return Returns an integer indicating whether there is a matching
870     * signature: the value is >= 0 if there is a match (or neither package
871     * is signed), or < 0 if there is not a match.  The match result can be
872     * further distinguished with the success (>= 0) constants
873     * {@link #SIGNATURE_MATCH}, {@link #SIGNATURE_NEITHER_SIGNED}; or
874     * failure (< 0) constants {@link #SIGNATURE_FIRST_NOT_SIGNED},
875     * {@link #SIGNATURE_SECOND_NOT_SIGNED}, {@link #SIGNATURE_NO_MATCH},
876     * or {@link #SIGNATURE_UNKNOWN_PACKAGE}.
877     *
878     * @see #checkSignatures(int, int)
879     * @see #SIGNATURE_MATCH
880     * @see #SIGNATURE_NEITHER_SIGNED
881     * @see #SIGNATURE_FIRST_NOT_SIGNED
882     * @see #SIGNATURE_SECOND_NOT_SIGNED
883     * @see #SIGNATURE_NO_MATCH
884     * @see #SIGNATURE_UNKNOWN_PACKAGE
885     */
886    public abstract int checkSignatures(String pkg1, String pkg2);
887
888    /**
889     * Like {@link #checkSignatures(String, String)}, but takes UIDs of
890     * the two packages to be checked.  This can be useful, for example,
891     * when doing the check in an IPC, where the UID is the only identity
892     * available.  It is functionally identical to determining the package
893     * associated with the UIDs and checking their signatures.
894     *
895     * @param uid1 First UID whose signature will be compared.
896     * @param uid2 Second UID whose signature will be compared.
897     * @return Returns an integer indicating whether there is a matching
898     * signature: the value is >= 0 if there is a match (or neither package
899     * is signed), or < 0 if there is not a match.  The match result can be
900     * further distinguished with the success (>= 0) constants
901     * {@link #SIGNATURE_MATCH}, {@link #SIGNATURE_NEITHER_SIGNED}; or
902     * failure (< 0) constants {@link #SIGNATURE_FIRST_NOT_SIGNED},
903     * {@link #SIGNATURE_SECOND_NOT_SIGNED}, {@link #SIGNATURE_NO_MATCH},
904     * or {@link #SIGNATURE_UNKNOWN_PACKAGE}.
905     *
906     * @see #checkSignatures(int, int)
907     * @see #SIGNATURE_MATCH
908     * @see #SIGNATURE_NEITHER_SIGNED
909     * @see #SIGNATURE_FIRST_NOT_SIGNED
910     * @see #SIGNATURE_SECOND_NOT_SIGNED
911     * @see #SIGNATURE_NO_MATCH
912     * @see #SIGNATURE_UNKNOWN_PACKAGE
913     */
914    public abstract int checkSignatures(int uid1, int uid2);
915
916    /**
917     * Retrieve the names of all packages that are associated with a particular
918     * user id.  In most cases, this will be a single package name, the package
919     * that has been assigned that user id.  Where there are multiple packages
920     * sharing the same user id through the "sharedUserId" mechanism, all
921     * packages with that id will be returned.
922     *
923     * @param uid The user id for which you would like to retrieve the
924     * associated packages.
925     *
926     * @return Returns an array of one or more packages assigned to the user
927     * id, or null if there are no known packages with the given id.
928     */
929    public abstract String[] getPackagesForUid(int uid);
930
931    /**
932     * Retrieve the official name associated with a user id.  This name is
933     * guaranteed to never change, though it is possibly for the underlying
934     * user id to be changed.  That is, if you are storing information about
935     * user ids in persistent storage, you should use the string returned
936     * by this function instead of the raw user-id.
937     *
938     * @param uid The user id for which you would like to retrieve a name.
939     * @return Returns a unique name for the given user id, or null if the
940     * user id is not currently assigned.
941     */
942    public abstract String getNameForUid(int uid);
943
944    /**
945     * Return the user id associated with a shared user name. Multiple
946     * applications can specify a shared user name in their manifest and thus
947     * end up using a common uid. This might be used for new applications
948     * that use an existing shared user name and need to know the uid of the
949     * shared user.
950     *
951     * @param sharedUserName The shared user name whose uid is to be retrieved.
952     * @return Returns the uid associated with the shared user, or  NameNotFoundException
953     * if the shared user name is not being used by any installed packages
954     * @hide
955     */
956    public abstract int getUidForSharedUser(String sharedUserName)
957            throws NameNotFoundException;
958
959    /**
960     * Return a List of all application packages that are installed on the
961     * device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all
962     * applications including those deleted with DONT_DELETE_DATA(partially
963     * installed apps with data directory) will be returned.
964     *
965     * @param flags Additional option flags. Use any combination of
966     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
967     * {link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
968     *
969     * @return A List of ApplicationInfo objects, one for each application that
970     *         is installed on the device.  In the unlikely case of there being
971     *         no installed applications, an empty list is returned.
972     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
973     *         applications including those deleted with DONT_DELETE_DATA
974     *         (partially installed apps with data directory) will be returned.
975     *
976     * @see #GET_META_DATA
977     * @see #GET_SHARED_LIBRARY_FILES
978     * @see #GET_UNINSTALLED_PACKAGES
979     */
980    public abstract List<ApplicationInfo> getInstalledApplications(int flags);
981
982    /**
983     * Get a list of shared libraries that are available on the
984     * system.
985     *
986     * @return An array of shared library names that are
987     * available on the system, or null if none are installed.
988     *
989     */
990    public abstract String[] getSystemSharedLibraryNames();
991
992    /**
993     * Get a list of features that are available on the
994     * system.
995     *
996     * @return An array of FeatureInfo classes describing the features
997     * that are available on the system, or null if there are none(!!).
998     *
999     */
1000    public abstract FeatureInfo[] getSystemAvailableFeatures();
1001
1002    /**
1003     * Determine the best action to perform for a given Intent.  This is how
1004     * {@link Intent#resolveActivity} finds an activity if a class has not
1005     * been explicitly specified.
1006     *
1007     * @param intent An intent containing all of the desired specification
1008     *               (action, data, type, category, and/or component).
1009     * @param flags Additional option flags.  The most important is
1010     *                    MATCH_DEFAULT_ONLY, to limit the resolution to only
1011     *                    those activities that support the CATEGORY_DEFAULT.
1012     *
1013     * @return Returns a ResolveInfo containing the final activity intent that
1014     *         was determined to be the best action.  Returns null if no
1015     *         matching activity was found.
1016     *
1017     * @see #MATCH_DEFAULT_ONLY
1018     * @see #GET_INTENT_FILTERS
1019     * @see #GET_RESOLVED_FILTER
1020     */
1021    public abstract ResolveInfo resolveActivity(Intent intent, int flags);
1022
1023    /**
1024     * Retrieve all activities that can be performed for the given intent.
1025     *
1026     * @param intent The desired intent as per resolveActivity().
1027     * @param flags Additional option flags.  The most important is
1028     *                    MATCH_DEFAULT_ONLY, to limit the resolution to only
1029     *                    those activities that support the CATEGORY_DEFAULT.
1030     *
1031     * @return A List<ResolveInfo> containing one entry for each matching
1032     *         Activity. These are ordered from best to worst match -- that
1033     *         is, the first item in the list is what is returned by
1034     *         resolveActivity().  If there are no matching activities, an empty
1035     *         list is returned.
1036     *
1037     * @see #MATCH_DEFAULT_ONLY
1038     * @see #GET_INTENT_FILTERS
1039     * @see #GET_RESOLVED_FILTER
1040     */
1041    public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
1042            int flags);
1043
1044    /**
1045     * Retrieve a set of activities that should be presented to the user as
1046     * similar options.  This is like {@link #queryIntentActivities}, except it
1047     * also allows you to supply a list of more explicit Intents that you would
1048     * like to resolve to particular options, and takes care of returning the
1049     * final ResolveInfo list in a reasonable order, with no duplicates, based
1050     * on those inputs.
1051     *
1052     * @param caller The class name of the activity that is making the
1053     *               request.  This activity will never appear in the output
1054     *               list.  Can be null.
1055     * @param specifics An array of Intents that should be resolved to the
1056     *                  first specific results.  Can be null.
1057     * @param intent The desired intent as per resolveActivity().
1058     * @param flags Additional option flags.  The most important is
1059     *                    MATCH_DEFAULT_ONLY, to limit the resolution to only
1060     *                    those activities that support the CATEGORY_DEFAULT.
1061     *
1062     * @return A List<ResolveInfo> containing one entry for each matching
1063     *         Activity. These are ordered first by all of the intents resolved
1064     *         in <var>specifics</var> and then any additional activities that
1065     *         can handle <var>intent</var> but did not get included by one of
1066     *         the <var>specifics</var> intents.  If there are no matching
1067     *         activities, an empty list is returned.
1068     *
1069     * @see #MATCH_DEFAULT_ONLY
1070     * @see #GET_INTENT_FILTERS
1071     * @see #GET_RESOLVED_FILTER
1072     */
1073    public abstract List<ResolveInfo> queryIntentActivityOptions(
1074            ComponentName caller, Intent[] specifics, Intent intent, int flags);
1075
1076    /**
1077     * Retrieve all receivers that can handle a broadcast of the given intent.
1078     *
1079     * @param intent The desired intent as per resolveActivity().
1080     * @param flags Additional option flags.  The most important is
1081     *                    MATCH_DEFAULT_ONLY, to limit the resolution to only
1082     *                    those activities that support the CATEGORY_DEFAULT.
1083     *
1084     * @return A List<ResolveInfo> containing one entry for each matching
1085     *         Receiver. These are ordered from first to last in priority.  If
1086     *         there are no matching receivers, an empty list is returned.
1087     *
1088     * @see #MATCH_DEFAULT_ONLY
1089     * @see #GET_INTENT_FILTERS
1090     * @see #GET_RESOLVED_FILTER
1091     */
1092    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
1093            int flags);
1094
1095    /**
1096     * Determine the best service to handle for a given Intent.
1097     *
1098     * @param intent An intent containing all of the desired specification
1099     *               (action, data, type, category, and/or component).
1100     * @param flags Additional option flags.
1101     *
1102     * @return Returns a ResolveInfo containing the final service intent that
1103     *         was determined to be the best action.  Returns null if no
1104     *         matching service was found.
1105     *
1106     * @see #GET_INTENT_FILTERS
1107     * @see #GET_RESOLVED_FILTER
1108     */
1109    public abstract ResolveInfo resolveService(Intent intent, int flags);
1110
1111    /**
1112     * Retrieve all services that can match the given intent.
1113     *
1114     * @param intent The desired intent as per resolveService().
1115     * @param flags Additional option flags.
1116     *
1117     * @return A List<ResolveInfo> containing one entry for each matching
1118     *         ServiceInfo. These are ordered from best to worst match -- that
1119     *         is, the first item in the list is what is returned by
1120     *         resolveService().  If there are no matching services, an empty
1121     *         list is returned.
1122     *
1123     * @see #GET_INTENT_FILTERS
1124     * @see #GET_RESOLVED_FILTER
1125     */
1126    public abstract List<ResolveInfo> queryIntentServices(Intent intent,
1127            int flags);
1128
1129    /**
1130     * Find a single content provider by its base path name.
1131     *
1132     * @param name The name of the provider to find.
1133     * @param flags Additional option flags.  Currently should always be 0.
1134     *
1135     * @return ContentProviderInfo Information about the provider, if found,
1136     *         else null.
1137     */
1138    public abstract ProviderInfo resolveContentProvider(String name,
1139            int flags);
1140
1141    /**
1142     * Retrieve content provider information.
1143     *
1144     * <p><em>Note: unlike most other methods, an empty result set is indicated
1145     * by a null return instead of an empty list.</em>
1146     *
1147     * @param processName If non-null, limits the returned providers to only
1148     *                    those that are hosted by the given process.  If null,
1149     *                    all content providers are returned.
1150     * @param uid If <var>processName</var> is non-null, this is the required
1151     *        uid owning the requested content providers.
1152     * @param flags Additional option flags.  Currently should always be 0.
1153     *
1154     * @return A List<ContentProviderInfo> containing one entry for each
1155     *         content provider either patching <var>processName</var> or, if
1156     *         <var>processName</var> is null, all known content providers.
1157     *         <em>If there are no matching providers, null is returned.</em>
1158     */
1159    public abstract List<ProviderInfo> queryContentProviders(
1160            String processName, int uid, int flags);
1161
1162    /**
1163     * Retrieve all of the information we know about a particular
1164     * instrumentation class.
1165     *
1166     * <p>Throws {@link NameNotFoundException} if instrumentation with the
1167     * given class name can not be found on the system.
1168     *
1169     * @param className The full name (i.e.
1170     *                  com.google.apps.contacts.InstrumentList) of an
1171     *                  Instrumentation class.
1172     * @param flags Additional option flags.  Currently should always be 0.
1173     *
1174     * @return InstrumentationInfo containing information about the
1175     *         instrumentation.
1176     */
1177    public abstract InstrumentationInfo getInstrumentationInfo(
1178            ComponentName className, int flags) throws NameNotFoundException;
1179
1180    /**
1181     * Retrieve information about available instrumentation code.  May be used
1182     * to retrieve either all instrumentation code, or only the code targeting
1183     * a particular package.
1184     *
1185     * @param targetPackage If null, all instrumentation is returned; only the
1186     *                      instrumentation targeting this package name is
1187     *                      returned.
1188     * @param flags Additional option flags.  Currently should always be 0.
1189     *
1190     * @return A List<InstrumentationInfo> containing one entry for each
1191     *         matching available Instrumentation.  Returns an empty list if
1192     *         there is no instrumentation available for the given package.
1193     */
1194    public abstract List<InstrumentationInfo> queryInstrumentation(
1195            String targetPackage, int flags);
1196
1197    /**
1198     * Retrieve an image from a package.  This is a low-level API used by
1199     * the various package manager info structures (such as
1200     * {@link ComponentInfo} to implement retrieval of their associated
1201     * icon.
1202     *
1203     * @param packageName The name of the package that this icon is coming from.
1204     * Can not be null.
1205     * @param resid The resource identifier of the desired image.  Can not be 0.
1206     * @param appInfo Overall information about <var>packageName</var>.  This
1207     * may be null, in which case the application information will be retrieved
1208     * for you if needed; if you already have this information around, it can
1209     * be much more efficient to supply it here.
1210     *
1211     * @return Returns a Drawable holding the requested image.  Returns null if
1212     * an image could not be found for any reason.
1213     */
1214    public abstract Drawable getDrawable(String packageName, int resid,
1215            ApplicationInfo appInfo);
1216
1217    /**
1218     * Retrieve the icon associated with an activity.  Given the full name of
1219     * an activity, retrieves the information about it and calls
1220     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its icon.
1221     * If the activity can not be found, NameNotFoundException is thrown.
1222     *
1223     * @param activityName Name of the activity whose icon is to be retrieved.
1224     *
1225     * @return Returns the image of the icon, or the default activity icon if
1226     * it could not be found.  Does not return null.
1227     * @throws NameNotFoundException Thrown if the resources for the given
1228     * activity could not be loaded.
1229     *
1230     * @see #getActivityIcon(Intent)
1231     */
1232    public abstract Drawable getActivityIcon(ComponentName activityName)
1233            throws NameNotFoundException;
1234
1235    /**
1236     * Retrieve the icon associated with an Intent.  If intent.getClassName() is
1237     * set, this simply returns the result of
1238     * getActivityIcon(intent.getClassName()).  Otherwise it resolves the intent's
1239     * component and returns the icon associated with the resolved component.
1240     * If intent.getClassName() can not be found or the Intent can not be resolved
1241     * to a component, NameNotFoundException is thrown.
1242     *
1243     * @param intent The intent for which you would like to retrieve an icon.
1244     *
1245     * @return Returns the image of the icon, or the default activity icon if
1246     * it could not be found.  Does not return null.
1247     * @throws NameNotFoundException Thrown if the resources for application
1248     * matching the given intent could not be loaded.
1249     *
1250     * @see #getActivityIcon(ComponentName)
1251     */
1252    public abstract Drawable getActivityIcon(Intent intent)
1253            throws NameNotFoundException;
1254
1255    /**
1256     * Return the generic icon for an activity that is used when no specific
1257     * icon is defined.
1258     *
1259     * @return Drawable Image of the icon.
1260     */
1261    public abstract Drawable getDefaultActivityIcon();
1262
1263    /**
1264     * Retrieve the icon associated with an application.  If it has not defined
1265     * an icon, the default app icon is returned.  Does not return null.
1266     *
1267     * @param info Information about application being queried.
1268     *
1269     * @return Returns the image of the icon, or the default application icon
1270     * if it could not be found.
1271     *
1272     * @see #getApplicationIcon(String)
1273     */
1274    public abstract Drawable getApplicationIcon(ApplicationInfo info);
1275
1276    /**
1277     * Retrieve the icon associated with an application.  Given the name of the
1278     * application's package, retrieves the information about it and calls
1279     * getApplicationIcon() to return its icon. If the application can not be
1280     * found, NameNotFoundException is thrown.
1281     *
1282     * @param packageName Name of the package whose application icon is to be
1283     *                    retrieved.
1284     *
1285     * @return Returns the image of the icon, or the default application icon
1286     * if it could not be found.  Does not return null.
1287     * @throws NameNotFoundException Thrown if the resources for the given
1288     * application could not be loaded.
1289     *
1290     * @see #getApplicationIcon(ApplicationInfo)
1291     */
1292    public abstract Drawable getApplicationIcon(String packageName)
1293            throws NameNotFoundException;
1294
1295    /**
1296     * Retrieve text from a package.  This is a low-level API used by
1297     * the various package manager info structures (such as
1298     * {@link ComponentInfo} to implement retrieval of their associated
1299     * labels and other text.
1300     *
1301     * @param packageName The name of the package that this text is coming from.
1302     * Can not be null.
1303     * @param resid The resource identifier of the desired text.  Can not be 0.
1304     * @param appInfo Overall information about <var>packageName</var>.  This
1305     * may be null, in which case the application information will be retrieved
1306     * for you if needed; if you already have this information around, it can
1307     * be much more efficient to supply it here.
1308     *
1309     * @return Returns a CharSequence holding the requested text.  Returns null
1310     * if the text could not be found for any reason.
1311     */
1312    public abstract CharSequence getText(String packageName, int resid,
1313            ApplicationInfo appInfo);
1314
1315    /**
1316     * Retrieve an XML file from a package.  This is a low-level API used to
1317     * retrieve XML meta data.
1318     *
1319     * @param packageName The name of the package that this xml is coming from.
1320     * Can not be null.
1321     * @param resid The resource identifier of the desired xml.  Can not be 0.
1322     * @param appInfo Overall information about <var>packageName</var>.  This
1323     * may be null, in which case the application information will be retrieved
1324     * for you if needed; if you already have this information around, it can
1325     * be much more efficient to supply it here.
1326     *
1327     * @return Returns an XmlPullParser allowing you to parse out the XML
1328     * data.  Returns null if the xml resource could not be found for any
1329     * reason.
1330     */
1331    public abstract XmlResourceParser getXml(String packageName, int resid,
1332            ApplicationInfo appInfo);
1333
1334    /**
1335     * Return the label to use for this application.
1336     *
1337     * @return Returns the label associated with this application, or null if
1338     * it could not be found for any reason.
1339     * @param info The application to get the label of
1340     */
1341    public abstract CharSequence getApplicationLabel(ApplicationInfo info);
1342
1343    /**
1344     * Retrieve the resources associated with an activity.  Given the full
1345     * name of an activity, retrieves the information about it and calls
1346     * getResources() to return its application's resources.  If the activity
1347     * can not be found, NameNotFoundException is thrown.
1348     *
1349     * @param activityName Name of the activity whose resources are to be
1350     *                     retrieved.
1351     *
1352     * @return Returns the application's Resources.
1353     * @throws NameNotFoundException Thrown if the resources for the given
1354     * application could not be loaded.
1355     *
1356     * @see #getResourcesForApplication(ApplicationInfo)
1357     */
1358    public abstract Resources getResourcesForActivity(ComponentName activityName)
1359            throws NameNotFoundException;
1360
1361    /**
1362     * Retrieve the resources for an application.  Throws NameNotFoundException
1363     * if the package is no longer installed.
1364     *
1365     * @param app Information about the desired application.
1366     *
1367     * @return Returns the application's Resources.
1368     * @throws NameNotFoundException Thrown if the resources for the given
1369     * application could not be loaded (most likely because it was uninstalled).
1370     */
1371    public abstract Resources getResourcesForApplication(ApplicationInfo app)
1372            throws NameNotFoundException;
1373
1374    /**
1375     * Retrieve the resources associated with an application.  Given the full
1376     * package name of an application, retrieves the information about it and
1377     * calls getResources() to return its application's resources.  If the
1378     * appPackageName can not be found, NameNotFoundException is thrown.
1379     *
1380     * @param appPackageName Package name of the application whose resources
1381     *                       are to be retrieved.
1382     *
1383     * @return Returns the application's Resources.
1384     * @throws NameNotFoundException Thrown if the resources for the given
1385     * application could not be loaded.
1386     *
1387     * @see #getResourcesForApplication(ApplicationInfo)
1388     */
1389    public abstract Resources getResourcesForApplication(String appPackageName)
1390            throws NameNotFoundException;
1391
1392    /**
1393     * Retrieve overall information about an application package defined
1394     * in a package archive file
1395     *
1396     * @param archiveFilePath The path to the archive file
1397     * @param flags Additional option flags. Use any combination of
1398     * {@link #GET_ACTIVITIES},
1399     * {@link #GET_GIDS},
1400     * {@link #GET_CONFIGURATIONS},
1401     * {@link #GET_INSTRUMENTATION},
1402     * {@link #GET_PERMISSIONS},
1403     * {@link #GET_PROVIDERS},
1404     * {@link #GET_RECEIVERS},
1405     * {@link #GET_SERVICES},
1406     * {@link #GET_SIGNATURES}, to modify the data returned.
1407     *
1408     * @return Returns the information about the package. Returns
1409     * null if the package could not be successfully parsed.
1410     *
1411     * @see #GET_ACTIVITIES
1412     * @see #GET_GIDS
1413     * @see #GET_CONFIGURATIONS
1414     * @see #GET_INSTRUMENTATION
1415     * @see #GET_PERMISSIONS
1416     * @see #GET_PROVIDERS
1417     * @see #GET_RECEIVERS
1418     * @see #GET_SERVICES
1419     * @see #GET_SIGNATURES
1420     *
1421     */
1422    public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) {
1423        PackageParser packageParser = new PackageParser(archiveFilePath);
1424        DisplayMetrics metrics = new DisplayMetrics();
1425        metrics.setToDefaults();
1426        final File sourceFile = new File(archiveFilePath);
1427        PackageParser.Package pkg = packageParser.parsePackage(
1428                sourceFile, archiveFilePath, metrics, 0);
1429        if (pkg == null) {
1430            return null;
1431        }
1432        return PackageParser.generatePackageInfo(pkg, null, flags);
1433    }
1434
1435    /**
1436     * @hide
1437     *
1438     * Install a package. Since this may take a little while, the result will
1439     * be posted back to the given observer.  An installation will fail if the calling context
1440     * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the
1441     * package named in the package file's manifest is already installed, or if there's no space
1442     * available on the device.
1443     *
1444     * @param packageURI The location of the package file to install.  This can be a 'file:' or a
1445     * 'content:' URI.
1446     * @param observer An observer callback to get notified when the package installation is
1447     * complete. {@link IPackageInstallObserver#packageInstalled(String, int)} will be
1448     * called when that happens.  observer may be null to indicate that no callback is desired.
1449     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
1450     * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
1451     * @param installerPackageName Optional package name of the application that is performing the
1452     * installation. This identifies which market the package came from.
1453     */
1454    public abstract void installPackage(
1455            Uri packageURI, IPackageInstallObserver observer, int flags,
1456            String installerPackageName);
1457
1458    /**
1459     * Attempts to delete a package.  Since this may take a little while, the result will
1460     * be posted back to the given observer.  A deletion will fail if the calling context
1461     * lacks the {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the
1462     * named package cannot be found, or if the named package is a "system package".
1463     * (TODO: include pointer to documentation on "system packages")
1464     *
1465     * @param packageName The name of the package to delete
1466     * @param observer An observer callback to get notified when the package deletion is
1467     * complete. {@link android.content.pm.IPackageDeleteObserver#packageDeleted(boolean)} will be
1468     * called when that happens.  observer may be null to indicate that no callback is desired.
1469     * @param flags - possible values: {@link #DONT_DELETE_DATA}
1470     *
1471     * @hide
1472     */
1473    public abstract void deletePackage(
1474            String packageName, IPackageDeleteObserver observer, int flags);
1475
1476    /**
1477     * Retrieve the package name of the application that installed a package. This identifies
1478     * which market the package came from.
1479     *
1480     * @param packageName The name of the package to query
1481     */
1482    public abstract String getInstallerPackageName(String packageName);
1483
1484    /**
1485     * Attempts to clear the user data directory of an application.
1486     * Since this may take a little while, the result will
1487     * be posted back to the given observer.  A deletion will fail if the
1488     * named package cannot be found, or if the named package is a "system package".
1489     *
1490     * @param packageName The name of the package
1491     * @param observer An observer callback to get notified when the operation is finished
1492     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
1493     * will be called when that happens.  observer may be null to indicate that
1494     * no callback is desired.
1495     *
1496     * @hide
1497     */
1498    public abstract void clearApplicationUserData(String packageName,
1499            IPackageDataObserver observer);
1500    /**
1501     * Attempts to delete the cache files associated with an application.
1502     * Since this may take a little while, the result will
1503     * be posted back to the given observer.  A deletion will fail if the calling context
1504     * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the
1505     * named package cannot be found, or if the named package is a "system package".
1506     *
1507     * @param packageName The name of the package to delete
1508     * @param observer An observer callback to get notified when the cache file deletion
1509     * is complete.
1510     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
1511     * will be called when that happens.  observer may be null to indicate that
1512     * no callback is desired.
1513     *
1514     * @hide
1515     */
1516    public abstract void deleteApplicationCacheFiles(String packageName,
1517            IPackageDataObserver observer);
1518
1519    /**
1520     * Free storage by deleting LRU sorted list of cache files across
1521     * all applications. If the currently available free storage
1522     * on the device is greater than or equal to the requested
1523     * free storage, no cache files are cleared. If the currently
1524     * available storage on the device is less than the requested
1525     * free storage, some or all of the cache files across
1526     * all applications are deleted (based on last accessed time)
1527     * to increase the free storage space on the device to
1528     * the requested value. There is no guarantee that clearing all
1529     * the cache files from all applications will clear up
1530     * enough storage to achieve the desired value.
1531     * @param freeStorageSize The number of bytes of storage to be
1532     * freed by the system. Say if freeStorageSize is XX,
1533     * and the current free storage is YY,
1534     * if XX is less than YY, just return. if not free XX-YY number
1535     * of bytes if possible.
1536     * @param observer call back used to notify when
1537     * the operation is completed
1538     *
1539     * @hide
1540     */
1541    public abstract void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer);
1542
1543    /**
1544     * Free storage by deleting LRU sorted list of cache files across
1545     * all applications. If the currently available free storage
1546     * on the device is greater than or equal to the requested
1547     * free storage, no cache files are cleared. If the currently
1548     * available storage on the device is less than the requested
1549     * free storage, some or all of the cache files across
1550     * all applications are deleted (based on last accessed time)
1551     * to increase the free storage space on the device to
1552     * the requested value. There is no guarantee that clearing all
1553     * the cache files from all applications will clear up
1554     * enough storage to achieve the desired value.
1555     * @param freeStorageSize The number of bytes of storage to be
1556     * freed by the system. Say if freeStorageSize is XX,
1557     * and the current free storage is YY,
1558     * if XX is less than YY, just return. if not free XX-YY number
1559     * of bytes if possible.
1560     * @param pi IntentSender call back used to
1561     * notify when the operation is completed.May be null
1562     * to indicate that no call back is desired.
1563     *
1564     * @hide
1565     */
1566    public abstract void freeStorage(long freeStorageSize, IntentSender pi);
1567
1568    /**
1569     * Retrieve the size information for a package.
1570     * Since this may take a little while, the result will
1571     * be posted back to the given observer.  The calling context
1572     * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission.
1573     *
1574     * @param packageName The name of the package whose size information is to be retrieved
1575     * @param observer An observer callback to get notified when the operation
1576     * is complete.
1577     * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)}
1578     * The observer's callback is invoked with a PackageStats object(containing the
1579     * code, data and cache sizes of the package) and a boolean value representing
1580     * the status of the operation. observer may be null to indicate that
1581     * no callback is desired.
1582     *
1583     * @hide
1584     */
1585    public abstract void getPackageSizeInfo(String packageName,
1586            IPackageStatsObserver observer);
1587
1588    /**
1589     * Add a new package to the list of preferred packages.  This new package
1590     * will be added to the front of the list (removed from its current location
1591     * if already listed), meaning it will now be preferred over all other
1592     * packages when resolving conflicts.
1593     *
1594     * @param packageName The package name of the new package to make preferred.
1595     */
1596    public abstract void addPackageToPreferred(String packageName);
1597
1598    /**
1599     * Remove a package from the list of preferred packages.  If it was on
1600     * the list, it will no longer be preferred over other packages.
1601     *
1602     * @param packageName The package name to remove.
1603     */
1604    public abstract void removePackageFromPreferred(String packageName);
1605
1606    /**
1607     * Retrieve the list of all currently configured preferred packages.  The
1608     * first package on the list is the most preferred, the last is the
1609     * least preferred.
1610     *
1611     * @param flags Additional option flags. Use any combination of
1612     * {@link #GET_ACTIVITIES},
1613     * {@link #GET_GIDS},
1614     * {@link #GET_CONFIGURATIONS},
1615     * {@link #GET_INSTRUMENTATION},
1616     * {@link #GET_PERMISSIONS},
1617     * {@link #GET_PROVIDERS},
1618     * {@link #GET_RECEIVERS},
1619     * {@link #GET_SERVICES},
1620     * {@link #GET_SIGNATURES}, to modify the data returned.
1621     *
1622     * @return Returns a list of PackageInfo objects describing each
1623     * preferred application, in order of preference.
1624     *
1625     * @see #GET_ACTIVITIES
1626     * @see #GET_GIDS
1627     * @see #GET_CONFIGURATIONS
1628     * @see #GET_INSTRUMENTATION
1629     * @see #GET_PERMISSIONS
1630     * @see #GET_PROVIDERS
1631     * @see #GET_RECEIVERS
1632     * @see #GET_SERVICES
1633     * @see #GET_SIGNATURES
1634     */
1635    public abstract List<PackageInfo> getPreferredPackages(int flags);
1636
1637    /**
1638     * Add a new preferred activity mapping to the system.  This will be used
1639     * to automatically select the given activity component when
1640     * {@link Context#startActivity(Intent) Context.startActivity()} finds
1641     * multiple matching activities and also matches the given filter.
1642     *
1643     * @param filter The set of intents under which this activity will be
1644     * made preferred.
1645     * @param match The IntentFilter match category that this preference
1646     * applies to.
1647     * @param set The set of activities that the user was picking from when
1648     * this preference was made.
1649     * @param activity The component name of the activity that is to be
1650     * preferred.
1651     */
1652    public abstract void addPreferredActivity(IntentFilter filter, int match,
1653            ComponentName[] set, ComponentName activity);
1654
1655    /**
1656     * Replaces an existing preferred activity mapping to the system, and if that were not present
1657     * adds a new preferred activity.  This will be used
1658     * to automatically select the given activity component when
1659     * {@link Context#startActivity(Intent) Context.startActivity()} finds
1660     * multiple matching activities and also matches the given filter.
1661     *
1662     * @param filter The set of intents under which this activity will be
1663     * made preferred.
1664     * @param match The IntentFilter match category that this preference
1665     * applies to.
1666     * @param set The set of activities that the user was picking from when
1667     * this preference was made.
1668     * @param activity The component name of the activity that is to be
1669     * preferred.
1670     * @hide
1671     */
1672    public abstract void replacePreferredActivity(IntentFilter filter, int match,
1673            ComponentName[] set, ComponentName activity);
1674
1675    /**
1676     * Remove all preferred activity mappings, previously added with
1677     * {@link #addPreferredActivity}, from the
1678     * system whose activities are implemented in the given package name.
1679     *
1680     * @param packageName The name of the package whose preferred activity
1681     * mappings are to be removed.
1682     */
1683    public abstract void clearPackagePreferredActivities(String packageName);
1684
1685    /**
1686     * Retrieve all preferred activities, previously added with
1687     * {@link #addPreferredActivity}, that are
1688     * currently registered with the system.
1689     *
1690     * @param outFilters A list in which to place the filters of all of the
1691     * preferred activities, or null for none.
1692     * @param outActivities A list in which to place the component names of
1693     * all of the preferred activities, or null for none.
1694     * @param packageName An option package in which you would like to limit
1695     * the list.  If null, all activities will be returned; if non-null, only
1696     * those activities in the given package are returned.
1697     *
1698     * @return Returns the total number of registered preferred activities
1699     * (the number of distinct IntentFilter records, not the number of unique
1700     * activity components) that were found.
1701     */
1702    public abstract int getPreferredActivities(List<IntentFilter> outFilters,
1703            List<ComponentName> outActivities, String packageName);
1704
1705    /**
1706     * Set the enabled setting for a package component (activity, receiver, service, provider).
1707     * This setting will override any enabled state which may have been set by the component in its
1708     * manifest.
1709     *
1710     * @param componentName The component to enable
1711     * @param newState The new enabled state for the component.  The legal values for this state
1712     *                 are:
1713     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
1714     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
1715     *                   and
1716     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
1717     *                 The last one removes the setting, thereby restoring the component's state to
1718     *                 whatever was set in it's manifest (or enabled, by default).
1719     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
1720     */
1721    public abstract void setComponentEnabledSetting(ComponentName componentName,
1722            int newState, int flags);
1723
1724
1725    /**
1726     * Return the the enabled setting for a package component (activity,
1727     * receiver, service, provider).  This returns the last value set by
1728     * {@link #setComponentEnabledSetting(ComponentName, int, int)}; in most
1729     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
1730     * the value originally specified in the manifest has not been modified.
1731     *
1732     * @param componentName The component to retrieve.
1733     * @return Returns the current enabled state for the component.  May
1734     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
1735     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
1736     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
1737     * component's enabled state is based on the original information in
1738     * the manifest as found in {@link ComponentInfo}.
1739     */
1740    public abstract int getComponentEnabledSetting(ComponentName componentName);
1741
1742    /**
1743     * Set the enabled setting for an application
1744     * This setting will override any enabled state which may have been set by the application in
1745     * its manifest.  It also overrides the enabled state set in the manifest for any of the
1746     * application's components.  It does not override any enabled state set by
1747     * {@link #setComponentEnabledSetting} for any of the application's components.
1748     *
1749     * @param packageName The package name of the application to enable
1750     * @param newState The new enabled state for the component.  The legal values for this state
1751     *                 are:
1752     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
1753     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
1754     *                   and
1755     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
1756     *                 The last one removes the setting, thereby restoring the applications's state to
1757     *                 whatever was set in its manifest (or enabled, by default).
1758     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
1759     */
1760    public abstract void setApplicationEnabledSetting(String packageName,
1761            int newState, int flags);
1762
1763    /**
1764     * Return the the enabled setting for an application.  This returns
1765     * the last value set by
1766     * {@link #setApplicationEnabledSetting(String, int, int)}; in most
1767     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
1768     * the value originally specified in the manifest has not been modified.
1769     *
1770     * @param packageName The component to retrieve.
1771     * @return Returns the current enabled state for the component.  May
1772     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
1773     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
1774     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
1775     * application's enabled state is based on the original information in
1776     * the manifest as found in {@link ComponentInfo}.
1777     */
1778    public abstract int getApplicationEnabledSetting(String packageName);
1779
1780    /**
1781     * Return whether the device has been booted into safe mode.
1782     */
1783    public abstract boolean isSafeMode();
1784}
1785