PackageManager.java revision c40afac294a3d36568e9f460d7a77c4d184efd90
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    @SystemApi
436    public static final int MATCH_FACTORY_ONLY = 0x00200000;
437
438    /**
439     * Allows querying of packages installed for any user, not just the specific one. This flag
440     * is only meant for use by apps that have INTERACT_ACROSS_USERS permission.
441     * @hide
442     */
443    @SystemApi
444    public static final int MATCH_ANY_USER = 0x00400000;
445
446    /**
447     * Combination of MATCH_ANY_USER and MATCH_UNINSTALLED_PACKAGES to mean any known
448     * package.
449     * @hide
450     */
451    public static final int MATCH_KNOWN_PACKAGES = MATCH_UNINSTALLED_PACKAGES | MATCH_ANY_USER;
452
453    /**
454     * Internal {@link PackageInfo} flag: include components that are part of an
455     * instant app. By default, instant app components are not matched.
456     * @hide
457     */
458    @SystemApi
459    public static final int MATCH_INSTANT = 0x00800000;
460
461    /**
462     * Internal {@link PackageInfo} flag: include only components that are exposed to
463     * ephemeral apps.
464     * @hide
465     */
466    public static final int MATCH_VISIBLE_TO_INSTANT_APP_ONLY = 0x01000000;
467
468    /**
469     * Internal flag used to indicate that a system component has done their
470     * homework and verified that they correctly handle packages and components
471     * that come and go over time. In particular:
472     * <ul>
473     * <li>Apps installed on external storage, which will appear to be
474     * uninstalled while the the device is ejected.
475     * <li>Apps with encryption unaware components, which will appear to not
476     * exist while the device is locked.
477     * </ul>
478     *
479     * @see #MATCH_UNINSTALLED_PACKAGES
480     * @see #MATCH_DIRECT_BOOT_AWARE
481     * @see #MATCH_DIRECT_BOOT_UNAWARE
482     * @hide
483     */
484    public static final int MATCH_DEBUG_TRIAGED_MISSING = 0x10000000;
485
486    /**
487     * Flag for {@link #addCrossProfileIntentFilter}: if this flag is set: when
488     * resolving an intent that matches the {@code CrossProfileIntentFilter},
489     * the current profile will be skipped. Only activities in the target user
490     * can respond to the intent.
491     *
492     * @hide
493     */
494    public static final int SKIP_CURRENT_PROFILE = 0x00000002;
495
496    /**
497     * Flag for {@link #addCrossProfileIntentFilter}: if this flag is set:
498     * activities in the other profiles can respond to the intent only if no activity with
499     * non-negative priority in current profile can respond to the intent.
500     * @hide
501     */
502    public static final int ONLY_IF_NO_MATCH_FOUND = 0x00000004;
503
504    /** @hide */
505    @IntDef({PERMISSION_GRANTED, PERMISSION_DENIED})
506    @Retention(RetentionPolicy.SOURCE)
507    public @interface PermissionResult {}
508
509    /**
510     * Permission check result: this is returned by {@link #checkPermission}
511     * if the permission has been granted to the given package.
512     */
513    public static final int PERMISSION_GRANTED = 0;
514
515    /**
516     * Permission check result: this is returned by {@link #checkPermission}
517     * if the permission has not been granted to the given package.
518     */
519    public static final int PERMISSION_DENIED = -1;
520
521    /**
522     * Signature check result: this is returned by {@link #checkSignatures}
523     * if all signatures on the two packages match.
524     */
525    public static final int SIGNATURE_MATCH = 0;
526
527    /**
528     * Signature check result: this is returned by {@link #checkSignatures}
529     * if neither of the two packages is signed.
530     */
531    public static final int SIGNATURE_NEITHER_SIGNED = 1;
532
533    /**
534     * Signature check result: this is returned by {@link #checkSignatures}
535     * if the first package is not signed but the second is.
536     */
537    public static final int SIGNATURE_FIRST_NOT_SIGNED = -1;
538
539    /**
540     * Signature check result: this is returned by {@link #checkSignatures}
541     * if the second package is not signed but the first is.
542     */
543    public static final int SIGNATURE_SECOND_NOT_SIGNED = -2;
544
545    /**
546     * Signature check result: this is returned by {@link #checkSignatures}
547     * if not all signatures on both packages match.
548     */
549    public static final int SIGNATURE_NO_MATCH = -3;
550
551    /**
552     * Signature check result: this is returned by {@link #checkSignatures}
553     * if either of the packages are not valid.
554     */
555    public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
556
557    /**
558     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
559     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
560     * component or application is in its default enabled state (as specified
561     * in its manifest).
562     */
563    public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
564
565    /**
566     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
567     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
568     * component or application has been explictily enabled, regardless of
569     * what it has specified in its manifest.
570     */
571    public static final int COMPONENT_ENABLED_STATE_ENABLED = 1;
572
573    /**
574     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
575     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
576     * component or application has been explicitly disabled, regardless of
577     * what it has specified in its manifest.
578     */
579    public static final int COMPONENT_ENABLED_STATE_DISABLED = 2;
580
581    /**
582     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: The
583     * user has explicitly disabled the application, regardless of what it has
584     * specified in its manifest.  Because this is due to the user's request,
585     * they may re-enable it if desired through the appropriate system UI.  This
586     * option currently <strong>cannot</strong> be used with
587     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
588     */
589    public static final int COMPONENT_ENABLED_STATE_DISABLED_USER = 3;
590
591    /**
592     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: This
593     * application should be considered, until the point where the user actually
594     * wants to use it.  This means that it will not normally show up to the user
595     * (such as in the launcher), but various parts of the user interface can
596     * use {@link #GET_DISABLED_UNTIL_USED_COMPONENTS} to still see it and allow
597     * the user to select it (as for example an IME, device admin, etc).  Such code,
598     * once the user has selected the app, should at that point also make it enabled.
599     * This option currently <strong>can not</strong> be used with
600     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
601     */
602    public static final int COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED = 4;
603
604    /** @hide */
605    @IntDef(flag = true, value = {
606            INSTALL_FORWARD_LOCK,
607            INSTALL_REPLACE_EXISTING,
608            INSTALL_ALLOW_TEST,
609            INSTALL_EXTERNAL,
610            INSTALL_INTERNAL,
611            INSTALL_FROM_ADB,
612            INSTALL_ALL_USERS,
613            INSTALL_ALLOW_DOWNGRADE,
614            INSTALL_GRANT_RUNTIME_PERMISSIONS,
615            INSTALL_FORCE_VOLUME_UUID,
616            INSTALL_FORCE_PERMISSION_PROMPT,
617            INSTALL_INSTANT_APP,
618            INSTALL_DONT_KILL_APP,
619            INSTALL_FORCE_SDK,
620            INSTALL_FULL_APP,
621            INSTALL_ALLOCATE_AGGRESSIVE,
622    })
623    @Retention(RetentionPolicy.SOURCE)
624    public @interface InstallFlags {}
625
626    /**
627     * Flag parameter for {@link #installPackage} to indicate that this package
628     * should be installed as forward locked, i.e. only the app itself should
629     * have access to its code and non-resource assets.
630     *
631     * @deprecated new installs into ASEC containers are no longer supported.
632     * @hide
633     */
634    @Deprecated
635    public static final int INSTALL_FORWARD_LOCK = 0x00000001;
636
637    /**
638     * Flag parameter for {@link #installPackage} to indicate that you want to
639     * replace an already installed package, if one exists.
640     *
641     * @hide
642     */
643    public static final int INSTALL_REPLACE_EXISTING = 0x00000002;
644
645    /**
646     * Flag parameter for {@link #installPackage} to indicate that you want to
647     * allow test packages (those that have set android:testOnly in their
648     * manifest) to be installed.
649     * @hide
650     */
651    public static final int INSTALL_ALLOW_TEST = 0x00000004;
652
653    /**
654     * Flag parameter for {@link #installPackage} to indicate that this package
655     * must be installed to an ASEC on a {@link VolumeInfo#TYPE_PUBLIC}.
656     *
657     * @deprecated new installs into ASEC containers are no longer supported;
658     *             use adoptable storage instead.
659     * @hide
660     */
661    @Deprecated
662    public static final int INSTALL_EXTERNAL = 0x00000008;
663
664    /**
665     * Flag parameter for {@link #installPackage} to indicate that this package
666     * must be installed to internal storage.
667     *
668     * @hide
669     */
670    public static final int INSTALL_INTERNAL = 0x00000010;
671
672    /**
673     * Flag parameter for {@link #installPackage} to indicate that this install
674     * was initiated via ADB.
675     *
676     * @hide
677     */
678    public static final int INSTALL_FROM_ADB = 0x00000020;
679
680    /**
681     * Flag parameter for {@link #installPackage} to indicate that this install
682     * should immediately be visible to all users.
683     *
684     * @hide
685     */
686    public static final int INSTALL_ALL_USERS = 0x00000040;
687
688    /**
689     * Flag parameter for {@link #installPackage} to indicate that it is okay
690     * to install an update to an app where the newly installed app has a lower
691     * version code than the currently installed app. This is permitted only if
692     * the currently installed app is marked debuggable.
693     *
694     * @hide
695     */
696    public static final int INSTALL_ALLOW_DOWNGRADE = 0x00000080;
697
698    /**
699     * Flag parameter for {@link #installPackage} to indicate that all runtime
700     * permissions should be granted to the package. If {@link #INSTALL_ALL_USERS}
701     * is set the runtime permissions will be granted to all users, otherwise
702     * only to the owner.
703     *
704     * @hide
705     */
706    public static final int INSTALL_GRANT_RUNTIME_PERMISSIONS = 0x00000100;
707
708    /** {@hide} */
709    public static final int INSTALL_FORCE_VOLUME_UUID = 0x00000200;
710
711    /**
712     * Flag parameter for {@link #installPackage} to indicate that we always want to force
713     * the prompt for permission approval. This overrides any special behaviour for internal
714     * components.
715     *
716     * @hide
717     */
718    public static final int INSTALL_FORCE_PERMISSION_PROMPT = 0x00000400;
719
720    /**
721     * Flag parameter for {@link #installPackage} to indicate that this package is
722     * to be installed as a lightweight "ephemeral" app.
723     *
724     * @hide
725     */
726    public static final int INSTALL_INSTANT_APP = 0x00000800;
727
728    /**
729     * Flag parameter for {@link #installPackage} to indicate that this package contains
730     * a feature split to an existing application and the existing application should not
731     * be killed during the installation process.
732     *
733     * @hide
734     */
735    public static final int INSTALL_DONT_KILL_APP = 0x00001000;
736
737    /**
738     * Flag parameter for {@link #installPackage} to indicate that this package is an
739     * upgrade to a package that refers to the SDK via release letter.
740     *
741     * @hide
742     */
743    public static final int INSTALL_FORCE_SDK = 0x00002000;
744
745    /**
746     * Flag parameter for {@link #installPackage} to indicate that this package is
747     * to be installed as a heavy weight app. This is fundamentally the opposite of
748     * {@link #INSTALL_INSTANT_APP}.
749     *
750     * @hide
751     */
752    public static final int INSTALL_FULL_APP = 0x00004000;
753
754    /**
755     * Flag parameter for {@link #installPackage} to indicate that this package
756     * is critical to system health or security, meaning the system should use
757     * {@link StorageManager#FLAG_ALLOCATE_AGGRESSIVE} internally.
758     *
759     * @hide
760     */
761    public static final int INSTALL_ALLOCATE_AGGRESSIVE = 0x00008000;
762
763    /**
764     * Flag parameter for
765     * {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate
766     * that you don't want to kill the app containing the component.  Be careful when you set this
767     * since changing component states can make the containing application's behavior unpredictable.
768     */
769    public static final int DONT_KILL_APP = 0x00000001;
770
771    /** @hide */
772    @IntDef({INSTALL_REASON_UNKNOWN, INSTALL_REASON_POLICY, INSTALL_REASON_DEVICE_RESTORE,
773            INSTALL_REASON_DEVICE_SETUP, INSTALL_REASON_USER})
774    @Retention(RetentionPolicy.SOURCE)
775    public @interface InstallReason {}
776
777    /**
778     * Code indicating that the reason for installing this package is unknown.
779     */
780    public static final int INSTALL_REASON_UNKNOWN = 0;
781
782    /**
783     * Code indicating that this package was installed due to enterprise policy.
784     */
785    public static final int INSTALL_REASON_POLICY = 1;
786
787    /**
788     * Code indicating that this package was installed as part of restoring from another device.
789     */
790    public static final int INSTALL_REASON_DEVICE_RESTORE = 2;
791
792    /**
793     * Code indicating that this package was installed as part of device setup.
794     */
795    public static final int INSTALL_REASON_DEVICE_SETUP = 3;
796
797    /**
798     * Code indicating that the package installation was initiated by the user.
799     */
800    public static final int INSTALL_REASON_USER = 4;
801
802    /**
803     * Installation return code: this is passed to the
804     * {@link IPackageInstallObserver} on success.
805     *
806     * @hide
807     */
808    @SystemApi
809    public static final int INSTALL_SUCCEEDED = 1;
810
811    /**
812     * Installation return code: this is passed to the
813     * {@link IPackageInstallObserver} if the package is already installed.
814     *
815     * @hide
816     */
817    @SystemApi
818    public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;
819
820    /**
821     * Installation return code: this is passed to the
822     * {@link IPackageInstallObserver} if the package archive file is invalid.
823     *
824     * @hide
825     */
826    @SystemApi
827    public static final int INSTALL_FAILED_INVALID_APK = -2;
828
829    /**
830     * Installation return code: this is passed to the
831     * {@link IPackageInstallObserver} if the URI passed in is invalid.
832     *
833     * @hide
834     */
835    @SystemApi
836    public static final int INSTALL_FAILED_INVALID_URI = -3;
837
838    /**
839     * Installation return code: this is passed to the
840     * {@link IPackageInstallObserver} if the package manager service found that
841     * the device didn't have enough storage space to install the app.
842     *
843     * @hide
844     */
845    @SystemApi
846    public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;
847
848    /**
849     * Installation return code: this is passed to the
850     * {@link IPackageInstallObserver} if a package is already installed with
851     * the same name.
852     *
853     * @hide
854     */
855    @SystemApi
856    public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;
857
858    /**
859     * Installation return code: this is passed to the
860     * {@link IPackageInstallObserver} if the requested shared user does not
861     * exist.
862     *
863     * @hide
864     */
865    @SystemApi
866    public static final int INSTALL_FAILED_NO_SHARED_USER = -6;
867
868    /**
869     * Installation return code: this is passed to the
870     * {@link IPackageInstallObserver} if a previously installed package of the
871     * same name has a different signature than the new package (and the old
872     * package's data was not removed).
873     *
874     * @hide
875     */
876    @SystemApi
877    public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;
878
879    /**
880     * Installation return code: this is passed to the
881     * {@link IPackageInstallObserver} if the new package is requested a shared
882     * user which is already installed on the device and does not have matching
883     * signature.
884     *
885     * @hide
886     */
887    @SystemApi
888    public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;
889
890    /**
891     * Installation return code: this is passed to the
892     * {@link IPackageInstallObserver} if the new package uses a shared library
893     * that is not available.
894     *
895     * @hide
896     */
897    @SystemApi
898    public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;
899
900    /**
901     * Installation return code: this is passed to the
902     * {@link IPackageInstallObserver} if the new package uses a shared library
903     * that is not available.
904     *
905     * @hide
906     */
907    @SystemApi
908    public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;
909
910    /**
911     * Installation return code: this is passed to the
912     * {@link IPackageInstallObserver} if the new package failed while
913     * optimizing and validating its dex files, either because there was not
914     * enough storage or the validation failed.
915     *
916     * @hide
917     */
918    @SystemApi
919    public static final int INSTALL_FAILED_DEXOPT = -11;
920
921    /**
922     * Installation return code: this is passed to the
923     * {@link IPackageInstallObserver} if the new package failed because the
924     * current SDK version is older than that required by the package.
925     *
926     * @hide
927     */
928    @SystemApi
929    public static final int INSTALL_FAILED_OLDER_SDK = -12;
930
931    /**
932     * Installation return code: this is passed to the
933     * {@link IPackageInstallObserver} if the new package failed because it
934     * contains a content provider with the same authority as a provider already
935     * installed in the system.
936     *
937     * @hide
938     */
939    @SystemApi
940    public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;
941
942    /**
943     * Installation return code: this is passed to the
944     * {@link IPackageInstallObserver} if the new package failed because the
945     * current SDK version is newer than that required by the package.
946     *
947     * @hide
948     */
949    @SystemApi
950    public static final int INSTALL_FAILED_NEWER_SDK = -14;
951
952    /**
953     * Installation return code: this is passed to the
954     * {@link IPackageInstallObserver} if the new package failed because it has
955     * specified that it is a test-only package and the caller has not supplied
956     * the {@link #INSTALL_ALLOW_TEST} flag.
957     *
958     * @hide
959     */
960    @SystemApi
961    public static final int INSTALL_FAILED_TEST_ONLY = -15;
962
963    /**
964     * Installation return code: this is passed to the
965     * {@link IPackageInstallObserver} if the package being installed contains
966     * native code, but none that is compatible with the device's CPU_ABI.
967     *
968     * @hide
969     */
970    @SystemApi
971    public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;
972
973    /**
974     * Installation return code: this is passed to the
975     * {@link IPackageInstallObserver} if the new package uses a feature that is
976     * not available.
977     *
978     * @hide
979     */
980    @SystemApi
981    public static final int INSTALL_FAILED_MISSING_FEATURE = -17;
982
983    // ------ Errors related to sdcard
984    /**
985     * Installation return code: this is passed to the
986     * {@link IPackageInstallObserver} if a secure container mount point
987     * couldn't be accessed on external media.
988     *
989     * @hide
990     */
991    @SystemApi
992    public static final int INSTALL_FAILED_CONTAINER_ERROR = -18;
993
994    /**
995     * Installation return code: this is passed to the
996     * {@link IPackageInstallObserver} if the new package couldn't be installed
997     * in the specified install location.
998     *
999     * @hide
1000     */
1001    @SystemApi
1002    public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19;
1003
1004    /**
1005     * Installation return code: this is passed to the
1006     * {@link IPackageInstallObserver} if the new package couldn't be installed
1007     * in the specified install location because the media is not available.
1008     *
1009     * @hide
1010     */
1011    @SystemApi
1012    public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE = -20;
1013
1014    /**
1015     * Installation return code: this is passed to the
1016     * {@link IPackageInstallObserver} if the new package couldn't be installed
1017     * because the verification timed out.
1018     *
1019     * @hide
1020     */
1021    @SystemApi
1022    public static final int INSTALL_FAILED_VERIFICATION_TIMEOUT = -21;
1023
1024    /**
1025     * Installation return code: this is passed to the
1026     * {@link IPackageInstallObserver} if the new package couldn't be installed
1027     * because the verification did not succeed.
1028     *
1029     * @hide
1030     */
1031    @SystemApi
1032    public static final int INSTALL_FAILED_VERIFICATION_FAILURE = -22;
1033
1034    /**
1035     * Installation return code: this is passed to the
1036     * {@link IPackageInstallObserver} if the package changed from what the
1037     * calling program expected.
1038     *
1039     * @hide
1040     */
1041    @SystemApi
1042    public static final int INSTALL_FAILED_PACKAGE_CHANGED = -23;
1043
1044    /**
1045     * Installation return code: this is passed to the
1046     * {@link IPackageInstallObserver} if the new package is assigned a
1047     * different UID than it previously held.
1048     *
1049     * @hide
1050     */
1051    public static final int INSTALL_FAILED_UID_CHANGED = -24;
1052
1053    /**
1054     * Installation return code: this is passed to the
1055     * {@link IPackageInstallObserver} if the new package has an older version
1056     * code than the currently installed package.
1057     *
1058     * @hide
1059     */
1060    public static final int INSTALL_FAILED_VERSION_DOWNGRADE = -25;
1061
1062    /**
1063     * Installation return code: this is passed to the
1064     * {@link IPackageInstallObserver} if the old package has target SDK high
1065     * enough to support runtime permission and the new package has target SDK
1066     * low enough to not support runtime permissions.
1067     *
1068     * @hide
1069     */
1070    @SystemApi
1071    public static final int INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE = -26;
1072
1073    /**
1074     * Installation return code: this is passed to the
1075     * {@link IPackageInstallObserver} if the new package attempts to downgrade the
1076     * target sandbox version of the app.
1077     *
1078     * @hide
1079     */
1080    @SystemApi
1081    public static final int INSTALL_FAILED_SANDBOX_VERSION_DOWNGRADE = -27;
1082
1083    /**
1084     * Installation parse return code: this is passed to the
1085     * {@link IPackageInstallObserver} if the parser was given a path that is
1086     * not a file, or does not end with the expected '.apk' extension.
1087     *
1088     * @hide
1089     */
1090    @SystemApi
1091    public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;
1092
1093    /**
1094     * Installation parse return code: this is passed to the
1095     * {@link IPackageInstallObserver} if the parser was unable to retrieve the
1096     * AndroidManifest.xml file.
1097     *
1098     * @hide
1099     */
1100    @SystemApi
1101    public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;
1102
1103    /**
1104     * Installation parse return code: this is passed to the
1105     * {@link IPackageInstallObserver} if the parser encountered an unexpected
1106     * exception.
1107     *
1108     * @hide
1109     */
1110    @SystemApi
1111    public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;
1112
1113    /**
1114     * Installation parse return code: this is passed to the
1115     * {@link IPackageInstallObserver} if the parser did not find any
1116     * certificates in the .apk.
1117     *
1118     * @hide
1119     */
1120    @SystemApi
1121    public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;
1122
1123    /**
1124     * Installation parse return code: this is passed to the
1125     * {@link IPackageInstallObserver} if the parser found inconsistent
1126     * certificates on the files in the .apk.
1127     *
1128     * @hide
1129     */
1130    @SystemApi
1131    public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;
1132
1133    /**
1134     * Installation parse return code: this is passed to the
1135     * {@link IPackageInstallObserver} if the parser encountered a
1136     * CertificateEncodingException in one of the files in the .apk.
1137     *
1138     * @hide
1139     */
1140    @SystemApi
1141    public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;
1142
1143    /**
1144     * Installation parse return code: this is passed to the
1145     * {@link IPackageInstallObserver} if the parser encountered a bad or
1146     * missing package name in the manifest.
1147     *
1148     * @hide
1149     */
1150    @SystemApi
1151    public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;
1152
1153    /**
1154     * Installation parse return code: this is passed to the
1155     * {@link IPackageInstallObserver} if the parser encountered a bad shared
1156     * user id name in the manifest.
1157     *
1158     * @hide
1159     */
1160    @SystemApi
1161    public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;
1162
1163    /**
1164     * Installation parse return code: this is passed to the
1165     * {@link IPackageInstallObserver} if the parser encountered some structural
1166     * problem in the manifest.
1167     *
1168     * @hide
1169     */
1170    @SystemApi
1171    public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;
1172
1173    /**
1174     * Installation parse return code: this is passed to the
1175     * {@link IPackageInstallObserver} if the parser did not find any actionable
1176     * tags (instrumentation or application) in the manifest.
1177     *
1178     * @hide
1179     */
1180    @SystemApi
1181    public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;
1182
1183    /**
1184     * Installation failed return code: this is passed to the
1185     * {@link IPackageInstallObserver} if the system failed to install the
1186     * package because of system issues.
1187     *
1188     * @hide
1189     */
1190    @SystemApi
1191    public static final int INSTALL_FAILED_INTERNAL_ERROR = -110;
1192
1193    /**
1194     * Installation failed return code: this is passed to the
1195     * {@link IPackageInstallObserver} if the system failed to install the
1196     * package because the user is restricted from installing apps.
1197     *
1198     * @hide
1199     */
1200    public static final int INSTALL_FAILED_USER_RESTRICTED = -111;
1201
1202    /**
1203     * Installation failed return code: this is passed to the
1204     * {@link IPackageInstallObserver} if the system failed to install the
1205     * package because it is attempting to define a permission that is already
1206     * defined by some existing package.
1207     * <p>
1208     * The package name of the app which has already defined the permission is
1209     * passed to a {@link PackageInstallObserver}, if any, as the
1210     * {@link #EXTRA_FAILURE_EXISTING_PACKAGE} string extra; and the name of the
1211     * permission being redefined is passed in the
1212     * {@link #EXTRA_FAILURE_EXISTING_PERMISSION} string extra.
1213     *
1214     * @hide
1215     */
1216    public static final int INSTALL_FAILED_DUPLICATE_PERMISSION = -112;
1217
1218    /**
1219     * Installation failed return code: this is passed to the
1220     * {@link IPackageInstallObserver} if the system failed to install the
1221     * package because its packaged native code did not match any of the ABIs
1222     * supported by the system.
1223     *
1224     * @hide
1225     */
1226    public static final int INSTALL_FAILED_NO_MATCHING_ABIS = -113;
1227
1228    /**
1229     * Internal return code for NativeLibraryHelper methods to indicate that the package
1230     * being processed did not contain any native code. This is placed here only so that
1231     * it can belong to the same value space as the other install failure codes.
1232     *
1233     * @hide
1234     */
1235    public static final int NO_NATIVE_LIBRARIES = -114;
1236
1237    /** {@hide} */
1238    public static final int INSTALL_FAILED_ABORTED = -115;
1239
1240    /**
1241     * Installation failed return code: instant app installs are incompatible with some
1242     * other installation flags supplied for the operation; or other circumstances such
1243     * as trying to upgrade a system app via an instant app install.
1244     * @hide
1245     */
1246    public static final int INSTALL_FAILED_INSTANT_APP_INVALID = -116;
1247
1248    /** @hide */
1249    @IntDef(flag = true, value = {
1250            DELETE_KEEP_DATA,
1251            DELETE_ALL_USERS,
1252            DELETE_SYSTEM_APP,
1253            DELETE_DONT_KILL_APP,
1254    })
1255    @Retention(RetentionPolicy.SOURCE)
1256    public @interface DeleteFlags {}
1257
1258    /**
1259     * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
1260     * package's data directory.
1261     *
1262     * @hide
1263     */
1264    public static final int DELETE_KEEP_DATA = 0x00000001;
1265
1266    /**
1267     * Flag parameter for {@link #deletePackage} to indicate that you want the
1268     * package deleted for all users.
1269     *
1270     * @hide
1271     */
1272    public static final int DELETE_ALL_USERS = 0x00000002;
1273
1274    /**
1275     * Flag parameter for {@link #deletePackage} to indicate that, if you are calling
1276     * uninstall on a system that has been updated, then don't do the normal process
1277     * of uninstalling the update and rolling back to the older system version (which
1278     * needs to happen for all users); instead, just mark the app as uninstalled for
1279     * the current user.
1280     *
1281     * @hide
1282     */
1283    public static final int DELETE_SYSTEM_APP = 0x00000004;
1284
1285    /**
1286     * Flag parameter for {@link #deletePackage} to indicate that, if you are calling
1287     * uninstall on a package that is replaced to provide new feature splits, the
1288     * existing application should not be killed during the removal process.
1289     *
1290     * @hide
1291     */
1292    public static final int DELETE_DONT_KILL_APP = 0x00000008;
1293
1294    /**
1295     * Return code for when package deletion succeeds. This is passed to the
1296     * {@link IPackageDeleteObserver} if the system succeeded in deleting the
1297     * package.
1298     *
1299     * @hide
1300     */
1301    public static final int DELETE_SUCCEEDED = 1;
1302
1303    /**
1304     * Deletion failed return code: this is passed to the
1305     * {@link IPackageDeleteObserver} if the system failed to delete the package
1306     * for an unspecified reason.
1307     *
1308     * @hide
1309     */
1310    public static final int DELETE_FAILED_INTERNAL_ERROR = -1;
1311
1312    /**
1313     * Deletion failed return code: this is passed to the
1314     * {@link IPackageDeleteObserver} if the system failed to delete the package
1315     * because it is the active DevicePolicy manager.
1316     *
1317     * @hide
1318     */
1319    public static final int DELETE_FAILED_DEVICE_POLICY_MANAGER = -2;
1320
1321    /**
1322     * Deletion failed return code: this is passed to the
1323     * {@link IPackageDeleteObserver} if the system failed to delete the package
1324     * since the user is restricted.
1325     *
1326     * @hide
1327     */
1328    public static final int DELETE_FAILED_USER_RESTRICTED = -3;
1329
1330    /**
1331     * Deletion failed return code: this is passed to the
1332     * {@link IPackageDeleteObserver} if the system failed to delete the package
1333     * because a profile or device owner has marked the package as
1334     * uninstallable.
1335     *
1336     * @hide
1337     */
1338    public static final int DELETE_FAILED_OWNER_BLOCKED = -4;
1339
1340    /** {@hide} */
1341    public static final int DELETE_FAILED_ABORTED = -5;
1342
1343    /**
1344     * Deletion failed return code: this is passed to the
1345     * {@link IPackageDeleteObserver} if the system failed to delete the package
1346     * because the packge is a shared library used by other installed packages.
1347     * {@hide} */
1348    public static final int DELETE_FAILED_USED_SHARED_LIBRARY = -6;
1349
1350    /**
1351     * Return code that is passed to the {@link IPackageMoveObserver} when the
1352     * package has been successfully moved by the system.
1353     *
1354     * @hide
1355     */
1356    public static final int MOVE_SUCCEEDED = -100;
1357
1358    /**
1359     * Error code that is passed to the {@link IPackageMoveObserver} when the
1360     * package hasn't been successfully moved by the system because of
1361     * insufficient memory on specified media.
1362     *
1363     * @hide
1364     */
1365    public static final int MOVE_FAILED_INSUFFICIENT_STORAGE = -1;
1366
1367    /**
1368     * Error code that is passed to the {@link IPackageMoveObserver} if the
1369     * specified package doesn't exist.
1370     *
1371     * @hide
1372     */
1373    public static final int MOVE_FAILED_DOESNT_EXIST = -2;
1374
1375    /**
1376     * Error code that is passed to the {@link IPackageMoveObserver} if the
1377     * specified package cannot be moved since its a system package.
1378     *
1379     * @hide
1380     */
1381    public static final int MOVE_FAILED_SYSTEM_PACKAGE = -3;
1382
1383    /**
1384     * Error code that is passed to the {@link IPackageMoveObserver} if the
1385     * specified package cannot be moved since its forward locked.
1386     *
1387     * @hide
1388     */
1389    public static final int MOVE_FAILED_FORWARD_LOCKED = -4;
1390
1391    /**
1392     * Error code that is passed to the {@link IPackageMoveObserver} if the
1393     * specified package cannot be moved to the specified location.
1394     *
1395     * @hide
1396     */
1397    public static final int MOVE_FAILED_INVALID_LOCATION = -5;
1398
1399    /**
1400     * Error code that is passed to the {@link IPackageMoveObserver} if the
1401     * specified package cannot be moved to the specified location.
1402     *
1403     * @hide
1404     */
1405    public static final int MOVE_FAILED_INTERNAL_ERROR = -6;
1406
1407    /**
1408     * Error code that is passed to the {@link IPackageMoveObserver} if the
1409     * specified package already has an operation pending in the queue.
1410     *
1411     * @hide
1412     */
1413    public static final int MOVE_FAILED_OPERATION_PENDING = -7;
1414
1415    /**
1416     * Error code that is passed to the {@link IPackageMoveObserver} if the
1417     * specified package cannot be moved since it contains a device admin.
1418     *
1419     * @hide
1420     */
1421    public static final int MOVE_FAILED_DEVICE_ADMIN = -8;
1422
1423    /**
1424     * Error code that is passed to the {@link IPackageMoveObserver} if system does not allow
1425     * non-system apps to be moved to internal storage.
1426     *
1427     * @hide
1428     */
1429    public static final int MOVE_FAILED_3RD_PARTY_NOT_ALLOWED_ON_INTERNAL = -9;
1430
1431    /**
1432     * Flag parameter for {@link #movePackage} to indicate that
1433     * the package should be moved to internal storage if its
1434     * been installed on external media.
1435     * @hide
1436     */
1437    @Deprecated
1438    public static final int MOVE_INTERNAL = 0x00000001;
1439
1440    /**
1441     * Flag parameter for {@link #movePackage} to indicate that
1442     * the package should be moved to external media.
1443     * @hide
1444     */
1445    @Deprecated
1446    public static final int MOVE_EXTERNAL_MEDIA = 0x00000002;
1447
1448    /** {@hide} */
1449    public static final String EXTRA_MOVE_ID = "android.content.pm.extra.MOVE_ID";
1450
1451    /**
1452     * Usable by the required verifier as the {@code verificationCode} argument
1453     * for {@link PackageManager#verifyPendingInstall} to indicate that it will
1454     * allow the installation to proceed without any of the optional verifiers
1455     * needing to vote.
1456     *
1457     * @hide
1458     */
1459    public static final int VERIFICATION_ALLOW_WITHOUT_SUFFICIENT = 2;
1460
1461    /**
1462     * Used as the {@code verificationCode} argument for
1463     * {@link PackageManager#verifyPendingInstall} to indicate that the calling
1464     * package verifier allows the installation to proceed.
1465     */
1466    public static final int VERIFICATION_ALLOW = 1;
1467
1468    /**
1469     * Used as the {@code verificationCode} argument for
1470     * {@link PackageManager#verifyPendingInstall} to indicate the calling
1471     * package verifier does not vote to allow the installation to proceed.
1472     */
1473    public static final int VERIFICATION_REJECT = -1;
1474
1475    /**
1476     * Used as the {@code verificationCode} argument for
1477     * {@link PackageManager#verifyIntentFilter} to indicate that the calling
1478     * IntentFilter Verifier confirms that the IntentFilter is verified.
1479     *
1480     * @hide
1481     */
1482    @SystemApi
1483    public static final int INTENT_FILTER_VERIFICATION_SUCCESS = 1;
1484
1485    /**
1486     * Used as the {@code verificationCode} argument for
1487     * {@link PackageManager#verifyIntentFilter} to indicate that the calling
1488     * IntentFilter Verifier confirms that the IntentFilter is NOT verified.
1489     *
1490     * @hide
1491     */
1492    @SystemApi
1493    public static final int INTENT_FILTER_VERIFICATION_FAILURE = -1;
1494
1495    /**
1496     * Internal status code to indicate that an IntentFilter verification result is not specified.
1497     *
1498     * @hide
1499     */
1500    @SystemApi
1501    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED = 0;
1502
1503    /**
1504     * Used as the {@code status} argument for
1505     * {@link #updateIntentVerificationStatusAsUser} to indicate that the User
1506     * will always be prompted the Intent Disambiguation Dialog if there are two
1507     * or more Intent resolved for the IntentFilter's domain(s).
1508     *
1509     * @hide
1510     */
1511    @SystemApi
1512    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK = 1;
1513
1514    /**
1515     * Used as the {@code status} argument for
1516     * {@link #updateIntentVerificationStatusAsUser} to indicate that the User
1517     * will never be prompted the Intent Disambiguation Dialog if there are two
1518     * or more resolution of the Intent. The default App for the domain(s)
1519     * specified in the IntentFilter will also ALWAYS be used.
1520     *
1521     * @hide
1522     */
1523    @SystemApi
1524    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS = 2;
1525
1526    /**
1527     * Used as the {@code status} argument for
1528     * {@link #updateIntentVerificationStatusAsUser} to indicate that the User
1529     * may be prompted the Intent Disambiguation Dialog if there are two or more
1530     * Intent resolved. The default App for the domain(s) specified in the
1531     * IntentFilter will also NEVER be presented to the User.
1532     *
1533     * @hide
1534     */
1535    @SystemApi
1536    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER = 3;
1537
1538    /**
1539     * Used as the {@code status} argument for
1540     * {@link #updateIntentVerificationStatusAsUser} to indicate that this app
1541     * should always be considered as an ambiguous candidate for handling the
1542     * matching Intent even if there are other candidate apps in the "always"
1543     * state. Put another way: if there are any 'always ask' apps in a set of
1544     * more than one candidate app, then a disambiguation is *always* presented
1545     * even if there is another candidate app with the 'always' state.
1546     *
1547     * @hide
1548     */
1549    @SystemApi
1550    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK = 4;
1551
1552    /**
1553     * Can be used as the {@code millisecondsToDelay} argument for
1554     * {@link PackageManager#extendVerificationTimeout}. This is the
1555     * maximum time {@code PackageManager} waits for the verification
1556     * agent to return (in milliseconds).
1557     */
1558    public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000;
1559
1560    /**
1561     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's
1562     * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or
1563     * lag in sound input or output.
1564     */
1565    @SdkConstant(SdkConstantType.FEATURE)
1566    public static final String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
1567
1568    /**
1569     * Feature for {@link #getSystemAvailableFeatures} and
1570     * {@link #hasSystemFeature}: The device includes at least one form of audio
1571     * output, such as speakers, audio jack or streaming over bluetooth
1572     */
1573    @SdkConstant(SdkConstantType.FEATURE)
1574    public static final String FEATURE_AUDIO_OUTPUT = "android.hardware.audio.output";
1575
1576    /**
1577     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1578     * The device has professional audio level of functionality and performance.
1579     */
1580    @SdkConstant(SdkConstantType.FEATURE)
1581    public static final String FEATURE_AUDIO_PRO = "android.hardware.audio.pro";
1582
1583    /**
1584     * Feature for {@link #getSystemAvailableFeatures} and
1585     * {@link #hasSystemFeature}: The device is capable of communicating with
1586     * other devices via Bluetooth.
1587     */
1588    @SdkConstant(SdkConstantType.FEATURE)
1589    public static final String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
1590
1591    /**
1592     * Feature for {@link #getSystemAvailableFeatures} and
1593     * {@link #hasSystemFeature}: The device is capable of communicating with
1594     * other devices via Bluetooth Low Energy radio.
1595     */
1596    @SdkConstant(SdkConstantType.FEATURE)
1597    public static final String FEATURE_BLUETOOTH_LE = "android.hardware.bluetooth_le";
1598
1599    /**
1600     * Feature for {@link #getSystemAvailableFeatures} and
1601     * {@link #hasSystemFeature}: The device has a camera facing away
1602     * from the screen.
1603     */
1604    @SdkConstant(SdkConstantType.FEATURE)
1605    public static final String FEATURE_CAMERA = "android.hardware.camera";
1606
1607    /**
1608     * Feature for {@link #getSystemAvailableFeatures} and
1609     * {@link #hasSystemFeature}: The device's camera supports auto-focus.
1610     */
1611    @SdkConstant(SdkConstantType.FEATURE)
1612    public static final String FEATURE_CAMERA_AUTOFOCUS = "android.hardware.camera.autofocus";
1613
1614    /**
1615     * Feature for {@link #getSystemAvailableFeatures} and
1616     * {@link #hasSystemFeature}: The device has at least one camera pointing in
1617     * some direction, or can support an external camera being connected to it.
1618     */
1619    @SdkConstant(SdkConstantType.FEATURE)
1620    public static final String FEATURE_CAMERA_ANY = "android.hardware.camera.any";
1621
1622    /**
1623     * Feature for {@link #getSystemAvailableFeatures} and
1624     * {@link #hasSystemFeature}: The device can support having an external camera connected to it.
1625     * The external camera may not always be connected or available to applications to use.
1626     */
1627    @SdkConstant(SdkConstantType.FEATURE)
1628    public static final String FEATURE_CAMERA_EXTERNAL = "android.hardware.camera.external";
1629
1630    /**
1631     * Feature for {@link #getSystemAvailableFeatures} and
1632     * {@link #hasSystemFeature}: The device's camera supports flash.
1633     */
1634    @SdkConstant(SdkConstantType.FEATURE)
1635    public static final String FEATURE_CAMERA_FLASH = "android.hardware.camera.flash";
1636
1637    /**
1638     * Feature for {@link #getSystemAvailableFeatures} and
1639     * {@link #hasSystemFeature}: The device has a front facing camera.
1640     */
1641    @SdkConstant(SdkConstantType.FEATURE)
1642    public static final String FEATURE_CAMERA_FRONT = "android.hardware.camera.front";
1643
1644    /**
1645     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1646     * of the cameras on the device supports the
1647     * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL full hardware}
1648     * capability level.
1649     */
1650    @SdkConstant(SdkConstantType.FEATURE)
1651    public static final String FEATURE_CAMERA_LEVEL_FULL = "android.hardware.camera.level.full";
1652
1653    /**
1654     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1655     * of the cameras on the device supports the
1656     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR manual sensor}
1657     * capability level.
1658     */
1659    @SdkConstant(SdkConstantType.FEATURE)
1660    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR =
1661            "android.hardware.camera.capability.manual_sensor";
1662
1663    /**
1664     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1665     * of the cameras on the device supports the
1666     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING manual post-processing}
1667     * capability level.
1668     */
1669    @SdkConstant(SdkConstantType.FEATURE)
1670    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING =
1671            "android.hardware.camera.capability.manual_post_processing";
1672
1673    /**
1674     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1675     * of the cameras on the device supports the
1676     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}
1677     * capability level.
1678     */
1679    @SdkConstant(SdkConstantType.FEATURE)
1680    public static final String FEATURE_CAMERA_CAPABILITY_RAW =
1681            "android.hardware.camera.capability.raw";
1682
1683    /**
1684     * Feature for {@link #getSystemAvailableFeatures} and
1685     * {@link #hasSystemFeature}: The device is capable of communicating with
1686     * consumer IR devices.
1687     */
1688    @SdkConstant(SdkConstantType.FEATURE)
1689    public static final String FEATURE_CONSUMER_IR = "android.hardware.consumerir";
1690
1691    /**
1692     * Feature for {@link #getSystemAvailableFeatures} and
1693     * {@link #hasSystemFeature}: The device supports one or more methods of
1694     * reporting current location.
1695     */
1696    @SdkConstant(SdkConstantType.FEATURE)
1697    public static final String FEATURE_LOCATION = "android.hardware.location";
1698
1699    /**
1700     * Feature for {@link #getSystemAvailableFeatures} and
1701     * {@link #hasSystemFeature}: The device has a Global Positioning System
1702     * receiver and can report precise location.
1703     */
1704    @SdkConstant(SdkConstantType.FEATURE)
1705    public static final String FEATURE_LOCATION_GPS = "android.hardware.location.gps";
1706
1707    /**
1708     * Feature for {@link #getSystemAvailableFeatures} and
1709     * {@link #hasSystemFeature}: The device can report location with coarse
1710     * accuracy using a network-based geolocation system.
1711     */
1712    @SdkConstant(SdkConstantType.FEATURE)
1713    public static final String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
1714
1715    /**
1716     * Feature for {@link #getSystemAvailableFeatures} and
1717     * {@link #hasSystemFeature}: The device can record audio via a
1718     * microphone.
1719     */
1720    @SdkConstant(SdkConstantType.FEATURE)
1721    public static final String FEATURE_MICROPHONE = "android.hardware.microphone";
1722
1723    /**
1724     * Feature for {@link #getSystemAvailableFeatures} and
1725     * {@link #hasSystemFeature}: The device can communicate using Near-Field
1726     * Communications (NFC).
1727     */
1728    @SdkConstant(SdkConstantType.FEATURE)
1729    public static final String FEATURE_NFC = "android.hardware.nfc";
1730
1731    /**
1732     * Feature for {@link #getSystemAvailableFeatures} and
1733     * {@link #hasSystemFeature}: The device supports host-
1734     * based NFC card emulation.
1735     *
1736     * TODO remove when depending apps have moved to new constant.
1737     * @hide
1738     * @deprecated
1739     */
1740    @Deprecated
1741    @SdkConstant(SdkConstantType.FEATURE)
1742    public static final String FEATURE_NFC_HCE = "android.hardware.nfc.hce";
1743
1744    /**
1745     * Feature for {@link #getSystemAvailableFeatures} and
1746     * {@link #hasSystemFeature}: The device supports host-
1747     * based NFC card emulation.
1748     */
1749    @SdkConstant(SdkConstantType.FEATURE)
1750    public static final String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
1751
1752    /**
1753     * Feature for {@link #getSystemAvailableFeatures} and
1754     * {@link #hasSystemFeature}: The device supports host-
1755     * based NFC-F card emulation.
1756     */
1757    @SdkConstant(SdkConstantType.FEATURE)
1758    public static final String FEATURE_NFC_HOST_CARD_EMULATION_NFCF = "android.hardware.nfc.hcef";
1759
1760    /**
1761     * Feature for {@link #getSystemAvailableFeatures} and
1762     * {@link #hasSystemFeature}: The device supports the OpenGL ES
1763     * <a href="http://www.khronos.org/registry/gles/extensions/ANDROID/ANDROID_extension_pack_es31a.txt">
1764     * Android Extension Pack</a>.
1765     */
1766    @SdkConstant(SdkConstantType.FEATURE)
1767    public static final String FEATURE_OPENGLES_EXTENSION_PACK = "android.hardware.opengles.aep";
1768
1769    /**
1770     * Feature for {@link #getSystemAvailableFeatures} and
1771     * {@link #hasSystemFeature(String, int)}: If this feature is supported, the Vulkan native API
1772     * will enumerate at least one {@code VkPhysicalDevice}, and the feature version will indicate
1773     * what level of optional hardware features limits it supports.
1774     * <p>
1775     * Level 0 includes the base Vulkan requirements as well as:
1776     * <ul><li>{@code VkPhysicalDeviceFeatures::textureCompressionETC2}</li></ul>
1777     * <p>
1778     * Level 1 additionally includes:
1779     * <ul>
1780     * <li>{@code VkPhysicalDeviceFeatures::fullDrawIndexUint32}</li>
1781     * <li>{@code VkPhysicalDeviceFeatures::imageCubeArray}</li>
1782     * <li>{@code VkPhysicalDeviceFeatures::independentBlend}</li>
1783     * <li>{@code VkPhysicalDeviceFeatures::geometryShader}</li>
1784     * <li>{@code VkPhysicalDeviceFeatures::tessellationShader}</li>
1785     * <li>{@code VkPhysicalDeviceFeatures::sampleRateShading}</li>
1786     * <li>{@code VkPhysicalDeviceFeatures::textureCompressionASTC_LDR}</li>
1787     * <li>{@code VkPhysicalDeviceFeatures::fragmentStoresAndAtomics}</li>
1788     * <li>{@code VkPhysicalDeviceFeatures::shaderImageGatherExtended}</li>
1789     * <li>{@code VkPhysicalDeviceFeatures::shaderUniformBufferArrayDynamicIndexing}</li>
1790     * <li>{@code VkPhysicalDeviceFeatures::shaderSampledImageArrayDynamicIndexing}</li>
1791     * </ul>
1792     */
1793    @SdkConstant(SdkConstantType.FEATURE)
1794    public static final String FEATURE_VULKAN_HARDWARE_LEVEL = "android.hardware.vulkan.level";
1795
1796    /**
1797     * Feature for {@link #getSystemAvailableFeatures} and
1798     * {@link #hasSystemFeature(String, int)}: If this feature is supported, the Vulkan native API
1799     * will enumerate at least one {@code VkPhysicalDevice}, and the feature version will indicate
1800     * what level of optional compute features are supported beyond the Vulkan 1.0 requirements.
1801     * <p>
1802     * Compute level 0 indicates support for:
1803     * <ul>
1804     * <li>Ability to use pointers to buffer data from shaders</li>
1805     * <li>Ability to load/store 16-bit values from buffers</li>
1806     * <li>Ability to control shader floating point rounding mode</li>
1807     * </ul>
1808     */
1809    @SdkConstant(SdkConstantType.FEATURE)
1810    public static final String FEATURE_VULKAN_HARDWARE_COMPUTE = "android.hardware.vulkan.compute";
1811
1812    /**
1813     * Feature for {@link #getSystemAvailableFeatures} and
1814     * {@link #hasSystemFeature(String, int)}: The version of this feature indicates the highest
1815     * {@code VkPhysicalDeviceProperties::apiVersion} supported by the physical devices that support
1816     * the hardware level indicated by {@link #FEATURE_VULKAN_HARDWARE_LEVEL}. The feature version
1817     * uses the same encoding as Vulkan version numbers:
1818     * <ul>
1819     * <li>Major version number in bits 31-22</li>
1820     * <li>Minor version number in bits 21-12</li>
1821     * <li>Patch version number in bits 11-0</li>
1822     * </ul>
1823     */
1824    @SdkConstant(SdkConstantType.FEATURE)
1825    public static final String FEATURE_VULKAN_HARDWARE_VERSION = "android.hardware.vulkan.version";
1826
1827    /**
1828     * Feature for {@link #getSystemAvailableFeatures} and
1829     * {@link #hasSystemFeature}: The device includes an accelerometer.
1830     */
1831    @SdkConstant(SdkConstantType.FEATURE)
1832    public static final String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
1833
1834    /**
1835     * Feature for {@link #getSystemAvailableFeatures} and
1836     * {@link #hasSystemFeature}: The device includes a barometer (air
1837     * pressure sensor.)
1838     */
1839    @SdkConstant(SdkConstantType.FEATURE)
1840    public static final String FEATURE_SENSOR_BAROMETER = "android.hardware.sensor.barometer";
1841
1842    /**
1843     * Feature for {@link #getSystemAvailableFeatures} and
1844     * {@link #hasSystemFeature}: The device includes a magnetometer (compass).
1845     */
1846    @SdkConstant(SdkConstantType.FEATURE)
1847    public static final String FEATURE_SENSOR_COMPASS = "android.hardware.sensor.compass";
1848
1849    /**
1850     * Feature for {@link #getSystemAvailableFeatures} and
1851     * {@link #hasSystemFeature}: The device includes a gyroscope.
1852     */
1853    @SdkConstant(SdkConstantType.FEATURE)
1854    public static final String FEATURE_SENSOR_GYROSCOPE = "android.hardware.sensor.gyroscope";
1855
1856    /**
1857     * Feature for {@link #getSystemAvailableFeatures} and
1858     * {@link #hasSystemFeature}: The device includes a light sensor.
1859     */
1860    @SdkConstant(SdkConstantType.FEATURE)
1861    public static final String FEATURE_SENSOR_LIGHT = "android.hardware.sensor.light";
1862
1863    /**
1864     * Feature for {@link #getSystemAvailableFeatures} and
1865     * {@link #hasSystemFeature}: The device includes a proximity sensor.
1866     */
1867    @SdkConstant(SdkConstantType.FEATURE)
1868    public static final String FEATURE_SENSOR_PROXIMITY = "android.hardware.sensor.proximity";
1869
1870    /**
1871     * Feature for {@link #getSystemAvailableFeatures} and
1872     * {@link #hasSystemFeature}: The device includes a hardware step counter.
1873     */
1874    @SdkConstant(SdkConstantType.FEATURE)
1875    public static final String FEATURE_SENSOR_STEP_COUNTER = "android.hardware.sensor.stepcounter";
1876
1877    /**
1878     * Feature for {@link #getSystemAvailableFeatures} and
1879     * {@link #hasSystemFeature}: The device includes a hardware step detector.
1880     */
1881    @SdkConstant(SdkConstantType.FEATURE)
1882    public static final String FEATURE_SENSOR_STEP_DETECTOR = "android.hardware.sensor.stepdetector";
1883
1884    /**
1885     * Feature for {@link #getSystemAvailableFeatures} and
1886     * {@link #hasSystemFeature}: The device includes a heart rate monitor.
1887     */
1888    @SdkConstant(SdkConstantType.FEATURE)
1889    public static final String FEATURE_SENSOR_HEART_RATE = "android.hardware.sensor.heartrate";
1890
1891    /**
1892     * Feature for {@link #getSystemAvailableFeatures} and
1893     * {@link #hasSystemFeature}: The heart rate sensor on this device is an Electrocardiogram.
1894     */
1895    @SdkConstant(SdkConstantType.FEATURE)
1896    public static final String FEATURE_SENSOR_HEART_RATE_ECG =
1897            "android.hardware.sensor.heartrate.ecg";
1898
1899    /**
1900     * Feature for {@link #getSystemAvailableFeatures} and
1901     * {@link #hasSystemFeature}: The device includes a relative humidity sensor.
1902     */
1903    @SdkConstant(SdkConstantType.FEATURE)
1904    public static final String FEATURE_SENSOR_RELATIVE_HUMIDITY =
1905            "android.hardware.sensor.relative_humidity";
1906
1907    /**
1908     * Feature for {@link #getSystemAvailableFeatures} and
1909     * {@link #hasSystemFeature}: The device includes an ambient temperature sensor.
1910     */
1911    @SdkConstant(SdkConstantType.FEATURE)
1912    public static final String FEATURE_SENSOR_AMBIENT_TEMPERATURE =
1913            "android.hardware.sensor.ambient_temperature";
1914
1915    /**
1916     * Feature for {@link #getSystemAvailableFeatures} and
1917     * {@link #hasSystemFeature}: The device supports high fidelity sensor processing
1918     * capabilities.
1919     */
1920    @SdkConstant(SdkConstantType.FEATURE)
1921    public static final String FEATURE_HIFI_SENSORS =
1922            "android.hardware.sensor.hifi_sensors";
1923
1924    /**
1925     * Feature for {@link #getSystemAvailableFeatures} and
1926     * {@link #hasSystemFeature}: The device has a telephony radio with data
1927     * communication support.
1928     */
1929    @SdkConstant(SdkConstantType.FEATURE)
1930    public static final String FEATURE_TELEPHONY = "android.hardware.telephony";
1931
1932    /**
1933     * Feature for {@link #getSystemAvailableFeatures} and
1934     * {@link #hasSystemFeature}: The device has a CDMA telephony stack.
1935     */
1936    @SdkConstant(SdkConstantType.FEATURE)
1937    public static final String FEATURE_TELEPHONY_CDMA = "android.hardware.telephony.cdma";
1938
1939    /**
1940     * Feature for {@link #getSystemAvailableFeatures} and
1941     * {@link #hasSystemFeature}: The device has a GSM telephony stack.
1942     */
1943    @SdkConstant(SdkConstantType.FEATURE)
1944    public static final String FEATURE_TELEPHONY_GSM = "android.hardware.telephony.gsm";
1945
1946    /**
1947     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1948     * The device supports telephony carrier restriction mechanism.
1949     *
1950     * <p>Devices declaring this feature must have an implementation of the
1951     * {@link android.telephony.TelephonyManager#getAllowedCarriers} and
1952     * {@link android.telephony.TelephonyManager#setAllowedCarriers}.
1953     * @hide
1954     */
1955    @SystemApi
1956    @SdkConstant(SdkConstantType.FEATURE)
1957    public static final String FEATURE_TELEPHONY_CARRIERLOCK =
1958            "android.hardware.telephony.carrierlock";
1959
1960    /**
1961     * Feature for {@link #getSystemAvailableFeatures} and
1962     * {@link #hasSystemFeature}: The device supports connecting to USB devices
1963     * as the USB host.
1964     */
1965    @SdkConstant(SdkConstantType.FEATURE)
1966    public static final String FEATURE_USB_HOST = "android.hardware.usb.host";
1967
1968    /**
1969     * Feature for {@link #getSystemAvailableFeatures} and
1970     * {@link #hasSystemFeature}: The device supports connecting to USB accessories.
1971     */
1972    @SdkConstant(SdkConstantType.FEATURE)
1973    public static final String FEATURE_USB_ACCESSORY = "android.hardware.usb.accessory";
1974
1975    /**
1976     * Feature for {@link #getSystemAvailableFeatures} and
1977     * {@link #hasSystemFeature}: The SIP API is enabled on the device.
1978     */
1979    @SdkConstant(SdkConstantType.FEATURE)
1980    public static final String FEATURE_SIP = "android.software.sip";
1981
1982    /**
1983     * Feature for {@link #getSystemAvailableFeatures} and
1984     * {@link #hasSystemFeature}: The device supports SIP-based VOIP.
1985     */
1986    @SdkConstant(SdkConstantType.FEATURE)
1987    public static final String FEATURE_SIP_VOIP = "android.software.sip.voip";
1988
1989    /**
1990     * Feature for {@link #getSystemAvailableFeatures} and
1991     * {@link #hasSystemFeature}: The Connection Service API is enabled on the device.
1992     */
1993    @SdkConstant(SdkConstantType.FEATURE)
1994    public static final String FEATURE_CONNECTION_SERVICE = "android.software.connectionservice";
1995
1996    /**
1997     * Feature for {@link #getSystemAvailableFeatures} and
1998     * {@link #hasSystemFeature}: The device's display has a touch screen.
1999     */
2000    @SdkConstant(SdkConstantType.FEATURE)
2001    public static final String FEATURE_TOUCHSCREEN = "android.hardware.touchscreen";
2002
2003    /**
2004     * Feature for {@link #getSystemAvailableFeatures} and
2005     * {@link #hasSystemFeature}: The device's touch screen supports
2006     * multitouch sufficient for basic two-finger gesture detection.
2007     */
2008    @SdkConstant(SdkConstantType.FEATURE)
2009    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH = "android.hardware.touchscreen.multitouch";
2010
2011    /**
2012     * Feature for {@link #getSystemAvailableFeatures} and
2013     * {@link #hasSystemFeature}: The device's touch screen is capable of
2014     * tracking two or more fingers fully independently.
2015     */
2016    @SdkConstant(SdkConstantType.FEATURE)
2017    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT = "android.hardware.touchscreen.multitouch.distinct";
2018
2019    /**
2020     * Feature for {@link #getSystemAvailableFeatures} and
2021     * {@link #hasSystemFeature}: The device's touch screen is capable of
2022     * tracking a full hand of fingers fully independently -- that is, 5 or
2023     * more simultaneous independent pointers.
2024     */
2025    @SdkConstant(SdkConstantType.FEATURE)
2026    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND = "android.hardware.touchscreen.multitouch.jazzhand";
2027
2028    /**
2029     * Feature for {@link #getSystemAvailableFeatures} and
2030     * {@link #hasSystemFeature}: The device does not have a touch screen, but
2031     * does support touch emulation for basic events. For instance, the
2032     * device might use a mouse or remote control to drive a cursor, and
2033     * emulate basic touch pointer events like down, up, drag, etc. All
2034     * devices that support android.hardware.touchscreen or a sub-feature are
2035     * presumed to also support faketouch.
2036     */
2037    @SdkConstant(SdkConstantType.FEATURE)
2038    public static final String FEATURE_FAKETOUCH = "android.hardware.faketouch";
2039
2040    /**
2041     * Feature for {@link #getSystemAvailableFeatures} and
2042     * {@link #hasSystemFeature}: The device does not have a touch screen, but
2043     * does support touch emulation for basic events that supports distinct
2044     * tracking of two or more fingers.  This is an extension of
2045     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
2046     * that unlike a distinct multitouch screen as defined by
2047     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT}, these kinds of input
2048     * devices will not actually provide full two-finger gestures since the
2049     * input is being transformed to cursor movement on the screen.  That is,
2050     * single finger gestures will move a cursor; two-finger swipes will
2051     * result in single-finger touch events; other two-finger gestures will
2052     * result in the corresponding two-finger touch event.
2053     */
2054    @SdkConstant(SdkConstantType.FEATURE)
2055    public static final String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
2056
2057    /**
2058     * Feature for {@link #getSystemAvailableFeatures} and
2059     * {@link #hasSystemFeature}: The device does not have a touch screen, but
2060     * does support touch emulation for basic events that supports tracking
2061     * a hand of fingers (5 or more fingers) fully independently.
2062     * This is an extension of
2063     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
2064     * that unlike a multitouch screen as defined by
2065     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND}, not all two finger
2066     * gestures can be detected due to the limitations described for
2067     * {@link #FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT}.
2068     */
2069    @SdkConstant(SdkConstantType.FEATURE)
2070    public static final String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
2071
2072    /**
2073     * Feature for {@link #getSystemAvailableFeatures} and
2074     * {@link #hasSystemFeature}: The device has biometric hardware to detect a fingerprint.
2075      */
2076    @SdkConstant(SdkConstantType.FEATURE)
2077    public static final String FEATURE_FINGERPRINT = "android.hardware.fingerprint";
2078
2079    /**
2080     * Feature for {@link #getSystemAvailableFeatures} and
2081     * {@link #hasSystemFeature}: The device supports portrait orientation
2082     * screens.  For backwards compatibility, you can assume that if neither
2083     * this nor {@link #FEATURE_SCREEN_LANDSCAPE} is set then the device supports
2084     * both portrait and landscape.
2085     */
2086    @SdkConstant(SdkConstantType.FEATURE)
2087    public static final String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
2088
2089    /**
2090     * Feature for {@link #getSystemAvailableFeatures} and
2091     * {@link #hasSystemFeature}: The device supports landscape orientation
2092     * screens.  For backwards compatibility, you can assume that if neither
2093     * this nor {@link #FEATURE_SCREEN_PORTRAIT} is set then the device supports
2094     * both portrait and landscape.
2095     */
2096    @SdkConstant(SdkConstantType.FEATURE)
2097    public static final String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
2098
2099    /**
2100     * Feature for {@link #getSystemAvailableFeatures} and
2101     * {@link #hasSystemFeature}: The device supports live wallpapers.
2102     */
2103    @SdkConstant(SdkConstantType.FEATURE)
2104    public static final String FEATURE_LIVE_WALLPAPER = "android.software.live_wallpaper";
2105    /**
2106     * Feature for {@link #getSystemAvailableFeatures} and
2107     * {@link #hasSystemFeature}: The device supports app widgets.
2108     */
2109    @SdkConstant(SdkConstantType.FEATURE)
2110    public static final String FEATURE_APP_WIDGETS = "android.software.app_widgets";
2111
2112    /**
2113     * @hide
2114     * Feature for {@link #getSystemAvailableFeatures} and
2115     * {@link #hasSystemFeature}: The device supports
2116     * {@link android.service.voice.VoiceInteractionService} and
2117     * {@link android.app.VoiceInteractor}.
2118     */
2119    @SdkConstant(SdkConstantType.FEATURE)
2120    public static final String FEATURE_VOICE_RECOGNIZERS = "android.software.voice_recognizers";
2121
2122
2123    /**
2124     * Feature for {@link #getSystemAvailableFeatures} and
2125     * {@link #hasSystemFeature}: The device supports a home screen that is replaceable
2126     * by third party applications.
2127     */
2128    @SdkConstant(SdkConstantType.FEATURE)
2129    public static final String FEATURE_HOME_SCREEN = "android.software.home_screen";
2130
2131    /**
2132     * Feature for {@link #getSystemAvailableFeatures} and
2133     * {@link #hasSystemFeature}: The device supports adding new input methods implemented
2134     * with the {@link android.inputmethodservice.InputMethodService} API.
2135     */
2136    @SdkConstant(SdkConstantType.FEATURE)
2137    public static final String FEATURE_INPUT_METHODS = "android.software.input_methods";
2138
2139    /**
2140     * Feature for {@link #getSystemAvailableFeatures} and
2141     * {@link #hasSystemFeature}: The device supports device policy enforcement via device admins.
2142     */
2143    @SdkConstant(SdkConstantType.FEATURE)
2144    public static final String FEATURE_DEVICE_ADMIN = "android.software.device_admin";
2145
2146    /**
2147     * Feature for {@link #getSystemAvailableFeatures} and
2148     * {@link #hasSystemFeature}: The device supports leanback UI. This is
2149     * typically used in a living room television experience, but is a software
2150     * feature unlike {@link #FEATURE_TELEVISION}. Devices running with this
2151     * feature will use resources associated with the "television" UI mode.
2152     */
2153    @SdkConstant(SdkConstantType.FEATURE)
2154    public static final String FEATURE_LEANBACK = "android.software.leanback";
2155
2156    /**
2157     * Feature for {@link #getSystemAvailableFeatures} and
2158     * {@link #hasSystemFeature}: The device supports only leanback UI. Only
2159     * applications designed for this experience should be run, though this is
2160     * not enforced by the system.
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    /**
6243     * Return the {@link ComponentName} of the activity providing Settings for the Instant App
6244     * resolver.
6245     *
6246     * @see {@link android.content.intent#ACTION_EPHEMERAL_RESOLVER_SETTINGS}
6247     * @hide
6248     */
6249    @SystemApi
6250    public abstract ComponentName getInstantAppResolverSettingsComponent();
6251}
6252