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