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