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