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