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