Context.java revision 001bbbb239d4ef1005a87039c7c53e26d8f13ad6
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 filesystem similar to
651     * {@link #getFilesDir()}.  The difference is that files placed under this
652     * directory will be excluded from automatic backup to remote storage.  See
653     * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
654     * of the automatic backup mechanism in Android.
655     *
656     * <p>No permissions are required to read or write to the returned path, since this
657     * path is internal storage.
658     *
659     * @return The path of the directory holding application files that will not be
660     *         automatically backed up to remote storage.
661     *
662     * @see #openFileOutput
663     * @see #getFileStreamPath
664     * @see #getDir
665     * @see android.app.backup.BackupAgent
666     */
667    public abstract File getNoBackupFilesDir();
668
669    /**
670     * Returns the absolute path to the directory on the primary external filesystem
671     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
672     * Environment.getExternalStorageDirectory()}) where the application can
673     * place persistent files it owns.  These files are internal to the
674     * applications, and not typically visible to the user as media.
675     *
676     * <p>This is like {@link #getFilesDir()} in that these
677     * files will be deleted when the application is uninstalled, however there
678     * are some important differences:
679     *
680     * <ul>
681     * <li>External files are not always available: they will disappear if the
682     * user mounts the external storage on a computer or removes it.  See the
683     * APIs on {@link android.os.Environment} for information in the storage state.
684     * <li>There is no security enforced with these files.  For example, any application
685     * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
686     * these files.
687     * </ul>
688     *
689     * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
690     * are required to read or write to the returned path; it's always
691     * accessible to the calling app.  This only applies to paths generated for
692     * package name of the calling application.  To access paths belonging
693     * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
694     * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
695     *
696     * <p>On devices with multiple users (as described by {@link UserManager}),
697     * each user has their own isolated external storage. Applications only
698     * have access to the external storage for the user they're running as.</p>
699     *
700     * <p>Here is an example of typical code to manipulate a file in
701     * an application's private storage:</p>
702     *
703     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
704     * private_file}
705     *
706     * <p>If you supply a non-null <var>type</var> to this function, the returned
707     * file will be a path to a sub-directory of the given type.  Though these files
708     * are not automatically scanned by the media scanner, you can explicitly
709     * add them to the media database with
710     * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
711     *      OnScanCompletedListener) MediaScannerConnection.scanFile}.
712     * Note that this is not the same as
713     * {@link android.os.Environment#getExternalStoragePublicDirectory
714     * Environment.getExternalStoragePublicDirectory()}, which provides
715     * directories of media shared by all applications.  The
716     * directories returned here are
717     * owned by the application, and their contents will be removed when the
718     * application is uninstalled.  Unlike
719     * {@link android.os.Environment#getExternalStoragePublicDirectory
720     * Environment.getExternalStoragePublicDirectory()}, the directory
721     * returned here will be automatically created for you.
722     *
723     * <p>Here is an example of typical code to manipulate a picture in
724     * an application's private storage and add it to the media database:</p>
725     *
726     * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
727     * private_picture}
728     *
729     * @param type The type of files directory to return.  May be null for
730     * the root of the files directory or one of
731     * the following Environment constants for a subdirectory:
732     * {@link android.os.Environment#DIRECTORY_MUSIC},
733     * {@link android.os.Environment#DIRECTORY_PODCASTS},
734     * {@link android.os.Environment#DIRECTORY_RINGTONES},
735     * {@link android.os.Environment#DIRECTORY_ALARMS},
736     * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
737     * {@link android.os.Environment#DIRECTORY_PICTURES}, or
738     * {@link android.os.Environment#DIRECTORY_MOVIES}.
739     *
740     * @return The path of the directory holding application files
741     * on external storage.  Returns null if external storage is not currently
742     * mounted so it could not ensure the path exists; you will need to call
743     * this method again when it is available.
744     *
745     * @see #getFilesDir
746     * @see android.os.Environment#getExternalStoragePublicDirectory
747     */
748    @Nullable
749    public abstract File getExternalFilesDir(@Nullable String type);
750
751    /**
752     * Returns absolute paths to application-specific directories on all
753     * external storage devices where the application can place persistent files
754     * it owns. These files are internal to the application, and not typically
755     * visible to the user as media.
756     * <p>
757     * This is like {@link #getFilesDir()} in that these files will be deleted when
758     * the application is uninstalled, however there are some important differences:
759     * <ul>
760     * <li>External files are not always available: they will disappear if the
761     * user mounts the external storage on a computer or removes it.
762     * <li>There is no security enforced with these files.
763     * </ul>
764     * <p>
765     * External storage devices returned here are considered a permanent part of
766     * the device, including both emulated external storage and physical media
767     * slots, such as SD cards in a battery compartment. The returned paths do
768     * not include transient devices, such as USB flash drives.
769     * <p>
770     * An application may store data on any or all of the returned devices.  For
771     * example, an app may choose to store large files on the device with the
772     * most available space, as measured by {@link StatFs}.
773     * <p>
774     * No permissions are required to read or write to the returned paths; they
775     * are always accessible to the calling app.  Write access outside of these
776     * paths on secondary external storage devices is not available.
777     * <p>
778     * The first path returned is the same as {@link #getExternalFilesDir(String)}.
779     * Returned paths may be {@code null} if a storage device is unavailable.
780     *
781     * @see #getExternalFilesDir(String)
782     * @see Environment#getExternalStorageState(File)
783     */
784    public abstract File[] getExternalFilesDirs(String type);
785
786    /**
787     * Return the primary external storage directory where this application's OBB
788     * files (if there are any) can be found. Note if the application does not have
789     * any OBB files, this directory may not exist.
790     * <p>
791     * This is like {@link #getFilesDir()} in that these files will be deleted when
792     * the application is uninstalled, however there are some important differences:
793     * <ul>
794     * <li>External files are not always available: they will disappear if the
795     * user mounts the external storage on a computer or removes it.
796     * <li>There is no security enforced with these files.  For example, any application
797     * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
798     * these files.
799     * </ul>
800     * <p>
801     * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
802     * are required to read or write to the returned path; it's always
803     * accessible to the calling app.  This only applies to paths generated for
804     * package name of the calling application.  To access paths belonging
805     * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
806     * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
807     * <p>
808     * On devices with multiple users (as described by {@link UserManager}),
809     * multiple users may share the same OBB storage location. Applications
810     * should ensure that multiple instances running under different users don't
811     * interfere with each other.
812     */
813    public abstract File getObbDir();
814
815    /**
816     * Returns absolute paths to application-specific directories on all
817     * external storage devices where the application's OBB files (if there are
818     * any) can be found. Note if the application does not have any OBB files,
819     * these directories may not exist.
820     * <p>
821     * This is like {@link #getFilesDir()} in that these files will be deleted when
822     * the application is uninstalled, however there are some important differences:
823     * <ul>
824     * <li>External files are not always available: they will disappear if the
825     * user mounts the external storage on a computer or removes it.
826     * <li>There is no security enforced with these files.
827     * </ul>
828     * <p>
829     * External storage devices returned here are considered a permanent part of
830     * the device, including both emulated external storage and physical media
831     * slots, such as SD cards in a battery compartment. The returned paths do
832     * not include transient devices, such as USB flash drives.
833     * <p>
834     * An application may store data on any or all of the returned devices.  For
835     * example, an app may choose to store large files on the device with the
836     * most available space, as measured by {@link StatFs}.
837     * <p>
838     * No permissions are required to read or write to the returned paths; they
839     * are always accessible to the calling app.  Write access outside of these
840     * paths on secondary external storage devices is not available.
841     * <p>
842     * The first path returned is the same as {@link #getObbDir()}.
843     * Returned paths may be {@code null} if a storage device is unavailable.
844     *
845     * @see #getObbDir()
846     * @see Environment#getExternalStorageState(File)
847     */
848    public abstract File[] getObbDirs();
849
850    /**
851     * Returns the absolute path to the application specific cache directory
852     * on the filesystem. These files will be ones that get deleted first when the
853     * device runs low on storage.
854     * There is no guarantee when these files will be deleted.
855     *
856     * <strong>Note: you should not <em>rely</em> on the system deleting these
857     * files for you; you should always have a reasonable maximum, such as 1 MB,
858     * for the amount of space you consume with cache files, and prune those
859     * files when exceeding that space.</strong>
860     *
861     * @return The path of the directory holding application cache files.
862     *
863     * @see #openFileOutput
864     * @see #getFileStreamPath
865     * @see #getDir
866     */
867    public abstract File getCacheDir();
868
869    /**
870     * Returns the absolute path to the application specific cache directory on
871     * the filesystem designed for storing cached code. The system will delete
872     * any files stored in this location both when your specific application is
873     * upgraded, and when the entire platform is upgraded.
874     * <p>
875     * This location is optimal for storing compiled or optimized code generated
876     * by your application at runtime.
877     * <p>
878     * Apps require no extra permissions to read or write to the returned path,
879     * since this path lives in their private storage.
880     *
881     * @return The path of the directory holding application code cache files.
882     */
883    public abstract File getCodeCacheDir();
884
885    /**
886     * Returns the absolute path to the directory on the primary external filesystem
887     * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
888     * Environment.getExternalStorageDirectory()} where the application can
889     * place cache files it owns. These files are internal to the application, and
890     * not typically visible to the user as media.
891     *
892     * <p>This is like {@link #getCacheDir()} in that these
893     * files will be deleted when the application is uninstalled, however there
894     * are some important differences:
895     *
896     * <ul>
897     * <li>The platform does not always monitor the space available in external
898     * storage, and thus may not automatically delete these files.  Currently
899     * the only time files here will be deleted by the platform is when running
900     * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
901     * {@link android.os.Environment#isExternalStorageEmulated()
902     * Environment.isExternalStorageEmulated()} returns true.  Note that you should
903     * be managing the maximum space you will use for these anyway, just like
904     * with {@link #getCacheDir()}.
905     * <li>External files are not always available: they will disappear if the
906     * user mounts the external storage on a computer or removes it.  See the
907     * APIs on {@link android.os.Environment} for information in the storage state.
908     * <li>There is no security enforced with these files.  For example, any application
909     * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
910     * these files.
911     * </ul>
912     *
913     * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
914     * are required to read or write to the returned path; it's always
915     * accessible to the calling app.  This only applies to paths generated for
916     * package name of the calling application.  To access paths belonging
917     * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
918     * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
919     *
920     * <p>On devices with multiple users (as described by {@link UserManager}),
921     * each user has their own isolated external storage. Applications only
922     * have access to the external storage for the user they're running as.</p>
923     *
924     * @return The path of the directory holding application cache files
925     * on external storage.  Returns null if external storage is not currently
926     * mounted so it could not ensure the path exists; you will need to call
927     * this method again when it is available.
928     *
929     * @see #getCacheDir
930     */
931    @Nullable
932    public abstract File getExternalCacheDir();
933
934    /**
935     * Returns absolute paths to application-specific directories on all
936     * external storage devices where the application can place cache files it
937     * owns. These files are internal to the application, and not typically
938     * visible to the user as media.
939     * <p>
940     * This is like {@link #getCacheDir()} in that these files will be deleted when
941     * the application is uninstalled, however there are some 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     * The first path returned is the same as {@link #getExternalCacheDir()}.
962     * Returned paths may be {@code null} if a storage device is unavailable.
963     *
964     * @see #getExternalCacheDir()
965     * @see Environment#getExternalStorageState(File)
966     */
967    public abstract File[] getExternalCacheDirs();
968
969    /**
970     * Returns absolute paths to application-specific directories on all
971     * external storage devices where the application can place media files.
972     * These files are scanned and made available to other apps through
973     * {@link MediaStore}.
974     * <p>
975     * This is like {@link #getExternalFilesDirs} in that these files will be
976     * deleted when the application is uninstalled, however there are some
977     * important differences:
978     * <ul>
979     * <li>External files are not always available: they will disappear if the
980     * user mounts the external storage on a computer or removes it.
981     * <li>There is no security enforced with these files.
982     * </ul>
983     * <p>
984     * External storage devices returned here are considered a permanent part of
985     * the device, including both emulated external storage and physical media
986     * slots, such as SD cards in a battery compartment. The returned paths do
987     * not include transient devices, such as USB flash drives.
988     * <p>
989     * An application may store data on any or all of the returned devices. For
990     * example, an app may choose to store large files on the device with the
991     * most available space, as measured by {@link StatFs}.
992     * <p>
993     * No permissions are required to read or write to the returned paths; they
994     * are always accessible to the calling app. Write access outside of these
995     * paths on secondary external storage devices is not available.
996     * <p>
997     * Returned paths may be {@code null} if a storage device is unavailable.
998     *
999     * @see Environment#getExternalStorageState(File)
1000     */
1001    public abstract File[] getExternalMediaDirs();
1002
1003    /**
1004     * Returns an array of strings naming the private files associated with
1005     * this Context's application package.
1006     *
1007     * @return Array of strings naming the private files.
1008     *
1009     * @see #openFileInput
1010     * @see #openFileOutput
1011     * @see #deleteFile
1012     */
1013    public abstract String[] fileList();
1014
1015    /**
1016     * Retrieve, creating if needed, a new directory in which the application
1017     * can place its own custom data files.  You can use the returned File
1018     * object to create and access files in this directory.  Note that files
1019     * created through a File object will only be accessible by your own
1020     * application; you can only set the mode of the entire directory, not
1021     * of individual files.
1022     *
1023     * @param name Name of the directory to retrieve.  This is a directory
1024     * that is created as part of your application data.
1025     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
1026     * default operation, {@link #MODE_WORLD_READABLE} and
1027     * {@link #MODE_WORLD_WRITEABLE} to control permissions.
1028     *
1029     * @return A {@link File} object for the requested directory.  The directory
1030     * will have been created if it does not already exist.
1031     *
1032     * @see #openFileOutput(String, int)
1033     */
1034    public abstract File getDir(String name, int mode);
1035
1036    /**
1037     * Open a new private SQLiteDatabase associated with this Context's
1038     * application package.  Create the database file if it doesn't exist.
1039     *
1040     * @param name The name (unique in the application package) of the database.
1041     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
1042     *     default operation, {@link #MODE_WORLD_READABLE}
1043     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
1044     *     Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
1045     * @param factory An optional factory class that is called to instantiate a
1046     *     cursor when query is called.
1047     *
1048     * @return The contents of a newly created database with the given name.
1049     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
1050     *
1051     * @see #MODE_PRIVATE
1052     * @see #MODE_WORLD_READABLE
1053     * @see #MODE_WORLD_WRITEABLE
1054     * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1055     * @see #deleteDatabase
1056     */
1057    public abstract SQLiteDatabase openOrCreateDatabase(String name,
1058            int mode, CursorFactory factory);
1059
1060    /**
1061     * Open a new private SQLiteDatabase associated with this Context's
1062     * application package.  Creates the database file if it doesn't exist.
1063     *
1064     * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
1065     * used to handle corruption when sqlite reports database corruption.</p>
1066     *
1067     * @param name The name (unique in the application package) of the database.
1068     * @param mode Operating mode.  Use 0 or {@link #MODE_PRIVATE} for the
1069     *     default operation, {@link #MODE_WORLD_READABLE}
1070     *     and {@link #MODE_WORLD_WRITEABLE} to control permissions.
1071     *     Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
1072     * @param factory An optional factory class that is called to instantiate a
1073     *     cursor when query is called.
1074     * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
1075     * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
1076     * @return The contents of a newly created database with the given name.
1077     * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
1078     *
1079     * @see #MODE_PRIVATE
1080     * @see #MODE_WORLD_READABLE
1081     * @see #MODE_WORLD_WRITEABLE
1082     * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1083     * @see #deleteDatabase
1084     */
1085    public abstract SQLiteDatabase openOrCreateDatabase(String name,
1086            int mode, CursorFactory factory,
1087            @Nullable DatabaseErrorHandler errorHandler);
1088
1089    /**
1090     * Delete an existing private SQLiteDatabase associated with this Context's
1091     * application package.
1092     *
1093     * @param name The name (unique in the application package) of the
1094     *             database.
1095     *
1096     * @return {@code true} if the database was successfully deleted; else {@code false}.
1097     *
1098     * @see #openOrCreateDatabase
1099     */
1100    public abstract boolean deleteDatabase(String name);
1101
1102    /**
1103     * Returns the absolute path on the filesystem where a database created with
1104     * {@link #openOrCreateDatabase} is stored.
1105     *
1106     * @param name The name of the database for which you would like to get
1107     *          its path.
1108     *
1109     * @return An absolute path to the given database.
1110     *
1111     * @see #openOrCreateDatabase
1112     */
1113    public abstract File getDatabasePath(String name);
1114
1115    /**
1116     * Returns an array of strings naming the private databases associated with
1117     * this Context's application package.
1118     *
1119     * @return Array of strings naming the private databases.
1120     *
1121     * @see #openOrCreateDatabase
1122     * @see #deleteDatabase
1123     */
1124    public abstract String[] databaseList();
1125
1126    /**
1127     * @deprecated Use {@link android.app.WallpaperManager#getDrawable
1128     * WallpaperManager.get()} instead.
1129     */
1130    @Deprecated
1131    public abstract Drawable getWallpaper();
1132
1133    /**
1134     * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
1135     * WallpaperManager.peek()} instead.
1136     */
1137    @Deprecated
1138    public abstract Drawable peekWallpaper();
1139
1140    /**
1141     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1142     * WallpaperManager.getDesiredMinimumWidth()} instead.
1143     */
1144    @Deprecated
1145    public abstract int getWallpaperDesiredMinimumWidth();
1146
1147    /**
1148     * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1149     * WallpaperManager.getDesiredMinimumHeight()} instead.
1150     */
1151    @Deprecated
1152    public abstract int getWallpaperDesiredMinimumHeight();
1153
1154    /**
1155     * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
1156     * WallpaperManager.set()} instead.
1157     * <p>This method requires the caller to hold the permission
1158     * {@link android.Manifest.permission#SET_WALLPAPER}.
1159     */
1160    @Deprecated
1161    public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1162
1163    /**
1164     * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
1165     * WallpaperManager.set()} instead.
1166     * <p>This method requires the caller to hold the permission
1167     * {@link android.Manifest.permission#SET_WALLPAPER}.
1168     */
1169    @Deprecated
1170    public abstract void setWallpaper(InputStream data) throws IOException;
1171
1172    /**
1173     * @deprecated Use {@link android.app.WallpaperManager#clear
1174     * WallpaperManager.clear()} instead.
1175     * <p>This method requires the caller to hold the permission
1176     * {@link android.Manifest.permission#SET_WALLPAPER}.
1177     */
1178    @Deprecated
1179    public abstract void clearWallpaper() throws IOException;
1180
1181    /**
1182     * Same as {@link #startActivity(Intent, Bundle)} with no options
1183     * specified.
1184     *
1185     * @param intent The description of the activity to start.
1186     *
1187     * @throws ActivityNotFoundException &nbsp;
1188     *
1189     * @see #startActivity(Intent, Bundle)
1190     * @see PackageManager#resolveActivity
1191     */
1192    public abstract void startActivity(Intent intent);
1193
1194    /**
1195     * Version of {@link #startActivity(Intent)} that allows you to specify the
1196     * user the activity will be started for.  This is not available to applications
1197     * that are not pre-installed on the system image.  Using it requires holding
1198     * the INTERACT_ACROSS_USERS_FULL permission.
1199     * @param intent The description of the activity to start.
1200     * @param user The UserHandle of the user to start this activity for.
1201     * @throws ActivityNotFoundException &nbsp;
1202     * @hide
1203     */
1204    public void startActivityAsUser(Intent intent, UserHandle user) {
1205        throw new RuntimeException("Not implemented. Must override in a subclass.");
1206    }
1207
1208    /**
1209     * Launch a new activity.  You will not receive any information about when
1210     * the activity exits.
1211     *
1212     * <p>Note that if this method is being called from outside of an
1213     * {@link android.app.Activity} Context, then the Intent must include
1214     * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag.  This is because,
1215     * without being started from an existing Activity, there is no existing
1216     * task in which to place the new activity and thus it needs to be placed
1217     * in its own separate task.
1218     *
1219     * <p>This method throws {@link ActivityNotFoundException}
1220     * if there was no Activity found to run the given Intent.
1221     *
1222     * @param intent The description of the activity to start.
1223     * @param options Additional options for how the Activity should be started.
1224     * May be null if there are no options.  See {@link android.app.ActivityOptions}
1225     * for how to build the Bundle supplied here; there are no supported definitions
1226     * for building it manually.
1227     *
1228     * @throws ActivityNotFoundException &nbsp;
1229     *
1230     * @see #startActivity(Intent)
1231     * @see PackageManager#resolveActivity
1232     */
1233    public abstract void startActivity(Intent intent, @Nullable Bundle options);
1234
1235    /**
1236     * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1237     * user the activity will be started for.  This is not available to applications
1238     * that are not pre-installed on the system image.  Using it requires holding
1239     * the INTERACT_ACROSS_USERS_FULL permission.
1240     * @param intent The description of the activity to start.
1241     * @param options Additional options for how the Activity should be started.
1242     * May be null if there are no options.  See {@link android.app.ActivityOptions}
1243     * for how to build the Bundle supplied here; there are no supported definitions
1244     * for building it manually.
1245     * @param userId The UserHandle of the user to start this activity for.
1246     * @throws ActivityNotFoundException &nbsp;
1247     * @hide
1248     */
1249    public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
1250        throw new RuntimeException("Not implemented. Must override in a subclass.");
1251    }
1252
1253    /**
1254     * Same as {@link #startActivities(Intent[], Bundle)} with no options
1255     * specified.
1256     *
1257     * @param intents An array of Intents to be started.
1258     *
1259     * @throws ActivityNotFoundException &nbsp;
1260     *
1261     * @see #startActivities(Intent[], Bundle)
1262     * @see PackageManager#resolveActivity
1263     */
1264    public abstract void startActivities(Intent[] intents);
1265
1266    /**
1267     * Launch multiple new activities.  This is generally the same as calling
1268     * {@link #startActivity(Intent)} for the first Intent in the array,
1269     * that activity during its creation calling {@link #startActivity(Intent)}
1270     * for the second entry, etc.  Note that unlike that approach, generally
1271     * none of the activities except the last in the array will be created
1272     * at this point, but rather will be created when the user first visits
1273     * them (due to pressing back from the activity on top).
1274     *
1275     * <p>This method throws {@link ActivityNotFoundException}
1276     * if there was no Activity found for <em>any</em> given Intent.  In this
1277     * case the state of the activity stack is undefined (some Intents in the
1278     * list may be on it, some not), so you probably want to avoid such situations.
1279     *
1280     * @param intents An array of Intents to be started.
1281     * @param options Additional options for how the Activity should be started.
1282     * See {@link android.content.Context#startActivity(Intent, Bundle)
1283     * Context.startActivity(Intent, Bundle)} for more details.
1284     *
1285     * @throws ActivityNotFoundException &nbsp;
1286     *
1287     * @see #startActivities(Intent[])
1288     * @see PackageManager#resolveActivity
1289     */
1290    public abstract void startActivities(Intent[] intents, Bundle options);
1291
1292    /**
1293     * @hide
1294     * Launch multiple new activities.  This is generally the same as calling
1295     * {@link #startActivity(Intent)} for the first Intent in the array,
1296     * that activity during its creation calling {@link #startActivity(Intent)}
1297     * for the second entry, etc.  Note that unlike that approach, generally
1298     * none of the activities except the last in the array will be created
1299     * at this point, but rather will be created when the user first visits
1300     * them (due to pressing back from the activity on top).
1301     *
1302     * <p>This method throws {@link ActivityNotFoundException}
1303     * if there was no Activity found for <em>any</em> given Intent.  In this
1304     * case the state of the activity stack is undefined (some Intents in the
1305     * list may be on it, some not), so you probably want to avoid such situations.
1306     *
1307     * @param intents An array of Intents to be started.
1308     * @param options Additional options for how the Activity should be started.
1309     * @param userHandle The user for whom to launch the activities
1310     * See {@link android.content.Context#startActivity(Intent, Bundle)
1311     * Context.startActivity(Intent, Bundle)} for more details.
1312     *
1313     * @throws ActivityNotFoundException &nbsp;
1314     *
1315     * @see #startActivities(Intent[])
1316     * @see PackageManager#resolveActivity
1317     */
1318    public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1319        throw new RuntimeException("Not implemented. Must override in a subclass.");
1320    }
1321
1322    /**
1323     * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1324     * with no options specified.
1325     *
1326     * @param intent The IntentSender to launch.
1327     * @param fillInIntent If non-null, this will be provided as the
1328     * intent parameter to {@link IntentSender#sendIntent}.
1329     * @param flagsMask Intent flags in the original IntentSender that you
1330     * would like to change.
1331     * @param flagsValues Desired values for any bits set in
1332     * <var>flagsMask</var>
1333     * @param extraFlags Always set to 0.
1334     *
1335     * @see #startActivity(Intent)
1336     * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1337     */
1338    public abstract void startIntentSender(IntentSender intent,
1339            Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1340            throws IntentSender.SendIntentException;
1341
1342    /**
1343     * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
1344     * to start.  If the IntentSender is for an activity, that activity will be started
1345     * as if you had called the regular {@link #startActivity(Intent)}
1346     * here; otherwise, its associated action will be executed (such as
1347     * sending a broadcast) as if you had called
1348     * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
1349     *
1350     * @param intent The IntentSender to launch.
1351     * @param fillInIntent If non-null, this will be provided as the
1352     * intent parameter to {@link IntentSender#sendIntent}.
1353     * @param flagsMask Intent flags in the original IntentSender that you
1354     * would like to change.
1355     * @param flagsValues Desired values for any bits set in
1356     * <var>flagsMask</var>
1357     * @param extraFlags Always set to 0.
1358     * @param options Additional options for how the Activity should be started.
1359     * See {@link android.content.Context#startActivity(Intent, Bundle)
1360     * Context.startActivity(Intent, Bundle)} for more details.  If options
1361     * have also been supplied by the IntentSender, options given here will
1362     * override any that conflict with those given by the IntentSender.
1363     *
1364     * @see #startActivity(Intent, Bundle)
1365     * @see #startIntentSender(IntentSender, Intent, int, int, int)
1366     */
1367    public abstract void startIntentSender(IntentSender intent,
1368            @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1369            Bundle options) throws IntentSender.SendIntentException;
1370
1371    /**
1372     * Broadcast the given intent to all interested BroadcastReceivers.  This
1373     * call is asynchronous; it returns immediately, and you will continue
1374     * executing while the receivers are run.  No results are propagated from
1375     * receivers and receivers can not abort the broadcast. If you want
1376     * to allow receivers to propagate results or abort the broadcast, you must
1377     * send an ordered broadcast using
1378     * {@link #sendOrderedBroadcast(Intent, String)}.
1379     *
1380     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1381     *
1382     * @param intent The Intent to broadcast; all receivers matching this
1383     *               Intent will receive the broadcast.
1384     *
1385     * @see android.content.BroadcastReceiver
1386     * @see #registerReceiver
1387     * @see #sendBroadcast(Intent, String)
1388     * @see #sendOrderedBroadcast(Intent, String)
1389     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1390     */
1391    public abstract void sendBroadcast(Intent intent);
1392
1393    /**
1394     * Broadcast the given intent to all interested BroadcastReceivers, allowing
1395     * an optional required permission to be enforced.  This
1396     * call is asynchronous; it returns immediately, and you will continue
1397     * executing while the receivers are run.  No results are propagated from
1398     * receivers and receivers can not abort the broadcast. If you want
1399     * to allow receivers to propagate results or abort the broadcast, you must
1400     * send an ordered broadcast using
1401     * {@link #sendOrderedBroadcast(Intent, String)}.
1402     *
1403     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1404     *
1405     * @param intent The Intent to broadcast; all receivers matching this
1406     *               Intent will receive the broadcast.
1407     * @param receiverPermission (optional) String naming a permission that
1408     *               a receiver must hold in order to receive your broadcast.
1409     *               If null, no permission is required.
1410     *
1411     * @see android.content.BroadcastReceiver
1412     * @see #registerReceiver
1413     * @see #sendBroadcast(Intent)
1414     * @see #sendOrderedBroadcast(Intent, String)
1415     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1416     */
1417    public abstract void sendBroadcast(Intent intent,
1418            @Nullable String receiverPermission);
1419
1420    /**
1421     * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
1422     * of an associated app op as per {@link android.app.AppOpsManager}.
1423     * @hide
1424     */
1425    public abstract void sendBroadcast(Intent intent,
1426            String receiverPermission, int appOp);
1427
1428    /**
1429     * Broadcast the given intent to all interested BroadcastReceivers, delivering
1430     * them one at a time to allow more preferred receivers to consume the
1431     * broadcast before it is delivered to less preferred receivers.  This
1432     * call is asynchronous; it returns immediately, and you will continue
1433     * executing while the receivers are run.
1434     *
1435     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1436     *
1437     * @param intent The Intent to broadcast; all receivers matching this
1438     *               Intent will receive the broadcast.
1439     * @param receiverPermission (optional) String naming a permissions that
1440     *               a receiver must hold in order to receive your broadcast.
1441     *               If null, no permission is required.
1442     *
1443     * @see android.content.BroadcastReceiver
1444     * @see #registerReceiver
1445     * @see #sendBroadcast(Intent)
1446     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1447     */
1448    public abstract void sendOrderedBroadcast(Intent intent,
1449            @Nullable String receiverPermission);
1450
1451    /**
1452     * Version of {@link #sendBroadcast(Intent)} that allows you to
1453     * receive data back from the broadcast.  This is accomplished by
1454     * supplying your own BroadcastReceiver when calling, which will be
1455     * treated as a final receiver at the end of the broadcast -- its
1456     * {@link BroadcastReceiver#onReceive} method will be called with
1457     * the result values collected from the other receivers.  The broadcast will
1458     * be serialized in the same way as calling
1459     * {@link #sendOrderedBroadcast(Intent, String)}.
1460     *
1461     * <p>Like {@link #sendBroadcast(Intent)}, this method is
1462     * asynchronous; it will return before
1463     * resultReceiver.onReceive() is called.
1464     *
1465     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1466     *
1467     * @param intent The Intent to broadcast; all receivers matching this
1468     *               Intent will receive the broadcast.
1469     * @param receiverPermission String naming a permissions that
1470     *               a receiver must hold in order to receive your broadcast.
1471     *               If null, no permission is required.
1472     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1473     *                       receiver of the broadcast.
1474     * @param scheduler A custom Handler with which to schedule the
1475     *                  resultReceiver callback; if null it will be
1476     *                  scheduled in the Context's main thread.
1477     * @param initialCode An initial value for the result code.  Often
1478     *                    Activity.RESULT_OK.
1479     * @param initialData An initial value for the result data.  Often
1480     *                    null.
1481     * @param initialExtras An initial value for the result extras.  Often
1482     *                      null.
1483     *
1484     * @see #sendBroadcast(Intent)
1485     * @see #sendBroadcast(Intent, String)
1486     * @see #sendOrderedBroadcast(Intent, String)
1487     * @see #sendStickyBroadcast(Intent)
1488     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1489     * @see android.content.BroadcastReceiver
1490     * @see #registerReceiver
1491     * @see android.app.Activity#RESULT_OK
1492     */
1493    public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1494            @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1495            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1496            @Nullable Bundle initialExtras);
1497
1498    /**
1499     * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1500     * int, String, android.os.Bundle)}, but also allows specification
1501     * of an associated app op as per {@link android.app.AppOpsManager}.
1502     * @hide
1503     */
1504    public abstract void sendOrderedBroadcast(Intent intent,
1505            String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1506            Handler scheduler, int initialCode, String initialData,
1507            Bundle initialExtras);
1508
1509    /**
1510     * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1511     * user the broadcast will be sent to.  This is not available to applications
1512     * that are not pre-installed on the system image.  Using it requires holding
1513     * the INTERACT_ACROSS_USERS permission.
1514     * @param intent The intent to broadcast
1515     * @param user UserHandle to send the intent to.
1516     * @see #sendBroadcast(Intent)
1517     */
1518    public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
1519
1520    /**
1521     * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1522     * user the broadcast will be sent to.  This is not available to applications
1523     * that are not pre-installed on the system image.  Using it requires holding
1524     * the INTERACT_ACROSS_USERS permission.
1525     *
1526     * @param intent The Intent to broadcast; all receivers matching this
1527     *               Intent will receive the broadcast.
1528     * @param user UserHandle to send the intent to.
1529     * @param receiverPermission (optional) String naming a permission that
1530     *               a receiver must hold in order to receive your broadcast.
1531     *               If null, no permission is required.
1532     *
1533     * @see #sendBroadcast(Intent, String)
1534     */
1535    public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1536            @Nullable String receiverPermission);
1537
1538    /**
1539     * Version of
1540     * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1541     * that allows you to specify the
1542     * user the broadcast will be sent to.  This is not available to applications
1543     * that are not pre-installed on the system image.  Using it requires holding
1544     * the INTERACT_ACROSS_USERS permission.
1545     *
1546     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1547     *
1548     * @param intent The Intent to broadcast; all receivers matching this
1549     *               Intent will receive the broadcast.
1550     * @param user UserHandle to send the intent to.
1551     * @param receiverPermission String naming a permissions that
1552     *               a receiver must hold in order to receive your broadcast.
1553     *               If null, no permission is required.
1554     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1555     *                       receiver of the broadcast.
1556     * @param scheduler A custom Handler with which to schedule the
1557     *                  resultReceiver callback; if null it will be
1558     *                  scheduled in the Context's main thread.
1559     * @param initialCode An initial value for the result code.  Often
1560     *                    Activity.RESULT_OK.
1561     * @param initialData An initial value for the result data.  Often
1562     *                    null.
1563     * @param initialExtras An initial value for the result extras.  Often
1564     *                      null.
1565     *
1566     * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1567     */
1568    public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1569            @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1570            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1571            @Nullable  Bundle initialExtras);
1572
1573    /**
1574     * Similar to above but takes an appOp as well, to enforce restrictions.
1575     * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1576     *       BroadcastReceiver, Handler, int, String, Bundle)
1577     * @hide
1578     */
1579    public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1580            @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1581            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1582            @Nullable  Bundle initialExtras);
1583
1584    /**
1585     * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1586     * Intent you are sending stays around after the broadcast is complete,
1587     * so that others can quickly retrieve that data through the return
1588     * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}.  In
1589     * all other ways, this behaves the same as
1590     * {@link #sendBroadcast(Intent)}.
1591     *
1592     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1593     * permission in order to use this API.  If you do not hold that
1594     * permission, {@link SecurityException} will be thrown.
1595     *
1596     * @param intent The Intent to broadcast; all receivers matching this
1597     * Intent will receive the broadcast, and the Intent will be held to
1598     * be re-broadcast to future receivers.
1599     *
1600     * @see #sendBroadcast(Intent)
1601     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1602     */
1603    public abstract void sendStickyBroadcast(Intent intent);
1604
1605    /**
1606     * Version of {@link #sendStickyBroadcast} that allows you to
1607     * receive data back from the broadcast.  This is accomplished by
1608     * supplying your own BroadcastReceiver when calling, which will be
1609     * treated as a final receiver at the end of the broadcast -- its
1610     * {@link BroadcastReceiver#onReceive} method will be called with
1611     * the result values collected from the other receivers.  The broadcast will
1612     * be serialized in the same way as calling
1613     * {@link #sendOrderedBroadcast(Intent, String)}.
1614     *
1615     * <p>Like {@link #sendBroadcast(Intent)}, this method is
1616     * asynchronous; it will return before
1617     * resultReceiver.onReceive() is called.  Note that the sticky data
1618     * stored is only the data you initially supply to the broadcast, not
1619     * the result of any changes made by the receivers.
1620     *
1621     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1622     *
1623     * @param intent The Intent to broadcast; all receivers matching this
1624     *               Intent will receive the broadcast.
1625     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1626     *                       receiver of the broadcast.
1627     * @param scheduler A custom Handler with which to schedule the
1628     *                  resultReceiver callback; if null it will be
1629     *                  scheduled in the Context's main thread.
1630     * @param initialCode An initial value for the result code.  Often
1631     *                    Activity.RESULT_OK.
1632     * @param initialData An initial value for the result data.  Often
1633     *                    null.
1634     * @param initialExtras An initial value for the result extras.  Often
1635     *                      null.
1636     *
1637     * @see #sendBroadcast(Intent)
1638     * @see #sendBroadcast(Intent, String)
1639     * @see #sendOrderedBroadcast(Intent, String)
1640     * @see #sendStickyBroadcast(Intent)
1641     * @see android.content.BroadcastReceiver
1642     * @see #registerReceiver
1643     * @see android.app.Activity#RESULT_OK
1644     */
1645    public abstract void sendStickyOrderedBroadcast(Intent intent,
1646            BroadcastReceiver resultReceiver,
1647            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1648            @Nullable Bundle initialExtras);
1649
1650    /**
1651     * Remove the data previously sent with {@link #sendStickyBroadcast},
1652     * so that it is as if the sticky broadcast had never happened.
1653     *
1654     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1655     * permission in order to use this API.  If you do not hold that
1656     * permission, {@link SecurityException} will be thrown.
1657     *
1658     * @param intent The Intent that was previously broadcast.
1659     *
1660     * @see #sendStickyBroadcast
1661     */
1662    public abstract void removeStickyBroadcast(Intent intent);
1663
1664    /**
1665     * Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
1666     * user the broadcast will be sent to.  This is not available to applications
1667     * that are not pre-installed on the system image.  Using it requires holding
1668     * the INTERACT_ACROSS_USERS permission.
1669     *
1670     * @param intent The Intent to broadcast; all receivers matching this
1671     * Intent will receive the broadcast, and the Intent will be held to
1672     * be re-broadcast to future receivers.
1673     * @param user UserHandle to send the intent to.
1674     *
1675     * @see #sendBroadcast(Intent)
1676     */
1677    public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1678
1679    /**
1680     * Version of
1681     * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1682     * that allows you to specify the
1683     * user the broadcast will be sent to.  This is not available to applications
1684     * that are not pre-installed on the system image.  Using it requires holding
1685     * the INTERACT_ACROSS_USERS permission.
1686     *
1687     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1688     *
1689     * @param intent The Intent to broadcast; all receivers matching this
1690     *               Intent will receive the broadcast.
1691     * @param user UserHandle to send the intent to.
1692     * @param resultReceiver Your own BroadcastReceiver to treat as the final
1693     *                       receiver of the broadcast.
1694     * @param scheduler A custom Handler with which to schedule the
1695     *                  resultReceiver callback; if null it will be
1696     *                  scheduled in the Context's main thread.
1697     * @param initialCode An initial value for the result code.  Often
1698     *                    Activity.RESULT_OK.
1699     * @param initialData An initial value for the result data.  Often
1700     *                    null.
1701     * @param initialExtras An initial value for the result extras.  Often
1702     *                      null.
1703     *
1704     * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1705     */
1706    public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1707            UserHandle user, BroadcastReceiver resultReceiver,
1708            @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1709            @Nullable Bundle initialExtras);
1710
1711    /**
1712     * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
1713     * user the broadcast will be sent to.  This is not available to applications
1714     * that are not pre-installed on the system image.  Using it requires holding
1715     * the INTERACT_ACROSS_USERS permission.
1716     *
1717     * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1718     * permission in order to use this API.  If you do not hold that
1719     * permission, {@link SecurityException} will be thrown.
1720     *
1721     * @param intent The Intent that was previously broadcast.
1722     * @param user UserHandle to remove the sticky broadcast from.
1723     *
1724     * @see #sendStickyBroadcastAsUser
1725     */
1726    public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1727
1728    /**
1729     * Register a BroadcastReceiver to be run in the main activity thread.  The
1730     * <var>receiver</var> will be called with any broadcast Intent that
1731     * matches <var>filter</var>, in the main application thread.
1732     *
1733     * <p>The system may broadcast Intents that are "sticky" -- these stay
1734     * around after the broadcast as finished, to be sent to any later
1735     * registrations. If your IntentFilter matches one of these sticky
1736     * Intents, that Intent will be returned by this function
1737     * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1738     * been broadcast.
1739     *
1740     * <p>There may be multiple sticky Intents that match <var>filter</var>,
1741     * in which case each of these will be sent to <var>receiver</var>.  In
1742     * this case, only one of these can be returned directly by the function;
1743     * which of these that is returned is arbitrarily decided by the system.
1744     *
1745     * <p>If you know the Intent your are registering for is sticky, you can
1746     * supply null for your <var>receiver</var>.  In this case, no receiver is
1747     * registered -- the function simply returns the sticky Intent that
1748     * matches <var>filter</var>.  In the case of multiple matches, the same
1749     * rules as described above apply.
1750     *
1751     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1752     *
1753     * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1754     * registered with this method will correctly respect the
1755     * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1756     * Prior to that, it would be ignored and delivered to all matching registered
1757     * receivers.  Be careful if using this for security.</p>
1758     *
1759     * <p class="note">Note: this method <em>cannot be called from a
1760     * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1761     * that is declared in an application's manifest.  It is okay, however, to call
1762     * this method from another BroadcastReceiver that has itself been registered
1763     * at run time with {@link #registerReceiver}, since the lifetime of such a
1764     * registered BroadcastReceiver is tied to the object that registered it.</p>
1765     *
1766     * @param receiver The BroadcastReceiver to handle the broadcast.
1767     * @param filter Selects the Intent broadcasts to be received.
1768     *
1769     * @return The first sticky intent found that matches <var>filter</var>,
1770     *         or null if there are none.
1771     *
1772     * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1773     * @see #sendBroadcast
1774     * @see #unregisterReceiver
1775     */
1776    @Nullable
1777    public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
1778                                            IntentFilter filter);
1779
1780    /**
1781     * Register to receive intent broadcasts, to run in the context of
1782     * <var>scheduler</var>.  See
1783     * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1784     * information.  This allows you to enforce permissions on who can
1785     * broadcast intents to your receiver, or have the receiver run in
1786     * a different thread than the main application thread.
1787     *
1788     * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1789     *
1790     * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1791     * registered with this method will correctly respect the
1792     * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1793     * Prior to that, it would be ignored and delivered to all matching registered
1794     * receivers.  Be careful if using this for security.</p>
1795     *
1796     * @param receiver The BroadcastReceiver to handle the broadcast.
1797     * @param filter Selects the Intent broadcasts to be received.
1798     * @param broadcastPermission String naming a permissions that a
1799     *      broadcaster must hold in order to send an Intent to you.  If null,
1800     *      no permission is required.
1801     * @param scheduler Handler identifying the thread that will receive
1802     *      the Intent.  If null, the main thread of the process will be used.
1803     *
1804     * @return The first sticky intent found that matches <var>filter</var>,
1805     *         or null if there are none.
1806     *
1807     * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1808     * @see #sendBroadcast
1809     * @see #unregisterReceiver
1810     */
1811    @Nullable
1812    public abstract Intent registerReceiver(BroadcastReceiver receiver,
1813            IntentFilter filter, @Nullable String broadcastPermission,
1814            @Nullable Handler scheduler);
1815
1816    /**
1817     * @hide
1818     * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1819     * but for a specific user.  This receiver will receiver broadcasts that
1820     * are sent to the requested user.  It
1821     * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1822     * permission.
1823     *
1824     * @param receiver The BroadcastReceiver to handle the broadcast.
1825     * @param user UserHandle to send the intent to.
1826     * @param filter Selects the Intent broadcasts to be received.
1827     * @param broadcastPermission String naming a permissions that a
1828     *      broadcaster must hold in order to send an Intent to you.  If null,
1829     *      no permission is required.
1830     * @param scheduler Handler identifying the thread that will receive
1831     *      the Intent.  If null, the main thread of the process will be used.
1832     *
1833     * @return The first sticky intent found that matches <var>filter</var>,
1834     *         or null if there are none.
1835     *
1836     * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1837     * @see #sendBroadcast
1838     * @see #unregisterReceiver
1839     */
1840    @Nullable
1841    public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
1842            UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1843            @Nullable Handler scheduler);
1844
1845    /**
1846     * Unregister a previously registered BroadcastReceiver.  <em>All</em>
1847     * filters that have been registered for this BroadcastReceiver will be
1848     * removed.
1849     *
1850     * @param receiver The BroadcastReceiver to unregister.
1851     *
1852     * @see #registerReceiver
1853     */
1854    public abstract void unregisterReceiver(BroadcastReceiver receiver);
1855
1856    /**
1857     * Request that a given application service be started.  The Intent
1858     * should contain either contain the complete class name of a specific service
1859     * implementation to start or a specific package name to target.  If the
1860     * Intent is less specified, it log a warning about this and which of the
1861     * multiple matching services it finds and uses will be undefined.  If this service
1862     * is not already running, it will be instantiated and started (creating a
1863     * process for it if needed); if it is running then it remains running.
1864     *
1865     * <p>Every call to this method will result in a corresponding call to
1866     * the target service's {@link android.app.Service#onStartCommand} method,
1867     * with the <var>intent</var> given here.  This provides a convenient way
1868     * to submit jobs to a service without having to bind and call on to its
1869     * interface.
1870     *
1871     * <p>Using startService() overrides the default service lifetime that is
1872     * managed by {@link #bindService}: it requires the service to remain
1873     * running until {@link #stopService} is called, regardless of whether
1874     * any clients are connected to it.  Note that calls to startService()
1875     * are not nesting: no matter how many times you call startService(),
1876     * a single call to {@link #stopService} will stop it.
1877     *
1878     * <p>The system attempts to keep running services around as much as
1879     * possible.  The only time they should be stopped is if the current
1880     * foreground application is using so many resources that the service needs
1881     * to be killed.  If any errors happen in the service's process, it will
1882     * automatically be restarted.
1883     *
1884     * <p>This function will throw {@link SecurityException} if you do not
1885     * have permission to start the given service.
1886     *
1887     * @param service Identifies the service to be started.  The Intent must be either
1888     *      fully explicit (supplying a component name) or specify a specific package
1889     *      name it is targetted to.  Additional values
1890     *      may be included in the Intent extras to supply arguments along with
1891     *      this specific start call.
1892     *
1893     * @return If the service is being started or is already running, the
1894     * {@link ComponentName} of the actual service that was started is
1895     * returned; else if the service does not exist null is returned.
1896     *
1897     * @throws SecurityException &nbsp;
1898     *
1899     * @see #stopService
1900     * @see #bindService
1901     */
1902    @Nullable
1903    public abstract ComponentName startService(Intent service);
1904
1905    /**
1906     * Request that a given application service be stopped.  If the service is
1907     * not running, nothing happens.  Otherwise it is stopped.  Note that calls
1908     * to startService() are not counted -- this stops the service no matter
1909     * how many times it was started.
1910     *
1911     * <p>Note that if a stopped service still has {@link ServiceConnection}
1912     * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1913     * not be destroyed until all of these bindings are removed.  See
1914     * the {@link android.app.Service} documentation for more details on a
1915     * service's lifecycle.
1916     *
1917     * <p>This function will throw {@link SecurityException} if you do not
1918     * have permission to stop the given service.
1919     *
1920     * @param service Description of the service to be stopped.  The Intent must be either
1921     *      fully explicit (supplying a component name) or specify a specific package
1922     *      name it is targetted to.
1923     *
1924     * @return If there is a service matching the given Intent that is already
1925     * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
1926     *
1927     * @throws SecurityException &nbsp;
1928     *
1929     * @see #startService
1930     */
1931    public abstract boolean stopService(Intent service);
1932
1933    /**
1934     * @hide like {@link #startService(Intent)} but for a specific user.
1935     */
1936    public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1937
1938    /**
1939     * @hide like {@link #stopService(Intent)} but for a specific user.
1940     */
1941    public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
1942
1943    /**
1944     * Connect to an application service, creating it if needed.  This defines
1945     * a dependency between your application and the service.  The given
1946     * <var>conn</var> will receive the service object when it is created and be
1947     * told if it dies and restarts.  The service will be considered required
1948     * by the system only for as long as the calling context exists.  For
1949     * example, if this Context is an Activity that is stopped, the service will
1950     * not be required to continue running until the Activity is resumed.
1951     *
1952     * <p>This function will throw {@link SecurityException} if you do not
1953     * have permission to bind to the given service.
1954     *
1955     * <p class="note">Note: this method <em>can not be called from a
1956     * {@link BroadcastReceiver} component</em>.  A pattern you can use to
1957     * communicate from a BroadcastReceiver to a Service is to call
1958     * {@link #startService} with the arguments containing the command to be
1959     * sent, with the service calling its
1960     * {@link android.app.Service#stopSelf(int)} method when done executing
1961     * that command.  See the API demo App/Service/Service Start Arguments
1962     * Controller for an illustration of this.  It is okay, however, to use
1963     * this method from a BroadcastReceiver that has been registered with
1964     * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1965     * is tied to another object (the one that registered it).</p>
1966     *
1967     * @param service Identifies the service to connect to.  The Intent may
1968     *      specify either an explicit component name, or a logical
1969     *      description (action, category, etc) to match an
1970     *      {@link IntentFilter} published by a service.
1971     * @param conn Receives information as the service is started and stopped.
1972     *      This must be a valid ServiceConnection object; it must not be null.
1973     * @param flags Operation options for the binding.  May be 0,
1974     *          {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1975     *          {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1976     *          {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1977     *          {@link #BIND_WAIVE_PRIORITY}.
1978     * @return If you have successfully bound to the service, {@code true} is returned;
1979     *         {@code false} is returned if the connection is not made so you will not
1980     *         receive the service object.
1981     *
1982     * @throws SecurityException &nbsp;
1983     *
1984     * @see #unbindService
1985     * @see #startService
1986     * @see #BIND_AUTO_CREATE
1987     * @see #BIND_DEBUG_UNBIND
1988     * @see #BIND_NOT_FOREGROUND
1989     */
1990    public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
1991            @BindServiceFlags int flags);
1992
1993    /**
1994     * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
1995     * argument for use by system server and other multi-user aware code.
1996     * @hide
1997     */
1998    public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
1999        throw new RuntimeException("Not implemented. Must override in a subclass.");
2000    }
2001
2002    /**
2003     * Disconnect from an application service.  You will no longer receive
2004     * calls as the service is restarted, and the service is now allowed to
2005     * stop at any time.
2006     *
2007     * @param conn The connection interface previously supplied to
2008     *             bindService().  This parameter must not be null.
2009     *
2010     * @see #bindService
2011     */
2012    public abstract void unbindService(@NonNull ServiceConnection conn);
2013
2014    /**
2015     * Start executing an {@link android.app.Instrumentation} class.  The given
2016     * Instrumentation component will be run by killing its target application
2017     * (if currently running), starting the target process, instantiating the
2018     * instrumentation component, and then letting it drive the application.
2019     *
2020     * <p>This function is not synchronous -- it returns as soon as the
2021     * instrumentation has started and while it is running.
2022     *
2023     * <p>Instrumentation is normally only allowed to run against a package
2024     * that is either unsigned or signed with a signature that the
2025     * the instrumentation package is also signed with (ensuring the target
2026     * trusts the instrumentation).
2027     *
2028     * @param className Name of the Instrumentation component to be run.
2029     * @param profileFile Optional path to write profiling data as the
2030     * instrumentation runs, or null for no profiling.
2031     * @param arguments Additional optional arguments to pass to the
2032     * instrumentation, or null.
2033     *
2034     * @return {@code true} if the instrumentation was successfully started,
2035     * else {@code false} if it could not be found.
2036     */
2037    public abstract boolean startInstrumentation(@NonNull ComponentName className,
2038            @Nullable String profileFile, @Nullable Bundle arguments);
2039
2040    /** @hide */
2041    @StringDef({
2042            POWER_SERVICE,
2043            WINDOW_SERVICE,
2044            LAYOUT_INFLATER_SERVICE,
2045            ACCOUNT_SERVICE,
2046            ACTIVITY_SERVICE,
2047            ALARM_SERVICE,
2048            NOTIFICATION_SERVICE,
2049            ACCESSIBILITY_SERVICE,
2050            CAPTIONING_SERVICE,
2051            KEYGUARD_SERVICE,
2052            LOCATION_SERVICE,
2053            //@hide: COUNTRY_DETECTOR,
2054            SEARCH_SERVICE,
2055            SENSOR_SERVICE,
2056            STORAGE_SERVICE,
2057            WALLPAPER_SERVICE,
2058            VIBRATOR_SERVICE,
2059            //@hide: STATUS_BAR_SERVICE,
2060            CONNECTIVITY_SERVICE,
2061            //@hide: UPDATE_LOCK_SERVICE,
2062            //@hide: NETWORKMANAGEMENT_SERVICE,
2063            //@hide: NETWORK_STATS_SERVICE,
2064            //@hide: NETWORK_POLICY_SERVICE,
2065            WIFI_SERVICE,
2066            WIFI_PASSPOINT_SERVICE,
2067            WIFI_P2P_SERVICE,
2068            WIFI_SCANNING_SERVICE,
2069            //@hide: ETHERNET_SERVICE,
2070            NSD_SERVICE,
2071            AUDIO_SERVICE,
2072            MEDIA_ROUTER_SERVICE,
2073            TELEPHONY_SERVICE,
2074            TELECOMM_SERVICE,
2075            CLIPBOARD_SERVICE,
2076            INPUT_METHOD_SERVICE,
2077            TEXT_SERVICES_MANAGER_SERVICE,
2078            //@hide: APPWIDGET_SERVICE,
2079            //@hide: BACKUP_SERVICE,
2080            DROPBOX_SERVICE,
2081            DEVICE_POLICY_SERVICE,
2082            UI_MODE_SERVICE,
2083            DOWNLOAD_SERVICE,
2084            NFC_SERVICE,
2085            BLUETOOTH_SERVICE,
2086            //@hide: SIP_SERVICE,
2087            USB_SERVICE,
2088            LAUNCHER_APPS_SERVICE,
2089            //@hide: SERIAL_SERVICE,
2090            INPUT_SERVICE,
2091            DISPLAY_SERVICE,
2092            //@hide: SCHEDULING_POLICY_SERVICE,
2093            USER_SERVICE,
2094            //@hide: APP_OPS_SERVICE
2095            CAMERA_SERVICE,
2096            PRINT_SERVICE,
2097            MEDIA_SESSION_SERVICE,
2098            BATTERY_SERVICE,
2099            JOB_SCHEDULER_SERVICE,
2100    })
2101    @Retention(RetentionPolicy.SOURCE)
2102    public @interface ServiceName {}
2103
2104    /**
2105     * Return the handle to a system-level service by name. The class of the
2106     * returned object varies by the requested name. Currently available names
2107     * are:
2108     *
2109     * <dl>
2110     *  <dt> {@link #WINDOW_SERVICE} ("window")
2111     *  <dd> The top-level window manager in which you can place custom
2112     *  windows.  The returned object is a {@link android.view.WindowManager}.
2113     *  <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2114     *  <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2115     *  in this context.
2116     *  <dt> {@link #ACTIVITY_SERVICE} ("activity")
2117     *  <dd> A {@link android.app.ActivityManager} for interacting with the
2118     *  global activity state of the system.
2119     *  <dt> {@link #POWER_SERVICE} ("power")
2120     *  <dd> A {@link android.os.PowerManager} for controlling power
2121     *  management.
2122     *  <dt> {@link #ALARM_SERVICE} ("alarm")
2123     *  <dd> A {@link android.app.AlarmManager} for receiving intents at the
2124     *  time of your choosing.
2125     *  <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2126     *  <dd> A {@link android.app.NotificationManager} for informing the user
2127     *   of background events.
2128     *  <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2129     *  <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2130     *  <dt> {@link #LOCATION_SERVICE} ("location")
2131     *  <dd> A {@link android.location.LocationManager} for controlling location
2132     *   (e.g., GPS) updates.
2133     *  <dt> {@link #SEARCH_SERVICE} ("search")
2134     *  <dd> A {@link android.app.SearchManager} for handling search.
2135     *  <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2136     *  <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2137     *  hardware.
2138     *  <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2139     *  <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2140     *  handling management of network connections.
2141     *  <dt> {@link #WIFI_SERVICE} ("wifi")
2142     *  <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2143     * Wi-Fi connectivity.
2144     *  <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2145     *  <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2146     * Wi-Fi Direct connectivity.
2147     * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2148     * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2149     * for management of input methods.
2150     * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2151     * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
2152     * <dt> {@link #DOWNLOAD_SERVICE} ("download")
2153     * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
2154     * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
2155     * <dd> A {@link android.os.BatteryManager} for managing battery state
2156     * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2157     * <dd>  A {@link android.app.job.JobScheduler} for managing scheduled tasks
2158     * </dl>
2159     *
2160     * <p>Note:  System services obtained via this API may be closely associated with
2161     * the Context in which they are obtained from.  In general, do not share the
2162     * service objects between various different contexts (Activities, Applications,
2163     * Services, Providers, etc.)
2164     *
2165     * @param name The name of the desired service.
2166     *
2167     * @return The service or null if the name does not exist.
2168     *
2169     * @see #WINDOW_SERVICE
2170     * @see android.view.WindowManager
2171     * @see #LAYOUT_INFLATER_SERVICE
2172     * @see android.view.LayoutInflater
2173     * @see #ACTIVITY_SERVICE
2174     * @see android.app.ActivityManager
2175     * @see #POWER_SERVICE
2176     * @see android.os.PowerManager
2177     * @see #ALARM_SERVICE
2178     * @see android.app.AlarmManager
2179     * @see #NOTIFICATION_SERVICE
2180     * @see android.app.NotificationManager
2181     * @see #KEYGUARD_SERVICE
2182     * @see android.app.KeyguardManager
2183     * @see #LOCATION_SERVICE
2184     * @see android.location.LocationManager
2185     * @see #SEARCH_SERVICE
2186     * @see android.app.SearchManager
2187     * @see #SENSOR_SERVICE
2188     * @see android.hardware.SensorManager
2189     * @see #STORAGE_SERVICE
2190     * @see android.os.storage.StorageManager
2191     * @see #VIBRATOR_SERVICE
2192     * @see android.os.Vibrator
2193     * @see #CONNECTIVITY_SERVICE
2194     * @see android.net.ConnectivityManager
2195     * @see #WIFI_SERVICE
2196     * @see android.net.wifi.WifiManager
2197     * @see #AUDIO_SERVICE
2198     * @see android.media.AudioManager
2199     * @see #MEDIA_ROUTER_SERVICE
2200     * @see android.media.MediaRouter
2201     * @see #TELEPHONY_SERVICE
2202     * @see android.telephony.TelephonyManager
2203     * @see #PHONE_SERVICE
2204     * @see android.phone.PhoneManager
2205     * @see #INPUT_METHOD_SERVICE
2206     * @see android.view.inputmethod.InputMethodManager
2207     * @see #UI_MODE_SERVICE
2208     * @see android.app.UiModeManager
2209     * @see #DOWNLOAD_SERVICE
2210     * @see android.app.DownloadManager
2211     * @see #BATTERY_SERVICE
2212     * @see android.os.BatteryManager
2213     * @see #JOB_SCHEDULER_SERVICE
2214     * @see android.app.job.JobScheduler
2215     */
2216    public abstract Object getSystemService(@ServiceName @NonNull String name);
2217
2218    /**
2219     * Use with {@link #getSystemService} to retrieve a
2220     * {@link android.os.PowerManager} for controlling power management,
2221     * including "wake locks," which let you keep the device on while
2222     * you're running long tasks.
2223     */
2224    public static final String POWER_SERVICE = "power";
2225
2226    /**
2227     * Use with {@link #getSystemService} to retrieve a
2228     * {@link android.view.WindowManager} for accessing the system's window
2229     * manager.
2230     *
2231     * @see #getSystemService
2232     * @see android.view.WindowManager
2233     */
2234    public static final String WINDOW_SERVICE = "window";
2235
2236    /**
2237     * Use with {@link #getSystemService} to retrieve a
2238     * {@link android.view.LayoutInflater} for inflating layout resources in this
2239     * context.
2240     *
2241     * @see #getSystemService
2242     * @see android.view.LayoutInflater
2243     */
2244    public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
2245
2246    /**
2247     * Use with {@link #getSystemService} to retrieve a
2248     * {@link android.accounts.AccountManager} for receiving intents at a
2249     * time of your choosing.
2250     *
2251     * @see #getSystemService
2252     * @see android.accounts.AccountManager
2253     */
2254    public static final String ACCOUNT_SERVICE = "account";
2255
2256    /**
2257     * Use with {@link #getSystemService} to retrieve a
2258     * {@link android.app.ActivityManager} for interacting with the global
2259     * system state.
2260     *
2261     * @see #getSystemService
2262     * @see android.app.ActivityManager
2263     */
2264    public static final String ACTIVITY_SERVICE = "activity";
2265
2266    /**
2267     * Use with {@link #getSystemService} to retrieve a
2268     * {@link android.app.AlarmManager} for receiving intents at a
2269     * time of your choosing.
2270     *
2271     * @see #getSystemService
2272     * @see android.app.AlarmManager
2273     */
2274    public static final String ALARM_SERVICE = "alarm";
2275
2276    /**
2277     * Use with {@link #getSystemService} to retrieve a
2278     * {@link android.app.NotificationManager} for informing the user of
2279     * background events.
2280     *
2281     * @see #getSystemService
2282     * @see android.app.NotificationManager
2283     */
2284    public static final String NOTIFICATION_SERVICE = "notification";
2285
2286    /**
2287     * Use with {@link #getSystemService} to retrieve a
2288     * {@link android.view.accessibility.AccessibilityManager} for giving the user
2289     * feedback for UI events through the registered event listeners.
2290     *
2291     * @see #getSystemService
2292     * @see android.view.accessibility.AccessibilityManager
2293     */
2294    public static final String ACCESSIBILITY_SERVICE = "accessibility";
2295
2296    /**
2297     * Use with {@link #getSystemService} to retrieve a
2298     * {@link android.view.accessibility.CaptioningManager} for obtaining
2299     * captioning properties and listening for changes in captioning
2300     * preferences.
2301     *
2302     * @see #getSystemService
2303     * @see android.view.accessibility.CaptioningManager
2304     */
2305    public static final String CAPTIONING_SERVICE = "captioning";
2306
2307    /**
2308     * Use with {@link #getSystemService} to retrieve a
2309     * {@link android.app.NotificationManager} for controlling keyguard.
2310     *
2311     * @see #getSystemService
2312     * @see android.app.KeyguardManager
2313     */
2314    public static final String KEYGUARD_SERVICE = "keyguard";
2315
2316    /**
2317     * Use with {@link #getSystemService} to retrieve a {@link
2318     * android.location.LocationManager} for controlling location
2319     * updates.
2320     *
2321     * @see #getSystemService
2322     * @see android.location.LocationManager
2323     */
2324    public static final String LOCATION_SERVICE = "location";
2325
2326    /**
2327     * Use with {@link #getSystemService} to retrieve a
2328     * {@link android.location.CountryDetector} for detecting the country that
2329     * the user is in.
2330     *
2331     * @hide
2332     */
2333    public static final String COUNTRY_DETECTOR = "country_detector";
2334
2335    /**
2336     * Use with {@link #getSystemService} to retrieve a {@link
2337     * android.app.SearchManager} for handling searches.
2338     *
2339     * @see #getSystemService
2340     * @see android.app.SearchManager
2341     */
2342    public static final String SEARCH_SERVICE = "search";
2343
2344    /**
2345     * Use with {@link #getSystemService} to retrieve a {@link
2346     * android.hardware.SensorManager} for accessing sensors.
2347     *
2348     * @see #getSystemService
2349     * @see android.hardware.SensorManager
2350     */
2351    public static final String SENSOR_SERVICE = "sensor";
2352
2353    /**
2354     * Use with {@link #getSystemService} to retrieve a {@link
2355     * android.os.storage.StorageManager} for accessing system storage
2356     * functions.
2357     *
2358     * @see #getSystemService
2359     * @see android.os.storage.StorageManager
2360     */
2361    public static final String STORAGE_SERVICE = "storage";
2362
2363    /**
2364     * Use with {@link #getSystemService} to retrieve a
2365     * com.android.server.WallpaperService for accessing wallpapers.
2366     *
2367     * @see #getSystemService
2368     */
2369    public static final String WALLPAPER_SERVICE = "wallpaper";
2370
2371    /**
2372     * Use with {@link #getSystemService} to retrieve a {@link
2373     * android.os.Vibrator} for interacting with the vibration hardware.
2374     *
2375     * @see #getSystemService
2376     * @see android.os.Vibrator
2377     */
2378    public static final String VIBRATOR_SERVICE = "vibrator";
2379
2380    /**
2381     * Use with {@link #getSystemService} to retrieve a {@link
2382     * android.app.StatusBarManager} for interacting with the status bar.
2383     *
2384     * @see #getSystemService
2385     * @see android.app.StatusBarManager
2386     * @hide
2387     */
2388    public static final String STATUS_BAR_SERVICE = "statusbar";
2389
2390    /**
2391     * Use with {@link #getSystemService} to retrieve a {@link
2392     * android.net.ConnectivityManager} for handling management of
2393     * network connections.
2394     *
2395     * @see #getSystemService
2396     * @see android.net.ConnectivityManager
2397     */
2398    public static final String CONNECTIVITY_SERVICE = "connectivity";
2399
2400    /**
2401     * Use with {@link #getSystemService} to retrieve a {@link
2402     * android.os.IUpdateLock} for managing runtime sequences that
2403     * must not be interrupted by headless OTA application or similar.
2404     *
2405     * @hide
2406     * @see #getSystemService
2407     * @see android.os.UpdateLock
2408     */
2409    public static final String UPDATE_LOCK_SERVICE = "updatelock";
2410
2411    /**
2412     * Constant for the internal network management service, not really a Context service.
2413     * @hide
2414     */
2415    public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2416
2417    /** {@hide} */
2418    public static final String NETWORK_STATS_SERVICE = "netstats";
2419    /** {@hide} */
2420    public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2421
2422    /**
2423     * Use with {@link #getSystemService} to retrieve a {@link
2424     * android.net.wifi.WifiManager} for handling management of
2425     * Wi-Fi access.
2426     *
2427     * @see #getSystemService
2428     * @see android.net.wifi.WifiManager
2429     */
2430    public static final String WIFI_SERVICE = "wifi";
2431
2432    /**
2433     * Use with {@link #getSystemService} to retrieve a {@link
2434     * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
2435     * Wi-Fi passpoint access.
2436     *
2437     * @see #getSystemService
2438     * @see android.net.wifi.passpoint.WifiPasspointManager
2439     * @hide
2440     */
2441    public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
2442
2443    /**
2444     * Use with {@link #getSystemService} to retrieve a {@link
2445     * android.net.wifi.p2p.WifiP2pManager} for handling management of
2446     * Wi-Fi peer-to-peer connections.
2447     *
2448     * @see #getSystemService
2449     * @see android.net.wifi.p2p.WifiP2pManager
2450     */
2451    public static final String WIFI_P2P_SERVICE = "wifip2p";
2452
2453    /**
2454     * Use with {@link #getSystemService} to retrieve a {@link
2455     * android.net.wifi.WifiScanner} for scanning the wifi universe
2456     *
2457     * @see #getSystemService
2458     * @see android.net.wifi.WifiScanner
2459     * @hide
2460     */
2461    @SystemApi
2462    public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2463
2464    /**
2465     * Use with {@link #getSystemService} to retrieve a {@link
2466     * android.net.ethernet.EthernetManager} for handling management of
2467     * Ethernet access.
2468     *
2469     * @see #getSystemService
2470     * @see android.net.ethernet.EthernetManager
2471     *
2472     * @hide
2473     */
2474    public static final String ETHERNET_SERVICE = "ethernet";
2475
2476    /**
2477     * Use with {@link #getSystemService} to retrieve a {@link
2478     * android.net.nsd.NsdManager} for handling management of network service
2479     * discovery
2480     *
2481     * @see #getSystemService
2482     * @see android.net.nsd.NsdManager
2483     */
2484    public static final String NSD_SERVICE = "servicediscovery";
2485
2486    /**
2487     * Use with {@link #getSystemService} to retrieve a
2488     * {@link android.media.AudioManager} for handling management of volume,
2489     * ringer modes and audio routing.
2490     *
2491     * @see #getSystemService
2492     * @see android.media.AudioManager
2493     */
2494    public static final String AUDIO_SERVICE = "audio";
2495
2496    /**
2497     * Use with {@link #getSystemService} to retrieve a
2498     * {@link android.service.fingerprint.FingerprintManager} for handling management
2499     * of fingerprints.
2500     *
2501     * @see #getSystemService
2502     * @see android.app.FingerprintManager
2503     */
2504    public static final String FINGERPRINT_SERVICE = "fingerprint";
2505
2506    /**
2507     * Use with {@link #getSystemService} to retrieve a
2508     * {@link android.media.MediaRouter} for controlling and managing
2509     * routing of media.
2510     *
2511     * @see #getSystemService
2512     * @see android.media.MediaRouter
2513     */
2514    public static final String MEDIA_ROUTER_SERVICE = "media_router";
2515
2516    /**
2517     * Use with {@link #getSystemService} to retrieve a
2518     * {@link android.media.session.MediaSessionManager} for managing media Sessions.
2519     *
2520     * @see #getSystemService
2521     * @see android.media.session.MediaSessionManager
2522     */
2523    public static final String MEDIA_SESSION_SERVICE = "media_session";
2524
2525    /**
2526     * Use with {@link #getSystemService} to retrieve a
2527     * {@link android.telephony.TelephonyManager} for handling management the
2528     * telephony features of the device.
2529     *
2530     * @see #getSystemService
2531     * @see android.telephony.TelephonyManager
2532     */
2533    public static final String TELEPHONY_SERVICE = "phone";
2534
2535    /**
2536     * Use with {@link #getSystemService} to retrieve a
2537     * {@link android.telecomm.TelecommManager} to manage telecomm-related features
2538     * of the device.
2539     *
2540     * @see #getSystemService
2541     * @see android.telecomm.TelecommManager
2542     */
2543    public static final String TELECOMM_SERVICE = "telecomm";
2544
2545    /**
2546     * Use with {@link #getSystemService} to retrieve a
2547     * {@link android.phone.PhoneManager} to manage phone-related features
2548     * of the device.
2549     *
2550     * @see #getSystemService
2551     * @see android.phone.PhoneManager
2552     */
2553    public static final String PHONE_SERVICE = "phone_service";  // "phone" used by telephony.
2554
2555    /**
2556     * Use with {@link #getSystemService} to retrieve a
2557     * {@link android.text.ClipboardManager} for accessing and modifying
2558     * the contents of the global clipboard.
2559     *
2560     * @see #getSystemService
2561     * @see android.text.ClipboardManager
2562     */
2563    public static final String CLIPBOARD_SERVICE = "clipboard";
2564
2565    /**
2566     * Use with {@link #getSystemService} to retrieve a
2567     * {@link android.view.inputmethod.InputMethodManager} for accessing input
2568     * methods.
2569     *
2570     * @see #getSystemService
2571     */
2572    public static final String INPUT_METHOD_SERVICE = "input_method";
2573
2574    /**
2575     * Use with {@link #getSystemService} to retrieve a
2576     * {@link android.view.textservice.TextServicesManager} for accessing
2577     * text services.
2578     *
2579     * @see #getSystemService
2580     */
2581    public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2582
2583    /**
2584     * Use with {@link #getSystemService} to retrieve a
2585     * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
2586     *
2587     * @hide
2588     * @see #getSystemService
2589     */
2590    public static final String APPWIDGET_SERVICE = "appwidget";
2591
2592    /**
2593     * Official published name of the (internal) voice interaction manager service.
2594     *
2595     * @hide
2596     * @see #getSystemService
2597     */
2598    public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2599
2600    /**
2601     * Use with {@link #getSystemService} to retrieve an
2602     * {@link android.app.backup.IBackupManager IBackupManager} for communicating
2603     * with the backup mechanism.
2604     * @hide
2605     *
2606     * @see #getSystemService
2607     */
2608    public static final String BACKUP_SERVICE = "backup";
2609
2610    /**
2611     * Use with {@link #getSystemService} to retrieve a
2612     * {@link android.os.DropBoxManager} instance for recording
2613     * diagnostic logs.
2614     * @see #getSystemService
2615     */
2616    public static final String DROPBOX_SERVICE = "dropbox";
2617
2618    /**
2619     * Use with {@link #getSystemService} to retrieve a
2620     * {@link android.app.admin.DevicePolicyManager} for working with global
2621     * device policy management.
2622     *
2623     * @see #getSystemService
2624     */
2625    public static final String DEVICE_POLICY_SERVICE = "device_policy";
2626
2627    /**
2628     * Use with {@link #getSystemService} to retrieve a
2629     * {@link android.app.UiModeManager} for controlling UI modes.
2630     *
2631     * @see #getSystemService
2632     */
2633    public static final String UI_MODE_SERVICE = "uimode";
2634
2635    /**
2636     * Use with {@link #getSystemService} to retrieve a
2637     * {@link android.app.DownloadManager} for requesting HTTP downloads.
2638     *
2639     * @see #getSystemService
2640     */
2641    public static final String DOWNLOAD_SERVICE = "download";
2642
2643    /**
2644     * Use with {@link #getSystemService} to retrieve a
2645     * {@link android.os.BatteryManager} for managing battery state.
2646     *
2647     * @see #getSystemService
2648     */
2649    public static final String BATTERY_SERVICE = "batterymanager";
2650
2651    /**
2652     * Use with {@link #getSystemService} to retrieve a
2653     * {@link android.nfc.NfcManager} for using NFC.
2654     *
2655     * @see #getSystemService
2656     */
2657    public static final String NFC_SERVICE = "nfc";
2658
2659    /**
2660     * Use with {@link #getSystemService} to retrieve a
2661     * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2662     *
2663     * @see #getSystemService
2664     */
2665    public static final String BLUETOOTH_SERVICE = "bluetooth";
2666
2667    /**
2668     * Use with {@link #getSystemService} to retrieve a
2669     * {@link android.net.sip.SipManager} for accessing the SIP related service.
2670     *
2671     * @see #getSystemService
2672     */
2673    /** @hide */
2674    public static final String SIP_SERVICE = "sip";
2675
2676    /**
2677     * Use with {@link #getSystemService} to retrieve a {@link
2678     * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
2679     * and for controlling this device's behavior as a USB device.
2680     *
2681     * @see #getSystemService
2682     * @see android.hardware.usb.UsbManager
2683     */
2684    public static final String USB_SERVICE = "usb";
2685
2686    /**
2687     * Use with {@link #getSystemService} to retrieve a {@link
2688     * android.hardware.SerialManager} for access to serial ports.
2689     *
2690     * @see #getSystemService
2691     * @see android.hardware.SerialManager
2692     *
2693     * @hide
2694     */
2695    public static final String SERIAL_SERVICE = "serial";
2696
2697    /**
2698     * Use with {@link #getSystemService} to retrieve a
2699     * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2700     * HDMI-CEC protocol.
2701     *
2702     * @see #getSystemService
2703     * @see android.hardware.hdmi.HdmiControlManager
2704     * @hide
2705     */
2706    @SystemApi
2707    public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
2708
2709    /**
2710     * Use with {@link #getSystemService} to retrieve a
2711     * {@link android.hardware.input.InputManager} for interacting with input devices.
2712     *
2713     * @see #getSystemService
2714     * @see android.hardware.input.InputManager
2715     */
2716    public static final String INPUT_SERVICE = "input";
2717
2718    /**
2719     * Use with {@link #getSystemService} to retrieve a
2720     * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2721     *
2722     * @see #getSystemService
2723     * @see android.hardware.display.DisplayManager
2724     */
2725    public static final String DISPLAY_SERVICE = "display";
2726
2727    /**
2728     * Use with {@link #getSystemService} to retrieve a
2729     * {@link android.os.UserManager} for managing users on devices that support multiple users.
2730     *
2731     * @see #getSystemService
2732     * @see android.os.UserManager
2733     */
2734    public static final String USER_SERVICE = "user";
2735
2736    /**
2737     * Use with {@link #getSystemService} to retrieve a
2738     * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
2739     * profiles of a user.
2740     *
2741     * @see #getSystemService
2742     * @see android.content.pm.LauncherApps
2743     */
2744    public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
2745
2746    /**
2747     * Use with {@link #getSystemService} to retrieve a
2748     * {@link android.content.RestrictionsManager} for retrieving application restrictions
2749     * and requesting permissions for restricted operations.
2750     * @see #getSystemService
2751     * @see android.content.RestrictionsManager
2752     */
2753    public static final String RESTRICTIONS_SERVICE = "restrictions";
2754
2755    /**
2756     * Use with {@link #getSystemService} to retrieve a
2757     * {@link android.app.AppOpsManager} for tracking application operations
2758     * on the device.
2759     *
2760     * @see #getSystemService
2761     * @see android.app.AppOpsManager
2762     */
2763    public static final String APP_OPS_SERVICE = "appops";
2764
2765    /**
2766     * Use with {@link #getSystemService} to retrieve a
2767     * {@link android.hardware.camera2.CameraManager} for interacting with
2768     * camera devices.
2769     *
2770     * @see #getSystemService
2771     * @see android.hardware.camera2.CameraManager
2772     */
2773    public static final String CAMERA_SERVICE = "camera";
2774
2775    /**
2776     * {@link android.print.PrintManager} for printing and managing
2777     * printers and print tasks.
2778     *
2779     * @see #getSystemService
2780     * @see android.print.PrintManager
2781     */
2782    public static final String PRINT_SERVICE = "print";
2783
2784    /**
2785     * Use with {@link #getSystemService} to retrieve a
2786     * {@link android.hardware.ConsumerIrManager} for transmitting infrared
2787     * signals from the device.
2788     *
2789     * @see #getSystemService
2790     * @see android.hardware.ConsumerIrManager
2791     */
2792    public static final String CONSUMER_IR_SERVICE = "consumer_ir";
2793
2794    /**
2795     * {@link android.app.trust.TrustManager} for managing trust agents.
2796     * @see #getSystemService
2797     * @see android.app.trust.TrustManager
2798     * @hide
2799     */
2800    public static final String TRUST_SERVICE = "trust";
2801
2802    /**
2803     * Use with {@link #getSystemService} to retrieve a
2804     * {@link android.media.tv.TvInputManager} for interacting with TV inputs
2805     * on the device.
2806     *
2807     * @see #getSystemService
2808     * @see android.media.tv.TvInputManager
2809     */
2810    public static final String TV_INPUT_SERVICE = "tv_input";
2811
2812    /**
2813     * {@link android.net.NetworkScoreManager} for managing network scoring.
2814     * @see #getSystemService
2815     * @see android.net.NetworkScoreManager
2816     * @hide
2817     */
2818    public static final String NETWORK_SCORE_SERVICE = "network_score";
2819
2820    /**
2821     * Use with {@link #getSystemService} to retrieve a {@link
2822     * android.app.UsageStatsManager} for interacting with the status bar.
2823     *
2824     * @see #getSystemService
2825     * @see android.app.UsageStatsManager
2826     * @hide
2827     */
2828    public static final String USAGE_STATS_SERVICE = "usagestats";
2829
2830    /**
2831     * Use with {@link #getSystemService} to retrieve a {@link
2832     * android.app.job.JobScheduler} instance for managing occasional
2833     * background tasks.
2834     * @see #getSystemService
2835     * @see android.app.job.JobScheduler
2836     */
2837    public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
2838
2839    /**
2840     * Use with {@link #getSystemService} to retrieve a {@link
2841     * android.service.persistentdata.PersistentDataBlockManager} instance retrieving
2842     * a file descriptor for a persistent data block.
2843     * @see #getSystemService
2844     * @see android.service.persistentdata.PersistentDataBlockManager
2845     * @hide
2846     */
2847    public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
2848
2849    /**
2850     * Determine whether the given permission is allowed for a particular
2851     * process and user ID running in the system.
2852     *
2853     * @param permission The name of the permission being checked.
2854     * @param pid The process ID being checked against.  Must be > 0.
2855     * @param uid The user ID being checked against.  A uid of 0 is the root
2856     * user, which will pass every permission check.
2857     *
2858     * @return {@link PackageManager#PERMISSION_GRANTED} if the given
2859     * pid/uid is allowed that permission, or
2860     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2861     *
2862     * @see PackageManager#checkPermission(String, String)
2863     * @see #checkCallingPermission
2864     */
2865    @PackageManager.PermissionResult
2866    public abstract int checkPermission(@NonNull String permission, int pid, int uid);
2867
2868    /**
2869     * Determine whether the calling process of an IPC you are handling has been
2870     * granted a particular permission.  This is basically the same as calling
2871     * {@link #checkPermission(String, int, int)} with the pid and uid returned
2872     * by {@link android.os.Binder#getCallingPid} and
2873     * {@link android.os.Binder#getCallingUid}.  One important difference
2874     * is that if you are not currently processing an IPC, this function
2875     * will always fail.  This is done to protect against accidentally
2876     * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2877     * to avoid this protection.
2878     *
2879     * @param permission The name of the permission being checked.
2880     *
2881     * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
2882     * pid/uid is allowed that permission, or
2883     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2884     *
2885     * @see PackageManager#checkPermission(String, String)
2886     * @see #checkPermission
2887     * @see #checkCallingOrSelfPermission
2888     */
2889    @PackageManager.PermissionResult
2890    public abstract int checkCallingPermission(@NonNull String permission);
2891
2892    /**
2893     * Determine whether the calling process of an IPC <em>or you</em> have been
2894     * granted a particular permission.  This is the same as
2895     * {@link #checkCallingPermission}, except it grants your own permissions
2896     * if you are not currently processing an IPC.  Use with care!
2897     *
2898     * @param permission The name of the permission being checked.
2899     *
2900     * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
2901     * pid/uid is allowed that permission, or
2902     * {@link PackageManager#PERMISSION_DENIED} if it is not.
2903     *
2904     * @see PackageManager#checkPermission(String, String)
2905     * @see #checkPermission
2906     * @see #checkCallingPermission
2907     */
2908    @PackageManager.PermissionResult
2909    public abstract int checkCallingOrSelfPermission(@NonNull String permission);
2910
2911    /**
2912     * If the given permission is not allowed for a particular process
2913     * and user ID running in the system, throw a {@link SecurityException}.
2914     *
2915     * @param permission The name of the permission being checked.
2916     * @param pid The process ID being checked against.  Must be &gt; 0.
2917     * @param uid The user ID being checked against.  A uid of 0 is the root
2918     * user, which will pass every permission check.
2919     * @param message A message to include in the exception if it is thrown.
2920     *
2921     * @see #checkPermission(String, int, int)
2922     */
2923    public abstract void enforcePermission(
2924            @NonNull String permission, int pid, int uid, @Nullable String message);
2925
2926    /**
2927     * If the calling process of an IPC you are handling has not been
2928     * granted a particular permission, throw a {@link
2929     * SecurityException}.  This is basically the same as calling
2930     * {@link #enforcePermission(String, int, int, String)} with the
2931     * pid and uid returned by {@link android.os.Binder#getCallingPid}
2932     * and {@link android.os.Binder#getCallingUid}.  One important
2933     * difference is that if you are not currently processing an IPC,
2934     * this function will always throw the SecurityException.  This is
2935     * done to protect against accidentally leaking permissions; you
2936     * can use {@link #enforceCallingOrSelfPermission} to avoid this
2937     * protection.
2938     *
2939     * @param permission The name of the permission being checked.
2940     * @param message A message to include in the exception if it is thrown.
2941     *
2942     * @see #checkCallingPermission(String)
2943     */
2944    public abstract void enforceCallingPermission(
2945            @NonNull String permission, @Nullable String message);
2946
2947    /**
2948     * If neither you nor the calling process of an IPC you are
2949     * handling has been granted a particular permission, throw a
2950     * {@link SecurityException}.  This is the same as {@link
2951     * #enforceCallingPermission}, except it grants your own
2952     * permissions if you are not currently processing an IPC.  Use
2953     * with care!
2954     *
2955     * @param permission The name of the permission being checked.
2956     * @param message A message to include in the exception if it is thrown.
2957     *
2958     * @see #checkCallingOrSelfPermission(String)
2959     */
2960    public abstract void enforceCallingOrSelfPermission(
2961            @NonNull String permission, @Nullable String message);
2962
2963    /**
2964     * Grant permission to access a specific Uri to another package, regardless
2965     * of whether that package has general permission to access the Uri's
2966     * content provider.  This can be used to grant specific, temporary
2967     * permissions, typically in response to user interaction (such as the
2968     * user opening an attachment that you would like someone else to
2969     * display).
2970     *
2971     * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2972     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2973     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2974     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
2975     * start an activity instead of this function directly.  If you use this
2976     * function directly, you should be sure to call
2977     * {@link #revokeUriPermission} when the target should no longer be allowed
2978     * to access it.
2979     *
2980     * <p>To succeed, the content provider owning the Uri must have set the
2981     * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
2982     * grantUriPermissions} attribute in its manifest or included the
2983     * {@link android.R.styleable#AndroidManifestGrantUriPermission
2984     * &lt;grant-uri-permissions&gt;} tag.
2985     *
2986     * @param toPackage The package you would like to allow to access the Uri.
2987     * @param uri The Uri you would like to grant access to.
2988     * @param modeFlags The desired access modes.  Any combination of
2989     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2990     * Intent.FLAG_GRANT_READ_URI_PERMISSION},
2991     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2992     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
2993     * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
2994     * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
2995     * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
2996     * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
2997     *
2998     * @see #revokeUriPermission
2999     */
3000    public abstract void grantUriPermission(String toPackage, Uri uri,
3001            @Intent.GrantUriMode int modeFlags);
3002
3003    /**
3004     * Remove all permissions to access a particular content provider Uri
3005     * that were previously added with {@link #grantUriPermission}.  The given
3006     * Uri will match all previously granted Uris that are the same or a
3007     * sub-path of the given Uri.  That is, revoking "content://foo/target" will
3008     * revoke both "content://foo/target" and "content://foo/target/sub", but not
3009     * "content://foo".  It will not remove any prefix grants that exist at a
3010     * higher level.
3011     *
3012     * @param uri The Uri you would like to revoke access to.
3013     * @param modeFlags The desired access modes.  Any combination of
3014     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3015     * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3016     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3017     * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3018     *
3019     * @see #grantUriPermission
3020     */
3021    public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
3022
3023    /**
3024     * Determine whether a particular process and user ID has been granted
3025     * permission to access a specific URI.  This only checks for permissions
3026     * that have been explicitly granted -- if the given process/uid has
3027     * more general access to the URI's content provider then this check will
3028     * always fail.
3029     *
3030     * @param uri The uri that is being checked.
3031     * @param pid The process ID being checked against.  Must be &gt; 0.
3032     * @param uid The user ID being checked against.  A uid of 0 is the root
3033     * user, which will pass every permission check.
3034     * @param modeFlags The type of access to grant.  May be one or both of
3035     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3036     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3037     *
3038     * @return {@link PackageManager#PERMISSION_GRANTED} if the given
3039     * pid/uid is allowed to access that uri, or
3040     * {@link PackageManager#PERMISSION_DENIED} if it is not.
3041     *
3042     * @see #checkCallingUriPermission
3043     */
3044    public abstract int checkUriPermission(Uri uri, int pid, int uid,
3045            @Intent.AccessUriMode int modeFlags);
3046
3047    /**
3048     * Determine whether the calling process and user ID has been
3049     * granted permission to access a specific URI.  This is basically
3050     * the same as calling {@link #checkUriPermission(Uri, int, int,
3051     * int)} with the pid and uid returned by {@link
3052     * android.os.Binder#getCallingPid} and {@link
3053     * android.os.Binder#getCallingUid}.  One important difference is
3054     * that if you are not currently processing an IPC, this function
3055     * will always fail.
3056     *
3057     * @param uri The uri that is being checked.
3058     * @param modeFlags The type of access to grant.  May be one or both of
3059     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3060     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3061     *
3062     * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
3063     * is allowed to access that uri, or
3064     * {@link PackageManager#PERMISSION_DENIED} if it is not.
3065     *
3066     * @see #checkUriPermission(Uri, int, int, int)
3067     */
3068    public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
3069
3070    /**
3071     * Determine whether the calling process of an IPC <em>or you</em> has been granted
3072     * permission to access a specific URI.  This is the same as
3073     * {@link #checkCallingUriPermission}, except it grants your own permissions
3074     * if you are not currently processing an IPC.  Use with care!
3075     *
3076     * @param uri The uri that is being checked.
3077     * @param modeFlags The type of access to grant.  May be one or both of
3078     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3079     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3080     *
3081     * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
3082     * is allowed to access that uri, or
3083     * {@link PackageManager#PERMISSION_DENIED} if it is not.
3084     *
3085     * @see #checkCallingUriPermission
3086     */
3087    public abstract int checkCallingOrSelfUriPermission(Uri uri,
3088            @Intent.AccessUriMode int modeFlags);
3089
3090    /**
3091     * Check both a Uri and normal permission.  This allows you to perform
3092     * both {@link #checkPermission} and {@link #checkUriPermission} in one
3093     * call.
3094     *
3095     * @param uri The Uri whose permission is to be checked, or null to not
3096     * do this check.
3097     * @param readPermission The permission that provides overall read access,
3098     * or null to not do this check.
3099     * @param writePermission The permission that provides overall write
3100     * access, or null to not do this check.
3101     * @param pid The process ID being checked against.  Must be &gt; 0.
3102     * @param uid The user ID being checked against.  A uid of 0 is the root
3103     * user, which will pass every permission check.
3104     * @param modeFlags The type of access to grant.  May be one or both of
3105     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3106     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3107     *
3108     * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
3109     * is allowed to access that uri or holds one of the given permissions, or
3110     * {@link PackageManager#PERMISSION_DENIED} if it is not.
3111     */
3112    public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3113            @Nullable String writePermission, int pid, int uid,
3114            @Intent.AccessUriMode int modeFlags);
3115
3116    /**
3117     * If a particular process and user ID has not been granted
3118     * permission to access a specific URI, throw {@link
3119     * SecurityException}.  This only checks for permissions that have
3120     * been explicitly granted -- if the given process/uid has more
3121     * general access to the URI's content provider then this check
3122     * will always fail.
3123     *
3124     * @param uri The uri that is being checked.
3125     * @param pid The process ID being checked against.  Must be &gt; 0.
3126     * @param uid The user ID being checked against.  A uid of 0 is the root
3127     * user, which will pass every permission check.
3128     * @param modeFlags The type of access to grant.  May be one or both of
3129     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3130     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3131     * @param message A message to include in the exception if it is thrown.
3132     *
3133     * @see #checkUriPermission(Uri, int, int, int)
3134     */
3135    public abstract void enforceUriPermission(
3136            Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
3137
3138    /**
3139     * If the calling process and user ID has not been granted
3140     * permission to access a specific URI, throw {@link
3141     * SecurityException}.  This is basically the same as calling
3142     * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3143     * the pid and uid returned by {@link
3144     * android.os.Binder#getCallingPid} and {@link
3145     * android.os.Binder#getCallingUid}.  One important difference is
3146     * that if you are not currently processing an IPC, this function
3147     * will always throw a SecurityException.
3148     *
3149     * @param uri The uri that is being checked.
3150     * @param modeFlags The type of access to grant.  May be one or both of
3151     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3152     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3153     * @param message A message to include in the exception if it is thrown.
3154     *
3155     * @see #checkCallingUriPermission(Uri, int)
3156     */
3157    public abstract void enforceCallingUriPermission(
3158            Uri uri, @Intent.AccessUriMode int modeFlags, String message);
3159
3160    /**
3161     * If the calling process of an IPC <em>or you</em> has not been
3162     * granted permission to access a specific URI, throw {@link
3163     * SecurityException}.  This is the same as {@link
3164     * #enforceCallingUriPermission}, except it grants your own
3165     * permissions if you are not currently processing an IPC.  Use
3166     * with care!
3167     *
3168     * @param uri The uri that is being checked.
3169     * @param modeFlags The type of access to grant.  May be one or both of
3170     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3171     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3172     * @param message A message to include in the exception if it is thrown.
3173     *
3174     * @see #checkCallingOrSelfUriPermission(Uri, int)
3175     */
3176    public abstract void enforceCallingOrSelfUriPermission(
3177            Uri uri, @Intent.AccessUriMode int modeFlags, String message);
3178
3179    /**
3180     * Enforce both a Uri and normal permission.  This allows you to perform
3181     * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3182     * call.
3183     *
3184     * @param uri The Uri whose permission is to be checked, or null to not
3185     * do this check.
3186     * @param readPermission The permission that provides overall read access,
3187     * or null to not do this check.
3188     * @param writePermission The permission that provides overall write
3189     * access, or null to not do this check.
3190     * @param pid The process ID being checked against.  Must be &gt; 0.
3191     * @param uid The user ID being checked against.  A uid of 0 is the root
3192     * user, which will pass every permission check.
3193     * @param modeFlags The type of access to grant.  May be one or both of
3194     * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3195     * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3196     * @param message A message to include in the exception if it is thrown.
3197     *
3198     * @see #checkUriPermission(Uri, String, String, int, int, int)
3199     */
3200    public abstract void enforceUriPermission(
3201            @Nullable Uri uri, @Nullable String readPermission,
3202            @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
3203            @Nullable String message);
3204
3205    /** @hide */
3206    @IntDef(flag = true,
3207            value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3208    @Retention(RetentionPolicy.SOURCE)
3209    public @interface CreatePackageOptions {}
3210
3211    /**
3212     * Flag for use with {@link #createPackageContext}: include the application
3213     * code with the context.  This means loading code into the caller's
3214     * process, so that {@link #getClassLoader()} can be used to instantiate
3215     * the application's classes.  Setting this flags imposes security
3216     * restrictions on what application context you can access; if the
3217     * requested application can not be safely loaded into your process,
3218     * java.lang.SecurityException will be thrown.  If this flag is not set,
3219     * there will be no restrictions on the packages that can be loaded,
3220     * but {@link #getClassLoader} will always return the default system
3221     * class loader.
3222     */
3223    public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3224
3225    /**
3226     * Flag for use with {@link #createPackageContext}: ignore any security
3227     * restrictions on the Context being requested, allowing it to always
3228     * be loaded.  For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3229     * to be loaded into a process even when it isn't safe to do so.  Use
3230     * with extreme care!
3231     */
3232    public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
3233
3234    /**
3235     * Flag for use with {@link #createPackageContext}: a restricted context may
3236     * disable specific features. For instance, a View associated with a restricted
3237     * context would ignore particular XML attributes.
3238     */
3239    public static final int CONTEXT_RESTRICTED = 0x00000004;
3240
3241    /**
3242     * Return a new Context object for the given application name.  This
3243     * Context is the same as what the named application gets when it is
3244     * launched, containing the same resources and class loader.  Each call to
3245     * this method returns a new instance of a Context object; Context objects
3246     * are not shared, however they share common state (Resources, ClassLoader,
3247     * etc) so the Context instance itself is fairly lightweight.
3248     *
3249     * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
3250     * application with the given package name.
3251     *
3252     * <p>Throws {@link java.lang.SecurityException} if the Context requested
3253     * can not be loaded into the caller's process for security reasons (see
3254     * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3255     *
3256     * @param packageName Name of the application's package.
3257     * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3258     *              or {@link #CONTEXT_IGNORE_SECURITY}.
3259     *
3260     * @return A {@link Context} for the application.
3261     *
3262     * @throws SecurityException &nbsp;
3263     * @throws PackageManager.NameNotFoundException if there is no application with
3264     * the given package name.
3265     */
3266    public abstract Context createPackageContext(String packageName,
3267            @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
3268
3269    /**
3270     * Similar to {@link #createPackageContext(String, int)}, but with a
3271     * different {@link UserHandle}. For example, {@link #getContentResolver()}
3272     * will open any {@link Uri} as the given user.
3273     *
3274     * @hide
3275     */
3276    public abstract Context createPackageContextAsUser(
3277            String packageName, int flags, UserHandle user)
3278            throws PackageManager.NameNotFoundException;
3279
3280    /**
3281     * Get the userId associated with this context
3282     * @return user id
3283     *
3284     * @hide
3285     */
3286    public abstract int getUserId();
3287
3288    /**
3289     * Return a new Context object for the current Context but whose resources
3290     * are adjusted to match the given Configuration.  Each call to this method
3291     * returns a new instance of a Context object; Context objects are not
3292     * shared, however common state (ClassLoader, other Resources for the
3293     * same configuration) may be so the Context itself can be fairly lightweight.
3294     *
3295     * @param overrideConfiguration A {@link Configuration} specifying what
3296     * values to modify in the base Configuration of the original Context's
3297     * resources.  If the base configuration changes (such as due to an
3298     * orientation change), the resources of this context will also change except
3299     * for those that have been explicitly overridden with a value here.
3300     *
3301     * @return A {@link Context} with the given configuration override.
3302     */
3303    public abstract Context createConfigurationContext(
3304            @NonNull Configuration overrideConfiguration);
3305
3306    /**
3307     * Return a new Context object for the current Context but whose resources
3308     * are adjusted to match the metrics of the given Display.  Each call to this method
3309     * returns a new instance of a Context object; Context objects are not
3310     * shared, however common state (ClassLoader, other Resources for the
3311     * same configuration) may be so the Context itself can be fairly lightweight.
3312     *
3313     * The returned display Context provides a {@link WindowManager}
3314     * (see {@link #getSystemService(String)}) that is configured to show windows
3315     * on the given display.  The WindowManager's {@link WindowManager#getDefaultDisplay}
3316     * method can be used to retrieve the Display from the returned Context.
3317     *
3318     * @param display A {@link Display} object specifying the display
3319     * for whose metrics the Context's resources should be tailored and upon which
3320     * new windows should be shown.
3321     *
3322     * @return A {@link Context} for the display.
3323     */
3324    public abstract Context createDisplayContext(@NonNull Display display);
3325
3326    /**
3327     * Gets the display adjustments holder for this context.  This information
3328     * is provided on a per-application or activity basis and is used to simulate lower density
3329     * display metrics for legacy applications and restricted screen sizes.
3330     *
3331     * @param displayId The display id for which to get compatibility info.
3332     * @return The compatibility info holder, or null if not required by the application.
3333     * @hide
3334     */
3335    public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
3336
3337    /**
3338     * Indicates whether this Context is restricted.
3339     *
3340     * @return {@code true} if this Context is restricted, {@code false} otherwise.
3341     *
3342     * @see #CONTEXT_RESTRICTED
3343     */
3344    public boolean isRestricted() {
3345        return false;
3346    }
3347}
3348