2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.content;
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.StringDef;
23 import android.annotation.SystemApi;
24 import android.content.pm.ApplicationInfo;
25 import android.content.pm.PackageManager;
26 import android.content.res.AssetManager;
27 import android.content.res.Configuration;
28 import android.content.res.Resources;
29 import android.content.res.TypedArray;
30 import android.database.DatabaseErrorHandler;
31 import android.database.sqlite.SQLiteDatabase;
32 import android.database.sqlite.SQLiteDatabase.CursorFactory;
33 import android.graphics.Bitmap;
34 import android.graphics.drawable.Drawable;
35 import android.media.MediaScannerConnection.OnScanCompletedListener;
36 import android.net.Uri;
37 import android.os.Bundle;
38 import android.os.Environment;
39 import android.os.Handler;
40 import android.os.Looper;
41 import android.os.StatFs;
42 import android.os.UserHandle;
43 import android.os.UserManager;
44 import android.provider.MediaStore;
45 import android.util.AttributeSet;
46 import android.view.DisplayAdjustments;
47 import android.view.Display;
48 import android.view.ViewDebug;
49 import android.view.WindowManager;
52 import java.io.FileInputStream;
53 import java.io.FileNotFoundException;
54 import java.io.FileOutputStream;
55 import java.io.IOException;
56 import java.io.InputStream;
57 import java.lang.annotation.Retention;
58 import java.lang.annotation.RetentionPolicy;
61 * Interface to global information about an application environment. This is
62 * an abstract class whose implementation is provided by
63 * the Android system. It
64 * allows access to application-specific resources and classes, as well as
65 * up-calls for application-level operations such as launching activities,
66 * broadcasting and receiving intents, etc.
68 public abstract class Context {
70 * File creation mode: the default mode, where the created file can only
71 * be accessed by the calling application (or all applications sharing the
73 * @see #MODE_WORLD_READABLE
74 * @see #MODE_WORLD_WRITEABLE
76 public static final int MODE_PRIVATE = 0x0000;
78 * @deprecated Creating world-readable files is very dangerous, and likely
79 * to cause security holes in applications. It is strongly discouraged;
80 * instead, applications should use more formal mechanism for interactions
81 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
82 * {@link android.app.Service}. There are no guarantees that this
83 * access mode will remain on a file, such as when it goes through a
85 * File creation mode: allow all other applications to have read access
86 * to the created file.
88 * @see #MODE_WORLD_WRITEABLE
91 public static final int MODE_WORLD_READABLE = 0x0001;
93 * @deprecated Creating world-writable files is very dangerous, and likely
94 * to cause security holes in applications. It is strongly discouraged;
95 * instead, applications should use more formal mechanism for interactions
96 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
97 * {@link android.app.Service}. There are no guarantees that this
98 * access mode will remain on a file, such as when it goes through a
100 * File creation mode: allow all other applications to have write access
101 * to the created file.
103 * @see #MODE_WORLD_READABLE
106 public static final int MODE_WORLD_WRITEABLE = 0x0002;
108 * File creation mode: for use with {@link #openFileOutput}, if the file
109 * already exists then write data to the end of the existing file
110 * instead of erasing it.
111 * @see #openFileOutput
113 public static final int MODE_APPEND = 0x8000;
116 * SharedPreference loading flag: when set, the file on disk will
117 * be checked for modification even if the shared preferences
118 * instance is already loaded in this process. This behavior is
119 * sometimes desired in cases where the application has multiple
120 * processes, all writing to the same SharedPreferences file.
121 * Generally there are better forms of communication between
124 * <p>This was the legacy (but undocumented) behavior in and
125 * before Gingerbread (Android 2.3) and this flag is implied when
126 * targetting such releases. For applications targetting SDK
127 * versions <em>greater than</em> Android 2.3, this flag must be
128 * explicitly set if desired.
130 * @see #getSharedPreferences
132 public static final int MODE_MULTI_PROCESS = 0x0004;
135 * Database open flag: when set, the database is opened with write-ahead
136 * logging enabled by default.
138 * @see #openOrCreateDatabase(String, int, CursorFactory)
139 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
140 * @see SQLiteDatabase#enableWriteAheadLogging
142 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
152 BIND_ALLOW_OOM_MANAGEMENT,
155 @Retention(RetentionPolicy.SOURCE)
156 public @interface BindServiceFlags {}
159 * Flag for {@link #bindService}: automatically create the service as long
160 * as the binding exists. Note that while this will create the service,
161 * its {@link android.app.Service#onStartCommand}
162 * method will still only be called due to an
163 * explicit call to {@link #startService}. Even without that, though,
164 * this still provides you with access to the service object while the
165 * service is created.
167 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
168 * not supplying this flag would also impact how important the system
169 * consider's the target service's process to be. When set, the only way
170 * for it to be raised was by binding from a service in which case it will
171 * only be important when that activity is in the foreground. Now to
172 * achieve this behavior you must explicitly supply the new flag
173 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
174 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
175 * the flags {@link #BIND_WAIVE_PRIORITY} and
176 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
179 public static final int BIND_AUTO_CREATE = 0x0001;
182 * Flag for {@link #bindService}: include debugging help for mismatched
183 * calls to unbind. When this flag is set, the callstack of the following
184 * {@link #unbindService} call is retained, to be printed if a later
185 * incorrect unbind call is made. Note that doing this requires retaining
186 * information about the binding that was made for the lifetime of the app,
187 * resulting in a leak -- this should only be used for debugging.
189 public static final int BIND_DEBUG_UNBIND = 0x0002;
192 * Flag for {@link #bindService}: don't allow this binding to raise
193 * the target service's process to the foreground scheduling priority.
194 * It will still be raised to at least the same memory priority
195 * as the client (so that its process will not be killable in any
196 * situation where the client is not killable), but for CPU scheduling
197 * purposes it may be left in the background. This only has an impact
198 * in the situation where the binding client is a foreground process
199 * and the target service is in a background process.
201 public static final int BIND_NOT_FOREGROUND = 0x0004;
204 * Flag for {@link #bindService}: indicates that the client application
205 * binding to this service considers the service to be more important than
206 * the app itself. When set, the platform will try to have the out of
207 * memory killer kill the app before it kills the service it is bound to, though
208 * this is not guaranteed to be the case.
210 public static final int BIND_ABOVE_CLIENT = 0x0008;
213 * Flag for {@link #bindService}: allow the process hosting the bound
214 * service to go through its normal memory management. It will be
215 * treated more like a running service, allowing the system to
216 * (temporarily) expunge the process if low on memory or for some other
217 * whim it may have, and being more aggressive about making it a candidate
218 * to be killed (and restarted) if running for a long time.
220 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
223 * Flag for {@link #bindService}: don't impact the scheduling or
224 * memory management priority of the target service's hosting process.
225 * Allows the service's process to be managed on the background LRU list
226 * just like a regular application process in the background.
228 public static final int BIND_WAIVE_PRIORITY = 0x0020;
231 * Flag for {@link #bindService}: this service is very important to
232 * the client, so should be brought to the foreground process level
233 * when the client is. Normally a process can only be raised to the
234 * visibility level by a client, even if that client is in the foreground.
236 public static final int BIND_IMPORTANT = 0x0040;
239 * Flag for {@link #bindService}: If binding from an activity, allow the
240 * target service's process importance to be raised based on whether the
241 * activity is visible to the user, regardless whether another flag is
242 * used to reduce the amount that the client process's overall importance
243 * is used to impact it.
245 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
248 * @hide Flag for {@link #bindService}: Treat the binding as hosting
249 * an activity, an unbinding as the activity going in the background.
250 * That is, when unbinding, the process when empty will go on the activity
251 * LRU list instead of the regular one, keeping it around more aggressively
252 * than it otherwise would be. This is intended for use with IMEs to try
253 * to keep IME processes around for faster keyboard switching.
255 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
258 * @hide An idea that is not yet implemented.
259 * Flag for {@link #bindService}: If binding from an activity, consider
260 * this service to be visible like the binding activity is. That is,
261 * it will be treated as something more important to keep around than
262 * invisible background activities. This will impact the number of
263 * recent activities the user can switch between without having them
264 * restart. There is no guarantee this will be respected, as the system
265 * tries to balance such requests from one app vs. the importantance of
266 * keeping other apps around.
268 public static final int BIND_VISIBLE = 0x10000000;
272 * Flag for {@link #bindService}: Consider this binding to be causing the target
273 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
276 public static final int BIND_SHOWING_UI = 0x20000000;
279 * Flag for {@link #bindService}: Don't consider the bound service to be
280 * visible, even if the caller is visible.
283 public static final int BIND_NOT_VISIBLE = 0x40000000;
285 /** Return an AssetManager instance for your application's package. */
286 public abstract AssetManager getAssets();
288 /** Return a Resources instance for your application's package. */
289 public abstract Resources getResources();
291 /** Return PackageManager instance to find global package information. */
292 public abstract PackageManager getPackageManager();
294 /** Return a ContentResolver instance for your application's package. */
295 public abstract ContentResolver getContentResolver();
298 * Return the Looper for the main thread of the current process. This is
299 * the thread used to dispatch calls to application components (activities,
302 * By definition, this method returns the same result as would be obtained
303 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
306 * @return The main looper.
308 public abstract Looper getMainLooper();
311 * Return the context of the single, global Application object of the
312 * current process. This generally should only be used if you need a
313 * Context whose lifecycle is separate from the current context, that is
314 * tied to the lifetime of the process rather than the current component.
316 * <p>Consider for example how this interacts with
317 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
319 * <li> <p>If used from an Activity context, the receiver is being registered
320 * within that activity. This means that you are expected to unregister
321 * before the activity is done being destroyed; in fact if you do not do
322 * so, the framework will clean up your leaked registration as it removes
323 * the activity and log an error. Thus, if you use the Activity context
324 * to register a receiver that is static (global to the process, not
325 * associated with an Activity instance) then that registration will be
326 * removed on you at whatever point the activity you used is destroyed.
327 * <li> <p>If used from the Context returned here, the receiver is being
328 * registered with the global state associated with your application. Thus
329 * it will never be unregistered for you. This is necessary if the receiver
330 * is associated with static data, not a particular component. However
331 * using the ApplicationContext elsewhere can easily lead to serious leaks
332 * if you forget to unregister, unbind, etc.
335 public abstract Context getApplicationContext();
338 * Add a new {@link ComponentCallbacks} to the base application of the
339 * Context, which will be called at the same times as the ComponentCallbacks
340 * methods of activities and other components are called. Note that you
341 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
342 * appropriate in the future; this will not be removed for you.
344 * @param callback The interface to call. This can be either a
345 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
347 public void registerComponentCallbacks(ComponentCallbacks callback) {
348 getApplicationContext().registerComponentCallbacks(callback);
352 * Remove a {@link ComponentCallbacks} object that was previously registered
353 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
355 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
356 getApplicationContext().unregisterComponentCallbacks(callback);
360 * Return a localized, styled CharSequence from the application's package's
361 * default string table.
363 * @param resId Resource id for the CharSequence text
365 public final CharSequence getText(int resId) {
366 return getResources().getText(resId);
370 * Return a localized string from the application's package's
371 * default string table.
373 * @param resId Resource id for the string
375 public final String getString(int resId) {
376 return getResources().getString(resId);
380 * Return a localized formatted string from the application's package's
381 * default string table, substituting the format arguments as defined in
382 * {@link java.util.Formatter} and {@link java.lang.String#format}.
384 * @param resId Resource id for the format string
385 * @param formatArgs The format arguments that will be used for substitution.
388 public final String getString(int resId, Object... formatArgs) {
389 return getResources().getString(resId, formatArgs);
393 * Return a drawable object associated with a particular resource ID and
394 * styled for the current theme.
396 * @param id The desired resource identifier, as generated by the aapt
397 * tool. This integer encodes the package, type, and resource
398 * entry. The value 0 is an invalid identifier.
399 * @return Drawable An object that can be used to draw this resource.
401 public final Drawable getDrawable(int id) {
402 return getResources().getDrawable(id, getTheme());
406 * Set the base theme for this context. Note that this should be called
407 * before any views are instantiated in the Context (for example before
408 * calling {@link android.app.Activity#setContentView} or
409 * {@link android.view.LayoutInflater#inflate}).
411 * @param resid The style resource describing the theme.
413 public abstract void setTheme(int resid);
415 /** @hide Needed for some internal implementation... not public because
416 * you can't assume this actually means anything. */
417 public int getThemeResId() {
422 * Return the Theme object associated with this Context.
424 @ViewDebug.ExportedProperty(deepExport = true)
425 public abstract Resources.Theme getTheme();
428 * Retrieve styled attribute information in this Context's theme. See
429 * {@link Resources.Theme#obtainStyledAttributes(int[])}
430 * for more information.
432 * @see Resources.Theme#obtainStyledAttributes(int[])
434 public final TypedArray obtainStyledAttributes(
436 return getTheme().obtainStyledAttributes(attrs);
440 * Retrieve styled attribute information in this Context's theme. See
441 * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
442 * for more information.
444 * @see Resources.Theme#obtainStyledAttributes(int, int[])
446 public final TypedArray obtainStyledAttributes(
447 int resid, int[] attrs) throws Resources.NotFoundException {
448 return getTheme().obtainStyledAttributes(resid, attrs);
452 * Retrieve styled attribute information in this Context's theme. See
453 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
454 * for more information.
456 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
458 public final TypedArray obtainStyledAttributes(
459 AttributeSet set, int[] attrs) {
460 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
464 * Retrieve styled attribute information in this Context's theme. See
465 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
466 * for more information.
468 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
470 public final TypedArray obtainStyledAttributes(
471 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
472 return getTheme().obtainStyledAttributes(
473 set, attrs, defStyleAttr, defStyleRes);
477 * Return a class loader you can use to retrieve classes in this package.
479 public abstract ClassLoader getClassLoader();
481 /** Return the name of this application's package. */
482 public abstract String getPackageName();
484 /** @hide Return the name of the base context this context is derived from. */
485 public abstract String getBasePackageName();
487 /** @hide Return the package name that should be used for app ops calls from
488 * this context. This is the same as {@link #getBasePackageName()} except in
489 * cases where system components are loaded into other app processes, in which
490 * case this will be the name of the primary package in that process (so that app
491 * ops uid verification will work with the name). */
492 public abstract String getOpPackageName();
494 /** Return the full application info for this context's package. */
495 public abstract ApplicationInfo getApplicationInfo();
498 * Return the full path to this context's primary Android package.
499 * The Android package is a ZIP file which contains the application's
502 * <p>Note: this is not generally useful for applications, since they should
503 * not be directly accessing the file system.
505 * @return String Path to the resources.
507 public abstract String getPackageResourcePath();
510 * Return the full path to this context's primary Android package.
511 * The Android package is a ZIP file which contains application's
512 * primary code and assets.
514 * <p>Note: this is not generally useful for applications, since they should
515 * not be directly accessing the file system.
517 * @return String Path to the code and assets.
519 public abstract String getPackageCodePath();
523 * Return the full path to the shared prefs file for the given prefs group name.
525 * <p>Note: this is not generally useful for applications, since they should
526 * not be directly accessing the file system.
528 public abstract File getSharedPrefsFile(String name);
531 * Retrieve and hold the contents of the preferences file 'name', returning
532 * a SharedPreferences through which you can retrieve and modify its
533 * values. Only one instance of the SharedPreferences object is returned
534 * to any callers for the same name, meaning they will see each other's
535 * edits as soon as they are made.
537 * @param name Desired preferences file. If a preferences file by this name
538 * does not exist, it will be created when you retrieve an
539 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
540 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
541 * default operation, {@link #MODE_WORLD_READABLE}
542 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
543 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
544 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
545 * is always on in apps targeting Gingerbread (Android 2.3) and below, and
546 * off by default in later versions.
548 * @return The single {@link SharedPreferences} instance that can be used
549 * to retrieve and modify the preference values.
552 * @see #MODE_WORLD_READABLE
553 * @see #MODE_WORLD_WRITEABLE
554 * @see #MODE_MULTI_PROCESS
556 public abstract SharedPreferences getSharedPreferences(String name,
560 * Open a private file associated with this Context's application package
563 * @param name The name of the file to open; can not contain path
566 * @return The resulting {@link FileInputStream}.
568 * @see #openFileOutput
571 * @see java.io.FileInputStream#FileInputStream(String)
573 public abstract FileInputStream openFileInput(String name)
574 throws FileNotFoundException;
577 * Open a private file associated with this Context's application package
578 * for writing. Creates the file if it doesn't already exist.
580 * <p>No permissions are required to invoke this method, since it uses internal
583 * @param name The name of the file to open; can not contain path
585 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
586 * default operation, {@link #MODE_APPEND} to append to an existing file,
587 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
590 * @return The resulting {@link FileOutputStream}.
594 * @see #MODE_WORLD_READABLE
595 * @see #MODE_WORLD_WRITEABLE
596 * @see #openFileInput
599 * @see java.io.FileOutputStream#FileOutputStream(String)
601 public abstract FileOutputStream openFileOutput(String name, int mode)
602 throws FileNotFoundException;
605 * Delete the given private file associated with this Context's
606 * application package.
608 * @param name The name of the file to delete; can not contain path
611 * @return {@code true} if the file was successfully deleted; else
614 * @see #openFileInput
615 * @see #openFileOutput
617 * @see java.io.File#delete()
619 public abstract boolean deleteFile(String name);
622 * Returns the absolute path on the filesystem where a file created with
623 * {@link #openFileOutput} is stored.
625 * @param name The name of the file for which you would like to get
628 * @return An absolute path to the given file.
630 * @see #openFileOutput
634 public abstract File getFileStreamPath(String name);
637 * Returns the absolute path to the directory on the filesystem where
638 * files created with {@link #openFileOutput} are stored.
640 * <p>No permissions are required to read or write to the returned path, since this
641 * path is internal storage.
643 * @return The path of the directory holding application files.
645 * @see #openFileOutput
646 * @see #getFileStreamPath
649 public abstract File getFilesDir();
652 * Returns the absolute path to the directory on the filesystem similar to
653 * {@link #getFilesDir()}. The difference is that files placed under this
654 * directory will be excluded from automatic backup to remote storage. See
655 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
656 * of the automatic backup mechanism in Android.
658 * <p>No permissions are required to read or write to the returned path, since this
659 * path is internal storage.
661 * @return The path of the directory holding application files that will not be
662 * automatically backed up to remote storage.
664 * @see #openFileOutput
665 * @see #getFileStreamPath
667 * @see android.app.backup.BackupAgent
669 public abstract File getNoBackupFilesDir();
672 * Returns the absolute path to the directory on the primary external filesystem
673 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
674 * Environment.getExternalStorageDirectory()}) where the application can
675 * place persistent files it owns. These files are internal to the
676 * applications, and not typically visible to the user as media.
678 * <p>This is like {@link #getFilesDir()} in that these
679 * files will be deleted when the application is uninstalled, however there
680 * are some important differences:
683 * <li>External files are not always available: they will disappear if the
684 * user mounts the external storage on a computer or removes it. See the
685 * APIs on {@link android.os.Environment} for information in the storage state.
686 * <li>There is no security enforced with these files. For example, any application
687 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
691 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
692 * are required to read or write to the returned path; it's always
693 * accessible to the calling app. This only applies to paths generated for
694 * package name of the calling application. To access paths belonging
695 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
696 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
698 * <p>On devices with multiple users (as described by {@link UserManager}),
699 * each user has their own isolated external storage. Applications only
700 * have access to the external storage for the user they're running as.</p>
702 * <p>Here is an example of typical code to manipulate a file in
703 * an application's private storage:</p>
705 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
708 * <p>If you supply a non-null <var>type</var> to this function, the returned
709 * file will be a path to a sub-directory of the given type. Though these files
710 * are not automatically scanned by the media scanner, you can explicitly
711 * add them to the media database with
712 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
713 * OnScanCompletedListener) MediaScannerConnection.scanFile}.
714 * Note that this is not the same as
715 * {@link android.os.Environment#getExternalStoragePublicDirectory
716 * Environment.getExternalStoragePublicDirectory()}, which provides
717 * directories of media shared by all applications. The
718 * directories returned here are
719 * owned by the application, and their contents will be removed when the
720 * application is uninstalled. Unlike
721 * {@link android.os.Environment#getExternalStoragePublicDirectory
722 * Environment.getExternalStoragePublicDirectory()}, the directory
723 * returned here will be automatically created for you.
725 * <p>Here is an example of typical code to manipulate a picture in
726 * an application's private storage and add it to the media database:</p>
728 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
731 * @param type The type of files directory to return. May be null for
732 * the root of the files directory or one of
733 * the following Environment constants for a subdirectory:
734 * {@link android.os.Environment#DIRECTORY_MUSIC},
735 * {@link android.os.Environment#DIRECTORY_PODCASTS},
736 * {@link android.os.Environment#DIRECTORY_RINGTONES},
737 * {@link android.os.Environment#DIRECTORY_ALARMS},
738 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
739 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
740 * {@link android.os.Environment#DIRECTORY_MOVIES}.
742 * @return The path of the directory holding application files
743 * on external storage. Returns null if external storage is not currently
744 * mounted so it could not ensure the path exists; you will need to call
745 * this method again when it is available.
748 * @see android.os.Environment#getExternalStoragePublicDirectory
751 public abstract File getExternalFilesDir(@Nullable String type);
754 * Returns absolute paths to application-specific directories on all
755 * external storage devices where the application can place persistent files
756 * it owns. These files are internal to the application, and not typically
757 * visible to the user as media.
759 * This is like {@link #getFilesDir()} in that these files will be deleted when
760 * the application is uninstalled, however there are some important differences:
762 * <li>External files are not always available: they will disappear if the
763 * user mounts the external storage on a computer or removes it.
764 * <li>There is no security enforced with these files.
767 * External storage devices returned here are considered a permanent part of
768 * the device, including both emulated external storage and physical media
769 * slots, such as SD cards in a battery compartment. The returned paths do
770 * not include transient devices, such as USB flash drives.
772 * An application may store data on any or all of the returned devices. For
773 * example, an app may choose to store large files on the device with the
774 * most available space, as measured by {@link StatFs}.
776 * No permissions are required to read or write to the returned paths; they
777 * are always accessible to the calling app. Write access outside of these
778 * paths on secondary external storage devices is not available.
780 * The first path returned is the same as {@link #getExternalFilesDir(String)}.
781 * Returned paths may be {@code null} if a storage device is unavailable.
783 * @see #getExternalFilesDir(String)
784 * @see Environment#getExternalStorageState(File)
786 public abstract File[] getExternalFilesDirs(String type);
789 * Return the primary external storage directory where this application's OBB
790 * files (if there are any) can be found. Note if the application does not have
791 * any OBB files, this directory may not exist.
793 * This is like {@link #getFilesDir()} in that these files will be deleted when
794 * the application is uninstalled, however there are some important differences:
796 * <li>External files are not always available: they will disappear if the
797 * user mounts the external storage on a computer or removes it.
798 * <li>There is no security enforced with these files. For example, any application
799 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
803 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
804 * are required to read or write to the returned path; it's always
805 * accessible to the calling app. This only applies to paths generated for
806 * package name of the calling application. To access paths belonging
807 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
808 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
810 * On devices with multiple users (as described by {@link UserManager}),
811 * multiple users may share the same OBB storage location. Applications
812 * should ensure that multiple instances running under different users don't
813 * interfere with each other.
815 public abstract File getObbDir();
818 * Returns absolute paths to application-specific directories on all
819 * external storage devices where the application's OBB files (if there are
820 * any) can be found. Note if the application does not have any OBB files,
821 * these directories may not exist.
823 * This is like {@link #getFilesDir()} in that these files will be deleted when
824 * the application is uninstalled, however there are some important differences:
826 * <li>External files are not always available: they will disappear if the
827 * user mounts the external storage on a computer or removes it.
828 * <li>There is no security enforced with these files.
831 * External storage devices returned here are considered a permanent part of
832 * the device, including both emulated external storage and physical media
833 * slots, such as SD cards in a battery compartment. The returned paths do
834 * not include transient devices, such as USB flash drives.
836 * An application may store data on any or all of the returned devices. For
837 * example, an app may choose to store large files on the device with the
838 * most available space, as measured by {@link StatFs}.
840 * No permissions are required to read or write to the returned paths; they
841 * are always accessible to the calling app. Write access outside of these
842 * paths on secondary external storage devices is not available.
844 * The first path returned is the same as {@link #getObbDir()}.
845 * Returned paths may be {@code null} if a storage device is unavailable.
848 * @see Environment#getExternalStorageState(File)
850 public abstract File[] getObbDirs();
853 * Returns the absolute path to the application specific cache directory
854 * on the filesystem. These files will be ones that get deleted first when the
855 * device runs low on storage.
856 * There is no guarantee when these files will be deleted.
858 * <strong>Note: you should not <em>rely</em> on the system deleting these
859 * files for you; you should always have a reasonable maximum, such as 1 MB,
860 * for the amount of space you consume with cache files, and prune those
861 * files when exceeding that space.</strong>
863 * @return The path of the directory holding application cache files.
865 * @see #openFileOutput
866 * @see #getFileStreamPath
869 public abstract File getCacheDir();
872 * Returns the absolute path to the application specific cache directory on
873 * the filesystem designed for storing cached code. The system will delete
874 * any files stored in this location both when your specific application is
875 * upgraded, and when the entire platform is upgraded.
877 * This location is optimal for storing compiled or optimized code generated
878 * by your application at runtime.
880 * Apps require no extra permissions to read or write to the returned path,
881 * since this path lives in their private storage.
883 * @return The path of the directory holding application code cache files.
885 public abstract File getCodeCacheDir();
888 * Returns the absolute path to the directory on the primary external filesystem
889 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
890 * Environment.getExternalStorageDirectory()} where the application can
891 * place cache files it owns. These files are internal to the application, and
892 * not typically visible to the user as media.
894 * <p>This is like {@link #getCacheDir()} in that these
895 * files will be deleted when the application is uninstalled, however there
896 * are some important differences:
899 * <li>The platform does not always monitor the space available in external
900 * storage, and thus may not automatically delete these files. Currently
901 * the only time files here will be deleted by the platform is when running
902 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
903 * {@link android.os.Environment#isExternalStorageEmulated()
904 * Environment.isExternalStorageEmulated()} returns true. Note that you should
905 * be managing the maximum space you will use for these anyway, just like
906 * with {@link #getCacheDir()}.
907 * <li>External files are not always available: they will disappear if the
908 * user mounts the external storage on a computer or removes it. See the
909 * APIs on {@link android.os.Environment} for information in the storage state.
910 * <li>There is no security enforced with these files. For example, any application
911 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
915 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
916 * are required to read or write to the returned path; it's always
917 * accessible to the calling app. This only applies to paths generated for
918 * package name of the calling application. To access paths belonging
919 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
920 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
922 * <p>On devices with multiple users (as described by {@link UserManager}),
923 * each user has their own isolated external storage. Applications only
924 * have access to the external storage for the user they're running as.</p>
926 * @return The path of the directory holding application cache files
927 * on external storage. Returns null if external storage is not currently
928 * mounted so it could not ensure the path exists; you will need to call
929 * this method again when it is available.
934 public abstract File getExternalCacheDir();
937 * Returns absolute paths to application-specific directories on all
938 * external storage devices where the application can place cache files it
939 * owns. These files are internal to the application, and not typically
940 * visible to the user as media.
942 * This is like {@link #getCacheDir()} in that these files will be deleted when
943 * the application is uninstalled, however there are some important differences:
945 * <li>External files are not always available: they will disappear if the
946 * user mounts the external storage on a computer or removes it.
947 * <li>There is no security enforced with these files.
950 * External storage devices returned here are considered a permanent part of
951 * the device, including both emulated external storage and physical media
952 * slots, such as SD cards in a battery compartment. The returned paths do
953 * not include transient devices, such as USB flash drives.
955 * An application may store data on any or all of the returned devices. For
956 * example, an app may choose to store large files on the device with the
957 * most available space, as measured by {@link StatFs}.
959 * No permissions are required to read or write to the returned paths; they
960 * are always accessible to the calling app. Write access outside of these
961 * paths on secondary external storage devices is not available.
963 * The first path returned is the same as {@link #getExternalCacheDir()}.
964 * Returned paths may be {@code null} if a storage device is unavailable.
966 * @see #getExternalCacheDir()
967 * @see Environment#getExternalStorageState(File)
969 public abstract File[] getExternalCacheDirs();
972 * Returns absolute paths to application-specific directories on all
973 * external storage devices where the application can place media files.
974 * These files are scanned and made available to other apps through
975 * {@link MediaStore}.
977 * This is like {@link #getExternalFilesDirs} in that these files will be
978 * deleted when the application is uninstalled, however there are some
979 * important differences:
981 * <li>External files are not always available: they will disappear if the
982 * user mounts the external storage on a computer or removes it.
983 * <li>There is no security enforced with these files.
986 * External storage devices returned here are considered a permanent part of
987 * the device, including both emulated external storage and physical media
988 * slots, such as SD cards in a battery compartment. The returned paths do
989 * not include transient devices, such as USB flash drives.
991 * An application may store data on any or all of the returned devices. For
992 * example, an app may choose to store large files on the device with the
993 * most available space, as measured by {@link StatFs}.
995 * No permissions are required to read or write to the returned paths; they
996 * are always accessible to the calling app. Write access outside of these
997 * paths on secondary external storage devices is not available.
999 * Returned paths may be {@code null} if a storage device is unavailable.
1001 * @see Environment#getExternalStorageState(File)
1003 public abstract File[] getExternalMediaDirs();
1006 * Returns an array of strings naming the private files associated with
1007 * this Context's application package.
1009 * @return Array of strings naming the private files.
1011 * @see #openFileInput
1012 * @see #openFileOutput
1015 public abstract String[] fileList();
1018 * Retrieve, creating if needed, a new directory in which the application
1019 * can place its own custom data files. You can use the returned File
1020 * object to create and access files in this directory. Note that files
1021 * created through a File object will only be accessible by your own
1022 * application; you can only set the mode of the entire directory, not
1023 * of individual files.
1025 * @param name Name of the directory to retrieve. This is a directory
1026 * that is created as part of your application data.
1027 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1028 * default operation, {@link #MODE_WORLD_READABLE} and
1029 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
1031 * @return A {@link File} object for the requested directory. The directory
1032 * will have been created if it does not already exist.
1034 * @see #openFileOutput(String, int)
1036 public abstract File getDir(String name, int mode);
1039 * Open a new private SQLiteDatabase associated with this Context's
1040 * application package. Create the database file if it doesn't exist.
1042 * @param name The name (unique in the application package) of the database.
1043 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1044 * default operation, {@link #MODE_WORLD_READABLE}
1045 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
1046 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
1047 * @param factory An optional factory class that is called to instantiate a
1048 * cursor when query is called.
1050 * @return The contents of a newly created database with the given name.
1051 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
1053 * @see #MODE_PRIVATE
1054 * @see #MODE_WORLD_READABLE
1055 * @see #MODE_WORLD_WRITEABLE
1056 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1057 * @see #deleteDatabase
1059 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1060 int mode, CursorFactory factory);
1063 * Open a new private SQLiteDatabase associated with this Context's
1064 * application package. Creates the database file if it doesn't exist.
1066 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
1067 * used to handle corruption when sqlite reports database corruption.</p>
1069 * @param name The name (unique in the application package) of the database.
1070 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1071 * default operation, {@link #MODE_WORLD_READABLE}
1072 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
1073 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
1074 * @param factory An optional factory class that is called to instantiate a
1075 * cursor when query is called.
1076 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
1077 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
1078 * @return The contents of a newly created database with the given name.
1079 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
1081 * @see #MODE_PRIVATE
1082 * @see #MODE_WORLD_READABLE
1083 * @see #MODE_WORLD_WRITEABLE
1084 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1085 * @see #deleteDatabase
1087 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1088 int mode, CursorFactory factory,
1089 @Nullable DatabaseErrorHandler errorHandler);
1092 * Delete an existing private SQLiteDatabase associated with this Context's
1093 * application package.
1095 * @param name The name (unique in the application package) of the
1098 * @return {@code true} if the database was successfully deleted; else {@code false}.
1100 * @see #openOrCreateDatabase
1102 public abstract boolean deleteDatabase(String name);
1105 * Returns the absolute path on the filesystem where a database created with
1106 * {@link #openOrCreateDatabase} is stored.
1108 * @param name The name of the database for which you would like to get
1111 * @return An absolute path to the given database.
1113 * @see #openOrCreateDatabase
1115 public abstract File getDatabasePath(String name);
1118 * Returns an array of strings naming the private databases associated with
1119 * this Context's application package.
1121 * @return Array of strings naming the private databases.
1123 * @see #openOrCreateDatabase
1124 * @see #deleteDatabase
1126 public abstract String[] databaseList();
1129 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
1130 * WallpaperManager.get()} instead.
1133 public abstract Drawable getWallpaper();
1136 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
1137 * WallpaperManager.peek()} instead.
1140 public abstract Drawable peekWallpaper();
1143 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1144 * WallpaperManager.getDesiredMinimumWidth()} instead.
1147 public abstract int getWallpaperDesiredMinimumWidth();
1150 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1151 * WallpaperManager.getDesiredMinimumHeight()} instead.
1154 public abstract int getWallpaperDesiredMinimumHeight();
1157 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
1158 * WallpaperManager.set()} instead.
1159 * <p>This method requires the caller to hold the permission
1160 * {@link android.Manifest.permission#SET_WALLPAPER}.
1163 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1166 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
1167 * WallpaperManager.set()} instead.
1168 * <p>This method requires the caller to hold the permission
1169 * {@link android.Manifest.permission#SET_WALLPAPER}.
1172 public abstract void setWallpaper(InputStream data) throws IOException;
1175 * @deprecated Use {@link android.app.WallpaperManager#clear
1176 * WallpaperManager.clear()} instead.
1177 * <p>This method requires the caller to hold the permission
1178 * {@link android.Manifest.permission#SET_WALLPAPER}.
1181 public abstract void clearWallpaper() throws IOException;
1184 * Same as {@link #startActivity(Intent, Bundle)} with no options
1187 * @param intent The description of the activity to start.
1189 * @throws ActivityNotFoundException
1191 * @see #startActivity(Intent, Bundle)
1192 * @see PackageManager#resolveActivity
1194 public abstract void startActivity(Intent intent);
1197 * Version of {@link #startActivity(Intent)} that allows you to specify the
1198 * user the activity will be started for. This is not available to applications
1199 * that are not pre-installed on the system image. Using it requires holding
1200 * the INTERACT_ACROSS_USERS_FULL permission.
1201 * @param intent The description of the activity to start.
1202 * @param user The UserHandle of the user to start this activity for.
1203 * @throws ActivityNotFoundException
1206 public void startActivityAsUser(Intent intent, UserHandle user) {
1207 throw new RuntimeException("Not implemented. Must override in a subclass.");
1211 * Launch a new activity. You will not receive any information about when
1212 * the activity exits.
1214 * <p>Note that if this method is being called from outside of an
1215 * {@link android.app.Activity} Context, then the Intent must include
1216 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1217 * without being started from an existing Activity, there is no existing
1218 * task in which to place the new activity and thus it needs to be placed
1219 * in its own separate task.
1221 * <p>This method throws {@link ActivityNotFoundException}
1222 * if there was no Activity found to run the given Intent.
1224 * @param intent The description of the activity to start.
1225 * @param options Additional options for how the Activity should be started.
1226 * May be null if there are no options. See {@link android.app.ActivityOptions}
1227 * for how to build the Bundle supplied here; there are no supported definitions
1228 * for building it manually.
1230 * @throws ActivityNotFoundException
1232 * @see #startActivity(Intent)
1233 * @see PackageManager#resolveActivity
1235 public abstract void startActivity(Intent intent, @Nullable Bundle options);
1238 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1239 * user the activity will be started for. This is not available to applications
1240 * that are not pre-installed on the system image. Using it requires holding
1241 * the INTERACT_ACROSS_USERS_FULL permission.
1242 * @param intent The description of the activity to start.
1243 * @param options Additional options for how the Activity should be started.
1244 * May be null if there are no options. See {@link android.app.ActivityOptions}
1245 * for how to build the Bundle supplied here; there are no supported definitions
1246 * for building it manually.
1247 * @param userId The UserHandle of the user to start this activity for.
1248 * @throws ActivityNotFoundException
1251 public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
1252 throw new RuntimeException("Not implemented. Must override in a subclass.");
1256 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1259 * @param intents An array of Intents to be started.
1261 * @throws ActivityNotFoundException
1263 * @see #startActivities(Intent[], Bundle)
1264 * @see PackageManager#resolveActivity
1266 public abstract void startActivities(Intent[] intents);
1269 * Launch multiple new activities. This is generally the same as calling
1270 * {@link #startActivity(Intent)} for the first Intent in the array,
1271 * that activity during its creation calling {@link #startActivity(Intent)}
1272 * for the second entry, etc. Note that unlike that approach, generally
1273 * none of the activities except the last in the array will be created
1274 * at this point, but rather will be created when the user first visits
1275 * them (due to pressing back from the activity on top).
1277 * <p>This method throws {@link ActivityNotFoundException}
1278 * if there was no Activity found for <em>any</em> given Intent. In this
1279 * case the state of the activity stack is undefined (some Intents in the
1280 * list may be on it, some not), so you probably want to avoid such situations.
1282 * @param intents An array of Intents to be started.
1283 * @param options Additional options for how the Activity should be started.
1284 * See {@link android.content.Context#startActivity(Intent, Bundle)
1285 * Context.startActivity(Intent, Bundle)} for more details.
1287 * @throws ActivityNotFoundException
1289 * @see #startActivities(Intent[])
1290 * @see PackageManager#resolveActivity
1292 public abstract void startActivities(Intent[] intents, Bundle options);
1296 * Launch multiple new activities. This is generally the same as calling
1297 * {@link #startActivity(Intent)} for the first Intent in the array,
1298 * that activity during its creation calling {@link #startActivity(Intent)}
1299 * for the second entry, etc. Note that unlike that approach, generally
1300 * none of the activities except the last in the array will be created
1301 * at this point, but rather will be created when the user first visits
1302 * them (due to pressing back from the activity on top).
1304 * <p>This method throws {@link ActivityNotFoundException}
1305 * if there was no Activity found for <em>any</em> given Intent. In this
1306 * case the state of the activity stack is undefined (some Intents in the
1307 * list may be on it, some not), so you probably want to avoid such situations.
1309 * @param intents An array of Intents to be started.
1310 * @param options Additional options for how the Activity should be started.
1311 * @param userHandle The user for whom to launch the activities
1312 * See {@link android.content.Context#startActivity(Intent, Bundle)
1313 * Context.startActivity(Intent, Bundle)} for more details.
1315 * @throws ActivityNotFoundException
1317 * @see #startActivities(Intent[])
1318 * @see PackageManager#resolveActivity
1320 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1321 throw new RuntimeException("Not implemented. Must override in a subclass.");
1325 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1326 * with no options specified.
1328 * @param intent The IntentSender to launch.
1329 * @param fillInIntent If non-null, this will be provided as the
1330 * intent parameter to {@link IntentSender#sendIntent}.
1331 * @param flagsMask Intent flags in the original IntentSender that you
1332 * would like to change.
1333 * @param flagsValues Desired values for any bits set in
1334 * <var>flagsMask</var>
1335 * @param extraFlags Always set to 0.
1337 * @see #startActivity(Intent)
1338 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1340 public abstract void startIntentSender(IntentSender intent,
1341 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1342 throws IntentSender.SendIntentException;
1345 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
1346 * to start. If the IntentSender is for an activity, that activity will be started
1347 * as if you had called the regular {@link #startActivity(Intent)}
1348 * here; otherwise, its associated action will be executed (such as
1349 * sending a broadcast) as if you had called
1350 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
1352 * @param intent The IntentSender to launch.
1353 * @param fillInIntent If non-null, this will be provided as the
1354 * intent parameter to {@link IntentSender#sendIntent}.
1355 * @param flagsMask Intent flags in the original IntentSender that you
1356 * would like to change.
1357 * @param flagsValues Desired values for any bits set in
1358 * <var>flagsMask</var>
1359 * @param extraFlags Always set to 0.
1360 * @param options Additional options for how the Activity should be started.
1361 * See {@link android.content.Context#startActivity(Intent, Bundle)
1362 * Context.startActivity(Intent, Bundle)} for more details. If options
1363 * have also been supplied by the IntentSender, options given here will
1364 * override any that conflict with those given by the IntentSender.
1366 * @see #startActivity(Intent, Bundle)
1367 * @see #startIntentSender(IntentSender, Intent, int, int, int)
1369 public abstract void startIntentSender(IntentSender intent,
1370 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1371 Bundle options) throws IntentSender.SendIntentException;
1374 * Broadcast the given intent to all interested BroadcastReceivers. This
1375 * call is asynchronous; it returns immediately, and you will continue
1376 * executing while the receivers are run. No results are propagated from
1377 * receivers and receivers can not abort the broadcast. If you want
1378 * to allow receivers to propagate results or abort the broadcast, you must
1379 * send an ordered broadcast using
1380 * {@link #sendOrderedBroadcast(Intent, String)}.
1382 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1384 * @param intent The Intent to broadcast; all receivers matching this
1385 * Intent will receive the broadcast.
1387 * @see android.content.BroadcastReceiver
1388 * @see #registerReceiver
1389 * @see #sendBroadcast(Intent, String)
1390 * @see #sendOrderedBroadcast(Intent, String)
1391 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1393 public abstract void sendBroadcast(Intent intent);
1396 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1397 * an optional required permission to be enforced. This
1398 * call is asynchronous; it returns immediately, and you will continue
1399 * executing while the receivers are run. No results are propagated from
1400 * receivers and receivers can not abort the broadcast. If you want
1401 * to allow receivers to propagate results or abort the broadcast, you must
1402 * send an ordered broadcast using
1403 * {@link #sendOrderedBroadcast(Intent, String)}.
1405 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1407 * @param intent The Intent to broadcast; all receivers matching this
1408 * Intent will receive the broadcast.
1409 * @param receiverPermission (optional) String naming a permission that
1410 * a receiver must hold in order to receive your broadcast.
1411 * If null, no permission is required.
1413 * @see android.content.BroadcastReceiver
1414 * @see #registerReceiver
1415 * @see #sendBroadcast(Intent)
1416 * @see #sendOrderedBroadcast(Intent, String)
1417 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1419 public abstract void sendBroadcast(Intent intent,
1420 @Nullable String receiverPermission);
1423 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
1424 * of an associated app op as per {@link android.app.AppOpsManager}.
1427 public abstract void sendBroadcast(Intent intent,
1428 String receiverPermission, int appOp);
1431 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1432 * them one at a time to allow more preferred receivers to consume the
1433 * broadcast before it is delivered to less preferred receivers. This
1434 * call is asynchronous; it returns immediately, and you will continue
1435 * executing while the receivers are run.
1437 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1439 * @param intent The Intent to broadcast; all receivers matching this
1440 * Intent will receive the broadcast.
1441 * @param receiverPermission (optional) String naming a permissions that
1442 * a receiver must hold in order to receive your broadcast.
1443 * If null, no permission is required.
1445 * @see android.content.BroadcastReceiver
1446 * @see #registerReceiver
1447 * @see #sendBroadcast(Intent)
1448 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1450 public abstract void sendOrderedBroadcast(Intent intent,
1451 @Nullable String receiverPermission);
1454 * Version of {@link #sendBroadcast(Intent)} that allows you to
1455 * receive data back from the broadcast. This is accomplished by
1456 * supplying your own BroadcastReceiver when calling, which will be
1457 * treated as a final receiver at the end of the broadcast -- its
1458 * {@link BroadcastReceiver#onReceive} method will be called with
1459 * the result values collected from the other receivers. The broadcast will
1460 * be serialized in the same way as calling
1461 * {@link #sendOrderedBroadcast(Intent, String)}.
1463 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1464 * asynchronous; it will return before
1465 * resultReceiver.onReceive() is called.
1467 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1469 * @param intent The Intent to broadcast; all receivers matching this
1470 * Intent will receive the broadcast.
1471 * @param receiverPermission String naming a permissions that
1472 * a receiver must hold in order to receive your broadcast.
1473 * If null, no permission is required.
1474 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1475 * receiver of the broadcast.
1476 * @param scheduler A custom Handler with which to schedule the
1477 * resultReceiver callback; if null it will be
1478 * scheduled in the Context's main thread.
1479 * @param initialCode An initial value for the result code. Often
1480 * Activity.RESULT_OK.
1481 * @param initialData An initial value for the result data. Often
1483 * @param initialExtras An initial value for the result extras. Often
1486 * @see #sendBroadcast(Intent)
1487 * @see #sendBroadcast(Intent, String)
1488 * @see #sendOrderedBroadcast(Intent, String)
1489 * @see android.content.BroadcastReceiver
1490 * @see #registerReceiver
1491 * @see android.app.Activity#RESULT_OK
1493 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1494 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1495 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1496 @Nullable Bundle initialExtras);
1499 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1500 * int, String, android.os.Bundle)}, but also allows specification
1501 * of an associated app op as per {@link android.app.AppOpsManager}.
1504 public abstract void sendOrderedBroadcast(Intent intent,
1505 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1506 Handler scheduler, int initialCode, String initialData,
1507 Bundle initialExtras);
1510 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1511 * user the broadcast will be sent to. This is not available to applications
1512 * that are not pre-installed on the system image. Using it requires holding
1513 * the INTERACT_ACROSS_USERS permission.
1514 * @param intent The intent to broadcast
1515 * @param user UserHandle to send the intent to.
1516 * @see #sendBroadcast(Intent)
1518 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
1521 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1522 * user the broadcast will be sent to. This is not available to applications
1523 * that are not pre-installed on the system image. Using it requires holding
1524 * the INTERACT_ACROSS_USERS permission.
1526 * @param intent The Intent to broadcast; all receivers matching this
1527 * Intent will receive the broadcast.
1528 * @param user UserHandle to send the intent to.
1529 * @param receiverPermission (optional) String naming a permission that
1530 * a receiver must hold in order to receive your broadcast.
1531 * If null, no permission is required.
1533 * @see #sendBroadcast(Intent, String)
1535 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1536 @Nullable String receiverPermission);
1540 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1541 * that allows you to specify the
1542 * user the broadcast will be sent to. This is not available to applications
1543 * that are not pre-installed on the system image. Using it requires holding
1544 * the INTERACT_ACROSS_USERS permission.
1546 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1548 * @param intent The Intent to broadcast; all receivers matching this
1549 * Intent will receive the broadcast.
1550 * @param user UserHandle to send the intent to.
1551 * @param receiverPermission String naming a permissions that
1552 * a receiver must hold in order to receive your broadcast.
1553 * If null, no permission is required.
1554 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1555 * receiver of the broadcast.
1556 * @param scheduler A custom Handler with which to schedule the
1557 * resultReceiver callback; if null it will be
1558 * scheduled in the Context's main thread.
1559 * @param initialCode An initial value for the result code. Often
1560 * Activity.RESULT_OK.
1561 * @param initialData An initial value for the result data. Often
1563 * @param initialExtras An initial value for the result extras. Often
1566 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1568 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1569 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1570 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1571 @Nullable Bundle initialExtras);
1574 * Similar to above but takes an appOp as well, to enforce restrictions.
1575 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1576 * BroadcastReceiver, Handler, int, String, Bundle)
1579 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1580 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1581 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1582 @Nullable Bundle initialExtras);
1585 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1586 * Intent you are sending stays around after the broadcast is complete,
1587 * so that others can quickly retrieve that data through the return
1588 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1589 * all other ways, this behaves the same as
1590 * {@link #sendBroadcast(Intent)}.
1592 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1593 * permission in order to use this API. If you do not hold that
1594 * permission, {@link SecurityException} will be thrown.
1596 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1597 * can access them), no protection (anyone can modify them), and many other problems.
1598 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1599 * has changed, with another mechanism for apps to retrieve the current value whenever
1602 * @param intent The Intent to broadcast; all receivers matching this
1603 * Intent will receive the broadcast, and the Intent will be held to
1604 * be re-broadcast to future receivers.
1606 * @see #sendBroadcast(Intent)
1607 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1610 public abstract void sendStickyBroadcast(Intent intent);
1613 * <p>Version of {@link #sendStickyBroadcast} that allows you to
1614 * receive data back from the broadcast. This is accomplished by
1615 * supplying your own BroadcastReceiver when calling, which will be
1616 * treated as a final receiver at the end of the broadcast -- its
1617 * {@link BroadcastReceiver#onReceive} method will be called with
1618 * the result values collected from the other receivers. The broadcast will
1619 * be serialized in the same way as calling
1620 * {@link #sendOrderedBroadcast(Intent, String)}.
1622 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1623 * asynchronous; it will return before
1624 * resultReceiver.onReceive() is called. Note that the sticky data
1625 * stored is only the data you initially supply to the broadcast, not
1626 * the result of any changes made by the receivers.
1628 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1630 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1631 * can access them), no protection (anyone can modify them), and many other problems.
1632 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1633 * has changed, with another mechanism for apps to retrieve the current value whenever
1636 * @param intent The Intent to broadcast; all receivers matching this
1637 * Intent will receive the broadcast.
1638 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1639 * receiver of the broadcast.
1640 * @param scheduler A custom Handler with which to schedule the
1641 * resultReceiver callback; if null it will be
1642 * scheduled in the Context's main thread.
1643 * @param initialCode An initial value for the result code. Often
1644 * Activity.RESULT_OK.
1645 * @param initialData An initial value for the result data. Often
1647 * @param initialExtras An initial value for the result extras. Often
1650 * @see #sendBroadcast(Intent)
1651 * @see #sendBroadcast(Intent, String)
1652 * @see #sendOrderedBroadcast(Intent, String)
1653 * @see #sendStickyBroadcast(Intent)
1654 * @see android.content.BroadcastReceiver
1655 * @see #registerReceiver
1656 * @see android.app.Activity#RESULT_OK
1659 public abstract void sendStickyOrderedBroadcast(Intent intent,
1660 BroadcastReceiver resultReceiver,
1661 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1662 @Nullable Bundle initialExtras);
1665 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
1666 * so that it is as if the sticky broadcast had never happened.
1668 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1669 * permission in order to use this API. If you do not hold that
1670 * permission, {@link SecurityException} will be thrown.
1672 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1673 * can access them), no protection (anyone can modify them), and many other problems.
1674 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1675 * has changed, with another mechanism for apps to retrieve the current value whenever
1678 * @param intent The Intent that was previously broadcast.
1680 * @see #sendStickyBroadcast
1683 public abstract void removeStickyBroadcast(Intent intent);
1686 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
1687 * user the broadcast will be sent to. This is not available to applications
1688 * that are not pre-installed on the system image. Using it requires holding
1689 * the INTERACT_ACROSS_USERS permission.
1691 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1692 * can access them), no protection (anyone can modify them), and many other problems.
1693 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1694 * has changed, with another mechanism for apps to retrieve the current value whenever
1697 * @param intent The Intent to broadcast; all receivers matching this
1698 * Intent will receive the broadcast, and the Intent will be held to
1699 * be re-broadcast to future receivers.
1700 * @param user UserHandle to send the intent to.
1702 * @see #sendBroadcast(Intent)
1705 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1709 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1710 * that allows you to specify the
1711 * user the broadcast will be sent to. This is not available to applications
1712 * that are not pre-installed on the system image. Using it requires holding
1713 * the INTERACT_ACROSS_USERS permission.
1715 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1717 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1718 * can access them), no protection (anyone can modify them), and many other problems.
1719 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1720 * has changed, with another mechanism for apps to retrieve the current value whenever
1723 * @param intent The Intent to broadcast; all receivers matching this
1724 * Intent will receive the broadcast.
1725 * @param user UserHandle to send the intent to.
1726 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1727 * receiver of the broadcast.
1728 * @param scheduler A custom Handler with which to schedule the
1729 * resultReceiver callback; if null it will be
1730 * scheduled in the Context's main thread.
1731 * @param initialCode An initial value for the result code. Often
1732 * Activity.RESULT_OK.
1733 * @param initialData An initial value for the result data. Often
1735 * @param initialExtras An initial value for the result extras. Often
1738 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1741 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1742 UserHandle user, BroadcastReceiver resultReceiver,
1743 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1744 @Nullable Bundle initialExtras);
1747 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
1748 * user the broadcast will be sent to. This is not available to applications
1749 * that are not pre-installed on the system image. Using it requires holding
1750 * the INTERACT_ACROSS_USERS permission.
1752 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1753 * permission in order to use this API. If you do not hold that
1754 * permission, {@link SecurityException} will be thrown.
1756 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1757 * can access them), no protection (anyone can modify them), and many other problems.
1758 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1759 * has changed, with another mechanism for apps to retrieve the current value whenever
1762 * @param intent The Intent that was previously broadcast.
1763 * @param user UserHandle to remove the sticky broadcast from.
1765 * @see #sendStickyBroadcastAsUser
1768 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1771 * Register a BroadcastReceiver to be run in the main activity thread. The
1772 * <var>receiver</var> will be called with any broadcast Intent that
1773 * matches <var>filter</var>, in the main application thread.
1775 * <p>The system may broadcast Intents that are "sticky" -- these stay
1776 * around after the broadcast as finished, to be sent to any later
1777 * registrations. If your IntentFilter matches one of these sticky
1778 * Intents, that Intent will be returned by this function
1779 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1782 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1783 * in which case each of these will be sent to <var>receiver</var>. In
1784 * this case, only one of these can be returned directly by the function;
1785 * which of these that is returned is arbitrarily decided by the system.
1787 * <p>If you know the Intent your are registering for is sticky, you can
1788 * supply null for your <var>receiver</var>. In this case, no receiver is
1789 * registered -- the function simply returns the sticky Intent that
1790 * matches <var>filter</var>. In the case of multiple matches, the same
1791 * rules as described above apply.
1793 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1795 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1796 * registered with this method will correctly respect the
1797 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1798 * Prior to that, it would be ignored and delivered to all matching registered
1799 * receivers. Be careful if using this for security.</p>
1801 * <p class="note">Note: this method <em>cannot be called from a
1802 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1803 * that is declared in an application's manifest. It is okay, however, to call
1804 * this method from another BroadcastReceiver that has itself been registered
1805 * at run time with {@link #registerReceiver}, since the lifetime of such a
1806 * registered BroadcastReceiver is tied to the object that registered it.</p>
1808 * @param receiver The BroadcastReceiver to handle the broadcast.
1809 * @param filter Selects the Intent broadcasts to be received.
1811 * @return The first sticky intent found that matches <var>filter</var>,
1812 * or null if there are none.
1814 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1815 * @see #sendBroadcast
1816 * @see #unregisterReceiver
1819 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
1820 IntentFilter filter);
1823 * Register to receive intent broadcasts, to run in the context of
1824 * <var>scheduler</var>. See
1825 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1826 * information. This allows you to enforce permissions on who can
1827 * broadcast intents to your receiver, or have the receiver run in
1828 * a different thread than the main application thread.
1830 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1832 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1833 * registered with this method will correctly respect the
1834 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1835 * Prior to that, it would be ignored and delivered to all matching registered
1836 * receivers. Be careful if using this for security.</p>
1838 * @param receiver The BroadcastReceiver to handle the broadcast.
1839 * @param filter Selects the Intent broadcasts to be received.
1840 * @param broadcastPermission String naming a permissions that a
1841 * broadcaster must hold in order to send an Intent to you. If null,
1842 * no permission is required.
1843 * @param scheduler Handler identifying the thread that will receive
1844 * the Intent. If null, the main thread of the process will be used.
1846 * @return The first sticky intent found that matches <var>filter</var>,
1847 * or null if there are none.
1849 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1850 * @see #sendBroadcast
1851 * @see #unregisterReceiver
1854 public abstract Intent registerReceiver(BroadcastReceiver receiver,
1855 IntentFilter filter, @Nullable String broadcastPermission,
1856 @Nullable Handler scheduler);
1860 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1861 * but for a specific user. This receiver will receiver broadcasts that
1862 * are sent to the requested user. It
1863 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1866 * @param receiver The BroadcastReceiver to handle the broadcast.
1867 * @param user UserHandle to send the intent to.
1868 * @param filter Selects the Intent broadcasts to be received.
1869 * @param broadcastPermission String naming a permissions that a
1870 * broadcaster must hold in order to send an Intent to you. If null,
1871 * no permission is required.
1872 * @param scheduler Handler identifying the thread that will receive
1873 * the Intent. If null, the main thread of the process will be used.
1875 * @return The first sticky intent found that matches <var>filter</var>,
1876 * or null if there are none.
1878 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1879 * @see #sendBroadcast
1880 * @see #unregisterReceiver
1883 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
1884 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1885 @Nullable Handler scheduler);
1888 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1889 * filters that have been registered for this BroadcastReceiver will be
1892 * @param receiver The BroadcastReceiver to unregister.
1894 * @see #registerReceiver
1896 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1899 * Request that a given application service be started. The Intent
1900 * should contain either contain the complete class name of a specific service
1901 * implementation to start or a specific package name to target. If the
1902 * Intent is less specified, it log a warning about this and which of the
1903 * multiple matching services it finds and uses will be undefined. If this service
1904 * is not already running, it will be instantiated and started (creating a
1905 * process for it if needed); if it is running then it remains running.
1907 * <p>Every call to this method will result in a corresponding call to
1908 * the target service's {@link android.app.Service#onStartCommand} method,
1909 * with the <var>intent</var> given here. This provides a convenient way
1910 * to submit jobs to a service without having to bind and call on to its
1913 * <p>Using startService() overrides the default service lifetime that is
1914 * managed by {@link #bindService}: it requires the service to remain
1915 * running until {@link #stopService} is called, regardless of whether
1916 * any clients are connected to it. Note that calls to startService()
1917 * are not nesting: no matter how many times you call startService(),
1918 * a single call to {@link #stopService} will stop it.
1920 * <p>The system attempts to keep running services around as much as
1921 * possible. The only time they should be stopped is if the current
1922 * foreground application is using so many resources that the service needs
1923 * to be killed. If any errors happen in the service's process, it will
1924 * automatically be restarted.
1926 * <p>This function will throw {@link SecurityException} if you do not
1927 * have permission to start the given service.
1929 * @param service Identifies the service to be started. The Intent must be either
1930 * fully explicit (supplying a component name) or specify a specific package
1931 * name it is targetted to. Additional values
1932 * may be included in the Intent extras to supply arguments along with
1933 * this specific start call.
1935 * @return If the service is being started or is already running, the
1936 * {@link ComponentName} of the actual service that was started is
1937 * returned; else if the service does not exist null is returned.
1939 * @throws SecurityException
1945 public abstract ComponentName startService(Intent service);
1948 * Request that a given application service be stopped. If the service is
1949 * not running, nothing happens. Otherwise it is stopped. Note that calls
1950 * to startService() are not counted -- this stops the service no matter
1951 * how many times it was started.
1953 * <p>Note that if a stopped service still has {@link ServiceConnection}
1954 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1955 * not be destroyed until all of these bindings are removed. See
1956 * the {@link android.app.Service} documentation for more details on a
1957 * service's lifecycle.
1959 * <p>This function will throw {@link SecurityException} if you do not
1960 * have permission to stop the given service.
1962 * @param service Description of the service to be stopped. The Intent must be either
1963 * fully explicit (supplying a component name) or specify a specific package
1964 * name it is targetted to.
1966 * @return If there is a service matching the given Intent that is already
1967 * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
1969 * @throws SecurityException
1971 * @see #startService
1973 public abstract boolean stopService(Intent service);
1976 * @hide like {@link #startService(Intent)} but for a specific user.
1978 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1981 * @hide like {@link #stopService(Intent)} but for a specific user.
1983 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
1986 * Connect to an application service, creating it if needed. This defines
1987 * a dependency between your application and the service. The given
1988 * <var>conn</var> will receive the service object when it is created and be
1989 * told if it dies and restarts. The service will be considered required
1990 * by the system only for as long as the calling context exists. For
1991 * example, if this Context is an Activity that is stopped, the service will
1992 * not be required to continue running until the Activity is resumed.
1994 * <p>This function will throw {@link SecurityException} if you do not
1995 * have permission to bind to the given service.
1997 * <p class="note">Note: this method <em>can not be called from a
1998 * {@link BroadcastReceiver} component</em>. A pattern you can use to
1999 * communicate from a BroadcastReceiver to a Service is to call
2000 * {@link #startService} with the arguments containing the command to be
2001 * sent, with the service calling its
2002 * {@link android.app.Service#stopSelf(int)} method when done executing
2003 * that command. See the API demo App/Service/Service Start Arguments
2004 * Controller for an illustration of this. It is okay, however, to use
2005 * this method from a BroadcastReceiver that has been registered with
2006 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2007 * is tied to another object (the one that registered it).</p>
2009 * @param service Identifies the service to connect to. The Intent may
2010 * specify either an explicit component name, or a logical
2011 * description (action, category, etc) to match an
2012 * {@link IntentFilter} published by a service.
2013 * @param conn Receives information as the service is started and stopped.
2014 * This must be a valid ServiceConnection object; it must not be null.
2015 * @param flags Operation options for the binding. May be 0,
2016 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2017 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2018 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2019 * {@link #BIND_WAIVE_PRIORITY}.
2020 * @return If you have successfully bound to the service, {@code true} is returned;
2021 * {@code false} is returned if the connection is not made so you will not
2022 * receive the service object.
2024 * @throws SecurityException
2026 * @see #unbindService
2027 * @see #startService
2028 * @see #BIND_AUTO_CREATE
2029 * @see #BIND_DEBUG_UNBIND
2030 * @see #BIND_NOT_FOREGROUND
2032 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
2033 @BindServiceFlags int flags);
2036 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
2037 * argument for use by system server and other multi-user aware code.
2041 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
2042 throw new RuntimeException("Not implemented. Must override in a subclass.");
2046 * Disconnect from an application service. You will no longer receive
2047 * calls as the service is restarted, and the service is now allowed to
2050 * @param conn The connection interface previously supplied to
2051 * bindService(). This parameter must not be null.
2055 public abstract void unbindService(@NonNull ServiceConnection conn);
2058 * Start executing an {@link android.app.Instrumentation} class. The given
2059 * Instrumentation component will be run by killing its target application
2060 * (if currently running), starting the target process, instantiating the
2061 * instrumentation component, and then letting it drive the application.
2063 * <p>This function is not synchronous -- it returns as soon as the
2064 * instrumentation has started and while it is running.
2066 * <p>Instrumentation is normally only allowed to run against a package
2067 * that is either unsigned or signed with a signature that the
2068 * the instrumentation package is also signed with (ensuring the target
2069 * trusts the instrumentation).
2071 * @param className Name of the Instrumentation component to be run.
2072 * @param profileFile Optional path to write profiling data as the
2073 * instrumentation runs, or null for no profiling.
2074 * @param arguments Additional optional arguments to pass to the
2075 * instrumentation, or null.
2077 * @return {@code true} if the instrumentation was successfully started,
2078 * else {@code false} if it could not be found.
2080 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2081 @Nullable String profileFile, @Nullable Bundle arguments);
2087 LAYOUT_INFLATER_SERVICE,
2091 NOTIFICATION_SERVICE,
2092 ACCESSIBILITY_SERVICE,
2096 //@hide: COUNTRY_DETECTOR,
2102 //@hide: STATUS_BAR_SERVICE,
2103 CONNECTIVITY_SERVICE,
2104 //@hide: UPDATE_LOCK_SERVICE,
2105 //@hide: NETWORKMANAGEMENT_SERVICE,
2106 //@hide: NETWORK_STATS_SERVICE,
2107 //@hide: NETWORK_POLICY_SERVICE,
2109 WIFI_PASSPOINT_SERVICE,
2111 WIFI_SCANNING_SERVICE,
2112 //@hide: ETHERNET_SERVICE,
2116 MEDIA_ROUTER_SERVICE,
2120 INPUT_METHOD_SERVICE,
2121 TEXT_SERVICES_MANAGER_SERVICE,
2123 //@hide: BACKUP_SERVICE,
2125 DEVICE_POLICY_SERVICE,
2130 //@hide: SIP_SERVICE,
2132 LAUNCHER_APPS_SERVICE,
2133 //@hide: SERIAL_SERVICE,
2136 //@hide: SCHEDULING_POLICY_SERVICE,
2138 //@hide: APP_OPS_SERVICE
2141 MEDIA_SESSION_SERVICE,
2143 JOB_SCHEDULER_SERVICE,
2145 @Retention(RetentionPolicy.SOURCE)
2146 public @interface ServiceName {}
2149 * Return the handle to a system-level service by name. The class of the
2150 * returned object varies by the requested name. Currently available names
2154 * <dt> {@link #WINDOW_SERVICE} ("window")
2155 * <dd> The top-level window manager in which you can place custom
2156 * windows. The returned object is a {@link android.view.WindowManager}.
2157 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2158 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2160 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2161 * <dd> A {@link android.app.ActivityManager} for interacting with the
2162 * global activity state of the system.
2163 * <dt> {@link #POWER_SERVICE} ("power")
2164 * <dd> A {@link android.os.PowerManager} for controlling power
2166 * <dt> {@link #ALARM_SERVICE} ("alarm")
2167 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2168 * time of your choosing.
2169 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2170 * <dd> A {@link android.app.NotificationManager} for informing the user
2171 * of background events.
2172 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2173 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2174 * <dt> {@link #LOCATION_SERVICE} ("location")
2175 * <dd> A {@link android.location.LocationManager} for controlling location
2176 * (e.g., GPS) updates.
2177 * <dt> {@link #SEARCH_SERVICE} ("search")
2178 * <dd> A {@link android.app.SearchManager} for handling search.
2179 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2180 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2182 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2183 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2184 * handling management of network connections.
2185 * <dt> {@link #WIFI_SERVICE} ("wifi")
2186 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2187 * Wi-Fi connectivity.
2188 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2189 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2190 * Wi-Fi Direct connectivity.
2191 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2192 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2193 * for management of input methods.
2194 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2195 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
2196 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
2197 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
2198 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
2199 * <dd> A {@link android.os.BatteryManager} for managing battery state
2200 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2201 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
2204 * <p>Note: System services obtained via this API may be closely associated with
2205 * the Context in which they are obtained from. In general, do not share the
2206 * service objects between various different contexts (Activities, Applications,
2207 * Services, Providers, etc.)
2209 * @param name The name of the desired service.
2211 * @return The service or null if the name does not exist.
2213 * @see #WINDOW_SERVICE
2214 * @see android.view.WindowManager
2215 * @see #LAYOUT_INFLATER_SERVICE
2216 * @see android.view.LayoutInflater
2217 * @see #ACTIVITY_SERVICE
2218 * @see android.app.ActivityManager
2219 * @see #POWER_SERVICE
2220 * @see android.os.PowerManager
2221 * @see #ALARM_SERVICE
2222 * @see android.app.AlarmManager
2223 * @see #NOTIFICATION_SERVICE
2224 * @see android.app.NotificationManager
2225 * @see #KEYGUARD_SERVICE
2226 * @see android.app.KeyguardManager
2227 * @see #LOCATION_SERVICE
2228 * @see android.location.LocationManager
2229 * @see #SEARCH_SERVICE
2230 * @see android.app.SearchManager
2231 * @see #SENSOR_SERVICE
2232 * @see android.hardware.SensorManager
2233 * @see #STORAGE_SERVICE
2234 * @see android.os.storage.StorageManager
2235 * @see #VIBRATOR_SERVICE
2236 * @see android.os.Vibrator
2237 * @see #CONNECTIVITY_SERVICE
2238 * @see android.net.ConnectivityManager
2239 * @see #WIFI_SERVICE
2240 * @see android.net.wifi.WifiManager
2241 * @see #AUDIO_SERVICE
2242 * @see android.media.AudioManager
2243 * @see #MEDIA_ROUTER_SERVICE
2244 * @see android.media.MediaRouter
2245 * @see #TELEPHONY_SERVICE
2246 * @see android.telephony.TelephonyManager
2247 * @see #INPUT_METHOD_SERVICE
2248 * @see android.view.inputmethod.InputMethodManager
2249 * @see #UI_MODE_SERVICE
2250 * @see android.app.UiModeManager
2251 * @see #DOWNLOAD_SERVICE
2252 * @see android.app.DownloadManager
2253 * @see #BATTERY_SERVICE
2254 * @see android.os.BatteryManager
2255 * @see #JOB_SCHEDULER_SERVICE
2256 * @see android.app.job.JobScheduler
2258 public abstract Object getSystemService(@ServiceName @NonNull String name);
2261 * Use with {@link #getSystemService} to retrieve a
2262 * {@link android.os.PowerManager} for controlling power management,
2263 * including "wake locks," which let you keep the device on while
2264 * you're running long tasks.
2266 public static final String POWER_SERVICE = "power";
2269 * Use with {@link #getSystemService} to retrieve a
2270 * {@link android.view.WindowManager} for accessing the system's window
2273 * @see #getSystemService
2274 * @see android.view.WindowManager
2276 public static final String WINDOW_SERVICE = "window";
2279 * Use with {@link #getSystemService} to retrieve a
2280 * {@link android.view.LayoutInflater} for inflating layout resources in this
2283 * @see #getSystemService
2284 * @see android.view.LayoutInflater
2286 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
2289 * Use with {@link #getSystemService} to retrieve a
2290 * {@link android.accounts.AccountManager} for receiving intents at a
2291 * time of your choosing.
2293 * @see #getSystemService
2294 * @see android.accounts.AccountManager
2296 public static final String ACCOUNT_SERVICE = "account";
2299 * Use with {@link #getSystemService} to retrieve a
2300 * {@link android.app.ActivityManager} for interacting with the global
2303 * @see #getSystemService
2304 * @see android.app.ActivityManager
2306 public static final String ACTIVITY_SERVICE = "activity";
2309 * Use with {@link #getSystemService} to retrieve a
2310 * {@link android.app.AlarmManager} for receiving intents at a
2311 * time of your choosing.
2313 * @see #getSystemService
2314 * @see android.app.AlarmManager
2316 public static final String ALARM_SERVICE = "alarm";
2319 * Use with {@link #getSystemService} to retrieve a
2320 * {@link android.app.NotificationManager} for informing the user of
2321 * background events.
2323 * @see #getSystemService
2324 * @see android.app.NotificationManager
2326 public static final String NOTIFICATION_SERVICE = "notification";
2329 * Use with {@link #getSystemService} to retrieve a
2330 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2331 * feedback for UI events through the registered event listeners.
2333 * @see #getSystemService
2334 * @see android.view.accessibility.AccessibilityManager
2336 public static final String ACCESSIBILITY_SERVICE = "accessibility";
2339 * Use with {@link #getSystemService} to retrieve a
2340 * {@link android.view.accessibility.CaptioningManager} for obtaining
2341 * captioning properties and listening for changes in captioning
2344 * @see #getSystemService
2345 * @see android.view.accessibility.CaptioningManager
2347 public static final String CAPTIONING_SERVICE = "captioning";
2350 * Use with {@link #getSystemService} to retrieve a
2351 * {@link android.app.NotificationManager} for controlling keyguard.
2353 * @see #getSystemService
2354 * @see android.app.KeyguardManager
2356 public static final String KEYGUARD_SERVICE = "keyguard";
2359 * Use with {@link #getSystemService} to retrieve a {@link
2360 * android.location.LocationManager} for controlling location
2363 * @see #getSystemService
2364 * @see android.location.LocationManager
2366 public static final String LOCATION_SERVICE = "location";
2369 * Use with {@link #getSystemService} to retrieve a
2370 * {@link android.location.CountryDetector} for detecting the country that
2375 public static final String COUNTRY_DETECTOR = "country_detector";
2378 * Use with {@link #getSystemService} to retrieve a {@link
2379 * android.app.SearchManager} for handling searches.
2381 * @see #getSystemService
2382 * @see android.app.SearchManager
2384 public static final String SEARCH_SERVICE = "search";
2387 * Use with {@link #getSystemService} to retrieve a {@link
2388 * android.hardware.SensorManager} for accessing sensors.
2390 * @see #getSystemService
2391 * @see android.hardware.SensorManager
2393 public static final String SENSOR_SERVICE = "sensor";
2396 * Use with {@link #getSystemService} to retrieve a {@link
2397 * android.os.storage.StorageManager} for accessing system storage
2400 * @see #getSystemService
2401 * @see android.os.storage.StorageManager
2403 public static final String STORAGE_SERVICE = "storage";
2406 * Use with {@link #getSystemService} to retrieve a
2407 * com.android.server.WallpaperService for accessing wallpapers.
2409 * @see #getSystemService
2411 public static final String WALLPAPER_SERVICE = "wallpaper";
2414 * Use with {@link #getSystemService} to retrieve a {@link
2415 * android.os.Vibrator} for interacting with the vibration hardware.
2417 * @see #getSystemService
2418 * @see android.os.Vibrator
2420 public static final String VIBRATOR_SERVICE = "vibrator";
2423 * Use with {@link #getSystemService} to retrieve a {@link
2424 * android.app.StatusBarManager} for interacting with the status bar.
2426 * @see #getSystemService
2427 * @see android.app.StatusBarManager
2430 public static final String STATUS_BAR_SERVICE = "statusbar";
2433 * Use with {@link #getSystemService} to retrieve a {@link
2434 * android.net.ConnectivityManager} for handling management of
2435 * network connections.
2437 * @see #getSystemService
2438 * @see android.net.ConnectivityManager
2440 public static final String CONNECTIVITY_SERVICE = "connectivity";
2443 * Use with {@link #getSystemService} to retrieve a {@link
2444 * android.os.IUpdateLock} for managing runtime sequences that
2445 * must not be interrupted by headless OTA application or similar.
2448 * @see #getSystemService
2449 * @see android.os.UpdateLock
2451 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2454 * Constant for the internal network management service, not really a Context service.
2457 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2460 public static final String NETWORK_STATS_SERVICE = "netstats";
2462 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2465 * Use with {@link #getSystemService} to retrieve a {@link
2466 * android.net.wifi.WifiManager} for handling management of
2469 * @see #getSystemService
2470 * @see android.net.wifi.WifiManager
2472 public static final String WIFI_SERVICE = "wifi";
2475 * Use with {@link #getSystemService} to retrieve a {@link
2476 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
2477 * Wi-Fi passpoint access.
2479 * @see #getSystemService
2480 * @see android.net.wifi.passpoint.WifiPasspointManager
2483 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
2486 * Use with {@link #getSystemService} to retrieve a {@link
2487 * android.net.wifi.p2p.WifiP2pManager} for handling management of
2488 * Wi-Fi peer-to-peer connections.
2490 * @see #getSystemService
2491 * @see android.net.wifi.p2p.WifiP2pManager
2493 public static final String WIFI_P2P_SERVICE = "wifip2p";
2496 * Use with {@link #getSystemService} to retrieve a {@link
2497 * android.net.wifi.WifiScanner} for scanning the wifi universe
2499 * @see #getSystemService
2500 * @see android.net.wifi.WifiScanner
2504 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2507 * Use with {@link #getSystemService} to retrieve a {@link
2508 * android.net.wifi.RttManager} for ranging devices with wifi
2510 * @see #getSystemService
2511 * @see android.net.wifi.RttManager
2515 public static final String WIFI_RTT_SERVICE = "rttmanager";
2518 * Use with {@link #getSystemService} to retrieve a {@link
2519 * android.net.EthernetManager} for handling management of
2522 * @see #getSystemService
2523 * @see android.net.EthernetManager
2527 public static final String ETHERNET_SERVICE = "ethernet";
2530 * Use with {@link #getSystemService} to retrieve a {@link
2531 * android.net.nsd.NsdManager} for handling management of network service
2534 * @see #getSystemService
2535 * @see android.net.nsd.NsdManager
2537 public static final String NSD_SERVICE = "servicediscovery";
2540 * Use with {@link #getSystemService} to retrieve a
2541 * {@link android.media.AudioManager} for handling management of volume,
2542 * ringer modes and audio routing.
2544 * @see #getSystemService
2545 * @see android.media.AudioManager
2547 public static final String AUDIO_SERVICE = "audio";
2550 * Use with {@link #getSystemService} to retrieve a
2551 * {@link android.service.fingerprint.FingerprintManager} for handling management
2554 * @see #getSystemService
2555 * @see android.app.FingerprintManager
2558 public static final String FINGERPRINT_SERVICE = "fingerprint";
2561 * Use with {@link #getSystemService} to retrieve a
2562 * {@link android.media.MediaRouter} for controlling and managing
2565 * @see #getSystemService
2566 * @see android.media.MediaRouter
2568 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2571 * Use with {@link #getSystemService} to retrieve a
2572 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
2574 * @see #getSystemService
2575 * @see android.media.session.MediaSessionManager
2577 public static final String MEDIA_SESSION_SERVICE = "media_session";
2580 * Use with {@link #getSystemService} to retrieve a
2581 * {@link android.telephony.TelephonyManager} for handling management the
2582 * telephony features of the device.
2584 * @see #getSystemService
2585 * @see android.telephony.TelephonyManager
2587 public static final String TELEPHONY_SERVICE = "phone";
2590 * Use with {@link #getSystemService} to retrieve a
2591 * {@link android.telecom.TelecomManager} to manage telecom-related features
2594 * @see #getSystemService
2595 * @see android.telecom.TelecomManager
2597 public static final String TELECOM_SERVICE = "telecom";
2600 * Use with {@link #getSystemService} to retrieve a
2601 * {@link android.text.ClipboardManager} for accessing and modifying
2602 * the contents of the global clipboard.
2604 * @see #getSystemService
2605 * @see android.text.ClipboardManager
2607 public static final String CLIPBOARD_SERVICE = "clipboard";
2610 * Use with {@link #getSystemService} to retrieve a
2611 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2614 * @see #getSystemService
2616 public static final String INPUT_METHOD_SERVICE = "input_method";
2619 * Use with {@link #getSystemService} to retrieve a
2620 * {@link android.view.textservice.TextServicesManager} for accessing
2623 * @see #getSystemService
2625 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2628 * Use with {@link #getSystemService} to retrieve a
2629 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
2631 * @see #getSystemService
2633 public static final String APPWIDGET_SERVICE = "appwidget";
2636 * Official published name of the (internal) voice interaction manager service.
2639 * @see #getSystemService
2641 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2644 * Use with {@link #getSystemService} to retrieve an
2645 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
2646 * with the backup mechanism.
2649 * @see #getSystemService
2652 public static final String BACKUP_SERVICE = "backup";
2655 * Use with {@link #getSystemService} to retrieve a
2656 * {@link android.os.DropBoxManager} instance for recording
2658 * @see #getSystemService
2660 public static final String DROPBOX_SERVICE = "dropbox";
2663 * Use with {@link #getSystemService} to retrieve a
2664 * {@link android.app.admin.DevicePolicyManager} for working with global
2665 * device policy management.
2667 * @see #getSystemService
2669 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2672 * Use with {@link #getSystemService} to retrieve a
2673 * {@link android.app.UiModeManager} for controlling UI modes.
2675 * @see #getSystemService
2677 public static final String UI_MODE_SERVICE = "uimode";
2680 * Use with {@link #getSystemService} to retrieve a
2681 * {@link android.app.DownloadManager} for requesting HTTP downloads.
2683 * @see #getSystemService
2685 public static final String DOWNLOAD_SERVICE = "download";
2688 * Use with {@link #getSystemService} to retrieve a
2689 * {@link android.os.BatteryManager} for managing battery state.
2691 * @see #getSystemService
2693 public static final String BATTERY_SERVICE = "batterymanager";
2696 * Use with {@link #getSystemService} to retrieve a
2697 * {@link android.nfc.NfcManager} for using NFC.
2699 * @see #getSystemService
2701 public static final String NFC_SERVICE = "nfc";
2704 * Use with {@link #getSystemService} to retrieve a
2705 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2707 * @see #getSystemService
2709 public static final String BLUETOOTH_SERVICE = "bluetooth";
2712 * Use with {@link #getSystemService} to retrieve a
2713 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2715 * @see #getSystemService
2718 public static final String SIP_SERVICE = "sip";
2721 * Use with {@link #getSystemService} to retrieve a {@link
2722 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
2723 * and for controlling this device's behavior as a USB device.
2725 * @see #getSystemService
2726 * @see android.hardware.usb.UsbManager
2728 public static final String USB_SERVICE = "usb";
2731 * Use with {@link #getSystemService} to retrieve a {@link
2732 * android.hardware.SerialManager} for access to serial ports.
2734 * @see #getSystemService
2735 * @see android.hardware.SerialManager
2739 public static final String SERIAL_SERVICE = "serial";
2742 * Use with {@link #getSystemService} to retrieve a
2743 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2744 * HDMI-CEC protocol.
2746 * @see #getSystemService
2747 * @see android.hardware.hdmi.HdmiControlManager
2751 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
2754 * Use with {@link #getSystemService} to retrieve a
2755 * {@link android.hardware.input.InputManager} for interacting with input devices.
2757 * @see #getSystemService
2758 * @see android.hardware.input.InputManager
2760 public static final String INPUT_SERVICE = "input";
2763 * Use with {@link #getSystemService} to retrieve a
2764 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2766 * @see #getSystemService
2767 * @see android.hardware.display.DisplayManager
2769 public static final String DISPLAY_SERVICE = "display";
2772 * Use with {@link #getSystemService} to retrieve a
2773 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2775 * @see #getSystemService
2776 * @see android.os.UserManager
2778 public static final String USER_SERVICE = "user";
2781 * Use with {@link #getSystemService} to retrieve a
2782 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
2783 * profiles of a user.
2785 * @see #getSystemService
2786 * @see android.content.pm.LauncherApps
2788 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
2791 * Use with {@link #getSystemService} to retrieve a
2792 * {@link android.content.RestrictionsManager} for retrieving application restrictions
2793 * and requesting permissions for restricted operations.
2794 * @see #getSystemService
2795 * @see android.content.RestrictionsManager
2797 public static final String RESTRICTIONS_SERVICE = "restrictions";
2800 * Use with {@link #getSystemService} to retrieve a
2801 * {@link android.app.AppOpsManager} for tracking application operations
2804 * @see #getSystemService
2805 * @see android.app.AppOpsManager
2807 public static final String APP_OPS_SERVICE = "appops";
2810 * Use with {@link #getSystemService} to retrieve a
2811 * {@link android.hardware.camera2.CameraManager} for interacting with
2814 * @see #getSystemService
2815 * @see android.hardware.camera2.CameraManager
2817 public static final String CAMERA_SERVICE = "camera";
2820 * {@link android.print.PrintManager} for printing and managing
2821 * printers and print tasks.
2823 * @see #getSystemService
2824 * @see android.print.PrintManager
2826 public static final String PRINT_SERVICE = "print";
2829 * Use with {@link #getSystemService} to retrieve a
2830 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
2831 * signals from the device.
2833 * @see #getSystemService
2834 * @see android.hardware.ConsumerIrManager
2836 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
2839 * {@link android.app.trust.TrustManager} for managing trust agents.
2840 * @see #getSystemService
2841 * @see android.app.trust.TrustManager
2844 public static final String TRUST_SERVICE = "trust";
2847 * Use with {@link #getSystemService} to retrieve a
2848 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
2851 * @see #getSystemService
2852 * @see android.media.tv.TvInputManager
2854 public static final String TV_INPUT_SERVICE = "tv_input";
2857 * {@link android.net.NetworkScoreManager} for managing network scoring.
2858 * @see #getSystemService
2859 * @see android.net.NetworkScoreManager
2863 public static final String NETWORK_SCORE_SERVICE = "network_score";
2866 * Use with {@link #getSystemService} to retrieve a {@link
2867 * android.app.UsageStatsManager} for interacting with the status bar.
2869 * @see #getSystemService
2870 * @see android.app.UsageStatsManager
2873 public static final String USAGE_STATS_SERVICE = "usagestats";
2876 * Use with {@link #getSystemService} to retrieve a {@link
2877 * android.app.job.JobScheduler} instance for managing occasional
2879 * @see #getSystemService
2880 * @see android.app.job.JobScheduler
2882 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
2885 * Use with {@link #getSystemService} to retrieve a {@link
2886 * android.service.persistentdata.PersistentDataBlockManager} instance
2887 * for interacting with a storage device that lives across factory resets.
2889 * @see #getSystemService
2890 * @see android.service.persistentdata.PersistentDataBlockManager
2894 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
2897 * Use with {@link #getSystemService} to retrieve a {@link
2898 * android.media.projection.MediaProjectionManager} instance for managing
2899 * media projection sessions.
2900 * @see #getSystemService
2901 * @see android.media.projection.ProjectionManager
2903 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
2906 * Determine whether the given permission is allowed for a particular
2907 * process and user ID running in the system.
2909 * @param permission The name of the permission being checked.
2910 * @param pid The process ID being checked against. Must be > 0.
2911 * @param uid The user ID being checked against. A uid of 0 is the root
2912 * user, which will pass every permission check.
2914 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
2915 * pid/uid is allowed that permission, or
2916 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2918 * @see PackageManager#checkPermission(String, String)
2919 * @see #checkCallingPermission
2921 @PackageManager.PermissionResult
2922 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
2925 * Determine whether the calling process of an IPC you are handling has been
2926 * granted a particular permission. This is basically the same as calling
2927 * {@link #checkPermission(String, int, int)} with the pid and uid returned
2928 * by {@link android.os.Binder#getCallingPid} and
2929 * {@link android.os.Binder#getCallingUid}. One important difference
2930 * is that if you are not currently processing an IPC, this function
2931 * will always fail. This is done to protect against accidentally
2932 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2933 * to avoid this protection.
2935 * @param permission The name of the permission being checked.
2937 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
2938 * pid/uid is allowed that permission, or
2939 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2941 * @see PackageManager#checkPermission(String, String)
2942 * @see #checkPermission
2943 * @see #checkCallingOrSelfPermission
2945 @PackageManager.PermissionResult
2946 public abstract int checkCallingPermission(@NonNull String permission);
2949 * Determine whether the calling process of an IPC <em>or you</em> have been
2950 * granted a particular permission. This is the same as
2951 * {@link #checkCallingPermission}, except it grants your own permissions
2952 * if you are not currently processing an IPC. Use with care!
2954 * @param permission The name of the permission being checked.
2956 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
2957 * pid/uid is allowed that permission, or
2958 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2960 * @see PackageManager#checkPermission(String, String)
2961 * @see #checkPermission
2962 * @see #checkCallingPermission
2964 @PackageManager.PermissionResult
2965 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
2968 * If the given permission is not allowed for a particular process
2969 * and user ID running in the system, throw a {@link SecurityException}.
2971 * @param permission The name of the permission being checked.
2972 * @param pid The process ID being checked against. Must be > 0.
2973 * @param uid The user ID being checked against. A uid of 0 is the root
2974 * user, which will pass every permission check.
2975 * @param message A message to include in the exception if it is thrown.
2977 * @see #checkPermission(String, int, int)
2979 public abstract void enforcePermission(
2980 @NonNull String permission, int pid, int uid, @Nullable String message);
2983 * If the calling process of an IPC you are handling has not been
2984 * granted a particular permission, throw a {@link
2985 * SecurityException}. This is basically the same as calling
2986 * {@link #enforcePermission(String, int, int, String)} with the
2987 * pid and uid returned by {@link android.os.Binder#getCallingPid}
2988 * and {@link android.os.Binder#getCallingUid}. One important
2989 * difference is that if you are not currently processing an IPC,
2990 * this function will always throw the SecurityException. This is
2991 * done to protect against accidentally leaking permissions; you
2992 * can use {@link #enforceCallingOrSelfPermission} to avoid this
2995 * @param permission The name of the permission being checked.
2996 * @param message A message to include in the exception if it is thrown.
2998 * @see #checkCallingPermission(String)
3000 public abstract void enforceCallingPermission(
3001 @NonNull String permission, @Nullable String message);
3004 * If neither you nor the calling process of an IPC you are
3005 * handling has been granted a particular permission, throw a
3006 * {@link SecurityException}. This is the same as {@link
3007 * #enforceCallingPermission}, except it grants your own
3008 * permissions if you are not currently processing an IPC. Use
3011 * @param permission The name of the permission being checked.
3012 * @param message A message to include in the exception if it is thrown.
3014 * @see #checkCallingOrSelfPermission(String)
3016 public abstract void enforceCallingOrSelfPermission(
3017 @NonNull String permission, @Nullable String message);
3020 * Grant permission to access a specific Uri to another package, regardless
3021 * of whether that package has general permission to access the Uri's
3022 * content provider. This can be used to grant specific, temporary
3023 * permissions, typically in response to user interaction (such as the
3024 * user opening an attachment that you would like someone else to
3027 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3028 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3029 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3030 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3031 * start an activity instead of this function directly. If you use this
3032 * function directly, you should be sure to call
3033 * {@link #revokeUriPermission} when the target should no longer be allowed
3036 * <p>To succeed, the content provider owning the Uri must have set the
3037 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3038 * grantUriPermissions} attribute in its manifest or included the
3039 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3040 * <grant-uri-permissions>} tag.
3042 * @param toPackage The package you would like to allow to access the Uri.
3043 * @param uri The Uri you would like to grant access to.
3044 * @param modeFlags The desired access modes. Any combination of
3045 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3046 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
3047 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3048 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3049 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3050 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3051 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3052 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
3054 * @see #revokeUriPermission
3056 public abstract void grantUriPermission(String toPackage, Uri uri,
3057 @Intent.GrantUriMode int modeFlags);
3060 * Remove all permissions to access a particular content provider Uri
3061 * that were previously added with {@link #grantUriPermission}. The given
3062 * Uri will match all previously granted Uris that are the same or a
3063 * sub-path of the given Uri. That is, revoking "content://foo/target" will
3064 * revoke both "content://foo/target" and "content://foo/target/sub", but not
3065 * "content://foo". It will not remove any prefix grants that exist at a
3068 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
3069 * regular permission access to a Uri, but had received access to it through
3070 * a specific Uri permission grant, you could not revoke that grant with this
3071 * function and a {@link SecurityException} would be thrown. As of
3072 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
3073 * but will remove whatever permission grants to the Uri had been given to the app
3076 * @param uri The Uri you would like to revoke access to.
3077 * @param modeFlags The desired access modes. Any combination of
3078 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3079 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3080 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3081 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3083 * @see #grantUriPermission
3085 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
3088 * Determine whether a particular process and user ID has been granted
3089 * permission to access a specific URI. This only checks for permissions
3090 * that have been explicitly granted -- if the given process/uid has
3091 * more general access to the URI's content provider then this check will
3094 * @param uri The uri that is being checked.
3095 * @param pid The process ID being checked against. Must be > 0.
3096 * @param uid The user ID being checked against. A uid of 0 is the root
3097 * user, which will pass every permission check.
3098 * @param modeFlags The type of access to grant. May be one or both of
3099 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3100 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3102 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
3103 * pid/uid is allowed to access that uri, or
3104 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3106 * @see #checkCallingUriPermission
3108 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3109 @Intent.AccessUriMode int modeFlags);
3112 * Determine whether the calling process and user ID has been
3113 * granted permission to access a specific URI. This is basically
3114 * the same as calling {@link #checkUriPermission(Uri, int, int,
3115 * int)} with the pid and uid returned by {@link
3116 * android.os.Binder#getCallingPid} and {@link
3117 * android.os.Binder#getCallingUid}. One important difference is
3118 * that if you are not currently processing an IPC, this function
3121 * @param uri The uri that is being checked.
3122 * @param modeFlags The type of access to grant. May be one or both of
3123 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3124 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3126 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
3127 * is allowed to access that uri, or
3128 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3130 * @see #checkUriPermission(Uri, int, int, int)
3132 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
3135 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3136 * permission to access a specific URI. This is the same as
3137 * {@link #checkCallingUriPermission}, except it grants your own permissions
3138 * if you are not currently processing an IPC. Use with care!
3140 * @param uri The uri that is being checked.
3141 * @param modeFlags The type of access to grant. May be one or both of
3142 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3143 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3145 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
3146 * is allowed to access that uri, or
3147 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3149 * @see #checkCallingUriPermission
3151 public abstract int checkCallingOrSelfUriPermission(Uri uri,
3152 @Intent.AccessUriMode int modeFlags);
3155 * Check both a Uri and normal permission. This allows you to perform
3156 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3159 * @param uri The Uri whose permission is to be checked, or null to not
3161 * @param readPermission The permission that provides overall read access,
3162 * or null to not do this check.
3163 * @param writePermission The permission that provides overall write
3164 * access, or null to not do this check.
3165 * @param pid The process ID being checked against. Must be > 0.
3166 * @param uid The user ID being checked against. A uid of 0 is the root
3167 * user, which will pass every permission check.
3168 * @param modeFlags The type of access to grant. May be one or both of
3169 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3170 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3172 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
3173 * is allowed to access that uri or holds one of the given permissions, or
3174 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3176 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3177 @Nullable String writePermission, int pid, int uid,
3178 @Intent.AccessUriMode int modeFlags);
3181 * If a particular process and user ID has not been granted
3182 * permission to access a specific URI, throw {@link
3183 * SecurityException}. This only checks for permissions that have
3184 * been explicitly granted -- if the given process/uid has more
3185 * general access to the URI's content provider then this check
3188 * @param uri The uri that is being checked.
3189 * @param pid The process ID being checked against. Must be > 0.
3190 * @param uid The user ID being checked against. A uid of 0 is the root
3191 * user, which will pass every permission check.
3192 * @param modeFlags The type of access to grant. May be one or both of
3193 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3194 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3195 * @param message A message to include in the exception if it is thrown.
3197 * @see #checkUriPermission(Uri, int, int, int)
3199 public abstract void enforceUriPermission(
3200 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
3203 * If the calling process and user ID has not been granted
3204 * permission to access a specific URI, throw {@link
3205 * SecurityException}. This is basically the same as calling
3206 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3207 * the pid and uid returned by {@link
3208 * android.os.Binder#getCallingPid} and {@link
3209 * android.os.Binder#getCallingUid}. One important difference is
3210 * that if you are not currently processing an IPC, this function
3211 * will always throw a SecurityException.
3213 * @param uri The uri that is being checked.
3214 * @param modeFlags The type of access to grant. May be one or both of
3215 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3216 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3217 * @param message A message to include in the exception if it is thrown.
3219 * @see #checkCallingUriPermission(Uri, int)
3221 public abstract void enforceCallingUriPermission(
3222 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
3225 * If the calling process of an IPC <em>or you</em> has not been
3226 * granted permission to access a specific URI, throw {@link
3227 * SecurityException}. This is the same as {@link
3228 * #enforceCallingUriPermission}, except it grants your own
3229 * permissions if you are not currently processing an IPC. Use
3232 * @param uri The uri that is being checked.
3233 * @param modeFlags The type of access to grant. May be one or both of
3234 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3235 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3236 * @param message A message to include in the exception if it is thrown.
3238 * @see #checkCallingOrSelfUriPermission(Uri, int)
3240 public abstract void enforceCallingOrSelfUriPermission(
3241 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
3244 * Enforce both a Uri and normal permission. This allows you to perform
3245 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3248 * @param uri The Uri whose permission is to be checked, or null to not
3250 * @param readPermission The permission that provides overall read access,
3251 * or null to not do this check.
3252 * @param writePermission The permission that provides overall write
3253 * access, or null to not do this check.
3254 * @param pid The process ID being checked against. Must be > 0.
3255 * @param uid The user ID being checked against. A uid of 0 is the root
3256 * user, which will pass every permission check.
3257 * @param modeFlags The type of access to grant. May be one or both of
3258 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3259 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3260 * @param message A message to include in the exception if it is thrown.
3262 * @see #checkUriPermission(Uri, String, String, int, int, int)
3264 public abstract void enforceUriPermission(
3265 @Nullable Uri uri, @Nullable String readPermission,
3266 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
3267 @Nullable String message);
3270 @IntDef(flag = true,
3271 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3272 @Retention(RetentionPolicy.SOURCE)
3273 public @interface CreatePackageOptions {}
3276 * Flag for use with {@link #createPackageContext}: include the application
3277 * code with the context. This means loading code into the caller's
3278 * process, so that {@link #getClassLoader()} can be used to instantiate
3279 * the application's classes. Setting this flags imposes security
3280 * restrictions on what application context you can access; if the
3281 * requested application can not be safely loaded into your process,
3282 * java.lang.SecurityException will be thrown. If this flag is not set,
3283 * there will be no restrictions on the packages that can be loaded,
3284 * but {@link #getClassLoader} will always return the default system
3287 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3290 * Flag for use with {@link #createPackageContext}: ignore any security
3291 * restrictions on the Context being requested, allowing it to always
3292 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3293 * to be loaded into a process even when it isn't safe to do so. Use
3294 * with extreme care!
3296 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
3299 * Flag for use with {@link #createPackageContext}: a restricted context may
3300 * disable specific features. For instance, a View associated with a restricted
3301 * context would ignore particular XML attributes.
3303 public static final int CONTEXT_RESTRICTED = 0x00000004;
3306 * @hide Used to indicate we should tell the activity manager about the process
3307 * loading this code.
3309 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
3312 * Return a new Context object for the given application name. This
3313 * Context is the same as what the named application gets when it is
3314 * launched, containing the same resources and class loader. Each call to
3315 * this method returns a new instance of a Context object; Context objects
3316 * are not shared, however they share common state (Resources, ClassLoader,
3317 * etc) so the Context instance itself is fairly lightweight.
3319 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
3320 * application with the given package name.
3322 * <p>Throws {@link java.lang.SecurityException} if the Context requested
3323 * can not be loaded into the caller's process for security reasons (see
3324 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3326 * @param packageName Name of the application's package.
3327 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3328 * or {@link #CONTEXT_IGNORE_SECURITY}.
3330 * @return A {@link Context} for the application.
3332 * @throws SecurityException
3333 * @throws PackageManager.NameNotFoundException if there is no application with
3334 * the given package name.
3336 public abstract Context createPackageContext(String packageName,
3337 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
3340 * Similar to {@link #createPackageContext(String, int)}, but with a
3341 * different {@link UserHandle}. For example, {@link #getContentResolver()}
3342 * will open any {@link Uri} as the given user.
3346 public abstract Context createPackageContextAsUser(
3347 String packageName, int flags, UserHandle user)
3348 throws PackageManager.NameNotFoundException;
3351 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
3355 public abstract Context createApplicationContext(ApplicationInfo application,
3356 int flags) throws PackageManager.NameNotFoundException;
3359 * Get the userId associated with this context
3364 public abstract int getUserId();
3367 * Return a new Context object for the current Context but whose resources
3368 * are adjusted to match the given Configuration. Each call to this method
3369 * returns a new instance of a Context object; Context objects are not
3370 * shared, however common state (ClassLoader, other Resources for the
3371 * same configuration) may be so the Context itself can be fairly lightweight.
3373 * @param overrideConfiguration A {@link Configuration} specifying what
3374 * values to modify in the base Configuration of the original Context's
3375 * resources. If the base configuration changes (such as due to an
3376 * orientation change), the resources of this context will also change except
3377 * for those that have been explicitly overridden with a value here.
3379 * @return A {@link Context} with the given configuration override.
3381 public abstract Context createConfigurationContext(
3382 @NonNull Configuration overrideConfiguration);
3385 * Return a new Context object for the current Context but whose resources
3386 * are adjusted to match the metrics of the given Display. Each call to this method
3387 * returns a new instance of a Context object; Context objects are not
3388 * shared, however common state (ClassLoader, other Resources for the
3389 * same configuration) may be so the Context itself can be fairly lightweight.
3391 * The returned display Context provides a {@link WindowManager}
3392 * (see {@link #getSystemService(String)}) that is configured to show windows
3393 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
3394 * method can be used to retrieve the Display from the returned Context.
3396 * @param display A {@link Display} object specifying the display
3397 * for whose metrics the Context's resources should be tailored and upon which
3398 * new windows should be shown.
3400 * @return A {@link Context} for the display.
3402 public abstract Context createDisplayContext(@NonNull Display display);
3405 * Gets the display adjustments holder for this context. This information
3406 * is provided on a per-application or activity basis and is used to simulate lower density
3407 * display metrics for legacy applications and restricted screen sizes.
3409 * @param displayId The display id for which to get compatibility info.
3410 * @return The compatibility info holder, or null if not required by the application.
3413 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
3416 * Indicates whether this Context is restricted.
3418 * @return {@code true} if this Context is restricted, {@code false} otherwise.
3420 * @see #CONTEXT_RESTRICTED
3422 public boolean isRestricted() {