PackageManager.java revision ef9acb6ed97ececa4c8554adb693ec948a963db1
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    public abstract List<ApplicationInfo> getInstalledApplicationsAsUser(
3802            @ApplicationInfoFlags int flags, @UserIdInt int userId);
3803
3804    /**
3805     * Gets the instant applications the user recently used.
3806     *
3807     * @return The instant app list.
3808     *
3809     * @hide
3810     */
3811    @SystemApi
3812    @RequiresPermission(Manifest.permission.ACCESS_INSTANT_APPS)
3813    public abstract @NonNull List<InstantAppInfo> getInstantApps();
3814
3815    /**
3816     * Gets the icon for an instant application.
3817     *
3818     * @param packageName The app package name.
3819     *
3820     * @hide
3821     */
3822    @SystemApi
3823    @RequiresPermission(Manifest.permission.ACCESS_INSTANT_APPS)
3824    public abstract @Nullable Drawable getInstantAppIcon(String packageName);
3825
3826    /**
3827     * Gets whether this application is an instant app.
3828     *
3829     * @return Whether caller is an instant app.
3830     *
3831     * @see #isInstantApp(String)
3832     * @see #updateInstantAppCookie(byte[])
3833     * @see #getInstantAppCookie()
3834     * @see #getInstantAppCookieMaxBytes()
3835     */
3836    public abstract boolean isInstantApp();
3837
3838    /**
3839     * Gets whether the given package is an instant app.
3840     *
3841     * @param packageName The package to check
3842     * @return Whether the given package is an instant app.
3843     *
3844     * @see #isInstantApp()
3845     * @see #updateInstantAppCookie(byte[])
3846     * @see #getInstantAppCookie()
3847     * @see #getInstantAppCookieMaxBytes()
3848     * @see #clearInstantAppCookie()
3849     */
3850    public abstract boolean isInstantApp(String packageName);
3851
3852    /**
3853     * Gets the maximum size in bytes of the cookie data an instant app
3854     * can store on the device.
3855     *
3856     * @return The max cookie size in bytes.
3857     *
3858     * @see #isInstantApp()
3859     * @see #isInstantApp(String)
3860     * @see #updateInstantAppCookie(byte[])
3861     * @see #getInstantAppCookie()
3862     * @see #clearInstantAppCookie()
3863     */
3864    public abstract int getInstantAppCookieMaxBytes();
3865
3866    /**
3867     * deprecated
3868     * @hide
3869     */
3870    public abstract int getInstantAppCookieMaxSize();
3871
3872    /**
3873     * Gets the instant application cookie for this app. Non
3874     * instant apps and apps that were instant but were upgraded
3875     * to normal apps can still access this API. For instant apps
3876     * this cookie is cached for some time after uninstall while for
3877     * normal apps the cookie is deleted after the app is uninstalled.
3878     * The cookie is always present while the app is installed.
3879     *
3880     * @return The cookie.
3881     *
3882     * @see #isInstantApp()
3883     * @see #isInstantApp(String)
3884     * @see #updateInstantAppCookie(byte[])
3885     * @see #getInstantAppCookieMaxBytes()
3886     * @see #clearInstantAppCookie()
3887     */
3888    public abstract @NonNull byte[] getInstantAppCookie();
3889
3890    /**
3891     * Clears the instant application cookie for the calling app.
3892     *
3893     * @see #isInstantApp()
3894     * @see #isInstantApp(String)
3895     * @see #getInstantAppCookieMaxBytes()
3896     * @see #getInstantAppCookie()
3897     * @see #clearInstantAppCookie()
3898     */
3899    public abstract void clearInstantAppCookie();
3900
3901    /**
3902     * Updates the instant application cookie for the calling app. Non
3903     * instant apps and apps that were instant but were upgraded
3904     * to normal apps can still access this API. For instant apps
3905     * this cookie is cached for some time after uninstall while for
3906     * normal apps the cookie is deleted after the app is uninstalled.
3907     * The cookie is always present while the app is installed. The
3908     * cookie size is limited by {@link #getInstantAppCookieMaxBytes()}.
3909     * Passing <code>null</code> or an empty array clears the cookie.
3910     * </p>
3911     *
3912     * @param cookie The cookie data.
3913     *
3914     * @see #isInstantApp()
3915     * @see #isInstantApp(String)
3916     * @see #getInstantAppCookieMaxBytes()
3917     * @see #getInstantAppCookie()
3918     * @see #clearInstantAppCookie()
3919     *
3920     * @throws IllegalArgumentException if the array exceeds max cookie size.
3921     */
3922    public abstract void updateInstantAppCookie(@Nullable byte[] cookie);
3923
3924    /**
3925     * @removed
3926     */
3927    public abstract boolean setInstantAppCookie(@Nullable byte[] cookie);
3928
3929    /**
3930     * Get a list of shared libraries that are available on the
3931     * system.
3932     *
3933     * @return An array of shared library names that are
3934     * available on the system, or null if none are installed.
3935     *
3936     */
3937    public abstract String[] getSystemSharedLibraryNames();
3938
3939    /**
3940     * Get a list of shared libraries on the device.
3941     *
3942     * @param flags To filter the libraries to return.
3943     * @return The shared library list.
3944     *
3945     * @see #MATCH_UNINSTALLED_PACKAGES
3946     */
3947    public abstract @NonNull List<SharedLibraryInfo> getSharedLibraries(
3948            @InstallFlags int flags);
3949
3950    /**
3951     * Get a list of shared libraries on the device.
3952     *
3953     * @param flags To filter the libraries to return.
3954     * @param userId The user to query for.
3955     * @return The shared library list.
3956     *
3957     * @see #MATCH_FACTORY_ONLY
3958     * @see #MATCH_KNOWN_PACKAGES
3959     * @see #MATCH_ANY_USER
3960     * @see #MATCH_UNINSTALLED_PACKAGES
3961     *
3962     * @hide
3963     */
3964    public abstract @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(
3965            @InstallFlags int flags, @UserIdInt int userId);
3966
3967    /**
3968     * Get the name of the package hosting the services shared library.
3969     *
3970     * @return The library host package.
3971     *
3972     * @hide
3973     */
3974    @TestApi
3975    public abstract @NonNull String getServicesSystemSharedLibraryPackageName();
3976
3977    /**
3978     * Get the name of the package hosting the shared components shared library.
3979     *
3980     * @return The library host package.
3981     *
3982     * @hide
3983     */
3984    @TestApi
3985    public abstract @NonNull String getSharedSystemSharedLibraryPackageName();
3986
3987    /**
3988     * Returns the names of the packages that have been changed
3989     * [eg. added, removed or updated] since the given sequence
3990     * number.
3991     * <p>If no packages have been changed, returns <code>null</code>.
3992     * <p>The sequence number starts at <code>0</code> and is
3993     * reset every boot.
3994     * @param sequenceNumber The first sequence number for which to retrieve package changes.
3995     * @see Settings.Global#BOOT_COUNT
3996     */
3997    public abstract @Nullable ChangedPackages getChangedPackages(
3998            @IntRange(from=0) int sequenceNumber);
3999
4000    /**
4001     * Get a list of features that are available on the
4002     * system.
4003     *
4004     * @return An array of FeatureInfo classes describing the features
4005     * that are available on the system, or null if there are none(!!).
4006     */
4007    public abstract FeatureInfo[] getSystemAvailableFeatures();
4008
4009    /**
4010     * Check whether the given feature name is one of the available features as
4011     * returned by {@link #getSystemAvailableFeatures()}. This tests for the
4012     * presence of <em>any</em> version of the given feature name; use
4013     * {@link #hasSystemFeature(String, int)} to check for a minimum version.
4014     *
4015     * @return Returns true if the devices supports the feature, else false.
4016     */
4017    public abstract boolean hasSystemFeature(String name);
4018
4019    /**
4020     * Check whether the given feature name and version is one of the available
4021     * features as returned by {@link #getSystemAvailableFeatures()}. Since
4022     * features are defined to always be backwards compatible, this returns true
4023     * if the available feature version is greater than or equal to the
4024     * requested version.
4025     *
4026     * @return Returns true if the devices supports the feature, else false.
4027     */
4028    public abstract boolean hasSystemFeature(String name, int version);
4029
4030    /**
4031     * Determine the best action to perform for a given Intent. This is how
4032     * {@link Intent#resolveActivity} finds an activity if a class has not been
4033     * explicitly specified.
4034     * <p>
4035     * <em>Note:</em> if using an implicit Intent (without an explicit
4036     * ComponentName specified), be sure to consider whether to set the
4037     * {@link #MATCH_DEFAULT_ONLY} only flag. You need to do so to resolve the
4038     * activity in the same way that
4039     * {@link android.content.Context#startActivity(Intent)} and
4040     * {@link android.content.Intent#resolveActivity(PackageManager)
4041     * Intent.resolveActivity(PackageManager)} do.
4042     * </p>
4043     *
4044     * @param intent An intent containing all of the desired specification
4045     *            (action, data, type, category, and/or component).
4046     * @param flags Additional option flags to modify the data returned. The
4047     *            most important is {@link #MATCH_DEFAULT_ONLY}, to limit the
4048     *            resolution to only those activities that support the
4049     *            {@link android.content.Intent#CATEGORY_DEFAULT}.
4050     * @return Returns a ResolveInfo object containing the final activity intent
4051     *         that was determined to be the best action. Returns null if no
4052     *         matching activity was found. If multiple matching activities are
4053     *         found and there is no default set, returns a ResolveInfo object
4054     *         containing something else, such as the activity resolver.
4055     */
4056    public abstract ResolveInfo resolveActivity(Intent intent, @ResolveInfoFlags int flags);
4057
4058    /**
4059     * Determine the best action to perform for a given Intent for a given user.
4060     * This is how {@link Intent#resolveActivity} finds an activity if a class
4061     * has not been explicitly specified.
4062     * <p>
4063     * <em>Note:</em> if using an implicit Intent (without an explicit
4064     * ComponentName specified), be sure to consider whether to set the
4065     * {@link #MATCH_DEFAULT_ONLY} only flag. You need to do so to resolve the
4066     * activity in the same way that
4067     * {@link android.content.Context#startActivity(Intent)} and
4068     * {@link android.content.Intent#resolveActivity(PackageManager)
4069     * Intent.resolveActivity(PackageManager)} do.
4070     * </p>
4071     *
4072     * @param intent An intent containing all of the desired specification
4073     *            (action, data, type, category, and/or component).
4074     * @param flags Additional option flags to modify the data returned. The
4075     *            most important is {@link #MATCH_DEFAULT_ONLY}, to limit the
4076     *            resolution to only those activities that support the
4077     *            {@link android.content.Intent#CATEGORY_DEFAULT}.
4078     * @param userId The user id.
4079     * @return Returns a ResolveInfo object containing the final activity intent
4080     *         that was determined to be the best action. Returns null if no
4081     *         matching activity was found. If multiple matching activities are
4082     *         found and there is no default set, returns a ResolveInfo object
4083     *         containing something else, such as the activity resolver.
4084     * @hide
4085     */
4086    public abstract ResolveInfo resolveActivityAsUser(Intent intent, @ResolveInfoFlags int flags,
4087            @UserIdInt int userId);
4088
4089    /**
4090     * Retrieve all activities that can be performed for the given intent.
4091     *
4092     * @param intent The desired intent as per resolveActivity().
4093     * @param flags Additional option flags to modify the data returned. The
4094     *            most important is {@link #MATCH_DEFAULT_ONLY}, to limit the
4095     *            resolution to only those activities that support the
4096     *            {@link android.content.Intent#CATEGORY_DEFAULT}. Or, set
4097     *            {@link #MATCH_ALL} to prevent any filtering of the results.
4098     * @return Returns a List of ResolveInfo objects containing one entry for
4099     *         each matching activity, ordered from best to worst. In other
4100     *         words, the first item is what would be returned by
4101     *         {@link #resolveActivity}. If there are no matching activities, an
4102     *         empty list is returned.
4103     */
4104    public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
4105            @ResolveInfoFlags int flags);
4106
4107    /**
4108     * Retrieve all activities that can be performed for the given intent, for a
4109     * specific user.
4110     *
4111     * @param intent The desired intent as per resolveActivity().
4112     * @param flags Additional option flags to modify the data returned. The
4113     *            most important is {@link #MATCH_DEFAULT_ONLY}, to limit the
4114     *            resolution to only those activities that support the
4115     *            {@link android.content.Intent#CATEGORY_DEFAULT}. Or, set
4116     *            {@link #MATCH_ALL} to prevent any filtering of the results.
4117     * @return Returns a List of ResolveInfo objects containing one entry for
4118     *         each matching activity, ordered from best to worst. In other
4119     *         words, the first item is what would be returned by
4120     *         {@link #resolveActivity}. If there are no matching activities, an
4121     *         empty list is returned.
4122     * @hide
4123     */
4124    public abstract List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
4125            @ResolveInfoFlags int flags, @UserIdInt int userId);
4126
4127    /**
4128     * Retrieve a set of activities that should be presented to the user as
4129     * similar options. This is like {@link #queryIntentActivities}, except it
4130     * also allows you to supply a list of more explicit Intents that you would
4131     * like to resolve to particular options, and takes care of returning the
4132     * final ResolveInfo list in a reasonable order, with no duplicates, based
4133     * on those inputs.
4134     *
4135     * @param caller The class name of the activity that is making the request.
4136     *            This activity will never appear in the output list. Can be
4137     *            null.
4138     * @param specifics An array of Intents that should be resolved to the first
4139     *            specific results. Can be null.
4140     * @param intent The desired intent as per resolveActivity().
4141     * @param flags Additional option flags to modify the data returned. The
4142     *            most important is {@link #MATCH_DEFAULT_ONLY}, to limit the
4143     *            resolution to only those activities that support the
4144     *            {@link android.content.Intent#CATEGORY_DEFAULT}.
4145     * @return Returns a List of ResolveInfo objects containing one entry for
4146     *         each matching activity. The list is ordered first by all of the
4147     *         intents resolved in <var>specifics</var> and then any additional
4148     *         activities that can handle <var>intent</var> but did not get
4149     *         included by one of the <var>specifics</var> intents. If there are
4150     *         no matching activities, an empty list is returned.
4151     */
4152    public abstract List<ResolveInfo> queryIntentActivityOptions(@Nullable ComponentName caller,
4153            @Nullable Intent[] specifics, Intent intent, @ResolveInfoFlags int flags);
4154
4155    /**
4156     * Retrieve all receivers that can handle a broadcast of the given intent.
4157     *
4158     * @param intent The desired intent as per resolveActivity().
4159     * @param flags Additional option flags to modify the data returned.
4160     * @return Returns a List of ResolveInfo objects containing one entry for
4161     *         each matching receiver, ordered from best to worst. If there are
4162     *         no matching receivers, an empty list or null is returned.
4163     */
4164    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
4165            @ResolveInfoFlags int flags);
4166
4167    /**
4168     * Retrieve all receivers that can handle a broadcast of the given intent,
4169     * for a specific user.
4170     *
4171     * @param intent The desired intent as per resolveActivity().
4172     * @param flags Additional option flags to modify the data returned.
4173     * @param userHandle UserHandle of the user being queried.
4174     * @return Returns a List of ResolveInfo objects containing one entry for
4175     *         each matching receiver, ordered from best to worst. If there are
4176     *         no matching receivers, an empty list or null is returned.
4177     * @hide
4178     */
4179    @SystemApi
4180    @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS)
4181    public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent,
4182            @ResolveInfoFlags int flags, UserHandle userHandle) {
4183        return queryBroadcastReceiversAsUser(intent, flags, userHandle.getIdentifier());
4184    }
4185
4186    /**
4187     * @hide
4188     */
4189    public abstract List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent,
4190            @ResolveInfoFlags int flags, @UserIdInt int userId);
4191
4192
4193    /** {@hide} */
4194    @Deprecated
4195    public List<ResolveInfo> queryBroadcastReceivers(Intent intent,
4196            @ResolveInfoFlags int flags, @UserIdInt int userId) {
4197        final String msg = "Shame on you for calling the hidden API "
4198                + "queryBroadcastReceivers(). Shame!";
4199        if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.O) {
4200            throw new UnsupportedOperationException(msg);
4201        } else {
4202            Log.d(TAG, msg);
4203            return queryBroadcastReceiversAsUser(intent, flags, userId);
4204        }
4205    }
4206
4207    /**
4208     * Determine the best service to handle for a given Intent.
4209     *
4210     * @param intent An intent containing all of the desired specification
4211     *            (action, data, type, category, and/or component).
4212     * @param flags Additional option flags to modify the data returned.
4213     * @return Returns a ResolveInfo object containing the final service intent
4214     *         that was determined to be the best action. Returns null if no
4215     *         matching service was found.
4216     */
4217    public abstract ResolveInfo resolveService(Intent intent, @ResolveInfoFlags int flags);
4218
4219    /**
4220     * @hide
4221     */
4222    public abstract ResolveInfo resolveServiceAsUser(Intent intent, @ResolveInfoFlags int flags,
4223            @UserIdInt int userId);
4224
4225    /**
4226     * Retrieve all services that can match the given intent.
4227     *
4228     * @param intent The desired intent as per resolveService().
4229     * @param flags Additional option flags to modify the data returned.
4230     * @return Returns a List of ResolveInfo objects containing one entry for
4231     *         each matching service, ordered from best to worst. In other
4232     *         words, the first item is what would be returned by
4233     *         {@link #resolveService}. If there are no matching services, an
4234     *         empty list or null is returned.
4235     */
4236    public abstract List<ResolveInfo> queryIntentServices(Intent intent,
4237            @ResolveInfoFlags int flags);
4238
4239    /**
4240     * Retrieve all services that can match the given intent for a given user.
4241     *
4242     * @param intent The desired intent as per resolveService().
4243     * @param flags Additional option flags to modify the data returned.
4244     * @param userId The user id.
4245     * @return Returns a List of ResolveInfo objects containing one entry for
4246     *         each matching service, ordered from best to worst. In other
4247     *         words, the first item is what would be returned by
4248     *         {@link #resolveService}. If there are no matching services, an
4249     *         empty list or null is returned.
4250     * @hide
4251     */
4252    public abstract List<ResolveInfo> queryIntentServicesAsUser(Intent intent,
4253            @ResolveInfoFlags int flags, @UserIdInt int userId);
4254
4255    /**
4256     * Retrieve all providers that can match the given intent.
4257     *
4258     * @param intent An intent containing all of the desired specification
4259     *            (action, data, type, category, and/or component).
4260     * @param flags Additional option flags to modify the data returned.
4261     * @param userId The user id.
4262     * @return Returns a List of ResolveInfo objects containing one entry for
4263     *         each matching provider, ordered from best to worst. If there are
4264     *         no matching services, an empty list or null is returned.
4265     * @hide
4266     */
4267    public abstract List<ResolveInfo> queryIntentContentProvidersAsUser(
4268            Intent intent, @ResolveInfoFlags int flags, @UserIdInt int userId);
4269
4270    /**
4271     * Retrieve all providers that can match the given intent.
4272     *
4273     * @param intent An intent containing all of the desired specification
4274     *            (action, data, type, category, and/or component).
4275     * @param flags Additional option flags to modify the data returned.
4276     * @return Returns a List of ResolveInfo objects containing one entry for
4277     *         each matching provider, ordered from best to worst. If there are
4278     *         no matching services, an empty list or null is returned.
4279     */
4280    public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent,
4281            @ResolveInfoFlags int flags);
4282
4283    /**
4284     * Find a single content provider by its base path name.
4285     *
4286     * @param name The name of the provider to find.
4287     * @param flags Additional option flags to modify the data returned.
4288     * @return A {@link ProviderInfo} object containing information about the
4289     *         provider. If a provider was not found, returns null.
4290     */
4291    public abstract ProviderInfo resolveContentProvider(String name,
4292            @ComponentInfoFlags int flags);
4293
4294    /**
4295     * Find a single content provider by its base path name.
4296     *
4297     * @param name The name of the provider to find.
4298     * @param flags Additional option flags to modify the data returned.
4299     * @param userId The user id.
4300     * @return A {@link ProviderInfo} object containing information about the
4301     *         provider. If a provider was not found, returns null.
4302     * @hide
4303     */
4304    public abstract ProviderInfo resolveContentProviderAsUser(String name,
4305            @ComponentInfoFlags int flags, @UserIdInt int userId);
4306
4307    /**
4308     * Retrieve content provider information.
4309     * <p>
4310     * <em>Note: unlike most other methods, an empty result set is indicated
4311     * by a null return instead of an empty list.</em>
4312     *
4313     * @param processName If non-null, limits the returned providers to only
4314     *            those that are hosted by the given process. If null, all
4315     *            content providers are returned.
4316     * @param uid If <var>processName</var> is non-null, this is the required
4317     *            uid owning the requested content providers.
4318     * @param flags Additional option flags to modify the data returned.
4319     * @return A list of {@link ProviderInfo} objects containing one entry for
4320     *         each provider either matching <var>processName</var> or, if
4321     *         <var>processName</var> is null, all known content providers.
4322     *         <em>If there are no matching providers, null is returned.</em>
4323     */
4324    public abstract List<ProviderInfo> queryContentProviders(
4325            String processName, int uid, @ComponentInfoFlags int flags);
4326
4327    /**
4328     * Same as {@link #queryContentProviders}, except when {@code metaDataKey} is not null,
4329     * it only returns providers which have metadata with the {@code metaDataKey} key.
4330     *
4331     * <p>DO NOT USE the {@code metaDataKey} parameter, unless you're the contacts provider.
4332     * You really shouldn't need it.  Other apps should use {@link #queryIntentContentProviders}
4333     * instead.
4334     *
4335     * <p>The {@code metaDataKey} parameter was added to allow the contacts provider to quickly
4336     * scan the GAL providers on the device.  Unfortunately the discovery protocol used metadata
4337     * to mark GAL providers, rather than intent filters, so we can't use
4338     * {@link #queryIntentContentProviders} for that.
4339     *
4340     * @hide
4341     */
4342    public List<ProviderInfo> queryContentProviders(
4343            String processName, int uid, @ComponentInfoFlags int flags, String metaDataKey) {
4344        // Provide the default implementation for mocks.
4345        return queryContentProviders(processName, uid, flags);
4346    }
4347
4348    /**
4349     * Retrieve all of the information we know about a particular
4350     * instrumentation class.
4351     *
4352     * @param className The full name (i.e.
4353     *            com.google.apps.contacts.InstrumentList) of an Instrumentation
4354     *            class.
4355     * @param flags Additional option flags to modify the data returned.
4356     * @return An {@link InstrumentationInfo} object containing information
4357     *         about the instrumentation.
4358     * @throws NameNotFoundException if a package with the given name cannot be
4359     *             found on the system.
4360     */
4361    public abstract InstrumentationInfo getInstrumentationInfo(ComponentName className,
4362            @InstrumentationInfoFlags int flags) throws NameNotFoundException;
4363
4364    /**
4365     * Retrieve information about available instrumentation code. May be used to
4366     * retrieve either all instrumentation code, or only the code targeting a
4367     * particular package.
4368     *
4369     * @param targetPackage If null, all instrumentation is returned; only the
4370     *            instrumentation targeting this package name is returned.
4371     * @param flags Additional option flags to modify the data returned.
4372     * @return A list of {@link InstrumentationInfo} objects containing one
4373     *         entry for each matching instrumentation. If there are no
4374     *         instrumentation available, returns an empty list.
4375     */
4376    public abstract List<InstrumentationInfo> queryInstrumentation(String targetPackage,
4377            @InstrumentationInfoFlags int flags);
4378
4379    /**
4380     * Retrieve an image from a package.  This is a low-level API used by
4381     * the various package manager info structures (such as
4382     * {@link ComponentInfo} to implement retrieval of their associated
4383     * icon.
4384     *
4385     * @param packageName The name of the package that this icon is coming from.
4386     * Cannot be null.
4387     * @param resid The resource identifier of the desired image.  Cannot be 0.
4388     * @param appInfo Overall information about <var>packageName</var>.  This
4389     * may be null, in which case the application information will be retrieved
4390     * for you if needed; if you already have this information around, it can
4391     * be much more efficient to supply it here.
4392     *
4393     * @return Returns a Drawable holding the requested image.  Returns null if
4394     * an image could not be found for any reason.
4395     */
4396    public abstract Drawable getDrawable(String packageName, @DrawableRes int resid,
4397            ApplicationInfo appInfo);
4398
4399    /**
4400     * Retrieve the icon associated with an activity.  Given the full name of
4401     * an activity, retrieves the information about it and calls
4402     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its icon.
4403     * If the activity cannot be found, NameNotFoundException is thrown.
4404     *
4405     * @param activityName Name of the activity whose icon is to be retrieved.
4406     *
4407     * @return Returns the image of the icon, or the default activity icon if
4408     * it could not be found.  Does not return null.
4409     * @throws NameNotFoundException Thrown if the resources for the given
4410     * activity could not be loaded.
4411     *
4412     * @see #getActivityIcon(Intent)
4413     */
4414    public abstract Drawable getActivityIcon(ComponentName activityName)
4415            throws NameNotFoundException;
4416
4417    /**
4418     * Retrieve the icon associated with an Intent.  If intent.getClassName() is
4419     * set, this simply returns the result of
4420     * getActivityIcon(intent.getClassName()).  Otherwise it resolves the intent's
4421     * component and returns the icon associated with the resolved component.
4422     * If intent.getClassName() cannot be found or the Intent cannot be resolved
4423     * to a component, NameNotFoundException is thrown.
4424     *
4425     * @param intent The intent for which you would like to retrieve an icon.
4426     *
4427     * @return Returns the image of the icon, or the default activity icon if
4428     * it could not be found.  Does not return null.
4429     * @throws NameNotFoundException Thrown if the resources for application
4430     * matching the given intent could not be loaded.
4431     *
4432     * @see #getActivityIcon(ComponentName)
4433     */
4434    public abstract Drawable getActivityIcon(Intent intent)
4435            throws NameNotFoundException;
4436
4437    /**
4438     * Retrieve the banner associated with an activity. Given the full name of
4439     * an activity, retrieves the information about it and calls
4440     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its
4441     * banner. If the activity cannot be found, NameNotFoundException is thrown.
4442     *
4443     * @param activityName Name of the activity whose banner is to be retrieved.
4444     * @return Returns the image of the banner, or null if the activity has no
4445     *         banner specified.
4446     * @throws NameNotFoundException Thrown if the resources for the given
4447     *             activity could not be loaded.
4448     * @see #getActivityBanner(Intent)
4449     */
4450    public abstract Drawable getActivityBanner(ComponentName activityName)
4451            throws NameNotFoundException;
4452
4453    /**
4454     * Retrieve the banner associated with an Intent. If intent.getClassName()
4455     * is set, this simply returns the result of
4456     * getActivityBanner(intent.getClassName()). Otherwise it resolves the
4457     * intent's component and returns the banner associated with the resolved
4458     * component. If intent.getClassName() cannot be found or the Intent cannot
4459     * be resolved to a component, NameNotFoundException is thrown.
4460     *
4461     * @param intent The intent for which you would like to retrieve a banner.
4462     * @return Returns the image of the banner, or null if the activity has no
4463     *         banner specified.
4464     * @throws NameNotFoundException Thrown if the resources for application
4465     *             matching the given intent could not be loaded.
4466     * @see #getActivityBanner(ComponentName)
4467     */
4468    public abstract Drawable getActivityBanner(Intent intent)
4469            throws NameNotFoundException;
4470
4471    /**
4472     * Return the generic icon for an activity that is used when no specific
4473     * icon is defined.
4474     *
4475     * @return Drawable Image of the icon.
4476     */
4477    public abstract Drawable getDefaultActivityIcon();
4478
4479    /**
4480     * Retrieve the icon associated with an application.  If it has not defined
4481     * an icon, the default app icon is returned.  Does not return null.
4482     *
4483     * @param info Information about application being queried.
4484     *
4485     * @return Returns the image of the icon, or the default application icon
4486     * if it could not be found.
4487     *
4488     * @see #getApplicationIcon(String)
4489     */
4490    public abstract Drawable getApplicationIcon(ApplicationInfo info);
4491
4492    /**
4493     * Retrieve the icon associated with an application.  Given the name of the
4494     * application's package, retrieves the information about it and calls
4495     * getApplicationIcon() to return its icon. If the application cannot be
4496     * found, NameNotFoundException is thrown.
4497     *
4498     * @param packageName Name of the package whose application icon is to be
4499     *                    retrieved.
4500     *
4501     * @return Returns the image of the icon, or the default application icon
4502     * if it could not be found.  Does not return null.
4503     * @throws NameNotFoundException Thrown if the resources for the given
4504     * application could not be loaded.
4505     *
4506     * @see #getApplicationIcon(ApplicationInfo)
4507     */
4508    public abstract Drawable getApplicationIcon(String packageName)
4509            throws NameNotFoundException;
4510
4511    /**
4512     * Retrieve the banner associated with an application.
4513     *
4514     * @param info Information about application being queried.
4515     * @return Returns the image of the banner or null if the application has no
4516     *         banner specified.
4517     * @see #getApplicationBanner(String)
4518     */
4519    public abstract Drawable getApplicationBanner(ApplicationInfo info);
4520
4521    /**
4522     * Retrieve the banner associated with an application. Given the name of the
4523     * application's package, retrieves the information about it and calls
4524     * getApplicationIcon() to return its banner. If the application cannot be
4525     * found, NameNotFoundException is thrown.
4526     *
4527     * @param packageName Name of the package whose application banner is to be
4528     *            retrieved.
4529     * @return Returns the image of the banner or null if the application has no
4530     *         banner specified.
4531     * @throws NameNotFoundException Thrown if the resources for the given
4532     *             application could not be loaded.
4533     * @see #getApplicationBanner(ApplicationInfo)
4534     */
4535    public abstract Drawable getApplicationBanner(String packageName)
4536            throws NameNotFoundException;
4537
4538    /**
4539     * Retrieve the logo associated with an activity. Given the full name of an
4540     * activity, retrieves the information about it and calls
4541     * {@link ComponentInfo#loadLogo ComponentInfo.loadLogo()} to return its
4542     * logo. If the activity cannot be found, NameNotFoundException is thrown.
4543     *
4544     * @param activityName Name of the activity whose logo is to be retrieved.
4545     * @return Returns the image of the logo or null if the activity has no logo
4546     *         specified.
4547     * @throws NameNotFoundException Thrown if the resources for the given
4548     *             activity could not be loaded.
4549     * @see #getActivityLogo(Intent)
4550     */
4551    public abstract Drawable getActivityLogo(ComponentName activityName)
4552            throws NameNotFoundException;
4553
4554    /**
4555     * Retrieve the logo associated with an Intent.  If intent.getClassName() is
4556     * set, this simply returns the result of
4557     * getActivityLogo(intent.getClassName()).  Otherwise it resolves the intent's
4558     * component and returns the logo associated with the resolved component.
4559     * If intent.getClassName() cannot be found or the Intent cannot be resolved
4560     * to a component, NameNotFoundException is thrown.
4561     *
4562     * @param intent The intent for which you would like to retrieve a logo.
4563     *
4564     * @return Returns the image of the logo, or null if the activity has no
4565     * logo specified.
4566     *
4567     * @throws NameNotFoundException Thrown if the resources for application
4568     * matching the given intent could not be loaded.
4569     *
4570     * @see #getActivityLogo(ComponentName)
4571     */
4572    public abstract Drawable getActivityLogo(Intent intent)
4573            throws NameNotFoundException;
4574
4575    /**
4576     * Retrieve the logo associated with an application.  If it has not specified
4577     * a logo, this method returns null.
4578     *
4579     * @param info Information about application being queried.
4580     *
4581     * @return Returns the image of the logo, or null if no logo is specified
4582     * by the application.
4583     *
4584     * @see #getApplicationLogo(String)
4585     */
4586    public abstract Drawable getApplicationLogo(ApplicationInfo info);
4587
4588    /**
4589     * Retrieve the logo associated with an application.  Given the name of the
4590     * application's package, retrieves the information about it and calls
4591     * getApplicationLogo() to return its logo. If the application cannot be
4592     * found, NameNotFoundException is thrown.
4593     *
4594     * @param packageName Name of the package whose application logo is to be
4595     *                    retrieved.
4596     *
4597     * @return Returns the image of the logo, or null if no application logo
4598     * has been specified.
4599     *
4600     * @throws NameNotFoundException Thrown if the resources for the given
4601     * application could not be loaded.
4602     *
4603     * @see #getApplicationLogo(ApplicationInfo)
4604     */
4605    public abstract Drawable getApplicationLogo(String packageName)
4606            throws NameNotFoundException;
4607
4608    /**
4609     * If the target user is a managed profile, then this returns a badged copy of the given icon
4610     * to be able to distinguish it from the original icon. For badging an arbitrary drawable use
4611     * {@link #getUserBadgedDrawableForDensity(
4612     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
4613     * <p>
4614     * If the original drawable is a BitmapDrawable and the backing bitmap is
4615     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
4616     * is performed in place and the original drawable is returned.
4617     * </p>
4618     *
4619     * @param icon The icon to badge.
4620     * @param user The target user.
4621     * @return A drawable that combines the original icon and a badge as
4622     *         determined by the system.
4623     */
4624    public abstract Drawable getUserBadgedIcon(Drawable icon, UserHandle user);
4625
4626    /**
4627     * If the target user is a managed profile of the calling user or the caller
4628     * is itself a managed profile, then this returns a badged copy of the given
4629     * drawable allowing the user to distinguish it from the original drawable.
4630     * The caller can specify the location in the bounds of the drawable to be
4631     * badged where the badge should be applied as well as the density of the
4632     * badge to be used.
4633     * <p>
4634     * If the original drawable is a BitmapDrawable and the backing bitmap is
4635     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
4636     * is performed in place and the original drawable is returned.
4637     * </p>
4638     *
4639     * @param drawable The drawable to badge.
4640     * @param user The target user.
4641     * @param badgeLocation Where in the bounds of the badged drawable to place
4642     *         the badge. If it's {@code null}, the badge is applied on top of the entire
4643     *         drawable being badged.
4644     * @param badgeDensity The optional desired density for the badge as per
4645     *         {@link android.util.DisplayMetrics#densityDpi}. If it's not positive,
4646     *         the density of the display is used.
4647     * @return A drawable that combines the original drawable and a badge as
4648     *         determined by the system.
4649     */
4650    public abstract Drawable getUserBadgedDrawableForDensity(Drawable drawable,
4651            UserHandle user, Rect badgeLocation, int badgeDensity);
4652
4653    /**
4654     * If the target user is a managed profile of the calling user or the caller
4655     * is itself a managed profile, then this returns a drawable to use as a small
4656     * icon to include in a view to distinguish it from the original icon.
4657     *
4658     * @param user The target user.
4659     * @param density The optional desired density for the badge as per
4660     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided
4661     *         the density of the current display is used.
4662     * @return the drawable or null if no drawable is required.
4663     * @hide
4664     */
4665    public abstract Drawable getUserBadgeForDensity(UserHandle user, int density);
4666
4667    /**
4668     * If the target user is a managed profile of the calling user or the caller
4669     * is itself a managed profile, then this returns a drawable to use as a small
4670     * icon to include in a view to distinguish it from the original icon. This version
4671     * doesn't have background protection and should be used over a light background instead of
4672     * a badge.
4673     *
4674     * @param user The target user.
4675     * @param density The optional desired density for the badge as per
4676     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided
4677     *         the density of the current display is used.
4678     * @return the drawable or null if no drawable is required.
4679     * @hide
4680     */
4681    public abstract Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density);
4682
4683    /**
4684     * If the target user is a managed profile of the calling user or the caller
4685     * is itself a managed profile, then this returns a copy of the label with
4686     * badging for accessibility services like talkback. E.g. passing in "Email"
4687     * and it might return "Work Email" for Email in the work profile.
4688     *
4689     * @param label The label to change.
4690     * @param user The target user.
4691     * @return A label that combines the original label and a badge as
4692     *         determined by the system.
4693     */
4694    public abstract CharSequence getUserBadgedLabel(CharSequence label, UserHandle user);
4695
4696    /**
4697     * Retrieve text from a package.  This is a low-level API used by
4698     * the various package manager info structures (such as
4699     * {@link ComponentInfo} to implement retrieval of their associated
4700     * labels and other text.
4701     *
4702     * @param packageName The name of the package that this text is coming from.
4703     * Cannot be null.
4704     * @param resid The resource identifier of the desired text.  Cannot be 0.
4705     * @param appInfo Overall information about <var>packageName</var>.  This
4706     * may be null, in which case the application information will be retrieved
4707     * for you if needed; if you already have this information around, it can
4708     * be much more efficient to supply it here.
4709     *
4710     * @return Returns a CharSequence holding the requested text.  Returns null
4711     * if the text could not be found for any reason.
4712     */
4713    public abstract CharSequence getText(String packageName, @StringRes int resid,
4714            ApplicationInfo appInfo);
4715
4716    /**
4717     * Retrieve an XML file from a package.  This is a low-level API used to
4718     * retrieve XML meta data.
4719     *
4720     * @param packageName The name of the package that this xml is coming from.
4721     * Cannot be null.
4722     * @param resid The resource identifier of the desired xml.  Cannot be 0.
4723     * @param appInfo Overall information about <var>packageName</var>.  This
4724     * may be null, in which case the application information will be retrieved
4725     * for you if needed; if you already have this information around, it can
4726     * be much more efficient to supply it here.
4727     *
4728     * @return Returns an XmlPullParser allowing you to parse out the XML
4729     * data.  Returns null if the xml resource could not be found for any
4730     * reason.
4731     */
4732    public abstract XmlResourceParser getXml(String packageName, @XmlRes int resid,
4733            ApplicationInfo appInfo);
4734
4735    /**
4736     * Return the label to use for this application.
4737     *
4738     * @return Returns the label associated with this application, or null if
4739     * it could not be found for any reason.
4740     * @param info The application to get the label of.
4741     */
4742    public abstract CharSequence getApplicationLabel(ApplicationInfo info);
4743
4744    /**
4745     * Retrieve the resources associated with an activity.  Given the full
4746     * name of an activity, retrieves the information about it and calls
4747     * getResources() to return its application's resources.  If the activity
4748     * cannot be found, NameNotFoundException is thrown.
4749     *
4750     * @param activityName Name of the activity whose resources are to be
4751     *                     retrieved.
4752     *
4753     * @return Returns the application's Resources.
4754     * @throws NameNotFoundException Thrown if the resources for the given
4755     * application could not be loaded.
4756     *
4757     * @see #getResourcesForApplication(ApplicationInfo)
4758     */
4759    public abstract Resources getResourcesForActivity(ComponentName activityName)
4760            throws NameNotFoundException;
4761
4762    /**
4763     * Retrieve the resources for an application.  Throws NameNotFoundException
4764     * if the package is no longer installed.
4765     *
4766     * @param app Information about the desired application.
4767     *
4768     * @return Returns the application's Resources.
4769     * @throws NameNotFoundException Thrown if the resources for the given
4770     * application could not be loaded (most likely because it was uninstalled).
4771     */
4772    public abstract Resources getResourcesForApplication(ApplicationInfo app)
4773            throws NameNotFoundException;
4774
4775    /**
4776     * Retrieve the resources associated with an application.  Given the full
4777     * package name of an application, retrieves the information about it and
4778     * calls getResources() to return its application's resources.  If the
4779     * appPackageName cannot be found, NameNotFoundException is thrown.
4780     *
4781     * @param appPackageName Package name of the application whose resources
4782     *                       are to be retrieved.
4783     *
4784     * @return Returns the application's Resources.
4785     * @throws NameNotFoundException Thrown if the resources for the given
4786     * application could not be loaded.
4787     *
4788     * @see #getResourcesForApplication(ApplicationInfo)
4789     */
4790    public abstract Resources getResourcesForApplication(String appPackageName)
4791            throws NameNotFoundException;
4792
4793    /** @hide */
4794    public abstract Resources getResourcesForApplicationAsUser(String appPackageName,
4795            @UserIdInt int userId) throws NameNotFoundException;
4796
4797    /**
4798     * Retrieve overall information about an application package defined in a
4799     * package archive file
4800     *
4801     * @param archiveFilePath The path to the archive file
4802     * @param flags Additional option flags to modify the data returned.
4803     * @return A PackageInfo object containing information about the package
4804     *         archive. If the package could not be parsed, returns null.
4805     */
4806    public PackageInfo getPackageArchiveInfo(String archiveFilePath, @PackageInfoFlags int flags) {
4807        final PackageParser parser = new PackageParser();
4808        parser.setCallback(new PackageParser.CallbackImpl(this));
4809        final File apkFile = new File(archiveFilePath);
4810        try {
4811            if ((flags & (MATCH_DIRECT_BOOT_UNAWARE | MATCH_DIRECT_BOOT_AWARE)) != 0) {
4812                // Caller expressed an explicit opinion about what encryption
4813                // aware/unaware components they want to see, so fall through and
4814                // give them what they want
4815            } else {
4816                // Caller expressed no opinion, so match everything
4817                flags |= MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE;
4818            }
4819
4820            PackageParser.Package pkg = parser.parseMonolithicPackage(apkFile, 0);
4821            if ((flags & GET_SIGNATURES) != 0) {
4822                PackageParser.collectCertificates(pkg, false /* skipVerify */);
4823            }
4824            PackageUserState state = new PackageUserState();
4825            return PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, state);
4826        } catch (PackageParserException e) {
4827            return null;
4828        }
4829    }
4830
4831    /**
4832     * If there is already an application with the given package name installed
4833     * on the system for other users, also install it for the calling user.
4834     * @hide
4835     */
4836    @SystemApi
4837    public abstract int installExistingPackage(String packageName) throws NameNotFoundException;
4838
4839    /**
4840     * If there is already an application with the given package name installed
4841     * on the system for other users, also install it for the calling user.
4842     * @hide
4843     */
4844    @SystemApi
4845    public abstract int installExistingPackage(String packageName, @InstallReason int installReason)
4846            throws NameNotFoundException;
4847
4848    /**
4849     * If there is already an application with the given package name installed
4850     * on the system for other users, also install it for the specified user.
4851     * @hide
4852     */
4853    @RequiresPermission(anyOf = {
4854            Manifest.permission.INSTALL_EXISTING_PACKAGES,
4855            Manifest.permission.INSTALL_PACKAGES,
4856            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
4857    public abstract int installExistingPackageAsUser(String packageName, @UserIdInt int userId)
4858            throws NameNotFoundException;
4859
4860    /**
4861     * Allows a package listening to the
4862     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
4863     * broadcast} to respond to the package manager. The response must include
4864     * the {@code verificationCode} which is one of
4865     * {@link PackageManager#VERIFICATION_ALLOW} or
4866     * {@link PackageManager#VERIFICATION_REJECT}.
4867     *
4868     * @param id pending package identifier as passed via the
4869     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
4870     * @param verificationCode either {@link PackageManager#VERIFICATION_ALLOW}
4871     *            or {@link PackageManager#VERIFICATION_REJECT}.
4872     * @throws SecurityException if the caller does not have the
4873     *            PACKAGE_VERIFICATION_AGENT permission.
4874     */
4875    public abstract void verifyPendingInstall(int id, int verificationCode);
4876
4877    /**
4878     * Allows a package listening to the
4879     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
4880     * broadcast} to extend the default timeout for a response and declare what
4881     * action to perform after the timeout occurs. The response must include
4882     * the {@code verificationCodeAtTimeout} which is one of
4883     * {@link PackageManager#VERIFICATION_ALLOW} or
4884     * {@link PackageManager#VERIFICATION_REJECT}.
4885     *
4886     * This method may only be called once per package id. Additional calls
4887     * will have no effect.
4888     *
4889     * @param id pending package identifier as passed via the
4890     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
4891     * @param verificationCodeAtTimeout either
4892     *            {@link PackageManager#VERIFICATION_ALLOW} or
4893     *            {@link PackageManager#VERIFICATION_REJECT}. If
4894     *            {@code verificationCodeAtTimeout} is neither
4895     *            {@link PackageManager#VERIFICATION_ALLOW} or
4896     *            {@link PackageManager#VERIFICATION_REJECT}, then
4897     *            {@code verificationCodeAtTimeout} will default to
4898     *            {@link PackageManager#VERIFICATION_REJECT}.
4899     * @param millisecondsToDelay the amount of time requested for the timeout.
4900     *            Must be positive and less than
4901     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}. If
4902     *            {@code millisecondsToDelay} is out of bounds,
4903     *            {@code millisecondsToDelay} will be set to the closest in
4904     *            bounds value; namely, 0 or
4905     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}.
4906     * @throws SecurityException if the caller does not have the
4907     *            PACKAGE_VERIFICATION_AGENT permission.
4908     */
4909    public abstract void extendVerificationTimeout(int id,
4910            int verificationCodeAtTimeout, long millisecondsToDelay);
4911
4912    /**
4913     * Allows a package listening to the
4914     * {@link Intent#ACTION_INTENT_FILTER_NEEDS_VERIFICATION} intent filter verification
4915     * broadcast to respond to the package manager. The response must include
4916     * the {@code verificationCode} which is one of
4917     * {@link PackageManager#INTENT_FILTER_VERIFICATION_SUCCESS} or
4918     * {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}.
4919     *
4920     * @param verificationId pending package identifier as passed via the
4921     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
4922     * @param verificationCode either {@link PackageManager#INTENT_FILTER_VERIFICATION_SUCCESS}
4923     *            or {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}.
4924     * @param failedDomains a list of failed domains if the verificationCode is
4925     *            {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}, otherwise null;
4926     * @throws SecurityException if the caller does not have the
4927     *            INTENT_FILTER_VERIFICATION_AGENT permission.
4928     *
4929     * @hide
4930     */
4931    @SystemApi
4932    @RequiresPermission(android.Manifest.permission.INTENT_FILTER_VERIFICATION_AGENT)
4933    public abstract void verifyIntentFilter(int verificationId, int verificationCode,
4934            List<String> failedDomains);
4935
4936    /**
4937     * Get the status of a Domain Verification Result for an IntentFilter. This is
4938     * related to the {@link android.content.IntentFilter#setAutoVerify(boolean)} and
4939     * {@link android.content.IntentFilter#getAutoVerify()}
4940     *
4941     * This is used by the ResolverActivity to change the status depending on what the User select
4942     * in the Disambiguation Dialog and also used by the Settings App for changing the default App
4943     * for a domain.
4944     *
4945     * @param packageName The package name of the Activity associated with the IntentFilter.
4946     * @param userId The user id.
4947     *
4948     * @return The status to set to. This can be
4949     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK} or
4950     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS} or
4951     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER} or
4952     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED}
4953     *
4954     * @hide
4955     */
4956    @SystemApi
4957    @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL)
4958    public abstract int getIntentVerificationStatusAsUser(String packageName, @UserIdInt int userId);
4959
4960    /**
4961     * Allow to change the status of a Intent Verification status for all IntentFilter of an App.
4962     * This is related to the {@link android.content.IntentFilter#setAutoVerify(boolean)} and
4963     * {@link android.content.IntentFilter#getAutoVerify()}
4964     *
4965     * This is used by the ResolverActivity to change the status depending on what the User select
4966     * in the Disambiguation Dialog and also used by the Settings App for changing the default App
4967     * for a domain.
4968     *
4969     * @param packageName The package name of the Activity associated with the IntentFilter.
4970     * @param status The status to set to. This can be
4971     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK} or
4972     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS} or
4973     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER}
4974     * @param userId The user id.
4975     *
4976     * @return true if the status has been set. False otherwise.
4977     *
4978     * @hide
4979     */
4980    @SystemApi
4981    @RequiresPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS)
4982    public abstract boolean updateIntentVerificationStatusAsUser(String packageName, int status,
4983            @UserIdInt int userId);
4984
4985    /**
4986     * Get the list of IntentFilterVerificationInfo for a specific package and User.
4987     *
4988     * @param packageName the package name. When this parameter is set to a non null value,
4989     *                    the results will be filtered by the package name provided.
4990     *                    Otherwise, there will be no filtering and it will return a list
4991     *                    corresponding for all packages
4992     *
4993     * @return a list of IntentFilterVerificationInfo for a specific package.
4994     *
4995     * @hide
4996     */
4997    @SystemApi
4998    public abstract List<IntentFilterVerificationInfo> getIntentFilterVerifications(
4999            String packageName);
5000
5001    /**
5002     * Get the list of IntentFilter for a specific package.
5003     *
5004     * @param packageName the package name. This parameter is set to a non null value,
5005     *                    the list will contain all the IntentFilter for that package.
5006     *                    Otherwise, the list will be empty.
5007     *
5008     * @return a list of IntentFilter for a specific package.
5009     *
5010     * @hide
5011     */
5012    @SystemApi
5013    public abstract List<IntentFilter> getAllIntentFilters(String packageName);
5014
5015    /**
5016     * Get the default Browser package name for a specific user.
5017     *
5018     * @param userId The user id.
5019     *
5020     * @return the package name of the default Browser for the specified user. If the user id passed
5021     *         is -1 (all users) it will return a null value.
5022     *
5023     * @hide
5024     */
5025    @TestApi
5026    @SystemApi
5027    @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL)
5028    public abstract String getDefaultBrowserPackageNameAsUser(@UserIdInt int userId);
5029
5030    /**
5031     * Set the default Browser package name for a specific user.
5032     *
5033     * @param packageName The package name of the default Browser.
5034     * @param userId The user id.
5035     *
5036     * @return true if the default Browser for the specified user has been set,
5037     *         otherwise return false. If the user id passed is -1 (all users) this call will not
5038     *         do anything and just return false.
5039     *
5040     * @hide
5041     */
5042    @SystemApi
5043    @RequiresPermission(allOf = {
5044            Manifest.permission.SET_PREFERRED_APPLICATIONS,
5045            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5046    public abstract boolean setDefaultBrowserPackageNameAsUser(String packageName,
5047            @UserIdInt int userId);
5048
5049    /**
5050     * Change the installer associated with a given package.  There are limitations
5051     * on how the installer package can be changed; in particular:
5052     * <ul>
5053     * <li> A SecurityException will be thrown if <var>installerPackageName</var>
5054     * is not signed with the same certificate as the calling application.
5055     * <li> A SecurityException will be thrown if <var>targetPackage</var> already
5056     * has an installer package, and that installer package is not signed with
5057     * the same certificate as the calling application.
5058     * </ul>
5059     *
5060     * @param targetPackage The installed package whose installer will be changed.
5061     * @param installerPackageName The package name of the new installer.  May be
5062     * null to clear the association.
5063     */
5064    public abstract void setInstallerPackageName(String targetPackage,
5065            String installerPackageName);
5066
5067    /** @hide */
5068    @SystemApi
5069    @RequiresPermission(Manifest.permission.INSTALL_PACKAGES)
5070    public abstract void setUpdateAvailable(String packageName, boolean updateAvaialble);
5071
5072    /**
5073     * Attempts to delete a package. Since this may take a little while, the
5074     * result will be posted back to the given observer. A deletion will fail if
5075     * the calling context lacks the
5076     * {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the
5077     * named package cannot be found, or if the named package is a system
5078     * package.
5079     *
5080     * @param packageName The name of the package to delete
5081     * @param observer An observer callback to get notified when the package
5082     *            deletion is complete.
5083     *            {@link android.content.pm.IPackageDeleteObserver#packageDeleted}
5084     *            will be called when that happens. observer may be null to
5085     *            indicate that no callback is desired.
5086     * @hide
5087     */
5088    @RequiresPermission(Manifest.permission.DELETE_PACKAGES)
5089    public abstract void deletePackage(String packageName, IPackageDeleteObserver observer,
5090            @DeleteFlags int flags);
5091
5092    /**
5093     * Attempts to delete a package. Since this may take a little while, the
5094     * result will be posted back to the given observer. A deletion will fail if
5095     * the named package cannot be found, or if the named package is a system
5096     * package.
5097     *
5098     * @param packageName The name of the package to delete
5099     * @param observer An observer callback to get notified when the package
5100     *            deletion is complete.
5101     *            {@link android.content.pm.IPackageDeleteObserver#packageDeleted}
5102     *            will be called when that happens. observer may be null to
5103     *            indicate that no callback is desired.
5104     * @param userId The user Id
5105     * @hide
5106     */
5107    @RequiresPermission(anyOf = {
5108            Manifest.permission.DELETE_PACKAGES,
5109            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
5110    public abstract void deletePackageAsUser(@NonNull String packageName,
5111            IPackageDeleteObserver observer, @DeleteFlags int flags, @UserIdInt int userId);
5112
5113    /**
5114     * Retrieve the package name of the application that installed a package. This identifies
5115     * which market the package came from.
5116     *
5117     * @param packageName The name of the package to query
5118     * @throws IllegalArgumentException if the given package name is not installed
5119     */
5120    public abstract String getInstallerPackageName(String packageName);
5121
5122    /**
5123     * Attempts to clear the user data directory of an application.
5124     * Since this may take a little while, the result will
5125     * be posted back to the given observer.  A deletion will fail if the
5126     * named package cannot be found, or if the named package is a "system package".
5127     *
5128     * @param packageName The name of the package
5129     * @param observer An observer callback to get notified when the operation is finished
5130     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
5131     * will be called when that happens.  observer may be null to indicate that
5132     * no callback is desired.
5133     *
5134     * @hide
5135     */
5136    public abstract void clearApplicationUserData(String packageName,
5137            IPackageDataObserver observer);
5138    /**
5139     * Attempts to delete the cache files associated with an application.
5140     * Since this may take a little while, the result will
5141     * be posted back to the given observer.  A deletion will fail if the calling context
5142     * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the
5143     * named package cannot be found, or if the named package is a "system package".
5144     *
5145     * @param packageName The name of the package to delete
5146     * @param observer An observer callback to get notified when the cache file deletion
5147     * is complete.
5148     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
5149     * will be called when that happens.  observer may be null to indicate that
5150     * no callback is desired.
5151     *
5152     * @hide
5153     */
5154    public abstract void deleteApplicationCacheFiles(String packageName,
5155            IPackageDataObserver observer);
5156
5157    /**
5158     * Attempts to delete the cache files associated with an application for a given user. Since
5159     * this may take a little while, the result will be posted back to the given observer. A
5160     * deletion will fail if the calling context lacks the
5161     * {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the named package
5162     * cannot be found, or if the named package is a "system package". If {@code userId} does not
5163     * belong to the calling user, the caller must have
5164     * {@link android.Manifest.permission#INTERACT_ACROSS_USERS} permission.
5165     *
5166     * @param packageName The name of the package to delete
5167     * @param userId the user for which the cache files needs to be deleted
5168     * @param observer An observer callback to get notified when the cache file deletion is
5169     *            complete.
5170     *            {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
5171     *            will be called when that happens. observer may be null to indicate that no
5172     *            callback is desired.
5173     * @hide
5174     */
5175    public abstract void deleteApplicationCacheFilesAsUser(String packageName, int userId,
5176            IPackageDataObserver observer);
5177
5178    /**
5179     * Free storage by deleting LRU sorted list of cache files across
5180     * all applications. If the currently available free storage
5181     * on the device is greater than or equal to the requested
5182     * free storage, no cache files are cleared. If the currently
5183     * available storage on the device is less than the requested
5184     * free storage, some or all of the cache files across
5185     * all applications are deleted (based on last accessed time)
5186     * to increase the free storage space on the device to
5187     * the requested value. There is no guarantee that clearing all
5188     * the cache files from all applications will clear up
5189     * enough storage to achieve the desired value.
5190     * @param freeStorageSize The number of bytes of storage to be
5191     * freed by the system. Say if freeStorageSize is XX,
5192     * and the current free storage is YY,
5193     * if XX is less than YY, just return. if not free XX-YY number
5194     * of bytes if possible.
5195     * @param observer call back used to notify when
5196     * the operation is completed
5197     *
5198     * @hide
5199     */
5200    public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
5201        freeStorageAndNotify(null, freeStorageSize, observer);
5202    }
5203
5204    /** {@hide} */
5205    public abstract void freeStorageAndNotify(String volumeUuid, long freeStorageSize,
5206            IPackageDataObserver observer);
5207
5208    /**
5209     * Free storage by deleting LRU sorted list of cache files across
5210     * all applications. If the currently available free storage
5211     * on the device is greater than or equal to the requested
5212     * free storage, no cache files are cleared. If the currently
5213     * available storage on the device is less than the requested
5214     * free storage, some or all of the cache files across
5215     * all applications are deleted (based on last accessed time)
5216     * to increase the free storage space on the device to
5217     * the requested value. There is no guarantee that clearing all
5218     * the cache files from all applications will clear up
5219     * enough storage to achieve the desired value.
5220     * @param freeStorageSize The number of bytes of storage to be
5221     * freed by the system. Say if freeStorageSize is XX,
5222     * and the current free storage is YY,
5223     * if XX is less than YY, just return. if not free XX-YY number
5224     * of bytes if possible.
5225     * @param pi IntentSender call back used to
5226     * notify when the operation is completed.May be null
5227     * to indicate that no call back is desired.
5228     *
5229     * @hide
5230     */
5231    public void freeStorage(long freeStorageSize, IntentSender pi) {
5232        freeStorage(null, freeStorageSize, pi);
5233    }
5234
5235    /** {@hide} */
5236    public abstract void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi);
5237
5238    /**
5239     * Retrieve the size information for a package.
5240     * Since this may take a little while, the result will
5241     * be posted back to the given observer.  The calling context
5242     * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission.
5243     *
5244     * @param packageName The name of the package whose size information is to be retrieved
5245     * @param userId The user whose size information should be retrieved.
5246     * @param observer An observer callback to get notified when the operation
5247     * is complete.
5248     * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)}
5249     * The observer's callback is invoked with a PackageStats object(containing the
5250     * code, data and cache sizes of the package) and a boolean value representing
5251     * the status of the operation. observer may be null to indicate that
5252     * no callback is desired.
5253     *
5254     * @deprecated use {@link StorageStatsManager} instead.
5255     * @hide
5256     */
5257    @Deprecated
5258    public abstract void getPackageSizeInfoAsUser(String packageName, @UserIdInt int userId,
5259            IPackageStatsObserver observer);
5260
5261    /**
5262     * Like {@link #getPackageSizeInfoAsUser(String, int, IPackageStatsObserver)}, but
5263     * returns the size for the calling user.
5264     *
5265     * @deprecated use {@link StorageStatsManager} instead.
5266     * @hide
5267     */
5268    @Deprecated
5269    public void getPackageSizeInfo(String packageName, IPackageStatsObserver observer) {
5270        getPackageSizeInfoAsUser(packageName, getUserId(), observer);
5271    }
5272
5273    /**
5274     * @deprecated This function no longer does anything; it was an old
5275     * approach to managing preferred activities, which has been superseded
5276     * by (and conflicts with) the modern activity-based preferences.
5277     */
5278    @Deprecated
5279    public abstract void addPackageToPreferred(String packageName);
5280
5281    /**
5282     * @deprecated This function no longer does anything; it was an old
5283     * approach to managing preferred activities, which has been superseded
5284     * by (and conflicts with) the modern activity-based preferences.
5285     */
5286    @Deprecated
5287    public abstract void removePackageFromPreferred(String packageName);
5288
5289    /**
5290     * Retrieve the list of all currently configured preferred packages. The
5291     * first package on the list is the most preferred, the last is the least
5292     * preferred.
5293     *
5294     * @param flags Additional option flags to modify the data returned.
5295     * @return A List of PackageInfo objects, one for each preferred
5296     *         application, in order of preference.
5297     */
5298    public abstract List<PackageInfo> getPreferredPackages(@PackageInfoFlags int flags);
5299
5300    /**
5301     * @deprecated This is a protected API that should not have been available
5302     * to third party applications.  It is the platform's responsibility for
5303     * assigning preferred activities and this cannot be directly modified.
5304     *
5305     * Add a new preferred activity mapping to the system.  This will be used
5306     * to automatically select the given activity component when
5307     * {@link Context#startActivity(Intent) Context.startActivity()} finds
5308     * multiple matching activities and also matches the given filter.
5309     *
5310     * @param filter The set of intents under which this activity will be
5311     * made preferred.
5312     * @param match The IntentFilter match category that this preference
5313     * applies to.
5314     * @param set The set of activities that the user was picking from when
5315     * this preference was made.
5316     * @param activity The component name of the activity that is to be
5317     * preferred.
5318     */
5319    @Deprecated
5320    public abstract void addPreferredActivity(IntentFilter filter, int match,
5321            ComponentName[] set, ComponentName activity);
5322
5323    /**
5324     * Same as {@link #addPreferredActivity(IntentFilter, int,
5325            ComponentName[], ComponentName)}, but with a specific userId to apply the preference
5326            to.
5327     * @hide
5328     */
5329    public void addPreferredActivityAsUser(IntentFilter filter, int match,
5330            ComponentName[] set, ComponentName activity, @UserIdInt int userId) {
5331        throw new RuntimeException("Not implemented. Must override in a subclass.");
5332    }
5333
5334    /**
5335     * @deprecated This is a protected API that should not have been available
5336     * to third party applications.  It is the platform's responsibility for
5337     * assigning preferred activities and this cannot be directly modified.
5338     *
5339     * Replaces an existing preferred activity mapping to the system, and if that were not present
5340     * adds a new preferred activity.  This will be used
5341     * to automatically select the given activity component when
5342     * {@link Context#startActivity(Intent) Context.startActivity()} finds
5343     * multiple matching activities and also matches the given filter.
5344     *
5345     * @param filter The set of intents under which this activity will be
5346     * made preferred.
5347     * @param match The IntentFilter match category that this preference
5348     * applies to.
5349     * @param set The set of activities that the user was picking from when
5350     * this preference was made.
5351     * @param activity The component name of the activity that is to be
5352     * preferred.
5353     * @hide
5354     */
5355    @Deprecated
5356    public abstract void replacePreferredActivity(IntentFilter filter, int match,
5357            ComponentName[] set, ComponentName activity);
5358
5359    /**
5360     * @hide
5361     */
5362    @Deprecated
5363    public void replacePreferredActivityAsUser(IntentFilter filter, int match,
5364           ComponentName[] set, ComponentName activity, @UserIdInt int userId) {
5365        throw new RuntimeException("Not implemented. Must override in a subclass.");
5366    }
5367
5368    /**
5369     * Remove all preferred activity mappings, previously added with
5370     * {@link #addPreferredActivity}, from the
5371     * system whose activities are implemented in the given package name.
5372     * An application can only clear its own package(s).
5373     *
5374     * @param packageName The name of the package whose preferred activity
5375     * mappings are to be removed.
5376     */
5377    public abstract void clearPackagePreferredActivities(String packageName);
5378
5379    /**
5380     * Retrieve all preferred activities, previously added with
5381     * {@link #addPreferredActivity}, that are
5382     * currently registered with the system.
5383     *
5384     * @param outFilters A required list in which to place the filters of all of the
5385     * preferred activities.
5386     * @param outActivities A required list in which to place the component names of
5387     * all of the preferred activities.
5388     * @param packageName An optional package in which you would like to limit
5389     * the list.  If null, all activities will be returned; if non-null, only
5390     * those activities in the given package are returned.
5391     *
5392     * @return Returns the total number of registered preferred activities
5393     * (the number of distinct IntentFilter records, not the number of unique
5394     * activity components) that were found.
5395     */
5396    public abstract int getPreferredActivities(@NonNull List<IntentFilter> outFilters,
5397            @NonNull List<ComponentName> outActivities, String packageName);
5398
5399    /**
5400     * Ask for the set of available 'home' activities and the current explicit
5401     * default, if any.
5402     * @hide
5403     */
5404    public abstract ComponentName getHomeActivities(List<ResolveInfo> outActivities);
5405
5406    /**
5407     * Set the enabled setting for a package component (activity, receiver, service, provider).
5408     * This setting will override any enabled state which may have been set by the component in its
5409     * manifest.
5410     *
5411     * @param componentName The component to enable
5412     * @param newState The new enabled state for the component.
5413     * @param flags Optional behavior flags.
5414     */
5415    public abstract void setComponentEnabledSetting(ComponentName componentName,
5416            @EnabledState int newState, @EnabledFlags int flags);
5417
5418    /**
5419     * Return the enabled setting for a package component (activity,
5420     * receiver, service, provider).  This returns the last value set by
5421     * {@link #setComponentEnabledSetting(ComponentName, int, int)}; in most
5422     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
5423     * the value originally specified in the manifest has not been modified.
5424     *
5425     * @param componentName The component to retrieve.
5426     * @return Returns the current enabled state for the component.
5427     */
5428    public abstract @EnabledState int getComponentEnabledSetting(
5429            ComponentName componentName);
5430
5431    /**
5432     * Set the enabled setting for an application
5433     * This setting will override any enabled state which may have been set by the application in
5434     * its manifest.  It also overrides the enabled state set in the manifest for any of the
5435     * application's components.  It does not override any enabled state set by
5436     * {@link #setComponentEnabledSetting} for any of the application's components.
5437     *
5438     * @param packageName The package name of the application to enable
5439     * @param newState The new enabled state for the application.
5440     * @param flags Optional behavior flags.
5441     */
5442    public abstract void setApplicationEnabledSetting(String packageName,
5443            @EnabledState int newState, @EnabledFlags int flags);
5444
5445    /**
5446     * Return the enabled setting for an application. This returns
5447     * the last value set by
5448     * {@link #setApplicationEnabledSetting(String, int, int)}; in most
5449     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
5450     * the value originally specified in the manifest has not been modified.
5451     *
5452     * @param packageName The package name of the application to retrieve.
5453     * @return Returns the current enabled state for the application.
5454     * @throws IllegalArgumentException if the named package does not exist.
5455     */
5456    public abstract @EnabledState int getApplicationEnabledSetting(String packageName);
5457
5458    /**
5459     * Flush the package restrictions for a given user to disk. This forces the package restrictions
5460     * like component and package enabled settings to be written to disk and avoids the delay that
5461     * is otherwise present when changing those settings.
5462     *
5463     * @param userId Ther userId of the user whose restrictions are to be flushed.
5464     * @hide
5465     */
5466    public abstract void flushPackageRestrictionsAsUser(int userId);
5467
5468    /**
5469     * Puts the package in a hidden state, which is almost like an uninstalled state,
5470     * making the package unavailable, but it doesn't remove the data or the actual
5471     * package file. Application can be unhidden by either resetting the hidden state
5472     * or by installing it, such as with {@link #installExistingPackage(String)}
5473     * @hide
5474     */
5475    public abstract boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
5476            UserHandle userHandle);
5477
5478    /**
5479     * Returns the hidden state of a package.
5480     * @see #setApplicationHiddenSettingAsUser(String, boolean, UserHandle)
5481     * @hide
5482     */
5483    public abstract boolean getApplicationHiddenSettingAsUser(String packageName,
5484            UserHandle userHandle);
5485
5486    /**
5487     * Return whether the device has been booted into safe mode.
5488     */
5489    public abstract boolean isSafeMode();
5490
5491    /**
5492     * Adds a listener for permission changes for installed packages.
5493     *
5494     * @param listener The listener to add.
5495     *
5496     * @hide
5497     */
5498    @SystemApi
5499    @RequiresPermission(Manifest.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS)
5500    public abstract void addOnPermissionsChangeListener(OnPermissionsChangedListener listener);
5501
5502    /**
5503     * Remvoes a listener for permission changes for installed packages.
5504     *
5505     * @param listener The listener to remove.
5506     *
5507     * @hide
5508     */
5509    @SystemApi
5510    @RequiresPermission(Manifest.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS)
5511    public abstract void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener);
5512
5513    /**
5514     * Return the {@link KeySet} associated with the String alias for this
5515     * application.
5516     *
5517     * @param alias The alias for a given {@link KeySet} as defined in the
5518     *        application's AndroidManifest.xml.
5519     * @hide
5520     */
5521    public abstract KeySet getKeySetByAlias(String packageName, String alias);
5522
5523    /** Return the signing {@link KeySet} for this application.
5524     * @hide
5525     */
5526    public abstract KeySet getSigningKeySet(String packageName);
5527
5528    /**
5529     * Return whether the package denoted by packageName has been signed by all
5530     * of the keys specified by the {@link KeySet} ks.  This will return true if
5531     * the package has been signed by additional keys (a superset) as well.
5532     * Compare to {@link #isSignedByExactly(String packageName, KeySet ks)}.
5533     * @hide
5534     */
5535    public abstract boolean isSignedBy(String packageName, KeySet ks);
5536
5537    /**
5538     * Return whether the package denoted by packageName has been signed by all
5539     * of, and only, the keys specified by the {@link KeySet} ks. Compare to
5540     * {@link #isSignedBy(String packageName, KeySet ks)}.
5541     * @hide
5542     */
5543    public abstract boolean isSignedByExactly(String packageName, KeySet ks);
5544
5545    /**
5546     * Puts the package in a suspended state, where attempts at starting activities are denied.
5547     *
5548     * <p>It doesn't remove the data or the actual package file. The application's notifications
5549     * will be hidden, any of its started activities will be stopped and it will not be able to
5550     * show toasts or system alert windows or ring the device.
5551     *
5552     * <p>When the user tries to launch a suspended app, a system dialog with the given
5553     * {@code dialogMessage} will be shown instead. Since the message is supplied to the system as
5554     * a {@link String}, the caller needs to take care of localization as needed.
5555     * The dialog message can optionally contain a placeholder for the name of the suspended app.
5556     * The system uses {@link String#format(Locale, String, Object...) String.format} to insert the
5557     * app name into the message, so an example format string could be {@code "The app %1$s is
5558     * currently suspended"}. This makes it easier for callers to provide a single message which
5559     * works for all the packages being suspended in a single call.
5560     *
5561     * <p>The package must already be installed. If the package is uninstalled while suspended
5562     * the package will no longer be suspended. </p>
5563     *
5564     * <p>Optionally, the suspending app can provide extra information in the form of
5565     * {@link PersistableBundle} objects to be shared with the apps being suspended and the
5566     * launcher to support customization that they might need to handle the suspended state.
5567     *
5568     * <p>The caller must hold {@link Manifest.permission#SUSPEND_APPS} or
5569     * {@link Manifest.permission#MANAGE_USERS} to use this api.</p>
5570     *
5571     * @param packageNames The names of the packages to set the suspended status.
5572     * @param suspended If set to {@code true} than the packages will be suspended, if set to
5573     * {@code false}, the packages will be unsuspended.
5574     * @param appExtras An optional {@link PersistableBundle} that the suspending app can provide
5575     *                  which will be shared with the apps being suspended. Ignored if
5576     *                  {@code suspended} is false.
5577     * @param launcherExtras An optional {@link PersistableBundle} that the suspending app can
5578     *                       provide which will be shared with the launcher. Ignored if
5579     *                       {@code suspended} is false.
5580     * @param dialogMessage The message to be displayed to the user, when they try to launch a
5581     *                      suspended app.
5582     *
5583     * @return an array of package names for which the suspended status could not be set as
5584     * requested in this method.
5585     *
5586     * @hide
5587     */
5588    @SystemApi
5589    @RequiresPermission(Manifest.permission.SUSPEND_APPS)
5590    public String[] setPackagesSuspended(String[] packageNames, boolean suspended,
5591            @Nullable PersistableBundle appExtras, @Nullable PersistableBundle launcherExtras,
5592            String dialogMessage) {
5593        throw new UnsupportedOperationException("setPackagesSuspended not implemented");
5594    }
5595
5596    /**
5597     * @see #setPackagesSuspended(String[], boolean, PersistableBundle, PersistableBundle, String)
5598     * @param packageName The name of the package to get the suspended status of.
5599     * @param userId The user id.
5600     * @return {@code true} if the package is suspended or {@code false} if the package is not
5601     * suspended.
5602     * @throws IllegalArgumentException if the package was not found.
5603     * @hide
5604     */
5605    public abstract boolean isPackageSuspendedForUser(String packageName, int userId);
5606
5607    /**
5608     * Query if an app is currently suspended.
5609     *
5610     * @return {@code true} if the given package is suspended, {@code false} otherwise
5611     * @throws NameNotFoundException if the package could not be found.
5612     *
5613     * @see #setPackagesSuspended(String[], boolean, PersistableBundle, PersistableBundle, String)
5614     * @hide
5615     */
5616    @SystemApi
5617    public boolean isPackageSuspended(String packageName) throws NameNotFoundException {
5618        throw new UnsupportedOperationException("isPackageSuspended not implemented");
5619    }
5620
5621    /**
5622     * Apps can query this to know if they have been suspended. A system app with the permission
5623     * {@code android.permission.SUSPEND_APPS} can put any app on the device into a suspended state.
5624     *
5625     * <p>While in this state, the application's notifications will be hidden, any of its started
5626     * activities will be stopped and it will not be able to show toasts or dialogs or ring the
5627     * device. When the user tries to launch a suspended app, the system will, instead, show a
5628     * dialog to the user informing them that they cannot use this app while it is suspended.
5629     *
5630     * <p>When an app is put into this state, the broadcast action
5631     * {@link Intent#ACTION_MY_PACKAGE_SUSPENDED} will be delivered to any of its broadcast
5632     * receivers that included this action in their intent-filters, <em>including manifest
5633     * receivers.</em> Similarly, a broadcast action {@link Intent#ACTION_MY_PACKAGE_UNSUSPENDED}
5634     * is delivered when a previously suspended app is taken out of this state.
5635     * </p>
5636     *
5637     * @return {@code true} if the calling package has been suspended, {@code false} otherwise.
5638     *
5639     * @see #getSuspendedPackageAppExtras()
5640     * @see Intent#ACTION_MY_PACKAGE_SUSPENDED
5641     * @see Intent#ACTION_MY_PACKAGE_UNSUSPENDED
5642     */
5643    public boolean isPackageSuspended() {
5644        throw new UnsupportedOperationException("isPackageSuspended not implemented");
5645    }
5646
5647    /**
5648     * Returns a {@link Bundle} of extras that was meant to be sent to the calling app when it was
5649     * suspended. An app with the permission {@code android.permission.SUSPEND_APPS} can supply this
5650     * to the system at the time of suspending an app.
5651     *
5652     * <p>This is the same {@link Bundle} that is sent along with the broadcast
5653     * {@link Intent#ACTION_MY_PACKAGE_SUSPENDED}, whenever the app is suspended. The contents of
5654     * this {@link Bundle} are a contract between the suspended app and the suspending app.
5655     *
5656     * <p>Note: These extras are optional, so if no extras were supplied to the system, this method
5657     * will return {@code null}, even when the calling app has been suspended.
5658     *
5659     * @return A {@link Bundle} containing the extras for the app, or {@code null} if the
5660     * package is not currently suspended.
5661     *
5662     * @see #isPackageSuspended()
5663     * @see Intent#ACTION_MY_PACKAGE_UNSUSPENDED
5664     * @see Intent#ACTION_MY_PACKAGE_SUSPENDED
5665     * @see Intent#EXTRA_SUSPENDED_PACKAGE_EXTRAS
5666     */
5667    public @Nullable Bundle getSuspendedPackageAppExtras() {
5668        throw new UnsupportedOperationException("getSuspendedPackageAppExtras not implemented");
5669    }
5670
5671    /**
5672     * Provide a hint of what the {@link ApplicationInfo#category} value should
5673     * be for the given package.
5674     * <p>
5675     * This hint can only be set by the app which installed this package, as
5676     * determined by {@link #getInstallerPackageName(String)}.
5677     *
5678     * @param packageName the package to change the category hint for.
5679     * @param categoryHint the category hint to set.
5680     */
5681    public abstract void setApplicationCategoryHint(@NonNull String packageName,
5682            @ApplicationInfo.Category int categoryHint);
5683
5684    /** {@hide} */
5685    public static boolean isMoveStatusFinished(int status) {
5686        return (status < 0 || status > 100);
5687    }
5688
5689    /** {@hide} */
5690    public static abstract class MoveCallback {
5691        public void onCreated(int moveId, Bundle extras) {}
5692        public abstract void onStatusChanged(int moveId, int status, long estMillis);
5693    }
5694
5695    /** {@hide} */
5696    public abstract int getMoveStatus(int moveId);
5697
5698    /** {@hide} */
5699    public abstract void registerMoveCallback(MoveCallback callback, Handler handler);
5700    /** {@hide} */
5701    public abstract void unregisterMoveCallback(MoveCallback callback);
5702
5703    /** {@hide} */
5704    public abstract int movePackage(String packageName, VolumeInfo vol);
5705    /** {@hide} */
5706    public abstract @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app);
5707    /** {@hide} */
5708    public abstract @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app);
5709
5710    /** {@hide} */
5711    public abstract int movePrimaryStorage(VolumeInfo vol);
5712    /** {@hide} */
5713    public abstract @Nullable VolumeInfo getPrimaryStorageCurrentVolume();
5714    /** {@hide} */
5715    public abstract @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes();
5716
5717    /**
5718     * Returns the device identity that verifiers can use to associate their scheme to a particular
5719     * device. This should not be used by anything other than a package verifier.
5720     *
5721     * @return identity that uniquely identifies current device
5722     * @hide
5723     */
5724    public abstract VerifierDeviceIdentity getVerifierDeviceIdentity();
5725
5726    /**
5727     * Returns true if the device is upgrading, such as first boot after OTA.
5728     *
5729     * @hide
5730     */
5731    public abstract boolean isUpgrade();
5732
5733    /**
5734     * Return interface that offers the ability to install, upgrade, and remove
5735     * applications on the device.
5736     */
5737    public abstract @NonNull PackageInstaller getPackageInstaller();
5738
5739    /**
5740     * Adds a {@code CrossProfileIntentFilter}. After calling this method all
5741     * intents sent from the user with id sourceUserId can also be be resolved
5742     * by activities in the user with id targetUserId if they match the
5743     * specified intent filter.
5744     *
5745     * @param filter The {@link IntentFilter} the intent has to match
5746     * @param sourceUserId The source user id.
5747     * @param targetUserId The target user id.
5748     * @param flags The possible values are {@link #SKIP_CURRENT_PROFILE} and
5749     *            {@link #ONLY_IF_NO_MATCH_FOUND}.
5750     * @hide
5751     */
5752    public abstract void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId,
5753            int targetUserId, int flags);
5754
5755    /**
5756     * Clearing {@code CrossProfileIntentFilter}s which have the specified user
5757     * as their source, and have been set by the app calling this method.
5758     *
5759     * @param sourceUserId The source user id.
5760     * @hide
5761     */
5762    public abstract void clearCrossProfileIntentFilters(int sourceUserId);
5763
5764    /**
5765     * @hide
5766     */
5767    public abstract Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
5768
5769    /**
5770     * @hide
5771     */
5772    public abstract Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
5773
5774    /** {@hide} */
5775    public abstract boolean isPackageAvailable(String packageName);
5776
5777    /** {@hide} */
5778    public static String installStatusToString(int status, String msg) {
5779        final String str = installStatusToString(status);
5780        if (msg != null) {
5781            return str + ": " + msg;
5782        } else {
5783            return str;
5784        }
5785    }
5786
5787    /** {@hide} */
5788    public static String installStatusToString(int status) {
5789        switch (status) {
5790            case INSTALL_SUCCEEDED: return "INSTALL_SUCCEEDED";
5791            case INSTALL_FAILED_ALREADY_EXISTS: return "INSTALL_FAILED_ALREADY_EXISTS";
5792            case INSTALL_FAILED_INVALID_APK: return "INSTALL_FAILED_INVALID_APK";
5793            case INSTALL_FAILED_INVALID_URI: return "INSTALL_FAILED_INVALID_URI";
5794            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return "INSTALL_FAILED_INSUFFICIENT_STORAGE";
5795            case INSTALL_FAILED_DUPLICATE_PACKAGE: return "INSTALL_FAILED_DUPLICATE_PACKAGE";
5796            case INSTALL_FAILED_NO_SHARED_USER: return "INSTALL_FAILED_NO_SHARED_USER";
5797            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return "INSTALL_FAILED_UPDATE_INCOMPATIBLE";
5798            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return "INSTALL_FAILED_SHARED_USER_INCOMPATIBLE";
5799            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return "INSTALL_FAILED_MISSING_SHARED_LIBRARY";
5800            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return "INSTALL_FAILED_REPLACE_COULDNT_DELETE";
5801            case INSTALL_FAILED_DEXOPT: return "INSTALL_FAILED_DEXOPT";
5802            case INSTALL_FAILED_OLDER_SDK: return "INSTALL_FAILED_OLDER_SDK";
5803            case INSTALL_FAILED_CONFLICTING_PROVIDER: return "INSTALL_FAILED_CONFLICTING_PROVIDER";
5804            case INSTALL_FAILED_NEWER_SDK: return "INSTALL_FAILED_NEWER_SDK";
5805            case INSTALL_FAILED_TEST_ONLY: return "INSTALL_FAILED_TEST_ONLY";
5806            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE";
5807            case INSTALL_FAILED_MISSING_FEATURE: return "INSTALL_FAILED_MISSING_FEATURE";
5808            case INSTALL_FAILED_CONTAINER_ERROR: return "INSTALL_FAILED_CONTAINER_ERROR";
5809            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return "INSTALL_FAILED_INVALID_INSTALL_LOCATION";
5810            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return "INSTALL_FAILED_MEDIA_UNAVAILABLE";
5811            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return "INSTALL_FAILED_VERIFICATION_TIMEOUT";
5812            case INSTALL_FAILED_VERIFICATION_FAILURE: return "INSTALL_FAILED_VERIFICATION_FAILURE";
5813            case INSTALL_FAILED_PACKAGE_CHANGED: return "INSTALL_FAILED_PACKAGE_CHANGED";
5814            case INSTALL_FAILED_UID_CHANGED: return "INSTALL_FAILED_UID_CHANGED";
5815            case INSTALL_FAILED_VERSION_DOWNGRADE: return "INSTALL_FAILED_VERSION_DOWNGRADE";
5816            case INSTALL_PARSE_FAILED_NOT_APK: return "INSTALL_PARSE_FAILED_NOT_APK";
5817            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return "INSTALL_PARSE_FAILED_BAD_MANIFEST";
5818            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return "INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION";
5819            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return "INSTALL_PARSE_FAILED_NO_CERTIFICATES";
5820            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return "INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES";
5821            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return "INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING";
5822            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return "INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME";
5823            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return "INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID";
5824            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return "INSTALL_PARSE_FAILED_MANIFEST_MALFORMED";
5825            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return "INSTALL_PARSE_FAILED_MANIFEST_EMPTY";
5826            case INSTALL_FAILED_INTERNAL_ERROR: return "INSTALL_FAILED_INTERNAL_ERROR";
5827            case INSTALL_FAILED_USER_RESTRICTED: return "INSTALL_FAILED_USER_RESTRICTED";
5828            case INSTALL_FAILED_DUPLICATE_PERMISSION: return "INSTALL_FAILED_DUPLICATE_PERMISSION";
5829            case INSTALL_FAILED_NO_MATCHING_ABIS: return "INSTALL_FAILED_NO_MATCHING_ABIS";
5830            case INSTALL_FAILED_ABORTED: return "INSTALL_FAILED_ABORTED";
5831            case INSTALL_FAILED_BAD_DEX_METADATA:
5832                return "INSTALL_FAILED_BAD_DEX_METADATA";
5833            default: return Integer.toString(status);
5834        }
5835    }
5836
5837    /** {@hide} */
5838    public static int installStatusToPublicStatus(int status) {
5839        switch (status) {
5840            case INSTALL_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
5841            case INSTALL_FAILED_ALREADY_EXISTS: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5842            case INSTALL_FAILED_INVALID_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
5843            case INSTALL_FAILED_INVALID_URI: return PackageInstaller.STATUS_FAILURE_INVALID;
5844            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return PackageInstaller.STATUS_FAILURE_STORAGE;
5845            case INSTALL_FAILED_DUPLICATE_PACKAGE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5846            case INSTALL_FAILED_NO_SHARED_USER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5847            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5848            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5849            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
5850            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5851            case INSTALL_FAILED_DEXOPT: return PackageInstaller.STATUS_FAILURE_INVALID;
5852            case INSTALL_FAILED_OLDER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
5853            case INSTALL_FAILED_CONFLICTING_PROVIDER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5854            case INSTALL_FAILED_NEWER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
5855            case INSTALL_FAILED_TEST_ONLY: return PackageInstaller.STATUS_FAILURE_INVALID;
5856            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
5857            case INSTALL_FAILED_MISSING_FEATURE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
5858            case INSTALL_FAILED_CONTAINER_ERROR: return PackageInstaller.STATUS_FAILURE_STORAGE;
5859            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return PackageInstaller.STATUS_FAILURE_STORAGE;
5860            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return PackageInstaller.STATUS_FAILURE_STORAGE;
5861            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return PackageInstaller.STATUS_FAILURE_ABORTED;
5862            case INSTALL_FAILED_VERIFICATION_FAILURE: return PackageInstaller.STATUS_FAILURE_ABORTED;
5863            case INSTALL_FAILED_PACKAGE_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
5864            case INSTALL_FAILED_UID_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
5865            case INSTALL_FAILED_VERSION_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
5866            case INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
5867            case INSTALL_PARSE_FAILED_NOT_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
5868            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return PackageInstaller.STATUS_FAILURE_INVALID;
5869            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return PackageInstaller.STATUS_FAILURE_INVALID;
5870            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
5871            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
5872            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return PackageInstaller.STATUS_FAILURE_INVALID;
5873            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return PackageInstaller.STATUS_FAILURE_INVALID;
5874            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return PackageInstaller.STATUS_FAILURE_INVALID;
5875            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return PackageInstaller.STATUS_FAILURE_INVALID;
5876            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return PackageInstaller.STATUS_FAILURE_INVALID;
5877            case INSTALL_FAILED_BAD_DEX_METADATA: return PackageInstaller.STATUS_FAILURE_INVALID;
5878            case INSTALL_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
5879            case INSTALL_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
5880            case INSTALL_FAILED_DUPLICATE_PERMISSION: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5881            case INSTALL_FAILED_NO_MATCHING_ABIS: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
5882            case INSTALL_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
5883            default: return PackageInstaller.STATUS_FAILURE;
5884        }
5885    }
5886
5887    /** {@hide} */
5888    public static String deleteStatusToString(int status, String msg) {
5889        final String str = deleteStatusToString(status);
5890        if (msg != null) {
5891            return str + ": " + msg;
5892        } else {
5893            return str;
5894        }
5895    }
5896
5897    /** {@hide} */
5898    public static String deleteStatusToString(int status) {
5899        switch (status) {
5900            case DELETE_SUCCEEDED: return "DELETE_SUCCEEDED";
5901            case DELETE_FAILED_INTERNAL_ERROR: return "DELETE_FAILED_INTERNAL_ERROR";
5902            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return "DELETE_FAILED_DEVICE_POLICY_MANAGER";
5903            case DELETE_FAILED_USER_RESTRICTED: return "DELETE_FAILED_USER_RESTRICTED";
5904            case DELETE_FAILED_OWNER_BLOCKED: return "DELETE_FAILED_OWNER_BLOCKED";
5905            case DELETE_FAILED_ABORTED: return "DELETE_FAILED_ABORTED";
5906            case DELETE_FAILED_USED_SHARED_LIBRARY: return "DELETE_FAILED_USED_SHARED_LIBRARY";
5907            default: return Integer.toString(status);
5908        }
5909    }
5910
5911    /** {@hide} */
5912    public static int deleteStatusToPublicStatus(int status) {
5913        switch (status) {
5914            case DELETE_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
5915            case DELETE_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
5916            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return PackageInstaller.STATUS_FAILURE_BLOCKED;
5917            case DELETE_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
5918            case DELETE_FAILED_OWNER_BLOCKED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
5919            case DELETE_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
5920            case DELETE_FAILED_USED_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_CONFLICT;
5921            default: return PackageInstaller.STATUS_FAILURE;
5922        }
5923    }
5924
5925    /** {@hide} */
5926    public static String permissionFlagToString(int flag) {
5927        switch (flag) {
5928            case FLAG_PERMISSION_GRANTED_BY_DEFAULT: return "GRANTED_BY_DEFAULT";
5929            case FLAG_PERMISSION_POLICY_FIXED: return "POLICY_FIXED";
5930            case FLAG_PERMISSION_SYSTEM_FIXED: return "SYSTEM_FIXED";
5931            case FLAG_PERMISSION_USER_SET: return "USER_SET";
5932            case FLAG_PERMISSION_REVOKE_ON_UPGRADE: return "REVOKE_ON_UPGRADE";
5933            case FLAG_PERMISSION_USER_FIXED: return "USER_FIXED";
5934            case FLAG_PERMISSION_REVIEW_REQUIRED: return "REVIEW_REQUIRED";
5935            default: return Integer.toString(flag);
5936        }
5937    }
5938
5939    /** {@hide} */
5940    public static class LegacyPackageDeleteObserver extends PackageDeleteObserver {
5941        private final IPackageDeleteObserver mLegacy;
5942
5943        public LegacyPackageDeleteObserver(IPackageDeleteObserver legacy) {
5944            mLegacy = legacy;
5945        }
5946
5947        @Override
5948        public void onPackageDeleted(String basePackageName, int returnCode, String msg) {
5949            if (mLegacy == null) return;
5950            try {
5951                mLegacy.packageDeleted(basePackageName, returnCode);
5952            } catch (RemoteException ignored) {
5953            }
5954        }
5955    }
5956
5957    /**
5958     * Return the install reason that was recorded when a package was first
5959     * installed for a specific user. Requesting the install reason for another
5960     * user will require the permission INTERACT_ACROSS_USERS_FULL.
5961     *
5962     * @param packageName The package for which to retrieve the install reason
5963     * @param user The user for whom to retrieve the install reason
5964     * @return The install reason. If the package is not installed for the given
5965     *         user, {@code INSTALL_REASON_UNKNOWN} is returned.
5966     * @hide
5967     */
5968    @TestApi
5969    public abstract @InstallReason int getInstallReason(String packageName,
5970            @NonNull UserHandle user);
5971
5972    /**
5973     * Checks whether the calling package is allowed to request package installs through package
5974     * installer. Apps are encouraged to call this API before launching the package installer via
5975     * intent {@link android.content.Intent#ACTION_INSTALL_PACKAGE}. Starting from Android O, the
5976     * user can explicitly choose what external sources they trust to install apps on the device.
5977     * If this API returns false, the install request will be blocked by the package installer and
5978     * a dialog will be shown to the user with an option to launch settings to change their
5979     * preference. An application must target Android O or higher and declare permission
5980     * {@link android.Manifest.permission#REQUEST_INSTALL_PACKAGES} in order to use this API.
5981     *
5982     * @return true if the calling package is trusted by the user to request install packages on
5983     * the device, false otherwise.
5984     * @see android.content.Intent#ACTION_INSTALL_PACKAGE
5985     * @see android.provider.Settings#ACTION_MANAGE_UNKNOWN_APP_SOURCES
5986     */
5987    public abstract boolean canRequestPackageInstalls();
5988
5989    /**
5990     * Return the {@link ComponentName} of the activity providing Settings for the Instant App
5991     * resolver.
5992     *
5993     * @see {@link android.content.Intent#ACTION_INSTANT_APP_RESOLVER_SETTINGS}
5994     * @hide
5995     */
5996    @SystemApi
5997    public abstract ComponentName getInstantAppResolverSettingsComponent();
5998
5999    /**
6000     * Return the {@link ComponentName} of the activity responsible for installing instant
6001     * applications.
6002     *
6003     * @see {@link android.content.Intent#ACTION_INSTALL_INSTANT_APP_PACKAGE}
6004     * @hide
6005     */
6006    @SystemApi
6007    public abstract ComponentName getInstantAppInstallerComponent();
6008
6009    /**
6010     * Return the Android Id for a given Instant App.
6011     *
6012     * @see {@link android.provider.Settings.Secure#ANDROID_ID}
6013     * @hide
6014     */
6015    public abstract String getInstantAppAndroidId(String packageName, @NonNull UserHandle user);
6016
6017    /**
6018     * Callback use to notify the callers of module registration that the operation
6019     * has finished.
6020     *
6021     * @hide
6022     */
6023    @SystemApi
6024    public static abstract class DexModuleRegisterCallback {
6025        public abstract void onDexModuleRegistered(String dexModulePath, boolean success,
6026                String message);
6027    }
6028
6029    /**
6030     * Register an application dex module with the package manager.
6031     * The package manager will keep track of the given module for future optimizations.
6032     *
6033     * Dex module optimizations will disable the classpath checking at runtime. The client bares
6034     * the responsibility to ensure that the static assumptions on classes in the optimized code
6035     * hold at runtime (e.g. there's no duplicate classes in the classpath).
6036     *
6037     * Note that the package manager already keeps track of dex modules loaded with
6038     * {@link dalvik.system.DexClassLoader} and {@link dalvik.system.PathClassLoader}.
6039     * This can be called for an eager registration.
6040     *
6041     * The call might take a while and the results will be posted on the main thread, using
6042     * the given callback.
6043     *
6044     * If the module is intended to be shared with other apps, make sure that the file
6045     * permissions allow for it.
6046     * If at registration time the permissions allow for others to read it, the module would
6047     * be marked as a shared module which might undergo a different optimization strategy.
6048     * (usually shared modules will generated larger optimizations artifacts,
6049     * taking more disk space).
6050     *
6051     * @param dexModulePath the absolute path of the dex module.
6052     * @param callback if not null, {@link DexModuleRegisterCallback#onDexModuleRegistered} will
6053     *                 be called once the registration finishes.
6054     *
6055     * @hide
6056     */
6057    @SystemApi
6058    public abstract void registerDexModule(String dexModulePath,
6059            @Nullable DexModuleRegisterCallback callback);
6060
6061    /**
6062     * Returns the {@link ArtManager} associated with this package manager.
6063     *
6064     * @hide
6065     */
6066    @SystemApi
6067    public @NonNull ArtManager getArtManager() {
6068        throw new UnsupportedOperationException("getArtManager not implemented in subclass");
6069    }
6070
6071    /**
6072     * Sets or clears the harmful app warning details for the given app.
6073     *
6074     * When set, any attempt to launch an activity in this package will be intercepted and a
6075     * warning dialog will be shown to the user instead, with the given warning. The user
6076     * will have the option to proceed with the activity launch, or to uninstall the application.
6077     *
6078     * @param packageName The full name of the package to warn on.
6079     * @param warning A warning string to display to the user describing the threat posed by the
6080     *                application, or null to clear the warning.
6081     *
6082     * @hide
6083     */
6084    @RequiresPermission(Manifest.permission.SET_HARMFUL_APP_WARNINGS)
6085    @SystemApi
6086    public void setHarmfulAppWarning(@NonNull String packageName, @Nullable CharSequence warning) {
6087        throw new UnsupportedOperationException("setHarmfulAppWarning not implemented in subclass");
6088    }
6089
6090    /**
6091     * Returns the harmful app warning string for the given app, or null if there is none set.
6092     *
6093     * @param packageName The full name of the desired package.
6094     *
6095     * @hide
6096     */
6097    @RequiresPermission(Manifest.permission.SET_HARMFUL_APP_WARNINGS)
6098    @Nullable
6099    @SystemApi
6100    public CharSequence getHarmfulAppWarning(@NonNull String packageName) {
6101        throw new UnsupportedOperationException("getHarmfulAppWarning not implemented in subclass");
6102    }
6103
6104    /** @hide */
6105    @IntDef(prefix = { "CERT_INPUT_" }, value = {
6106            CERT_INPUT_RAW_X509,
6107            CERT_INPUT_SHA256
6108    })
6109    @Retention(RetentionPolicy.SOURCE)
6110    public @interface CertificateInputType {}
6111
6112    /**
6113     * Certificate input bytes: the input bytes represent an encoded X.509 Certificate which could
6114     * be generated using an {@code CertificateFactory}
6115     */
6116    public static final int CERT_INPUT_RAW_X509 = 0;
6117
6118    /**
6119     * Certificate input bytes: the input bytes represent the SHA256 output of an encoded X.509
6120     * Certificate.
6121     */
6122    public static final int CERT_INPUT_SHA256 = 1;
6123
6124    /**
6125     * Searches the set of signing certificates by which the given package has proven to have been
6126     * signed.  This should be used instead of {@code getPackageInfo} with {@code GET_SIGNATURES}
6127     * since it takes into account the possibility of signing certificate rotation, except in the
6128     * case of packages that are signed by multiple certificates, for which signing certificate
6129     * rotation is not supported.  This method is analogous to using {@code getPackageInfo} with
6130     * {@code GET_SIGNING_CERTIFICATES} and then searching through the resulting {@code
6131     * signingInfo} field to see if the desired certificate is present.
6132     *
6133     * @param packageName package whose signing certificates to check
6134     * @param certificate signing certificate for which to search
6135     * @param type representation of the {@code certificate}
6136     * @return true if this package was or is signed by exactly the certificate {@code certificate}
6137     */
6138    public boolean hasSigningCertificate(
6139            String packageName, byte[] certificate, @CertificateInputType int type) {
6140        throw new UnsupportedOperationException(
6141                "hasSigningCertificate not implemented in subclass");
6142    }
6143
6144    /**
6145     * Searches the set of signing certificates by which the package(s) for the given uid has proven
6146     * to have been signed.  For multiple packages sharing the same uid, this will return the
6147     * signing certificates found in the signing history of the "newest" package, where "newest"
6148     * indicates the package with the newest signing certificate in the shared uid group.  This
6149     * method should be used instead of {@code getPackageInfo} with {@code GET_SIGNATURES}
6150     * since it takes into account the possibility of signing certificate rotation, except in the
6151     * case of packages that are signed by multiple certificates, for which signing certificate
6152     * rotation is not supported. This method is analogous to using {@code getPackagesForUid}
6153     * followed by {@code getPackageInfo} with {@code GET_SIGNING_CERTIFICATES}, selecting the
6154     * {@code PackageInfo} of the newest-signed bpackage , and finally searching through the
6155     * resulting {@code signingInfo} field to see if the desired certificate is there.
6156     *
6157     * @param uid uid whose signing certificates to check
6158     * @param certificate signing certificate for which to search
6159     * @param type representation of the {@code certificate}
6160     * @return true if this package was or is signed by exactly the certificate {@code certificate}
6161     */
6162    public boolean hasSigningCertificate(
6163            int uid, byte[] certificate, @CertificateInputType int type) {
6164        throw new UnsupportedOperationException(
6165                "hasSigningCertificate not implemented in subclass");
6166    }
6167
6168    /**
6169     * @return the system defined text classifier package name, or null if there's none.
6170     *
6171     * @hide
6172     */
6173    public String getSystemTextClassifierPackageName() {
6174        throw new UnsupportedOperationException(
6175                "getSystemTextClassifierPackageName not implemented in subclass");
6176    }
6177
6178    /**
6179     * @return whether a given package's state is protected, e.g. package cannot be disabled,
6180     *         suspended, hidden or force stopped.
6181     *
6182     * @hide
6183     */
6184    public boolean isPackageStateProtected(String packageName, int userId) {
6185        throw new UnsupportedOperationException(
6186            "isPackageStateProtected not implemented in subclass");
6187    }
6188
6189}
6190