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