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