blob: c2b796a92eff2f55116d4880d9ef4a26d75fa08f [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
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070019import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.pm.PackageManager;
21import android.content.res.AssetManager;
Dianne Hackborn756220b2012-08-14 16:45:30 -070022import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.content.res.Resources;
24import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070025import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.database.sqlite.SQLiteDatabase;
27import android.database.sqlite.SQLiteDatabase.CursorFactory;
28import android.graphics.Bitmap;
29import android.graphics.drawable.Drawable;
Adam Powellac695c62010-07-20 18:19:27 -070030import android.media.MediaScannerConnection.OnScanCompletedListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.net.Uri;
32import android.os.Bundle;
33import android.os.Handler;
34import android.os.Looper;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070035import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.util.AttributeSet;
Jeff Brown98365d72012-08-19 20:30:52 -070037import android.view.CompatibilityInfoHolder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
39import java.io.File;
40import java.io.FileInputStream;
41import java.io.FileNotFoundException;
42import java.io.FileOutputStream;
43import java.io.IOException;
44import java.io.InputStream;
45
46/**
47 * Interface to global information about an application environment. This is
48 * an abstract class whose implementation is provided by
49 * the Android system. It
50 * allows access to application-specific resources and classes, as well as
51 * up-calls for application-level operations such as launching activities,
52 * broadcasting and receiving intents, etc.
53 */
54public abstract class Context {
55 /**
56 * File creation mode: the default mode, where the created file can only
57 * be accessed by the calling application (or all applications sharing the
58 * same user ID).
59 * @see #MODE_WORLD_READABLE
60 * @see #MODE_WORLD_WRITEABLE
61 */
62 public static final int MODE_PRIVATE = 0x0000;
63 /**
64 * File creation mode: allow all other applications to have read access
65 * to the created file.
66 * @see #MODE_PRIVATE
67 * @see #MODE_WORLD_WRITEABLE
68 */
69 public static final int MODE_WORLD_READABLE = 0x0001;
70 /**
71 * File creation mode: allow all other applications to have write access
72 * to the created file.
73 * @see #MODE_PRIVATE
74 * @see #MODE_WORLD_READABLE
75 */
76 public static final int MODE_WORLD_WRITEABLE = 0x0002;
77 /**
78 * File creation mode: for use with {@link #openFileOutput}, if the file
79 * already exists then write data to the end of the existing file
80 * instead of erasing it.
81 * @see #openFileOutput
82 */
83 public static final int MODE_APPEND = 0x8000;
84
85 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -080086 * SharedPreference loading flag: when set, the file on disk will
87 * be checked for modification even if the shared preferences
88 * instance is already loaded in this process. This behavior is
89 * sometimes desired in cases where the application has multiple
90 * processes, all writing to the same SharedPreferences file.
91 * Generally there are better forms of communication between
92 * processes, though.
93 *
94 * <p>This was the legacy (but undocumented) behavior in and
95 * before Gingerbread (Android 2.3) and this flag is implied when
96 * targetting such releases. For applications targetting SDK
97 * versions <em>greater than</em> Android 2.3, this flag must be
98 * explicitly set if desired.
99 *
100 * @see #getSharedPreferences
101 */
102 public static final int MODE_MULTI_PROCESS = 0x0004;
103
104 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700105 * Database open flag: when set, the database is opened with write-ahead
106 * logging enabled by default.
107 *
108 * @see #openOrCreateDatabase(String, int, CursorFactory)
109 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
110 * @see SQLiteDatabase#enableWriteAheadLogging
111 */
112 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
113
114 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 * Flag for {@link #bindService}: automatically create the service as long
116 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700117 * its {@link android.app.Service#onStartCommand}
118 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 * explicit call to {@link #startService}. Even without that, though,
120 * this still provides you with access to the service object while the
121 * service is created.
122 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700123 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
124 * not supplying this flag would also impact how important the system
125 * consider's the target service's process to be. When set, the only way
126 * for it to be raised was by binding from a service in which case it will
127 * only be important when that activity is in the foreground. Now to
128 * achieve this behavior you must explicitly supply the new flag
129 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
130 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
131 * the flags {@link #BIND_WAIVE_PRIORITY} and
132 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
133 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 */
135 public static final int BIND_AUTO_CREATE = 0x0001;
136
137 /**
138 * Flag for {@link #bindService}: include debugging help for mismatched
139 * calls to unbind. When this flag is set, the callstack of the following
140 * {@link #unbindService} call is retained, to be printed if a later
141 * incorrect unbind call is made. Note that doing this requires retaining
142 * information about the binding that was made for the lifetime of the app,
143 * resulting in a leak -- this should only be used for debugging.
144 */
145 public static final int BIND_DEBUG_UNBIND = 0x0002;
146
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800147 /**
148 * Flag for {@link #bindService}: don't allow this binding to raise
149 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700150 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800151 * as the client (so that its process will not be killable in any
152 * situation where the client is not killable), but for CPU scheduling
153 * purposes it may be left in the background. This only has an impact
154 * in the situation where the binding client is a foreground process
155 * and the target service is in a background process.
156 */
157 public static final int BIND_NOT_FOREGROUND = 0x0004;
158
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700159 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700160 * Flag for {@link #bindService}: indicates that the client application
161 * binding to this service considers the service to be more important than
162 * the app itself. When set, the platform will try to have the out of
163 * memory kill the app before it kills the service it is bound to, though
164 * this is not guaranteed to be the case.
165 */
166 public static final int BIND_ABOVE_CLIENT = 0x0008;
167
168 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700169 * Flag for {@link #bindService}: allow the process hosting the bound
170 * service to go through its normal memory management. It will be
171 * treated more like a running service, allowing the system to
172 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700173 * whim it may have, and being more aggressive about making it a candidate
174 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700175 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700176 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
177
178 /**
179 * Flag for {@link #bindService}: don't impact the scheduling or
180 * memory management priority of the target service's hosting process.
181 * Allows the service's process to be managed on the background LRU list
182 * just like a regular application process in the background.
183 */
184 public static final int BIND_WAIVE_PRIORITY = 0x0020;
185
186 /**
187 * Flag for {@link #bindService}: this service is very important to
188 * the client, so should be brought to the foreground process level
189 * when the client is. Normally a process can only be raised to the
190 * visibility level by a client, even if that client is in the foreground.
191 */
192 public static final int BIND_IMPORTANT = 0x0040;
193
194 /**
195 * Flag for {@link #bindService}: If binding from an activity, allow the
196 * target service's process importance to be raised based on whether the
197 * activity is visible to the user, regardless whether another flag is
198 * used to reduce the amount that the client process's overall importance
199 * is used to impact it.
200 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700201 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
202
203 /**
204 * Flag for {@link #bindService}: Don't consider the bound service to be
205 * visible, even if the caller is visible.
206 * @hide
207 */
208 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 /** Return an AssetManager instance for your application's package. */
211 public abstract AssetManager getAssets();
212
213 /** Return a Resources instance for your application's package. */
214 public abstract Resources getResources();
215
216 /** Return PackageManager instance to find global package information. */
217 public abstract PackageManager getPackageManager();
218
219 /** Return a ContentResolver instance for your application's package. */
220 public abstract ContentResolver getContentResolver();
221
222 /**
223 * Return the Looper for the main thread of the current process. This is
224 * the thread used to dispatch calls to application components (activities,
225 * services, etc).
226 */
227 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 /**
230 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800231 * current process. This generally should only be used if you need a
232 * Context whose lifecycle is separate from the current context, that is
233 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700234 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800235 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800236 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800237 * <ul>
238 * <li> <p>If used from an Activity context, the receiver is being registered
239 * within that activity. This means that you are expected to unregister
240 * before the activity is done being destroyed; in fact if you do not do
241 * so, the framework will clean up your leaked registration as it removes
242 * the activity and log an error. Thus, if you use the Activity context
243 * to register a receiver that is static (global to the process, not
244 * associated with an Activity instance) then that registration will be
245 * removed on you at whatever point the activity you used is destroyed.
246 * <li> <p>If used from the Context returned here, the receiver is being
247 * registered with the global state associated with your application. Thus
248 * it will never be unregistered for you. This is necessary if the receiver
249 * is associated with static data, not a particular component. However
250 * using the ApplicationContext elsewhere can easily lead to serious leaks
251 * if you forget to unregister, unbind, etc.
252 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 */
254 public abstract Context getApplicationContext();
255
256 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700257 * Add a new {@link ComponentCallbacks} to the base application of the
258 * Context, which will be called at the same times as the ComponentCallbacks
259 * methods of activities and other components are called. Note that you
260 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
261 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700262 *
263 * @param callback The interface to call. This can be either a
264 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700265 */
266 public void registerComponentCallbacks(ComponentCallbacks callback) {
267 getApplicationContext().registerComponentCallbacks(callback);
268 }
269
270 /**
271 * Remove a {@link ComponentCallbacks} objec that was previously registered
272 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
273 */
274 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
275 getApplicationContext().unregisterComponentCallbacks(callback);
276 }
277
278 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 * Return a localized, styled CharSequence from the application's package's
280 * default string table.
281 *
282 * @param resId Resource id for the CharSequence text
283 */
284 public final CharSequence getText(int resId) {
285 return getResources().getText(resId);
286 }
287
288 /**
289 * Return a localized string from the application's package's
290 * default string table.
291 *
292 * @param resId Resource id for the string
293 */
294 public final String getString(int resId) {
295 return getResources().getString(resId);
296 }
297
298 /**
299 * Return a localized formatted string from the application's package's
300 * default string table, substituting the format arguments as defined in
301 * {@link java.util.Formatter} and {@link java.lang.String#format}.
302 *
303 * @param resId Resource id for the format string
304 * @param formatArgs The format arguments that will be used for substitution.
305 */
306
307 public final String getString(int resId, Object... formatArgs) {
308 return getResources().getString(resId, formatArgs);
309 }
310
311 /**
312 * Set the base theme for this context. Note that this should be called
313 * before any views are instantiated in the Context (for example before
314 * calling {@link android.app.Activity#setContentView} or
315 * {@link android.view.LayoutInflater#inflate}).
316 *
317 * @param resid The style resource describing the theme.
318 */
319 public abstract void setTheme(int resid);
320
Dianne Hackborn247fe742011-01-08 17:25:57 -0800321 /** @hide Needed for some internal implementation... not public because
322 * you can't assume this actually means anything. */
323 public int getThemeResId() {
324 return 0;
325 }
326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 /**
328 * Return the Theme object associated with this Context.
329 */
330 public abstract Resources.Theme getTheme();
331
332 /**
333 * Retrieve styled attribute information in this Context's theme. See
334 * {@link Resources.Theme#obtainStyledAttributes(int[])}
335 * for more information.
336 *
337 * @see Resources.Theme#obtainStyledAttributes(int[])
338 */
339 public final TypedArray obtainStyledAttributes(
340 int[] attrs) {
341 return getTheme().obtainStyledAttributes(attrs);
342 }
343
344 /**
345 * Retrieve styled attribute information in this Context's theme. See
346 * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
347 * for more information.
348 *
349 * @see Resources.Theme#obtainStyledAttributes(int, int[])
350 */
351 public final TypedArray obtainStyledAttributes(
352 int resid, int[] attrs) throws Resources.NotFoundException {
353 return getTheme().obtainStyledAttributes(resid, attrs);
354 }
355
356 /**
357 * Retrieve styled attribute information in this Context's theme. See
358 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
359 * for more information.
360 *
361 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
362 */
363 public final TypedArray obtainStyledAttributes(
364 AttributeSet set, int[] attrs) {
365 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
366 }
367
368 /**
369 * Retrieve styled attribute information in this Context's theme. See
370 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
371 * for more information.
372 *
373 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
374 */
375 public final TypedArray obtainStyledAttributes(
376 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
377 return getTheme().obtainStyledAttributes(
378 set, attrs, defStyleAttr, defStyleRes);
379 }
380
381 /**
382 * Return a class loader you can use to retrieve classes in this package.
383 */
384 public abstract ClassLoader getClassLoader();
385
386 /** Return the name of this application's package. */
387 public abstract String getPackageName();
388
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700389 /** Return the full application info for this context's package. */
390 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 /**
Kenny Root32148392010-01-21 15:40:47 -0800393 * Return the full path to this context's primary Android package.
394 * The Android package is a ZIP file which contains the application's
395 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 *
397 * <p>Note: this is not generally useful for applications, since they should
398 * not be directly accessing the file system.
399 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800400 * @return String Path to the resources.
401 */
402 public abstract String getPackageResourcePath();
403
404 /**
Kenny Root32148392010-01-21 15:40:47 -0800405 * Return the full path to this context's primary Android package.
406 * The Android package is a ZIP file which contains application's
407 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 *
409 * <p>Note: this is not generally useful for applications, since they should
410 * not be directly accessing the file system.
411 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 * @return String Path to the code and assets.
413 */
414 public abstract String getPackageCodePath();
415
416 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700417 * {@hide}
418 * Return the full path to the shared prefs file for the given prefs group name.
419 *
420 * <p>Note: this is not generally useful for applications, since they should
421 * not be directly accessing the file system.
422 */
423 public abstract File getSharedPrefsFile(String name);
424
425 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 * Retrieve and hold the contents of the preferences file 'name', returning
427 * a SharedPreferences through which you can retrieve and modify its
428 * values. Only one instance of the SharedPreferences object is returned
429 * to any callers for the same name, meaning they will see each other's
430 * edits as soon as they are made.
431 *
432 * @param name Desired preferences file. If a preferences file by this name
433 * does not exist, it will be created when you retrieve an
434 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
435 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
436 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800437 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
438 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
439 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
440 * is always on in apps targetting Gingerbread (Android 2.3) and below, and
441 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 *
443 * @return Returns the single SharedPreferences instance that can be used
444 * to retrieve and modify the preference values.
445 *
446 * @see #MODE_PRIVATE
447 * @see #MODE_WORLD_READABLE
448 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800449 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 */
451 public abstract SharedPreferences getSharedPreferences(String name,
452 int mode);
453
454 /**
455 * Open a private file associated with this Context's application package
456 * for reading.
457 *
458 * @param name The name of the file to open; can not contain path
459 * separators.
460 *
461 * @return FileInputStream Resulting input stream.
462 *
463 * @see #openFileOutput
464 * @see #fileList
465 * @see #deleteFile
466 * @see java.io.FileInputStream#FileInputStream(String)
467 */
468 public abstract FileInputStream openFileInput(String name)
469 throws FileNotFoundException;
470
471 /**
472 * Open a private file associated with this Context's application package
473 * for writing. Creates the file if it doesn't already exist.
474 *
475 * @param name The name of the file to open; can not contain path
476 * separators.
477 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
478 * default operation, {@link #MODE_APPEND} to append to an existing file,
479 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
480 * permissions.
481 *
482 * @return FileOutputStream Resulting output stream.
483 *
484 * @see #MODE_APPEND
485 * @see #MODE_PRIVATE
486 * @see #MODE_WORLD_READABLE
487 * @see #MODE_WORLD_WRITEABLE
488 * @see #openFileInput
489 * @see #fileList
490 * @see #deleteFile
491 * @see java.io.FileOutputStream#FileOutputStream(String)
492 */
493 public abstract FileOutputStream openFileOutput(String name, int mode)
494 throws FileNotFoundException;
495
496 /**
497 * Delete the given private file associated with this Context's
498 * application package.
499 *
500 * @param name The name of the file to delete; can not contain path
501 * separators.
502 *
503 * @return True if the file was successfully deleted; else
504 * false.
505 *
506 * @see #openFileInput
507 * @see #openFileOutput
508 * @see #fileList
509 * @see java.io.File#delete()
510 */
511 public abstract boolean deleteFile(String name);
512
513 /**
514 * Returns the absolute path on the filesystem where a file created with
515 * {@link #openFileOutput} is stored.
516 *
517 * @param name The name of the file for which you would like to get
518 * its path.
519 *
520 * @return Returns an absolute path to the given file.
521 *
522 * @see #openFileOutput
523 * @see #getFilesDir
524 * @see #getDir
525 */
526 public abstract File getFileStreamPath(String name);
527
528 /**
529 * Returns the absolute path to the directory on the filesystem where
530 * files created with {@link #openFileOutput} are stored.
531 *
532 * @return Returns the path of the directory holding application files.
533 *
534 * @see #openFileOutput
535 * @see #getFileStreamPath
536 * @see #getDir
537 */
538 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 /**
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800541 * Returns the absolute path to the directory on the external filesystem
542 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700543 * Environment.getExternalStorageDirectory()}) where the application can
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800544 * place persistent files it owns. These files are private to the
545 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700546 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800547 * <p>This is like {@link #getFilesDir()} in that these
548 * files will be deleted when the application is uninstalled, however there
549 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700550 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800551 * <ul>
552 * <li>External files are not always available: they will disappear if the
553 * user mounts the external storage on a computer or removes it. See the
554 * APIs on {@link android.os.Environment} for information in the storage state.
555 * <li>There is no security enforced with these files. All applications
556 * can read and write files placed here.
557 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700558 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800559 * <p>Here is an example of typical code to manipulate a file in
560 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700561 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800562 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
563 * private_file}
564 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700565 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800566 * file will be a path to a sub-directory of the given type. Though these files
567 * are not automatically scanned by the media scanner, you can explicitly
568 * add them to the media database with
569 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Ray Chenb7c8c762010-03-30 17:21:39 -0700570 * OnScanCompletedListener) MediaScannerConnection.scanFile}.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800571 * Note that this is not the same as
572 * {@link android.os.Environment#getExternalStoragePublicDirectory
573 * Environment.getExternalStoragePublicDirectory()}, which provides
574 * directories of media shared by all applications. The
575 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700576 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800577 * application is uninstalled. Unlike
578 * {@link android.os.Environment#getExternalStoragePublicDirectory
579 * Environment.getExternalStoragePublicDirectory()}, the directory
580 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700581 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800582 * <p>Here is an example of typical code to manipulate a picture in
583 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700584 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800585 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
586 * private_picture}
Scott Main4b5da682010-10-21 11:49:12 -0700587 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800588 * @param type The type of files directory to return. May be null for
589 * the root of the files directory or one of
590 * the following Environment constants for a subdirectory:
591 * {@link android.os.Environment#DIRECTORY_MUSIC},
592 * {@link android.os.Environment#DIRECTORY_PODCASTS},
593 * {@link android.os.Environment#DIRECTORY_RINGTONES},
594 * {@link android.os.Environment#DIRECTORY_ALARMS},
595 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
596 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
597 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700598 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800599 * @return Returns the path of the directory holding application files
600 * on external storage. Returns null if external storage is not currently
601 * mounted so it could not ensure the path exists; you will need to call
602 * this method again when it is available.
603 *
604 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700605 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800606 */
607 public abstract File getExternalFilesDir(String type);
Scott Main4b5da682010-10-21 11:49:12 -0700608
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800609 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800610 * Return the directory where this application's OBB files (if there
611 * are any) can be found. Note if the application does not have any OBB
612 * files, this directory may not exist.
613 */
614 public abstract File getObbDir();
615
616 /**
Scott Main4b5da682010-10-21 11:49:12 -0700617 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800619 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700621 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800622 * <strong>Note: you should not <em>rely</em> on the system deleting these
623 * files for you; you should always have a reasonable maximum, such as 1 MB,
624 * for the amount of space you consume with cache files, and prune those
625 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700626 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 * @return Returns the path of the directory holding application cache files.
628 *
629 * @see #openFileOutput
630 * @see #getFileStreamPath
631 * @see #getDir
632 */
633 public abstract File getCacheDir();
634
635 /**
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800636 * Returns the absolute path to the directory on the external filesystem
637 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
638 * Environment.getExternalStorageDirectory()} where the application can
639 * place cache files it owns.
Scott Main4b5da682010-10-21 11:49:12 -0700640 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800641 * <p>This is like {@link #getCacheDir()} in that these
642 * files will be deleted when the application is uninstalled, however there
643 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700644 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800645 * <ul>
646 * <li>The platform does not monitor the space available in external storage,
647 * and thus will not automatically delete these files. Note that you should
648 * be managing the maximum space you will use for these anyway, just like
649 * with {@link #getCacheDir()}.
650 * <li>External files are not always available: they will disappear if the
651 * user mounts the external storage on a computer or removes it. See the
652 * APIs on {@link android.os.Environment} for information in the storage state.
653 * <li>There is no security enforced with these files. All applications
654 * can read and write files placed here.
655 * </ul>
656 *
657 * @return Returns the path of the directory holding application cache files
658 * on external storage. Returns null if external storage is not currently
659 * mounted so it could not ensure the path exists; you will need to call
660 * this method again when it is available.
661 *
662 * @see #getCacheDir
663 */
664 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700665
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800666 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 * Returns an array of strings naming the private files associated with
668 * this Context's application package.
669 *
670 * @return Array of strings naming the private files.
671 *
672 * @see #openFileInput
673 * @see #openFileOutput
674 * @see #deleteFile
675 */
676 public abstract String[] fileList();
677
678 /**
679 * Retrieve, creating if needed, a new directory in which the application
680 * can place its own custom data files. You can use the returned File
681 * object to create and access files in this directory. Note that files
682 * created through a File object will only be accessible by your own
683 * application; you can only set the mode of the entire directory, not
684 * of individual files.
685 *
686 * @param name Name of the directory to retrieve. This is a directory
687 * that is created as part of your application data.
688 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
689 * default operation, {@link #MODE_WORLD_READABLE} and
690 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
691 *
692 * @return Returns a File object for the requested directory. The directory
693 * will have been created if it does not already exist.
694 *
695 * @see #openFileOutput(String, int)
696 */
697 public abstract File getDir(String name, int mode);
698
699 /**
700 * Open a new private SQLiteDatabase associated with this Context's
701 * application package. Create the database file if it doesn't exist.
702 *
703 * @param name The name (unique in the application package) of the database.
704 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
705 * default operation, {@link #MODE_WORLD_READABLE}
706 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700707 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 * @param factory An optional factory class that is called to instantiate a
709 * cursor when query is called.
710 *
711 * @return The contents of a newly created database with the given name.
712 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
713 *
714 * @see #MODE_PRIVATE
715 * @see #MODE_WORLD_READABLE
716 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700717 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718 * @see #deleteDatabase
719 */
720 public abstract SQLiteDatabase openOrCreateDatabase(String name,
721 int mode, CursorFactory factory);
722
723 /**
Vasu Nori74f170f2010-06-01 18:06:18 -0700724 * Open a new private SQLiteDatabase associated with this Context's
725 * application package. Creates the database file if it doesn't exist.
726 *
727 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
728 * used to handle corruption when sqlite reports database corruption.</p>
729 *
730 * @param name The name (unique in the application package) of the database.
731 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
732 * default operation, {@link #MODE_WORLD_READABLE}
733 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700734 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -0700735 * @param factory An optional factory class that is called to instantiate a
736 * cursor when query is called.
737 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Vasu Nori03acd512010-06-03 14:39:40 -0700738 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -0700739 * @return The contents of a newly created database with the given name.
740 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
741 *
742 * @see #MODE_PRIVATE
743 * @see #MODE_WORLD_READABLE
744 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700745 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -0700746 * @see #deleteDatabase
747 */
748 public abstract SQLiteDatabase openOrCreateDatabase(String name,
749 int mode, CursorFactory factory, DatabaseErrorHandler errorHandler);
750
751 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 * Delete an existing private SQLiteDatabase associated with this Context's
753 * application package.
754 *
755 * @param name The name (unique in the application package) of the
756 * database.
757 *
758 * @return True if the database was successfully deleted; else false.
759 *
760 * @see #openOrCreateDatabase
761 */
762 public abstract boolean deleteDatabase(String name);
763
764 /**
765 * Returns the absolute path on the filesystem where a database created with
766 * {@link #openOrCreateDatabase} is stored.
767 *
768 * @param name The name of the database for which you would like to get
769 * its path.
770 *
771 * @return Returns an absolute path to the given database.
772 *
773 * @see #openOrCreateDatabase
774 */
775 public abstract File getDatabasePath(String name);
776
777 /**
778 * Returns an array of strings naming the private databases associated with
779 * this Context's application package.
780 *
781 * @return Array of strings naming the private databases.
782 *
783 * @see #openOrCreateDatabase
784 * @see #deleteDatabase
785 */
786 public abstract String[] databaseList();
787
788 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700789 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700790 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700792 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 public abstract Drawable getWallpaper();
794
795 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700796 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700797 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700799 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 public abstract Drawable peekWallpaper();
801
802 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700803 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
804 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700806 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 public abstract int getWallpaperDesiredMinimumWidth();
808
809 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700810 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
811 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800812 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700813 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800814 public abstract int getWallpaperDesiredMinimumHeight();
815
816 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700817 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700818 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700819 * <p>This method requires the caller to hold the permission
820 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700822 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
824
825 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700826 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700827 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700828 * <p>This method requires the caller to hold the permission
829 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700831 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 public abstract void setWallpaper(InputStream data) throws IOException;
833
834 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700835 * @deprecated Use {@link android.app.WallpaperManager#clear
836 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700837 * <p>This method requires the caller to hold the permission
838 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700840 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800841 public abstract void clearWallpaper() throws IOException;
842
843 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700844 * Same as {@link #startActivity(Intent, Bundle)} with no options
845 * specified.
846 *
847 * @param intent The description of the activity to start.
848 *
849 * @throws ActivityNotFoundException
850 *
851 * @see {@link #startActivity(Intent, Bundle)}
852 * @see PackageManager#resolveActivity
853 */
854 public abstract void startActivity(Intent intent);
855
856 /**
Amith Yamasani82644082012-08-03 13:09:11 -0700857 * Same as {@link #startActivity(Intent)}, but for a specific user. It requires holding
858 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
859 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700860 * @param user The UserHandle of the user to start this activity for.
Amith Yamasani82644082012-08-03 13:09:11 -0700861 * @throws ActivityNotFoundException
862 * @hide
863 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700864 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -0700865 throw new RuntimeException("Not implemented. Must override in a subclass.");
866 }
867
868 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 * Launch a new activity. You will not receive any information about when
870 * the activity exits.
871 *
872 * <p>Note that if this method is being called from outside of an
873 * {@link android.app.Activity} Context, then the Intent must include
874 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
875 * without being started from an existing Activity, there is no existing
876 * task in which to place the new activity and thus it needs to be placed
877 * in its own separate task.
878 *
879 * <p>This method throws {@link ActivityNotFoundException}
880 * if there was no Activity found to run the given Intent.
881 *
882 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700883 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700884 * May be null if there are no options. See {@link android.app.ActivityOptions}
885 * for how to build the Bundle supplied here; there are no supported definitions
886 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 *
888 * @throws ActivityNotFoundException
889 *
Scott Main60dd5202012-06-23 00:01:22 -0700890 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800891 * @see PackageManager#resolveActivity
892 */
Dianne Hackborna4972e92012-03-14 10:38:05 -0700893 public abstract void startActivity(Intent intent, Bundle options);
894
895 /**
Amith Yamasani258848d2012-08-10 17:06:33 -0700896 * Same as {@link #startActivity(Intent, Bundle)}, but for a specific user. It requires holding
897 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
898 * @param intent The description of the activity to start.
899 * @param options Additional options for how the Activity should be started.
900 * May be null if there are no options. See {@link android.app.ActivityOptions}
901 * for how to build the Bundle supplied here; there are no supported definitions
902 * for building it manually.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700903 * @param user The UserHandle of the user to start this activity for.
Amith Yamasani258848d2012-08-10 17:06:33 -0700904 * @throws ActivityNotFoundException
905 * @hide
906 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700907 public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -0700908 throw new RuntimeException("Not implemented. Must override in a subclass.");
909 }
910
911 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700912 * Same as {@link #startActivities(Intent[], Bundle)} with no options
913 * specified.
914 *
915 * @param intents An array of Intents to be started.
916 *
917 * @throws ActivityNotFoundException
918 *
919 * @see {@link #startActivities(Intent[], Bundle)}
920 * @see PackageManager#resolveActivity
921 */
922 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923
924 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800925 * Launch multiple new activities. This is generally the same as calling
926 * {@link #startActivity(Intent)} for the first Intent in the array,
927 * that activity during its creation calling {@link #startActivity(Intent)}
928 * for the second entry, etc. Note that unlike that approach, generally
929 * none of the activities except the last in the array will be created
930 * at this point, but rather will be created when the user first visits
931 * them (due to pressing back from the activity on top).
932 *
933 * <p>This method throws {@link ActivityNotFoundException}
934 * if there was no Activity found for <em>any</em> given Intent. In this
935 * case the state of the activity stack is undefined (some Intents in the
936 * list may be on it, some not), so you probably want to avoid such situations.
937 *
938 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700939 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700940 * See {@link android.content.Context#startActivity(Intent, Bundle)
941 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800942 *
943 * @throws ActivityNotFoundException
944 *
Dianne Hackborna4972e92012-03-14 10:38:05 -0700945 * @see {@link #startActivities(Intent[])}
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800946 * @see PackageManager#resolveActivity
947 */
Dianne Hackborna4972e92012-03-14 10:38:05 -0700948 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800949
950 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700951 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
952 * with no options specified.
953 *
954 * @param intent The IntentSender to launch.
955 * @param fillInIntent If non-null, this will be provided as the
956 * intent parameter to {@link IntentSender#sendIntent}.
957 * @param flagsMask Intent flags in the original IntentSender that you
958 * would like to change.
959 * @param flagsValues Desired values for any bits set in
960 * <var>flagsMask</var>
961 * @param extraFlags Always set to 0.
962 *
963 * @see #startActivity(Intent)
964 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
965 */
966 public abstract void startIntentSender(IntentSender intent,
967 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
968 throws IntentSender.SendIntentException;
969
970 /**
971 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700972 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -0700973 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700974 * here; otherwise, its associated action will be executed (such as
975 * sending a broadcast) as if you had called
976 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -0700977 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700978 * @param intent The IntentSender to launch.
979 * @param fillInIntent If non-null, this will be provided as the
980 * intent parameter to {@link IntentSender#sendIntent}.
981 * @param flagsMask Intent flags in the original IntentSender that you
982 * would like to change.
983 * @param flagsValues Desired values for any bits set in
984 * <var>flagsMask</var>
985 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700986 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700987 * See {@link android.content.Context#startActivity(Intent, Bundle)
988 * Context.startActivity(Intent, Bundle)} for more details. If options
989 * have also been supplied by the IntentSender, options given here will
990 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700991 *
992 * @see #startActivity(Intent, Bundle)
993 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700994 */
995 public abstract void startIntentSender(IntentSender intent,
Dianne Hackborna4972e92012-03-14 10:38:05 -0700996 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
997 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700998
999 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 * Broadcast the given intent to all interested BroadcastReceivers. This
1001 * call is asynchronous; it returns immediately, and you will continue
1002 * executing while the receivers are run. No results are propagated from
1003 * receivers and receivers can not abort the broadcast. If you want
1004 * to allow receivers to propagate results or abort the broadcast, you must
1005 * send an ordered broadcast using
1006 * {@link #sendOrderedBroadcast(Intent, String)}.
1007 *
1008 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1009 *
1010 * @param intent The Intent to broadcast; all receivers matching this
1011 * Intent will receive the broadcast.
1012 *
1013 * @see android.content.BroadcastReceiver
1014 * @see #registerReceiver
1015 * @see #sendBroadcast(Intent, String)
1016 * @see #sendOrderedBroadcast(Intent, String)
1017 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1018 */
1019 public abstract void sendBroadcast(Intent intent);
1020
1021 /**
1022 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1023 * an optional required permission to be enforced. This
1024 * call is asynchronous; it returns immediately, and you will continue
1025 * executing while the receivers are run. No results are propagated from
1026 * receivers and receivers can not abort the broadcast. If you want
1027 * to allow receivers to propagate results or abort the broadcast, you must
1028 * send an ordered broadcast using
1029 * {@link #sendOrderedBroadcast(Intent, String)}.
1030 *
1031 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1032 *
1033 * @param intent The Intent to broadcast; all receivers matching this
1034 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001035 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001036 * a receiver must hold in order to receive your broadcast.
1037 * If null, no permission is required.
1038 *
1039 * @see android.content.BroadcastReceiver
1040 * @see #registerReceiver
1041 * @see #sendBroadcast(Intent)
1042 * @see #sendOrderedBroadcast(Intent, String)
1043 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1044 */
1045 public abstract void sendBroadcast(Intent intent,
1046 String receiverPermission);
1047
1048 /**
1049 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1050 * them one at a time to allow more preferred receivers to consume the
1051 * broadcast before it is delivered to less preferred receivers. This
1052 * call is asynchronous; it returns immediately, and you will continue
1053 * executing while the receivers are run.
1054 *
1055 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1056 *
1057 * @param intent The Intent to broadcast; all receivers matching this
1058 * Intent will receive the broadcast.
1059 * @param receiverPermission (optional) String naming a permissions that
1060 * a receiver must hold in order to receive your broadcast.
1061 * If null, no permission is required.
1062 *
1063 * @see android.content.BroadcastReceiver
1064 * @see #registerReceiver
1065 * @see #sendBroadcast(Intent)
1066 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1067 */
1068 public abstract void sendOrderedBroadcast(Intent intent,
1069 String receiverPermission);
1070
1071 /**
1072 * Version of {@link #sendBroadcast(Intent)} that allows you to
1073 * receive data back from the broadcast. This is accomplished by
1074 * supplying your own BroadcastReceiver when calling, which will be
1075 * treated as a final receiver at the end of the broadcast -- its
1076 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001077 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 * be serialized in the same way as calling
1079 * {@link #sendOrderedBroadcast(Intent, String)}.
1080 *
1081 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1082 * asynchronous; it will return before
1083 * resultReceiver.onReceive() is called.
1084 *
1085 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1086 *
1087 * @param intent The Intent to broadcast; all receivers matching this
1088 * Intent will receive the broadcast.
1089 * @param receiverPermission String naming a permissions that
1090 * a receiver must hold in order to receive your broadcast.
1091 * If null, no permission is required.
1092 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1093 * receiver of the broadcast.
1094 * @param scheduler A custom Handler with which to schedule the
1095 * resultReceiver callback; if null it will be
1096 * scheduled in the Context's main thread.
1097 * @param initialCode An initial value for the result code. Often
1098 * Activity.RESULT_OK.
1099 * @param initialData An initial value for the result data. Often
1100 * null.
1101 * @param initialExtras An initial value for the result extras. Often
1102 * null.
1103 *
1104 * @see #sendBroadcast(Intent)
1105 * @see #sendBroadcast(Intent, String)
1106 * @see #sendOrderedBroadcast(Intent, String)
1107 * @see #sendStickyBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001108 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001109 * @see android.content.BroadcastReceiver
1110 * @see #registerReceiver
1111 * @see android.app.Activity#RESULT_OK
1112 */
1113 public abstract void sendOrderedBroadcast(Intent intent,
1114 String receiverPermission, BroadcastReceiver resultReceiver,
1115 Handler scheduler, int initialCode, String initialData,
1116 Bundle initialExtras);
1117
1118 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001119 * Same as {@link #sendBroadcast(Intent)}, but for a specific user. This broadcast
1120 * can only be sent to receivers that are part of the calling application. It
1121 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1122 * permission.
1123 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001124 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001125 * @see #sendBroadcast(Intent)
1126 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001127 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001128
1129 /**
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001130 * Same as {@link #sendBroadcast(Intent, String)}, but for a specific user. This broadcast
1131 * can only be sent to receivers that are part of the calling application. It
1132 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1133 * permission.
1134 *
1135 * @param intent The Intent to broadcast; all receivers matching this
1136 * Intent will receive the broadcast.
1137 * @param user UserHandle to send the intent to.
1138 * @param receiverPermission (optional) String naming a permission that
1139 * a receiver must hold in order to receive your broadcast.
1140 * If null, no permission is required.
1141 *
1142 * @see #sendBroadcast(Intent, String)
1143 */
1144 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1145 String receiverPermission);
1146
1147 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001148 * Same as
1149 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)},
1150 * but for a specific user. This broadcast
1151 * can only be sent to receivers that are part of the calling application. It
1152 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1153 * permission.
1154 *
1155 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1156 *
1157 * @param intent The Intent to broadcast; all receivers matching this
1158 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001159 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001160 * @param receiverPermission String naming a permissions that
1161 * a receiver must hold in order to receive your broadcast.
1162 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001163 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1164 * receiver of the broadcast.
1165 * @param scheduler A custom Handler with which to schedule the
1166 * resultReceiver callback; if null it will be
1167 * scheduled in the Context's main thread.
1168 * @param initialCode An initial value for the result code. Often
1169 * Activity.RESULT_OK.
1170 * @param initialData An initial value for the result data. Often
1171 * null.
1172 * @param initialExtras An initial value for the result extras. Often
1173 * null.
1174 *
1175 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1176 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001177 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001178 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001179 int initialCode, String initialData, Bundle initialExtras);
1180
1181 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1183 * Intent you are sending stays around after the broadcast is complete,
1184 * so that others can quickly retrieve that data through the return
1185 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1186 * all other ways, this behaves the same as
1187 * {@link #sendBroadcast(Intent)}.
1188 *
1189 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1190 * permission in order to use this API. If you do not hold that
1191 * permission, {@link SecurityException} will be thrown.
1192 *
1193 * @param intent The Intent to broadcast; all receivers matching this
1194 * Intent will receive the broadcast, and the Intent will be held to
1195 * be re-broadcast to future receivers.
1196 *
1197 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001198 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 */
1200 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001201
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001202 /**
1203 * Version of {@link #sendStickyBroadcast} that allows you to
1204 * receive data back from the broadcast. This is accomplished by
1205 * supplying your own BroadcastReceiver when calling, which will be
1206 * treated as a final receiver at the end of the broadcast -- its
1207 * {@link BroadcastReceiver#onReceive} method will be called with
1208 * the result values collected from the other receivers. The broadcast will
1209 * be serialized in the same way as calling
1210 * {@link #sendOrderedBroadcast(Intent, String)}.
1211 *
1212 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1213 * asynchronous; it will return before
1214 * resultReceiver.onReceive() is called. Note that the sticky data
1215 * stored is only the data you initially supply to the broadcast, not
1216 * the result of any changes made by the receivers.
1217 *
1218 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1219 *
1220 * @param intent The Intent to broadcast; all receivers matching this
1221 * Intent will receive the broadcast.
1222 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1223 * receiver of the broadcast.
1224 * @param scheduler A custom Handler with which to schedule the
1225 * resultReceiver callback; if null it will be
1226 * scheduled in the Context's main thread.
1227 * @param initialCode An initial value for the result code. Often
1228 * Activity.RESULT_OK.
1229 * @param initialData An initial value for the result data. Often
1230 * null.
1231 * @param initialExtras An initial value for the result extras. Often
1232 * null.
1233 *
1234 * @see #sendBroadcast(Intent)
1235 * @see #sendBroadcast(Intent, String)
1236 * @see #sendOrderedBroadcast(Intent, String)
1237 * @see #sendStickyBroadcast(Intent)
1238 * @see android.content.BroadcastReceiver
1239 * @see #registerReceiver
1240 * @see android.app.Activity#RESULT_OK
1241 */
1242 public abstract void sendStickyOrderedBroadcast(Intent intent,
1243 BroadcastReceiver resultReceiver,
1244 Handler scheduler, int initialCode, String initialData,
1245 Bundle initialExtras);
1246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 /**
1248 * Remove the data previously sent with {@link #sendStickyBroadcast},
1249 * so that it is as if the sticky broadcast had never happened.
1250 *
1251 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1252 * permission in order to use this API. If you do not hold that
1253 * permission, {@link SecurityException} will be thrown.
1254 *
1255 * @param intent The Intent that was previously broadcast.
1256 *
1257 * @see #sendStickyBroadcast
1258 */
1259 public abstract void removeStickyBroadcast(Intent intent);
1260
1261 /**
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001262 * Same as {@link #sendStickyBroadcast(Intent)},
1263 * but for a specific user. This broadcast
1264 * can only be sent to receivers that are part of the calling application. It
1265 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1266 * permission.
1267 *
1268 * @param intent The Intent to broadcast; all receivers matching this
1269 * Intent will receive the broadcast, and the Intent will be held to
1270 * be re-broadcast to future receivers.
1271 * @param user UserHandle to send the intent to.
1272 *
1273 * @see #sendBroadcast(Intent)
1274 */
1275 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1276
1277 /**
1278 * Same as
1279 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1280 * but for a specific user. This broadcast
1281 * can only be sent to receivers that are part of the calling application. It
1282 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1283 * permission.
1284 *
1285 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1286 *
1287 * @param intent The Intent to broadcast; all receivers matching this
1288 * Intent will receive the broadcast.
1289 * @param user UserHandle to send the intent to.
1290 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1291 * receiver of the broadcast.
1292 * @param scheduler A custom Handler with which to schedule the
1293 * resultReceiver callback; if null it will be
1294 * scheduled in the Context's main thread.
1295 * @param initialCode An initial value for the result code. Often
1296 * Activity.RESULT_OK.
1297 * @param initialData An initial value for the result data. Often
1298 * null.
1299 * @param initialExtras An initial value for the result extras. Often
1300 * null.
1301 *
1302 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1303 */
1304 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1305 UserHandle user, BroadcastReceiver resultReceiver,
1306 Handler scheduler, int initialCode, String initialData,
1307 Bundle initialExtras);
1308
1309 /**
1310 * Same as
1311 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1312 * but for a specific user. This broadcast
1313 * can only be sent to receivers that are part of the calling application. It
1314 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1315 * permission.
1316 *
1317 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1318 * permission in order to use this API. If you do not hold that
1319 * permission, {@link SecurityException} will be thrown.
1320 *
1321 * @param intent The Intent that was previously broadcast.
1322 * @param user UserHandle to remove the sticky broadcast from.
1323 *
1324 * @see #sendStickyBroadcastAsUser
1325 */
1326 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1327
1328 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07001329 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 * <var>receiver</var> will be called with any broadcast Intent that
1331 * matches <var>filter</var>, in the main application thread.
1332 *
1333 * <p>The system may broadcast Intents that are "sticky" -- these stay
1334 * around after the broadcast as finished, to be sent to any later
1335 * registrations. If your IntentFilter matches one of these sticky
1336 * Intents, that Intent will be returned by this function
1337 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1338 * been broadcast.
1339 *
1340 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1341 * in which case each of these will be sent to <var>receiver</var>. In
1342 * this case, only one of these can be returned directly by the function;
1343 * which of these that is returned is arbitrarily decided by the system.
1344 *
1345 * <p>If you know the Intent your are registering for is sticky, you can
1346 * supply null for your <var>receiver</var>. In this case, no receiver is
1347 * registered -- the function simply returns the sticky Intent that
1348 * matches <var>filter</var>. In the case of multiple matches, the same
1349 * rules as described above apply.
1350 *
1351 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1352 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001353 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1354 * registered with this method will correctly respect the
1355 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1356 * Prior to that, it would be ignored and delivered to all matching registered
1357 * receivers. Be careful if using this for security.</p>
1358 *
Chris Tatea34df8a22009-04-02 23:15:58 -07001359 * <p class="note">Note: this method <em>cannot be called from a
1360 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1361 * that is declared in an application's manifest. It is okay, however, to call
1362 * this method from another BroadcastReceiver that has itself been registered
1363 * at run time with {@link #registerReceiver}, since the lifetime of such a
1364 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 *
1366 * @param receiver The BroadcastReceiver to handle the broadcast.
1367 * @param filter Selects the Intent broadcasts to be received.
1368 *
1369 * @return The first sticky intent found that matches <var>filter</var>,
1370 * or null if there are none.
1371 *
1372 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1373 * @see #sendBroadcast
1374 * @see #unregisterReceiver
1375 */
1376 public abstract Intent registerReceiver(BroadcastReceiver receiver,
1377 IntentFilter filter);
1378
1379 /**
1380 * Register to receive intent broadcasts, to run in the context of
1381 * <var>scheduler</var>. See
1382 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1383 * information. This allows you to enforce permissions on who can
1384 * broadcast intents to your receiver, or have the receiver run in
1385 * a different thread than the main application thread.
1386 *
1387 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1388 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001389 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1390 * registered with this method will correctly respect the
1391 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1392 * Prior to that, it would be ignored and delivered to all matching registered
1393 * receivers. Be careful if using this for security.</p>
1394 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001395 * @param receiver The BroadcastReceiver to handle the broadcast.
1396 * @param filter Selects the Intent broadcasts to be received.
1397 * @param broadcastPermission String naming a permissions that a
1398 * broadcaster must hold in order to send an Intent to you. If null,
1399 * no permission is required.
1400 * @param scheduler Handler identifying the thread that will receive
1401 * the Intent. If null, the main thread of the process will be used.
1402 *
1403 * @return The first sticky intent found that matches <var>filter</var>,
1404 * or null if there are none.
1405 *
1406 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1407 * @see #sendBroadcast
1408 * @see #unregisterReceiver
1409 */
1410 public abstract Intent registerReceiver(BroadcastReceiver receiver,
1411 IntentFilter filter,
1412 String broadcastPermission,
1413 Handler scheduler);
1414
1415 /**
1416 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1417 * filters that have been registered for this BroadcastReceiver will be
1418 * removed.
1419 *
1420 * @param receiver The BroadcastReceiver to unregister.
1421 *
1422 * @see #registerReceiver
1423 */
1424 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1425
1426 /**
1427 * Request that a given application service be started. The Intent
1428 * can either contain the complete class name of a specific service
1429 * implementation to start, or an abstract definition through the
1430 * action and other fields of the kind of service to start. If this service
1431 * is not already running, it will be instantiated and started (creating a
1432 * process for it if needed); if it is running then it remains running.
1433 *
1434 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001435 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 * with the <var>intent</var> given here. This provides a convenient way
1437 * to submit jobs to a service without having to bind and call on to its
1438 * interface.
1439 *
1440 * <p>Using startService() overrides the default service lifetime that is
1441 * managed by {@link #bindService}: it requires the service to remain
1442 * running until {@link #stopService} is called, regardless of whether
1443 * any clients are connected to it. Note that calls to startService()
1444 * are not nesting: no matter how many times you call startService(),
1445 * a single call to {@link #stopService} will stop it.
1446 *
1447 * <p>The system attempts to keep running services around as much as
1448 * possible. The only time they should be stopped is if the current
1449 * foreground application is using so many resources that the service needs
1450 * to be killed. If any errors happen in the service's process, it will
1451 * automatically be restarted.
1452 *
1453 * <p>This function will throw {@link SecurityException} if you do not
1454 * have permission to start the given service.
1455 *
1456 * @param service Identifies the service to be started. The Intent may
1457 * specify either an explicit component name to start, or a logical
1458 * description (action, category, etc) to match an
1459 * {@link IntentFilter} published by a service. Additional values
1460 * may be included in the Intent extras to supply arguments along with
1461 * this specific start call.
1462 *
1463 * @return If the service is being started or is already running, the
1464 * {@link ComponentName} of the actual service that was started is
1465 * returned; else if the service does not exist null is returned.
1466 *
1467 * @throws SecurityException
1468 *
1469 * @see #stopService
1470 * @see #bindService
1471 */
1472 public abstract ComponentName startService(Intent service);
1473
1474 /**
1475 * Request that a given application service be stopped. If the service is
1476 * not running, nothing happens. Otherwise it is stopped. Note that calls
1477 * to startService() are not counted -- this stops the service no matter
1478 * how many times it was started.
1479 *
1480 * <p>Note that if a stopped service still has {@link ServiceConnection}
1481 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1482 * not be destroyed until all of these bindings are removed. See
1483 * the {@link android.app.Service} documentation for more details on a
1484 * service's lifecycle.
1485 *
1486 * <p>This function will throw {@link SecurityException} if you do not
1487 * have permission to stop the given service.
1488 *
1489 * @param service Description of the service to be stopped. The Intent may
1490 * specify either an explicit component name to start, or a logical
1491 * description (action, category, etc) to match an
1492 * {@link IntentFilter} published by a service.
1493 *
1494 * @return If there is a service matching the given Intent that is already
1495 * running, then it is stopped and true is returned; else false is returned.
1496 *
1497 * @throws SecurityException
1498 *
1499 * @see #startService
1500 */
1501 public abstract boolean stopService(Intent service);
1502
1503 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001504 * @hide like {@link #startService(Intent)} but for a specific user.
1505 */
1506 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1507
1508 /**
1509 * @hide like {@link #stopService(Intent)} but for a specific user.
1510 */
1511 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
1512
1513 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 * Connect to an application service, creating it if needed. This defines
1515 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001516 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 * told if it dies and restarts. The service will be considered required
1518 * by the system only for as long as the calling context exists. For
1519 * example, if this Context is an Activity that is stopped, the service will
1520 * not be required to continue running until the Activity is resumed.
1521 *
1522 * <p>This function will throw {@link SecurityException} if you do not
1523 * have permission to bind to the given service.
1524 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001525 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001526 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001527 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 * {@link #startService} with the arguments containing the command to be
1529 * sent, with the service calling its
1530 * {@link android.app.Service#stopSelf(int)} method when done executing
1531 * that command. See the API demo App/Service/Service Start Arguments
1532 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001533 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1535 * is tied to another object (the one that registered it).</p>
1536 *
1537 * @param service Identifies the service to connect to. The Intent may
1538 * specify either an explicit component name, or a logical
1539 * description (action, category, etc) to match an
1540 * {@link IntentFilter} published by a service.
1541 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07001542 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07001543 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07001544 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1545 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1546 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1547 * {@link #BIND_WAIVE_PRIORITY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001548 * @return If you have successfully bound to the service, true is returned;
1549 * false is returned if the connection is not made so you will not
1550 * receive the service object.
1551 *
1552 * @throws SecurityException
1553 *
1554 * @see #unbindService
1555 * @see #startService
1556 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07001557 * @see #BIND_DEBUG_UNBIND
1558 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 */
1560 public abstract boolean bindService(Intent service, ServiceConnection conn,
1561 int flags);
1562
1563 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001564 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001565 * argument for use by system server and other multi-user aware code.
1566 * @hide
1567 */
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001568 public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001569 throw new RuntimeException("Not implemented. Must override in a subclass.");
1570 }
1571
1572 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001573 * Disconnect from an application service. You will no longer receive
1574 * calls as the service is restarted, and the service is now allowed to
1575 * stop at any time.
1576 *
1577 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07001578 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 *
1580 * @see #bindService
1581 */
1582 public abstract void unbindService(ServiceConnection conn);
1583
1584 /**
1585 * Start executing an {@link android.app.Instrumentation} class. The given
1586 * Instrumentation component will be run by killing its target application
1587 * (if currently running), starting the target process, instantiating the
1588 * instrumentation component, and then letting it drive the application.
1589 *
1590 * <p>This function is not synchronous -- it returns as soon as the
1591 * instrumentation has started and while it is running.
1592 *
1593 * <p>Instrumentation is normally only allowed to run against a package
1594 * that is either unsigned or signed with a signature that the
1595 * the instrumentation package is also signed with (ensuring the target
1596 * trusts the instrumentation).
1597 *
1598 * @param className Name of the Instrumentation component to be run.
1599 * @param profileFile Optional path to write profiling data as the
1600 * instrumentation runs, or null for no profiling.
1601 * @param arguments Additional optional arguments to pass to the
1602 * instrumentation, or null.
1603 *
1604 * @return Returns true if the instrumentation was successfully started,
1605 * else false if it could not be found.
1606 */
1607 public abstract boolean startInstrumentation(ComponentName className,
1608 String profileFile, Bundle arguments);
1609
1610 /**
1611 * Return the handle to a system-level service by name. The class of the
1612 * returned object varies by the requested name. Currently available names
1613 * are:
Scott Main4b5da682010-10-21 11:49:12 -07001614 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 * <dl>
1616 * <dt> {@link #WINDOW_SERVICE} ("window")
1617 * <dd> The top-level window manager in which you can place custom
1618 * windows. The returned object is a {@link android.view.WindowManager}.
1619 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
1620 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
1621 * in this context.
1622 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
1623 * <dd> A {@link android.app.ActivityManager} for interacting with the
1624 * global activity state of the system.
1625 * <dt> {@link #POWER_SERVICE} ("power")
1626 * <dd> A {@link android.os.PowerManager} for controlling power
1627 * management.
1628 * <dt> {@link #ALARM_SERVICE} ("alarm")
1629 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
1630 * time of your choosing.
1631 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
1632 * <dd> A {@link android.app.NotificationManager} for informing the user
1633 * of background events.
1634 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
1635 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
1636 * <dt> {@link #LOCATION_SERVICE} ("location")
1637 * <dd> A {@link android.location.LocationManager} for controlling location
1638 * (e.g., GPS) updates.
1639 * <dt> {@link #SEARCH_SERVICE} ("search")
1640 * <dd> A {@link android.app.SearchManager} for handling search.
1641 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
1642 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
1643 * hardware.
1644 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
1645 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
1646 * handling management of network connections.
1647 * <dt> {@link #WIFI_SERVICE} ("wifi")
1648 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
1649 * Wi-Fi connectivity.
1650 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
1651 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
1652 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08001653 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
1654 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07001655 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07001656 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001657 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07001658 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 * <p>Note: System services obtained via this API may be closely associated with
1660 * the Context in which they are obtained from. In general, do not share the
1661 * service objects between various different contexts (Activities, Applications,
1662 * Services, Providers, etc.)
1663 *
1664 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07001665 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07001667 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 * @see #WINDOW_SERVICE
1669 * @see android.view.WindowManager
1670 * @see #LAYOUT_INFLATER_SERVICE
1671 * @see android.view.LayoutInflater
1672 * @see #ACTIVITY_SERVICE
1673 * @see android.app.ActivityManager
1674 * @see #POWER_SERVICE
1675 * @see android.os.PowerManager
1676 * @see #ALARM_SERVICE
1677 * @see android.app.AlarmManager
1678 * @see #NOTIFICATION_SERVICE
1679 * @see android.app.NotificationManager
1680 * @see #KEYGUARD_SERVICE
1681 * @see android.app.KeyguardManager
1682 * @see #LOCATION_SERVICE
1683 * @see android.location.LocationManager
1684 * @see #SEARCH_SERVICE
1685 * @see android.app.SearchManager
1686 * @see #SENSOR_SERVICE
1687 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08001688 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08001689 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001690 * @see #VIBRATOR_SERVICE
1691 * @see android.os.Vibrator
1692 * @see #CONNECTIVITY_SERVICE
1693 * @see android.net.ConnectivityManager
1694 * @see #WIFI_SERVICE
1695 * @see android.net.wifi.WifiManager
1696 * @see #AUDIO_SERVICE
1697 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07001698 * @see #MEDIA_ROUTER_SERVICE
1699 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 * @see #TELEPHONY_SERVICE
1701 * @see android.telephony.TelephonyManager
1702 * @see #INPUT_METHOD_SERVICE
1703 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08001704 * @see #UI_MODE_SERVICE
1705 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07001706 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07001707 * @see android.app.DownloadManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 */
1709 public abstract Object getSystemService(String name);
1710
1711 /**
1712 * Use with {@link #getSystemService} to retrieve a
1713 * {@link android.os.PowerManager} for controlling power management,
1714 * including "wake locks," which let you keep the device on while
1715 * you're running long tasks.
1716 */
1717 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07001718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 /**
1720 * Use with {@link #getSystemService} to retrieve a
1721 * {@link android.view.WindowManager} for accessing the system's window
1722 * manager.
1723 *
1724 * @see #getSystemService
1725 * @see android.view.WindowManager
1726 */
1727 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07001728
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001729 /**
1730 * Use with {@link #getSystemService} to retrieve a
1731 * {@link android.view.LayoutInflater} for inflating layout resources in this
1732 * context.
1733 *
1734 * @see #getSystemService
1735 * @see android.view.LayoutInflater
1736 */
1737 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07001738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 /**
1740 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07001741 * {@link android.accounts.AccountManager} for receiving intents at a
1742 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07001743 *
1744 * @see #getSystemService
1745 * @see android.accounts.AccountManager
1746 */
1747 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07001748
Fred Quintana60307342009-03-24 22:48:12 -07001749 /**
1750 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001751 * {@link android.app.ActivityManager} for interacting with the global
1752 * system state.
1753 *
1754 * @see #getSystemService
1755 * @see android.app.ActivityManager
1756 */
1757 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07001758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 /**
1760 * Use with {@link #getSystemService} to retrieve a
1761 * {@link android.app.AlarmManager} for receiving intents at a
1762 * time of your choosing.
1763 *
1764 * @see #getSystemService
1765 * @see android.app.AlarmManager
1766 */
1767 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07001768
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 /**
1770 * Use with {@link #getSystemService} to retrieve a
1771 * {@link android.app.NotificationManager} for informing the user of
1772 * background events.
1773 *
1774 * @see #getSystemService
1775 * @see android.app.NotificationManager
1776 */
1777 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07001778
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001779 /**
1780 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07001781 * {@link android.view.accessibility.AccessibilityManager} for giving the user
1782 * feedback for UI events through the registered event listeners.
1783 *
1784 * @see #getSystemService
1785 * @see android.view.accessibility.AccessibilityManager
1786 */
1787 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07001788
svetoslavganov75986cf2009-05-14 22:28:01 -07001789 /**
1790 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 * {@link android.app.NotificationManager} for controlling keyguard.
1792 *
1793 * @see #getSystemService
1794 * @see android.app.KeyguardManager
1795 */
1796 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07001797
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 /**
1799 * Use with {@link #getSystemService} to retrieve a {@link
1800 * android.location.LocationManager} for controlling location
1801 * updates.
1802 *
1803 * @see #getSystemService
1804 * @see android.location.LocationManager
1805 */
1806 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08001807
1808 /**
1809 * Use with {@link #getSystemService} to retrieve a
1810 * {@link android.location.CountryDetector} for detecting the country that
1811 * the user is in.
1812 *
1813 * @hide
1814 */
1815 public static final String COUNTRY_DETECTOR = "country_detector";
1816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 /**
1818 * Use with {@link #getSystemService} to retrieve a {@link
1819 * android.app.SearchManager} for handling searches.
1820 *
1821 * @see #getSystemService
1822 * @see android.app.SearchManager
1823 */
1824 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07001825
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001826 /**
1827 * Use with {@link #getSystemService} to retrieve a {@link
1828 * android.hardware.SensorManager} for accessing sensors.
1829 *
1830 * @see #getSystemService
1831 * @see android.hardware.SensorManager
1832 */
1833 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07001834
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001835 /**
San Mehatc9d81752010-02-01 10:23:27 -08001836 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07001837 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08001838 * functions.
1839 *
1840 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08001841 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08001842 */
1843 public static final String STORAGE_SERVICE = "storage";
1844
1845 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 * Use with {@link #getSystemService} to retrieve a
1847 * com.android.server.WallpaperService for accessing wallpapers.
1848 *
1849 * @see #getSystemService
1850 */
1851 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07001852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 /**
1854 * Use with {@link #getSystemService} to retrieve a {@link
1855 * android.os.Vibrator} for interacting with the vibration hardware.
1856 *
1857 * @see #getSystemService
1858 * @see android.os.Vibrator
1859 */
1860 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07001861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 /**
1863 * Use with {@link #getSystemService} to retrieve a {@link
1864 * android.app.StatusBarManager} for interacting with the status bar.
1865 *
1866 * @see #getSystemService
1867 * @see android.app.StatusBarManager
1868 * @hide
1869 */
1870 public static final String STATUS_BAR_SERVICE = "statusbar";
1871
1872 /**
1873 * Use with {@link #getSystemService} to retrieve a {@link
1874 * android.net.ConnectivityManager} for handling management of
1875 * network connections.
1876 *
1877 * @see #getSystemService
1878 * @see android.net.ConnectivityManager
1879 */
1880 public static final String CONNECTIVITY_SERVICE = "connectivity";
1881
1882 /**
1883 * Use with {@link #getSystemService} to retrieve a {@link
Robert Greenwalt9e696c22010-04-01 14:45:18 -07001884 * android.net.ThrottleManager} for handling management of
1885 * throttling.
1886 *
1887 * @hide
1888 * @see #getSystemService
1889 * @see android.net.ThrottleManager
1890 */
1891 public static final String THROTTLE_SERVICE = "throttle";
1892
1893 /**
1894 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08001895 * android.os.IUpdateLock} for managing runtime sequences that
1896 * must not be interrupted by headless OTA application or similar.
1897 *
1898 * @hide
1899 * @see #getSystemService
1900 * @see android.os.UpdateLock
1901 */
1902 public static final String UPDATE_LOCK_SERVICE = "updatelock";
1903
1904 /**
1905 * Use with {@link #getSystemService} to retrieve a {@link
San Mehatd1df8ac2010-01-26 06:17:26 -08001906 * android.net.NetworkManagementService} for handling management of
1907 * system network services
1908 *
1909 * @hide
1910 * @see #getSystemService
1911 * @see android.net.NetworkManagementService
1912 */
1913 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
1914
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001915 /** {@hide} */
Jeff Sharkey75279902011-05-24 18:39:45 -07001916 public static final String NETWORK_STATS_SERVICE = "netstats";
1917 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001918 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
1919
San Mehatd1df8ac2010-01-26 06:17:26 -08001920 /**
1921 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922 * android.net.wifi.WifiManager} for handling management of
1923 * Wi-Fi access.
1924 *
1925 * @see #getSystemService
1926 * @see android.net.wifi.WifiManager
1927 */
1928 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07001929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 /**
repo sync55bc5f32011-06-24 14:23:07 -07001931 * Use with {@link #getSystemService} to retrieve a {@link
1932 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07001933 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07001934 *
1935 * @see #getSystemService
1936 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07001937 */
1938 public static final String WIFI_P2P_SERVICE = "wifip2p";
1939
1940 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001941 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07001942 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001943 * discovery
1944 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001945 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07001946 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001947 */
1948 public static final String NSD_SERVICE = "servicediscovery";
1949
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001950 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 * Use with {@link #getSystemService} to retrieve a
1952 * {@link android.media.AudioManager} for handling management of volume,
1953 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07001954 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 * @see #getSystemService
1956 * @see android.media.AudioManager
1957 */
1958 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07001959
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 /**
1961 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07001962 * {@link android.media.MediaRouter} for controlling and managing
1963 * routing of media.
1964 *
1965 * @see #getSystemService
1966 * @see android.media.MediaRouter
1967 */
1968 public static final String MEDIA_ROUTER_SERVICE = "media_router";
1969
1970 /**
1971 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001972 * {@link android.telephony.TelephonyManager} for handling management the
1973 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07001974 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001975 * @see #getSystemService
1976 * @see android.telephony.TelephonyManager
1977 */
1978 public static final String TELEPHONY_SERVICE = "phone";
1979
1980 /**
1981 * Use with {@link #getSystemService} to retrieve a
1982 * {@link android.text.ClipboardManager} for accessing and modifying
1983 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07001984 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 * @see #getSystemService
1986 * @see android.text.ClipboardManager
1987 */
1988 public static final String CLIPBOARD_SERVICE = "clipboard";
1989
1990 /**
Scott Main4b5da682010-10-21 11:49:12 -07001991 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 * {@link android.view.inputmethod.InputMethodManager} for accessing input
1993 * methods.
1994 *
1995 * @see #getSystemService
1996 */
1997 public static final String INPUT_METHOD_SERVICE = "input_method";
1998
1999 /**
2000 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002001 * {@link android.view.textservice.TextServicesManager} for accessing
2002 * text services.
2003 *
2004 * @see #getSystemService
2005 */
2006 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2007
2008 /**
2009 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002010 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002011 *
2012 * @hide
2013 * @see #getSystemService
2014 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002015 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002017 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002018 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002019 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002020 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002021 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002022 *
Christopher Tate487529a2009-04-29 14:03:25 -07002023 * @see #getSystemService
2024 */
2025 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002026
2027 /**
2028 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002029 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002030 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002031 * @see #getSystemService
2032 */
2033 public static final String DROPBOX_SERVICE = "dropbox";
2034
Christopher Tate487529a2009-04-29 14:03:25 -07002035 /**
Scott Main4b5da682010-10-21 11:49:12 -07002036 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002037 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002038 * device policy management.
2039 *
2040 * @see #getSystemService
2041 */
2042 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2043
2044 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002045 * Use with {@link #getSystemService} to retrieve a
2046 * {@link android.app.UiModeManager} for controlling UI modes.
2047 *
2048 * @see #getSystemService
2049 */
2050 public static final String UI_MODE_SERVICE = "uimode";
2051
2052 /**
Steve Howarda2709362010-07-02 17:12:48 -07002053 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002054 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002055 *
2056 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002057 */
2058 public static final String DOWNLOAD_SERVICE = "download";
2059
2060 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002061 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002062 * {@link android.nfc.NfcManager} for using NFC.
2063 *
2064 * @see #getSystemService
2065 */
2066 public static final String NFC_SERVICE = "nfc";
2067
2068 /**
2069 * Use with {@link #getSystemService} to retrieve a
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002070 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2071 *
2072 * @see #getSystemService
2073 * @hide
2074 */
2075 public static final String BLUETOOTH_SERVICE = "bluetooth";
2076
2077 /**
2078 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002079 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2080 *
2081 * @see #getSystemService
2082 */
2083 /** @hide */
2084 public static final String SIP_SERVICE = "sip";
2085
2086 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002087 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002088 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002089 * and for controlling this device's behavior as a USB device.
2090 *
2091 * @see #getSystemService
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002092 * @see android.harware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002093 */
2094 public static final String USB_SERVICE = "usb";
2095
2096 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002097 * Use with {@link #getSystemService} to retrieve a {@link
2098 * android.hardware.SerialManager} for access to serial ports.
2099 *
2100 * @see #getSystemService
2101 * @see android.harware.SerialManager
2102 *
2103 * @hide
2104 */
2105 public static final String SERIAL_SERVICE = "serial";
2106
2107 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002108 * Use with {@link #getSystemService} to retrieve a
2109 * {@link android.hardware.input.InputManager} for interacting with input devices.
2110 *
2111 * @see #getSystemService
2112 * @see android.hardware.input.InputManager
2113 */
2114 public static final String INPUT_SERVICE = "input";
2115
2116 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002117 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002118 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2119 *
2120 * @see #getSystemService
2121 * @see android.hardware.display.DisplayManager
2122 */
2123 public static final String DISPLAY_SERVICE = "display";
2124
2125 /**
2126 * Use with {@link #getSystemService} to retrieve a
Glenn Kasten07b04652012-04-23 15:00:43 -07002127 * {@link android.os.SchedulingPolicyService} for managing scheduling policy.
2128 *
2129 * @see #getSystemService
2130 * @see android.os.SchedulingPolicyService
2131 *
2132 * @hide
2133 */
2134 public static final String SCHEDULING_POLICY_SERVICE = "scheduling_policy";
2135
2136 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002137 * Use with {@link #getSystemService} to retrieve a
2138 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2139 *
2140 * @see #getSystemService
2141 * @see android.os.UserManager
2142 */
2143 public static final String USER_SERVICE = "user";
2144
2145 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002146 * Determine whether the given permission is allowed for a particular
2147 * process and user ID running in the system.
2148 *
2149 * @param permission The name of the permission being checked.
2150 * @param pid The process ID being checked against. Must be > 0.
2151 * @param uid The user ID being checked against. A uid of 0 is the root
2152 * user, which will pass every permission check.
2153 *
2154 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
2155 * pid/uid is allowed that permission, or
2156 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2157 *
2158 * @see PackageManager#checkPermission(String, String)
2159 * @see #checkCallingPermission
2160 */
2161 public abstract int checkPermission(String permission, int pid, int uid);
2162
2163 /**
2164 * Determine whether the calling process of an IPC you are handling has been
2165 * granted a particular permission. This is basically the same as calling
2166 * {@link #checkPermission(String, int, int)} with the pid and uid returned
2167 * by {@link android.os.Binder#getCallingPid} and
2168 * {@link android.os.Binder#getCallingUid}. One important difference
2169 * is that if you are not currently processing an IPC, this function
2170 * will always fail. This is done to protect against accidentally
2171 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2172 * to avoid this protection.
2173 *
2174 * @param permission The name of the permission being checked.
2175 *
2176 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
2177 * pid/uid is allowed that permission, or
2178 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2179 *
2180 * @see PackageManager#checkPermission(String, String)
2181 * @see #checkPermission
2182 * @see #checkCallingOrSelfPermission
2183 */
2184 public abstract int checkCallingPermission(String permission);
2185
2186 /**
2187 * Determine whether the calling process of an IPC <em>or you</em> have been
2188 * granted a particular permission. This is the same as
2189 * {@link #checkCallingPermission}, except it grants your own permissions
2190 * if you are not currently processing an IPC. Use with care!
2191 *
2192 * @param permission The name of the permission being checked.
2193 *
2194 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
2195 * pid/uid is allowed that permission, or
2196 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2197 *
2198 * @see PackageManager#checkPermission(String, String)
2199 * @see #checkPermission
2200 * @see #checkCallingPermission
2201 */
2202 public abstract int checkCallingOrSelfPermission(String permission);
2203
2204 /**
2205 * If the given permission is not allowed for a particular process
2206 * and user ID running in the system, throw a {@link SecurityException}.
2207 *
2208 * @param permission The name of the permission being checked.
2209 * @param pid The process ID being checked against. Must be &gt; 0.
2210 * @param uid The user ID being checked against. A uid of 0 is the root
2211 * user, which will pass every permission check.
2212 * @param message A message to include in the exception if it is thrown.
2213 *
2214 * @see #checkPermission(String, int, int)
2215 */
2216 public abstract void enforcePermission(
2217 String permission, int pid, int uid, String message);
2218
2219 /**
2220 * If the calling process of an IPC you are handling has not been
2221 * granted a particular permission, throw a {@link
2222 * SecurityException}. This is basically the same as calling
2223 * {@link #enforcePermission(String, int, int, String)} with the
2224 * pid and uid returned by {@link android.os.Binder#getCallingPid}
2225 * and {@link android.os.Binder#getCallingUid}. One important
2226 * difference is that if you are not currently processing an IPC,
2227 * this function will always throw the SecurityException. This is
2228 * done to protect against accidentally leaking permissions; you
2229 * can use {@link #enforceCallingOrSelfPermission} to avoid this
2230 * protection.
2231 *
2232 * @param permission The name of the permission being checked.
2233 * @param message A message to include in the exception if it is thrown.
2234 *
2235 * @see #checkCallingPermission(String)
2236 */
2237 public abstract void enforceCallingPermission(
2238 String permission, String message);
2239
2240 /**
2241 * If neither you nor the calling process of an IPC you are
2242 * handling has been granted a particular permission, throw a
2243 * {@link SecurityException}. This is the same as {@link
2244 * #enforceCallingPermission}, except it grants your own
2245 * permissions if you are not currently processing an IPC. Use
2246 * with care!
2247 *
2248 * @param permission The name of the permission being checked.
2249 * @param message A message to include in the exception if it is thrown.
2250 *
2251 * @see #checkCallingOrSelfPermission(String)
2252 */
2253 public abstract void enforceCallingOrSelfPermission(
2254 String permission, String message);
2255
2256 /**
2257 * Grant permission to access a specific Uri to another package, regardless
2258 * of whether that package has general permission to access the Uri's
2259 * content provider. This can be used to grant specific, temporary
2260 * permissions, typically in response to user interaction (such as the
2261 * user opening an attachment that you would like someone else to
2262 * display).
2263 *
2264 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2265 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2266 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2267 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
2268 * start an activity instead of this function directly. If you use this
2269 * function directly, you should be sure to call
2270 * {@link #revokeUriPermission} when the target should no longer be allowed
2271 * to access it.
2272 *
2273 * <p>To succeed, the content provider owning the Uri must have set the
2274 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
2275 * grantUriPermissions} attribute in its manifest or included the
2276 * {@link android.R.styleable#AndroidManifestGrantUriPermission
2277 * &lt;grant-uri-permissions&gt;} tag.
2278 *
2279 * @param toPackage The package you would like to allow to access the Uri.
2280 * @param uri The Uri you would like to grant access to.
2281 * @param modeFlags The desired access modes. Any combination of
2282 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2283 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2284 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2285 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2286 *
2287 * @see #revokeUriPermission
2288 */
2289 public abstract void grantUriPermission(String toPackage, Uri uri,
2290 int modeFlags);
2291
2292 /**
2293 * Remove all permissions to access a particular content provider Uri
2294 * that were previously added with {@link #grantUriPermission}. The given
2295 * Uri will match all previously granted Uris that are the same or a
2296 * sub-path of the given Uri. That is, revoking "content://foo/one" will
2297 * revoke both "content://foo/target" and "content://foo/target/sub", but not
2298 * "content://foo".
2299 *
2300 * @param uri The Uri you would like to revoke access to.
2301 * @param modeFlags The desired access modes. Any combination of
2302 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2303 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2304 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2305 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2306 *
2307 * @see #grantUriPermission
2308 */
2309 public abstract void revokeUriPermission(Uri uri, int modeFlags);
2310
2311 /**
2312 * Determine whether a particular process and user ID has been granted
2313 * permission to access a specific URI. This only checks for permissions
2314 * that have been explicitly granted -- if the given process/uid has
2315 * more general access to the URI's content provider then this check will
2316 * always fail.
2317 *
2318 * @param uri The uri that is being checked.
2319 * @param pid The process ID being checked against. Must be &gt; 0.
2320 * @param uid The user ID being checked against. A uid of 0 is the root
2321 * user, which will pass every permission check.
2322 * @param modeFlags The type of access to grant. May be one or both of
2323 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2324 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2325 *
2326 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
2327 * pid/uid is allowed to access that uri, or
2328 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2329 *
2330 * @see #checkCallingUriPermission
2331 */
2332 public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags);
2333
2334 /**
2335 * Determine whether the calling process and user ID has been
2336 * granted permission to access a specific URI. This is basically
2337 * the same as calling {@link #checkUriPermission(Uri, int, int,
2338 * int)} with the pid and uid returned by {@link
2339 * android.os.Binder#getCallingPid} and {@link
2340 * android.os.Binder#getCallingUid}. One important difference is
2341 * that if you are not currently processing an IPC, this function
2342 * will always fail.
2343 *
2344 * @param uri The uri that is being checked.
2345 * @param modeFlags The type of access to grant. May be one or both of
2346 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2347 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2348 *
2349 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2350 * is allowed to access that uri, or
2351 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2352 *
2353 * @see #checkUriPermission(Uri, int, int, int)
2354 */
2355 public abstract int checkCallingUriPermission(Uri uri, int modeFlags);
2356
2357 /**
2358 * Determine whether the calling process of an IPC <em>or you</em> has been granted
2359 * permission to access a specific URI. This is the same as
2360 * {@link #checkCallingUriPermission}, except it grants your own permissions
2361 * if you are not currently processing an IPC. Use with care!
2362 *
2363 * @param uri The uri that is being checked.
2364 * @param modeFlags The type of access to grant. May be one or both of
2365 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2366 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2367 *
2368 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2369 * is allowed to access that uri, or
2370 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2371 *
2372 * @see #checkCallingUriPermission
2373 */
2374 public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags);
2375
2376 /**
2377 * Check both a Uri and normal permission. This allows you to perform
2378 * both {@link #checkPermission} and {@link #checkUriPermission} in one
2379 * call.
2380 *
2381 * @param uri The Uri whose permission is to be checked, or null to not
2382 * do this check.
2383 * @param readPermission The permission that provides overall read access,
2384 * or null to not do this check.
2385 * @param writePermission The permission that provides overall write
2386 * acess, or null to not do this check.
2387 * @param pid The process ID being checked against. Must be &gt; 0.
2388 * @param uid The user ID being checked against. A uid of 0 is the root
2389 * user, which will pass every permission check.
2390 * @param modeFlags The type of access to grant. May be one or both of
2391 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2392 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2393 *
2394 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2395 * is allowed to access that uri or holds one of the given permissions, or
2396 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2397 */
2398 public abstract int checkUriPermission(Uri uri, String readPermission,
2399 String writePermission, int pid, int uid, int modeFlags);
2400
2401 /**
2402 * If a particular process and user ID has not been granted
2403 * permission to access a specific URI, throw {@link
2404 * SecurityException}. This only checks for permissions that have
2405 * been explicitly granted -- if the given process/uid has more
2406 * general access to the URI's content provider then this check
2407 * will always fail.
2408 *
2409 * @param uri The uri that is being checked.
2410 * @param pid The process ID being checked against. Must be &gt; 0.
2411 * @param uid The user ID being checked against. A uid of 0 is the root
2412 * user, which will pass every permission check.
2413 * @param modeFlags The type of access to grant. May be one or both of
2414 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2415 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2416 * @param message A message to include in the exception if it is thrown.
2417 *
2418 * @see #checkUriPermission(Uri, int, int, int)
2419 */
2420 public abstract void enforceUriPermission(
2421 Uri uri, int pid, int uid, int modeFlags, String message);
2422
2423 /**
2424 * If the calling process and user ID has not been granted
2425 * permission to access a specific URI, throw {@link
2426 * SecurityException}. This is basically the same as calling
2427 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
2428 * the pid and uid returned by {@link
2429 * android.os.Binder#getCallingPid} and {@link
2430 * android.os.Binder#getCallingUid}. One important difference is
2431 * that if you are not currently processing an IPC, this function
2432 * will always throw a SecurityException.
2433 *
2434 * @param uri The uri that is being checked.
2435 * @param modeFlags The type of access to grant. May be one or both of
2436 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2437 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2438 * @param message A message to include in the exception if it is thrown.
2439 *
2440 * @see #checkCallingUriPermission(Uri, int)
2441 */
2442 public abstract void enforceCallingUriPermission(
2443 Uri uri, int modeFlags, String message);
2444
2445 /**
2446 * If the calling process of an IPC <em>or you</em> has not been
2447 * granted permission to access a specific URI, throw {@link
2448 * SecurityException}. This is the same as {@link
2449 * #enforceCallingUriPermission}, except it grants your own
2450 * permissions if you are not currently processing an IPC. Use
2451 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07002452 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 * @param uri The uri that is being checked.
2454 * @param modeFlags The type of access to grant. May be one or both of
2455 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2456 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2457 * @param message A message to include in the exception if it is thrown.
2458 *
2459 * @see #checkCallingOrSelfUriPermission(Uri, int)
2460 */
2461 public abstract void enforceCallingOrSelfUriPermission(
2462 Uri uri, int modeFlags, String message);
2463
2464 /**
2465 * Enforce both a Uri and normal permission. This allows you to perform
2466 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
2467 * call.
Scott Main4b5da682010-10-21 11:49:12 -07002468 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 * @param uri The Uri whose permission is to be checked, or null to not
2470 * do this check.
2471 * @param readPermission The permission that provides overall read access,
2472 * or null to not do this check.
2473 * @param writePermission The permission that provides overall write
2474 * acess, or null to not do this check.
2475 * @param pid The process ID being checked against. Must be &gt; 0.
2476 * @param uid The user ID being checked against. A uid of 0 is the root
2477 * user, which will pass every permission check.
2478 * @param modeFlags The type of access to grant. May be one or both of
2479 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2480 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2481 * @param message A message to include in the exception if it is thrown.
2482 *
2483 * @see #checkUriPermission(Uri, String, String, int, int, int)
2484 */
2485 public abstract void enforceUriPermission(
2486 Uri uri, String readPermission, String writePermission,
2487 int pid, int uid, int modeFlags, String message);
2488
2489 /**
2490 * Flag for use with {@link #createPackageContext}: include the application
2491 * code with the context. This means loading code into the caller's
2492 * process, so that {@link #getClassLoader()} can be used to instantiate
2493 * the application's classes. Setting this flags imposes security
2494 * restrictions on what application context you can access; if the
2495 * requested application can not be safely loaded into your process,
2496 * java.lang.SecurityException will be thrown. If this flag is not set,
2497 * there will be no restrictions on the packages that can be loaded,
2498 * but {@link #getClassLoader} will always return the default system
2499 * class loader.
2500 */
2501 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
2502
2503 /**
2504 * Flag for use with {@link #createPackageContext}: ignore any security
2505 * restrictions on the Context being requested, allowing it to always
2506 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
2507 * to be loaded into a process even when it isn't safe to do so. Use
2508 * with extreme care!
2509 */
2510 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07002511
Romain Guy870e09f2009-07-06 16:35:25 -07002512 /**
2513 * Flag for use with {@link #createPackageContext}: a restricted context may
2514 * disable specific features. For instance, a View associated with a restricted
2515 * context would ignore particular XML attributes.
2516 */
2517 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518
2519 /**
2520 * Return a new Context object for the given application name. This
2521 * Context is the same as what the named application gets when it is
2522 * launched, containing the same resources and class loader. Each call to
2523 * this method returns a new instance of a Context object; Context objects
2524 * are not shared, however they share common state (Resources, ClassLoader,
2525 * etc) so the Context instance itself is fairly lightweight.
2526 *
2527 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
2528 * application with the given package name.
2529 *
2530 * <p>Throws {@link java.lang.SecurityException} if the Context requested
2531 * can not be loaded into the caller's process for security reasons (see
2532 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
2533 *
2534 * @param packageName Name of the application's package.
2535 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
2536 * or {@link #CONTEXT_IGNORE_SECURITY}.
2537 *
2538 * @return A Context for the application.
2539 *
2540 * @throws java.lang.SecurityException
2541 * @throws PackageManager.NameNotFoundException if there is no application with
2542 * the given package name
2543 */
2544 public abstract Context createPackageContext(String packageName,
2545 int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07002546
2547 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07002548 * Return a new Context object for the current Context but whose resources
2549 * are adjusted to match the given Configuration. Each call to this method
2550 * returns a new instance of a Contex object; Context objects are not
2551 * shared, however common state (ClassLoader, other Resources for the
2552 * same configuration) may be so the Context itself can be fairly lightweight.
2553 *
2554 * @param overrideConfiguration A {@link Configuration} specifying what
2555 * values to modify in the base Configuration of the original Context's
2556 * resources. If the base configuration changes (such as due to an
2557 * orientation change), the resources of this context will also change except
2558 * for those that have been explicitly overridden with a value here.
2559 *
2560 * @return A Context for the application.
2561 */
2562 public abstract Context createConfigurationContext(Configuration overrideConfiguration);
2563
2564 /**
Jeff Brown98365d72012-08-19 20:30:52 -07002565 * Gets the compatibility info holder for this context. This information
2566 * is provided on a per-application basis and is used to simulate lower density
2567 * display metrics for legacy applications.
2568 *
2569 * @return The compatibility info holder, or null if not required by the application.
2570 * @hide
2571 */
2572 public abstract CompatibilityInfoHolder getCompatibilityInfo();
2573
2574 /**
Romain Guy870e09f2009-07-06 16:35:25 -07002575 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07002576 *
Romain Guy870e09f2009-07-06 16:35:25 -07002577 * @return True if this Context is restricted, false otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07002578 *
Romain Guy870e09f2009-07-06 16:35:25 -07002579 * @see #CONTEXT_RESTRICTED
2580 */
2581 public boolean isRestricted() {
2582 return false;
2583 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002584}