Context.java revision df2dae01b065ef18b7de7f76b29a9857bf70f443
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;
18
19import android.annotation.IntDef;
20import android.annotation.NonNull;
21import android.annotation.Nullable;
22import android.annotation.StringDef;
23import android.content.pm.ApplicationInfo;
24import android.content.pm.PackageManager;
25import android.content.res.AssetManager;
26import android.content.res.Configuration;
27import android.content.res.Resources;
28import android.content.res.TypedArray;
29import android.database.DatabaseErrorHandler;
30import android.database.sqlite.SQLiteDatabase;
31import android.database.sqlite.SQLiteDatabase.CursorFactory;
32import android.graphics.Bitmap;
33import android.graphics.drawable.Drawable;
34import android.media.MediaScannerConnection.OnScanCompletedListener;
35import android.net.Uri;
36import android.os.Bundle;
37import android.os.Handler;
38import android.os.Looper;
39import android.os.UserHandle;
40import android.os.UserManager;
41import android.util.AttributeSet;
42import android.view.DisplayAdjustments;
43import android.view.Display;
44import android.view.WindowManager;
45
46import java.io.File;
47import java.io.FileInputStream;
48import java.io.FileNotFoundException;
49import java.io.FileOutputStream;
50import java.io.IOException;
51import java.io.InputStream;
52import java.lang.annotation.Retention;
53import java.lang.annotation.RetentionPolicy;
54
55/**
56 * Interface to global information about an application environment.  This is
57 * an abstract class whose implementation is provided by
58 * the Android system.  It
59 * allows access to application-specific resources and classes, as well as
60 * up-calls for application-level operations such as launching activities,
61 * broadcasting and receiving intents, etc.
62 */
63public abstract class Context {
64    /**
65     * File creation mode: the default mode, where the created file can only
66     * be accessed by the calling application (or all applications sharing the
67     * same user ID).
68     * @see #MODE_WORLD_READABLE
69     * @see #MODE_WORLD_WRITEABLE
70     */
71    public static final int MODE_PRIVATE = 0x0000;
72    /**
73     * @deprecated Creating world-readable files is very dangerous, and likely
74     * to cause security holes in applications.  It is strongly discouraged;
75     * instead, applications should use more formal mechanism for interactions
76     * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
77     * {@link android.app.Service}.  There are no guarantees that this
78     * access mode will remain on a file, such as when it goes through a
79     * backup and restore.
80     * File creation mode: allow all other applications to have read access
81     * to the created file.
82     * @see #MODE_PRIVATE
83     * @see #MODE_WORLD_WRITEABLE
84     */
85    @Deprecated
86    public static final int MODE_WORLD_READABLE = 0x0001;
87    /**
88     * @deprecated Creating world-writable files is very dangerous, and likely
89     * to cause security holes in applications.  It is strongly discouraged;
90     * instead, applications should use more formal mechanism for interactions
91     * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
92     * {@link android.app.Service}.  There are no guarantees that this
93     * access mode will remain on a file, such as when it goes through a
94     * backup and restore.
95     * File creation mode: allow all other applications to have write access
96     * to the created file.
97     * @see #MODE_PRIVATE
98     * @see #MODE_WORLD_READABLE
99     */
100    @Deprecated
101    public static final int MODE_WORLD_WRITEABLE = 0x0002;
102    /**
103     * File creation mode: for use with {@link #openFileOutput}, if the file
104     * already exists then write data to the end of the existing file
105     * instead of erasing it.
106     * @see #openFileOutput
107     */
108    public static final int MODE_APPEND = 0x8000;
109
110    /**
111     * SharedPreference loading flag: when set, the file on disk will
112     * be checked for modification even if the shared preferences
113     * instance is already loaded in this process.  This behavior is
114     * sometimes desired in cases where the application has multiple
115     * processes, all writing to the same SharedPreferences file.
116     * Generally there are better forms of communication between
117     * processes, though.
118     *
119     * <p>This was the legacy (but undocumented) behavior in and
120     * before Gingerbread (Android 2.3) and this flag is implied when
121     * targetting such releases.  For applications targetting SDK
122     * versions <em>greater than</em> Android 2.3, this flag must be
123     * explicitly set if desired.
124     *
125     * @see #getSharedPreferences
126     */
127    public static final int MODE_MULTI_PROCESS = 0x0004;
128
129    /**
130     * Database open flag: when set, the database is opened with write-ahead
131     * logging enabled by default.
132     *
133     * @see #openOrCreateDatabase(String, int, CursorFactory)
134     * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
135     * @see SQLiteDatabase#enableWriteAheadLogging
136     */
137    public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
138
139    /** @hide */
140    @IntDef(flag = true,
141            value = {
142                BIND_AUTO_CREATE,
143                BIND_AUTO_CREATE,
144                BIND_DEBUG_UNBIND,
145                BIND_NOT_FOREGROUND,
146                BIND_ABOVE_CLIENT,
147                BIND_ALLOW_OOM_MANAGEMENT,
148                BIND_WAIVE_PRIORITY
149            })
150    @Retention(RetentionPolicy.SOURCE)
151    public @interface BindServiceFlags {}
152
153    /**
154     * Flag for {@link #bindService}: automatically create the service as long
155     * as the binding exists.  Note that while this will create the service,
156     * its {@link android.app.Service#onStartCommand}
157     * method will still only be called due to an
158     * explicit call to {@link #startService}.  Even without that, though,
159     * this still provides you with access to the service object while the
160     * service is created.
161     *
162     * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
163     * not supplying this flag would also impact how important the system
164     * consider's the target service's process to be.  When set, the only way
165     * for it to be raised was by binding from a service in which case it will
166     * only be important when that activity is in the foreground.  Now to
167     * achieve this behavior you must explicitly supply the new flag
168     * {@link #BIND_ADJUST_WITH_ACTIVITY}.  For compatibility, old applications
169     * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
170     * the flags {@link #BIND_WAIVE_PRIORITY} and
171     * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
172     * the same result.
173     */
174    public static final int BIND_AUTO_CREATE = 0x0001;
175
176    /**
177     * Flag for {@link #bindService}: include debugging help for mismatched
178     * calls to unbind.  When this flag is set, the callstack of the following
179     * {@link #unbindService} call is retained, to be printed if a later
180     * incorrect unbind call is made.  Note that doing this requires retaining
181     * information about the binding that was made for the lifetime of the app,
182     * resulting in a leak -- this should only be used for debugging.
183     */
184    public static final int BIND_DEBUG_UNBIND = 0x0002;
185
186    /**
187     * Flag for {@link #bindService}: don't allow this binding to raise
188     * the target service's process to the foreground scheduling priority.
189     * It will still be raised to at least the same memory priority
190     * as the client (so that its process will not be killable in any
191     * situation where the client is not killable), but for CPU scheduling
192     * purposes it may be left in the background.  This only has an impact
193     * in the situation where the binding client is a foreground process
194     * and the target service is in a background process.
195     */
196    public static final int BIND_NOT_FOREGROUND = 0x0004;
197
198    /**
199     * Flag for {@link #bindService}: indicates that the client application
200     * binding to this service considers the service to be more important than
201     * the app itself.  When set, the platform will try to have the out of
202     * memory killer kill the app before it kills the service it is bound to, though
203     * this is not guaranteed to be the case.
204     */
205    public static final int BIND_ABOVE_CLIENT = 0x0008;
206
207    /**
208     * Flag for {@link #bindService}: allow the process hosting the bound
209     * service to go through its normal memory management.  It will be
210     * treated more like a running service, allowing the system to
211     * (temporarily) expunge the process if low on memory or for some other
212     * whim it may have, and being more aggressive about making it a candidate
213     * to be killed (and restarted) if running for a long time.
214     */
215    public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
216
217    /**
218     * Flag for {@link #bindService}: don't impact the scheduling or
219     * memory management priority of the target service's hosting process.
220     * Allows the service's process to be managed on the background LRU list
221     * just like a regular application process in the background.
222     */
223    public static final int BIND_WAIVE_PRIORITY = 0x0020;
224
225    /**
226     * Flag for {@link #bindService}: this service is very important to
227     * the client, so should be brought to the foreground process level
228     * when the client is.  Normally a process can only be raised to the
229     * visibility level by a client, even if that client is in the foreground.
230     */
231    public static final int BIND_IMPORTANT = 0x0040;
232
233    /**
234     * Flag for {@link #bindService}: If binding from an activity, allow the
235     * target service's process importance to be raised based on whether the
236     * activity is visible to the user, regardless whether another flag is
237     * used to reduce the amount that the client process's overall importance
238     * is used to impact it.
239     */
240    public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
241
242    /**
243     * @hide An idea that is not yet implemented.
244     * Flag for {@link #bindService}: If binding from an activity, consider
245     * this service to be visible like the binding activity is.  That is,
246     * it will be treated as something more important to keep around than
247     * invisible background activities.  This will impact the number of
248     * recent activities the user can switch between without having them
249     * restart.  There is no guarantee this will be respected, as the system
250     * tries to balance such requests from one app vs. the importantance of
251     * keeping other apps around.
252     */
253    public static final int BIND_VISIBLE = 0x10000000;
254
255    /**
256     * @hide
257     * Flag for {@link #bindService}: Consider this binding to be causing the target
258     * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
259     * away.
260     */
261    public static final int BIND_SHOWING_UI = 0x20000000;
262
263    /**
264     * Flag for {@link #bindService}: Don't consider the bound service to be
265     * visible, even if the caller is visible.
266     * @hide
267     */
268    public static final int BIND_NOT_VISIBLE = 0x40000000;
269
270    /** Return an AssetManager instance for your application's package. */
271    public abstract AssetManager getAssets();
272
273    /** Return a Resources instance for your application's package. */
274    public abstract Resources getResources();
275
276    /** Return PackageManager instance to find global package information. */
277    public abstract PackageManager getPackageManager();
278
279    /** Return a ContentResolver instance for your application's package. */
280    public abstract ContentResolver getContentResolver();
281
282    /**
283     * Return the Looper for the main thread of the current process.  This is
284     * the thread used to dispatch calls to application components (activities,
285     * services, etc).
286     * <p>
287     * By definition, this method returns the same result as would be obtained
288     * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
289     * </p>
290     *
291     * @return The main looper.
292     */
293    public abstract Looper getMainLooper();
294
295    /**
296     * Return the context of the single, global Application object of the
297     * current process.  This generally should only be used if you need a
298     * Context whose lifecycle is separate from the current context, that is
299     * tied to the lifetime of the process rather than the current component.
300     *
301     * <p>Consider for example how this interacts with
302     * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
303     * <ul>
304     * <li> <p>If used from an Activity context, the receiver is being registered
305     * within that activity.  This means that you are expected to unregister
306     * before the activity is done being destroyed; in fact if you do not do
307     * so, the framework will clean up your leaked registration as it removes
308     * the activity and log an error.  Thus, if you use the Activity context
309     * to register a receiver that is static (global to the process, not
310     * associated with an Activity instance) then that registration will be
311     * removed on you at whatever point the activity you used is destroyed.
312     * <li> <p>If used from the Context returned here, the receiver is being
313     * registered with the global state associated with your application.  Thus
314     * it will never be unregistered for you.  This is necessary if the receiver
315     * is associated with static data, not a particular component.  However
316     * using the ApplicationContext elsewhere can easily lead to serious leaks
317     * if you forget to unregister, unbind, etc.
318     * </ul>
319     */
320    public abstract Context getApplicationContext();
321
322    /**
323     * Add a new {@link ComponentCallbacks} to the base application of the
324     * Context, which will be called at the same times as the ComponentCallbacks
325     * methods of activities and other components are called.  Note that you
326     * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
327     * appropriate in the future; this will not be removed for you.
328     *
329     * @param callback The interface to call.  This can be either a
330     * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
331     */
332    public void registerComponentCallbacks(ComponentCallbacks callback) {
333        getApplicationContext().registerComponentCallbacks(callback);
334    }
335
336    /**
337     * Remove a {@link ComponentCallbacks} object that was previously registered
338     * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
339     */
340    public void unregisterComponentCallbacks(ComponentCallbacks callback) {
341        getApplicationContext().unregisterComponentCallbacks(callback);
342    }
343
344    /**
345     * Return a localized, styled CharSequence from the application's package's
346     * default string table.
347     *
348     * @param resId Resource id for the CharSequence text
349     */
350    public final CharSequence getText(int resId) {
351        return getResources().getText(resId);
352    }
353
354    /**
355     * Return a localized string from the application's package's
356     * default string table.
357     *
358     * @param resId Resource id for the string
359     */
360    public final String getString(int resId) {
361        return getResources().getString(resId);
362    }
363
364    /**
365     * Return a localized formatted string from the application's package's
366     * default string table, substituting the format arguments as defined in
367     * {@link java.util.Formatter} and {@link java.lang.String#format}.
368     *
369     * @param resId Resource id for the format string
370     * @param formatArgs The format arguments that will be used for substitution.
371     */
372
373    public final String getString(int resId, Object... formatArgs) {
374        return getResources().getString(resId, formatArgs);
375    }
376
377     /**
378     * Set the base theme for this context.  Note that this should be called
379     * before any views are instantiated in the Context (for example before
380     * calling {@link android.app.Activity#setContentView} or
381     * {@link android.view.LayoutInflater#inflate}).
382     *
383     * @param resid The style resource describing the theme.
384     */
385    public abstract void setTheme(int resid);
386
387    /** @hide Needed for some internal implementation...  not public because
388     * you can't assume this actually means anything. */
389    public int getThemeResId() {
390        return 0;
391    }
392
393    /**
394     * Return the Theme object associated with this Context.
395     */
396    public abstract Resources.Theme getTheme();
397
398    /**
399     * Retrieve styled attribute information in this Context's theme.  See
400     * {@link Resources.Theme#obtainStyledAttributes(int[])}
401     * for more information.
402     *
403     * @see Resources.Theme#obtainStyledAttributes(int[])
404     */
405    public final TypedArray obtainStyledAttributes(
406            int[] attrs) {
407        return getTheme().obtainStyledAttributes(attrs);
408    }
409
410    /**
411     * Retrieve styled attribute information in this Context's theme.  See
412     * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
413     * for more information.
414     *
415     * @see Resources.Theme#obtainStyledAttributes(int, int[])
416     */
417    public final TypedArray obtainStyledAttributes(
418            int resid, int[] attrs) throws Resources.NotFoundException {
419        return getTheme().obtainStyledAttributes(resid, attrs);
420    }
421
422    /**
423     * Retrieve styled attribute information in this Context's theme.  See
424     * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
425     * for more information.
426     *
427     * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
428     */
429    public final TypedArray obtainStyledAttributes(
430            AttributeSet set, int[] attrs) {
431        return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
432    }
433
434    /**
435     * Retrieve styled attribute information in this Context's theme.  See
436     * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
437     * for more information.
438     *
439     * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
440     */
441    public final TypedArray obtainStyledAttributes(
442            AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
443        return getTheme().obtainStyledAttributes(
444            set, attrs, defStyleAttr, defStyleRes);
445    }
446
447    /**
448     * Return a class loader you can use to retrieve classes in this package.
449     */
450    public abstract ClassLoader getClassLoader();
451
452    /** Return the name of this application's package. */
453    public abstract String getPackageName();
454
455    /** @hide Return the name of the base context this context is derived from. */
456    public abstract String getBasePackageName();
457
458    /** @hide Return the package name that should be used for app ops calls from
459     * this context.  This is the same as {@link #getBasePackageName()} except in
460     * cases where system components are loaded into other app processes, in which
461     * case this will be the name of the primary package in that process (so that app
462     * ops uid verification will work with the name). */
463    public abstract String getOpPackageName();
464
465    /** Return the full application info for this context's package. */
466    public abstract ApplicationInfo getApplicationInfo();
467
468    /**
469     * Return the full path to this context's primary Android package.
470     * The Android package is a ZIP file which contains the application's
471     * primary resources.
472     *
473     * <p>Note: this is not generally useful for applications, since they should
474     * not be directly accessing the file system.
475     *
476     * @return String Path to the resources.
477     */
478    public abstract String getPackageResourcePath();
479
480    /**
481     * Return the full path to this context's primary Android package.
482     * The Android package is a ZIP file which contains application's
483     * primary code and assets.
484     *
485     * <p>Note: this is not generally useful for applications, since they should
486     * not be directly accessing the file system.
487     *
488     * @return String Path to the code and assets.
489     */
490    public abstract String getPackageCodePath();
491
492    /**
493     * {@hide}
494     * Return the full path to the shared prefs file for the given prefs group name.
495     *
496     * <p>Note: this is not generally useful for applications, since they should
497     * not be directly accessing the file system.
498     */
499    public abstract File getSharedPrefsFile(String name);
500
501    /**
502     * Retrieve and hold the contents of the preferences file 'name', returning
503     * a SharedPreferences through which you can retrieve and modify its
504     * values.  Only one instance of the SharedPreferences object is returned
505     * to any callers for the same name, meaning they will see each other's
506     * edits as soon as they are made.
507     *
508     * @param name Desired preferences file. If a preferences file by this name
509     * does not exist, it will be created when you retrieve an
510     * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
511     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
512     * default operation, {@link #MODE_WORLD_READABLE}
513     * and {@link #MODE_WORLD_WRITEABLE} to control permissions.  The bit
514     * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
515     * are mutating the same SharedPreferences file.  {@link #MODE_MULTI_PROCESS}
516     * is always on in apps targeting Gingerbread (Android 2.3) and below, and
517     * off by default in later versions.
518     *
519     * @return The single {@link SharedPreferences} instance that can be used
520     *         to retrieve and modify the preference values.
521     *
522     * @see #MODE_PRIVATE
523     * @see #MODE_WORLD_READABLE
524     * @see #MODE_WORLD_WRITEABLE
525     * @see #MODE_MULTI_PROCESS
526     */
527    public abstract SharedPreferences getSharedPreferences(String name,
528            int mode);
529
530    /**
531     * Open a private file associated with this Context's application package
532     * for reading.
533     *
534     * @param name The name of the file to open; can not contain path
535     *             separators.
536     *
537     * @return The resulting {@link FileInputStream}.
538     *
539     * @see #openFileOutput
540     * @see #fileList
541     * @see #deleteFile
542     * @see java.io.FileInputStream#FileInputStream(String)
543     */
544    public abstract FileInputStream openFileInput(String name)
545        throws FileNotFoundException;
546
547    /**
548     * Open a private file associated with this Context's application package
549     * for writing.  Creates the file if it doesn't already exist.
550     *
551     * @param name The name of the file to open; can not contain path
552     *             separators.
553     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
554     * default operation, {@link #MODE_APPEND} to append to an existing file,
555     * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
556     * permissions.
557     *
558     * @return The resulting {@link FileOutputStream}.
559     *
560     * @see #MODE_APPEND
561     * @see #MODE_PRIVATE
562     * @see #MODE_WORLD_READABLE
563     * @see #MODE_WORLD_WRITEABLE
564     * @see #openFileInput
565     * @see #fileList
566     * @see #deleteFile
567     * @see java.io.FileOutputStream#FileOutputStream(String)
568     */
569    public abstract FileOutputStream openFileOutput(String name, int mode)
570        throws FileNotFoundException;
571
572    /**
573     * Delete the given private file associated with this Context's
574     * application package.
575     *
576     * @param name The name of the file to delete; can not contain path
577     *             separators.
578     *
579     * @return {@code true} if the file was successfully deleted; else
580     *         {@code false}.
581     *
582     * @see #openFileInput
583     * @see #openFileOutput
584     * @see #fileList
585     * @see java.io.File#delete()
586     */
587    public abstract boolean deleteFile(String name);
588
589    /**
590     * Returns the absolute path on the filesystem where a file created with
591     * {@link #openFileOutput} is stored.
592     *
593     * @param name The name of the file for which you would like to get
594     *          its path.
595     *
596     * @return An absolute path to the given file.
597     *
598     * @see #openFileOutput
599     * @see #getFilesDir
600     * @see #getDir
601     */
602    public abstract File getFileStreamPath(String name);
603
604    /**
605     * Returns the absolute path to the directory on the filesystem where
606     * files created with {@link #openFileOutput} are stored.
607     *
608     * @return The path of the directory holding application files.
609     *
610     * @see #openFileOutput
611     * @see #getFileStreamPath
612     * @see #getDir
613     */
614    public abstract File getFilesDir();
615
616    /**
617     * Returns the absolute path to the directory on the external filesystem
618     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
619     * Environment.getExternalStorageDirectory()}) where the application can
620     * place persistent files it owns.  These files are internal to the
621     * applications, and not typically visible to the user as media.
622     *
623     * <p>This is like {@link #getFilesDir()} in that these
624     * files will be deleted when the application is uninstalled, however there
625     * are some important differences:
626     *
627     * <ul>
628     * <li>External files are not always available: they will disappear if the
629     * user mounts the external storage on a computer or removes it.  See the
630     * APIs on {@link android.os.Environment} for information in the storage state.
631     * <li>There is no security enforced with these files.  All applications
632     * can read and write files placed here.
633     * </ul>
634     *
635     * <p>On devices with multiple users (as described by {@link UserManager}),
636     * each user has their own isolated external storage. Applications only
637     * have access to the external storage for the user they're running as.</p>
638     *
639     * <p>Here is an example of typical code to manipulate a file in
640     * an application's private storage:</p>
641     *
642     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
643     * private_file}
644     *
645     * <p>If you supply a non-null <var>type</var> to this function, the returned
646     * file will be a path to a sub-directory of the given type.  Though these files
647     * are not automatically scanned by the media scanner, you can explicitly
648     * add them to the media database with
649     * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
650     *      OnScanCompletedListener) MediaScannerConnection.scanFile}.
651     * Note that this is not the same as
652     * {@link android.os.Environment#getExternalStoragePublicDirectory
653     * Environment.getExternalStoragePublicDirectory()}, which provides
654     * directories of media shared by all applications.  The
655     * directories returned here are
656     * owned by the application, and their contents will be removed when the
657     * application is uninstalled.  Unlike
658     * {@link android.os.Environment#getExternalStoragePublicDirectory
659     * Environment.getExternalStoragePublicDirectory()}, the directory
660     * returned here will be automatically created for you.
661     *
662     * <p>Here is an example of typical code to manipulate a picture in
663     * an application's private storage and add it to the media database:</p>
664     *
665     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
666     * private_picture}
667     * <p>
668     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
669     * permissions are required for the owning application to read or write to
670     * this path. Otherwise, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
671     * or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
672     *
673     * @param type The type of files directory to return.  May be null for
674     * the root of the files directory or one of
675     * the following Environment constants for a subdirectory:
676     * {@link android.os.Environment#DIRECTORY_MUSIC},
677     * {@link android.os.Environment#DIRECTORY_PODCASTS},
678     * {@link android.os.Environment#DIRECTORY_RINGTONES},
679     * {@link android.os.Environment#DIRECTORY_ALARMS},
680     * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
681     * {@link android.os.Environment#DIRECTORY_PICTURES}, or
682     * {@link android.os.Environment#DIRECTORY_MOVIES}.
683     *
684     * @return The path of the directory holding application files
685     * on external storage.  Returns null if external storage is not currently
686     * mounted so it could not ensure the path exists; you will need to call
687     * this method again when it is available.
688     *
689     * @see #getFilesDir
690     * @see android.os.Environment#getExternalStoragePublicDirectory
691     */
692    @Nullable
693    public abstract File getExternalFilesDir(@Nullable String type);
694
695    /**
696     * Returns absolute paths to application-specific directories on all
697     * external storage devices where the application can place persistent files
698     * it owns. These files are internal to the application, and not typically
699     * visible to the user as media.
700     * <p>
701     * External storage devices returned here are considered a permanent part of
702     * the device, including both emulated external storage and physical media
703     * slots. This does not include transient devices, such as USB flash drives.
704     * <p>
705     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
706     * permissions are required for the owning application to read or write to
707     * these paths.
708     * <p>
709     * The returned paths include any path that would be returned by
710     * {@link #getExternalFilesDir(String)}.
711     *
712     * @see #getExternalFilesDir(String)
713     */
714    public abstract File[] getExternalFilesDirs(String type);
715
716    /**
717     * Return the directory where this application's OBB files (if there are
718     * any) can be found. Note if the application does not have any OBB files,
719     * this directory may not exist.
720     * <p>
721     * On devices with multiple users (as described by {@link UserManager}),
722     * multiple users may share the same OBB storage location. Applications
723     * should ensure that multiple instances running under different users don't
724     * interfere with each other.
725     * <p>
726     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
727     * permissions are required for the owning application to read or write to
728     * this path. Otherwise,
729     * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} or
730     * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
731     */
732    public abstract File getObbDir();
733
734    /**
735     * Returns absolute paths to application-specific directories on all
736     * external storage devices where the application's OBB files (if there are
737     * any) can be found. Note if the application does not have any OBB files,
738     * these directories may not exist.
739     * <p>
740     * External storage devices returned here are considered a permanent part of
741     * the device, including both emulated external storage and physical media
742     * slots. This does not include transient devices, such as USB flash drives.
743     * <p>
744     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
745     * permissions are required for the owning application to read or write to
746     * this path.
747     * <p>
748     * The returned paths include any path that would be returned by
749     * {@link #getObbDir()}
750     *
751     * @see #getObbDir()
752     */
753    public abstract File[] getObbDirs();
754
755    /**
756     * Returns the absolute path to the application specific cache directory
757     * on the filesystem. These files will be ones that get deleted first when the
758     * device runs low on storage.
759     * There is no guarantee when these files will be deleted.
760     *
761     * <strong>Note: you should not <em>rely</em> on the system deleting these
762     * files for you; you should always have a reasonable maximum, such as 1 MB,
763     * for the amount of space you consume with cache files, and prune those
764     * files when exceeding that space.</strong>
765     *
766     * @return The path of the directory holding application cache files.
767     *
768     * @see #openFileOutput
769     * @see #getFileStreamPath
770     * @see #getDir
771     */
772    public abstract File getCacheDir();
773
774    /**
775     * Returns the absolute path to the directory on the external filesystem
776     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
777     * Environment.getExternalStorageDirectory()} where the application can
778     * place cache files it owns. These files are internal to the application, and
779     * not typically visible to the user as media.
780     *
781     * <p>This is like {@link #getCacheDir()} in that these
782     * files will be deleted when the application is uninstalled, however there
783     * are some important differences:
784     *
785     * <ul>
786     * <li>The platform does not always monitor the space available in external
787     * storage, and thus may not automatically delete these files.  Currently
788     * the only time files here will be deleted by the platform is when running
789     * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
790     * {@link android.os.Environment#isExternalStorageEmulated()
791     * Environment.isExternalStorageEmulated()} returns true.  Note that you should
792     * be managing the maximum space you will use for these anyway, just like
793     * with {@link #getCacheDir()}.
794     * <li>External files are not always available: they will disappear if the
795     * user mounts the external storage on a computer or removes it.  See the
796     * APIs on {@link android.os.Environment} for information in the storage state.
797     * <li>There is no security enforced with these files.  All applications
798     * can read and write files placed here.
799     * </ul>
800     *
801     * <p>On devices with multiple users (as described by {@link UserManager}),
802     * each user has their own isolated external storage. Applications only
803     * have access to the external storage for the user they're running as.</p>
804     * <p>
805     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
806     * permissions are required for the owning application to read or write to
807     * this path. Otherwise,
808     * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} or
809     * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
810     *
811     * @return The path of the directory holding application cache files
812     * on external storage.  Returns null if external storage is not currently
813     * mounted so it could not ensure the path exists; you will need to call
814     * this method again when it is available.
815     *
816     * @see #getCacheDir
817     */
818    @Nullable
819    public abstract File getExternalCacheDir();
820
821    /**
822     * Returns absolute paths to application-specific directories on all
823     * external storage devices where the application can place cache files it
824     * owns. These files are internal to the application, and not typically
825     * visible to the user as media.
826     * <p>
827     * External storage devices returned here are considered a permanent part of
828     * the device, including both emulated external storage and physical media
829     * slots. This does not include transient devices, such as USB flash drives.
830     * <p>
831     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
832     * permissions are required for the owning application to read or write to
833     * these paths.
834     * <p>
835     * The returned paths include any path that would be returned by
836     * {@link #getExternalCacheDir()}.
837     *
838     * @see #getExternalCacheDir()
839     */
840    public abstract File[] getExternalCacheDirs();
841
842    /**
843     * Returns an array of strings naming the private files associated with
844     * this Context's application package.
845     *
846     * @return Array of strings naming the private files.
847     *
848     * @see #openFileInput
849     * @see #openFileOutput
850     * @see #deleteFile
851     */
852    public abstract String[] fileList();
853
854    /**
855     * Retrieve, creating if needed, a new directory in which the application
856     * can place its own custom data files.  You can use the returned File
857     * object to create and access files in this directory.  Note that files
858     * created through a File object will only be accessible by your own
859     * application; you can only set the mode of the entire directory, not
860     * of individual files.
861     *
862     * @param name Name of the directory to retrieve.  This is a directory
863     * that is created as part of your application data.
864     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
865     * default operation, {@link #MODE_WORLD_READABLE} and
866     * {@link #MODE_WORLD_WRITEABLE} to control permissions.
867     *
868     * @return A {@link File} object for the requested directory.  The directory
869     * will have been created if it does not already exist.
870     *
871     * @see #openFileOutput(String, int)
872     */
873    public abstract File getDir(String name, int mode);
874
875    /**
876     * Open a new private SQLiteDatabase associated with this Context's
877     * application package.  Create the database file if it doesn't exist.
878     *
879     * @param name The name (unique in the application package) of the database.
880     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
881     *     default operation, {@link #MODE_WORLD_READABLE}
882     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
883     *     Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
884     * @param factory An optional factory class that is called to instantiate a
885     *     cursor when query is called.
886     *
887     * @return The contents of a newly created database with the given name.
888     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
889     *
890     * @see #MODE_PRIVATE
891     * @see #MODE_WORLD_READABLE
892     * @see #MODE_WORLD_WRITEABLE
893     * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
894     * @see #deleteDatabase
895     */
896    public abstract SQLiteDatabase openOrCreateDatabase(String name,
897            int mode, CursorFactory factory);
898
899    /**
900     * Open a new private SQLiteDatabase associated with this Context's
901     * application package.  Creates the database file if it doesn't exist.
902     *
903     * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
904     * used to handle corruption when sqlite reports database corruption.</p>
905     *
906     * @param name The name (unique in the application package) of the database.
907     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
908     *     default operation, {@link #MODE_WORLD_READABLE}
909     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
910     *     Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
911     * @param factory An optional factory class that is called to instantiate a
912     *     cursor when query is called.
913     * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
914     * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
915     * @return The contents of a newly created database with the given name.
916     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
917     *
918     * @see #MODE_PRIVATE
919     * @see #MODE_WORLD_READABLE
920     * @see #MODE_WORLD_WRITEABLE
921     * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
922     * @see #deleteDatabase
923     */
924    public abstract SQLiteDatabase openOrCreateDatabase(String name,
925            int mode, CursorFactory factory,
926            @Nullable DatabaseErrorHandler errorHandler);
927
928    /**
929     * Delete an existing private SQLiteDatabase associated with this Context's
930     * application package.
931     *
932     * @param name The name (unique in the application package) of the
933     *             database.
934     *
935     * @return {@code true} if the database was successfully deleted; else {@code false}.
936     *
937     * @see #openOrCreateDatabase
938     */
939    public abstract boolean deleteDatabase(String name);
940
941    /**
942     * Returns the absolute path on the filesystem where a database created with
943     * {@link #openOrCreateDatabase} is stored.
944     *
945     * @param name The name of the database for which you would like to get
946     *          its path.
947     *
948     * @return An absolute path to the given database.
949     *
950     * @see #openOrCreateDatabase
951     */
952    public abstract File getDatabasePath(String name);
953
954    /**
955     * Returns an array of strings naming the private databases associated with
956     * this Context's application package.
957     *
958     * @return Array of strings naming the private databases.
959     *
960     * @see #openOrCreateDatabase
961     * @see #deleteDatabase
962     */
963    public abstract String[] databaseList();
964
965    /**
966     * @deprecated Use {@link android.app.WallpaperManager#getDrawable
967     * WallpaperManager.get()} instead.
968     */
969    @Deprecated
970    public abstract Drawable getWallpaper();
971
972    /**
973     * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
974     * WallpaperManager.peek()} instead.
975     */
976    @Deprecated
977    public abstract Drawable peekWallpaper();
978
979    /**
980     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
981     * WallpaperManager.getDesiredMinimumWidth()} instead.
982     */
983    @Deprecated
984    public abstract int getWallpaperDesiredMinimumWidth();
985
986    /**
987     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
988     * WallpaperManager.getDesiredMinimumHeight()} instead.
989     */
990    @Deprecated
991    public abstract int getWallpaperDesiredMinimumHeight();
992
993    /**
994     * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
995     * WallpaperManager.set()} instead.
996     * <p>This method requires the caller to hold the permission
997     * {@link android.Manifest.permission#SET_WALLPAPER}.
998     */
999    @Deprecated
1000    public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1001
1002    /**
1003     * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
1004     * WallpaperManager.set()} instead.
1005     * <p>This method requires the caller to hold the permission
1006     * {@link android.Manifest.permission#SET_WALLPAPER}.
1007     */
1008    @Deprecated
1009    public abstract void setWallpaper(InputStream data) throws IOException;
1010
1011    /**
1012     * @deprecated Use {@link android.app.WallpaperManager#clear
1013     * WallpaperManager.clear()} instead.
1014     * <p>This method requires the caller to hold the permission
1015     * {@link android.Manifest.permission#SET_WALLPAPER}.
1016     */
1017    @Deprecated
1018    public abstract void clearWallpaper() throws IOException;
1019
1020    /**
1021     * Same as {@link #startActivity(Intent, Bundle)} with no options
1022     * specified.
1023     *
1024     * @param intent The description of the activity to start.
1025     *
1026     * @throws ActivityNotFoundException &nbsp;
1027     *
1028     * @see #startActivity(Intent, Bundle)
1029     * @see PackageManager#resolveActivity
1030     */
1031    public abstract void startActivity(Intent intent);
1032
1033    /**
1034     * Version of {@link #startActivity(Intent)} that allows you to specify the
1035     * user the activity will be started for.  This is not available to applications
1036     * that are not pre-installed on the system image.  Using it requires holding
1037     * the INTERACT_ACROSS_USERS_FULL permission.
1038     * @param intent The description of the activity to start.
1039     * @param user The UserHandle of the user to start this activity for.
1040     * @throws ActivityNotFoundException &nbsp;
1041     * @hide
1042     */
1043    public void startActivityAsUser(Intent intent, UserHandle user) {
1044        throw new RuntimeException("Not implemented. Must override in a subclass.");
1045    }
1046
1047    /**
1048     * Launch a new activity.  You will not receive any information about when
1049     * the activity exits.
1050     *
1051     * <p>Note that if this method is being called from outside of an
1052     * {@link android.app.Activity} Context, then the Intent must include
1053     * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because,
1054     * without being started from an existing Activity, there is no existing
1055     * task in which to place the new activity and thus it needs to be placed
1056     * in its own separate task.
1057     *
1058     * <p>This method throws {@link ActivityNotFoundException}
1059     * if there was no Activity found to run the given Intent.
1060     *
1061     * @param intent The description of the activity to start.
1062     * @param options Additional options for how the Activity should be started.
1063     * May be null if there are no options.  See {@link android.app.ActivityOptions}
1064     * for how to build the Bundle supplied here; there are no supported definitions
1065     * for building it manually.
1066     *
1067     * @throws ActivityNotFoundException &nbsp;
1068     *
1069     * @see #startActivity(Intent)
1070     * @see PackageManager#resolveActivity
1071     */
1072    public abstract void startActivity(Intent intent, @Nullable Bundle options);
1073
1074    /**
1075     * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1076     * user the activity will be started for.  This is not available to applications
1077     * that are not pre-installed on the system image.  Using it requires holding
1078     * the INTERACT_ACROSS_USERS_FULL permission.
1079     * @param intent The description of the activity to start.
1080     * @param options Additional options for how the Activity should be started.
1081     * May be null if there are no options.  See {@link android.app.ActivityOptions}
1082     * for how to build the Bundle supplied here; there are no supported definitions
1083     * for building it manually.
1084     * @param userId The UserHandle of the user to start this activity for.
1085     * @throws ActivityNotFoundException &nbsp;
1086     * @hide
1087     */
1088    public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
1089        throw new RuntimeException("Not implemented. Must override in a subclass.");
1090    }
1091
1092    /**
1093     * Same as {@link #startActivities(Intent[], Bundle)} with no options
1094     * specified.
1095     *
1096     * @param intents An array of Intents to be started.
1097     *
1098     * @throws ActivityNotFoundException &nbsp;
1099     *
1100     * @see #startActivities(Intent[], Bundle)
1101     * @see PackageManager#resolveActivity
1102     */
1103    public abstract void startActivities(Intent[] intents);
1104
1105    /**
1106     * Launch multiple new activities.  This is generally the same as calling
1107     * {@link #startActivity(Intent)} for the first Intent in the array,
1108     * that activity during its creation calling {@link #startActivity(Intent)}
1109     * for the second entry, etc.  Note that unlike that approach, generally
1110     * none of the activities except the last in the array will be created
1111     * at this point, but rather will be created when the user first visits
1112     * them (due to pressing back from the activity on top).
1113     *
1114     * <p>This method throws {@link ActivityNotFoundException}
1115     * if there was no Activity found for <em>any</em> given Intent.  In this
1116     * case the state of the activity stack is undefined (some Intents in the
1117     * list may be on it, some not), so you probably want to avoid such situations.
1118     *
1119     * @param intents An array of Intents to be started.
1120     * @param options Additional options for how the Activity should be started.
1121     * See {@link android.content.Context#startActivity(Intent, Bundle)
1122     * Context.startActivity(Intent, Bundle)} for more details.
1123     *
1124     * @throws ActivityNotFoundException &nbsp;
1125     *
1126     * @see #startActivities(Intent[])
1127     * @see PackageManager#resolveActivity
1128     */
1129    public abstract void startActivities(Intent[] intents, Bundle options);
1130
1131    /**
1132     * @hide
1133     * Launch multiple new activities.  This is generally the same as calling
1134     * {@link #startActivity(Intent)} for the first Intent in the array,
1135     * that activity during its creation calling {@link #startActivity(Intent)}
1136     * for the second entry, etc.  Note that unlike that approach, generally
1137     * none of the activities except the last in the array will be created
1138     * at this point, but rather will be created when the user first visits
1139     * them (due to pressing back from the activity on top).
1140     *
1141     * <p>This method throws {@link ActivityNotFoundException}
1142     * if there was no Activity found for <em>any</em> given Intent.  In this
1143     * case the state of the activity stack is undefined (some Intents in the
1144     * list may be on it, some not), so you probably want to avoid such situations.
1145     *
1146     * @param intents An array of Intents to be started.
1147     * @param options Additional options for how the Activity should be started.
1148     * @param userHandle The user for whom to launch the activities
1149     * See {@link android.content.Context#startActivity(Intent, Bundle)
1150     * Context.startActivity(Intent, Bundle)} for more details.
1151     *
1152     * @throws ActivityNotFoundException &nbsp;
1153     *
1154     * @see #startActivities(Intent[])
1155     * @see PackageManager#resolveActivity
1156     */
1157    public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1158        throw new RuntimeException("Not implemented. Must override in a subclass.");
1159    }
1160
1161    /**
1162     * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1163     * with no options specified.
1164     *
1165     * @param intent The IntentSender to launch.
1166     * @param fillInIntent If non-null, this will be provided as the
1167     * intent parameter to {@link IntentSender#sendIntent}.
1168     * @param flagsMask Intent flags in the original IntentSender that you
1169     * would like to change.
1170     * @param flagsValues Desired values for any bits set in
1171     * <var>flagsMask</var>
1172     * @param extraFlags Always set to 0.
1173     *
1174     * @see #startActivity(Intent)
1175     * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1176     */
1177    public abstract void startIntentSender(IntentSender intent,
1178            Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1179            throws IntentSender.SendIntentException;
1180
1181    /**
1182     * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
1183     * to start.  If the IntentSender is for an activity, that activity will be started
1184     * as if you had called the regular {@link #startActivity(Intent)}
1185     * here; otherwise, its associated action will be executed (such as
1186     * sending a broadcast) as if you had called
1187     * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
1188     *
1189     * @param intent The IntentSender to launch.
1190     * @param fillInIntent If non-null, this will be provided as the
1191     * intent parameter to {@link IntentSender#sendIntent}.
1192     * @param flagsMask Intent flags in the original IntentSender that you
1193     * would like to change.
1194     * @param flagsValues Desired values for any bits set in
1195     * <var>flagsMask</var>
1196     * @param extraFlags Always set to 0.
1197     * @param options Additional options for how the Activity should be started.
1198     * See {@link android.content.Context#startActivity(Intent, Bundle)
1199     * Context.startActivity(Intent, Bundle)} for more details.  If options
1200     * have also been supplied by the IntentSender, options given here will
1201     * override any that conflict with those given by the IntentSender.
1202     *
1203     * @see #startActivity(Intent, Bundle)
1204     * @see #startIntentSender(IntentSender, Intent, int, int, int)
1205     */
1206    public abstract void startIntentSender(IntentSender intent,
1207            @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1208            Bundle options) throws IntentSender.SendIntentException;
1209
1210    /**
1211     * Broadcast the given intent to all interested BroadcastReceivers.  This
1212     * call is asynchronous; it returns immediately, and you will continue
1213     * executing while the receivers are run.  No results are propagated from
1214     * receivers and receivers can not abort the broadcast. If you want
1215     * to allow receivers to propagate results or abort the broadcast, you must
1216     * send an ordered broadcast using
1217     * {@link #sendOrderedBroadcast(Intent, String)}.
1218     *
1219     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1220     *
1221     * @param intent The Intent to broadcast; all receivers matching this
1222     *               Intent will receive the broadcast.
1223     *
1224     * @see android.content.BroadcastReceiver
1225     * @see #registerReceiver
1226     * @see #sendBroadcast(Intent, String)
1227     * @see #sendOrderedBroadcast(Intent, String)
1228     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1229     */
1230    public abstract void sendBroadcast(Intent intent);
1231
1232    /**
1233     * Broadcast the given intent to all interested BroadcastReceivers, allowing
1234     * an optional required permission to be enforced.  This
1235     * call is asynchronous; it returns immediately, and you will continue
1236     * executing while the receivers are run.  No results are propagated from
1237     * receivers and receivers can not abort the broadcast. If you want
1238     * to allow receivers to propagate results or abort the broadcast, you must
1239     * send an ordered broadcast using
1240     * {@link #sendOrderedBroadcast(Intent, String)}.
1241     *
1242     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1243     *
1244     * @param intent The Intent to broadcast; all receivers matching this
1245     *               Intent will receive the broadcast.
1246     * @param receiverPermission (optional) String naming a permission that
1247     *               a receiver must hold in order to receive your broadcast.
1248     *               If null, no permission is required.
1249     *
1250     * @see android.content.BroadcastReceiver
1251     * @see #registerReceiver
1252     * @see #sendBroadcast(Intent)
1253     * @see #sendOrderedBroadcast(Intent, String)
1254     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1255     */
1256    public abstract void sendBroadcast(Intent intent,
1257            @Nullable String receiverPermission);
1258
1259    /**
1260     * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
1261     * of an associated app op as per {@link android.app.AppOpsManager}.
1262     * @hide
1263     */
1264    public abstract void sendBroadcast(Intent intent,
1265            String receiverPermission, int appOp);
1266
1267    /**
1268     * Broadcast the given intent to all interested BroadcastReceivers, delivering
1269     * them one at a time to allow more preferred receivers to consume the
1270     * broadcast before it is delivered to less preferred receivers.  This
1271     * call is asynchronous; it returns immediately, and you will continue
1272     * executing while the receivers are run.
1273     *
1274     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1275     *
1276     * @param intent The Intent to broadcast; all receivers matching this
1277     *               Intent will receive the broadcast.
1278     * @param receiverPermission (optional) String naming a permissions that
1279     *               a receiver must hold in order to receive your broadcast.
1280     *               If null, no permission is required.
1281     *
1282     * @see android.content.BroadcastReceiver
1283     * @see #registerReceiver
1284     * @see #sendBroadcast(Intent)
1285     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1286     */
1287    public abstract void sendOrderedBroadcast(Intent intent,
1288            @Nullable String receiverPermission);
1289
1290    /**
1291     * Version of {@link #sendBroadcast(Intent)} that allows you to
1292     * receive data back from the broadcast.  This is accomplished by
1293     * supplying your own BroadcastReceiver when calling, which will be
1294     * treated as a final receiver at the end of the broadcast -- its
1295     * {@link BroadcastReceiver#onReceive} method will be called with
1296     * the result values collected from the other receivers.  The broadcast will
1297     * be serialized in the same way as calling
1298     * {@link #sendOrderedBroadcast(Intent, String)}.
1299     *
1300     * <p>Like {@link #sendBroadcast(Intent)}, this method is
1301     * asynchronous; it will return before
1302     * resultReceiver.onReceive() is called.
1303     *
1304     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1305     *
1306     * @param intent The Intent to broadcast; all receivers matching this
1307     *               Intent will receive the broadcast.
1308     * @param receiverPermission String naming a permissions that
1309     *               a receiver must hold in order to receive your broadcast.
1310     *               If null, no permission is required.
1311     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1312     *                       receiver of the broadcast.
1313     * @param scheduler A custom Handler with which to schedule the
1314     *                  resultReceiver callback; if null it will be
1315     *                  scheduled in the Context's main thread.
1316     * @param initialCode An initial value for the result code.  Often
1317     *                    Activity.RESULT_OK.
1318     * @param initialData An initial value for the result data.  Often
1319     *                    null.
1320     * @param initialExtras An initial value for the result extras.  Often
1321     *                      null.
1322     *
1323     * @see #sendBroadcast(Intent)
1324     * @see #sendBroadcast(Intent, String)
1325     * @see #sendOrderedBroadcast(Intent, String)
1326     * @see #sendStickyBroadcast(Intent)
1327     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1328     * @see android.content.BroadcastReceiver
1329     * @see #registerReceiver
1330     * @see android.app.Activity#RESULT_OK
1331     */
1332    public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1333            @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1334            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1335            @Nullable Bundle initialExtras);
1336
1337    /**
1338     * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1339     * int, String, android.os.Bundle)}, but also allows specification
1340     * of an associated app op as per {@link android.app.AppOpsManager}.
1341     * @hide
1342     */
1343    public abstract void sendOrderedBroadcast(Intent intent,
1344            String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1345            Handler scheduler, int initialCode, String initialData,
1346            Bundle initialExtras);
1347
1348    /**
1349     * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1350     * user the broadcast will be sent to.  This is not available to applications
1351     * that are not pre-installed on the system image.  Using it requires holding
1352     * the INTERACT_ACROSS_USERS permission.
1353     * @param intent The intent to broadcast
1354     * @param user UserHandle to send the intent to.
1355     * @see #sendBroadcast(Intent)
1356     */
1357    public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
1358
1359    /**
1360     * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1361     * user the broadcast will be sent to.  This is not available to applications
1362     * that are not pre-installed on the system image.  Using it requires holding
1363     * the INTERACT_ACROSS_USERS permission.
1364     *
1365     * @param intent The Intent to broadcast; all receivers matching this
1366     *               Intent will receive the broadcast.
1367     * @param user UserHandle to send the intent to.
1368     * @param receiverPermission (optional) String naming a permission that
1369     *               a receiver must hold in order to receive your broadcast.
1370     *               If null, no permission is required.
1371     *
1372     * @see #sendBroadcast(Intent, String)
1373     */
1374    public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1375            @Nullable String receiverPermission);
1376
1377    /**
1378     * Version of
1379     * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1380     * that allows you to specify the
1381     * user the broadcast will be sent to.  This is not available to applications
1382     * that are not pre-installed on the system image.  Using it requires holding
1383     * the INTERACT_ACROSS_USERS permission.
1384     *
1385     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1386     *
1387     * @param intent The Intent to broadcast; all receivers matching this
1388     *               Intent will receive the broadcast.
1389     * @param user UserHandle to send the intent to.
1390     * @param receiverPermission String naming a permissions that
1391     *               a receiver must hold in order to receive your broadcast.
1392     *               If null, no permission is required.
1393     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1394     *                       receiver of the broadcast.
1395     * @param scheduler A custom Handler with which to schedule the
1396     *                  resultReceiver callback; if null it will be
1397     *                  scheduled in the Context's main thread.
1398     * @param initialCode An initial value for the result code.  Often
1399     *                    Activity.RESULT_OK.
1400     * @param initialData An initial value for the result data.  Often
1401     *                    null.
1402     * @param initialExtras An initial value for the result extras.  Often
1403     *                      null.
1404     *
1405     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1406     */
1407    public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1408            @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1409            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1410            @Nullable  Bundle initialExtras);
1411
1412    /**
1413     * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1414     * Intent you are sending stays around after the broadcast is complete,
1415     * so that others can quickly retrieve that data through the return
1416     * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
1417     * all other ways, this behaves the same as
1418     * {@link #sendBroadcast(Intent)}.
1419     *
1420     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1421     * permission in order to use this API.  If you do not hold that
1422     * permission, {@link SecurityException} will be thrown.
1423     *
1424     * @param intent The Intent to broadcast; all receivers matching this
1425     * Intent will receive the broadcast, and the Intent will be held to
1426     * be re-broadcast to future receivers.
1427     *
1428     * @see #sendBroadcast(Intent)
1429     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1430     */
1431    public abstract void sendStickyBroadcast(Intent intent);
1432
1433    /**
1434     * Version of {@link #sendStickyBroadcast} that allows you to
1435     * receive data back from the broadcast.  This is accomplished by
1436     * supplying your own BroadcastReceiver when calling, which will be
1437     * treated as a final receiver at the end of the broadcast -- its
1438     * {@link BroadcastReceiver#onReceive} method will be called with
1439     * the result values collected from the other receivers.  The broadcast will
1440     * be serialized in the same way as calling
1441     * {@link #sendOrderedBroadcast(Intent, String)}.
1442     *
1443     * <p>Like {@link #sendBroadcast(Intent)}, this method is
1444     * asynchronous; it will return before
1445     * resultReceiver.onReceive() is called.  Note that the sticky data
1446     * stored is only the data you initially supply to the broadcast, not
1447     * the result of any changes made by the receivers.
1448     *
1449     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1450     *
1451     * @param intent The Intent to broadcast; all receivers matching this
1452     *               Intent will receive the broadcast.
1453     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1454     *                       receiver of the broadcast.
1455     * @param scheduler A custom Handler with which to schedule the
1456     *                  resultReceiver callback; if null it will be
1457     *                  scheduled in the Context's main thread.
1458     * @param initialCode An initial value for the result code.  Often
1459     *                    Activity.RESULT_OK.
1460     * @param initialData An initial value for the result data.  Often
1461     *                    null.
1462     * @param initialExtras An initial value for the result extras.  Often
1463     *                      null.
1464     *
1465     * @see #sendBroadcast(Intent)
1466     * @see #sendBroadcast(Intent, String)
1467     * @see #sendOrderedBroadcast(Intent, String)
1468     * @see #sendStickyBroadcast(Intent)
1469     * @see android.content.BroadcastReceiver
1470     * @see #registerReceiver
1471     * @see android.app.Activity#RESULT_OK
1472     */
1473    public abstract void sendStickyOrderedBroadcast(Intent intent,
1474            BroadcastReceiver resultReceiver,
1475            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1476            @Nullable Bundle initialExtras);
1477
1478    /**
1479     * Remove the data previously sent with {@link #sendStickyBroadcast},
1480     * so that it is as if the sticky broadcast had never happened.
1481     *
1482     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1483     * permission in order to use this API.  If you do not hold that
1484     * permission, {@link SecurityException} will be thrown.
1485     *
1486     * @param intent The Intent that was previously broadcast.
1487     *
1488     * @see #sendStickyBroadcast
1489     */
1490    public abstract void removeStickyBroadcast(Intent intent);
1491
1492    /**
1493     * Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
1494     * user the broadcast will be sent to.  This is not available to applications
1495     * that are not pre-installed on the system image.  Using it requires holding
1496     * the INTERACT_ACROSS_USERS permission.
1497     *
1498     * @param intent The Intent to broadcast; all receivers matching this
1499     * Intent will receive the broadcast, and the Intent will be held to
1500     * be re-broadcast to future receivers.
1501     * @param user UserHandle to send the intent to.
1502     *
1503     * @see #sendBroadcast(Intent)
1504     */
1505    public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1506
1507    /**
1508     * Version of
1509     * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1510     * that allows you to specify the
1511     * user the broadcast will be sent to.  This is not available to applications
1512     * that are not pre-installed on the system image.  Using it requires holding
1513     * the INTERACT_ACROSS_USERS permission.
1514     *
1515     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1516     *
1517     * @param intent The Intent to broadcast; all receivers matching this
1518     *               Intent will receive the broadcast.
1519     * @param user UserHandle to send the intent to.
1520     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1521     *                       receiver of the broadcast.
1522     * @param scheduler A custom Handler with which to schedule the
1523     *                  resultReceiver callback; if null it will be
1524     *                  scheduled in the Context's main thread.
1525     * @param initialCode An initial value for the result code.  Often
1526     *                    Activity.RESULT_OK.
1527     * @param initialData An initial value for the result data.  Often
1528     *                    null.
1529     * @param initialExtras An initial value for the result extras.  Often
1530     *                      null.
1531     *
1532     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1533     */
1534    public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1535            UserHandle user, BroadcastReceiver resultReceiver,
1536            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1537            @Nullable Bundle initialExtras);
1538
1539    /**
1540     * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
1541     * user the broadcast will be sent to.  This is not available to applications
1542     * that are not pre-installed on the system image.  Using it requires holding
1543     * the INTERACT_ACROSS_USERS permission.
1544     *
1545     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1546     * permission in order to use this API.  If you do not hold that
1547     * permission, {@link SecurityException} will be thrown.
1548     *
1549     * @param intent The Intent that was previously broadcast.
1550     * @param user UserHandle to remove the sticky broadcast from.
1551     *
1552     * @see #sendStickyBroadcastAsUser
1553     */
1554    public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1555
1556    /**
1557     * Register a BroadcastReceiver to be run in the main activity thread.  The
1558     * <var>receiver</var> will be called with any broadcast Intent that
1559     * matches <var>filter</var>, in the main application thread.
1560     *
1561     * <p>The system may broadcast Intents that are "sticky" -- these stay
1562     * around after the broadcast as finished, to be sent to any later
1563     * registrations. If your IntentFilter matches one of these sticky
1564     * Intents, that Intent will be returned by this function
1565     * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1566     * been broadcast.
1567     *
1568     * <p>There may be multiple sticky Intents that match <var>filter</var>,
1569     * in which case each of these will be sent to <var>receiver</var>.  In
1570     * this case, only one of these can be returned directly by the function;
1571     * which of these that is returned is arbitrarily decided by the system.
1572     *
1573     * <p>If you know the Intent your are registering for is sticky, you can
1574     * supply null for your <var>receiver</var>.  In this case, no receiver is
1575     * registered -- the function simply returns the sticky Intent that
1576     * matches <var>filter</var>.  In the case of multiple matches, the same
1577     * rules as described above apply.
1578     *
1579     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1580     *
1581     * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1582     * registered with this method will correctly respect the
1583     * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1584     * Prior to that, it would be ignored and delivered to all matching registered
1585     * receivers.  Be careful if using this for security.</p>
1586     *
1587     * <p class="note">Note: this method <em>cannot be called from a
1588     * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1589     * that is declared in an application's manifest.  It is okay, however, to call
1590     * this method from another BroadcastReceiver that has itself been registered
1591     * at run time with {@link #registerReceiver}, since the lifetime of such a
1592     * registered BroadcastReceiver is tied to the object that registered it.</p>
1593     *
1594     * @param receiver The BroadcastReceiver to handle the broadcast.
1595     * @param filter Selects the Intent broadcasts to be received.
1596     *
1597     * @return The first sticky intent found that matches <var>filter</var>,
1598     *         or null if there are none.
1599     *
1600     * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1601     * @see #sendBroadcast
1602     * @see #unregisterReceiver
1603     */
1604    @Nullable
1605    public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
1606                                            IntentFilter filter);
1607
1608    /**
1609     * Register to receive intent broadcasts, to run in the context of
1610     * <var>scheduler</var>.  See
1611     * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1612     * information.  This allows you to enforce permissions on who can
1613     * broadcast intents to your receiver, or have the receiver run in
1614     * a different thread than the main application thread.
1615     *
1616     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1617     *
1618     * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1619     * registered with this method will correctly respect the
1620     * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1621     * Prior to that, it would be ignored and delivered to all matching registered
1622     * receivers.  Be careful if using this for security.</p>
1623     *
1624     * @param receiver The BroadcastReceiver to handle the broadcast.
1625     * @param filter Selects the Intent broadcasts to be received.
1626     * @param broadcastPermission String naming a permissions that a
1627     *      broadcaster must hold in order to send an Intent to you.  If null,
1628     *      no permission is required.
1629     * @param scheduler Handler identifying the thread that will receive
1630     *      the Intent.  If null, the main thread of the process will be used.
1631     *
1632     * @return The first sticky intent found that matches <var>filter</var>,
1633     *         or null if there are none.
1634     *
1635     * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1636     * @see #sendBroadcast
1637     * @see #unregisterReceiver
1638     */
1639    @Nullable
1640    public abstract Intent registerReceiver(BroadcastReceiver receiver,
1641            IntentFilter filter, @Nullable String broadcastPermission,
1642            @Nullable Handler scheduler);
1643
1644    /**
1645     * @hide
1646     * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1647     * but for a specific user.  This receiver will receiver broadcasts that
1648     * are sent to the requested user.  It
1649     * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1650     * permission.
1651     *
1652     * @param receiver The BroadcastReceiver to handle the broadcast.
1653     * @param user UserHandle to send the intent to.
1654     * @param filter Selects the Intent broadcasts to be received.
1655     * @param broadcastPermission String naming a permissions that a
1656     *      broadcaster must hold in order to send an Intent to you.  If null,
1657     *      no permission is required.
1658     * @param scheduler Handler identifying the thread that will receive
1659     *      the Intent.  If null, the main thread of the process will be used.
1660     *
1661     * @return The first sticky intent found that matches <var>filter</var>,
1662     *         or null if there are none.
1663     *
1664     * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1665     * @see #sendBroadcast
1666     * @see #unregisterReceiver
1667     */
1668    @Nullable
1669    public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
1670            UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1671            @Nullable Handler scheduler);
1672
1673    /**
1674     * Unregister a previously registered BroadcastReceiver.  <em>All</em>
1675     * filters that have been registered for this BroadcastReceiver will be
1676     * removed.
1677     *
1678     * @param receiver The BroadcastReceiver to unregister.
1679     *
1680     * @see #registerReceiver
1681     */
1682    public abstract void unregisterReceiver(BroadcastReceiver receiver);
1683
1684    /**
1685     * Request that a given application service be started.  The Intent
1686     * should contain either contain the complete class name of a specific service
1687     * implementation to start or a specific package name to target.  If the
1688     * Intent is less specified, it will either throw an {@link IllegalArgumentException}
1689     * (if the caller targets {@link android.os.Build.VERSION_CODES#KITKAT} or later),
1690     * or which of multiple matching services it finds and uses will be undefined.  If this service
1691     * is not already running, it will be instantiated and started (creating a
1692     * process for it if needed); if it is running then it remains running.
1693     *
1694     * <p>Every call to this method will result in a corresponding call to
1695     * the target service's {@link android.app.Service#onStartCommand} method,
1696     * with the <var>intent</var> given here.  This provides a convenient way
1697     * to submit jobs to a service without having to bind and call on to its
1698     * interface.
1699     *
1700     * <p>Using startService() overrides the default service lifetime that is
1701     * managed by {@link #bindService}: it requires the service to remain
1702     * running until {@link #stopService} is called, regardless of whether
1703     * any clients are connected to it.  Note that calls to startService()
1704     * are not nesting: no matter how many times you call startService(),
1705     * a single call to {@link #stopService} will stop it.
1706     *
1707     * <p>The system attempts to keep running services around as much as
1708     * possible.  The only time they should be stopped is if the current
1709     * foreground application is using so many resources that the service needs
1710     * to be killed.  If any errors happen in the service's process, it will
1711     * automatically be restarted.
1712     *
1713     * <p>This function will throw {@link SecurityException} if you do not
1714     * have permission to start the given service.
1715     *
1716     * @param service Identifies the service to be started.  The Intent must be either
1717     *      fully explicit (supplying a component name) or specify a specific package
1718     *      name it is targetted to.  Additional values
1719     *      may be included in the Intent extras to supply arguments along with
1720     *      this specific start call.
1721     *
1722     * @return If the service is being started or is already running, the
1723     * {@link ComponentName} of the actual service that was started is
1724     * returned; else if the service does not exist null is returned.
1725     *
1726     * @throws SecurityException &nbsp;
1727     *
1728     * @see #stopService
1729     * @see #bindService
1730     */
1731    @Nullable
1732    public abstract ComponentName startService(Intent service);
1733
1734    /**
1735     * Request that a given application service be stopped.  If the service is
1736     * not running, nothing happens.  Otherwise it is stopped.  Note that calls
1737     * to startService() are not counted -- this stops the service no matter
1738     * how many times it was started.
1739     *
1740     * <p>Note that if a stopped service still has {@link ServiceConnection}
1741     * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1742     * not be destroyed until all of these bindings are removed.  See
1743     * the {@link android.app.Service} documentation for more details on a
1744     * service's lifecycle.
1745     *
1746     * <p>This function will throw {@link SecurityException} if you do not
1747     * have permission to stop the given service.
1748     *
1749     * @param service Description of the service to be stopped.  The Intent must be either
1750     *      fully explicit (supplying a component name) or specify a specific package
1751     *      name it is targetted to.
1752     *
1753     * @return If there is a service matching the given Intent that is already
1754     * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
1755     *
1756     * @throws SecurityException &nbsp;
1757     *
1758     * @see #startService
1759     */
1760    public abstract boolean stopService(Intent service);
1761
1762    /**
1763     * @hide like {@link #startService(Intent)} but for a specific user.
1764     */
1765    public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1766
1767    /**
1768     * @hide like {@link #stopService(Intent)} but for a specific user.
1769     */
1770    public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
1771
1772    /**
1773     * Connect to an application service, creating it if needed.  This defines
1774     * a dependency between your application and the service.  The given
1775     * <var>conn</var> will receive the service object when it is created and be
1776     * told if it dies and restarts.  The service will be considered required
1777     * by the system only for as long as the calling context exists.  For
1778     * example, if this Context is an Activity that is stopped, the service will
1779     * not be required to continue running until the Activity is resumed.
1780     *
1781     * <p>This function will throw {@link SecurityException} if you do not
1782     * have permission to bind to the given service.
1783     *
1784     * <p class="note">Note: this method <em>can not be called from a
1785     * {@link BroadcastReceiver} component</em>.  A pattern you can use to
1786     * communicate from a BroadcastReceiver to a Service is to call
1787     * {@link #startService} with the arguments containing the command to be
1788     * sent, with the service calling its
1789     * {@link android.app.Service#stopSelf(int)} method when done executing
1790     * that command.  See the API demo App/Service/Service Start Arguments
1791     * Controller for an illustration of this.  It is okay, however, to use
1792     * this method from a BroadcastReceiver that has been registered with
1793     * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1794     * is tied to another object (the one that registered it).</p>
1795     *
1796     * @param service Identifies the service to connect to.  The Intent may
1797     *      specify either an explicit component name, or a logical
1798     *      description (action, category, etc) to match an
1799     *      {@link IntentFilter} published by a service.
1800     * @param conn Receives information as the service is started and stopped.
1801     *      This must be a valid ServiceConnection object; it must not be null.
1802     * @param flags Operation options for the binding.  May be 0,
1803     *          {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1804     *          {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1805     *          {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1806     *          {@link #BIND_WAIVE_PRIORITY}.
1807     * @return If you have successfully bound to the service, {@code true} is returned;
1808     *         {@code false} is returned if the connection is not made so you will not
1809     *         receive the service object.
1810     *
1811     * @throws SecurityException &nbsp;
1812     *
1813     * @see #unbindService
1814     * @see #startService
1815     * @see #BIND_AUTO_CREATE
1816     * @see #BIND_DEBUG_UNBIND
1817     * @see #BIND_NOT_FOREGROUND
1818     */
1819    public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
1820            @BindServiceFlags int flags);
1821
1822    /**
1823     * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
1824     * argument for use by system server and other multi-user aware code.
1825     * @hide
1826     */
1827    public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
1828        throw new RuntimeException("Not implemented. Must override in a subclass.");
1829    }
1830
1831    /**
1832     * Disconnect from an application service.  You will no longer receive
1833     * calls as the service is restarted, and the service is now allowed to
1834     * stop at any time.
1835     *
1836     * @param conn The connection interface previously supplied to
1837     *             bindService().  This parameter must not be null.
1838     *
1839     * @see #bindService
1840     */
1841    public abstract void unbindService(@NonNull ServiceConnection conn);
1842
1843    /**
1844     * Start executing an {@link android.app.Instrumentation} class.  The given
1845     * Instrumentation component will be run by killing its target application
1846     * (if currently running), starting the target process, instantiating the
1847     * instrumentation component, and then letting it drive the application.
1848     *
1849     * <p>This function is not synchronous -- it returns as soon as the
1850     * instrumentation has started and while it is running.
1851     *
1852     * <p>Instrumentation is normally only allowed to run against a package
1853     * that is either unsigned or signed with a signature that the
1854     * the instrumentation package is also signed with (ensuring the target
1855     * trusts the instrumentation).
1856     *
1857     * @param className Name of the Instrumentation component to be run.
1858     * @param profileFile Optional path to write profiling data as the
1859     * instrumentation runs, or null for no profiling.
1860     * @param arguments Additional optional arguments to pass to the
1861     * instrumentation, or null.
1862     *
1863     * @return {@code true} if the instrumentation was successfully started,
1864     * else {@code false} if it could not be found.
1865     */
1866    public abstract boolean startInstrumentation(@NonNull ComponentName className,
1867            @Nullable String profileFile, @Nullable Bundle arguments);
1868
1869    /** @hide */
1870    @StringDef({
1871            POWER_SERVICE,
1872            WINDOW_SERVICE,
1873            LAYOUT_INFLATER_SERVICE,
1874            ACCOUNT_SERVICE,
1875            ACTIVITY_SERVICE,
1876            ALARM_SERVICE,
1877            NOTIFICATION_SERVICE,
1878            ACCESSIBILITY_SERVICE,
1879            CAPTIONING_SERVICE,
1880            KEYGUARD_SERVICE,
1881            LOCATION_SERVICE,
1882            //@hide: COUNTRY_DETECTOR,
1883            SEARCH_SERVICE,
1884            SENSOR_SERVICE,
1885            STORAGE_SERVICE,
1886            WALLPAPER_SERVICE,
1887            VIBRATOR_SERVICE,
1888            //@hide: STATUS_BAR_SERVICE,
1889            CONNECTIVITY_SERVICE,
1890            //@hide: UPDATE_LOCK_SERVICE,
1891            //@hide: NETWORKMANAGEMENT_SERVICE,
1892            //@hide: NETWORK_STATS_SERVICE,
1893            //@hide: NETWORK_POLICY_SERVICE,
1894            WIFI_SERVICE,
1895            WIFI_P2P_SERVICE,
1896            NSD_SERVICE,
1897            AUDIO_SERVICE,
1898            MEDIA_ROUTER_SERVICE,
1899            TELEPHONY_SERVICE,
1900            CLIPBOARD_SERVICE,
1901            INPUT_METHOD_SERVICE,
1902            TEXT_SERVICES_MANAGER_SERVICE,
1903            //@hide: APPWIDGET_SERVICE,
1904            //@hide: BACKUP_SERVICE,
1905            DROPBOX_SERVICE,
1906            DEVICE_POLICY_SERVICE,
1907            UI_MODE_SERVICE,
1908            DOWNLOAD_SERVICE,
1909            NFC_SERVICE,
1910            BLUETOOTH_SERVICE,
1911            //@hide: SIP_SERVICE,
1912            USB_SERVICE,
1913            //@hide: SERIAL_SERVICE,
1914            INPUT_SERVICE,
1915            DISPLAY_SERVICE,
1916            //@hide: SCHEDULING_POLICY_SERVICE,
1917            USER_SERVICE,
1918            //@hide: APP_OPS_SERVICE
1919            CAMERA_SERVICE,
1920            PRINT_SERVICE
1921    })
1922    @Retention(RetentionPolicy.SOURCE)
1923    public @interface ServiceName {}
1924
1925    /**
1926     * Return the handle to a system-level service by name. The class of the
1927     * returned object varies by the requested name. Currently available names
1928     * are:
1929     *
1930     * <dl>
1931     *  <dt> {@link #WINDOW_SERVICE} ("window")
1932     *  <dd> The top-level window manager in which you can place custom
1933     *  windows.  The returned object is a {@link android.view.WindowManager}.
1934     *  <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
1935     *  <dd> A {@link android.view.LayoutInflater} for inflating layout resources
1936     *  in this context.
1937     *  <dt> {@link #ACTIVITY_SERVICE} ("activity")
1938     *  <dd> A {@link android.app.ActivityManager} for interacting with the
1939     *  global activity state of the system.
1940     *  <dt> {@link #POWER_SERVICE} ("power")
1941     *  <dd> A {@link android.os.PowerManager} for controlling power
1942     *  management.
1943     *  <dt> {@link #ALARM_SERVICE} ("alarm")
1944     *  <dd> A {@link android.app.AlarmManager} for receiving intents at the
1945     *  time of your choosing.
1946     *  <dt> {@link #NOTIFICATION_SERVICE} ("notification")
1947     *  <dd> A {@link android.app.NotificationManager} for informing the user
1948     *   of background events.
1949     *  <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
1950     *  <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
1951     *  <dt> {@link #LOCATION_SERVICE} ("location")
1952     *  <dd> A {@link android.location.LocationManager} for controlling location
1953     *   (e.g., GPS) updates.
1954     *  <dt> {@link #SEARCH_SERVICE} ("search")
1955     *  <dd> A {@link android.app.SearchManager} for handling search.
1956     *  <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
1957     *  <dd> A {@link android.os.Vibrator} for interacting with the vibrator
1958     *  hardware.
1959     *  <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
1960     *  <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
1961     *  handling management of network connections.
1962     *  <dt> {@link #WIFI_SERVICE} ("wifi")
1963     *  <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
1964     * Wi-Fi connectivity.
1965     * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
1966     * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
1967     * for management of input methods.
1968     * <dt> {@link #UI_MODE_SERVICE} ("uimode")
1969     * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
1970     * <dt> {@link #DOWNLOAD_SERVICE} ("download")
1971     * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
1972     * </dl>
1973     *
1974     * <p>Note:  System services obtained via this API may be closely associated with
1975     * the Context in which they are obtained from.  In general, do not share the
1976     * service objects between various different contexts (Activities, Applications,
1977     * Services, Providers, etc.)
1978     *
1979     * @param name The name of the desired service.
1980     *
1981     * @return The service or null if the name does not exist.
1982     *
1983     * @see #WINDOW_SERVICE
1984     * @see android.view.WindowManager
1985     * @see #LAYOUT_INFLATER_SERVICE
1986     * @see android.view.LayoutInflater
1987     * @see #ACTIVITY_SERVICE
1988     * @see android.app.ActivityManager
1989     * @see #POWER_SERVICE
1990     * @see android.os.PowerManager
1991     * @see #ALARM_SERVICE
1992     * @see android.app.AlarmManager
1993     * @see #NOTIFICATION_SERVICE
1994     * @see android.app.NotificationManager
1995     * @see #KEYGUARD_SERVICE
1996     * @see android.app.KeyguardManager
1997     * @see #LOCATION_SERVICE
1998     * @see android.location.LocationManager
1999     * @see #SEARCH_SERVICE
2000     * @see android.app.SearchManager
2001     * @see #SENSOR_SERVICE
2002     * @see android.hardware.SensorManager
2003     * @see #STORAGE_SERVICE
2004     * @see android.os.storage.StorageManager
2005     * @see #VIBRATOR_SERVICE
2006     * @see android.os.Vibrator
2007     * @see #CONNECTIVITY_SERVICE
2008     * @see android.net.ConnectivityManager
2009     * @see #WIFI_SERVICE
2010     * @see android.net.wifi.WifiManager
2011     * @see #AUDIO_SERVICE
2012     * @see android.media.AudioManager
2013     * @see #MEDIA_ROUTER_SERVICE
2014     * @see android.media.MediaRouter
2015     * @see #TELEPHONY_SERVICE
2016     * @see android.telephony.TelephonyManager
2017     * @see #INPUT_METHOD_SERVICE
2018     * @see android.view.inputmethod.InputMethodManager
2019     * @see #UI_MODE_SERVICE
2020     * @see android.app.UiModeManager
2021     * @see #DOWNLOAD_SERVICE
2022     * @see android.app.DownloadManager
2023     */
2024    public abstract Object getSystemService(@ServiceName @NonNull String name);
2025
2026    /**
2027     * Use with {@link #getSystemService} to retrieve a
2028     * {@link android.os.PowerManager} for controlling power management,
2029     * including "wake locks," which let you keep the device on while
2030     * you're running long tasks.
2031     */
2032    public static final String POWER_SERVICE = "power";
2033
2034    /**
2035     * Use with {@link #getSystemService} to retrieve a
2036     * {@link android.view.WindowManager} for accessing the system's window
2037     * manager.
2038     *
2039     * @see #getSystemService
2040     * @see android.view.WindowManager
2041     */
2042    public static final String WINDOW_SERVICE = "window";
2043
2044    /**
2045     * Use with {@link #getSystemService} to retrieve a
2046     * {@link android.view.LayoutInflater} for inflating layout resources in this
2047     * context.
2048     *
2049     * @see #getSystemService
2050     * @see android.view.LayoutInflater
2051     */
2052    public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
2053
2054    /**
2055     * Use with {@link #getSystemService} to retrieve a
2056     * {@link android.accounts.AccountManager} for receiving intents at a
2057     * time of your choosing.
2058     *
2059     * @see #getSystemService
2060     * @see android.accounts.AccountManager
2061     */
2062    public static final String ACCOUNT_SERVICE = "account";
2063
2064    /**
2065     * Use with {@link #getSystemService} to retrieve a
2066     * {@link android.app.ActivityManager} for interacting with the global
2067     * system state.
2068     *
2069     * @see #getSystemService
2070     * @see android.app.ActivityManager
2071     */
2072    public static final String ACTIVITY_SERVICE = "activity";
2073
2074    /**
2075     * Use with {@link #getSystemService} to retrieve a
2076     * {@link android.app.AlarmManager} for receiving intents at a
2077     * time of your choosing.
2078     *
2079     * @see #getSystemService
2080     * @see android.app.AlarmManager
2081     */
2082    public static final String ALARM_SERVICE = "alarm";
2083
2084    /**
2085     * Use with {@link #getSystemService} to retrieve a
2086     * {@link android.app.NotificationManager} for informing the user of
2087     * background events.
2088     *
2089     * @see #getSystemService
2090     * @see android.app.NotificationManager
2091     */
2092    public static final String NOTIFICATION_SERVICE = "notification";
2093
2094    /**
2095     * Use with {@link #getSystemService} to retrieve a
2096     * {@link android.view.accessibility.AccessibilityManager} for giving the user
2097     * feedback for UI events through the registered event listeners.
2098     *
2099     * @see #getSystemService
2100     * @see android.view.accessibility.AccessibilityManager
2101     */
2102    public static final String ACCESSIBILITY_SERVICE = "accessibility";
2103
2104    /**
2105     * Use with {@link #getSystemService} to retrieve a
2106     * {@link android.view.accessibility.CaptioningManager} for obtaining
2107     * captioning properties and listening for changes in captioning
2108     * preferences.
2109     *
2110     * @see #getSystemService
2111     * @see android.view.accessibility.CaptioningManager
2112     */
2113    public static final String CAPTIONING_SERVICE = "captioning";
2114
2115    /**
2116     * Use with {@link #getSystemService} to retrieve a
2117     * {@link android.app.NotificationManager} for controlling keyguard.
2118     *
2119     * @see #getSystemService
2120     * @see android.app.KeyguardManager
2121     */
2122    public static final String KEYGUARD_SERVICE = "keyguard";
2123
2124    /**
2125     * Use with {@link #getSystemService} to retrieve a {@link
2126     * android.location.LocationManager} for controlling location
2127     * updates.
2128     *
2129     * @see #getSystemService
2130     * @see android.location.LocationManager
2131     */
2132    public static final String LOCATION_SERVICE = "location";
2133
2134    /**
2135     * Use with {@link #getSystemService} to retrieve a
2136     * {@link android.location.CountryDetector} for detecting the country that
2137     * the user is in.
2138     *
2139     * @hide
2140     */
2141    public static final String COUNTRY_DETECTOR = "country_detector";
2142
2143    /**
2144     * Use with {@link #getSystemService} to retrieve a {@link
2145     * android.app.SearchManager} for handling searches.
2146     *
2147     * @see #getSystemService
2148     * @see android.app.SearchManager
2149     */
2150    public static final String SEARCH_SERVICE = "search";
2151
2152    /**
2153     * Use with {@link #getSystemService} to retrieve a {@link
2154     * android.hardware.SensorManager} for accessing sensors.
2155     *
2156     * @see #getSystemService
2157     * @see android.hardware.SensorManager
2158     */
2159    public static final String SENSOR_SERVICE = "sensor";
2160
2161    /**
2162     * Use with {@link #getSystemService} to retrieve a {@link
2163     * android.os.storage.StorageManager} for accessing system storage
2164     * functions.
2165     *
2166     * @see #getSystemService
2167     * @see android.os.storage.StorageManager
2168     */
2169    public static final String STORAGE_SERVICE = "storage";
2170
2171    /**
2172     * Use with {@link #getSystemService} to retrieve a
2173     * com.android.server.WallpaperService for accessing wallpapers.
2174     *
2175     * @see #getSystemService
2176     */
2177    public static final String WALLPAPER_SERVICE = "wallpaper";
2178
2179    /**
2180     * Use with {@link #getSystemService} to retrieve a {@link
2181     * android.os.Vibrator} for interacting with the vibration hardware.
2182     *
2183     * @see #getSystemService
2184     * @see android.os.Vibrator
2185     */
2186    public static final String VIBRATOR_SERVICE = "vibrator";
2187
2188    /**
2189     * Use with {@link #getSystemService} to retrieve a {@link
2190     * android.app.StatusBarManager} for interacting with the status bar.
2191     *
2192     * @see #getSystemService
2193     * @see android.app.StatusBarManager
2194     * @hide
2195     */
2196    public static final String STATUS_BAR_SERVICE = "statusbar";
2197
2198    /**
2199     * Use with {@link #getSystemService} to retrieve a {@link
2200     * android.net.ConnectivityManager} for handling management of
2201     * network connections.
2202     *
2203     * @see #getSystemService
2204     * @see android.net.ConnectivityManager
2205     */
2206    public static final String CONNECTIVITY_SERVICE = "connectivity";
2207
2208    /**
2209     * Use with {@link #getSystemService} to retrieve a {@link
2210     * android.os.IUpdateLock} for managing runtime sequences that
2211     * must not be interrupted by headless OTA application or similar.
2212     *
2213     * @hide
2214     * @see #getSystemService
2215     * @see android.os.UpdateLock
2216     */
2217    public static final String UPDATE_LOCK_SERVICE = "updatelock";
2218
2219    /**
2220     * Constant for the internal network management service, not really a Context service.
2221     */
2222    public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2223
2224    /** {@hide} */
2225    public static final String NETWORK_STATS_SERVICE = "netstats";
2226    /** {@hide} */
2227    public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2228
2229    /**
2230     * Use with {@link #getSystemService} to retrieve a {@link
2231     * android.net.wifi.WifiManager} for handling management of
2232     * Wi-Fi access.
2233     *
2234     * @see #getSystemService
2235     * @see android.net.wifi.WifiManager
2236     */
2237    public static final String WIFI_SERVICE = "wifi";
2238
2239    /**
2240     * Use with {@link #getSystemService} to retrieve a {@link
2241     * android.net.wifi.p2p.WifiP2pManager} for handling management of
2242     * Wi-Fi peer-to-peer connections.
2243     *
2244     * @see #getSystemService
2245     * @see android.net.wifi.p2p.WifiP2pManager
2246     */
2247    public static final String WIFI_P2P_SERVICE = "wifip2p";
2248
2249    /**
2250     * Use with {@link #getSystemService} to retrieve a {@link
2251     * android.net.nsd.NsdManager} for handling management of network service
2252     * discovery
2253     *
2254     * @see #getSystemService
2255     * @see android.net.nsd.NsdManager
2256     */
2257    public static final String NSD_SERVICE = "servicediscovery";
2258
2259    /**
2260     * Use with {@link #getSystemService} to retrieve a
2261     * {@link android.media.AudioManager} for handling management of volume,
2262     * ringer modes and audio routing.
2263     *
2264     * @see #getSystemService
2265     * @see android.media.AudioManager
2266     */
2267    public static final String AUDIO_SERVICE = "audio";
2268
2269    /**
2270     * Use with {@link #getSystemService} to retrieve a
2271     * {@link android.media.MediaRouter} for controlling and managing
2272     * routing of media.
2273     *
2274     * @see #getSystemService
2275     * @see android.media.MediaRouter
2276     */
2277    public static final String MEDIA_ROUTER_SERVICE = "media_router";
2278
2279    /**
2280     * Use with {@link #getSystemService} to retrieve a
2281     * {@link android.telephony.TelephonyManager} for handling management the
2282     * telephony features of the device.
2283     *
2284     * @see #getSystemService
2285     * @see android.telephony.TelephonyManager
2286     */
2287    public static final String TELEPHONY_SERVICE = "phone";
2288
2289    /**
2290     * Use with {@link #getSystemService} to retrieve a
2291     * {@link android.text.ClipboardManager} for accessing and modifying
2292     * the contents of the global clipboard.
2293     *
2294     * @see #getSystemService
2295     * @see android.text.ClipboardManager
2296     */
2297    public static final String CLIPBOARD_SERVICE = "clipboard";
2298
2299    /**
2300     * Use with {@link #getSystemService} to retrieve a
2301     * {@link android.view.inputmethod.InputMethodManager} for accessing input
2302     * methods.
2303     *
2304     * @see #getSystemService
2305     */
2306    public static final String INPUT_METHOD_SERVICE = "input_method";
2307
2308    /**
2309     * Use with {@link #getSystemService} to retrieve a
2310     * {@link android.view.textservice.TextServicesManager} for accessing
2311     * text services.
2312     *
2313     * @see #getSystemService
2314     */
2315    public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2316
2317    /**
2318     * Use with {@link #getSystemService} to retrieve a
2319     * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
2320     *
2321     * @hide
2322     * @see #getSystemService
2323     */
2324    public static final String APPWIDGET_SERVICE = "appwidget";
2325
2326    /**
2327     * Use with {@link #getSystemService} to retrieve an
2328     * {@link android.app.backup.IBackupManager IBackupManager} for communicating
2329     * with the backup mechanism.
2330     * @hide
2331     *
2332     * @see #getSystemService
2333     */
2334    public static final String BACKUP_SERVICE = "backup";
2335
2336    /**
2337     * Use with {@link #getSystemService} to retrieve a
2338     * {@link android.os.DropBoxManager} instance for recording
2339     * diagnostic logs.
2340     * @see #getSystemService
2341     */
2342    public static final String DROPBOX_SERVICE = "dropbox";
2343
2344    /**
2345     * Use with {@link #getSystemService} to retrieve a
2346     * {@link android.app.admin.DevicePolicyManager} for working with global
2347     * device policy management.
2348     *
2349     * @see #getSystemService
2350     */
2351    public static final String DEVICE_POLICY_SERVICE = "device_policy";
2352
2353    /**
2354     * Use with {@link #getSystemService} to retrieve a
2355     * {@link android.app.UiModeManager} for controlling UI modes.
2356     *
2357     * @see #getSystemService
2358     */
2359    public static final String UI_MODE_SERVICE = "uimode";
2360
2361    /**
2362     * Use with {@link #getSystemService} to retrieve a
2363     * {@link android.app.DownloadManager} for requesting HTTP downloads.
2364     *
2365     * @see #getSystemService
2366     */
2367    public static final String DOWNLOAD_SERVICE = "download";
2368
2369    /**
2370     * Use with {@link #getSystemService} to retrieve a
2371     * {@link android.nfc.NfcManager} for using NFC.
2372     *
2373     * @see #getSystemService
2374     */
2375    public static final String NFC_SERVICE = "nfc";
2376
2377    /**
2378     * Use with {@link #getSystemService} to retrieve a
2379     * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2380     *
2381     * @see #getSystemService
2382     */
2383    public static final String BLUETOOTH_SERVICE = "bluetooth";
2384
2385    /**
2386     * Use with {@link #getSystemService} to retrieve a
2387     * {@link android.net.sip.SipManager} for accessing the SIP related service.
2388     *
2389     * @see #getSystemService
2390     */
2391    /** @hide */
2392    public static final String SIP_SERVICE = "sip";
2393
2394    /**
2395     * Use with {@link #getSystemService} to retrieve a {@link
2396     * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
2397     * and for controlling this device's behavior as a USB device.
2398     *
2399     * @see #getSystemService
2400     * @see android.hardware.usb.UsbManager
2401     */
2402    public static final String USB_SERVICE = "usb";
2403
2404    /**
2405     * Use with {@link #getSystemService} to retrieve a {@link
2406     * android.hardware.SerialManager} for access to serial ports.
2407     *
2408     * @see #getSystemService
2409     * @see android.hardware.SerialManager
2410     *
2411     * @hide
2412     */
2413    public static final String SERIAL_SERVICE = "serial";
2414
2415    /**
2416     * Use with {@link #getSystemService} to retrieve a
2417     * {@link android.hardware.input.InputManager} for interacting with input devices.
2418     *
2419     * @see #getSystemService
2420     * @see android.hardware.input.InputManager
2421     */
2422    public static final String INPUT_SERVICE = "input";
2423
2424    /**
2425     * Use with {@link #getSystemService} to retrieve a
2426     * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2427     *
2428     * @see #getSystemService
2429     * @see android.hardware.display.DisplayManager
2430     */
2431    public static final String DISPLAY_SERVICE = "display";
2432
2433    /**
2434     * Use with {@link #getSystemService} to retrieve a
2435     * {@link android.os.UserManager} for managing users on devices that support multiple users.
2436     *
2437     * @see #getSystemService
2438     * @see android.os.UserManager
2439     */
2440    public static final String USER_SERVICE = "user";
2441
2442    /**
2443     * Use with {@link #getSystemService} to retrieve a
2444     * {@link android.app.AppOpsManager} for tracking application operations
2445     * on the device.
2446     *
2447     * @see #getSystemService
2448     * @see android.app.AppOpsManager
2449     */
2450    public static final String APP_OPS_SERVICE = "appops";
2451
2452    /**
2453     * Use with {@link #getSystemService} to retrieve a
2454     * {@link android.hardware.camera2.CameraManager} for interacting with
2455     * camera devices.
2456     *
2457     * @see #getSystemService
2458     * @see android.hardware.camera2.CameraManager
2459     */
2460    public static final String CAMERA_SERVICE = "camera";
2461
2462    /**
2463     * {@link android.print.PrintManager} for printing and managing
2464     * printers and print tasks.
2465     *
2466     * @see #getSystemService
2467     * @see android.print.PrintManager
2468     */
2469    public static final String PRINT_SERVICE = "print";
2470
2471    /**
2472     * Use with {@link #getSystemService} to retrieve a
2473     * {@link android.hardware.ConsumerIrManager} for transmitting infrared
2474     * signals from the device.
2475     *
2476     * @see #getSystemService
2477     * @see android.hardware.ConsumerIrManager
2478     */
2479    public static final String CONSUMER_IR_SERVICE = "consumer_ir";
2480
2481    /**
2482     * Determine whether the given permission is allowed for a particular
2483     * process and user ID running in the system.
2484     *
2485     * @param permission The name of the permission being checked.
2486     * @param pid The process ID being checked against.  Must be > 0.
2487     * @param uid The user ID being checked against.  A uid of 0 is the root
2488     * user, which will pass every permission check.
2489     *
2490     * @return {@link PackageManager#PERMISSION_GRANTED} if the given
2491     * pid/uid is allowed that permission, or
2492     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2493     *
2494     * @see PackageManager#checkPermission(String, String)
2495     * @see #checkCallingPermission
2496     */
2497    @PackageManager.PermissionResult
2498    public abstract int checkPermission(@NonNull String permission, int pid, int uid);
2499
2500    /**
2501     * Determine whether the calling process of an IPC you are handling has been
2502     * granted a particular permission.  This is basically the same as calling
2503     * {@link #checkPermission(String, int, int)} with the pid and uid returned
2504     * by {@link android.os.Binder#getCallingPid} and
2505     * {@link android.os.Binder#getCallingUid}.  One important difference
2506     * is that if you are not currently processing an IPC, this function
2507     * will always fail.  This is done to protect against accidentally
2508     * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2509     * to avoid this protection.
2510     *
2511     * @param permission The name of the permission being checked.
2512     *
2513     * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
2514     * pid/uid is allowed that permission, or
2515     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2516     *
2517     * @see PackageManager#checkPermission(String, String)
2518     * @see #checkPermission
2519     * @see #checkCallingOrSelfPermission
2520     */
2521    @PackageManager.PermissionResult
2522    public abstract int checkCallingPermission(@NonNull String permission);
2523
2524    /**
2525     * Determine whether the calling process of an IPC <em>or you</em> have been
2526     * granted a particular permission.  This is the same as
2527     * {@link #checkCallingPermission}, except it grants your own permissions
2528     * if you are not currently processing an IPC.  Use with care!
2529     *
2530     * @param permission The name of the permission being checked.
2531     *
2532     * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
2533     * pid/uid is allowed that permission, or
2534     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2535     *
2536     * @see PackageManager#checkPermission(String, String)
2537     * @see #checkPermission
2538     * @see #checkCallingPermission
2539     */
2540    @PackageManager.PermissionResult
2541    public abstract int checkCallingOrSelfPermission(@NonNull String permission);
2542
2543    /**
2544     * If the given permission is not allowed for a particular process
2545     * and user ID running in the system, throw a {@link SecurityException}.
2546     *
2547     * @param permission The name of the permission being checked.
2548     * @param pid The process ID being checked against.  Must be &gt; 0.
2549     * @param uid The user ID being checked against.  A uid of 0 is the root
2550     * user, which will pass every permission check.
2551     * @param message A message to include in the exception if it is thrown.
2552     *
2553     * @see #checkPermission(String, int, int)
2554     */
2555    public abstract void enforcePermission(
2556            @NonNull String permission, int pid, int uid, @Nullable String message);
2557
2558    /**
2559     * If the calling process of an IPC you are handling has not been
2560     * granted a particular permission, throw a {@link
2561     * SecurityException}.  This is basically the same as calling
2562     * {@link #enforcePermission(String, int, int, String)} with the
2563     * pid and uid returned by {@link android.os.Binder#getCallingPid}
2564     * and {@link android.os.Binder#getCallingUid}.  One important
2565     * difference is that if you are not currently processing an IPC,
2566     * this function will always throw the SecurityException.  This is
2567     * done to protect against accidentally leaking permissions; you
2568     * can use {@link #enforceCallingOrSelfPermission} to avoid this
2569     * protection.
2570     *
2571     * @param permission The name of the permission being checked.
2572     * @param message A message to include in the exception if it is thrown.
2573     *
2574     * @see #checkCallingPermission(String)
2575     */
2576    public abstract void enforceCallingPermission(
2577            @NonNull String permission, @Nullable String message);
2578
2579    /**
2580     * If neither you nor the calling process of an IPC you are
2581     * handling has been granted a particular permission, throw a
2582     * {@link SecurityException}.  This is the same as {@link
2583     * #enforceCallingPermission}, except it grants your own
2584     * permissions if you are not currently processing an IPC.  Use
2585     * with care!
2586     *
2587     * @param permission The name of the permission being checked.
2588     * @param message A message to include in the exception if it is thrown.
2589     *
2590     * @see #checkCallingOrSelfPermission(String)
2591     */
2592    public abstract void enforceCallingOrSelfPermission(
2593            @NonNull String permission, @Nullable String message);
2594
2595    /**
2596     * Grant permission to access a specific Uri to another package, regardless
2597     * of whether that package has general permission to access the Uri's
2598     * content provider.  This can be used to grant specific, temporary
2599     * permissions, typically in response to user interaction (such as the
2600     * user opening an attachment that you would like someone else to
2601     * display).
2602     *
2603     * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2604     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2605     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2606     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
2607     * start an activity instead of this function directly.  If you use this
2608     * function directly, you should be sure to call
2609     * {@link #revokeUriPermission} when the target should no longer be allowed
2610     * to access it.
2611     *
2612     * <p>To succeed, the content provider owning the Uri must have set the
2613     * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
2614     * grantUriPermissions} attribute in its manifest or included the
2615     * {@link android.R.styleable#AndroidManifestGrantUriPermission
2616     * &lt;grant-uri-permissions&gt;} tag.
2617     *
2618     * @param toPackage The package you would like to allow to access the Uri.
2619     * @param uri The Uri you would like to grant access to.
2620     * @param modeFlags The desired access modes.  Any combination of
2621     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2622     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2623     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2624     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2625     *
2626     * @see #revokeUriPermission
2627     */
2628    public abstract void grantUriPermission(String toPackage, Uri uri,
2629            @Intent.GrantUriMode int modeFlags);
2630
2631    /**
2632     * Remove all permissions to access a particular content provider Uri
2633     * that were previously added with {@link #grantUriPermission}.  The given
2634     * Uri will match all previously granted Uris that are the same or a
2635     * sub-path of the given Uri.  That is, revoking "content://foo/target" will
2636     * revoke both "content://foo/target" and "content://foo/target/sub", but not
2637     * "content://foo".
2638     *
2639     * @param uri The Uri you would like to revoke access to.
2640     * @param modeFlags The desired access modes.  Any combination of
2641     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2642     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2643     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2644     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2645     *
2646     * @see #grantUriPermission
2647     */
2648    public abstract void revokeUriPermission(Uri uri, @Intent.GrantUriMode int modeFlags);
2649
2650    /**
2651     * Determine whether a particular process and user ID has been granted
2652     * permission to access a specific URI.  This only checks for permissions
2653     * that have been explicitly granted -- if the given process/uid has
2654     * more general access to the URI's content provider then this check will
2655     * always fail.
2656     *
2657     * @param uri The uri that is being checked.
2658     * @param pid The process ID being checked against.  Must be &gt; 0.
2659     * @param uid The user ID being checked against.  A uid of 0 is the root
2660     * user, which will pass every permission check.
2661     * @param modeFlags The type of access to grant.  May be one or both of
2662     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2663     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2664     *
2665     * @return {@link PackageManager#PERMISSION_GRANTED} if the given
2666     * pid/uid is allowed to access that uri, or
2667     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2668     *
2669     * @see #checkCallingUriPermission
2670     */
2671    public abstract int checkUriPermission(Uri uri, int pid, int uid,
2672            @Intent.GrantUriMode int modeFlags);
2673
2674    /**
2675     * Determine whether the calling process and user ID has been
2676     * granted permission to access a specific URI.  This is basically
2677     * the same as calling {@link #checkUriPermission(Uri, int, int,
2678     * int)} with the pid and uid returned by {@link
2679     * android.os.Binder#getCallingPid} and {@link
2680     * android.os.Binder#getCallingUid}.  One important difference is
2681     * that if you are not currently processing an IPC, this function
2682     * will always fail.
2683     *
2684     * @param uri The uri that is being checked.
2685     * @param modeFlags The type of access to grant.  May be one or both of
2686     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2687     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2688     *
2689     * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
2690     * is allowed to access that uri, or
2691     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2692     *
2693     * @see #checkUriPermission(Uri, int, int, int)
2694     */
2695    public abstract int checkCallingUriPermission(Uri uri, @Intent.GrantUriMode int modeFlags);
2696
2697    /**
2698     * Determine whether the calling process of an IPC <em>or you</em> has been granted
2699     * permission to access a specific URI.  This is the same as
2700     * {@link #checkCallingUriPermission}, except it grants your own permissions
2701     * if you are not currently processing an IPC.  Use with care!
2702     *
2703     * @param uri The uri that is being checked.
2704     * @param modeFlags The type of access to grant.  May be one or both of
2705     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2706     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2707     *
2708     * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
2709     * is allowed to access that uri, or
2710     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2711     *
2712     * @see #checkCallingUriPermission
2713     */
2714    public abstract int checkCallingOrSelfUriPermission(Uri uri,
2715            @Intent.GrantUriMode int modeFlags);
2716
2717    /**
2718     * Check both a Uri and normal permission.  This allows you to perform
2719     * both {@link #checkPermission} and {@link #checkUriPermission} in one
2720     * call.
2721     *
2722     * @param uri The Uri whose permission is to be checked, or null to not
2723     * do this check.
2724     * @param readPermission The permission that provides overall read access,
2725     * or null to not do this check.
2726     * @param writePermission The permission that provides overall write
2727     * access, or null to not do this check.
2728     * @param pid The process ID being checked against.  Must be &gt; 0.
2729     * @param uid The user ID being checked against.  A uid of 0 is the root
2730     * user, which will pass every permission check.
2731     * @param modeFlags The type of access to grant.  May be one or both of
2732     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2733     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2734     *
2735     * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
2736     * is allowed to access that uri or holds one of the given permissions, or
2737     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2738     */
2739    public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
2740            @Nullable String writePermission, int pid, int uid,
2741            @Intent.GrantUriMode int modeFlags);
2742
2743    /**
2744     * If a particular process and user ID has not been granted
2745     * permission to access a specific URI, throw {@link
2746     * SecurityException}.  This only checks for permissions that have
2747     * been explicitly granted -- if the given process/uid has more
2748     * general access to the URI's content provider then this check
2749     * will always fail.
2750     *
2751     * @param uri The uri that is being checked.
2752     * @param pid The process ID being checked against.  Must be &gt; 0.
2753     * @param uid The user ID being checked against.  A uid of 0 is the root
2754     * user, which will pass every permission check.
2755     * @param modeFlags The type of access to grant.  May be one or both of
2756     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2757     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2758     * @param message A message to include in the exception if it is thrown.
2759     *
2760     * @see #checkUriPermission(Uri, int, int, int)
2761     */
2762    public abstract void enforceUriPermission(
2763            Uri uri, int pid, int uid, @Intent.GrantUriMode int modeFlags, String message);
2764
2765    /**
2766     * If the calling process and user ID has not been granted
2767     * permission to access a specific URI, throw {@link
2768     * SecurityException}.  This is basically the same as calling
2769     * {@link #enforceUriPermission(Uri, int, int, int, String)} with
2770     * the pid and uid returned by {@link
2771     * android.os.Binder#getCallingPid} and {@link
2772     * android.os.Binder#getCallingUid}.  One important difference is
2773     * that if you are not currently processing an IPC, this function
2774     * will always throw a SecurityException.
2775     *
2776     * @param uri The uri that is being checked.
2777     * @param modeFlags The type of access to grant.  May be one or both of
2778     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2779     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2780     * @param message A message to include in the exception if it is thrown.
2781     *
2782     * @see #checkCallingUriPermission(Uri, int)
2783     */
2784    public abstract void enforceCallingUriPermission(
2785            Uri uri, @Intent.GrantUriMode int modeFlags, String message);
2786
2787    /**
2788     * If the calling process of an IPC <em>or you</em> has not been
2789     * granted permission to access a specific URI, throw {@link
2790     * SecurityException}.  This is the same as {@link
2791     * #enforceCallingUriPermission}, except it grants your own
2792     * permissions if you are not currently processing an IPC.  Use
2793     * with care!
2794     *
2795     * @param uri The uri that is being checked.
2796     * @param modeFlags The type of access to grant.  May be one or both of
2797     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2798     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2799     * @param message A message to include in the exception if it is thrown.
2800     *
2801     * @see #checkCallingOrSelfUriPermission(Uri, int)
2802     */
2803    public abstract void enforceCallingOrSelfUriPermission(
2804            Uri uri, @Intent.GrantUriMode int modeFlags, String message);
2805
2806    /**
2807     * Enforce both a Uri and normal permission.  This allows you to perform
2808     * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
2809     * call.
2810     *
2811     * @param uri The Uri whose permission is to be checked, or null to not
2812     * do this check.
2813     * @param readPermission The permission that provides overall read access,
2814     * or null to not do this check.
2815     * @param writePermission The permission that provides overall write
2816     * access, or null to not do this check.
2817     * @param pid The process ID being checked against.  Must be &gt; 0.
2818     * @param uid The user ID being checked against.  A uid of 0 is the root
2819     * user, which will pass every permission check.
2820     * @param modeFlags The type of access to grant.  May be one or both of
2821     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2822     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2823     * @param message A message to include in the exception if it is thrown.
2824     *
2825     * @see #checkUriPermission(Uri, String, String, int, int, int)
2826     */
2827    public abstract void enforceUriPermission(
2828            @Nullable Uri uri, @Nullable String readPermission,
2829            @Nullable String writePermission, int pid, int uid, @Intent.GrantUriMode int modeFlags,
2830            @Nullable String message);
2831
2832    /** @hide */
2833    @IntDef(flag = true,
2834            value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
2835    @Retention(RetentionPolicy.SOURCE)
2836    public @interface CreatePackageOptions {}
2837
2838    /**
2839     * Flag for use with {@link #createPackageContext}: include the application
2840     * code with the context.  This means loading code into the caller's
2841     * process, so that {@link #getClassLoader()} can be used to instantiate
2842     * the application's classes.  Setting this flags imposes security
2843     * restrictions on what application context you can access; if the
2844     * requested application can not be safely loaded into your process,
2845     * java.lang.SecurityException will be thrown.  If this flag is not set,
2846     * there will be no restrictions on the packages that can be loaded,
2847     * but {@link #getClassLoader} will always return the default system
2848     * class loader.
2849     */
2850    public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
2851
2852    /**
2853     * Flag for use with {@link #createPackageContext}: ignore any security
2854     * restrictions on the Context being requested, allowing it to always
2855     * be loaded.  For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
2856     * to be loaded into a process even when it isn't safe to do so.  Use
2857     * with extreme care!
2858     */
2859    public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
2860
2861    /**
2862     * Flag for use with {@link #createPackageContext}: a restricted context may
2863     * disable specific features. For instance, a View associated with a restricted
2864     * context would ignore particular XML attributes.
2865     */
2866    public static final int CONTEXT_RESTRICTED = 0x00000004;
2867
2868    /**
2869     * Return a new Context object for the given application name.  This
2870     * Context is the same as what the named application gets when it is
2871     * launched, containing the same resources and class loader.  Each call to
2872     * this method returns a new instance of a Context object; Context objects
2873     * are not shared, however they share common state (Resources, ClassLoader,
2874     * etc) so the Context instance itself is fairly lightweight.
2875     *
2876     * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
2877     * application with the given package name.
2878     *
2879     * <p>Throws {@link java.lang.SecurityException} if the Context requested
2880     * can not be loaded into the caller's process for security reasons (see
2881     * {@link #CONTEXT_INCLUDE_CODE} for more information}.
2882     *
2883     * @param packageName Name of the application's package.
2884     * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
2885     *              or {@link #CONTEXT_IGNORE_SECURITY}.
2886     *
2887     * @return A {@link Context} for the application.
2888     *
2889     * @throws SecurityException &nbsp;
2890     * @throws PackageManager.NameNotFoundException if there is no application with
2891     * the given package name.
2892     */
2893    public abstract Context createPackageContext(String packageName,
2894            @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
2895
2896    /**
2897     * Similar to {@link #createPackageContext(String, int)}, but with a
2898     * different {@link UserHandle}. For example, {@link #getContentResolver()}
2899     * will open any {@link Uri} as the given user.
2900     *
2901     * @hide
2902     */
2903    public abstract Context createPackageContextAsUser(
2904            String packageName, int flags, UserHandle user)
2905            throws PackageManager.NameNotFoundException;
2906
2907    /**
2908     * Get the userId associated with this context
2909     * @return user id
2910     *
2911     * @hide
2912     */
2913    public abstract int getUserId();
2914
2915    /**
2916     * Return a new Context object for the current Context but whose resources
2917     * are adjusted to match the given Configuration.  Each call to this method
2918     * returns a new instance of a Context object; Context objects are not
2919     * shared, however common state (ClassLoader, other Resources for the
2920     * same configuration) may be so the Context itself can be fairly lightweight.
2921     *
2922     * @param overrideConfiguration A {@link Configuration} specifying what
2923     * values to modify in the base Configuration of the original Context's
2924     * resources.  If the base configuration changes (such as due to an
2925     * orientation change), the resources of this context will also change except
2926     * for those that have been explicitly overridden with a value here.
2927     *
2928     * @return A {@link Context} with the given configuration override.
2929     */
2930    public abstract Context createConfigurationContext(
2931            @NonNull Configuration overrideConfiguration);
2932
2933    /**
2934     * Return a new Context object for the current Context but whose resources
2935     * are adjusted to match the metrics of the given Display.  Each call to this method
2936     * returns a new instance of a Context object; Context objects are not
2937     * shared, however common state (ClassLoader, other Resources for the
2938     * same configuration) may be so the Context itself can be fairly lightweight.
2939     *
2940     * The returned display Context provides a {@link WindowManager}
2941     * (see {@link #getSystemService(String)}) that is configured to show windows
2942     * on the given display.  The WindowManager's {@link WindowManager#getDefaultDisplay}
2943     * method can be used to retrieve the Display from the returned Context.
2944     *
2945     * @param display A {@link Display} object specifying the display
2946     * for whose metrics the Context's resources should be tailored and upon which
2947     * new windows should be shown.
2948     *
2949     * @return A {@link Context} for the display.
2950     */
2951    public abstract Context createDisplayContext(@NonNull Display display);
2952
2953    /**
2954     * Gets the display adjustments holder for this context.  This information
2955     * is provided on a per-application or activity basis and is used to simulate lower density
2956     * display metrics for legacy applications and restricted screen sizes.
2957     *
2958     * @param displayId The display id for which to get compatibility info.
2959     * @return The compatibility info holder, or null if not required by the application.
2960     * @hide
2961     */
2962    public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
2963
2964    /**
2965     * Indicates whether this Context is restricted.
2966     *
2967     * @return {@code true} if this Context is restricted, {@code false} otherwise.
2968     *
2969     * @see #CONTEXT_RESTRICTED
2970     */
2971    public boolean isRestricted() {
2972        return false;
2973    }
2974}
2975