PackageManager.java revision 38e6425bb490fbc65c1d0d74cdca205b4db4197d
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
19import android.annotation.CheckResult;
20import android.annotation.DrawableRes;
21import android.annotation.IntDef;
22import android.annotation.NonNull;
23import android.annotation.SdkConstant;
24import android.annotation.SdkConstant.SdkConstantType;
25import android.annotation.StringRes;
26import android.annotation.SystemApi;
27import android.annotation.XmlRes;
28import android.app.PackageDeleteObserver;
29import android.app.PackageInstallObserver;
30import android.app.admin.DevicePolicyManager;
31import android.content.ComponentName;
32import android.content.Context;
33import android.content.Intent;
34import android.content.IntentFilter;
35import android.content.IntentSender;
36import android.content.pm.PackageParser.PackageParserException;
37import android.content.res.Resources;
38import android.content.res.XmlResourceParser;
39import android.graphics.Rect;
40import android.graphics.drawable.Drawable;
41import android.net.Uri;
42import android.os.Bundle;
43import android.os.Environment;
44import android.os.RemoteException;
45import android.os.UserHandle;
46import android.util.AndroidException;
47
48import java.io.File;
49import java.lang.annotation.Retention;
50import java.lang.annotation.RetentionPolicy;
51import java.util.List;
52
53/**
54 * Class for retrieving various kinds of information related to the application
55 * packages that are currently installed on the device.
56 *
57 * You can find this class through {@link Context#getPackageManager}.
58 */
59public abstract class PackageManager {
60
61    /**
62     * This exception is thrown when a given package, application, or component
63     * name cannot be found.
64     */
65    public static class NameNotFoundException extends AndroidException {
66        public NameNotFoundException() {
67        }
68
69        public NameNotFoundException(String name) {
70            super(name);
71        }
72    }
73
74    /**
75     * {@link PackageInfo} flag: return information about
76     * activities in the package in {@link PackageInfo#activities}.
77     */
78    public static final int GET_ACTIVITIES              = 0x00000001;
79
80    /**
81     * {@link PackageInfo} flag: return information about
82     * intent receivers in the package in
83     * {@link PackageInfo#receivers}.
84     */
85    public static final int GET_RECEIVERS               = 0x00000002;
86
87    /**
88     * {@link PackageInfo} flag: return information about
89     * services in the package in {@link PackageInfo#services}.
90     */
91    public static final int GET_SERVICES                = 0x00000004;
92
93    /**
94     * {@link PackageInfo} flag: return information about
95     * content providers in the package in
96     * {@link PackageInfo#providers}.
97     */
98    public static final int GET_PROVIDERS               = 0x00000008;
99
100    /**
101     * {@link PackageInfo} flag: return information about
102     * instrumentation in the package in
103     * {@link PackageInfo#instrumentation}.
104     */
105    public static final int GET_INSTRUMENTATION         = 0x00000010;
106
107    /**
108     * {@link PackageInfo} flag: return information about the
109     * intent filters supported by the activity.
110     */
111    public static final int GET_INTENT_FILTERS          = 0x00000020;
112
113    /**
114     * {@link PackageInfo} flag: return information about the
115     * signatures included in the package.
116     */
117    public static final int GET_SIGNATURES          = 0x00000040;
118
119    /**
120     * {@link ResolveInfo} flag: return the IntentFilter that
121     * was matched for a particular ResolveInfo in
122     * {@link ResolveInfo#filter}.
123     */
124    public static final int GET_RESOLVED_FILTER         = 0x00000040;
125
126    /**
127     * {@link ComponentInfo} flag: return the {@link ComponentInfo#metaData}
128     * data {@link android.os.Bundle}s that are associated with a component.
129     * This applies for any API returning a ComponentInfo subclass.
130     */
131    public static final int GET_META_DATA               = 0x00000080;
132
133    /**
134     * {@link PackageInfo} flag: return the
135     * {@link PackageInfo#gids group ids} that are associated with an
136     * application.
137     * This applies for any API returning a PackageInfo class, either
138     * directly or nested inside of another.
139     */
140    public static final int GET_GIDS                    = 0x00000100;
141
142    /**
143     * {@link PackageInfo} flag: include disabled components in the returned info.
144     */
145    public static final int GET_DISABLED_COMPONENTS     = 0x00000200;
146
147    /**
148     * {@link ApplicationInfo} flag: return the
149     * {@link ApplicationInfo#sharedLibraryFiles paths to the shared libraries}
150     * that are associated with an application.
151     * This applies for any API returning an ApplicationInfo class, either
152     * directly or nested inside of another.
153     */
154    public static final int GET_SHARED_LIBRARY_FILES    = 0x00000400;
155
156    /**
157     * {@link ProviderInfo} flag: return the
158     * {@link ProviderInfo#uriPermissionPatterns URI permission patterns}
159     * that are associated with a content provider.
160     * This applies for any API returning a ProviderInfo class, either
161     * directly or nested inside of another.
162     */
163    public static final int GET_URI_PERMISSION_PATTERNS  = 0x00000800;
164    /**
165     * {@link PackageInfo} flag: return information about
166     * permissions in the package in
167     * {@link PackageInfo#permissions}.
168     */
169    public static final int GET_PERMISSIONS               = 0x00001000;
170
171    /**
172     * Flag parameter to retrieve some information about all applications (even
173     * uninstalled ones) which have data directories. This state could have
174     * resulted if applications have been deleted with flag
175     * {@code DONT_DELETE_DATA} with a possibility of being replaced or
176     * reinstalled in future.
177     * <p>
178     * Note: this flag may cause less information about currently installed
179     * applications to be returned.
180     */
181    public static final int GET_UNINSTALLED_PACKAGES = 0x00002000;
182
183    /**
184     * {@link PackageInfo} flag: return information about
185     * hardware preferences in
186     * {@link PackageInfo#configPreferences PackageInfo.configPreferences},
187     * and requested features in {@link PackageInfo#reqFeatures} and
188     * {@link PackageInfo#featureGroups}.
189     */
190    public static final int GET_CONFIGURATIONS = 0x00004000;
191
192    /**
193     * {@link PackageInfo} flag: include disabled components which are in
194     * that state only because of {@link #COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED}
195     * in the returned info.  Note that if you set this flag, applications
196     * that are in this disabled state will be reported as enabled.
197     */
198    public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 0x00008000;
199
200    /**
201     * Resolution and querying flag: if set, only filters that support the
202     * {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for
203     * matching.  This is a synonym for including the CATEGORY_DEFAULT in your
204     * supplied Intent.
205     */
206    public static final int MATCH_DEFAULT_ONLY   = 0x00010000;
207
208    /**
209     * Flag for {@link addCrossProfileIntentFilter}: if this flag is set:
210     * when resolving an intent that matches the {@link CrossProfileIntentFilter}, the current
211     * profile will be skipped.
212     * Only activities in the target user can respond to the intent.
213     * @hide
214     */
215    public static final int SKIP_CURRENT_PROFILE = 0x00000002;
216
217    /** @hide */
218    @IntDef({PERMISSION_GRANTED, PERMISSION_DENIED})
219    @Retention(RetentionPolicy.SOURCE)
220    public @interface PermissionResult {}
221
222    /**
223     * Permission check result: this is returned by {@link #checkPermission}
224     * if the permission has been granted to the given package.
225     */
226    public static final int PERMISSION_GRANTED = 0;
227
228    /**
229     * Permission check result: this is returned by {@link #checkPermission}
230     * if the permission has not been granted to the given package.
231     */
232    public static final int PERMISSION_DENIED = -1;
233
234    /**
235     * Signature check result: this is returned by {@link #checkSignatures}
236     * if all signatures on the two packages match.
237     */
238    public static final int SIGNATURE_MATCH = 0;
239
240    /**
241     * Signature check result: this is returned by {@link #checkSignatures}
242     * if neither of the two packages is signed.
243     */
244    public static final int SIGNATURE_NEITHER_SIGNED = 1;
245
246    /**
247     * Signature check result: this is returned by {@link #checkSignatures}
248     * if the first package is not signed but the second is.
249     */
250    public static final int SIGNATURE_FIRST_NOT_SIGNED = -1;
251
252    /**
253     * Signature check result: this is returned by {@link #checkSignatures}
254     * if the second package is not signed but the first is.
255     */
256    public static final int SIGNATURE_SECOND_NOT_SIGNED = -2;
257
258    /**
259     * Signature check result: this is returned by {@link #checkSignatures}
260     * if not all signatures on both packages match.
261     */
262    public static final int SIGNATURE_NO_MATCH = -3;
263
264    /**
265     * Signature check result: this is returned by {@link #checkSignatures}
266     * if either of the packages are not valid.
267     */
268    public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
269
270    /**
271     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
272     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
273     * component or application is in its default enabled state (as specified
274     * in its manifest).
275     */
276    public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
277
278    /**
279     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
280     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
281     * component or application has been explictily enabled, regardless of
282     * what it has specified in its manifest.
283     */
284    public static final int COMPONENT_ENABLED_STATE_ENABLED = 1;
285
286    /**
287     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
288     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
289     * component or application has been explicitly disabled, regardless of
290     * what it has specified in its manifest.
291     */
292    public static final int COMPONENT_ENABLED_STATE_DISABLED = 2;
293
294    /**
295     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: The
296     * user has explicitly disabled the application, regardless of what it has
297     * specified in its manifest.  Because this is due to the user's request,
298     * they may re-enable it if desired through the appropriate system UI.  This
299     * option currently <strong>cannot</strong> be used with
300     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
301     */
302    public static final int COMPONENT_ENABLED_STATE_DISABLED_USER = 3;
303
304    /**
305     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: This
306     * application should be considered, until the point where the user actually
307     * wants to use it.  This means that it will not normally show up to the user
308     * (such as in the launcher), but various parts of the user interface can
309     * use {@link #GET_DISABLED_UNTIL_USED_COMPONENTS} to still see it and allow
310     * the user to select it (as for example an IME, device admin, etc).  Such code,
311     * once the user has selected the app, should at that point also make it enabled.
312     * This option currently <strong>can not</strong> be used with
313     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
314     */
315    public static final int COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED = 4;
316
317    /**
318     * Flag parameter for {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} to
319     * indicate that this package should be installed as forward locked, i.e. only the app itself
320     * should have access to its code and non-resource assets.
321     * @hide
322     */
323    public static final int INSTALL_FORWARD_LOCK = 0x00000001;
324
325    /**
326     * Flag parameter for {@link #installPackage} to indicate that you want to replace an already
327     * installed package, if one exists.
328     * @hide
329     */
330    public static final int INSTALL_REPLACE_EXISTING = 0x00000002;
331
332    /**
333     * Flag parameter for {@link #installPackage} to indicate that you want to
334     * allow test packages (those that have set android:testOnly in their
335     * manifest) to be installed.
336     * @hide
337     */
338    public static final int INSTALL_ALLOW_TEST = 0x00000004;
339
340    /**
341     * Flag parameter for {@link #installPackage} to indicate that this
342     * package has to be installed on the sdcard.
343     * @hide
344     */
345    public static final int INSTALL_EXTERNAL = 0x00000008;
346
347    /**
348     * Flag parameter for {@link #installPackage} to indicate that this package
349     * has to be installed on the sdcard.
350     * @hide
351     */
352    public static final int INSTALL_INTERNAL = 0x00000010;
353
354    /**
355     * Flag parameter for {@link #installPackage} to indicate that this install
356     * was initiated via ADB.
357     *
358     * @hide
359     */
360    public static final int INSTALL_FROM_ADB = 0x00000020;
361
362    /**
363     * Flag parameter for {@link #installPackage} to indicate that this install
364     * should immediately be visible to all users.
365     *
366     * @hide
367     */
368    public static final int INSTALL_ALL_USERS = 0x00000040;
369
370    /**
371     * Flag parameter for {@link #installPackage} to indicate that it is okay
372     * to install an update to an app where the newly installed app has a lower
373     * version code than the currently installed app.
374     *
375     * @hide
376     */
377    public static final int INSTALL_ALLOW_DOWNGRADE = 0x00000080;
378
379    /**
380     * Flag parameter for
381     * {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate
382     * that you don't want to kill the app containing the component.  Be careful when you set this
383     * since changing component states can make the containing application's behavior unpredictable.
384     */
385    public static final int DONT_KILL_APP = 0x00000001;
386
387    /**
388     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
389     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} on success.
390     * @hide
391     */
392    @SystemApi
393    public static final int INSTALL_SUCCEEDED = 1;
394
395    /**
396     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
397     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package is
398     * already installed.
399     * @hide
400     */
401    @SystemApi
402    public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;
403
404    /**
405     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
406     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package archive
407     * file is invalid.
408     * @hide
409     */
410    @SystemApi
411    public static final int INSTALL_FAILED_INVALID_APK = -2;
412
413    /**
414     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
415     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the URI passed in
416     * is invalid.
417     * @hide
418     */
419    @SystemApi
420    public static final int INSTALL_FAILED_INVALID_URI = -3;
421
422    /**
423     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
424     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package manager
425     * service found that the device didn't have enough storage space to install the app.
426     * @hide
427     */
428    @SystemApi
429    public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;
430
431    /**
432     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
433     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if a
434     * package is already installed with the same name.
435     * @hide
436     */
437    @SystemApi
438    public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;
439
440    /**
441     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
442     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
443     * the requested shared user does not exist.
444     * @hide
445     */
446    @SystemApi
447    public static final int INSTALL_FAILED_NO_SHARED_USER = -6;
448
449    /**
450     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
451     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
452     * a previously installed package of the same name has a different signature
453     * than the new package (and the old package's data was not removed).
454     * @hide
455     */
456    @SystemApi
457    public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;
458
459    /**
460     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
461     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
462     * the new package is requested a shared user which is already installed on the
463     * device and does not have matching signature.
464     * @hide
465     */
466    @SystemApi
467    public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;
468
469    /**
470     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
471     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
472     * the new package uses a shared library that is not available.
473     * @hide
474     */
475    @SystemApi
476    public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;
477
478    /**
479     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
480     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
481     * the new package uses a shared library that is not available.
482     * @hide
483     */
484    @SystemApi
485    public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;
486
487    /**
488     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
489     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
490     * the new package failed while optimizing and validating its dex files,
491     * either because there was not enough storage or the validation failed.
492     * @hide
493     */
494    @SystemApi
495    public static final int INSTALL_FAILED_DEXOPT = -11;
496
497    /**
498     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
499     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
500     * the new package failed because the current SDK version is older than
501     * that required by the package.
502     * @hide
503     */
504    @SystemApi
505    public static final int INSTALL_FAILED_OLDER_SDK = -12;
506
507    /**
508     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
509     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
510     * the new package failed because it contains a content provider with the
511     * same authority as a provider already installed in the system.
512     * @hide
513     */
514    @SystemApi
515    public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;
516
517    /**
518     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
519     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
520     * the new package failed because the current SDK version is newer than
521     * that required by the package.
522     * @hide
523     */
524    @SystemApi
525    public static final int INSTALL_FAILED_NEWER_SDK = -14;
526
527    /**
528     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
529     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
530     * the new package failed because it has specified that it is a test-only
531     * package and the caller has not supplied the {@link #INSTALL_ALLOW_TEST}
532     * flag.
533     * @hide
534     */
535    @SystemApi
536    public static final int INSTALL_FAILED_TEST_ONLY = -15;
537
538    /**
539     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
540     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
541     * the package being installed contains native code, but none that is
542     * compatible with the device's CPU_ABI.
543     * @hide
544     */
545    @SystemApi
546    public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;
547
548    /**
549     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
550     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
551     * the new package uses a feature that is not available.
552     * @hide
553     */
554    @SystemApi
555    public static final int INSTALL_FAILED_MISSING_FEATURE = -17;
556
557    // ------ Errors related to sdcard
558    /**
559     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
560     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
561     * a secure container mount point couldn't be accessed on external media.
562     * @hide
563     */
564    @SystemApi
565    public static final int INSTALL_FAILED_CONTAINER_ERROR = -18;
566
567    /**
568     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
569     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
570     * the new package couldn't be installed in the specified install
571     * location.
572     * @hide
573     */
574    @SystemApi
575    public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19;
576
577    /**
578     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
579     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
580     * the new package couldn't be installed in the specified install
581     * location because the media is not available.
582     * @hide
583     */
584    @SystemApi
585    public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE = -20;
586
587    /**
588     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
589     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
590     * the new package couldn't be installed because the verification timed out.
591     * @hide
592     */
593    @SystemApi
594    public static final int INSTALL_FAILED_VERIFICATION_TIMEOUT = -21;
595
596    /**
597     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
598     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
599     * the new package couldn't be installed because the verification did not succeed.
600     * @hide
601     */
602    @SystemApi
603    public static final int INSTALL_FAILED_VERIFICATION_FAILURE = -22;
604
605    /**
606     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
607     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
608     * the package changed from what the calling program expected.
609     * @hide
610     */
611    @SystemApi
612    public static final int INSTALL_FAILED_PACKAGE_CHANGED = -23;
613
614    /**
615     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
616     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
617     * the new package is assigned a different UID than it previously held.
618     * @hide
619     */
620    public static final int INSTALL_FAILED_UID_CHANGED = -24;
621
622    /**
623     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
624     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
625     * the new package has an older version code than the currently installed package.
626     * @hide
627     */
628    public static final int INSTALL_FAILED_VERSION_DOWNGRADE = -25;
629
630    /**
631     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
632     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
633     * if the parser was given a path that is not a file, or does not end with the expected
634     * '.apk' extension.
635     * @hide
636     */
637    @SystemApi
638    public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;
639
640    /**
641     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
642     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
643     * if the parser was unable to retrieve the AndroidManifest.xml file.
644     * @hide
645     */
646    @SystemApi
647    public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;
648
649    /**
650     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
651     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
652     * if the parser encountered an unexpected exception.
653     * @hide
654     */
655    @SystemApi
656    public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;
657
658    /**
659     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
660     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
661     * if the parser did not find any certificates in the .apk.
662     * @hide
663     */
664    @SystemApi
665    public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;
666
667    /**
668     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
669     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
670     * if the parser found inconsistent certificates on the files in the .apk.
671     * @hide
672     */
673    @SystemApi
674    public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;
675
676    /**
677     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
678     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
679     * if the parser encountered a CertificateEncodingException in one of the
680     * files in the .apk.
681     * @hide
682     */
683    @SystemApi
684    public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;
685
686    /**
687     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
688     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
689     * if the parser encountered a bad or missing package name in the manifest.
690     * @hide
691     */
692    @SystemApi
693    public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;
694
695    /**
696     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
697     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
698     * if the parser encountered a bad shared user id name in the manifest.
699     * @hide
700     */
701    @SystemApi
702    public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;
703
704    /**
705     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
706     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
707     * if the parser encountered some structural problem in the manifest.
708     * @hide
709     */
710    @SystemApi
711    public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;
712
713    /**
714     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
715     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
716     * if the parser did not find any actionable tags (instrumentation or application)
717     * in the manifest.
718     * @hide
719     */
720    @SystemApi
721    public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;
722
723    /**
724     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
725     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
726     * if the system failed to install the package because of system issues.
727     * @hide
728     */
729    @SystemApi
730    public static final int INSTALL_FAILED_INTERNAL_ERROR = -110;
731
732    /**
733     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
734     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
735     * if the system failed to install the package because the user is restricted from installing
736     * apps.
737     * @hide
738     */
739    public static final int INSTALL_FAILED_USER_RESTRICTED = -111;
740
741    /**
742     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
743     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
744     * if the system failed to install the package because it is attempting to define a
745     * permission that is already defined by some existing package.
746     *
747     * <p>The package name of the app which has already defined the permission is passed to
748     * a {@link PackageInstallObserver}, if any, as the {@link #EXTRA_EXISTING_PACKAGE}
749     * string extra; and the name of the permission being redefined is passed in the
750     * {@link #EXTRA_EXISTING_PERMISSION} string extra.
751     * @hide
752     */
753    public static final int INSTALL_FAILED_DUPLICATE_PERMISSION = -112;
754
755    /**
756     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
757     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
758     * if the system failed to install the package because its packaged native code did not
759     * match any of the ABIs supported by the system.
760     *
761     * @hide
762     */
763    public static final int INSTALL_FAILED_NO_MATCHING_ABIS = -113;
764
765    /**
766     * Internal return code for NativeLibraryHelper methods to indicate that the package
767     * being processed did not contain any native code. This is placed here only so that
768     * it can belong to the same value space as the other install failure codes.
769     *
770     * @hide
771     */
772    public static final int NO_NATIVE_LIBRARIES = -114;
773
774    /** {@hide} */
775    public static final int INSTALL_FAILED_ABORTED = -115;
776
777    /**
778     * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
779     * package's data directory.
780     *
781     * @hide
782     */
783    public static final int DELETE_KEEP_DATA = 0x00000001;
784
785    /**
786     * Flag parameter for {@link #deletePackage} to indicate that you want the
787     * package deleted for all users.
788     *
789     * @hide
790     */
791    public static final int DELETE_ALL_USERS = 0x00000002;
792
793    /**
794     * Flag parameter for {@link #deletePackage} to indicate that, if you are calling
795     * uninstall on a system that has been updated, then don't do the normal process
796     * of uninstalling the update and rolling back to the older system version (which
797     * needs to happen for all users); instead, just mark the app as uninstalled for
798     * the current user.
799     *
800     * @hide
801     */
802    public static final int DELETE_SYSTEM_APP = 0x00000004;
803
804    /**
805     * Return code for when package deletion succeeds. This is passed to the
806     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
807     * succeeded in deleting the package.
808     *
809     * @hide
810     */
811    public static final int DELETE_SUCCEEDED = 1;
812
813    /**
814     * Deletion failed return code: this is passed to the
815     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
816     * failed to delete the package for an unspecified reason.
817     *
818     * @hide
819     */
820    public static final int DELETE_FAILED_INTERNAL_ERROR = -1;
821
822    /**
823     * Deletion failed return code: this is passed to the
824     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
825     * failed to delete the package because it is the active DevicePolicy
826     * manager.
827     *
828     * @hide
829     */
830    public static final int DELETE_FAILED_DEVICE_POLICY_MANAGER = -2;
831
832    /**
833     * Deletion failed return code: this is passed to the
834     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
835     * failed to delete the package since the user is restricted.
836     *
837     * @hide
838     */
839    public static final int DELETE_FAILED_USER_RESTRICTED = -3;
840
841    /**
842     * Deletion failed return code: this is passed to the
843     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
844     * failed to delete the package because a profile
845     * or device owner has marked the package as uninstallable.
846     *
847     * @hide
848     */
849    public static final int DELETE_FAILED_OWNER_BLOCKED = -4;
850
851    /** {@hide} */
852    public static final int DELETE_FAILED_ABORTED = -5;
853
854    /**
855     * Return code that is passed to the {@link IPackageMoveObserver} by
856     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)} when the
857     * package has been successfully moved by the system.
858     *
859     * @hide
860     */
861    public static final int MOVE_SUCCEEDED = 1;
862    /**
863     * Error code that is passed to the {@link IPackageMoveObserver} by
864     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
865     * when the package hasn't been successfully moved by the system
866     * because of insufficient memory on specified media.
867     * @hide
868     */
869    public static final int MOVE_FAILED_INSUFFICIENT_STORAGE = -1;
870
871    /**
872     * Error code that is passed to the {@link IPackageMoveObserver} by
873     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
874     * if the specified package doesn't exist.
875     * @hide
876     */
877    public static final int MOVE_FAILED_DOESNT_EXIST = -2;
878
879    /**
880     * Error code that is passed to the {@link IPackageMoveObserver} by
881     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
882     * if the specified package cannot be moved since its a system package.
883     * @hide
884     */
885    public static final int MOVE_FAILED_SYSTEM_PACKAGE = -3;
886
887    /**
888     * Error code that is passed to the {@link IPackageMoveObserver} by
889     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
890     * if the specified package cannot be moved since its forward locked.
891     * @hide
892     */
893    public static final int MOVE_FAILED_FORWARD_LOCKED = -4;
894
895    /**
896     * Error code that is passed to the {@link IPackageMoveObserver} by
897     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
898     * if the specified package cannot be moved to the specified location.
899     * @hide
900     */
901    public static final int MOVE_FAILED_INVALID_LOCATION = -5;
902
903    /**
904     * Error code that is passed to the {@link IPackageMoveObserver} by
905     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
906     * if the specified package cannot be moved to the specified location.
907     * @hide
908     */
909    public static final int MOVE_FAILED_INTERNAL_ERROR = -6;
910
911    /**
912     * Error code that is passed to the {@link IPackageMoveObserver} by
913     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)} if the
914     * specified package already has an operation pending in the
915     * {@link PackageHandler} queue.
916     *
917     * @hide
918     */
919    public static final int MOVE_FAILED_OPERATION_PENDING = -7;
920
921    /**
922     * Flag parameter for {@link #movePackage} to indicate that
923     * the package should be moved to internal storage if its
924     * been installed on external media.
925     * @hide
926     */
927    public static final int MOVE_INTERNAL = 0x00000001;
928
929    /**
930     * Flag parameter for {@link #movePackage} to indicate that
931     * the package should be moved to external media.
932     * @hide
933     */
934    public static final int MOVE_EXTERNAL_MEDIA = 0x00000002;
935
936    /**
937     * Usable by the required verifier as the {@code verificationCode} argument
938     * for {@link PackageManager#verifyPendingInstall} to indicate that it will
939     * allow the installation to proceed without any of the optional verifiers
940     * needing to vote.
941     *
942     * @hide
943     */
944    public static final int VERIFICATION_ALLOW_WITHOUT_SUFFICIENT = 2;
945
946    /**
947     * Used as the {@code verificationCode} argument for
948     * {@link PackageManager#verifyPendingInstall} to indicate that the calling
949     * package verifier allows the installation to proceed.
950     */
951    public static final int VERIFICATION_ALLOW = 1;
952
953    /**
954     * Used as the {@code verificationCode} argument for
955     * {@link PackageManager#verifyPendingInstall} to indicate the calling
956     * package verifier does not vote to allow the installation to proceed.
957     */
958    public static final int VERIFICATION_REJECT = -1;
959
960    /**
961     * Can be used as the {@code millisecondsToDelay} argument for
962     * {@link PackageManager#extendVerificationTimeout}. This is the
963     * maximum time {@code PackageManager} waits for the verification
964     * agent to return (in milliseconds).
965     */
966    public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000;
967
968    /**
969     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's
970     * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or
971     * lag in sound input or output.
972     */
973    @SdkConstant(SdkConstantType.FEATURE)
974    public static final String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
975
976    /**
977     * Feature for {@link #getSystemAvailableFeatures} and
978     * {@link #hasSystemFeature}: The device includes at least one form of audio
979     * output, such as speakers, audio jack or streaming over bluetooth
980     */
981    @SdkConstant(SdkConstantType.FEATURE)
982    public static final String FEATURE_AUDIO_OUTPUT = "android.hardware.audio.output";
983
984    /**
985     * Feature for {@link #getSystemAvailableFeatures} and
986     * {@link #hasSystemFeature}: The device is capable of communicating with
987     * other devices via Bluetooth.
988     */
989    @SdkConstant(SdkConstantType.FEATURE)
990    public static final String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
991
992    /**
993     * Feature for {@link #getSystemAvailableFeatures} and
994     * {@link #hasSystemFeature}: The device is capable of communicating with
995     * other devices via Bluetooth Low Energy radio.
996     */
997    @SdkConstant(SdkConstantType.FEATURE)
998    public static final String FEATURE_BLUETOOTH_LE = "android.hardware.bluetooth_le";
999
1000    /**
1001     * Feature for {@link #getSystemAvailableFeatures} and
1002     * {@link #hasSystemFeature}: The device has a camera facing away
1003     * from the screen.
1004     */
1005    @SdkConstant(SdkConstantType.FEATURE)
1006    public static final String FEATURE_CAMERA = "android.hardware.camera";
1007
1008    /**
1009     * Feature for {@link #getSystemAvailableFeatures} and
1010     * {@link #hasSystemFeature}: The device's camera supports auto-focus.
1011     */
1012    @SdkConstant(SdkConstantType.FEATURE)
1013    public static final String FEATURE_CAMERA_AUTOFOCUS = "android.hardware.camera.autofocus";
1014
1015    /**
1016     * Feature for {@link #getSystemAvailableFeatures} and
1017     * {@link #hasSystemFeature}: The device has at least one camera pointing in
1018     * some direction, or can support an external camera being connected to it.
1019     */
1020    @SdkConstant(SdkConstantType.FEATURE)
1021    public static final String FEATURE_CAMERA_ANY = "android.hardware.camera.any";
1022
1023    /**
1024     * Feature for {@link #getSystemAvailableFeatures} and
1025     * {@link #hasSystemFeature}: The device can support having an external camera connected to it.
1026     * The external camera may not always be connected or available to applications to use.
1027     */
1028    @SdkConstant(SdkConstantType.FEATURE)
1029    public static final String FEATURE_CAMERA_EXTERNAL = "android.hardware.camera.external";
1030
1031    /**
1032     * Feature for {@link #getSystemAvailableFeatures} and
1033     * {@link #hasSystemFeature}: The device's camera supports flash.
1034     */
1035    @SdkConstant(SdkConstantType.FEATURE)
1036    public static final String FEATURE_CAMERA_FLASH = "android.hardware.camera.flash";
1037
1038    /**
1039     * Feature for {@link #getSystemAvailableFeatures} and
1040     * {@link #hasSystemFeature}: The device has a front facing camera.
1041     */
1042    @SdkConstant(SdkConstantType.FEATURE)
1043    public static final String FEATURE_CAMERA_FRONT = "android.hardware.camera.front";
1044
1045    /**
1046     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1047     * of the cameras on the device supports the
1048     * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL full hardware}
1049     * capability level.
1050     */
1051    @SdkConstant(SdkConstantType.FEATURE)
1052    public static final String FEATURE_CAMERA_LEVEL_FULL = "android.hardware.camera.level.full";
1053
1054    /**
1055     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1056     * of the cameras on the device supports the
1057     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR manual sensor}
1058     * capability level.
1059     */
1060    @SdkConstant(SdkConstantType.FEATURE)
1061    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR =
1062            "android.hardware.camera.capability.manual_sensor";
1063
1064    /**
1065     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1066     * of the cameras on the device supports the
1067     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING manual post-processing}
1068     * capability level.
1069     */
1070    @SdkConstant(SdkConstantType.FEATURE)
1071    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING =
1072            "android.hardware.camera.capability.manual_post_processing";
1073
1074    /**
1075     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1076     * of the cameras on the device supports the
1077     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}
1078     * capability level.
1079     */
1080    @SdkConstant(SdkConstantType.FEATURE)
1081    public static final String FEATURE_CAMERA_CAPABILITY_RAW =
1082            "android.hardware.camera.capability.raw";
1083
1084    /**
1085     * Feature for {@link #getSystemAvailableFeatures} and
1086     * {@link #hasSystemFeature}: The device is capable of communicating with
1087     * consumer IR devices.
1088     */
1089    @SdkConstant(SdkConstantType.FEATURE)
1090    public static final String FEATURE_CONSUMER_IR = "android.hardware.consumerir";
1091
1092    /**
1093     * Feature for {@link #getSystemAvailableFeatures} and
1094     * {@link #hasSystemFeature}: The device supports one or more methods of
1095     * reporting current location.
1096     */
1097    @SdkConstant(SdkConstantType.FEATURE)
1098    public static final String FEATURE_LOCATION = "android.hardware.location";
1099
1100    /**
1101     * Feature for {@link #getSystemAvailableFeatures} and
1102     * {@link #hasSystemFeature}: The device has a Global Positioning System
1103     * receiver and can report precise location.
1104     */
1105    @SdkConstant(SdkConstantType.FEATURE)
1106    public static final String FEATURE_LOCATION_GPS = "android.hardware.location.gps";
1107
1108    /**
1109     * Feature for {@link #getSystemAvailableFeatures} and
1110     * {@link #hasSystemFeature}: The device can report location with coarse
1111     * accuracy using a network-based geolocation system.
1112     */
1113    @SdkConstant(SdkConstantType.FEATURE)
1114    public static final String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
1115
1116    /**
1117     * Feature for {@link #getSystemAvailableFeatures} and
1118     * {@link #hasSystemFeature}: The device can record audio via a
1119     * microphone.
1120     */
1121    @SdkConstant(SdkConstantType.FEATURE)
1122    public static final String FEATURE_MICROPHONE = "android.hardware.microphone";
1123
1124    /**
1125     * Feature for {@link #getSystemAvailableFeatures} and
1126     * {@link #hasSystemFeature}: The device can communicate using Near-Field
1127     * Communications (NFC).
1128     */
1129    @SdkConstant(SdkConstantType.FEATURE)
1130    public static final String FEATURE_NFC = "android.hardware.nfc";
1131
1132    /**
1133     * Feature for {@link #getSystemAvailableFeatures} and
1134     * {@link #hasSystemFeature}: The device supports host-
1135     * based NFC card emulation.
1136     *
1137     * TODO remove when depending apps have moved to new constant.
1138     * @hide
1139     * @deprecated
1140     */
1141    @Deprecated
1142    @SdkConstant(SdkConstantType.FEATURE)
1143    public static final String FEATURE_NFC_HCE = "android.hardware.nfc.hce";
1144
1145    /**
1146     * Feature for {@link #getSystemAvailableFeatures} and
1147     * {@link #hasSystemFeature}: The device supports host-
1148     * based NFC card emulation.
1149     */
1150    @SdkConstant(SdkConstantType.FEATURE)
1151    public static final String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
1152
1153    /**
1154     * Feature for {@link #getSystemAvailableFeatures} and
1155     * {@link #hasSystemFeature}: The device supports the OpenGL ES
1156     * <a href="http://www.khronos.org/registry/gles/extensions/ANDROID/ANDROID_extension_pack_es31a.txt">
1157     * Android Extension Pack</a>.
1158     */
1159    @SdkConstant(SdkConstantType.FEATURE)
1160    public static final String FEATURE_OPENGLES_EXTENSION_PACK = "android.hardware.opengles.aep";
1161
1162    /**
1163     * Feature for {@link #getSystemAvailableFeatures} and
1164     * {@link #hasSystemFeature}: The device includes an accelerometer.
1165     */
1166    @SdkConstant(SdkConstantType.FEATURE)
1167    public static final String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
1168
1169    /**
1170     * Feature for {@link #getSystemAvailableFeatures} and
1171     * {@link #hasSystemFeature}: The device includes a barometer (air
1172     * pressure sensor.)
1173     */
1174    @SdkConstant(SdkConstantType.FEATURE)
1175    public static final String FEATURE_SENSOR_BAROMETER = "android.hardware.sensor.barometer";
1176
1177    /**
1178     * Feature for {@link #getSystemAvailableFeatures} and
1179     * {@link #hasSystemFeature}: The device includes a magnetometer (compass).
1180     */
1181    @SdkConstant(SdkConstantType.FEATURE)
1182    public static final String FEATURE_SENSOR_COMPASS = "android.hardware.sensor.compass";
1183
1184    /**
1185     * Feature for {@link #getSystemAvailableFeatures} and
1186     * {@link #hasSystemFeature}: The device includes a gyroscope.
1187     */
1188    @SdkConstant(SdkConstantType.FEATURE)
1189    public static final String FEATURE_SENSOR_GYROSCOPE = "android.hardware.sensor.gyroscope";
1190
1191    /**
1192     * Feature for {@link #getSystemAvailableFeatures} and
1193     * {@link #hasSystemFeature}: The device includes a light sensor.
1194     */
1195    @SdkConstant(SdkConstantType.FEATURE)
1196    public static final String FEATURE_SENSOR_LIGHT = "android.hardware.sensor.light";
1197
1198    /**
1199     * Feature for {@link #getSystemAvailableFeatures} and
1200     * {@link #hasSystemFeature}: The device includes a proximity sensor.
1201     */
1202    @SdkConstant(SdkConstantType.FEATURE)
1203    public static final String FEATURE_SENSOR_PROXIMITY = "android.hardware.sensor.proximity";
1204
1205    /**
1206     * Feature for {@link #getSystemAvailableFeatures} and
1207     * {@link #hasSystemFeature}: The device includes a hardware step counter.
1208     */
1209    @SdkConstant(SdkConstantType.FEATURE)
1210    public static final String FEATURE_SENSOR_STEP_COUNTER = "android.hardware.sensor.stepcounter";
1211
1212    /**
1213     * Feature for {@link #getSystemAvailableFeatures} and
1214     * {@link #hasSystemFeature}: The device includes a hardware step detector.
1215     */
1216    @SdkConstant(SdkConstantType.FEATURE)
1217    public static final String FEATURE_SENSOR_STEP_DETECTOR = "android.hardware.sensor.stepdetector";
1218
1219    /**
1220     * Feature for {@link #getSystemAvailableFeatures} and
1221     * {@link #hasSystemFeature}: The device includes a heart rate monitor.
1222     */
1223    @SdkConstant(SdkConstantType.FEATURE)
1224    public static final String FEATURE_SENSOR_HEART_RATE = "android.hardware.sensor.heartrate";
1225
1226    /**
1227     * Feature for {@link #getSystemAvailableFeatures} and
1228     * {@link #hasSystemFeature}: The heart rate sensor on this device is an Electrocargiogram.
1229     */
1230    @SdkConstant(SdkConstantType.FEATURE)
1231    public static final String FEATURE_SENSOR_HEART_RATE_ECG =
1232            "android.hardware.sensor.heartrate.ecg";
1233
1234    /**
1235     * Feature for {@link #getSystemAvailableFeatures} and
1236     * {@link #hasSystemFeature}: The device includes a relative humidity sensor.
1237     */
1238    @SdkConstant(SdkConstantType.FEATURE)
1239    public static final String FEATURE_SENSOR_RELATIVE_HUMIDITY =
1240            "android.hardware.sensor.relative_humidity";
1241
1242    /**
1243     * Feature for {@link #getSystemAvailableFeatures} and
1244     * {@link #hasSystemFeature}: The device includes an ambient temperature sensor.
1245     */
1246    @SdkConstant(SdkConstantType.FEATURE)
1247    public static final String FEATURE_SENSOR_AMBIENT_TEMPERATURE =
1248            "android.hardware.sensor.ambient_temperature";
1249
1250    /**
1251     * Feature for {@link #getSystemAvailableFeatures} and
1252     * {@link #hasSystemFeature}: The device has a telephony radio with data
1253     * communication support.
1254     */
1255    @SdkConstant(SdkConstantType.FEATURE)
1256    public static final String FEATURE_TELEPHONY = "android.hardware.telephony";
1257
1258    /**
1259     * Feature for {@link #getSystemAvailableFeatures} and
1260     * {@link #hasSystemFeature}: The device has a CDMA telephony stack.
1261     */
1262    @SdkConstant(SdkConstantType.FEATURE)
1263    public static final String FEATURE_TELEPHONY_CDMA = "android.hardware.telephony.cdma";
1264
1265    /**
1266     * Feature for {@link #getSystemAvailableFeatures} and
1267     * {@link #hasSystemFeature}: The device has a GSM telephony stack.
1268     */
1269    @SdkConstant(SdkConstantType.FEATURE)
1270    public static final String FEATURE_TELEPHONY_GSM = "android.hardware.telephony.gsm";
1271
1272    /**
1273     * Feature for {@link #getSystemAvailableFeatures} and
1274     * {@link #hasSystemFeature}: The device supports connecting to USB devices
1275     * as the USB host.
1276     */
1277    @SdkConstant(SdkConstantType.FEATURE)
1278    public static final String FEATURE_USB_HOST = "android.hardware.usb.host";
1279
1280    /**
1281     * Feature for {@link #getSystemAvailableFeatures} and
1282     * {@link #hasSystemFeature}: The device supports connecting to USB accessories.
1283     */
1284    @SdkConstant(SdkConstantType.FEATURE)
1285    public static final String FEATURE_USB_ACCESSORY = "android.hardware.usb.accessory";
1286
1287    /**
1288     * Feature for {@link #getSystemAvailableFeatures} and
1289     * {@link #hasSystemFeature}: The SIP API is enabled on the device.
1290     */
1291    @SdkConstant(SdkConstantType.FEATURE)
1292    public static final String FEATURE_SIP = "android.software.sip";
1293
1294    /**
1295     * Feature for {@link #getSystemAvailableFeatures} and
1296     * {@link #hasSystemFeature}: The device supports SIP-based VOIP.
1297     */
1298    @SdkConstant(SdkConstantType.FEATURE)
1299    public static final String FEATURE_SIP_VOIP = "android.software.sip.voip";
1300
1301    /**
1302     * Feature for {@link #getSystemAvailableFeatures} and
1303     * {@link #hasSystemFeature}: The Connection Service API is enabled on the device.
1304     */
1305    @SdkConstant(SdkConstantType.FEATURE)
1306    public static final String FEATURE_CONNECTION_SERVICE = "android.software.connectionservice";
1307
1308    /**
1309     * Feature for {@link #getSystemAvailableFeatures} and
1310     * {@link #hasSystemFeature}: The device's display has a touch screen.
1311     */
1312    @SdkConstant(SdkConstantType.FEATURE)
1313    public static final String FEATURE_TOUCHSCREEN = "android.hardware.touchscreen";
1314
1315    /**
1316     * Feature for {@link #getSystemAvailableFeatures} and
1317     * {@link #hasSystemFeature}: The device's touch screen supports
1318     * multitouch sufficient for basic two-finger gesture detection.
1319     */
1320    @SdkConstant(SdkConstantType.FEATURE)
1321    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH = "android.hardware.touchscreen.multitouch";
1322
1323    /**
1324     * Feature for {@link #getSystemAvailableFeatures} and
1325     * {@link #hasSystemFeature}: The device's touch screen is capable of
1326     * tracking two or more fingers fully independently.
1327     */
1328    @SdkConstant(SdkConstantType.FEATURE)
1329    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT = "android.hardware.touchscreen.multitouch.distinct";
1330
1331    /**
1332     * Feature for {@link #getSystemAvailableFeatures} and
1333     * {@link #hasSystemFeature}: The device's touch screen is capable of
1334     * tracking a full hand of fingers fully independently -- that is, 5 or
1335     * more simultaneous independent pointers.
1336     */
1337    @SdkConstant(SdkConstantType.FEATURE)
1338    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND = "android.hardware.touchscreen.multitouch.jazzhand";
1339
1340    /**
1341     * Feature for {@link #getSystemAvailableFeatures} and
1342     * {@link #hasSystemFeature}: The device does not have a touch screen, but
1343     * does support touch emulation for basic events. For instance, the
1344     * device might use a mouse or remote control to drive a cursor, and
1345     * emulate basic touch pointer events like down, up, drag, etc. All
1346     * devices that support android.hardware.touchscreen or a sub-feature are
1347     * presumed to also support faketouch.
1348     */
1349    @SdkConstant(SdkConstantType.FEATURE)
1350    public static final String FEATURE_FAKETOUCH = "android.hardware.faketouch";
1351
1352    /**
1353     * Feature for {@link #getSystemAvailableFeatures} and
1354     * {@link #hasSystemFeature}: The device does not have a touch screen, but
1355     * does support touch emulation for basic events that supports distinct
1356     * tracking of two or more fingers.  This is an extension of
1357     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
1358     * that unlike a distinct multitouch screen as defined by
1359     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT}, these kinds of input
1360     * devices will not actually provide full two-finger gestures since the
1361     * input is being transformed to cursor movement on the screen.  That is,
1362     * single finger gestures will move a cursor; two-finger swipes will
1363     * result in single-finger touch events; other two-finger gestures will
1364     * result in the corresponding two-finger touch event.
1365     */
1366    @SdkConstant(SdkConstantType.FEATURE)
1367    public static final String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
1368
1369    /**
1370     * Feature for {@link #getSystemAvailableFeatures} and
1371     * {@link #hasSystemFeature}: The device does not have a touch screen, but
1372     * does support touch emulation for basic events that supports tracking
1373     * a hand of fingers (5 or more fingers) fully independently.
1374     * This is an extension of
1375     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
1376     * that unlike a multitouch screen as defined by
1377     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND}, not all two finger
1378     * gestures can be detected due to the limitations described for
1379     * {@link #FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT}.
1380     */
1381    @SdkConstant(SdkConstantType.FEATURE)
1382    public static final String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
1383
1384    /**
1385     * Feature for {@link #getSystemAvailableFeatures} and
1386     * {@link #hasSystemFeature}: The device supports portrait orientation
1387     * screens.  For backwards compatibility, you can assume that if neither
1388     * this nor {@link #FEATURE_SCREEN_LANDSCAPE} is set then the device supports
1389     * both portrait and landscape.
1390     */
1391    @SdkConstant(SdkConstantType.FEATURE)
1392    public static final String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
1393
1394    /**
1395     * Feature for {@link #getSystemAvailableFeatures} and
1396     * {@link #hasSystemFeature}: The device supports landscape orientation
1397     * screens.  For backwards compatibility, you can assume that if neither
1398     * this nor {@link #FEATURE_SCREEN_PORTRAIT} is set then the device supports
1399     * both portrait and landscape.
1400     */
1401    @SdkConstant(SdkConstantType.FEATURE)
1402    public static final String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
1403
1404    /**
1405     * Feature for {@link #getSystemAvailableFeatures} and
1406     * {@link #hasSystemFeature}: The device supports live wallpapers.
1407     */
1408    @SdkConstant(SdkConstantType.FEATURE)
1409    public static final String FEATURE_LIVE_WALLPAPER = "android.software.live_wallpaper";
1410    /**
1411     * Feature for {@link #getSystemAvailableFeatures} and
1412     * {@link #hasSystemFeature}: The device supports app widgets.
1413     */
1414    @SdkConstant(SdkConstantType.FEATURE)
1415    public static final String FEATURE_APP_WIDGETS = "android.software.app_widgets";
1416
1417    /**
1418     * @hide
1419     * Feature for {@link #getSystemAvailableFeatures} and
1420     * {@link #hasSystemFeature}: The device supports
1421     * {@link android.service.voice.VoiceInteractionService} and
1422     * {@link android.app.VoiceInteractor}.
1423     */
1424    @SdkConstant(SdkConstantType.FEATURE)
1425    public static final String FEATURE_VOICE_RECOGNIZERS = "android.software.voice_recognizers";
1426
1427
1428    /**
1429     * Feature for {@link #getSystemAvailableFeatures} and
1430     * {@link #hasSystemFeature}: The device supports a home screen that is replaceable
1431     * by third party applications.
1432     */
1433    @SdkConstant(SdkConstantType.FEATURE)
1434    public static final String FEATURE_HOME_SCREEN = "android.software.home_screen";
1435
1436    /**
1437     * Feature for {@link #getSystemAvailableFeatures} and
1438     * {@link #hasSystemFeature}: The device supports adding new input methods implemented
1439     * with the {@link android.inputmethodservice.InputMethodService} API.
1440     */
1441    @SdkConstant(SdkConstantType.FEATURE)
1442    public static final String FEATURE_INPUT_METHODS = "android.software.input_methods";
1443
1444    /**
1445     * Feature for {@link #getSystemAvailableFeatures} and
1446     * {@link #hasSystemFeature}: The device supports device policy enforcement via device admins.
1447     */
1448    @SdkConstant(SdkConstantType.FEATURE)
1449    public static final String FEATURE_DEVICE_ADMIN = "android.software.device_admin";
1450
1451    /**
1452     * Feature for {@link #getSystemAvailableFeatures} and
1453     * {@link #hasSystemFeature}: The device supports leanback UI. This is
1454     * typically used in a living room television experience, but is a software
1455     * feature unlike {@link #FEATURE_TELEVISION}. Devices running with this
1456     * feature will use resources associated with the "television" UI mode.
1457     */
1458    @SdkConstant(SdkConstantType.FEATURE)
1459    public static final String FEATURE_LEANBACK = "android.software.leanback";
1460
1461    /**
1462     * Feature for {@link #getSystemAvailableFeatures} and
1463     * {@link #hasSystemFeature}: The device supports only leanback UI. Only
1464     * applications designed for this experience should be run, though this is
1465     * not enforced by the system.
1466     * @hide
1467     */
1468    @SdkConstant(SdkConstantType.FEATURE)
1469    public static final String FEATURE_LEANBACK_ONLY = "android.software.leanback_only";
1470
1471    /**
1472     * Feature for {@link #getSystemAvailableFeatures} and
1473     * {@link #hasSystemFeature}: The device supports live TV and can display
1474     * contents from TV inputs implemented with the
1475     * {@link android.media.tv.TvInputService} API.
1476     */
1477    @SdkConstant(SdkConstantType.FEATURE)
1478    public static final String FEATURE_LIVE_TV = "android.software.live_tv";
1479
1480    /**
1481     * Feature for {@link #getSystemAvailableFeatures} and
1482     * {@link #hasSystemFeature}: The device supports WiFi (802.11) networking.
1483     */
1484    @SdkConstant(SdkConstantType.FEATURE)
1485    public static final String FEATURE_WIFI = "android.hardware.wifi";
1486
1487    /**
1488     * Feature for {@link #getSystemAvailableFeatures} and
1489     * {@link #hasSystemFeature}: The device supports Wi-Fi Direct networking.
1490     */
1491    @SdkConstant(SdkConstantType.FEATURE)
1492    public static final String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
1493
1494    /**
1495     * Feature for {@link #getSystemAvailableFeatures} and
1496     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
1497     * on a television.  Television here is defined to be a typical living
1498     * room television experience: displayed on a big screen, where the user
1499     * is sitting far away from it, and the dominant form of input will be
1500     * something like a DPAD, not through touch or mouse.
1501     * @deprecated use {@link #FEATURE_LEANBACK} instead.
1502     */
1503    @Deprecated
1504    @SdkConstant(SdkConstantType.FEATURE)
1505    public static final String FEATURE_TELEVISION = "android.hardware.type.television";
1506
1507    /**
1508     * Feature for {@link #getSystemAvailableFeatures} and
1509     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
1510     * on a watch. A watch here is defined to be a device worn on the body, perhaps on
1511     * the wrist. The user is very close when interacting with the device.
1512     */
1513    @SdkConstant(SdkConstantType.FEATURE)
1514    public static final String FEATURE_WATCH = "android.hardware.type.watch";
1515
1516    /**
1517     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1518     * The device supports printing.
1519     */
1520    @SdkConstant(SdkConstantType.FEATURE)
1521    public static final String FEATURE_PRINTING = "android.software.print";
1522
1523    /**
1524     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1525     * The device can perform backup and restore operations on installed applications.
1526     */
1527    @SdkConstant(SdkConstantType.FEATURE)
1528    public static final String FEATURE_BACKUP = "android.software.backup";
1529
1530    /**
1531     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1532     * The device supports creating secondary users and managed profiles via
1533     * {@link DevicePolicyManager}.
1534     */
1535    @SdkConstant(SdkConstantType.FEATURE)
1536    public static final String FEATURE_MANAGED_USERS = "android.software.managed_users";
1537
1538    /**
1539     * @hide
1540     * TODO: Remove after dependencies updated b/17392243
1541     */
1542    public static final String FEATURE_MANAGED_PROFILES = "android.software.managed_users";
1543
1544    /**
1545     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1546     * The device supports verified boot.
1547     */
1548    @SdkConstant(SdkConstantType.FEATURE)
1549    public static final String FEATURE_VERIFIED_BOOT = "android.software.verified_boot";
1550
1551    /**
1552     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1553     * The device supports secure removal of users. When a user is deleted the data associated
1554     * with that user is securely deleted and no longer available.
1555     */
1556    @SdkConstant(SdkConstantType.FEATURE)
1557    public static final String FEATURE_SECURELY_REMOVES_USERS
1558            = "android.software.securely_removes_users";
1559
1560    /**
1561     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1562     * The device has a full implementation of the android.webkit.* APIs. Devices
1563     * lacking this feature will not have a functioning WebView implementation.
1564     */
1565    @SdkConstant(SdkConstantType.FEATURE)
1566    public static final String FEATURE_WEBVIEW = "android.software.webview";
1567
1568    /**
1569     * Feature for {@link #getSystemAvailableFeatures} and
1570     * {@link #hasSystemFeature}: This device supports ethernet.
1571     * @hide
1572     */
1573    @SdkConstant(SdkConstantType.FEATURE)
1574    public static final String FEATURE_ETHERNET = "android.hardware.ethernet";
1575
1576    /**
1577     * Feature for {@link #getSystemAvailableFeatures} and
1578     * {@link #hasSystemFeature}: This device supports HDMI-CEC.
1579     * @hide
1580     */
1581    @SdkConstant(SdkConstantType.FEATURE)
1582    public static final String FEATURE_HDMI_CEC = "android.hardware.hdmi.cec";
1583
1584    /**
1585     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1586     * The device has all of the inputs necessary to be considered a compatible game controller, or
1587     * includes a compatible game controller in the box.
1588     */
1589    @SdkConstant(SdkConstantType.FEATURE)
1590    public static final String FEATURE_GAMEPAD = "android.hardware.gamepad";
1591
1592
1593    /**
1594     * Action to external storage service to clean out removed apps.
1595     * @hide
1596     */
1597    public static final String ACTION_CLEAN_EXTERNAL_STORAGE
1598            = "android.content.pm.CLEAN_EXTERNAL_STORAGE";
1599
1600    /**
1601     * Extra field name for the URI to a verification file. Passed to a package
1602     * verifier.
1603     *
1604     * @hide
1605     */
1606    public static final String EXTRA_VERIFICATION_URI = "android.content.pm.extra.VERIFICATION_URI";
1607
1608    /**
1609     * Extra field name for the ID of a package pending verification. Passed to
1610     * a package verifier and is used to call back to
1611     * {@link PackageManager#verifyPendingInstall(int, int)}
1612     */
1613    public static final String EXTRA_VERIFICATION_ID = "android.content.pm.extra.VERIFICATION_ID";
1614
1615    /**
1616     * Extra field name for the package identifier which is trying to install
1617     * the package.
1618     *
1619     * @hide
1620     */
1621    public static final String EXTRA_VERIFICATION_INSTALLER_PACKAGE
1622            = "android.content.pm.extra.VERIFICATION_INSTALLER_PACKAGE";
1623
1624    /**
1625     * Extra field name for the requested install flags for a package pending
1626     * verification. Passed to a package verifier.
1627     *
1628     * @hide
1629     */
1630    public static final String EXTRA_VERIFICATION_INSTALL_FLAGS
1631            = "android.content.pm.extra.VERIFICATION_INSTALL_FLAGS";
1632
1633    /**
1634     * Extra field name for the uid of who is requesting to install
1635     * the package.
1636     *
1637     * @hide
1638     */
1639    public static final String EXTRA_VERIFICATION_INSTALLER_UID
1640            = "android.content.pm.extra.VERIFICATION_INSTALLER_UID";
1641
1642    /**
1643     * Extra field name for the package name of a package pending verification.
1644     *
1645     * @hide
1646     */
1647    public static final String EXTRA_VERIFICATION_PACKAGE_NAME
1648            = "android.content.pm.extra.VERIFICATION_PACKAGE_NAME";
1649    /**
1650     * Extra field name for the result of a verification, either
1651     * {@link #VERIFICATION_ALLOW}, or {@link #VERIFICATION_REJECT}.
1652     * Passed to package verifiers after a package is verified.
1653     */
1654    public static final String EXTRA_VERIFICATION_RESULT
1655            = "android.content.pm.extra.VERIFICATION_RESULT";
1656
1657    /**
1658     * Extra field name for the version code of a package pending verification.
1659     *
1660     * @hide
1661     */
1662    public static final String EXTRA_VERIFICATION_VERSION_CODE
1663            = "android.content.pm.extra.VERIFICATION_VERSION_CODE";
1664
1665    /**
1666     * The action used to request that the user approve a permission request
1667     * from the application.
1668     *
1669     * @hide
1670     */
1671    public static final String ACTION_REQUEST_PERMISSION
1672            = "android.content.pm.action.REQUEST_PERMISSION";
1673
1674    /**
1675     * Extra field name for the list of permissions, which the user must approve.
1676     *
1677     * @hide
1678     */
1679    public static final String EXTRA_REQUEST_PERMISSION_PERMISSION_LIST
1680            = "android.content.pm.extra.PERMISSION_LIST";
1681
1682    /**
1683     * String extra for {@link PackageInstallObserver} in the 'extras' Bundle in case of
1684     * {@link #INSTALL_FAILED_DUPLICATE_PERMISSION}.  This extra names the package which provides
1685     * the existing definition for the permission.
1686     * @hide
1687     */
1688    public static final String EXTRA_FAILURE_EXISTING_PACKAGE
1689            = "android.content.pm.extra.FAILURE_EXISTING_PACKAGE";
1690
1691    /**
1692     * String extra for {@link PackageInstallObserver} in the 'extras' Bundle in case of
1693     * {@link #INSTALL_FAILED_DUPLICATE_PERMISSION}.  This extra names the permission that is
1694     * being redundantly defined by the package being installed.
1695     * @hide
1696     */
1697    public static final String EXTRA_FAILURE_EXISTING_PERMISSION
1698            = "android.content.pm.extra.FAILURE_EXISTING_PERMISSION";
1699
1700    /**
1701     * Retrieve overall information about an application package that is
1702     * installed on the system.
1703     * <p>
1704     * Throws {@link NameNotFoundException} if a package with the given name can
1705     * not be found on the system.
1706     *
1707     * @param packageName The full name (i.e. com.google.apps.contacts) of the
1708     *            desired package.
1709     * @param flags Additional option flags. Use any combination of
1710     *            {@link #GET_ACTIVITIES}, {@link #GET_GIDS},
1711     *            {@link #GET_CONFIGURATIONS}, {@link #GET_INSTRUMENTATION},
1712     *            {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
1713     *            {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
1714     *            {@link #GET_SIGNATURES}, {@link #GET_UNINSTALLED_PACKAGES} to
1715     *            modify the data returned.
1716     * @return Returns a PackageInfo object containing information about the
1717     *         package. If flag GET_UNINSTALLED_PACKAGES is set and if the
1718     *         package is not found in the list of installed applications, the
1719     *         package information is retrieved from the list of uninstalled
1720     *         applications (which includes installed applications as well as
1721     *         applications with data directory i.e. applications which had been
1722     *         deleted with {@code DONT_DELETE_DATA} flag set).
1723     * @see #GET_ACTIVITIES
1724     * @see #GET_GIDS
1725     * @see #GET_CONFIGURATIONS
1726     * @see #GET_INSTRUMENTATION
1727     * @see #GET_PERMISSIONS
1728     * @see #GET_PROVIDERS
1729     * @see #GET_RECEIVERS
1730     * @see #GET_SERVICES
1731     * @see #GET_SIGNATURES
1732     * @see #GET_UNINSTALLED_PACKAGES
1733     */
1734    public abstract PackageInfo getPackageInfo(String packageName, int flags)
1735            throws NameNotFoundException;
1736
1737    /**
1738     * Map from the current package names in use on the device to whatever
1739     * the current canonical name of that package is.
1740     * @param names Array of current names to be mapped.
1741     * @return Returns an array of the same size as the original, containing
1742     * the canonical name for each package.
1743     */
1744    public abstract String[] currentToCanonicalPackageNames(String[] names);
1745
1746    /**
1747     * Map from a packages canonical name to the current name in use on the device.
1748     * @param names Array of new names to be mapped.
1749     * @return Returns an array of the same size as the original, containing
1750     * the current name for each package.
1751     */
1752    public abstract String[] canonicalToCurrentPackageNames(String[] names);
1753
1754    /**
1755     * Returns a "good" intent to launch a front-door activity in a package.
1756     * This is used, for example, to implement an "open" button when browsing
1757     * through packages.  The current implementation looks first for a main
1758     * activity in the category {@link Intent#CATEGORY_INFO}, and next for a
1759     * main activity in the category {@link Intent#CATEGORY_LAUNCHER}. Returns
1760     * <code>null</code> if neither are found.
1761     *
1762     * @param packageName The name of the package to inspect.
1763     *
1764     * @return A fully-qualified {@link Intent} that can be used to launch the
1765     * main activity in the package. Returns <code>null</code> if the package
1766     * does not contain such an activity, or if <em>packageName</em> is not
1767     * recognized.
1768     */
1769    public abstract Intent getLaunchIntentForPackage(String packageName);
1770
1771    /**
1772     * Return a "good" intent to launch a front-door Leanback activity in a
1773     * package, for use for example to implement an "open" button when browsing
1774     * through packages. The current implementation will look for a main
1775     * activity in the category {@link Intent#CATEGORY_LEANBACK_LAUNCHER}, or
1776     * return null if no main leanback activities are found.
1777     * <p>
1778     * Throws {@link NameNotFoundException} if a package with the given name
1779     * cannot be found on the system.
1780     *
1781     * @param packageName The name of the package to inspect.
1782     * @return Returns either a fully-qualified Intent that can be used to launch
1783     *         the main Leanback activity in the package, or null if the package
1784     *         does not contain such an activity.
1785     */
1786    public abstract Intent getLeanbackLaunchIntentForPackage(String packageName);
1787
1788    /**
1789     * Return an array of all of the secondary group-ids that have been assigned
1790     * to a package.
1791     * <p>
1792     * Throws {@link NameNotFoundException} if a package with the given name
1793     * cannot be found on the system.
1794     *
1795     * @param packageName The full name (i.e. com.google.apps.contacts) of the
1796     *            desired package.
1797     * @return Returns an int array of the assigned gids, or null if there are
1798     *         none.
1799     */
1800    public abstract int[] getPackageGids(String packageName)
1801            throws NameNotFoundException;
1802
1803    /**
1804     * @hide Return the uid associated with the given package name for the
1805     * given user.
1806     *
1807     * <p>Throws {@link NameNotFoundException} if a package with the given
1808     * name can not be found on the system.
1809     *
1810     * @param packageName The full name (i.e. com.google.apps.contacts) of the
1811     *                    desired package.
1812     * @param userHandle The user handle identifier to look up the package under.
1813     *
1814     * @return Returns an integer uid who owns the given package name.
1815     */
1816    public abstract int getPackageUid(String packageName, int userHandle)
1817            throws NameNotFoundException;
1818
1819    /**
1820     * Retrieve all of the information we know about a particular permission.
1821     *
1822     * <p>Throws {@link NameNotFoundException} if a permission with the given
1823     * name cannot be found on the system.
1824     *
1825     * @param name The fully qualified name (i.e. com.google.permission.LOGIN)
1826     *             of the permission you are interested in.
1827     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
1828     * retrieve any meta-data associated with the permission.
1829     *
1830     * @return Returns a {@link PermissionInfo} containing information about the
1831     *         permission.
1832     */
1833    public abstract PermissionInfo getPermissionInfo(String name, int flags)
1834            throws NameNotFoundException;
1835
1836    /**
1837     * Query for all of the permissions associated with a particular group.
1838     *
1839     * <p>Throws {@link NameNotFoundException} if the given group does not
1840     * exist.
1841     *
1842     * @param group The fully qualified name (i.e. com.google.permission.LOGIN)
1843     *             of the permission group you are interested in.  Use null to
1844     *             find all of the permissions not associated with a group.
1845     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
1846     * retrieve any meta-data associated with the permissions.
1847     *
1848     * @return Returns a list of {@link PermissionInfo} containing information
1849     * about all of the permissions in the given group.
1850     */
1851    public abstract List<PermissionInfo> queryPermissionsByGroup(String group,
1852            int flags) throws NameNotFoundException;
1853
1854    /**
1855     * Retrieve all of the information we know about a particular group of
1856     * permissions.
1857     *
1858     * <p>Throws {@link NameNotFoundException} if a permission group with the given
1859     * name cannot be found on the system.
1860     *
1861     * @param name The fully qualified name (i.e. com.google.permission_group.APPS)
1862     *             of the permission you are interested in.
1863     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
1864     * retrieve any meta-data associated with the permission group.
1865     *
1866     * @return Returns a {@link PermissionGroupInfo} containing information
1867     * about the permission.
1868     */
1869    public abstract PermissionGroupInfo getPermissionGroupInfo(String name,
1870            int flags) throws NameNotFoundException;
1871
1872    /**
1873     * Retrieve all of the known permission groups in the system.
1874     *
1875     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
1876     * retrieve any meta-data associated with the permission group.
1877     *
1878     * @return Returns a list of {@link PermissionGroupInfo} containing
1879     * information about all of the known permission groups.
1880     */
1881    public abstract List<PermissionGroupInfo> getAllPermissionGroups(int flags);
1882
1883    /**
1884     * Retrieve all of the information we know about a particular
1885     * package/application.
1886     *
1887     * <p>Throws {@link NameNotFoundException} if an application with the given
1888     * package name cannot be found on the system.
1889     *
1890     * @param packageName The full name (i.e. com.google.apps.contacts) of an
1891     *                    application.
1892     * @param flags Additional option flags. Use any combination of
1893     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
1894     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
1895     *
1896     * @return  {@link ApplicationInfo} Returns ApplicationInfo object containing
1897     *         information about the package.
1898     *         If flag GET_UNINSTALLED_PACKAGES is set and  if the package is not
1899     *         found in the list of installed applications,
1900     *         the application information is retrieved from the
1901     *         list of uninstalled applications(which includes
1902     *         installed applications as well as applications
1903     *         with data directory ie applications which had been
1904     *         deleted with {@code DONT_DELETE_DATA} flag set).
1905     *
1906     * @see #GET_META_DATA
1907     * @see #GET_SHARED_LIBRARY_FILES
1908     * @see #GET_UNINSTALLED_PACKAGES
1909     */
1910    public abstract ApplicationInfo getApplicationInfo(String packageName,
1911            int flags) throws NameNotFoundException;
1912
1913    /**
1914     * Retrieve all of the information we know about a particular activity
1915     * class.
1916     *
1917     * <p>Throws {@link NameNotFoundException} if an activity with the given
1918     * class name cannot be found on the system.
1919     *
1920     * @param component The full component name (i.e.
1921     * com.google.apps.contacts/com.google.apps.contacts.ContactsList) of an Activity
1922     * class.
1923     * @param flags Additional option flags. Use any combination of
1924     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
1925     * to modify the data (in ApplicationInfo) returned.
1926     *
1927     * @return {@link ActivityInfo} containing information about the activity.
1928     *
1929     * @see #GET_INTENT_FILTERS
1930     * @see #GET_META_DATA
1931     * @see #GET_SHARED_LIBRARY_FILES
1932     */
1933    public abstract ActivityInfo getActivityInfo(ComponentName component,
1934            int flags) throws NameNotFoundException;
1935
1936    /**
1937     * Retrieve all of the information we know about a particular receiver
1938     * class.
1939     *
1940     * <p>Throws {@link NameNotFoundException} if a receiver with the given
1941     * class name cannot be found on the system.
1942     *
1943     * @param component The full component name (i.e.
1944     * com.google.apps.calendar/com.google.apps.calendar.CalendarAlarm) of a Receiver
1945     * class.
1946     * @param flags Additional option flags.  Use any combination of
1947     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
1948     * to modify the data returned.
1949     *
1950     * @return {@link ActivityInfo} containing information about the receiver.
1951     *
1952     * @see #GET_INTENT_FILTERS
1953     * @see #GET_META_DATA
1954     * @see #GET_SHARED_LIBRARY_FILES
1955     */
1956    public abstract ActivityInfo getReceiverInfo(ComponentName component,
1957            int flags) throws NameNotFoundException;
1958
1959    /**
1960     * Retrieve all of the information we know about a particular service
1961     * class.
1962     *
1963     * <p>Throws {@link NameNotFoundException} if a service with the given
1964     * class name cannot be found on the system.
1965     *
1966     * @param component The full component name (i.e.
1967     * com.google.apps.media/com.google.apps.media.BackgroundPlayback) of a Service
1968     * class.
1969     * @param flags Additional option flags.  Use any combination of
1970     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
1971     * to modify the data returned.
1972     *
1973     * @return ServiceInfo containing information about the service.
1974     *
1975     * @see #GET_META_DATA
1976     * @see #GET_SHARED_LIBRARY_FILES
1977     */
1978    public abstract ServiceInfo getServiceInfo(ComponentName component,
1979            int flags) throws NameNotFoundException;
1980
1981    /**
1982     * Retrieve all of the information we know about a particular content
1983     * provider class.
1984     *
1985     * <p>Throws {@link NameNotFoundException} if a provider with the given
1986     * class name cannot be found on the system.
1987     *
1988     * @param component The full component name (i.e.
1989     * com.google.providers.media/com.google.providers.media.MediaProvider) of a
1990     * ContentProvider class.
1991     * @param flags Additional option flags.  Use any combination of
1992     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
1993     * to modify the data returned.
1994     *
1995     * @return ProviderInfo containing information about the service.
1996     *
1997     * @see #GET_META_DATA
1998     * @see #GET_SHARED_LIBRARY_FILES
1999     */
2000    public abstract ProviderInfo getProviderInfo(ComponentName component,
2001            int flags) throws NameNotFoundException;
2002
2003    /**
2004     * Return a List of all packages that are installed
2005     * on the device.
2006     *
2007     * @param flags Additional option flags. Use any combination of
2008     * {@link #GET_ACTIVITIES},
2009     * {@link #GET_GIDS},
2010     * {@link #GET_CONFIGURATIONS},
2011     * {@link #GET_INSTRUMENTATION},
2012     * {@link #GET_PERMISSIONS},
2013     * {@link #GET_PROVIDERS},
2014     * {@link #GET_RECEIVERS},
2015     * {@link #GET_SERVICES},
2016     * {@link #GET_SIGNATURES},
2017     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2018     *
2019     * @return A List of PackageInfo objects, one for each package that is
2020     *         installed on the device.  In the unlikely case of there being no
2021     *         installed packages, an empty list is returned.
2022     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
2023     *         applications including those deleted with {@code DONT_DELETE_DATA}
2024     *         (partially installed apps with data directory) will be returned.
2025     *
2026     * @see #GET_ACTIVITIES
2027     * @see #GET_GIDS
2028     * @see #GET_CONFIGURATIONS
2029     * @see #GET_INSTRUMENTATION
2030     * @see #GET_PERMISSIONS
2031     * @see #GET_PROVIDERS
2032     * @see #GET_RECEIVERS
2033     * @see #GET_SERVICES
2034     * @see #GET_SIGNATURES
2035     * @see #GET_UNINSTALLED_PACKAGES
2036     */
2037    public abstract List<PackageInfo> getInstalledPackages(int flags);
2038
2039    /**
2040     * Return a List of all installed packages that are currently
2041     * holding any of the given permissions.
2042     *
2043     * @param flags Additional option flags. Use any combination of
2044     * {@link #GET_ACTIVITIES},
2045     * {@link #GET_GIDS},
2046     * {@link #GET_CONFIGURATIONS},
2047     * {@link #GET_INSTRUMENTATION},
2048     * {@link #GET_PERMISSIONS},
2049     * {@link #GET_PROVIDERS},
2050     * {@link #GET_RECEIVERS},
2051     * {@link #GET_SERVICES},
2052     * {@link #GET_SIGNATURES},
2053     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2054     *
2055     * @return Returns a List of PackageInfo objects, one for each installed
2056     * application that is holding any of the permissions that were provided.
2057     *
2058     * @see #GET_ACTIVITIES
2059     * @see #GET_GIDS
2060     * @see #GET_CONFIGURATIONS
2061     * @see #GET_INSTRUMENTATION
2062     * @see #GET_PERMISSIONS
2063     * @see #GET_PROVIDERS
2064     * @see #GET_RECEIVERS
2065     * @see #GET_SERVICES
2066     * @see #GET_SIGNATURES
2067     * @see #GET_UNINSTALLED_PACKAGES
2068     */
2069    public abstract List<PackageInfo> getPackagesHoldingPermissions(
2070            String[] permissions, int flags);
2071
2072    /**
2073     * Return a List of all packages that are installed on the device, for a specific user.
2074     * Requesting a list of installed packages for another user
2075     * will require the permission INTERACT_ACROSS_USERS_FULL.
2076     * @param flags Additional option flags. Use any combination of
2077     * {@link #GET_ACTIVITIES},
2078     * {@link #GET_GIDS},
2079     * {@link #GET_CONFIGURATIONS},
2080     * {@link #GET_INSTRUMENTATION},
2081     * {@link #GET_PERMISSIONS},
2082     * {@link #GET_PROVIDERS},
2083     * {@link #GET_RECEIVERS},
2084     * {@link #GET_SERVICES},
2085     * {@link #GET_SIGNATURES},
2086     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2087     * @param userId The user for whom the installed packages are to be listed
2088     *
2089     * @return A List of PackageInfo objects, one for each package that is
2090     *         installed on the device.  In the unlikely case of there being no
2091     *         installed packages, an empty list is returned.
2092     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
2093     *         applications including those deleted with {@code DONT_DELETE_DATA}
2094     *         (partially installed apps with data directory) will be returned.
2095     *
2096     * @see #GET_ACTIVITIES
2097     * @see #GET_GIDS
2098     * @see #GET_CONFIGURATIONS
2099     * @see #GET_INSTRUMENTATION
2100     * @see #GET_PERMISSIONS
2101     * @see #GET_PROVIDERS
2102     * @see #GET_RECEIVERS
2103     * @see #GET_SERVICES
2104     * @see #GET_SIGNATURES
2105     * @see #GET_UNINSTALLED_PACKAGES
2106     *
2107     * @hide
2108     */
2109    public abstract List<PackageInfo> getInstalledPackages(int flags, int userId);
2110
2111    /**
2112     * Check whether a particular package has been granted a particular
2113     * permission.
2114     *
2115     * @param permName The name of the permission you are checking for,
2116     * @param pkgName The name of the package you are checking against.
2117     *
2118     * @return If the package has the permission, PERMISSION_GRANTED is
2119     * returned.  If it does not have the permission, PERMISSION_DENIED
2120     * is returned.
2121     *
2122     * @see #PERMISSION_GRANTED
2123     * @see #PERMISSION_DENIED
2124     */
2125    @CheckResult
2126    public abstract int checkPermission(String permName, String pkgName);
2127
2128    /**
2129     * Add a new dynamic permission to the system.  For this to work, your
2130     * package must have defined a permission tree through the
2131     * {@link android.R.styleable#AndroidManifestPermissionTree
2132     * &lt;permission-tree&gt;} tag in its manifest.  A package can only add
2133     * permissions to trees that were defined by either its own package or
2134     * another with the same user id; a permission is in a tree if it
2135     * matches the name of the permission tree + ".": for example,
2136     * "com.foo.bar" is a member of the permission tree "com.foo".
2137     *
2138     * <p>It is good to make your permission tree name descriptive, because you
2139     * are taking possession of that entire set of permission names.  Thus, it
2140     * must be under a domain you control, with a suffix that will not match
2141     * any normal permissions that may be declared in any applications that
2142     * are part of that domain.
2143     *
2144     * <p>New permissions must be added before
2145     * any .apks are installed that use those permissions.  Permissions you
2146     * add through this method are remembered across reboots of the device.
2147     * If the given permission already exists, the info you supply here
2148     * will be used to update it.
2149     *
2150     * @param info Description of the permission to be added.
2151     *
2152     * @return Returns true if a new permission was created, false if an
2153     * existing one was updated.
2154     *
2155     * @throws SecurityException if you are not allowed to add the
2156     * given permission name.
2157     *
2158     * @see #removePermission(String)
2159     */
2160    public abstract boolean addPermission(PermissionInfo info);
2161
2162    /**
2163     * Like {@link #addPermission(PermissionInfo)} but asynchronously
2164     * persists the package manager state after returning from the call,
2165     * allowing it to return quicker and batch a series of adds at the
2166     * expense of no guarantee the added permission will be retained if
2167     * the device is rebooted before it is written.
2168     */
2169    public abstract boolean addPermissionAsync(PermissionInfo info);
2170
2171    /**
2172     * Removes a permission that was previously added with
2173     * {@link #addPermission(PermissionInfo)}.  The same ownership rules apply
2174     * -- you are only allowed to remove permissions that you are allowed
2175     * to add.
2176     *
2177     * @param name The name of the permission to remove.
2178     *
2179     * @throws SecurityException if you are not allowed to remove the
2180     * given permission name.
2181     *
2182     * @see #addPermission(PermissionInfo)
2183     */
2184    public abstract void removePermission(String name);
2185
2186    /**
2187     * Returns an {@link Intent} suitable for passing to {@code startActivityForResult}
2188     * which prompts the user to grant {@code permissions} to this application.
2189     * @hide
2190     *
2191     * @throws NullPointerException if {@code permissions} is {@code null}.
2192     * @throws IllegalArgumentException if {@code permissions} contains {@code null}.
2193     */
2194    public Intent buildPermissionRequestIntent(String... permissions) {
2195        if (permissions == null) {
2196            throw new NullPointerException("permissions cannot be null");
2197        }
2198        for (String permission : permissions) {
2199            if (permission == null) {
2200                throw new IllegalArgumentException("permissions cannot contain null");
2201            }
2202        }
2203
2204        Intent i = new Intent(ACTION_REQUEST_PERMISSION);
2205        i.putExtra(EXTRA_REQUEST_PERMISSION_PERMISSION_LIST, permissions);
2206        i.setPackage("com.android.packageinstaller");
2207        return i;
2208    }
2209
2210    /**
2211     * Grant a permission to an application which the application does not
2212     * already have.  The permission must have been requested by the application,
2213     * but as an optional permission.  If the application is not allowed to
2214     * hold the permission, a SecurityException is thrown.
2215     * @hide
2216     *
2217     * @param packageName The name of the package that the permission will be
2218     * granted to.
2219     * @param permissionName The name of the permission.
2220     */
2221    public abstract void grantPermission(String packageName, String permissionName);
2222
2223    /**
2224     * Revoke a permission that was previously granted by {@link #grantPermission}.
2225     * @hide
2226     *
2227     * @param packageName The name of the package that the permission will be
2228     * granted to.
2229     * @param permissionName The name of the permission.
2230     */
2231    public abstract void revokePermission(String packageName, String permissionName);
2232
2233    /**
2234     * Compare the signatures of two packages to determine if the same
2235     * signature appears in both of them.  If they do contain the same
2236     * signature, then they are allowed special privileges when working
2237     * with each other: they can share the same user-id, run instrumentation
2238     * against each other, etc.
2239     *
2240     * @param pkg1 First package name whose signature will be compared.
2241     * @param pkg2 Second package name whose signature will be compared.
2242     *
2243     * @return Returns an integer indicating whether all signatures on the
2244     * two packages match. The value is >= 0 ({@link #SIGNATURE_MATCH}) if
2245     * all signatures match or < 0 if there is not a match ({@link
2246     * #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
2247     *
2248     * @see #checkSignatures(int, int)
2249     * @see #SIGNATURE_MATCH
2250     * @see #SIGNATURE_NO_MATCH
2251     * @see #SIGNATURE_UNKNOWN_PACKAGE
2252     */
2253    @CheckResult
2254    public abstract int checkSignatures(String pkg1, String pkg2);
2255
2256    /**
2257     * Like {@link #checkSignatures(String, String)}, but takes UIDs of
2258     * the two packages to be checked.  This can be useful, for example,
2259     * when doing the check in an IPC, where the UID is the only identity
2260     * available.  It is functionally identical to determining the package
2261     * associated with the UIDs and checking their signatures.
2262     *
2263     * @param uid1 First UID whose signature will be compared.
2264     * @param uid2 Second UID whose signature will be compared.
2265     *
2266     * @return Returns an integer indicating whether all signatures on the
2267     * two packages match. The value is >= 0 ({@link #SIGNATURE_MATCH}) if
2268     * all signatures match or < 0 if there is not a match ({@link
2269     * #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
2270     *
2271     * @see #checkSignatures(String, String)
2272     * @see #SIGNATURE_MATCH
2273     * @see #SIGNATURE_NO_MATCH
2274     * @see #SIGNATURE_UNKNOWN_PACKAGE
2275     */
2276    @CheckResult
2277    public abstract int checkSignatures(int uid1, int uid2);
2278
2279    /**
2280     * Retrieve the names of all packages that are associated with a particular
2281     * user id.  In most cases, this will be a single package name, the package
2282     * that has been assigned that user id.  Where there are multiple packages
2283     * sharing the same user id through the "sharedUserId" mechanism, all
2284     * packages with that id will be returned.
2285     *
2286     * @param uid The user id for which you would like to retrieve the
2287     * associated packages.
2288     *
2289     * @return Returns an array of one or more packages assigned to the user
2290     * id, or null if there are no known packages with the given id.
2291     */
2292    public abstract String[] getPackagesForUid(int uid);
2293
2294    /**
2295     * Retrieve the official name associated with a user id.  This name is
2296     * guaranteed to never change, though it is possibly for the underlying
2297     * user id to be changed.  That is, if you are storing information about
2298     * user ids in persistent storage, you should use the string returned
2299     * by this function instead of the raw user-id.
2300     *
2301     * @param uid The user id for which you would like to retrieve a name.
2302     * @return Returns a unique name for the given user id, or null if the
2303     * user id is not currently assigned.
2304     */
2305    public abstract String getNameForUid(int uid);
2306
2307    /**
2308     * Return the user id associated with a shared user name. Multiple
2309     * applications can specify a shared user name in their manifest and thus
2310     * end up using a common uid. This might be used for new applications
2311     * that use an existing shared user name and need to know the uid of the
2312     * shared user.
2313     *
2314     * @param sharedUserName The shared user name whose uid is to be retrieved.
2315     * @return Returns the uid associated with the shared user, or  NameNotFoundException
2316     * if the shared user name is not being used by any installed packages
2317     * @hide
2318     */
2319    public abstract int getUidForSharedUser(String sharedUserName)
2320            throws NameNotFoundException;
2321
2322    /**
2323     * Return a List of all application packages that are installed on the
2324     * device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all
2325     * applications including those deleted with {@code DONT_DELETE_DATA} (partially
2326     * installed apps with data directory) will be returned.
2327     *
2328     * @param flags Additional option flags. Use any combination of
2329     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
2330     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2331     *
2332     * @return Returns a List of ApplicationInfo objects, one for each application that
2333     *         is installed on the device.  In the unlikely case of there being
2334     *         no installed applications, an empty list is returned.
2335     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
2336     *         applications including those deleted with {@code DONT_DELETE_DATA}
2337     *         (partially installed apps with data directory) will be returned.
2338     *
2339     * @see #GET_META_DATA
2340     * @see #GET_SHARED_LIBRARY_FILES
2341     * @see #GET_UNINSTALLED_PACKAGES
2342     */
2343    public abstract List<ApplicationInfo> getInstalledApplications(int flags);
2344
2345    /**
2346     * Get a list of shared libraries that are available on the
2347     * system.
2348     *
2349     * @return An array of shared library names that are
2350     * available on the system, or null if none are installed.
2351     *
2352     */
2353    public abstract String[] getSystemSharedLibraryNames();
2354
2355    /**
2356     * Get a list of features that are available on the
2357     * system.
2358     *
2359     * @return An array of FeatureInfo classes describing the features
2360     * that are available on the system, or null if there are none(!!).
2361     */
2362    public abstract FeatureInfo[] getSystemAvailableFeatures();
2363
2364    /**
2365     * Check whether the given feature name is one of the available
2366     * features as returned by {@link #getSystemAvailableFeatures()}.
2367     *
2368     * @return Returns true if the devices supports the feature, else
2369     * false.
2370     */
2371    public abstract boolean hasSystemFeature(String name);
2372
2373    /**
2374     * Determine the best action to perform for a given Intent.  This is how
2375     * {@link Intent#resolveActivity} finds an activity if a class has not
2376     * been explicitly specified.
2377     *
2378     * <p><em>Note:</em> if using an implicit Intent (without an explicit ComponentName
2379     * specified), be sure to consider whether to set the {@link #MATCH_DEFAULT_ONLY}
2380     * only flag.  You need to do so to resolve the activity in the same way
2381     * that {@link android.content.Context#startActivity(Intent)} and
2382     * {@link android.content.Intent#resolveActivity(PackageManager)
2383     * Intent.resolveActivity(PackageManager)} do.</p>
2384     *
2385     * @param intent An intent containing all of the desired specification
2386     *               (action, data, type, category, and/or component).
2387     * @param flags Additional option flags.  The most important is
2388     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2389     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2390     *
2391     * @return Returns a ResolveInfo containing the final activity intent that
2392     *         was determined to be the best action.  Returns null if no
2393     *         matching activity was found. If multiple matching activities are
2394     *         found and there is no default set, returns a ResolveInfo
2395     *         containing something else, such as the activity resolver.
2396     *
2397     * @see #MATCH_DEFAULT_ONLY
2398     * @see #GET_INTENT_FILTERS
2399     * @see #GET_RESOLVED_FILTER
2400     */
2401    public abstract ResolveInfo resolveActivity(Intent intent, int flags);
2402
2403    /**
2404     * Determine the best action to perform for a given Intent for a given user. This
2405     * is how {@link Intent#resolveActivity} finds an activity if a class has not
2406     * been explicitly specified.
2407     *
2408     * <p><em>Note:</em> if using an implicit Intent (without an explicit ComponentName
2409     * specified), be sure to consider whether to set the {@link #MATCH_DEFAULT_ONLY}
2410     * only flag.  You need to do so to resolve the activity in the same way
2411     * that {@link android.content.Context#startActivity(Intent)} and
2412     * {@link android.content.Intent#resolveActivity(PackageManager)
2413     * Intent.resolveActivity(PackageManager)} do.</p>
2414     *
2415     * @param intent An intent containing all of the desired specification
2416     *               (action, data, type, category, and/or component).
2417     * @param flags Additional option flags.  The most important is
2418     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2419     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2420     * @param userId The user id.
2421     *
2422     * @return Returns a ResolveInfo containing the final activity intent that
2423     *         was determined to be the best action.  Returns null if no
2424     *         matching activity was found. If multiple matching activities are
2425     *         found and there is no default set, returns a ResolveInfo
2426     *         containing something else, such as the activity resolver.
2427     *
2428     * @see #MATCH_DEFAULT_ONLY
2429     * @see #GET_INTENT_FILTERS
2430     * @see #GET_RESOLVED_FILTER
2431     *
2432     * @hide
2433     */
2434    public abstract ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId);
2435
2436    /**
2437     * Retrieve all activities that can be performed for the given intent.
2438     *
2439     * @param intent The desired intent as per resolveActivity().
2440     * @param flags Additional option flags.  The most important is
2441     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2442     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2443     *
2444     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2445     *         Activity. These are ordered from best to worst match -- that
2446     *         is, the first item in the list is what is returned by
2447     *         {@link #resolveActivity}.  If there are no matching activities, an empty
2448     *         list is returned.
2449     *
2450     * @see #MATCH_DEFAULT_ONLY
2451     * @see #GET_INTENT_FILTERS
2452     * @see #GET_RESOLVED_FILTER
2453     */
2454    public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
2455            int flags);
2456
2457    /**
2458     * Retrieve all activities that can be performed for the given intent, for a specific user.
2459     *
2460     * @param intent The desired intent as per resolveActivity().
2461     * @param flags Additional option flags.  The most important is
2462     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2463     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2464     *
2465     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2466     *         Activity. These are ordered from best to worst match -- that
2467     *         is, the first item in the list is what is returned by
2468     *         {@link #resolveActivity}.  If there are no matching activities, an empty
2469     *         list is returned.
2470     *
2471     * @see #MATCH_DEFAULT_ONLY
2472     * @see #GET_INTENT_FILTERS
2473     * @see #GET_RESOLVED_FILTER
2474     * @hide
2475     */
2476    public abstract List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
2477            int flags, int userId);
2478
2479
2480    /**
2481     * Retrieve a set of activities that should be presented to the user as
2482     * similar options.  This is like {@link #queryIntentActivities}, except it
2483     * also allows you to supply a list of more explicit Intents that you would
2484     * like to resolve to particular options, and takes care of returning the
2485     * final ResolveInfo list in a reasonable order, with no duplicates, based
2486     * on those inputs.
2487     *
2488     * @param caller The class name of the activity that is making the
2489     *               request.  This activity will never appear in the output
2490     *               list.  Can be null.
2491     * @param specifics An array of Intents that should be resolved to the
2492     *                  first specific results.  Can be null.
2493     * @param intent The desired intent as per resolveActivity().
2494     * @param flags Additional option flags.  The most important is
2495     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2496     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2497     *
2498     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2499     *         Activity. These are ordered first by all of the intents resolved
2500     *         in <var>specifics</var> and then any additional activities that
2501     *         can handle <var>intent</var> but did not get included by one of
2502     *         the <var>specifics</var> intents.  If there are no matching
2503     *         activities, an empty list is returned.
2504     *
2505     * @see #MATCH_DEFAULT_ONLY
2506     * @see #GET_INTENT_FILTERS
2507     * @see #GET_RESOLVED_FILTER
2508     */
2509    public abstract List<ResolveInfo> queryIntentActivityOptions(
2510            ComponentName caller, Intent[] specifics, Intent intent, int flags);
2511
2512    /**
2513     * Retrieve all receivers that can handle a broadcast of the given intent.
2514     *
2515     * @param intent The desired intent as per resolveActivity().
2516     * @param flags Additional option flags.
2517     *
2518     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2519     *         Receiver. These are ordered from first to last in priority.  If
2520     *         there are no matching receivers, an empty list is returned.
2521     *
2522     * @see #MATCH_DEFAULT_ONLY
2523     * @see #GET_INTENT_FILTERS
2524     * @see #GET_RESOLVED_FILTER
2525     */
2526    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
2527            int flags);
2528
2529    /**
2530     * Retrieve all receivers that can handle a broadcast of the given intent, for a specific
2531     * user.
2532     *
2533     * @param intent The desired intent as per resolveActivity().
2534     * @param flags Additional option flags.
2535     * @param userId The userId of the user being queried.
2536     *
2537     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2538     *         Receiver. These are ordered from first to last in priority.  If
2539     *         there are no matching receivers, an empty list is returned.
2540     *
2541     * @see #MATCH_DEFAULT_ONLY
2542     * @see #GET_INTENT_FILTERS
2543     * @see #GET_RESOLVED_FILTER
2544     * @hide
2545     */
2546    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
2547            int flags, int userId);
2548
2549    /**
2550     * Determine the best service to handle for a given Intent.
2551     *
2552     * @param intent An intent containing all of the desired specification
2553     *               (action, data, type, category, and/or component).
2554     * @param flags Additional option flags.
2555     *
2556     * @return Returns a ResolveInfo containing the final service intent that
2557     *         was determined to be the best action.  Returns null if no
2558     *         matching service was found.
2559     *
2560     * @see #GET_INTENT_FILTERS
2561     * @see #GET_RESOLVED_FILTER
2562     */
2563    public abstract ResolveInfo resolveService(Intent intent, int flags);
2564
2565    /**
2566     * Retrieve all services that can match the given intent.
2567     *
2568     * @param intent The desired intent as per resolveService().
2569     * @param flags Additional option flags.
2570     *
2571     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2572     *         ServiceInfo. These are ordered from best to worst match -- that
2573     *         is, the first item in the list is what is returned by
2574     *         resolveService().  If there are no matching services, an empty
2575     *         list is returned.
2576     *
2577     * @see #GET_INTENT_FILTERS
2578     * @see #GET_RESOLVED_FILTER
2579     */
2580    public abstract List<ResolveInfo> queryIntentServices(Intent intent,
2581            int flags);
2582
2583    /**
2584     * Retrieve all services that can match the given intent for a given user.
2585     *
2586     * @param intent The desired intent as per resolveService().
2587     * @param flags Additional option flags.
2588     * @param userId The user id.
2589     *
2590     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2591     *         ServiceInfo. These are ordered from best to worst match -- that
2592     *         is, the first item in the list is what is returned by
2593     *         resolveService().  If there are no matching services, an empty
2594     *         list is returned.
2595     *
2596     * @see #GET_INTENT_FILTERS
2597     * @see #GET_RESOLVED_FILTER
2598     *
2599     * @hide
2600     */
2601    public abstract List<ResolveInfo> queryIntentServicesAsUser(Intent intent,
2602            int flags, int userId);
2603
2604    /** {@hide} */
2605    public abstract List<ResolveInfo> queryIntentContentProvidersAsUser(
2606            Intent intent, int flags, int userId);
2607
2608    /**
2609     * Retrieve all providers that can match the given intent.
2610     *
2611     * @param intent An intent containing all of the desired specification
2612     *            (action, data, type, category, and/or component).
2613     * @param flags Additional option flags.
2614     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2615     *         ProviderInfo. These are ordered from best to worst match. If
2616     *         there are no matching providers, an empty list is returned.
2617     * @see #GET_INTENT_FILTERS
2618     * @see #GET_RESOLVED_FILTER
2619     */
2620    public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags);
2621
2622    /**
2623     * Find a single content provider by its base path name.
2624     *
2625     * @param name The name of the provider to find.
2626     * @param flags Additional option flags.  Currently should always be 0.
2627     *
2628     * @return ContentProviderInfo Information about the provider, if found,
2629     *         else null.
2630     */
2631    public abstract ProviderInfo resolveContentProvider(String name,
2632            int flags);
2633
2634    /**
2635     * Find a single content provider by its base path name.
2636     *
2637     * @param name The name of the provider to find.
2638     * @param flags Additional option flags.  Currently should always be 0.
2639     * @param userId The user id.
2640     *
2641     * @return ContentProviderInfo Information about the provider, if found,
2642     *         else null.
2643     * @hide
2644     */
2645    public abstract ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId);
2646
2647    /**
2648     * Retrieve content provider information.
2649     *
2650     * <p><em>Note: unlike most other methods, an empty result set is indicated
2651     * by a null return instead of an empty list.</em>
2652     *
2653     * @param processName If non-null, limits the returned providers to only
2654     *                    those that are hosted by the given process.  If null,
2655     *                    all content providers are returned.
2656     * @param uid If <var>processName</var> is non-null, this is the required
2657     *        uid owning the requested content providers.
2658     * @param flags Additional option flags.  Currently should always be 0.
2659     *
2660     * @return A List&lt;ContentProviderInfo&gt; containing one entry for each
2661     *         content provider either patching <var>processName</var> or, if
2662     *         <var>processName</var> is null, all known content providers.
2663     *         <em>If there are no matching providers, null is returned.</em>
2664     */
2665    public abstract List<ProviderInfo> queryContentProviders(
2666            String processName, int uid, int flags);
2667
2668    /**
2669     * Retrieve all of the information we know about a particular
2670     * instrumentation class.
2671     *
2672     * <p>Throws {@link NameNotFoundException} if instrumentation with the
2673     * given class name cannot be found on the system.
2674     *
2675     * @param className The full name (i.e.
2676     *                  com.google.apps.contacts.InstrumentList) of an
2677     *                  Instrumentation class.
2678     * @param flags Additional option flags.  Currently should always be 0.
2679     *
2680     * @return InstrumentationInfo containing information about the
2681     *         instrumentation.
2682     */
2683    public abstract InstrumentationInfo getInstrumentationInfo(
2684            ComponentName className, int flags) throws NameNotFoundException;
2685
2686    /**
2687     * Retrieve information about available instrumentation code.  May be used
2688     * to retrieve either all instrumentation code, or only the code targeting
2689     * a particular package.
2690     *
2691     * @param targetPackage If null, all instrumentation is returned; only the
2692     *                      instrumentation targeting this package name is
2693     *                      returned.
2694     * @param flags Additional option flags.  Currently should always be 0.
2695     *
2696     * @return A List&lt;InstrumentationInfo&gt; containing one entry for each
2697     *         matching available Instrumentation.  Returns an empty list if
2698     *         there is no instrumentation available for the given package.
2699     */
2700    public abstract List<InstrumentationInfo> queryInstrumentation(
2701            String targetPackage, int flags);
2702
2703    /**
2704     * Retrieve an image from a package.  This is a low-level API used by
2705     * the various package manager info structures (such as
2706     * {@link ComponentInfo} to implement retrieval of their associated
2707     * icon.
2708     *
2709     * @param packageName The name of the package that this icon is coming from.
2710     * Cannot be null.
2711     * @param resid The resource identifier of the desired image.  Cannot be 0.
2712     * @param appInfo Overall information about <var>packageName</var>.  This
2713     * may be null, in which case the application information will be retrieved
2714     * for you if needed; if you already have this information around, it can
2715     * be much more efficient to supply it here.
2716     *
2717     * @return Returns a Drawable holding the requested image.  Returns null if
2718     * an image could not be found for any reason.
2719     */
2720    public abstract Drawable getDrawable(String packageName, @DrawableRes int resid,
2721            ApplicationInfo appInfo);
2722
2723    /**
2724     * Retrieve the icon associated with an activity.  Given the full name of
2725     * an activity, retrieves the information about it and calls
2726     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its icon.
2727     * If the activity cannot be found, NameNotFoundException is thrown.
2728     *
2729     * @param activityName Name of the activity whose icon is to be retrieved.
2730     *
2731     * @return Returns the image of the icon, or the default activity icon if
2732     * it could not be found.  Does not return null.
2733     * @throws NameNotFoundException Thrown if the resources for the given
2734     * activity could not be loaded.
2735     *
2736     * @see #getActivityIcon(Intent)
2737     */
2738    public abstract Drawable getActivityIcon(ComponentName activityName)
2739            throws NameNotFoundException;
2740
2741    /**
2742     * Retrieve the icon associated with an Intent.  If intent.getClassName() is
2743     * set, this simply returns the result of
2744     * getActivityIcon(intent.getClassName()).  Otherwise it resolves the intent's
2745     * component and returns the icon associated with the resolved component.
2746     * If intent.getClassName() cannot be found or the Intent cannot be resolved
2747     * to a component, NameNotFoundException is thrown.
2748     *
2749     * @param intent The intent for which you would like to retrieve an icon.
2750     *
2751     * @return Returns the image of the icon, or the default activity icon if
2752     * it could not be found.  Does not return null.
2753     * @throws NameNotFoundException Thrown if the resources for application
2754     * matching the given intent could not be loaded.
2755     *
2756     * @see #getActivityIcon(ComponentName)
2757     */
2758    public abstract Drawable getActivityIcon(Intent intent)
2759            throws NameNotFoundException;
2760
2761    /**
2762     * Retrieve the banner associated with an activity. Given the full name of
2763     * an activity, retrieves the information about it and calls
2764     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its
2765     * banner. If the activity cannot be found, NameNotFoundException is thrown.
2766     *
2767     * @param activityName Name of the activity whose banner is to be retrieved.
2768     * @return Returns the image of the banner, or null if the activity has no
2769     *         banner specified.
2770     * @throws NameNotFoundException Thrown if the resources for the given
2771     *             activity could not be loaded.
2772     * @see #getActivityBanner(Intent)
2773     */
2774    public abstract Drawable getActivityBanner(ComponentName activityName)
2775            throws NameNotFoundException;
2776
2777    /**
2778     * Retrieve the banner associated with an Intent. If intent.getClassName()
2779     * is set, this simply returns the result of
2780     * getActivityBanner(intent.getClassName()). Otherwise it resolves the
2781     * intent's component and returns the banner associated with the resolved
2782     * component. If intent.getClassName() cannot be found or the Intent cannot
2783     * be resolved to a component, NameNotFoundException is thrown.
2784     *
2785     * @param intent The intent for which you would like to retrieve a banner.
2786     * @return Returns the image of the banner, or null if the activity has no
2787     *         banner specified.
2788     * @throws NameNotFoundException Thrown if the resources for application
2789     *             matching the given intent could not be loaded.
2790     * @see #getActivityBanner(ComponentName)
2791     */
2792    public abstract Drawable getActivityBanner(Intent intent)
2793            throws NameNotFoundException;
2794
2795    /**
2796     * Return the generic icon for an activity that is used when no specific
2797     * icon is defined.
2798     *
2799     * @return Drawable Image of the icon.
2800     */
2801    public abstract Drawable getDefaultActivityIcon();
2802
2803    /**
2804     * Retrieve the icon associated with an application.  If it has not defined
2805     * an icon, the default app icon is returned.  Does not return null.
2806     *
2807     * @param info Information about application being queried.
2808     *
2809     * @return Returns the image of the icon, or the default application icon
2810     * if it could not be found.
2811     *
2812     * @see #getApplicationIcon(String)
2813     */
2814    public abstract Drawable getApplicationIcon(ApplicationInfo info);
2815
2816    /**
2817     * Retrieve the icon associated with an application.  Given the name of the
2818     * application's package, retrieves the information about it and calls
2819     * getApplicationIcon() to return its icon. If the application cannot be
2820     * found, NameNotFoundException is thrown.
2821     *
2822     * @param packageName Name of the package whose application icon is to be
2823     *                    retrieved.
2824     *
2825     * @return Returns the image of the icon, or the default application icon
2826     * if it could not be found.  Does not return null.
2827     * @throws NameNotFoundException Thrown if the resources for the given
2828     * application could not be loaded.
2829     *
2830     * @see #getApplicationIcon(ApplicationInfo)
2831     */
2832    public abstract Drawable getApplicationIcon(String packageName)
2833            throws NameNotFoundException;
2834
2835    /**
2836     * Retrieve the banner associated with an application.
2837     *
2838     * @param info Information about application being queried.
2839     * @return Returns the image of the banner or null if the application has no
2840     *         banner specified.
2841     * @see #getApplicationBanner(String)
2842     */
2843    public abstract Drawable getApplicationBanner(ApplicationInfo info);
2844
2845    /**
2846     * Retrieve the banner associated with an application. Given the name of the
2847     * application's package, retrieves the information about it and calls
2848     * getApplicationIcon() to return its banner. If the application cannot be
2849     * found, NameNotFoundException is thrown.
2850     *
2851     * @param packageName Name of the package whose application banner is to be
2852     *            retrieved.
2853     * @return Returns the image of the banner or null if the application has no
2854     *         banner specified.
2855     * @throws NameNotFoundException Thrown if the resources for the given
2856     *             application could not be loaded.
2857     * @see #getApplicationBanner(ApplicationInfo)
2858     */
2859    public abstract Drawable getApplicationBanner(String packageName)
2860            throws NameNotFoundException;
2861
2862    /**
2863     * Retrieve the logo associated with an activity. Given the full name of an
2864     * activity, retrieves the information about it and calls
2865     * {@link ComponentInfo#loadLogo ComponentInfo.loadLogo()} to return its
2866     * logo. If the activity cannot be found, NameNotFoundException is thrown.
2867     *
2868     * @param activityName Name of the activity whose logo is to be retrieved.
2869     * @return Returns the image of the logo or null if the activity has no logo
2870     *         specified.
2871     * @throws NameNotFoundException Thrown if the resources for the given
2872     *             activity could not be loaded.
2873     * @see #getActivityLogo(Intent)
2874     */
2875    public abstract Drawable getActivityLogo(ComponentName activityName)
2876            throws NameNotFoundException;
2877
2878    /**
2879     * Retrieve the logo associated with an Intent.  If intent.getClassName() is
2880     * set, this simply returns the result of
2881     * getActivityLogo(intent.getClassName()).  Otherwise it resolves the intent's
2882     * component and returns the logo associated with the resolved component.
2883     * If intent.getClassName() cannot be found or the Intent cannot be resolved
2884     * to a component, NameNotFoundException is thrown.
2885     *
2886     * @param intent The intent for which you would like to retrieve a logo.
2887     *
2888     * @return Returns the image of the logo, or null if the activity has no
2889     * logo specified.
2890     *
2891     * @throws NameNotFoundException Thrown if the resources for application
2892     * matching the given intent could not be loaded.
2893     *
2894     * @see #getActivityLogo(ComponentName)
2895     */
2896    public abstract Drawable getActivityLogo(Intent intent)
2897            throws NameNotFoundException;
2898
2899    /**
2900     * Retrieve the logo associated with an application.  If it has not specified
2901     * a logo, this method returns null.
2902     *
2903     * @param info Information about application being queried.
2904     *
2905     * @return Returns the image of the logo, or null if no logo is specified
2906     * by the application.
2907     *
2908     * @see #getApplicationLogo(String)
2909     */
2910    public abstract Drawable getApplicationLogo(ApplicationInfo info);
2911
2912    /**
2913     * Retrieve the logo associated with an application.  Given the name of the
2914     * application's package, retrieves the information about it and calls
2915     * getApplicationLogo() to return its logo. If the application cannot be
2916     * found, NameNotFoundException is thrown.
2917     *
2918     * @param packageName Name of the package whose application logo is to be
2919     *                    retrieved.
2920     *
2921     * @return Returns the image of the logo, or null if no application logo
2922     * has been specified.
2923     *
2924     * @throws NameNotFoundException Thrown if the resources for the given
2925     * application could not be loaded.
2926     *
2927     * @see #getApplicationLogo(ApplicationInfo)
2928     */
2929    public abstract Drawable getApplicationLogo(String packageName)
2930            throws NameNotFoundException;
2931
2932    /**
2933     * If the target user is a managed profile of the calling user or the caller
2934     * is itself a managed profile, then this returns a badged copy of the given
2935     * icon to be able to distinguish it from the original icon. For badging an
2936     * arbitrary drawable use {@link #getUserBadgedDrawableForDensity(
2937     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
2938     * <p>
2939     * If the original drawable is a BitmapDrawable and the backing bitmap is
2940     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
2941     * is performed in place and the original drawable is returned.
2942     * </p>
2943     *
2944     * @param icon The icon to badge.
2945     * @param user The target user.
2946     * @return A drawable that combines the original icon and a badge as
2947     *         determined by the system.
2948     */
2949    public abstract Drawable getUserBadgedIcon(Drawable icon, UserHandle user);
2950
2951    /**
2952     * If the target user is a managed profile of the calling user or the caller
2953     * is itself a managed profile, then this returns a badged copy of the given
2954     * drawable allowing the user to distinguish it from the original drawable.
2955     * The caller can specify the location in the bounds of the drawable to be
2956     * badged where the badge should be applied as well as the density of the
2957     * badge to be used.
2958     * <p>
2959     * If the original drawable is a BitmapDrawable and the backing bitmap is
2960     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
2961     * is performed in place and the original drawable is returned.
2962     * </p>
2963     *
2964     * @param drawable The drawable to badge.
2965     * @param user The target user.
2966     * @param badgeLocation Where in the bounds of the badged drawable to place
2967     *         the badge. If not provided, the badge is applied on top of the entire
2968     *         drawable being badged.
2969     * @param badgeDensity The optional desired density for the badge as per
2970     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
2971     *         the density of the display is used.
2972     * @return A drawable that combines the original drawable and a badge as
2973     *         determined by the system.
2974     */
2975    public abstract Drawable getUserBadgedDrawableForDensity(Drawable drawable,
2976            UserHandle user, Rect badgeLocation, int badgeDensity);
2977
2978    /**
2979     * If the target user is a managed profile of the calling user or the caller
2980     * is itself a managed profile, then this returns a drawable to use as a small
2981     * icon to include in a view to distinguish it from the original icon.
2982     *
2983     * @param user The target user.
2984     * @param density The optional desired density for the badge as per
2985     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided
2986     *         the density of the current display is used.
2987     * @return the drawable or null if no drawable is required.
2988     * @hide
2989     */
2990    public abstract Drawable getUserBadgeForDensity(UserHandle user, int density);
2991
2992    /**
2993     * If the target user is a managed profile of the calling user or the caller
2994     * is itself a managed profile, then this returns a copy of the label with
2995     * badging for accessibility services like talkback. E.g. passing in "Email"
2996     * and it might return "Work Email" for Email in the work profile.
2997     *
2998     * @param label The label to change.
2999     * @param user The target user.
3000     * @return A label that combines the original label and a badge as
3001     *         determined by the system.
3002     */
3003    public abstract CharSequence getUserBadgedLabel(CharSequence label, UserHandle user);
3004
3005    /**
3006     * Retrieve text from a package.  This is a low-level API used by
3007     * the various package manager info structures (such as
3008     * {@link ComponentInfo} to implement retrieval of their associated
3009     * labels and other text.
3010     *
3011     * @param packageName The name of the package that this text is coming from.
3012     * Cannot be null.
3013     * @param resid The resource identifier of the desired text.  Cannot be 0.
3014     * @param appInfo Overall information about <var>packageName</var>.  This
3015     * may be null, in which case the application information will be retrieved
3016     * for you if needed; if you already have this information around, it can
3017     * be much more efficient to supply it here.
3018     *
3019     * @return Returns a CharSequence holding the requested text.  Returns null
3020     * if the text could not be found for any reason.
3021     */
3022    public abstract CharSequence getText(String packageName, @StringRes int resid,
3023            ApplicationInfo appInfo);
3024
3025    /**
3026     * Retrieve an XML file from a package.  This is a low-level API used to
3027     * retrieve XML meta data.
3028     *
3029     * @param packageName The name of the package that this xml is coming from.
3030     * Cannot be null.
3031     * @param resid The resource identifier of the desired xml.  Cannot be 0.
3032     * @param appInfo Overall information about <var>packageName</var>.  This
3033     * may be null, in which case the application information will be retrieved
3034     * for you if needed; if you already have this information around, it can
3035     * be much more efficient to supply it here.
3036     *
3037     * @return Returns an XmlPullParser allowing you to parse out the XML
3038     * data.  Returns null if the xml resource could not be found for any
3039     * reason.
3040     */
3041    public abstract XmlResourceParser getXml(String packageName, @XmlRes int resid,
3042            ApplicationInfo appInfo);
3043
3044    /**
3045     * Return the label to use for this application.
3046     *
3047     * @return Returns the label associated with this application, or null if
3048     * it could not be found for any reason.
3049     * @param info The application to get the label of.
3050     */
3051    public abstract CharSequence getApplicationLabel(ApplicationInfo info);
3052
3053    /**
3054     * Retrieve the resources associated with an activity.  Given the full
3055     * name of an activity, retrieves the information about it and calls
3056     * getResources() to return its application's resources.  If the activity
3057     * cannot be found, NameNotFoundException is thrown.
3058     *
3059     * @param activityName Name of the activity whose resources are to be
3060     *                     retrieved.
3061     *
3062     * @return Returns the application's Resources.
3063     * @throws NameNotFoundException Thrown if the resources for the given
3064     * application could not be loaded.
3065     *
3066     * @see #getResourcesForApplication(ApplicationInfo)
3067     */
3068    public abstract Resources getResourcesForActivity(ComponentName activityName)
3069            throws NameNotFoundException;
3070
3071    /**
3072     * Retrieve the resources for an application.  Throws NameNotFoundException
3073     * if the package is no longer installed.
3074     *
3075     * @param app Information about the desired application.
3076     *
3077     * @return Returns the application's Resources.
3078     * @throws NameNotFoundException Thrown if the resources for the given
3079     * application could not be loaded (most likely because it was uninstalled).
3080     */
3081    public abstract Resources getResourcesForApplication(ApplicationInfo app)
3082            throws NameNotFoundException;
3083
3084    /**
3085     * Retrieve the resources associated with an application.  Given the full
3086     * package name of an application, retrieves the information about it and
3087     * calls getResources() to return its application's resources.  If the
3088     * appPackageName cannot be found, NameNotFoundException is thrown.
3089     *
3090     * @param appPackageName Package name of the application whose resources
3091     *                       are to be retrieved.
3092     *
3093     * @return Returns the application's Resources.
3094     * @throws NameNotFoundException Thrown if the resources for the given
3095     * application could not be loaded.
3096     *
3097     * @see #getResourcesForApplication(ApplicationInfo)
3098     */
3099    public abstract Resources getResourcesForApplication(String appPackageName)
3100            throws NameNotFoundException;
3101
3102    /** @hide */
3103    public abstract Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
3104            throws NameNotFoundException;
3105
3106    /**
3107     * Retrieve overall information about an application package defined
3108     * in a package archive file
3109     *
3110     * @param archiveFilePath The path to the archive file
3111     * @param flags Additional option flags. Use any combination of
3112     * {@link #GET_ACTIVITIES},
3113     * {@link #GET_GIDS},
3114     * {@link #GET_CONFIGURATIONS},
3115     * {@link #GET_INSTRUMENTATION},
3116     * {@link #GET_PERMISSIONS},
3117     * {@link #GET_PROVIDERS},
3118     * {@link #GET_RECEIVERS},
3119     * {@link #GET_SERVICES},
3120     * {@link #GET_SIGNATURES}, to modify the data returned.
3121     *
3122     * @return Returns the information about the package. Returns
3123     * null if the package could not be successfully parsed.
3124     *
3125     * @see #GET_ACTIVITIES
3126     * @see #GET_GIDS
3127     * @see #GET_CONFIGURATIONS
3128     * @see #GET_INSTRUMENTATION
3129     * @see #GET_PERMISSIONS
3130     * @see #GET_PROVIDERS
3131     * @see #GET_RECEIVERS
3132     * @see #GET_SERVICES
3133     * @see #GET_SIGNATURES
3134     *
3135     */
3136    public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) {
3137        final PackageParser parser = new PackageParser();
3138        final File apkFile = new File(archiveFilePath);
3139        try {
3140            PackageParser.Package pkg = parser.parseMonolithicPackage(apkFile, 0);
3141            if ((flags & GET_SIGNATURES) != 0) {
3142                parser.collectCertificates(pkg, 0);
3143                parser.collectManifestDigest(pkg);
3144            }
3145            PackageUserState state = new PackageUserState();
3146            return PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, state);
3147        } catch (PackageParserException e) {
3148            return null;
3149        }
3150    }
3151
3152    /**
3153     * @hide Install a package. Since this may take a little while, the result
3154     *       will be posted back to the given observer. An installation will
3155     *       fail if the calling context lacks the
3156     *       {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if
3157     *       the package named in the package file's manifest is already
3158     *       installed, or if there's no space available on the device.
3159     * @param packageURI The location of the package file to install. This can
3160     *            be a 'file:' or a 'content:' URI.
3161     * @param observer An observer callback to get notified when the package
3162     *            installation is complete.
3163     *            {@link IPackageInstallObserver#packageInstalled(String, int)}
3164     *            will be called when that happens. This parameter must not be
3165     *            null.
3166     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3167     *            {@link #INSTALL_REPLACE_EXISTING},
3168     *            {@link #INSTALL_ALLOW_TEST}.
3169     * @param installerPackageName Optional package name of the application that
3170     *            is performing the installation. This identifies which market
3171     *            the package came from.
3172     * @deprecated Use {@link #installPackage(Uri, PackageInstallObserver, int,
3173     *             String)} instead. This method will continue to be supported
3174     *             but the older observer interface will not get additional
3175     *             failure details.
3176     */
3177    // @SystemApi
3178    public abstract void installPackage(
3179            Uri packageURI, IPackageInstallObserver observer, int flags,
3180            String installerPackageName);
3181
3182    /**
3183     * Similar to
3184     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3185     * with an extra verification file provided.
3186     *
3187     * @param packageURI The location of the package file to install. This can
3188     *            be a 'file:' or a 'content:' URI.
3189     * @param observer An observer callback to get notified when the package
3190     *            installation is complete.
3191     *            {@link IPackageInstallObserver#packageInstalled(String, int)}
3192     *            will be called when that happens. This parameter must not be
3193     *            null.
3194     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3195     *            {@link #INSTALL_REPLACE_EXISTING},
3196     *            {@link #INSTALL_ALLOW_TEST}.
3197     * @param installerPackageName Optional package name of the application that
3198     *            is performing the installation. This identifies which market
3199     *            the package came from.
3200     * @param verificationURI The location of the supplementary verification
3201     *            file. This can be a 'file:' or a 'content:' URI. May be
3202     *            {@code null}.
3203     * @param manifestDigest an object that holds the digest of the package
3204     *            which can be used to verify ownership. May be {@code null}.
3205     * @param encryptionParams if the package to be installed is encrypted,
3206     *            these parameters describing the encryption and authentication
3207     *            used. May be {@code null}.
3208     * @hide
3209     * @deprecated Use {@link #installPackageWithVerification(Uri,
3210     *             PackageInstallObserver, int, String, Uri, ManifestDigest,
3211     *             ContainerEncryptionParams)} instead. This method will
3212     *             continue to be supported but the older observer interface
3213     *             will not get additional failure details.
3214     */
3215    // @SystemApi
3216    public abstract void installPackageWithVerification(Uri packageURI,
3217            IPackageInstallObserver observer, int flags, String installerPackageName,
3218            Uri verificationURI, ManifestDigest manifestDigest,
3219            ContainerEncryptionParams encryptionParams);
3220
3221    /**
3222     * Similar to
3223     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3224     * with an extra verification information provided.
3225     *
3226     * @param packageURI The location of the package file to install. This can
3227     *            be a 'file:' or a 'content:' URI.
3228     * @param observer An observer callback to get notified when the package
3229     *            installation is complete.
3230     *            {@link IPackageInstallObserver#packageInstalled(String, int)}
3231     *            will be called when that happens. This parameter must not be
3232     *            null.
3233     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3234     *            {@link #INSTALL_REPLACE_EXISTING},
3235     *            {@link #INSTALL_ALLOW_TEST}.
3236     * @param installerPackageName Optional package name of the application that
3237     *            is performing the installation. This identifies which market
3238     *            the package came from.
3239     * @param verificationParams an object that holds signal information to
3240     *            assist verification. May be {@code null}.
3241     * @param encryptionParams if the package to be installed is encrypted,
3242     *            these parameters describing the encryption and authentication
3243     *            used. May be {@code null}.
3244     * @hide
3245     * @deprecated Use {@link #installPackageWithVerificationAndEncryption(Uri,
3246     *             PackageInstallObserver, int, String, VerificationParams,
3247     *             ContainerEncryptionParams)} instead. This method will
3248     *             continue to be supported but the older observer interface
3249     *             will not get additional failure details.
3250     */
3251    @Deprecated
3252    public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
3253            IPackageInstallObserver observer, int flags, String installerPackageName,
3254            VerificationParams verificationParams,
3255            ContainerEncryptionParams encryptionParams);
3256
3257    // Package-install variants that take the new, expanded form of observer interface.
3258    // Note that these *also* take the original observer type and will redundantly
3259    // report the same information to that observer if supplied; but it is not required.
3260
3261    /**
3262     * @hide
3263     *
3264     * Install a package. Since this may take a little while, the result will
3265     * be posted back to the given observer.  An installation will fail if the calling context
3266     * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the
3267     * package named in the package file's manifest is already installed, or if there's no space
3268     * available on the device.
3269     *
3270     * @param packageURI The location of the package file to install.  This can be a 'file:' or a
3271     * 'content:' URI.
3272     * @param observer An observer callback to get notified when the package installation is
3273     * complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
3274     * called when that happens. This parameter must not be null.
3275     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3276     * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
3277     * @param installerPackageName Optional package name of the application that is performing the
3278     * installation. This identifies which market the package came from.
3279     */
3280    public abstract void installPackage(
3281            Uri packageURI, PackageInstallObserver observer,
3282            int flags, String installerPackageName);
3283
3284    /**
3285     * Similar to
3286     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3287     * with an extra verification file provided.
3288     *
3289     * @param packageURI The location of the package file to install. This can
3290     *            be a 'file:' or a 'content:' URI.
3291     * @param observer An observer callback to get notified when the package installation is
3292     * complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
3293     * called when that happens. This parameter must not be null.
3294     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3295     *            {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
3296     * @param installerPackageName Optional package name of the application that
3297     *            is performing the installation. This identifies which market
3298     *            the package came from.
3299     * @param verificationURI The location of the supplementary verification
3300     *            file. This can be a 'file:' or a 'content:' URI. May be
3301     *            {@code null}.
3302     * @param manifestDigest an object that holds the digest of the package
3303     *            which can be used to verify ownership. May be {@code null}.
3304     * @param encryptionParams if the package to be installed is encrypted,
3305     *            these parameters describing the encryption and authentication
3306     *            used. May be {@code null}.
3307     * @hide
3308     */
3309    public abstract void installPackageWithVerification(Uri packageURI,
3310            PackageInstallObserver observer, int flags, String installerPackageName,
3311            Uri verificationURI, ManifestDigest manifestDigest,
3312            ContainerEncryptionParams encryptionParams);
3313
3314    /**
3315     * Similar to
3316     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3317     * with an extra verification information provided.
3318     *
3319     * @param packageURI The location of the package file to install. This can
3320     *            be a 'file:' or a 'content:' URI.
3321     * @param observer An observer callback to get notified when the package installation is
3322     * complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
3323     * called when that happens. This parameter must not be null.
3324     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3325     *            {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
3326     * @param installerPackageName Optional package name of the application that
3327     *            is performing the installation. This identifies which market
3328     *            the package came from.
3329     * @param verificationParams an object that holds signal information to
3330     *            assist verification. May be {@code null}.
3331     * @param encryptionParams if the package to be installed is encrypted,
3332     *            these parameters describing the encryption and authentication
3333     *            used. May be {@code null}.
3334     *
3335     * @hide
3336     */
3337    public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
3338            PackageInstallObserver observer, int flags, String installerPackageName,
3339            VerificationParams verificationParams, ContainerEncryptionParams encryptionParams);
3340
3341    /**
3342     * If there is already an application with the given package name installed
3343     * on the system for other users, also install it for the calling user.
3344     * @hide
3345     */
3346    // @SystemApi
3347    public abstract int installExistingPackage(String packageName)
3348            throws NameNotFoundException;
3349
3350    /**
3351     * Allows a package listening to the
3352     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
3353     * broadcast} to respond to the package manager. The response must include
3354     * the {@code verificationCode} which is one of
3355     * {@link PackageManager#VERIFICATION_ALLOW} or
3356     * {@link PackageManager#VERIFICATION_REJECT}.
3357     *
3358     * @param id pending package identifier as passed via the
3359     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
3360     * @param verificationCode either {@link PackageManager#VERIFICATION_ALLOW}
3361     *            or {@link PackageManager#VERIFICATION_REJECT}.
3362     * @throws SecurityException if the caller does not have the
3363     *            PACKAGE_VERIFICATION_AGENT permission.
3364     */
3365    public abstract void verifyPendingInstall(int id, int verificationCode);
3366
3367    /**
3368     * Allows a package listening to the
3369     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
3370     * broadcast} to extend the default timeout for a response and declare what
3371     * action to perform after the timeout occurs. The response must include
3372     * the {@code verificationCodeAtTimeout} which is one of
3373     * {@link PackageManager#VERIFICATION_ALLOW} or
3374     * {@link PackageManager#VERIFICATION_REJECT}.
3375     *
3376     * This method may only be called once per package id. Additional calls
3377     * will have no effect.
3378     *
3379     * @param id pending package identifier as passed via the
3380     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
3381     * @param verificationCodeAtTimeout either
3382     *            {@link PackageManager#VERIFICATION_ALLOW} or
3383     *            {@link PackageManager#VERIFICATION_REJECT}. If
3384     *            {@code verificationCodeAtTimeout} is neither
3385     *            {@link PackageManager#VERIFICATION_ALLOW} or
3386     *            {@link PackageManager#VERIFICATION_REJECT}, then
3387     *            {@code verificationCodeAtTimeout} will default to
3388     *            {@link PackageManager#VERIFICATION_REJECT}.
3389     * @param millisecondsToDelay the amount of time requested for the timeout.
3390     *            Must be positive and less than
3391     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}. If
3392     *            {@code millisecondsToDelay} is out of bounds,
3393     *            {@code millisecondsToDelay} will be set to the closest in
3394     *            bounds value; namely, 0 or
3395     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}.
3396     * @throws SecurityException if the caller does not have the
3397     *            PACKAGE_VERIFICATION_AGENT permission.
3398     */
3399    public abstract void extendVerificationTimeout(int id,
3400            int verificationCodeAtTimeout, long millisecondsToDelay);
3401
3402    /**
3403     * Change the installer associated with a given package.  There are limitations
3404     * on how the installer package can be changed; in particular:
3405     * <ul>
3406     * <li> A SecurityException will be thrown if <var>installerPackageName</var>
3407     * is not signed with the same certificate as the calling application.
3408     * <li> A SecurityException will be thrown if <var>targetPackage</var> already
3409     * has an installer package, and that installer package is not signed with
3410     * the same certificate as the calling application.
3411     * </ul>
3412     *
3413     * @param targetPackage The installed package whose installer will be changed.
3414     * @param installerPackageName The package name of the new installer.  May be
3415     * null to clear the association.
3416     */
3417    public abstract void setInstallerPackageName(String targetPackage,
3418            String installerPackageName);
3419
3420    /**
3421     * Attempts to delete a package.  Since this may take a little while, the result will
3422     * be posted back to the given observer.  A deletion will fail if the calling context
3423     * lacks the {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the
3424     * named package cannot be found, or if the named package is a "system package".
3425     * (TODO: include pointer to documentation on "system packages")
3426     *
3427     * @param packageName The name of the package to delete
3428     * @param observer An observer callback to get notified when the package deletion is
3429     * complete. {@link android.content.pm.IPackageDeleteObserver#packageDeleted(boolean)} will be
3430     * called when that happens.  observer may be null to indicate that no callback is desired.
3431     * @param flags - possible values: {@link #DELETE_KEEP_DATA},
3432     * {@link #DELETE_ALL_USERS}.
3433     *
3434     * @hide
3435     */
3436    // @SystemApi
3437    public abstract void deletePackage(
3438            String packageName, IPackageDeleteObserver observer, int flags);
3439
3440    /**
3441     * Retrieve the package name of the application that installed a package. This identifies
3442     * which market the package came from.
3443     *
3444     * @param packageName The name of the package to query
3445     */
3446    public abstract String getInstallerPackageName(String packageName);
3447
3448    /**
3449     * Attempts to clear the user data directory of an application.
3450     * Since this may take a little while, the result will
3451     * be posted back to the given observer.  A deletion will fail if the
3452     * named package cannot be found, or if the named package is a "system package".
3453     *
3454     * @param packageName The name of the package
3455     * @param observer An observer callback to get notified when the operation is finished
3456     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
3457     * will be called when that happens.  observer may be null to indicate that
3458     * no callback is desired.
3459     *
3460     * @hide
3461     */
3462    public abstract void clearApplicationUserData(String packageName,
3463            IPackageDataObserver observer);
3464    /**
3465     * Attempts to delete the cache files associated with an application.
3466     * Since this may take a little while, the result will
3467     * be posted back to the given observer.  A deletion will fail if the calling context
3468     * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the
3469     * named package cannot be found, or if the named package is a "system package".
3470     *
3471     * @param packageName The name of the package to delete
3472     * @param observer An observer callback to get notified when the cache file deletion
3473     * is complete.
3474     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
3475     * will be called when that happens.  observer may be null to indicate that
3476     * no callback is desired.
3477     *
3478     * @hide
3479     */
3480    public abstract void deleteApplicationCacheFiles(String packageName,
3481            IPackageDataObserver observer);
3482
3483    /**
3484     * Free storage by deleting LRU sorted list of cache files across
3485     * all applications. If the currently available free storage
3486     * on the device is greater than or equal to the requested
3487     * free storage, no cache files are cleared. If the currently
3488     * available storage on the device is less than the requested
3489     * free storage, some or all of the cache files across
3490     * all applications are deleted (based on last accessed time)
3491     * to increase the free storage space on the device to
3492     * the requested value. There is no guarantee that clearing all
3493     * the cache files from all applications will clear up
3494     * enough storage to achieve the desired value.
3495     * @param freeStorageSize The number of bytes of storage to be
3496     * freed by the system. Say if freeStorageSize is XX,
3497     * and the current free storage is YY,
3498     * if XX is less than YY, just return. if not free XX-YY number
3499     * of bytes if possible.
3500     * @param observer call back used to notify when
3501     * the operation is completed
3502     *
3503     * @hide
3504     */
3505    // @SystemApi
3506    public abstract void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer);
3507
3508    /**
3509     * Free storage by deleting LRU sorted list of cache files across
3510     * all applications. If the currently available free storage
3511     * on the device is greater than or equal to the requested
3512     * free storage, no cache files are cleared. If the currently
3513     * available storage on the device is less than the requested
3514     * free storage, some or all of the cache files across
3515     * all applications are deleted (based on last accessed time)
3516     * to increase the free storage space on the device to
3517     * the requested value. There is no guarantee that clearing all
3518     * the cache files from all applications will clear up
3519     * enough storage to achieve the desired value.
3520     * @param freeStorageSize The number of bytes of storage to be
3521     * freed by the system. Say if freeStorageSize is XX,
3522     * and the current free storage is YY,
3523     * if XX is less than YY, just return. if not free XX-YY number
3524     * of bytes if possible.
3525     * @param pi IntentSender call back used to
3526     * notify when the operation is completed.May be null
3527     * to indicate that no call back is desired.
3528     *
3529     * @hide
3530     */
3531    public abstract void freeStorage(long freeStorageSize, IntentSender pi);
3532
3533    /**
3534     * Retrieve the size information for a package.
3535     * Since this may take a little while, the result will
3536     * be posted back to the given observer.  The calling context
3537     * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission.
3538     *
3539     * @param packageName The name of the package whose size information is to be retrieved
3540     * @param userHandle The user whose size information should be retrieved.
3541     * @param observer An observer callback to get notified when the operation
3542     * is complete.
3543     * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)}
3544     * The observer's callback is invoked with a PackageStats object(containing the
3545     * code, data and cache sizes of the package) and a boolean value representing
3546     * the status of the operation. observer may be null to indicate that
3547     * no callback is desired.
3548     *
3549     * @hide
3550     */
3551    public abstract void getPackageSizeInfo(String packageName, int userHandle,
3552            IPackageStatsObserver observer);
3553
3554    /**
3555     * Like {@link #getPackageSizeInfo(String, int, IPackageStatsObserver)}, but
3556     * returns the size for the calling user.
3557     *
3558     * @hide
3559     */
3560    public void getPackageSizeInfo(String packageName, IPackageStatsObserver observer) {
3561        getPackageSizeInfo(packageName, UserHandle.myUserId(), observer);
3562    }
3563
3564    /**
3565     * @deprecated This function no longer does anything; it was an old
3566     * approach to managing preferred activities, which has been superseded
3567     * by (and conflicts with) the modern activity-based preferences.
3568     */
3569    @Deprecated
3570    public abstract void addPackageToPreferred(String packageName);
3571
3572    /**
3573     * @deprecated This function no longer does anything; it was an old
3574     * approach to managing preferred activities, which has been superseded
3575     * by (and conflicts with) the modern activity-based preferences.
3576     */
3577    @Deprecated
3578    public abstract void removePackageFromPreferred(String packageName);
3579
3580    /**
3581     * Retrieve the list of all currently configured preferred packages.  The
3582     * first package on the list is the most preferred, the last is the
3583     * least preferred.
3584     *
3585     * @param flags Additional option flags. Use any combination of
3586     * {@link #GET_ACTIVITIES},
3587     * {@link #GET_GIDS},
3588     * {@link #GET_CONFIGURATIONS},
3589     * {@link #GET_INSTRUMENTATION},
3590     * {@link #GET_PERMISSIONS},
3591     * {@link #GET_PROVIDERS},
3592     * {@link #GET_RECEIVERS},
3593     * {@link #GET_SERVICES},
3594     * {@link #GET_SIGNATURES}, to modify the data returned.
3595     *
3596     * @return Returns a list of PackageInfo objects describing each
3597     * preferred application, in order of preference.
3598     *
3599     * @see #GET_ACTIVITIES
3600     * @see #GET_GIDS
3601     * @see #GET_CONFIGURATIONS
3602     * @see #GET_INSTRUMENTATION
3603     * @see #GET_PERMISSIONS
3604     * @see #GET_PROVIDERS
3605     * @see #GET_RECEIVERS
3606     * @see #GET_SERVICES
3607     * @see #GET_SIGNATURES
3608     */
3609    public abstract List<PackageInfo> getPreferredPackages(int flags);
3610
3611    /**
3612     * @deprecated This is a protected API that should not have been available
3613     * to third party applications.  It is the platform's responsibility for
3614     * assigning preferred activities and this cannot be directly modified.
3615     *
3616     * Add a new preferred activity mapping to the system.  This will be used
3617     * to automatically select the given activity component when
3618     * {@link Context#startActivity(Intent) Context.startActivity()} finds
3619     * multiple matching activities and also matches the given filter.
3620     *
3621     * @param filter The set of intents under which this activity will be
3622     * made preferred.
3623     * @param match The IntentFilter match category that this preference
3624     * applies to.
3625     * @param set The set of activities that the user was picking from when
3626     * this preference was made.
3627     * @param activity The component name of the activity that is to be
3628     * preferred.
3629     */
3630    @Deprecated
3631    public abstract void addPreferredActivity(IntentFilter filter, int match,
3632            ComponentName[] set, ComponentName activity);
3633
3634    /**
3635     * Same as {@link #addPreferredActivity(IntentFilter, int,
3636            ComponentName[], ComponentName)}, but with a specific userId to apply the preference
3637            to.
3638     * @hide
3639     */
3640    public void addPreferredActivity(IntentFilter filter, int match,
3641            ComponentName[] set, ComponentName activity, int userId) {
3642        throw new RuntimeException("Not implemented. Must override in a subclass.");
3643    }
3644
3645    /**
3646     * @deprecated This is a protected API that should not have been available
3647     * to third party applications.  It is the platform's responsibility for
3648     * assigning preferred activities and this cannot be directly modified.
3649     *
3650     * Replaces an existing preferred activity mapping to the system, and if that were not present
3651     * adds a new preferred activity.  This will be used
3652     * to automatically select the given activity component when
3653     * {@link Context#startActivity(Intent) Context.startActivity()} finds
3654     * multiple matching activities and also matches the given filter.
3655     *
3656     * @param filter The set of intents under which this activity will be
3657     * made preferred.
3658     * @param match The IntentFilter match category that this preference
3659     * applies to.
3660     * @param set The set of activities that the user was picking from when
3661     * this preference was made.
3662     * @param activity The component name of the activity that is to be
3663     * preferred.
3664     * @hide
3665     */
3666    @Deprecated
3667    public abstract void replacePreferredActivity(IntentFilter filter, int match,
3668            ComponentName[] set, ComponentName activity);
3669
3670    /**
3671     * @hide
3672     */
3673    @Deprecated
3674    public void replacePreferredActivityAsUser(IntentFilter filter, int match,
3675           ComponentName[] set, ComponentName activity, int userId) {
3676        throw new RuntimeException("Not implemented. Must override in a subclass.");
3677    }
3678
3679    /**
3680     * Remove all preferred activity mappings, previously added with
3681     * {@link #addPreferredActivity}, from the
3682     * system whose activities are implemented in the given package name.
3683     * An application can only clear its own package(s).
3684     *
3685     * @param packageName The name of the package whose preferred activity
3686     * mappings are to be removed.
3687     */
3688    public abstract void clearPackagePreferredActivities(String packageName);
3689
3690    /**
3691     * Retrieve all preferred activities, previously added with
3692     * {@link #addPreferredActivity}, that are
3693     * currently registered with the system.
3694     *
3695     * @param outFilters A required list in which to place the filters of all of the
3696     * preferred activities.
3697     * @param outActivities A required list in which to place the component names of
3698     * all of the preferred activities.
3699     * @param packageName An optional package in which you would like to limit
3700     * the list.  If null, all activities will be returned; if non-null, only
3701     * those activities in the given package are returned.
3702     *
3703     * @return Returns the total number of registered preferred activities
3704     * (the number of distinct IntentFilter records, not the number of unique
3705     * activity components) that were found.
3706     */
3707    public abstract int getPreferredActivities(@NonNull List<IntentFilter> outFilters,
3708            @NonNull List<ComponentName> outActivities, String packageName);
3709
3710    /**
3711     * Ask for the set of available 'home' activities and the current explicit
3712     * default, if any.
3713     * @hide
3714     */
3715    public abstract ComponentName getHomeActivities(List<ResolveInfo> outActivities);
3716
3717    /**
3718     * Set the enabled setting for a package component (activity, receiver, service, provider).
3719     * This setting will override any enabled state which may have been set by the component in its
3720     * manifest.
3721     *
3722     * @param componentName The component to enable
3723     * @param newState The new enabled state for the component.  The legal values for this state
3724     *                 are:
3725     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
3726     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
3727     *                   and
3728     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
3729     *                 The last one removes the setting, thereby restoring the component's state to
3730     *                 whatever was set in it's manifest (or enabled, by default).
3731     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
3732     */
3733    public abstract void setComponentEnabledSetting(ComponentName componentName,
3734            int newState, int flags);
3735
3736
3737    /**
3738     * Return the enabled setting for a package component (activity,
3739     * receiver, service, provider).  This returns the last value set by
3740     * {@link #setComponentEnabledSetting(ComponentName, int, int)}; in most
3741     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
3742     * the value originally specified in the manifest has not been modified.
3743     *
3744     * @param componentName The component to retrieve.
3745     * @return Returns the current enabled state for the component.  May
3746     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
3747     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
3748     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
3749     * component's enabled state is based on the original information in
3750     * the manifest as found in {@link ComponentInfo}.
3751     */
3752    public abstract int getComponentEnabledSetting(ComponentName componentName);
3753
3754    /**
3755     * Set the enabled setting for an application
3756     * This setting will override any enabled state which may have been set by the application in
3757     * its manifest.  It also overrides the enabled state set in the manifest for any of the
3758     * application's components.  It does not override any enabled state set by
3759     * {@link #setComponentEnabledSetting} for any of the application's components.
3760     *
3761     * @param packageName The package name of the application to enable
3762     * @param newState The new enabled state for the component.  The legal values for this state
3763     *                 are:
3764     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
3765     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
3766     *                   and
3767     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
3768     *                 The last one removes the setting, thereby restoring the applications's state to
3769     *                 whatever was set in its manifest (or enabled, by default).
3770     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
3771     */
3772    public abstract void setApplicationEnabledSetting(String packageName,
3773            int newState, int flags);
3774
3775    /**
3776     * Return the enabled setting for an application. This returns
3777     * the last value set by
3778     * {@link #setApplicationEnabledSetting(String, int, int)}; in most
3779     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
3780     * the value originally specified in the manifest has not been modified.
3781     *
3782     * @param packageName The package name of the application to retrieve.
3783     * @return Returns the current enabled state for the application.  May
3784     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
3785     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
3786     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
3787     * application's enabled state is based on the original information in
3788     * the manifest as found in {@link ComponentInfo}.
3789     * @throws IllegalArgumentException if the named package does not exist.
3790     */
3791    public abstract int getApplicationEnabledSetting(String packageName);
3792
3793    /**
3794     * Puts the package in a hidden state, which is almost like an uninstalled state,
3795     * making the package unavailable, but it doesn't remove the data or the actual
3796     * package file. Application can be unhidden by either resetting the hidden state
3797     * or by installing it, such as with {@link #installExistingPackage(String)}
3798     * @hide
3799     */
3800    public abstract boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
3801            UserHandle userHandle);
3802
3803    /**
3804     * Returns the hidden state of a package.
3805     * @see #setApplicationHiddenSettingAsUser(String, boolean, UserHandle)
3806     * @hide
3807     */
3808    public abstract boolean getApplicationHiddenSettingAsUser(String packageName,
3809            UserHandle userHandle);
3810
3811    /**
3812     * Return whether the device has been booted into safe mode.
3813     */
3814    public abstract boolean isSafeMode();
3815
3816    /**
3817     * Return the {@link KeySet} associated with the String alias for this
3818     * application.
3819     *
3820     * @param alias The alias for a given {@link KeySet} as defined in the
3821     *        application's AndroidManifest.xml.
3822     * @hide
3823     */
3824    public abstract KeySet getKeySetByAlias(String packageName, String alias);
3825
3826    /** Return the signing {@link KeySet} for this application.
3827     * @hide
3828     */
3829    public abstract KeySet getSigningKeySet(String packageName);
3830
3831    /**
3832     * Return whether the package denoted by packageName has been signed by all
3833     * of the keys specified by the {@link KeySet} ks.  This will return true if
3834     * the package has been signed by additional keys (a superset) as well.
3835     * Compare to {@link #isSignedByExactly(String packageName, KeySet ks)}.
3836     * @hide
3837     */
3838    public abstract boolean isSignedBy(String packageName, KeySet ks);
3839
3840    /**
3841     * Return whether the package denoted by packageName has been signed by all
3842     * of, and only, the keys specified by the {@link KeySet} ks. Compare to
3843     * {@link #isSignedBy(String packageName, KeySet ks)}.
3844     * @hide
3845     */
3846    public abstract boolean isSignedByExactly(String packageName, KeySet ks);
3847
3848    /**
3849     * Attempts to move package resources from internal to external media or vice versa.
3850     * Since this may take a little while, the result will
3851     * be posted back to the given observer.   This call may fail if the calling context
3852     * lacks the {@link android.Manifest.permission#MOVE_PACKAGE} permission, if the
3853     * named package cannot be found, or if the named package is a "system package".
3854     *
3855     * @param packageName The name of the package to delete
3856     * @param observer An observer callback to get notified when the package move is
3857     * complete. {@link android.content.pm.IPackageMoveObserver#packageMoved(boolean)} will be
3858     * called when that happens.  observer may be null to indicate that no callback is desired.
3859     * @param flags To indicate install location {@link #MOVE_INTERNAL} or
3860     * {@link #MOVE_EXTERNAL_MEDIA}
3861     *
3862     * @hide
3863     */
3864    public abstract void movePackage(
3865            String packageName, IPackageMoveObserver observer, int flags);
3866
3867    /**
3868     * Returns the device identity that verifiers can use to associate their scheme to a particular
3869     * device. This should not be used by anything other than a package verifier.
3870     *
3871     * @return identity that uniquely identifies current device
3872     * @hide
3873     */
3874    public abstract VerifierDeviceIdentity getVerifierDeviceIdentity();
3875
3876    /**
3877     * Returns true if the device is upgrading, such as first boot after OTA.
3878     *
3879     * @hide
3880     */
3881    public abstract boolean isUpgrade();
3882
3883    /**
3884     * Return interface that offers the ability to install, upgrade, and remove
3885     * applications on the device.
3886     */
3887    public abstract @NonNull PackageInstaller getPackageInstaller();
3888
3889    /**
3890     * Returns the data directory for a particular user and package, given the uid of the package.
3891     * @param uid uid of the package, including the userId and appId
3892     * @param packageName name of the package
3893     * @return the user-specific data directory for the package
3894     * @hide
3895     */
3896    public static String getDataDirForUser(int userId, String packageName) {
3897        // TODO: This should be shared with Installer's knowledge of user directory
3898        return Environment.getDataDirectory().toString() + "/user/" + userId
3899                + "/" + packageName;
3900    }
3901
3902    /**
3903     * Adds a {@link CrossProfileIntentFilter}. After calling this method all intents sent from the
3904     * user with id sourceUserId can also be be resolved by activities in the user with id
3905     * targetUserId if they match the specified intent filter.
3906     * @param filter The {@link IntentFilter} the intent has to match
3907     * @param sourceUserId The source user id.
3908     * @param targetUserId The target user id.
3909     * @param flags The only possible value is {@link SKIP_CURRENT_PROFILE}
3910     * @hide
3911     */
3912    public abstract void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId,
3913            int targetUserId, int flags);
3914
3915    /**
3916     * Clearing {@link CrossProfileIntentFilter}s which have the specified user as their
3917     * source, and have been set by the app calling this method.
3918     * @param sourceUserId The source user id.
3919     * @hide
3920     */
3921    public abstract void clearCrossProfileIntentFilters(int sourceUserId);
3922
3923    /**
3924     * @hide
3925     */
3926    public abstract Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
3927
3928    /**
3929     * @hide
3930     */
3931    public abstract Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
3932
3933    /** {@hide} */
3934    public abstract boolean isPackageAvailable(String packageName);
3935
3936    /** {@hide} */
3937    public static String installStatusToString(int status, String msg) {
3938        final String str = installStatusToString(status);
3939        if (msg != null) {
3940            return str + ": " + msg;
3941        } else {
3942            return str;
3943        }
3944    }
3945
3946    /** {@hide} */
3947    public static String installStatusToString(int status) {
3948        switch (status) {
3949            case INSTALL_SUCCEEDED: return "INSTALL_SUCCEEDED";
3950            case INSTALL_FAILED_ALREADY_EXISTS: return "INSTALL_FAILED_ALREADY_EXISTS";
3951            case INSTALL_FAILED_INVALID_APK: return "INSTALL_FAILED_INVALID_APK";
3952            case INSTALL_FAILED_INVALID_URI: return "INSTALL_FAILED_INVALID_URI";
3953            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return "INSTALL_FAILED_INSUFFICIENT_STORAGE";
3954            case INSTALL_FAILED_DUPLICATE_PACKAGE: return "INSTALL_FAILED_DUPLICATE_PACKAGE";
3955            case INSTALL_FAILED_NO_SHARED_USER: return "INSTALL_FAILED_NO_SHARED_USER";
3956            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return "INSTALL_FAILED_UPDATE_INCOMPATIBLE";
3957            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return "INSTALL_FAILED_SHARED_USER_INCOMPATIBLE";
3958            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return "INSTALL_FAILED_MISSING_SHARED_LIBRARY";
3959            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return "INSTALL_FAILED_REPLACE_COULDNT_DELETE";
3960            case INSTALL_FAILED_DEXOPT: return "INSTALL_FAILED_DEXOPT";
3961            case INSTALL_FAILED_OLDER_SDK: return "INSTALL_FAILED_OLDER_SDK";
3962            case INSTALL_FAILED_CONFLICTING_PROVIDER: return "INSTALL_FAILED_CONFLICTING_PROVIDER";
3963            case INSTALL_FAILED_NEWER_SDK: return "INSTALL_FAILED_NEWER_SDK";
3964            case INSTALL_FAILED_TEST_ONLY: return "INSTALL_FAILED_TEST_ONLY";
3965            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE";
3966            case INSTALL_FAILED_MISSING_FEATURE: return "INSTALL_FAILED_MISSING_FEATURE";
3967            case INSTALL_FAILED_CONTAINER_ERROR: return "INSTALL_FAILED_CONTAINER_ERROR";
3968            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return "INSTALL_FAILED_INVALID_INSTALL_LOCATION";
3969            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return "INSTALL_FAILED_MEDIA_UNAVAILABLE";
3970            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return "INSTALL_FAILED_VERIFICATION_TIMEOUT";
3971            case INSTALL_FAILED_VERIFICATION_FAILURE: return "INSTALL_FAILED_VERIFICATION_FAILURE";
3972            case INSTALL_FAILED_PACKAGE_CHANGED: return "INSTALL_FAILED_PACKAGE_CHANGED";
3973            case INSTALL_FAILED_UID_CHANGED: return "INSTALL_FAILED_UID_CHANGED";
3974            case INSTALL_FAILED_VERSION_DOWNGRADE: return "INSTALL_FAILED_VERSION_DOWNGRADE";
3975            case INSTALL_PARSE_FAILED_NOT_APK: return "INSTALL_PARSE_FAILED_NOT_APK";
3976            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return "INSTALL_PARSE_FAILED_BAD_MANIFEST";
3977            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return "INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION";
3978            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return "INSTALL_PARSE_FAILED_NO_CERTIFICATES";
3979            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return "INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES";
3980            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return "INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING";
3981            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return "INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME";
3982            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return "INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID";
3983            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return "INSTALL_PARSE_FAILED_MANIFEST_MALFORMED";
3984            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return "INSTALL_PARSE_FAILED_MANIFEST_EMPTY";
3985            case INSTALL_FAILED_INTERNAL_ERROR: return "INSTALL_FAILED_INTERNAL_ERROR";
3986            case INSTALL_FAILED_USER_RESTRICTED: return "INSTALL_FAILED_USER_RESTRICTED";
3987            case INSTALL_FAILED_DUPLICATE_PERMISSION: return "INSTALL_FAILED_DUPLICATE_PERMISSION";
3988            case INSTALL_FAILED_NO_MATCHING_ABIS: return "INSTALL_FAILED_NO_MATCHING_ABIS";
3989            case INSTALL_FAILED_ABORTED: return "INSTALL_FAILED_ABORTED";
3990            default: return Integer.toString(status);
3991        }
3992    }
3993
3994    /** {@hide} */
3995    public static int installStatusToPublicStatus(int status) {
3996        switch (status) {
3997            case INSTALL_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
3998            case INSTALL_FAILED_ALREADY_EXISTS: return PackageInstaller.STATUS_FAILURE_CONFLICT;
3999            case INSTALL_FAILED_INVALID_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
4000            case INSTALL_FAILED_INVALID_URI: return PackageInstaller.STATUS_FAILURE_INVALID;
4001            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return PackageInstaller.STATUS_FAILURE_STORAGE;
4002            case INSTALL_FAILED_DUPLICATE_PACKAGE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4003            case INSTALL_FAILED_NO_SHARED_USER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4004            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4005            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4006            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4007            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4008            case INSTALL_FAILED_DEXOPT: return PackageInstaller.STATUS_FAILURE_INVALID;
4009            case INSTALL_FAILED_OLDER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4010            case INSTALL_FAILED_CONFLICTING_PROVIDER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4011            case INSTALL_FAILED_NEWER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4012            case INSTALL_FAILED_TEST_ONLY: return PackageInstaller.STATUS_FAILURE_INVALID;
4013            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4014            case INSTALL_FAILED_MISSING_FEATURE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4015            case INSTALL_FAILED_CONTAINER_ERROR: return PackageInstaller.STATUS_FAILURE_STORAGE;
4016            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return PackageInstaller.STATUS_FAILURE_STORAGE;
4017            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return PackageInstaller.STATUS_FAILURE_STORAGE;
4018            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return PackageInstaller.STATUS_FAILURE_ABORTED;
4019            case INSTALL_FAILED_VERIFICATION_FAILURE: return PackageInstaller.STATUS_FAILURE_ABORTED;
4020            case INSTALL_FAILED_PACKAGE_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
4021            case INSTALL_FAILED_UID_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
4022            case INSTALL_FAILED_VERSION_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
4023            case INSTALL_PARSE_FAILED_NOT_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
4024            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return PackageInstaller.STATUS_FAILURE_INVALID;
4025            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return PackageInstaller.STATUS_FAILURE_INVALID;
4026            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
4027            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
4028            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return PackageInstaller.STATUS_FAILURE_INVALID;
4029            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return PackageInstaller.STATUS_FAILURE_INVALID;
4030            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return PackageInstaller.STATUS_FAILURE_INVALID;
4031            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return PackageInstaller.STATUS_FAILURE_INVALID;
4032            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return PackageInstaller.STATUS_FAILURE_INVALID;
4033            case INSTALL_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
4034            case INSTALL_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4035            case INSTALL_FAILED_DUPLICATE_PERMISSION: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4036            case INSTALL_FAILED_NO_MATCHING_ABIS: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4037            case INSTALL_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
4038            default: return PackageInstaller.STATUS_FAILURE;
4039        }
4040    }
4041
4042    /** {@hide} */
4043    public static String deleteStatusToString(int status, String msg) {
4044        final String str = deleteStatusToString(status);
4045        if (msg != null) {
4046            return str + ": " + msg;
4047        } else {
4048            return str;
4049        }
4050    }
4051
4052    /** {@hide} */
4053    public static String deleteStatusToString(int status) {
4054        switch (status) {
4055            case DELETE_SUCCEEDED: return "DELETE_SUCCEEDED";
4056            case DELETE_FAILED_INTERNAL_ERROR: return "DELETE_FAILED_INTERNAL_ERROR";
4057            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return "DELETE_FAILED_DEVICE_POLICY_MANAGER";
4058            case DELETE_FAILED_USER_RESTRICTED: return "DELETE_FAILED_USER_RESTRICTED";
4059            case DELETE_FAILED_OWNER_BLOCKED: return "DELETE_FAILED_OWNER_BLOCKED";
4060            case DELETE_FAILED_ABORTED: return "DELETE_FAILED_ABORTED";
4061            default: return Integer.toString(status);
4062        }
4063    }
4064
4065    /** {@hide} */
4066    public static int deleteStatusToPublicStatus(int status) {
4067        switch (status) {
4068            case DELETE_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
4069            case DELETE_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
4070            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return PackageInstaller.STATUS_FAILURE_BLOCKED;
4071            case DELETE_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
4072            case DELETE_FAILED_OWNER_BLOCKED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
4073            case DELETE_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
4074            default: return PackageInstaller.STATUS_FAILURE;
4075        }
4076    }
4077
4078    /** {@hide} */
4079    public static class LegacyPackageInstallObserver extends PackageInstallObserver {
4080        private final IPackageInstallObserver mLegacy;
4081
4082        public LegacyPackageInstallObserver(IPackageInstallObserver legacy) {
4083            mLegacy = legacy;
4084        }
4085
4086        @Override
4087        public void onPackageInstalled(String basePackageName, int returnCode, String msg,
4088                Bundle extras) {
4089            if (mLegacy == null) return;
4090            try {
4091                mLegacy.packageInstalled(basePackageName, returnCode);
4092            } catch (RemoteException ignored) {
4093            }
4094        }
4095    }
4096
4097    /** {@hide} */
4098    public static class LegacyPackageDeleteObserver extends PackageDeleteObserver {
4099        private final IPackageDeleteObserver mLegacy;
4100
4101        public LegacyPackageDeleteObserver(IPackageDeleteObserver legacy) {
4102            mLegacy = legacy;
4103        }
4104
4105        @Override
4106        public void onPackageDeleted(String basePackageName, int returnCode, String msg) {
4107            if (mLegacy == null) return;
4108            try {
4109                mLegacy.packageDeleted(basePackageName, returnCode);
4110            } catch (RemoteException ignored) {
4111            }
4112        }
4113    }
4114}
4115