blob: a70bf6cb52baf824d96bd028b27e5766fc35b5d8 [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;
37
38import java.io.File;
39import java.io.FileInputStream;
40import java.io.FileNotFoundException;
41import java.io.FileOutputStream;
42import java.io.IOException;
43import java.io.InputStream;
44
45/**
46 * Interface to global information about an application environment. This is
47 * an abstract class whose implementation is provided by
48 * the Android system. It
49 * allows access to application-specific resources and classes, as well as
50 * up-calls for application-level operations such as launching activities,
51 * broadcasting and receiving intents, etc.
52 */
53public abstract class Context {
54 /**
55 * File creation mode: the default mode, where the created file can only
56 * be accessed by the calling application (or all applications sharing the
57 * same user ID).
58 * @see #MODE_WORLD_READABLE
59 * @see #MODE_WORLD_WRITEABLE
60 */
61 public static final int MODE_PRIVATE = 0x0000;
62 /**
63 * File creation mode: allow all other applications to have read access
64 * to the created file.
65 * @see #MODE_PRIVATE
66 * @see #MODE_WORLD_WRITEABLE
67 */
68 public static final int MODE_WORLD_READABLE = 0x0001;
69 /**
70 * File creation mode: allow all other applications to have write access
71 * to the created file.
72 * @see #MODE_PRIVATE
73 * @see #MODE_WORLD_READABLE
74 */
75 public static final int MODE_WORLD_WRITEABLE = 0x0002;
76 /**
77 * File creation mode: for use with {@link #openFileOutput}, if the file
78 * already exists then write data to the end of the existing file
79 * instead of erasing it.
80 * @see #openFileOutput
81 */
82 public static final int MODE_APPEND = 0x8000;
83
84 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -080085 * SharedPreference loading flag: when set, the file on disk will
86 * be checked for modification even if the shared preferences
87 * instance is already loaded in this process. This behavior is
88 * sometimes desired in cases where the application has multiple
89 * processes, all writing to the same SharedPreferences file.
90 * Generally there are better forms of communication between
91 * processes, though.
92 *
93 * <p>This was the legacy (but undocumented) behavior in and
94 * before Gingerbread (Android 2.3) and this flag is implied when
95 * targetting such releases. For applications targetting SDK
96 * versions <em>greater than</em> Android 2.3, this flag must be
97 * explicitly set if desired.
98 *
99 * @see #getSharedPreferences
100 */
101 public static final int MODE_MULTI_PROCESS = 0x0004;
102
103 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700104 * Database open flag: when set, the database is opened with write-ahead
105 * logging enabled by default.
106 *
107 * @see #openOrCreateDatabase(String, int, CursorFactory)
108 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
109 * @see SQLiteDatabase#enableWriteAheadLogging
110 */
111 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
112
113 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 * Flag for {@link #bindService}: automatically create the service as long
115 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700116 * its {@link android.app.Service#onStartCommand}
117 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800118 * explicit call to {@link #startService}. Even without that, though,
119 * this still provides you with access to the service object while the
120 * service is created.
121 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700122 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
123 * not supplying this flag would also impact how important the system
124 * consider's the target service's process to be. When set, the only way
125 * for it to be raised was by binding from a service in which case it will
126 * only be important when that activity is in the foreground. Now to
127 * achieve this behavior you must explicitly supply the new flag
128 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
129 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
130 * the flags {@link #BIND_WAIVE_PRIORITY} and
131 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
132 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 */
134 public static final int BIND_AUTO_CREATE = 0x0001;
135
136 /**
137 * Flag for {@link #bindService}: include debugging help for mismatched
138 * calls to unbind. When this flag is set, the callstack of the following
139 * {@link #unbindService} call is retained, to be printed if a later
140 * incorrect unbind call is made. Note that doing this requires retaining
141 * information about the binding that was made for the lifetime of the app,
142 * resulting in a leak -- this should only be used for debugging.
143 */
144 public static final int BIND_DEBUG_UNBIND = 0x0002;
145
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800146 /**
147 * Flag for {@link #bindService}: don't allow this binding to raise
148 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700149 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800150 * as the client (so that its process will not be killable in any
151 * situation where the client is not killable), but for CPU scheduling
152 * purposes it may be left in the background. This only has an impact
153 * in the situation where the binding client is a foreground process
154 * and the target service is in a background process.
155 */
156 public static final int BIND_NOT_FOREGROUND = 0x0004;
157
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700158 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700159 * Flag for {@link #bindService}: indicates that the client application
160 * binding to this service considers the service to be more important than
161 * the app itself. When set, the platform will try to have the out of
162 * memory kill the app before it kills the service it is bound to, though
163 * this is not guaranteed to be the case.
164 */
165 public static final int BIND_ABOVE_CLIENT = 0x0008;
166
167 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700168 * Flag for {@link #bindService}: allow the process hosting the bound
169 * service to go through its normal memory management. It will be
170 * treated more like a running service, allowing the system to
171 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700172 * whim it may have, and being more aggressive about making it a candidate
173 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700174 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700175 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
176
177 /**
178 * Flag for {@link #bindService}: don't impact the scheduling or
179 * memory management priority of the target service's hosting process.
180 * Allows the service's process to be managed on the background LRU list
181 * just like a regular application process in the background.
182 */
183 public static final int BIND_WAIVE_PRIORITY = 0x0020;
184
185 /**
186 * Flag for {@link #bindService}: this service is very important to
187 * the client, so should be brought to the foreground process level
188 * when the client is. Normally a process can only be raised to the
189 * visibility level by a client, even if that client is in the foreground.
190 */
191 public static final int BIND_IMPORTANT = 0x0040;
192
193 /**
194 * Flag for {@link #bindService}: If binding from an activity, allow the
195 * target service's process importance to be raised based on whether the
196 * activity is visible to the user, regardless whether another flag is
197 * used to reduce the amount that the client process's overall importance
198 * is used to impact it.
199 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700200 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
201
202 /**
203 * Flag for {@link #bindService}: Don't consider the bound service to be
204 * visible, even if the caller is visible.
205 * @hide
206 */
207 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 /** Return an AssetManager instance for your application's package. */
210 public abstract AssetManager getAssets();
211
212 /** Return a Resources instance for your application's package. */
213 public abstract Resources getResources();
214
215 /** Return PackageManager instance to find global package information. */
216 public abstract PackageManager getPackageManager();
217
218 /** Return a ContentResolver instance for your application's package. */
219 public abstract ContentResolver getContentResolver();
220
221 /**
222 * Return the Looper for the main thread of the current process. This is
223 * the thread used to dispatch calls to application components (activities,
224 * services, etc).
225 */
226 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 /**
229 * Return the context of the single, global Application object of the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800230 * current process. This generally should only be used if you need a
231 * Context whose lifecycle is separate from the current context, that is
232 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700233 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800234 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800235 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800236 * <ul>
237 * <li> <p>If used from an Activity context, the receiver is being registered
238 * within that activity. This means that you are expected to unregister
239 * before the activity is done being destroyed; in fact if you do not do
240 * so, the framework will clean up your leaked registration as it removes
241 * the activity and log an error. Thus, if you use the Activity context
242 * to register a receiver that is static (global to the process, not
243 * associated with an Activity instance) then that registration will be
244 * removed on you at whatever point the activity you used is destroyed.
245 * <li> <p>If used from the Context returned here, the receiver is being
246 * registered with the global state associated with your application. Thus
247 * it will never be unregistered for you. This is necessary if the receiver
248 * is associated with static data, not a particular component. However
249 * using the ApplicationContext elsewhere can easily lead to serious leaks
250 * if you forget to unregister, unbind, etc.
251 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 */
253 public abstract Context getApplicationContext();
254
255 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700256 * Add a new {@link ComponentCallbacks} to the base application of the
257 * Context, which will be called at the same times as the ComponentCallbacks
258 * methods of activities and other components are called. Note that you
259 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
260 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700261 *
262 * @param callback The interface to call. This can be either a
263 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700264 */
265 public void registerComponentCallbacks(ComponentCallbacks callback) {
266 getApplicationContext().registerComponentCallbacks(callback);
267 }
268
269 /**
270 * Remove a {@link ComponentCallbacks} objec that was previously registered
271 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
272 */
273 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
274 getApplicationContext().unregisterComponentCallbacks(callback);
275 }
276
277 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 * Return a localized, styled CharSequence from the application's package's
279 * default string table.
280 *
281 * @param resId Resource id for the CharSequence text
282 */
283 public final CharSequence getText(int resId) {
284 return getResources().getText(resId);
285 }
286
287 /**
288 * Return a localized string from the application's package's
289 * default string table.
290 *
291 * @param resId Resource id for the string
292 */
293 public final String getString(int resId) {
294 return getResources().getString(resId);
295 }
296
297 /**
298 * Return a localized formatted string from the application's package's
299 * default string table, substituting the format arguments as defined in
300 * {@link java.util.Formatter} and {@link java.lang.String#format}.
301 *
302 * @param resId Resource id for the format string
303 * @param formatArgs The format arguments that will be used for substitution.
304 */
305
306 public final String getString(int resId, Object... formatArgs) {
307 return getResources().getString(resId, formatArgs);
308 }
309
310 /**
311 * Set the base theme for this context. Note that this should be called
312 * before any views are instantiated in the Context (for example before
313 * calling {@link android.app.Activity#setContentView} or
314 * {@link android.view.LayoutInflater#inflate}).
315 *
316 * @param resid The style resource describing the theme.
317 */
318 public abstract void setTheme(int resid);
319
Dianne Hackborn247fe742011-01-08 17:25:57 -0800320 /** @hide Needed for some internal implementation... not public because
321 * you can't assume this actually means anything. */
322 public int getThemeResId() {
323 return 0;
324 }
325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 /**
327 * Return the Theme object associated with this Context.
328 */
329 public abstract Resources.Theme getTheme();
330
331 /**
332 * Retrieve styled attribute information in this Context's theme. See
333 * {@link Resources.Theme#obtainStyledAttributes(int[])}
334 * for more information.
335 *
336 * @see Resources.Theme#obtainStyledAttributes(int[])
337 */
338 public final TypedArray obtainStyledAttributes(
339 int[] attrs) {
340 return getTheme().obtainStyledAttributes(attrs);
341 }
342
343 /**
344 * Retrieve styled attribute information in this Context's theme. See
345 * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
346 * for more information.
347 *
348 * @see Resources.Theme#obtainStyledAttributes(int, int[])
349 */
350 public final TypedArray obtainStyledAttributes(
351 int resid, int[] attrs) throws Resources.NotFoundException {
352 return getTheme().obtainStyledAttributes(resid, attrs);
353 }
354
355 /**
356 * Retrieve styled attribute information in this Context's theme. See
357 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
358 * for more information.
359 *
360 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
361 */
362 public final TypedArray obtainStyledAttributes(
363 AttributeSet set, int[] attrs) {
364 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
365 }
366
367 /**
368 * Retrieve styled attribute information in this Context's theme. See
369 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
370 * for more information.
371 *
372 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
373 */
374 public final TypedArray obtainStyledAttributes(
375 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
376 return getTheme().obtainStyledAttributes(
377 set, attrs, defStyleAttr, defStyleRes);
378 }
379
380 /**
381 * Return a class loader you can use to retrieve classes in this package.
382 */
383 public abstract ClassLoader getClassLoader();
384
385 /** Return the name of this application's package. */
386 public abstract String getPackageName();
387
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700388 /** Return the full application info for this context's package. */
389 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700390
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 /**
Kenny Root32148392010-01-21 15:40:47 -0800392 * Return the full path to this context's primary Android package.
393 * The Android package is a ZIP file which contains the application's
394 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 *
396 * <p>Note: this is not generally useful for applications, since they should
397 * not be directly accessing the file system.
398 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 * @return String Path to the resources.
400 */
401 public abstract String getPackageResourcePath();
402
403 /**
Kenny Root32148392010-01-21 15:40:47 -0800404 * Return the full path to this context's primary Android package.
405 * The Android package is a ZIP file which contains application's
406 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 *
408 * <p>Note: this is not generally useful for applications, since they should
409 * not be directly accessing the file system.
410 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 * @return String Path to the code and assets.
412 */
413 public abstract String getPackageCodePath();
414
415 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700416 * {@hide}
417 * Return the full path to the shared prefs file for the given prefs group name.
418 *
419 * <p>Note: this is not generally useful for applications, since they should
420 * not be directly accessing the file system.
421 */
422 public abstract File getSharedPrefsFile(String name);
423
424 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 * Retrieve and hold the contents of the preferences file 'name', returning
426 * a SharedPreferences through which you can retrieve and modify its
427 * values. Only one instance of the SharedPreferences object is returned
428 * to any callers for the same name, meaning they will see each other's
429 * edits as soon as they are made.
430 *
431 * @param name Desired preferences file. If a preferences file by this name
432 * does not exist, it will be created when you retrieve an
433 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
434 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
435 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800436 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
437 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
438 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
439 * is always on in apps targetting Gingerbread (Android 2.3) and below, and
440 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 *
442 * @return Returns the single SharedPreferences instance that can be used
443 * to retrieve and modify the preference values.
444 *
445 * @see #MODE_PRIVATE
446 * @see #MODE_WORLD_READABLE
447 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800448 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 */
450 public abstract SharedPreferences getSharedPreferences(String name,
451 int mode);
452
453 /**
454 * Open a private file associated with this Context's application package
455 * for reading.
456 *
457 * @param name The name of the file to open; can not contain path
458 * separators.
459 *
460 * @return FileInputStream Resulting input stream.
461 *
462 * @see #openFileOutput
463 * @see #fileList
464 * @see #deleteFile
465 * @see java.io.FileInputStream#FileInputStream(String)
466 */
467 public abstract FileInputStream openFileInput(String name)
468 throws FileNotFoundException;
469
470 /**
471 * Open a private file associated with this Context's application package
472 * for writing. Creates the file if it doesn't already exist.
473 *
474 * @param name The name of the file to open; can not contain path
475 * separators.
476 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
477 * default operation, {@link #MODE_APPEND} to append to an existing file,
478 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
479 * permissions.
480 *
481 * @return FileOutputStream Resulting output stream.
482 *
483 * @see #MODE_APPEND
484 * @see #MODE_PRIVATE
485 * @see #MODE_WORLD_READABLE
486 * @see #MODE_WORLD_WRITEABLE
487 * @see #openFileInput
488 * @see #fileList
489 * @see #deleteFile
490 * @see java.io.FileOutputStream#FileOutputStream(String)
491 */
492 public abstract FileOutputStream openFileOutput(String name, int mode)
493 throws FileNotFoundException;
494
495 /**
496 * Delete the given private file associated with this Context's
497 * application package.
498 *
499 * @param name The name of the file to delete; can not contain path
500 * separators.
501 *
502 * @return True if the file was successfully deleted; else
503 * false.
504 *
505 * @see #openFileInput
506 * @see #openFileOutput
507 * @see #fileList
508 * @see java.io.File#delete()
509 */
510 public abstract boolean deleteFile(String name);
511
512 /**
513 * Returns the absolute path on the filesystem where a file created with
514 * {@link #openFileOutput} is stored.
515 *
516 * @param name The name of the file for which you would like to get
517 * its path.
518 *
519 * @return Returns an absolute path to the given file.
520 *
521 * @see #openFileOutput
522 * @see #getFilesDir
523 * @see #getDir
524 */
525 public abstract File getFileStreamPath(String name);
526
527 /**
528 * Returns the absolute path to the directory on the filesystem where
529 * files created with {@link #openFileOutput} are stored.
530 *
531 * @return Returns the path of the directory holding application files.
532 *
533 * @see #openFileOutput
534 * @see #getFileStreamPath
535 * @see #getDir
536 */
537 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 /**
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800540 * Returns the absolute path to the directory on the external filesystem
541 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700542 * Environment.getExternalStorageDirectory()}) where the application can
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800543 * place persistent files it owns. These files are private to the
544 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700545 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800546 * <p>This is like {@link #getFilesDir()} in that these
547 * files will be deleted when the application is uninstalled, however there
548 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700549 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800550 * <ul>
551 * <li>External files are not always available: they will disappear if the
552 * user mounts the external storage on a computer or removes it. See the
553 * APIs on {@link android.os.Environment} for information in the storage state.
554 * <li>There is no security enforced with these files. All applications
555 * can read and write files placed here.
556 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700557 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800558 * <p>Here is an example of typical code to manipulate a file in
559 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700560 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800561 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
562 * private_file}
563 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700564 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800565 * file will be a path to a sub-directory of the given type. Though these files
566 * are not automatically scanned by the media scanner, you can explicitly
567 * add them to the media database with
568 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Ray Chenb7c8c762010-03-30 17:21:39 -0700569 * OnScanCompletedListener) MediaScannerConnection.scanFile}.
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800570 * Note that this is not the same as
571 * {@link android.os.Environment#getExternalStoragePublicDirectory
572 * Environment.getExternalStoragePublicDirectory()}, which provides
573 * directories of media shared by all applications. The
574 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700575 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800576 * application is uninstalled. Unlike
577 * {@link android.os.Environment#getExternalStoragePublicDirectory
578 * Environment.getExternalStoragePublicDirectory()}, the directory
579 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700580 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800581 * <p>Here is an example of typical code to manipulate a picture in
582 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700583 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800584 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
585 * private_picture}
Scott Main4b5da682010-10-21 11:49:12 -0700586 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800587 * @param type The type of files directory to return. May be null for
588 * the root of the files directory or one of
589 * the following Environment constants for a subdirectory:
590 * {@link android.os.Environment#DIRECTORY_MUSIC},
591 * {@link android.os.Environment#DIRECTORY_PODCASTS},
592 * {@link android.os.Environment#DIRECTORY_RINGTONES},
593 * {@link android.os.Environment#DIRECTORY_ALARMS},
594 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
595 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
596 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700597 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800598 * @return Returns the path of the directory holding application files
599 * on external storage. Returns null if external storage is not currently
600 * mounted so it could not ensure the path exists; you will need to call
601 * this method again when it is available.
602 *
603 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700604 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800605 */
606 public abstract File getExternalFilesDir(String type);
Scott Main4b5da682010-10-21 11:49:12 -0700607
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800608 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800609 * Return the directory where this application's OBB files (if there
610 * are any) can be found. Note if the application does not have any OBB
611 * files, this directory may not exist.
612 */
613 public abstract File getObbDir();
614
615 /**
Scott Main4b5da682010-10-21 11:49:12 -0700616 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800618 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700620 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800621 * <strong>Note: you should not <em>rely</em> on the system deleting these
622 * files for you; you should always have a reasonable maximum, such as 1 MB,
623 * for the amount of space you consume with cache files, and prune those
624 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700625 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 * @return Returns the path of the directory holding application cache files.
627 *
628 * @see #openFileOutput
629 * @see #getFileStreamPath
630 * @see #getDir
631 */
632 public abstract File getCacheDir();
633
634 /**
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800635 * Returns the absolute path to the directory on the external filesystem
636 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
637 * Environment.getExternalStorageDirectory()} where the application can
638 * place cache files it owns.
Scott Main4b5da682010-10-21 11:49:12 -0700639 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800640 * <p>This is like {@link #getCacheDir()} in that these
641 * files will be deleted when the application is uninstalled, however there
642 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700643 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800644 * <ul>
645 * <li>The platform does not monitor the space available in external storage,
646 * and thus will not automatically delete these files. Note that you should
647 * be managing the maximum space you will use for these anyway, just like
648 * with {@link #getCacheDir()}.
649 * <li>External files are not always available: they will disappear if the
650 * user mounts the external storage on a computer or removes it. See the
651 * APIs on {@link android.os.Environment} for information in the storage state.
652 * <li>There is no security enforced with these files. All applications
653 * can read and write files placed here.
654 * </ul>
655 *
656 * @return Returns the path of the directory holding application cache files
657 * on external storage. Returns null if external storage is not currently
658 * mounted so it could not ensure the path exists; you will need to call
659 * this method again when it is available.
660 *
661 * @see #getCacheDir
662 */
663 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700664
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800665 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 * Returns an array of strings naming the private files associated with
667 * this Context's application package.
668 *
669 * @return Array of strings naming the private files.
670 *
671 * @see #openFileInput
672 * @see #openFileOutput
673 * @see #deleteFile
674 */
675 public abstract String[] fileList();
676
677 /**
678 * Retrieve, creating if needed, a new directory in which the application
679 * can place its own custom data files. You can use the returned File
680 * object to create and access files in this directory. Note that files
681 * created through a File object will only be accessible by your own
682 * application; you can only set the mode of the entire directory, not
683 * of individual files.
684 *
685 * @param name Name of the directory to retrieve. This is a directory
686 * that is created as part of your application data.
687 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
688 * default operation, {@link #MODE_WORLD_READABLE} and
689 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
690 *
691 * @return Returns a File object for the requested directory. The directory
692 * will have been created if it does not already exist.
693 *
694 * @see #openFileOutput(String, int)
695 */
696 public abstract File getDir(String name, int mode);
697
698 /**
699 * Open a new private SQLiteDatabase associated with this Context's
700 * application package. Create the database file if it doesn't exist.
701 *
702 * @param name The name (unique in the application package) of the database.
703 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
704 * default operation, {@link #MODE_WORLD_READABLE}
705 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700706 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 * @param factory An optional factory class that is called to instantiate a
708 * cursor when query is called.
709 *
710 * @return The contents of a newly created database with the given name.
711 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
712 *
713 * @see #MODE_PRIVATE
714 * @see #MODE_WORLD_READABLE
715 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700716 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 * @see #deleteDatabase
718 */
719 public abstract SQLiteDatabase openOrCreateDatabase(String name,
720 int mode, CursorFactory factory);
721
722 /**
Vasu Nori74f170f2010-06-01 18:06:18 -0700723 * Open a new private SQLiteDatabase associated with this Context's
724 * application package. Creates the database file if it doesn't exist.
725 *
726 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
727 * used to handle corruption when sqlite reports database corruption.</p>
728 *
729 * @param name The name (unique in the application package) of the database.
730 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
731 * default operation, {@link #MODE_WORLD_READABLE}
732 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700733 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -0700734 * @param factory An optional factory class that is called to instantiate a
735 * cursor when query is called.
736 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Vasu Nori03acd512010-06-03 14:39:40 -0700737 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -0700738 * @return The contents of a newly created database with the given name.
739 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
740 *
741 * @see #MODE_PRIVATE
742 * @see #MODE_WORLD_READABLE
743 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700744 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -0700745 * @see #deleteDatabase
746 */
747 public abstract SQLiteDatabase openOrCreateDatabase(String name,
748 int mode, CursorFactory factory, DatabaseErrorHandler errorHandler);
749
750 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 * Delete an existing private SQLiteDatabase associated with this Context's
752 * application package.
753 *
754 * @param name The name (unique in the application package) of the
755 * database.
756 *
757 * @return True if the database was successfully deleted; else false.
758 *
759 * @see #openOrCreateDatabase
760 */
761 public abstract boolean deleteDatabase(String name);
762
763 /**
764 * Returns the absolute path on the filesystem where a database created with
765 * {@link #openOrCreateDatabase} is stored.
766 *
767 * @param name The name of the database for which you would like to get
768 * its path.
769 *
770 * @return Returns an absolute path to the given database.
771 *
772 * @see #openOrCreateDatabase
773 */
774 public abstract File getDatabasePath(String name);
775
776 /**
777 * Returns an array of strings naming the private databases associated with
778 * this Context's application package.
779 *
780 * @return Array of strings naming the private databases.
781 *
782 * @see #openOrCreateDatabase
783 * @see #deleteDatabase
784 */
785 public abstract String[] databaseList();
786
787 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700788 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700789 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700791 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 public abstract Drawable getWallpaper();
793
794 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700795 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700796 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700798 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 public abstract Drawable peekWallpaper();
800
801 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700802 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
803 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700805 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 public abstract int getWallpaperDesiredMinimumWidth();
807
808 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700809 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
810 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700812 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 public abstract int getWallpaperDesiredMinimumHeight();
814
815 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700816 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700817 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700818 * <p>This method requires the caller to hold the permission
819 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800820 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700821 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
823
824 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700825 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700826 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700827 * <p>This method requires the caller to hold the permission
828 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700830 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 public abstract void setWallpaper(InputStream data) throws IOException;
832
833 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700834 * @deprecated Use {@link android.app.WallpaperManager#clear
835 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700836 * <p>This method requires the caller to hold the permission
837 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700839 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 public abstract void clearWallpaper() throws IOException;
841
842 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700843 * Same as {@link #startActivity(Intent, Bundle)} with no options
844 * specified.
845 *
846 * @param intent The description of the activity to start.
847 *
848 * @throws ActivityNotFoundException
849 *
850 * @see {@link #startActivity(Intent, Bundle)}
851 * @see PackageManager#resolveActivity
852 */
853 public abstract void startActivity(Intent intent);
854
855 /**
Amith Yamasani82644082012-08-03 13:09:11 -0700856 * Same as {@link #startActivity(Intent)}, but for a specific user. It requires holding
857 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
858 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700859 * @param user The UserHandle of the user to start this activity for.
Amith Yamasani82644082012-08-03 13:09:11 -0700860 * @throws ActivityNotFoundException
861 * @hide
862 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700863 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -0700864 throw new RuntimeException("Not implemented. Must override in a subclass.");
865 }
866
867 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 * Launch a new activity. You will not receive any information about when
869 * the activity exits.
870 *
871 * <p>Note that if this method is being called from outside of an
872 * {@link android.app.Activity} Context, then the Intent must include
873 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
874 * without being started from an existing Activity, there is no existing
875 * task in which to place the new activity and thus it needs to be placed
876 * in its own separate task.
877 *
878 * <p>This method throws {@link ActivityNotFoundException}
879 * if there was no Activity found to run the given Intent.
880 *
881 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700882 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700883 * May be null if there are no options. See {@link android.app.ActivityOptions}
884 * for how to build the Bundle supplied here; there are no supported definitions
885 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 *
887 * @throws ActivityNotFoundException
888 *
Scott Main60dd5202012-06-23 00:01:22 -0700889 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 * @see PackageManager#resolveActivity
891 */
Dianne Hackborna4972e92012-03-14 10:38:05 -0700892 public abstract void startActivity(Intent intent, Bundle options);
893
894 /**
Amith Yamasani258848d2012-08-10 17:06:33 -0700895 * Same as {@link #startActivity(Intent, Bundle)}, but for a specific user. It requires holding
896 * the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL} permission.
897 * @param intent The description of the activity to start.
898 * @param options Additional options for how the Activity should be started.
899 * May be null if there are no options. See {@link android.app.ActivityOptions}
900 * for how to build the Bundle supplied here; there are no supported definitions
901 * for building it manually.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700902 * @param user The UserHandle of the user to start this activity for.
Amith Yamasani258848d2012-08-10 17:06:33 -0700903 * @throws ActivityNotFoundException
904 * @hide
905 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700906 public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -0700907 throw new RuntimeException("Not implemented. Must override in a subclass.");
908 }
909
910 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700911 * Same as {@link #startActivities(Intent[], Bundle)} with no options
912 * specified.
913 *
914 * @param intents An array of Intents to be started.
915 *
916 * @throws ActivityNotFoundException
917 *
918 * @see {@link #startActivities(Intent[], Bundle)}
919 * @see PackageManager#resolveActivity
920 */
921 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800922
923 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800924 * Launch multiple new activities. This is generally the same as calling
925 * {@link #startActivity(Intent)} for the first Intent in the array,
926 * that activity during its creation calling {@link #startActivity(Intent)}
927 * for the second entry, etc. Note that unlike that approach, generally
928 * none of the activities except the last in the array will be created
929 * at this point, but rather will be created when the user first visits
930 * them (due to pressing back from the activity on top).
931 *
932 * <p>This method throws {@link ActivityNotFoundException}
933 * if there was no Activity found for <em>any</em> given Intent. In this
934 * case the state of the activity stack is undefined (some Intents in the
935 * list may be on it, some not), so you probably want to avoid such situations.
936 *
937 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700938 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700939 * See {@link android.content.Context#startActivity(Intent, Bundle)
940 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800941 *
942 * @throws ActivityNotFoundException
943 *
Dianne Hackborna4972e92012-03-14 10:38:05 -0700944 * @see {@link #startActivities(Intent[])}
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800945 * @see PackageManager#resolveActivity
946 */
Dianne Hackborna4972e92012-03-14 10:38:05 -0700947 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800948
949 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700950 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
951 * with no options specified.
952 *
953 * @param intent The IntentSender to launch.
954 * @param fillInIntent If non-null, this will be provided as the
955 * intent parameter to {@link IntentSender#sendIntent}.
956 * @param flagsMask Intent flags in the original IntentSender that you
957 * would like to change.
958 * @param flagsValues Desired values for any bits set in
959 * <var>flagsMask</var>
960 * @param extraFlags Always set to 0.
961 *
962 * @see #startActivity(Intent)
963 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
964 */
965 public abstract void startIntentSender(IntentSender intent,
966 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
967 throws IntentSender.SendIntentException;
968
969 /**
970 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700971 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -0700972 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700973 * here; otherwise, its associated action will be executed (such as
974 * sending a broadcast) as if you had called
975 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -0700976 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700977 * @param intent The IntentSender to launch.
978 * @param fillInIntent If non-null, this will be provided as the
979 * intent parameter to {@link IntentSender#sendIntent}.
980 * @param flagsMask Intent flags in the original IntentSender that you
981 * would like to change.
982 * @param flagsValues Desired values for any bits set in
983 * <var>flagsMask</var>
984 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700985 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700986 * See {@link android.content.Context#startActivity(Intent, Bundle)
987 * Context.startActivity(Intent, Bundle)} for more details. If options
988 * have also been supplied by the IntentSender, options given here will
989 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700990 *
991 * @see #startActivity(Intent, Bundle)
992 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700993 */
994 public abstract void startIntentSender(IntentSender intent,
Dianne Hackborna4972e92012-03-14 10:38:05 -0700995 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
996 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -0700997
998 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800999 * Broadcast the given intent to all interested BroadcastReceivers. This
1000 * call is asynchronous; it returns immediately, and you will continue
1001 * executing while the receivers are run. No results are propagated from
1002 * receivers and receivers can not abort the broadcast. If you want
1003 * to allow receivers to propagate results or abort the broadcast, you must
1004 * send an ordered broadcast using
1005 * {@link #sendOrderedBroadcast(Intent, String)}.
1006 *
1007 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1008 *
1009 * @param intent The Intent to broadcast; all receivers matching this
1010 * Intent will receive the broadcast.
1011 *
1012 * @see android.content.BroadcastReceiver
1013 * @see #registerReceiver
1014 * @see #sendBroadcast(Intent, String)
1015 * @see #sendOrderedBroadcast(Intent, String)
1016 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1017 */
1018 public abstract void sendBroadcast(Intent intent);
1019
1020 /**
1021 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1022 * an optional required permission to be enforced. This
1023 * call is asynchronous; it returns immediately, and you will continue
1024 * executing while the receivers are run. No results are propagated from
1025 * receivers and receivers can not abort the broadcast. If you want
1026 * to allow receivers to propagate results or abort the broadcast, you must
1027 * send an ordered broadcast using
1028 * {@link #sendOrderedBroadcast(Intent, String)}.
1029 *
1030 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1031 *
1032 * @param intent The Intent to broadcast; all receivers matching this
1033 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001034 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001035 * a receiver must hold in order to receive your broadcast.
1036 * If null, no permission is required.
1037 *
1038 * @see android.content.BroadcastReceiver
1039 * @see #registerReceiver
1040 * @see #sendBroadcast(Intent)
1041 * @see #sendOrderedBroadcast(Intent, String)
1042 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1043 */
1044 public abstract void sendBroadcast(Intent intent,
1045 String receiverPermission);
1046
1047 /**
1048 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1049 * them one at a time to allow more preferred receivers to consume the
1050 * broadcast before it is delivered to less preferred receivers. This
1051 * call is asynchronous; it returns immediately, and you will continue
1052 * executing while the receivers are run.
1053 *
1054 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1055 *
1056 * @param intent The Intent to broadcast; all receivers matching this
1057 * Intent will receive the broadcast.
1058 * @param receiverPermission (optional) String naming a permissions that
1059 * a receiver must hold in order to receive your broadcast.
1060 * If null, no permission is required.
1061 *
1062 * @see android.content.BroadcastReceiver
1063 * @see #registerReceiver
1064 * @see #sendBroadcast(Intent)
1065 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1066 */
1067 public abstract void sendOrderedBroadcast(Intent intent,
1068 String receiverPermission);
1069
1070 /**
1071 * Version of {@link #sendBroadcast(Intent)} that allows you to
1072 * receive data back from the broadcast. This is accomplished by
1073 * supplying your own BroadcastReceiver when calling, which will be
1074 * treated as a final receiver at the end of the broadcast -- its
1075 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001076 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 * be serialized in the same way as calling
1078 * {@link #sendOrderedBroadcast(Intent, String)}.
1079 *
1080 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1081 * asynchronous; it will return before
1082 * resultReceiver.onReceive() is called.
1083 *
1084 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1085 *
1086 * @param intent The Intent to broadcast; all receivers matching this
1087 * Intent will receive the broadcast.
1088 * @param receiverPermission String naming a permissions that
1089 * a receiver must hold in order to receive your broadcast.
1090 * If null, no permission is required.
1091 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1092 * receiver of the broadcast.
1093 * @param scheduler A custom Handler with which to schedule the
1094 * resultReceiver callback; if null it will be
1095 * scheduled in the Context's main thread.
1096 * @param initialCode An initial value for the result code. Often
1097 * Activity.RESULT_OK.
1098 * @param initialData An initial value for the result data. Often
1099 * null.
1100 * @param initialExtras An initial value for the result extras. Often
1101 * null.
1102 *
1103 * @see #sendBroadcast(Intent)
1104 * @see #sendBroadcast(Intent, String)
1105 * @see #sendOrderedBroadcast(Intent, String)
1106 * @see #sendStickyBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001107 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001108 * @see android.content.BroadcastReceiver
1109 * @see #registerReceiver
1110 * @see android.app.Activity#RESULT_OK
1111 */
1112 public abstract void sendOrderedBroadcast(Intent intent,
1113 String receiverPermission, BroadcastReceiver resultReceiver,
1114 Handler scheduler, int initialCode, String initialData,
1115 Bundle initialExtras);
1116
1117 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001118 * Same as {@link #sendBroadcast(Intent)}, but for a specific user. This broadcast
1119 * can only be sent to receivers that are part of the calling application. It
1120 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1121 * permission.
1122 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001123 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001124 * @see #sendBroadcast(Intent)
1125 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001126 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001127
1128 /**
1129 * Same as
1130 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)},
1131 * but for a specific user. This broadcast
1132 * can only be sent to receivers that are part of the calling application. It
1133 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS}
1134 * permission.
1135 *
1136 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1137 *
1138 * @param intent The Intent to broadcast; all receivers matching this
1139 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001140 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001141 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1142 * receiver of the broadcast.
1143 * @param scheduler A custom Handler with which to schedule the
1144 * resultReceiver callback; if null it will be
1145 * scheduled in the Context's main thread.
1146 * @param initialCode An initial value for the result code. Often
1147 * Activity.RESULT_OK.
1148 * @param initialData An initial value for the result data. Often
1149 * null.
1150 * @param initialExtras An initial value for the result extras. Often
1151 * null.
1152 *
1153 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1154 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001155 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001156 BroadcastReceiver resultReceiver, Handler scheduler,
1157 int initialCode, String initialData, Bundle initialExtras);
1158
1159 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1161 * Intent you are sending stays around after the broadcast is complete,
1162 * so that others can quickly retrieve that data through the return
1163 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1164 * all other ways, this behaves the same as
1165 * {@link #sendBroadcast(Intent)}.
1166 *
1167 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1168 * permission in order to use this API. If you do not hold that
1169 * permission, {@link SecurityException} will be thrown.
1170 *
1171 * @param intent The Intent to broadcast; all receivers matching this
1172 * Intent will receive the broadcast, and the Intent will be held to
1173 * be re-broadcast to future receivers.
1174 *
1175 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001176 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 */
1178 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001179
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001180 /**
1181 * Version of {@link #sendStickyBroadcast} that allows you to
1182 * receive data back from the broadcast. This is accomplished by
1183 * supplying your own BroadcastReceiver when calling, which will be
1184 * treated as a final receiver at the end of the broadcast -- its
1185 * {@link BroadcastReceiver#onReceive} method will be called with
1186 * the result values collected from the other receivers. The broadcast will
1187 * be serialized in the same way as calling
1188 * {@link #sendOrderedBroadcast(Intent, String)}.
1189 *
1190 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1191 * asynchronous; it will return before
1192 * resultReceiver.onReceive() is called. Note that the sticky data
1193 * stored is only the data you initially supply to the broadcast, not
1194 * the result of any changes made by the receivers.
1195 *
1196 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1197 *
1198 * @param intent The Intent to broadcast; all receivers matching this
1199 * Intent will receive the broadcast.
1200 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1201 * receiver of the broadcast.
1202 * @param scheduler A custom Handler with which to schedule the
1203 * resultReceiver callback; if null it will be
1204 * scheduled in the Context's main thread.
1205 * @param initialCode An initial value for the result code. Often
1206 * Activity.RESULT_OK.
1207 * @param initialData An initial value for the result data. Often
1208 * null.
1209 * @param initialExtras An initial value for the result extras. Often
1210 * null.
1211 *
1212 * @see #sendBroadcast(Intent)
1213 * @see #sendBroadcast(Intent, String)
1214 * @see #sendOrderedBroadcast(Intent, String)
1215 * @see #sendStickyBroadcast(Intent)
1216 * @see android.content.BroadcastReceiver
1217 * @see #registerReceiver
1218 * @see android.app.Activity#RESULT_OK
1219 */
1220 public abstract void sendStickyOrderedBroadcast(Intent intent,
1221 BroadcastReceiver resultReceiver,
1222 Handler scheduler, int initialCode, String initialData,
1223 Bundle initialExtras);
1224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225
1226 /**
1227 * Remove the data previously sent with {@link #sendStickyBroadcast},
1228 * so that it is as if the sticky broadcast had never happened.
1229 *
1230 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1231 * permission in order to use this API. If you do not hold that
1232 * permission, {@link SecurityException} will be thrown.
1233 *
1234 * @param intent The Intent that was previously broadcast.
1235 *
1236 * @see #sendStickyBroadcast
1237 */
1238 public abstract void removeStickyBroadcast(Intent intent);
1239
1240 /**
Chris Tatea34df8a2009-04-02 23:15:58 -07001241 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 * <var>receiver</var> will be called with any broadcast Intent that
1243 * matches <var>filter</var>, in the main application thread.
1244 *
1245 * <p>The system may broadcast Intents that are "sticky" -- these stay
1246 * around after the broadcast as finished, to be sent to any later
1247 * registrations. If your IntentFilter matches one of these sticky
1248 * Intents, that Intent will be returned by this function
1249 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1250 * been broadcast.
1251 *
1252 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1253 * in which case each of these will be sent to <var>receiver</var>. In
1254 * this case, only one of these can be returned directly by the function;
1255 * which of these that is returned is arbitrarily decided by the system.
1256 *
1257 * <p>If you know the Intent your are registering for is sticky, you can
1258 * supply null for your <var>receiver</var>. In this case, no receiver is
1259 * registered -- the function simply returns the sticky Intent that
1260 * matches <var>filter</var>. In the case of multiple matches, the same
1261 * rules as described above apply.
1262 *
1263 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1264 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001265 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1266 * registered with this method will correctly respect the
1267 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1268 * Prior to that, it would be ignored and delivered to all matching registered
1269 * receivers. Be careful if using this for security.</p>
1270 *
Chris Tatea34df8a2009-04-02 23:15:58 -07001271 * <p class="note">Note: this method <em>cannot be called from a
1272 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1273 * that is declared in an application's manifest. It is okay, however, to call
1274 * this method from another BroadcastReceiver that has itself been registered
1275 * at run time with {@link #registerReceiver}, since the lifetime of such a
1276 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 *
1278 * @param receiver The BroadcastReceiver to handle the broadcast.
1279 * @param filter Selects the Intent broadcasts to be received.
1280 *
1281 * @return The first sticky intent found that matches <var>filter</var>,
1282 * or null if there are none.
1283 *
1284 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1285 * @see #sendBroadcast
1286 * @see #unregisterReceiver
1287 */
1288 public abstract Intent registerReceiver(BroadcastReceiver receiver,
1289 IntentFilter filter);
1290
1291 /**
1292 * Register to receive intent broadcasts, to run in the context of
1293 * <var>scheduler</var>. See
1294 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1295 * information. This allows you to enforce permissions on who can
1296 * broadcast intents to your receiver, or have the receiver run in
1297 * a different thread than the main application thread.
1298 *
1299 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1300 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001301 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1302 * registered with this method will correctly respect the
1303 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1304 * Prior to that, it would be ignored and delivered to all matching registered
1305 * receivers. Be careful if using this for security.</p>
1306 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 * @param receiver The BroadcastReceiver to handle the broadcast.
1308 * @param filter Selects the Intent broadcasts to be received.
1309 * @param broadcastPermission String naming a permissions that a
1310 * broadcaster must hold in order to send an Intent to you. If null,
1311 * no permission is required.
1312 * @param scheduler Handler identifying the thread that will receive
1313 * the Intent. If null, the main thread of the process will be used.
1314 *
1315 * @return The first sticky intent found that matches <var>filter</var>,
1316 * or null if there are none.
1317 *
1318 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1319 * @see #sendBroadcast
1320 * @see #unregisterReceiver
1321 */
1322 public abstract Intent registerReceiver(BroadcastReceiver receiver,
1323 IntentFilter filter,
1324 String broadcastPermission,
1325 Handler scheduler);
1326
1327 /**
1328 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1329 * filters that have been registered for this BroadcastReceiver will be
1330 * removed.
1331 *
1332 * @param receiver The BroadcastReceiver to unregister.
1333 *
1334 * @see #registerReceiver
1335 */
1336 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1337
1338 /**
1339 * Request that a given application service be started. The Intent
1340 * can either contain the complete class name of a specific service
1341 * implementation to start, or an abstract definition through the
1342 * action and other fields of the kind of service to start. If this service
1343 * is not already running, it will be instantiated and started (creating a
1344 * process for it if needed); if it is running then it remains running.
1345 *
1346 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001347 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348 * with the <var>intent</var> given here. This provides a convenient way
1349 * to submit jobs to a service without having to bind and call on to its
1350 * interface.
1351 *
1352 * <p>Using startService() overrides the default service lifetime that is
1353 * managed by {@link #bindService}: it requires the service to remain
1354 * running until {@link #stopService} is called, regardless of whether
1355 * any clients are connected to it. Note that calls to startService()
1356 * are not nesting: no matter how many times you call startService(),
1357 * a single call to {@link #stopService} will stop it.
1358 *
1359 * <p>The system attempts to keep running services around as much as
1360 * possible. The only time they should be stopped is if the current
1361 * foreground application is using so many resources that the service needs
1362 * to be killed. If any errors happen in the service's process, it will
1363 * automatically be restarted.
1364 *
1365 * <p>This function will throw {@link SecurityException} if you do not
1366 * have permission to start the given service.
1367 *
1368 * @param service Identifies the service to be started. The Intent may
1369 * specify either an explicit component name to start, or a logical
1370 * description (action, category, etc) to match an
1371 * {@link IntentFilter} published by a service. Additional values
1372 * may be included in the Intent extras to supply arguments along with
1373 * this specific start call.
1374 *
1375 * @return If the service is being started or is already running, the
1376 * {@link ComponentName} of the actual service that was started is
1377 * returned; else if the service does not exist null is returned.
1378 *
1379 * @throws SecurityException
1380 *
1381 * @see #stopService
1382 * @see #bindService
1383 */
1384 public abstract ComponentName startService(Intent service);
1385
1386 /**
1387 * Request that a given application service be stopped. If the service is
1388 * not running, nothing happens. Otherwise it is stopped. Note that calls
1389 * to startService() are not counted -- this stops the service no matter
1390 * how many times it was started.
1391 *
1392 * <p>Note that if a stopped service still has {@link ServiceConnection}
1393 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1394 * not be destroyed until all of these bindings are removed. See
1395 * the {@link android.app.Service} documentation for more details on a
1396 * service's lifecycle.
1397 *
1398 * <p>This function will throw {@link SecurityException} if you do not
1399 * have permission to stop the given service.
1400 *
1401 * @param service Description of the service to be stopped. The Intent may
1402 * specify either an explicit component name to start, or a logical
1403 * description (action, category, etc) to match an
1404 * {@link IntentFilter} published by a service.
1405 *
1406 * @return If there is a service matching the given Intent that is already
1407 * running, then it is stopped and true is returned; else false is returned.
1408 *
1409 * @throws SecurityException
1410 *
1411 * @see #startService
1412 */
1413 public abstract boolean stopService(Intent service);
1414
1415 /**
1416 * Connect to an application service, creating it if needed. This defines
1417 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001418 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001419 * told if it dies and restarts. The service will be considered required
1420 * by the system only for as long as the calling context exists. For
1421 * example, if this Context is an Activity that is stopped, the service will
1422 * not be required to continue running until the Activity is resumed.
1423 *
1424 * <p>This function will throw {@link SecurityException} if you do not
1425 * have permission to bind to the given service.
1426 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001427 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001428 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001429 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001430 * {@link #startService} with the arguments containing the command to be
1431 * sent, with the service calling its
1432 * {@link android.app.Service#stopSelf(int)} method when done executing
1433 * that command. See the API demo App/Service/Service Start Arguments
1434 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001435 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1437 * is tied to another object (the one that registered it).</p>
1438 *
1439 * @param service Identifies the service to connect to. The Intent may
1440 * specify either an explicit component name, or a logical
1441 * description (action, category, etc) to match an
1442 * {@link IntentFilter} published by a service.
1443 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07001444 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07001445 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07001446 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1447 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1448 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1449 * {@link #BIND_WAIVE_PRIORITY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 * @return If you have successfully bound to the service, true is returned;
1451 * false is returned if the connection is not made so you will not
1452 * receive the service object.
1453 *
1454 * @throws SecurityException
1455 *
1456 * @see #unbindService
1457 * @see #startService
1458 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07001459 * @see #BIND_DEBUG_UNBIND
1460 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 */
1462 public abstract boolean bindService(Intent service, ServiceConnection conn,
1463 int flags);
1464
1465 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001466 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001467 * argument for use by system server and other multi-user aware code.
1468 * @hide
1469 */
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001470 public boolean bindService(Intent service, ServiceConnection conn, int flags, int userHandle) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001471 throw new RuntimeException("Not implemented. Must override in a subclass.");
1472 }
1473
1474 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 * Disconnect from an application service. You will no longer receive
1476 * calls as the service is restarted, and the service is now allowed to
1477 * stop at any time.
1478 *
1479 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07001480 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 *
1482 * @see #bindService
1483 */
1484 public abstract void unbindService(ServiceConnection conn);
1485
1486 /**
1487 * Start executing an {@link android.app.Instrumentation} class. The given
1488 * Instrumentation component will be run by killing its target application
1489 * (if currently running), starting the target process, instantiating the
1490 * instrumentation component, and then letting it drive the application.
1491 *
1492 * <p>This function is not synchronous -- it returns as soon as the
1493 * instrumentation has started and while it is running.
1494 *
1495 * <p>Instrumentation is normally only allowed to run against a package
1496 * that is either unsigned or signed with a signature that the
1497 * the instrumentation package is also signed with (ensuring the target
1498 * trusts the instrumentation).
1499 *
1500 * @param className Name of the Instrumentation component to be run.
1501 * @param profileFile Optional path to write profiling data as the
1502 * instrumentation runs, or null for no profiling.
1503 * @param arguments Additional optional arguments to pass to the
1504 * instrumentation, or null.
1505 *
1506 * @return Returns true if the instrumentation was successfully started,
1507 * else false if it could not be found.
1508 */
1509 public abstract boolean startInstrumentation(ComponentName className,
1510 String profileFile, Bundle arguments);
1511
1512 /**
1513 * Return the handle to a system-level service by name. The class of the
1514 * returned object varies by the requested name. Currently available names
1515 * are:
Scott Main4b5da682010-10-21 11:49:12 -07001516 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 * <dl>
1518 * <dt> {@link #WINDOW_SERVICE} ("window")
1519 * <dd> The top-level window manager in which you can place custom
1520 * windows. The returned object is a {@link android.view.WindowManager}.
1521 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
1522 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
1523 * in this context.
1524 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
1525 * <dd> A {@link android.app.ActivityManager} for interacting with the
1526 * global activity state of the system.
1527 * <dt> {@link #POWER_SERVICE} ("power")
1528 * <dd> A {@link android.os.PowerManager} for controlling power
1529 * management.
1530 * <dt> {@link #ALARM_SERVICE} ("alarm")
1531 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
1532 * time of your choosing.
1533 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
1534 * <dd> A {@link android.app.NotificationManager} for informing the user
1535 * of background events.
1536 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
1537 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
1538 * <dt> {@link #LOCATION_SERVICE} ("location")
1539 * <dd> A {@link android.location.LocationManager} for controlling location
1540 * (e.g., GPS) updates.
1541 * <dt> {@link #SEARCH_SERVICE} ("search")
1542 * <dd> A {@link android.app.SearchManager} for handling search.
1543 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
1544 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
1545 * hardware.
1546 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
1547 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
1548 * handling management of network connections.
1549 * <dt> {@link #WIFI_SERVICE} ("wifi")
1550 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
1551 * Wi-Fi connectivity.
1552 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
1553 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
1554 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08001555 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
1556 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07001557 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07001558 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07001560 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001561 * <p>Note: System services obtained via this API may be closely associated with
1562 * the Context in which they are obtained from. In general, do not share the
1563 * service objects between various different contexts (Activities, Applications,
1564 * Services, Providers, etc.)
1565 *
1566 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07001567 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07001569 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 * @see #WINDOW_SERVICE
1571 * @see android.view.WindowManager
1572 * @see #LAYOUT_INFLATER_SERVICE
1573 * @see android.view.LayoutInflater
1574 * @see #ACTIVITY_SERVICE
1575 * @see android.app.ActivityManager
1576 * @see #POWER_SERVICE
1577 * @see android.os.PowerManager
1578 * @see #ALARM_SERVICE
1579 * @see android.app.AlarmManager
1580 * @see #NOTIFICATION_SERVICE
1581 * @see android.app.NotificationManager
1582 * @see #KEYGUARD_SERVICE
1583 * @see android.app.KeyguardManager
1584 * @see #LOCATION_SERVICE
1585 * @see android.location.LocationManager
1586 * @see #SEARCH_SERVICE
1587 * @see android.app.SearchManager
1588 * @see #SENSOR_SERVICE
1589 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08001590 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08001591 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 * @see #VIBRATOR_SERVICE
1593 * @see android.os.Vibrator
1594 * @see #CONNECTIVITY_SERVICE
1595 * @see android.net.ConnectivityManager
1596 * @see #WIFI_SERVICE
1597 * @see android.net.wifi.WifiManager
1598 * @see #AUDIO_SERVICE
1599 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07001600 * @see #MEDIA_ROUTER_SERVICE
1601 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 * @see #TELEPHONY_SERVICE
1603 * @see android.telephony.TelephonyManager
1604 * @see #INPUT_METHOD_SERVICE
1605 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08001606 * @see #UI_MODE_SERVICE
1607 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07001608 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07001609 * @see android.app.DownloadManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 */
1611 public abstract Object getSystemService(String name);
1612
1613 /**
1614 * Use with {@link #getSystemService} to retrieve a
1615 * {@link android.os.PowerManager} for controlling power management,
1616 * including "wake locks," which let you keep the device on while
1617 * you're running long tasks.
1618 */
1619 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07001620
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 /**
1622 * Use with {@link #getSystemService} to retrieve a
1623 * {@link android.view.WindowManager} for accessing the system's window
1624 * manager.
1625 *
1626 * @see #getSystemService
1627 * @see android.view.WindowManager
1628 */
1629 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07001630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001631 /**
1632 * Use with {@link #getSystemService} to retrieve a
1633 * {@link android.view.LayoutInflater} for inflating layout resources in this
1634 * context.
1635 *
1636 * @see #getSystemService
1637 * @see android.view.LayoutInflater
1638 */
1639 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07001640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 /**
1642 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07001643 * {@link android.accounts.AccountManager} for receiving intents at a
1644 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07001645 *
1646 * @see #getSystemService
1647 * @see android.accounts.AccountManager
1648 */
1649 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07001650
Fred Quintana60307342009-03-24 22:48:12 -07001651 /**
1652 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 * {@link android.app.ActivityManager} for interacting with the global
1654 * system state.
1655 *
1656 * @see #getSystemService
1657 * @see android.app.ActivityManager
1658 */
1659 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07001660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 /**
1662 * Use with {@link #getSystemService} to retrieve a
1663 * {@link android.app.AlarmManager} for receiving intents at a
1664 * time of your choosing.
1665 *
1666 * @see #getSystemService
1667 * @see android.app.AlarmManager
1668 */
1669 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07001670
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 /**
1672 * Use with {@link #getSystemService} to retrieve a
1673 * {@link android.app.NotificationManager} for informing the user of
1674 * background events.
1675 *
1676 * @see #getSystemService
1677 * @see android.app.NotificationManager
1678 */
1679 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07001680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 /**
1682 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07001683 * {@link android.view.accessibility.AccessibilityManager} for giving the user
1684 * feedback for UI events through the registered event listeners.
1685 *
1686 * @see #getSystemService
1687 * @see android.view.accessibility.AccessibilityManager
1688 */
1689 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07001690
svetoslavganov75986cf2009-05-14 22:28:01 -07001691 /**
1692 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 * {@link android.app.NotificationManager} for controlling keyguard.
1694 *
1695 * @see #getSystemService
1696 * @see android.app.KeyguardManager
1697 */
1698 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07001699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 /**
1701 * Use with {@link #getSystemService} to retrieve a {@link
1702 * android.location.LocationManager} for controlling location
1703 * updates.
1704 *
1705 * @see #getSystemService
1706 * @see android.location.LocationManager
1707 */
1708 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08001709
1710 /**
1711 * Use with {@link #getSystemService} to retrieve a
1712 * {@link android.location.CountryDetector} for detecting the country that
1713 * the user is in.
1714 *
1715 * @hide
1716 */
1717 public static final String COUNTRY_DETECTOR = "country_detector";
1718
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 /**
1720 * Use with {@link #getSystemService} to retrieve a {@link
1721 * android.app.SearchManager} for handling searches.
1722 *
1723 * @see #getSystemService
1724 * @see android.app.SearchManager
1725 */
1726 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07001727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 /**
1729 * Use with {@link #getSystemService} to retrieve a {@link
1730 * android.hardware.SensorManager} for accessing sensors.
1731 *
1732 * @see #getSystemService
1733 * @see android.hardware.SensorManager
1734 */
1735 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07001736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001737 /**
San Mehatc9d81752010-02-01 10:23:27 -08001738 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07001739 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08001740 * functions.
1741 *
1742 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08001743 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08001744 */
1745 public static final String STORAGE_SERVICE = "storage";
1746
1747 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001748 * Use with {@link #getSystemService} to retrieve a
1749 * com.android.server.WallpaperService for accessing wallpapers.
1750 *
1751 * @see #getSystemService
1752 */
1753 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07001754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001755 /**
1756 * Use with {@link #getSystemService} to retrieve a {@link
1757 * android.os.Vibrator} for interacting with the vibration hardware.
1758 *
1759 * @see #getSystemService
1760 * @see android.os.Vibrator
1761 */
1762 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07001763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 /**
1765 * Use with {@link #getSystemService} to retrieve a {@link
1766 * android.app.StatusBarManager} for interacting with the status bar.
1767 *
1768 * @see #getSystemService
1769 * @see android.app.StatusBarManager
1770 * @hide
1771 */
1772 public static final String STATUS_BAR_SERVICE = "statusbar";
1773
1774 /**
1775 * Use with {@link #getSystemService} to retrieve a {@link
1776 * android.net.ConnectivityManager} for handling management of
1777 * network connections.
1778 *
1779 * @see #getSystemService
1780 * @see android.net.ConnectivityManager
1781 */
1782 public static final String CONNECTIVITY_SERVICE = "connectivity";
1783
1784 /**
1785 * Use with {@link #getSystemService} to retrieve a {@link
Robert Greenwalt9e696c22010-04-01 14:45:18 -07001786 * android.net.ThrottleManager} for handling management of
1787 * throttling.
1788 *
1789 * @hide
1790 * @see #getSystemService
1791 * @see android.net.ThrottleManager
1792 */
1793 public static final String THROTTLE_SERVICE = "throttle";
1794
1795 /**
1796 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08001797 * android.os.IUpdateLock} for managing runtime sequences that
1798 * must not be interrupted by headless OTA application or similar.
1799 *
1800 * @hide
1801 * @see #getSystemService
1802 * @see android.os.UpdateLock
1803 */
1804 public static final String UPDATE_LOCK_SERVICE = "updatelock";
1805
1806 /**
1807 * Use with {@link #getSystemService} to retrieve a {@link
San Mehatd1df8ac2010-01-26 06:17:26 -08001808 * android.net.NetworkManagementService} for handling management of
1809 * system network services
1810 *
1811 * @hide
1812 * @see #getSystemService
1813 * @see android.net.NetworkManagementService
1814 */
1815 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
1816
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001817 /** {@hide} */
Jeff Sharkey75279902011-05-24 18:39:45 -07001818 public static final String NETWORK_STATS_SERVICE = "netstats";
1819 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07001820 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
1821
San Mehatd1df8ac2010-01-26 06:17:26 -08001822 /**
1823 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 * android.net.wifi.WifiManager} for handling management of
1825 * Wi-Fi access.
1826 *
1827 * @see #getSystemService
1828 * @see android.net.wifi.WifiManager
1829 */
1830 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07001831
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001832 /**
repo sync55bc5f32011-06-24 14:23:07 -07001833 * Use with {@link #getSystemService} to retrieve a {@link
1834 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07001835 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07001836 *
1837 * @see #getSystemService
1838 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07001839 */
1840 public static final String WIFI_P2P_SERVICE = "wifip2p";
1841
1842 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001843 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07001844 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001845 * discovery
1846 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001847 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07001848 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001849 */
1850 public static final String NSD_SERVICE = "servicediscovery";
1851
Irfan Sheriff7d024d32012-03-22 17:01:39 -07001852 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 * Use with {@link #getSystemService} to retrieve a
1854 * {@link android.media.AudioManager} for handling management of volume,
1855 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07001856 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001857 * @see #getSystemService
1858 * @see android.media.AudioManager
1859 */
1860 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07001861
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001862 /**
1863 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07001864 * {@link android.media.MediaRouter} for controlling and managing
1865 * routing of media.
1866 *
1867 * @see #getSystemService
1868 * @see android.media.MediaRouter
1869 */
1870 public static final String MEDIA_ROUTER_SERVICE = "media_router";
1871
1872 /**
1873 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 * {@link android.telephony.TelephonyManager} for handling management the
1875 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07001876 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 * @see #getSystemService
1878 * @see android.telephony.TelephonyManager
1879 */
1880 public static final String TELEPHONY_SERVICE = "phone";
1881
1882 /**
1883 * Use with {@link #getSystemService} to retrieve a
1884 * {@link android.text.ClipboardManager} for accessing and modifying
1885 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07001886 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 * @see #getSystemService
1888 * @see android.text.ClipboardManager
1889 */
1890 public static final String CLIPBOARD_SERVICE = "clipboard";
1891
1892 /**
Scott Main4b5da682010-10-21 11:49:12 -07001893 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 * {@link android.view.inputmethod.InputMethodManager} for accessing input
1895 * methods.
1896 *
1897 * @see #getSystemService
1898 */
1899 public static final String INPUT_METHOD_SERVICE = "input_method";
1900
1901 /**
1902 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09001903 * {@link android.view.textservice.TextServicesManager} for accessing
1904 * text services.
1905 *
1906 * @see #getSystemService
1907 */
1908 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
1909
1910 /**
1911 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08001912 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 *
1914 * @hide
1915 * @see #getSystemService
1916 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07001917 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07001918
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 /**
Christopher Tate487529a2009-04-29 14:03:25 -07001920 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08001921 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07001922 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07001923 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07001924 *
Christopher Tate487529a2009-04-29 14:03:25 -07001925 * @see #getSystemService
1926 */
1927 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07001928
1929 /**
1930 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08001931 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07001932 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07001933 * @see #getSystemService
1934 */
1935 public static final String DROPBOX_SERVICE = "dropbox";
1936
Christopher Tate487529a2009-04-29 14:03:25 -07001937 /**
Scott Main4b5da682010-10-21 11:49:12 -07001938 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08001939 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08001940 * device policy management.
1941 *
1942 * @see #getSystemService
1943 */
1944 public static final String DEVICE_POLICY_SERVICE = "device_policy";
1945
1946 /**
Tobias Haamel53332882010-02-18 16:15:43 -08001947 * Use with {@link #getSystemService} to retrieve a
1948 * {@link android.app.UiModeManager} for controlling UI modes.
1949 *
1950 * @see #getSystemService
1951 */
1952 public static final String UI_MODE_SERVICE = "uimode";
1953
1954 /**
Steve Howarda2709362010-07-02 17:12:48 -07001955 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07001956 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07001957 *
1958 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07001959 */
1960 public static final String DOWNLOAD_SERVICE = "download";
1961
1962 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08001963 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08001964 * {@link android.nfc.NfcManager} for using NFC.
1965 *
1966 * @see #getSystemService
1967 */
1968 public static final String NFC_SERVICE = "nfc";
1969
1970 /**
1971 * Use with {@link #getSystemService} to retrieve a
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08001972 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
1973 *
1974 * @see #getSystemService
1975 * @hide
1976 */
1977 public static final String BLUETOOTH_SERVICE = "bluetooth";
1978
1979 /**
1980 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08001981 * {@link android.net.sip.SipManager} for accessing the SIP related service.
1982 *
1983 * @see #getSystemService
1984 */
1985 /** @hide */
1986 public static final String SIP_SERVICE = "sip";
1987
1988 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001989 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08001990 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001991 * and for controlling this device's behavior as a USB device.
1992 *
1993 * @see #getSystemService
Mike Lockwoodc4308f02011-03-01 08:04:54 -08001994 * @see android.harware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001995 */
1996 public static final String USB_SERVICE = "usb";
1997
1998 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04001999 * Use with {@link #getSystemService} to retrieve a {@link
2000 * android.hardware.SerialManager} for access to serial ports.
2001 *
2002 * @see #getSystemService
2003 * @see android.harware.SerialManager
2004 *
2005 * @hide
2006 */
2007 public static final String SERIAL_SERVICE = "serial";
2008
2009 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002010 * Use with {@link #getSystemService} to retrieve a
2011 * {@link android.hardware.input.InputManager} for interacting with input devices.
2012 *
2013 * @see #getSystemService
2014 * @see android.hardware.input.InputManager
2015 */
2016 public static final String INPUT_SERVICE = "input";
2017
2018 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002019 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002020 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2021 *
2022 * @see #getSystemService
2023 * @see android.hardware.display.DisplayManager
2024 */
2025 public static final String DISPLAY_SERVICE = "display";
2026
2027 /**
2028 * Use with {@link #getSystemService} to retrieve a
Glenn Kasten07b04652012-04-23 15:00:43 -07002029 * {@link android.os.SchedulingPolicyService} for managing scheduling policy.
2030 *
2031 * @see #getSystemService
2032 * @see android.os.SchedulingPolicyService
2033 *
2034 * @hide
2035 */
2036 public static final String SCHEDULING_POLICY_SERVICE = "scheduling_policy";
2037
2038 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002039 * Use with {@link #getSystemService} to retrieve a
2040 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2041 *
2042 * @see #getSystemService
2043 * @see android.os.UserManager
2044 */
2045 public static final String USER_SERVICE = "user";
2046
2047 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 * Determine whether the given permission is allowed for a particular
2049 * process and user ID running in the system.
2050 *
2051 * @param permission The name of the permission being checked.
2052 * @param pid The process ID being checked against. Must be > 0.
2053 * @param uid The user ID being checked against. A uid of 0 is the root
2054 * user, which will pass every permission check.
2055 *
2056 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
2057 * pid/uid is allowed that permission, or
2058 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2059 *
2060 * @see PackageManager#checkPermission(String, String)
2061 * @see #checkCallingPermission
2062 */
2063 public abstract int checkPermission(String permission, int pid, int uid);
2064
2065 /**
2066 * Determine whether the calling process of an IPC you are handling has been
2067 * granted a particular permission. This is basically the same as calling
2068 * {@link #checkPermission(String, int, int)} with the pid and uid returned
2069 * by {@link android.os.Binder#getCallingPid} and
2070 * {@link android.os.Binder#getCallingUid}. One important difference
2071 * is that if you are not currently processing an IPC, this function
2072 * will always fail. This is done to protect against accidentally
2073 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2074 * to avoid this protection.
2075 *
2076 * @param permission The name of the permission being checked.
2077 *
2078 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
2079 * pid/uid is allowed that permission, or
2080 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2081 *
2082 * @see PackageManager#checkPermission(String, String)
2083 * @see #checkPermission
2084 * @see #checkCallingOrSelfPermission
2085 */
2086 public abstract int checkCallingPermission(String permission);
2087
2088 /**
2089 * Determine whether the calling process of an IPC <em>or you</em> have been
2090 * granted a particular permission. This is the same as
2091 * {@link #checkCallingPermission}, except it grants your own permissions
2092 * if you are not currently processing an IPC. Use with care!
2093 *
2094 * @param permission The name of the permission being checked.
2095 *
2096 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
2097 * pid/uid is allowed that permission, or
2098 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2099 *
2100 * @see PackageManager#checkPermission(String, String)
2101 * @see #checkPermission
2102 * @see #checkCallingPermission
2103 */
2104 public abstract int checkCallingOrSelfPermission(String permission);
2105
2106 /**
2107 * If the given permission is not allowed for a particular process
2108 * and user ID running in the system, throw a {@link SecurityException}.
2109 *
2110 * @param permission The name of the permission being checked.
2111 * @param pid The process ID being checked against. Must be &gt; 0.
2112 * @param uid The user ID being checked against. A uid of 0 is the root
2113 * user, which will pass every permission check.
2114 * @param message A message to include in the exception if it is thrown.
2115 *
2116 * @see #checkPermission(String, int, int)
2117 */
2118 public abstract void enforcePermission(
2119 String permission, int pid, int uid, String message);
2120
2121 /**
2122 * If the calling process of an IPC you are handling has not been
2123 * granted a particular permission, throw a {@link
2124 * SecurityException}. This is basically the same as calling
2125 * {@link #enforcePermission(String, int, int, String)} with the
2126 * pid and uid returned by {@link android.os.Binder#getCallingPid}
2127 * and {@link android.os.Binder#getCallingUid}. One important
2128 * difference is that if you are not currently processing an IPC,
2129 * this function will always throw the SecurityException. This is
2130 * done to protect against accidentally leaking permissions; you
2131 * can use {@link #enforceCallingOrSelfPermission} to avoid this
2132 * protection.
2133 *
2134 * @param permission The name of the permission being checked.
2135 * @param message A message to include in the exception if it is thrown.
2136 *
2137 * @see #checkCallingPermission(String)
2138 */
2139 public abstract void enforceCallingPermission(
2140 String permission, String message);
2141
2142 /**
2143 * If neither you nor the calling process of an IPC you are
2144 * handling has been granted a particular permission, throw a
2145 * {@link SecurityException}. This is the same as {@link
2146 * #enforceCallingPermission}, except it grants your own
2147 * permissions if you are not currently processing an IPC. Use
2148 * with care!
2149 *
2150 * @param permission The name of the permission being checked.
2151 * @param message A message to include in the exception if it is thrown.
2152 *
2153 * @see #checkCallingOrSelfPermission(String)
2154 */
2155 public abstract void enforceCallingOrSelfPermission(
2156 String permission, String message);
2157
2158 /**
2159 * Grant permission to access a specific Uri to another package, regardless
2160 * of whether that package has general permission to access the Uri's
2161 * content provider. This can be used to grant specific, temporary
2162 * permissions, typically in response to user interaction (such as the
2163 * user opening an attachment that you would like someone else to
2164 * display).
2165 *
2166 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2167 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2168 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2169 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
2170 * start an activity instead of this function directly. If you use this
2171 * function directly, you should be sure to call
2172 * {@link #revokeUriPermission} when the target should no longer be allowed
2173 * to access it.
2174 *
2175 * <p>To succeed, the content provider owning the Uri must have set the
2176 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
2177 * grantUriPermissions} attribute in its manifest or included the
2178 * {@link android.R.styleable#AndroidManifestGrantUriPermission
2179 * &lt;grant-uri-permissions&gt;} tag.
2180 *
2181 * @param toPackage The package you would like to allow to access the Uri.
2182 * @param uri The Uri you would like to grant access to.
2183 * @param modeFlags The desired access modes. Any combination of
2184 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2185 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2186 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2187 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2188 *
2189 * @see #revokeUriPermission
2190 */
2191 public abstract void grantUriPermission(String toPackage, Uri uri,
2192 int modeFlags);
2193
2194 /**
2195 * Remove all permissions to access a particular content provider Uri
2196 * that were previously added with {@link #grantUriPermission}. The given
2197 * Uri will match all previously granted Uris that are the same or a
2198 * sub-path of the given Uri. That is, revoking "content://foo/one" will
2199 * revoke both "content://foo/target" and "content://foo/target/sub", but not
2200 * "content://foo".
2201 *
2202 * @param uri The Uri you would like to revoke access to.
2203 * @param modeFlags The desired access modes. Any combination of
2204 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2205 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2206 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2207 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2208 *
2209 * @see #grantUriPermission
2210 */
2211 public abstract void revokeUriPermission(Uri uri, int modeFlags);
2212
2213 /**
2214 * Determine whether a particular process and user ID has been granted
2215 * permission to access a specific URI. This only checks for permissions
2216 * that have been explicitly granted -- if the given process/uid has
2217 * more general access to the URI's content provider then this check will
2218 * always fail.
2219 *
2220 * @param uri The uri that is being checked.
2221 * @param pid The process ID being checked against. Must be &gt; 0.
2222 * @param uid The user ID being checked against. A uid of 0 is the root
2223 * user, which will pass every permission check.
2224 * @param modeFlags The type of access to grant. May be one or both of
2225 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2226 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2227 *
2228 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
2229 * pid/uid is allowed to access that uri, or
2230 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2231 *
2232 * @see #checkCallingUriPermission
2233 */
2234 public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags);
2235
2236 /**
2237 * Determine whether the calling process and user ID has been
2238 * granted permission to access a specific URI. This is basically
2239 * the same as calling {@link #checkUriPermission(Uri, int, int,
2240 * int)} with the pid and uid returned by {@link
2241 * android.os.Binder#getCallingPid} and {@link
2242 * android.os.Binder#getCallingUid}. One important difference is
2243 * that if you are not currently processing an IPC, this function
2244 * will always fail.
2245 *
2246 * @param uri The uri that is being checked.
2247 * @param modeFlags The type of access to grant. May be one or both of
2248 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2249 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2250 *
2251 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2252 * is allowed to access that uri, or
2253 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2254 *
2255 * @see #checkUriPermission(Uri, int, int, int)
2256 */
2257 public abstract int checkCallingUriPermission(Uri uri, int modeFlags);
2258
2259 /**
2260 * Determine whether the calling process of an IPC <em>or you</em> has been granted
2261 * permission to access a specific URI. This is the same as
2262 * {@link #checkCallingUriPermission}, except it grants your own permissions
2263 * if you are not currently processing an IPC. Use with care!
2264 *
2265 * @param uri The uri that is being checked.
2266 * @param modeFlags The type of access to grant. May be one or both of
2267 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2268 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2269 *
2270 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2271 * is allowed to access that uri, or
2272 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2273 *
2274 * @see #checkCallingUriPermission
2275 */
2276 public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags);
2277
2278 /**
2279 * Check both a Uri and normal permission. This allows you to perform
2280 * both {@link #checkPermission} and {@link #checkUriPermission} in one
2281 * call.
2282 *
2283 * @param uri The Uri whose permission is to be checked, or null to not
2284 * do this check.
2285 * @param readPermission The permission that provides overall read access,
2286 * or null to not do this check.
2287 * @param writePermission The permission that provides overall write
2288 * acess, or null to not do this check.
2289 * @param pid The process ID being checked against. Must be &gt; 0.
2290 * @param uid The user ID being checked against. A uid of 0 is the root
2291 * user, which will pass every permission check.
2292 * @param modeFlags The type of access to grant. May be one or both of
2293 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2294 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2295 *
2296 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2297 * is allowed to access that uri or holds one of the given permissions, or
2298 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2299 */
2300 public abstract int checkUriPermission(Uri uri, String readPermission,
2301 String writePermission, int pid, int uid, int modeFlags);
2302
2303 /**
2304 * If a particular process and user ID has not been granted
2305 * permission to access a specific URI, throw {@link
2306 * SecurityException}. This only checks for permissions that have
2307 * been explicitly granted -- if the given process/uid has more
2308 * general access to the URI's content provider then this check
2309 * will always fail.
2310 *
2311 * @param uri The uri that is being checked.
2312 * @param pid The process ID being checked against. Must be &gt; 0.
2313 * @param uid The user ID being checked against. A uid of 0 is the root
2314 * user, which will pass every permission check.
2315 * @param modeFlags The type of access to grant. May be one or both of
2316 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2317 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2318 * @param message A message to include in the exception if it is thrown.
2319 *
2320 * @see #checkUriPermission(Uri, int, int, int)
2321 */
2322 public abstract void enforceUriPermission(
2323 Uri uri, int pid, int uid, int modeFlags, String message);
2324
2325 /**
2326 * If the calling process and user ID has not been granted
2327 * permission to access a specific URI, throw {@link
2328 * SecurityException}. This is basically the same as calling
2329 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
2330 * the pid and uid returned by {@link
2331 * android.os.Binder#getCallingPid} and {@link
2332 * android.os.Binder#getCallingUid}. One important difference is
2333 * that if you are not currently processing an IPC, this function
2334 * will always throw a SecurityException.
2335 *
2336 * @param uri The uri that is being checked.
2337 * @param modeFlags The type of access to grant. May be one or both of
2338 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2339 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2340 * @param message A message to include in the exception if it is thrown.
2341 *
2342 * @see #checkCallingUriPermission(Uri, int)
2343 */
2344 public abstract void enforceCallingUriPermission(
2345 Uri uri, int modeFlags, String message);
2346
2347 /**
2348 * If the calling process of an IPC <em>or you</em> has not been
2349 * granted permission to access a specific URI, throw {@link
2350 * SecurityException}. This is the same as {@link
2351 * #enforceCallingUriPermission}, except it grants your own
2352 * permissions if you are not currently processing an IPC. Use
2353 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07002354 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 * @param uri The uri that is being checked.
2356 * @param modeFlags The type of access to grant. May be one or both of
2357 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2358 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2359 * @param message A message to include in the exception if it is thrown.
2360 *
2361 * @see #checkCallingOrSelfUriPermission(Uri, int)
2362 */
2363 public abstract void enforceCallingOrSelfUriPermission(
2364 Uri uri, int modeFlags, String message);
2365
2366 /**
2367 * Enforce both a Uri and normal permission. This allows you to perform
2368 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
2369 * call.
Scott Main4b5da682010-10-21 11:49:12 -07002370 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 * @param uri The Uri whose permission is to be checked, or null to not
2372 * do this check.
2373 * @param readPermission The permission that provides overall read access,
2374 * or null to not do this check.
2375 * @param writePermission The permission that provides overall write
2376 * acess, or null to not do this check.
2377 * @param pid The process ID being checked against. Must be &gt; 0.
2378 * @param uid The user ID being checked against. A uid of 0 is the root
2379 * user, which will pass every permission check.
2380 * @param modeFlags The type of access to grant. May be one or both of
2381 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2382 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2383 * @param message A message to include in the exception if it is thrown.
2384 *
2385 * @see #checkUriPermission(Uri, String, String, int, int, int)
2386 */
2387 public abstract void enforceUriPermission(
2388 Uri uri, String readPermission, String writePermission,
2389 int pid, int uid, int modeFlags, String message);
2390
2391 /**
2392 * Flag for use with {@link #createPackageContext}: include the application
2393 * code with the context. This means loading code into the caller's
2394 * process, so that {@link #getClassLoader()} can be used to instantiate
2395 * the application's classes. Setting this flags imposes security
2396 * restrictions on what application context you can access; if the
2397 * requested application can not be safely loaded into your process,
2398 * java.lang.SecurityException will be thrown. If this flag is not set,
2399 * there will be no restrictions on the packages that can be loaded,
2400 * but {@link #getClassLoader} will always return the default system
2401 * class loader.
2402 */
2403 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
2404
2405 /**
2406 * Flag for use with {@link #createPackageContext}: ignore any security
2407 * restrictions on the Context being requested, allowing it to always
2408 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
2409 * to be loaded into a process even when it isn't safe to do so. Use
2410 * with extreme care!
2411 */
2412 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07002413
Romain Guy870e09f2009-07-06 16:35:25 -07002414 /**
2415 * Flag for use with {@link #createPackageContext}: a restricted context may
2416 * disable specific features. For instance, a View associated with a restricted
2417 * context would ignore particular XML attributes.
2418 */
2419 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420
2421 /**
2422 * Return a new Context object for the given application name. This
2423 * Context is the same as what the named application gets when it is
2424 * launched, containing the same resources and class loader. Each call to
2425 * this method returns a new instance of a Context object; Context objects
2426 * are not shared, however they share common state (Resources, ClassLoader,
2427 * etc) so the Context instance itself is fairly lightweight.
2428 *
2429 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
2430 * application with the given package name.
2431 *
2432 * <p>Throws {@link java.lang.SecurityException} if the Context requested
2433 * can not be loaded into the caller's process for security reasons (see
2434 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
2435 *
2436 * @param packageName Name of the application's package.
2437 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
2438 * or {@link #CONTEXT_IGNORE_SECURITY}.
2439 *
2440 * @return A Context for the application.
2441 *
2442 * @throws java.lang.SecurityException
2443 * @throws PackageManager.NameNotFoundException if there is no application with
2444 * the given package name
2445 */
2446 public abstract Context createPackageContext(String packageName,
2447 int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07002448
2449 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07002450 * Return a new Context object for the current Context but whose resources
2451 * are adjusted to match the given Configuration. Each call to this method
2452 * returns a new instance of a Contex object; Context objects are not
2453 * shared, however common state (ClassLoader, other Resources for the
2454 * same configuration) may be so the Context itself can be fairly lightweight.
2455 *
2456 * @param overrideConfiguration A {@link Configuration} specifying what
2457 * values to modify in the base Configuration of the original Context's
2458 * resources. If the base configuration changes (such as due to an
2459 * orientation change), the resources of this context will also change except
2460 * for those that have been explicitly overridden with a value here.
2461 *
2462 * @return A Context for the application.
2463 */
2464 public abstract Context createConfigurationContext(Configuration overrideConfiguration);
2465
2466 /**
Romain Guy870e09f2009-07-06 16:35:25 -07002467 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07002468 *
Romain Guy870e09f2009-07-06 16:35:25 -07002469 * @return True if this Context is restricted, false otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07002470 *
Romain Guy870e09f2009-07-06 16:35:25 -07002471 * @see #CONTEXT_RESTRICTED
2472 */
2473 public boolean isRestricted() {
2474 return false;
2475 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002476}