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