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