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