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