Context.java revision d9273d6f289d9b55da3fd0db2f659fdfb48106a8
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    /** Return the full application info for this context's package. */
459    public abstract ApplicationInfo getApplicationInfo();
460
461    /**
462     * Return the full path to this context's primary Android package.
463     * The Android package is a ZIP file which contains the application's
464     * primary resources.
465     *
466     * <p>Note: this is not generally useful for applications, since they should
467     * not be directly accessing the file system.
468     *
469     * @return String Path to the resources.
470     */
471    public abstract String getPackageResourcePath();
472
473    /**
474     * Return the full path to this context's primary Android package.
475     * The Android package is a ZIP file which contains application's
476     * primary code and assets.
477     *
478     * <p>Note: this is not generally useful for applications, since they should
479     * not be directly accessing the file system.
480     *
481     * @return String Path to the code and assets.
482     */
483    public abstract String getPackageCodePath();
484
485    /**
486     * {@hide}
487     * Return the full path to the shared prefs file for the given prefs group name.
488     *
489     * <p>Note: this is not generally useful for applications, since they should
490     * not be directly accessing the file system.
491     */
492    public abstract File getSharedPrefsFile(String name);
493
494    /**
495     * Retrieve and hold the contents of the preferences file 'name', returning
496     * a SharedPreferences through which you can retrieve and modify its
497     * values.  Only one instance of the SharedPreferences object is returned
498     * to any callers for the same name, meaning they will see each other's
499     * edits as soon as they are made.
500     *
501     * @param name Desired preferences file. If a preferences file by this name
502     * does not exist, it will be created when you retrieve an
503     * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
504     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
505     * default operation, {@link #MODE_WORLD_READABLE}
506     * and {@link #MODE_WORLD_WRITEABLE} to control permissions.  The bit
507     * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
508     * are mutating the same SharedPreferences file.  {@link #MODE_MULTI_PROCESS}
509     * is always on in apps targeting Gingerbread (Android 2.3) and below, and
510     * off by default in later versions.
511     *
512     * @return The single {@link SharedPreferences} instance that can be used
513     *         to retrieve and modify the preference values.
514     *
515     * @see #MODE_PRIVATE
516     * @see #MODE_WORLD_READABLE
517     * @see #MODE_WORLD_WRITEABLE
518     * @see #MODE_MULTI_PROCESS
519     */
520    public abstract SharedPreferences getSharedPreferences(String name,
521            int mode);
522
523    /**
524     * Open a private file associated with this Context's application package
525     * for reading.
526     *
527     * @param name The name of the file to open; can not contain path
528     *             separators.
529     *
530     * @return The resulting {@link FileInputStream}.
531     *
532     * @see #openFileOutput
533     * @see #fileList
534     * @see #deleteFile
535     * @see java.io.FileInputStream#FileInputStream(String)
536     */
537    public abstract FileInputStream openFileInput(String name)
538        throws FileNotFoundException;
539
540    /**
541     * Open a private file associated with this Context's application package
542     * for writing.  Creates the file if it doesn't already exist.
543     *
544     * @param name The name of the file to open; can not contain path
545     *             separators.
546     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
547     * default operation, {@link #MODE_APPEND} to append to an existing file,
548     * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
549     * permissions.
550     *
551     * @return The resulting {@link FileOutputStream}.
552     *
553     * @see #MODE_APPEND
554     * @see #MODE_PRIVATE
555     * @see #MODE_WORLD_READABLE
556     * @see #MODE_WORLD_WRITEABLE
557     * @see #openFileInput
558     * @see #fileList
559     * @see #deleteFile
560     * @see java.io.FileOutputStream#FileOutputStream(String)
561     */
562    public abstract FileOutputStream openFileOutput(String name, int mode)
563        throws FileNotFoundException;
564
565    /**
566     * Delete the given private file associated with this Context's
567     * application package.
568     *
569     * @param name The name of the file to delete; can not contain path
570     *             separators.
571     *
572     * @return {@code true} if the file was successfully deleted; else
573     *         {@code false}.
574     *
575     * @see #openFileInput
576     * @see #openFileOutput
577     * @see #fileList
578     * @see java.io.File#delete()
579     */
580    public abstract boolean deleteFile(String name);
581
582    /**
583     * Returns the absolute path on the filesystem where a file created with
584     * {@link #openFileOutput} is stored.
585     *
586     * @param name The name of the file for which you would like to get
587     *          its path.
588     *
589     * @return An absolute path to the given file.
590     *
591     * @see #openFileOutput
592     * @see #getFilesDir
593     * @see #getDir
594     */
595    public abstract File getFileStreamPath(String name);
596
597    /**
598     * Returns the absolute path to the directory on the filesystem where
599     * files created with {@link #openFileOutput} are stored.
600     *
601     * @return The path of the directory holding application files.
602     *
603     * @see #openFileOutput
604     * @see #getFileStreamPath
605     * @see #getDir
606     */
607    public abstract File getFilesDir();
608
609    /**
610     * Returns the absolute path to the directory on the external filesystem
611     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
612     * Environment.getExternalStorageDirectory()}) where the application can
613     * place persistent files it owns.  These files are internal to the
614     * applications, and not typically visible to the user as media.
615     *
616     * <p>This is like {@link #getFilesDir()} in that these
617     * files will be deleted when the application is uninstalled, however there
618     * are some important differences:
619     *
620     * <ul>
621     * <li>External files are not always available: they will disappear if the
622     * user mounts the external storage on a computer or removes it.  See the
623     * APIs on {@link android.os.Environment} for information in the storage state.
624     * <li>There is no security enforced with these files.  All applications
625     * can read and write files placed here.
626     * </ul>
627     *
628     * <p>On devices with multiple users (as described by {@link UserManager}),
629     * each user has their own isolated external storage. Applications only
630     * have access to the external storage for the user they're running as.</p>
631     *
632     * <p>Here is an example of typical code to manipulate a file in
633     * an application's private storage:</p>
634     *
635     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
636     * private_file}
637     *
638     * <p>If you supply a non-null <var>type</var> to this function, the returned
639     * file will be a path to a sub-directory of the given type.  Though these files
640     * are not automatically scanned by the media scanner, you can explicitly
641     * add them to the media database with
642     * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
643     *      OnScanCompletedListener) MediaScannerConnection.scanFile}.
644     * Note that this is not the same as
645     * {@link android.os.Environment#getExternalStoragePublicDirectory
646     * Environment.getExternalStoragePublicDirectory()}, which provides
647     * directories of media shared by all applications.  The
648     * directories returned here are
649     * owned by the application, and their contents will be removed when the
650     * application is uninstalled.  Unlike
651     * {@link android.os.Environment#getExternalStoragePublicDirectory
652     * Environment.getExternalStoragePublicDirectory()}, the directory
653     * returned here will be automatically created for you.
654     *
655     * <p>Here is an example of typical code to manipulate a picture in
656     * an application's private storage and add it to the media database:</p>
657     *
658     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
659     * private_picture}
660     * <p>
661     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
662     * permissions are required for the owning application to read or write to
663     * this path. Otherwise, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
664     * or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
665     *
666     * @param type The type of files directory to return.  May be null for
667     * the root of the files directory or one of
668     * the following Environment constants for a subdirectory:
669     * {@link android.os.Environment#DIRECTORY_MUSIC},
670     * {@link android.os.Environment#DIRECTORY_PODCASTS},
671     * {@link android.os.Environment#DIRECTORY_RINGTONES},
672     * {@link android.os.Environment#DIRECTORY_ALARMS},
673     * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
674     * {@link android.os.Environment#DIRECTORY_PICTURES}, or
675     * {@link android.os.Environment#DIRECTORY_MOVIES}.
676     *
677     * @return The path of the directory holding application files
678     * on external storage.  Returns null if external storage is not currently
679     * mounted so it could not ensure the path exists; you will need to call
680     * this method again when it is available.
681     *
682     * @see #getFilesDir
683     * @see android.os.Environment#getExternalStoragePublicDirectory
684     */
685    @Nullable
686    public abstract File getExternalFilesDir(@Nullable String type);
687
688    /**
689     * Returns absolute paths to application-specific directories on all
690     * external storage devices where the application can place persistent files
691     * it owns. These files are internal to the application, and not typically
692     * visible to the user as media.
693     * <p>
694     * External storage devices returned here are considered a permanent part of
695     * the device, including both emulated external storage and physical media
696     * slots. This does not include transient devices, such as USB flash drives.
697     * <p>
698     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
699     * permissions are required for the owning application to read or write to
700     * these paths.
701     * <p>
702     * The returned paths include any path that would be returned by
703     * {@link #getExternalFilesDir(String)}.
704     *
705     * @see #getExternalFilesDir(String)
706     */
707    public abstract File[] getExternalFilesDirs(String type);
708
709    /**
710     * Return the directory where this application's OBB files (if there are
711     * any) can be found. Note if the application does not have any OBB files,
712     * this directory may not exist.
713     * <p>
714     * On devices with multiple users (as described by {@link UserManager}),
715     * multiple users may share the same OBB storage location. Applications
716     * should ensure that multiple instances running under different users don't
717     * interfere with each other.
718     * <p>
719     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
720     * permissions are required for the owning application to read or write to
721     * this path. Otherwise,
722     * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} or
723     * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
724     */
725    public abstract File getObbDir();
726
727    /**
728     * Returns absolute paths to application-specific directories on all
729     * external storage devices where the application's OBB files (if there are
730     * any) can be found. Note if the application does not have any OBB files,
731     * these directories may not exist.
732     * <p>
733     * External storage devices returned here are considered a permanent part of
734     * the device, including both emulated external storage and physical media
735     * slots. This does not include transient devices, such as USB flash drives.
736     * <p>
737     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
738     * permissions are required for the owning application to read or write to
739     * this path.
740     * <p>
741     * The returned paths include any path that would be returned by
742     * {@link #getObbDir()}
743     *
744     * @see #getObbDir()
745     */
746    public abstract File[] getObbDirs();
747
748    /**
749     * Returns the absolute path to the application specific cache directory
750     * on the filesystem. These files will be ones that get deleted first when the
751     * device runs low on storage.
752     * There is no guarantee when these files will be deleted.
753     *
754     * <strong>Note: you should not <em>rely</em> on the system deleting these
755     * files for you; you should always have a reasonable maximum, such as 1 MB,
756     * for the amount of space you consume with cache files, and prune those
757     * files when exceeding that space.</strong>
758     *
759     * @return The path of the directory holding application cache files.
760     *
761     * @see #openFileOutput
762     * @see #getFileStreamPath
763     * @see #getDir
764     */
765    public abstract File getCacheDir();
766
767    /**
768     * Returns the absolute path to the directory on the external filesystem
769     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
770     * Environment.getExternalStorageDirectory()} where the application can
771     * place cache files it owns. These files are internal to the application, and
772     * not typically visible to the user as media.
773     *
774     * <p>This is like {@link #getCacheDir()} in that these
775     * files will be deleted when the application is uninstalled, however there
776     * are some important differences:
777     *
778     * <ul>
779     * <li>The platform does not always monitor the space available in external
780     * storage, and thus may not automatically delete these files.  Currently
781     * the only time files here will be deleted by the platform is when running
782     * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
783     * {@link android.os.Environment#isExternalStorageEmulated()
784     * Environment.isExternalStorageEmulated()} returns true.  Note that you should
785     * be managing the maximum space you will use for these anyway, just like
786     * with {@link #getCacheDir()}.
787     * <li>External files are not always available: they will disappear if the
788     * user mounts the external storage on a computer or removes it.  See the
789     * APIs on {@link android.os.Environment} for information in the storage state.
790     * <li>There is no security enforced with these files.  All applications
791     * can read and write files placed here.
792     * </ul>
793     *
794     * <p>On devices with multiple users (as described by {@link UserManager}),
795     * each user has their own isolated external storage. Applications only
796     * have access to the external storage for the user they're running as.</p>
797     * <p>
798     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
799     * permissions are required for the owning application to read or write to
800     * this path. Otherwise,
801     * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} or
802     * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
803     *
804     * @return The path of the directory holding application cache files
805     * on external storage.  Returns null if external storage is not currently
806     * mounted so it could not ensure the path exists; you will need to call
807     * this method again when it is available.
808     *
809     * @see #getCacheDir
810     */
811    @Nullable
812    public abstract File getExternalCacheDir();
813
814    /**
815     * Returns absolute paths to application-specific directories on all
816     * external storage devices where the application can place cache files it
817     * owns. These files are internal to the application, and not typically
818     * visible to the user as media.
819     * <p>
820     * External storage devices returned here are considered a permanent part of
821     * the device, including both emulated external storage and physical media
822     * slots. This does not include transient devices, such as USB flash drives.
823     * <p>
824     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
825     * permissions are required for the owning application to read or write to
826     * these paths.
827     * <p>
828     * The returned paths include any path that would be returned by
829     * {@link #getExternalCacheDir()}.
830     *
831     * @see #getExternalCacheDir()
832     */
833    public abstract File[] getExternalCacheDirs();
834
835    /**
836     * Returns an array of strings naming the private files associated with
837     * this Context's application package.
838     *
839     * @return Array of strings naming the private files.
840     *
841     * @see #openFileInput
842     * @see #openFileOutput
843     * @see #deleteFile
844     */
845    public abstract String[] fileList();
846
847    /**
848     * Retrieve, creating if needed, a new directory in which the application
849     * can place its own custom data files.  You can use the returned File
850     * object to create and access files in this directory.  Note that files
851     * created through a File object will only be accessible by your own
852     * application; you can only set the mode of the entire directory, not
853     * of individual files.
854     *
855     * @param name Name of the directory to retrieve.  This is a directory
856     * that is created as part of your application data.
857     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
858     * default operation, {@link #MODE_WORLD_READABLE} and
859     * {@link #MODE_WORLD_WRITEABLE} to control permissions.
860     *
861     * @return A {@link File} object for the requested directory.  The directory
862     * will have been created if it does not already exist.
863     *
864     * @see #openFileOutput(String, int)
865     */
866    public abstract File getDir(String name, int mode);
867
868    /**
869     * Open a new private SQLiteDatabase associated with this Context's
870     * application package.  Create the database file if it doesn't exist.
871     *
872     * @param name The name (unique in the application package) of the database.
873     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
874     *     default operation, {@link #MODE_WORLD_READABLE}
875     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
876     *     Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
877     * @param factory An optional factory class that is called to instantiate a
878     *     cursor when query is called.
879     *
880     * @return The contents of a newly created database with the given name.
881     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
882     *
883     * @see #MODE_PRIVATE
884     * @see #MODE_WORLD_READABLE
885     * @see #MODE_WORLD_WRITEABLE
886     * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
887     * @see #deleteDatabase
888     */
889    public abstract SQLiteDatabase openOrCreateDatabase(String name,
890            int mode, CursorFactory factory);
891
892    /**
893     * Open a new private SQLiteDatabase associated with this Context's
894     * application package.  Creates the database file if it doesn't exist.
895     *
896     * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
897     * used to handle corruption when sqlite reports database corruption.</p>
898     *
899     * @param name The name (unique in the application package) of the database.
900     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
901     *     default operation, {@link #MODE_WORLD_READABLE}
902     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
903     *     Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
904     * @param factory An optional factory class that is called to instantiate a
905     *     cursor when query is called.
906     * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
907     * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
908     * @return The contents of a newly created database with the given name.
909     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
910     *
911     * @see #MODE_PRIVATE
912     * @see #MODE_WORLD_READABLE
913     * @see #MODE_WORLD_WRITEABLE
914     * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
915     * @see #deleteDatabase
916     */
917    public abstract SQLiteDatabase openOrCreateDatabase(String name,
918            int mode, CursorFactory factory,
919            @Nullable DatabaseErrorHandler errorHandler);
920
921    /**
922     * Delete an existing private SQLiteDatabase associated with this Context's
923     * application package.
924     *
925     * @param name The name (unique in the application package) of the
926     *             database.
927     *
928     * @return {@code true} if the database was successfully deleted; else {@code false}.
929     *
930     * @see #openOrCreateDatabase
931     */
932    public abstract boolean deleteDatabase(String name);
933
934    /**
935     * Returns the absolute path on the filesystem where a database created with
936     * {@link #openOrCreateDatabase} is stored.
937     *
938     * @param name The name of the database for which you would like to get
939     *          its path.
940     *
941     * @return An absolute path to the given database.
942     *
943     * @see #openOrCreateDatabase
944     */
945    public abstract File getDatabasePath(String name);
946
947    /**
948     * Returns an array of strings naming the private databases associated with
949     * this Context's application package.
950     *
951     * @return Array of strings naming the private databases.
952     *
953     * @see #openOrCreateDatabase
954     * @see #deleteDatabase
955     */
956    public abstract String[] databaseList();
957
958    /**
959     * @deprecated Use {@link android.app.WallpaperManager#getDrawable
960     * WallpaperManager.get()} instead.
961     */
962    @Deprecated
963    public abstract Drawable getWallpaper();
964
965    /**
966     * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
967     * WallpaperManager.peek()} instead.
968     */
969    @Deprecated
970    public abstract Drawable peekWallpaper();
971
972    /**
973     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
974     * WallpaperManager.getDesiredMinimumWidth()} instead.
975     */
976    @Deprecated
977    public abstract int getWallpaperDesiredMinimumWidth();
978
979    /**
980     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
981     * WallpaperManager.getDesiredMinimumHeight()} instead.
982     */
983    @Deprecated
984    public abstract int getWallpaperDesiredMinimumHeight();
985
986    /**
987     * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
988     * WallpaperManager.set()} instead.
989     * <p>This method requires the caller to hold the permission
990     * {@link android.Manifest.permission#SET_WALLPAPER}.
991     */
992    @Deprecated
993    public abstract void setWallpaper(Bitmap bitmap) throws IOException;
994
995    /**
996     * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
997     * WallpaperManager.set()} instead.
998     * <p>This method requires the caller to hold the permission
999     * {@link android.Manifest.permission#SET_WALLPAPER}.
1000     */
1001    @Deprecated
1002    public abstract void setWallpaper(InputStream data) throws IOException;
1003
1004    /**
1005     * @deprecated Use {@link android.app.WallpaperManager#clear
1006     * WallpaperManager.clear()} instead.
1007     * <p>This method requires the caller to hold the permission
1008     * {@link android.Manifest.permission#SET_WALLPAPER}.
1009     */
1010    @Deprecated
1011    public abstract void clearWallpaper() throws IOException;
1012
1013    /**
1014     * Same as {@link #startActivity(Intent, Bundle)} with no options
1015     * specified.
1016     *
1017     * @param intent The description of the activity to start.
1018     *
1019     * @throws ActivityNotFoundException &nbsp;
1020     *
1021     * @see #startActivity(Intent, Bundle)
1022     * @see PackageManager#resolveActivity
1023     */
1024    public abstract void startActivity(Intent intent);
1025
1026    /**
1027     * Version of {@link #startActivity(Intent)} that allows you to specify the
1028     * user the activity will be started for.  This is not available to applications
1029     * that are not pre-installed on the system image.  Using it requires holding
1030     * the INTERACT_ACROSS_USERS_FULL permission.
1031     * @param intent The description of the activity to start.
1032     * @param user The UserHandle of the user to start this activity for.
1033     * @throws ActivityNotFoundException &nbsp;
1034     * @hide
1035     */
1036    public void startActivityAsUser(Intent intent, UserHandle user) {
1037        throw new RuntimeException("Not implemented. Must override in a subclass.");
1038    }
1039
1040    /**
1041     * Launch a new activity.  You will not receive any information about when
1042     * the activity exits.
1043     *
1044     * <p>Note that if this method is being called from outside of an
1045     * {@link android.app.Activity} Context, then the Intent must include
1046     * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because,
1047     * without being started from an existing Activity, there is no existing
1048     * task in which to place the new activity and thus it needs to be placed
1049     * in its own separate task.
1050     *
1051     * <p>This method throws {@link ActivityNotFoundException}
1052     * if there was no Activity found to run the given Intent.
1053     *
1054     * @param intent The description of the activity to start.
1055     * @param options Additional options for how the Activity should be started.
1056     * May be null if there are no options.  See {@link android.app.ActivityOptions}
1057     * for how to build the Bundle supplied here; there are no supported definitions
1058     * for building it manually.
1059     *
1060     * @throws ActivityNotFoundException &nbsp;
1061     *
1062     * @see #startActivity(Intent)
1063     * @see PackageManager#resolveActivity
1064     */
1065    public abstract void startActivity(Intent intent, @Nullable Bundle options);
1066
1067    /**
1068     * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1069     * user the activity will be started for.  This is not available to applications
1070     * that are not pre-installed on the system image.  Using it requires holding
1071     * the INTERACT_ACROSS_USERS_FULL permission.
1072     * @param intent The description of the activity to start.
1073     * @param options Additional options for how the Activity should be started.
1074     * May be null if there are no options.  See {@link android.app.ActivityOptions}
1075     * for how to build the Bundle supplied here; there are no supported definitions
1076     * for building it manually.
1077     * @param userId The UserHandle of the user to start this activity for.
1078     * @throws ActivityNotFoundException &nbsp;
1079     * @hide
1080     */
1081    public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
1082        throw new RuntimeException("Not implemented. Must override in a subclass.");
1083    }
1084
1085    /**
1086     * Same as {@link #startActivities(Intent[], Bundle)} with no options
1087     * specified.
1088     *
1089     * @param intents An array of Intents to be started.
1090     *
1091     * @throws ActivityNotFoundException &nbsp;
1092     *
1093     * @see #startActivities(Intent[], Bundle)
1094     * @see PackageManager#resolveActivity
1095     */
1096    public abstract void startActivities(Intent[] intents);
1097
1098    /**
1099     * Launch multiple new activities.  This is generally the same as calling
1100     * {@link #startActivity(Intent)} for the first Intent in the array,
1101     * that activity during its creation calling {@link #startActivity(Intent)}
1102     * for the second entry, etc.  Note that unlike that approach, generally
1103     * none of the activities except the last in the array will be created
1104     * at this point, but rather will be created when the user first visits
1105     * them (due to pressing back from the activity on top).
1106     *
1107     * <p>This method throws {@link ActivityNotFoundException}
1108     * if there was no Activity found for <em>any</em> given Intent.  In this
1109     * case the state of the activity stack is undefined (some Intents in the
1110     * list may be on it, some not), so you probably want to avoid such situations.
1111     *
1112     * @param intents An array of Intents to be started.
1113     * @param options Additional options for how the Activity should be started.
1114     * See {@link android.content.Context#startActivity(Intent, Bundle)
1115     * Context.startActivity(Intent, Bundle)} for more details.
1116     *
1117     * @throws ActivityNotFoundException &nbsp;
1118     *
1119     * @see #startActivities(Intent[])
1120     * @see PackageManager#resolveActivity
1121     */
1122    public abstract void startActivities(Intent[] intents, Bundle options);
1123
1124    /**
1125     * @hide
1126     * Launch multiple new activities.  This is generally the same as calling
1127     * {@link #startActivity(Intent)} for the first Intent in the array,
1128     * that activity during its creation calling {@link #startActivity(Intent)}
1129     * for the second entry, etc.  Note that unlike that approach, generally
1130     * none of the activities except the last in the array will be created
1131     * at this point, but rather will be created when the user first visits
1132     * them (due to pressing back from the activity on top).
1133     *
1134     * <p>This method throws {@link ActivityNotFoundException}
1135     * if there was no Activity found for <em>any</em> given Intent.  In this
1136     * case the state of the activity stack is undefined (some Intents in the
1137     * list may be on it, some not), so you probably want to avoid such situations.
1138     *
1139     * @param intents An array of Intents to be started.
1140     * @param options Additional options for how the Activity should be started.
1141     * @param userHandle The user for whom to launch the activities
1142     * See {@link android.content.Context#startActivity(Intent, Bundle)
1143     * Context.startActivity(Intent, Bundle)} for more details.
1144     *
1145     * @throws ActivityNotFoundException &nbsp;
1146     *
1147     * @see #startActivities(Intent[])
1148     * @see PackageManager#resolveActivity
1149     */
1150    public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1151        throw new RuntimeException("Not implemented. Must override in a subclass.");
1152    }
1153
1154    /**
1155     * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1156     * with no options specified.
1157     *
1158     * @param intent The IntentSender to launch.
1159     * @param fillInIntent If non-null, this will be provided as the
1160     * intent parameter to {@link IntentSender#sendIntent}.
1161     * @param flagsMask Intent flags in the original IntentSender that you
1162     * would like to change.
1163     * @param flagsValues Desired values for any bits set in
1164     * <var>flagsMask</var>
1165     * @param extraFlags Always set to 0.
1166     *
1167     * @see #startActivity(Intent)
1168     * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1169     */
1170    public abstract void startIntentSender(IntentSender intent,
1171            Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1172            throws IntentSender.SendIntentException;
1173
1174    /**
1175     * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
1176     * to start.  If the IntentSender is for an activity, that activity will be started
1177     * as if you had called the regular {@link #startActivity(Intent)}
1178     * here; otherwise, its associated action will be executed (such as
1179     * sending a broadcast) as if you had called
1180     * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
1181     *
1182     * @param intent The IntentSender to launch.
1183     * @param fillInIntent If non-null, this will be provided as the
1184     * intent parameter to {@link IntentSender#sendIntent}.
1185     * @param flagsMask Intent flags in the original IntentSender that you
1186     * would like to change.
1187     * @param flagsValues Desired values for any bits set in
1188     * <var>flagsMask</var>
1189     * @param extraFlags Always set to 0.
1190     * @param options Additional options for how the Activity should be started.
1191     * See {@link android.content.Context#startActivity(Intent, Bundle)
1192     * Context.startActivity(Intent, Bundle)} for more details.  If options
1193     * have also been supplied by the IntentSender, options given here will
1194     * override any that conflict with those given by the IntentSender.
1195     *
1196     * @see #startActivity(Intent, Bundle)
1197     * @see #startIntentSender(IntentSender, Intent, int, int, int)
1198     */
1199    public abstract void startIntentSender(IntentSender intent,
1200            @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1201            Bundle options) throws IntentSender.SendIntentException;
1202
1203    /**
1204     * Broadcast the given intent to all interested BroadcastReceivers.  This
1205     * call is asynchronous; it returns immediately, and you will continue
1206     * executing while the receivers are run.  No results are propagated from
1207     * receivers and receivers can not abort the broadcast. If you want
1208     * to allow receivers to propagate results or abort the broadcast, you must
1209     * send an ordered broadcast using
1210     * {@link #sendOrderedBroadcast(Intent, String)}.
1211     *
1212     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1213     *
1214     * @param intent The Intent to broadcast; all receivers matching this
1215     *               Intent will receive the broadcast.
1216     *
1217     * @see android.content.BroadcastReceiver
1218     * @see #registerReceiver
1219     * @see #sendBroadcast(Intent, String)
1220     * @see #sendOrderedBroadcast(Intent, String)
1221     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1222     */
1223    public abstract void sendBroadcast(Intent intent);
1224
1225    /**
1226     * Broadcast the given intent to all interested BroadcastReceivers, allowing
1227     * an optional required permission to be enforced.  This
1228     * call is asynchronous; it returns immediately, and you will continue
1229     * executing while the receivers are run.  No results are propagated from
1230     * receivers and receivers can not abort the broadcast. If you want
1231     * to allow receivers to propagate results or abort the broadcast, you must
1232     * send an ordered broadcast using
1233     * {@link #sendOrderedBroadcast(Intent, String)}.
1234     *
1235     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1236     *
1237     * @param intent The Intent to broadcast; all receivers matching this
1238     *               Intent will receive the broadcast.
1239     * @param receiverPermission (optional) String naming a permission that
1240     *               a receiver must hold in order to receive your broadcast.
1241     *               If null, no permission is required.
1242     *
1243     * @see android.content.BroadcastReceiver
1244     * @see #registerReceiver
1245     * @see #sendBroadcast(Intent)
1246     * @see #sendOrderedBroadcast(Intent, String)
1247     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1248     */
1249    public abstract void sendBroadcast(Intent intent,
1250            @Nullable String receiverPermission);
1251
1252    /**
1253     * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
1254     * of an associated app op as per {@link android.app.AppOpsManager}.
1255     * @hide
1256     */
1257    public abstract void sendBroadcast(Intent intent,
1258            String receiverPermission, int appOp);
1259
1260    /**
1261     * Broadcast the given intent to all interested BroadcastReceivers, delivering
1262     * them one at a time to allow more preferred receivers to consume the
1263     * broadcast before it is delivered to less preferred receivers.  This
1264     * call is asynchronous; it returns immediately, and you will continue
1265     * executing while the receivers are run.
1266     *
1267     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1268     *
1269     * @param intent The Intent to broadcast; all receivers matching this
1270     *               Intent will receive the broadcast.
1271     * @param receiverPermission (optional) String naming a permissions that
1272     *               a receiver must hold in order to receive your broadcast.
1273     *               If null, no permission is required.
1274     *
1275     * @see android.content.BroadcastReceiver
1276     * @see #registerReceiver
1277     * @see #sendBroadcast(Intent)
1278     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1279     */
1280    public abstract void sendOrderedBroadcast(Intent intent,
1281            @Nullable String receiverPermission);
1282
1283    /**
1284     * Version of {@link #sendBroadcast(Intent)} that allows you to
1285     * receive data back from the broadcast.  This is accomplished by
1286     * supplying your own BroadcastReceiver when calling, which will be
1287     * treated as a final receiver at the end of the broadcast -- its
1288     * {@link BroadcastReceiver#onReceive} method will be called with
1289     * the result values collected from the other receivers.  The broadcast will
1290     * be serialized in the same way as calling
1291     * {@link #sendOrderedBroadcast(Intent, String)}.
1292     *
1293     * <p>Like {@link #sendBroadcast(Intent)}, this method is
1294     * asynchronous; it will return before
1295     * resultReceiver.onReceive() is called.
1296     *
1297     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1298     *
1299     * @param intent The Intent to broadcast; all receivers matching this
1300     *               Intent will receive the broadcast.
1301     * @param receiverPermission String naming a permissions that
1302     *               a receiver must hold in order to receive your broadcast.
1303     *               If null, no permission is required.
1304     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1305     *                       receiver of the broadcast.
1306     * @param scheduler A custom Handler with which to schedule the
1307     *                  resultReceiver callback; if null it will be
1308     *                  scheduled in the Context's main thread.
1309     * @param initialCode An initial value for the result code.  Often
1310     *                    Activity.RESULT_OK.
1311     * @param initialData An initial value for the result data.  Often
1312     *                    null.
1313     * @param initialExtras An initial value for the result extras.  Often
1314     *                      null.
1315     *
1316     * @see #sendBroadcast(Intent)
1317     * @see #sendBroadcast(Intent, String)
1318     * @see #sendOrderedBroadcast(Intent, String)
1319     * @see #sendStickyBroadcast(Intent)
1320     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1321     * @see android.content.BroadcastReceiver
1322     * @see #registerReceiver
1323     * @see android.app.Activity#RESULT_OK
1324     */
1325    public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1326            @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1327            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1328            @Nullable Bundle initialExtras);
1329
1330    /**
1331     * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1332     * int, String, android.os.Bundle)}, but also allows specification
1333     * of an associated app op as per {@link android.app.AppOpsManager}.
1334     * @hide
1335     */
1336    public abstract void sendOrderedBroadcast(Intent intent,
1337            String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1338            Handler scheduler, int initialCode, String initialData,
1339            Bundle initialExtras);
1340
1341    /**
1342     * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1343     * user the broadcast will be sent to.  This is not available to applications
1344     * that are not pre-installed on the system image.  Using it requires holding
1345     * the INTERACT_ACROSS_USERS permission.
1346     * @param intent The intent to broadcast
1347     * @param user UserHandle to send the intent to.
1348     * @see #sendBroadcast(Intent)
1349     */
1350    public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
1351
1352    /**
1353     * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1354     * user the broadcast will be sent to.  This is not available to applications
1355     * that are not pre-installed on the system image.  Using it requires holding
1356     * the INTERACT_ACROSS_USERS permission.
1357     *
1358     * @param intent The Intent to broadcast; all receivers matching this
1359     *               Intent will receive the broadcast.
1360     * @param user UserHandle to send the intent to.
1361     * @param receiverPermission (optional) String naming a permission that
1362     *               a receiver must hold in order to receive your broadcast.
1363     *               If null, no permission is required.
1364     *
1365     * @see #sendBroadcast(Intent, String)
1366     */
1367    public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1368            @Nullable String receiverPermission);
1369
1370    /**
1371     * Version of
1372     * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1373     * that allows you to specify the
1374     * user the broadcast will be sent to.  This is not available to applications
1375     * that are not pre-installed on the system image.  Using it requires holding
1376     * the INTERACT_ACROSS_USERS permission.
1377     *
1378     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1379     *
1380     * @param intent The Intent to broadcast; all receivers matching this
1381     *               Intent will receive the broadcast.
1382     * @param user UserHandle to send the intent to.
1383     * @param receiverPermission String naming a permissions that
1384     *               a receiver must hold in order to receive your broadcast.
1385     *               If null, no permission is required.
1386     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1387     *                       receiver of the broadcast.
1388     * @param scheduler A custom Handler with which to schedule the
1389     *                  resultReceiver callback; if null it will be
1390     *                  scheduled in the Context's main thread.
1391     * @param initialCode An initial value for the result code.  Often
1392     *                    Activity.RESULT_OK.
1393     * @param initialData An initial value for the result data.  Often
1394     *                    null.
1395     * @param initialExtras An initial value for the result extras.  Often
1396     *                      null.
1397     *
1398     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1399     */
1400    public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1401            @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1402            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1403            @Nullable  Bundle initialExtras);
1404
1405    /**
1406     * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1407     * Intent you are sending stays around after the broadcast is complete,
1408     * so that others can quickly retrieve that data through the return
1409     * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
1410     * all other ways, this behaves the same as
1411     * {@link #sendBroadcast(Intent)}.
1412     *
1413     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1414     * permission in order to use this API.  If you do not hold that
1415     * permission, {@link SecurityException} will be thrown.
1416     *
1417     * @param intent The Intent to broadcast; all receivers matching this
1418     * Intent will receive the broadcast, and the Intent will be held to
1419     * be re-broadcast to future receivers.
1420     *
1421     * @see #sendBroadcast(Intent)
1422     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1423     */
1424    public abstract void sendStickyBroadcast(Intent intent);
1425
1426    /**
1427     * Version of {@link #sendStickyBroadcast} that allows you to
1428     * receive data back from the broadcast.  This is accomplished by
1429     * supplying your own BroadcastReceiver when calling, which will be
1430     * treated as a final receiver at the end of the broadcast -- its
1431     * {@link BroadcastReceiver#onReceive} method will be called with
1432     * the result values collected from the other receivers.  The broadcast will
1433     * be serialized in the same way as calling
1434     * {@link #sendOrderedBroadcast(Intent, String)}.
1435     *
1436     * <p>Like {@link #sendBroadcast(Intent)}, this method is
1437     * asynchronous; it will return before
1438     * resultReceiver.onReceive() is called.  Note that the sticky data
1439     * stored is only the data you initially supply to the broadcast, not
1440     * the result of any changes made by the receivers.
1441     *
1442     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1443     *
1444     * @param intent The Intent to broadcast; all receivers matching this
1445     *               Intent will receive the broadcast.
1446     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1447     *                       receiver of the broadcast.
1448     * @param scheduler A custom Handler with which to schedule the
1449     *                  resultReceiver callback; if null it will be
1450     *                  scheduled in the Context's main thread.
1451     * @param initialCode An initial value for the result code.  Often
1452     *                    Activity.RESULT_OK.
1453     * @param initialData An initial value for the result data.  Often
1454     *                    null.
1455     * @param initialExtras An initial value for the result extras.  Often
1456     *                      null.
1457     *
1458     * @see #sendBroadcast(Intent)
1459     * @see #sendBroadcast(Intent, String)
1460     * @see #sendOrderedBroadcast(Intent, String)
1461     * @see #sendStickyBroadcast(Intent)
1462     * @see android.content.BroadcastReceiver
1463     * @see #registerReceiver
1464     * @see android.app.Activity#RESULT_OK
1465     */
1466    public abstract void sendStickyOrderedBroadcast(Intent intent,
1467            BroadcastReceiver resultReceiver,
1468            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1469            @Nullable Bundle initialExtras);
1470
1471    /**
1472     * Remove the data previously sent with {@link #sendStickyBroadcast},
1473     * so that it is as if the sticky broadcast had never happened.
1474     *
1475     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1476     * permission in order to use this API.  If you do not hold that
1477     * permission, {@link SecurityException} will be thrown.
1478     *
1479     * @param intent The Intent that was previously broadcast.
1480     *
1481     * @see #sendStickyBroadcast
1482     */
1483    public abstract void removeStickyBroadcast(Intent intent);
1484
1485    /**
1486     * Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
1487     * user the broadcast will be sent to.  This is not available to applications
1488     * that are not pre-installed on the system image.  Using it requires holding
1489     * the INTERACT_ACROSS_USERS permission.
1490     *
1491     * @param intent The Intent to broadcast; all receivers matching this
1492     * Intent will receive the broadcast, and the Intent will be held to
1493     * be re-broadcast to future receivers.
1494     * @param user UserHandle to send the intent to.
1495     *
1496     * @see #sendBroadcast(Intent)
1497     */
1498    public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1499
1500    /**
1501     * Version of
1502     * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1503     * that allows you to specify the
1504     * user the broadcast will be sent to.  This is not available to applications
1505     * that are not pre-installed on the system image.  Using it requires holding
1506     * the INTERACT_ACROSS_USERS permission.
1507     *
1508     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1509     *
1510     * @param intent The Intent to broadcast; all receivers matching this
1511     *               Intent will receive the broadcast.
1512     * @param user UserHandle to send the intent to.
1513     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1514     *                       receiver of the broadcast.
1515     * @param scheduler A custom Handler with which to schedule the
1516     *                  resultReceiver callback; if null it will be
1517     *                  scheduled in the Context's main thread.
1518     * @param initialCode An initial value for the result code.  Often
1519     *                    Activity.RESULT_OK.
1520     * @param initialData An initial value for the result data.  Often
1521     *                    null.
1522     * @param initialExtras An initial value for the result extras.  Often
1523     *                      null.
1524     *
1525     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1526     */
1527    public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1528            UserHandle user, BroadcastReceiver resultReceiver,
1529            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1530            @Nullable Bundle initialExtras);
1531
1532    /**
1533     * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
1534     * user the broadcast will be sent to.  This is not available to applications
1535     * that are not pre-installed on the system image.  Using it requires holding
1536     * the INTERACT_ACROSS_USERS permission.
1537     *
1538     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1539     * permission in order to use this API.  If you do not hold that
1540     * permission, {@link SecurityException} will be thrown.
1541     *
1542     * @param intent The Intent that was previously broadcast.
1543     * @param user UserHandle to remove the sticky broadcast from.
1544     *
1545     * @see #sendStickyBroadcastAsUser
1546     */
1547    public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1548
1549    /**
1550     * Register a BroadcastReceiver to be run in the main activity thread.  The
1551     * <var>receiver</var> will be called with any broadcast Intent that
1552     * matches <var>filter</var>, in the main application thread.
1553     *
1554     * <p>The system may broadcast Intents that are "sticky" -- these stay
1555     * around after the broadcast as finished, to be sent to any later
1556     * registrations. If your IntentFilter matches one of these sticky
1557     * Intents, that Intent will be returned by this function
1558     * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1559     * been broadcast.
1560     *
1561     * <p>There may be multiple sticky Intents that match <var>filter</var>,
1562     * in which case each of these will be sent to <var>receiver</var>.  In
1563     * this case, only one of these can be returned directly by the function;
1564     * which of these that is returned is arbitrarily decided by the system.
1565     *
1566     * <p>If you know the Intent your are registering for is sticky, you can
1567     * supply null for your <var>receiver</var>.  In this case, no receiver is
1568     * registered -- the function simply returns the sticky Intent that
1569     * matches <var>filter</var>.  In the case of multiple matches, the same
1570     * rules as described above apply.
1571     *
1572     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1573     *
1574     * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1575     * registered with this method will correctly respect the
1576     * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1577     * Prior to that, it would be ignored and delivered to all matching registered
1578     * receivers.  Be careful if using this for security.</p>
1579     *
1580     * <p class="note">Note: this method <em>cannot be called from a
1581     * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1582     * that is declared in an application's manifest.  It is okay, however, to call
1583     * this method from another BroadcastReceiver that has itself been registered
1584     * at run time with {@link #registerReceiver}, since the lifetime of such a
1585     * registered BroadcastReceiver is tied to the object that registered it.</p>
1586     *
1587     * @param receiver The BroadcastReceiver to handle the broadcast.
1588     * @param filter Selects the Intent broadcasts to be received.
1589     *
1590     * @return The first sticky intent found that matches <var>filter</var>,
1591     *         or null if there are none.
1592     *
1593     * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1594     * @see #sendBroadcast
1595     * @see #unregisterReceiver
1596     */
1597    @Nullable
1598    public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
1599                                            IntentFilter filter);
1600
1601    /**
1602     * Register to receive intent broadcasts, to run in the context of
1603     * <var>scheduler</var>.  See
1604     * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1605     * information.  This allows you to enforce permissions on who can
1606     * broadcast intents to your receiver, or have the receiver run in
1607     * a different thread than the main application thread.
1608     *
1609     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1610     *
1611     * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1612     * registered with this method will correctly respect the
1613     * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1614     * Prior to that, it would be ignored and delivered to all matching registered
1615     * receivers.  Be careful if using this for security.</p>
1616     *
1617     * @param receiver The BroadcastReceiver to handle the broadcast.
1618     * @param filter Selects the Intent broadcasts to be received.
1619     * @param broadcastPermission String naming a permissions that a
1620     *      broadcaster must hold in order to send an Intent to you.  If null,
1621     *      no permission is required.
1622     * @param scheduler Handler identifying the thread that will receive
1623     *      the Intent.  If null, the main thread of the process will be used.
1624     *
1625     * @return The first sticky intent found that matches <var>filter</var>,
1626     *         or null if there are none.
1627     *
1628     * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1629     * @see #sendBroadcast
1630     * @see #unregisterReceiver
1631     */
1632    @Nullable
1633    public abstract Intent registerReceiver(BroadcastReceiver receiver,
1634            IntentFilter filter, @Nullable String broadcastPermission,
1635            @Nullable Handler scheduler);
1636
1637    /**
1638     * @hide
1639     * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1640     * but for a specific user.  This receiver will receiver broadcasts that
1641     * are sent to the requested user.  It
1642     * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1643     * permission.
1644     *
1645     * @param receiver The BroadcastReceiver to handle the broadcast.
1646     * @param user UserHandle to send the intent to.
1647     * @param filter Selects the Intent broadcasts to be received.
1648     * @param broadcastPermission String naming a permissions that a
1649     *      broadcaster must hold in order to send an Intent to you.  If null,
1650     *      no permission is required.
1651     * @param scheduler Handler identifying the thread that will receive
1652     *      the Intent.  If null, the main thread of the process will be used.
1653     *
1654     * @return The first sticky intent found that matches <var>filter</var>,
1655     *         or null if there are none.
1656     *
1657     * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1658     * @see #sendBroadcast
1659     * @see #unregisterReceiver
1660     */
1661    @Nullable
1662    public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
1663            UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1664            @Nullable Handler scheduler);
1665
1666    /**
1667     * Unregister a previously registered BroadcastReceiver.  <em>All</em>
1668     * filters that have been registered for this BroadcastReceiver will be
1669     * removed.
1670     *
1671     * @param receiver The BroadcastReceiver to unregister.
1672     *
1673     * @see #registerReceiver
1674     */
1675    public abstract void unregisterReceiver(BroadcastReceiver receiver);
1676
1677    /**
1678     * Request that a given application service be started.  The Intent
1679     * should contain either contain the complete class name of a specific service
1680     * implementation to start or a specific package name to target.  If the
1681     * Intent is less specified, it will either throw an {@link IllegalArgumentException}
1682     * (if the caller targets {@link android.os.Build.VERSION_CODES#KITKAT} or later),
1683     * or which of multiple matching services it finds and uses will be undefined.  If this service
1684     * is not already running, it will be instantiated and started (creating a
1685     * process for it if needed); if it is running then it remains running.
1686     *
1687     * <p>Every call to this method will result in a corresponding call to
1688     * the target service's {@link android.app.Service#onStartCommand} method,
1689     * with the <var>intent</var> given here.  This provides a convenient way
1690     * to submit jobs to a service without having to bind and call on to its
1691     * interface.
1692     *
1693     * <p>Using startService() overrides the default service lifetime that is
1694     * managed by {@link #bindService}: it requires the service to remain
1695     * running until {@link #stopService} is called, regardless of whether
1696     * any clients are connected to it.  Note that calls to startService()
1697     * are not nesting: no matter how many times you call startService(),
1698     * a single call to {@link #stopService} will stop it.
1699     *
1700     * <p>The system attempts to keep running services around as much as
1701     * possible.  The only time they should be stopped is if the current
1702     * foreground application is using so many resources that the service needs
1703     * to be killed.  If any errors happen in the service's process, it will
1704     * automatically be restarted.
1705     *
1706     * <p>This function will throw {@link SecurityException} if you do not
1707     * have permission to start the given service.
1708     *
1709     * @param service Identifies the service to be started.  The Intent must be either
1710     *      fully explicit (supplying a component name) or specify a specific package
1711     *      name it is targetted to.  Additional values
1712     *      may be included in the Intent extras to supply arguments along with
1713     *      this specific start call.
1714     *
1715     * @return If the service is being started or is already running, the
1716     * {@link ComponentName} of the actual service that was started is
1717     * returned; else if the service does not exist null is returned.
1718     *
1719     * @throws SecurityException &nbsp;
1720     *
1721     * @see #stopService
1722     * @see #bindService
1723     */
1724    @Nullable
1725    public abstract ComponentName startService(Intent service);
1726
1727    /**
1728     * Request that a given application service be stopped.  If the service is
1729     * not running, nothing happens.  Otherwise it is stopped.  Note that calls
1730     * to startService() are not counted -- this stops the service no matter
1731     * how many times it was started.
1732     *
1733     * <p>Note that if a stopped service still has {@link ServiceConnection}
1734     * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1735     * not be destroyed until all of these bindings are removed.  See
1736     * the {@link android.app.Service} documentation for more details on a
1737     * service's lifecycle.
1738     *
1739     * <p>This function will throw {@link SecurityException} if you do not
1740     * have permission to stop the given service.
1741     *
1742     * @param service Description of the service to be stopped.  The Intent must be either
1743     *      fully explicit (supplying a component name) or specify a specific package
1744     *      name it is targetted to.
1745     *
1746     * @return If there is a service matching the given Intent that is already
1747     * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
1748     *
1749     * @throws SecurityException &nbsp;
1750     *
1751     * @see #startService
1752     */
1753    public abstract boolean stopService(Intent service);
1754
1755    /**
1756     * @hide like {@link #startService(Intent)} but for a specific user.
1757     */
1758    public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1759
1760    /**
1761     * @hide like {@link #stopService(Intent)} but for a specific user.
1762     */
1763    public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
1764
1765    /**
1766     * Connect to an application service, creating it if needed.  This defines
1767     * a dependency between your application and the service.  The given
1768     * <var>conn</var> will receive the service object when it is created and be
1769     * told if it dies and restarts.  The service will be considered required
1770     * by the system only for as long as the calling context exists.  For
1771     * example, if this Context is an Activity that is stopped, the service will
1772     * not be required to continue running until the Activity is resumed.
1773     *
1774     * <p>This function will throw {@link SecurityException} if you do not
1775     * have permission to bind to the given service.
1776     *
1777     * <p class="note">Note: this method <em>can not be called from a
1778     * {@link BroadcastReceiver} component</em>.  A pattern you can use to
1779     * communicate from a BroadcastReceiver to a Service is to call
1780     * {@link #startService} with the arguments containing the command to be
1781     * sent, with the service calling its
1782     * {@link android.app.Service#stopSelf(int)} method when done executing
1783     * that command.  See the API demo App/Service/Service Start Arguments
1784     * Controller for an illustration of this.  It is okay, however, to use
1785     * this method from a BroadcastReceiver that has been registered with
1786     * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1787     * is tied to another object (the one that registered it).</p>
1788     *
1789     * @param service Identifies the service to connect to.  The Intent may
1790     *      specify either an explicit component name, or a logical
1791     *      description (action, category, etc) to match an
1792     *      {@link IntentFilter} published by a service.
1793     * @param conn Receives information as the service is started and stopped.
1794     *      This must be a valid ServiceConnection object; it must not be null.
1795     * @param flags Operation options for the binding.  May be 0,
1796     *          {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1797     *          {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1798     *          {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1799     *          {@link #BIND_WAIVE_PRIORITY}.
1800     * @return If you have successfully bound to the service, {@code true} is returned;
1801     *         {@code false} is returned if the connection is not made so you will not
1802     *         receive the service object.
1803     *
1804     * @throws SecurityException &nbsp;
1805     *
1806     * @see #unbindService
1807     * @see #startService
1808     * @see #BIND_AUTO_CREATE
1809     * @see #BIND_DEBUG_UNBIND
1810     * @see #BIND_NOT_FOREGROUND
1811     */
1812    public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
1813            @BindServiceFlags int flags);
1814
1815    /**
1816     * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
1817     * argument for use by system server and other multi-user aware code.
1818     * @hide
1819     */
1820    public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
1821        throw new RuntimeException("Not implemented. Must override in a subclass.");
1822    }
1823
1824    /**
1825     * Disconnect from an application service.  You will no longer receive
1826     * calls as the service is restarted, and the service is now allowed to
1827     * stop at any time.
1828     *
1829     * @param conn The connection interface previously supplied to
1830     *             bindService().  This parameter must not be null.
1831     *
1832     * @see #bindService
1833     */
1834    public abstract void unbindService(@NonNull ServiceConnection conn);
1835
1836    /**
1837     * Start executing an {@link android.app.Instrumentation} class.  The given
1838     * Instrumentation component will be run by killing its target application
1839     * (if currently running), starting the target process, instantiating the
1840     * instrumentation component, and then letting it drive the application.
1841     *
1842     * <p>This function is not synchronous -- it returns as soon as the
1843     * instrumentation has started and while it is running.
1844     *
1845     * <p>Instrumentation is normally only allowed to run against a package
1846     * that is either unsigned or signed with a signature that the
1847     * the instrumentation package is also signed with (ensuring the target
1848     * trusts the instrumentation).
1849     *
1850     * @param className Name of the Instrumentation component to be run.
1851     * @param profileFile Optional path to write profiling data as the
1852     * instrumentation runs, or null for no profiling.
1853     * @param arguments Additional optional arguments to pass to the
1854     * instrumentation, or null.
1855     *
1856     * @return {@code true} if the instrumentation was successfully started,
1857     * else {@code false} if it could not be found.
1858     */
1859    public abstract boolean startInstrumentation(@NonNull ComponentName className,
1860            @Nullable String profileFile, @Nullable Bundle arguments);
1861
1862    /** @hide */
1863    @StringDef({
1864            POWER_SERVICE,
1865            WINDOW_SERVICE,
1866            LAYOUT_INFLATER_SERVICE,
1867            ACCOUNT_SERVICE,
1868            ACTIVITY_SERVICE,
1869            ALARM_SERVICE,
1870            NOTIFICATION_SERVICE,
1871            ACCESSIBILITY_SERVICE,
1872            CAPTIONING_SERVICE,
1873            KEYGUARD_SERVICE,
1874            LOCATION_SERVICE,
1875            //@hide: COUNTRY_DETECTOR,
1876            SEARCH_SERVICE,
1877            SENSOR_SERVICE,
1878            STORAGE_SERVICE,
1879            WALLPAPER_SERVICE,
1880            VIBRATOR_SERVICE,
1881            //@hide: STATUS_BAR_SERVICE,
1882            CONNECTIVITY_SERVICE,
1883            //@hide: UPDATE_LOCK_SERVICE,
1884            //@hide: NETWORKMANAGEMENT_SERVICE,
1885            //@hide: NETWORK_STATS_SERVICE,
1886            //@hide: NETWORK_POLICY_SERVICE,
1887            WIFI_SERVICE,
1888            WIFI_P2P_SERVICE,
1889            NSD_SERVICE,
1890            AUDIO_SERVICE,
1891            MEDIA_ROUTER_SERVICE,
1892            TELEPHONY_SERVICE,
1893            CLIPBOARD_SERVICE,
1894            INPUT_METHOD_SERVICE,
1895            TEXT_SERVICES_MANAGER_SERVICE,
1896            //@hide: APPWIDGET_SERVICE,
1897            //@hide: BACKUP_SERVICE,
1898            DROPBOX_SERVICE,
1899            DEVICE_POLICY_SERVICE,
1900            UI_MODE_SERVICE,
1901            DOWNLOAD_SERVICE,
1902            NFC_SERVICE,
1903            BLUETOOTH_SERVICE,
1904            //@hide: SIP_SERVICE,
1905            USB_SERVICE,
1906            //@hide: SERIAL_SERVICE,
1907            INPUT_SERVICE,
1908            DISPLAY_SERVICE,
1909            //@hide: SCHEDULING_POLICY_SERVICE,
1910            USER_SERVICE,
1911            //@hide: APP_OPS_SERVICE
1912            CAMERA_SERVICE,
1913            PRINT_SERVICE
1914    })
1915    @Retention(RetentionPolicy.SOURCE)
1916    public @interface ServiceName {}
1917
1918    /**
1919     * Return the handle to a system-level service by name. The class of the
1920     * returned object varies by the requested name. Currently available names
1921     * are:
1922     *
1923     * <dl>
1924     *  <dt> {@link #WINDOW_SERVICE} ("window")
1925     *  <dd> The top-level window manager in which you can place custom
1926     *  windows.  The returned object is a {@link android.view.WindowManager}.
1927     *  <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
1928     *  <dd> A {@link android.view.LayoutInflater} for inflating layout resources
1929     *  in this context.
1930     *  <dt> {@link #ACTIVITY_SERVICE} ("activity")
1931     *  <dd> A {@link android.app.ActivityManager} for interacting with the
1932     *  global activity state of the system.
1933     *  <dt> {@link #POWER_SERVICE} ("power")
1934     *  <dd> A {@link android.os.PowerManager} for controlling power
1935     *  management.
1936     *  <dt> {@link #ALARM_SERVICE} ("alarm")
1937     *  <dd> A {@link android.app.AlarmManager} for receiving intents at the
1938     *  time of your choosing.
1939     *  <dt> {@link #NOTIFICATION_SERVICE} ("notification")
1940     *  <dd> A {@link android.app.NotificationManager} for informing the user
1941     *   of background events.
1942     *  <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
1943     *  <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
1944     *  <dt> {@link #LOCATION_SERVICE} ("location")
1945     *  <dd> A {@link android.location.LocationManager} for controlling location
1946     *   (e.g., GPS) updates.
1947     *  <dt> {@link #SEARCH_SERVICE} ("search")
1948     *  <dd> A {@link android.app.SearchManager} for handling search.
1949     *  <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
1950     *  <dd> A {@link android.os.Vibrator} for interacting with the vibrator
1951     *  hardware.
1952     *  <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
1953     *  <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
1954     *  handling management of network connections.
1955     *  <dt> {@link #WIFI_SERVICE} ("wifi")
1956     *  <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
1957     * Wi-Fi connectivity.
1958     * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
1959     * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
1960     * for management of input methods.
1961     * <dt> {@link #UI_MODE_SERVICE} ("uimode")
1962     * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
1963     * <dt> {@link #DOWNLOAD_SERVICE} ("download")
1964     * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
1965     * </dl>
1966     *
1967     * <p>Note:  System services obtained via this API may be closely associated with
1968     * the Context in which they are obtained from.  In general, do not share the
1969     * service objects between various different contexts (Activities, Applications,
1970     * Services, Providers, etc.)
1971     *
1972     * @param name The name of the desired service.
1973     *
1974     * @return The service or null if the name does not exist.
1975     *
1976     * @see #WINDOW_SERVICE
1977     * @see android.view.WindowManager
1978     * @see #LAYOUT_INFLATER_SERVICE
1979     * @see android.view.LayoutInflater
1980     * @see #ACTIVITY_SERVICE
1981     * @see android.app.ActivityManager
1982     * @see #POWER_SERVICE
1983     * @see android.os.PowerManager
1984     * @see #ALARM_SERVICE
1985     * @see android.app.AlarmManager
1986     * @see #NOTIFICATION_SERVICE
1987     * @see android.app.NotificationManager
1988     * @see #KEYGUARD_SERVICE
1989     * @see android.app.KeyguardManager
1990     * @see #LOCATION_SERVICE
1991     * @see android.location.LocationManager
1992     * @see #SEARCH_SERVICE
1993     * @see android.app.SearchManager
1994     * @see #SENSOR_SERVICE
1995     * @see android.hardware.SensorManager
1996     * @see #STORAGE_SERVICE
1997     * @see android.os.storage.StorageManager
1998     * @see #VIBRATOR_SERVICE
1999     * @see android.os.Vibrator
2000     * @see #CONNECTIVITY_SERVICE
2001     * @see android.net.ConnectivityManager
2002     * @see #WIFI_SERVICE
2003     * @see android.net.wifi.WifiManager
2004     * @see #AUDIO_SERVICE
2005     * @see android.media.AudioManager
2006     * @see #MEDIA_ROUTER_SERVICE
2007     * @see android.media.MediaRouter
2008     * @see #TELEPHONY_SERVICE
2009     * @see android.telephony.TelephonyManager
2010     * @see #INPUT_METHOD_SERVICE
2011     * @see android.view.inputmethod.InputMethodManager
2012     * @see #UI_MODE_SERVICE
2013     * @see android.app.UiModeManager
2014     * @see #DOWNLOAD_SERVICE
2015     * @see android.app.DownloadManager
2016     */
2017    public abstract Object getSystemService(@ServiceName @NonNull String name);
2018
2019    /**
2020     * Use with {@link #getSystemService} to retrieve a
2021     * {@link android.os.PowerManager} for controlling power management,
2022     * including "wake locks," which let you keep the device on while
2023     * you're running long tasks.
2024     */
2025    public static final String POWER_SERVICE = "power";
2026
2027    /**
2028     * Use with {@link #getSystemService} to retrieve a
2029     * {@link android.view.WindowManager} for accessing the system's window
2030     * manager.
2031     *
2032     * @see #getSystemService
2033     * @see android.view.WindowManager
2034     */
2035    public static final String WINDOW_SERVICE = "window";
2036
2037    /**
2038     * Use with {@link #getSystemService} to retrieve a
2039     * {@link android.view.LayoutInflater} for inflating layout resources in this
2040     * context.
2041     *
2042     * @see #getSystemService
2043     * @see android.view.LayoutInflater
2044     */
2045    public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
2046
2047    /**
2048     * Use with {@link #getSystemService} to retrieve a
2049     * {@link android.accounts.AccountManager} for receiving intents at a
2050     * time of your choosing.
2051     *
2052     * @see #getSystemService
2053     * @see android.accounts.AccountManager
2054     */
2055    public static final String ACCOUNT_SERVICE = "account";
2056
2057    /**
2058     * Use with {@link #getSystemService} to retrieve a
2059     * {@link android.app.ActivityManager} for interacting with the global
2060     * system state.
2061     *
2062     * @see #getSystemService
2063     * @see android.app.ActivityManager
2064     */
2065    public static final String ACTIVITY_SERVICE = "activity";
2066
2067    /**
2068     * Use with {@link #getSystemService} to retrieve a
2069     * {@link android.app.AlarmManager} for receiving intents at a
2070     * time of your choosing.
2071     *
2072     * @see #getSystemService
2073     * @see android.app.AlarmManager
2074     */
2075    public static final String ALARM_SERVICE = "alarm";
2076
2077    /**
2078     * Use with {@link #getSystemService} to retrieve a
2079     * {@link android.app.NotificationManager} for informing the user of
2080     * background events.
2081     *
2082     * @see #getSystemService
2083     * @see android.app.NotificationManager
2084     */
2085    public static final String NOTIFICATION_SERVICE = "notification";
2086
2087    /**
2088     * Use with {@link #getSystemService} to retrieve a
2089     * {@link android.view.accessibility.AccessibilityManager} for giving the user
2090     * feedback for UI events through the registered event listeners.
2091     *
2092     * @see #getSystemService
2093     * @see android.view.accessibility.AccessibilityManager
2094     */
2095    public static final String ACCESSIBILITY_SERVICE = "accessibility";
2096
2097    /**
2098     * Use with {@link #getSystemService} to retrieve a
2099     * {@link android.view.accessibility.CaptioningManager} for obtaining
2100     * captioning properties and listening for changes in captioning
2101     * preferences.
2102     *
2103     * @see #getSystemService
2104     * @see android.view.accessibility.CaptioningManager
2105     */
2106    public static final String CAPTIONING_SERVICE = "captioning";
2107
2108    /**
2109     * Use with {@link #getSystemService} to retrieve a
2110     * {@link android.app.NotificationManager} for controlling keyguard.
2111     *
2112     * @see #getSystemService
2113     * @see android.app.KeyguardManager
2114     */
2115    public static final String KEYGUARD_SERVICE = "keyguard";
2116
2117    /**
2118     * Use with {@link #getSystemService} to retrieve a {@link
2119     * android.location.LocationManager} for controlling location
2120     * updates.
2121     *
2122     * @see #getSystemService
2123     * @see android.location.LocationManager
2124     */
2125    public static final String LOCATION_SERVICE = "location";
2126
2127    /**
2128     * Use with {@link #getSystemService} to retrieve a
2129     * {@link android.location.CountryDetector} for detecting the country that
2130     * the user is in.
2131     *
2132     * @hide
2133     */
2134    public static final String COUNTRY_DETECTOR = "country_detector";
2135
2136    /**
2137     * Use with {@link #getSystemService} to retrieve a {@link
2138     * android.app.SearchManager} for handling searches.
2139     *
2140     * @see #getSystemService
2141     * @see android.app.SearchManager
2142     */
2143    public static final String SEARCH_SERVICE = "search";
2144
2145    /**
2146     * Use with {@link #getSystemService} to retrieve a {@link
2147     * android.hardware.SensorManager} for accessing sensors.
2148     *
2149     * @see #getSystemService
2150     * @see android.hardware.SensorManager
2151     */
2152    public static final String SENSOR_SERVICE = "sensor";
2153
2154    /**
2155     * Use with {@link #getSystemService} to retrieve a {@link
2156     * android.os.storage.StorageManager} for accessing system storage
2157     * functions.
2158     *
2159     * @see #getSystemService
2160     * @see android.os.storage.StorageManager
2161     */
2162    public static final String STORAGE_SERVICE = "storage";
2163
2164    /**
2165     * Use with {@link #getSystemService} to retrieve a
2166     * com.android.server.WallpaperService for accessing wallpapers.
2167     *
2168     * @see #getSystemService
2169     */
2170    public static final String WALLPAPER_SERVICE = "wallpaper";
2171
2172    /**
2173     * Use with {@link #getSystemService} to retrieve a {@link
2174     * android.os.Vibrator} for interacting with the vibration hardware.
2175     *
2176     * @see #getSystemService
2177     * @see android.os.Vibrator
2178     */
2179    public static final String VIBRATOR_SERVICE = "vibrator";
2180
2181    /**
2182     * Use with {@link #getSystemService} to retrieve a {@link
2183     * android.app.StatusBarManager} for interacting with the status bar.
2184     *
2185     * @see #getSystemService
2186     * @see android.app.StatusBarManager
2187     * @hide
2188     */
2189    public static final String STATUS_BAR_SERVICE = "statusbar";
2190
2191    /**
2192     * Use with {@link #getSystemService} to retrieve a {@link
2193     * android.net.ConnectivityManager} for handling management of
2194     * network connections.
2195     *
2196     * @see #getSystemService
2197     * @see android.net.ConnectivityManager
2198     */
2199    public static final String CONNECTIVITY_SERVICE = "connectivity";
2200
2201    /**
2202     * Use with {@link #getSystemService} to retrieve a {@link
2203     * android.os.IUpdateLock} for managing runtime sequences that
2204     * must not be interrupted by headless OTA application or similar.
2205     *
2206     * @hide
2207     * @see #getSystemService
2208     * @see android.os.UpdateLock
2209     */
2210    public static final String UPDATE_LOCK_SERVICE = "updatelock";
2211
2212    /**
2213     * Use with {@link #getSystemService} to retrieve a {@link
2214     * android.net.NetworkManagementService} for handling management of
2215     * system network services
2216     *
2217     * @hide
2218     * @see #getSystemService
2219     * @see android.net.NetworkManagementService
2220     */
2221    public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2222
2223    /** {@hide} */
2224    public static final String NETWORK_STATS_SERVICE = "netstats";
2225    /** {@hide} */
2226    public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2227
2228    /**
2229     * Use with {@link #getSystemService} to retrieve a {@link
2230     * android.net.wifi.WifiManager} for handling management of
2231     * Wi-Fi access.
2232     *
2233     * @see #getSystemService
2234     * @see android.net.wifi.WifiManager
2235     */
2236    public static final String WIFI_SERVICE = "wifi";
2237
2238    /**
2239     * Use with {@link #getSystemService} to retrieve a {@link
2240     * android.net.wifi.p2p.WifiP2pManager} for handling management of
2241     * Wi-Fi peer-to-peer connections.
2242     *
2243     * @see #getSystemService
2244     * @see android.net.wifi.p2p.WifiP2pManager
2245     */
2246    public static final String WIFI_P2P_SERVICE = "wifip2p";
2247
2248    /**
2249     * Use with {@link #getSystemService} to retrieve a {@link
2250     * android.net.nsd.NsdManager} for handling management of network service
2251     * discovery
2252     *
2253     * @see #getSystemService
2254     * @see android.net.nsd.NsdManager
2255     */
2256    public static final String NSD_SERVICE = "servicediscovery";
2257
2258    /**
2259     * Use with {@link #getSystemService} to retrieve a
2260     * {@link android.media.AudioManager} for handling management of volume,
2261     * ringer modes and audio routing.
2262     *
2263     * @see #getSystemService
2264     * @see android.media.AudioManager
2265     */
2266    public static final String AUDIO_SERVICE = "audio";
2267
2268    /**
2269     * Use with {@link #getSystemService} to retrieve a
2270     * {@link android.media.MediaRouter} for controlling and managing
2271     * routing of media.
2272     *
2273     * @see #getSystemService
2274     * @see android.media.MediaRouter
2275     */
2276    public static final String MEDIA_ROUTER_SERVICE = "media_router";
2277
2278    /**
2279     * Use with {@link #getSystemService} to retrieve a
2280     * {@link android.telephony.TelephonyManager} for handling management the
2281     * telephony features of the device.
2282     *
2283     * @see #getSystemService
2284     * @see android.telephony.TelephonyManager
2285     */
2286    public static final String TELEPHONY_SERVICE = "phone";
2287
2288    /**
2289     * Use with {@link #getSystemService} to retrieve a
2290     * {@link android.text.ClipboardManager} for accessing and modifying
2291     * the contents of the global clipboard.
2292     *
2293     * @see #getSystemService
2294     * @see android.text.ClipboardManager
2295     */
2296    public static final String CLIPBOARD_SERVICE = "clipboard";
2297
2298    /**
2299     * Use with {@link #getSystemService} to retrieve a
2300     * {@link android.view.inputmethod.InputMethodManager} for accessing input
2301     * methods.
2302     *
2303     * @see #getSystemService
2304     */
2305    public static final String INPUT_METHOD_SERVICE = "input_method";
2306
2307    /**
2308     * Use with {@link #getSystemService} to retrieve a
2309     * {@link android.view.textservice.TextServicesManager} for accessing
2310     * text services.
2311     *
2312     * @see #getSystemService
2313     */
2314    public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2315
2316    /**
2317     * Use with {@link #getSystemService} to retrieve a
2318     * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
2319     *
2320     * @hide
2321     * @see #getSystemService
2322     */
2323    public static final String APPWIDGET_SERVICE = "appwidget";
2324
2325    /**
2326     * Use with {@link #getSystemService} to retrieve an
2327     * {@link android.app.backup.IBackupManager IBackupManager} for communicating
2328     * with the backup mechanism.
2329     * @hide
2330     *
2331     * @see #getSystemService
2332     */
2333    public static final String BACKUP_SERVICE = "backup";
2334
2335    /**
2336     * Use with {@link #getSystemService} to retrieve a
2337     * {@link android.os.DropBoxManager} instance for recording
2338     * diagnostic logs.
2339     * @see #getSystemService
2340     */
2341    public static final String DROPBOX_SERVICE = "dropbox";
2342
2343    /**
2344     * Use with {@link #getSystemService} to retrieve a
2345     * {@link android.app.admin.DevicePolicyManager} for working with global
2346     * device policy management.
2347     *
2348     * @see #getSystemService
2349     */
2350    public static final String DEVICE_POLICY_SERVICE = "device_policy";
2351
2352    /**
2353     * Use with {@link #getSystemService} to retrieve a
2354     * {@link android.app.UiModeManager} for controlling UI modes.
2355     *
2356     * @see #getSystemService
2357     */
2358    public static final String UI_MODE_SERVICE = "uimode";
2359
2360    /**
2361     * Use with {@link #getSystemService} to retrieve a
2362     * {@link android.app.DownloadManager} for requesting HTTP downloads.
2363     *
2364     * @see #getSystemService
2365     */
2366    public static final String DOWNLOAD_SERVICE = "download";
2367
2368    /**
2369     * Use with {@link #getSystemService} to retrieve a
2370     * {@link android.nfc.NfcManager} for using NFC.
2371     *
2372     * @see #getSystemService
2373     */
2374    public static final String NFC_SERVICE = "nfc";
2375
2376    /**
2377     * Use with {@link #getSystemService} to retrieve a
2378     * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2379     *
2380     * @see #getSystemService
2381     */
2382    public static final String BLUETOOTH_SERVICE = "bluetooth";
2383
2384    /**
2385     * Use with {@link #getSystemService} to retrieve a
2386     * {@link android.net.sip.SipManager} for accessing the SIP related service.
2387     *
2388     * @see #getSystemService
2389     */
2390    /** @hide */
2391    public static final String SIP_SERVICE = "sip";
2392
2393    /**
2394     * Use with {@link #getSystemService} to retrieve a {@link
2395     * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
2396     * and for controlling this device's behavior as a USB device.
2397     *
2398     * @see #getSystemService
2399     * @see android.hardware.usb.UsbManager
2400     */
2401    public static final String USB_SERVICE = "usb";
2402
2403    /**
2404     * Use with {@link #getSystemService} to retrieve a {@link
2405     * android.hardware.SerialManager} for access to serial ports.
2406     *
2407     * @see #getSystemService
2408     * @see android.harware.SerialManager
2409     *
2410     * @hide
2411     */
2412    public static final String SERIAL_SERVICE = "serial";
2413
2414    /**
2415     * Use with {@link #getSystemService} to retrieve a
2416     * {@link android.hardware.input.InputManager} for interacting with input devices.
2417     *
2418     * @see #getSystemService
2419     * @see android.hardware.input.InputManager
2420     */
2421    public static final String INPUT_SERVICE = "input";
2422
2423    /**
2424     * Use with {@link #getSystemService} to retrieve a
2425     * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2426     *
2427     * @see #getSystemService
2428     * @see android.hardware.display.DisplayManager
2429     */
2430    public static final String DISPLAY_SERVICE = "display";
2431
2432    /**
2433     * Use with {@link #getSystemService} to retrieve a
2434     * {@link android.os.SchedulingPolicyService} for managing scheduling policy.
2435     *
2436     * @see #getSystemService
2437     * @see android.os.SchedulingPolicyService
2438     *
2439     * @hide
2440     */
2441    public static final String SCHEDULING_POLICY_SERVICE = "scheduling_policy";
2442
2443    /**
2444     * Use with {@link #getSystemService} to retrieve a
2445     * {@link android.os.UserManager} for managing users on devices that support multiple users.
2446     *
2447     * @see #getSystemService
2448     * @see android.os.UserManager
2449     */
2450    public static final String USER_SERVICE = "user";
2451
2452    /**
2453     * Use with {@link #getSystemService} to retrieve a
2454     * {@link android.app.AppOpsManager} for tracking application operations
2455     * on the device.
2456     *
2457     * @see #getSystemService
2458     * @see android.app.AppOpsManager
2459     */
2460    public static final String APP_OPS_SERVICE = "appops";
2461
2462    /**
2463     * Use with {@link #getSystemService} to retrieve a
2464     * {@link android.hardware.camera2.CameraManager} for interacting with
2465     * camera devices.
2466     *
2467     * @see #getSystemService
2468     * @see android.hardware.camera2.CameraManager
2469     */
2470    public static final String CAMERA_SERVICE = "camera";
2471
2472    /**
2473     * {@link android.print.PrintManager} for printing and managing
2474     * printers and print tasks.
2475     *
2476     * @see #getSystemService
2477     * @see android.print.PrintManager
2478     */
2479    public static final String PRINT_SERVICE = "print";
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