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