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