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