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