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