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