PackageManager.java revision d303b25ad3dc7249800b28c4a5bda2d787f0c4c5
1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.pm;
18
19import android.Manifest;
20import android.annotation.CheckResult;
21import android.annotation.DrawableRes;
22import android.annotation.IntDef;
23import android.annotation.NonNull;
24import android.annotation.Nullable;
25import android.annotation.RequiresPermission;
26import android.annotation.SdkConstant;
27import android.annotation.SdkConstant.SdkConstantType;
28import android.annotation.StringRes;
29import android.annotation.SystemApi;
30import android.annotation.XmlRes;
31import android.app.PackageDeleteObserver;
32import android.app.PackageInstallObserver;
33import android.app.admin.DevicePolicyManager;
34import android.content.ComponentName;
35import android.content.Context;
36import android.content.Intent;
37import android.content.IntentFilter;
38import android.content.IntentSender;
39import android.content.pm.PackageParser.PackageParserException;
40import android.content.res.Resources;
41import android.content.res.XmlResourceParser;
42import android.graphics.Rect;
43import android.graphics.drawable.Drawable;
44import android.net.Uri;
45import android.os.Bundle;
46import android.os.Environment;
47import android.os.Handler;
48import android.os.RemoteException;
49import android.os.UserHandle;
50import android.os.storage.VolumeInfo;
51import android.text.TextUtils;
52import android.util.AndroidException;
53
54import com.android.internal.util.ArrayUtils;
55
56import java.io.File;
57import java.lang.annotation.Retention;
58import java.lang.annotation.RetentionPolicy;
59import java.util.List;
60
61/**
62 * Class for retrieving various kinds of information related to the application
63 * packages that are currently installed on the device.
64 *
65 * You can find this class through {@link Context#getPackageManager}.
66 */
67public abstract class PackageManager {
68
69    /**
70     * This exception is thrown when a given package, application, or component
71     * name cannot be found.
72     */
73    public static class NameNotFoundException extends AndroidException {
74        public NameNotFoundException() {
75        }
76
77        public NameNotFoundException(String name) {
78            super(name);
79        }
80    }
81
82    /**
83     * Listener for changes in permissions granted to a UID.
84     *
85     * @hide
86     */
87    @SystemApi
88    public interface OnPermissionsChangedListener {
89
90        /**
91         * Called when the permissions for a UID change.
92         * @param uid The UID with a change.
93         */
94        public void onPermissionsChanged(int uid);
95    }
96
97    /**
98     * {@link PackageInfo} flag: return information about
99     * activities in the package in {@link PackageInfo#activities}.
100     */
101    public static final int GET_ACTIVITIES              = 0x00000001;
102
103    /**
104     * {@link PackageInfo} flag: return information about
105     * intent receivers in the package in
106     * {@link PackageInfo#receivers}.
107     */
108    public static final int GET_RECEIVERS               = 0x00000002;
109
110    /**
111     * {@link PackageInfo} flag: return information about
112     * services in the package in {@link PackageInfo#services}.
113     */
114    public static final int GET_SERVICES                = 0x00000004;
115
116    /**
117     * {@link PackageInfo} flag: return information about
118     * content providers in the package in
119     * {@link PackageInfo#providers}.
120     */
121    public static final int GET_PROVIDERS               = 0x00000008;
122
123    /**
124     * {@link PackageInfo} flag: return information about
125     * instrumentation in the package in
126     * {@link PackageInfo#instrumentation}.
127     */
128    public static final int GET_INSTRUMENTATION         = 0x00000010;
129
130    /**
131     * {@link PackageInfo} flag: return information about the
132     * intent filters supported by the activity.
133     */
134    public static final int GET_INTENT_FILTERS          = 0x00000020;
135
136    /**
137     * {@link PackageInfo} flag: return information about the
138     * signatures included in the package.
139     */
140    public static final int GET_SIGNATURES          = 0x00000040;
141
142    /**
143     * {@link ResolveInfo} flag: return the IntentFilter that
144     * was matched for a particular ResolveInfo in
145     * {@link ResolveInfo#filter}.
146     */
147    public static final int GET_RESOLVED_FILTER         = 0x00000040;
148
149    /**
150     * {@link ComponentInfo} flag: return the {@link ComponentInfo#metaData}
151     * data {@link android.os.Bundle}s that are associated with a component.
152     * This applies for any API returning a ComponentInfo subclass.
153     */
154    public static final int GET_META_DATA               = 0x00000080;
155
156    /**
157     * {@link PackageInfo} flag: return the
158     * {@link PackageInfo#gids group ids} that are associated with an
159     * application.
160     * This applies for any API returning a PackageInfo class, either
161     * directly or nested inside of another.
162     */
163    public static final int GET_GIDS                    = 0x00000100;
164
165    /**
166     * {@link PackageInfo} flag: include disabled components in the returned info.
167     */
168    public static final int GET_DISABLED_COMPONENTS     = 0x00000200;
169
170    /**
171     * {@link ApplicationInfo} flag: return the
172     * {@link ApplicationInfo#sharedLibraryFiles paths to the shared libraries}
173     * that are associated with an application.
174     * This applies for any API returning an ApplicationInfo class, either
175     * directly or nested inside of another.
176     */
177    public static final int GET_SHARED_LIBRARY_FILES    = 0x00000400;
178
179    /**
180     * {@link ProviderInfo} flag: return the
181     * {@link ProviderInfo#uriPermissionPatterns URI permission patterns}
182     * that are associated with a content provider.
183     * This applies for any API returning a ProviderInfo class, either
184     * directly or nested inside of another.
185     */
186    public static final int GET_URI_PERMISSION_PATTERNS  = 0x00000800;
187    /**
188     * {@link PackageInfo} flag: return information about
189     * permissions in the package in
190     * {@link PackageInfo#permissions}.
191     */
192    public static final int GET_PERMISSIONS               = 0x00001000;
193
194    /**
195     * Flag parameter to retrieve some information about all applications (even
196     * uninstalled ones) which have data directories. This state could have
197     * resulted if applications have been deleted with flag
198     * {@code DONT_DELETE_DATA} with a possibility of being replaced or
199     * reinstalled in future.
200     * <p>
201     * Note: this flag may cause less information about currently installed
202     * applications to be returned.
203     */
204    public static final int GET_UNINSTALLED_PACKAGES = 0x00002000;
205
206    /**
207     * {@link PackageInfo} flag: return information about
208     * hardware preferences in
209     * {@link PackageInfo#configPreferences PackageInfo.configPreferences},
210     * and requested features in {@link PackageInfo#reqFeatures} and
211     * {@link PackageInfo#featureGroups}.
212     */
213    public static final int GET_CONFIGURATIONS = 0x00004000;
214
215    /**
216     * {@link PackageInfo} flag: include disabled components which are in
217     * that state only because of {@link #COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED}
218     * in the returned info.  Note that if you set this flag, applications
219     * that are in this disabled state will be reported as enabled.
220     */
221    public static final int GET_DISABLED_UNTIL_USED_COMPONENTS = 0x00008000;
222
223    /**
224     * Resolution and querying flag: if set, only filters that support the
225     * {@link android.content.Intent#CATEGORY_DEFAULT} will be considered for
226     * matching.  This is a synonym for including the CATEGORY_DEFAULT in your
227     * supplied Intent.
228     */
229    public static final int MATCH_DEFAULT_ONLY  = 0x00010000;
230
231    /**
232     * Querying flag: if set and if the platform is doing any filtering of the results, then
233     * the filtering will not happen. This is a synonym for saying that all results should
234     * be returned.
235     */
236    public static final int MATCH_ALL = 0x00020000;
237
238    /**
239     * Flag for {@link addCrossProfileIntentFilter}: if this flag is set:
240     * when resolving an intent that matches the {@link CrossProfileIntentFilter}, the current
241     * profile will be skipped.
242     * Only activities in the target user can respond to the intent.
243     * @hide
244     */
245    public static final int SKIP_CURRENT_PROFILE = 0x00000002;
246
247    /** @hide */
248    @IntDef({PERMISSION_GRANTED, PERMISSION_DENIED})
249    @Retention(RetentionPolicy.SOURCE)
250    public @interface PermissionResult {}
251
252    /**
253     * Permission check result: this is returned by {@link #checkPermission}
254     * if the permission has been granted to the given package.
255     */
256    public static final int PERMISSION_GRANTED = 0;
257
258    /**
259     * Permission check result: this is returned by {@link #checkPermission}
260     * if the permission has not been granted to the given package.
261     */
262    public static final int PERMISSION_DENIED = -1;
263
264    /**
265     * Signature check result: this is returned by {@link #checkSignatures}
266     * if all signatures on the two packages match.
267     */
268    public static final int SIGNATURE_MATCH = 0;
269
270    /**
271     * Signature check result: this is returned by {@link #checkSignatures}
272     * if neither of the two packages is signed.
273     */
274    public static final int SIGNATURE_NEITHER_SIGNED = 1;
275
276    /**
277     * Signature check result: this is returned by {@link #checkSignatures}
278     * if the first package is not signed but the second is.
279     */
280    public static final int SIGNATURE_FIRST_NOT_SIGNED = -1;
281
282    /**
283     * Signature check result: this is returned by {@link #checkSignatures}
284     * if the second package is not signed but the first is.
285     */
286    public static final int SIGNATURE_SECOND_NOT_SIGNED = -2;
287
288    /**
289     * Signature check result: this is returned by {@link #checkSignatures}
290     * if not all signatures on both packages match.
291     */
292    public static final int SIGNATURE_NO_MATCH = -3;
293
294    /**
295     * Signature check result: this is returned by {@link #checkSignatures}
296     * if either of the packages are not valid.
297     */
298    public static final int SIGNATURE_UNKNOWN_PACKAGE = -4;
299
300    /**
301     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
302     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
303     * component or application is in its default enabled state (as specified
304     * in its manifest).
305     */
306    public static final int COMPONENT_ENABLED_STATE_DEFAULT = 0;
307
308    /**
309     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
310     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
311     * component or application has been explictily enabled, regardless of
312     * what it has specified in its manifest.
313     */
314    public static final int COMPONENT_ENABLED_STATE_ENABLED = 1;
315
316    /**
317     * Flag for {@link #setApplicationEnabledSetting(String, int, int)}
318     * and {@link #setComponentEnabledSetting(ComponentName, int, int)}: This
319     * component or application has been explicitly disabled, regardless of
320     * what it has specified in its manifest.
321     */
322    public static final int COMPONENT_ENABLED_STATE_DISABLED = 2;
323
324    /**
325     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: The
326     * user has explicitly disabled the application, regardless of what it has
327     * specified in its manifest.  Because this is due to the user's request,
328     * they may re-enable it if desired through the appropriate system UI.  This
329     * option currently <strong>cannot</strong> be used with
330     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
331     */
332    public static final int COMPONENT_ENABLED_STATE_DISABLED_USER = 3;
333
334    /**
335     * Flag for {@link #setApplicationEnabledSetting(String, int, int)} only: This
336     * application should be considered, until the point where the user actually
337     * wants to use it.  This means that it will not normally show up to the user
338     * (such as in the launcher), but various parts of the user interface can
339     * use {@link #GET_DISABLED_UNTIL_USED_COMPONENTS} to still see it and allow
340     * the user to select it (as for example an IME, device admin, etc).  Such code,
341     * once the user has selected the app, should at that point also make it enabled.
342     * This option currently <strong>can not</strong> be used with
343     * {@link #setComponentEnabledSetting(ComponentName, int, int)}.
344     */
345    public static final int COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED = 4;
346
347    /**
348     * Flag parameter for {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} to
349     * indicate that this package should be installed as forward locked, i.e. only the app itself
350     * should have access to its code and non-resource assets.
351     * @hide
352     */
353    public static final int INSTALL_FORWARD_LOCK = 0x00000001;
354
355    /**
356     * Flag parameter for {@link #installPackage} to indicate that you want to replace an already
357     * installed package, if one exists.
358     * @hide
359     */
360    public static final int INSTALL_REPLACE_EXISTING = 0x00000002;
361
362    /**
363     * Flag parameter for {@link #installPackage} to indicate that you want to
364     * allow test packages (those that have set android:testOnly in their
365     * manifest) to be installed.
366     * @hide
367     */
368    public static final int INSTALL_ALLOW_TEST = 0x00000004;
369
370    /**
371     * Flag parameter for {@link #installPackage} to indicate that this package
372     * must be installed to an ASEC on a {@link VolumeInfo#TYPE_PUBLIC}.
373     *
374     * @hide
375     */
376    public static final int INSTALL_EXTERNAL = 0x00000008;
377
378    /**
379     * Flag parameter for {@link #installPackage} to indicate that this package
380     * must be installed to internal storage.
381     *
382     * @hide
383     */
384    public static final int INSTALL_INTERNAL = 0x00000010;
385
386    /**
387     * Flag parameter for {@link #installPackage} to indicate that this install
388     * was initiated via ADB.
389     *
390     * @hide
391     */
392    public static final int INSTALL_FROM_ADB = 0x00000020;
393
394    /**
395     * Flag parameter for {@link #installPackage} to indicate that this install
396     * should immediately be visible to all users.
397     *
398     * @hide
399     */
400    public static final int INSTALL_ALL_USERS = 0x00000040;
401
402    /**
403     * Flag parameter for {@link #installPackage} to indicate that it is okay
404     * to install an update to an app where the newly installed app has a lower
405     * version code than the currently installed app.
406     *
407     * @hide
408     */
409    public static final int INSTALL_ALLOW_DOWNGRADE = 0x00000080;
410
411    /**
412     * Flag parameter for {@link #installPackage} to indicate that all runtime
413     * permissions should be granted to the package. If {@link #INSTALL_ALL_USERS}
414     * is set the runtime permissions will be granted to all users, otherwise
415     * only to the owner.
416     *
417     * @hide
418     */
419    public static final int INSTALL_GRANT_RUNTIME_PERMISSIONS = 0x00000100;
420
421    /** {@hide} */
422    public static final int INSTALL_FORCE_VOLUME_UUID = 0x00000200;
423
424    /**
425     * Flag parameter for {@link #installPackage} to indicate that we always want to force
426     * the prompt for permission approval. This overrides any special behaviour for internal
427     * components.
428     *
429     * @hide
430     */
431    public static final int INSTALL_FORCE_PERMISSION_PROMPT = 0x00000400;
432
433    /**
434     * Flag parameter for
435     * {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate
436     * that you don't want to kill the app containing the component.  Be careful when you set this
437     * since changing component states can make the containing application's behavior unpredictable.
438     */
439    public static final int DONT_KILL_APP = 0x00000001;
440
441    /**
442     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
443     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} on success.
444     * @hide
445     */
446    @SystemApi
447    public static final int INSTALL_SUCCEEDED = 1;
448
449    /**
450     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
451     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package is
452     * already installed.
453     * @hide
454     */
455    @SystemApi
456    public static final int INSTALL_FAILED_ALREADY_EXISTS = -1;
457
458    /**
459     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
460     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package archive
461     * file is invalid.
462     * @hide
463     */
464    @SystemApi
465    public static final int INSTALL_FAILED_INVALID_APK = -2;
466
467    /**
468     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
469     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the URI passed in
470     * is invalid.
471     * @hide
472     */
473    @SystemApi
474    public static final int INSTALL_FAILED_INVALID_URI = -3;
475
476    /**
477     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
478     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if the package manager
479     * service found that the device didn't have enough storage space to install the app.
480     * @hide
481     */
482    @SystemApi
483    public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE = -4;
484
485    /**
486     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
487     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if a
488     * package is already installed with the same name.
489     * @hide
490     */
491    @SystemApi
492    public static final int INSTALL_FAILED_DUPLICATE_PACKAGE = -5;
493
494    /**
495     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
496     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
497     * the requested shared user does not exist.
498     * @hide
499     */
500    @SystemApi
501    public static final int INSTALL_FAILED_NO_SHARED_USER = -6;
502
503    /**
504     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
505     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
506     * a previously installed package of the same name has a different signature
507     * than the new package (and the old package's data was not removed).
508     * @hide
509     */
510    @SystemApi
511    public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE = -7;
512
513    /**
514     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
515     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
516     * the new package is requested a shared user which is already installed on the
517     * device and does not have matching signature.
518     * @hide
519     */
520    @SystemApi
521    public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE = -8;
522
523    /**
524     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
525     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
526     * the new package uses a shared library that is not available.
527     * @hide
528     */
529    @SystemApi
530    public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY = -9;
531
532    /**
533     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
534     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
535     * the new package uses a shared library that is not available.
536     * @hide
537     */
538    @SystemApi
539    public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE = -10;
540
541    /**
542     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
543     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
544     * the new package failed while optimizing and validating its dex files,
545     * either because there was not enough storage or the validation failed.
546     * @hide
547     */
548    @SystemApi
549    public static final int INSTALL_FAILED_DEXOPT = -11;
550
551    /**
552     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
553     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
554     * the new package failed because the current SDK version is older than
555     * that required by the package.
556     * @hide
557     */
558    @SystemApi
559    public static final int INSTALL_FAILED_OLDER_SDK = -12;
560
561    /**
562     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
563     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
564     * the new package failed because it contains a content provider with the
565     * same authority as a provider already installed in the system.
566     * @hide
567     */
568    @SystemApi
569    public static final int INSTALL_FAILED_CONFLICTING_PROVIDER = -13;
570
571    /**
572     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
573     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
574     * the new package failed because the current SDK version is newer than
575     * that required by the package.
576     * @hide
577     */
578    @SystemApi
579    public static final int INSTALL_FAILED_NEWER_SDK = -14;
580
581    /**
582     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
583     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
584     * the new package failed because it has specified that it is a test-only
585     * package and the caller has not supplied the {@link #INSTALL_ALLOW_TEST}
586     * flag.
587     * @hide
588     */
589    @SystemApi
590    public static final int INSTALL_FAILED_TEST_ONLY = -15;
591
592    /**
593     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
594     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
595     * the package being installed contains native code, but none that is
596     * compatible with the device's CPU_ABI.
597     * @hide
598     */
599    @SystemApi
600    public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;
601
602    /**
603     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
604     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
605     * the new package uses a feature that is not available.
606     * @hide
607     */
608    @SystemApi
609    public static final int INSTALL_FAILED_MISSING_FEATURE = -17;
610
611    // ------ Errors related to sdcard
612    /**
613     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
614     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
615     * a secure container mount point couldn't be accessed on external media.
616     * @hide
617     */
618    @SystemApi
619    public static final int INSTALL_FAILED_CONTAINER_ERROR = -18;
620
621    /**
622     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
623     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
624     * the new package couldn't be installed in the specified install
625     * location.
626     * @hide
627     */
628    @SystemApi
629    public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION = -19;
630
631    /**
632     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
633     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
634     * the new package couldn't be installed in the specified install
635     * location because the media is not available.
636     * @hide
637     */
638    @SystemApi
639    public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE = -20;
640
641    /**
642     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
643     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
644     * the new package couldn't be installed because the verification timed out.
645     * @hide
646     */
647    @SystemApi
648    public static final int INSTALL_FAILED_VERIFICATION_TIMEOUT = -21;
649
650    /**
651     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
652     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
653     * the new package couldn't be installed because the verification did not succeed.
654     * @hide
655     */
656    @SystemApi
657    public static final int INSTALL_FAILED_VERIFICATION_FAILURE = -22;
658
659    /**
660     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
661     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
662     * the package changed from what the calling program expected.
663     * @hide
664     */
665    @SystemApi
666    public static final int INSTALL_FAILED_PACKAGE_CHANGED = -23;
667
668    /**
669     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
670     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
671     * the new package is assigned a different UID than it previously held.
672     * @hide
673     */
674    public static final int INSTALL_FAILED_UID_CHANGED = -24;
675
676    /**
677     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
678     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
679     * the new package has an older version code than the currently installed package.
680     * @hide
681     */
682    public static final int INSTALL_FAILED_VERSION_DOWNGRADE = -25;
683
684    /**
685     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
686     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
687     * the old package has target SDK high enough to support runtime permission and
688     * the new package has target SDK low enough to not support runtime permissions.
689     * @hide
690     */
691    @SystemApi
692    public static final int INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE = -26;
693
694    /**
695     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
696     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
697     * if the parser was given a path that is not a file, or does not end with the expected
698     * '.apk' extension.
699     * @hide
700     */
701    @SystemApi
702    public static final int INSTALL_PARSE_FAILED_NOT_APK = -100;
703
704    /**
705     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
706     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
707     * if the parser was unable to retrieve the AndroidManifest.xml file.
708     * @hide
709     */
710    @SystemApi
711    public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST = -101;
712
713    /**
714     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
715     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
716     * if the parser encountered an unexpected exception.
717     * @hide
718     */
719    @SystemApi
720    public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION = -102;
721
722    /**
723     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
724     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
725     * if the parser did not find any certificates in the .apk.
726     * @hide
727     */
728    @SystemApi
729    public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES = -103;
730
731    /**
732     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
733     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
734     * if the parser found inconsistent certificates on the files in the .apk.
735     * @hide
736     */
737    @SystemApi
738    public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES = -104;
739
740    /**
741     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
742     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
743     * if the parser encountered a CertificateEncodingException in one of the
744     * files in the .apk.
745     * @hide
746     */
747    @SystemApi
748    public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING = -105;
749
750    /**
751     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
752     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
753     * if the parser encountered a bad or missing package name in the manifest.
754     * @hide
755     */
756    @SystemApi
757    public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME = -106;
758
759    /**
760     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
761     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
762     * if the parser encountered a bad shared user id name in the manifest.
763     * @hide
764     */
765    @SystemApi
766    public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID = -107;
767
768    /**
769     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
770     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
771     * if the parser encountered some structural problem in the manifest.
772     * @hide
773     */
774    @SystemApi
775    public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED = -108;
776
777    /**
778     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
779     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
780     * if the parser did not find any actionable tags (instrumentation or application)
781     * in the manifest.
782     * @hide
783     */
784    @SystemApi
785    public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY = -109;
786
787    /**
788     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
789     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
790     * if the system failed to install the package because of system issues.
791     * @hide
792     */
793    @SystemApi
794    public static final int INSTALL_FAILED_INTERNAL_ERROR = -110;
795
796    /**
797     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
798     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
799     * if the system failed to install the package because the user is restricted from installing
800     * apps.
801     * @hide
802     */
803    public static final int INSTALL_FAILED_USER_RESTRICTED = -111;
804
805    /**
806     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
807     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
808     * if the system failed to install the package because it is attempting to define a
809     * permission that is already defined by some existing package.
810     *
811     * <p>The package name of the app which has already defined the permission is passed to
812     * a {@link PackageInstallObserver}, if any, as the {@link #EXTRA_EXISTING_PACKAGE}
813     * string extra; and the name of the permission being redefined is passed in the
814     * {@link #EXTRA_EXISTING_PERMISSION} string extra.
815     * @hide
816     */
817    public static final int INSTALL_FAILED_DUPLICATE_PERMISSION = -112;
818
819    /**
820     * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
821     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
822     * if the system failed to install the package because its packaged native code did not
823     * match any of the ABIs supported by the system.
824     *
825     * @hide
826     */
827    public static final int INSTALL_FAILED_NO_MATCHING_ABIS = -113;
828
829    /**
830     * Internal return code for NativeLibraryHelper methods to indicate that the package
831     * being processed did not contain any native code. This is placed here only so that
832     * it can belong to the same value space as the other install failure codes.
833     *
834     * @hide
835     */
836    public static final int NO_NATIVE_LIBRARIES = -114;
837
838    /** {@hide} */
839    public static final int INSTALL_FAILED_ABORTED = -115;
840
841    /**
842     * Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
843     * package's data directory.
844     *
845     * @hide
846     */
847    public static final int DELETE_KEEP_DATA = 0x00000001;
848
849    /**
850     * Flag parameter for {@link #deletePackage} to indicate that you want the
851     * package deleted for all users.
852     *
853     * @hide
854     */
855    public static final int DELETE_ALL_USERS = 0x00000002;
856
857    /**
858     * Flag parameter for {@link #deletePackage} to indicate that, if you are calling
859     * uninstall on a system that has been updated, then don't do the normal process
860     * of uninstalling the update and rolling back to the older system version (which
861     * needs to happen for all users); instead, just mark the app as uninstalled for
862     * the current user.
863     *
864     * @hide
865     */
866    public static final int DELETE_SYSTEM_APP = 0x00000004;
867
868    /**
869     * Return code for when package deletion succeeds. This is passed to the
870     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
871     * succeeded in deleting the package.
872     *
873     * @hide
874     */
875    public static final int DELETE_SUCCEEDED = 1;
876
877    /**
878     * Deletion failed return code: this is passed to the
879     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
880     * failed to delete the package for an unspecified reason.
881     *
882     * @hide
883     */
884    public static final int DELETE_FAILED_INTERNAL_ERROR = -1;
885
886    /**
887     * Deletion failed return code: this is passed to the
888     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
889     * failed to delete the package because it is the active DevicePolicy
890     * manager.
891     *
892     * @hide
893     */
894    public static final int DELETE_FAILED_DEVICE_POLICY_MANAGER = -2;
895
896    /**
897     * Deletion failed return code: this is passed to the
898     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
899     * failed to delete the package since the user is restricted.
900     *
901     * @hide
902     */
903    public static final int DELETE_FAILED_USER_RESTRICTED = -3;
904
905    /**
906     * Deletion failed return code: this is passed to the
907     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
908     * failed to delete the package because a profile
909     * or device owner has marked the package as uninstallable.
910     *
911     * @hide
912     */
913    public static final int DELETE_FAILED_OWNER_BLOCKED = -4;
914
915    /** {@hide} */
916    public static final int DELETE_FAILED_ABORTED = -5;
917
918    /**
919     * Return code that is passed to the {@link IPackageMoveObserver} by
920     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)} when the
921     * package has been successfully moved by the system.
922     *
923     * @hide
924     */
925    public static final int MOVE_SUCCEEDED = -100;
926
927    /**
928     * Error code that is passed to the {@link IPackageMoveObserver} by
929     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
930     * when the package hasn't been successfully moved by the system
931     * because of insufficient memory on specified media.
932     * @hide
933     */
934    public static final int MOVE_FAILED_INSUFFICIENT_STORAGE = -1;
935
936    /**
937     * Error code that is passed to the {@link IPackageMoveObserver} by
938     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
939     * if the specified package doesn't exist.
940     * @hide
941     */
942    public static final int MOVE_FAILED_DOESNT_EXIST = -2;
943
944    /**
945     * Error code that is passed to the {@link IPackageMoveObserver} by
946     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
947     * if the specified package cannot be moved since its a system package.
948     * @hide
949     */
950    public static final int MOVE_FAILED_SYSTEM_PACKAGE = -3;
951
952    /**
953     * Error code that is passed to the {@link IPackageMoveObserver} by
954     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
955     * if the specified package cannot be moved since its forward locked.
956     * @hide
957     */
958    public static final int MOVE_FAILED_FORWARD_LOCKED = -4;
959
960    /**
961     * Error code that is passed to the {@link IPackageMoveObserver} by
962     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
963     * if the specified package cannot be moved to the specified location.
964     * @hide
965     */
966    public static final int MOVE_FAILED_INVALID_LOCATION = -5;
967
968    /**
969     * Error code that is passed to the {@link IPackageMoveObserver} by
970     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
971     * if the specified package cannot be moved to the specified location.
972     * @hide
973     */
974    public static final int MOVE_FAILED_INTERNAL_ERROR = -6;
975
976    /**
977     * Error code that is passed to the {@link IPackageMoveObserver} by
978     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)} if the
979     * specified package already has an operation pending in the
980     * {@link PackageHandler} queue.
981     *
982     * @hide
983     */
984    public static final int MOVE_FAILED_OPERATION_PENDING = -7;
985
986    /**
987     * Flag parameter for {@link #movePackage} to indicate that
988     * the package should be moved to internal storage if its
989     * been installed on external media.
990     * @hide
991     */
992    @Deprecated
993    public static final int MOVE_INTERNAL = 0x00000001;
994
995    /**
996     * Flag parameter for {@link #movePackage} to indicate that
997     * the package should be moved to external media.
998     * @hide
999     */
1000    @Deprecated
1001    public static final int MOVE_EXTERNAL_MEDIA = 0x00000002;
1002
1003    /** {@hide} */
1004    public static final String EXTRA_MOVE_ID = "android.content.pm.extra.MOVE_ID";
1005
1006    /**
1007     * Usable by the required verifier as the {@code verificationCode} argument
1008     * for {@link PackageManager#verifyPendingInstall} to indicate that it will
1009     * allow the installation to proceed without any of the optional verifiers
1010     * needing to vote.
1011     *
1012     * @hide
1013     */
1014    public static final int VERIFICATION_ALLOW_WITHOUT_SUFFICIENT = 2;
1015
1016    /**
1017     * Used as the {@code verificationCode} argument for
1018     * {@link PackageManager#verifyPendingInstall} to indicate that the calling
1019     * package verifier allows the installation to proceed.
1020     */
1021    public static final int VERIFICATION_ALLOW = 1;
1022
1023    /**
1024     * Used as the {@code verificationCode} argument for
1025     * {@link PackageManager#verifyPendingInstall} to indicate the calling
1026     * package verifier does not vote to allow the installation to proceed.
1027     */
1028    public static final int VERIFICATION_REJECT = -1;
1029
1030    /**
1031     * Used as the {@code verificationCode} argument for
1032     * {@link PackageManager#verifyIntentFilter} to indicate that the calling
1033     * IntentFilter Verifier confirms that the IntentFilter is verified.
1034     *
1035     * @hide
1036     */
1037    public static final int INTENT_FILTER_VERIFICATION_SUCCESS = 1;
1038
1039    /**
1040     * Used as the {@code verificationCode} argument for
1041     * {@link PackageManager#verifyIntentFilter} to indicate that the calling
1042     * IntentFilter Verifier confirms that the IntentFilter is NOT verified.
1043     *
1044     * @hide
1045     */
1046    public static final int INTENT_FILTER_VERIFICATION_FAILURE = -1;
1047
1048    /**
1049     * Internal status code to indicate that an IntentFilter verification result is not specified.
1050     *
1051     * @hide
1052     */
1053    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED = 0;
1054
1055    /**
1056     * Used as the {@code status} argument for {@link PackageManager#updateIntentVerificationStatus}
1057     * to indicate that the User will always be prompted the Intent Disambiguation Dialog if there
1058     * are two or more Intent resolved for the IntentFilter's domain(s).
1059     *
1060     * @hide
1061     */
1062    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK = 1;
1063
1064    /**
1065     * Used as the {@code status} argument for {@link PackageManager#updateIntentVerificationStatus}
1066     * to indicate that the User will never be prompted the Intent Disambiguation Dialog if there
1067     * are two or more resolution of the Intent. The default App for the domain(s) specified in the
1068     * IntentFilter will also ALWAYS be used.
1069     *
1070     * @hide
1071     */
1072    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS = 2;
1073
1074    /**
1075     * Used as the {@code status} argument for {@link PackageManager#updateIntentVerificationStatus}
1076     * to indicate that the User may be prompted the Intent Disambiguation Dialog if there
1077     * are two or more Intent resolved. The default App for the domain(s) specified in the
1078     * IntentFilter will also NEVER be presented to the User.
1079     *
1080     * @hide
1081     */
1082    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER = 3;
1083
1084    /**
1085     * Used as the {@code status} argument for {@link PackageManager#updateIntentVerificationStatus}
1086     * to indicate that this app should always be considered as an ambiguous candidate for
1087     * handling the matching Intent even if there are other candidate apps in the "always"
1088     * state.  Put another way: if there are any 'always ask' apps in a set of more than
1089     * one candidate app, then a disambiguation is *always* presented even if there is
1090     * another candidate app with the 'always' state.
1091     *
1092     * @hide
1093     */
1094    public static final int INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK = 4;
1095
1096    /**
1097     * Can be used as the {@code millisecondsToDelay} argument for
1098     * {@link PackageManager#extendVerificationTimeout}. This is the
1099     * maximum time {@code PackageManager} waits for the verification
1100     * agent to return (in milliseconds).
1101     */
1102    public static final long MAXIMUM_VERIFICATION_TIMEOUT = 60*60*1000;
1103
1104    /**
1105     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: The device's
1106     * audio pipeline is low-latency, more suitable for audio applications sensitive to delays or
1107     * lag in sound input or output.
1108     */
1109    @SdkConstant(SdkConstantType.FEATURE)
1110    public static final String FEATURE_AUDIO_LOW_LATENCY = "android.hardware.audio.low_latency";
1111
1112    /**
1113     * Feature for {@link #getSystemAvailableFeatures} and
1114     * {@link #hasSystemFeature}: The device includes at least one form of audio
1115     * output, such as speakers, audio jack or streaming over bluetooth
1116     */
1117    @SdkConstant(SdkConstantType.FEATURE)
1118    public static final String FEATURE_AUDIO_OUTPUT = "android.hardware.audio.output";
1119
1120    /**
1121     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1122     * The device has professional audio level of functionality, performance, and acoustics.
1123     */
1124    @SdkConstant(SdkConstantType.FEATURE)
1125    public static final String FEATURE_AUDIO_PRO = "android.hardware.audio.pro";
1126
1127    /**
1128     * Feature for {@link #getSystemAvailableFeatures} and
1129     * {@link #hasSystemFeature}: The device is capable of communicating with
1130     * other devices via Bluetooth.
1131     */
1132    @SdkConstant(SdkConstantType.FEATURE)
1133    public static final String FEATURE_BLUETOOTH = "android.hardware.bluetooth";
1134
1135    /**
1136     * Feature for {@link #getSystemAvailableFeatures} and
1137     * {@link #hasSystemFeature}: The device is capable of communicating with
1138     * other devices via Bluetooth Low Energy radio.
1139     */
1140    @SdkConstant(SdkConstantType.FEATURE)
1141    public static final String FEATURE_BLUETOOTH_LE = "android.hardware.bluetooth_le";
1142
1143    /**
1144     * Feature for {@link #getSystemAvailableFeatures} and
1145     * {@link #hasSystemFeature}: The device has a camera facing away
1146     * from the screen.
1147     */
1148    @SdkConstant(SdkConstantType.FEATURE)
1149    public static final String FEATURE_CAMERA = "android.hardware.camera";
1150
1151    /**
1152     * Feature for {@link #getSystemAvailableFeatures} and
1153     * {@link #hasSystemFeature}: The device's camera supports auto-focus.
1154     */
1155    @SdkConstant(SdkConstantType.FEATURE)
1156    public static final String FEATURE_CAMERA_AUTOFOCUS = "android.hardware.camera.autofocus";
1157
1158    /**
1159     * Feature for {@link #getSystemAvailableFeatures} and
1160     * {@link #hasSystemFeature}: The device has at least one camera pointing in
1161     * some direction, or can support an external camera being connected to it.
1162     */
1163    @SdkConstant(SdkConstantType.FEATURE)
1164    public static final String FEATURE_CAMERA_ANY = "android.hardware.camera.any";
1165
1166    /**
1167     * Feature for {@link #getSystemAvailableFeatures} and
1168     * {@link #hasSystemFeature}: The device can support having an external camera connected to it.
1169     * The external camera may not always be connected or available to applications to use.
1170     */
1171    @SdkConstant(SdkConstantType.FEATURE)
1172    public static final String FEATURE_CAMERA_EXTERNAL = "android.hardware.camera.external";
1173
1174    /**
1175     * Feature for {@link #getSystemAvailableFeatures} and
1176     * {@link #hasSystemFeature}: The device's camera supports flash.
1177     */
1178    @SdkConstant(SdkConstantType.FEATURE)
1179    public static final String FEATURE_CAMERA_FLASH = "android.hardware.camera.flash";
1180
1181    /**
1182     * Feature for {@link #getSystemAvailableFeatures} and
1183     * {@link #hasSystemFeature}: The device has a front facing camera.
1184     */
1185    @SdkConstant(SdkConstantType.FEATURE)
1186    public static final String FEATURE_CAMERA_FRONT = "android.hardware.camera.front";
1187
1188    /**
1189     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1190     * of the cameras on the device supports the
1191     * {@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL full hardware}
1192     * capability level.
1193     */
1194    @SdkConstant(SdkConstantType.FEATURE)
1195    public static final String FEATURE_CAMERA_LEVEL_FULL = "android.hardware.camera.level.full";
1196
1197    /**
1198     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1199     * of the cameras on the device supports the
1200     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR manual sensor}
1201     * capability level.
1202     */
1203    @SdkConstant(SdkConstantType.FEATURE)
1204    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR =
1205            "android.hardware.camera.capability.manual_sensor";
1206
1207    /**
1208     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1209     * of the cameras on the device supports the
1210     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING manual post-processing}
1211     * capability level.
1212     */
1213    @SdkConstant(SdkConstantType.FEATURE)
1214    public static final String FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING =
1215            "android.hardware.camera.capability.manual_post_processing";
1216
1217    /**
1218     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}: At least one
1219     * of the cameras on the device supports the
1220     * {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}
1221     * capability level.
1222     */
1223    @SdkConstant(SdkConstantType.FEATURE)
1224    public static final String FEATURE_CAMERA_CAPABILITY_RAW =
1225            "android.hardware.camera.capability.raw";
1226
1227    /**
1228     * Feature for {@link #getSystemAvailableFeatures} and
1229     * {@link #hasSystemFeature}: The device is capable of communicating with
1230     * consumer IR devices.
1231     */
1232    @SdkConstant(SdkConstantType.FEATURE)
1233    public static final String FEATURE_CONSUMER_IR = "android.hardware.consumerir";
1234
1235    /**
1236     * Feature for {@link #getSystemAvailableFeatures} and
1237     * {@link #hasSystemFeature}: The device supports one or more methods of
1238     * reporting current location.
1239     */
1240    @SdkConstant(SdkConstantType.FEATURE)
1241    public static final String FEATURE_LOCATION = "android.hardware.location";
1242
1243    /**
1244     * Feature for {@link #getSystemAvailableFeatures} and
1245     * {@link #hasSystemFeature}: The device has a Global Positioning System
1246     * receiver and can report precise location.
1247     */
1248    @SdkConstant(SdkConstantType.FEATURE)
1249    public static final String FEATURE_LOCATION_GPS = "android.hardware.location.gps";
1250
1251    /**
1252     * Feature for {@link #getSystemAvailableFeatures} and
1253     * {@link #hasSystemFeature}: The device can report location with coarse
1254     * accuracy using a network-based geolocation system.
1255     */
1256    @SdkConstant(SdkConstantType.FEATURE)
1257    public static final String FEATURE_LOCATION_NETWORK = "android.hardware.location.network";
1258
1259    /**
1260     * Feature for {@link #getSystemAvailableFeatures} and
1261     * {@link #hasSystemFeature}: The device can record audio via a
1262     * microphone.
1263     */
1264    @SdkConstant(SdkConstantType.FEATURE)
1265    public static final String FEATURE_MICROPHONE = "android.hardware.microphone";
1266
1267    /**
1268     * Feature for {@link #getSystemAvailableFeatures} and
1269     * {@link #hasSystemFeature}: The device can communicate using Near-Field
1270     * Communications (NFC).
1271     */
1272    @SdkConstant(SdkConstantType.FEATURE)
1273    public static final String FEATURE_NFC = "android.hardware.nfc";
1274
1275    /**
1276     * Feature for {@link #getSystemAvailableFeatures} and
1277     * {@link #hasSystemFeature}: The device supports host-
1278     * based NFC card emulation.
1279     *
1280     * TODO remove when depending apps have moved to new constant.
1281     * @hide
1282     * @deprecated
1283     */
1284    @Deprecated
1285    @SdkConstant(SdkConstantType.FEATURE)
1286    public static final String FEATURE_NFC_HCE = "android.hardware.nfc.hce";
1287
1288    /**
1289     * Feature for {@link #getSystemAvailableFeatures} and
1290     * {@link #hasSystemFeature}: The device supports host-
1291     * based NFC card emulation.
1292     */
1293    @SdkConstant(SdkConstantType.FEATURE)
1294    public static final String FEATURE_NFC_HOST_CARD_EMULATION = "android.hardware.nfc.hce";
1295
1296    /**
1297     * Feature for {@link #getSystemAvailableFeatures} and
1298     * {@link #hasSystemFeature}: The device supports the OpenGL ES
1299     * <a href="http://www.khronos.org/registry/gles/extensions/ANDROID/ANDROID_extension_pack_es31a.txt">
1300     * Android Extension Pack</a>.
1301     */
1302    @SdkConstant(SdkConstantType.FEATURE)
1303    public static final String FEATURE_OPENGLES_EXTENSION_PACK = "android.hardware.opengles.aep";
1304
1305    /**
1306     * Feature for {@link #getSystemAvailableFeatures} and
1307     * {@link #hasSystemFeature}: The device includes an accelerometer.
1308     */
1309    @SdkConstant(SdkConstantType.FEATURE)
1310    public static final String FEATURE_SENSOR_ACCELEROMETER = "android.hardware.sensor.accelerometer";
1311
1312    /**
1313     * Feature for {@link #getSystemAvailableFeatures} and
1314     * {@link #hasSystemFeature}: The device includes a barometer (air
1315     * pressure sensor.)
1316     */
1317    @SdkConstant(SdkConstantType.FEATURE)
1318    public static final String FEATURE_SENSOR_BAROMETER = "android.hardware.sensor.barometer";
1319
1320    /**
1321     * Feature for {@link #getSystemAvailableFeatures} and
1322     * {@link #hasSystemFeature}: The device includes a magnetometer (compass).
1323     */
1324    @SdkConstant(SdkConstantType.FEATURE)
1325    public static final String FEATURE_SENSOR_COMPASS = "android.hardware.sensor.compass";
1326
1327    /**
1328     * Feature for {@link #getSystemAvailableFeatures} and
1329     * {@link #hasSystemFeature}: The device includes a gyroscope.
1330     */
1331    @SdkConstant(SdkConstantType.FEATURE)
1332    public static final String FEATURE_SENSOR_GYROSCOPE = "android.hardware.sensor.gyroscope";
1333
1334    /**
1335     * Feature for {@link #getSystemAvailableFeatures} and
1336     * {@link #hasSystemFeature}: The device includes a light sensor.
1337     */
1338    @SdkConstant(SdkConstantType.FEATURE)
1339    public static final String FEATURE_SENSOR_LIGHT = "android.hardware.sensor.light";
1340
1341    /**
1342     * Feature for {@link #getSystemAvailableFeatures} and
1343     * {@link #hasSystemFeature}: The device includes a proximity sensor.
1344     */
1345    @SdkConstant(SdkConstantType.FEATURE)
1346    public static final String FEATURE_SENSOR_PROXIMITY = "android.hardware.sensor.proximity";
1347
1348    /**
1349     * Feature for {@link #getSystemAvailableFeatures} and
1350     * {@link #hasSystemFeature}: The device includes a hardware step counter.
1351     */
1352    @SdkConstant(SdkConstantType.FEATURE)
1353    public static final String FEATURE_SENSOR_STEP_COUNTER = "android.hardware.sensor.stepcounter";
1354
1355    /**
1356     * Feature for {@link #getSystemAvailableFeatures} and
1357     * {@link #hasSystemFeature}: The device includes a hardware step detector.
1358     */
1359    @SdkConstant(SdkConstantType.FEATURE)
1360    public static final String FEATURE_SENSOR_STEP_DETECTOR = "android.hardware.sensor.stepdetector";
1361
1362    /**
1363     * Feature for {@link #getSystemAvailableFeatures} and
1364     * {@link #hasSystemFeature}: The device includes a heart rate monitor.
1365     */
1366    @SdkConstant(SdkConstantType.FEATURE)
1367    public static final String FEATURE_SENSOR_HEART_RATE = "android.hardware.sensor.heartrate";
1368
1369    /**
1370     * Feature for {@link #getSystemAvailableFeatures} and
1371     * {@link #hasSystemFeature}: The heart rate sensor on this device is an Electrocargiogram.
1372     */
1373    @SdkConstant(SdkConstantType.FEATURE)
1374    public static final String FEATURE_SENSOR_HEART_RATE_ECG =
1375            "android.hardware.sensor.heartrate.ecg";
1376
1377    /**
1378     * Feature for {@link #getSystemAvailableFeatures} and
1379     * {@link #hasSystemFeature}: The device includes a relative humidity sensor.
1380     */
1381    @SdkConstant(SdkConstantType.FEATURE)
1382    public static final String FEATURE_SENSOR_RELATIVE_HUMIDITY =
1383            "android.hardware.sensor.relative_humidity";
1384
1385    /**
1386     * Feature for {@link #getSystemAvailableFeatures} and
1387     * {@link #hasSystemFeature}: The device includes an ambient temperature sensor.
1388     */
1389    @SdkConstant(SdkConstantType.FEATURE)
1390    public static final String FEATURE_SENSOR_AMBIENT_TEMPERATURE =
1391            "android.hardware.sensor.ambient_temperature";
1392
1393    /**
1394     * Feature for {@link #getSystemAvailableFeatures} and
1395     * {@link #hasSystemFeature}: The device supports high fidelity sensor processing
1396     * capabilities.
1397     */
1398    @SdkConstant(SdkConstantType.FEATURE)
1399    public static final String FEATURE_HIFI_SENSORS =
1400            "android.hardware.sensor.hifi_sensors";
1401
1402    /**
1403     * Feature for {@link #getSystemAvailableFeatures} and
1404     * {@link #hasSystemFeature}: The device has a telephony radio with data
1405     * communication support.
1406     */
1407    @SdkConstant(SdkConstantType.FEATURE)
1408    public static final String FEATURE_TELEPHONY = "android.hardware.telephony";
1409
1410    /**
1411     * Feature for {@link #getSystemAvailableFeatures} and
1412     * {@link #hasSystemFeature}: The device has a CDMA telephony stack.
1413     */
1414    @SdkConstant(SdkConstantType.FEATURE)
1415    public static final String FEATURE_TELEPHONY_CDMA = "android.hardware.telephony.cdma";
1416
1417    /**
1418     * Feature for {@link #getSystemAvailableFeatures} and
1419     * {@link #hasSystemFeature}: The device has a GSM telephony stack.
1420     */
1421    @SdkConstant(SdkConstantType.FEATURE)
1422    public static final String FEATURE_TELEPHONY_GSM = "android.hardware.telephony.gsm";
1423
1424    /**
1425     * Feature for {@link #getSystemAvailableFeatures} and
1426     * {@link #hasSystemFeature}: The device supports connecting to USB devices
1427     * as the USB host.
1428     */
1429    @SdkConstant(SdkConstantType.FEATURE)
1430    public static final String FEATURE_USB_HOST = "android.hardware.usb.host";
1431
1432    /**
1433     * Feature for {@link #getSystemAvailableFeatures} and
1434     * {@link #hasSystemFeature}: The device supports connecting to USB accessories.
1435     */
1436    @SdkConstant(SdkConstantType.FEATURE)
1437    public static final String FEATURE_USB_ACCESSORY = "android.hardware.usb.accessory";
1438
1439    /**
1440     * Feature for {@link #getSystemAvailableFeatures} and
1441     * {@link #hasSystemFeature}: The SIP API is enabled on the device.
1442     */
1443    @SdkConstant(SdkConstantType.FEATURE)
1444    public static final String FEATURE_SIP = "android.software.sip";
1445
1446    /**
1447     * Feature for {@link #getSystemAvailableFeatures} and
1448     * {@link #hasSystemFeature}: The device supports SIP-based VOIP.
1449     */
1450    @SdkConstant(SdkConstantType.FEATURE)
1451    public static final String FEATURE_SIP_VOIP = "android.software.sip.voip";
1452
1453    /**
1454     * Feature for {@link #getSystemAvailableFeatures} and
1455     * {@link #hasSystemFeature}: The Connection Service API is enabled on the device.
1456     */
1457    @SdkConstant(SdkConstantType.FEATURE)
1458    public static final String FEATURE_CONNECTION_SERVICE = "android.software.connectionservice";
1459
1460    /**
1461     * Feature for {@link #getSystemAvailableFeatures} and
1462     * {@link #hasSystemFeature}: The device's display has a touch screen.
1463     */
1464    @SdkConstant(SdkConstantType.FEATURE)
1465    public static final String FEATURE_TOUCHSCREEN = "android.hardware.touchscreen";
1466
1467    /**
1468     * Feature for {@link #getSystemAvailableFeatures} and
1469     * {@link #hasSystemFeature}: The device's touch screen supports
1470     * multitouch sufficient for basic two-finger gesture detection.
1471     */
1472    @SdkConstant(SdkConstantType.FEATURE)
1473    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH = "android.hardware.touchscreen.multitouch";
1474
1475    /**
1476     * Feature for {@link #getSystemAvailableFeatures} and
1477     * {@link #hasSystemFeature}: The device's touch screen is capable of
1478     * tracking two or more fingers fully independently.
1479     */
1480    @SdkConstant(SdkConstantType.FEATURE)
1481    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT = "android.hardware.touchscreen.multitouch.distinct";
1482
1483    /**
1484     * Feature for {@link #getSystemAvailableFeatures} and
1485     * {@link #hasSystemFeature}: The device's touch screen is capable of
1486     * tracking a full hand of fingers fully independently -- that is, 5 or
1487     * more simultaneous independent pointers.
1488     */
1489    @SdkConstant(SdkConstantType.FEATURE)
1490    public static final String FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND = "android.hardware.touchscreen.multitouch.jazzhand";
1491
1492    /**
1493     * Feature for {@link #getSystemAvailableFeatures} and
1494     * {@link #hasSystemFeature}: The device does not have a touch screen, but
1495     * does support touch emulation for basic events. For instance, the
1496     * device might use a mouse or remote control to drive a cursor, and
1497     * emulate basic touch pointer events like down, up, drag, etc. All
1498     * devices that support android.hardware.touchscreen or a sub-feature are
1499     * presumed to also support faketouch.
1500     */
1501    @SdkConstant(SdkConstantType.FEATURE)
1502    public static final String FEATURE_FAKETOUCH = "android.hardware.faketouch";
1503
1504    /**
1505     * Feature for {@link #getSystemAvailableFeatures} and
1506     * {@link #hasSystemFeature}: The device does not have a touch screen, but
1507     * does support touch emulation for basic events that supports distinct
1508     * tracking of two or more fingers.  This is an extension of
1509     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
1510     * that unlike a distinct multitouch screen as defined by
1511     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT}, these kinds of input
1512     * devices will not actually provide full two-finger gestures since the
1513     * input is being transformed to cursor movement on the screen.  That is,
1514     * single finger gestures will move a cursor; two-finger swipes will
1515     * result in single-finger touch events; other two-finger gestures will
1516     * result in the corresponding two-finger touch event.
1517     */
1518    @SdkConstant(SdkConstantType.FEATURE)
1519    public static final String FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT = "android.hardware.faketouch.multitouch.distinct";
1520
1521    /**
1522     * Feature for {@link #getSystemAvailableFeatures} and
1523     * {@link #hasSystemFeature}: The device does not have a touch screen, but
1524     * does support touch emulation for basic events that supports tracking
1525     * a hand of fingers (5 or more fingers) fully independently.
1526     * This is an extension of
1527     * {@link #FEATURE_FAKETOUCH} for input devices with this capability.  Note
1528     * that unlike a multitouch screen as defined by
1529     * {@link #FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND}, not all two finger
1530     * gestures can be detected due to the limitations described for
1531     * {@link #FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT}.
1532     */
1533    @SdkConstant(SdkConstantType.FEATURE)
1534    public static final String FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND = "android.hardware.faketouch.multitouch.jazzhand";
1535
1536    /**
1537     * Feature for {@link #getSystemAvailableFeatures} and
1538     * {@link #hasSystemFeature}: The device has biometric hardware to detect a fingerprint.
1539      */
1540    @SdkConstant(SdkConstantType.FEATURE)
1541    public static final String FEATURE_FINGERPRINT = "android.hardware.fingerprint";
1542
1543    /**
1544     * Feature for {@link #getSystemAvailableFeatures} and
1545     * {@link #hasSystemFeature}: The device supports portrait orientation
1546     * screens.  For backwards compatibility, you can assume that if neither
1547     * this nor {@link #FEATURE_SCREEN_LANDSCAPE} is set then the device supports
1548     * both portrait and landscape.
1549     */
1550    @SdkConstant(SdkConstantType.FEATURE)
1551    public static final String FEATURE_SCREEN_PORTRAIT = "android.hardware.screen.portrait";
1552
1553    /**
1554     * Feature for {@link #getSystemAvailableFeatures} and
1555     * {@link #hasSystemFeature}: The device supports landscape orientation
1556     * screens.  For backwards compatibility, you can assume that if neither
1557     * this nor {@link #FEATURE_SCREEN_PORTRAIT} is set then the device supports
1558     * both portrait and landscape.
1559     */
1560    @SdkConstant(SdkConstantType.FEATURE)
1561    public static final String FEATURE_SCREEN_LANDSCAPE = "android.hardware.screen.landscape";
1562
1563    /**
1564     * Feature for {@link #getSystemAvailableFeatures} and
1565     * {@link #hasSystemFeature}: The device supports live wallpapers.
1566     */
1567    @SdkConstant(SdkConstantType.FEATURE)
1568    public static final String FEATURE_LIVE_WALLPAPER = "android.software.live_wallpaper";
1569    /**
1570     * Feature for {@link #getSystemAvailableFeatures} and
1571     * {@link #hasSystemFeature}: The device supports app widgets.
1572     */
1573    @SdkConstant(SdkConstantType.FEATURE)
1574    public static final String FEATURE_APP_WIDGETS = "android.software.app_widgets";
1575
1576    /**
1577     * @hide
1578     * Feature for {@link #getSystemAvailableFeatures} and
1579     * {@link #hasSystemFeature}: The device supports
1580     * {@link android.service.voice.VoiceInteractionService} and
1581     * {@link android.app.VoiceInteractor}.
1582     */
1583    @SdkConstant(SdkConstantType.FEATURE)
1584    public static final String FEATURE_VOICE_RECOGNIZERS = "android.software.voice_recognizers";
1585
1586
1587    /**
1588     * Feature for {@link #getSystemAvailableFeatures} and
1589     * {@link #hasSystemFeature}: The device supports a home screen that is replaceable
1590     * by third party applications.
1591     */
1592    @SdkConstant(SdkConstantType.FEATURE)
1593    public static final String FEATURE_HOME_SCREEN = "android.software.home_screen";
1594
1595    /**
1596     * Feature for {@link #getSystemAvailableFeatures} and
1597     * {@link #hasSystemFeature}: The device supports adding new input methods implemented
1598     * with the {@link android.inputmethodservice.InputMethodService} API.
1599     */
1600    @SdkConstant(SdkConstantType.FEATURE)
1601    public static final String FEATURE_INPUT_METHODS = "android.software.input_methods";
1602
1603    /**
1604     * Feature for {@link #getSystemAvailableFeatures} and
1605     * {@link #hasSystemFeature}: The device supports device policy enforcement via device admins.
1606     */
1607    @SdkConstant(SdkConstantType.FEATURE)
1608    public static final String FEATURE_DEVICE_ADMIN = "android.software.device_admin";
1609
1610    /**
1611     * Feature for {@link #getSystemAvailableFeatures} and
1612     * {@link #hasSystemFeature}: The device supports leanback UI. This is
1613     * typically used in a living room television experience, but is a software
1614     * feature unlike {@link #FEATURE_TELEVISION}. Devices running with this
1615     * feature will use resources associated with the "television" UI mode.
1616     */
1617    @SdkConstant(SdkConstantType.FEATURE)
1618    public static final String FEATURE_LEANBACK = "android.software.leanback";
1619
1620    /**
1621     * Feature for {@link #getSystemAvailableFeatures} and
1622     * {@link #hasSystemFeature}: The device supports only leanback UI. Only
1623     * applications designed for this experience should be run, though this is
1624     * not enforced by the system.
1625     * @hide
1626     */
1627    @SdkConstant(SdkConstantType.FEATURE)
1628    public static final String FEATURE_LEANBACK_ONLY = "android.software.leanback_only";
1629
1630    /**
1631     * Feature for {@link #getSystemAvailableFeatures} and
1632     * {@link #hasSystemFeature}: The device supports live TV and can display
1633     * contents from TV inputs implemented with the
1634     * {@link android.media.tv.TvInputService} API.
1635     */
1636    @SdkConstant(SdkConstantType.FEATURE)
1637    public static final String FEATURE_LIVE_TV = "android.software.live_tv";
1638
1639    /**
1640     * Feature for {@link #getSystemAvailableFeatures} and
1641     * {@link #hasSystemFeature}: The device supports WiFi (802.11) networking.
1642     */
1643    @SdkConstant(SdkConstantType.FEATURE)
1644    public static final String FEATURE_WIFI = "android.hardware.wifi";
1645
1646    /**
1647     * Feature for {@link #getSystemAvailableFeatures} and
1648     * {@link #hasSystemFeature}: The device supports Wi-Fi Direct networking.
1649     */
1650    @SdkConstant(SdkConstantType.FEATURE)
1651    public static final String FEATURE_WIFI_DIRECT = "android.hardware.wifi.direct";
1652
1653    /**
1654     * Feature for {@link #getSystemAvailableFeatures} and
1655     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
1656     * on a vehicle headunit. A headunit here is defined to be inside a
1657     * vehicle that may or may not be moving. A headunit uses either a
1658     * primary display in the center console and/or additional displays in
1659     * the instrument cluster or elsewhere in the vehicle. Headunit display(s)
1660     * have limited size and resolution. The user will likely be focused on
1661     * driving so limiting driver distraction is a primary concern. User input
1662     * can be a variety of hard buttons, touch, rotary controllers and even mouse-
1663     * like interfaces.
1664     */
1665    @SdkConstant(SdkConstantType.FEATURE)
1666    public static final String FEATURE_AUTOMOTIVE = "android.hardware.type.automotive";
1667
1668    /**
1669     * Feature for {@link #getSystemAvailableFeatures} and
1670     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
1671     * on a television.  Television here is defined to be a typical living
1672     * room television experience: displayed on a big screen, where the user
1673     * is sitting far away from it, and the dominant form of input will be
1674     * something like a DPAD, not through touch or mouse.
1675     * @deprecated use {@link #FEATURE_LEANBACK} instead.
1676     */
1677    @Deprecated
1678    @SdkConstant(SdkConstantType.FEATURE)
1679    public static final String FEATURE_TELEVISION = "android.hardware.type.television";
1680
1681    /**
1682     * Feature for {@link #getSystemAvailableFeatures} and
1683     * {@link #hasSystemFeature}: This is a device dedicated to showing UI
1684     * on a watch. A watch here is defined to be a device worn on the body, perhaps on
1685     * the wrist. The user is very close when interacting with the device.
1686     */
1687    @SdkConstant(SdkConstantType.FEATURE)
1688    public static final String FEATURE_WATCH = "android.hardware.type.watch";
1689
1690    /**
1691     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1692     * The device supports printing.
1693     */
1694    @SdkConstant(SdkConstantType.FEATURE)
1695    public static final String FEATURE_PRINTING = "android.software.print";
1696
1697    /**
1698     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1699     * The device can perform backup and restore operations on installed applications.
1700     */
1701    @SdkConstant(SdkConstantType.FEATURE)
1702    public static final String FEATURE_BACKUP = "android.software.backup";
1703
1704    /**
1705     * Feature for {@link #getSystemAvailableFeatures} and
1706     * {@link #hasSystemFeature}: The device supports freeform window management.
1707     * Windows have title bars and can be moved and resized.
1708     */
1709    @SdkConstant(SdkConstantType.FEATURE)
1710    public static final String FEATURE_FREEFORM_WINDOW_MANAGEMENT
1711            = "android.software.freeform_window_management";
1712
1713    /**
1714     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1715     * The device supports creating secondary users and managed profiles via
1716     * {@link DevicePolicyManager}.
1717     */
1718    @SdkConstant(SdkConstantType.FEATURE)
1719    public static final String FEATURE_MANAGED_USERS = "android.software.managed_users";
1720
1721    /**
1722     * @hide
1723     * TODO: Remove after dependencies updated b/17392243
1724     */
1725    public static final String FEATURE_MANAGED_PROFILES = "android.software.managed_users";
1726
1727    /**
1728     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1729     * The device supports verified boot.
1730     */
1731    @SdkConstant(SdkConstantType.FEATURE)
1732    public static final String FEATURE_VERIFIED_BOOT = "android.software.verified_boot";
1733
1734    /**
1735     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1736     * The device supports secure removal of users. When a user is deleted the data associated
1737     * with that user is securely deleted and no longer available.
1738     */
1739    @SdkConstant(SdkConstantType.FEATURE)
1740    public static final String FEATURE_SECURELY_REMOVES_USERS
1741            = "android.software.securely_removes_users";
1742
1743    /**
1744     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1745     * The device has a full implementation of the android.webkit.* APIs. Devices
1746     * lacking this feature will not have a functioning WebView implementation.
1747     */
1748    @SdkConstant(SdkConstantType.FEATURE)
1749    public static final String FEATURE_WEBVIEW = "android.software.webview";
1750
1751    /**
1752     * Feature for {@link #getSystemAvailableFeatures} and
1753     * {@link #hasSystemFeature}: This device supports ethernet.
1754     * @hide
1755     */
1756    @SdkConstant(SdkConstantType.FEATURE)
1757    public static final String FEATURE_ETHERNET = "android.hardware.ethernet";
1758
1759    /**
1760     * Feature for {@link #getSystemAvailableFeatures} and
1761     * {@link #hasSystemFeature}: This device supports HDMI-CEC.
1762     * @hide
1763     */
1764    @SdkConstant(SdkConstantType.FEATURE)
1765    public static final String FEATURE_HDMI_CEC = "android.hardware.hdmi.cec";
1766
1767    /**
1768     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1769     * The device has all of the inputs necessary to be considered a compatible game controller, or
1770     * includes a compatible game controller in the box.
1771     */
1772    @SdkConstant(SdkConstantType.FEATURE)
1773    public static final String FEATURE_GAMEPAD = "android.hardware.gamepad";
1774
1775    /**
1776     * Feature for {@link #getSystemAvailableFeatures} and {@link #hasSystemFeature}:
1777     * The device has a full implementation of the android.media.midi.* APIs.
1778     */
1779    @SdkConstant(SdkConstantType.FEATURE)
1780    public static final String FEATURE_MIDI = "android.software.midi";
1781
1782    /**
1783     * Action to external storage service to clean out removed apps.
1784     * @hide
1785     */
1786    public static final String ACTION_CLEAN_EXTERNAL_STORAGE
1787            = "android.content.pm.CLEAN_EXTERNAL_STORAGE";
1788
1789    /**
1790     * Extra field name for the URI to a verification file. Passed to a package
1791     * verifier.
1792     *
1793     * @hide
1794     */
1795    public static final String EXTRA_VERIFICATION_URI = "android.content.pm.extra.VERIFICATION_URI";
1796
1797    /**
1798     * Extra field name for the ID of a package pending verification. Passed to
1799     * a package verifier and is used to call back to
1800     * {@link PackageManager#verifyPendingInstall(int, int)}
1801     */
1802    public static final String EXTRA_VERIFICATION_ID = "android.content.pm.extra.VERIFICATION_ID";
1803
1804    /**
1805     * Extra field name for the package identifier which is trying to install
1806     * the package.
1807     *
1808     * @hide
1809     */
1810    public static final String EXTRA_VERIFICATION_INSTALLER_PACKAGE
1811            = "android.content.pm.extra.VERIFICATION_INSTALLER_PACKAGE";
1812
1813    /**
1814     * Extra field name for the requested install flags for a package pending
1815     * verification. Passed to a package verifier.
1816     *
1817     * @hide
1818     */
1819    public static final String EXTRA_VERIFICATION_INSTALL_FLAGS
1820            = "android.content.pm.extra.VERIFICATION_INSTALL_FLAGS";
1821
1822    /**
1823     * Extra field name for the uid of who is requesting to install
1824     * the package.
1825     *
1826     * @hide
1827     */
1828    public static final String EXTRA_VERIFICATION_INSTALLER_UID
1829            = "android.content.pm.extra.VERIFICATION_INSTALLER_UID";
1830
1831    /**
1832     * Extra field name for the package name of a package pending verification.
1833     *
1834     * @hide
1835     */
1836    public static final String EXTRA_VERIFICATION_PACKAGE_NAME
1837            = "android.content.pm.extra.VERIFICATION_PACKAGE_NAME";
1838    /**
1839     * Extra field name for the result of a verification, either
1840     * {@link #VERIFICATION_ALLOW}, or {@link #VERIFICATION_REJECT}.
1841     * Passed to package verifiers after a package is verified.
1842     */
1843    public static final String EXTRA_VERIFICATION_RESULT
1844            = "android.content.pm.extra.VERIFICATION_RESULT";
1845
1846    /**
1847     * Extra field name for the version code of a package pending verification.
1848     *
1849     * @hide
1850     */
1851    public static final String EXTRA_VERIFICATION_VERSION_CODE
1852            = "android.content.pm.extra.VERIFICATION_VERSION_CODE";
1853
1854    /**
1855     * Extra field name for the ID of a intent filter pending verification. Passed to
1856     * an intent filter verifier and is used to call back to
1857     * {@link PackageManager#verifyIntentFilter(int, int)}
1858     *
1859     * @hide
1860     */
1861    public static final String EXTRA_INTENT_FILTER_VERIFICATION_ID
1862            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_ID";
1863
1864    /**
1865     * Extra field name for the scheme used for an intent filter pending verification. Passed to
1866     * an intent filter verifier and is used to construct the URI to verify against.
1867     *
1868     * Usually this is "https"
1869     *
1870     * @hide
1871     */
1872    public static final String EXTRA_INTENT_FILTER_VERIFICATION_URI_SCHEME
1873            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_URI_SCHEME";
1874
1875    /**
1876     * Extra field name for the host names to be used for an intent filter pending verification.
1877     * Passed to an intent filter verifier and is used to construct the URI to verify the
1878     * intent filter.
1879     *
1880     * This is a space delimited list of hosts.
1881     *
1882     * @hide
1883     */
1884    public static final String EXTRA_INTENT_FILTER_VERIFICATION_HOSTS
1885            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_HOSTS";
1886
1887    /**
1888     * Extra field name for the package name to be used for an intent filter pending verification.
1889     * Passed to an intent filter verifier and is used to check the verification responses coming
1890     * from the hosts. Each host response will need to include the package name of APK containing
1891     * the intent filter.
1892     *
1893     * @hide
1894     */
1895    public static final String EXTRA_INTENT_FILTER_VERIFICATION_PACKAGE_NAME
1896            = "android.content.pm.extra.INTENT_FILTER_VERIFICATION_PACKAGE_NAME";
1897
1898    /**
1899     * The action used to request that the user approve a permission request
1900     * from the application.
1901     *
1902     * @hide
1903     */
1904    @SystemApi
1905    public static final String ACTION_REQUEST_PERMISSIONS =
1906            "android.content.pm.action.REQUEST_PERMISSIONS";
1907
1908    /**
1909     * The names of the requested permissions.
1910     * <p>
1911     * <strong>Type:</strong> String[]
1912     * </p>
1913     *
1914     * @hide
1915     */
1916    @SystemApi
1917    public static final String EXTRA_REQUEST_PERMISSIONS_NAMES =
1918            "android.content.pm.extra.REQUEST_PERMISSIONS_NAMES";
1919
1920    /**
1921     * The results from the permissions request.
1922     * <p>
1923     * <strong>Type:</strong> int[] of #PermissionResult
1924     * </p>
1925     *
1926     * @hide
1927     */
1928    @SystemApi
1929    public static final String EXTRA_REQUEST_PERMISSIONS_RESULTS
1930            = "android.content.pm.extra.REQUEST_PERMISSIONS_RESULTS";
1931
1932    /**
1933     * String extra for {@link PackageInstallObserver} in the 'extras' Bundle in case of
1934     * {@link #INSTALL_FAILED_DUPLICATE_PERMISSION}.  This extra names the package which provides
1935     * the existing definition for the permission.
1936     * @hide
1937     */
1938    public static final String EXTRA_FAILURE_EXISTING_PACKAGE
1939            = "android.content.pm.extra.FAILURE_EXISTING_PACKAGE";
1940
1941    /**
1942     * String extra for {@link PackageInstallObserver} in the 'extras' Bundle in case of
1943     * {@link #INSTALL_FAILED_DUPLICATE_PERMISSION}.  This extra names the permission that is
1944     * being redundantly defined by the package being installed.
1945     * @hide
1946     */
1947    public static final String EXTRA_FAILURE_EXISTING_PERMISSION
1948            = "android.content.pm.extra.FAILURE_EXISTING_PERMISSION";
1949
1950   /**
1951    * Permission flag: The permission is set in its current state
1952    * by the user and apps can still request it at runtime.
1953    *
1954    * @hide
1955    */
1956    public static final int FLAG_PERMISSION_USER_SET = 1 << 0;
1957
1958    /**
1959     * Permission flag: The permission is set in its current state
1960     * by the user and it is fixed, i.e. apps can no longer request
1961     * this permission.
1962     *
1963     * @hide
1964     */
1965    public static final int FLAG_PERMISSION_USER_FIXED =  1 << 1;
1966
1967    /**
1968     * Permission flag: The permission is set in its current state
1969     * by device policy and neither apps nor the user can change
1970     * its state.
1971     *
1972     * @hide
1973     */
1974    public static final int FLAG_PERMISSION_POLICY_FIXED =  1 << 2;
1975
1976    /**
1977     * Permission flag: The permission is set in a granted state but
1978     * access to resources it guards is restricted by other means to
1979     * enable revoking a permission on legacy apps that do not support
1980     * runtime permissions. If this permission is upgraded to runtime
1981     * because the app was updated to support runtime permissions, the
1982     * the permission will be revoked in the upgrade process.
1983     *
1984     * @hide
1985     */
1986    public static final int FLAG_PERMISSION_REVOKE_ON_UPGRADE =  1 << 3;
1987
1988    /**
1989     * Permission flag: The permission is set in its current state
1990     * because the app is a component that is a part of the system.
1991     *
1992     * @hide
1993     */
1994    public static final int FLAG_PERMISSION_SYSTEM_FIXED =  1 << 4;
1995
1996
1997    /**
1998     * Permission flag: The permission is granted by default because it
1999     * enables app functionality that is expected to work out-of-the-box
2000     * for providing a smooth user experience. For example, the phone app
2001     * is expected to have the phone permission.
2002     *
2003     * @hide
2004     */
2005    public static final int FLAG_PERMISSION_GRANTED_BY_DEFAULT =  1 << 5;
2006
2007    /**
2008     * Mask for all permission flags.
2009     *
2010     * @hide
2011     */
2012    @SystemApi
2013    public static final int MASK_PERMISSION_FLAGS = 0xFF;
2014
2015    /**
2016     * Retrieve overall information about an application package that is
2017     * installed on the system.
2018     * <p>
2019     * Throws {@link NameNotFoundException} if a package with the given name can
2020     * not be found on the system.
2021     *
2022     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2023     *            desired package.
2024     * @param flags Additional option flags. Use any combination of
2025     *            {@link #GET_ACTIVITIES}, {@link #GET_GIDS},
2026     *            {@link #GET_CONFIGURATIONS}, {@link #GET_INSTRUMENTATION},
2027     *            {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
2028     *            {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
2029     *            {@link #GET_SIGNATURES}, {@link #GET_UNINSTALLED_PACKAGES} to
2030     *            modify the data returned.
2031     * @return A PackageInfo object containing information about the
2032     *         package. If flag GET_UNINSTALLED_PACKAGES is set and if the
2033     *         package is not found in the list of installed applications, the
2034     *         package information is retrieved from the list of uninstalled
2035     *         applications (which includes installed applications as well as
2036     *         applications with data directory i.e. applications which had been
2037     *         deleted with {@code DONT_DELETE_DATA} flag set).
2038     * @see #GET_ACTIVITIES
2039     * @see #GET_GIDS
2040     * @see #GET_CONFIGURATIONS
2041     * @see #GET_INSTRUMENTATION
2042     * @see #GET_PERMISSIONS
2043     * @see #GET_PROVIDERS
2044     * @see #GET_RECEIVERS
2045     * @see #GET_SERVICES
2046     * @see #GET_SIGNATURES
2047     * @see #GET_UNINSTALLED_PACKAGES
2048     */
2049    public abstract PackageInfo getPackageInfo(String packageName, int flags)
2050            throws NameNotFoundException;
2051
2052    /**
2053     * @hide
2054     * Retrieve overall information about an application package that is
2055     * installed on the system.
2056     * <p>
2057     * Throws {@link NameNotFoundException} if a package with the given name can
2058     * not be found on the system.
2059     *
2060     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2061     *            desired package.
2062     * @param flags Additional option flags. Use any combination of
2063     *            {@link #GET_ACTIVITIES}, {@link #GET_GIDS},
2064     *            {@link #GET_CONFIGURATIONS}, {@link #GET_INSTRUMENTATION},
2065     *            {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
2066     *            {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
2067     *            {@link #GET_SIGNATURES}, {@link #GET_UNINSTALLED_PACKAGES} to
2068     *            modify the data returned.
2069     * @param userId The user id.
2070     * @return A PackageInfo object containing information about the
2071     *         package. If flag GET_UNINSTALLED_PACKAGES is set and if the
2072     *         package is not found in the list of installed applications, the
2073     *         package information is retrieved from the list of uninstalled
2074     *         applications (which includes installed applications as well as
2075     *         applications with data directory i.e. applications which had been
2076     *         deleted with {@code DONT_DELETE_DATA} flag set).
2077     * @see #GET_ACTIVITIES
2078     * @see #GET_GIDS
2079     * @see #GET_CONFIGURATIONS
2080     * @see #GET_INSTRUMENTATION
2081     * @see #GET_PERMISSIONS
2082     * @see #GET_PROVIDERS
2083     * @see #GET_RECEIVERS
2084     * @see #GET_SERVICES
2085     * @see #GET_SIGNATURES
2086     * @see #GET_UNINSTALLED_PACKAGES
2087     */
2088    @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS)
2089    public abstract PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
2090            throws NameNotFoundException;
2091
2092    /**
2093     * Map from the current package names in use on the device to whatever
2094     * the current canonical name of that package is.
2095     * @param names Array of current names to be mapped.
2096     * @return Returns an array of the same size as the original, containing
2097     * the canonical name for each package.
2098     */
2099    public abstract String[] currentToCanonicalPackageNames(String[] names);
2100
2101    /**
2102     * Map from a packages canonical name to the current name in use on the device.
2103     * @param names Array of new names to be mapped.
2104     * @return Returns an array of the same size as the original, containing
2105     * the current name for each package.
2106     */
2107    public abstract String[] canonicalToCurrentPackageNames(String[] names);
2108
2109    /**
2110     * Returns a "good" intent to launch a front-door activity in a package.
2111     * This is used, for example, to implement an "open" button when browsing
2112     * through packages.  The current implementation looks first for a main
2113     * activity in the category {@link Intent#CATEGORY_INFO}, and next for a
2114     * main activity in the category {@link Intent#CATEGORY_LAUNCHER}. Returns
2115     * <code>null</code> if neither are found.
2116     *
2117     * @param packageName The name of the package to inspect.
2118     *
2119     * @return A fully-qualified {@link Intent} that can be used to launch the
2120     * main activity in the package. Returns <code>null</code> if the package
2121     * does not contain such an activity, or if <em>packageName</em> is not
2122     * recognized.
2123     */
2124    public abstract Intent getLaunchIntentForPackage(String packageName);
2125
2126    /**
2127     * Return a "good" intent to launch a front-door Leanback activity in a
2128     * package, for use for example to implement an "open" button when browsing
2129     * through packages. The current implementation will look for a main
2130     * activity in the category {@link Intent#CATEGORY_LEANBACK_LAUNCHER}, or
2131     * return null if no main leanback activities are found.
2132     * <p>
2133     * Throws {@link NameNotFoundException} if a package with the given name
2134     * cannot be found on the system.
2135     *
2136     * @param packageName The name of the package to inspect.
2137     * @return Returns either a fully-qualified Intent that can be used to launch
2138     *         the main Leanback activity in the package, or null if the package
2139     *         does not contain such an activity.
2140     */
2141    public abstract Intent getLeanbackLaunchIntentForPackage(String packageName);
2142
2143    /**
2144     * Return an array of all of the secondary group-ids that have been assigned
2145     * to a package.
2146     * <p>
2147     * Throws {@link NameNotFoundException} if a package with the given name
2148     * cannot be found on the system.
2149     *
2150     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2151     *            desired package.
2152     * @return Returns an int array of the assigned gids, or null if there are
2153     *         none.
2154     */
2155    public abstract int[] getPackageGids(String packageName)
2156            throws NameNotFoundException;
2157
2158    /**
2159     * @hide Return the uid associated with the given package name for the
2160     * given user.
2161     *
2162     * <p>Throws {@link NameNotFoundException} if a package with the given
2163     * name can not be found on the system.
2164     *
2165     * @param packageName The full name (i.e. com.google.apps.contacts) of the
2166     *                    desired package.
2167     * @param userHandle The user handle identifier to look up the package under.
2168     *
2169     * @return Returns an integer uid who owns the given package name.
2170     */
2171    public abstract int getPackageUid(String packageName, int userHandle)
2172            throws NameNotFoundException;
2173
2174    /**
2175     * Retrieve all of the information we know about a particular permission.
2176     *
2177     * <p>Throws {@link NameNotFoundException} if a permission with the given
2178     * name cannot be found on the system.
2179     *
2180     * @param name The fully qualified name (i.e. com.google.permission.LOGIN)
2181     *             of the permission you are interested in.
2182     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
2183     * retrieve any meta-data associated with the permission.
2184     *
2185     * @return Returns a {@link PermissionInfo} containing information about the
2186     *         permission.
2187     */
2188    public abstract PermissionInfo getPermissionInfo(String name, int flags)
2189            throws NameNotFoundException;
2190
2191    /**
2192     * Query for all of the permissions associated with a particular group.
2193     *
2194     * <p>Throws {@link NameNotFoundException} if the given group does not
2195     * exist.
2196     *
2197     * @param group The fully qualified name (i.e. com.google.permission.LOGIN)
2198     *             of the permission group you are interested in.  Use null to
2199     *             find all of the permissions not associated with a group.
2200     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
2201     * retrieve any meta-data associated with the permissions.
2202     *
2203     * @return Returns a list of {@link PermissionInfo} containing information
2204     * about all of the permissions in the given group.
2205     */
2206    public abstract List<PermissionInfo> queryPermissionsByGroup(String group,
2207            int flags) throws NameNotFoundException;
2208
2209    /**
2210     * Retrieve all of the information we know about a particular group of
2211     * permissions.
2212     *
2213     * <p>Throws {@link NameNotFoundException} if a permission group with the given
2214     * name cannot be found on the system.
2215     *
2216     * @param name The fully qualified name (i.e. com.google.permission_group.APPS)
2217     *             of the permission you are interested in.
2218     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
2219     * retrieve any meta-data associated with the permission group.
2220     *
2221     * @return Returns a {@link PermissionGroupInfo} containing information
2222     * about the permission.
2223     */
2224    public abstract PermissionGroupInfo getPermissionGroupInfo(String name,
2225            int flags) throws NameNotFoundException;
2226
2227    /**
2228     * Retrieve all of the known permission groups in the system.
2229     *
2230     * @param flags Additional option flags.  Use {@link #GET_META_DATA} to
2231     * retrieve any meta-data associated with the permission group.
2232     *
2233     * @return Returns a list of {@link PermissionGroupInfo} containing
2234     * information about all of the known permission groups.
2235     */
2236    public abstract List<PermissionGroupInfo> getAllPermissionGroups(int flags);
2237
2238    /**
2239     * Retrieve all of the information we know about a particular
2240     * package/application.
2241     *
2242     * <p>Throws {@link NameNotFoundException} if an application with the given
2243     * package name cannot be found on the system.
2244     *
2245     * @param packageName The full name (i.e. com.google.apps.contacts) of an
2246     *                    application.
2247     * @param flags Additional option flags. Use any combination of
2248     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
2249     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2250     *
2251     * @return  {@link ApplicationInfo} Returns ApplicationInfo object containing
2252     *         information about the package.
2253     *         If flag GET_UNINSTALLED_PACKAGES is set and  if the package is not
2254     *         found in the list of installed applications,
2255     *         the application information is retrieved from the
2256     *         list of uninstalled applications(which includes
2257     *         installed applications as well as applications
2258     *         with data directory ie applications which had been
2259     *         deleted with {@code DONT_DELETE_DATA} flag set).
2260     *
2261     * @see #GET_META_DATA
2262     * @see #GET_SHARED_LIBRARY_FILES
2263     * @see #GET_UNINSTALLED_PACKAGES
2264     */
2265    public abstract ApplicationInfo getApplicationInfo(String packageName,
2266            int flags) throws NameNotFoundException;
2267
2268    /**
2269     * Retrieve all of the information we know about a particular activity
2270     * class.
2271     *
2272     * <p>Throws {@link NameNotFoundException} if an activity with the given
2273     * class name cannot be found on the system.
2274     *
2275     * @param component The full component name (i.e.
2276     * com.google.apps.contacts/com.google.apps.contacts.ContactsList) of an Activity
2277     * class.
2278     * @param flags Additional option flags. Use any combination of
2279     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
2280     * to modify the data (in ApplicationInfo) returned.
2281     *
2282     * @return {@link ActivityInfo} containing information about the activity.
2283     *
2284     * @see #GET_INTENT_FILTERS
2285     * @see #GET_META_DATA
2286     * @see #GET_SHARED_LIBRARY_FILES
2287     */
2288    public abstract ActivityInfo getActivityInfo(ComponentName component,
2289            int flags) throws NameNotFoundException;
2290
2291    /**
2292     * Retrieve all of the information we know about a particular receiver
2293     * class.
2294     *
2295     * <p>Throws {@link NameNotFoundException} if a receiver with the given
2296     * class name cannot be found on the system.
2297     *
2298     * @param component The full component name (i.e.
2299     * com.google.apps.calendar/com.google.apps.calendar.CalendarAlarm) of a Receiver
2300     * class.
2301     * @param flags Additional option flags.  Use any combination of
2302     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
2303     * to modify the data returned.
2304     *
2305     * @return {@link ActivityInfo} containing information about the receiver.
2306     *
2307     * @see #GET_INTENT_FILTERS
2308     * @see #GET_META_DATA
2309     * @see #GET_SHARED_LIBRARY_FILES
2310     */
2311    public abstract ActivityInfo getReceiverInfo(ComponentName component,
2312            int flags) throws NameNotFoundException;
2313
2314    /**
2315     * Retrieve all of the information we know about a particular service
2316     * class.
2317     *
2318     * <p>Throws {@link NameNotFoundException} if a service with the given
2319     * class name cannot be found on the system.
2320     *
2321     * @param component The full component name (i.e.
2322     * com.google.apps.media/com.google.apps.media.BackgroundPlayback) of a Service
2323     * class.
2324     * @param flags Additional option flags.  Use any combination of
2325     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
2326     * to modify the data returned.
2327     *
2328     * @return ServiceInfo containing information about the service.
2329     *
2330     * @see #GET_META_DATA
2331     * @see #GET_SHARED_LIBRARY_FILES
2332     */
2333    public abstract ServiceInfo getServiceInfo(ComponentName component,
2334            int flags) throws NameNotFoundException;
2335
2336    /**
2337     * Retrieve all of the information we know about a particular content
2338     * provider class.
2339     *
2340     * <p>Throws {@link NameNotFoundException} if a provider with the given
2341     * class name cannot be found on the system.
2342     *
2343     * @param component The full component name (i.e.
2344     * com.google.providers.media/com.google.providers.media.MediaProvider) of a
2345     * ContentProvider class.
2346     * @param flags Additional option flags.  Use any combination of
2347     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
2348     * to modify the data returned.
2349     *
2350     * @return ProviderInfo containing information about the service.
2351     *
2352     * @see #GET_META_DATA
2353     * @see #GET_SHARED_LIBRARY_FILES
2354     */
2355    public abstract ProviderInfo getProviderInfo(ComponentName component,
2356            int flags) throws NameNotFoundException;
2357
2358    /**
2359     * Return a List of all packages that are installed
2360     * on the device.
2361     *
2362     * @param flags Additional option flags. Use any combination of
2363     * {@link #GET_ACTIVITIES},
2364     * {@link #GET_GIDS},
2365     * {@link #GET_CONFIGURATIONS},
2366     * {@link #GET_INSTRUMENTATION},
2367     * {@link #GET_PERMISSIONS},
2368     * {@link #GET_PROVIDERS},
2369     * {@link #GET_RECEIVERS},
2370     * {@link #GET_SERVICES},
2371     * {@link #GET_SIGNATURES},
2372     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2373     *
2374     * @return A List of PackageInfo objects, one for each package that is
2375     *         installed on the device.  In the unlikely case of there being no
2376     *         installed packages, an empty list is returned.
2377     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
2378     *         applications including those deleted with {@code DONT_DELETE_DATA}
2379     *         (partially installed apps with data directory) will be returned.
2380     *
2381     * @see #GET_ACTIVITIES
2382     * @see #GET_GIDS
2383     * @see #GET_CONFIGURATIONS
2384     * @see #GET_INSTRUMENTATION
2385     * @see #GET_PERMISSIONS
2386     * @see #GET_PROVIDERS
2387     * @see #GET_RECEIVERS
2388     * @see #GET_SERVICES
2389     * @see #GET_SIGNATURES
2390     * @see #GET_UNINSTALLED_PACKAGES
2391     */
2392    public abstract List<PackageInfo> getInstalledPackages(int flags);
2393
2394    /**
2395     * Return a List of all installed packages that are currently
2396     * holding any of the given permissions.
2397     *
2398     * @param flags Additional option flags. Use any combination of
2399     * {@link #GET_ACTIVITIES},
2400     * {@link #GET_GIDS},
2401     * {@link #GET_CONFIGURATIONS},
2402     * {@link #GET_INSTRUMENTATION},
2403     * {@link #GET_PERMISSIONS},
2404     * {@link #GET_PROVIDERS},
2405     * {@link #GET_RECEIVERS},
2406     * {@link #GET_SERVICES},
2407     * {@link #GET_SIGNATURES},
2408     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2409     *
2410     * @return Returns a List of PackageInfo objects, one for each installed
2411     * application that is holding any of the permissions that were provided.
2412     *
2413     * @see #GET_ACTIVITIES
2414     * @see #GET_GIDS
2415     * @see #GET_CONFIGURATIONS
2416     * @see #GET_INSTRUMENTATION
2417     * @see #GET_PERMISSIONS
2418     * @see #GET_PROVIDERS
2419     * @see #GET_RECEIVERS
2420     * @see #GET_SERVICES
2421     * @see #GET_SIGNATURES
2422     * @see #GET_UNINSTALLED_PACKAGES
2423     */
2424    public abstract List<PackageInfo> getPackagesHoldingPermissions(
2425            String[] permissions, int flags);
2426
2427    /**
2428     * Return a List of all packages that are installed on the device, for a specific user.
2429     * Requesting a list of installed packages for another user
2430     * will require the permission INTERACT_ACROSS_USERS_FULL.
2431     * @param flags Additional option flags. Use any combination of
2432     * {@link #GET_ACTIVITIES},
2433     * {@link #GET_GIDS},
2434     * {@link #GET_CONFIGURATIONS},
2435     * {@link #GET_INSTRUMENTATION},
2436     * {@link #GET_PERMISSIONS},
2437     * {@link #GET_PROVIDERS},
2438     * {@link #GET_RECEIVERS},
2439     * {@link #GET_SERVICES},
2440     * {@link #GET_SIGNATURES},
2441     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2442     * @param userId The user for whom the installed packages are to be listed
2443     *
2444     * @return A List of PackageInfo objects, one for each package that is
2445     *         installed on the device.  In the unlikely case of there being no
2446     *         installed packages, an empty list is returned.
2447     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
2448     *         applications including those deleted with {@code DONT_DELETE_DATA}
2449     *         (partially installed apps with data directory) will be returned.
2450     *
2451     * @see #GET_ACTIVITIES
2452     * @see #GET_GIDS
2453     * @see #GET_CONFIGURATIONS
2454     * @see #GET_INSTRUMENTATION
2455     * @see #GET_PERMISSIONS
2456     * @see #GET_PROVIDERS
2457     * @see #GET_RECEIVERS
2458     * @see #GET_SERVICES
2459     * @see #GET_SIGNATURES
2460     * @see #GET_UNINSTALLED_PACKAGES
2461     *
2462     * @hide
2463     */
2464    public abstract List<PackageInfo> getInstalledPackages(int flags, int userId);
2465
2466    /**
2467     * Check whether a particular package has been granted a particular
2468     * permission.
2469     *
2470     * @param permName The name of the permission you are checking for.
2471     * @param pkgName The name of the package you are checking against.
2472     *
2473     * @return If the package has the permission, PERMISSION_GRANTED is
2474     * returned.  If it does not have the permission, PERMISSION_DENIED
2475     * is returned.
2476     *
2477     * @see #PERMISSION_GRANTED
2478     * @see #PERMISSION_DENIED
2479     */
2480    @CheckResult
2481    public abstract int checkPermission(String permName, String pkgName);
2482
2483    /**
2484     * Checks whether a particular permissions has been revoked for a
2485     * package by policy. Typically the device owner or the profile owner
2486     * may apply such a policy. The user cannot grant policy revoked
2487     * permissions, hence the only way for an app to get such a permission
2488     * is by a policy change.
2489     *
2490     * @param permName The name of the permission you are checking for.
2491     * @param pkgName The name of the package you are checking against.
2492     *
2493     * @return Whether the permission is restricted by policy.
2494     */
2495    @CheckResult
2496    public abstract boolean isPermissionRevokedByPolicy(@NonNull String permName,
2497            @NonNull String pkgName);
2498
2499    /**
2500     * Gets the package name of the component controlling runtime permissions.
2501     *
2502     * @return The package name.
2503     *
2504     * @hide
2505     */
2506    public abstract String getPermissionControllerPackageName();
2507
2508    /**
2509     * Add a new dynamic permission to the system.  For this to work, your
2510     * package must have defined a permission tree through the
2511     * {@link android.R.styleable#AndroidManifestPermissionTree
2512     * &lt;permission-tree&gt;} tag in its manifest.  A package can only add
2513     * permissions to trees that were defined by either its own package or
2514     * another with the same user id; a permission is in a tree if it
2515     * matches the name of the permission tree + ".": for example,
2516     * "com.foo.bar" is a member of the permission tree "com.foo".
2517     *
2518     * <p>It is good to make your permission tree name descriptive, because you
2519     * are taking possession of that entire set of permission names.  Thus, it
2520     * must be under a domain you control, with a suffix that will not match
2521     * any normal permissions that may be declared in any applications that
2522     * are part of that domain.
2523     *
2524     * <p>New permissions must be added before
2525     * any .apks are installed that use those permissions.  Permissions you
2526     * add through this method are remembered across reboots of the device.
2527     * If the given permission already exists, the info you supply here
2528     * will be used to update it.
2529     *
2530     * @param info Description of the permission to be added.
2531     *
2532     * @return Returns true if a new permission was created, false if an
2533     * existing one was updated.
2534     *
2535     * @throws SecurityException if you are not allowed to add the
2536     * given permission name.
2537     *
2538     * @see #removePermission(String)
2539     */
2540    public abstract boolean addPermission(PermissionInfo info);
2541
2542    /**
2543     * Like {@link #addPermission(PermissionInfo)} but asynchronously
2544     * persists the package manager state after returning from the call,
2545     * allowing it to return quicker and batch a series of adds at the
2546     * expense of no guarantee the added permission will be retained if
2547     * the device is rebooted before it is written.
2548     */
2549    public abstract boolean addPermissionAsync(PermissionInfo info);
2550
2551    /**
2552     * Removes a permission that was previously added with
2553     * {@link #addPermission(PermissionInfo)}.  The same ownership rules apply
2554     * -- you are only allowed to remove permissions that you are allowed
2555     * to add.
2556     *
2557     * @param name The name of the permission to remove.
2558     *
2559     * @throws SecurityException if you are not allowed to remove the
2560     * given permission name.
2561     *
2562     * @see #addPermission(PermissionInfo)
2563     */
2564    public abstract void removePermission(String name);
2565
2566
2567    /**
2568     * Permission flags set when granting or revoking a permission.
2569     *
2570     * @hide
2571     */
2572    @SystemApi
2573    @IntDef({FLAG_PERMISSION_USER_SET,
2574            FLAG_PERMISSION_USER_FIXED,
2575            FLAG_PERMISSION_POLICY_FIXED,
2576            FLAG_PERMISSION_REVOKE_ON_UPGRADE,
2577            FLAG_PERMISSION_SYSTEM_FIXED,
2578            FLAG_PERMISSION_GRANTED_BY_DEFAULT})
2579    @Retention(RetentionPolicy.SOURCE)
2580    public @interface PermissionFlags {}
2581
2582    /**
2583     * Grant a runtime permission to an application which the application does not
2584     * already have. The permission must have been requested by the application.
2585     * If the application is not allowed to hold the permission, a {@link
2586     * java.lang.SecurityException} is thrown.
2587     * <p>
2588     * <strong>Note: </strong>Using this API requires holding
2589     * android.permission.GRANT_REVOKE_PERMISSIONS and if the user id is
2590     * not the current user android.permission.INTERACT_ACROSS_USERS_FULL.
2591     * </p>
2592     *
2593     * @param packageName The package to which to grant the permission.
2594     * @param permissionName The permission name to grant.
2595     * @param user The user for which to grant the permission.
2596     *
2597     * @see #revokeRuntimePermission(String, String, android.os.UserHandle)
2598     * @see android.content.pm.PackageManager.PermissionFlags
2599     *
2600     * @hide
2601     */
2602    @SystemApi
2603    public abstract void grantRuntimePermission(@NonNull String packageName,
2604            @NonNull String permissionName, @NonNull UserHandle user);
2605
2606    /**
2607     * Revoke a runtime permission that was previously granted by {@link
2608     * #grantRuntimePermission(String, String, android.os.UserHandle)}. The
2609     * permission must have been requested by and granted to the application.
2610     * If the application is not allowed to hold the permission, a {@link
2611     * java.lang.SecurityException} is thrown.
2612     * <p>
2613     * <strong>Note: </strong>Using this API requires holding
2614     * android.permission.GRANT_REVOKE_PERMISSIONS and if the user id is
2615     * not the current user android.permission.INTERACT_ACROSS_USERS_FULL.
2616     * </p>
2617     *
2618     * @param packageName The package from which to revoke the permission.
2619     * @param permissionName The permission name to revoke.
2620     * @param user The user for which to revoke the permission.
2621     *
2622     * @see #grantRuntimePermission(String, String, android.os.UserHandle)
2623     * @see android.content.pm.PackageManager.PermissionFlags
2624     *
2625     * @hide
2626     */
2627    @SystemApi
2628    public abstract void revokeRuntimePermission(@NonNull String packageName,
2629            @NonNull String permissionName, @NonNull UserHandle user);
2630
2631    /**
2632     * Gets the state flags associated with a permission.
2633     *
2634     * @param permissionName The permission for which to get the flags.
2635     * @param packageName The package name for which to get the flags.
2636     * @param user The user for which to get permission flags.
2637     * @return The permission flags.
2638     *
2639     * @hide
2640     */
2641    @SystemApi
2642    public abstract @PermissionFlags int getPermissionFlags(String permissionName,
2643            String packageName, @NonNull UserHandle user);
2644
2645    /**
2646     * Updates the flags associated with a permission by replacing the flags in
2647     * the specified mask with the provided flag values.
2648     *
2649     * @param permissionName The permission for which to update the flags.
2650     * @param packageName The package name for which to update the flags.
2651     * @param flagMask The flags which to replace.
2652     * @param flagValues The flags with which to replace.
2653     * @param user The user for which to update the permission flags.
2654     *
2655     * @hide
2656     */
2657    @SystemApi
2658    public abstract void updatePermissionFlags(String permissionName,
2659            String packageName, @PermissionFlags int flagMask, int flagValues,
2660            @NonNull UserHandle user);
2661
2662    /**
2663     * Gets whether you should show UI with rationale for requesting a permission.
2664     * You should do this only if you do not have the permission and the context in
2665     * which the permission is requested does not clearly communicate to the user
2666     * what would be the benefit from grating this permission.
2667     *
2668     * @param permission A permission your app wants to request.
2669     * @return Whether you can show permission rationale UI.
2670     *
2671     * @hide
2672     */
2673    public abstract boolean shouldShowRequestPermissionRationale(String permission);
2674
2675    /**
2676     * Returns an {@link android.content.Intent} suitable for passing to
2677     * {@link android.app.Activity#startActivityForResult(android.content.Intent, int)}
2678     * which prompts the user to grant permissions to this application.
2679     *
2680     * @throws NullPointerException if {@code permissions} is {@code null} or empty.
2681     *
2682     * @hide
2683     */
2684    public Intent buildRequestPermissionsIntent(@NonNull String[] permissions) {
2685        if (ArrayUtils.isEmpty(permissions)) {
2686           throw new NullPointerException("permission cannot be null or empty");
2687        }
2688        Intent intent = new Intent(ACTION_REQUEST_PERMISSIONS);
2689        intent.putExtra(EXTRA_REQUEST_PERMISSIONS_NAMES, permissions);
2690        intent.setPackage(getPermissionControllerPackageName());
2691        return intent;
2692    }
2693
2694    /**
2695     * Compare the signatures of two packages to determine if the same
2696     * signature appears in both of them.  If they do contain the same
2697     * signature, then they are allowed special privileges when working
2698     * with each other: they can share the same user-id, run instrumentation
2699     * against each other, etc.
2700     *
2701     * @param pkg1 First package name whose signature will be compared.
2702     * @param pkg2 Second package name whose signature will be compared.
2703     *
2704     * @return Returns an integer indicating whether all signatures on the
2705     * two packages match. The value is >= 0 ({@link #SIGNATURE_MATCH}) if
2706     * all signatures match or < 0 if there is not a match ({@link
2707     * #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
2708     *
2709     * @see #checkSignatures(int, int)
2710     * @see #SIGNATURE_MATCH
2711     * @see #SIGNATURE_NO_MATCH
2712     * @see #SIGNATURE_UNKNOWN_PACKAGE
2713     */
2714    @CheckResult
2715    public abstract int checkSignatures(String pkg1, String pkg2);
2716
2717    /**
2718     * Like {@link #checkSignatures(String, String)}, but takes UIDs of
2719     * the two packages to be checked.  This can be useful, for example,
2720     * when doing the check in an IPC, where the UID is the only identity
2721     * available.  It is functionally identical to determining the package
2722     * associated with the UIDs and checking their signatures.
2723     *
2724     * @param uid1 First UID whose signature will be compared.
2725     * @param uid2 Second UID whose signature will be compared.
2726     *
2727     * @return Returns an integer indicating whether all signatures on the
2728     * two packages match. The value is >= 0 ({@link #SIGNATURE_MATCH}) if
2729     * all signatures match or < 0 if there is not a match ({@link
2730     * #SIGNATURE_NO_MATCH} or {@link #SIGNATURE_UNKNOWN_PACKAGE}).
2731     *
2732     * @see #checkSignatures(String, String)
2733     * @see #SIGNATURE_MATCH
2734     * @see #SIGNATURE_NO_MATCH
2735     * @see #SIGNATURE_UNKNOWN_PACKAGE
2736     */
2737    @CheckResult
2738    public abstract int checkSignatures(int uid1, int uid2);
2739
2740    /**
2741     * Retrieve the names of all packages that are associated with a particular
2742     * user id.  In most cases, this will be a single package name, the package
2743     * that has been assigned that user id.  Where there are multiple packages
2744     * sharing the same user id through the "sharedUserId" mechanism, all
2745     * packages with that id will be returned.
2746     *
2747     * @param uid The user id for which you would like to retrieve the
2748     * associated packages.
2749     *
2750     * @return Returns an array of one or more packages assigned to the user
2751     * id, or null if there are no known packages with the given id.
2752     */
2753    public abstract String[] getPackagesForUid(int uid);
2754
2755    /**
2756     * Retrieve the official name associated with a user id.  This name is
2757     * guaranteed to never change, though it is possible for the underlying
2758     * user id to be changed.  That is, if you are storing information about
2759     * user ids in persistent storage, you should use the string returned
2760     * by this function instead of the raw user-id.
2761     *
2762     * @param uid The user id for which you would like to retrieve a name.
2763     * @return Returns a unique name for the given user id, or null if the
2764     * user id is not currently assigned.
2765     */
2766    public abstract String getNameForUid(int uid);
2767
2768    /**
2769     * Return the user id associated with a shared user name. Multiple
2770     * applications can specify a shared user name in their manifest and thus
2771     * end up using a common uid. This might be used for new applications
2772     * that use an existing shared user name and need to know the uid of the
2773     * shared user.
2774     *
2775     * @param sharedUserName The shared user name whose uid is to be retrieved.
2776     * @return Returns the uid associated with the shared user, or  NameNotFoundException
2777     * if the shared user name is not being used by any installed packages
2778     * @hide
2779     */
2780    public abstract int getUidForSharedUser(String sharedUserName)
2781            throws NameNotFoundException;
2782
2783    /**
2784     * Return a List of all application packages that are installed on the
2785     * device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all
2786     * applications including those deleted with {@code DONT_DELETE_DATA} (partially
2787     * installed apps with data directory) will be returned.
2788     *
2789     * @param flags Additional option flags. Use any combination of
2790     * {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
2791     * {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
2792     *
2793     * @return Returns a List of ApplicationInfo objects, one for each application that
2794     *         is installed on the device.  In the unlikely case of there being
2795     *         no installed applications, an empty list is returned.
2796     *         If flag GET_UNINSTALLED_PACKAGES is set, a list of all
2797     *         applications including those deleted with {@code DONT_DELETE_DATA}
2798     *         (partially installed apps with data directory) will be returned.
2799     *
2800     * @see #GET_META_DATA
2801     * @see #GET_SHARED_LIBRARY_FILES
2802     * @see #GET_UNINSTALLED_PACKAGES
2803     */
2804    public abstract List<ApplicationInfo> getInstalledApplications(int flags);
2805
2806    /**
2807     * Get a list of shared libraries that are available on the
2808     * system.
2809     *
2810     * @return An array of shared library names that are
2811     * available on the system, or null if none are installed.
2812     *
2813     */
2814    public abstract String[] getSystemSharedLibraryNames();
2815
2816    /**
2817     * Get a list of features that are available on the
2818     * system.
2819     *
2820     * @return An array of FeatureInfo classes describing the features
2821     * that are available on the system, or null if there are none(!!).
2822     */
2823    public abstract FeatureInfo[] getSystemAvailableFeatures();
2824
2825    /**
2826     * Check whether the given feature name is one of the available
2827     * features as returned by {@link #getSystemAvailableFeatures()}.
2828     *
2829     * @return Returns true if the devices supports the feature, else
2830     * false.
2831     */
2832    public abstract boolean hasSystemFeature(String name);
2833
2834    /**
2835     * Determine the best action to perform for a given Intent.  This is how
2836     * {@link Intent#resolveActivity} finds an activity if a class has not
2837     * been explicitly specified.
2838     *
2839     * <p><em>Note:</em> if using an implicit Intent (without an explicit ComponentName
2840     * specified), be sure to consider whether to set the {@link #MATCH_DEFAULT_ONLY}
2841     * only flag.  You need to do so to resolve the activity in the same way
2842     * that {@link android.content.Context#startActivity(Intent)} and
2843     * {@link android.content.Intent#resolveActivity(PackageManager)
2844     * Intent.resolveActivity(PackageManager)} do.</p>
2845     *
2846     * @param intent An intent containing all of the desired specification
2847     *               (action, data, type, category, and/or component).
2848     * @param flags Additional option flags.  The most important is
2849     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2850     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2851     *
2852     * @return Returns a ResolveInfo containing the final activity intent that
2853     *         was determined to be the best action.  Returns null if no
2854     *         matching activity was found. If multiple matching activities are
2855     *         found and there is no default set, returns a ResolveInfo
2856     *         containing something else, such as the activity resolver.
2857     *
2858     * @see #MATCH_DEFAULT_ONLY
2859     * @see #GET_INTENT_FILTERS
2860     * @see #GET_RESOLVED_FILTER
2861     */
2862    public abstract ResolveInfo resolveActivity(Intent intent, int flags);
2863
2864    /**
2865     * Determine the best action to perform for a given Intent for a given user. This
2866     * is how {@link Intent#resolveActivity} finds an activity if a class has not
2867     * been explicitly specified.
2868     *
2869     * <p><em>Note:</em> if using an implicit Intent (without an explicit ComponentName
2870     * specified), be sure to consider whether to set the {@link #MATCH_DEFAULT_ONLY}
2871     * only flag.  You need to do so to resolve the activity in the same way
2872     * that {@link android.content.Context#startActivity(Intent)} and
2873     * {@link android.content.Intent#resolveActivity(PackageManager)
2874     * Intent.resolveActivity(PackageManager)} do.</p>
2875     *
2876     * @param intent An intent containing all of the desired specification
2877     *               (action, data, type, category, and/or component).
2878     * @param flags Additional option flags.  The most important is
2879     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2880     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2881     * @param userId The user id.
2882     *
2883     * @return Returns a ResolveInfo containing the final activity intent that
2884     *         was determined to be the best action.  Returns null if no
2885     *         matching activity was found. If multiple matching activities are
2886     *         found and there is no default set, returns a ResolveInfo
2887     *         containing something else, such as the activity resolver.
2888     *
2889     * @see #MATCH_DEFAULT_ONLY
2890     * @see #GET_INTENT_FILTERS
2891     * @see #GET_RESOLVED_FILTER
2892     *
2893     * @hide
2894     */
2895    public abstract ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId);
2896
2897    /**
2898     * Retrieve all activities that can be performed for the given intent.
2899     *
2900     * @param intent The desired intent as per resolveActivity().
2901     * @param flags Additional option flags.  The most important is
2902     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2903     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2904     *
2905     * You can also set {@link #MATCH_ALL} for preventing the filtering of the results.
2906     *
2907     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2908     *         Activity. These are ordered from best to worst match -- that
2909     *         is, the first item in the list is what is returned by
2910     *         {@link #resolveActivity}.  If there are no matching activities, an empty
2911     *         list is returned.
2912     *
2913     * @see #MATCH_DEFAULT_ONLY
2914     * @see #GET_INTENT_FILTERS
2915     * @see #GET_RESOLVED_FILTER
2916     */
2917    public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
2918            int flags);
2919
2920    /**
2921     * Retrieve all activities that can be performed for the given intent, for a specific user.
2922     *
2923     * @param intent The desired intent as per resolveActivity().
2924     * @param flags Additional option flags.  The most important is
2925     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2926     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2927     *
2928     * You can also set {@link #MATCH_ALL} for preventing the filtering of the results.
2929     *
2930     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2931     *         Activity. These are ordered from best to worst match -- that
2932     *         is, the first item in the list is what is returned by
2933     *         {@link #resolveActivity}.  If there are no matching activities, an empty
2934     *         list is returned.
2935     *
2936     * @see #MATCH_DEFAULT_ONLY
2937     * @see #GET_INTENT_FILTERS
2938     * @see #GET_RESOLVED_FILTER
2939     * @hide
2940     */
2941    public abstract List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
2942            int flags, int userId);
2943
2944
2945    /**
2946     * Retrieve a set of activities that should be presented to the user as
2947     * similar options.  This is like {@link #queryIntentActivities}, except it
2948     * also allows you to supply a list of more explicit Intents that you would
2949     * like to resolve to particular options, and takes care of returning the
2950     * final ResolveInfo list in a reasonable order, with no duplicates, based
2951     * on those inputs.
2952     *
2953     * @param caller The class name of the activity that is making the
2954     *               request.  This activity will never appear in the output
2955     *               list.  Can be null.
2956     * @param specifics An array of Intents that should be resolved to the
2957     *                  first specific results.  Can be null.
2958     * @param intent The desired intent as per resolveActivity().
2959     * @param flags Additional option flags.  The most important is
2960     * {@link #MATCH_DEFAULT_ONLY}, to limit the resolution to only
2961     * those activities that support the {@link android.content.Intent#CATEGORY_DEFAULT}.
2962     *
2963     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2964     *         Activity. These are ordered first by all of the intents resolved
2965     *         in <var>specifics</var> and then any additional activities that
2966     *         can handle <var>intent</var> but did not get included by one of
2967     *         the <var>specifics</var> intents.  If there are no matching
2968     *         activities, an empty list is returned.
2969     *
2970     * @see #MATCH_DEFAULT_ONLY
2971     * @see #GET_INTENT_FILTERS
2972     * @see #GET_RESOLVED_FILTER
2973     */
2974    public abstract List<ResolveInfo> queryIntentActivityOptions(
2975            ComponentName caller, Intent[] specifics, Intent intent, int flags);
2976
2977    /**
2978     * Retrieve all receivers that can handle a broadcast of the given intent.
2979     *
2980     * @param intent The desired intent as per resolveActivity().
2981     * @param flags Additional option flags.
2982     *
2983     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
2984     *         Receiver. These are ordered from first to last in priority.  If
2985     *         there are no matching receivers, an empty list is returned.
2986     *
2987     * @see #MATCH_DEFAULT_ONLY
2988     * @see #GET_INTENT_FILTERS
2989     * @see #GET_RESOLVED_FILTER
2990     */
2991    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
2992            int flags);
2993
2994    /**
2995     * Retrieve all receivers that can handle a broadcast of the given intent, for a specific
2996     * user.
2997     *
2998     * @param intent The desired intent as per resolveActivity().
2999     * @param flags Additional option flags.
3000     * @param userId The userId of the user being queried.
3001     *
3002     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
3003     *         Receiver. These are ordered from first to last in priority.  If
3004     *         there are no matching receivers, an empty list or {@code null} is returned.
3005     *
3006     * @see #MATCH_DEFAULT_ONLY
3007     * @see #GET_INTENT_FILTERS
3008     * @see #GET_RESOLVED_FILTER
3009     * @hide
3010     */
3011    public abstract List<ResolveInfo> queryBroadcastReceivers(Intent intent,
3012            int flags, int userId);
3013
3014    /**
3015     * Determine the best service to handle for a given Intent.
3016     *
3017     * @param intent An intent containing all of the desired specification
3018     *               (action, data, type, category, and/or component).
3019     * @param flags Additional option flags.
3020     *
3021     * @return Returns a ResolveInfo containing the final service intent that
3022     *         was determined to be the best action.  Returns null if no
3023     *         matching service was found.
3024     *
3025     * @see #GET_INTENT_FILTERS
3026     * @see #GET_RESOLVED_FILTER
3027     */
3028    public abstract ResolveInfo resolveService(Intent intent, int flags);
3029
3030    /**
3031     * Retrieve all services that can match the given intent.
3032     *
3033     * @param intent The desired intent as per resolveService().
3034     * @param flags Additional option flags.
3035     *
3036     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
3037     *         ServiceInfo. These are ordered from best to worst match -- that
3038     *         is, the first item in the list is what is returned by
3039     *         resolveService().  If there are no matching services, an empty
3040     *         list or {@code null} is returned.
3041     *
3042     * @see #GET_INTENT_FILTERS
3043     * @see #GET_RESOLVED_FILTER
3044     */
3045    public abstract List<ResolveInfo> queryIntentServices(Intent intent,
3046            int flags);
3047
3048    /**
3049     * Retrieve all services that can match the given intent for a given user.
3050     *
3051     * @param intent The desired intent as per resolveService().
3052     * @param flags Additional option flags.
3053     * @param userId The user id.
3054     *
3055     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
3056     *         ServiceInfo. These are ordered from best to worst match -- that
3057     *         is, the first item in the list is what is returned by
3058     *         resolveService().  If there are no matching services, an empty
3059     *         list or {@code null} is returned.
3060     *
3061     * @see #GET_INTENT_FILTERS
3062     * @see #GET_RESOLVED_FILTER
3063     *
3064     * @hide
3065     */
3066    public abstract List<ResolveInfo> queryIntentServicesAsUser(Intent intent,
3067            int flags, int userId);
3068
3069    /** {@hide} */
3070    public abstract List<ResolveInfo> queryIntentContentProvidersAsUser(
3071            Intent intent, int flags, int userId);
3072
3073    /**
3074     * Retrieve all providers that can match the given intent.
3075     *
3076     * @param intent An intent containing all of the desired specification
3077     *            (action, data, type, category, and/or component).
3078     * @param flags Additional option flags.
3079     * @return A List&lt;ResolveInfo&gt; containing one entry for each matching
3080     *         ProviderInfo. These are ordered from best to worst match. If
3081     *         there are no matching providers, an empty list or {@code null} is returned.
3082     * @see #GET_INTENT_FILTERS
3083     * @see #GET_RESOLVED_FILTER
3084     */
3085    public abstract List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags);
3086
3087    /**
3088     * Find a single content provider by its base path name.
3089     *
3090     * @param name The name of the provider to find.
3091     * @param flags Additional option flags.  Currently should always be 0.
3092     *
3093     * @return ContentProviderInfo Information about the provider, if found,
3094     *         else null.
3095     */
3096    public abstract ProviderInfo resolveContentProvider(String name,
3097            int flags);
3098
3099    /**
3100     * Find a single content provider by its base path name.
3101     *
3102     * @param name The name of the provider to find.
3103     * @param flags Additional option flags.  Currently should always be 0.
3104     * @param userId The user id.
3105     *
3106     * @return ContentProviderInfo Information about the provider, if found,
3107     *         else null.
3108     * @hide
3109     */
3110    public abstract ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId);
3111
3112    /**
3113     * Retrieve content provider information.
3114     *
3115     * <p><em>Note: unlike most other methods, an empty result set is indicated
3116     * by a null return instead of an empty list.</em>
3117     *
3118     * @param processName If non-null, limits the returned providers to only
3119     *                    those that are hosted by the given process.  If null,
3120     *                    all content providers are returned.
3121     * @param uid If <var>processName</var> is non-null, this is the required
3122     *        uid owning the requested content providers.
3123     * @param flags Additional option flags.  Currently should always be 0.
3124     *
3125     * @return A List&lt;ContentProviderInfo&gt; containing one entry for each
3126     *         content provider either patching <var>processName</var> or, if
3127     *         <var>processName</var> is null, all known content providers.
3128     *         <em>If there are no matching providers, null is returned.</em>
3129     */
3130    public abstract List<ProviderInfo> queryContentProviders(
3131            String processName, int uid, int flags);
3132
3133    /**
3134     * Retrieve all of the information we know about a particular
3135     * instrumentation class.
3136     *
3137     * <p>Throws {@link NameNotFoundException} if instrumentation with the
3138     * given class name cannot be found on the system.
3139     *
3140     * @param className The full name (i.e.
3141     *                  com.google.apps.contacts.InstrumentList) of an
3142     *                  Instrumentation class.
3143     * @param flags Additional option flags.  Currently should always be 0.
3144     *
3145     * @return InstrumentationInfo containing information about the
3146     *         instrumentation.
3147     */
3148    public abstract InstrumentationInfo getInstrumentationInfo(
3149            ComponentName className, int flags) throws NameNotFoundException;
3150
3151    /**
3152     * Retrieve information about available instrumentation code.  May be used
3153     * to retrieve either all instrumentation code, or only the code targeting
3154     * a particular package.
3155     *
3156     * @param targetPackage If null, all instrumentation is returned; only the
3157     *                      instrumentation targeting this package name is
3158     *                      returned.
3159     * @param flags Additional option flags.  Currently should always be 0.
3160     *
3161     * @return A List&lt;InstrumentationInfo&gt; containing one entry for each
3162     *         matching available Instrumentation.  Returns an empty list if
3163     *         there is no instrumentation available for the given package.
3164     */
3165    public abstract List<InstrumentationInfo> queryInstrumentation(
3166            String targetPackage, int flags);
3167
3168    /**
3169     * Retrieve an image from a package.  This is a low-level API used by
3170     * the various package manager info structures (such as
3171     * {@link ComponentInfo} to implement retrieval of their associated
3172     * icon.
3173     *
3174     * @param packageName The name of the package that this icon is coming from.
3175     * Cannot be null.
3176     * @param resid The resource identifier of the desired image.  Cannot be 0.
3177     * @param appInfo Overall information about <var>packageName</var>.  This
3178     * may be null, in which case the application information will be retrieved
3179     * for you if needed; if you already have this information around, it can
3180     * be much more efficient to supply it here.
3181     *
3182     * @return Returns a Drawable holding the requested image.  Returns null if
3183     * an image could not be found for any reason.
3184     */
3185    public abstract Drawable getDrawable(String packageName, @DrawableRes int resid,
3186            ApplicationInfo appInfo);
3187
3188    /**
3189     * Retrieve the icon associated with an activity.  Given the full name of
3190     * an activity, retrieves the information about it and calls
3191     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its icon.
3192     * If the activity cannot be found, NameNotFoundException is thrown.
3193     *
3194     * @param activityName Name of the activity whose icon is to be retrieved.
3195     *
3196     * @return Returns the image of the icon, or the default activity icon if
3197     * it could not be found.  Does not return null.
3198     * @throws NameNotFoundException Thrown if the resources for the given
3199     * activity could not be loaded.
3200     *
3201     * @see #getActivityIcon(Intent)
3202     */
3203    public abstract Drawable getActivityIcon(ComponentName activityName)
3204            throws NameNotFoundException;
3205
3206    /**
3207     * Retrieve the icon associated with an Intent.  If intent.getClassName() is
3208     * set, this simply returns the result of
3209     * getActivityIcon(intent.getClassName()).  Otherwise it resolves the intent's
3210     * component and returns the icon associated with the resolved component.
3211     * If intent.getClassName() cannot be found or the Intent cannot be resolved
3212     * to a component, NameNotFoundException is thrown.
3213     *
3214     * @param intent The intent for which you would like to retrieve an icon.
3215     *
3216     * @return Returns the image of the icon, or the default activity icon if
3217     * it could not be found.  Does not return null.
3218     * @throws NameNotFoundException Thrown if the resources for application
3219     * matching the given intent could not be loaded.
3220     *
3221     * @see #getActivityIcon(ComponentName)
3222     */
3223    public abstract Drawable getActivityIcon(Intent intent)
3224            throws NameNotFoundException;
3225
3226    /**
3227     * Retrieve the banner associated with an activity. Given the full name of
3228     * an activity, retrieves the information about it and calls
3229     * {@link ComponentInfo#loadIcon ComponentInfo.loadIcon()} to return its
3230     * banner. If the activity cannot be found, NameNotFoundException is thrown.
3231     *
3232     * @param activityName Name of the activity whose banner is to be retrieved.
3233     * @return Returns the image of the banner, or null if the activity has no
3234     *         banner specified.
3235     * @throws NameNotFoundException Thrown if the resources for the given
3236     *             activity could not be loaded.
3237     * @see #getActivityBanner(Intent)
3238     */
3239    public abstract Drawable getActivityBanner(ComponentName activityName)
3240            throws NameNotFoundException;
3241
3242    /**
3243     * Retrieve the banner associated with an Intent. If intent.getClassName()
3244     * is set, this simply returns the result of
3245     * getActivityBanner(intent.getClassName()). Otherwise it resolves the
3246     * intent's component and returns the banner associated with the resolved
3247     * component. If intent.getClassName() cannot be found or the Intent cannot
3248     * be resolved to a component, NameNotFoundException is thrown.
3249     *
3250     * @param intent The intent for which you would like to retrieve a banner.
3251     * @return Returns the image of the banner, or null if the activity has no
3252     *         banner specified.
3253     * @throws NameNotFoundException Thrown if the resources for application
3254     *             matching the given intent could not be loaded.
3255     * @see #getActivityBanner(ComponentName)
3256     */
3257    public abstract Drawable getActivityBanner(Intent intent)
3258            throws NameNotFoundException;
3259
3260    /**
3261     * Return the generic icon for an activity that is used when no specific
3262     * icon is defined.
3263     *
3264     * @return Drawable Image of the icon.
3265     */
3266    public abstract Drawable getDefaultActivityIcon();
3267
3268    /**
3269     * Retrieve the icon associated with an application.  If it has not defined
3270     * an icon, the default app icon is returned.  Does not return null.
3271     *
3272     * @param info Information about application being queried.
3273     *
3274     * @return Returns the image of the icon, or the default application icon
3275     * if it could not be found.
3276     *
3277     * @see #getApplicationIcon(String)
3278     */
3279    public abstract Drawable getApplicationIcon(ApplicationInfo info);
3280
3281    /**
3282     * Retrieve the icon associated with an application.  Given the name of the
3283     * application's package, retrieves the information about it and calls
3284     * getApplicationIcon() to return its icon. If the application cannot be
3285     * found, NameNotFoundException is thrown.
3286     *
3287     * @param packageName Name of the package whose application icon is to be
3288     *                    retrieved.
3289     *
3290     * @return Returns the image of the icon, or the default application icon
3291     * if it could not be found.  Does not return null.
3292     * @throws NameNotFoundException Thrown if the resources for the given
3293     * application could not be loaded.
3294     *
3295     * @see #getApplicationIcon(ApplicationInfo)
3296     */
3297    public abstract Drawable getApplicationIcon(String packageName)
3298            throws NameNotFoundException;
3299
3300    /**
3301     * Retrieve the banner associated with an application.
3302     *
3303     * @param info Information about application being queried.
3304     * @return Returns the image of the banner or null if the application has no
3305     *         banner specified.
3306     * @see #getApplicationBanner(String)
3307     */
3308    public abstract Drawable getApplicationBanner(ApplicationInfo info);
3309
3310    /**
3311     * Retrieve the banner associated with an application. Given the name of the
3312     * application's package, retrieves the information about it and calls
3313     * getApplicationIcon() to return its banner. If the application cannot be
3314     * found, NameNotFoundException is thrown.
3315     *
3316     * @param packageName Name of the package whose application banner is to be
3317     *            retrieved.
3318     * @return Returns the image of the banner or null if the application has no
3319     *         banner specified.
3320     * @throws NameNotFoundException Thrown if the resources for the given
3321     *             application could not be loaded.
3322     * @see #getApplicationBanner(ApplicationInfo)
3323     */
3324    public abstract Drawable getApplicationBanner(String packageName)
3325            throws NameNotFoundException;
3326
3327    /**
3328     * Retrieve the logo associated with an activity. Given the full name of an
3329     * activity, retrieves the information about it and calls
3330     * {@link ComponentInfo#loadLogo ComponentInfo.loadLogo()} to return its
3331     * logo. If the activity cannot be found, NameNotFoundException is thrown.
3332     *
3333     * @param activityName Name of the activity whose logo is to be retrieved.
3334     * @return Returns the image of the logo or null if the activity has no logo
3335     *         specified.
3336     * @throws NameNotFoundException Thrown if the resources for the given
3337     *             activity could not be loaded.
3338     * @see #getActivityLogo(Intent)
3339     */
3340    public abstract Drawable getActivityLogo(ComponentName activityName)
3341            throws NameNotFoundException;
3342
3343    /**
3344     * Retrieve the logo associated with an Intent.  If intent.getClassName() is
3345     * set, this simply returns the result of
3346     * getActivityLogo(intent.getClassName()).  Otherwise it resolves the intent's
3347     * component and returns the logo associated with the resolved component.
3348     * If intent.getClassName() cannot be found or the Intent cannot be resolved
3349     * to a component, NameNotFoundException is thrown.
3350     *
3351     * @param intent The intent for which you would like to retrieve a logo.
3352     *
3353     * @return Returns the image of the logo, or null if the activity has no
3354     * logo specified.
3355     *
3356     * @throws NameNotFoundException Thrown if the resources for application
3357     * matching the given intent could not be loaded.
3358     *
3359     * @see #getActivityLogo(ComponentName)
3360     */
3361    public abstract Drawable getActivityLogo(Intent intent)
3362            throws NameNotFoundException;
3363
3364    /**
3365     * Retrieve the logo associated with an application.  If it has not specified
3366     * a logo, this method returns null.
3367     *
3368     * @param info Information about application being queried.
3369     *
3370     * @return Returns the image of the logo, or null if no logo is specified
3371     * by the application.
3372     *
3373     * @see #getApplicationLogo(String)
3374     */
3375    public abstract Drawable getApplicationLogo(ApplicationInfo info);
3376
3377    /**
3378     * Retrieve the logo associated with an application.  Given the name of the
3379     * application's package, retrieves the information about it and calls
3380     * getApplicationLogo() to return its logo. If the application cannot be
3381     * found, NameNotFoundException is thrown.
3382     *
3383     * @param packageName Name of the package whose application logo is to be
3384     *                    retrieved.
3385     *
3386     * @return Returns the image of the logo, or null if no application logo
3387     * has been specified.
3388     *
3389     * @throws NameNotFoundException Thrown if the resources for the given
3390     * application could not be loaded.
3391     *
3392     * @see #getApplicationLogo(ApplicationInfo)
3393     */
3394    public abstract Drawable getApplicationLogo(String packageName)
3395            throws NameNotFoundException;
3396
3397    /**
3398     * If the target user is a managed profile of the calling user or if the
3399     * target user is the caller and is itself a managed profile, then this
3400     * returns a badged copy of the given icon to be able to distinguish it from
3401     * the original icon. For badging an arbitrary drawable use
3402     * {@link #getUserBadgedDrawableForDensity(
3403     * android.graphics.drawable.Drawable, UserHandle, android.graphics.Rect, int)}.
3404     * <p>
3405     * If the original drawable is a BitmapDrawable and the backing bitmap is
3406     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the badging
3407     * is performed in place and the original drawable is returned.
3408     * </p>
3409     *
3410     * @param icon The icon to badge.
3411     * @param user The target user.
3412     * @return A drawable that combines the original icon and a badge as
3413     *         determined by the system.
3414     */
3415    public abstract Drawable getUserBadgedIcon(Drawable icon, UserHandle user);
3416
3417    /**
3418     * If the target user is a managed profile of the calling user or the caller
3419     * is itself a managed profile, then this returns a badged copy of the given
3420     * drawable allowing the user to distinguish it from the original drawable.
3421     * The caller can specify the location in the bounds of the drawable to be
3422     * badged where the badge should be applied as well as the density of the
3423     * badge to be used.
3424     * <p>
3425     * If the original drawable is a BitmapDrawable and the backing bitmap is
3426     * mutable as per {@link android.graphics.Bitmap#isMutable()}, the bading
3427     * is performed in place and the original drawable is returned.
3428     * </p>
3429     *
3430     * @param drawable The drawable to badge.
3431     * @param user The target user.
3432     * @param badgeLocation Where in the bounds of the badged drawable to place
3433     *         the badge. If not provided, the badge is applied on top of the entire
3434     *         drawable being badged.
3435     * @param badgeDensity The optional desired density for the badge as per
3436     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided,
3437     *         the density of the display is used.
3438     * @return A drawable that combines the original drawable and a badge as
3439     *         determined by the system.
3440     */
3441    public abstract Drawable getUserBadgedDrawableForDensity(Drawable drawable,
3442            UserHandle user, Rect badgeLocation, int badgeDensity);
3443
3444    /**
3445     * If the target user is a managed profile of the calling user or the caller
3446     * is itself a managed profile, then this returns a drawable to use as a small
3447     * icon to include in a view to distinguish it from the original icon.
3448     *
3449     * @param user The target user.
3450     * @param density The optional desired density for the badge as per
3451     *         {@link android.util.DisplayMetrics#densityDpi}. If not provided
3452     *         the density of the current display is used.
3453     * @return the drawable or null if no drawable is required.
3454     * @hide
3455     */
3456    public abstract Drawable getUserBadgeForDensity(UserHandle user, int density);
3457
3458    /**
3459     * If the target user is a managed profile of the calling user or the caller
3460     * is itself a managed profile, then this returns a copy of the label with
3461     * badging for accessibility services like talkback. E.g. passing in "Email"
3462     * and it might return "Work Email" for Email in the work profile.
3463     *
3464     * @param label The label to change.
3465     * @param user The target user.
3466     * @return A label that combines the original label and a badge as
3467     *         determined by the system.
3468     */
3469    public abstract CharSequence getUserBadgedLabel(CharSequence label, UserHandle user);
3470
3471    /**
3472     * Retrieve text from a package.  This is a low-level API used by
3473     * the various package manager info structures (such as
3474     * {@link ComponentInfo} to implement retrieval of their associated
3475     * labels and other text.
3476     *
3477     * @param packageName The name of the package that this text is coming from.
3478     * Cannot be null.
3479     * @param resid The resource identifier of the desired text.  Cannot be 0.
3480     * @param appInfo Overall information about <var>packageName</var>.  This
3481     * may be null, in which case the application information will be retrieved
3482     * for you if needed; if you already have this information around, it can
3483     * be much more efficient to supply it here.
3484     *
3485     * @return Returns a CharSequence holding the requested text.  Returns null
3486     * if the text could not be found for any reason.
3487     */
3488    public abstract CharSequence getText(String packageName, @StringRes int resid,
3489            ApplicationInfo appInfo);
3490
3491    /**
3492     * Retrieve an XML file from a package.  This is a low-level API used to
3493     * retrieve XML meta data.
3494     *
3495     * @param packageName The name of the package that this xml is coming from.
3496     * Cannot be null.
3497     * @param resid The resource identifier of the desired xml.  Cannot be 0.
3498     * @param appInfo Overall information about <var>packageName</var>.  This
3499     * may be null, in which case the application information will be retrieved
3500     * for you if needed; if you already have this information around, it can
3501     * be much more efficient to supply it here.
3502     *
3503     * @return Returns an XmlPullParser allowing you to parse out the XML
3504     * data.  Returns null if the xml resource could not be found for any
3505     * reason.
3506     */
3507    public abstract XmlResourceParser getXml(String packageName, @XmlRes int resid,
3508            ApplicationInfo appInfo);
3509
3510    /**
3511     * Return the label to use for this application.
3512     *
3513     * @return Returns the label associated with this application, or null if
3514     * it could not be found for any reason.
3515     * @param info The application to get the label of.
3516     */
3517    public abstract CharSequence getApplicationLabel(ApplicationInfo info);
3518
3519    /**
3520     * Retrieve the resources associated with an activity.  Given the full
3521     * name of an activity, retrieves the information about it and calls
3522     * getResources() to return its application's resources.  If the activity
3523     * cannot be found, NameNotFoundException is thrown.
3524     *
3525     * @param activityName Name of the activity whose resources are to be
3526     *                     retrieved.
3527     *
3528     * @return Returns the application's Resources.
3529     * @throws NameNotFoundException Thrown if the resources for the given
3530     * application could not be loaded.
3531     *
3532     * @see #getResourcesForApplication(ApplicationInfo)
3533     */
3534    public abstract Resources getResourcesForActivity(ComponentName activityName)
3535            throws NameNotFoundException;
3536
3537    /**
3538     * Retrieve the resources for an application.  Throws NameNotFoundException
3539     * if the package is no longer installed.
3540     *
3541     * @param app Information about the desired application.
3542     *
3543     * @return Returns the application's Resources.
3544     * @throws NameNotFoundException Thrown if the resources for the given
3545     * application could not be loaded (most likely because it was uninstalled).
3546     */
3547    public abstract Resources getResourcesForApplication(ApplicationInfo app)
3548            throws NameNotFoundException;
3549
3550    /**
3551     * Retrieve the resources associated with an application.  Given the full
3552     * package name of an application, retrieves the information about it and
3553     * calls getResources() to return its application's resources.  If the
3554     * appPackageName cannot be found, NameNotFoundException is thrown.
3555     *
3556     * @param appPackageName Package name of the application whose resources
3557     *                       are to be retrieved.
3558     *
3559     * @return Returns the application's Resources.
3560     * @throws NameNotFoundException Thrown if the resources for the given
3561     * application could not be loaded.
3562     *
3563     * @see #getResourcesForApplication(ApplicationInfo)
3564     */
3565    public abstract Resources getResourcesForApplication(String appPackageName)
3566            throws NameNotFoundException;
3567
3568    /** @hide */
3569    public abstract Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
3570            throws NameNotFoundException;
3571
3572    /**
3573     * Retrieve overall information about an application package defined
3574     * in a package archive file
3575     *
3576     * @param archiveFilePath The path to the archive file
3577     * @param flags Additional option flags. Use any combination of
3578     * {@link #GET_ACTIVITIES},
3579     * {@link #GET_GIDS},
3580     * {@link #GET_CONFIGURATIONS},
3581     * {@link #GET_INSTRUMENTATION},
3582     * {@link #GET_PERMISSIONS},
3583     * {@link #GET_PROVIDERS},
3584     * {@link #GET_RECEIVERS},
3585     * {@link #GET_SERVICES},
3586     * {@link #GET_SIGNATURES}, to modify the data returned.
3587     *
3588     * @return Returns the information about the package. Returns
3589     * null if the package could not be successfully parsed.
3590     *
3591     * @see #GET_ACTIVITIES
3592     * @see #GET_GIDS
3593     * @see #GET_CONFIGURATIONS
3594     * @see #GET_INSTRUMENTATION
3595     * @see #GET_PERMISSIONS
3596     * @see #GET_PROVIDERS
3597     * @see #GET_RECEIVERS
3598     * @see #GET_SERVICES
3599     * @see #GET_SIGNATURES
3600     *
3601     */
3602    public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) {
3603        final PackageParser parser = new PackageParser();
3604        final File apkFile = new File(archiveFilePath);
3605        try {
3606            PackageParser.Package pkg = parser.parseMonolithicPackage(apkFile, 0);
3607            if ((flags & GET_SIGNATURES) != 0) {
3608                parser.collectCertificates(pkg, 0);
3609                parser.collectManifestDigest(pkg);
3610            }
3611            PackageUserState state = new PackageUserState();
3612            return PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, state);
3613        } catch (PackageParserException e) {
3614            return null;
3615        }
3616    }
3617
3618    /**
3619     * @hide Install a package. Since this may take a little while, the result
3620     *       will be posted back to the given observer. An installation will
3621     *       fail if the calling context lacks the
3622     *       {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if
3623     *       the package named in the package file's manifest is already
3624     *       installed, or if there's no space available on the device.
3625     * @param packageURI The location of the package file to install. This can
3626     *            be a 'file:' or a 'content:' URI.
3627     * @param observer An observer callback to get notified when the package
3628     *            installation is complete.
3629     *            {@link IPackageInstallObserver#packageInstalled(String, int)}
3630     *            will be called when that happens. This parameter must not be
3631     *            null.
3632     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3633     *            {@link #INSTALL_REPLACE_EXISTING},
3634     *            {@link #INSTALL_ALLOW_TEST}.
3635     * @param installerPackageName Optional package name of the application that
3636     *            is performing the installation. This identifies which market
3637     *            the package came from.
3638     * @deprecated Use {@link #installPackage(Uri, PackageInstallObserver, int,
3639     *             String)} instead. This method will continue to be supported
3640     *             but the older observer interface will not get additional
3641     *             failure details.
3642     */
3643    // @SystemApi
3644    public abstract void installPackage(
3645            Uri packageURI, IPackageInstallObserver observer, int flags,
3646            String installerPackageName);
3647
3648    /**
3649     * Similar to
3650     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3651     * with an extra verification file provided.
3652     *
3653     * @param packageURI The location of the package file to install. This can
3654     *            be a 'file:' or a 'content:' URI.
3655     * @param observer An observer callback to get notified when the package
3656     *            installation is complete.
3657     *            {@link IPackageInstallObserver#packageInstalled(String, int)}
3658     *            will be called when that happens. This parameter must not be
3659     *            null.
3660     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3661     *            {@link #INSTALL_REPLACE_EXISTING},
3662     *            {@link #INSTALL_ALLOW_TEST}.
3663     * @param installerPackageName Optional package name of the application that
3664     *            is performing the installation. This identifies which market
3665     *            the package came from.
3666     * @param verificationURI The location of the supplementary verification
3667     *            file. This can be a 'file:' or a 'content:' URI. May be
3668     *            {@code null}.
3669     * @param manifestDigest an object that holds the digest of the package
3670     *            which can be used to verify ownership. May be {@code null}.
3671     * @param encryptionParams if the package to be installed is encrypted,
3672     *            these parameters describing the encryption and authentication
3673     *            used. May be {@code null}.
3674     * @hide
3675     * @deprecated Use {@link #installPackageWithVerification(Uri,
3676     *             PackageInstallObserver, int, String, Uri, ManifestDigest,
3677     *             ContainerEncryptionParams)} instead. This method will
3678     *             continue to be supported but the older observer interface
3679     *             will not get additional failure details.
3680     */
3681    // @SystemApi
3682    public abstract void installPackageWithVerification(Uri packageURI,
3683            IPackageInstallObserver observer, int flags, String installerPackageName,
3684            Uri verificationURI, ManifestDigest manifestDigest,
3685            ContainerEncryptionParams encryptionParams);
3686
3687    /**
3688     * Similar to
3689     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3690     * with an extra verification information provided.
3691     *
3692     * @param packageURI The location of the package file to install. This can
3693     *            be a 'file:' or a 'content:' URI.
3694     * @param observer An observer callback to get notified when the package
3695     *            installation is complete.
3696     *            {@link IPackageInstallObserver#packageInstalled(String, int)}
3697     *            will be called when that happens. This parameter must not be
3698     *            null.
3699     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3700     *            {@link #INSTALL_REPLACE_EXISTING},
3701     *            {@link #INSTALL_ALLOW_TEST}.
3702     * @param installerPackageName Optional package name of the application that
3703     *            is performing the installation. This identifies which market
3704     *            the package came from.
3705     * @param verificationParams an object that holds signal information to
3706     *            assist verification. May be {@code null}.
3707     * @param encryptionParams if the package to be installed is encrypted,
3708     *            these parameters describing the encryption and authentication
3709     *            used. May be {@code null}.
3710     * @hide
3711     * @deprecated Use {@link #installPackageWithVerificationAndEncryption(Uri,
3712     *             PackageInstallObserver, int, String, VerificationParams,
3713     *             ContainerEncryptionParams)} instead. This method will
3714     *             continue to be supported but the older observer interface
3715     *             will not get additional failure details.
3716     */
3717    @Deprecated
3718    public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
3719            IPackageInstallObserver observer, int flags, String installerPackageName,
3720            VerificationParams verificationParams,
3721            ContainerEncryptionParams encryptionParams);
3722
3723    // Package-install variants that take the new, expanded form of observer interface.
3724    // Note that these *also* take the original observer type and will redundantly
3725    // report the same information to that observer if supplied; but it is not required.
3726
3727    /**
3728     * @hide
3729     *
3730     * Install a package. Since this may take a little while, the result will
3731     * be posted back to the given observer.  An installation will fail if the calling context
3732     * lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the
3733     * package named in the package file's manifest is already installed, or if there's no space
3734     * available on the device.
3735     *
3736     * @param packageURI The location of the package file to install.  This can be a 'file:' or a
3737     * 'content:' URI.
3738     * @param observer An observer callback to get notified when the package installation is
3739     * complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
3740     * called when that happens. This parameter must not be null.
3741     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3742     * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
3743     * @param installerPackageName Optional package name of the application that is performing the
3744     * installation. This identifies which market the package came from.
3745     */
3746    public abstract void installPackage(
3747            Uri packageURI, PackageInstallObserver observer,
3748            int flags, String installerPackageName);
3749
3750
3751    /**
3752     * @hide
3753     * Install a package. Since this may take a little while, the result will be
3754     * posted back to the given observer. An installation will fail if the package named
3755     * in the package file's manifest is already installed, or if there's no space
3756     * available on the device.
3757     * @param packageURI The location of the package file to install. This can be a 'file:' or a
3758     * 'content:' URI.
3759     * @param observer An observer callback to get notified when the package installation is
3760     * complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
3761     * called when that happens. This parameter must not be null.
3762     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3763     * {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
3764     * @param installerPackageName Optional package name of the application that is performing the
3765     * installation. This identifies which market the package came from.
3766     * @param userId The user id.
3767     */
3768     @RequiresPermission(anyOf = {
3769            Manifest.permission.INSTALL_PACKAGES,
3770            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
3771    public abstract void installPackageAsUser(
3772            Uri packageURI, PackageInstallObserver observer, int flags,
3773            String installerPackageName, int userId);
3774
3775    /**
3776     * Similar to
3777     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3778     * with an extra verification file provided.
3779     *
3780     * @param packageURI The location of the package file to install. This can
3781     *            be a 'file:' or a 'content:' URI.
3782     * @param observer An observer callback to get notified when the package installation is
3783     * complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
3784     * called when that happens. This parameter must not be null.
3785     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3786     *            {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
3787     * @param installerPackageName Optional package name of the application that
3788     *            is performing the installation. This identifies which market
3789     *            the package came from.
3790     * @param verificationURI The location of the supplementary verification
3791     *            file. This can be a 'file:' or a 'content:' URI. May be
3792     *            {@code null}.
3793     * @param manifestDigest an object that holds the digest of the package
3794     *            which can be used to verify ownership. May be {@code null}.
3795     * @param encryptionParams if the package to be installed is encrypted,
3796     *            these parameters describing the encryption and authentication
3797     *            used. May be {@code null}.
3798     * @hide
3799     */
3800    public abstract void installPackageWithVerification(Uri packageURI,
3801            PackageInstallObserver observer, int flags, String installerPackageName,
3802            Uri verificationURI, ManifestDigest manifestDigest,
3803            ContainerEncryptionParams encryptionParams);
3804
3805    /**
3806     * Similar to
3807     * {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
3808     * with an extra verification information provided.
3809     *
3810     * @param packageURI The location of the package file to install. This can
3811     *            be a 'file:' or a 'content:' URI.
3812     * @param observer An observer callback to get notified when the package installation is
3813     * complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
3814     * called when that happens. This parameter must not be null.
3815     * @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
3816     *            {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
3817     * @param installerPackageName Optional package name of the application that
3818     *            is performing the installation. This identifies which market
3819     *            the package came from.
3820     * @param verificationParams an object that holds signal information to
3821     *            assist verification. May be {@code null}.
3822     * @param encryptionParams if the package to be installed is encrypted,
3823     *            these parameters describing the encryption and authentication
3824     *            used. May be {@code null}.
3825     *
3826     * @hide
3827     */
3828    public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
3829            PackageInstallObserver observer, int flags, String installerPackageName,
3830            VerificationParams verificationParams, ContainerEncryptionParams encryptionParams);
3831
3832    /**
3833     * If there is already an application with the given package name installed
3834     * on the system for other users, also install it for the calling user.
3835     * @hide
3836     */
3837    // @SystemApi
3838    public abstract int installExistingPackage(String packageName) throws NameNotFoundException;
3839
3840    /**
3841     * If there is already an application with the given package name installed
3842     * on the system for other users, also install it for the specified user.
3843     * @hide
3844     */
3845     @RequiresPermission(anyOf = {
3846            Manifest.permission.INSTALL_PACKAGES,
3847            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
3848    public abstract int installExistingPackageAsUser(String packageName, int userId)
3849            throws NameNotFoundException;
3850
3851    /**
3852     * Allows a package listening to the
3853     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
3854     * broadcast} to respond to the package manager. The response must include
3855     * the {@code verificationCode} which is one of
3856     * {@link PackageManager#VERIFICATION_ALLOW} or
3857     * {@link PackageManager#VERIFICATION_REJECT}.
3858     *
3859     * @param id pending package identifier as passed via the
3860     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
3861     * @param verificationCode either {@link PackageManager#VERIFICATION_ALLOW}
3862     *            or {@link PackageManager#VERIFICATION_REJECT}.
3863     * @throws SecurityException if the caller does not have the
3864     *            PACKAGE_VERIFICATION_AGENT permission.
3865     */
3866    public abstract void verifyPendingInstall(int id, int verificationCode);
3867
3868    /**
3869     * Allows a package listening to the
3870     * {@link Intent#ACTION_PACKAGE_NEEDS_VERIFICATION package verification
3871     * broadcast} to extend the default timeout for a response and declare what
3872     * action to perform after the timeout occurs. The response must include
3873     * the {@code verificationCodeAtTimeout} which is one of
3874     * {@link PackageManager#VERIFICATION_ALLOW} or
3875     * {@link PackageManager#VERIFICATION_REJECT}.
3876     *
3877     * This method may only be called once per package id. Additional calls
3878     * will have no effect.
3879     *
3880     * @param id pending package identifier as passed via the
3881     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
3882     * @param verificationCodeAtTimeout either
3883     *            {@link PackageManager#VERIFICATION_ALLOW} or
3884     *            {@link PackageManager#VERIFICATION_REJECT}. If
3885     *            {@code verificationCodeAtTimeout} is neither
3886     *            {@link PackageManager#VERIFICATION_ALLOW} or
3887     *            {@link PackageManager#VERIFICATION_REJECT}, then
3888     *            {@code verificationCodeAtTimeout} will default to
3889     *            {@link PackageManager#VERIFICATION_REJECT}.
3890     * @param millisecondsToDelay the amount of time requested for the timeout.
3891     *            Must be positive and less than
3892     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}. If
3893     *            {@code millisecondsToDelay} is out of bounds,
3894     *            {@code millisecondsToDelay} will be set to the closest in
3895     *            bounds value; namely, 0 or
3896     *            {@link PackageManager#MAXIMUM_VERIFICATION_TIMEOUT}.
3897     * @throws SecurityException if the caller does not have the
3898     *            PACKAGE_VERIFICATION_AGENT permission.
3899     */
3900    public abstract void extendVerificationTimeout(int id,
3901            int verificationCodeAtTimeout, long millisecondsToDelay);
3902
3903    /**
3904     * Allows a package listening to the
3905     * {@link Intent#ACTION_INTENT_FILTER_NEEDS_VERIFICATION intent filter verification
3906     * broadcast} to respond to the package manager. The response must include
3907     * the {@code verificationCode} which is one of
3908     * {@link PackageManager#INTENT_FILTER_VERIFICATION_SUCCESS} or
3909     * {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}.
3910     *
3911     * @param verificationId pending package identifier as passed via the
3912     *            {@link PackageManager#EXTRA_VERIFICATION_ID} Intent extra.
3913     * @param verificationCode either {@link PackageManager#INTENT_FILTER_VERIFICATION_SUCCESS}
3914     *            or {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}.
3915     * @param outFailedDomains a list of failed domains if the verificationCode is
3916     *            {@link PackageManager#INTENT_FILTER_VERIFICATION_FAILURE}, otherwise null;
3917     * @throws SecurityException if the caller does not have the
3918     *            INTENT_FILTER_VERIFICATION_AGENT permission.
3919     *
3920     * @hide
3921     */
3922    @SystemApi
3923    public abstract void verifyIntentFilter(int verificationId, int verificationCode,
3924            List<String> outFailedDomains);
3925
3926    /**
3927     * Get the status of a Domain Verification Result for an IntentFilter. This is
3928     * related to the {@link android.content.IntentFilter#setAutoVerify(boolean)} and
3929     * {@link android.content.IntentFilter#getAutoVerify()}
3930     *
3931     * This is used by the ResolverActivity to change the status depending on what the User select
3932     * in the Disambiguation Dialog and also used by the Settings App for changing the default App
3933     * for a domain.
3934     *
3935     * @param packageName The package name of the Activity associated with the IntentFilter.
3936     * @param userId The user id.
3937     *
3938     * @return The status to set to. This can be
3939     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK} or
3940     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS} or
3941     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER} or
3942     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED}
3943     *
3944     * @hide
3945     */
3946    public abstract int getIntentVerificationStatus(String packageName, int userId);
3947
3948    /**
3949     * Allow to change the status of a Intent Verification status for all IntentFilter of an App.
3950     * This is related to the {@link android.content.IntentFilter#setAutoVerify(boolean)} and
3951     * {@link android.content.IntentFilter#getAutoVerify()}
3952     *
3953     * This is used by the ResolverActivity to change the status depending on what the User select
3954     * in the Disambiguation Dialog and also used by the Settings App for changing the default App
3955     * for a domain.
3956     *
3957     * @param packageName The package name of the Activity associated with the IntentFilter.
3958     * @param status The status to set to. This can be
3959     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK} or
3960     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS} or
3961     *              {@link #INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER}
3962     * @param userId The user id.
3963     *
3964     * @return true if the status has been set. False otherwise.
3965     *
3966     * @hide
3967     */
3968    public abstract boolean updateIntentVerificationStatus(String packageName, int status,
3969            int userId);
3970
3971    /**
3972     * Get the list of IntentFilterVerificationInfo for a specific package and User.
3973     *
3974     * @param packageName the package name. When this parameter is set to a non null value,
3975     *                    the results will be filtered by the package name provided.
3976     *                    Otherwise, there will be no filtering and it will return a list
3977     *                    corresponding for all packages
3978     *
3979     * @return a list of IntentFilterVerificationInfo for a specific package.
3980     *
3981     * @hide
3982     */
3983    public abstract List<IntentFilterVerificationInfo> getIntentFilterVerifications(
3984            String packageName);
3985
3986    /**
3987     * Get the list of IntentFilter for a specific package.
3988     *
3989     * @param packageName the package name. This parameter is set to a non null value,
3990     *                    the list will contain all the IntentFilter for that package.
3991     *                    Otherwise, the list will be empty.
3992     *
3993     * @return a list of IntentFilter for a specific package.
3994     *
3995     * @hide
3996     */
3997    public abstract List<IntentFilter> getAllIntentFilters(String packageName);
3998
3999    /**
4000     * Get the default Browser package name for a specific user.
4001     *
4002     * @param userId The user id.
4003     *
4004     * @return the package name of the default Browser for the specified user. If the user id passed
4005     *         is -1 (all users) it will return a null value.
4006     *
4007     * @hide
4008     */
4009    public abstract String getDefaultBrowserPackageName(int userId);
4010
4011    /**
4012     * Set the default Browser package name for a specific user.
4013     *
4014     * @param packageName The package name of the default Browser.
4015     * @param userId The user id.
4016     *
4017     * @return true if the default Browser for the specified user has been set,
4018     *         otherwise return false. If the user id passed is -1 (all users) this call will not
4019     *         do anything and just return false.
4020     *
4021     * @hide
4022     */
4023    public abstract boolean setDefaultBrowserPackageName(String packageName, int userId);
4024
4025    /**
4026     * Change the installer associated with a given package.  There are limitations
4027     * on how the installer package can be changed; in particular:
4028     * <ul>
4029     * <li> A SecurityException will be thrown if <var>installerPackageName</var>
4030     * is not signed with the same certificate as the calling application.
4031     * <li> A SecurityException will be thrown if <var>targetPackage</var> already
4032     * has an installer package, and that installer package is not signed with
4033     * the same certificate as the calling application.
4034     * </ul>
4035     *
4036     * @param targetPackage The installed package whose installer will be changed.
4037     * @param installerPackageName The package name of the new installer.  May be
4038     * null to clear the association.
4039     */
4040    public abstract void setInstallerPackageName(String targetPackage,
4041            String installerPackageName);
4042
4043    /**
4044     * Attempts to delete a package.  Since this may take a little while, the result will
4045     * be posted back to the given observer.  A deletion will fail if the calling context
4046     * lacks the {@link android.Manifest.permission#DELETE_PACKAGES} permission, if the
4047     * named package cannot be found, or if the named package is a "system package".
4048     * (TODO: include pointer to documentation on "system packages")
4049     *
4050     * @param packageName The name of the package to delete
4051     * @param observer An observer callback to get notified when the package deletion is
4052     * complete. {@link android.content.pm.IPackageDeleteObserver#packageDeleted(boolean)} will be
4053     * called when that happens.  observer may be null to indicate that no callback is desired.
4054     * @param flags Possible values: {@link #DELETE_KEEP_DATA},
4055     * {@link #DELETE_ALL_USERS}.
4056     *
4057     * @hide
4058     */
4059    // @SystemApi
4060    public abstract void deletePackage(
4061            String packageName, IPackageDeleteObserver observer, int flags);
4062
4063    /**
4064     * Attempts to delete a package.  Since this may take a little while, the result will
4065     * be posted back to the given observer. A deletion will fail if the named package cannot be
4066     * found, or if the named package is a "system package".
4067     * (TODO: include pointer to documentation on "system packages")
4068     *
4069     * @param packageName The name of the package to delete
4070     * @param observer An observer callback to get notified when the package deletion is
4071     * complete. {@link android.content.pm.IPackageDeleteObserver#packageDeleted(boolean)} will be
4072     * called when that happens.  observer may be null to indicate that no callback is desired.
4073     * @param flags Possible values: {@link #DELETE_KEEP_DATA}, {@link #DELETE_ALL_USERS}.
4074     * @param userId The user Id
4075     *
4076     * @hide
4077     */
4078     @RequiresPermission(anyOf = {
4079            Manifest.permission.DELETE_PACKAGES,
4080            Manifest.permission.INTERACT_ACROSS_USERS_FULL})
4081    public abstract void deletePackageAsUser(
4082            String packageName, IPackageDeleteObserver observer, int flags, int userId);
4083
4084    /**
4085     * Retrieve the package name of the application that installed a package. This identifies
4086     * which market the package came from.
4087     *
4088     * @param packageName The name of the package to query
4089     */
4090    public abstract String getInstallerPackageName(String packageName);
4091
4092    /**
4093     * Attempts to clear the user data directory of an application.
4094     * Since this may take a little while, the result will
4095     * be posted back to the given observer.  A deletion will fail if the
4096     * named package cannot be found, or if the named package is a "system package".
4097     *
4098     * @param packageName The name of the package
4099     * @param observer An observer callback to get notified when the operation is finished
4100     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
4101     * will be called when that happens.  observer may be null to indicate that
4102     * no callback is desired.
4103     *
4104     * @hide
4105     */
4106    public abstract void clearApplicationUserData(String packageName,
4107            IPackageDataObserver observer);
4108    /**
4109     * Attempts to delete the cache files associated with an application.
4110     * Since this may take a little while, the result will
4111     * be posted back to the given observer.  A deletion will fail if the calling context
4112     * lacks the {@link android.Manifest.permission#DELETE_CACHE_FILES} permission, if the
4113     * named package cannot be found, or if the named package is a "system package".
4114     *
4115     * @param packageName The name of the package to delete
4116     * @param observer An observer callback to get notified when the cache file deletion
4117     * is complete.
4118     * {@link android.content.pm.IPackageDataObserver#onRemoveCompleted(String, boolean)}
4119     * will be called when that happens.  observer may be null to indicate that
4120     * no callback is desired.
4121     *
4122     * @hide
4123     */
4124    public abstract void deleteApplicationCacheFiles(String packageName,
4125            IPackageDataObserver observer);
4126
4127    /**
4128     * Free storage by deleting LRU sorted list of cache files across
4129     * all applications. If the currently available free storage
4130     * on the device is greater than or equal to the requested
4131     * free storage, no cache files are cleared. If the currently
4132     * available storage on the device is less than the requested
4133     * free storage, some or all of the cache files across
4134     * all applications are deleted (based on last accessed time)
4135     * to increase the free storage space on the device to
4136     * the requested value. There is no guarantee that clearing all
4137     * the cache files from all applications will clear up
4138     * enough storage to achieve the desired value.
4139     * @param freeStorageSize The number of bytes of storage to be
4140     * freed by the system. Say if freeStorageSize is XX,
4141     * and the current free storage is YY,
4142     * if XX is less than YY, just return. if not free XX-YY number
4143     * of bytes if possible.
4144     * @param observer call back used to notify when
4145     * the operation is completed
4146     *
4147     * @hide
4148     */
4149    // @SystemApi
4150    public void freeStorageAndNotify(long freeStorageSize, IPackageDataObserver observer) {
4151        freeStorageAndNotify(null, freeStorageSize, observer);
4152    }
4153
4154    /** {@hide} */
4155    public abstract void freeStorageAndNotify(String volumeUuid, long freeStorageSize,
4156            IPackageDataObserver observer);
4157
4158    /**
4159     * Free storage by deleting LRU sorted list of cache files across
4160     * all applications. If the currently available free storage
4161     * on the device is greater than or equal to the requested
4162     * free storage, no cache files are cleared. If the currently
4163     * available storage on the device is less than the requested
4164     * free storage, some or all of the cache files across
4165     * all applications are deleted (based on last accessed time)
4166     * to increase the free storage space on the device to
4167     * the requested value. There is no guarantee that clearing all
4168     * the cache files from all applications will clear up
4169     * enough storage to achieve the desired value.
4170     * @param freeStorageSize The number of bytes of storage to be
4171     * freed by the system. Say if freeStorageSize is XX,
4172     * and the current free storage is YY,
4173     * if XX is less than YY, just return. if not free XX-YY number
4174     * of bytes if possible.
4175     * @param pi IntentSender call back used to
4176     * notify when the operation is completed.May be null
4177     * to indicate that no call back is desired.
4178     *
4179     * @hide
4180     */
4181    public void freeStorage(long freeStorageSize, IntentSender pi) {
4182        freeStorage(null, freeStorageSize, pi);
4183    }
4184
4185    /** {@hide} */
4186    public abstract void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi);
4187
4188    /**
4189     * Retrieve the size information for a package.
4190     * Since this may take a little while, the result will
4191     * be posted back to the given observer.  The calling context
4192     * should have the {@link android.Manifest.permission#GET_PACKAGE_SIZE} permission.
4193     *
4194     * @param packageName The name of the package whose size information is to be retrieved
4195     * @param userHandle The user whose size information should be retrieved.
4196     * @param observer An observer callback to get notified when the operation
4197     * is complete.
4198     * {@link android.content.pm.IPackageStatsObserver#onGetStatsCompleted(PackageStats, boolean)}
4199     * The observer's callback is invoked with a PackageStats object(containing the
4200     * code, data and cache sizes of the package) and a boolean value representing
4201     * the status of the operation. observer may be null to indicate that
4202     * no callback is desired.
4203     *
4204     * @hide
4205     */
4206    public abstract void getPackageSizeInfo(String packageName, int userHandle,
4207            IPackageStatsObserver observer);
4208
4209    /**
4210     * Like {@link #getPackageSizeInfo(String, int, IPackageStatsObserver)}, but
4211     * returns the size for the calling user.
4212     *
4213     * @hide
4214     */
4215    public void getPackageSizeInfo(String packageName, IPackageStatsObserver observer) {
4216        getPackageSizeInfo(packageName, UserHandle.myUserId(), observer);
4217    }
4218
4219    /**
4220     * @deprecated This function no longer does anything; it was an old
4221     * approach to managing preferred activities, which has been superseded
4222     * by (and conflicts with) the modern activity-based preferences.
4223     */
4224    @Deprecated
4225    public abstract void addPackageToPreferred(String packageName);
4226
4227    /**
4228     * @deprecated This function no longer does anything; it was an old
4229     * approach to managing preferred activities, which has been superseded
4230     * by (and conflicts with) the modern activity-based preferences.
4231     */
4232    @Deprecated
4233    public abstract void removePackageFromPreferred(String packageName);
4234
4235    /**
4236     * Retrieve the list of all currently configured preferred packages.  The
4237     * first package on the list is the most preferred, the last is the
4238     * least preferred.
4239     *
4240     * @param flags Additional option flags. Use any combination of
4241     * {@link #GET_ACTIVITIES},
4242     * {@link #GET_GIDS},
4243     * {@link #GET_CONFIGURATIONS},
4244     * {@link #GET_INSTRUMENTATION},
4245     * {@link #GET_PERMISSIONS},
4246     * {@link #GET_PROVIDERS},
4247     * {@link #GET_RECEIVERS},
4248     * {@link #GET_SERVICES},
4249     * {@link #GET_SIGNATURES}, to modify the data returned.
4250     *
4251     * @return Returns a list of PackageInfo objects describing each
4252     * preferred application, in order of preference.
4253     *
4254     * @see #GET_ACTIVITIES
4255     * @see #GET_GIDS
4256     * @see #GET_CONFIGURATIONS
4257     * @see #GET_INSTRUMENTATION
4258     * @see #GET_PERMISSIONS
4259     * @see #GET_PROVIDERS
4260     * @see #GET_RECEIVERS
4261     * @see #GET_SERVICES
4262     * @see #GET_SIGNATURES
4263     */
4264    public abstract List<PackageInfo> getPreferredPackages(int flags);
4265
4266    /**
4267     * @deprecated This is a protected API that should not have been available
4268     * to third party applications.  It is the platform's responsibility for
4269     * assigning preferred activities and this cannot be directly modified.
4270     *
4271     * Add a new preferred activity mapping to the system.  This will be used
4272     * to automatically select the given activity component when
4273     * {@link Context#startActivity(Intent) Context.startActivity()} finds
4274     * multiple matching activities and also matches the given filter.
4275     *
4276     * @param filter The set of intents under which this activity will be
4277     * made preferred.
4278     * @param match The IntentFilter match category that this preference
4279     * applies to.
4280     * @param set The set of activities that the user was picking from when
4281     * this preference was made.
4282     * @param activity The component name of the activity that is to be
4283     * preferred.
4284     */
4285    @Deprecated
4286    public abstract void addPreferredActivity(IntentFilter filter, int match,
4287            ComponentName[] set, ComponentName activity);
4288
4289    /**
4290     * Same as {@link #addPreferredActivity(IntentFilter, int,
4291            ComponentName[], ComponentName)}, but with a specific userId to apply the preference
4292            to.
4293     * @hide
4294     */
4295    public void addPreferredActivity(IntentFilter filter, int match,
4296            ComponentName[] set, ComponentName activity, int userId) {
4297        throw new RuntimeException("Not implemented. Must override in a subclass.");
4298    }
4299
4300    /**
4301     * @deprecated This is a protected API that should not have been available
4302     * to third party applications.  It is the platform's responsibility for
4303     * assigning preferred activities and this cannot be directly modified.
4304     *
4305     * Replaces an existing preferred activity mapping to the system, and if that were not present
4306     * adds a new preferred activity.  This will be used
4307     * to automatically select the given activity component when
4308     * {@link Context#startActivity(Intent) Context.startActivity()} finds
4309     * multiple matching activities and also matches the given filter.
4310     *
4311     * @param filter The set of intents under which this activity will be
4312     * made preferred.
4313     * @param match The IntentFilter match category that this preference
4314     * applies to.
4315     * @param set The set of activities that the user was picking from when
4316     * this preference was made.
4317     * @param activity The component name of the activity that is to be
4318     * preferred.
4319     * @hide
4320     */
4321    @Deprecated
4322    public abstract void replacePreferredActivity(IntentFilter filter, int match,
4323            ComponentName[] set, ComponentName activity);
4324
4325    /**
4326     * @hide
4327     */
4328    @Deprecated
4329    public void replacePreferredActivityAsUser(IntentFilter filter, int match,
4330           ComponentName[] set, ComponentName activity, int userId) {
4331        throw new RuntimeException("Not implemented. Must override in a subclass.");
4332    }
4333
4334    /**
4335     * Remove all preferred activity mappings, previously added with
4336     * {@link #addPreferredActivity}, from the
4337     * system whose activities are implemented in the given package name.
4338     * An application can only clear its own package(s).
4339     *
4340     * @param packageName The name of the package whose preferred activity
4341     * mappings are to be removed.
4342     */
4343    public abstract void clearPackagePreferredActivities(String packageName);
4344
4345    /**
4346     * Retrieve all preferred activities, previously added with
4347     * {@link #addPreferredActivity}, that are
4348     * currently registered with the system.
4349     *
4350     * @param outFilters A required list in which to place the filters of all of the
4351     * preferred activities.
4352     * @param outActivities A required list in which to place the component names of
4353     * all of the preferred activities.
4354     * @param packageName An optional package in which you would like to limit
4355     * the list.  If null, all activities will be returned; if non-null, only
4356     * those activities in the given package are returned.
4357     *
4358     * @return Returns the total number of registered preferred activities
4359     * (the number of distinct IntentFilter records, not the number of unique
4360     * activity components) that were found.
4361     */
4362    public abstract int getPreferredActivities(@NonNull List<IntentFilter> outFilters,
4363            @NonNull List<ComponentName> outActivities, String packageName);
4364
4365    /**
4366     * Ask for the set of available 'home' activities and the current explicit
4367     * default, if any.
4368     * @hide
4369     */
4370    public abstract ComponentName getHomeActivities(List<ResolveInfo> outActivities);
4371
4372    /**
4373     * Set the enabled setting for a package component (activity, receiver, service, provider).
4374     * This setting will override any enabled state which may have been set by the component in its
4375     * manifest.
4376     *
4377     * @param componentName The component to enable
4378     * @param newState The new enabled state for the component.  The legal values for this state
4379     *                 are:
4380     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
4381     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
4382     *                   and
4383     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
4384     *                 The last one removes the setting, thereby restoring the component's state to
4385     *                 whatever was set in it's manifest (or enabled, by default).
4386     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
4387     */
4388    public abstract void setComponentEnabledSetting(ComponentName componentName,
4389            int newState, int flags);
4390
4391
4392    /**
4393     * Return the enabled setting for a package component (activity,
4394     * receiver, service, provider).  This returns the last value set by
4395     * {@link #setComponentEnabledSetting(ComponentName, int, int)}; in most
4396     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
4397     * the value originally specified in the manifest has not been modified.
4398     *
4399     * @param componentName The component to retrieve.
4400     * @return Returns the current enabled state for the component.  May
4401     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
4402     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
4403     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
4404     * component's enabled state is based on the original information in
4405     * the manifest as found in {@link ComponentInfo}.
4406     */
4407    public abstract int getComponentEnabledSetting(ComponentName componentName);
4408
4409    /**
4410     * Set the enabled setting for an application
4411     * This setting will override any enabled state which may have been set by the application in
4412     * its manifest.  It also overrides the enabled state set in the manifest for any of the
4413     * application's components.  It does not override any enabled state set by
4414     * {@link #setComponentEnabledSetting} for any of the application's components.
4415     *
4416     * @param packageName The package name of the application to enable
4417     * @param newState The new enabled state for the component.  The legal values for this state
4418     *                 are:
4419     *                   {@link #COMPONENT_ENABLED_STATE_ENABLED},
4420     *                   {@link #COMPONENT_ENABLED_STATE_DISABLED}
4421     *                   and
4422     *                   {@link #COMPONENT_ENABLED_STATE_DEFAULT}
4423     *                 The last one removes the setting, thereby restoring the applications's state to
4424     *                 whatever was set in its manifest (or enabled, by default).
4425     * @param flags Optional behavior flags: {@link #DONT_KILL_APP} or 0.
4426     */
4427    public abstract void setApplicationEnabledSetting(String packageName,
4428            int newState, int flags);
4429
4430    /**
4431     * Return the enabled setting for an application. This returns
4432     * the last value set by
4433     * {@link #setApplicationEnabledSetting(String, int, int)}; in most
4434     * cases this value will be {@link #COMPONENT_ENABLED_STATE_DEFAULT} since
4435     * the value originally specified in the manifest has not been modified.
4436     *
4437     * @param packageName The package name of the application to retrieve.
4438     * @return Returns the current enabled state for the application.  May
4439     * be one of {@link #COMPONENT_ENABLED_STATE_ENABLED},
4440     * {@link #COMPONENT_ENABLED_STATE_DISABLED}, or
4441     * {@link #COMPONENT_ENABLED_STATE_DEFAULT}.  The last one means the
4442     * application's enabled state is based on the original information in
4443     * the manifest as found in {@link ComponentInfo}.
4444     * @throws IllegalArgumentException if the named package does not exist.
4445     */
4446    public abstract int getApplicationEnabledSetting(String packageName);
4447
4448    /**
4449     * Puts the package in a hidden state, which is almost like an uninstalled state,
4450     * making the package unavailable, but it doesn't remove the data or the actual
4451     * package file. Application can be unhidden by either resetting the hidden state
4452     * or by installing it, such as with {@link #installExistingPackage(String)}
4453     * @hide
4454     */
4455    public abstract boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
4456            UserHandle userHandle);
4457
4458    /**
4459     * Returns the hidden state of a package.
4460     * @see #setApplicationHiddenSettingAsUser(String, boolean, UserHandle)
4461     * @hide
4462     */
4463    public abstract boolean getApplicationHiddenSettingAsUser(String packageName,
4464            UserHandle userHandle);
4465
4466    /**
4467     * Return whether the device has been booted into safe mode.
4468     */
4469    public abstract boolean isSafeMode();
4470
4471    /**
4472     * Adds a listener for permission changes for installed packages.
4473     *
4474     * @param listener The listener to add.
4475     *
4476     * @hide
4477     */
4478    @SystemApi
4479    @RequiresPermission(Manifest.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS)
4480    public abstract void addOnPermissionsChangeListener(OnPermissionsChangedListener listener);
4481
4482    /**
4483     * Remvoes a listener for permission changes for installed packages.
4484     *
4485     * @param listener The listener to remove.
4486     *
4487     * @hide
4488     */
4489    @SystemApi
4490    public abstract void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener);
4491
4492    /**
4493     * Return the {@link KeySet} associated with the String alias for this
4494     * application.
4495     *
4496     * @param alias The alias for a given {@link KeySet} as defined in the
4497     *        application's AndroidManifest.xml.
4498     * @hide
4499     */
4500    public abstract KeySet getKeySetByAlias(String packageName, String alias);
4501
4502    /** Return the signing {@link KeySet} for this application.
4503     * @hide
4504     */
4505    public abstract KeySet getSigningKeySet(String packageName);
4506
4507    /**
4508     * Return whether the package denoted by packageName has been signed by all
4509     * of the keys specified by the {@link KeySet} ks.  This will return true if
4510     * the package has been signed by additional keys (a superset) as well.
4511     * Compare to {@link #isSignedByExactly(String packageName, KeySet ks)}.
4512     * @hide
4513     */
4514    public abstract boolean isSignedBy(String packageName, KeySet ks);
4515
4516    /**
4517     * Return whether the package denoted by packageName has been signed by all
4518     * of, and only, the keys specified by the {@link KeySet} ks. Compare to
4519     * {@link #isSignedBy(String packageName, KeySet ks)}.
4520     * @hide
4521     */
4522    public abstract boolean isSignedByExactly(String packageName, KeySet ks);
4523
4524    /**
4525     * Attempts to move package resources from internal to external media or vice versa.
4526     * Since this may take a little while, the result will
4527     * be posted back to the given observer.   This call may fail if the calling context
4528     * lacks the {@link android.Manifest.permission#MOVE_PACKAGE} permission, if the
4529     * named package cannot be found, or if the named package is a "system package".
4530     *
4531     * @param packageName The name of the package to delete
4532     * @param observer An observer callback to get notified when the package move is
4533     * complete. {@link android.content.pm.IPackageMoveObserver#packageMoved(boolean)} will be
4534     * called when that happens.  observer may be null to indicate that no callback is desired.
4535     * @param flags To indicate install location {@link #MOVE_INTERNAL} or
4536     * {@link #MOVE_EXTERNAL_MEDIA}
4537     *
4538     * @hide
4539     */
4540    @Deprecated
4541    public void movePackage(String packageName, IPackageMoveObserver observer, int flags) {
4542        throw new UnsupportedOperationException();
4543    }
4544
4545    /** {@hide} */
4546    public static boolean isMoveStatusFinished(int status) {
4547        return (status < 0 || status > 100);
4548    }
4549
4550    /** {@hide} */
4551    public static abstract class MoveCallback {
4552        public void onCreated(int moveId, Bundle extras) {}
4553        public abstract void onStatusChanged(int moveId, int status, long estMillis);
4554    }
4555
4556    /** {@hide} */
4557    public abstract int getMoveStatus(int moveId);
4558
4559    /** {@hide} */
4560    public abstract void registerMoveCallback(MoveCallback callback, Handler handler);
4561    /** {@hide} */
4562    public abstract void unregisterMoveCallback(MoveCallback callback);
4563
4564    /** {@hide} */
4565    public abstract int movePackage(String packageName, VolumeInfo vol);
4566    /** {@hide} */
4567    public abstract @Nullable VolumeInfo getPackageCurrentVolume(ApplicationInfo app);
4568    /** {@hide} */
4569    public abstract @NonNull List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app);
4570
4571    /** {@hide} */
4572    public abstract int movePrimaryStorage(VolumeInfo vol);
4573    /** {@hide} */
4574    public abstract @Nullable VolumeInfo getPrimaryStorageCurrentVolume();
4575    /** {@hide} */
4576    public abstract @NonNull List<VolumeInfo> getPrimaryStorageCandidateVolumes();
4577
4578    /**
4579     * Returns the device identity that verifiers can use to associate their scheme to a particular
4580     * device. This should not be used by anything other than a package verifier.
4581     *
4582     * @return identity that uniquely identifies current device
4583     * @hide
4584     */
4585    public abstract VerifierDeviceIdentity getVerifierDeviceIdentity();
4586
4587    /**
4588     * Returns true if the device is upgrading, such as first boot after OTA.
4589     *
4590     * @hide
4591     */
4592    public abstract boolean isUpgrade();
4593
4594    /**
4595     * Return interface that offers the ability to install, upgrade, and remove
4596     * applications on the device.
4597     */
4598    public abstract @NonNull PackageInstaller getPackageInstaller();
4599
4600    /**
4601     * Adds a {@link CrossProfileIntentFilter}. After calling this method all intents sent from the
4602     * user with id sourceUserId can also be be resolved by activities in the user with id
4603     * targetUserId if they match the specified intent filter.
4604     * @param filter The {@link IntentFilter} the intent has to match
4605     * @param sourceUserId The source user id.
4606     * @param targetUserId The target user id.
4607     * @param flags The only possible value is {@link SKIP_CURRENT_PROFILE}
4608     * @hide
4609     */
4610    public abstract void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId,
4611            int targetUserId, int flags);
4612
4613    /**
4614     * Clearing {@link CrossProfileIntentFilter}s which have the specified user as their
4615     * source, and have been set by the app calling this method.
4616     * @param sourceUserId The source user id.
4617     * @hide
4618     */
4619    public abstract void clearCrossProfileIntentFilters(int sourceUserId);
4620
4621    /**
4622     * @hide
4623     */
4624    public abstract Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
4625
4626    /**
4627     * @hide
4628     */
4629    public abstract Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo);
4630
4631    /** {@hide} */
4632    public abstract boolean isPackageAvailable(String packageName);
4633
4634    /** {@hide} */
4635    public static String installStatusToString(int status, String msg) {
4636        final String str = installStatusToString(status);
4637        if (msg != null) {
4638            return str + ": " + msg;
4639        } else {
4640            return str;
4641        }
4642    }
4643
4644    /** {@hide} */
4645    public static String installStatusToString(int status) {
4646        switch (status) {
4647            case INSTALL_SUCCEEDED: return "INSTALL_SUCCEEDED";
4648            case INSTALL_FAILED_ALREADY_EXISTS: return "INSTALL_FAILED_ALREADY_EXISTS";
4649            case INSTALL_FAILED_INVALID_APK: return "INSTALL_FAILED_INVALID_APK";
4650            case INSTALL_FAILED_INVALID_URI: return "INSTALL_FAILED_INVALID_URI";
4651            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return "INSTALL_FAILED_INSUFFICIENT_STORAGE";
4652            case INSTALL_FAILED_DUPLICATE_PACKAGE: return "INSTALL_FAILED_DUPLICATE_PACKAGE";
4653            case INSTALL_FAILED_NO_SHARED_USER: return "INSTALL_FAILED_NO_SHARED_USER";
4654            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return "INSTALL_FAILED_UPDATE_INCOMPATIBLE";
4655            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return "INSTALL_FAILED_SHARED_USER_INCOMPATIBLE";
4656            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return "INSTALL_FAILED_MISSING_SHARED_LIBRARY";
4657            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return "INSTALL_FAILED_REPLACE_COULDNT_DELETE";
4658            case INSTALL_FAILED_DEXOPT: return "INSTALL_FAILED_DEXOPT";
4659            case INSTALL_FAILED_OLDER_SDK: return "INSTALL_FAILED_OLDER_SDK";
4660            case INSTALL_FAILED_CONFLICTING_PROVIDER: return "INSTALL_FAILED_CONFLICTING_PROVIDER";
4661            case INSTALL_FAILED_NEWER_SDK: return "INSTALL_FAILED_NEWER_SDK";
4662            case INSTALL_FAILED_TEST_ONLY: return "INSTALL_FAILED_TEST_ONLY";
4663            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE";
4664            case INSTALL_FAILED_MISSING_FEATURE: return "INSTALL_FAILED_MISSING_FEATURE";
4665            case INSTALL_FAILED_CONTAINER_ERROR: return "INSTALL_FAILED_CONTAINER_ERROR";
4666            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return "INSTALL_FAILED_INVALID_INSTALL_LOCATION";
4667            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return "INSTALL_FAILED_MEDIA_UNAVAILABLE";
4668            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return "INSTALL_FAILED_VERIFICATION_TIMEOUT";
4669            case INSTALL_FAILED_VERIFICATION_FAILURE: return "INSTALL_FAILED_VERIFICATION_FAILURE";
4670            case INSTALL_FAILED_PACKAGE_CHANGED: return "INSTALL_FAILED_PACKAGE_CHANGED";
4671            case INSTALL_FAILED_UID_CHANGED: return "INSTALL_FAILED_UID_CHANGED";
4672            case INSTALL_FAILED_VERSION_DOWNGRADE: return "INSTALL_FAILED_VERSION_DOWNGRADE";
4673            case INSTALL_PARSE_FAILED_NOT_APK: return "INSTALL_PARSE_FAILED_NOT_APK";
4674            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return "INSTALL_PARSE_FAILED_BAD_MANIFEST";
4675            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return "INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION";
4676            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return "INSTALL_PARSE_FAILED_NO_CERTIFICATES";
4677            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return "INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES";
4678            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return "INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING";
4679            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return "INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME";
4680            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return "INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID";
4681            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return "INSTALL_PARSE_FAILED_MANIFEST_MALFORMED";
4682            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return "INSTALL_PARSE_FAILED_MANIFEST_EMPTY";
4683            case INSTALL_FAILED_INTERNAL_ERROR: return "INSTALL_FAILED_INTERNAL_ERROR";
4684            case INSTALL_FAILED_USER_RESTRICTED: return "INSTALL_FAILED_USER_RESTRICTED";
4685            case INSTALL_FAILED_DUPLICATE_PERMISSION: return "INSTALL_FAILED_DUPLICATE_PERMISSION";
4686            case INSTALL_FAILED_NO_MATCHING_ABIS: return "INSTALL_FAILED_NO_MATCHING_ABIS";
4687            case INSTALL_FAILED_ABORTED: return "INSTALL_FAILED_ABORTED";
4688            default: return Integer.toString(status);
4689        }
4690    }
4691
4692    /** {@hide} */
4693    public static int installStatusToPublicStatus(int status) {
4694        switch (status) {
4695            case INSTALL_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
4696            case INSTALL_FAILED_ALREADY_EXISTS: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4697            case INSTALL_FAILED_INVALID_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
4698            case INSTALL_FAILED_INVALID_URI: return PackageInstaller.STATUS_FAILURE_INVALID;
4699            case INSTALL_FAILED_INSUFFICIENT_STORAGE: return PackageInstaller.STATUS_FAILURE_STORAGE;
4700            case INSTALL_FAILED_DUPLICATE_PACKAGE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4701            case INSTALL_FAILED_NO_SHARED_USER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4702            case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4703            case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4704            case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4705            case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4706            case INSTALL_FAILED_DEXOPT: return PackageInstaller.STATUS_FAILURE_INVALID;
4707            case INSTALL_FAILED_OLDER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4708            case INSTALL_FAILED_CONFLICTING_PROVIDER: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4709            case INSTALL_FAILED_NEWER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4710            case INSTALL_FAILED_TEST_ONLY: return PackageInstaller.STATUS_FAILURE_INVALID;
4711            case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4712            case INSTALL_FAILED_MISSING_FEATURE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4713            case INSTALL_FAILED_CONTAINER_ERROR: return PackageInstaller.STATUS_FAILURE_STORAGE;
4714            case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return PackageInstaller.STATUS_FAILURE_STORAGE;
4715            case INSTALL_FAILED_MEDIA_UNAVAILABLE: return PackageInstaller.STATUS_FAILURE_STORAGE;
4716            case INSTALL_FAILED_VERIFICATION_TIMEOUT: return PackageInstaller.STATUS_FAILURE_ABORTED;
4717            case INSTALL_FAILED_VERIFICATION_FAILURE: return PackageInstaller.STATUS_FAILURE_ABORTED;
4718            case INSTALL_FAILED_PACKAGE_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
4719            case INSTALL_FAILED_UID_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID;
4720            case INSTALL_FAILED_VERSION_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
4721            case INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID;
4722            case INSTALL_PARSE_FAILED_NOT_APK: return PackageInstaller.STATUS_FAILURE_INVALID;
4723            case INSTALL_PARSE_FAILED_BAD_MANIFEST: return PackageInstaller.STATUS_FAILURE_INVALID;
4724            case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return PackageInstaller.STATUS_FAILURE_INVALID;
4725            case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
4726            case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID;
4727            case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return PackageInstaller.STATUS_FAILURE_INVALID;
4728            case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return PackageInstaller.STATUS_FAILURE_INVALID;
4729            case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return PackageInstaller.STATUS_FAILURE_INVALID;
4730            case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return PackageInstaller.STATUS_FAILURE_INVALID;
4731            case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return PackageInstaller.STATUS_FAILURE_INVALID;
4732            case INSTALL_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
4733            case INSTALL_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4734            case INSTALL_FAILED_DUPLICATE_PERMISSION: return PackageInstaller.STATUS_FAILURE_CONFLICT;
4735            case INSTALL_FAILED_NO_MATCHING_ABIS: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE;
4736            case INSTALL_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
4737            default: return PackageInstaller.STATUS_FAILURE;
4738        }
4739    }
4740
4741    /** {@hide} */
4742    public static String deleteStatusToString(int status, String msg) {
4743        final String str = deleteStatusToString(status);
4744        if (msg != null) {
4745            return str + ": " + msg;
4746        } else {
4747            return str;
4748        }
4749    }
4750
4751    /** {@hide} */
4752    public static String deleteStatusToString(int status) {
4753        switch (status) {
4754            case DELETE_SUCCEEDED: return "DELETE_SUCCEEDED";
4755            case DELETE_FAILED_INTERNAL_ERROR: return "DELETE_FAILED_INTERNAL_ERROR";
4756            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return "DELETE_FAILED_DEVICE_POLICY_MANAGER";
4757            case DELETE_FAILED_USER_RESTRICTED: return "DELETE_FAILED_USER_RESTRICTED";
4758            case DELETE_FAILED_OWNER_BLOCKED: return "DELETE_FAILED_OWNER_BLOCKED";
4759            case DELETE_FAILED_ABORTED: return "DELETE_FAILED_ABORTED";
4760            default: return Integer.toString(status);
4761        }
4762    }
4763
4764    /** {@hide} */
4765    public static int deleteStatusToPublicStatus(int status) {
4766        switch (status) {
4767            case DELETE_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS;
4768            case DELETE_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE;
4769            case DELETE_FAILED_DEVICE_POLICY_MANAGER: return PackageInstaller.STATUS_FAILURE_BLOCKED;
4770            case DELETE_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
4771            case DELETE_FAILED_OWNER_BLOCKED: return PackageInstaller.STATUS_FAILURE_BLOCKED;
4772            case DELETE_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED;
4773            default: return PackageInstaller.STATUS_FAILURE;
4774        }
4775    }
4776
4777    /** {@hide} */
4778    public static String permissionFlagToString(int flag) {
4779        switch (flag) {
4780            case FLAG_PERMISSION_GRANTED_BY_DEFAULT: return "GRANTED_BY_DEFAULT";
4781            case FLAG_PERMISSION_POLICY_FIXED: return "POLICY_FIXED";
4782            case FLAG_PERMISSION_SYSTEM_FIXED: return "SYSTEM_FIXED";
4783            case FLAG_PERMISSION_USER_SET: return "USER_SET";
4784            case FLAG_PERMISSION_REVOKE_ON_UPGRADE: return "REVOKE_ON_UPGRADE";
4785            case FLAG_PERMISSION_USER_FIXED: return "USER_FIXED";
4786            default: return Integer.toString(flag);
4787        }
4788    }
4789
4790    /** {@hide} */
4791    public static class LegacyPackageInstallObserver extends PackageInstallObserver {
4792        private final IPackageInstallObserver mLegacy;
4793
4794        public LegacyPackageInstallObserver(IPackageInstallObserver legacy) {
4795            mLegacy = legacy;
4796        }
4797
4798        @Override
4799        public void onPackageInstalled(String basePackageName, int returnCode, String msg,
4800                Bundle extras) {
4801            if (mLegacy == null) return;
4802            try {
4803                mLegacy.packageInstalled(basePackageName, returnCode);
4804            } catch (RemoteException ignored) {
4805            }
4806        }
4807    }
4808
4809    /** {@hide} */
4810    public static class LegacyPackageDeleteObserver extends PackageDeleteObserver {
4811        private final IPackageDeleteObserver mLegacy;
4812
4813        public LegacyPackageDeleteObserver(IPackageDeleteObserver legacy) {
4814            mLegacy = legacy;
4815        }
4816
4817        @Override
4818        public void onPackageDeleted(String basePackageName, int returnCode, String msg) {
4819            if (mLegacy == null) return;
4820            try {
4821                mLegacy.packageDeleted(basePackageName, returnCode);
4822            } catch (RemoteException ignored) {
4823            }
4824        }
4825    }
4826}
4827