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