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