PackageManager.java revision ea2529df19eb38425d86ae74c7ba01089492aa31
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.Manifest;
20import android.annotation.CheckResult;
21import android.annotation.DrawableRes;
22import android.annotation.IntDef;
23import android.annotation.IntRange;
24import android.annotation.NonNull;
25import android.annotation.Nullable;
26import android.annotation.RequiresPermission;
27import android.annotation.SdkConstant;
28import android.annotation.SdkConstant.SdkConstantType;
29import android.annotation.StringRes;
30import android.annotation.SystemApi;
31import android.annotation.TestApi;
32import android.annotation.UserIdInt;
33import android.annotation.XmlRes;
34import android.app.PackageDeleteObserver;
35import android.app.PackageInstallObserver;
36import android.app.admin.DevicePolicyManager;
37import android.app.usage.StorageStatsManager;
38import android.content.ComponentName;
39import android.content.Context;
40import android.content.Intent;
41import android.content.IntentFilter;
42import android.content.IntentSender;
43import android.content.pm.PackageParser.PackageParserException;
44import android.content.res.Resources;
45import android.content.res.XmlResourceParser;
46import android.graphics.Rect;
47import android.graphics.drawable.Drawable;
48import android.net.Uri;
49import android.os.Build;
50import android.os.Bundle;
51import android.os.Handler;
52import android.os.RemoteException;
53import android.os.UserHandle;
54import android.os.UserManager;
55import android.os.storage.StorageManager;
56import android.os.storage.VolumeInfo;
57import android.util.AndroidException;
58import android.util.Log;
59
60import com.android.internal.util.ArrayUtils;
61
62import dalvik.system.VMRuntime;
63
64import java.io.File;
65import java.lang.annotation.Retention;
66import java.lang.annotation.RetentionPolicy;
67import java.util.List;
68
69/**
70 * Class for retrieving various kinds of information related to the application
71 * packages that are currently installed on the device.
72 *
73 * You can find this class through {@link Context#getPackageManager}.
74 */
75public abstract class PackageManager {
76    private static final String TAG = "PackageManager";
77
78    /** {@hide} */
79    public static final boolean APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE = true;
80
81    /**
82     * This exception is thrown when a given package, application, or component
83     * name cannot be found.
84     */
85    public static class NameNotFoundException extends AndroidException {
86        public NameNotFoundException() {
87        }
88
89        public NameNotFoundException(String name) {
90            super(name);
91        }
92    }
93
94    /**
95     * Listener for changes in permissions granted to a UID.
96     *
97     * @hide
98     */
99    @SystemApi
100    public interface OnPermissionsChangedListener {
101
102        /**
103         * Called when the permissions for a UID change.
104         * @param uid The UID with a change.
105         */
106        public void onPermissionsChanged(int uid);
107    }
108
109    /**
110     * As a guiding principle:
111     * <p>
112     * {@code GET_} flags are used to request additional data that may have been
113     * elided to save wire space.
114     * <p>
115     * {@code MATCH_} flags are used to include components or packages that
116     * would have otherwise been omitted from a result set by current system
117     * state.
118     */
119
120    /** @hide */
121    @IntDef(flag = true, value = {
122            GET_ACTIVITIES,
123            GET_CONFIGURATIONS,
124            GET_GIDS,
125            GET_INSTRUMENTATION,
126            GET_INTENT_FILTERS,
127            GET_META_DATA,
128            GET_PERMISSIONS,
129            GET_PROVIDERS,
130            GET_RECEIVERS,
131            GET_SERVICES,
132            GET_SHARED_LIBRARY_FILES,
133            GET_SIGNATURES,
134            GET_URI_PERMISSION_PATTERNS,
135            MATCH_UNINSTALLED_PACKAGES,
136            MATCH_DISABLED_COMPONENTS,
137            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
138            MATCH_SYSTEM_ONLY,
139            MATCH_FACTORY_ONLY,
140            MATCH_DEBUG_TRIAGED_MISSING,
141            MATCH_INSTANT,
142            GET_DISABLED_COMPONENTS,
143            GET_DISABLED_UNTIL_USED_COMPONENTS,
144            GET_UNINSTALLED_PACKAGES,
145    })
146    @Retention(RetentionPolicy.SOURCE)
147    public @interface PackageInfoFlags {}
148
149    /** @hide */
150    @IntDef(flag = true, value = {
151            GET_META_DATA,
152            GET_SHARED_LIBRARY_FILES,
153            MATCH_UNINSTALLED_PACKAGES,
154            MATCH_SYSTEM_ONLY,
155            MATCH_DEBUG_TRIAGED_MISSING,
156            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
157            MATCH_INSTANT,
158            GET_DISABLED_UNTIL_USED_COMPONENTS,
159            GET_UNINSTALLED_PACKAGES,
160    })
161    @Retention(RetentionPolicy.SOURCE)
162    public @interface ApplicationInfoFlags {}
163
164    /** @hide */
165    @IntDef(flag = true, value = {
166            GET_META_DATA,
167            GET_SHARED_LIBRARY_FILES,
168            MATCH_ALL,
169            MATCH_DEBUG_TRIAGED_MISSING,
170            MATCH_DEFAULT_ONLY,
171            MATCH_DISABLED_COMPONENTS,
172            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
173            MATCH_DIRECT_BOOT_AWARE,
174            MATCH_DIRECT_BOOT_UNAWARE,
175            MATCH_SYSTEM_ONLY,
176            MATCH_UNINSTALLED_PACKAGES,
177            MATCH_INSTANT,
178            GET_DISABLED_COMPONENTS,
179            GET_DISABLED_UNTIL_USED_COMPONENTS,
180            GET_UNINSTALLED_PACKAGES,
181    })
182    @Retention(RetentionPolicy.SOURCE)
183    public @interface ComponentInfoFlags {}
184
185    /** @hide */
186    @IntDef(flag = true, value = {
187            GET_META_DATA,
188            GET_RESOLVED_FILTER,
189            GET_SHARED_LIBRARY_FILES,
190            MATCH_ALL,
191            MATCH_DEBUG_TRIAGED_MISSING,
192            MATCH_DISABLED_COMPONENTS,
193            MATCH_DISABLED_UNTIL_USED_COMPONENTS,
194            MATCH_DEFAULT_ONLY,
195            MATCH_DIRECT_BOOT_AWARE,
196            MATCH_DIRECT_BOOT_UNAWARE,
197            MATCH_SYSTEM_ONLY,
198            MATCH_UNINSTALLED_PACKAGES,
199            MATCH_INSTANT,
200            GET_DISABLED_COMPONENTS,
201            GET_DISABLED_UNTIL_USED_COMPONENTS,
202            GET_UNINSTALLED_PACKAGES,
203    })
204    @Retention(RetentionPolicy.SOURCE)
205    public @interface ResolveInfoFlags {}
206
207    /** @hide */
208    @IntDef(flag = true, value = {
209            GET_META_DATA,
210    })
211    @Retention(RetentionPolicy.SOURCE)
212    public @interface PermissionInfoFlags {}
213
214    /** @hide */
215    @IntDef(flag = true, value = {
216            GET_META_DATA,
217    })
218    @Retention(RetentionPolicy.SOURCE)
219    public @interface PermissionGroupInfoFlags {}
220
221    /** @hide */
222    @IntDef(flag = true, value = {
223            GET_META_DATA,
224    })
225    @Retention(RetentionPolicy.SOURCE)
226    public @interface InstrumentationInfoFlags {}
227
228    /**
229     * {@link PackageInfo} flag: return information about
230     * activities in the package in {@link PackageInfo#activities}.
231     */
232    public static final int GET_ACTIVITIES              = 0x00000001;
233
234    /**
235     * {@link PackageInfo} flag: return information about
236     * intent receivers in the package in
237     * {@link PackageInfo#receivers}.
238     */
239    public static final int GET_RECEIVERS               = 0x00000002;
240
241    /**
242     * {@link PackageInfo} flag: return information about
243     * services in the package in {@link PackageInfo#services}.
244     */
245    public static final int GET_SERVICES                = 0x00000004;
246
247    /**
248     * {@link PackageInfo} flag: return information about
249     * content providers in the package in
250     * {@link PackageInfo#providers}.
251     */
252    public static final int GET_PROVIDERS               = 0x00000008;
253
254    /**
255     * {@link PackageInfo} flag: return information about
256     * instrumentation in the package in
257     * {@link PackageInfo#instrumentation}.
258     */
259    public static final int GET_INSTRUMENTATION         = 0x00000010;
260
261    /**
262     * {@link PackageInfo} flag: return information about the
263     * intent filters supported by the activity.
264     */
265    public static final int GET_INTENT_FILTERS          = 0x00000020;
266
267    /**
268     * {@link PackageInfo} flag: return information about the
269     * signatures included in the package.
270     */
271    public static final int GET_SIGNATURES          = 0x00000040;
272
273    /**
274     * {@link ResolveInfo} flag: return the IntentFilter that
275     * was matched for a particular ResolveInfo in
276     * {@link ResolveInfo#filter}.
277     */
278    public static final int GET_RESOLVED_FILTER         = 0x00000040;
279
280    /**
281     * {@link ComponentInfo} flag: return the {@link ComponentInfo#metaData}
282     * data {@link android.os.Bundle}s that are associated with a component.
283     * This applies for any API returning a ComponentInfo subclass.
284     */
285    public static final int GET_META_DATA               = 0x00000080;
286
287    /**
288     * {@link PackageInfo} flag: return the
289     * {@link PackageInfo#gids group ids} that are associated with an
290     * application.
291     * This applies for any API returning a PackageInfo class, either
292     * directly or nested inside of another.
293     */
294    public static final int GET_GIDS                    = 0x00000100;
295
296    /**
297     * @deprecated replaced with {@link #MATCH_DISABLED_COMPONENTS}
298     */
299    @Deprecated
300    public static final int GET_DISABLED_COMPONENTS = 0x00000200;
301
302    /**
303     * {@link PackageInfo} flag: include disabled components in the returned info.
304     */
305    public static final int MATCH_DISABLED_COMPONENTS = 0x00000200;
306
307    /**
308     * {@link ApplicationInfo} flag: return the
309     * {@link ApplicationInfo#sharedLibraryFiles paths to the shared libraries}
310     * that are associated with an application.
311     * This applies for any API returning an ApplicationInfo class, either
312     * directly or nested inside of another.
313     */
314    public static final int GET_SHARED_LIBRARY_FILES    = 0x00000400;
315
316    /**
317     * {@link ProviderInfo} flag: return the
318     * {@link ProviderInfo#uriPermissionPatterns URI permission patterns}
319     * that are associated with a content provider.
320     * This applies for any API returning a ProviderInfo class, either
321     * directly or nested inside of another.
322     */
323    public static final int GET_URI_PERMISSION_PATTERNS  = 0x00000800;
324    /**
325     * {@link PackageInfo} flag: return information about
326     * permissions in the package in
327     * {@link PackageInfo#permissions}.
328     */
329    public static final int GET_PERMISSIONS               = 0x00001000;
330
331    /**
332     * @deprecated replaced with {@link #MATCH_UNINSTALLED_PACKAGES}
333     */
334    @Deprecated
335    public static final int GET_UNINSTALLED_PACKAGES = 0x00002000;
336
337    /**
338     * Flag parameter to retrieve some information about all applications (even
339     * uninstalled ones) which have data directories. This state could have
340     * resulted if applications have been deleted with flag
341     * {@code DONT_DELETE_DATA} with a possibility of being replaced or
342     * reinstalled in future.
343     * <p>
344     * Note: this flag may cause less information about currently installed
345     * applications to be returned.
346     */
347    public static final int MATCH_UNINSTALLED_PACKAGES = 0x00002000;
348
349    /**
350     * {@link PackageInfo} flag: return information about
351     * hardware preferences in
352     * {@link PackageInfo#configPreferences PackageInfo.configPreferences},
353     * and requested features in {@link PackageInfo#reqFeatures} and
354     * {@link PackageInfo#featureGroups}.
355     */
356    public static final int GET_CONFIGURATIONS = 0x00004000;
357
358    /**
359     * @deprecated replaced with {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS}.
360     */
361    @Deprecated
362    public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 0x00008000;
363
364    /**
365     * {@link PackageInfo} flag: include disabled components which are in
366     * that state only because of {@link #COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED}
367     * in the returned info.  Note that if you set this flag, applications
368     * that are in this disabled state will be reported as enabled.
369     */
370    public static final int MATCH_DISABLED_UNTIL_USED_COMPONENTS = 0x00008000;
371
372    /**
373     * Resolution and querying flag: if set, only filters that support the
374     * {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for
375     * matching.  This is a synonym for including the CATEGORY_DEFAULT in your
376     * supplied Intent.
377     */
378    public static final int MATCH_DEFAULT_ONLY  = 0x00010000;
379
380    /**
381     * Querying flag: if set and if the platform is doing any filtering of the
382     * results, then the filtering will not happen. This is a synonym for saying
383     * that all results should be returned.
384     * <p>
385     * <em>This flag should be used with extreme care.</em>
386     */
387    public static final int MATCH_ALL = 0x00020000;
388
389    /**
390     * Querying flag: match components which are direct boot <em>unaware</em> in
391     * the returned info, regardless of the current user state.
392     * <p>
393     * When neither {@link #MATCH_DIRECT_BOOT_AWARE} nor
394     * {@link #MATCH_DIRECT_BOOT_UNAWARE} are specified, the default behavior is
395     * to match only runnable components based on the user state. For example,
396     * when a user is started but credentials have not been presented yet, the
397     * user is running "locked" and only {@link #MATCH_DIRECT_BOOT_AWARE}
398     * components are returned. Once the user credentials have been presented,
399     * the user is running "unlocked" and both {@link #MATCH_DIRECT_BOOT_AWARE}
400     * and {@link #MATCH_DIRECT_BOOT_UNAWARE} components are returned.
401     *
402     * @see UserManager#isUserUnlocked()
403     */
404    public static final int MATCH_DIRECT_BOOT_UNAWARE = 0x00040000;
405
406    /**
407     * Querying flag: match components which are direct boot <em>aware</em> in
408     * the returned info, regardless of the current user state.
409     * <p>
410     * When neither {@link #MATCH_DIRECT_BOOT_AWARE} nor
411     * {@link #MATCH_DIRECT_BOOT_UNAWARE} are specified, the default behavior is
412     * to match only runnable components based on the user state. For example,
413     * when a user is started but credentials have not been presented yet, the
414     * user is running "locked" and only {@link #MATCH_DIRECT_BOOT_AWARE}
415     * components are returned. Once the user credentials have been presented,
416     * the user is running "unlocked" and both {@link #MATCH_DIRECT_BOOT_AWARE}
417     * and {@link #MATCH_DIRECT_BOOT_UNAWARE} components are returned.
418     *
419     * @see UserManager#isUserUnlocked()
420     */
421    public static final int MATCH_DIRECT_BOOT_AWARE = 0x00080000;
422
423    /**
424     * Querying flag: include only components from applications that are marked
425     * with {@link ApplicationInfo#FLAG_SYSTEM}.
426     */
427    public static final int MATCH_SYSTEM_ONLY = 0x00100000;
428
429    /**
430     * Internal {@link PackageInfo} flag: include only components on the system image.
431     * This will not return information on any unbundled update to system components.
432     * @hide
433     */
434    @SystemApi
435    public static final int MATCH_FACTORY_ONLY = 0x00200000;
436
437    /**
438     * Allows querying of packages installed for any user, not just the specific one. This flag
439     * is only meant for use by apps that have INTERACT_ACROSS_USERS permission.
440     * @hide
441     */
442    @SystemApi
443    public static final int MATCH_ANY_USER = 0x00400000;
444
445    /**
446     * Combination of MATCH_ANY_USER and MATCH_UNINSTALLED_PACKAGES to mean any known
447     * package.
448     * @hide
449     */
450    public static final int MATCH_KNOWN_PACKAGES = MATCH_UNINSTALLED_PACKAGES | MATCH_ANY_USER;
451
452    /**
453     * Internal {@link PackageInfo} flag: include components that are part of an
454     * instant app. By default, instant app components are not matched.
455     * @hide
456     */
457    @SystemApi
458    public static final int MATCH_INSTANT = 0x00800000;
459
460    /**
461     * Internal {@link PackageInfo} flag: include only components that are exposed to
462     * ephemeral apps.
463     * @hide
464     */
465    public static final int MATCH_VISIBLE_TO_INSTANT_APP_ONLY = 0x01000000;
466
467    /**
468     * Internal flag used to indicate that a system component has done their
469     * homework and verified that they correctly handle packages and components
470     * that come and go over time. In particular:
471     * <ul>
472     * <li>Apps installed on external storage, which will appear to be
473     * uninstalled while the the device is ejected.
474     * <li>Apps with encryption unaware components, which will appear to not
475     * exist while the device is locked.
476     * </ul>
477     *
478     * @see #MATCH_UNINSTALLED_PACKAGES
479     * @see #MATCH_DIRECT_BOOT_AWARE
480     * @see #MATCH_DIRECT_BOOT_UNAWARE
481     * @hide
482     */
483    public static final int MATCH_DEBUG_TRIAGED_MISSING = 0x10000000;
484
485    /**
486     * Flag for {@link #addCrossProfileIntentFilter}: if this flag is set: when
487     * resolving an intent that matches the {@code CrossProfileIntentFilter},
488     * the current profile will be skipped. Only activities in the target user
489     * can respond to the intent.
490     *
491     * @hide
492     */
493    public static final int SKIP_CURRENT_PROFILE = 0x00000002;
494
495    /**
496     * Flag for {@link #addCrossProfileIntentFilter}: if this flag is set:
497     * activities in the other profiles can respond to the intent only if no activity with
498     * non-negative priority in current profile can respond to the intent.
499     * @hide
500     */
501    public static final int ONLY_IF_NO_MATCH_FOUND = 0x00000004;
502
503    /** @hide */
504    @IntDef({PERMISSION_GRANTED, PERMISSION_DENIED})
505    @Retention(RetentionPolicy.SOURCE)
506    public @interface PermissionResult {}
507
508    /**
509     * Permission check result: this is returned by {@link #checkPermission}
510     * if the permission has been granted to the given package.
511     */
512    public static final int PERMISSION_GRANTED = 0;
513
514    /**
515     * Permission check result: this is returned by {@link #checkPermission}
516     * if the permission has not been granted to the given package.
517     */
518    public static final int PERMISSION_DENIED = -1;
519
520    /**
521     * Signature check result: this is returned by {@link #checkSignatures}
522     * if all signatures on the two packages match.
523     */
524    public static final int SIGNATURE_MATCH = 0;
525
526    /**
527     * Signature check result: this is returned by {@link #checkSignatures}
528     * if neither of the two packages is signed.
529     */
530    public static final int SIGNATURE_NEITHER_SIGNED = 1;
531
532    /**
533     * Signature check result: this is returned by {@link #checkSignatures}
534     * if the first package is not signed but the second is.
535     */
536    public static final int SIGNATURE_FIRST_NOT_SIGNED = -1;
537
538    /**
539     * Signature check result: this is returned by {@link #checkSignatures}
540     * if the second package is not signed but the first is.
541     */
542    public static final int SIGNATURE_SECOND_NOT_SIGNED = -2;
543
544    /**
545     * Signature check result: this is returned by {@link #checkSignatures}
546     * if not all signatures on both packages match.
547     */
548    public static final int SIGNATURE_NO_MATCH = -3;
549
550    /**
551     * Signature check result: this is returned by {@link #checkSignatures}
552     * if either of the packages are not valid.
553     */
554    public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
555
556    /**
557     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
558     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
559     * component or application is in its default enabled state (as specified
560     * in its manifest).
561     */
562    public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
563
564    /**
565     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
566     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
567     * component or application has been explictily enabled, regardless of
568     * what it has specified in its manifest.
569     */
570    public static final int COMPONENT_ENABLED_STATE_ENABLED = 1;
571
572    /**
573     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
574     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
575     * component or application has been explicitly disabled, regardless of
576     * what it has specified in its manifest.
577     */
578    public static final int COMPONENT_ENABLED_STATE_DISABLED = 2;
579
580    /**
581     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: The
582     * user has explicitly disabled the application, regardless of what it has
583     * specified in its manifest.  Because this is due to the user's request,
584     * they may re-enable it if desired through the appropriate system UI.  This
585     * option currently <strong>cannot</strong> be used with
586     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
587     */
588    public static final int COMPONENT_ENABLED_STATE_DISABLED_USER = 3;
589
590    /**
591     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: This
592     * application should be considered, until the point where the user actually
593     * wants to use it.  This means that it will not normally show up to the user
594     * (such as in the launcher), but various parts of the user interface can
595     * use {@link #GET_DISABLED_UNTIL_USED_COMPONENTS} to still see it and allow
596     * the user to select it (as for example an IME, device admin, etc).  Such code,
597     * once the user has selected the app, should at that point also make it enabled.
598     * This option currently <strong>can not</strong> be used with
599     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
600     */
601    public static final int COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED = 4;
602
603    /** @hide */
604    @IntDef(flag = true, value = {
605            INSTALL_FORWARD_LOCK,
606            INSTALL_REPLACE_EXISTING,
607            INSTALL_ALLOW_TEST,
608            INSTALL_EXTERNAL,
609            INSTALL_INTERNAL,
610            INSTALL_FROM_ADB,
611            INSTALL_ALL_USERS,
612            INSTALL_ALLOW_DOWNGRADE,
613            INSTALL_GRANT_RUNTIME_PERMISSIONS,
614            INSTALL_FORCE_VOLUME_UUID,
615            INSTALL_FORCE_PERMISSION_PROMPT,
616            INSTALL_INSTANT_APP,
617            INSTALL_DONT_KILL_APP,
618            INSTALL_FORCE_SDK,
619            INSTALL_FULL_APP,
620            INSTALL_ALLOCATE_AGGRESSIVE,
621    })
622    @Retention(RetentionPolicy.SOURCE)
623    public @interface InstallFlags {}
624
625    /**
626     * Flag parameter for {@link #installPackage} to indicate that this package
627     * should be installed as forward locked, i.e. only the app itself should
628     * have access to its code and non-resource assets.
629     *
630     * @deprecated new installs into ASEC containers are no longer supported.
631     * @hide
632     */
633    @Deprecated
634    public static final int INSTALL_FORWARD_LOCK = 0x00000001;
635
636    /**
637     * Flag parameter for {@link #installPackage} to indicate that you want to
638     * replace an already installed package, if one exists.
639     *
640     * @hide
641     */
642    public static final int INSTALL_REPLACE_EXISTING = 0x00000002;
643
644    /**
645     * Flag parameter for {@link #installPackage} to indicate that you want to
646     * allow test packages (those that have set android:testOnly in their
647     * manifest) to be installed.
648     * @hide
649     */
650    public static final int INSTALL_ALLOW_TEST = 0x00000004;
651
652    /**
653     * Flag parameter for {@link #installPackage} to indicate that this package
654     * must be installed to an ASEC on a {@link VolumeInfo#TYPE_PUBLIC}.
655     *
656     * @deprecated new installs into ASEC containers are no longer supported;
657     *             use adoptable storage instead.
658     * @hide
659     */
660    @Deprecated
661    public static final int INSTALL_EXTERNAL = 0x00000008;
662
663    /**
664     * Flag parameter for {@link #installPackage} to indicate that this package
665     * must be installed to internal storage.
666     *
667     * @hide
668     */
669    public static final int INSTALL_INTERNAL = 0x00000010;
670
671    /**
672     * Flag parameter for {@link #installPackage} to indicate that this install
673     * was initiated via ADB.
674     *
675     * @hide
676     */
677    public static final int INSTALL_FROM_ADB = 0x00000020;
678
679    /**
680     * Flag parameter for {@link #installPackage} to indicate that this install
681     * should immediately be visible to all users.
682     *
683     * @hide
684     */
685    public static final int INSTALL_ALL_USERS = 0x00000040;
686
687    /**
688     * Flag parameter for {@link #installPackage} to indicate that it is okay
689     * to install an update to an app where the newly installed app has a lower
690     * version code than the currently installed app. This is permitted only if
691     * the currently installed app is marked debuggable.
692     *
693     * @hide
694     */
695    public static final int INSTALL_ALLOW_DOWNGRADE = 0x00000080;
696
697    /**
698     * Flag parameter for {@link #installPackage} to indicate that all runtime
699     * permissions should be granted to the package. If {@link #INSTALL_ALL_USERS}
700     * is set the runtime permissions will be granted to all users, otherwise
701     * only to the owner.
702     *
703     * @hide
704     */
705    public static final int INSTALL_GRANT_RUNTIME_PERMISSIONS = 0x00000100;
706
707    /** {@hide} */
708    public static final int INSTALL_FORCE_VOLUME_UUID = 0x00000200;
709
710    /**
711     * Flag parameter for {@link #installPackage} to indicate that we always want to force
712     * the prompt for permission approval. This overrides any special behaviour for internal
713     * components.
714     *
715     * @hide
716     */
717    public static final int INSTALL_FORCE_PERMISSION_PROMPT = 0x00000400;
718
719    /**
720     * Flag parameter for {@link #installPackage} to indicate that this package is
721     * to be installed as a lightweight "ephemeral" app.
722     *
723     * @hide
724     */
725    public static final int INSTALL_INSTANT_APP = 0x00000800;
726
727    /**
728     * Flag parameter for {@link #installPackage} to indicate that this package contains
729     * a feature split to an existing application and the existing application should not
730     * be killed during the installation process.
731     *
732     * @hide
733     */
734    public static final int INSTALL_DONT_KILL_APP = 0x00001000;
735
736    /**
737     * Flag parameter for {@link #installPackage} to indicate that this package is an
738     * upgrade to a package that refers to the SDK via release letter.
739     *
740     * @hide
741     */
742    public static final int INSTALL_FORCE_SDK = 0x00002000;
743
744    /**
745     * Flag parameter for {@link #installPackage} to indicate that this package is
746     * to be installed as a heavy weight app. This is fundamentally the opposite of
747     * {@link #INSTALL_INSTANT_APP}.
748     *
749     * @hide
750     */
751    public static final int INSTALL_FULL_APP = 0x00004000;
752
753    /**
754     * Flag parameter for {@link #installPackage} to indicate that this package
755     * is critical to system health or security, meaning the system should use
756     * {@link StorageManager#FLAG_ALLOCATE_AGGRESSIVE} internally.
757     *
758     * @hide
759     */
760    public static final int INSTALL_ALLOCATE_AGGRESSIVE = 0x00008000;
761
762    /**
763     * Flag parameter for
764     * {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate
765     * that you don't want to kill the app containing the component.  Be careful when you set this
766     * since changing component states can make the containing application's behavior unpredictable.
767     */
768    public static final int DONT_KILL_APP = 0x00000001;
769
770    /** @hide */
771    @IntDef({INSTALL_REASON_UNKNOWN, INSTALL_REASON_POLICY, INSTALL_REASON_DEVICE_RESTORE,
772            INSTALL_REASON_DEVICE_SETUP, INSTALL_REASON_USER})
773    @Retention(RetentionPolicy.SOURCE)
774    public @interface InstallReason {}
775
776    /**
777     * Code indicating that the reason for installing this package is unknown.
778     */
779    public static final int INSTALL_REASON_UNKNOWN = 0;
780
781    /**
782     * Code indicating that this package was installed due to enterprise policy.
783     */
784    public static final int INSTALL_REASON_POLICY = 1;
785
786    /**
787     * Code indicating that this package was installed as part of restoring from another device.
788     */
789    public static final int INSTALL_REASON_DEVICE_RESTORE = 2;
790
791    /**
792     * Code indicating that this package was installed as part of device setup.
793     */
794    public static final int INSTALL_REASON_DEVICE_SETUP = 3;
795
796    /**
797     * Code indicating that the package installation was initiated by the user.
798     */
799    public static final int INSTALL_REASON_USER = 4;
800
801    /**
802     * Installation return code: this is passed to the
803     * {@link IPackageInstallObserver} on success.
804     *
805     * @hide
806     */
807    @SystemApi
808    public static final int INSTALL_SUCCEEDED = 1;
809
810    /**
811     * Installation return code: this is passed to the
812     * {@link IPackageInstallObserver} if the package is already installed.
813     *
814     * @hide
815     */
816    @SystemApi
817    public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;
818
819    /**
820     * Installation return code: this is passed to the
821     * {@link IPackageInstallObserver} if the package archive file is invalid.
822     *
823     * @hide
824     */
825    @SystemApi
826    public static final int INSTALL_FAILED_INVALID_APK = -2;
827
828    /**
829     * Installation return code: this is passed to the
830     * {@link IPackageInstallObserver} if the URI passed in is invalid.
831     *
832     * @hide
833     */
834    @SystemApi
835    public static final int INSTALL_FAILED_INVALID_URI = -3;
836
837    /**
838     * Installation return code: this is passed to the
839     * {@link IPackageInstallObserver} if the package manager service found that
840     * the device didn't have enough storage space to install the app.
841     *
842     * @hide
843     */
844    @SystemApi
845    public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;
846
847    /**
848     * Installation return code: this is passed to the
849     * {@link IPackageInstallObserver} if a package is already installed with
850     * the same name.
851     *
852     * @hide
853     */
854    @SystemApi
855    public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;
856
857    /**
858     * Installation return code: this is passed to the
859     * {@link IPackageInstallObserver} if the requested shared user does not
860     * exist.
861     *
862     * @hide
863     */
864    @SystemApi
865    public static final int INSTALL_FAILED_NO_SHARED_USER = -6;
866
867    /**
868     * Installation return code: this is passed to the
869     * {@link IPackageInstallObserver} if a previously installed package of the
870     * same name has a different signature than the new package (and the old
871     * package's data was not removed).
872     *
873     * @hide
874     */
875    @SystemApi
876    public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;
877
878    /**
879     * Installation return code: this is passed to the
880     * {@link IPackageInstallObserver} if the new package is requested a shared
881     * user which is already installed on the device and does not have matching
882     * signature.
883     *
884     * @hide
885     */
886    @SystemApi
887    public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;
888
889    /**
890     * Installation return code: this is passed to the
891     * {@link IPackageInstallObserver} if the new package uses a shared library
892     * that is not available.
893     *
894     * @hide
895     */
896    @SystemApi
897    public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;
898
899    /**
900     * Installation return code: this is passed to the
901     * {@link IPackageInstallObserver} if the new package uses a shared library
902     * that is not available.
903     *
904     * @hide
905     */
906    @SystemApi
907    public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;
908
909    /**
910     * Installation return code: this is passed to the
911     * {@link IPackageInstallObserver} if the new package failed while
912     * optimizing and validating its dex files, either because there was not
913     * enough storage or the validation failed.
914     *
915     * @hide
916     */
917    @SystemApi
918    public static final int INSTALL_FAILED_DEXOPT = -11;
919
920    /**
921     * Installation return code: this is passed to the
922     * {@link IPackageInstallObserver} if the new package failed because the
923     * current SDK version is older than that required by the package.
924     *
925     * @hide
926     */
927    @SystemApi
928    public static final int INSTALL_FAILED_OLDER_SDK = -12;
929
930    /**
931     * Installation return code: this is passed to the
932     * {@link IPackageInstallObserver} if the new package failed because it
933     * contains a content provider with the same authority as a provider already
934     * installed in the system.
935     *
936     * @hide
937     */
938    @SystemApi
939    public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;
940
941    /**
942     * Installation return code: this is passed to the
943     * {@link IPackageInstallObserver} if the new package failed because the
944     * current SDK version is newer than that required by the package.
945     *
946     * @hide
947     */
948    @SystemApi
949    public static final int INSTALL_FAILED_NEWER_SDK = -14;
950
951    /**
952     * Installation return code: this is passed to the
953     * {@link IPackageInstallObserver} if the new package failed because it has
954     * specified that it is a test-only package and the caller has not supplied
955     * the {@link #INSTALL_ALLOW_TEST} flag.
956     *
957     * @hide
958     */
959    @SystemApi
960    public static final int INSTALL_FAILED_TEST_ONLY = -15;
961
962    /**
963     * Installation return code: this is passed to the
964     * {@link IPackageInstallObserver} if the package being installed contains
965     * native code, but none that is compatible with the device's CPU_ABI.
966     *
967     * @hide
968     */
969    @SystemApi
970    public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;
971
972    /**
973     * Installation return code: this is passed to the
974     * {@link IPackageInstallObserver} if the new package uses a feature that is
975     * not available.
976     *
977     * @hide
978     */
979    @SystemApi
980    public static final int INSTALL_FAILED_MISSING_FEATURE = -17;
981
982    // ------ Errors related to sdcard
983    /**
984     * Installation return code: this is passed to the
985     * {@link IPackageInstallObserver} if a secure container mount point
986     * couldn't be accessed on external media.
987     *
988     * @hide
989     */
990    @SystemApi
991    public static final int INSTALL_FAILED_CONTAINER_ERROR = -18;
992
993    /**
994     * Installation return code: this is passed to the
995     * {@link IPackageInstallObserver} if the new package couldn't be installed
996     * in the specified install location.
997     *
998     * @hide
999     */
1000    @SystemApi
1001    public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19;
1002
1003    /**
1004     * Installation return code: this is passed to the
1005     * {@link IPackageInstallObserver} if the new package couldn't be installed
1006     * in the specified install location because the media is not available.
1007     *
1008     * @hide
1009     */
1010    @SystemApi
1011    public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE = -20;
1012
1013    /**
1014     * Installation return code: this is passed to the
1015     * {@link IPackageInstallObserver} if the new package couldn't be installed
1016     * because the verification timed out.
1017     *
1018     * @hide
1019     */
1020    @SystemApi
1021    public static final int INSTALL_FAILED_VERIFICATION_TIMEOUT = -21;
1022
1023    /**
1024     * Installation return code: this is passed to the
1025     * {@link IPackageInstallObserver} if the new package couldn't be installed
1026     * because the verification did not succeed.
1027     *
1028     * @hide
1029     */
1030    @SystemApi
1031    public static final int INSTALL_FAILED_VERIFICATION_FAILURE = -22;
1032
1033    /**
1034     * Installation return code: this is passed to the
1035     * {@link IPackageInstallObserver} if the package changed from what the
1036     * calling program expected.
1037     *
1038     * @hide
1039     */
1040    @SystemApi
1041    public static final int INSTALL_FAILED_PACKAGE_CHANGED = -23;
1042
1043    /**
1044     * Installation return code: this is passed to the
1045     * {@link IPackageInstallObserver} if the new package is assigned a
1046     * different UID than it previously held.
1047     *
1048     * @hide
1049     */
1050    public static final int INSTALL_FAILED_UID_CHANGED = -24;
1051
1052    /**
1053     * Installation return code: this is passed to the
1054     * {@link IPackageInstallObserver} if the new package has an older version
1055     * code than the currently installed package.
1056     *
1057     * @hide
1058     */
1059    public static final int INSTALL_FAILED_VERSION_DOWNGRADE = -25;
1060
1061    /**
1062     * Installation return code: this is passed to the
1063     * {@link IPackageInstallObserver} if the old package has target SDK high
1064     * enough to support runtime permission and the new package has target SDK
1065     * low enough to not support runtime permissions.
1066     *
1067     * @hide
1068     */
1069    @SystemApi
1070    public static final int INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE = -26;
1071
1072    /**
1073     * Installation return code: this is passed to the
1074     * {@link IPackageInstallObserver} if the new package attempts to downgrade the
1075     * target sandbox version of the app.
1076     *
1077     * @hide
1078     */
1079    @SystemApi
1080    public static final int INSTALL_FAILED_SANDBOX_VERSION_DOWNGRADE = -27;
1081
1082    /**
1083     * Installation parse return code: this is passed to the
1084     * {@link IPackageInstallObserver} if the parser was given a path that is
1085     * not a file, or does not end with the expected '.apk' extension.
1086     *
1087     * @hide
1088     */
1089    @SystemApi
1090    public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;
1091
1092    /**
1093     * Installation parse return code: this is passed to the
1094     * {@link IPackageInstallObserver} if the parser was unable to retrieve the
1095     * AndroidManifest.xml file.
1096     *
1097     * @hide
1098     */
1099    @SystemApi
1100    public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;
1101
1102    /**
1103     * Installation parse return code: this is passed to the
1104     * {@link IPackageInstallObserver} if the parser encountered an unexpected
1105     * exception.
1106     *
1107     * @hide
1108     */
1109    @SystemApi
1110    public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;
1111
1112    /**
1113     * Installation parse return code: this is passed to the
1114     * {@link IPackageInstallObserver} if the parser did not find any
1115     * certificates in the .apk.
1116     *
1117     * @hide
1118     */
1119    @SystemApi
1120    public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;
1121
1122    /**
1123     * Installation parse return code: this is passed to the
1124     * {@link IPackageInstallObserver} if the parser found inconsistent
1125     * certificates on the files in the .apk.
1126     *
1127     * @hide
1128     */
1129    @SystemApi
1130    public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;
1131
1132    /**
1133     * Installation parse return code: this is passed to the
1134     * {@link IPackageInstallObserver} if the parser encountered a
1135     * CertificateEncodingException in one of the files in the .apk.
1136     *
1137     * @hide
1138     */
1139    @SystemApi
1140    public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;
1141
1142    /**
1143     * Installation parse return code: this is passed to the
1144     * {@link IPackageInstallObserver} if the parser encountered a bad or
1145     * missing package name in the manifest.
1146     *
1147     * @hide
1148     */
1149    @SystemApi
1150    public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;
1151
1152    /**
1153     * Installation parse return code: this is passed to the
1154     * {@link IPackageInstallObserver} if the parser encountered a bad shared
1155     * user id name in the manifest.
1156     *
1157     * @hide
1158     */
1159    @SystemApi
1160    public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;
1161
1162    /**
1163     * Installation parse return code: this is passed to the
1164     * {@link IPackageInstallObserver} if the parser encountered some structural
1165     * problem in the manifest.
1166     *
1167     * @hide
1168     */
1169    @SystemApi
1170    public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;
1171
1172    /**
1173     * Installation parse return code: this is passed to the
1174     * {@link IPackageInstallObserver} if the parser did not find any actionable
1175     * tags (instrumentation or application) in the manifest.
1176     *
1177     * @hide
1178     */
1179    @SystemApi
1180    public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;
1181
1182    /**
1183     * Installation failed return code: this is passed to the
1184     * {@link IPackageInstallObserver} if the system failed to install the
1185     * package because of system issues.
1186     *
1187     * @hide
1188     */
1189    @SystemApi
1190    public static final int INSTALL_FAILED_INTERNAL_ERROR = -110;
1191
1192    /**
1193     * Installation failed return code: this is passed to the
1194     * {@link IPackageInstallObserver} if the system failed to install the
1195     * package because the user is restricted from installing apps.
1196     *
1197     * @hide
1198     */
1199    public static final int INSTALL_FAILED_USER_RESTRICTED = -111;
1200
1201    /**
1202     * Installation failed return code: this is passed to the
1203     * {@link IPackageInstallObserver} if the system failed to install the
1204     * package because it is attempting to define a permission that is already
1205     * defined by some existing package.
1206     * <p>
1207     * The package name of the app which has already defined the permission is
1208     * passed to a {@link PackageInstallObserver}, if any, as the
1209     * {@link #EXTRA_FAILURE_EXISTING_PACKAGE} string extra; and the name of the
1210     * permission being redefined is passed in the
1211     * {@link #EXTRA_FAILURE_EXISTING_PERMISSION} string extra.
1212     *
1213     * @hide
1214     */
1215    public static final int INSTALL_FAILED_DUPLICATE_PERMISSION = -112;
1216
1217    /**
1218     * Installation failed return code: this is passed to the
1219     * {@link IPackageInstallObserver} if the system failed to install the
1220     * package because its packaged native code did not match any of the ABIs
1221     * supported by the system.
1222     *
1223     * @hide
1224     */
1225    public static final int INSTALL_FAILED_NO_MATCHING_ABIS = -113;
1226
1227    /**
1228     * Internal return code for NativeLibraryHelper methods to indicate that the package
1229     * being processed did not contain any native code. This is placed here only so that
1230     * it can belong to the same value space as the other install failure codes.
1231     *
1232     * @hide
1233     */
1234    public static final int NO_NATIVE_LIBRARIES = -114;
1235
1236    /** {@hide} */
1237    public static final int INSTALL_FAILED_ABORTED = -115;
1238
1239    /**
1240     * Installation failed return code: instant app installs are incompatible with some
1241     * other installation flags supplied for the operation; or other circumstances such
1242     * as trying to upgrade a system app via an instant app install.
1243     * @hide
1244     */
1245    public static final int INSTALL_FAILED_INSTANT_APP_INVALID = -116;
1246
1247    /** @hide */
1248    @IntDef(flag = true, value = {
1249            DELETE_KEEP_DATA,
1250            DELETE_ALL_USERS,
1251            DELETE_SYSTEM_APP,
1252            DELETE_DONT_KILL_APP,
1253    })
1254    @Retention(RetentionPolicy.SOURCE)
1255    public @interface DeleteFlags {}
1256
1257    /**
1258     * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
1259     * package's data directory.
1260     *
1261     * @hide
1262     */
1263    public static final int DELETE_KEEP_DATA = 0x00000001;
1264
1265    /**
1266     * Flag parameter for {@link #deletePackage} to indicate that you want the
1267     * package deleted for all users.
1268     *
1269     * @hide
1270     */
1271    public static final int DELETE_ALL_USERS = 0x00000002;
1272
1273    /**
1274     * Flag parameter for {@link #deletePackage} to indicate that, if you are calling
1275     * uninstall on a system that has been updated, then don't do the normal process
1276     * of uninstalling the update and rolling back to the older system version (which
1277     * needs to happen for all users); instead, just mark the app as uninstalled for
1278     * the current user.
1279     *
1280     * @hide
1281     */
1282    public static final int DELETE_SYSTEM_APP = 0x00000004;
1283
1284    /**
1285     * Flag parameter for {@link #deletePackage} to indicate that, if you are calling
1286     * uninstall on a package that is replaced to provide new feature splits, the
1287     * existing application should not be killed during the removal process.
1288     *
1289     * @hide
1290     */
1291    public static final int DELETE_DONT_KILL_APP = 0x00000008;
1292
1293    /**
1294     * Return code for when package deletion succeeds. This is passed to the
1295     * {@link IPackageDeleteObserver} if the system succeeded in deleting the
1296     * package.
1297     *
1298     * @hide
1299     */
1300    public static final int DELETE_SUCCEEDED = 1;
1301
1302    /**
1303     * Deletion failed return code: this is passed to the
1304     * {@link IPackageDeleteObserver} if the system failed to delete the package
1305     * for an unspecified reason.
1306     *
1307     * @hide
1308     */
1309    public static final int DELETE_FAILED_INTERNAL_ERROR = -1;
1310
1311    /**
1312     * Deletion failed return code: this is passed to the
1313     * {@link IPackageDeleteObserver} if the system failed to delete the package
1314     * because it is the active DevicePolicy manager.
1315     *
1316     * @hide
1317     */
1318    public static final int DELETE_FAILED_DEVICE_POLICY_MANAGER = -2;
1319
1320    /**
1321     * Deletion failed return code: this is passed to the
1322     * {@link IPackageDeleteObserver} if the system failed to delete the package
1323     * since the user is restricted.
1324     *
1325     * @hide
1326     */
1327    public static final int DELETE_FAILED_USER_RESTRICTED = -3;
1328
1329    /**
1330     * Deletion failed return code: this is passed to the
1331     * {@link IPackageDeleteObserver} if the system failed to delete the package
1332     * because a profile or device owner has marked the package as
1333     * uninstallable.
1334     *
1335     * @hide
1336     */
1337    public static final int DELETE_FAILED_OWNER_BLOCKED = -4;
1338
1339    /** {@hide} */
1340    public static final int DELETE_FAILED_ABORTED = -5;
1341
1342    /**
1343     * Deletion failed return code: this is passed to the
1344     * {@link IPackageDeleteObserver} if the system failed to delete the package
1345     * because the packge is a shared library used by other installed packages.
1346     * {@hide} */
1347    public static final int DELETE_FAILED_USED_SHARED_LIBRARY = -6;
1348
1349    /**
1350     * Return code that is passed to the {@link IPackageMoveObserver} when the
1351     * package has been successfully moved by the system.
1352     *
1353     * @hide
1354     */
1355    public static final int MOVE_SUCCEEDED = -100;
1356
1357    /**
1358     * Error code that is passed to the {@link IPackageMoveObserver} when the
1359     * package hasn't been successfully moved by the system because of
1360     * insufficient memory on specified media.
1361     *
1362     * @hide
1363     */
1364    public static final int MOVE_FAILED_INSUFFICIENT_STORAGE = -1;
1365
1366    /**
1367     * Error code that is passed to the {@link IPackageMoveObserver} if the
1368     * specified package doesn't exist.
1369     *
1370     * @hide
1371     */
1372    public static final int MOVE_FAILED_DOESNT_EXIST = -2;
1373
1374    /**
1375     * Error code that is passed to the {@link IPackageMoveObserver} if the
1376     * specified package cannot be moved since its a system package.
1377     *
1378     * @hide
1379     */
1380    public static final int MOVE_FAILED_SYSTEM_PACKAGE = -3;
1381
1382    /**
1383     * Error code that is passed to the {@link IPackageMoveObserver} if the
1384     * specified package cannot be moved since its forward locked.
1385     *
1386     * @hide
1387     */
1388    public static final int MOVE_FAILED_FORWARD_LOCKED = -4;
1389
1390    /**
1391     * Error code that is passed to the {@link IPackageMoveObserver} if the
1392     * specified package cannot be moved to the specified location.
1393     *
1394     * @hide
1395     */
1396    public static final int MOVE_FAILED_INVALID_LOCATION = -5;
1397
1398    /**
1399     * Error code that is passed to the {@link IPackageMoveObserver} if the
1400     * specified package cannot be moved to the specified location.
1401     *
1402     * @hide
1403     */
1404    public static final int MOVE_FAILED_INTERNAL_ERROR = -6;
1405
1406    /**
1407     * Error code that is passed to the {@link IPackageMoveObserver} if the
1408     * specified package already has an operation pending in the queue.
1409     *
1410     * @hide
1411     */
1412    public static final int MOVE_FAILED_OPERATION_PENDING = -7;
1413
1414    /**
1415     * Error code that is passed to the {@link IPackageMoveObserver} if the
1416     * specified package cannot be moved since it contains a device admin.
1417     *
1418     * @hide
1419     */
1420    public static final int MOVE_FAILED_DEVICE_ADMIN = -8;
1421
1422    /**
1423     * Error code that is passed to the {@link IPackageMoveObserver} if system does not allow
1424     * non-system apps to be moved to internal storage.
1425     *
1426     * @hide
1427     */
1428    public static final int MOVE_FAILED_3RD_PARTY_NOT_ALLOWED_ON_INTERNAL = -9;
1429
1430    /**
1431     * Flag parameter for {@link #movePackage} to indicate that
1432     * the package should be moved to internal storage if its
1433     * been installed on external media.
1434     * @hide
1435     */
1436    @Deprecated
1437    public static final int MOVE_INTERNAL = 0x00000001;
1438
1439    /**
1440     * Flag parameter for {@link #movePackage} to indicate that
1441     * the package should be moved to external media.
1442     * @hide
1443     */
1444    @Deprecated
1445    public static final int MOVE_EXTERNAL_MEDIA = 0x00000002;
1446
1447    /** {@hide} */
1448    public static final String EXTRA_MOVE_ID = "android.content.pm.extra.MOVE_ID";
1449
1450    /**
1451     * Usable by the required verifier as the {@code verificationCode} argument
1452     * for {@link PackageManager#verifyPendingInstall} to indicate that it will
1453     * allow the installation to proceed without any of the optional verifiers
1454     * needing to vote.
1455     *
1456     * @hide
1457     */
1458    public static final int VERIFICATION_ALLOW_WITHOUT_SUFFICIENT = 2;
1459
1460    /**
1461     * Used as the {@code verificationCode} argument for
1462     * {@link PackageManager#verifyPendingInstall} to indicate that the calling
1463     * package verifier allows the installation to proceed.
1464     */
1465    public static final int VERIFICATION_ALLOW = 1;
1466
1467    /**
1468     * Used as the {@code verificationCode} argument for
1469     * {@link PackageManager#verifyPendingInstall} to indicate the calling
1470     * package verifier does not vote to allow the installation to proceed.
1471     */
1472    public static final int VERIFICATION_REJECT = -1;
1473
1474    /**
1475     * Used as the {@code verificationCode} argument for
1476     * {@link PackageManager#verifyIntentFilter} to indicate that the calling
1477     * IntentFilter Verifier confirms that the IntentFilter is verified.
1478     *
1479     * @hide
1480     */
1481    @SystemApi
1482    public static final int INTENT_FILTER_VERIFICATION_SUCCESS = 1;
1483
1484    /**
1485     * Used as the {@code verificationCode} argument for
1486     * {@link PackageManager#verifyIntentFilter} to indicate that the calling
1487     * IntentFilter Verifier confirms that the IntentFilter is NOT verified.
1488     *
1489     * @hide
1490     */
1491    @SystemApi
1492    public static final int INTENT_FILTER_VERIFICATION_FAILURE = -1;
1493
1494    /**
1495     * Internal status code to indicate that an IntentFilter verification result is not specified.
1496     *
1497     * @hide
1498     */
1499    @SystemApi
1500    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED = 0;
1501
1502    /**
1503     * Used as the {@code status} argument for
1504     * {@link #updateIntentVerificationStatusAsUser} to indicate that the User
1505     * will always be prompted the Intent Disambiguation Dialog if there are two
1506     * or more Intent resolved for the IntentFilter's domain(s).
1507     *
1508     * @hide
1509     */
1510    @SystemApi
1511    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK = 1;
1512
1513    /**
1514     * Used as the {@code status} argument for
1515     * {@link #updateIntentVerificationStatusAsUser} to indicate that the User
1516     * will never be prompted the Intent Disambiguation Dialog if there are two
1517     * or more resolution of the Intent. The default App for the domain(s)
1518     * specified in the IntentFilter will also ALWAYS be used.
1519     *
1520     * @hide
1521     */
1522    @SystemApi
1523    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS = 2;
1524
1525    /**
1526     * Used as the {@code status} argument for
1527     * {@link #updateIntentVerificationStatusAsUser} to indicate that the User
1528     * may be prompted the Intent Disambiguation Dialog if there are two or more
1529     * Intent resolved. The default App for the domain(s) specified in the
1530     * IntentFilter will also NEVER be presented to the User.
1531     *
1532     * @hide
1533     */
1534    @SystemApi
1535    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER = 3;
1536
1537    /**
1538     * Used as the {@code status} argument for
1539     * {@link #updateIntentVerificationStatusAsUser} to indicate that this app
1540     * should always be considered as an ambiguous candidate for handling the
1541     * matching Intent even if there are other candidate apps in the "always"
1542     * state. Put another way: if there are any 'always ask' apps in a set of
1543     * more than one candidate app, then a disambiguation is *always* presented
1544     * even if there is another candidate app with the 'always' state.
1545     *
1546     * @hide
1547     */
1548    @SystemApi
1549    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK = 4;
1550
1551    /**
1552     * Can be used as the {@code millisecondsToDelay} argument for
1553     * {@link PackageManager#extendVerificationTimeout}. This is the
1554     * maximum time {@code PackageManager} waits for the verification
1555     * agent to return (in milliseconds).
1556     */
1557    public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000;
1558
1559    /**
1560     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's
1561     * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or
1562     * lag in sound input or output.
1563     */
1564    @SdkConstant(SdkConstantType.FEATURE)
1565    public static final String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
1566
1567    /**
1568     * Feature for {@link #getSystemAvailableFeatures} and
1569     * {@link #hasSystemFeature}: The device includes at least one form of audio
1570     * output, such as speakers, audio jack or streaming over bluetooth
1571     */
1572    @SdkConstant(SdkConstantType.FEATURE)
1573    public static final String FEATURE_AUDIO_OUTPUT = "android.hardware.audio.output";
1574
1575    /**
1576     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1577     * The device has professional audio level of functionality and performance.
1578     */
1579    @SdkConstant(SdkConstantType.FEATURE)
1580    public static final String FEATURE_AUDIO_PRO = "android.hardware.audio.pro";
1581
1582    /**
1583     * Feature for {@link #getSystemAvailableFeatures} and
1584     * {@link #hasSystemFeature}: The device is capable of communicating with
1585     * other devices via Bluetooth.
1586     */
1587    @SdkConstant(SdkConstantType.FEATURE)
1588    public static final String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
1589
1590    /**
1591     * Feature for {@link #getSystemAvailableFeatures} and
1592     * {@link #hasSystemFeature}: The device is capable of communicating with
1593     * other devices via Bluetooth Low Energy radio.
1594     */
1595    @SdkConstant(SdkConstantType.FEATURE)
1596    public static final String FEATURE_BLUETOOTH_LE = "android.hardware.bluetooth_le";
1597
1598    /**
1599     * Feature for {@link #getSystemAvailableFeatures} and
1600     * {@link #hasSystemFeature}: The device has a camera facing away
1601     * from the screen.
1602     */
1603    @SdkConstant(SdkConstantType.FEATURE)
1604    public static final String FEATURE_CAMERA = "android.hardware.camera";
1605
1606    /**
1607     * Feature for {@link #getSystemAvailableFeatures} and
1608     * {@link #hasSystemFeature}: The device's camera supports auto-focus.
1609     */
1610    @SdkConstant(SdkConstantType.FEATURE)
1611    public static final String FEATURE_CAMERA_AUTOFOCUS = "android.hardware.camera.autofocus";
1612
1613    /**
1614     * Feature for {@link #getSystemAvailableFeatures} and
1615     * {@link #hasSystemFeature}: The device has at least one camera pointing in
1616     * some direction, or can support an external camera being connected to it.
1617     */
1618    @SdkConstant(SdkConstantType.FEATURE)
1619    public static final String FEATURE_CAMERA_ANY = "android.hardware.camera.any";
1620
1621    /**
1622     * Feature for {@link #getSystemAvailableFeatures} and
1623     * {@link #hasSystemFeature}: The device can support having an external camera connected to it.
1624     * The external camera may not always be connected or available to applications to use.
1625     */
1626    @SdkConstant(SdkConstantType.FEATURE)
1627    public static final String FEATURE_CAMERA_EXTERNAL = "android.hardware.camera.external";
1628
1629    /**
1630     * Feature for {@link #getSystemAvailableFeatures} and
1631     * {@link #hasSystemFeature}: The device's camera supports flash.
1632     */
1633    @SdkConstant(SdkConstantType.FEATURE)
1634    public static final String FEATURE_CAMERA_FLASH = "android.hardware.camera.flash";
1635
1636    /**
1637     * Feature for {@link #getSystemAvailableFeatures} and
1638     * {@link #hasSystemFeature}: The device has a front facing camera.
1639     */
1640    @SdkConstant(SdkConstantType.FEATURE)
1641    public static final String FEATURE_CAMERA_FRONT = "android.hardware.camera.front";
1642
1643    /**
1644     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1645     * of the cameras on the device supports the
1646     * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL full hardware}
1647     * capability level.
1648     */
1649    @SdkConstant(SdkConstantType.FEATURE)
1650    public static final String FEATURE_CAMERA_LEVEL_FULL = "android.hardware.camera.level.full";
1651
1652    /**
1653     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1654     * of the cameras on the device supports the
1655     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR manual sensor}
1656     * capability level.
1657     */
1658    @SdkConstant(SdkConstantType.FEATURE)
1659    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR =
1660            "android.hardware.camera.capability.manual_sensor";
1661
1662    /**
1663     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1664     * of the cameras on the device supports the
1665     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING manual post-processing}
1666     * capability level.
1667     */
1668    @SdkConstant(SdkConstantType.FEATURE)
1669    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING =
1670            "android.hardware.camera.capability.manual_post_processing";
1671
1672    /**
1673     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1674     * of the cameras on the device supports the
1675     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}
1676     * capability level.
1677     */
1678    @SdkConstant(SdkConstantType.FEATURE)
1679    public static final String FEATURE_CAMERA_CAPABILITY_RAW =
1680            "android.hardware.camera.capability.raw";
1681
1682    /**
1683     * Feature for {@link #getSystemAvailableFeatures} and
1684     * {@link #hasSystemFeature}: The device is capable of communicating with
1685     * consumer IR devices.
1686     */
1687    @SdkConstant(SdkConstantType.FEATURE)
1688    public static final String FEATURE_CONSUMER_IR = "android.hardware.consumerir";
1689
1690    /**
1691     * Feature for {@link #getSystemAvailableFeatures} and
1692     * {@link #hasSystemFeature}: The device supports one or more methods of
1693     * reporting current location.
1694     */
1695    @SdkConstant(SdkConstantType.FEATURE)
1696    public static final String FEATURE_LOCATION = "android.hardware.location";
1697
1698    /**
1699     * Feature for {@link #getSystemAvailableFeatures} and
1700     * {@link #hasSystemFeature}: The device has a Global Positioning System
1701     * receiver and can report precise location.
1702     */
1703    @SdkConstant(SdkConstantType.FEATURE)
1704    public static final String FEATURE_LOCATION_GPS = "android.hardware.location.gps";
1705
1706    /**
1707     * Feature for {@link #getSystemAvailableFeatures} and
1708     * {@link #hasSystemFeature}: The device can report location with coarse
1709     * accuracy using a network-based geolocation system.
1710     */
1711    @SdkConstant(SdkConstantType.FEATURE)
1712    public static final String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
1713
1714    /**
1715     * Feature for {@link #getSystemAvailableFeatures} and
1716     * {@link #hasSystemFeature}: The device can record audio via a
1717     * microphone.
1718     */
1719    @SdkConstant(SdkConstantType.FEATURE)
1720    public static final String FEATURE_MICROPHONE = "android.hardware.microphone";
1721
1722    /**
1723     * Feature for {@link #getSystemAvailableFeatures} and
1724     * {@link #hasSystemFeature}: The device can communicate using Near-Field
1725     * Communications (NFC).
1726     */
1727    @SdkConstant(SdkConstantType.FEATURE)
1728    public static final String FEATURE_NFC = "android.hardware.nfc";
1729
1730    /**
1731     * Feature for {@link #getSystemAvailableFeatures} and
1732     * {@link #hasSystemFeature}: The device supports host-
1733     * based NFC card emulation.
1734     *
1735     * TODO remove when depending apps have moved to new constant.
1736     * @hide
1737     * @deprecated
1738     */
1739    @Deprecated
1740    @SdkConstant(SdkConstantType.FEATURE)
1741    public static final String FEATURE_NFC_HCE = "android.hardware.nfc.hce";
1742
1743    /**
1744     * Feature for {@link #getSystemAvailableFeatures} and
1745     * {@link #hasSystemFeature}: The device supports host-
1746     * based NFC card emulation.
1747     */
1748    @SdkConstant(SdkConstantType.FEATURE)
1749    public static final String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
1750
1751    /**
1752     * Feature for {@link #getSystemAvailableFeatures} and
1753     * {@link #hasSystemFeature}: The device supports host-
1754     * based NFC-F card emulation.
1755     */
1756    @SdkConstant(SdkConstantType.FEATURE)
1757    public static final String FEATURE_NFC_HOST_CARD_EMULATION_NFCF = "android.hardware.nfc.hcef";
1758
1759    /**
1760     * Feature for {@link #getSystemAvailableFeatures} and
1761     * {@link #hasSystemFeature}: The device supports the OpenGL ES
1762     * <a href="http://www.khronos.org/registry/gles/extensions/ANDROID/ANDROID_extension_pack_es31a.txt">
1763     * Android Extension Pack</a>.
1764     */
1765    @SdkConstant(SdkConstantType.FEATURE)
1766    public static final String FEATURE_OPENGLES_EXTENSION_PACK = "android.hardware.opengles.aep";
1767
1768    /**
1769     * Feature for {@link #getSystemAvailableFeatures} and
1770     * {@link #hasSystemFeature(String, int)}: If this feature is supported, the Vulkan native API
1771     * will enumerate at least one {@code VkPhysicalDevice}, and the feature version will indicate
1772     * what level of optional hardware features limits it supports.
1773     * <p>
1774     * Level 0 includes the base Vulkan requirements as well as:
1775     * <ul><li>{@code VkPhysicalDeviceFeatures::textureCompressionETC2}</li></ul>
1776     * <p>
1777     * Level 1 additionally includes:
1778     * <ul>
1779     * <li>{@code VkPhysicalDeviceFeatures::fullDrawIndexUint32}</li>
1780     * <li>{@code VkPhysicalDeviceFeatures::imageCubeArray}</li>
1781     * <li>{@code VkPhysicalDeviceFeatures::independentBlend}</li>
1782     * <li>{@code VkPhysicalDeviceFeatures::geometryShader}</li>
1783     * <li>{@code VkPhysicalDeviceFeatures::tessellationShader}</li>
1784     * <li>{@code VkPhysicalDeviceFeatures::sampleRateShading}</li>
1785     * <li>{@code VkPhysicalDeviceFeatures::textureCompressionASTC_LDR}</li>
1786     * <li>{@code VkPhysicalDeviceFeatures::fragmentStoresAndAtomics}</li>
1787     * <li>{@code VkPhysicalDeviceFeatures::shaderImageGatherExtended}</li>
1788     * <li>{@code VkPhysicalDeviceFeatures::shaderUniformBufferArrayDynamicIndexing}</li>
1789     * <li>{@code VkPhysicalDeviceFeatures::shaderSampledImageArrayDynamicIndexing}</li>
1790     * </ul>
1791     */
1792    @SdkConstant(SdkConstantType.FEATURE)
1793    public static final String FEATURE_VULKAN_HARDWARE_LEVEL = "android.hardware.vulkan.level";
1794
1795    /**
1796     * Feature for {@link #getSystemAvailableFeatures} and
1797     * {@link #hasSystemFeature(String, int)}: If this feature is supported, the Vulkan native API
1798     * will enumerate at least one {@code VkPhysicalDevice}, and the feature version will indicate
1799     * what level of optional compute features are supported beyond the Vulkan 1.0 requirements.
1800     * <p>
1801     * Compute level 0 indicates support for:
1802     * <ul>
1803     * <li>Ability to use pointers to buffer data from shaders</li>
1804     * <li>Ability to load/store 16-bit values from buffers</li>
1805     * <li>Ability to control shader floating point rounding mode</li>
1806     * </ul>
1807     */
1808    @SdkConstant(SdkConstantType.FEATURE)
1809    public static final String FEATURE_VULKAN_HARDWARE_COMPUTE = "android.hardware.vulkan.compute";
1810
1811    /**
1812     * Feature for {@link #getSystemAvailableFeatures} and
1813     * {@link #hasSystemFeature(String, int)}: The version of this feature indicates the highest
1814     * {@code VkPhysicalDeviceProperties::apiVersion} supported by the physical devices that support
1815     * the hardware level indicated by {@link #FEATURE_VULKAN_HARDWARE_LEVEL}. The feature version
1816     * uses the same encoding as Vulkan version numbers:
1817     * <ul>
1818     * <li>Major version number in bits 31-22</li>
1819     * <li>Minor version number in bits 21-12</li>
1820     * <li>Patch version number in bits 11-0</li>
1821     * </ul>
1822     */
1823    @SdkConstant(SdkConstantType.FEATURE)
1824    public static final String FEATURE_VULKAN_HARDWARE_VERSION = "android.hardware.vulkan.version";
1825
1826    /**
1827     * Feature for {@link #getSystemAvailableFeatures} and
1828     * {@link #hasSystemFeature}: The device includes an accelerometer.
1829     */
1830    @SdkConstant(SdkConstantType.FEATURE)
1831    public static final String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
1832
1833    /**
1834     * Feature for {@link #getSystemAvailableFeatures} and
1835     * {@link #hasSystemFeature}: The device includes a barometer (air
1836     * pressure sensor.)
1837     */
1838    @SdkConstant(SdkConstantType.FEATURE)
1839    public static final String FEATURE_SENSOR_BAROMETER = "android.hardware.sensor.barometer";
1840
1841    /**
1842     * Feature for {@link #getSystemAvailableFeatures} and
1843     * {@link #hasSystemFeature}: The device includes a magnetometer (compass).
1844     */
1845    @SdkConstant(SdkConstantType.FEATURE)
1846    public static final String FEATURE_SENSOR_COMPASS = "android.hardware.sensor.compass";
1847
1848    /**
1849     * Feature for {@link #getSystemAvailableFeatures} and
1850     * {@link #hasSystemFeature}: The device includes a gyroscope.
1851     */
1852    @SdkConstant(SdkConstantType.FEATURE)
1853    public static final String FEATURE_SENSOR_GYROSCOPE = "android.hardware.sensor.gyroscope";
1854
1855    /**
1856     * Feature for {@link #getSystemAvailableFeatures} and
1857     * {@link #hasSystemFeature}: The device includes a light sensor.
1858     */
1859    @SdkConstant(SdkConstantType.FEATURE)
1860    public static final String FEATURE_SENSOR_LIGHT = "android.hardware.sensor.light";
1861
1862    /**
1863     * Feature for {@link #getSystemAvailableFeatures} and
1864     * {@link #hasSystemFeature}: The device includes a proximity sensor.
1865     */
1866    @SdkConstant(SdkConstantType.FEATURE)
1867    public static final String FEATURE_SENSOR_PROXIMITY = "android.hardware.sensor.proximity";
1868
1869    /**
1870     * Feature for {@link #getSystemAvailableFeatures} and
1871     * {@link #hasSystemFeature}: The device includes a hardware step counter.
1872     */
1873    @SdkConstant(SdkConstantType.FEATURE)
1874    public static final String FEATURE_SENSOR_STEP_COUNTER = "android.hardware.sensor.stepcounter";
1875
1876    /**
1877     * Feature for {@link #getSystemAvailableFeatures} and
1878     * {@link #hasSystemFeature}: The device includes a hardware step detector.
1879     */
1880    @SdkConstant(SdkConstantType.FEATURE)
1881    public static final String FEATURE_SENSOR_STEP_DETECTOR = "android.hardware.sensor.stepdetector";
1882
1883    /**
1884     * Feature for {@link #getSystemAvailableFeatures} and
1885     * {@link #hasSystemFeature}: The device includes a heart rate monitor.
1886     */
1887    @SdkConstant(SdkConstantType.FEATURE)
1888    public static final String FEATURE_SENSOR_HEART_RATE = "android.hardware.sensor.heartrate";
1889
1890    /**
1891     * Feature for {@link #getSystemAvailableFeatures} and
1892     * {@link #hasSystemFeature}: The heart rate sensor on this device is an Electrocardiogram.
1893     */
1894    @SdkConstant(SdkConstantType.FEATURE)
1895    public static final String FEATURE_SENSOR_HEART_RATE_ECG =
1896            "android.hardware.sensor.heartrate.ecg";
1897
1898    /**
1899     * Feature for {@link #getSystemAvailableFeatures} and
1900     * {@link #hasSystemFeature}: The device includes a relative humidity sensor.
1901     */
1902    @SdkConstant(SdkConstantType.FEATURE)
1903    public static final String FEATURE_SENSOR_RELATIVE_HUMIDITY =
1904            "android.hardware.sensor.relative_humidity";
1905
1906    /**
1907     * Feature for {@link #getSystemAvailableFeatures} and
1908     * {@link #hasSystemFeature}: The device includes an ambient temperature sensor.
1909     */
1910    @SdkConstant(SdkConstantType.FEATURE)
1911    public static final String FEATURE_SENSOR_AMBIENT_TEMPERATURE =
1912            "android.hardware.sensor.ambient_temperature";
1913
1914    /**
1915     * Feature for {@link #getSystemAvailableFeatures} and
1916     * {@link #hasSystemFeature}: The device supports high fidelity sensor processing
1917     * capabilities.
1918     */
1919    @SdkConstant(SdkConstantType.FEATURE)
1920    public static final String FEATURE_HIFI_SENSORS =
1921            "android.hardware.sensor.hifi_sensors";
1922
1923    /**
1924     * Feature for {@link #getSystemAvailableFeatures} and
1925     * {@link #hasSystemFeature}: The device has a telephony radio with data
1926     * communication support.
1927     */
1928    @SdkConstant(SdkConstantType.FEATURE)
1929    public static final String FEATURE_TELEPHONY = "android.hardware.telephony";
1930
1931    /**
1932     * Feature for {@link #getSystemAvailableFeatures} and
1933     * {@link #hasSystemFeature}: The device has a CDMA telephony stack.
1934     */
1935    @SdkConstant(SdkConstantType.FEATURE)
1936    public static final String FEATURE_TELEPHONY_CDMA = "android.hardware.telephony.cdma";
1937
1938    /**
1939     * Feature for {@link #getSystemAvailableFeatures} and
1940     * {@link #hasSystemFeature}: The device has a GSM telephony stack.
1941     */
1942    @SdkConstant(SdkConstantType.FEATURE)
1943    public static final String FEATURE_TELEPHONY_GSM = "android.hardware.telephony.gsm";
1944
1945    /**
1946     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1947     * The device supports telephony carrier restriction mechanism.
1948     *
1949     * <p>Devices declaring this feature must have an implementation of the
1950     * {@link android.telephony.TelephonyManager#getAllowedCarriers} and
1951     * {@link android.telephony.TelephonyManager#setAllowedCarriers}.
1952     * @hide
1953     */
1954    @SystemApi
1955    @SdkConstant(SdkConstantType.FEATURE)
1956    public static final String FEATURE_TELEPHONY_CARRIERLOCK =
1957            "android.hardware.telephony.carrierlock";
1958
1959    /**
1960     * Feature for {@link #getSystemAvailableFeatures} and
1961     * {@link #hasSystemFeature}: The device supports connecting to USB devices
1962     * as the USB host.
1963     */
1964    @SdkConstant(SdkConstantType.FEATURE)
1965    public static final String FEATURE_USB_HOST = "android.hardware.usb.host";
1966
1967    /**
1968     * Feature for {@link #getSystemAvailableFeatures} and
1969     * {@link #hasSystemFeature}: The device supports connecting to USB accessories.
1970     */
1971    @SdkConstant(SdkConstantType.FEATURE)
1972    public static final String FEATURE_USB_ACCESSORY = "android.hardware.usb.accessory";
1973
1974    /**
1975     * Feature for {@link #getSystemAvailableFeatures} and
1976     * {@link #hasSystemFeature}: The SIP API is enabled on the device.
1977     */
1978    @SdkConstant(SdkConstantType.FEATURE)
1979    public static final String FEATURE_SIP = "android.software.sip";
1980
1981    /**
1982     * Feature for {@link #getSystemAvailableFeatures} and
1983     * {@link #hasSystemFeature}: The device supports SIP-based VOIP.
1984     */
1985    @SdkConstant(SdkConstantType.FEATURE)
1986    public static final String FEATURE_SIP_VOIP = "android.software.sip.voip";
1987
1988    /**
1989     * Feature for {@link #getSystemAvailableFeatures} and
1990     * {@link #hasSystemFeature}: The Connection Service API is enabled on the device.
1991     */
1992    @SdkConstant(SdkConstantType.FEATURE)
1993    public static final String FEATURE_CONNECTION_SERVICE = "android.software.connectionservice";
1994
1995    /**
1996     * Feature for {@link #getSystemAvailableFeatures} and
1997     * {@link #hasSystemFeature}: The device's display has a touch screen.
1998     */
1999    @SdkConstant(SdkConstantType.FEATURE)
2000    public static final String FEATURE_TOUCHSCREEN = "android.hardware.touchscreen";
2001
2002    /**
2003     * Feature for {@link #getSystemAvailableFeatures} and
2004     * {@link #hasSystemFeature}: The device's touch screen supports
2005     * multitouch sufficient for basic two-finger gesture detection.
2006     */
2007    @SdkConstant(SdkConstantType.FEATURE)
2008    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH = "android.hardware.touchscreen.multitouch";
2009
2010    /**
2011     * Feature for {@link #getSystemAvailableFeatures} and
2012     * {@link #hasSystemFeature}: The device's touch screen is capable of
2013     * tracking two or more fingers fully independently.
2014     */
2015    @SdkConstant(SdkConstantType.FEATURE)
2016    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT = "android.hardware.touchscreen.multitouch.distinct";
2017
2018    /**
2019     * Feature for {@link #getSystemAvailableFeatures} and
2020     * {@link #hasSystemFeature}: The device's touch screen is capable of
2021     * tracking a full hand of fingers fully independently -- that is, 5 or
2022     * more simultaneous independent pointers.
2023     */
2024    @SdkConstant(SdkConstantType.FEATURE)
2025    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND = "android.hardware.touchscreen.multitouch.jazzhand";
2026
2027    /**
2028     * Feature for {@link #getSystemAvailableFeatures} and
2029     * {@link #hasSystemFeature}: The device does not have a touch screen, but
2030     * does support touch emulation for basic events. For instance, the
2031     * device might use a mouse or remote control to drive a cursor, and
2032     * emulate basic touch pointer events like down, up, drag, etc. All
2033     * devices that support android.hardware.touchscreen or a sub-feature are
2034     * presumed to also support faketouch.
2035     */
2036    @SdkConstant(SdkConstantType.FEATURE)
2037    public static final String FEATURE_FAKETOUCH = "android.hardware.faketouch";
2038
2039    /**
2040     * Feature for {@link #getSystemAvailableFeatures} and
2041     * {@link #hasSystemFeature}: The device does not have a touch screen, but
2042     * does support touch emulation for basic events that supports distinct
2043     * tracking of two or more fingers.  This is an extension of
2044     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
2045     * that unlike a distinct multitouch screen as defined by
2046     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT}, these kinds of input
2047     * devices will not actually provide full two-finger gestures since the
2048     * input is being transformed to cursor movement on the screen.  That is,
2049     * single finger gestures will move a cursor; two-finger swipes will
2050     * result in single-finger touch events; other two-finger gestures will
2051     * result in the corresponding two-finger touch event.
2052     */
2053    @SdkConstant(SdkConstantType.FEATURE)
2054    public static final String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
2055
2056    /**
2057     * Feature for {@link #getSystemAvailableFeatures} and
2058     * {@link #hasSystemFeature}: The device does not have a touch screen, but
2059     * does support touch emulation for basic events that supports tracking
2060     * a hand of fingers (5 or more fingers) fully independently.
2061     * This is an extension of
2062     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
2063     * that unlike a multitouch screen as defined by
2064     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND}, not all two finger
2065     * gestures can be detected due to the limitations described for
2066     * {@link #FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT}.
2067     */
2068    @SdkConstant(SdkConstantType.FEATURE)
2069    public static final String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
2070
2071    /**
2072     * Feature for {@link #getSystemAvailableFeatures} and
2073     * {@link #hasSystemFeature}: The device has biometric hardware to detect a fingerprint.
2074      */
2075    @SdkConstant(SdkConstantType.FEATURE)
2076    public static final String FEATURE_FINGERPRINT = "android.hardware.fingerprint";
2077
2078    /**
2079     * Feature for {@link #getSystemAvailableFeatures} and
2080     * {@link #hasSystemFeature}: The device supports portrait orientation
2081     * screens.  For backwards compatibility, you can assume that if neither
2082     * this nor {@link #FEATURE_SCREEN_LANDSCAPE} is set then the device supports
2083     * both portrait and landscape.
2084     */
2085    @SdkConstant(SdkConstantType.FEATURE)
2086    public static final String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
2087
2088    /**
2089     * Feature for {@link #getSystemAvailableFeatures} and
2090     * {@link #hasSystemFeature}: The device supports landscape orientation
2091     * screens.  For backwards compatibility, you can assume that if neither
2092     * this nor {@link #FEATURE_SCREEN_PORTRAIT} is set then the device supports
2093     * both portrait and landscape.
2094     */
2095    @SdkConstant(SdkConstantType.FEATURE)
2096    public static final String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
2097
2098    /**
2099     * Feature for {@link #getSystemAvailableFeatures} and
2100     * {@link #hasSystemFeature}: The device supports live wallpapers.
2101     */
2102    @SdkConstant(SdkConstantType.FEATURE)
2103    public static final String FEATURE_LIVE_WALLPAPER = "android.software.live_wallpaper";
2104    /**
2105     * Feature for {@link #getSystemAvailableFeatures} and
2106     * {@link #hasSystemFeature}: The device supports app widgets.
2107     */
2108    @SdkConstant(SdkConstantType.FEATURE)
2109    public static final String FEATURE_APP_WIDGETS = "android.software.app_widgets";
2110
2111    /**
2112     * @hide
2113     * Feature for {@link #getSystemAvailableFeatures} and
2114     * {@link #hasSystemFeature}: The device supports
2115     * {@link android.service.voice.VoiceInteractionService} and
2116     * {@link android.app.VoiceInteractor}.
2117     */
2118    @SdkConstant(SdkConstantType.FEATURE)
2119    public static final String FEATURE_VOICE_RECOGNIZERS = "android.software.voice_recognizers";
2120
2121
2122    /**
2123     * Feature for {@link #getSystemAvailableFeatures} and
2124     * {@link #hasSystemFeature}: The device supports a home screen that is replaceable
2125     * by third party applications.
2126     */
2127    @SdkConstant(SdkConstantType.FEATURE)
2128    public static final String FEATURE_HOME_SCREEN = "android.software.home_screen";
2129
2130    /**
2131     * Feature for {@link #getSystemAvailableFeatures} and
2132     * {@link #hasSystemFeature}: The device supports adding new input methods implemented
2133     * with the {@link android.inputmethodservice.InputMethodService} API.
2134     */
2135    @SdkConstant(SdkConstantType.FEATURE)
2136    public static final String FEATURE_INPUT_METHODS = "android.software.input_methods";
2137
2138    /**
2139     * Feature for {@link #getSystemAvailableFeatures} and
2140     * {@link #hasSystemFeature}: The device supports device policy enforcement via device admins.
2141     */
2142    @SdkConstant(SdkConstantType.FEATURE)
2143    public static final String FEATURE_DEVICE_ADMIN = "android.software.device_admin";
2144
2145    /**
2146     * Feature for {@link #getSystemAvailableFeatures} and
2147     * {@link #hasSystemFeature}: The device supports leanback UI. This is
2148     * typically used in a living room television experience, but is a software
2149     * feature unlike {@link #FEATURE_TELEVISION}. Devices running with this
2150     * feature will use resources associated with the "television" UI mode.
2151     */
2152    @SdkConstant(SdkConstantType.FEATURE)
2153    public static final String FEATURE_LEANBACK = "android.software.leanback";
2154
2155    /**
2156     * Feature for {@link #getSystemAvailableFeatures} and
2157     * {@link #hasSystemFeature}: The device supports only leanback UI. Only
2158     * applications designed for this experience should be run, though this is
2159     * not enforced by the system.
2160     * @hide
2161     */
2162    @SdkConstant(SdkConstantType.FEATURE)
2163    public static final String FEATURE_LEANBACK_ONLY = "android.software.leanback_only";
2164
2165    /**
2166     * Feature for {@link #getSystemAvailableFeatures} and
2167     * {@link #hasSystemFeature}: The device supports live TV and can display
2168     * contents from TV inputs implemented with the
2169     * {@link android.media.tv.TvInputService} API.
2170     */
2171    @SdkConstant(SdkConstantType.FEATURE)
2172    public static final String FEATURE_LIVE_TV = "android.software.live_tv";
2173
2174    /**
2175     * Feature for {@link #getSystemAvailableFeatures} and
2176     * {@link #hasSystemFeature}: The device supports WiFi (802.11) networking.
2177     */
2178    @SdkConstant(SdkConstantType.FEATURE)
2179    public static final String FEATURE_WIFI = "android.hardware.wifi";
2180
2181    /**
2182     * Feature for {@link #getSystemAvailableFeatures} and
2183     * {@link #hasSystemFeature}: The device supports Wi-Fi Direct networking.
2184     */
2185    @SdkConstant(SdkConstantType.FEATURE)
2186    public static final String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
2187
2188    /**
2189     * Feature for {@link #getSystemAvailableFeatures} and
2190     * {@link #hasSystemFeature}: The device supports Wi-Fi Aware.
2191     */
2192    @SdkConstant(SdkConstantType.FEATURE)
2193    public static final String FEATURE_WIFI_AWARE = "android.hardware.wifi.aware";
2194
2195    /**
2196     * Feature for {@link #getSystemAvailableFeatures} and
2197     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
2198     * on a vehicle headunit. A headunit here is defined to be inside a
2199     * vehicle that may or may not be moving. A headunit uses either a
2200     * primary display in the center console and/or additional displays in
2201     * the instrument cluster or elsewhere in the vehicle. Headunit display(s)
2202     * have limited size and resolution. The user will likely be focused on
2203     * driving so limiting driver distraction is a primary concern. User input
2204     * can be a variety of hard buttons, touch, rotary controllers and even mouse-
2205     * like interfaces.
2206     */
2207    @SdkConstant(SdkConstantType.FEATURE)
2208    public static final String FEATURE_AUTOMOTIVE = "android.hardware.type.automotive";
2209
2210    /**
2211     * Feature for {@link #getSystemAvailableFeatures} and
2212     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
2213     * on a television.  Television here is defined to be a typical living
2214     * room television experience: displayed on a big screen, where the user
2215     * is sitting far away from it, and the dominant form of input will be
2216     * something like a DPAD, not through touch or mouse.
2217     * @deprecated use {@link #FEATURE_LEANBACK} instead.
2218     */
2219    @Deprecated
2220    @SdkConstant(SdkConstantType.FEATURE)
2221    public static final String FEATURE_TELEVISION = "android.hardware.type.television";
2222
2223    /**
2224     * Feature for {@link #getSystemAvailableFeatures} and
2225     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
2226     * on a watch. A watch here is defined to be a device worn on the body, perhaps on
2227     * the wrist. The user is very close when interacting with the device.
2228     */
2229    @SdkConstant(SdkConstantType.FEATURE)
2230    public static final String FEATURE_WATCH = "android.hardware.type.watch";
2231
2232    /**
2233     * Feature for {@link #getSystemAvailableFeatures} and
2234     * {@link #hasSystemFeature}: This is a device for IoT and may not have an UI. An embedded
2235     * device is defined as a full stack Android device with or without a display and no
2236     * user-installable apps.
2237     */
2238    @SdkConstant(SdkConstantType.FEATURE)
2239    public static final String FEATURE_EMBEDDED = "android.hardware.type.embedded";
2240
2241    /**
2242     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2243     * The device supports printing.
2244     */
2245    @SdkConstant(SdkConstantType.FEATURE)
2246    public static final String FEATURE_PRINTING = "android.software.print";
2247
2248    /**
2249     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2250     * The device supports {@link android.companion.CompanionDeviceManager#associate associating}
2251     * with devices via {@link android.companion.CompanionDeviceManager}.
2252     */
2253    @SdkConstant(SdkConstantType.FEATURE)
2254    public static final String FEATURE_COMPANION_DEVICE_SETUP
2255            = "android.software.companion_device_setup";
2256
2257    /**
2258     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2259     * The device can perform backup and restore operations on installed applications.
2260     */
2261    @SdkConstant(SdkConstantType.FEATURE)
2262    public static final String FEATURE_BACKUP = "android.software.backup";
2263
2264    /**
2265     * Feature for {@link #getSystemAvailableFeatures} and
2266     * {@link #hasSystemFeature}: The device supports freeform window management.
2267     * Windows have title bars and can be moved and resized.
2268     */
2269    // If this feature is present, you also need to set
2270    // com.android.internal.R.config_freeformWindowManagement to true in your configuration overlay.
2271    @SdkConstant(SdkConstantType.FEATURE)
2272    public static final String FEATURE_FREEFORM_WINDOW_MANAGEMENT
2273            = "android.software.freeform_window_management";
2274
2275    /**
2276     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2277     * The device supports picture-in-picture multi-window mode.
2278     */
2279    @SdkConstant(SdkConstantType.FEATURE)
2280    public static final String FEATURE_PICTURE_IN_PICTURE = "android.software.picture_in_picture";
2281
2282    /**
2283     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2284     * The device supports creating secondary users and managed profiles via
2285     * {@link DevicePolicyManager}.
2286     */
2287    @SdkConstant(SdkConstantType.FEATURE)
2288    public static final String FEATURE_MANAGED_USERS = "android.software.managed_users";
2289
2290    /**
2291     * @hide
2292     * TODO: Remove after dependencies updated b/17392243
2293     */
2294    public static final String FEATURE_MANAGED_PROFILES = "android.software.managed_users";
2295
2296    /**
2297     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2298     * The device supports verified boot.
2299     */
2300    @SdkConstant(SdkConstantType.FEATURE)
2301    public static final String FEATURE_VERIFIED_BOOT = "android.software.verified_boot";
2302
2303    /**
2304     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2305     * The device supports secure removal of users. When a user is deleted the data associated
2306     * with that user is securely deleted and no longer available.
2307     */
2308    @SdkConstant(SdkConstantType.FEATURE)
2309    public static final String FEATURE_SECURELY_REMOVES_USERS
2310            = "android.software.securely_removes_users";
2311
2312    /** {@hide} */
2313    @SdkConstant(SdkConstantType.FEATURE)
2314    public static final String FEATURE_FILE_BASED_ENCRYPTION
2315            = "android.software.file_based_encryption";
2316
2317    /**
2318     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2319     * The device has a full implementation of the android.webkit.* APIs. Devices
2320     * lacking this feature will not have a functioning WebView implementation.
2321     */
2322    @SdkConstant(SdkConstantType.FEATURE)
2323    public static final String FEATURE_WEBVIEW = "android.software.webview";
2324
2325    /**
2326     * Feature for {@link #getSystemAvailableFeatures} and
2327     * {@link #hasSystemFeature}: This device supports ethernet.
2328     */
2329    @SdkConstant(SdkConstantType.FEATURE)
2330    public static final String FEATURE_ETHERNET = "android.hardware.ethernet";
2331
2332    /**
2333     * Feature for {@link #getSystemAvailableFeatures} and
2334     * {@link #hasSystemFeature}: This device supports HDMI-CEC.
2335     * @hide
2336     */
2337    @SdkConstant(SdkConstantType.FEATURE)
2338    public static final String FEATURE_HDMI_CEC = "android.hardware.hdmi.cec";
2339
2340    /**
2341     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2342     * The device has all of the inputs necessary to be considered a compatible game controller, or
2343     * includes a compatible game controller in the box.
2344     */
2345    @SdkConstant(SdkConstantType.FEATURE)
2346    public static final String FEATURE_GAMEPAD = "android.hardware.gamepad";
2347
2348    /**
2349     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2350     * The device has a full implementation of the android.media.midi.* APIs.
2351     */
2352    @SdkConstant(SdkConstantType.FEATURE)
2353    public static final String FEATURE_MIDI = "android.software.midi";
2354
2355    /**
2356     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2357     * The device implements an optimized mode for virtual reality (VR) applications that handles
2358     * stereoscopic rendering of notifications, and disables most monocular system UI components
2359     * while a VR application has user focus.
2360     * Devices declaring this feature must include an application implementing a
2361     * {@link android.service.vr.VrListenerService} that can be targeted by VR applications via
2362     * {@link android.app.Activity#setVrModeEnabled}.
2363     */
2364    @SdkConstant(SdkConstantType.FEATURE)
2365    public static final String FEATURE_VR_MODE = "android.software.vr.mode";
2366
2367    /**
2368     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2369     * The device implements {@link #FEATURE_VR_MODE} but additionally meets extra CDD requirements
2370     * to provide a high-quality VR experience.  In general, devices declaring this feature will
2371     * additionally:
2372     * <ul>
2373     *   <li>Deliver consistent performance at a high framerate over an extended period of time
2374     *   for typical VR application CPU/GPU workloads with a minimal number of frame drops for VR
2375     *   applications that have called
2376     *   {@link android.view.Window#setSustainedPerformanceMode}.</li>
2377     *   <li>Implement {@link #FEATURE_HIFI_SENSORS} and have a low sensor latency.</li>
2378     *   <li>Include optimizations to lower display persistence while running VR applications.</li>
2379     *   <li>Implement an optimized render path to minimize latency to draw to the device's main
2380     *   display.</li>
2381     *   <li>Include the following EGL extensions: EGL_ANDROID_create_native_client_buffer,
2382     *   EGL_ANDROID_front_buffer_auto_refresh, EGL_EXT_protected_content,
2383     *   EGL_KHR_mutable_render_buffer, EGL_KHR_reusable_sync, and EGL_KHR_wait_sync.</li>
2384     *   <li>Provide at least one CPU core that is reserved for use solely by the top, foreground
2385     *   VR application process for critical render threads while such an application is
2386     *   running.</li>
2387     * </ul>
2388     */
2389    @SdkConstant(SdkConstantType.FEATURE)
2390    public static final String FEATURE_VR_MODE_HIGH_PERFORMANCE
2391            = "android.hardware.vr.high_performance";
2392
2393    /**
2394     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
2395     * The device implements headtracking suitable for a VR device.
2396     */
2397    @SdkConstant(SdkConstantType.FEATURE)
2398    public static final String FEATURE_VR_HEADTRACKING = "android.hardware.vr.headtracking";
2399
2400    /**
2401     * Action to external storage service to clean out removed apps.
2402     * @hide
2403     */
2404    public static final String ACTION_CLEAN_EXTERNAL_STORAGE
2405            = "android.content.pm.CLEAN_EXTERNAL_STORAGE";
2406
2407    /**
2408     * Extra field name for the URI to a verification file. Passed to a package
2409     * verifier.
2410     *
2411     * @hide
2412     */
2413    public static final String EXTRA_VERIFICATION_URI = "android.content.pm.extra.VERIFICATION_URI";
2414
2415    /**
2416     * Extra field name for the ID of a package pending verification. Passed to
2417     * a package verifier and is used to call back to
2418     * {@link PackageManager#verifyPendingInstall(int, int)}
2419     */
2420    public static final String EXTRA_VERIFICATION_ID = "android.content.pm.extra.VERIFICATION_ID";
2421
2422    /**
2423     * Extra field name for the package identifier which is trying to install
2424     * the package.
2425     *
2426     * @hide
2427     */
2428    public static final String EXTRA_VERIFICATION_INSTALLER_PACKAGE
2429            = "android.content.pm.extra.VERIFICATION_INSTALLER_PACKAGE";
2430
2431    /**
2432     * Extra field name for the requested install flags for a package pending
2433     * verification. Passed to a package verifier.
2434     *
2435     * @hide
2436     */
2437    public static final String EXTRA_VERIFICATION_INSTALL_FLAGS
2438            = "android.content.pm.extra.VERIFICATION_INSTALL_FLAGS";
2439
2440    /**
2441     * Extra field name for the uid of who is requesting to install
2442     * the package.
2443     *
2444     * @hide
2445     */
2446    public static final String EXTRA_VERIFICATION_INSTALLER_UID
2447            = "android.content.pm.extra.VERIFICATION_INSTALLER_UID";
2448
2449    /**
2450     * Extra field name for the package name of a package pending verification.
2451     *
2452     * @hide
2453     */
2454    public static final String EXTRA_VERIFICATION_PACKAGE_NAME
2455            = "android.content.pm.extra.VERIFICATION_PACKAGE_NAME";
2456    /**
2457     * Extra field name for the result of a verification, either
2458     * {@link #VERIFICATION_ALLOW}, or {@link #VERIFICATION_REJECT}.
2459     * Passed to package verifiers after a package is verified.
2460     */
2461    public static final String EXTRA_VERIFICATION_RESULT
2462            = "android.content.pm.extra.VERIFICATION_RESULT";
2463
2464    /**
2465     * Extra field name for the version code of a package pending verification.
2466     *
2467     * @hide
2468     */
2469    public static final String EXTRA_VERIFICATION_VERSION_CODE
2470            = "android.content.pm.extra.VERIFICATION_VERSION_CODE";
2471
2472    /**
2473     * Extra field name for the ID of a intent filter pending verification.
2474     * Passed to an intent filter verifier and is used to call back to
2475     * {@link #verifyIntentFilter}
2476     *
2477     * @hide
2478     */
2479    public static final String EXTRA_INTENT_FILTER_VERIFICATION_ID
2480            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_ID";
2481
2482    /**
2483     * Extra field name for the scheme used for an intent filter pending verification. Passed to
2484     * an intent filter verifier and is used to construct the URI to verify against.
2485     *
2486     * Usually this is "https"
2487     *
2488     * @hide
2489     */
2490    public static final String EXTRA_INTENT_FILTER_VERIFICATION_URI_SCHEME
2491            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_URI_SCHEME";
2492
2493    /**
2494     * Extra field name for the host names to be used for an intent filter pending verification.
2495     * Passed to an intent filter verifier and is used to construct the URI to verify the
2496     * intent filter.
2497     *
2498     * This is a space delimited list of hosts.
2499     *
2500     * @hide
2501     */
2502    public static final String EXTRA_INTENT_FILTER_VERIFICATION_HOSTS
2503            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_HOSTS";
2504
2505    /**
2506     * Extra field name for the package name to be used for an intent filter pending verification.
2507     * Passed to an intent filter verifier and is used to check the verification responses coming
2508     * from the hosts. Each host response will need to include the package name of APK containing
2509     * the intent filter.
2510     *
2511     * @hide
2512     */
2513    public static final String EXTRA_INTENT_FILTER_VERIFICATION_PACKAGE_NAME
2514            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_PACKAGE_NAME";
2515
2516    /**
2517     * The action used to request that the user approve a permission request
2518     * from the application.
2519     *
2520     * @hide
2521     */
2522    @SystemApi
2523    public static final String ACTION_REQUEST_PERMISSIONS =
2524            "android.content.pm.action.REQUEST_PERMISSIONS";
2525
2526    /**
2527     * The names of the requested permissions.
2528     * <p>
2529     * <strong>Type:</strong> String[]
2530     * </p>
2531     *
2532     * @hide
2533     */
2534    @SystemApi
2535    public static final String EXTRA_REQUEST_PERMISSIONS_NAMES =
2536            "android.content.pm.extra.REQUEST_PERMISSIONS_NAMES";
2537
2538    /**
2539     * The results from the permissions request.
2540     * <p>
2541     * <strong>Type:</strong> int[] of #PermissionResult
2542     * </p>
2543     *
2544     * @hide
2545     */
2546    @SystemApi
2547    public static final String EXTRA_REQUEST_PERMISSIONS_RESULTS
2548            = "android.content.pm.extra.REQUEST_PERMISSIONS_RESULTS";
2549
2550    /**
2551     * String extra for {@link PackageInstallObserver} in the 'extras' Bundle in case of
2552     * {@link #INSTALL_FAILED_DUPLICATE_PERMISSION}.  This extra names the package which provides
2553     * the existing definition for the permission.
2554     * @hide
2555     */
2556    public static final String EXTRA_FAILURE_EXISTING_PACKAGE
2557            = "android.content.pm.extra.FAILURE_EXISTING_PACKAGE";
2558
2559    /**
2560     * String extra for {@link PackageInstallObserver} in the 'extras' Bundle in case of
2561     * {@link #INSTALL_FAILED_DUPLICATE_PERMISSION}.  This extra names the permission that is
2562     * being redundantly defined by the package being installed.
2563     * @hide
2564     */
2565    public static final String EXTRA_FAILURE_EXISTING_PERMISSION
2566            = "android.content.pm.extra.FAILURE_EXISTING_PERMISSION";
2567
2568   /**
2569    * Permission flag: The permission is set in its current state
2570    * by the user and apps can still request it at runtime.
2571    *
2572    * @hide
2573    */
2574    @SystemApi
2575    public static final int FLAG_PERMISSION_USER_SET = 1 << 0;
2576
2577    /**
2578     * Permission flag: The permission is set in its current state
2579     * by the user and it is fixed, i.e. apps can no longer request
2580     * this permission.
2581     *
2582     * @hide
2583     */
2584    @SystemApi
2585    public static final int FLAG_PERMISSION_USER_FIXED =  1 << 1;
2586
2587    /**
2588     * Permission flag: The permission is set in its current state
2589     * by device policy and neither apps nor the user can change
2590     * its state.
2591     *
2592     * @hide
2593     */
2594    @SystemApi
2595    public static final int FLAG_PERMISSION_POLICY_FIXED =  1 << 2;
2596
2597    /**
2598     * Permission flag: The permission is set in a granted state but
2599     * access to resources it guards is restricted by other means to
2600     * enable revoking a permission on legacy apps that do not support
2601     * runtime permissions. If this permission is upgraded to runtime
2602     * because the app was updated to support runtime permissions, the
2603     * the permission will be revoked in the upgrade process.
2604     *
2605     * @hide
2606     */
2607    @SystemApi
2608    public static final int FLAG_PERMISSION_REVOKE_ON_UPGRADE =  1 << 3;
2609
2610    /**
2611     * Permission flag: The permission is set in its current state
2612     * because the app is a component that is a part of the system.
2613     *
2614     * @hide
2615     */
2616    @SystemApi
2617    public static final int FLAG_PERMISSION_SYSTEM_FIXED =  1 << 4;
2618
2619    /**
2620     * Permission flag: The permission is granted by default because it
2621     * enables app functionality that is expected to work out-of-the-box
2622     * for providing a smooth user experience. For example, the phone app
2623     * is expected to have the phone permission.
2624     *
2625     * @hide
2626     */
2627    @SystemApi
2628    public static final int FLAG_PERMISSION_GRANTED_BY_DEFAULT =  1 << 5;
2629
2630    /**
2631     * Permission flag: The permission has to be reviewed before any of
2632     * the app components can run.
2633     *
2634     * @hide
2635     */
2636    @SystemApi
2637    public static final int FLAG_PERMISSION_REVIEW_REQUIRED =  1 << 6;
2638
2639    /**
2640     * Mask for all permission flags.
2641     *
2642     * @hide
2643     */
2644    @SystemApi
2645    public static final int MASK_PERMISSION_FLAGS = 0xFF;
2646
2647    /**
2648     * This is a library that contains components apps can invoke. For
2649     * example, a services for apps to bind to, or standard chooser UI,
2650     * etc. This library is versioned and backwards compatible. Clients
2651     * should check its version via {@link android.ext.services.Version
2652     * #getVersionCode()} and avoid calling APIs added in later versions.
2653     *
2654     * @hide
2655     */
2656    public static final String SYSTEM_SHARED_LIBRARY_SERVICES = "android.ext.services";
2657
2658    /**
2659     * This is a library that contains components apps can dynamically
2660     * load. For example, new widgets, helper classes, etc. This library
2661     * is versioned and backwards compatible. Clients should check its
2662     * version via {@link android.ext.shared.Version#getVersionCode()}
2663     * and avoid calling APIs added in later versions.
2664     *
2665     * @hide
2666     */
2667    public static final String SYSTEM_SHARED_LIBRARY_SHARED = "android.ext.shared";
2668
2669    /**
2670     * Used when starting a process for an Activity.
2671     *
2672     * @hide
2673     */
2674    public static final int NOTIFY_PACKAGE_USE_ACTIVITY = 0;
2675
2676    /**
2677     * Used when starting a process for a Service.
2678     *
2679     * @hide
2680     */
2681    public static final int NOTIFY_PACKAGE_USE_SERVICE = 1;
2682
2683    /**
2684     * Used when moving a Service to the foreground.
2685     *
2686     * @hide
2687     */
2688    public static final int NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE = 2;
2689
2690    /**
2691     * Used when starting a process for a BroadcastReceiver.
2692     *
2693     * @hide
2694     */
2695    public static final int NOTIFY_PACKAGE_USE_BROADCAST_RECEIVER = 3;
2696
2697    /**
2698     * Used when starting a process for a ContentProvider.
2699     *
2700     * @hide
2701     */
2702    public static final int NOTIFY_PACKAGE_USE_CONTENT_PROVIDER = 4;
2703
2704    /**
2705     * Used when starting a process for a BroadcastReceiver.
2706     *
2707     * @hide
2708     */
2709    public static final int NOTIFY_PACKAGE_USE_BACKUP = 5;
2710
2711    /**
2712     * Used with Context.getClassLoader() across Android packages.
2713     *
2714     * @hide
2715     */
2716    public static final int NOTIFY_PACKAGE_USE_CROSS_PACKAGE = 6;
2717
2718    /**
2719     * Used when starting a package within a process for Instrumentation.
2720     *
2721     * @hide
2722     */
2723    public static final int NOTIFY_PACKAGE_USE_INSTRUMENTATION = 7;
2724
2725    /**
2726     * Total number of usage reasons.
2727     *
2728     * @hide
2729     */
2730    public static final int NOTIFY_PACKAGE_USE_REASONS_COUNT = 8;
2731
2732    /**
2733     * Constant for specifying the highest installed package version code.
2734     */
2735    public static final int VERSION_CODE_HIGHEST = -1;
2736
2737    /**
2738     * Retrieve overall information about an application package that is
2739     * installed on the system.
2740     *
2741     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2742     *         desired package.
2743     * @param flags Additional option flags. Use any combination of
2744     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
2745     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
2746     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
2747     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
2748     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
2749     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
2750     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
2751     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
2752     *         {@link #MATCH_UNINSTALLED_PACKAGES}
2753     *         to modify the data returned.
2754     *
2755     * @return A PackageInfo object containing information about the
2756     *         package. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set and if the
2757     *         package is not found in the list of installed applications, the
2758     *         package information is retrieved from the list of uninstalled
2759     *         applications (which includes installed applications as well as
2760     *         applications with data directory i.e. applications which had been
2761     *         deleted with {@code DONT_DELETE_DATA} flag set).
2762     * @throws NameNotFoundException if a package with the given name cannot be
2763     *             found on the system.
2764     * @see #GET_ACTIVITIES
2765     * @see #GET_CONFIGURATIONS
2766     * @see #GET_GIDS
2767     * @see #GET_INSTRUMENTATION
2768     * @see #GET_INTENT_FILTERS
2769     * @see #GET_META_DATA
2770     * @see #GET_PERMISSIONS
2771     * @see #GET_PROVIDERS
2772     * @see #GET_RECEIVERS
2773     * @see #GET_SERVICES
2774     * @see #GET_SHARED_LIBRARY_FILES
2775     * @see #GET_SIGNATURES
2776     * @see #GET_URI_PERMISSION_PATTERNS
2777     * @see #MATCH_DISABLED_COMPONENTS
2778     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
2779     * @see #MATCH_UNINSTALLED_PACKAGES
2780     */
2781    public abstract PackageInfo getPackageInfo(String packageName, @PackageInfoFlags int flags)
2782            throws NameNotFoundException;
2783
2784    /**
2785     * Retrieve overall information about an application package that is
2786     * installed on the system. This method can be used for retrieving
2787     * information about packages for which multiple versions can be
2788     * installed at the time. Currently only packages hosting static shared
2789     * libraries can have multiple installed versions. The method can also
2790     * be used to get info for a package that has a single version installed
2791     * by passing {@link #VERSION_CODE_HIGHEST} in the {@link VersionedPackage}
2792     * constructor.
2793     *
2794     * @param versionedPackage The versioned packages for which to query.
2795     * @param flags Additional option flags. Use any combination of
2796     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
2797     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
2798     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
2799     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
2800     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
2801     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
2802     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
2803     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
2804     *         {@link #MATCH_UNINSTALLED_PACKAGES}
2805     *         to modify the data returned.
2806     *
2807     * @return A PackageInfo object containing information about the
2808     *         package. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set and if the
2809     *         package is not found in the list of installed applications, the
2810     *         package information is retrieved from the list of uninstalled
2811     *         applications (which includes installed applications as well as
2812     *         applications with data directory i.e. applications which had been
2813     *         deleted with {@code DONT_DELETE_DATA} flag set).
2814     * @throws NameNotFoundException if a package with the given name cannot be
2815     *             found on the system.
2816     * @see #GET_ACTIVITIES
2817     * @see #GET_CONFIGURATIONS
2818     * @see #GET_GIDS
2819     * @see #GET_INSTRUMENTATION
2820     * @see #GET_INTENT_FILTERS
2821     * @see #GET_META_DATA
2822     * @see #GET_PERMISSIONS
2823     * @see #GET_PROVIDERS
2824     * @see #GET_RECEIVERS
2825     * @see #GET_SERVICES
2826     * @see #GET_SHARED_LIBRARY_FILES
2827     * @see #GET_SIGNATURES
2828     * @see #GET_URI_PERMISSION_PATTERNS
2829     * @see #MATCH_DISABLED_COMPONENTS
2830     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
2831     * @see #MATCH_UNINSTALLED_PACKAGES
2832     */
2833    public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage,
2834            @PackageInfoFlags int flags) throws NameNotFoundException;
2835
2836    /**
2837     * Retrieve overall information about an application package that is
2838     * installed on the system.
2839     *
2840     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2841     *         desired package.
2842     * @param flags Additional option flags. Use any combination of
2843     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
2844     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
2845     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
2846     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
2847     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
2848     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
2849     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
2850     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
2851     *         {@link #MATCH_UNINSTALLED_PACKAGES}
2852     *         to modify the data returned.
2853     * @param userId The user id.
2854     *
2855     * @return A PackageInfo object containing information about the
2856     *         package. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set and if the
2857     *         package is not found in the list of installed applications, the
2858     *         package information is retrieved from the list of uninstalled
2859     *         applications (which includes installed applications as well as
2860     *         applications with data directory i.e. applications which had been
2861     *         deleted with {@code DONT_DELETE_DATA} flag set).
2862     * @throws NameNotFoundException if a package with the given name cannot be
2863     *             found on the system.
2864     * @see #GET_ACTIVITIES
2865     * @see #GET_CONFIGURATIONS
2866     * @see #GET_GIDS
2867     * @see #GET_INSTRUMENTATION
2868     * @see #GET_INTENT_FILTERS
2869     * @see #GET_META_DATA
2870     * @see #GET_PERMISSIONS
2871     * @see #GET_PROVIDERS
2872     * @see #GET_RECEIVERS
2873     * @see #GET_SERVICES
2874     * @see #GET_SHARED_LIBRARY_FILES
2875     * @see #GET_SIGNATURES
2876     * @see #GET_URI_PERMISSION_PATTERNS
2877     * @see #MATCH_DISABLED_COMPONENTS
2878     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
2879     * @see #MATCH_UNINSTALLED_PACKAGES
2880     *
2881     * @hide
2882     */
2883    @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS)
2884    public abstract PackageInfo getPackageInfoAsUser(String packageName,
2885            @PackageInfoFlags int flags, @UserIdInt int userId) throws NameNotFoundException;
2886
2887    /**
2888     * Map from the current package names in use on the device to whatever
2889     * the current canonical name of that package is.
2890     * @param names Array of current names to be mapped.
2891     * @return Returns an array of the same size as the original, containing
2892     * the canonical name for each package.
2893     */
2894    public abstract String[] currentToCanonicalPackageNames(String[] names);
2895
2896    /**
2897     * Map from a packages canonical name to the current name in use on the device.
2898     * @param names Array of new names to be mapped.
2899     * @return Returns an array of the same size as the original, containing
2900     * the current name for each package.
2901     */
2902    public abstract String[] canonicalToCurrentPackageNames(String[] names);
2903
2904    /**
2905     * Returns a "good" intent to launch a front-door activity in a package.
2906     * This is used, for example, to implement an "open" button when browsing
2907     * through packages.  The current implementation looks first for a main
2908     * activity in the category {@link Intent#CATEGORY_INFO}, and next for a
2909     * main activity in the category {@link Intent#CATEGORY_LAUNCHER}. Returns
2910     * <code>null</code> if neither are found.
2911     *
2912     * @param packageName The name of the package to inspect.
2913     *
2914     * @return A fully-qualified {@link Intent} that can be used to launch the
2915     * main activity in the package. Returns <code>null</code> if the package
2916     * does not contain such an activity, or if <em>packageName</em> is not
2917     * recognized.
2918     */
2919    public abstract Intent getLaunchIntentForPackage(String packageName);
2920
2921    /**
2922     * Return a "good" intent to launch a front-door Leanback activity in a
2923     * package, for use for example to implement an "open" button when browsing
2924     * through packages. The current implementation will look for a main
2925     * activity in the category {@link Intent#CATEGORY_LEANBACK_LAUNCHER}, or
2926     * return null if no main leanback activities are found.
2927     *
2928     * @param packageName The name of the package to inspect.
2929     * @return Returns either a fully-qualified Intent that can be used to launch
2930     *         the main Leanback activity in the package, or null if the package
2931     *         does not contain such an activity.
2932     */
2933    public abstract Intent getLeanbackLaunchIntentForPackage(String packageName);
2934
2935    /**
2936     * Return an array of all of the POSIX secondary group IDs that have been
2937     * assigned to the given package.
2938     * <p>
2939     * Note that the same package may have different GIDs under different
2940     * {@link UserHandle} on the same device.
2941     *
2942     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2943     *            desired package.
2944     * @return Returns an int array of the assigned GIDs, or null if there are
2945     *         none.
2946     * @throws NameNotFoundException if a package with the given name cannot be
2947     *             found on the system.
2948     */
2949    public abstract int[] getPackageGids(String packageName)
2950            throws NameNotFoundException;
2951
2952    /**
2953     * Return an array of all of the POSIX secondary group IDs that have been
2954     * assigned to the given package.
2955     * <p>
2956     * Note that the same package may have different GIDs under different
2957     * {@link UserHandle} on the same device.
2958     *
2959     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2960     *            desired package.
2961     * @return Returns an int array of the assigned gids, or null if there are
2962     *         none.
2963     * @throws NameNotFoundException if a package with the given name cannot be
2964     *             found on the system.
2965     */
2966    public abstract int[] getPackageGids(String packageName, @PackageInfoFlags int flags)
2967            throws NameNotFoundException;
2968
2969    /**
2970     * Return the UID associated with the given package name.
2971     * <p>
2972     * Note that the same package will have different UIDs under different
2973     * {@link UserHandle} on the same device.
2974     *
2975     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2976     *            desired package.
2977     * @return Returns an integer UID who owns the given package name.
2978     * @throws NameNotFoundException if a package with the given name can not be
2979     *             found on the system.
2980     */
2981    public abstract int getPackageUid(String packageName, @PackageInfoFlags int flags)
2982            throws NameNotFoundException;
2983
2984    /**
2985     * Return the UID associated with the given package name.
2986     * <p>
2987     * Note that the same package will have different UIDs under different
2988     * {@link UserHandle} on the same device.
2989     *
2990     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2991     *            desired package.
2992     * @param userId The user handle identifier to look up the package under.
2993     * @return Returns an integer UID who owns the given package name.
2994     * @throws NameNotFoundException if a package with the given name can not be
2995     *             found on the system.
2996     * @hide
2997     */
2998    public abstract int getPackageUidAsUser(String packageName, @UserIdInt int userId)
2999            throws NameNotFoundException;
3000
3001    /**
3002     * Return the UID associated with the given package name.
3003     * <p>
3004     * Note that the same package will have different UIDs under different
3005     * {@link UserHandle} on the same device.
3006     *
3007     * @param packageName The full name (i.e. com.google.apps.contacts) of the
3008     *            desired package.
3009     * @param userId The user handle identifier to look up the package under.
3010     * @return Returns an integer UID who owns the given package name.
3011     * @throws NameNotFoundException if a package with the given name can not be
3012     *             found on the system.
3013     * @hide
3014     */
3015    public abstract int getPackageUidAsUser(String packageName, @PackageInfoFlags int flags,
3016            @UserIdInt int userId) throws NameNotFoundException;
3017
3018    /**
3019     * Retrieve all of the information we know about a particular permission.
3020     *
3021     * @param name The fully qualified name (i.e. com.google.permission.LOGIN)
3022     *         of the permission you are interested in.
3023     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
3024     *         retrieve any meta-data associated with the permission.
3025     *
3026     * @return Returns a {@link PermissionInfo} containing information about the
3027     *         permission.
3028     * @throws NameNotFoundException if a package with the given name cannot be
3029     *             found on the system.
3030     *
3031     * @see #GET_META_DATA
3032     */
3033    public abstract PermissionInfo getPermissionInfo(String name, @PermissionInfoFlags int flags)
3034            throws NameNotFoundException;
3035
3036    /**
3037     * Query for all of the permissions associated with a particular group.
3038     *
3039     * @param group The fully qualified name (i.e. com.google.permission.LOGIN)
3040     *         of the permission group you are interested in.  Use null to
3041     *         find all of the permissions not associated with a group.
3042     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
3043     *         retrieve any meta-data associated with the permissions.
3044     *
3045     * @return Returns a list of {@link PermissionInfo} containing information
3046     *             about all of the permissions in the given group.
3047     * @throws NameNotFoundException if a package with the given name cannot be
3048     *             found on the system.
3049     *
3050     * @see #GET_META_DATA
3051     */
3052    public abstract List<PermissionInfo> queryPermissionsByGroup(String group,
3053            @PermissionInfoFlags int flags) throws NameNotFoundException;
3054
3055    /**
3056     * Returns true if Permission Review Mode is enabled, false otherwise.
3057     *
3058     * @hide
3059     */
3060    @TestApi
3061    public abstract boolean isPermissionReviewModeEnabled();
3062
3063    /**
3064     * Retrieve all of the information we know about a particular group of
3065     * permissions.
3066     *
3067     * @param name The fully qualified name (i.e. com.google.permission_group.APPS)
3068     *         of the permission you are interested in.
3069     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
3070     *         retrieve any meta-data associated with the permission group.
3071     *
3072     * @return Returns a {@link PermissionGroupInfo} containing information
3073     *         about the permission.
3074     * @throws NameNotFoundException if a package with the given name cannot be
3075     *             found on the system.
3076     *
3077     * @see #GET_META_DATA
3078     */
3079    public abstract PermissionGroupInfo getPermissionGroupInfo(String name,
3080            @PermissionGroupInfoFlags int flags) throws NameNotFoundException;
3081
3082    /**
3083     * Retrieve all of the known permission groups in the system.
3084     *
3085     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
3086     *         retrieve any meta-data associated with the permission group.
3087     *
3088     * @return Returns a list of {@link PermissionGroupInfo} containing
3089     *         information about all of the known permission groups.
3090     *
3091     * @see #GET_META_DATA
3092     */
3093    public abstract List<PermissionGroupInfo> getAllPermissionGroups(
3094            @PermissionGroupInfoFlags int flags);
3095
3096    /**
3097     * Retrieve all of the information we know about a particular
3098     * package/application.
3099     *
3100     * @param packageName The full name (i.e. com.google.apps.contacts) of an
3101     *         application.
3102     * @param flags Additional option flags. Use any combination of
3103     *         {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
3104     *         {@link #MATCH_SYSTEM_ONLY}, {@link #MATCH_UNINSTALLED_PACKAGES}
3105     *         to modify the data returned.
3106     *
3107     * @return An {@link ApplicationInfo} containing information about the
3108     *         package. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set and if the
3109     *         package is not found in the list of installed applications, the
3110     *         application information is retrieved from the list of uninstalled
3111     *         applications (which includes installed applications as well as
3112     *         applications with data directory i.e. applications which had been
3113     *         deleted with {@code DONT_DELETE_DATA} flag set).
3114     * @throws NameNotFoundException if a package with the given name cannot be
3115     *             found on the system.
3116     *
3117     * @see #GET_META_DATA
3118     * @see #GET_SHARED_LIBRARY_FILES
3119     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3120     * @see #MATCH_SYSTEM_ONLY
3121     * @see #MATCH_UNINSTALLED_PACKAGES
3122     */
3123    public abstract ApplicationInfo getApplicationInfo(String packageName,
3124            @ApplicationInfoFlags int flags) throws NameNotFoundException;
3125
3126    /** {@hide} */
3127    public abstract ApplicationInfo getApplicationInfoAsUser(String packageName,
3128            @ApplicationInfoFlags int flags, @UserIdInt int userId) throws NameNotFoundException;
3129
3130    /**
3131     * Retrieve all of the information we know about a particular activity
3132     * class.
3133     *
3134     * @param component The full component name (i.e.
3135     *            com.google.apps.contacts/com.google.apps.contacts.
3136     *            ContactsList) of an Activity class.
3137     * @param flags Additional option flags. Use any combination of
3138     *            {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
3139     *            {@link #MATCH_ALL}, {@link #MATCH_DEFAULT_ONLY},
3140     *            {@link #MATCH_DISABLED_COMPONENTS},
3141     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
3142     *            {@link #MATCH_DIRECT_BOOT_AWARE},
3143     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
3144     *            {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
3145     *            returned.
3146     * @return An {@link ActivityInfo} containing information about the
3147     *         activity.
3148     * @throws NameNotFoundException if a package with the given name cannot be
3149     *             found on the system.
3150     * @see #GET_META_DATA
3151     * @see #GET_SHARED_LIBRARY_FILES
3152     * @see #MATCH_ALL
3153     * @see #MATCH_DEBUG_TRIAGED_MISSING
3154     * @see #MATCH_DEFAULT_ONLY
3155     * @see #MATCH_DISABLED_COMPONENTS
3156     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3157     * @see #MATCH_DIRECT_BOOT_AWARE
3158     * @see #MATCH_DIRECT_BOOT_UNAWARE
3159     * @see #MATCH_SYSTEM_ONLY
3160     * @see #MATCH_UNINSTALLED_PACKAGES
3161     */
3162    public abstract ActivityInfo getActivityInfo(ComponentName component,
3163            @ComponentInfoFlags int flags) throws NameNotFoundException;
3164
3165    /**
3166     * Retrieve all of the information we know about a particular receiver
3167     * class.
3168     *
3169     * @param component The full component name (i.e.
3170     *            com.google.apps.calendar/com.google.apps.calendar.
3171     *            CalendarAlarm) of a Receiver class.
3172     * @param flags Additional option flags. Use any combination of
3173     *            {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
3174     *            {@link #MATCH_ALL}, {@link #MATCH_DEFAULT_ONLY},
3175     *            {@link #MATCH_DISABLED_COMPONENTS},
3176     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
3177     *            {@link #MATCH_DIRECT_BOOT_AWARE},
3178     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
3179     *            {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
3180     *            returned.
3181     * @return An {@link ActivityInfo} containing information about the
3182     *         receiver.
3183     * @throws NameNotFoundException if a package with the given name cannot be
3184     *             found on the system.
3185     * @see #GET_META_DATA
3186     * @see #GET_SHARED_LIBRARY_FILES
3187     * @see #MATCH_ALL
3188     * @see #MATCH_DEBUG_TRIAGED_MISSING
3189     * @see #MATCH_DEFAULT_ONLY
3190     * @see #MATCH_DISABLED_COMPONENTS
3191     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3192     * @see #MATCH_DIRECT_BOOT_AWARE
3193     * @see #MATCH_DIRECT_BOOT_UNAWARE
3194     * @see #MATCH_SYSTEM_ONLY
3195     * @see #MATCH_UNINSTALLED_PACKAGES
3196     */
3197    public abstract ActivityInfo getReceiverInfo(ComponentName component,
3198            @ComponentInfoFlags int flags) throws NameNotFoundException;
3199
3200    /**
3201     * Retrieve all of the information we know about a particular service class.
3202     *
3203     * @param component The full component name (i.e.
3204     *            com.google.apps.media/com.google.apps.media.
3205     *            BackgroundPlayback) of a Service class.
3206     * @param flags Additional option flags. Use any combination of
3207     *            {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
3208     *            {@link #MATCH_ALL}, {@link #MATCH_DEFAULT_ONLY},
3209     *            {@link #MATCH_DISABLED_COMPONENTS},
3210     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
3211     *            {@link #MATCH_DIRECT_BOOT_AWARE},
3212     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
3213     *            {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
3214     *            returned.
3215     * @return A {@link ServiceInfo} object containing information about the
3216     *         service.
3217     * @throws NameNotFoundException if a package with the given name cannot be
3218     *             found on the system.
3219     * @see #GET_META_DATA
3220     * @see #GET_SHARED_LIBRARY_FILES
3221     * @see #MATCH_ALL
3222     * @see #MATCH_DEBUG_TRIAGED_MISSING
3223     * @see #MATCH_DEFAULT_ONLY
3224     * @see #MATCH_DISABLED_COMPONENTS
3225     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3226     * @see #MATCH_DIRECT_BOOT_AWARE
3227     * @see #MATCH_DIRECT_BOOT_UNAWARE
3228     * @see #MATCH_SYSTEM_ONLY
3229     * @see #MATCH_UNINSTALLED_PACKAGES
3230     */
3231    public abstract ServiceInfo getServiceInfo(ComponentName component,
3232            @ComponentInfoFlags int flags) throws NameNotFoundException;
3233
3234    /**
3235     * Retrieve all of the information we know about a particular content
3236     * provider class.
3237     *
3238     * @param component The full component name (i.e.
3239     *            com.google.providers.media/com.google.providers.media.
3240     *            MediaProvider) of a ContentProvider class.
3241     * @param flags Additional option flags. Use any combination of
3242     *            {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
3243     *            {@link #MATCH_ALL}, {@link #MATCH_DEFAULT_ONLY},
3244     *            {@link #MATCH_DISABLED_COMPONENTS},
3245     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
3246     *            {@link #MATCH_DIRECT_BOOT_AWARE},
3247     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
3248     *            {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
3249     *            returned.
3250     * @return A {@link ProviderInfo} object containing information about the
3251     *         provider.
3252     * @throws NameNotFoundException if a package with the given name cannot be
3253     *             found on the system.
3254     * @see #GET_META_DATA
3255     * @see #GET_SHARED_LIBRARY_FILES
3256     * @see #MATCH_ALL
3257     * @see #MATCH_DEBUG_TRIAGED_MISSING
3258     * @see #MATCH_DEFAULT_ONLY
3259     * @see #MATCH_DISABLED_COMPONENTS
3260     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3261     * @see #MATCH_DIRECT_BOOT_AWARE
3262     * @see #MATCH_DIRECT_BOOT_UNAWARE
3263     * @see #MATCH_SYSTEM_ONLY
3264     * @see #MATCH_UNINSTALLED_PACKAGES
3265     */
3266    public abstract ProviderInfo getProviderInfo(ComponentName component,
3267            @ComponentInfoFlags int flags) throws NameNotFoundException;
3268
3269    /**
3270     * Return a List of all packages that are installed
3271     * on the device.
3272     *
3273     * @param flags Additional option flags. Use any combination of
3274     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
3275     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
3276     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
3277     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
3278     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
3279     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
3280     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
3281     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
3282     *         {@link #MATCH_UNINSTALLED_PACKAGES}
3283     *         to modify the data returned.
3284     *
3285     * @return A List of PackageInfo objects, one for each installed package,
3286     *         containing information about the package.  In the unlikely case
3287     *         there are no installed packages, an empty list is returned. If
3288     *         flag {@code MATCH_UNINSTALLED_PACKAGES} is set, the package
3289     *         information is retrieved from the list of uninstalled
3290     *         applications (which includes installed applications as well as
3291     *         applications with data directory i.e. applications which had been
3292     *         deleted with {@code DONT_DELETE_DATA} flag set).
3293     *
3294     * @see #GET_ACTIVITIES
3295     * @see #GET_CONFIGURATIONS
3296     * @see #GET_GIDS
3297     * @see #GET_INSTRUMENTATION
3298     * @see #GET_INTENT_FILTERS
3299     * @see #GET_META_DATA
3300     * @see #GET_PERMISSIONS
3301     * @see #GET_PROVIDERS
3302     * @see #GET_RECEIVERS
3303     * @see #GET_SERVICES
3304     * @see #GET_SHARED_LIBRARY_FILES
3305     * @see #GET_SIGNATURES
3306     * @see #GET_URI_PERMISSION_PATTERNS
3307     * @see #MATCH_DISABLED_COMPONENTS
3308     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3309     * @see #MATCH_UNINSTALLED_PACKAGES
3310     */
3311    public abstract List<PackageInfo> getInstalledPackages(@PackageInfoFlags int flags);
3312
3313    /**
3314     * Return a List of all installed packages that are currently
3315     * holding any of the given permissions.
3316     *
3317     * @param flags Additional option flags. Use any combination of
3318     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
3319     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
3320     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
3321     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
3322     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
3323     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
3324     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
3325     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
3326     *         {@link #MATCH_UNINSTALLED_PACKAGES}
3327     *         to modify the data returned.
3328     *
3329     * @return A List of PackageInfo objects, one for each installed package
3330     *         that holds any of the permissions that were provided, containing
3331     *         information about the package. If no installed packages hold any
3332     *         of the permissions, an empty list is returned. If flag
3333     *         {@code MATCH_UNINSTALLED_PACKAGES} is set, the package information
3334     *         is retrieved from the list of uninstalled applications (which
3335     *         includes installed applications as well as applications with data
3336     *         directory i.e. applications which had been deleted with
3337     *         {@code DONT_DELETE_DATA} flag set).
3338     *
3339     * @see #GET_ACTIVITIES
3340     * @see #GET_CONFIGURATIONS
3341     * @see #GET_GIDS
3342     * @see #GET_INSTRUMENTATION
3343     * @see #GET_INTENT_FILTERS
3344     * @see #GET_META_DATA
3345     * @see #GET_PERMISSIONS
3346     * @see #GET_PROVIDERS
3347     * @see #GET_RECEIVERS
3348     * @see #GET_SERVICES
3349     * @see #GET_SHARED_LIBRARY_FILES
3350     * @see #GET_SIGNATURES
3351     * @see #GET_URI_PERMISSION_PATTERNS
3352     * @see #MATCH_DISABLED_COMPONENTS
3353     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3354     * @see #MATCH_UNINSTALLED_PACKAGES
3355     */
3356    public abstract List<PackageInfo> getPackagesHoldingPermissions(
3357            String[] permissions, @PackageInfoFlags int flags);
3358
3359    /**
3360     * Return a List of all packages that are installed on the device, for a specific user.
3361     * Requesting a list of installed packages for another user
3362     * will require the permission INTERACT_ACROSS_USERS_FULL.
3363     *
3364     * @param flags Additional option flags. Use any combination of
3365     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
3366     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
3367     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
3368     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
3369     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
3370     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
3371     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
3372     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
3373     *         {@link #MATCH_UNINSTALLED_PACKAGES}
3374     *         to modify the data returned.
3375     * @param userId The user for whom the installed packages are to be listed
3376     *
3377     * @return A List of PackageInfo objects, one for each installed package,
3378     *         containing information about the package.  In the unlikely case
3379     *         there are no installed packages, an empty list is returned. If
3380     *         flag {@code MATCH_UNINSTALLED_PACKAGES} is set, the package
3381     *         information is retrieved from the list of uninstalled
3382     *         applications (which includes installed applications as well as
3383     *         applications with data directory i.e. applications which had been
3384     *         deleted with {@code DONT_DELETE_DATA} flag set).
3385     *
3386     * @see #GET_ACTIVITIES
3387     * @see #GET_CONFIGURATIONS
3388     * @see #GET_GIDS
3389     * @see #GET_INSTRUMENTATION
3390     * @see #GET_INTENT_FILTERS
3391     * @see #GET_META_DATA
3392     * @see #GET_PERMISSIONS
3393     * @see #GET_PROVIDERS
3394     * @see #GET_RECEIVERS
3395     * @see #GET_SERVICES
3396     * @see #GET_SHARED_LIBRARY_FILES
3397     * @see #GET_SIGNATURES
3398     * @see #GET_URI_PERMISSION_PATTERNS
3399     * @see #MATCH_DISABLED_COMPONENTS
3400     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3401     * @see #MATCH_UNINSTALLED_PACKAGES
3402     *
3403     * @hide
3404     */
3405    @SystemApi
3406    public abstract List<PackageInfo> getInstalledPackagesAsUser(@PackageInfoFlags int flags,
3407            @UserIdInt int userId);
3408
3409    /**
3410     * Check whether a particular package has been granted a particular
3411     * permission.
3412     *
3413     * @param permName The name of the permission you are checking for.
3414     * @param pkgName The name of the package you are checking against.
3415     *
3416     * @return If the package has the permission, PERMISSION_GRANTED is
3417     * returned.  If it does not have the permission, PERMISSION_DENIED
3418     * is returned.
3419     *
3420     * @see #PERMISSION_GRANTED
3421     * @see #PERMISSION_DENIED
3422     */
3423    @CheckResult
3424    public abstract int checkPermission(String permName, String pkgName);
3425
3426    /**
3427     * Checks whether a particular permissions has been revoked for a
3428     * package by policy. Typically the device owner or the profile owner
3429     * may apply such a policy. The user cannot grant policy revoked
3430     * permissions, hence the only way for an app to get such a permission
3431     * is by a policy change.
3432     *
3433     * @param permName The name of the permission you are checking for.
3434     * @param pkgName The name of the package you are checking against.
3435     *
3436     * @return Whether the permission is restricted by policy.
3437     */
3438    @CheckResult
3439    public abstract boolean isPermissionRevokedByPolicy(@NonNull String permName,
3440            @NonNull String pkgName);
3441
3442    /**
3443     * Gets the package name of the component controlling runtime permissions.
3444     *
3445     * @return The package name.
3446     *
3447     * @hide
3448     */
3449    public abstract String getPermissionControllerPackageName();
3450
3451    /**
3452     * Add a new dynamic permission to the system.  For this to work, your
3453     * package must have defined a permission tree through the
3454     * {@link android.R.styleable#AndroidManifestPermissionTree
3455     * &lt;permission-tree&gt;} tag in its manifest.  A package can only add
3456     * permissions to trees that were defined by either its own package or
3457     * another with the same user id; a permission is in a tree if it
3458     * matches the name of the permission tree + ".": for example,
3459     * "com.foo.bar" is a member of the permission tree "com.foo".
3460     *
3461     * <p>It is good to make your permission tree name descriptive, because you
3462     * are taking possession of that entire set of permission names.  Thus, it
3463     * must be under a domain you control, with a suffix that will not match
3464     * any normal permissions that may be declared in any applications that
3465     * are part of that domain.
3466     *
3467     * <p>New permissions must be added before
3468     * any .apks are installed that use those permissions.  Permissions you
3469     * add through this method are remembered across reboots of the device.
3470     * If the given permission already exists, the info you supply here
3471     * will be used to update it.
3472     *
3473     * @param info Description of the permission to be added.
3474     *
3475     * @return Returns true if a new permission was created, false if an
3476     * existing one was updated.
3477     *
3478     * @throws SecurityException if you are not allowed to add the
3479     * given permission name.
3480     *
3481     * @see #removePermission(String)
3482     */
3483    public abstract boolean addPermission(PermissionInfo info);
3484
3485    /**
3486     * Like {@link #addPermission(PermissionInfo)} but asynchronously
3487     * persists the package manager state after returning from the call,
3488     * allowing it to return quicker and batch a series of adds at the
3489     * expense of no guarantee the added permission will be retained if
3490     * the device is rebooted before it is written.
3491     */
3492    public abstract boolean addPermissionAsync(PermissionInfo info);
3493
3494    /**
3495     * Removes a permission that was previously added with
3496     * {@link #addPermission(PermissionInfo)}.  The same ownership rules apply
3497     * -- you are only allowed to remove permissions that you are allowed
3498     * to add.
3499     *
3500     * @param name The name of the permission to remove.
3501     *
3502     * @throws SecurityException if you are not allowed to remove the
3503     * given permission name.
3504     *
3505     * @see #addPermission(PermissionInfo)
3506     */
3507    public abstract void removePermission(String name);
3508
3509    /**
3510     * Permission flags set when granting or revoking a permission.
3511     *
3512     * @hide
3513     */
3514    @SystemApi
3515    @IntDef({FLAG_PERMISSION_USER_SET,
3516            FLAG_PERMISSION_USER_FIXED,
3517            FLAG_PERMISSION_POLICY_FIXED,
3518            FLAG_PERMISSION_REVOKE_ON_UPGRADE,
3519            FLAG_PERMISSION_SYSTEM_FIXED,
3520            FLAG_PERMISSION_GRANTED_BY_DEFAULT})
3521    @Retention(RetentionPolicy.SOURCE)
3522    public @interface PermissionFlags {}
3523
3524    /**
3525     * Grant a runtime permission to an application which the application does not
3526     * already have. The permission must have been requested by the application.
3527     * If the application is not allowed to hold the permission, a {@link
3528     * java.lang.SecurityException} is thrown. If the package or permission is
3529     * invalid, a {@link java.lang.IllegalArgumentException} is thrown.
3530     * <p>
3531     * <strong>Note: </strong>Using this API requires holding
3532     * android.permission.GRANT_RUNTIME_PERMISSIONS and if the user id is
3533     * not the current user android.permission.INTERACT_ACROSS_USERS_FULL.
3534     * </p>
3535     *
3536     * @param packageName The package to which to grant the permission.
3537     * @param permissionName The permission name to grant.
3538     * @param user The user for which to grant the permission.
3539     *
3540     * @see #revokeRuntimePermission(String, String, android.os.UserHandle)
3541     *
3542     * @hide
3543     */
3544    @SystemApi
3545    public abstract void grantRuntimePermission(@NonNull String packageName,
3546            @NonNull String permissionName, @NonNull UserHandle user);
3547
3548    /**
3549     * Revoke a runtime permission that was previously granted by {@link
3550     * #grantRuntimePermission(String, String, android.os.UserHandle)}. The
3551     * permission must have been requested by and granted to the application.
3552     * If the application is not allowed to hold the permission, a {@link
3553     * java.lang.SecurityException} is thrown. If the package or permission is
3554     * invalid, a {@link java.lang.IllegalArgumentException} is thrown.
3555     * <p>
3556     * <strong>Note: </strong>Using this API requires holding
3557     * android.permission.REVOKE_RUNTIME_PERMISSIONS and if the user id is
3558     * not the current user android.permission.INTERACT_ACROSS_USERS_FULL.
3559     * </p>
3560     *
3561     * @param packageName The package from which to revoke the permission.
3562     * @param permissionName The permission name to revoke.
3563     * @param user The user for which to revoke the permission.
3564     *
3565     * @see #grantRuntimePermission(String, String, android.os.UserHandle)
3566     *
3567     * @hide
3568     */
3569    @SystemApi
3570    public abstract void revokeRuntimePermission(@NonNull String packageName,
3571            @NonNull String permissionName, @NonNull UserHandle user);
3572
3573    /**
3574     * Gets the state flags associated with a permission.
3575     *
3576     * @param permissionName The permission for which to get the flags.
3577     * @param packageName The package name for which to get the flags.
3578     * @param user The user for which to get permission flags.
3579     * @return The permission flags.
3580     *
3581     * @hide
3582     */
3583    @SystemApi
3584    public abstract @PermissionFlags int getPermissionFlags(String permissionName,
3585            String packageName, @NonNull UserHandle user);
3586
3587    /**
3588     * Updates the flags associated with a permission by replacing the flags in
3589     * the specified mask with the provided flag values.
3590     *
3591     * @param permissionName The permission for which to update the flags.
3592     * @param packageName The package name for which to update the flags.
3593     * @param flagMask The flags which to replace.
3594     * @param flagValues The flags with which to replace.
3595     * @param user The user for which to update the permission flags.
3596     *
3597     * @hide
3598     */
3599    @SystemApi
3600    public abstract void updatePermissionFlags(String permissionName,
3601            String packageName, @PermissionFlags int flagMask, int flagValues,
3602            @NonNull UserHandle user);
3603
3604    /**
3605     * Gets whether you should show UI with rationale for requesting a permission.
3606     * You should do this only if you do not have the permission and the context in
3607     * which the permission is requested does not clearly communicate to the user
3608     * what would be the benefit from grating this permission.
3609     *
3610     * @param permission A permission your app wants to request.
3611     * @return Whether you can show permission rationale UI.
3612     *
3613     * @hide
3614     */
3615    public abstract boolean shouldShowRequestPermissionRationale(String permission);
3616
3617    /**
3618     * Returns an {@link android.content.Intent} suitable for passing to
3619     * {@link android.app.Activity#startActivityForResult(android.content.Intent, int)}
3620     * which prompts the user to grant permissions to this application.
3621     *
3622     * @throws NullPointerException if {@code permissions} is {@code null} or empty.
3623     *
3624     * @hide
3625     */
3626    public Intent buildRequestPermissionsIntent(@NonNull String[] permissions) {
3627        if (ArrayUtils.isEmpty(permissions)) {
3628           throw new IllegalArgumentException("permission cannot be null or empty");
3629        }
3630        Intent intent = new Intent(ACTION_REQUEST_PERMISSIONS);
3631        intent.putExtra(EXTRA_REQUEST_PERMISSIONS_NAMES, permissions);
3632        intent.setPackage(getPermissionControllerPackageName());
3633        return intent;
3634    }
3635
3636    /**
3637     * Compare the signatures of two packages to determine if the same
3638     * signature appears in both of them.  If they do contain the same
3639     * signature, then they are allowed special privileges when working
3640     * with each other: they can share the same user-id, run instrumentation
3641     * against each other, etc.
3642     *
3643     * @param pkg1 First package name whose signature will be compared.
3644     * @param pkg2 Second package name whose signature will be compared.
3645     *
3646     * @return Returns an integer indicating whether all signatures on the
3647     * two packages match. The value is >= 0 ({@link #SIGNATURE_MATCH}) if
3648     * all signatures match or < 0 if there is not a match ({@link
3649     * #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
3650     *
3651     * @see #checkSignatures(int, int)
3652     * @see #SIGNATURE_MATCH
3653     * @see #SIGNATURE_NO_MATCH
3654     * @see #SIGNATURE_UNKNOWN_PACKAGE
3655     */
3656    @CheckResult
3657    public abstract int checkSignatures(String pkg1, String pkg2);
3658
3659    /**
3660     * Like {@link #checkSignatures(String, String)}, but takes UIDs of
3661     * the two packages to be checked.  This can be useful, for example,
3662     * when doing the check in an IPC, where the UID is the only identity
3663     * available.  It is functionally identical to determining the package
3664     * associated with the UIDs and checking their signatures.
3665     *
3666     * @param uid1 First UID whose signature will be compared.
3667     * @param uid2 Second UID whose signature will be compared.
3668     *
3669     * @return Returns an integer indicating whether all signatures on the
3670     * two packages match. The value is >= 0 ({@link #SIGNATURE_MATCH}) if
3671     * all signatures match or < 0 if there is not a match ({@link
3672     * #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
3673     *
3674     * @see #checkSignatures(String, String)
3675     * @see #SIGNATURE_MATCH
3676     * @see #SIGNATURE_NO_MATCH
3677     * @see #SIGNATURE_UNKNOWN_PACKAGE
3678     */
3679    @CheckResult
3680    public abstract int checkSignatures(int uid1, int uid2);
3681
3682    /**
3683     * Retrieve the names of all packages that are associated with a particular
3684     * user id.  In most cases, this will be a single package name, the package
3685     * that has been assigned that user id.  Where there are multiple packages
3686     * sharing the same user id through the "sharedUserId" mechanism, all
3687     * packages with that id will be returned.
3688     *
3689     * @param uid The user id for which you would like to retrieve the
3690     * associated packages.
3691     *
3692     * @return Returns an array of one or more packages assigned to the user
3693     * id, or null if there are no known packages with the given id.
3694     */
3695    public abstract @Nullable String[] getPackagesForUid(int uid);
3696
3697    /**
3698     * Retrieve the official name associated with a uid. This name is
3699     * guaranteed to never change, though it is possible for the underlying
3700     * uid to be changed.  That is, if you are storing information about
3701     * uids in persistent storage, you should use the string returned
3702     * by this function instead of the raw uid.
3703     *
3704     * @param uid The uid for which you would like to retrieve a name.
3705     * @return Returns a unique name for the given uid, or null if the
3706     * uid is not currently assigned.
3707     */
3708    public abstract @Nullable String getNameForUid(int uid);
3709
3710    /**
3711     * Return the user id associated with a shared user name. Multiple
3712     * applications can specify a shared user name in their manifest and thus
3713     * end up using a common uid. This might be used for new applications
3714     * that use an existing shared user name and need to know the uid of the
3715     * shared user.
3716     *
3717     * @param sharedUserName The shared user name whose uid is to be retrieved.
3718     * @return Returns the UID associated with the shared user.
3719     * @throws NameNotFoundException if a package with the given name cannot be
3720     *             found on the system.
3721     * @hide
3722     */
3723    public abstract int getUidForSharedUser(String sharedUserName)
3724            throws NameNotFoundException;
3725
3726    /**
3727     * Return a List of all application packages that are installed on the
3728     * device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all
3729     * applications including those deleted with {@code DONT_DELETE_DATA} (partially
3730     * installed apps with data directory) will be returned.
3731     *
3732     * @param flags Additional option flags. Use any combination of
3733     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
3734     * {@link #MATCH_SYSTEM_ONLY}, {@link #MATCH_UNINSTALLED_PACKAGES}
3735     * to modify the data returned.
3736     *
3737     * @return A List of ApplicationInfo objects, one for each installed application.
3738     *         In the unlikely case there are no installed packages, an empty list
3739     *         is returned. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set, the
3740     *         application information is retrieved from the list of uninstalled
3741     *         applications (which includes installed applications as well as
3742     *         applications with data directory i.e. applications which had been
3743     *         deleted with {@code DONT_DELETE_DATA} flag set).
3744     *
3745     * @see #GET_META_DATA
3746     * @see #GET_SHARED_LIBRARY_FILES
3747     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3748     * @see #MATCH_SYSTEM_ONLY
3749     * @see #MATCH_UNINSTALLED_PACKAGES
3750     */
3751    public abstract List<ApplicationInfo> getInstalledApplications(@ApplicationInfoFlags int flags);
3752
3753    /**
3754     * Return a List of all application packages that are installed on the device, for a specific
3755     * user. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all applications including
3756     * those deleted with {@code DONT_DELETE_DATA} (partially installed apps with data directory)
3757     * will be returned.
3758     *
3759     * @param flags Additional option flags. Use any combination of
3760     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
3761     * {@link #MATCH_SYSTEM_ONLY}, {@link #MATCH_UNINSTALLED_PACKAGES}
3762     * to modify the data returned.
3763     * @param userId The user for whom the installed applications are to be listed
3764     *
3765     * @return A List of ApplicationInfo objects, one for each installed application.
3766     *         In the unlikely case there are no installed packages, an empty list
3767     *         is returned. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set, the
3768     *         application information is retrieved from the list of uninstalled
3769     *         applications (which includes installed applications as well as
3770     *         applications with data directory i.e. applications which had been
3771     *         deleted with {@code DONT_DELETE_DATA} flag set).
3772     * @hide
3773     *
3774     * @see #GET_META_DATA
3775     * @see #GET_SHARED_LIBRARY_FILES
3776     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
3777     * @see #MATCH_SYSTEM_ONLY
3778     * @see #MATCH_UNINSTALLED_PACKAGES
3779     */
3780    public abstract List<ApplicationInfo> getInstalledApplicationsAsUser(
3781            @ApplicationInfoFlags int flags, @UserIdInt int userId);
3782
3783    /**
3784     * Gets the instant applications the user recently used. Requires
3785     * holding "android.permission.ACCESS_INSTANT_APPS".
3786     *
3787     * @return The instant app list.
3788     *
3789     * @hide
3790     */
3791    @SystemApi
3792    @RequiresPermission(Manifest.permission.ACCESS_INSTANT_APPS)
3793    public abstract @NonNull List<InstantAppInfo> getInstantApps();
3794
3795    /**
3796     * Gets the icon for an instant application.
3797     *
3798     * @param packageName The app package name.
3799     *
3800     * @hide
3801     */
3802    @SystemApi
3803    @RequiresPermission(Manifest.permission.ACCESS_INSTANT_APPS)
3804    public abstract @Nullable Drawable getInstantAppIcon(String packageName);
3805
3806    /**
3807     * Gets whether this application is an instant app.
3808     *
3809     * @return Whether caller is an instant app.
3810     *
3811     * @see #isInstantApp(String)
3812     * @see #setInstantAppCookie(byte[])
3813     * @see #getInstantAppCookie()
3814     * @see #getInstantAppCookieMaxSize()
3815     */
3816    public abstract boolean isInstantApp();
3817
3818    /**
3819     * Gets whether the given package is an instant app.
3820     *
3821     * @param packageName The package to check
3822     * @return Whether the given package is an instant app.
3823     *
3824     * @see #isInstantApp()
3825     * @see #setInstantAppCookie(byte[])
3826     * @see #getInstantAppCookie()
3827     * @see #getInstantAppCookieMaxSize()
3828     */
3829    public abstract boolean isInstantApp(String packageName);
3830
3831    /**
3832     * Gets the maximum size in bytes of the cookie data an instant app
3833     * can store on the device.
3834     *
3835     * @return The max cookie size in bytes.
3836     *
3837     * @see #isInstantApp()
3838     * @see #isInstantApp(String)
3839     * @see #setInstantAppCookie(byte[])
3840     * @see #getInstantAppCookie()
3841     */
3842    public abstract int getInstantAppCookieMaxSize();
3843
3844    /**
3845     * Gets the instant application cookie for this app. Non
3846     * instant apps and apps that were instant but were upgraded
3847     * to normal apps can still access this API. For instant apps
3848     * this cooke is cached for some time after uninstall while for
3849     * normal apps the cookie is deleted after the app is uninstalled.
3850     * The cookie is always present while the app is installed.
3851     *
3852     * @return The cookie.
3853     *
3854     * @see #isInstantApp()
3855     * @see #isInstantApp(String)
3856     * @see #setInstantAppCookie(byte[])
3857     * @see #getInstantAppCookieMaxSize()
3858     */
3859    public abstract @NonNull byte[] getInstantAppCookie();
3860
3861    /**
3862     * Sets the instant application cookie for the calling app. Non
3863     * instant apps and apps that were instant but were upgraded
3864     * to normal apps can still access this API. For instant apps
3865     * this cooke is cached for some time after uninstall while for
3866     * normal apps the cookie is deleted after the app is uninstalled.
3867     * The cookie is always present while the app is installed. The
3868     * cookie size is limited by {@link #getInstantAppCookieMaxSize()}.
3869     * If the provided cookie size is over the limit this method
3870     * returns <code>false</code>. Passing <code>null</code> or an empty
3871     * array clears the cookie.
3872     * </p>
3873     *
3874     * @param cookie The cookie data.
3875     * @return Whether the cookie was set.
3876     *
3877     * @see #isInstantApp()
3878     * @see #isInstantApp(String)
3879     * @see #getInstantAppCookieMaxSize()
3880     * @see #getInstantAppCookie()
3881     */
3882    public abstract boolean setInstantAppCookie(@Nullable byte[] cookie);
3883
3884    /**
3885     * Get a list of shared libraries that are available on the
3886     * system.
3887     *
3888     * @return An array of shared library names that are
3889     * available on the system, or null if none are installed.
3890     *
3891     */
3892    public abstract String[] getSystemSharedLibraryNames();
3893
3894    /**
3895     * Get a list of shared libraries on the device.
3896     *
3897     * @param flags To filter the libraries to return.
3898     * @return The shared library list.
3899     *
3900     * @see #MATCH_FACTORY_ONLY
3901     * @see #MATCH_KNOWN_PACKAGES
3902     * @see #MATCH_ANY_USER
3903     * @see #MATCH_UNINSTALLED_PACKAGES
3904     */
3905    public abstract @NonNull List<SharedLibraryInfo> getSharedLibraries(
3906            @InstallFlags int flags);
3907
3908    /**
3909     * Get a list of shared libraries on the device.
3910     *
3911     * @param flags To filter the libraries to return.
3912     * @param userId The user to query for.
3913     * @return The shared library list.
3914     *
3915     * @see #MATCH_FACTORY_ONLY
3916     * @see #MATCH_KNOWN_PACKAGES
3917     * @see #MATCH_ANY_USER
3918     * @see #MATCH_UNINSTALLED_PACKAGES
3919     *
3920     * @hide
3921     */
3922    public abstract @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(
3923            @InstallFlags int flags, @UserIdInt int userId);
3924
3925    /**
3926     * Get the name of the package hosting the services shared library.
3927     *
3928     * @return The library host package.
3929     *
3930     * @hide
3931     */
3932    public abstract @NonNull String getServicesSystemSharedLibraryPackageName();
3933
3934    /**
3935     * Get the name of the package hosting the shared components shared library.
3936     *
3937     * @return The library host package.
3938     *
3939     * @hide
3940     */
3941    public abstract @NonNull String getSharedSystemSharedLibraryPackageName();
3942
3943    /**
3944     * Returns the names of the packages that have been changed
3945     * [eg. added, removed or updated] since the given sequence
3946     * number.
3947     * <p>If no packages have been changed, returns <code>null</code>.
3948     * <p>The sequence number starts at <code>0</code> and is
3949     * reset every boot.
3950     */
3951    public abstract @Nullable ChangedPackages getChangedPackages(
3952            @IntRange(from=0) int sequenceNumber);
3953
3954    /**
3955     * Get a list of features that are available on the
3956     * system.
3957     *
3958     * @return An array of FeatureInfo classes describing the features
3959     * that are available on the system, or null if there are none(!!).
3960     */
3961    public abstract FeatureInfo[] getSystemAvailableFeatures();
3962
3963    /**
3964     * Check whether the given feature name is one of the available features as
3965     * returned by {@link #getSystemAvailableFeatures()}. This tests for the
3966     * presence of <em>any</em> version of the given feature name; use
3967     * {@link #hasSystemFeature(String, int)} to check for a minimum version.
3968     *
3969     * @return Returns true if the devices supports the feature, else false.
3970     */
3971    public abstract boolean hasSystemFeature(String name);
3972
3973    /**
3974     * Check whether the given feature name and version is one of the available
3975     * features as returned by {@link #getSystemAvailableFeatures()}. Since
3976     * features are defined to always be backwards compatible, this returns true
3977     * if the available feature version is greater than or equal to the
3978     * requested version.
3979     *
3980     * @return Returns true if the devices supports the feature, else false.
3981     */
3982    public abstract boolean hasSystemFeature(String name, int version);
3983
3984    /**
3985     * Determine the best action to perform for a given Intent. This is how
3986     * {@link Intent#resolveActivity} finds an activity if a class has not been
3987     * explicitly specified.
3988     * <p>
3989     * <em>Note:</em> if using an implicit Intent (without an explicit
3990     * ComponentName specified), be sure to consider whether to set the
3991     * {@link #MATCH_DEFAULT_ONLY} only flag. You need to do so to resolve the
3992     * activity in the same way that
3993     * {@link android.content.Context#startActivity(Intent)} and
3994     * {@link android.content.Intent#resolveActivity(PackageManager)
3995     * Intent.resolveActivity(PackageManager)} do.
3996     * </p>
3997     *
3998     * @param intent An intent containing all of the desired specification
3999     *            (action, data, type, category, and/or component).
4000     * @param flags Additional option flags. Use any combination of
4001     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4002     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4003     *            {@link #MATCH_DISABLED_COMPONENTS},
4004     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4005     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4006     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4007     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4008     *            returned. The most important is {@link #MATCH_DEFAULT_ONLY},
4009     *            to limit the resolution to only those activities that support
4010     *            the {@link android.content.Intent#CATEGORY_DEFAULT}.
4011     * @return Returns a ResolveInfo object containing the final activity intent
4012     *         that was determined to be the best action. Returns null if no
4013     *         matching activity was found. If multiple matching activities are
4014     *         found and there is no default set, returns a ResolveInfo object
4015     *         containing something else, such as the activity resolver.
4016     * @see #GET_META_DATA
4017     * @see #GET_RESOLVED_FILTER
4018     * @see #GET_SHARED_LIBRARY_FILES
4019     * @see #MATCH_ALL
4020     * @see #MATCH_DISABLED_COMPONENTS
4021     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4022     * @see #MATCH_DEFAULT_ONLY
4023     * @see #MATCH_DIRECT_BOOT_AWARE
4024     * @see #MATCH_DIRECT_BOOT_UNAWARE
4025     * @see #MATCH_SYSTEM_ONLY
4026     * @see #MATCH_UNINSTALLED_PACKAGES
4027     */
4028    public abstract ResolveInfo resolveActivity(Intent intent, @ResolveInfoFlags int flags);
4029
4030    /**
4031     * Determine the best action to perform for a given Intent for a given user.
4032     * This is how {@link Intent#resolveActivity} finds an activity if a class
4033     * has not been explicitly specified.
4034     * <p>
4035     * <em>Note:</em> if using an implicit Intent (without an explicit
4036     * ComponentName specified), be sure to consider whether to set the
4037     * {@link #MATCH_DEFAULT_ONLY} only flag. You need to do so to resolve the
4038     * activity in the same way that
4039     * {@link android.content.Context#startActivity(Intent)} and
4040     * {@link android.content.Intent#resolveActivity(PackageManager)
4041     * Intent.resolveActivity(PackageManager)} do.
4042     * </p>
4043     *
4044     * @param intent An intent containing all of the desired specification
4045     *            (action, data, type, category, and/or component).
4046     * @param flags Additional option flags. Use any combination of
4047     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4048     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4049     *            {@link #MATCH_DISABLED_COMPONENTS},
4050     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4051     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4052     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4053     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4054     *            returned. The most important is {@link #MATCH_DEFAULT_ONLY},
4055     *            to limit the resolution to only those activities that support
4056     *            the {@link android.content.Intent#CATEGORY_DEFAULT}.
4057     * @param userId The user id.
4058     * @return Returns a ResolveInfo object containing the final activity intent
4059     *         that was determined to be the best action. Returns null if no
4060     *         matching activity was found. If multiple matching activities are
4061     *         found and there is no default set, returns a ResolveInfo object
4062     *         containing something else, such as the activity resolver.
4063     * @see #GET_META_DATA
4064     * @see #GET_RESOLVED_FILTER
4065     * @see #GET_SHARED_LIBRARY_FILES
4066     * @see #MATCH_ALL
4067     * @see #MATCH_DISABLED_COMPONENTS
4068     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4069     * @see #MATCH_DEFAULT_ONLY
4070     * @see #MATCH_DIRECT_BOOT_AWARE
4071     * @see #MATCH_DIRECT_BOOT_UNAWARE
4072     * @see #MATCH_SYSTEM_ONLY
4073     * @see #MATCH_UNINSTALLED_PACKAGES
4074     * @hide
4075     */
4076    public abstract ResolveInfo resolveActivityAsUser(Intent intent, @ResolveInfoFlags int flags,
4077            @UserIdInt int userId);
4078
4079    /**
4080     * Retrieve all activities that can be performed for the given intent.
4081     *
4082     * @param intent The desired intent as per resolveActivity().
4083     * @param flags Additional option flags. Use any combination of
4084     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4085     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4086     *            {@link #MATCH_DISABLED_COMPONENTS},
4087     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4088     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4089     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4090     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4091     *            returned. The most important is {@link #MATCH_DEFAULT_ONLY},
4092     *            to limit the resolution to only those activities that support
4093     *            the {@link android.content.Intent#CATEGORY_DEFAULT}. Or, set
4094     *            {@link #MATCH_ALL} to prevent any filtering of the results.
4095     * @return Returns a List of ResolveInfo objects containing one entry for
4096     *         each matching activity, ordered from best to worst. In other
4097     *         words, the first item is what would be returned by
4098     *         {@link #resolveActivity}. If there are no matching activities, an
4099     *         empty list is returned.
4100     * @see #GET_META_DATA
4101     * @see #GET_RESOLVED_FILTER
4102     * @see #GET_SHARED_LIBRARY_FILES
4103     * @see #MATCH_ALL
4104     * @see #MATCH_DISABLED_COMPONENTS
4105     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4106     * @see #MATCH_DEFAULT_ONLY
4107     * @see #MATCH_DIRECT_BOOT_AWARE
4108     * @see #MATCH_DIRECT_BOOT_UNAWARE
4109     * @see #MATCH_SYSTEM_ONLY
4110     * @see #MATCH_UNINSTALLED_PACKAGES
4111     */
4112    public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
4113            @ResolveInfoFlags int flags);
4114
4115    /**
4116     * Retrieve all activities that can be performed for the given intent, for a
4117     * specific user.
4118     *
4119     * @param intent The desired intent as per resolveActivity().
4120     * @param flags Additional option flags. Use any combination of
4121     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4122     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4123     *            {@link #MATCH_DISABLED_COMPONENTS},
4124     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4125     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4126     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4127     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4128     *            returned. The most important is {@link #MATCH_DEFAULT_ONLY},
4129     *            to limit the resolution to only those activities that support
4130     *            the {@link android.content.Intent#CATEGORY_DEFAULT}. Or, set
4131     *            {@link #MATCH_ALL} to prevent any filtering of the results.
4132     * @return Returns a List of ResolveInfo objects containing one entry for
4133     *         each matching activity, ordered from best to worst. In other
4134     *         words, the first item is what would be returned by
4135     *         {@link #resolveActivity}. If there are no matching activities, an
4136     *         empty list is returned.
4137     * @see #GET_META_DATA
4138     * @see #GET_RESOLVED_FILTER
4139     * @see #GET_SHARED_LIBRARY_FILES
4140     * @see #MATCH_ALL
4141     * @see #MATCH_DISABLED_COMPONENTS
4142     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4143     * @see #MATCH_DEFAULT_ONLY
4144     * @see #MATCH_DIRECT_BOOT_AWARE
4145     * @see #MATCH_DIRECT_BOOT_UNAWARE
4146     * @see #MATCH_SYSTEM_ONLY
4147     * @see #MATCH_UNINSTALLED_PACKAGES
4148     * @hide
4149     */
4150    public abstract List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
4151            @ResolveInfoFlags int flags, @UserIdInt int userId);
4152
4153    /**
4154     * Retrieve a set of activities that should be presented to the user as
4155     * similar options. This is like {@link #queryIntentActivities}, except it
4156     * also allows you to supply a list of more explicit Intents that you would
4157     * like to resolve to particular options, and takes care of returning the
4158     * final ResolveInfo list in a reasonable order, with no duplicates, based
4159     * on those inputs.
4160     *
4161     * @param caller The class name of the activity that is making the request.
4162     *            This activity will never appear in the output list. Can be
4163     *            null.
4164     * @param specifics An array of Intents that should be resolved to the first
4165     *            specific results. Can be null.
4166     * @param intent The desired intent as per resolveActivity().
4167     * @param flags Additional option flags. Use any combination of
4168     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4169     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4170     *            {@link #MATCH_DISABLED_COMPONENTS},
4171     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4172     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4173     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4174     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4175     *            returned. The most important is {@link #MATCH_DEFAULT_ONLY},
4176     *            to limit the resolution to only those activities that support
4177     *            the {@link android.content.Intent#CATEGORY_DEFAULT}.
4178     * @return Returns a List of ResolveInfo objects containing one entry for
4179     *         each matching activity. The list is ordered first by all of the
4180     *         intents resolved in <var>specifics</var> and then any additional
4181     *         activities that can handle <var>intent</var> but did not get
4182     *         included by one of the <var>specifics</var> intents. If there are
4183     *         no matching activities, an empty list is returned.
4184     * @see #GET_META_DATA
4185     * @see #GET_RESOLVED_FILTER
4186     * @see #GET_SHARED_LIBRARY_FILES
4187     * @see #MATCH_ALL
4188     * @see #MATCH_DISABLED_COMPONENTS
4189     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4190     * @see #MATCH_DEFAULT_ONLY
4191     * @see #MATCH_DIRECT_BOOT_AWARE
4192     * @see #MATCH_DIRECT_BOOT_UNAWARE
4193     * @see #MATCH_SYSTEM_ONLY
4194     * @see #MATCH_UNINSTALLED_PACKAGES
4195     */
4196    public abstract List<ResolveInfo> queryIntentActivityOptions(
4197            ComponentName caller, Intent[] specifics, Intent intent, @ResolveInfoFlags int flags);
4198
4199    /**
4200     * Retrieve all receivers that can handle a broadcast of the given intent.
4201     *
4202     * @param intent The desired intent as per resolveActivity().
4203     * @param flags Additional option flags. Use any combination of
4204     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4205     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4206     *            {@link #MATCH_DISABLED_COMPONENTS},
4207     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4208     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4209     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4210     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4211     *            returned.
4212     * @return Returns a List of ResolveInfo objects containing one entry for
4213     *         each matching receiver, ordered from best to worst. If there are
4214     *         no matching receivers, an empty list or null is returned.
4215     * @see #GET_META_DATA
4216     * @see #GET_RESOLVED_FILTER
4217     * @see #GET_SHARED_LIBRARY_FILES
4218     * @see #MATCH_ALL
4219     * @see #MATCH_DISABLED_COMPONENTS
4220     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4221     * @see #MATCH_DEFAULT_ONLY
4222     * @see #MATCH_DIRECT_BOOT_AWARE
4223     * @see #MATCH_DIRECT_BOOT_UNAWARE
4224     * @see #MATCH_SYSTEM_ONLY
4225     * @see #MATCH_UNINSTALLED_PACKAGES
4226     */
4227    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
4228            @ResolveInfoFlags int flags);
4229
4230    /**
4231     * Retrieve all receivers that can handle a broadcast of the given intent,
4232     * for a specific user.
4233     *
4234     * @param intent The desired intent as per resolveActivity().
4235     * @param flags Additional option flags. Use any combination of
4236     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4237     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4238     *            {@link #MATCH_DISABLED_COMPONENTS},
4239     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4240     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4241     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4242     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4243     *            returned.
4244     * @param userHandle UserHandle of the user being queried.
4245     * @return Returns a List of ResolveInfo objects containing one entry for
4246     *         each matching receiver, ordered from best to worst. If there are
4247     *         no matching receivers, an empty list or null is returned.
4248     * @see #GET_META_DATA
4249     * @see #GET_RESOLVED_FILTER
4250     * @see #GET_SHARED_LIBRARY_FILES
4251     * @see #MATCH_ALL
4252     * @see #MATCH_DISABLED_COMPONENTS
4253     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4254     * @see #MATCH_DEFAULT_ONLY
4255     * @see #MATCH_DIRECT_BOOT_AWARE
4256     * @see #MATCH_DIRECT_BOOT_UNAWARE
4257     * @see #MATCH_SYSTEM_ONLY
4258     * @see #MATCH_UNINSTALLED_PACKAGES
4259     * @hide
4260     */
4261    @SystemApi
4262    public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent,
4263            @ResolveInfoFlags int flags, UserHandle userHandle) {
4264        return queryBroadcastReceiversAsUser(intent, flags, userHandle.getIdentifier());
4265    }
4266
4267    /**
4268     * @hide
4269     */
4270    public abstract List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent,
4271            @ResolveInfoFlags int flags, @UserIdInt int userId);
4272
4273
4274    /** {@hide} */
4275    @Deprecated
4276    public List<ResolveInfo> queryBroadcastReceivers(Intent intent,
4277            @ResolveInfoFlags int flags, @UserIdInt int userId) {
4278        final String msg = "Shame on you for calling the hidden API "
4279                + "queryBroadcastReceivers(). Shame!";
4280        if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.O) {
4281            throw new UnsupportedOperationException(msg);
4282        } else {
4283            Log.d(TAG, msg);
4284            return queryBroadcastReceiversAsUser(intent, flags, userId);
4285        }
4286    }
4287
4288    /**
4289     * Determine the best service to handle for a given Intent.
4290     *
4291     * @param intent An intent containing all of the desired specification
4292     *            (action, data, type, category, and/or component).
4293     * @param flags Additional option flags. Use any combination of
4294     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4295     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4296     *            {@link #MATCH_DISABLED_COMPONENTS},
4297     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4298     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4299     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4300     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4301     *            returned.
4302     * @return Returns a ResolveInfo object containing the final service intent
4303     *         that was determined to be the best action. Returns null if no
4304     *         matching service was found.
4305     * @see #GET_META_DATA
4306     * @see #GET_RESOLVED_FILTER
4307     * @see #GET_SHARED_LIBRARY_FILES
4308     * @see #MATCH_ALL
4309     * @see #MATCH_DISABLED_COMPONENTS
4310     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4311     * @see #MATCH_DEFAULT_ONLY
4312     * @see #MATCH_DIRECT_BOOT_AWARE
4313     * @see #MATCH_DIRECT_BOOT_UNAWARE
4314     * @see #MATCH_SYSTEM_ONLY
4315     * @see #MATCH_UNINSTALLED_PACKAGES
4316     */
4317    public abstract ResolveInfo resolveService(Intent intent, @ResolveInfoFlags int flags);
4318
4319    /**
4320     * Retrieve all services that can match the given intent.
4321     *
4322     * @param intent The desired intent as per resolveService().
4323     * @param flags Additional option flags. Use any combination of
4324     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4325     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4326     *            {@link #MATCH_DISABLED_COMPONENTS},
4327     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4328     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4329     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4330     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4331     *            returned.
4332     * @return Returns a List of ResolveInfo objects containing one entry for
4333     *         each matching service, ordered from best to worst. In other
4334     *         words, the first item is what would be returned by
4335     *         {@link #resolveService}. If there are no matching services, an
4336     *         empty list or null is returned.
4337     * @see #GET_META_DATA
4338     * @see #GET_RESOLVED_FILTER
4339     * @see #GET_SHARED_LIBRARY_FILES
4340     * @see #MATCH_ALL
4341     * @see #MATCH_DISABLED_COMPONENTS
4342     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4343     * @see #MATCH_DEFAULT_ONLY
4344     * @see #MATCH_DIRECT_BOOT_AWARE
4345     * @see #MATCH_DIRECT_BOOT_UNAWARE
4346     * @see #MATCH_SYSTEM_ONLY
4347     * @see #MATCH_UNINSTALLED_PACKAGES
4348     */
4349    public abstract List<ResolveInfo> queryIntentServices(Intent intent,
4350            @ResolveInfoFlags int flags);
4351
4352    /**
4353     * Retrieve all services that can match the given intent for a given user.
4354     *
4355     * @param intent The desired intent as per resolveService().
4356     * @param flags Additional option flags. Use any combination of
4357     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4358     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4359     *            {@link #MATCH_DISABLED_COMPONENTS},
4360     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4361     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4362     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4363     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4364     *            returned.
4365     * @param userId The user id.
4366     * @return Returns a List of ResolveInfo objects containing one entry for
4367     *         each matching service, ordered from best to worst. In other
4368     *         words, the first item is what would be returned by
4369     *         {@link #resolveService}. If there are no matching services, an
4370     *         empty list or null is returned.
4371     * @see #GET_META_DATA
4372     * @see #GET_RESOLVED_FILTER
4373     * @see #GET_SHARED_LIBRARY_FILES
4374     * @see #MATCH_ALL
4375     * @see #MATCH_DISABLED_COMPONENTS
4376     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4377     * @see #MATCH_DEFAULT_ONLY
4378     * @see #MATCH_DIRECT_BOOT_AWARE
4379     * @see #MATCH_DIRECT_BOOT_UNAWARE
4380     * @see #MATCH_SYSTEM_ONLY
4381     * @see #MATCH_UNINSTALLED_PACKAGES
4382     * @hide
4383     */
4384    public abstract List<ResolveInfo> queryIntentServicesAsUser(Intent intent,
4385            @ResolveInfoFlags int flags, @UserIdInt int userId);
4386
4387    /**
4388     * Retrieve all providers that can match the given intent.
4389     *
4390     * @param intent An intent containing all of the desired specification
4391     *            (action, data, type, category, and/or component).
4392     * @param flags Additional option flags. Use any combination of
4393     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4394     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4395     *            {@link #MATCH_DISABLED_COMPONENTS},
4396     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4397     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4398     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4399     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4400     *            returned.
4401     * @param userId The user id.
4402     * @return Returns a List of ResolveInfo objects containing one entry for
4403     *         each matching provider, ordered from best to worst. If there are
4404     *         no matching services, an empty list or null is returned.
4405     * @see #GET_META_DATA
4406     * @see #GET_RESOLVED_FILTER
4407     * @see #GET_SHARED_LIBRARY_FILES
4408     * @see #MATCH_ALL
4409     * @see #MATCH_DISABLED_COMPONENTS
4410     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4411     * @see #MATCH_DEFAULT_ONLY
4412     * @see #MATCH_DIRECT_BOOT_AWARE
4413     * @see #MATCH_DIRECT_BOOT_UNAWARE
4414     * @see #MATCH_SYSTEM_ONLY
4415     * @see #MATCH_UNINSTALLED_PACKAGES
4416     * @hide
4417     */
4418    public abstract List<ResolveInfo> queryIntentContentProvidersAsUser(
4419            Intent intent, @ResolveInfoFlags int flags, @UserIdInt int userId);
4420
4421    /**
4422     * Retrieve all providers that can match the given intent.
4423     *
4424     * @param intent An intent containing all of the desired specification
4425     *            (action, data, type, category, and/or component).
4426     * @param flags Additional option flags. Use any combination of
4427     *            {@link #GET_META_DATA}, {@link #GET_RESOLVED_FILTER},
4428     *            {@link #GET_SHARED_LIBRARY_FILES}, {@link #MATCH_ALL},
4429     *            {@link #MATCH_DISABLED_COMPONENTS},
4430     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4431     *            {@link #MATCH_DEFAULT_ONLY}, {@link #MATCH_DIRECT_BOOT_AWARE},
4432     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4433     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4434     *            returned.
4435     * @return Returns a List of ResolveInfo objects containing one entry for
4436     *         each matching provider, ordered from best to worst. If there are
4437     *         no matching services, an empty list or null is returned.
4438     * @see #GET_META_DATA
4439     * @see #GET_RESOLVED_FILTER
4440     * @see #GET_SHARED_LIBRARY_FILES
4441     * @see #MATCH_ALL
4442     * @see #MATCH_DISABLED_COMPONENTS
4443     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4444     * @see #MATCH_DEFAULT_ONLY
4445     * @see #MATCH_DIRECT_BOOT_AWARE
4446     * @see #MATCH_DIRECT_BOOT_UNAWARE
4447     * @see #MATCH_SYSTEM_ONLY
4448     * @see #MATCH_UNINSTALLED_PACKAGES
4449     */
4450    public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent,
4451            @ResolveInfoFlags int flags);
4452
4453    /**
4454     * Find a single content provider by its base path name.
4455     *
4456     * @param name The name of the provider to find.
4457     * @param flags Additional option flags. Use any combination of
4458     *            {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
4459     *            {@link #MATCH_ALL}, {@link #MATCH_DEFAULT_ONLY},
4460     *            {@link #MATCH_DISABLED_COMPONENTS},
4461     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4462     *            {@link #MATCH_DIRECT_BOOT_AWARE},
4463     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4464     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4465     *            returned.
4466     * @return A {@link ProviderInfo} object containing information about the
4467     *         provider. If a provider was not found, returns null.
4468     * @see #GET_META_DATA
4469     * @see #GET_SHARED_LIBRARY_FILES
4470     * @see #MATCH_ALL
4471     * @see #MATCH_DEBUG_TRIAGED_MISSING
4472     * @see #MATCH_DEFAULT_ONLY
4473     * @see #MATCH_DISABLED_COMPONENTS
4474     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4475     * @see #MATCH_DIRECT_BOOT_AWARE
4476     * @see #MATCH_DIRECT_BOOT_UNAWARE
4477     * @see #MATCH_SYSTEM_ONLY
4478     * @see #MATCH_UNINSTALLED_PACKAGES
4479     */
4480    public abstract ProviderInfo resolveContentProvider(String name,
4481            @ComponentInfoFlags int flags);
4482
4483    /**
4484     * Find a single content provider by its base path name.
4485     *
4486     * @param name The name of the provider to find.
4487     * @param flags Additional option flags. Use any combination of
4488     *            {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
4489     *            {@link #MATCH_ALL}, {@link #MATCH_DEFAULT_ONLY},
4490     *            {@link #MATCH_DISABLED_COMPONENTS},
4491     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4492     *            {@link #MATCH_DIRECT_BOOT_AWARE},
4493     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4494     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4495     *            returned.
4496     * @param userId The user id.
4497     * @return A {@link ProviderInfo} object containing information about the
4498     *         provider. If a provider was not found, returns null.
4499     * @see #GET_META_DATA
4500     * @see #GET_SHARED_LIBRARY_FILES
4501     * @see #MATCH_ALL
4502     * @see #MATCH_DEBUG_TRIAGED_MISSING
4503     * @see #MATCH_DEFAULT_ONLY
4504     * @see #MATCH_DISABLED_COMPONENTS
4505     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4506     * @see #MATCH_DIRECT_BOOT_AWARE
4507     * @see #MATCH_DIRECT_BOOT_UNAWARE
4508     * @see #MATCH_SYSTEM_ONLY
4509     * @see #MATCH_UNINSTALLED_PACKAGES
4510     * @hide
4511     */
4512    public abstract ProviderInfo resolveContentProviderAsUser(String name,
4513            @ComponentInfoFlags int flags, @UserIdInt int userId);
4514
4515    /**
4516     * Retrieve content provider information.
4517     * <p>
4518     * <em>Note: unlike most other methods, an empty result set is indicated
4519     * by a null return instead of an empty list.</em>
4520     *
4521     * @param processName If non-null, limits the returned providers to only
4522     *            those that are hosted by the given process. If null, all
4523     *            content providers are returned.
4524     * @param uid If <var>processName</var> is non-null, this is the required
4525     *            uid owning the requested content providers.
4526     * @param flags Additional option flags. Use any combination of
4527     *            {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
4528     *            {@link #MATCH_ALL}, {@link #MATCH_DEFAULT_ONLY},
4529     *            {@link #MATCH_DISABLED_COMPONENTS},
4530     *            {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
4531     *            {@link #MATCH_DIRECT_BOOT_AWARE},
4532     *            {@link #MATCH_DIRECT_BOOT_UNAWARE}, {@link #MATCH_SYSTEM_ONLY}
4533     *            or {@link #MATCH_UNINSTALLED_PACKAGES} to modify the data
4534     *            returned.
4535     * @return A list of {@link ProviderInfo} objects containing one entry for
4536     *         each provider either matching <var>processName</var> or, if
4537     *         <var>processName</var> is null, all known content providers.
4538     *         <em>If there are no matching providers, null is returned.</em>
4539     * @see #GET_META_DATA
4540     * @see #GET_SHARED_LIBRARY_FILES
4541     * @see #MATCH_ALL
4542     * @see #MATCH_DEBUG_TRIAGED_MISSING
4543     * @see #MATCH_DEFAULT_ONLY
4544     * @see #MATCH_DISABLED_COMPONENTS
4545     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
4546     * @see #MATCH_DIRECT_BOOT_AWARE
4547     * @see #MATCH_DIRECT_BOOT_UNAWARE
4548     * @see #MATCH_SYSTEM_ONLY
4549     * @see #MATCH_UNINSTALLED_PACKAGES
4550     */
4551    public abstract List<ProviderInfo> queryContentProviders(
4552            String processName, int uid, @ComponentInfoFlags int flags);
4553
4554    /**
4555     * Same as {@link #queryContentProviders}, except when {@code metaDataKey} is not null,
4556     * it only returns providers which have metadata with the {@code metaDataKey} key.
4557     *
4558     * <p>DO NOT USE the {@code metaDataKey} parameter, unless you're the contacts provider.
4559     * You really shouldn't need it.  Other apps should use {@link #queryIntentContentProviders}
4560     * instead.
4561     *
4562     * <p>The {@code metaDataKey} parameter was added to allow the contacts provider to quickly
4563     * scan the GAL providers on the device.  Unfortunately the discovery protocol used metadata
4564     * to mark GAL providers, rather than intent filters, so we can't use
4565     * {@link #queryIntentContentProviders} for that.
4566     *
4567     * @hide
4568     */
4569    public List<ProviderInfo> queryContentProviders(
4570            String processName, int uid, @ComponentInfoFlags int flags, String metaDataKey) {
4571        // Provide the default implementation for mocks.
4572        return queryContentProviders(processName, uid, flags);
4573    }
4574
4575    /**
4576     * Retrieve all of the information we know about a particular
4577     * instrumentation class.
4578     *
4579     * @param className The full name (i.e.
4580     *                  com.google.apps.contacts.InstrumentList) of an
4581     *                  Instrumentation class.
4582     * @param flags Additional option flags. Use any combination of
4583     *         {@link #GET_META_DATA}
4584     *         to modify the data returned.
4585     *
4586     * @return An {@link InstrumentationInfo} object containing information about the
4587     *         instrumentation.
4588     * @throws NameNotFoundException if a package with the given name cannot be
4589     *             found on the system.
4590     *
4591     * @see #GET_META_DATA
4592     */
4593    public abstract InstrumentationInfo getInstrumentationInfo(ComponentName className,
4594            @InstrumentationInfoFlags int flags) throws NameNotFoundException;
4595
4596    /**
4597     * Retrieve information about available instrumentation code.  May be used
4598     * to retrieve either all instrumentation code, or only the code targeting
4599     * a particular package.
4600     *
4601     * @param targetPackage If null, all instrumentation is returned; only the
4602     *                      instrumentation targeting this package name is
4603     *                      returned.
4604     * @param flags Additional option flags. Use any combination of
4605     *         {@link #GET_META_DATA}
4606     *         to modify the data returned.
4607     *
4608     * @return A list of {@link InstrumentationInfo} objects containing one
4609     *         entry for each matching instrumentation. If there are no
4610     *         instrumentation available, returns an empty list.
4611     *
4612     * @see #GET_META_DATA
4613     */
4614    public abstract List<InstrumentationInfo> queryInstrumentation(String targetPackage,
4615            @InstrumentationInfoFlags int flags);
4616
4617    /**
4618     * Retrieve an image from a package.  This is a low-level API used by
4619     * the various package manager info structures (such as
4620     * {@link ComponentInfo} to implement retrieval of their associated
4621     * icon.
4622     *
4623     * @param packageName The name of the package that this icon is coming from.
4624     * Cannot be null.
4625     * @param resid The resource identifier of the desired image.  Cannot be 0.
4626     * @param appInfo Overall information about <var>packageName</var>.  This
4627     * may be null, in which case the application information will be retrieved
4628     * for you if needed; if you already have this information around, it can
4629     * be much more efficient to supply it here.
4630     *
4631     * @return Returns a Drawable holding the requested image.  Returns null if
4632     * an image could not be found for any reason.
4633     */
4634    public abstract Drawable getDrawable(String packageName, @DrawableRes int resid,
4635            ApplicationInfo appInfo);
4636
4637    /**
4638     * Retrieve the icon associated with an activity.  Given the full name of
4639     * an activity, retrieves the information about it and calls
4640     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its icon.
4641     * If the activity cannot be found, NameNotFoundException is thrown.
4642     *
4643     * @param activityName Name of the activity whose icon is to be retrieved.
4644     *
4645     * @return Returns the image of the icon, or the default activity icon if
4646     * it could not be found.  Does not return null.
4647     * @throws NameNotFoundException Thrown if the resources for the given
4648     * activity could not be loaded.
4649     *
4650     * @see #getActivityIcon(Intent)
4651     */
4652    public abstract Drawable getActivityIcon(ComponentName activityName)
4653            throws NameNotFoundException;
4654
4655    /**
4656     * Retrieve the icon associated with an Intent.  If intent.getClassName() is
4657     * set, this simply returns the result of
4658     * getActivityIcon(intent.getClassName()).  Otherwise it resolves the intent's
4659     * component and returns the icon associated with the resolved component.
4660     * If intent.getClassName() cannot be found or the Intent cannot be resolved
4661     * to a component, NameNotFoundException is thrown.
4662     *
4663     * @param intent The intent for which you would like to retrieve an icon.
4664     *
4665     * @return Returns the image of the icon, or the default activity icon if
4666     * it could not be found.  Does not return null.
4667     * @throws NameNotFoundException Thrown if the resources for application
4668     * matching the given intent could not be loaded.
4669     *
4670     * @see #getActivityIcon(ComponentName)
4671     */
4672    public abstract Drawable getActivityIcon(Intent intent)
4673            throws NameNotFoundException;
4674
4675    /**
4676     * Retrieve the banner associated with an activity. Given the full name of
4677     * an activity, retrieves the information about it and calls
4678     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its
4679     * banner. If the activity cannot be found, NameNotFoundException is thrown.
4680     *
4681     * @param activityName Name of the activity whose banner is to be retrieved.
4682     * @return Returns the image of the banner, or null if the activity has no
4683     *         banner specified.
4684     * @throws NameNotFoundException Thrown if the resources for the given
4685     *             activity could not be loaded.
4686     * @see #getActivityBanner(Intent)
4687     */
4688    public abstract Drawable getActivityBanner(ComponentName activityName)
4689            throws NameNotFoundException;
4690
4691    /**
4692     * Retrieve the banner associated with an Intent. If intent.getClassName()
4693     * is set, this simply returns the result of
4694     * getActivityBanner(intent.getClassName()). Otherwise it resolves the
4695     * intent's component and returns the banner associated with the resolved
4696     * component. If intent.getClassName() cannot be found or the Intent cannot
4697     * be resolved to a component, NameNotFoundException is thrown.
4698     *
4699     * @param intent The intent for which you would like to retrieve a banner.
4700     * @return Returns the image of the banner, or null if the activity has no
4701     *         banner specified.
4702     * @throws NameNotFoundException Thrown if the resources for application
4703     *             matching the given intent could not be loaded.
4704     * @see #getActivityBanner(ComponentName)
4705     */
4706    public abstract Drawable getActivityBanner(Intent intent)
4707            throws NameNotFoundException;
4708
4709    /**
4710     * Return the generic icon for an activity that is used when no specific
4711     * icon is defined.
4712     *
4713     * @return Drawable Image of the icon.
4714     */
4715    public abstract Drawable getDefaultActivityIcon();
4716
4717    /**
4718     * Retrieve the icon associated with an application.  If it has not defined
4719     * an icon, the default app icon is returned.  Does not return null.
4720     *
4721     * @param info Information about application being queried.
4722     *
4723     * @return Returns the image of the icon, or the default application icon
4724     * if it could not be found.
4725     *
4726     * @see #getApplicationIcon(String)
4727     */
4728    public abstract Drawable getApplicationIcon(ApplicationInfo info);
4729
4730    /**
4731     * Retrieve the icon associated with an application.  Given the name of the
4732     * application's package, retrieves the information about it and calls
4733     * getApplicationIcon() to return its icon. If the application cannot be
4734     * found, NameNotFoundException is thrown.
4735     *
4736     * @param packageName Name of the package whose application icon is to be
4737     *                    retrieved.
4738     *
4739     * @return Returns the image of the icon, or the default application icon
4740     * if it could not be found.  Does not return null.
4741     * @throws NameNotFoundException Thrown if the resources for the given
4742     * application could not be loaded.
4743     *
4744     * @see #getApplicationIcon(ApplicationInfo)
4745     */
4746    public abstract Drawable getApplicationIcon(String packageName)
4747            throws NameNotFoundException;
4748
4749    /**
4750     * Retrieve the banner associated with an application.
4751     *
4752     * @param info Information about application being queried.
4753     * @return Returns the image of the banner or null if the application has no
4754     *         banner specified.
4755     * @see #getApplicationBanner(String)
4756     */
4757    public abstract Drawable getApplicationBanner(ApplicationInfo info);
4758
4759    /**
4760     * Retrieve the banner associated with an application. Given the name of the
4761     * application's package, retrieves the information about it and calls
4762     * getApplicationIcon() to return its banner. If the application cannot be
4763     * found, NameNotFoundException is thrown.
4764     *
4765     * @param packageName Name of the package whose application banner is to be
4766     *            retrieved.
4767     * @return Returns the image of the banner or null if the application has no
4768     *         banner specified.
4769     * @throws NameNotFoundException Thrown if the resources for the given
4770     *             application could not be loaded.
4771     * @see #getApplicationBanner(ApplicationInfo)
4772     */
4773    public abstract Drawable getApplicationBanner(String packageName)
4774            throws NameNotFoundException;
4775
4776    /**
4777     * Retrieve the logo associated with an activity. Given the full name of an
4778     * activity, retrieves the information about it and calls
4779     * {@link ComponentInfo#loadLogo ComponentInfo.loadLogo()} to return its
4780     * logo. If the activity cannot be found, NameNotFoundException is thrown.
4781     *
4782     * @param activityName Name of the activity whose logo is to be retrieved.
4783     * @return Returns the image of the logo or null if the activity has no logo
4784     *         specified.
4785     * @throws NameNotFoundException Thrown if the resources for the given
4786     *             activity could not be loaded.
4787     * @see #getActivityLogo(Intent)
4788     */
4789    public abstract Drawable getActivityLogo(ComponentName activityName)
4790            throws NameNotFoundException;
4791
4792    /**
4793     * Retrieve the logo associated with an Intent.  If intent.getClassName() is
4794     * set, this simply returns the result of
4795     * getActivityLogo(intent.getClassName()).  Otherwise it resolves the intent's
4796     * component and returns the logo associated with the resolved component.
4797     * If intent.getClassName() cannot be found or the Intent cannot be resolved
4798     * to a component, NameNotFoundException is thrown.
4799     *
4800     * @param intent The intent for which you would like to retrieve a logo.
4801     *
4802     * @return Returns the image of the logo, or null if the activity has no
4803     * logo specified.
4804     *
4805     * @throws NameNotFoundException Thrown if the resources for application
4806     * matching the given intent could not be loaded.
4807     *
4808     * @see #getActivityLogo(ComponentName)
4809     */
4810    public abstract Drawable getActivityLogo(Intent intent)
4811            throws NameNotFoundException;
4812
4813    /**
4814     * Retrieve the logo associated with an application.  If it has not specified
4815     * a logo, this method returns null.
4816     *
4817     * @param info Information about application being queried.
4818     *
4819     * @return Returns the image of the logo, or null if no logo is specified
4820     * by the application.
4821     *
4822     * @see #getApplicationLogo(String)
4823     */
4824    public abstract Drawable getApplicationLogo(ApplicationInfo info);
4825
4826    /**
4827     * Retrieve the logo associated with an application.  Given the name of the
4828     * application's package, retrieves the information about it and calls
4829     * getApplicationLogo() to return its logo. If the application cannot be
4830     * found, NameNotFoundException is thrown.
4831     *
4832     * @param packageName Name of the package whose application logo is to be
4833     *                    retrieved.
4834     *
4835     * @return Returns the image of the logo, or null if no application logo
4836     * has been specified.
4837     *
4838     * @throws NameNotFoundException Thrown if the resources for the given
4839     * application could not be loaded.
4840     *
4841     * @see #getApplicationLogo(ApplicationInfo)
4842     */
4843    public abstract Drawable getApplicationLogo(String packageName)
4844            throws NameNotFoundException;
4845
4846    /**
4847     * If the target user is a managed profile, then this returns a badged copy of the given icon
4848     * to be able to distinguish it from the original icon. For badging an arbitrary drawable use
4849     * {@link #getUserBadgedDrawableForDensity(
4850     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
4851     * <p>
4852     * If the original drawable is a BitmapDrawable and the backing bitmap is
4853     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
4854     * is performed in place and the original drawable is returned.
4855     * </p>
4856     *
4857     * @param icon The icon to badge.
4858     * @param user The target user.
4859     * @return A drawable that combines the original icon and a badge as
4860     *         determined by the system.
4861     */
4862    public abstract Drawable getUserBadgedIcon(Drawable icon, UserHandle user);
4863
4864    /**
4865     * If the target user is a managed profile of the calling user or the caller
4866     * is itself a managed profile, then this returns a badged copy of the given
4867     * drawable allowing the user to distinguish it from the original drawable.
4868     * The caller can specify the location in the bounds of the drawable to be
4869     * badged where the badge should be applied as well as the density of the
4870     * badge to be used.
4871     * <p>
4872     * If the original drawable is a BitmapDrawable and the backing bitmap is
4873     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
4874     * is performed in place and the original drawable is returned.
4875     * </p>
4876     *
4877     * @param drawable The drawable to badge.
4878     * @param user The target user.
4879     * @param badgeLocation Where in the bounds of the badged drawable to place
4880     *         the badge. If it's {@code null}, the badge is applied on top of the entire
4881     *         drawable being badged.
4882     * @param badgeDensity The optional desired density for the badge as per
4883     *         {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
4884     *         the density of the display is used.
4885     * @return A drawable that combines the original drawable and a badge as
4886     *         determined by the system.
4887     */
4888    public abstract Drawable getUserBadgedDrawableForDensity(Drawable drawable,
4889            UserHandle user, Rect badgeLocation, int badgeDensity);
4890
4891    /**
4892     * If the target user is a managed profile of the calling user or the caller
4893     * is itself a managed profile, then this returns a drawable to use as a small
4894     * icon to include in a view to distinguish it from the original icon.
4895     *
4896     * @param user The target user.
4897     * @param density The optional desired density for the badge as per
4898     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided
4899     *         the density of the current display is used.
4900     * @return the drawable or null if no drawable is required.
4901     * @hide
4902     */
4903    public abstract Drawable getUserBadgeForDensity(UserHandle user, int density);
4904
4905    /**
4906     * If the target user is a managed profile of the calling user or the caller
4907     * is itself a managed profile, then this returns a drawable to use as a small
4908     * icon to include in a view to distinguish it from the original icon. This version
4909     * doesn't have background protection and should be used over a light background instead of
4910     * a badge.
4911     *
4912     * @param user The target user.
4913     * @param density The optional desired density for the badge as per
4914     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided
4915     *         the density of the current display is used.
4916     * @return the drawable or null if no drawable is required.
4917     * @hide
4918     */
4919    public abstract Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density);
4920
4921    /**
4922     * If the target user is a managed profile of the calling user or the caller
4923     * is itself a managed profile, then this returns a copy of the label with
4924     * badging for accessibility services like talkback. E.g. passing in "Email"
4925     * and it might return "Work Email" for Email in the work profile.
4926     *
4927     * @param label The label to change.
4928     * @param user The target user.
4929     * @return A label that combines the original label and a badge as
4930     *         determined by the system.
4931     */
4932    public abstract CharSequence getUserBadgedLabel(CharSequence label, UserHandle user);
4933
4934    /**
4935     * Retrieve text from a package.  This is a low-level API used by
4936     * the various package manager info structures (such as
4937     * {@link ComponentInfo} to implement retrieval of their associated
4938     * labels and other text.
4939     *
4940     * @param packageName The name of the package that this text is coming from.
4941     * Cannot be null.
4942     * @param resid The resource identifier of the desired text.  Cannot be 0.
4943     * @param appInfo Overall information about <var>packageName</var>.  This
4944     * may be null, in which case the application information will be retrieved
4945     * for you if needed; if you already have this information around, it can
4946     * be much more efficient to supply it here.
4947     *
4948     * @return Returns a CharSequence holding the requested text.  Returns null
4949     * if the text could not be found for any reason.
4950     */
4951    public abstract CharSequence getText(String packageName, @StringRes int resid,
4952            ApplicationInfo appInfo);
4953
4954    /**
4955     * Retrieve an XML file from a package.  This is a low-level API used to
4956     * retrieve XML meta data.
4957     *
4958     * @param packageName The name of the package that this xml is coming from.
4959     * Cannot be null.
4960     * @param resid The resource identifier of the desired xml.  Cannot be 0.
4961     * @param appInfo Overall information about <var>packageName</var>.  This
4962     * may be null, in which case the application information will be retrieved
4963     * for you if needed; if you already have this information around, it can
4964     * be much more efficient to supply it here.
4965     *
4966     * @return Returns an XmlPullParser allowing you to parse out the XML
4967     * data.  Returns null if the xml resource could not be found for any
4968     * reason.
4969     */
4970    public abstract XmlResourceParser getXml(String packageName, @XmlRes int resid,
4971            ApplicationInfo appInfo);
4972
4973    /**
4974     * Return the label to use for this application.
4975     *
4976     * @return Returns the label associated with this application, or null if
4977     * it could not be found for any reason.
4978     * @param info The application to get the label of.
4979     */
4980    public abstract CharSequence getApplicationLabel(ApplicationInfo info);
4981
4982    /**
4983     * Retrieve the resources associated with an activity.  Given the full
4984     * name of an activity, retrieves the information about it and calls
4985     * getResources() to return its application's resources.  If the activity
4986     * cannot be found, NameNotFoundException is thrown.
4987     *
4988     * @param activityName Name of the activity whose resources are to be
4989     *                     retrieved.
4990     *
4991     * @return Returns the application's Resources.
4992     * @throws NameNotFoundException Thrown if the resources for the given
4993     * application could not be loaded.
4994     *
4995     * @see #getResourcesForApplication(ApplicationInfo)
4996     */
4997    public abstract Resources getResourcesForActivity(ComponentName activityName)
4998            throws NameNotFoundException;
4999
5000    /**
5001     * Retrieve the resources for an application.  Throws NameNotFoundException
5002     * if the package is no longer installed.
5003     *
5004     * @param app Information about the desired application.
5005     *
5006     * @return Returns the application's Resources.
5007     * @throws NameNotFoundException Thrown if the resources for the given
5008     * application could not be loaded (most likely because it was uninstalled).
5009     */
5010    public abstract Resources getResourcesForApplication(ApplicationInfo app)
5011            throws NameNotFoundException;
5012
5013    /**
5014     * Retrieve the resources associated with an application.  Given the full
5015     * package name of an application, retrieves the information about it and
5016     * calls getResources() to return its application's resources.  If the
5017     * appPackageName cannot be found, NameNotFoundException is thrown.
5018     *
5019     * @param appPackageName Package name of the application whose resources
5020     *                       are to be retrieved.
5021     *
5022     * @return Returns the application's Resources.
5023     * @throws NameNotFoundException Thrown if the resources for the given
5024     * application could not be loaded.
5025     *
5026     * @see #getResourcesForApplication(ApplicationInfo)
5027     */
5028    public abstract Resources getResourcesForApplication(String appPackageName)
5029            throws NameNotFoundException;
5030
5031    /** @hide */
5032    public abstract Resources getResourcesForApplicationAsUser(String appPackageName,
5033            @UserIdInt int userId) throws NameNotFoundException;
5034
5035    /**
5036     * Retrieve overall information about an application package defined
5037     * in a package archive file
5038     *
5039     * @param archiveFilePath The path to the archive file
5040     * @param flags Additional option flags. Use any combination of
5041     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
5042     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
5043     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
5044     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
5045     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
5046     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
5047     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
5048     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
5049     *         {@link #MATCH_UNINSTALLED_PACKAGES}
5050     *         to modify the data returned.
5051     *
5052     * @return A PackageInfo object containing information about the
5053     *         package archive. If the package could not be parsed,
5054     *         returns null.
5055     *
5056     * @see #GET_ACTIVITIES
5057     * @see #GET_CONFIGURATIONS
5058     * @see #GET_GIDS
5059     * @see #GET_INSTRUMENTATION
5060     * @see #GET_INTENT_FILTERS
5061     * @see #GET_META_DATA
5062     * @see #GET_PERMISSIONS
5063     * @see #GET_PROVIDERS
5064     * @see #GET_RECEIVERS
5065     * @see #GET_SERVICES
5066     * @see #GET_SHARED_LIBRARY_FILES
5067     * @see #GET_SIGNATURES
5068     * @see #GET_URI_PERMISSION_PATTERNS
5069     * @see #MATCH_DISABLED_COMPONENTS
5070     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
5071     * @see #MATCH_UNINSTALLED_PACKAGES
5072     *
5073     */
5074    public PackageInfo getPackageArchiveInfo(String archiveFilePath, @PackageInfoFlags int flags) {
5075        final PackageParser parser = new PackageParser();
5076        parser.setCallback(new PackageParser.CallbackImpl(this));
5077        final File apkFile = new File(archiveFilePath);
5078        try {
5079            if ((flags & (MATCH_DIRECT_BOOT_UNAWARE | MATCH_DIRECT_BOOT_AWARE)) != 0) {
5080                // Caller expressed an explicit opinion about what encryption
5081                // aware/unaware components they want to see, so fall through and
5082                // give them what they want
5083            } else {
5084                // Caller expressed no opinion, so match everything
5085                flags |= MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE;
5086            }
5087
5088            PackageParser.Package pkg = parser.parseMonolithicPackage(apkFile, 0);
5089            if ((flags & GET_SIGNATURES) != 0) {
5090                PackageParser.collectCertificates(pkg, 0);
5091            }
5092            PackageUserState state = new PackageUserState();
5093            return PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, state);
5094        } catch (PackageParserException e) {
5095            return null;
5096        }
5097    }
5098
5099    /**
5100     * @deprecated replaced by {@link PackageInstaller}
5101     * @hide
5102     */
5103    @Deprecated
5104    public abstract void installPackage(
5105            Uri packageURI,
5106            IPackageInstallObserver observer,
5107            @InstallFlags int flags,
5108            String installerPackageName);
5109    /**
5110     * @deprecated replaced by {@link PackageInstaller}
5111     * @hide
5112     */
5113    @Deprecated
5114    public abstract void installPackage(
5115            Uri packageURI,
5116            PackageInstallObserver observer,
5117            @InstallFlags int flags,
5118            String installerPackageName);
5119
5120    /**
5121     * If there is already an application with the given package name installed
5122     * on the system for other users, also install it for the calling user.
5123     * @hide
5124     */
5125    public abstract int installExistingPackage(String packageName) throws NameNotFoundException;
5126
5127    /**
5128     * If there is already an application with the given package name installed
5129     * on the system for other users, also install it for the specified user.
5130     * @hide
5131     */
5132     @RequiresPermission(anyOf = {
5133            Manifest.permission.INSTALL_PACKAGES,
5134            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5135    public abstract int installExistingPackageAsUser(String packageName, @UserIdInt int userId)
5136            throws NameNotFoundException;
5137
5138    /**
5139     * Allows a package listening to the
5140     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
5141     * broadcast} to respond to the package manager. The response must include
5142     * the {@code verificationCode} which is one of
5143     * {@link PackageManager#VERIFICATION_ALLOW} or
5144     * {@link PackageManager#VERIFICATION_REJECT}.
5145     *
5146     * @param id pending package identifier as passed via the
5147     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
5148     * @param verificationCode either {@link PackageManager#VERIFICATION_ALLOW}
5149     *            or {@link PackageManager#VERIFICATION_REJECT}.
5150     * @throws SecurityException if the caller does not have the
5151     *            PACKAGE_VERIFICATION_AGENT permission.
5152     */
5153    public abstract void verifyPendingInstall(int id, int verificationCode);
5154
5155    /**
5156     * Allows a package listening to the
5157     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
5158     * broadcast} to extend the default timeout for a response and declare what
5159     * action to perform after the timeout occurs. The response must include
5160     * the {@code verificationCodeAtTimeout} which is one of
5161     * {@link PackageManager#VERIFICATION_ALLOW} or
5162     * {@link PackageManager#VERIFICATION_REJECT}.
5163     *
5164     * This method may only be called once per package id. Additional calls
5165     * will have no effect.
5166     *
5167     * @param id pending package identifier as passed via the
5168     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
5169     * @param verificationCodeAtTimeout either
5170     *            {@link PackageManager#VERIFICATION_ALLOW} or
5171     *            {@link PackageManager#VERIFICATION_REJECT}. If
5172     *            {@code verificationCodeAtTimeout} is neither
5173     *            {@link PackageManager#VERIFICATION_ALLOW} or
5174     *            {@link PackageManager#VERIFICATION_REJECT}, then
5175     *            {@code verificationCodeAtTimeout} will default to
5176     *            {@link PackageManager#VERIFICATION_REJECT}.
5177     * @param millisecondsToDelay the amount of time requested for the timeout.
5178     *            Must be positive and less than
5179     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}. If
5180     *            {@code millisecondsToDelay} is out of bounds,
5181     *            {@code millisecondsToDelay} will be set to the closest in
5182     *            bounds value; namely, 0 or
5183     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}.
5184     * @throws SecurityException if the caller does not have the
5185     *            PACKAGE_VERIFICATION_AGENT permission.
5186     */
5187    public abstract void extendVerificationTimeout(int id,
5188            int verificationCodeAtTimeout, long millisecondsToDelay);
5189
5190    /**
5191     * Allows a package listening to the
5192     * {@link Intent#ACTION_INTENT_FILTER_NEEDS_VERIFICATION} intent filter verification
5193     * broadcast to respond to the package manager. The response must include
5194     * the {@code verificationCode} which is one of
5195     * {@link PackageManager#INTENT_FILTER_VERIFICATION_SUCCESS} or
5196     * {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}.
5197     *
5198     * @param verificationId pending package identifier as passed via the
5199     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
5200     * @param verificationCode either {@link PackageManager#INTENT_FILTER_VERIFICATION_SUCCESS}
5201     *            or {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}.
5202     * @param failedDomains a list of failed domains if the verificationCode is
5203     *            {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}, otherwise null;
5204     * @throws SecurityException if the caller does not have the
5205     *            INTENT_FILTER_VERIFICATION_AGENT permission.
5206     *
5207     * @hide
5208     */
5209    @SystemApi
5210    public abstract void verifyIntentFilter(int verificationId, int verificationCode,
5211            List<String> failedDomains);
5212
5213    /**
5214     * Get the status of a Domain Verification Result for an IntentFilter. This is
5215     * related to the {@link android.content.IntentFilter#setAutoVerify(boolean)} and
5216     * {@link android.content.IntentFilter#getAutoVerify()}
5217     *
5218     * This is used by the ResolverActivity to change the status depending on what the User select
5219     * in the Disambiguation Dialog and also used by the Settings App for changing the default App
5220     * for a domain.
5221     *
5222     * @param packageName The package name of the Activity associated with the IntentFilter.
5223     * @param userId The user id.
5224     *
5225     * @return The status to set to. This can be
5226     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK} or
5227     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS} or
5228     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER} or
5229     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED}
5230     *
5231     * @hide
5232     */
5233    @SystemApi
5234    public abstract int getIntentVerificationStatusAsUser(String packageName, @UserIdInt int userId);
5235
5236    /**
5237     * Allow to change the status of a Intent Verification status for all IntentFilter of an App.
5238     * This is related to the {@link android.content.IntentFilter#setAutoVerify(boolean)} and
5239     * {@link android.content.IntentFilter#getAutoVerify()}
5240     *
5241     * This is used by the ResolverActivity to change the status depending on what the User select
5242     * in the Disambiguation Dialog and also used by the Settings App for changing the default App
5243     * for a domain.
5244     *
5245     * @param packageName The package name of the Activity associated with the IntentFilter.
5246     * @param status The status to set to. This can be
5247     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK} or
5248     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS} or
5249     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER}
5250     * @param userId The user id.
5251     *
5252     * @return true if the status has been set. False otherwise.
5253     *
5254     * @hide
5255     */
5256    @SystemApi
5257    public abstract boolean updateIntentVerificationStatusAsUser(String packageName, int status,
5258            @UserIdInt int userId);
5259
5260    /**
5261     * Get the list of IntentFilterVerificationInfo for a specific package and User.
5262     *
5263     * @param packageName the package name. When this parameter is set to a non null value,
5264     *                    the results will be filtered by the package name provided.
5265     *                    Otherwise, there will be no filtering and it will return a list
5266     *                    corresponding for all packages
5267     *
5268     * @return a list of IntentFilterVerificationInfo for a specific package.
5269     *
5270     * @hide
5271     */
5272    @SystemApi
5273    public abstract List<IntentFilterVerificationInfo> getIntentFilterVerifications(
5274            String packageName);
5275
5276    /**
5277     * Get the list of IntentFilter for a specific package.
5278     *
5279     * @param packageName the package name. This parameter is set to a non null value,
5280     *                    the list will contain all the IntentFilter for that package.
5281     *                    Otherwise, the list will be empty.
5282     *
5283     * @return a list of IntentFilter for a specific package.
5284     *
5285     * @hide
5286     */
5287    @SystemApi
5288    public abstract List<IntentFilter> getAllIntentFilters(String packageName);
5289
5290    /**
5291     * Get the default Browser package name for a specific user.
5292     *
5293     * @param userId The user id.
5294     *
5295     * @return the package name of the default Browser for the specified user. If the user id passed
5296     *         is -1 (all users) it will return a null value.
5297     *
5298     * @hide
5299     */
5300    @TestApi
5301    @SystemApi
5302    public abstract String getDefaultBrowserPackageNameAsUser(@UserIdInt int userId);
5303
5304    /**
5305     * Set the default Browser package name for a specific user.
5306     *
5307     * @param packageName The package name of the default Browser.
5308     * @param userId The user id.
5309     *
5310     * @return true if the default Browser for the specified user has been set,
5311     *         otherwise return false. If the user id passed is -1 (all users) this call will not
5312     *         do anything and just return false.
5313     *
5314     * @hide
5315     */
5316    @SystemApi
5317    public abstract boolean setDefaultBrowserPackageNameAsUser(String packageName,
5318            @UserIdInt int userId);
5319
5320    /**
5321     * Change the installer associated with a given package.  There are limitations
5322     * on how the installer package can be changed; in particular:
5323     * <ul>
5324     * <li> A SecurityException will be thrown if <var>installerPackageName</var>
5325     * is not signed with the same certificate as the calling application.
5326     * <li> A SecurityException will be thrown if <var>targetPackage</var> already
5327     * has an installer package, and that installer package is not signed with
5328     * the same certificate as the calling application.
5329     * </ul>
5330     *
5331     * @param targetPackage The installed package whose installer will be changed.
5332     * @param installerPackageName The package name of the new installer.  May be
5333     * null to clear the association.
5334     */
5335    public abstract void setInstallerPackageName(String targetPackage,
5336            String installerPackageName);
5337
5338    /** @hide */
5339    @SystemApi
5340    @RequiresPermission(Manifest.permission.INSTALL_PACKAGES)
5341    public abstract void setUpdateAvailable(String packageName, boolean updateAvaialble);
5342
5343    /**
5344     * Attempts to delete a package. Since this may take a little while, the
5345     * result will be posted back to the given observer. A deletion will fail if
5346     * the calling context lacks the
5347     * {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the
5348     * named package cannot be found, or if the named package is a system
5349     * package.
5350     *
5351     * @param packageName The name of the package to delete
5352     * @param observer An observer callback to get notified when the package
5353     *            deletion is complete.
5354     *            {@link android.content.pm.IPackageDeleteObserver#packageDeleted}
5355     *            will be called when that happens. observer may be null to
5356     *            indicate that no callback is desired.
5357     * @hide
5358     */
5359    @RequiresPermission(Manifest.permission.DELETE_PACKAGES)
5360    public abstract void deletePackage(String packageName, IPackageDeleteObserver observer,
5361            @DeleteFlags int flags);
5362
5363    /**
5364     * Attempts to delete a package. Since this may take a little while, the
5365     * result will be posted back to the given observer. A deletion will fail if
5366     * the named package cannot be found, or if the named package is a system
5367     * package.
5368     *
5369     * @param packageName The name of the package to delete
5370     * @param observer An observer callback to get notified when the package
5371     *            deletion is complete.
5372     *            {@link android.content.pm.IPackageDeleteObserver#packageDeleted}
5373     *            will be called when that happens. observer may be null to
5374     *            indicate that no callback is desired.
5375     * @param userId The user Id
5376     * @hide
5377     */
5378    @RequiresPermission(anyOf = {
5379            Manifest.permission.DELETE_PACKAGES,
5380            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5381    public abstract void deletePackageAsUser(@NonNull String packageName,
5382            IPackageDeleteObserver observer, @DeleteFlags int flags, @UserIdInt int userId);
5383
5384    /**
5385     * Retrieve the package name of the application that installed a package. This identifies
5386     * which market the package came from.
5387     *
5388     * @param packageName The name of the package to query
5389     */
5390    public abstract String getInstallerPackageName(String packageName);
5391
5392    /**
5393     * Attempts to clear the user data directory of an application.
5394     * Since this may take a little while, the result will
5395     * be posted back to the given observer.  A deletion will fail if the
5396     * named package cannot be found, or if the named package is a "system package".
5397     *
5398     * @param packageName The name of the package
5399     * @param observer An observer callback to get notified when the operation is finished
5400     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
5401     * will be called when that happens.  observer may be null to indicate that
5402     * no callback is desired.
5403     *
5404     * @hide
5405     */
5406    public abstract void clearApplicationUserData(String packageName,
5407            IPackageDataObserver observer);
5408    /**
5409     * Attempts to delete the cache files associated with an application.
5410     * Since this may take a little while, the result will
5411     * be posted back to the given observer.  A deletion will fail if the calling context
5412     * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the
5413     * named package cannot be found, or if the named package is a "system package".
5414     *
5415     * @param packageName The name of the package to delete
5416     * @param observer An observer callback to get notified when the cache file deletion
5417     * is complete.
5418     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
5419     * will be called when that happens.  observer may be null to indicate that
5420     * no callback is desired.
5421     *
5422     * @hide
5423     */
5424    public abstract void deleteApplicationCacheFiles(String packageName,
5425            IPackageDataObserver observer);
5426
5427    /**
5428     * Attempts to delete the cache files associated with an application for a given user. Since
5429     * this may take a little while, the result will be posted back to the given observer. A
5430     * deletion will fail if the calling context lacks the
5431     * {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the named package
5432     * cannot be found, or if the named package is a "system package". If {@code userId} does not
5433     * belong to the calling user, the caller must have
5434     * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission.
5435     *
5436     * @param packageName The name of the package to delete
5437     * @param userId the user for which the cache files needs to be deleted
5438     * @param observer An observer callback to get notified when the cache file deletion is
5439     *            complete.
5440     *            {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
5441     *            will be called when that happens. observer may be null to indicate that no
5442     *            callback is desired.
5443     * @hide
5444     */
5445    public abstract void deleteApplicationCacheFilesAsUser(String packageName, int userId,
5446            IPackageDataObserver observer);
5447
5448    /**
5449     * Free storage by deleting LRU sorted list of cache files across
5450     * all applications. If the currently available free storage
5451     * on the device is greater than or equal to the requested
5452     * free storage, no cache files are cleared. If the currently
5453     * available storage on the device is less than the requested
5454     * free storage, some or all of the cache files across
5455     * all applications are deleted (based on last accessed time)
5456     * to increase the free storage space on the device to
5457     * the requested value. There is no guarantee that clearing all
5458     * the cache files from all applications will clear up
5459     * enough storage to achieve the desired value.
5460     * @param freeStorageSize The number of bytes of storage to be
5461     * freed by the system. Say if freeStorageSize is XX,
5462     * and the current free storage is YY,
5463     * if XX is less than YY, just return. if not free XX-YY number
5464     * of bytes if possible.
5465     * @param observer call back used to notify when
5466     * the operation is completed
5467     *
5468     * @hide
5469     */
5470    public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
5471        freeStorageAndNotify(null, freeStorageSize, observer);
5472    }
5473
5474    /** {@hide} */
5475    public abstract void freeStorageAndNotify(String volumeUuid, long freeStorageSize,
5476            IPackageDataObserver observer);
5477
5478    /**
5479     * Free storage by deleting LRU sorted list of cache files across
5480     * all applications. If the currently available free storage
5481     * on the device is greater than or equal to the requested
5482     * free storage, no cache files are cleared. If the currently
5483     * available storage on the device is less than the requested
5484     * free storage, some or all of the cache files across
5485     * all applications are deleted (based on last accessed time)
5486     * to increase the free storage space on the device to
5487     * the requested value. There is no guarantee that clearing all
5488     * the cache files from all applications will clear up
5489     * enough storage to achieve the desired value.
5490     * @param freeStorageSize The number of bytes of storage to be
5491     * freed by the system. Say if freeStorageSize is XX,
5492     * and the current free storage is YY,
5493     * if XX is less than YY, just return. if not free XX-YY number
5494     * of bytes if possible.
5495     * @param pi IntentSender call back used to
5496     * notify when the operation is completed.May be null
5497     * to indicate that no call back is desired.
5498     *
5499     * @hide
5500     */
5501    public void freeStorage(long freeStorageSize, IntentSender pi) {
5502        freeStorage(null, freeStorageSize, pi);
5503    }
5504
5505    /** {@hide} */
5506    public abstract void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi);
5507
5508    /**
5509     * Retrieve the size information for a package.
5510     * Since this may take a little while, the result will
5511     * be posted back to the given observer.  The calling context
5512     * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission.
5513     *
5514     * @param packageName The name of the package whose size information is to be retrieved
5515     * @param userId The user whose size information should be retrieved.
5516     * @param observer An observer callback to get notified when the operation
5517     * is complete.
5518     * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)}
5519     * The observer's callback is invoked with a PackageStats object(containing the
5520     * code, data and cache sizes of the package) and a boolean value representing
5521     * the status of the operation. observer may be null to indicate that
5522     * no callback is desired.
5523     *
5524     * @deprecated use {@link StorageStatsManager} instead.
5525     * @hide
5526     */
5527    @Deprecated
5528    public abstract void getPackageSizeInfoAsUser(String packageName, @UserIdInt int userId,
5529            IPackageStatsObserver observer);
5530
5531    /**
5532     * Like {@link #getPackageSizeInfoAsUser(String, int, IPackageStatsObserver)}, but
5533     * returns the size for the calling user.
5534     *
5535     * @deprecated use {@link StorageStatsManager} instead.
5536     * @hide
5537     */
5538    @Deprecated
5539    public void getPackageSizeInfo(String packageName, IPackageStatsObserver observer) {
5540        getPackageSizeInfoAsUser(packageName, UserHandle.myUserId(), observer);
5541    }
5542
5543    /**
5544     * @deprecated This function no longer does anything; it was an old
5545     * approach to managing preferred activities, which has been superseded
5546     * by (and conflicts with) the modern activity-based preferences.
5547     */
5548    @Deprecated
5549    public abstract void addPackageToPreferred(String packageName);
5550
5551    /**
5552     * @deprecated This function no longer does anything; it was an old
5553     * approach to managing preferred activities, which has been superseded
5554     * by (and conflicts with) the modern activity-based preferences.
5555     */
5556    @Deprecated
5557    public abstract void removePackageFromPreferred(String packageName);
5558
5559    /**
5560     * Retrieve the list of all currently configured preferred packages.  The
5561     * first package on the list is the most preferred, the last is the
5562     * least preferred.
5563     *
5564     * @param flags Additional option flags. Use any combination of
5565     *         {@link #GET_ACTIVITIES}, {@link #GET_CONFIGURATIONS},
5566     *         {@link #GET_GIDS}, {@link #GET_INSTRUMENTATION},
5567     *         {@link #GET_INTENT_FILTERS}, {@link #GET_META_DATA},
5568     *         {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
5569     *         {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
5570     *         {@link #GET_SHARED_LIBRARY_FILES}, {@link #GET_SIGNATURES},
5571     *         {@link #GET_URI_PERMISSION_PATTERNS}, {@link #GET_UNINSTALLED_PACKAGES},
5572     *         {@link #MATCH_DISABLED_COMPONENTS}, {@link #MATCH_DISABLED_UNTIL_USED_COMPONENTS},
5573     *         {@link #MATCH_UNINSTALLED_PACKAGES}
5574     *         to modify the data returned.
5575     *
5576     * @return A List of PackageInfo objects, one for each preferred application,
5577     *         in order of preference.
5578     *
5579     * @see #GET_ACTIVITIES
5580     * @see #GET_CONFIGURATIONS
5581     * @see #GET_GIDS
5582     * @see #GET_INSTRUMENTATION
5583     * @see #GET_INTENT_FILTERS
5584     * @see #GET_META_DATA
5585     * @see #GET_PERMISSIONS
5586     * @see #GET_PROVIDERS
5587     * @see #GET_RECEIVERS
5588     * @see #GET_SERVICES
5589     * @see #GET_SHARED_LIBRARY_FILES
5590     * @see #GET_SIGNATURES
5591     * @see #GET_URI_PERMISSION_PATTERNS
5592     * @see #MATCH_DISABLED_COMPONENTS
5593     * @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
5594     * @see #MATCH_UNINSTALLED_PACKAGES
5595     */
5596    public abstract List<PackageInfo> getPreferredPackages(@PackageInfoFlags int flags);
5597
5598    /**
5599     * @deprecated This is a protected API that should not have been available
5600     * to third party applications.  It is the platform's responsibility for
5601     * assigning preferred activities and this cannot be directly modified.
5602     *
5603     * Add a new preferred activity mapping to the system.  This will be used
5604     * to automatically select the given activity component when
5605     * {@link Context#startActivity(Intent) Context.startActivity()} finds
5606     * multiple matching activities and also matches the given filter.
5607     *
5608     * @param filter The set of intents under which this activity will be
5609     * made preferred.
5610     * @param match The IntentFilter match category that this preference
5611     * applies to.
5612     * @param set The set of activities that the user was picking from when
5613     * this preference was made.
5614     * @param activity The component name of the activity that is to be
5615     * preferred.
5616     */
5617    @Deprecated
5618    public abstract void addPreferredActivity(IntentFilter filter, int match,
5619            ComponentName[] set, ComponentName activity);
5620
5621    /**
5622     * Same as {@link #addPreferredActivity(IntentFilter, int,
5623            ComponentName[], ComponentName)}, but with a specific userId to apply the preference
5624            to.
5625     * @hide
5626     */
5627    public void addPreferredActivityAsUser(IntentFilter filter, int match,
5628            ComponentName[] set, ComponentName activity, @UserIdInt int userId) {
5629        throw new RuntimeException("Not implemented. Must override in a subclass.");
5630    }
5631
5632    /**
5633     * @deprecated This is a protected API that should not have been available
5634     * to third party applications.  It is the platform's responsibility for
5635     * assigning preferred activities and this cannot be directly modified.
5636     *
5637     * Replaces an existing preferred activity mapping to the system, and if that were not present
5638     * adds a new preferred activity.  This will be used
5639     * to automatically select the given activity component when
5640     * {@link Context#startActivity(Intent) Context.startActivity()} finds
5641     * multiple matching activities and also matches the given filter.
5642     *
5643     * @param filter The set of intents under which this activity will be
5644     * made preferred.
5645     * @param match The IntentFilter match category that this preference
5646     * applies to.
5647     * @param set The set of activities that the user was picking from when
5648     * this preference was made.
5649     * @param activity The component name of the activity that is to be
5650     * preferred.
5651     * @hide
5652     */
5653    @Deprecated
5654    public abstract void replacePreferredActivity(IntentFilter filter, int match,
5655            ComponentName[] set, ComponentName activity);
5656
5657    /**
5658     * @hide
5659     */
5660    @Deprecated
5661    public void replacePreferredActivityAsUser(IntentFilter filter, int match,
5662           ComponentName[] set, ComponentName activity, @UserIdInt int userId) {
5663        throw new RuntimeException("Not implemented. Must override in a subclass.");
5664    }
5665
5666    /**
5667     * Remove all preferred activity mappings, previously added with
5668     * {@link #addPreferredActivity}, from the
5669     * system whose activities are implemented in the given package name.
5670     * An application can only clear its own package(s).
5671     *
5672     * @param packageName The name of the package whose preferred activity
5673     * mappings are to be removed.
5674     */
5675    public abstract void clearPackagePreferredActivities(String packageName);
5676
5677    /**
5678     * Retrieve all preferred activities, previously added with
5679     * {@link #addPreferredActivity}, that are
5680     * currently registered with the system.
5681     *
5682     * @param outFilters A required list in which to place the filters of all of the
5683     * preferred activities.
5684     * @param outActivities A required list in which to place the component names of
5685     * all of the preferred activities.
5686     * @param packageName An optional package in which you would like to limit
5687     * the list.  If null, all activities will be returned; if non-null, only
5688     * those activities in the given package are returned.
5689     *
5690     * @return Returns the total number of registered preferred activities
5691     * (the number of distinct IntentFilter records, not the number of unique
5692     * activity components) that were found.
5693     */
5694    public abstract int getPreferredActivities(@NonNull List<IntentFilter> outFilters,
5695            @NonNull List<ComponentName> outActivities, String packageName);
5696
5697    /**
5698     * Ask for the set of available 'home' activities and the current explicit
5699     * default, if any.
5700     * @hide
5701     */
5702    public abstract ComponentName getHomeActivities(List<ResolveInfo> outActivities);
5703
5704    /**
5705     * Set the enabled setting for a package component (activity, receiver, service, provider).
5706     * This setting will override any enabled state which may have been set by the component in its
5707     * manifest.
5708     *
5709     * @param componentName The component to enable
5710     * @param newState The new enabled state for the component.  The legal values for this state
5711     *                 are:
5712     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
5713     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
5714     *                   and
5715     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
5716     *                 The last one removes the setting, thereby restoring the component's state to
5717     *                 whatever was set in it's manifest (or enabled, by default).
5718     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
5719     */
5720    public abstract void setComponentEnabledSetting(ComponentName componentName,
5721            int newState, int flags);
5722
5723    /**
5724     * Return the enabled setting for a package component (activity,
5725     * receiver, service, provider).  This returns the last value set by
5726     * {@link #setComponentEnabledSetting(ComponentName, int, int)}; in most
5727     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
5728     * the value originally specified in the manifest has not been modified.
5729     *
5730     * @param componentName The component to retrieve.
5731     * @return Returns the current enabled state for the component.  May
5732     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
5733     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
5734     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
5735     * component's enabled state is based on the original information in
5736     * the manifest as found in {@link ComponentInfo}.
5737     */
5738    public abstract int getComponentEnabledSetting(ComponentName componentName);
5739
5740    /**
5741     * Set the enabled setting for an application
5742     * This setting will override any enabled state which may have been set by the application in
5743     * its manifest.  It also overrides the enabled state set in the manifest for any of the
5744     * application's components.  It does not override any enabled state set by
5745     * {@link #setComponentEnabledSetting} for any of the application's components.
5746     *
5747     * @param packageName The package name of the application to enable
5748     * @param newState The new enabled state for the component.  The legal values for this state
5749     *                 are:
5750     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
5751     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
5752     *                   and
5753     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
5754     *                 The last one removes the setting, thereby restoring the applications's state to
5755     *                 whatever was set in its manifest (or enabled, by default).
5756     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
5757     */
5758    public abstract void setApplicationEnabledSetting(String packageName,
5759            int newState, int flags);
5760
5761    /**
5762     * Return the enabled setting for an application. This returns
5763     * the last value set by
5764     * {@link #setApplicationEnabledSetting(String, int, int)}; in most
5765     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
5766     * the value originally specified in the manifest has not been modified.
5767     *
5768     * @param packageName The package name of the application to retrieve.
5769     * @return Returns the current enabled state for the application.  May
5770     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
5771     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
5772     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
5773     * application's enabled state is based on the original information in
5774     * the manifest as found in {@link ApplicationInfo}.
5775     * @throws IllegalArgumentException if the named package does not exist.
5776     */
5777    public abstract int getApplicationEnabledSetting(String packageName);
5778
5779    /**
5780     * Flush the package restrictions for a given user to disk. This forces the package restrictions
5781     * like component and package enabled settings to be written to disk and avoids the delay that
5782     * is otherwise present when changing those settings.
5783     *
5784     * @param userId Ther userId of the user whose restrictions are to be flushed.
5785     * @hide
5786     */
5787    public abstract void flushPackageRestrictionsAsUser(int userId);
5788
5789    /**
5790     * Puts the package in a hidden state, which is almost like an uninstalled state,
5791     * making the package unavailable, but it doesn't remove the data or the actual
5792     * package file. Application can be unhidden by either resetting the hidden state
5793     * or by installing it, such as with {@link #installExistingPackage(String)}
5794     * @hide
5795     */
5796    public abstract boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
5797            UserHandle userHandle);
5798
5799    /**
5800     * Returns the hidden state of a package.
5801     * @see #setApplicationHiddenSettingAsUser(String, boolean, UserHandle)
5802     * @hide
5803     */
5804    public abstract boolean getApplicationHiddenSettingAsUser(String packageName,
5805            UserHandle userHandle);
5806
5807    /**
5808     * Return whether the device has been booted into safe mode.
5809     */
5810    public abstract boolean isSafeMode();
5811
5812    /**
5813     * Adds a listener for permission changes for installed packages.
5814     *
5815     * @param listener The listener to add.
5816     *
5817     * @hide
5818     */
5819    @SystemApi
5820    @RequiresPermission(Manifest.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS)
5821    public abstract void addOnPermissionsChangeListener(OnPermissionsChangedListener listener);
5822
5823    /**
5824     * Remvoes a listener for permission changes for installed packages.
5825     *
5826     * @param listener The listener to remove.
5827     *
5828     * @hide
5829     */
5830    @SystemApi
5831    public abstract void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener);
5832
5833    /**
5834     * Return the {@link KeySet} associated with the String alias for this
5835     * application.
5836     *
5837     * @param alias The alias for a given {@link KeySet} as defined in the
5838     *        application's AndroidManifest.xml.
5839     * @hide
5840     */
5841    public abstract KeySet getKeySetByAlias(String packageName, String alias);
5842
5843    /** Return the signing {@link KeySet} for this application.
5844     * @hide
5845     */
5846    public abstract KeySet getSigningKeySet(String packageName);
5847
5848    /**
5849     * Return whether the package denoted by packageName has been signed by all
5850     * of the keys specified by the {@link KeySet} ks.  This will return true if
5851     * the package has been signed by additional keys (a superset) as well.
5852     * Compare to {@link #isSignedByExactly(String packageName, KeySet ks)}.
5853     * @hide
5854     */
5855    public abstract boolean isSignedBy(String packageName, KeySet ks);
5856
5857    /**
5858     * Return whether the package denoted by packageName has been signed by all
5859     * of, and only, the keys specified by the {@link KeySet} ks. Compare to
5860     * {@link #isSignedBy(String packageName, KeySet ks)}.
5861     * @hide
5862     */
5863    public abstract boolean isSignedByExactly(String packageName, KeySet ks);
5864
5865    /**
5866     * Puts the package in a suspended state, where attempts at starting activities are denied.
5867     *
5868     * <p>It doesn't remove the data or the actual package file. The application notifications
5869     * will be hidden, the application will not show up in recents, will not be able to show
5870     * toasts or dialogs or ring the device.
5871     *
5872     * <p>The package must already be installed. If the package is uninstalled while suspended
5873     * the package will no longer be suspended.
5874     *
5875     * @param packageNames The names of the packages to set the suspended status.
5876     * @param suspended If set to {@code true} than the packages will be suspended, if set to
5877     * {@code false} the packages will be unsuspended.
5878     * @param userId The user id.
5879     *
5880     * @return an array of package names for which the suspended status is not set as requested in
5881     * this method.
5882     *
5883     * @hide
5884     */
5885    public abstract String[] setPackagesSuspendedAsUser(
5886            String[] packageNames, boolean suspended, @UserIdInt int userId);
5887
5888    /**
5889     * @see #setPackageSuspendedAsUser(String, boolean, int)
5890     * @param packageName The name of the package to get the suspended status of.
5891     * @param userId The user id.
5892     * @return {@code true} if the package is suspended or {@code false} if the package is not
5893     * suspended or could not be found.
5894     * @hide
5895     */
5896    public abstract boolean isPackageSuspendedForUser(String packageName, int userId);
5897
5898    /**
5899     * Provide a hint of what the {@link ApplicationInfo#category} value should
5900     * be for the given package.
5901     * <p>
5902     * This hint can only be set by the app which installed this package, as
5903     * determined by {@link #getInstallerPackageName(String)}.
5904     */
5905    public abstract void setApplicationCategoryHint(String packageName,
5906            @ApplicationInfo.Category int categoryHint);
5907
5908    /** {@hide} */
5909    public static boolean isMoveStatusFinished(int status) {
5910        return (status < 0 || status > 100);
5911    }
5912
5913    /** {@hide} */
5914    public static abstract class MoveCallback {
5915        public void onCreated(int moveId, Bundle extras) {}
5916        public abstract void onStatusChanged(int moveId, int status, long estMillis);
5917    }
5918
5919    /** {@hide} */
5920    public abstract int getMoveStatus(int moveId);
5921
5922    /** {@hide} */
5923    public abstract void registerMoveCallback(MoveCallback callback, Handler handler);
5924    /** {@hide} */
5925    public abstract void unregisterMoveCallback(MoveCallback callback);
5926
5927    /** {@hide} */
5928    public abstract int movePackage(String packageName, VolumeInfo vol);
5929    /** {@hide} */
5930    public abstract @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app);
5931    /** {@hide} */
5932    public abstract @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app);
5933
5934    /** {@hide} */
5935    public abstract int movePrimaryStorage(VolumeInfo vol);
5936    /** {@hide} */
5937    public abstract @Nullable VolumeInfo getPrimaryStorageCurrentVolume();
5938    /** {@hide} */
5939    public abstract @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes();
5940
5941    /**
5942     * Returns the device identity that verifiers can use to associate their scheme to a particular
5943     * device. This should not be used by anything other than a package verifier.
5944     *
5945     * @return identity that uniquely identifies current device
5946     * @hide
5947     */
5948    public abstract VerifierDeviceIdentity getVerifierDeviceIdentity();
5949
5950    /**
5951     * Returns true if the device is upgrading, such as first boot after OTA.
5952     *
5953     * @hide
5954     */
5955    public abstract boolean isUpgrade();
5956
5957    /**
5958     * Return interface that offers the ability to install, upgrade, and remove
5959     * applications on the device.
5960     */
5961    public abstract @NonNull PackageInstaller getPackageInstaller();
5962
5963    /**
5964     * Adds a {@code CrossProfileIntentFilter}. After calling this method all
5965     * intents sent from the user with id sourceUserId can also be be resolved
5966     * by activities in the user with id targetUserId if they match the
5967     * specified intent filter.
5968     *
5969     * @param filter The {@link IntentFilter} the intent has to match
5970     * @param sourceUserId The source user id.
5971     * @param targetUserId The target user id.
5972     * @param flags The possible values are {@link #SKIP_CURRENT_PROFILE} and
5973     *            {@link #ONLY_IF_NO_MATCH_FOUND}.
5974     * @hide
5975     */
5976    public abstract void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId,
5977            int targetUserId, int flags);
5978
5979    /**
5980     * Clearing {@code CrossProfileIntentFilter}s which have the specified user
5981     * as their source, and have been set by the app calling this method.
5982     *
5983     * @param sourceUserId The source user id.
5984     * @hide
5985     */
5986    public abstract void clearCrossProfileIntentFilters(int sourceUserId);
5987
5988    /**
5989     * @hide
5990     */
5991    public abstract Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
5992
5993    /**
5994     * @hide
5995     */
5996    public abstract Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
5997
5998    /** {@hide} */
5999    public abstract boolean isPackageAvailable(String packageName);
6000
6001    /** {@hide} */
6002    public static String installStatusToString(int status, String msg) {
6003        final String str = installStatusToString(status);
6004        if (msg != null) {
6005            return str + ": " + msg;
6006        } else {
6007            return str;
6008        }
6009    }
6010
6011    /** {@hide} */
6012    public static String installStatusToString(int status) {
6013        switch (status) {
6014            case INSTALL_SUCCEEDED: return "INSTALL_SUCCEEDED";
6015            case INSTALL_FAILED_ALREADY_EXISTS: return "INSTALL_FAILED_ALREADY_EXISTS";
6016            case INSTALL_FAILED_INVALID_APK: return "INSTALL_FAILED_INVALID_APK";
6017            case INSTALL_FAILED_INVALID_URI: return "INSTALL_FAILED_INVALID_URI";
6018            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return "INSTALL_FAILED_INSUFFICIENT_STORAGE";
6019            case INSTALL_FAILED_DUPLICATE_PACKAGE: return "INSTALL_FAILED_DUPLICATE_PACKAGE";
6020            case INSTALL_FAILED_NO_SHARED_USER: return "INSTALL_FAILED_NO_SHARED_USER";
6021            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return "INSTALL_FAILED_UPDATE_INCOMPATIBLE";
6022            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return "INSTALL_FAILED_SHARED_USER_INCOMPATIBLE";
6023            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return "INSTALL_FAILED_MISSING_SHARED_LIBRARY";
6024            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return "INSTALL_FAILED_REPLACE_COULDNT_DELETE";
6025            case INSTALL_FAILED_DEXOPT: return "INSTALL_FAILED_DEXOPT";
6026            case INSTALL_FAILED_OLDER_SDK: return "INSTALL_FAILED_OLDER_SDK";
6027            case INSTALL_FAILED_CONFLICTING_PROVIDER: return "INSTALL_FAILED_CONFLICTING_PROVIDER";
6028            case INSTALL_FAILED_NEWER_SDK: return "INSTALL_FAILED_NEWER_SDK";
6029            case INSTALL_FAILED_TEST_ONLY: return "INSTALL_FAILED_TEST_ONLY";
6030            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE";
6031            case INSTALL_FAILED_MISSING_FEATURE: return "INSTALL_FAILED_MISSING_FEATURE";
6032            case INSTALL_FAILED_CONTAINER_ERROR: return "INSTALL_FAILED_CONTAINER_ERROR";
6033            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return "INSTALL_FAILED_INVALID_INSTALL_LOCATION";
6034            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return "INSTALL_FAILED_MEDIA_UNAVAILABLE";
6035            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return "INSTALL_FAILED_VERIFICATION_TIMEOUT";
6036            case INSTALL_FAILED_VERIFICATION_FAILURE: return "INSTALL_FAILED_VERIFICATION_FAILURE";
6037            case INSTALL_FAILED_PACKAGE_CHANGED: return "INSTALL_FAILED_PACKAGE_CHANGED";
6038            case INSTALL_FAILED_UID_CHANGED: return "INSTALL_FAILED_UID_CHANGED";
6039            case INSTALL_FAILED_VERSION_DOWNGRADE: return "INSTALL_FAILED_VERSION_DOWNGRADE";
6040            case INSTALL_PARSE_FAILED_NOT_APK: return "INSTALL_PARSE_FAILED_NOT_APK";
6041            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return "INSTALL_PARSE_FAILED_BAD_MANIFEST";
6042            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return "INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION";
6043            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return "INSTALL_PARSE_FAILED_NO_CERTIFICATES";
6044            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return "INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES";
6045            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return "INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING";
6046            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return "INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME";
6047            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return "INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID";
6048            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return "INSTALL_PARSE_FAILED_MANIFEST_MALFORMED";
6049            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return "INSTALL_PARSE_FAILED_MANIFEST_EMPTY";
6050            case INSTALL_FAILED_INTERNAL_ERROR: return "INSTALL_FAILED_INTERNAL_ERROR";
6051            case INSTALL_FAILED_USER_RESTRICTED: return "INSTALL_FAILED_USER_RESTRICTED";
6052            case INSTALL_FAILED_DUPLICATE_PERMISSION: return "INSTALL_FAILED_DUPLICATE_PERMISSION";
6053            case INSTALL_FAILED_NO_MATCHING_ABIS: return "INSTALL_FAILED_NO_MATCHING_ABIS";
6054            case INSTALL_FAILED_ABORTED: return "INSTALL_FAILED_ABORTED";
6055            default: return Integer.toString(status);
6056        }
6057    }
6058
6059    /** {@hide} */
6060    public static int installStatusToPublicStatus(int status) {
6061        switch (status) {
6062            case INSTALL_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
6063            case INSTALL_FAILED_ALREADY_EXISTS: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6064            case INSTALL_FAILED_INVALID_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
6065            case INSTALL_FAILED_INVALID_URI: return PackageInstaller.STATUS_FAILURE_INVALID;
6066            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return PackageInstaller.STATUS_FAILURE_STORAGE;
6067            case INSTALL_FAILED_DUPLICATE_PACKAGE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6068            case INSTALL_FAILED_NO_SHARED_USER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6069            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6070            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6071            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
6072            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6073            case INSTALL_FAILED_DEXOPT: return PackageInstaller.STATUS_FAILURE_INVALID;
6074            case INSTALL_FAILED_OLDER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
6075            case INSTALL_FAILED_CONFLICTING_PROVIDER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6076            case INSTALL_FAILED_NEWER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
6077            case INSTALL_FAILED_TEST_ONLY: return PackageInstaller.STATUS_FAILURE_INVALID;
6078            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
6079            case INSTALL_FAILED_MISSING_FEATURE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
6080            case INSTALL_FAILED_CONTAINER_ERROR: return PackageInstaller.STATUS_FAILURE_STORAGE;
6081            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return PackageInstaller.STATUS_FAILURE_STORAGE;
6082            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return PackageInstaller.STATUS_FAILURE_STORAGE;
6083            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return PackageInstaller.STATUS_FAILURE_ABORTED;
6084            case INSTALL_FAILED_VERIFICATION_FAILURE: return PackageInstaller.STATUS_FAILURE_ABORTED;
6085            case INSTALL_FAILED_PACKAGE_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
6086            case INSTALL_FAILED_UID_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
6087            case INSTALL_FAILED_VERSION_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
6088            case INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
6089            case INSTALL_PARSE_FAILED_NOT_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
6090            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return PackageInstaller.STATUS_FAILURE_INVALID;
6091            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return PackageInstaller.STATUS_FAILURE_INVALID;
6092            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
6093            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
6094            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return PackageInstaller.STATUS_FAILURE_INVALID;
6095            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return PackageInstaller.STATUS_FAILURE_INVALID;
6096            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return PackageInstaller.STATUS_FAILURE_INVALID;
6097            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return PackageInstaller.STATUS_FAILURE_INVALID;
6098            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return PackageInstaller.STATUS_FAILURE_INVALID;
6099            case INSTALL_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
6100            case INSTALL_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
6101            case INSTALL_FAILED_DUPLICATE_PERMISSION: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6102            case INSTALL_FAILED_NO_MATCHING_ABIS: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
6103            case INSTALL_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
6104            default: return PackageInstaller.STATUS_FAILURE;
6105        }
6106    }
6107
6108    /** {@hide} */
6109    public static String deleteStatusToString(int status, String msg) {
6110        final String str = deleteStatusToString(status);
6111        if (msg != null) {
6112            return str + ": " + msg;
6113        } else {
6114            return str;
6115        }
6116    }
6117
6118    /** {@hide} */
6119    public static String deleteStatusToString(int status) {
6120        switch (status) {
6121            case DELETE_SUCCEEDED: return "DELETE_SUCCEEDED";
6122            case DELETE_FAILED_INTERNAL_ERROR: return "DELETE_FAILED_INTERNAL_ERROR";
6123            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return "DELETE_FAILED_DEVICE_POLICY_MANAGER";
6124            case DELETE_FAILED_USER_RESTRICTED: return "DELETE_FAILED_USER_RESTRICTED";
6125            case DELETE_FAILED_OWNER_BLOCKED: return "DELETE_FAILED_OWNER_BLOCKED";
6126            case DELETE_FAILED_ABORTED: return "DELETE_FAILED_ABORTED";
6127            case DELETE_FAILED_USED_SHARED_LIBRARY: return "DELETE_FAILED_USED_SHARED_LIBRARY";
6128            default: return Integer.toString(status);
6129        }
6130    }
6131
6132    /** {@hide} */
6133    public static int deleteStatusToPublicStatus(int status) {
6134        switch (status) {
6135            case DELETE_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
6136            case DELETE_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
6137            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return PackageInstaller.STATUS_FAILURE_BLOCKED;
6138            case DELETE_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
6139            case DELETE_FAILED_OWNER_BLOCKED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
6140            case DELETE_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
6141            case DELETE_FAILED_USED_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_CONFLICT;
6142            default: return PackageInstaller.STATUS_FAILURE;
6143        }
6144    }
6145
6146    /** {@hide} */
6147    public static String permissionFlagToString(int flag) {
6148        switch (flag) {
6149            case FLAG_PERMISSION_GRANTED_BY_DEFAULT: return "GRANTED_BY_DEFAULT";
6150            case FLAG_PERMISSION_POLICY_FIXED: return "POLICY_FIXED";
6151            case FLAG_PERMISSION_SYSTEM_FIXED: return "SYSTEM_FIXED";
6152            case FLAG_PERMISSION_USER_SET: return "USER_SET";
6153            case FLAG_PERMISSION_REVOKE_ON_UPGRADE: return "REVOKE_ON_UPGRADE";
6154            case FLAG_PERMISSION_USER_FIXED: return "USER_FIXED";
6155            case FLAG_PERMISSION_REVIEW_REQUIRED: return "REVIEW_REQUIRED";
6156            default: return Integer.toString(flag);
6157        }
6158    }
6159
6160    /** {@hide} */
6161    public static class LegacyPackageInstallObserver extends PackageInstallObserver {
6162        private final IPackageInstallObserver mLegacy;
6163
6164        public LegacyPackageInstallObserver(IPackageInstallObserver legacy) {
6165            mLegacy = legacy;
6166        }
6167
6168        @Override
6169        public void onPackageInstalled(String basePackageName, int returnCode, String msg,
6170                Bundle extras) {
6171            if (mLegacy == null) return;
6172            try {
6173                mLegacy.packageInstalled(basePackageName, returnCode);
6174            } catch (RemoteException ignored) {
6175            }
6176        }
6177    }
6178
6179    /** {@hide} */
6180    public static class LegacyPackageDeleteObserver extends PackageDeleteObserver {
6181        private final IPackageDeleteObserver mLegacy;
6182
6183        public LegacyPackageDeleteObserver(IPackageDeleteObserver legacy) {
6184            mLegacy = legacy;
6185        }
6186
6187        @Override
6188        public void onPackageDeleted(String basePackageName, int returnCode, String msg) {
6189            if (mLegacy == null) return;
6190            try {
6191                mLegacy.packageDeleted(basePackageName, returnCode);
6192            } catch (RemoteException ignored) {
6193            }
6194        }
6195    }
6196
6197    /**
6198     * Return the install reason that was recorded when a package was first installed for a specific
6199     * user. Requesting the install reason for another user will require the permission
6200     * INTERACT_ACROSS_USERS_FULL.
6201     *
6202     * @param packageName The package for which to retrieve the install reason
6203     * @param user The user for whom to retrieve the install reason
6204     *
6205     * @return The install reason, currently one of {@code INSTALL_REASON_UNKNOWN} and
6206     *         {@code INSTALL_REASON_POLICY}. If the package is not installed for the given user,
6207     *         {@code INSTALL_REASON_UNKNOWN} is returned.
6208     *
6209     * @see #INSTALL_REASON_UNKNOWN
6210     * @see #INSTALL_REASON_POLICY
6211     * @see #INSTALL_REASON_DEVICE_RESTORE
6212     * @see #INSTALL_REASON_DEVICE_SETUP
6213     * @see #INSTALL_REASON_USER
6214     *
6215     * @hide
6216     */
6217    @TestApi
6218    public abstract @InstallReason int getInstallReason(String packageName,
6219            @NonNull UserHandle user);
6220
6221    /**
6222     * Checks whether the calling package is allowed to request package installs through package
6223     * installer. Apps are encouraged to call this api before launching the package installer via
6224     * intent {@link android.content.Intent#ACTION_INSTALL_PACKAGE}. Starting from Android O, the
6225     * user can explicitly choose what external sources they trust to install apps on the device.
6226     * If this api returns false, the install request will be blocked by the package installer and
6227     * a dialog will be shown to the user with an option to launch settings to change their
6228     * preference. An application must target Android O or higher and declare permission
6229     * {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES} in order to use this api.
6230     *
6231     * @return true if the calling package is trusted by the user to request install packages on
6232     * the device, false otherwise.
6233     * @see {@link android.content.Intent#ACTION_INSTALL_PACKAGE}
6234     * @see {@link android.provider.Settings#ACTION_MANAGE_EXTERNAL_SOURCES}
6235     */
6236    public abstract boolean canRequestPackageInstalls();
6237}
6238