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