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