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