blob: d068b1fba06fb82bd5a3c9907d43b19ee402a901 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Tor Norbyed9273d62013-05-30 15:59:53 -070019import android.annotation.IntDef;
20import android.annotation.NonNull;
21import android.annotation.Nullable;
22import android.annotation.StringDef;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090023import android.annotation.SystemApi;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070024import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.pm.PackageManager;
26import android.content.res.AssetManager;
Dianne Hackborn756220b2012-08-14 16:45:30 -070027import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.content.res.Resources;
29import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070030import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.database.sqlite.SQLiteDatabase;
32import android.database.sqlite.SQLiteDatabase.CursorFactory;
33import android.graphics.Bitmap;
34import android.graphics.drawable.Drawable;
Adam Powellac695c62010-07-20 18:19:27 -070035import android.media.MediaScannerConnection.OnScanCompletedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.net.Uri;
37import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070038import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.os.Handler;
40import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070041import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070042import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070043import android.os.UserManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070044import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.util.AttributeSet;
Craig Mautner48d0d182013-06-11 07:53:06 -070046import android.view.DisplayAdjustments;
Jeff Browna492c3a2012-08-23 19:48:44 -070047import android.view.Display;
48import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
50import java.io.File;
51import java.io.FileInputStream;
52import java.io.FileNotFoundException;
53import java.io.FileOutputStream;
54import java.io.IOException;
55import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070056import java.lang.annotation.Retention;
57import java.lang.annotation.RetentionPolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058
59/**
60 * Interface to global information about an application environment. This is
61 * an abstract class whose implementation is provided by
62 * the Android system. It
63 * allows access to application-specific resources and classes, as well as
64 * up-calls for application-level operations such as launching activities,
65 * broadcasting and receiving intents, etc.
66 */
67public abstract class Context {
68 /**
69 * File creation mode: the default mode, where the created file can only
70 * be accessed by the calling application (or all applications sharing the
71 * same user ID).
72 * @see #MODE_WORLD_READABLE
73 * @see #MODE_WORLD_WRITEABLE
74 */
75 public static final int MODE_PRIVATE = 0x0000;
76 /**
Nick Kralevich15069212013-01-09 15:54:56 -080077 * @deprecated Creating world-readable files is very dangerous, and likely
78 * to cause security holes in applications. It is strongly discouraged;
79 * instead, applications should use more formal mechanism for interactions
80 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
81 * {@link android.app.Service}. There are no guarantees that this
82 * access mode will remain on a file, such as when it goes through a
83 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 * File creation mode: allow all other applications to have read access
85 * to the created file.
86 * @see #MODE_PRIVATE
87 * @see #MODE_WORLD_WRITEABLE
88 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070089 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 public static final int MODE_WORLD_READABLE = 0x0001;
91 /**
Nick Kralevich15069212013-01-09 15:54:56 -080092 * @deprecated Creating world-writable files is very dangerous, and likely
93 * to cause security holes in applications. It is strongly discouraged;
94 * instead, applications should use more formal mechanism for interactions
95 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
96 * {@link android.app.Service}. There are no guarantees that this
97 * access mode will remain on a file, such as when it goes through a
98 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 * File creation mode: allow all other applications to have write access
100 * to the created file.
101 * @see #MODE_PRIVATE
102 * @see #MODE_WORLD_READABLE
103 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700104 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 public static final int MODE_WORLD_WRITEABLE = 0x0002;
106 /**
107 * File creation mode: for use with {@link #openFileOutput}, if the file
108 * already exists then write data to the end of the existing file
109 * instead of erasing it.
110 * @see #openFileOutput
111 */
112 public static final int MODE_APPEND = 0x8000;
113
114 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800115 * SharedPreference loading flag: when set, the file on disk will
116 * be checked for modification even if the shared preferences
117 * instance is already loaded in this process. This behavior is
118 * sometimes desired in cases where the application has multiple
119 * processes, all writing to the same SharedPreferences file.
120 * Generally there are better forms of communication between
121 * processes, though.
122 *
123 * <p>This was the legacy (but undocumented) behavior in and
124 * before Gingerbread (Android 2.3) and this flag is implied when
125 * targetting such releases. For applications targetting SDK
126 * versions <em>greater than</em> Android 2.3, this flag must be
127 * explicitly set if desired.
128 *
129 * @see #getSharedPreferences
130 */
131 public static final int MODE_MULTI_PROCESS = 0x0004;
132
133 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700134 * Database open flag: when set, the database is opened with write-ahead
135 * logging enabled by default.
136 *
137 * @see #openOrCreateDatabase(String, int, CursorFactory)
138 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
139 * @see SQLiteDatabase#enableWriteAheadLogging
140 */
141 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
142
Tor Norbyed9273d62013-05-30 15:59:53 -0700143 /** @hide */
144 @IntDef(flag = true,
145 value = {
146 BIND_AUTO_CREATE,
147 BIND_AUTO_CREATE,
148 BIND_DEBUG_UNBIND,
149 BIND_NOT_FOREGROUND,
150 BIND_ABOVE_CLIENT,
151 BIND_ALLOW_OOM_MANAGEMENT,
152 BIND_WAIVE_PRIORITY
153 })
154 @Retention(RetentionPolicy.SOURCE)
155 public @interface BindServiceFlags {}
156
Jeff Brown47847f32012-03-22 19:13:11 -0700157 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 * Flag for {@link #bindService}: automatically create the service as long
159 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700160 * its {@link android.app.Service#onStartCommand}
161 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 * explicit call to {@link #startService}. Even without that, though,
163 * this still provides you with access to the service object while the
164 * service is created.
165 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700166 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
167 * not supplying this flag would also impact how important the system
168 * consider's the target service's process to be. When set, the only way
169 * for it to be raised was by binding from a service in which case it will
170 * only be important when that activity is in the foreground. Now to
171 * achieve this behavior you must explicitly supply the new flag
172 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
173 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
174 * the flags {@link #BIND_WAIVE_PRIORITY} and
175 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
176 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 */
178 public static final int BIND_AUTO_CREATE = 0x0001;
179
180 /**
181 * Flag for {@link #bindService}: include debugging help for mismatched
182 * calls to unbind. When this flag is set, the callstack of the following
183 * {@link #unbindService} call is retained, to be printed if a later
184 * incorrect unbind call is made. Note that doing this requires retaining
185 * information about the binding that was made for the lifetime of the app,
186 * resulting in a leak -- this should only be used for debugging.
187 */
188 public static final int BIND_DEBUG_UNBIND = 0x0002;
189
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800190 /**
191 * Flag for {@link #bindService}: don't allow this binding to raise
192 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700193 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800194 * as the client (so that its process will not be killable in any
195 * situation where the client is not killable), but for CPU scheduling
196 * purposes it may be left in the background. This only has an impact
197 * in the situation where the binding client is a foreground process
198 * and the target service is in a background process.
199 */
200 public static final int BIND_NOT_FOREGROUND = 0x0004;
201
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700202 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700203 * Flag for {@link #bindService}: indicates that the client application
204 * binding to this service considers the service to be more important than
205 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700206 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700207 * this is not guaranteed to be the case.
208 */
209 public static final int BIND_ABOVE_CLIENT = 0x0008;
210
211 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700212 * Flag for {@link #bindService}: allow the process hosting the bound
213 * service to go through its normal memory management. It will be
214 * treated more like a running service, allowing the system to
215 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700216 * whim it may have, and being more aggressive about making it a candidate
217 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700218 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700219 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
220
221 /**
222 * Flag for {@link #bindService}: don't impact the scheduling or
223 * memory management priority of the target service's hosting process.
224 * Allows the service's process to be managed on the background LRU list
225 * just like a regular application process in the background.
226 */
227 public static final int BIND_WAIVE_PRIORITY = 0x0020;
228
229 /**
230 * Flag for {@link #bindService}: this service is very important to
231 * the client, so should be brought to the foreground process level
232 * when the client is. Normally a process can only be raised to the
233 * visibility level by a client, even if that client is in the foreground.
234 */
235 public static final int BIND_IMPORTANT = 0x0040;
236
237 /**
238 * Flag for {@link #bindService}: If binding from an activity, allow the
239 * target service's process importance to be raised based on whether the
240 * activity is visible to the user, regardless whether another flag is
241 * used to reduce the amount that the client process's overall importance
242 * is used to impact it.
243 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700244 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
245
246 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700247 * @hide Flag for {@link #bindService}: Treat the binding as hosting
248 * an activity, an unbinding as the activity going in the background.
249 * That is, when unbinding, the process when empty will go on the activity
250 * LRU list instead of the regular one, keeping it around more aggressively
251 * than it otherwise would be. This is intended for use with IMEs to try
252 * to keep IME processes around for faster keyboard switching.
253 */
254 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
255
256 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700257 * @hide An idea that is not yet implemented.
258 * Flag for {@link #bindService}: If binding from an activity, consider
259 * this service to be visible like the binding activity is. That is,
260 * it will be treated as something more important to keep around than
261 * invisible background activities. This will impact the number of
262 * recent activities the user can switch between without having them
263 * restart. There is no guarantee this will be respected, as the system
264 * tries to balance such requests from one app vs. the importantance of
265 * keeping other apps around.
266 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700267 public static final int BIND_VISIBLE = 0x10000000;
268
269 /**
270 * @hide
271 * Flag for {@link #bindService}: Consider this binding to be causing the target
272 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
273 * away.
274 */
275 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700276
277 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700278 * Flag for {@link #bindService}: Don't consider the bound service to be
279 * visible, even if the caller is visible.
280 * @hide
281 */
282 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 /** Return an AssetManager instance for your application's package. */
285 public abstract AssetManager getAssets();
286
287 /** Return a Resources instance for your application's package. */
288 public abstract Resources getResources();
289
290 /** Return PackageManager instance to find global package information. */
291 public abstract PackageManager getPackageManager();
292
293 /** Return a ContentResolver instance for your application's package. */
294 public abstract ContentResolver getContentResolver();
295
296 /**
297 * Return the Looper for the main thread of the current process. This is
298 * the thread used to dispatch calls to application components (activities,
299 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700300 * <p>
301 * By definition, this method returns the same result as would be obtained
302 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
303 * </p>
304 *
305 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 */
307 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700308
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 /**
310 * Return the context of the single, global Application object of the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800311 * current process. This generally should only be used if you need a
312 * Context whose lifecycle is separate from the current context, that is
313 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700314 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800315 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800316 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800317 * <ul>
318 * <li> <p>If used from an Activity context, the receiver is being registered
319 * within that activity. This means that you are expected to unregister
320 * before the activity is done being destroyed; in fact if you do not do
321 * so, the framework will clean up your leaked registration as it removes
322 * the activity and log an error. Thus, if you use the Activity context
323 * to register a receiver that is static (global to the process, not
324 * associated with an Activity instance) then that registration will be
325 * removed on you at whatever point the activity you used is destroyed.
326 * <li> <p>If used from the Context returned here, the receiver is being
327 * registered with the global state associated with your application. Thus
328 * it will never be unregistered for you. This is necessary if the receiver
329 * is associated with static data, not a particular component. However
330 * using the ApplicationContext elsewhere can easily lead to serious leaks
331 * if you forget to unregister, unbind, etc.
332 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800333 */
334 public abstract Context getApplicationContext();
335
336 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700337 * Add a new {@link ComponentCallbacks} to the base application of the
338 * Context, which will be called at the same times as the ComponentCallbacks
339 * methods of activities and other components are called. Note that you
340 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
341 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700342 *
343 * @param callback The interface to call. This can be either a
344 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700345 */
346 public void registerComponentCallbacks(ComponentCallbacks callback) {
347 getApplicationContext().registerComponentCallbacks(callback);
348 }
349
350 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400351 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700352 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
353 */
354 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
355 getApplicationContext().unregisterComponentCallbacks(callback);
356 }
357
358 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 * Return a localized, styled CharSequence from the application's package's
360 * default string table.
361 *
362 * @param resId Resource id for the CharSequence text
363 */
364 public final CharSequence getText(int resId) {
365 return getResources().getText(resId);
366 }
367
368 /**
369 * Return a localized string from the application's package's
370 * default string table.
371 *
372 * @param resId Resource id for the string
373 */
374 public final String getString(int resId) {
375 return getResources().getString(resId);
376 }
377
378 /**
379 * Return a localized formatted string from the application's package's
380 * default string table, substituting the format arguments as defined in
381 * {@link java.util.Formatter} and {@link java.lang.String#format}.
382 *
383 * @param resId Resource id for the format string
384 * @param formatArgs The format arguments that will be used for substitution.
385 */
386
387 public final String getString(int resId, Object... formatArgs) {
388 return getResources().getString(resId, formatArgs);
389 }
390
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800391 /**
392 * Return a drawable object associated with a particular resource ID and
393 * styled for the current theme.
394 *
395 * @param id The desired resource identifier, as generated by the aapt
396 * tool. This integer encodes the package, type, and resource
397 * entry. The value 0 is an invalid identifier.
398 * @return Drawable An object that can be used to draw this resource.
399 */
400 public final Drawable getDrawable(int id) {
401 return getResources().getDrawable(id, getTheme());
402 }
403
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 /**
405 * Set the base theme for this context. Note that this should be called
406 * before any views are instantiated in the Context (for example before
407 * calling {@link android.app.Activity#setContentView} or
408 * {@link android.view.LayoutInflater#inflate}).
409 *
410 * @param resid The style resource describing the theme.
411 */
412 public abstract void setTheme(int resid);
413
Dianne Hackborn247fe742011-01-08 17:25:57 -0800414 /** @hide Needed for some internal implementation... not public because
415 * you can't assume this actually means anything. */
416 public int getThemeResId() {
417 return 0;
418 }
419
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 /**
421 * Return the Theme object associated with this Context.
422 */
423 public abstract Resources.Theme getTheme();
424
425 /**
426 * Retrieve styled attribute information in this Context's theme. See
427 * {@link Resources.Theme#obtainStyledAttributes(int[])}
428 * for more information.
429 *
430 * @see Resources.Theme#obtainStyledAttributes(int[])
431 */
432 public final TypedArray obtainStyledAttributes(
433 int[] attrs) {
434 return getTheme().obtainStyledAttributes(attrs);
435 }
436
437 /**
438 * Retrieve styled attribute information in this Context's theme. See
439 * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
440 * for more information.
441 *
442 * @see Resources.Theme#obtainStyledAttributes(int, int[])
443 */
444 public final TypedArray obtainStyledAttributes(
445 int resid, int[] attrs) throws Resources.NotFoundException {
446 return getTheme().obtainStyledAttributes(resid, attrs);
447 }
448
449 /**
450 * Retrieve styled attribute information in this Context's theme. See
451 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
452 * for more information.
453 *
454 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
455 */
456 public final TypedArray obtainStyledAttributes(
457 AttributeSet set, int[] attrs) {
458 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
459 }
460
461 /**
462 * Retrieve styled attribute information in this Context's theme. See
463 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
464 * for more information.
465 *
466 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
467 */
468 public final TypedArray obtainStyledAttributes(
469 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
470 return getTheme().obtainStyledAttributes(
471 set, attrs, defStyleAttr, defStyleRes);
472 }
473
474 /**
475 * Return a class loader you can use to retrieve classes in this package.
476 */
477 public abstract ClassLoader getClassLoader();
478
479 /** Return the name of this application's package. */
480 public abstract String getPackageName();
481
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800482 /** @hide Return the name of the base context this context is derived from. */
483 public abstract String getBasePackageName();
484
Dianne Hackborn95d78532013-09-11 09:51:14 -0700485 /** @hide Return the package name that should be used for app ops calls from
486 * this context. This is the same as {@link #getBasePackageName()} except in
487 * cases where system components are loaded into other app processes, in which
488 * case this will be the name of the primary package in that process (so that app
489 * ops uid verification will work with the name). */
490 public abstract String getOpPackageName();
491
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700492 /** Return the full application info for this context's package. */
493 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 /**
Kenny Root32148392010-01-21 15:40:47 -0800496 * Return the full path to this context's primary Android package.
497 * The Android package is a ZIP file which contains the application's
498 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 *
500 * <p>Note: this is not generally useful for applications, since they should
501 * not be directly accessing the file system.
502 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 * @return String Path to the resources.
504 */
505 public abstract String getPackageResourcePath();
506
507 /**
Kenny Root32148392010-01-21 15:40:47 -0800508 * Return the full path to this context's primary Android package.
509 * The Android package is a ZIP file which contains application's
510 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 *
512 * <p>Note: this is not generally useful for applications, since they should
513 * not be directly accessing the file system.
514 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 * @return String Path to the code and assets.
516 */
517 public abstract String getPackageCodePath();
518
519 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700520 * {@hide}
521 * Return the full path to the shared prefs file for the given prefs group name.
522 *
523 * <p>Note: this is not generally useful for applications, since they should
524 * not be directly accessing the file system.
525 */
526 public abstract File getSharedPrefsFile(String name);
527
528 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 * Retrieve and hold the contents of the preferences file 'name', returning
530 * a SharedPreferences through which you can retrieve and modify its
531 * values. Only one instance of the SharedPreferences object is returned
532 * to any callers for the same name, meaning they will see each other's
533 * edits as soon as they are made.
534 *
535 * @param name Desired preferences file. If a preferences file by this name
536 * does not exist, it will be created when you retrieve an
537 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
538 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
539 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800540 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
541 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
542 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
Tor Norbyed9273d62013-05-30 15:59:53 -0700543 * is always on in apps targeting Gingerbread (Android 2.3) and below, and
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800544 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400546 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 * to retrieve and modify the preference values.
548 *
549 * @see #MODE_PRIVATE
550 * @see #MODE_WORLD_READABLE
551 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800552 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 */
554 public abstract SharedPreferences getSharedPreferences(String name,
555 int mode);
556
557 /**
558 * Open a private file associated with this Context's application package
559 * for reading.
560 *
561 * @param name The name of the file to open; can not contain path
562 * separators.
563 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400564 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 *
566 * @see #openFileOutput
567 * @see #fileList
568 * @see #deleteFile
569 * @see java.io.FileInputStream#FileInputStream(String)
570 */
571 public abstract FileInputStream openFileInput(String name)
572 throws FileNotFoundException;
573
574 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800575 * Open a private file associated with this Context's application package
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 * for writing. Creates the file if it doesn't already exist.
577 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700578 * <p>No permissions are required to invoke this method, since it uses internal
579 * storage.
580 *
Nick Kralevich15069212013-01-09 15:54:56 -0800581 * @param name The name of the file to open; can not contain path
582 * separators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800584 * default operation, {@link #MODE_APPEND} to append to an existing file,
585 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
586 * permissions.
587 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400588 * @return The resulting {@link FileOutputStream}.
Nick Kralevich15069212013-01-09 15:54:56 -0800589 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 * @see #MODE_APPEND
591 * @see #MODE_PRIVATE
592 * @see #MODE_WORLD_READABLE
593 * @see #MODE_WORLD_WRITEABLE
594 * @see #openFileInput
595 * @see #fileList
596 * @see #deleteFile
597 * @see java.io.FileOutputStream#FileOutputStream(String)
598 */
599 public abstract FileOutputStream openFileOutput(String name, int mode)
600 throws FileNotFoundException;
601
602 /**
603 * Delete the given private file associated with this Context's
604 * application package.
605 *
606 * @param name The name of the file to delete; can not contain path
607 * separators.
608 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400609 * @return {@code true} if the file was successfully deleted; else
610 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 *
612 * @see #openFileInput
613 * @see #openFileOutput
614 * @see #fileList
615 * @see java.io.File#delete()
616 */
617 public abstract boolean deleteFile(String name);
618
619 /**
620 * Returns the absolute path on the filesystem where a file created with
621 * {@link #openFileOutput} is stored.
622 *
623 * @param name The name of the file for which you would like to get
624 * its path.
625 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400626 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 *
628 * @see #openFileOutput
629 * @see #getFilesDir
630 * @see #getDir
631 */
632 public abstract File getFileStreamPath(String name);
633
634 /**
635 * Returns the absolute path to the directory on the filesystem where
636 * files created with {@link #openFileOutput} are stored.
637 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700638 * <p>No permissions are required to read or write to the returned path, since this
639 * path is internal storage.
640 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400641 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 *
643 * @see #openFileOutput
644 * @see #getFileStreamPath
645 * @see #getDir
646 */
647 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700650 * Returns the absolute path to the directory on the filesystem similar to
651 * {@link #getFilesDir()}. The difference is that files placed under this
652 * directory will be excluded from automatic backup to remote storage. See
653 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
654 * of the automatic backup mechanism in Android.
655 *
656 * <p>No permissions are required to read or write to the returned path, since this
657 * path is internal storage.
658 *
659 * @return The path of the directory holding application files that will not be
660 * automatically backed up to remote storage.
661 *
662 * @see #openFileOutput
663 * @see #getFileStreamPath
664 * @see #getDir
665 * @see android.app.backup.BackupAgent
666 */
667 public abstract File getNoBackupFilesDir();
668
669 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700670 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800671 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700672 * Environment.getExternalStorageDirectory()}) where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700673 * place persistent files it owns. These files are internal to the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800674 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700675 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800676 * <p>This is like {@link #getFilesDir()} in that these
677 * files will be deleted when the application is uninstalled, however there
678 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700679 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800680 * <ul>
681 * <li>External files are not always available: they will disappear if the
682 * user mounts the external storage on a computer or removes it. See the
683 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700684 * <li>There is no security enforced with these files. For example, any application
685 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
686 * these files.
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800687 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700688 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700689 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
690 * are required to read or write to the returned path; it's always
691 * accessible to the calling app. This only applies to paths generated for
692 * package name of the calling application. To access paths belonging
693 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
694 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
695 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700696 * <p>On devices with multiple users (as described by {@link UserManager}),
697 * each user has their own isolated external storage. Applications only
698 * have access to the external storage for the user they're running as.</p>
699 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800700 * <p>Here is an example of typical code to manipulate a file in
701 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700702 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800703 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
704 * private_file}
705 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700706 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800707 * file will be a path to a sub-directory of the given type. Though these files
708 * are not automatically scanned by the media scanner, you can explicitly
709 * add them to the media database with
710 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Ray Chenb7c8c762010-03-30 17:21:39 -0700711 * OnScanCompletedListener) MediaScannerConnection.scanFile}.
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800712 * Note that this is not the same as
713 * {@link android.os.Environment#getExternalStoragePublicDirectory
714 * Environment.getExternalStoragePublicDirectory()}, which provides
715 * directories of media shared by all applications. The
716 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700717 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800718 * application is uninstalled. Unlike
719 * {@link android.os.Environment#getExternalStoragePublicDirectory
720 * Environment.getExternalStoragePublicDirectory()}, the directory
721 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700722 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800723 * <p>Here is an example of typical code to manipulate a picture in
724 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700725 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800726 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
727 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700728 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800729 * @param type The type of files directory to return. May be null for
730 * the root of the files directory or one of
731 * the following Environment constants for a subdirectory:
732 * {@link android.os.Environment#DIRECTORY_MUSIC},
733 * {@link android.os.Environment#DIRECTORY_PODCASTS},
734 * {@link android.os.Environment#DIRECTORY_RINGTONES},
735 * {@link android.os.Environment#DIRECTORY_ALARMS},
736 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
737 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
738 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700739 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400740 * @return The path of the directory holding application files
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800741 * on external storage. Returns null if external storage is not currently
742 * mounted so it could not ensure the path exists; you will need to call
743 * this method again when it is available.
744 *
745 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700746 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800747 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700748 @Nullable
749 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700750
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800751 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700752 * Returns absolute paths to application-specific directories on all
753 * external storage devices where the application can place persistent files
754 * it owns. These files are internal to the application, and not typically
755 * visible to the user as media.
756 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700757 * This is like {@link #getFilesDir()} in that these files will be deleted when
758 * the application is uninstalled, however there are some important differences:
759 * <ul>
760 * <li>External files are not always available: they will disappear if the
761 * user mounts the external storage on a computer or removes it.
762 * <li>There is no security enforced with these files.
763 * </ul>
764 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700765 * External storage devices returned here are considered a permanent part of
766 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700767 * slots, such as SD cards in a battery compartment. The returned paths do
768 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700769 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700770 * An application may store data on any or all of the returned devices. For
771 * example, an app may choose to store large files on the device with the
772 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700773 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700774 * No permissions are required to read or write to the returned paths; they
775 * are always accessible to the calling app. Write access outside of these
776 * paths on secondary external storage devices is not available.
777 * <p>
778 * The first path returned is the same as {@link #getExternalFilesDir(String)}.
779 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700780 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700781 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800782 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700783 */
784 public abstract File[] getExternalFilesDirs(String type);
785
786 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700787 * Return the primary external storage directory where this application's OBB
788 * files (if there are any) can be found. Note if the application does not have
789 * any OBB files, this directory may not exist.
790 * <p>
791 * This is like {@link #getFilesDir()} in that these files will be deleted when
792 * the application is uninstalled, however there are some important differences:
793 * <ul>
794 * <li>External files are not always available: they will disappear if the
795 * user mounts the external storage on a computer or removes it.
796 * <li>There is no security enforced with these files. For example, any application
797 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
798 * these files.
799 * </ul>
800 * <p>
801 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
802 * are required to read or write to the returned path; it's always
803 * accessible to the calling app. This only applies to paths generated for
804 * package name of the calling application. To access paths belonging
805 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
806 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700807 * <p>
808 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -0700809 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700810 * should ensure that multiple instances running under different users don't
811 * interfere with each other.
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800812 */
813 public abstract File getObbDir();
814
815 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700816 * Returns absolute paths to application-specific directories on all
817 * external storage devices where the application's OBB files (if there are
818 * any) can be found. Note if the application does not have any OBB files,
819 * these directories may not exist.
820 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700821 * This is like {@link #getFilesDir()} in that these files will be deleted when
822 * the application is uninstalled, however there are some important differences:
823 * <ul>
824 * <li>External files are not always available: they will disappear if the
825 * user mounts the external storage on a computer or removes it.
826 * <li>There is no security enforced with these files.
827 * </ul>
828 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700829 * External storage devices returned here are considered a permanent part of
830 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700831 * slots, such as SD cards in a battery compartment. The returned paths do
832 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700833 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700834 * An application may store data on any or all of the returned devices. For
835 * example, an app may choose to store large files on the device with the
836 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700837 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700838 * No permissions are required to read or write to the returned paths; they
839 * are always accessible to the calling app. Write access outside of these
840 * paths on secondary external storage devices is not available.
841 * <p>
842 * The first path returned is the same as {@link #getObbDir()}.
843 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700844 *
845 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800846 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700847 */
848 public abstract File[] getObbDirs();
849
850 /**
Scott Main4b5da682010-10-21 11:49:12 -0700851 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800853 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800854 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700855 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800856 * <strong>Note: you should not <em>rely</em> on the system deleting these
857 * files for you; you should always have a reasonable maximum, such as 1 MB,
858 * for the amount of space you consume with cache files, and prune those
859 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700860 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400861 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 *
863 * @see #openFileOutput
864 * @see #getFileStreamPath
865 * @see #getDir
866 */
867 public abstract File getCacheDir();
868
869 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -0700870 * Returns the absolute path to the application specific cache directory on
871 * the filesystem designed for storing cached code. The system will delete
872 * any files stored in this location both when your specific application is
873 * upgraded, and when the entire platform is upgraded.
874 * <p>
875 * This location is optimal for storing compiled or optimized code generated
876 * by your application at runtime.
877 * <p>
878 * Apps require no extra permissions to read or write to the returned path,
879 * since this path lives in their private storage.
880 *
881 * @return The path of the directory holding application code cache files.
882 */
883 public abstract File getCodeCacheDir();
884
885 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700886 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800887 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
888 * Environment.getExternalStorageDirectory()} where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700889 * place cache files it owns. These files are internal to the application, and
890 * not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700891 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800892 * <p>This is like {@link #getCacheDir()} in that these
893 * files will be deleted when the application is uninstalled, however there
894 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700895 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800896 * <ul>
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700897 * <li>The platform does not always monitor the space available in external
898 * storage, and thus may not automatically delete these files. Currently
899 * the only time files here will be deleted by the platform is when running
900 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
901 * {@link android.os.Environment#isExternalStorageEmulated()
902 * Environment.isExternalStorageEmulated()} returns true. Note that you should
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800903 * be managing the maximum space you will use for these anyway, just like
904 * with {@link #getCacheDir()}.
905 * <li>External files are not always available: they will disappear if the
906 * user mounts the external storage on a computer or removes it. See the
907 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700908 * <li>There is no security enforced with these files. For example, any application
909 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
910 * these files.
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800911 * </ul>
912 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700913 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
914 * are required to read or write to the returned path; it's always
915 * accessible to the calling app. This only applies to paths generated for
916 * package name of the calling application. To access paths belonging
917 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
918 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
919 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700920 * <p>On devices with multiple users (as described by {@link UserManager}),
921 * each user has their own isolated external storage. Applications only
922 * have access to the external storage for the user they're running as.</p>
Jeff Sharkey8c165792012-10-22 14:08:29 -0700923 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400924 * @return The path of the directory holding application cache files
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800925 * on external storage. Returns null if external storage is not currently
926 * mounted so it could not ensure the path exists; you will need to call
927 * this method again when it is available.
928 *
929 * @see #getCacheDir
930 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700931 @Nullable
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800932 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700933
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800934 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700935 * Returns absolute paths to application-specific directories on all
936 * external storage devices where the application can place cache files it
937 * owns. These files are internal to the application, and not typically
938 * visible to the user as media.
939 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700940 * This is like {@link #getCacheDir()} in that these files will be deleted when
941 * the application is uninstalled, however there are some important differences:
942 * <ul>
943 * <li>External files are not always available: they will disappear if the
944 * user mounts the external storage on a computer or removes it.
945 * <li>There is no security enforced with these files.
946 * </ul>
947 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700948 * External storage devices returned here are considered a permanent part of
949 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700950 * slots, such as SD cards in a battery compartment. The returned paths do
951 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700952 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700953 * An application may store data on any or all of the returned devices. For
954 * example, an app may choose to store large files on the device with the
955 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700956 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700957 * No permissions are required to read or write to the returned paths; they
958 * are always accessible to the calling app. Write access outside of these
959 * paths on secondary external storage devices is not available.
960 * <p>
961 * The first path returned is the same as {@link #getExternalCacheDir()}.
962 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700963 *
964 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800965 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700966 */
967 public abstract File[] getExternalCacheDirs();
968
969 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -0700970 * Returns absolute paths to application-specific directories on all
971 * external storage devices where the application can place media files.
972 * These files are scanned and made available to other apps through
973 * {@link MediaStore}.
974 * <p>
975 * This is like {@link #getExternalFilesDirs} in that these files will be
976 * deleted when the application is uninstalled, however there are some
977 * important differences:
978 * <ul>
979 * <li>External files are not always available: they will disappear if the
980 * user mounts the external storage on a computer or removes it.
981 * <li>There is no security enforced with these files.
982 * </ul>
983 * <p>
984 * External storage devices returned here are considered a permanent part of
985 * the device, including both emulated external storage and physical media
986 * slots, such as SD cards in a battery compartment. The returned paths do
987 * not include transient devices, such as USB flash drives.
988 * <p>
989 * An application may store data on any or all of the returned devices. For
990 * example, an app may choose to store large files on the device with the
991 * most available space, as measured by {@link StatFs}.
992 * <p>
993 * No permissions are required to read or write to the returned paths; they
994 * are always accessible to the calling app. Write access outside of these
995 * paths on secondary external storage devices is not available.
996 * <p>
997 * Returned paths may be {@code null} if a storage device is unavailable.
998 *
999 * @see Environment#getExternalStorageState(File)
1000 */
1001 public abstract File[] getExternalMediaDirs();
1002
1003 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 * Returns an array of strings naming the private files associated with
1005 * this Context's application package.
1006 *
1007 * @return Array of strings naming the private files.
1008 *
1009 * @see #openFileInput
1010 * @see #openFileOutput
1011 * @see #deleteFile
1012 */
1013 public abstract String[] fileList();
1014
1015 /**
1016 * Retrieve, creating if needed, a new directory in which the application
1017 * can place its own custom data files. You can use the returned File
1018 * object to create and access files in this directory. Note that files
1019 * created through a File object will only be accessible by your own
1020 * application; you can only set the mode of the entire directory, not
1021 * of individual files.
1022 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001023 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001024 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001025 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -08001026 * default operation, {@link #MODE_WORLD_READABLE} and
1027 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
1028 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001029 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001030 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 *
1032 * @see #openFileOutput(String, int)
1033 */
1034 public abstract File getDir(String name, int mode);
1035
1036 /**
1037 * Open a new private SQLiteDatabase associated with this Context's
1038 * application package. Create the database file if it doesn't exist.
1039 *
1040 * @param name The name (unique in the application package) of the database.
1041 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1042 * default operation, {@link #MODE_WORLD_READABLE}
1043 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001044 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 * @param factory An optional factory class that is called to instantiate a
1046 * cursor when query is called.
Nick Kralevich15069212013-01-09 15:54:56 -08001047 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 * @return The contents of a newly created database with the given name.
1049 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001050 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 * @see #MODE_PRIVATE
1052 * @see #MODE_WORLD_READABLE
1053 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001054 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001055 * @see #deleteDatabase
1056 */
1057 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1058 int mode, CursorFactory factory);
1059
1060 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001061 * Open a new private SQLiteDatabase associated with this Context's
1062 * application package. Creates the database file if it doesn't exist.
1063 *
1064 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
1065 * used to handle corruption when sqlite reports database corruption.</p>
1066 *
1067 * @param name The name (unique in the application package) of the database.
1068 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1069 * default operation, {@link #MODE_WORLD_READABLE}
1070 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001071 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -07001072 * @param factory An optional factory class that is called to instantiate a
1073 * cursor when query is called.
1074 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Nick Kralevich15069212013-01-09 15:54:56 -08001075 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001076 * @return The contents of a newly created database with the given name.
1077 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001078 *
Vasu Nori74f170f2010-06-01 18:06:18 -07001079 * @see #MODE_PRIVATE
1080 * @see #MODE_WORLD_READABLE
1081 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001082 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -07001083 * @see #deleteDatabase
1084 */
1085 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001086 int mode, CursorFactory factory,
1087 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001088
1089 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001090 * Delete an existing private SQLiteDatabase associated with this Context's
1091 * application package.
1092 *
1093 * @param name The name (unique in the application package) of the
1094 * database.
1095 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001096 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 *
1098 * @see #openOrCreateDatabase
1099 */
1100 public abstract boolean deleteDatabase(String name);
1101
1102 /**
1103 * Returns the absolute path on the filesystem where a database created with
1104 * {@link #openOrCreateDatabase} is stored.
1105 *
1106 * @param name The name of the database for which you would like to get
1107 * its path.
1108 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001109 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001110 *
1111 * @see #openOrCreateDatabase
1112 */
1113 public abstract File getDatabasePath(String name);
1114
1115 /**
1116 * Returns an array of strings naming the private databases associated with
1117 * this Context's application package.
1118 *
1119 * @return Array of strings naming the private databases.
1120 *
1121 * @see #openOrCreateDatabase
1122 * @see #deleteDatabase
1123 */
1124 public abstract String[] databaseList();
1125
1126 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001127 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001128 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001130 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001131 public abstract Drawable getWallpaper();
1132
1133 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001134 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001135 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001137 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 public abstract Drawable peekWallpaper();
1139
1140 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001141 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1142 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001144 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 public abstract int getWallpaperDesiredMinimumWidth();
1146
1147 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001148 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1149 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001151 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 public abstract int getWallpaperDesiredMinimumHeight();
1153
1154 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001155 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001156 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001157 * <p>This method requires the caller to hold the permission
1158 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001160 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1162
1163 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001164 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001165 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001166 * <p>This method requires the caller to hold the permission
1167 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001169 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 public abstract void setWallpaper(InputStream data) throws IOException;
1171
1172 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001173 * @deprecated Use {@link android.app.WallpaperManager#clear
1174 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001175 * <p>This method requires the caller to hold the permission
1176 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001178 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 public abstract void clearWallpaper() throws IOException;
1180
1181 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001182 * Same as {@link #startActivity(Intent, Bundle)} with no options
1183 * specified.
1184 *
1185 * @param intent The description of the activity to start.
1186 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001187 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001188 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001189 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001190 * @see PackageManager#resolveActivity
1191 */
1192 public abstract void startActivity(Intent intent);
1193
1194 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001195 * Version of {@link #startActivity(Intent)} that allows you to specify the
1196 * user the activity will be started for. This is not available to applications
1197 * that are not pre-installed on the system image. Using it requires holding
1198 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001199 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001200 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001201 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001202 * @hide
1203 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001204 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001205 throw new RuntimeException("Not implemented. Must override in a subclass.");
1206 }
1207
1208 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 * Launch a new activity. You will not receive any information about when
1210 * the activity exits.
1211 *
1212 * <p>Note that if this method is being called from outside of an
1213 * {@link android.app.Activity} Context, then the Intent must include
1214 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1215 * without being started from an existing Activity, there is no existing
1216 * task in which to place the new activity and thus it needs to be placed
1217 * in its own separate task.
1218 *
1219 * <p>This method throws {@link ActivityNotFoundException}
1220 * if there was no Activity found to run the given Intent.
1221 *
1222 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001223 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001224 * May be null if there are no options. See {@link android.app.ActivityOptions}
1225 * for how to build the Bundle supplied here; there are no supported definitions
1226 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001227 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001228 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001229 *
Scott Main60dd5202012-06-23 00:01:22 -07001230 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001231 * @see PackageManager#resolveActivity
1232 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001233 public abstract void startActivity(Intent intent, @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001234
1235 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001236 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1237 * user the activity will be started for. This is not available to applications
1238 * that are not pre-installed on the system image. Using it requires holding
1239 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001240 * @param intent The description of the activity to start.
1241 * @param options Additional options for how the Activity should be started.
1242 * May be null if there are no options. See {@link android.app.ActivityOptions}
1243 * for how to build the Bundle supplied here; there are no supported definitions
1244 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001245 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001246 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001247 * @hide
1248 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001249 public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001250 throw new RuntimeException("Not implemented. Must override in a subclass.");
1251 }
1252
1253 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001254 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1255 * specified.
1256 *
1257 * @param intents An array of Intents to be started.
1258 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001259 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001260 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001261 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001262 * @see PackageManager#resolveActivity
1263 */
1264 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265
1266 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001267 * Launch multiple new activities. This is generally the same as calling
1268 * {@link #startActivity(Intent)} for the first Intent in the array,
1269 * that activity during its creation calling {@link #startActivity(Intent)}
1270 * for the second entry, etc. Note that unlike that approach, generally
1271 * none of the activities except the last in the array will be created
1272 * at this point, but rather will be created when the user first visits
1273 * them (due to pressing back from the activity on top).
1274 *
1275 * <p>This method throws {@link ActivityNotFoundException}
1276 * if there was no Activity found for <em>any</em> given Intent. In this
1277 * case the state of the activity stack is undefined (some Intents in the
1278 * list may be on it, some not), so you probably want to avoid such situations.
1279 *
1280 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001281 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001282 * See {@link android.content.Context#startActivity(Intent, Bundle)
1283 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001284 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001285 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001286 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001287 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001288 * @see PackageManager#resolveActivity
1289 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001290 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001291
1292 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001293 * @hide
1294 * Launch multiple new activities. This is generally the same as calling
1295 * {@link #startActivity(Intent)} for the first Intent in the array,
1296 * that activity during its creation calling {@link #startActivity(Intent)}
1297 * for the second entry, etc. Note that unlike that approach, generally
1298 * none of the activities except the last in the array will be created
1299 * at this point, but rather will be created when the user first visits
1300 * them (due to pressing back from the activity on top).
1301 *
1302 * <p>This method throws {@link ActivityNotFoundException}
1303 * if there was no Activity found for <em>any</em> given Intent. In this
1304 * case the state of the activity stack is undefined (some Intents in the
1305 * list may be on it, some not), so you probably want to avoid such situations.
1306 *
1307 * @param intents An array of Intents to be started.
1308 * @param options Additional options for how the Activity should be started.
1309 * @param userHandle The user for whom to launch the activities
1310 * See {@link android.content.Context#startActivity(Intent, Bundle)
1311 * Context.startActivity(Intent, Bundle)} for more details.
1312 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001313 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001314 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001315 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001316 * @see PackageManager#resolveActivity
1317 */
1318 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1319 throw new RuntimeException("Not implemented. Must override in a subclass.");
1320 }
1321
1322 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001323 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1324 * with no options specified.
1325 *
1326 * @param intent The IntentSender to launch.
1327 * @param fillInIntent If non-null, this will be provided as the
1328 * intent parameter to {@link IntentSender#sendIntent}.
1329 * @param flagsMask Intent flags in the original IntentSender that you
1330 * would like to change.
1331 * @param flagsValues Desired values for any bits set in
1332 * <var>flagsMask</var>
1333 * @param extraFlags Always set to 0.
1334 *
1335 * @see #startActivity(Intent)
1336 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1337 */
1338 public abstract void startIntentSender(IntentSender intent,
1339 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1340 throws IntentSender.SendIntentException;
1341
1342 /**
1343 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001344 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001345 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001346 * here; otherwise, its associated action will be executed (such as
1347 * sending a broadcast) as if you had called
1348 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001349 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001350 * @param intent The IntentSender to launch.
1351 * @param fillInIntent If non-null, this will be provided as the
1352 * intent parameter to {@link IntentSender#sendIntent}.
1353 * @param flagsMask Intent flags in the original IntentSender that you
1354 * would like to change.
1355 * @param flagsValues Desired values for any bits set in
1356 * <var>flagsMask</var>
1357 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001358 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001359 * See {@link android.content.Context#startActivity(Intent, Bundle)
1360 * Context.startActivity(Intent, Bundle)} for more details. If options
1361 * have also been supplied by the IntentSender, options given here will
1362 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001363 *
1364 * @see #startActivity(Intent, Bundle)
1365 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001366 */
1367 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001368 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001369 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001370
1371 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 * Broadcast the given intent to all interested BroadcastReceivers. This
1373 * call is asynchronous; it returns immediately, and you will continue
1374 * executing while the receivers are run. No results are propagated from
1375 * receivers and receivers can not abort the broadcast. If you want
1376 * to allow receivers to propagate results or abort the broadcast, you must
1377 * send an ordered broadcast using
1378 * {@link #sendOrderedBroadcast(Intent, String)}.
1379 *
1380 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1381 *
1382 * @param intent The Intent to broadcast; all receivers matching this
1383 * Intent will receive the broadcast.
1384 *
1385 * @see android.content.BroadcastReceiver
1386 * @see #registerReceiver
1387 * @see #sendBroadcast(Intent, String)
1388 * @see #sendOrderedBroadcast(Intent, String)
1389 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1390 */
1391 public abstract void sendBroadcast(Intent intent);
1392
1393 /**
1394 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1395 * an optional required permission to be enforced. This
1396 * call is asynchronous; it returns immediately, and you will continue
1397 * executing while the receivers are run. No results are propagated from
1398 * receivers and receivers can not abort the broadcast. If you want
1399 * to allow receivers to propagate results or abort the broadcast, you must
1400 * send an ordered broadcast using
1401 * {@link #sendOrderedBroadcast(Intent, String)}.
1402 *
1403 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1404 *
1405 * @param intent The Intent to broadcast; all receivers matching this
1406 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001407 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001408 * a receiver must hold in order to receive your broadcast.
1409 * If null, no permission is required.
1410 *
1411 * @see android.content.BroadcastReceiver
1412 * @see #registerReceiver
1413 * @see #sendBroadcast(Intent)
1414 * @see #sendOrderedBroadcast(Intent, String)
1415 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1416 */
1417 public abstract void sendBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001418 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419
1420 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001421 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001422 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001423 * @hide
1424 */
1425 public abstract void sendBroadcast(Intent intent,
1426 String receiverPermission, int appOp);
1427
1428 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001429 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1430 * them one at a time to allow more preferred receivers to consume the
1431 * broadcast before it is delivered to less preferred receivers. This
1432 * call is asynchronous; it returns immediately, and you will continue
1433 * executing while the receivers are run.
1434 *
1435 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1436 *
1437 * @param intent The Intent to broadcast; all receivers matching this
1438 * Intent will receive the broadcast.
1439 * @param receiverPermission (optional) String naming a permissions that
1440 * a receiver must hold in order to receive your broadcast.
1441 * If null, no permission is required.
1442 *
1443 * @see android.content.BroadcastReceiver
1444 * @see #registerReceiver
1445 * @see #sendBroadcast(Intent)
1446 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1447 */
1448 public abstract void sendOrderedBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001449 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450
1451 /**
1452 * Version of {@link #sendBroadcast(Intent)} that allows you to
1453 * receive data back from the broadcast. This is accomplished by
1454 * supplying your own BroadcastReceiver when calling, which will be
1455 * treated as a final receiver at the end of the broadcast -- its
1456 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001457 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 * be serialized in the same way as calling
1459 * {@link #sendOrderedBroadcast(Intent, String)}.
1460 *
1461 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1462 * asynchronous; it will return before
1463 * resultReceiver.onReceive() is called.
1464 *
1465 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1466 *
1467 * @param intent The Intent to broadcast; all receivers matching this
1468 * Intent will receive the broadcast.
1469 * @param receiverPermission String naming a permissions that
1470 * a receiver must hold in order to receive your broadcast.
1471 * If null, no permission is required.
1472 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1473 * receiver of the broadcast.
1474 * @param scheduler A custom Handler with which to schedule the
1475 * resultReceiver callback; if null it will be
1476 * scheduled in the Context's main thread.
1477 * @param initialCode An initial value for the result code. Often
1478 * Activity.RESULT_OK.
1479 * @param initialData An initial value for the result data. Often
1480 * null.
1481 * @param initialExtras An initial value for the result extras. Often
1482 * null.
1483 *
1484 * @see #sendBroadcast(Intent)
1485 * @see #sendBroadcast(Intent, String)
1486 * @see #sendOrderedBroadcast(Intent, String)
1487 * @see #sendStickyBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001488 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 * @see android.content.BroadcastReceiver
1490 * @see #registerReceiver
1491 * @see android.app.Activity#RESULT_OK
1492 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001493 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);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497
1498 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001499 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1500 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001501 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001502 * @hide
1503 */
1504 public abstract void sendOrderedBroadcast(Intent intent,
1505 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1506 Handler scheduler, int initialCode, String initialData,
1507 Bundle initialExtras);
1508
1509 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001510 * 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.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001514 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001515 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001516 * @see #sendBroadcast(Intent)
1517 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001518 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001519
1520 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001521 * 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.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001525 *
1526 * @param intent The Intent to broadcast; all receivers matching this
1527 * Intent will receive the broadcast.
1528 * @param user UserHandle to send the intent to.
1529 * @param receiverPermission (optional) String naming a permission that
1530 * a receiver must hold in order to receive your broadcast.
1531 * If null, no permission is required.
1532 *
1533 * @see #sendBroadcast(Intent, String)
1534 */
1535 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001536 @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001537
1538 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001539 * Version of
1540 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1541 * that allows you to specify the
1542 * user the broadcast will be sent to. This is not available to applications
1543 * that are not pre-installed on the system image. Using it requires holding
1544 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001545 *
1546 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1547 *
1548 * @param intent The Intent to broadcast; all receivers matching this
1549 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001550 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001551 * @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.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001554 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1555 * receiver of the broadcast.
1556 * @param scheduler A custom Handler with which to schedule the
1557 * resultReceiver callback; if null it will be
1558 * scheduled in the Context's main thread.
1559 * @param initialCode An initial value for the result code. Often
1560 * Activity.RESULT_OK.
1561 * @param initialData An initial value for the result data. Often
1562 * null.
1563 * @param initialExtras An initial value for the result extras. Often
1564 * null.
1565 *
1566 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1567 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001568 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001569 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1570 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1571 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001572
1573 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07001574 * Similar to above but takes an appOp as well, to enforce restrictions.
1575 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1576 * BroadcastReceiver, Handler, int, String, Bundle)
1577 * @hide
1578 */
1579 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1580 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1581 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1582 @Nullable Bundle initialExtras);
1583
1584 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1586 * Intent you are sending stays around after the broadcast is complete,
1587 * so that others can quickly retrieve that data through the return
1588 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1589 * all other ways, this behaves the same as
1590 * {@link #sendBroadcast(Intent)}.
1591 *
1592 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1593 * permission in order to use this API. If you do not hold that
1594 * permission, {@link SecurityException} will be thrown.
1595 *
1596 * @param intent The Intent to broadcast; all receivers matching this
1597 * Intent will receive the broadcast, and the Intent will be held to
1598 * be re-broadcast to future receivers.
1599 *
1600 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001601 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 */
1603 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001604
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001605 /**
1606 * Version of {@link #sendStickyBroadcast} that allows you to
1607 * receive data back from the broadcast. This is accomplished by
1608 * supplying your own BroadcastReceiver when calling, which will be
1609 * treated as a final receiver at the end of the broadcast -- its
1610 * {@link BroadcastReceiver#onReceive} method will be called with
1611 * the result values collected from the other receivers. The broadcast will
1612 * be serialized in the same way as calling
1613 * {@link #sendOrderedBroadcast(Intent, String)}.
1614 *
1615 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1616 * asynchronous; it will return before
1617 * resultReceiver.onReceive() is called. Note that the sticky data
1618 * stored is only the data you initially supply to the broadcast, not
1619 * the result of any changes made by the receivers.
1620 *
1621 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1622 *
1623 * @param intent The Intent to broadcast; all receivers matching this
1624 * Intent will receive the broadcast.
1625 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1626 * receiver of the broadcast.
1627 * @param scheduler A custom Handler with which to schedule the
1628 * resultReceiver callback; if null it will be
1629 * scheduled in the Context's main thread.
1630 * @param initialCode An initial value for the result code. Often
1631 * Activity.RESULT_OK.
1632 * @param initialData An initial value for the result data. Often
1633 * null.
1634 * @param initialExtras An initial value for the result extras. Often
1635 * null.
1636 *
1637 * @see #sendBroadcast(Intent)
1638 * @see #sendBroadcast(Intent, String)
1639 * @see #sendOrderedBroadcast(Intent, String)
1640 * @see #sendStickyBroadcast(Intent)
1641 * @see android.content.BroadcastReceiver
1642 * @see #registerReceiver
1643 * @see android.app.Activity#RESULT_OK
1644 */
1645 public abstract void sendStickyOrderedBroadcast(Intent intent,
1646 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001647 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1648 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001649
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 /**
1651 * Remove the data previously sent with {@link #sendStickyBroadcast},
1652 * so that it is as if the sticky broadcast had never happened.
1653 *
1654 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1655 * permission in order to use this API. If you do not hold that
1656 * permission, {@link SecurityException} will be thrown.
1657 *
1658 * @param intent The Intent that was previously broadcast.
1659 *
1660 * @see #sendStickyBroadcast
1661 */
1662 public abstract void removeStickyBroadcast(Intent intent);
1663
1664 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001665 * Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
1666 * user the broadcast will be sent to. This is not available to applications
1667 * that are not pre-installed on the system image. Using it requires holding
1668 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001669 *
1670 * @param intent The Intent to broadcast; all receivers matching this
1671 * Intent will receive the broadcast, and the Intent will be held to
1672 * be re-broadcast to future receivers.
1673 * @param user UserHandle to send the intent to.
1674 *
1675 * @see #sendBroadcast(Intent)
1676 */
1677 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1678
1679 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001680 * Version of
1681 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1682 * that allows you to specify the
1683 * user the broadcast will be sent to. This is not available to applications
1684 * that are not pre-installed on the system image. Using it requires holding
1685 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001686 *
1687 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1688 *
1689 * @param intent The Intent to broadcast; all receivers matching this
1690 * Intent will receive the broadcast.
1691 * @param user UserHandle to send the intent to.
1692 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1693 * receiver of the broadcast.
1694 * @param scheduler A custom Handler with which to schedule the
1695 * resultReceiver callback; if null it will be
1696 * scheduled in the Context's main thread.
1697 * @param initialCode An initial value for the result code. Often
1698 * Activity.RESULT_OK.
1699 * @param initialData An initial value for the result data. Often
1700 * null.
1701 * @param initialExtras An initial value for the result extras. Often
1702 * null.
1703 *
1704 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1705 */
1706 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1707 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001708 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1709 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001710
1711 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001712 * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
1713 * user the broadcast will be sent to. This is not available to applications
1714 * that are not pre-installed on the system image. Using it requires holding
1715 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001716 *
1717 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1718 * permission in order to use this API. If you do not hold that
1719 * permission, {@link SecurityException} will be thrown.
1720 *
1721 * @param intent The Intent that was previously broadcast.
1722 * @param user UserHandle to remove the sticky broadcast from.
1723 *
1724 * @see #sendStickyBroadcastAsUser
1725 */
1726 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1727
1728 /**
Chris Tatea34df8a2009-04-02 23:15:58 -07001729 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 * <var>receiver</var> will be called with any broadcast Intent that
1731 * matches <var>filter</var>, in the main application thread.
1732 *
1733 * <p>The system may broadcast Intents that are "sticky" -- these stay
1734 * around after the broadcast as finished, to be sent to any later
1735 * registrations. If your IntentFilter matches one of these sticky
1736 * Intents, that Intent will be returned by this function
1737 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1738 * been broadcast.
1739 *
1740 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1741 * in which case each of these will be sent to <var>receiver</var>. In
1742 * this case, only one of these can be returned directly by the function;
1743 * which of these that is returned is arbitrarily decided by the system.
1744 *
1745 * <p>If you know the Intent your are registering for is sticky, you can
1746 * supply null for your <var>receiver</var>. In this case, no receiver is
1747 * registered -- the function simply returns the sticky Intent that
1748 * matches <var>filter</var>. In the case of multiple matches, the same
1749 * rules as described above apply.
1750 *
1751 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1752 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001753 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1754 * registered with this method will correctly respect the
1755 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1756 * Prior to that, it would be ignored and delivered to all matching registered
1757 * receivers. Be careful if using this for security.</p>
1758 *
Chris Tatea34df8a2009-04-02 23:15:58 -07001759 * <p class="note">Note: this method <em>cannot be called from a
1760 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1761 * that is declared in an application's manifest. It is okay, however, to call
1762 * this method from another BroadcastReceiver that has itself been registered
1763 * at run time with {@link #registerReceiver}, since the lifetime of such a
1764 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001765 *
1766 * @param receiver The BroadcastReceiver to handle the broadcast.
1767 * @param filter Selects the Intent broadcasts to be received.
1768 *
1769 * @return The first sticky intent found that matches <var>filter</var>,
1770 * or null if there are none.
1771 *
1772 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1773 * @see #sendBroadcast
1774 * @see #unregisterReceiver
1775 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001776 @Nullable
1777 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001778 IntentFilter filter);
1779
1780 /**
1781 * Register to receive intent broadcasts, to run in the context of
1782 * <var>scheduler</var>. See
1783 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1784 * information. This allows you to enforce permissions on who can
1785 * broadcast intents to your receiver, or have the receiver run in
1786 * a different thread than the main application thread.
1787 *
1788 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1789 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001790 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1791 * registered with this method will correctly respect the
1792 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1793 * Prior to that, it would be ignored and delivered to all matching registered
1794 * receivers. Be careful if using this for security.</p>
1795 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 * @param receiver The BroadcastReceiver to handle the broadcast.
1797 * @param filter Selects the Intent broadcasts to be received.
1798 * @param broadcastPermission String naming a permissions that a
1799 * broadcaster must hold in order to send an Intent to you. If null,
1800 * no permission is required.
1801 * @param scheduler Handler identifying the thread that will receive
1802 * the Intent. If null, the main thread of the process will be used.
1803 *
1804 * @return The first sticky intent found that matches <var>filter</var>,
1805 * or null if there are none.
1806 *
1807 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1808 * @see #sendBroadcast
1809 * @see #unregisterReceiver
1810 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001811 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001812 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001813 IntentFilter filter, @Nullable String broadcastPermission,
1814 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07001815
1816 /**
1817 * @hide
1818 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1819 * but for a specific user. This receiver will receiver broadcasts that
1820 * are sent to the requested user. It
1821 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1822 * permission.
1823 *
1824 * @param receiver The BroadcastReceiver to handle the broadcast.
1825 * @param user UserHandle to send the intent to.
1826 * @param filter Selects the Intent broadcasts to be received.
1827 * @param broadcastPermission String naming a permissions that a
1828 * broadcaster must hold in order to send an Intent to you. If null,
1829 * no permission is required.
1830 * @param scheduler Handler identifying the thread that will receive
1831 * the Intent. If null, the main thread of the process will be used.
1832 *
1833 * @return The first sticky intent found that matches <var>filter</var>,
1834 * or null if there are none.
1835 *
1836 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1837 * @see #sendBroadcast
1838 * @see #unregisterReceiver
1839 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001840 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07001841 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001842 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1843 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001844
1845 /**
1846 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1847 * filters that have been registered for this BroadcastReceiver will be
1848 * removed.
1849 *
1850 * @param receiver The BroadcastReceiver to unregister.
1851 *
1852 * @see #registerReceiver
1853 */
1854 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1855
1856 /**
1857 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07001858 * should contain either contain the complete class name of a specific service
1859 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07001860 * Intent is less specified, it log a warning about this and which of the
1861 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 * is not already running, it will be instantiated and started (creating a
1863 * process for it if needed); if it is running then it remains running.
1864 *
1865 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001866 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 * with the <var>intent</var> given here. This provides a convenient way
1868 * to submit jobs to a service without having to bind and call on to its
1869 * interface.
1870 *
1871 * <p>Using startService() overrides the default service lifetime that is
1872 * managed by {@link #bindService}: it requires the service to remain
1873 * running until {@link #stopService} is called, regardless of whether
1874 * any clients are connected to it. Note that calls to startService()
1875 * are not nesting: no matter how many times you call startService(),
1876 * a single call to {@link #stopService} will stop it.
1877 *
1878 * <p>The system attempts to keep running services around as much as
1879 * possible. The only time they should be stopped is if the current
1880 * foreground application is using so many resources that the service needs
1881 * to be killed. If any errors happen in the service's process, it will
1882 * automatically be restarted.
1883 *
1884 * <p>This function will throw {@link SecurityException} if you do not
1885 * have permission to start the given service.
1886 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07001887 * @param service Identifies the service to be started. The Intent must be either
1888 * fully explicit (supplying a component name) or specify a specific package
1889 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001890 * may be included in the Intent extras to supply arguments along with
1891 * this specific start call.
1892 *
1893 * @return If the service is being started or is already running, the
1894 * {@link ComponentName} of the actual service that was started is
1895 * returned; else if the service does not exist null is returned.
1896 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001897 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 *
1899 * @see #stopService
1900 * @see #bindService
1901 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001902 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 public abstract ComponentName startService(Intent service);
1904
1905 /**
1906 * Request that a given application service be stopped. If the service is
1907 * not running, nothing happens. Otherwise it is stopped. Note that calls
1908 * to startService() are not counted -- this stops the service no matter
1909 * how many times it was started.
1910 *
1911 * <p>Note that if a stopped service still has {@link ServiceConnection}
1912 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1913 * not be destroyed until all of these bindings are removed. See
1914 * the {@link android.app.Service} documentation for more details on a
1915 * service's lifecycle.
1916 *
1917 * <p>This function will throw {@link SecurityException} if you do not
1918 * have permission to stop the given service.
1919 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07001920 * @param service Description of the service to be stopped. The Intent must be either
1921 * fully explicit (supplying a component name) or specify a specific package
1922 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923 *
1924 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04001925 * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001926 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001927 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 *
1929 * @see #startService
1930 */
1931 public abstract boolean stopService(Intent service);
1932
1933 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001934 * @hide like {@link #startService(Intent)} but for a specific user.
1935 */
1936 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1937
1938 /**
1939 * @hide like {@link #stopService(Intent)} but for a specific user.
1940 */
1941 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08001942
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001943 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 * Connect to an application service, creating it if needed. This defines
1945 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001946 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 * told if it dies and restarts. The service will be considered required
1948 * by the system only for as long as the calling context exists. For
1949 * example, if this Context is an Activity that is stopped, the service will
1950 * not be required to continue running until the Activity is resumed.
1951 *
1952 * <p>This function will throw {@link SecurityException} if you do not
1953 * have permission to bind to the given service.
1954 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001955 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001956 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001957 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 * {@link #startService} with the arguments containing the command to be
1959 * sent, with the service calling its
1960 * {@link android.app.Service#stopSelf(int)} method when done executing
1961 * that command. See the API demo App/Service/Service Start Arguments
1962 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001963 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1965 * is tied to another object (the one that registered it).</p>
1966 *
1967 * @param service Identifies the service to connect to. The Intent may
1968 * specify either an explicit component name, or a logical
1969 * description (action, category, etc) to match an
1970 * {@link IntentFilter} published by a service.
1971 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07001972 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07001973 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07001974 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1975 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1976 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1977 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04001978 * @return If you have successfully bound to the service, {@code true} is returned;
1979 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001980 * receive the service object.
1981 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001982 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001983 *
1984 * @see #unbindService
1985 * @see #startService
1986 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07001987 * @see #BIND_DEBUG_UNBIND
1988 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001990 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
1991 @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992
1993 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001994 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001995 * argument for use by system server and other multi-user aware code.
1996 * @hide
1997 */
Amith Yamasani27b89e62013-01-16 12:30:11 -08001998 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001999 throw new RuntimeException("Not implemented. Must override in a subclass.");
2000 }
2001
2002 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 * Disconnect from an application service. You will no longer receive
2004 * calls as the service is restarted, and the service is now allowed to
2005 * stop at any time.
2006 *
2007 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002008 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 *
2010 * @see #bindService
2011 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002012 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013
2014 /**
2015 * Start executing an {@link android.app.Instrumentation} class. The given
2016 * Instrumentation component will be run by killing its target application
2017 * (if currently running), starting the target process, instantiating the
2018 * instrumentation component, and then letting it drive the application.
2019 *
2020 * <p>This function is not synchronous -- it returns as soon as the
2021 * instrumentation has started and while it is running.
2022 *
2023 * <p>Instrumentation is normally only allowed to run against a package
2024 * that is either unsigned or signed with a signature that the
2025 * the instrumentation package is also signed with (ensuring the target
2026 * trusts the instrumentation).
2027 *
2028 * @param className Name of the Instrumentation component to be run.
2029 * @param profileFile Optional path to write profiling data as the
2030 * instrumentation runs, or null for no profiling.
2031 * @param arguments Additional optional arguments to pass to the
2032 * instrumentation, or null.
2033 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002034 * @return {@code true} if the instrumentation was successfully started,
2035 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002037 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2038 @Nullable String profileFile, @Nullable Bundle arguments);
2039
2040 /** @hide */
2041 @StringDef({
2042 POWER_SERVICE,
2043 WINDOW_SERVICE,
2044 LAYOUT_INFLATER_SERVICE,
2045 ACCOUNT_SERVICE,
2046 ACTIVITY_SERVICE,
2047 ALARM_SERVICE,
2048 NOTIFICATION_SERVICE,
2049 ACCESSIBILITY_SERVICE,
2050 CAPTIONING_SERVICE,
2051 KEYGUARD_SERVICE,
2052 LOCATION_SERVICE,
2053 //@hide: COUNTRY_DETECTOR,
2054 SEARCH_SERVICE,
2055 SENSOR_SERVICE,
2056 STORAGE_SERVICE,
2057 WALLPAPER_SERVICE,
2058 VIBRATOR_SERVICE,
2059 //@hide: STATUS_BAR_SERVICE,
2060 CONNECTIVITY_SERVICE,
2061 //@hide: UPDATE_LOCK_SERVICE,
2062 //@hide: NETWORKMANAGEMENT_SERVICE,
2063 //@hide: NETWORK_STATS_SERVICE,
2064 //@hide: NETWORK_POLICY_SERVICE,
2065 WIFI_SERVICE,
Yuhao Zhenga4864472014-04-10 11:45:42 -07002066 WIFI_PASSPOINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002067 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002068 WIFI_SCANNING_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002069 //@hide: ETHERNET_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002070 NSD_SERVICE,
2071 AUDIO_SERVICE,
2072 MEDIA_ROUTER_SERVICE,
2073 TELEPHONY_SERVICE,
Yorke Leeb4ce1432014-06-09 13:53:23 -07002074 TELECOMM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002075 CLIPBOARD_SERVICE,
2076 INPUT_METHOD_SERVICE,
2077 TEXT_SERVICES_MANAGER_SERVICE,
2078 //@hide: APPWIDGET_SERVICE,
2079 //@hide: BACKUP_SERVICE,
2080 DROPBOX_SERVICE,
2081 DEVICE_POLICY_SERVICE,
2082 UI_MODE_SERVICE,
2083 DOWNLOAD_SERVICE,
2084 NFC_SERVICE,
2085 BLUETOOTH_SERVICE,
2086 //@hide: SIP_SERVICE,
2087 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002088 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002089 //@hide: SERIAL_SERVICE,
2090 INPUT_SERVICE,
2091 DISPLAY_SERVICE,
2092 //@hide: SCHEDULING_POLICY_SERVICE,
2093 USER_SERVICE,
2094 //@hide: APP_OPS_SERVICE
2095 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002096 PRINT_SERVICE,
2097 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002098 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002099 JOB_SCHEDULER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002100 })
2101 @Retention(RetentionPolicy.SOURCE)
2102 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103
2104 /**
2105 * Return the handle to a system-level service by name. The class of the
2106 * returned object varies by the requested name. Currently available names
2107 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002108 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 * <dl>
2110 * <dt> {@link #WINDOW_SERVICE} ("window")
2111 * <dd> The top-level window manager in which you can place custom
2112 * windows. The returned object is a {@link android.view.WindowManager}.
2113 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2114 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2115 * in this context.
2116 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2117 * <dd> A {@link android.app.ActivityManager} for interacting with the
2118 * global activity state of the system.
2119 * <dt> {@link #POWER_SERVICE} ("power")
2120 * <dd> A {@link android.os.PowerManager} for controlling power
2121 * management.
2122 * <dt> {@link #ALARM_SERVICE} ("alarm")
2123 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2124 * time of your choosing.
2125 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2126 * <dd> A {@link android.app.NotificationManager} for informing the user
2127 * of background events.
2128 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2129 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2130 * <dt> {@link #LOCATION_SERVICE} ("location")
2131 * <dd> A {@link android.location.LocationManager} for controlling location
2132 * (e.g., GPS) updates.
2133 * <dt> {@link #SEARCH_SERVICE} ("search")
2134 * <dd> A {@link android.app.SearchManager} for handling search.
2135 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2136 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2137 * hardware.
2138 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2139 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2140 * handling management of network connections.
2141 * <dt> {@link #WIFI_SERVICE} ("wifi")
2142 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2143 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002144 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2145 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2146 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2148 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2149 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002150 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2151 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002152 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002153 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002154 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002155 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002156 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2157 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002159 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 * <p>Note: System services obtained via this API may be closely associated with
2161 * the Context in which they are obtained from. In general, do not share the
2162 * service objects between various different contexts (Activities, Applications,
2163 * Services, Providers, etc.)
2164 *
2165 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002166 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002168 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 * @see #WINDOW_SERVICE
2170 * @see android.view.WindowManager
2171 * @see #LAYOUT_INFLATER_SERVICE
2172 * @see android.view.LayoutInflater
2173 * @see #ACTIVITY_SERVICE
2174 * @see android.app.ActivityManager
2175 * @see #POWER_SERVICE
2176 * @see android.os.PowerManager
2177 * @see #ALARM_SERVICE
2178 * @see android.app.AlarmManager
2179 * @see #NOTIFICATION_SERVICE
2180 * @see android.app.NotificationManager
2181 * @see #KEYGUARD_SERVICE
2182 * @see android.app.KeyguardManager
2183 * @see #LOCATION_SERVICE
2184 * @see android.location.LocationManager
2185 * @see #SEARCH_SERVICE
2186 * @see android.app.SearchManager
2187 * @see #SENSOR_SERVICE
2188 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002189 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002190 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 * @see #VIBRATOR_SERVICE
2192 * @see android.os.Vibrator
2193 * @see #CONNECTIVITY_SERVICE
2194 * @see android.net.ConnectivityManager
2195 * @see #WIFI_SERVICE
2196 * @see android.net.wifi.WifiManager
2197 * @see #AUDIO_SERVICE
2198 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002199 * @see #MEDIA_ROUTER_SERVICE
2200 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 * @see #TELEPHONY_SERVICE
2202 * @see android.telephony.TelephonyManager
Santos Cordonf90186d2014-07-01 13:35:35 -07002203 * @see #PHONE_SERVICE
2204 * @see android.phone.PhoneManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 * @see #INPUT_METHOD_SERVICE
2206 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002207 * @see #UI_MODE_SERVICE
2208 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002209 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002210 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002211 * @see #BATTERY_SERVICE
2212 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002213 * @see #JOB_SCHEDULER_SERVICE
2214 * @see android.app.job.JobScheduler
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002216 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002217
2218 /**
2219 * Use with {@link #getSystemService} to retrieve a
2220 * {@link android.os.PowerManager} for controlling power management,
2221 * including "wake locks," which let you keep the device on while
2222 * you're running long tasks.
2223 */
2224 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002225
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002226 /**
2227 * Use with {@link #getSystemService} to retrieve a
2228 * {@link android.view.WindowManager} for accessing the system's window
2229 * manager.
2230 *
2231 * @see #getSystemService
2232 * @see android.view.WindowManager
2233 */
2234 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 /**
2237 * Use with {@link #getSystemService} to retrieve a
2238 * {@link android.view.LayoutInflater} for inflating layout resources in this
2239 * context.
2240 *
2241 * @see #getSystemService
2242 * @see android.view.LayoutInflater
2243 */
2244 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002245
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002246 /**
2247 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002248 * {@link android.accounts.AccountManager} for receiving intents at a
2249 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002250 *
2251 * @see #getSystemService
2252 * @see android.accounts.AccountManager
2253 */
2254 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002255
Fred Quintana60307342009-03-24 22:48:12 -07002256 /**
2257 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 * {@link android.app.ActivityManager} for interacting with the global
2259 * system state.
2260 *
2261 * @see #getSystemService
2262 * @see android.app.ActivityManager
2263 */
2264 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002266 /**
2267 * Use with {@link #getSystemService} to retrieve a
2268 * {@link android.app.AlarmManager} for receiving intents at a
2269 * time of your choosing.
2270 *
2271 * @see #getSystemService
2272 * @see android.app.AlarmManager
2273 */
2274 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002276 /**
2277 * Use with {@link #getSystemService} to retrieve a
2278 * {@link android.app.NotificationManager} for informing the user of
2279 * background events.
2280 *
2281 * @see #getSystemService
2282 * @see android.app.NotificationManager
2283 */
2284 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286 /**
2287 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002288 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2289 * feedback for UI events through the registered event listeners.
2290 *
2291 * @see #getSystemService
2292 * @see android.view.accessibility.AccessibilityManager
2293 */
2294 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002295
svetoslavganov75986cf2009-05-14 22:28:01 -07002296 /**
2297 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002298 * {@link android.view.accessibility.CaptioningManager} for obtaining
2299 * captioning properties and listening for changes in captioning
2300 * preferences.
2301 *
2302 * @see #getSystemService
2303 * @see android.view.accessibility.CaptioningManager
2304 */
2305 public static final String CAPTIONING_SERVICE = "captioning";
2306
2307 /**
2308 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 * {@link android.app.NotificationManager} for controlling keyguard.
2310 *
2311 * @see #getSystemService
2312 * @see android.app.KeyguardManager
2313 */
2314 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002316 /**
2317 * Use with {@link #getSystemService} to retrieve a {@link
2318 * android.location.LocationManager} for controlling location
2319 * updates.
2320 *
2321 * @see #getSystemService
2322 * @see android.location.LocationManager
2323 */
2324 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002325
2326 /**
2327 * Use with {@link #getSystemService} to retrieve a
2328 * {@link android.location.CountryDetector} for detecting the country that
2329 * the user is in.
2330 *
2331 * @hide
2332 */
2333 public static final String COUNTRY_DETECTOR = "country_detector";
2334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 /**
2336 * Use with {@link #getSystemService} to retrieve a {@link
2337 * android.app.SearchManager} for handling searches.
2338 *
2339 * @see #getSystemService
2340 * @see android.app.SearchManager
2341 */
2342 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 /**
2345 * Use with {@link #getSystemService} to retrieve a {@link
2346 * android.hardware.SensorManager} for accessing sensors.
2347 *
2348 * @see #getSystemService
2349 * @see android.hardware.SensorManager
2350 */
2351 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07002352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 /**
San Mehatc9d81752010-02-01 10:23:27 -08002354 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07002355 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08002356 * functions.
2357 *
2358 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08002359 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08002360 */
2361 public static final String STORAGE_SERVICE = "storage";
2362
2363 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002364 * Use with {@link #getSystemService} to retrieve a
2365 * com.android.server.WallpaperService for accessing wallpapers.
2366 *
2367 * @see #getSystemService
2368 */
2369 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07002370
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 /**
2372 * Use with {@link #getSystemService} to retrieve a {@link
2373 * android.os.Vibrator} for interacting with the vibration hardware.
2374 *
2375 * @see #getSystemService
2376 * @see android.os.Vibrator
2377 */
2378 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002379
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 /**
2381 * Use with {@link #getSystemService} to retrieve a {@link
2382 * android.app.StatusBarManager} for interacting with the status bar.
2383 *
2384 * @see #getSystemService
2385 * @see android.app.StatusBarManager
2386 * @hide
2387 */
2388 public static final String STATUS_BAR_SERVICE = "statusbar";
2389
2390 /**
2391 * Use with {@link #getSystemService} to retrieve a {@link
2392 * android.net.ConnectivityManager} for handling management of
2393 * network connections.
2394 *
2395 * @see #getSystemService
2396 * @see android.net.ConnectivityManager
2397 */
2398 public static final String CONNECTIVITY_SERVICE = "connectivity";
2399
2400 /**
2401 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002402 * android.os.IUpdateLock} for managing runtime sequences that
2403 * must not be interrupted by headless OTA application or similar.
2404 *
2405 * @hide
2406 * @see #getSystemService
2407 * @see android.os.UpdateLock
2408 */
2409 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2410
2411 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002412 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07002413 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08002414 */
2415 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2416
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002417 /** {@hide} */
Jeff Sharkey75279902011-05-24 18:39:45 -07002418 public static final String NETWORK_STATS_SERVICE = "netstats";
2419 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002420 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2421
San Mehatd1df8ac2010-01-26 06:17:26 -08002422 /**
2423 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 * android.net.wifi.WifiManager} for handling management of
2425 * Wi-Fi access.
2426 *
2427 * @see #getSystemService
2428 * @see android.net.wifi.WifiManager
2429 */
2430 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 /**
repo sync55bc5f32011-06-24 14:23:07 -07002433 * Use with {@link #getSystemService} to retrieve a {@link
Roger Chang7fee7232014-05-15 14:46:49 -07002434 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
Yuhao Zhenga4864472014-04-10 11:45:42 -07002435 * Wi-Fi passpoint access.
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002436 *
2437 * @see #getSystemService
Roger Chang7fee7232014-05-15 14:46:49 -07002438 * @see android.net.wifi.passpoint.WifiPasspointManager
Yuhao Zheng0cb59f22014-05-27 10:35:02 -07002439 * @hide
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002440 */
Yuhao Zhenga4864472014-04-10 11:45:42 -07002441 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002442
2443 /**
2444 * Use with {@link #getSystemService} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07002445 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002446 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002447 *
2448 * @see #getSystemService
2449 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002450 */
2451 public static final String WIFI_P2P_SERVICE = "wifip2p";
2452
2453 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002454 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002455 * android.net.wifi.WifiScanner} for scanning the wifi universe
2456 *
2457 * @see #getSystemService
2458 * @see android.net.wifi.WifiScanner
2459 * @hide
2460 */
Wei Wang35d552f2014-07-08 21:37:01 -07002461 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002462 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2463
2464 /**
2465 * Use with {@link #getSystemService} to retrieve a {@link
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002466 * android.net.ethernet.EthernetManager} for handling management of
2467 * Ethernet access.
2468 *
2469 * @see #getSystemService
2470 * @see android.net.ethernet.EthernetManager
2471 *
2472 * @hide
2473 */
2474 public static final String ETHERNET_SERVICE = "ethernet";
2475
2476 /**
2477 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002478 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002479 * discovery
2480 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002481 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002482 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002483 */
2484 public static final String NSD_SERVICE = "servicediscovery";
2485
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002486 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 * Use with {@link #getSystemService} to retrieve a
2488 * {@link android.media.AudioManager} for handling management of volume,
2489 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002490 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002491 * @see #getSystemService
2492 * @see android.media.AudioManager
2493 */
2494 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002495
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 /**
2497 * Use with {@link #getSystemService} to retrieve a
Jim Miller08fa40c2014-04-29 18:18:47 -07002498 * {@link android.service.fingerprint.FingerprintManager} for handling management
2499 * of fingerprints.
2500 *
2501 * @see #getSystemService
2502 * @see android.app.FingerprintManager
2503 */
2504 public static final String FINGERPRINT_SERVICE = "fingerprint";
2505
2506 /**
2507 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002508 * {@link android.media.MediaRouter} for controlling and managing
2509 * routing of media.
2510 *
2511 * @see #getSystemService
2512 * @see android.media.MediaRouter
2513 */
2514 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2515
2516 /**
2517 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07002518 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08002519 *
2520 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07002521 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08002522 */
2523 public static final String MEDIA_SESSION_SERVICE = "media_session";
2524
2525 /**
2526 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 * {@link android.telephony.TelephonyManager} for handling management the
2528 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002529 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 * @see #getSystemService
2531 * @see android.telephony.TelephonyManager
2532 */
2533 public static final String TELEPHONY_SERVICE = "phone";
2534
2535 /**
2536 * Use with {@link #getSystemService} to retrieve a
Yorke Leeb4ce1432014-06-09 13:53:23 -07002537 * {@link android.telecomm.TelecommManager} to manage telecomm-related features
2538 * of the device.
2539 *
2540 * @see #getSystemService
2541 * @see android.telecomm.TelecommManager
Santos Cordonf90186d2014-07-01 13:35:35 -07002542 * @hide
Yorke Leeb4ce1432014-06-09 13:53:23 -07002543 */
2544 public static final String TELECOMM_SERVICE = "telecomm";
2545
2546 /**
2547 * Use with {@link #getSystemService} to retrieve a
Santos Cordonf90186d2014-07-01 13:35:35 -07002548 * {@link android.phone.PhoneManager} to manage phone-related features
2549 * of the device.
2550 *
2551 * @see #getSystemService
2552 * @see android.phone.PhoneManager
2553 */
2554 public static final String PHONE_SERVICE = "phone_service"; // "phone" used by telephony.
2555
2556 /**
2557 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 * {@link android.text.ClipboardManager} for accessing and modifying
2559 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002560 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 * @see #getSystemService
2562 * @see android.text.ClipboardManager
2563 */
2564 public static final String CLIPBOARD_SERVICE = "clipboard";
2565
2566 /**
Scott Main4b5da682010-10-21 11:49:12 -07002567 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2569 * methods.
2570 *
2571 * @see #getSystemService
2572 */
2573 public static final String INPUT_METHOD_SERVICE = "input_method";
2574
2575 /**
2576 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002577 * {@link android.view.textservice.TextServicesManager} for accessing
2578 * text services.
2579 *
2580 * @see #getSystemService
2581 */
2582 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2583
2584 /**
2585 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002586 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002587 *
2588 * @hide
2589 * @see #getSystemService
2590 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002591 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002592
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07002594 * Official published name of the (internal) voice interaction manager service.
2595 *
2596 * @hide
2597 * @see #getSystemService
2598 */
2599 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2600
2601 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002602 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002603 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002604 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002605 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002606 *
Christopher Tate487529a2009-04-29 14:03:25 -07002607 * @see #getSystemService
2608 */
2609 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002610
2611 /**
2612 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002613 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002614 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002615 * @see #getSystemService
2616 */
2617 public static final String DROPBOX_SERVICE = "dropbox";
2618
Christopher Tate487529a2009-04-29 14:03:25 -07002619 /**
Scott Main4b5da682010-10-21 11:49:12 -07002620 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002621 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002622 * device policy management.
2623 *
2624 * @see #getSystemService
2625 */
2626 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2627
2628 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002629 * Use with {@link #getSystemService} to retrieve a
2630 * {@link android.app.UiModeManager} for controlling UI modes.
2631 *
2632 * @see #getSystemService
2633 */
2634 public static final String UI_MODE_SERVICE = "uimode";
2635
2636 /**
Steve Howarda2709362010-07-02 17:12:48 -07002637 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002638 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002639 *
2640 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002641 */
2642 public static final String DOWNLOAD_SERVICE = "download";
2643
2644 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002645 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08002646 * {@link android.os.BatteryManager} for managing battery state.
2647 *
2648 * @see #getSystemService
2649 */
2650 public static final String BATTERY_SERVICE = "batterymanager";
2651
2652 /**
2653 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002654 * {@link android.nfc.NfcManager} for using NFC.
2655 *
2656 * @see #getSystemService
2657 */
2658 public static final String NFC_SERVICE = "nfc";
2659
2660 /**
2661 * Use with {@link #getSystemService} to retrieve a
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002662 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2663 *
2664 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002665 */
2666 public static final String BLUETOOTH_SERVICE = "bluetooth";
2667
2668 /**
2669 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002670 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2671 *
2672 * @see #getSystemService
2673 */
2674 /** @hide */
2675 public static final String SIP_SERVICE = "sip";
2676
2677 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002678 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002679 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002680 * and for controlling this device's behavior as a USB device.
2681 *
2682 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04002683 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002684 */
2685 public static final String USB_SERVICE = "usb";
2686
2687 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002688 * Use with {@link #getSystemService} to retrieve a {@link
2689 * android.hardware.SerialManager} for access to serial ports.
2690 *
2691 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002692 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002693 *
2694 * @hide
2695 */
2696 public static final String SERIAL_SERVICE = "serial";
2697
2698 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002699 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09002700 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2701 * HDMI-CEC protocol.
2702 *
2703 * @see #getSystemService
2704 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002705 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09002706 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002707 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09002708 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09002709
2710 /**
2711 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002712 * {@link android.hardware.input.InputManager} for interacting with input devices.
2713 *
2714 * @see #getSystemService
2715 * @see android.hardware.input.InputManager
2716 */
2717 public static final String INPUT_SERVICE = "input";
2718
2719 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002720 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002721 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2722 *
2723 * @see #getSystemService
2724 * @see android.hardware.display.DisplayManager
2725 */
2726 public static final String DISPLAY_SERVICE = "display";
2727
2728 /**
2729 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07002730 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2731 *
2732 * @see #getSystemService
2733 * @see android.os.UserManager
2734 */
2735 public static final String USER_SERVICE = "user";
2736
2737 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002738 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08002739 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
2740 * profiles of a user.
2741 *
2742 * @see #getSystemService
2743 * @see android.content.pm.LauncherApps
2744 */
2745 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
2746
2747 /**
2748 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07002749 * {@link android.content.RestrictionsManager} for retrieving application restrictions
2750 * and requesting permissions for restricted operations.
2751 * @see #getSystemService
2752 * @see android.content.RestrictionsManager
2753 */
2754 public static final String RESTRICTIONS_SERVICE = "restrictions";
2755
2756 /**
2757 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002758 * {@link android.app.AppOpsManager} for tracking application operations
2759 * on the device.
2760 *
2761 * @see #getSystemService
2762 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002763 */
2764 public static final String APP_OPS_SERVICE = "appops";
2765
2766 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002767 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07002768 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002769 * camera devices.
2770 *
2771 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07002772 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002773 */
2774 public static final String CAMERA_SERVICE = "camera";
2775
2776 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002777 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07002778 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002779 *
2780 * @see #getSystemService
2781 * @see android.print.PrintManager
2782 */
2783 public static final String PRINT_SERVICE = "print";
2784
2785 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07002786 * Use with {@link #getSystemService} to retrieve a
2787 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
2788 * signals from the device.
2789 *
2790 * @see #getSystemService
2791 * @see android.hardware.ConsumerIrManager
2792 */
2793 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
2794
2795 /**
Adrian Roos82142c22014-03-27 14:56:59 +01002796 * {@link android.app.trust.TrustManager} for managing trust agents.
2797 * @see #getSystemService
2798 * @see android.app.trust.TrustManager
2799 * @hide
2800 */
2801 public static final String TRUST_SERVICE = "trust";
2802
2803 /**
Jae Seo39570912014-02-20 18:23:25 -08002804 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07002805 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
2806 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08002807 *
2808 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07002809 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08002810 */
2811 public static final String TV_INPUT_SERVICE = "tv_input";
2812
2813 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07002814 * {@link android.net.NetworkScoreManager} for managing network scoring.
2815 * @see #getSystemService
2816 * @see android.net.NetworkScoreManager
2817 * @hide
2818 */
2819 public static final String NETWORK_SCORE_SERVICE = "network_score";
2820
2821 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07002822 * Use with {@link #getSystemService} to retrieve a {@link
2823 * android.app.UsageStatsManager} for interacting with the status bar.
2824 *
2825 * @see #getSystemService
2826 * @see android.app.UsageStatsManager
2827 * @hide
2828 */
2829 public static final String USAGE_STATS_SERVICE = "usagestats";
2830
2831 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07002832 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07002833 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07002834 * background tasks.
2835 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07002836 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07002837 */
Christopher Tate7060b042014-06-09 19:50:00 -07002838 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07002839
2840 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07002841 * Use with {@link #getSystemService} to retrieve a {@link
2842 * android.service.persistentdata.PersistentDataBlockManager} instance retrieving
2843 * a file descriptor for a persistent data block.
2844 * @see #getSystemService
2845 * @see android.service.persistentdata.PersistentDataBlockManager
2846 * @hide
2847 */
2848 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
2849
2850 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002851 * Determine whether the given permission is allowed for a particular
2852 * process and user ID running in the system.
2853 *
2854 * @param permission The name of the permission being checked.
2855 * @param pid The process ID being checked against. Must be > 0.
2856 * @param uid The user ID being checked against. A uid of 0 is the root
2857 * user, which will pass every permission check.
2858 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002859 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 * pid/uid is allowed that permission, or
2861 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2862 *
2863 * @see PackageManager#checkPermission(String, String)
2864 * @see #checkCallingPermission
2865 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002866 @PackageManager.PermissionResult
2867 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868
2869 /**
2870 * Determine whether the calling process of an IPC you are handling has been
2871 * granted a particular permission. This is basically the same as calling
2872 * {@link #checkPermission(String, int, int)} with the pid and uid returned
2873 * by {@link android.os.Binder#getCallingPid} and
2874 * {@link android.os.Binder#getCallingUid}. One important difference
2875 * is that if you are not currently processing an IPC, this function
2876 * will always fail. This is done to protect against accidentally
2877 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2878 * to avoid this protection.
2879 *
2880 * @param permission The name of the permission being checked.
2881 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002882 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883 * pid/uid is allowed that permission, or
2884 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2885 *
2886 * @see PackageManager#checkPermission(String, String)
2887 * @see #checkPermission
2888 * @see #checkCallingOrSelfPermission
2889 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002890 @PackageManager.PermissionResult
2891 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892
2893 /**
2894 * Determine whether the calling process of an IPC <em>or you</em> have been
2895 * granted a particular permission. This is the same as
2896 * {@link #checkCallingPermission}, except it grants your own permissions
2897 * if you are not currently processing an IPC. Use with care!
2898 *
2899 * @param permission The name of the permission being checked.
2900 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002901 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 * pid/uid is allowed that permission, or
2903 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2904 *
2905 * @see PackageManager#checkPermission(String, String)
2906 * @see #checkPermission
2907 * @see #checkCallingPermission
2908 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002909 @PackageManager.PermissionResult
2910 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911
2912 /**
2913 * If the given permission is not allowed for a particular process
2914 * and user ID running in the system, throw a {@link SecurityException}.
2915 *
2916 * @param permission The name of the permission being checked.
2917 * @param pid The process ID being checked against. Must be &gt; 0.
2918 * @param uid The user ID being checked against. A uid of 0 is the root
2919 * user, which will pass every permission check.
2920 * @param message A message to include in the exception if it is thrown.
2921 *
2922 * @see #checkPermission(String, int, int)
2923 */
2924 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07002925 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926
2927 /**
2928 * If the calling process of an IPC you are handling has not been
2929 * granted a particular permission, throw a {@link
2930 * SecurityException}. This is basically the same as calling
2931 * {@link #enforcePermission(String, int, int, String)} with the
2932 * pid and uid returned by {@link android.os.Binder#getCallingPid}
2933 * and {@link android.os.Binder#getCallingUid}. One important
2934 * difference is that if you are not currently processing an IPC,
2935 * this function will always throw the SecurityException. This is
2936 * done to protect against accidentally leaking permissions; you
2937 * can use {@link #enforceCallingOrSelfPermission} to avoid this
2938 * protection.
2939 *
2940 * @param permission The name of the permission being checked.
2941 * @param message A message to include in the exception if it is thrown.
2942 *
2943 * @see #checkCallingPermission(String)
2944 */
2945 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07002946 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947
2948 /**
2949 * If neither you nor the calling process of an IPC you are
2950 * handling has been granted a particular permission, throw a
2951 * {@link SecurityException}. This is the same as {@link
2952 * #enforceCallingPermission}, except it grants your own
2953 * permissions if you are not currently processing an IPC. Use
2954 * with care!
2955 *
2956 * @param permission The name of the permission being checked.
2957 * @param message A message to include in the exception if it is thrown.
2958 *
2959 * @see #checkCallingOrSelfPermission(String)
2960 */
2961 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07002962 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002963
2964 /**
2965 * Grant permission to access a specific Uri to another package, regardless
2966 * of whether that package has general permission to access the Uri's
2967 * content provider. This can be used to grant specific, temporary
2968 * permissions, typically in response to user interaction (such as the
2969 * user opening an attachment that you would like someone else to
2970 * display).
2971 *
2972 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2973 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2974 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2975 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
2976 * start an activity instead of this function directly. If you use this
2977 * function directly, you should be sure to call
2978 * {@link #revokeUriPermission} when the target should no longer be allowed
2979 * to access it.
2980 *
2981 * <p>To succeed, the content provider owning the Uri must have set the
2982 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
2983 * grantUriPermissions} attribute in its manifest or included the
2984 * {@link android.R.styleable#AndroidManifestGrantUriPermission
2985 * &lt;grant-uri-permissions&gt;} tag.
2986 *
2987 * @param toPackage The package you would like to allow to access the Uri.
2988 * @param uri The Uri you would like to grant access to.
2989 * @param modeFlags The desired access modes. Any combination of
2990 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07002991 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07002993 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
2994 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
2995 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
2996 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
2997 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 *
2999 * @see #revokeUriPermission
3000 */
3001 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003002 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003
3004 /**
3005 * Remove all permissions to access a particular content provider Uri
3006 * that were previously added with {@link #grantUriPermission}. The given
3007 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003008 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003010 * "content://foo". It will not remove any prefix grants that exist at a
3011 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 *
3013 * @param uri The Uri you would like to revoke access to.
3014 * @param modeFlags The desired access modes. Any combination of
3015 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3016 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3017 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3018 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3019 *
3020 * @see #grantUriPermission
3021 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003022 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023
3024 /**
3025 * Determine whether a particular process and user ID has been granted
3026 * permission to access a specific URI. This only checks for permissions
3027 * that have been explicitly granted -- if the given process/uid has
3028 * more general access to the URI's content provider then this check will
3029 * always fail.
3030 *
3031 * @param uri The uri that is being checked.
3032 * @param pid The process ID being checked against. Must be &gt; 0.
3033 * @param uid The user ID being checked against. A uid of 0 is the root
3034 * user, which will pass every permission check.
3035 * @param modeFlags The type of access to grant. May be one or both of
3036 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3037 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3038 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003039 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 * pid/uid is allowed to access that uri, or
3041 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3042 *
3043 * @see #checkCallingUriPermission
3044 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003045 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003046 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047
3048 /**
3049 * Determine whether the calling process and user ID has been
3050 * granted permission to access a specific URI. This is basically
3051 * the same as calling {@link #checkUriPermission(Uri, int, int,
3052 * int)} with the pid and uid returned by {@link
3053 * android.os.Binder#getCallingPid} and {@link
3054 * android.os.Binder#getCallingUid}. One important difference is
3055 * that if you are not currently processing an IPC, this function
3056 * will always fail.
3057 *
3058 * @param uri The uri that is being checked.
3059 * @param modeFlags The type of access to grant. May be one or both of
3060 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3061 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3062 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003063 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003064 * is allowed to access that uri, or
3065 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3066 *
3067 * @see #checkUriPermission(Uri, int, int, int)
3068 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003069 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070
3071 /**
3072 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3073 * permission to access a specific URI. This is the same as
3074 * {@link #checkCallingUriPermission}, except it grants your own permissions
3075 * if you are not currently processing an IPC. Use with care!
3076 *
3077 * @param uri The uri that is being checked.
3078 * @param modeFlags The type of access to grant. May be one or both of
3079 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3080 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3081 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003082 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083 * is allowed to access that uri, or
3084 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3085 *
3086 * @see #checkCallingUriPermission
3087 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003088 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003089 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090
3091 /**
3092 * Check both a Uri and normal permission. This allows you to perform
3093 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3094 * call.
3095 *
3096 * @param uri The Uri whose permission is to be checked, or null to not
3097 * do this check.
3098 * @param readPermission The permission that provides overall read access,
3099 * or null to not do this check.
3100 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003101 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003102 * @param pid The process ID being checked against. Must be &gt; 0.
3103 * @param uid The user ID being checked against. A uid of 0 is the root
3104 * user, which will pass every permission check.
3105 * @param modeFlags The type of access to grant. May be one or both of
3106 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3107 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3108 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003109 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 * is allowed to access that uri or holds one of the given permissions, or
3111 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3112 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003113 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3114 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003115 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003116
3117 /**
3118 * If a particular process and user ID has not been granted
3119 * permission to access a specific URI, throw {@link
3120 * SecurityException}. This only checks for permissions that have
3121 * been explicitly granted -- if the given process/uid has more
3122 * general access to the URI's content provider then this check
3123 * will always fail.
3124 *
3125 * @param uri The uri that is being checked.
3126 * @param pid The process ID being checked against. Must be &gt; 0.
3127 * @param uid The user ID being checked against. A uid of 0 is the root
3128 * user, which will pass every permission check.
3129 * @param modeFlags The type of access to grant. May be one or both of
3130 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3131 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3132 * @param message A message to include in the exception if it is thrown.
3133 *
3134 * @see #checkUriPermission(Uri, int, int, int)
3135 */
3136 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003137 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138
3139 /**
3140 * If the calling process and user ID has not been granted
3141 * permission to access a specific URI, throw {@link
3142 * SecurityException}. This is basically the same as calling
3143 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3144 * the pid and uid returned by {@link
3145 * android.os.Binder#getCallingPid} and {@link
3146 * android.os.Binder#getCallingUid}. One important difference is
3147 * that if you are not currently processing an IPC, this function
3148 * will always throw a SecurityException.
3149 *
3150 * @param uri The uri that is being checked.
3151 * @param modeFlags The type of access to grant. May be one or both of
3152 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3153 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3154 * @param message A message to include in the exception if it is thrown.
3155 *
3156 * @see #checkCallingUriPermission(Uri, int)
3157 */
3158 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003159 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160
3161 /**
3162 * If the calling process of an IPC <em>or you</em> has not been
3163 * granted permission to access a specific URI, throw {@link
3164 * SecurityException}. This is the same as {@link
3165 * #enforceCallingUriPermission}, except it grants your own
3166 * permissions if you are not currently processing an IPC. Use
3167 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003168 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003169 * @param uri The uri that is being checked.
3170 * @param modeFlags The type of access to grant. May be one or both of
3171 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3172 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3173 * @param message A message to include in the exception if it is thrown.
3174 *
3175 * @see #checkCallingOrSelfUriPermission(Uri, int)
3176 */
3177 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003178 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179
3180 /**
3181 * Enforce both a Uri and normal permission. This allows you to perform
3182 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3183 * call.
Scott Main4b5da682010-10-21 11:49:12 -07003184 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 * @param uri The Uri whose permission is to be checked, or null to not
3186 * do this check.
3187 * @param readPermission The permission that provides overall read access,
3188 * or null to not do this check.
3189 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003190 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 * @param pid The process ID being checked against. Must be &gt; 0.
3192 * @param uid The user ID being checked against. A uid of 0 is the root
3193 * user, which will pass every permission check.
3194 * @param modeFlags The type of access to grant. May be one or both of
3195 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3196 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3197 * @param message A message to include in the exception if it is thrown.
3198 *
3199 * @see #checkUriPermission(Uri, String, String, int, int, int)
3200 */
3201 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003202 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003203 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07003204 @Nullable String message);
3205
3206 /** @hide */
3207 @IntDef(flag = true,
3208 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3209 @Retention(RetentionPolicy.SOURCE)
3210 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211
3212 /**
3213 * Flag for use with {@link #createPackageContext}: include the application
3214 * code with the context. This means loading code into the caller's
3215 * process, so that {@link #getClassLoader()} can be used to instantiate
3216 * the application's classes. Setting this flags imposes security
3217 * restrictions on what application context you can access; if the
3218 * requested application can not be safely loaded into your process,
3219 * java.lang.SecurityException will be thrown. If this flag is not set,
3220 * there will be no restrictions on the packages that can be loaded,
3221 * but {@link #getClassLoader} will always return the default system
3222 * class loader.
3223 */
3224 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3225
3226 /**
3227 * Flag for use with {@link #createPackageContext}: ignore any security
3228 * restrictions on the Context being requested, allowing it to always
3229 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3230 * to be loaded into a process even when it isn't safe to do so. Use
3231 * with extreme care!
3232 */
3233 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07003234
Romain Guy870e09f2009-07-06 16:35:25 -07003235 /**
3236 * Flag for use with {@link #createPackageContext}: a restricted context may
3237 * disable specific features. For instance, a View associated with a restricted
3238 * context would ignore particular XML attributes.
3239 */
3240 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003241
3242 /**
3243 * Return a new Context object for the given application name. This
3244 * Context is the same as what the named application gets when it is
3245 * launched, containing the same resources and class loader. Each call to
3246 * this method returns a new instance of a Context object; Context objects
3247 * are not shared, however they share common state (Resources, ClassLoader,
3248 * etc) so the Context instance itself is fairly lightweight.
3249 *
3250 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
3251 * application with the given package name.
3252 *
3253 * <p>Throws {@link java.lang.SecurityException} if the Context requested
3254 * can not be loaded into the caller's process for security reasons (see
3255 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3256 *
3257 * @param packageName Name of the application's package.
3258 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3259 * or {@link #CONTEXT_IGNORE_SECURITY}.
3260 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003261 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003263 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04003265 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 */
3267 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07003268 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07003269
3270 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07003271 * Similar to {@link #createPackageContext(String, int)}, but with a
3272 * different {@link UserHandle}. For example, {@link #getContentResolver()}
3273 * will open any {@link Uri} as the given user.
3274 *
3275 * @hide
3276 */
3277 public abstract Context createPackageContextAsUser(
3278 String packageName, int flags, UserHandle user)
3279 throws PackageManager.NameNotFoundException;
3280
3281 /**
Jim Millera75a8832013-02-07 16:53:32 -08003282 * Get the userId associated with this context
3283 * @return user id
3284 *
3285 * @hide
3286 */
3287 public abstract int getUserId();
3288
3289 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07003290 * Return a new Context object for the current Context but whose resources
3291 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07003292 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07003293 * shared, however common state (ClassLoader, other Resources for the
3294 * same configuration) may be so the Context itself can be fairly lightweight.
3295 *
3296 * @param overrideConfiguration A {@link Configuration} specifying what
3297 * values to modify in the base Configuration of the original Context's
3298 * resources. If the base configuration changes (such as due to an
3299 * orientation change), the resources of this context will also change except
3300 * for those that have been explicitly overridden with a value here.
3301 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003302 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07003303 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003304 public abstract Context createConfigurationContext(
3305 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07003306
3307 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07003308 * Return a new Context object for the current Context but whose resources
3309 * are adjusted to match the metrics of the given Display. Each call to this method
3310 * returns a new instance of a Context object; Context objects are not
3311 * shared, however common state (ClassLoader, other Resources for the
3312 * same configuration) may be so the Context itself can be fairly lightweight.
3313 *
3314 * The returned display Context provides a {@link WindowManager}
3315 * (see {@link #getSystemService(String)}) that is configured to show windows
3316 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
3317 * method can be used to retrieve the Display from the returned Context.
3318 *
3319 * @param display A {@link Display} object specifying the display
3320 * for whose metrics the Context's resources should be tailored and upon which
3321 * new windows should be shown.
3322 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003323 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07003324 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003325 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07003326
3327 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07003328 * Gets the display adjustments holder for this context. This information
3329 * is provided on a per-application or activity basis and is used to simulate lower density
3330 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07003331 *
Jeff Browna492c3a2012-08-23 19:48:44 -07003332 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07003333 * @return The compatibility info holder, or null if not required by the application.
3334 * @hide
3335 */
Craig Mautner48d0d182013-06-11 07:53:06 -07003336 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07003337
3338 /**
Romain Guy870e09f2009-07-06 16:35:25 -07003339 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07003340 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003341 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07003342 *
Romain Guy870e09f2009-07-06 16:35:25 -07003343 * @see #CONTEXT_RESTRICTED
3344 */
3345 public boolean isRestricted() {
3346 return false;
3347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348}