blob: 5bd28b983abba864beaa2595ca1b82bed39a55a9 [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;
Jeff Sharkey8c165792012-10-22 14:08:29 -070036import android.os.UserManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.AttributeSet;
Jeff Brown98365d72012-08-19 20:30:52 -070038import android.view.CompatibilityInfoHolder;
Jeff Browna492c3a2012-08-23 19:48:44 -070039import android.view.Display;
40import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
42import java.io.File;
43import java.io.FileInputStream;
44import java.io.FileNotFoundException;
45import java.io.FileOutputStream;
46import java.io.IOException;
47import java.io.InputStream;
Amith Yamasanidf2e92a2013-03-01 17:04:38 -080048import java.util.List;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
50/**
51 * Interface to global information about an application environment. This is
52 * an abstract class whose implementation is provided by
53 * the Android system. It
54 * allows access to application-specific resources and classes, as well as
55 * up-calls for application-level operations such as launching activities,
56 * broadcasting and receiving intents, etc.
57 */
58public abstract class Context {
59 /**
60 * File creation mode: the default mode, where the created file can only
61 * be accessed by the calling application (or all applications sharing the
62 * same user ID).
63 * @see #MODE_WORLD_READABLE
64 * @see #MODE_WORLD_WRITEABLE
65 */
66 public static final int MODE_PRIVATE = 0x0000;
67 /**
Nick Kralevich15069212013-01-09 15:54:56 -080068 * @deprecated Creating world-readable files is very dangerous, and likely
69 * to cause security holes in applications. It is strongly discouraged;
70 * instead, applications should use more formal mechanism for interactions
71 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
72 * {@link android.app.Service}. There are no guarantees that this
73 * access mode will remain on a file, such as when it goes through a
74 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 * File creation mode: allow all other applications to have read access
76 * to the created file.
77 * @see #MODE_PRIVATE
78 * @see #MODE_WORLD_WRITEABLE
79 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070080 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081 public static final int MODE_WORLD_READABLE = 0x0001;
82 /**
Nick Kralevich15069212013-01-09 15:54:56 -080083 * @deprecated Creating world-writable files is very dangerous, and likely
84 * to cause security holes in applications. It is strongly discouraged;
85 * instead, applications should use more formal mechanism for interactions
86 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
87 * {@link android.app.Service}. There are no guarantees that this
88 * access mode will remain on a file, such as when it goes through a
89 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 * File creation mode: allow all other applications to have write access
91 * to the created file.
92 * @see #MODE_PRIVATE
93 * @see #MODE_WORLD_READABLE
94 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070095 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 public static final int MODE_WORLD_WRITEABLE = 0x0002;
97 /**
98 * File creation mode: for use with {@link #openFileOutput}, if the file
99 * already exists then write data to the end of the existing file
100 * instead of erasing it.
101 * @see #openFileOutput
102 */
103 public static final int MODE_APPEND = 0x8000;
104
105 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800106 * SharedPreference loading flag: when set, the file on disk will
107 * be checked for modification even if the shared preferences
108 * instance is already loaded in this process. This behavior is
109 * sometimes desired in cases where the application has multiple
110 * processes, all writing to the same SharedPreferences file.
111 * Generally there are better forms of communication between
112 * processes, though.
113 *
114 * <p>This was the legacy (but undocumented) behavior in and
115 * before Gingerbread (Android 2.3) and this flag is implied when
116 * targetting such releases. For applications targetting SDK
117 * versions <em>greater than</em> Android 2.3, this flag must be
118 * explicitly set if desired.
119 *
120 * @see #getSharedPreferences
121 */
122 public static final int MODE_MULTI_PROCESS = 0x0004;
123
124 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700125 * Database open flag: when set, the database is opened with write-ahead
126 * logging enabled by default.
127 *
128 * @see #openOrCreateDatabase(String, int, CursorFactory)
129 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
130 * @see SQLiteDatabase#enableWriteAheadLogging
131 */
132 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
133
134 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 * Flag for {@link #bindService}: automatically create the service as long
136 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700137 * its {@link android.app.Service#onStartCommand}
138 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 * explicit call to {@link #startService}. Even without that, though,
140 * this still provides you with access to the service object while the
141 * service is created.
142 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700143 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
144 * not supplying this flag would also impact how important the system
145 * consider's the target service's process to be. When set, the only way
146 * for it to be raised was by binding from a service in which case it will
147 * only be important when that activity is in the foreground. Now to
148 * achieve this behavior you must explicitly supply the new flag
149 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
150 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
151 * the flags {@link #BIND_WAIVE_PRIORITY} and
152 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
153 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 */
155 public static final int BIND_AUTO_CREATE = 0x0001;
156
157 /**
158 * Flag for {@link #bindService}: include debugging help for mismatched
159 * calls to unbind. When this flag is set, the callstack of the following
160 * {@link #unbindService} call is retained, to be printed if a later
161 * incorrect unbind call is made. Note that doing this requires retaining
162 * information about the binding that was made for the lifetime of the app,
163 * resulting in a leak -- this should only be used for debugging.
164 */
165 public static final int BIND_DEBUG_UNBIND = 0x0002;
166
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800167 /**
168 * Flag for {@link #bindService}: don't allow this binding to raise
169 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700170 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800171 * as the client (so that its process will not be killable in any
172 * situation where the client is not killable), but for CPU scheduling
173 * purposes it may be left in the background. This only has an impact
174 * in the situation where the binding client is a foreground process
175 * and the target service is in a background process.
176 */
177 public static final int BIND_NOT_FOREGROUND = 0x0004;
178
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700179 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700180 * Flag for {@link #bindService}: indicates that the client application
181 * binding to this service considers the service to be more important than
182 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700183 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700184 * this is not guaranteed to be the case.
185 */
186 public static final int BIND_ABOVE_CLIENT = 0x0008;
187
188 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700189 * Flag for {@link #bindService}: allow the process hosting the bound
190 * service to go through its normal memory management. It will be
191 * treated more like a running service, allowing the system to
192 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700193 * whim it may have, and being more aggressive about making it a candidate
194 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700195 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700196 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
197
198 /**
199 * Flag for {@link #bindService}: don't impact the scheduling or
200 * memory management priority of the target service's hosting process.
201 * Allows the service's process to be managed on the background LRU list
202 * just like a regular application process in the background.
203 */
204 public static final int BIND_WAIVE_PRIORITY = 0x0020;
205
206 /**
207 * Flag for {@link #bindService}: this service is very important to
208 * the client, so should be brought to the foreground process level
209 * when the client is. Normally a process can only be raised to the
210 * visibility level by a client, even if that client is in the foreground.
211 */
212 public static final int BIND_IMPORTANT = 0x0040;
213
214 /**
215 * Flag for {@link #bindService}: If binding from an activity, allow the
216 * target service's process importance to be raised based on whether the
217 * activity is visible to the user, regardless whether another flag is
218 * used to reduce the amount that the client process's overall importance
219 * is used to impact it.
220 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700221 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
222
223 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700224 * @hide An idea that is not yet implemented.
225 * Flag for {@link #bindService}: If binding from an activity, consider
226 * this service to be visible like the binding activity is. That is,
227 * it will be treated as something more important to keep around than
228 * invisible background activities. This will impact the number of
229 * recent activities the user can switch between without having them
230 * restart. There is no guarantee this will be respected, as the system
231 * tries to balance such requests from one app vs. the importantance of
232 * keeping other apps around.
233 */
234 public static final int BIND_VISIBLE = 0x0100;
235
236 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700237 * Flag for {@link #bindService}: Don't consider the bound service to be
238 * visible, even if the caller is visible.
239 * @hide
240 */
241 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700242
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 /** Return an AssetManager instance for your application's package. */
244 public abstract AssetManager getAssets();
245
246 /** Return a Resources instance for your application's package. */
247 public abstract Resources getResources();
248
249 /** Return PackageManager instance to find global package information. */
250 public abstract PackageManager getPackageManager();
251
252 /** Return a ContentResolver instance for your application's package. */
253 public abstract ContentResolver getContentResolver();
254
255 /**
256 * Return the Looper for the main thread of the current process. This is
257 * the thread used to dispatch calls to application components (activities,
258 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700259 * <p>
260 * By definition, this method returns the same result as would be obtained
261 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
262 * </p>
263 *
264 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800265 */
266 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700267
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 /**
269 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800270 * current process. This generally should only be used if you need a
271 * Context whose lifecycle is separate from the current context, that is
272 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700273 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800274 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800275 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800276 * <ul>
277 * <li> <p>If used from an Activity context, the receiver is being registered
278 * within that activity. This means that you are expected to unregister
279 * before the activity is done being destroyed; in fact if you do not do
280 * so, the framework will clean up your leaked registration as it removes
281 * the activity and log an error. Thus, if you use the Activity context
282 * to register a receiver that is static (global to the process, not
283 * associated with an Activity instance) then that registration will be
284 * removed on you at whatever point the activity you used is destroyed.
285 * <li> <p>If used from the Context returned here, the receiver is being
286 * registered with the global state associated with your application. Thus
287 * it will never be unregistered for you. This is necessary if the receiver
288 * is associated with static data, not a particular component. However
289 * using the ApplicationContext elsewhere can easily lead to serious leaks
290 * if you forget to unregister, unbind, etc.
291 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 */
293 public abstract Context getApplicationContext();
294
295 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700296 * Add a new {@link ComponentCallbacks} to the base application of the
297 * Context, which will be called at the same times as the ComponentCallbacks
298 * methods of activities and other components are called. Note that you
299 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
300 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700301 *
302 * @param callback The interface to call. This can be either a
303 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700304 */
305 public void registerComponentCallbacks(ComponentCallbacks callback) {
306 getApplicationContext().registerComponentCallbacks(callback);
307 }
308
309 /**
310 * Remove a {@link ComponentCallbacks} objec that was previously registered
311 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
312 */
313 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
314 getApplicationContext().unregisterComponentCallbacks(callback);
315 }
316
317 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 * Return a localized, styled CharSequence from the application's package's
319 * default string table.
320 *
321 * @param resId Resource id for the CharSequence text
322 */
323 public final CharSequence getText(int resId) {
324 return getResources().getText(resId);
325 }
326
327 /**
328 * Return a localized string from the application's package's
329 * default string table.
330 *
331 * @param resId Resource id for the string
332 */
333 public final String getString(int resId) {
334 return getResources().getString(resId);
335 }
336
337 /**
338 * Return a localized formatted string from the application's package's
339 * default string table, substituting the format arguments as defined in
340 * {@link java.util.Formatter} and {@link java.lang.String#format}.
341 *
342 * @param resId Resource id for the format string
343 * @param formatArgs The format arguments that will be used for substitution.
344 */
345
346 public final String getString(int resId, Object... formatArgs) {
347 return getResources().getString(resId, formatArgs);
348 }
349
350 /**
351 * Set the base theme for this context. Note that this should be called
352 * before any views are instantiated in the Context (for example before
353 * calling {@link android.app.Activity#setContentView} or
354 * {@link android.view.LayoutInflater#inflate}).
355 *
356 * @param resid The style resource describing the theme.
357 */
358 public abstract void setTheme(int resid);
359
Dianne Hackborn247fe742011-01-08 17:25:57 -0800360 /** @hide Needed for some internal implementation... not public because
361 * you can't assume this actually means anything. */
362 public int getThemeResId() {
363 return 0;
364 }
365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 /**
367 * Return the Theme object associated with this Context.
368 */
369 public abstract Resources.Theme getTheme();
370
371 /**
372 * Retrieve styled attribute information in this Context's theme. See
373 * {@link Resources.Theme#obtainStyledAttributes(int[])}
374 * for more information.
375 *
376 * @see Resources.Theme#obtainStyledAttributes(int[])
377 */
378 public final TypedArray obtainStyledAttributes(
379 int[] attrs) {
380 return getTheme().obtainStyledAttributes(attrs);
381 }
382
383 /**
384 * Retrieve styled attribute information in this Context's theme. See
385 * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
386 * for more information.
387 *
388 * @see Resources.Theme#obtainStyledAttributes(int, int[])
389 */
390 public final TypedArray obtainStyledAttributes(
391 int resid, int[] attrs) throws Resources.NotFoundException {
392 return getTheme().obtainStyledAttributes(resid, attrs);
393 }
394
395 /**
396 * Retrieve styled attribute information in this Context's theme. See
397 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
398 * for more information.
399 *
400 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
401 */
402 public final TypedArray obtainStyledAttributes(
403 AttributeSet set, int[] attrs) {
404 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
405 }
406
407 /**
408 * Retrieve styled attribute information in this Context's theme. See
409 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
410 * for more information.
411 *
412 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
413 */
414 public final TypedArray obtainStyledAttributes(
415 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
416 return getTheme().obtainStyledAttributes(
417 set, attrs, defStyleAttr, defStyleRes);
418 }
419
420 /**
421 * Return a class loader you can use to retrieve classes in this package.
422 */
423 public abstract ClassLoader getClassLoader();
424
425 /** Return the name of this application's package. */
426 public abstract String getPackageName();
427
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800428 /** @hide Return the name of the base context this context is derived from. */
429 public abstract String getBasePackageName();
430
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700431 /** Return the full application info for this context's package. */
432 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 /**
Kenny Root32148392010-01-21 15:40:47 -0800435 * Return the full path to this context's primary Android package.
436 * The Android package is a ZIP file which contains the application's
437 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 *
439 * <p>Note: this is not generally useful for applications, since they should
440 * not be directly accessing the file system.
441 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 * @return String Path to the resources.
443 */
444 public abstract String getPackageResourcePath();
445
446 /**
Kenny Root32148392010-01-21 15:40:47 -0800447 * Return the full path to this context's primary Android package.
448 * The Android package is a ZIP file which contains application's
449 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 *
451 * <p>Note: this is not generally useful for applications, since they should
452 * not be directly accessing the file system.
453 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 * @return String Path to the code and assets.
455 */
456 public abstract String getPackageCodePath();
457
458 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700459 * {@hide}
460 * Return the full path to the shared prefs file for the given prefs group name.
461 *
462 * <p>Note: this is not generally useful for applications, since they should
463 * not be directly accessing the file system.
464 */
465 public abstract File getSharedPrefsFile(String name);
466
467 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 * Retrieve and hold the contents of the preferences file 'name', returning
469 * a SharedPreferences through which you can retrieve and modify its
470 * values. Only one instance of the SharedPreferences object is returned
471 * to any callers for the same name, meaning they will see each other's
472 * edits as soon as they are made.
473 *
474 * @param name Desired preferences file. If a preferences file by this name
475 * does not exist, it will be created when you retrieve an
476 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
477 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
478 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800479 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
480 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
481 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
482 * is always on in apps targetting Gingerbread (Android 2.3) and below, and
483 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 *
485 * @return Returns the single SharedPreferences instance that can be used
486 * to retrieve and modify the preference values.
487 *
488 * @see #MODE_PRIVATE
489 * @see #MODE_WORLD_READABLE
490 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800491 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 */
493 public abstract SharedPreferences getSharedPreferences(String name,
494 int mode);
495
496 /**
497 * Open a private file associated with this Context's application package
498 * for reading.
499 *
500 * @param name The name of the file to open; can not contain path
501 * separators.
502 *
503 * @return FileInputStream Resulting input stream.
504 *
505 * @see #openFileOutput
506 * @see #fileList
507 * @see #deleteFile
508 * @see java.io.FileInputStream#FileInputStream(String)
509 */
510 public abstract FileInputStream openFileInput(String name)
511 throws FileNotFoundException;
512
513 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800514 * Open a private file associated with this Context's application package
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 * for writing. Creates the file if it doesn't already exist.
516 *
Nick Kralevich15069212013-01-09 15:54:56 -0800517 * @param name The name of the file to open; can not contain path
518 * separators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800520 * default operation, {@link #MODE_APPEND} to append to an existing file,
521 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
522 * permissions.
523 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 * @return FileOutputStream Resulting output stream.
Nick Kralevich15069212013-01-09 15:54:56 -0800525 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800526 * @see #MODE_APPEND
527 * @see #MODE_PRIVATE
528 * @see #MODE_WORLD_READABLE
529 * @see #MODE_WORLD_WRITEABLE
530 * @see #openFileInput
531 * @see #fileList
532 * @see #deleteFile
533 * @see java.io.FileOutputStream#FileOutputStream(String)
534 */
535 public abstract FileOutputStream openFileOutput(String name, int mode)
536 throws FileNotFoundException;
537
538 /**
539 * Delete the given private file associated with this Context's
540 * application package.
541 *
542 * @param name The name of the file to delete; can not contain path
543 * separators.
544 *
545 * @return True if the file was successfully deleted; else
546 * false.
547 *
548 * @see #openFileInput
549 * @see #openFileOutput
550 * @see #fileList
551 * @see java.io.File#delete()
552 */
553 public abstract boolean deleteFile(String name);
554
555 /**
556 * Returns the absolute path on the filesystem where a file created with
557 * {@link #openFileOutput} is stored.
558 *
559 * @param name The name of the file for which you would like to get
560 * its path.
561 *
562 * @return Returns an absolute path to the given file.
563 *
564 * @see #openFileOutput
565 * @see #getFilesDir
566 * @see #getDir
567 */
568 public abstract File getFileStreamPath(String name);
569
570 /**
571 * Returns the absolute path to the directory on the filesystem where
572 * files created with {@link #openFileOutput} are stored.
573 *
574 * @return Returns the path of the directory holding application files.
575 *
576 * @see #openFileOutput
577 * @see #getFileStreamPath
578 * @see #getDir
579 */
580 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 /**
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800583 * Returns the absolute path to the directory on the external filesystem
584 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700585 * Environment.getExternalStorageDirectory()}) where the application can
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800586 * place persistent files it owns. These files are private to the
587 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700588 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800589 * <p>This is like {@link #getFilesDir()} in that these
590 * files will be deleted when the application is uninstalled, however there
591 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700592 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800593 * <ul>
594 * <li>External files are not always available: they will disappear if the
595 * user mounts the external storage on a computer or removes it. See the
596 * APIs on {@link android.os.Environment} for information in the storage state.
597 * <li>There is no security enforced with these files. All applications
598 * can read and write files placed here.
599 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700600 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700601 * <p>On devices with multiple users (as described by {@link UserManager}),
602 * each user has their own isolated external storage. Applications only
603 * have access to the external storage for the user they're running as.</p>
604 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800605 * <p>Here is an example of typical code to manipulate a file in
606 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700607 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800608 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
609 * private_file}
610 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700611 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800612 * file will be a path to a sub-directory of the given type. Though these files
613 * are not automatically scanned by the media scanner, you can explicitly
614 * add them to the media database with
615 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Ray Chenb7c8c762010-03-30 17:21:39 -0700616 * OnScanCompletedListener) MediaScannerConnection.scanFile}.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800617 * Note that this is not the same as
618 * {@link android.os.Environment#getExternalStoragePublicDirectory
619 * Environment.getExternalStoragePublicDirectory()}, which provides
620 * directories of media shared by all applications. The
621 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700622 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800623 * application is uninstalled. Unlike
624 * {@link android.os.Environment#getExternalStoragePublicDirectory
625 * Environment.getExternalStoragePublicDirectory()}, the directory
626 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700627 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800628 * <p>Here is an example of typical code to manipulate a picture in
629 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700630 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800631 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
632 * private_picture}
Scott Main4b5da682010-10-21 11:49:12 -0700633 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700634 * <p>Writing to this path requires the
635 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission.</p>
636 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800637 * @param type The type of files directory to return. May be null for
638 * the root of the files directory or one of
639 * the following Environment constants for a subdirectory:
640 * {@link android.os.Environment#DIRECTORY_MUSIC},
641 * {@link android.os.Environment#DIRECTORY_PODCASTS},
642 * {@link android.os.Environment#DIRECTORY_RINGTONES},
643 * {@link android.os.Environment#DIRECTORY_ALARMS},
644 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
645 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
646 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700647 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800648 * @return Returns the path of the directory holding application files
649 * on external storage. Returns null if external storage is not currently
650 * mounted so it could not ensure the path exists; you will need to call
651 * this method again when it is available.
652 *
653 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700654 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800655 */
656 public abstract File getExternalFilesDir(String type);
Scott Main4b5da682010-10-21 11:49:12 -0700657
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800658 /**
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800659 * Return the directory where this application's OBB files (if there
660 * are any) can be found. Note if the application does not have any OBB
661 * files, this directory may not exist.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700662 *
663 * <p>On devices with multiple users (as described by {@link UserManager}),
664 * multiple users may share the same OBB storage location. Applications
665 * should ensure that multiple instances running under different users
666 * don't interfere with each other.</p>
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800667 */
668 public abstract File getObbDir();
669
670 /**
Scott Main4b5da682010-10-21 11:49:12 -0700671 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800673 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800674 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700675 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800676 * <strong>Note: you should not <em>rely</em> on the system deleting these
677 * files for you; you should always have a reasonable maximum, such as 1 MB,
678 * for the amount of space you consume with cache files, and prune those
679 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700680 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 * @return Returns the path of the directory holding application cache files.
682 *
683 * @see #openFileOutput
684 * @see #getFileStreamPath
685 * @see #getDir
686 */
687 public abstract File getCacheDir();
688
689 /**
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800690 * Returns the absolute path to the directory on the external filesystem
691 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
692 * Environment.getExternalStorageDirectory()} where the application can
693 * place cache files it owns.
Scott Main4b5da682010-10-21 11:49:12 -0700694 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800695 * <p>This is like {@link #getCacheDir()} in that these
696 * files will be deleted when the application is uninstalled, however there
697 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700698 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800699 * <ul>
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700700 * <li>The platform does not always monitor the space available in external
701 * storage, and thus may not automatically delete these files. Currently
702 * the only time files here will be deleted by the platform is when running
703 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
704 * {@link android.os.Environment#isExternalStorageEmulated()
705 * Environment.isExternalStorageEmulated()} returns true. Note that you should
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800706 * be managing the maximum space you will use for these anyway, just like
707 * with {@link #getCacheDir()}.
708 * <li>External files are not always available: they will disappear if the
709 * user mounts the external storage on a computer or removes it. See the
710 * APIs on {@link android.os.Environment} for information in the storage state.
711 * <li>There is no security enforced with these files. All applications
712 * can read and write files placed here.
713 * </ul>
714 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700715 * <p>On devices with multiple users (as described by {@link UserManager}),
716 * each user has their own isolated external storage. Applications only
717 * have access to the external storage for the user they're running as.</p>
718 *
719 * <p>Writing to this path requires the
720 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission.</p>
721 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800722 * @return Returns the path of the directory holding application cache files
723 * on external storage. Returns null if external storage is not currently
724 * mounted so it could not ensure the path exists; you will need to call
725 * this method again when it is available.
726 *
727 * @see #getCacheDir
728 */
729 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700730
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800731 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 * Returns an array of strings naming the private files associated with
733 * this Context's application package.
734 *
735 * @return Array of strings naming the private files.
736 *
737 * @see #openFileInput
738 * @see #openFileOutput
739 * @see #deleteFile
740 */
741 public abstract String[] fileList();
742
743 /**
744 * Retrieve, creating if needed, a new directory in which the application
745 * can place its own custom data files. You can use the returned File
746 * object to create and access files in this directory. Note that files
747 * created through a File object will only be accessible by your own
748 * application; you can only set the mode of the entire directory, not
749 * of individual files.
750 *
Nick Kralevich92091fa2012-12-12 16:24:31 -0800751 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -0800752 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -0800753 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800754 * default operation, {@link #MODE_WORLD_READABLE} and
755 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
756 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 * @return Returns a File object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -0800758 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 *
760 * @see #openFileOutput(String, int)
761 */
762 public abstract File getDir(String name, int mode);
763
764 /**
765 * Open a new private SQLiteDatabase associated with this Context's
766 * application package. Create the database file if it doesn't exist.
767 *
768 * @param name The name (unique in the application package) of the database.
769 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
770 * default operation, {@link #MODE_WORLD_READABLE}
771 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700772 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 * @param factory An optional factory class that is called to instantiate a
774 * cursor when query is called.
Nick Kralevich15069212013-01-09 15:54:56 -0800775 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 * @return The contents of a newly created database with the given name.
777 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -0800778 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 * @see #MODE_PRIVATE
780 * @see #MODE_WORLD_READABLE
781 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700782 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 * @see #deleteDatabase
784 */
785 public abstract SQLiteDatabase openOrCreateDatabase(String name,
786 int mode, CursorFactory factory);
787
788 /**
Vasu Nori74f170f2010-06-01 18:06:18 -0700789 * Open a new private SQLiteDatabase associated with this Context's
790 * application package. Creates the database file if it doesn't exist.
791 *
792 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
793 * used to handle corruption when sqlite reports database corruption.</p>
794 *
795 * @param name The name (unique in the application package) of the database.
796 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
797 * default operation, {@link #MODE_WORLD_READABLE}
798 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700799 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -0700800 * @param factory An optional factory class that is called to instantiate a
801 * cursor when query is called.
802 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Nick Kralevich15069212013-01-09 15:54:56 -0800803 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -0700804 * @return The contents of a newly created database with the given name.
805 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -0800806 *
Vasu Nori74f170f2010-06-01 18:06:18 -0700807 * @see #MODE_PRIVATE
808 * @see #MODE_WORLD_READABLE
809 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700810 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -0700811 * @see #deleteDatabase
812 */
813 public abstract SQLiteDatabase openOrCreateDatabase(String name,
814 int mode, CursorFactory factory, DatabaseErrorHandler errorHandler);
815
816 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 * Delete an existing private SQLiteDatabase associated with this Context's
818 * application package.
819 *
820 * @param name The name (unique in the application package) of the
821 * database.
822 *
823 * @return True if the database was successfully deleted; else false.
824 *
825 * @see #openOrCreateDatabase
826 */
827 public abstract boolean deleteDatabase(String name);
828
829 /**
830 * Returns the absolute path on the filesystem where a database created with
831 * {@link #openOrCreateDatabase} is stored.
832 *
833 * @param name The name of the database for which you would like to get
834 * its path.
835 *
836 * @return Returns an absolute path to the given database.
837 *
838 * @see #openOrCreateDatabase
839 */
840 public abstract File getDatabasePath(String name);
841
842 /**
843 * Returns an array of strings naming the private databases associated with
844 * this Context's application package.
845 *
846 * @return Array of strings naming the private databases.
847 *
848 * @see #openOrCreateDatabase
849 * @see #deleteDatabase
850 */
851 public abstract String[] databaseList();
852
853 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700854 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700855 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700857 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 public abstract Drawable getWallpaper();
859
860 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700861 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700862 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700864 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 public abstract Drawable peekWallpaper();
866
867 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700868 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
869 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700871 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 public abstract int getWallpaperDesiredMinimumWidth();
873
874 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700875 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
876 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700878 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800879 public abstract int getWallpaperDesiredMinimumHeight();
880
881 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700882 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700883 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700884 * <p>This method requires the caller to hold the permission
885 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700887 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
889
890 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700891 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700892 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700893 * <p>This method requires the caller to hold the permission
894 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800895 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700896 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 public abstract void setWallpaper(InputStream data) throws IOException;
898
899 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700900 * @deprecated Use {@link android.app.WallpaperManager#clear
901 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700902 * <p>This method requires the caller to hold the permission
903 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700905 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 public abstract void clearWallpaper() throws IOException;
907
908 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700909 * Same as {@link #startActivity(Intent, Bundle)} with no options
910 * specified.
911 *
912 * @param intent The description of the activity to start.
913 *
914 * @throws ActivityNotFoundException
915 *
916 * @see {@link #startActivity(Intent, Bundle)}
917 * @see PackageManager#resolveActivity
918 */
919 public abstract void startActivity(Intent intent);
920
921 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -0700922 * Version of {@link #startActivity(Intent)} that allows you to specify the
923 * user the activity will be started for. This is not available to applications
924 * that are not pre-installed on the system image. Using it requires holding
925 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -0700926 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700927 * @param user The UserHandle of the user to start this activity for.
Amith Yamasani82644082012-08-03 13:09:11 -0700928 * @throws ActivityNotFoundException
929 * @hide
930 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700931 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -0700932 throw new RuntimeException("Not implemented. Must override in a subclass.");
933 }
934
935 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 * Launch a new activity. You will not receive any information about when
937 * the activity exits.
938 *
939 * <p>Note that if this method is being called from outside of an
940 * {@link android.app.Activity} Context, then the Intent must include
941 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
942 * without being started from an existing Activity, there is no existing
943 * task in which to place the new activity and thus it needs to be placed
944 * in its own separate task.
945 *
946 * <p>This method throws {@link ActivityNotFoundException}
947 * if there was no Activity found to run the given Intent.
948 *
949 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -0700950 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -0700951 * May be null if there are no options. See {@link android.app.ActivityOptions}
952 * for how to build the Bundle supplied here; there are no supported definitions
953 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 *
955 * @throws ActivityNotFoundException
956 *
Scott Main60dd5202012-06-23 00:01:22 -0700957 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 * @see PackageManager#resolveActivity
959 */
Dianne Hackborna4972e92012-03-14 10:38:05 -0700960 public abstract void startActivity(Intent intent, Bundle options);
961
962 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -0700963 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
964 * user the activity will be started for. This is not available to applications
965 * that are not pre-installed on the system image. Using it requires holding
966 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -0700967 * @param intent The description of the activity to start.
968 * @param options Additional options for how the Activity should be started.
969 * May be null if there are no options. See {@link android.app.ActivityOptions}
970 * for how to build the Bundle supplied here; there are no supported definitions
971 * for building it manually.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700972 * @param user The UserHandle of the user to start this activity for.
Amith Yamasani258848d2012-08-10 17:06:33 -0700973 * @throws ActivityNotFoundException
974 * @hide
975 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -0700976 public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -0700977 throw new RuntimeException("Not implemented. Must override in a subclass.");
978 }
979
980 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700981 * Same as {@link #startActivities(Intent[], Bundle)} with no options
982 * specified.
983 *
984 * @param intents An array of Intents to be started.
985 *
986 * @throws ActivityNotFoundException
987 *
988 * @see {@link #startActivities(Intent[], Bundle)}
989 * @see PackageManager#resolveActivity
990 */
991 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992
993 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -0800994 * Launch multiple new activities. This is generally the same as calling
995 * {@link #startActivity(Intent)} for the first Intent in the array,
996 * that activity during its creation calling {@link #startActivity(Intent)}
997 * for the second entry, etc. Note that unlike that approach, generally
998 * none of the activities except the last in the array will be created
999 * at this point, but rather will be created when the user first visits
1000 * them (due to pressing back from the activity on top).
1001 *
1002 * <p>This method throws {@link ActivityNotFoundException}
1003 * if there was no Activity found for <em>any</em> given Intent. In this
1004 * case the state of the activity stack is undefined (some Intents in the
1005 * list may be on it, some not), so you probably want to avoid such situations.
1006 *
1007 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001008 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001009 * See {@link android.content.Context#startActivity(Intent, Bundle)
1010 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001011 *
1012 * @throws ActivityNotFoundException
1013 *
Dianne Hackborna4972e92012-03-14 10:38:05 -07001014 * @see {@link #startActivities(Intent[])}
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001015 * @see PackageManager#resolveActivity
1016 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001017 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001018
1019 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001020 * @hide
1021 * Launch multiple new activities. This is generally the same as calling
1022 * {@link #startActivity(Intent)} for the first Intent in the array,
1023 * that activity during its creation calling {@link #startActivity(Intent)}
1024 * for the second entry, etc. Note that unlike that approach, generally
1025 * none of the activities except the last in the array will be created
1026 * at this point, but rather will be created when the user first visits
1027 * them (due to pressing back from the activity on top).
1028 *
1029 * <p>This method throws {@link ActivityNotFoundException}
1030 * if there was no Activity found for <em>any</em> given Intent. In this
1031 * case the state of the activity stack is undefined (some Intents in the
1032 * list may be on it, some not), so you probably want to avoid such situations.
1033 *
1034 * @param intents An array of Intents to be started.
1035 * @param options Additional options for how the Activity should be started.
1036 * @param userHandle The user for whom to launch the activities
1037 * See {@link android.content.Context#startActivity(Intent, Bundle)
1038 * Context.startActivity(Intent, Bundle)} for more details.
1039 *
1040 * @throws ActivityNotFoundException
1041 *
1042 * @see {@link #startActivities(Intent[])}
1043 * @see PackageManager#resolveActivity
1044 */
1045 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1046 throw new RuntimeException("Not implemented. Must override in a subclass.");
1047 }
1048
1049 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001050 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1051 * with no options specified.
1052 *
1053 * @param intent The IntentSender to launch.
1054 * @param fillInIntent If non-null, this will be provided as the
1055 * intent parameter to {@link IntentSender#sendIntent}.
1056 * @param flagsMask Intent flags in the original IntentSender that you
1057 * would like to change.
1058 * @param flagsValues Desired values for any bits set in
1059 * <var>flagsMask</var>
1060 * @param extraFlags Always set to 0.
1061 *
1062 * @see #startActivity(Intent)
1063 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1064 */
1065 public abstract void startIntentSender(IntentSender intent,
1066 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1067 throws IntentSender.SendIntentException;
1068
1069 /**
1070 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001071 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001072 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001073 * here; otherwise, its associated action will be executed (such as
1074 * sending a broadcast) as if you had called
1075 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001076 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001077 * @param intent The IntentSender to launch.
1078 * @param fillInIntent If non-null, this will be provided as the
1079 * intent parameter to {@link IntentSender#sendIntent}.
1080 * @param flagsMask Intent flags in the original IntentSender that you
1081 * would like to change.
1082 * @param flagsValues Desired values for any bits set in
1083 * <var>flagsMask</var>
1084 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001085 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001086 * See {@link android.content.Context#startActivity(Intent, Bundle)
1087 * Context.startActivity(Intent, Bundle)} for more details. If options
1088 * have also been supplied by the IntentSender, options given here will
1089 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001090 *
1091 * @see #startActivity(Intent, Bundle)
1092 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001093 */
1094 public abstract void startIntentSender(IntentSender intent,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001095 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1096 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001097
1098 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 * Broadcast the given intent to all interested BroadcastReceivers. This
1100 * call is asynchronous; it returns immediately, and you will continue
1101 * executing while the receivers are run. No results are propagated from
1102 * receivers and receivers can not abort the broadcast. If you want
1103 * to allow receivers to propagate results or abort the broadcast, you must
1104 * send an ordered broadcast using
1105 * {@link #sendOrderedBroadcast(Intent, String)}.
1106 *
1107 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1108 *
1109 * @param intent The Intent to broadcast; all receivers matching this
1110 * Intent will receive the broadcast.
1111 *
1112 * @see android.content.BroadcastReceiver
1113 * @see #registerReceiver
1114 * @see #sendBroadcast(Intent, String)
1115 * @see #sendOrderedBroadcast(Intent, String)
1116 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1117 */
1118 public abstract void sendBroadcast(Intent intent);
1119
1120 /**
1121 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1122 * an optional required permission to be enforced. This
1123 * call is asynchronous; it returns immediately, and you will continue
1124 * executing while the receivers are run. No results are propagated from
1125 * receivers and receivers can not abort the broadcast. If you want
1126 * to allow receivers to propagate results or abort the broadcast, you must
1127 * send an ordered broadcast using
1128 * {@link #sendOrderedBroadcast(Intent, String)}.
1129 *
1130 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1131 *
1132 * @param intent The Intent to broadcast; all receivers matching this
1133 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001134 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 * a receiver must hold in order to receive your broadcast.
1136 * If null, no permission is required.
1137 *
1138 * @see android.content.BroadcastReceiver
1139 * @see #registerReceiver
1140 * @see #sendBroadcast(Intent)
1141 * @see #sendOrderedBroadcast(Intent, String)
1142 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1143 */
1144 public abstract void sendBroadcast(Intent intent,
1145 String receiverPermission);
1146
1147 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001148 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
1149 * of an assocated app op as per {@link android.app.AppOpsManager}.
1150 * @hide
1151 */
1152 public abstract void sendBroadcast(Intent intent,
1153 String receiverPermission, int appOp);
1154
1155 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1157 * them one at a time to allow more preferred receivers to consume the
1158 * broadcast before it is delivered to less preferred receivers. This
1159 * call is asynchronous; it returns immediately, and you will continue
1160 * executing while the receivers are run.
1161 *
1162 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1163 *
1164 * @param intent The Intent to broadcast; all receivers matching this
1165 * Intent will receive the broadcast.
1166 * @param receiverPermission (optional) String naming a permissions that
1167 * a receiver must hold in order to receive your broadcast.
1168 * If null, no permission is required.
1169 *
1170 * @see android.content.BroadcastReceiver
1171 * @see #registerReceiver
1172 * @see #sendBroadcast(Intent)
1173 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1174 */
1175 public abstract void sendOrderedBroadcast(Intent intent,
1176 String receiverPermission);
1177
1178 /**
1179 * Version of {@link #sendBroadcast(Intent)} that allows you to
1180 * receive data back from the broadcast. This is accomplished by
1181 * supplying your own BroadcastReceiver when calling, which will be
1182 * treated as a final receiver at the end of the broadcast -- its
1183 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001184 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 * be serialized in the same way as calling
1186 * {@link #sendOrderedBroadcast(Intent, String)}.
1187 *
1188 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1189 * asynchronous; it will return before
1190 * resultReceiver.onReceive() is called.
1191 *
1192 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1193 *
1194 * @param intent The Intent to broadcast; all receivers matching this
1195 * Intent will receive the broadcast.
1196 * @param receiverPermission String naming a permissions that
1197 * a receiver must hold in order to receive your broadcast.
1198 * If null, no permission is required.
1199 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1200 * receiver of the broadcast.
1201 * @param scheduler A custom Handler with which to schedule the
1202 * resultReceiver callback; if null it will be
1203 * scheduled in the Context's main thread.
1204 * @param initialCode An initial value for the result code. Often
1205 * Activity.RESULT_OK.
1206 * @param initialData An initial value for the result data. Often
1207 * null.
1208 * @param initialExtras An initial value for the result extras. Often
1209 * null.
1210 *
1211 * @see #sendBroadcast(Intent)
1212 * @see #sendBroadcast(Intent, String)
1213 * @see #sendOrderedBroadcast(Intent, String)
1214 * @see #sendStickyBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001215 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 * @see android.content.BroadcastReceiver
1217 * @see #registerReceiver
1218 * @see android.app.Activity#RESULT_OK
1219 */
1220 public abstract void sendOrderedBroadcast(Intent intent,
1221 String receiverPermission, BroadcastReceiver resultReceiver,
1222 Handler scheduler, int initialCode, String initialData,
1223 Bundle initialExtras);
1224
1225 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001226 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1227 * int, String, android.os.Bundle)}, but also allows specification
1228 * of an assocated app op as per {@link android.app.AppOpsManager}.
1229 * @hide
1230 */
1231 public abstract void sendOrderedBroadcast(Intent intent,
1232 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1233 Handler scheduler, int initialCode, String initialData,
1234 Bundle initialExtras);
1235
1236 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001237 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1238 * user the broadcast will be sent to. This is not available to applications
1239 * that are not pre-installed on the system image. Using it requires holding
1240 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001241 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001242 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001243 * @see #sendBroadcast(Intent)
1244 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001245 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001246
1247 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001248 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1249 * user the broadcast will be sent to. This is not available to applications
1250 * that are not pre-installed on the system image. Using it requires holding
1251 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001252 *
1253 * @param intent The Intent to broadcast; all receivers matching this
1254 * Intent will receive the broadcast.
1255 * @param user UserHandle to send the intent to.
1256 * @param receiverPermission (optional) String naming a permission that
1257 * a receiver must hold in order to receive your broadcast.
1258 * If null, no permission is required.
1259 *
1260 * @see #sendBroadcast(Intent, String)
1261 */
1262 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1263 String receiverPermission);
1264
1265 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001266 * Version of
1267 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1268 * that allows you to specify the
1269 * user the broadcast will be sent to. This is not available to applications
1270 * that are not pre-installed on the system image. Using it requires holding
1271 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001272 *
1273 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1274 *
1275 * @param intent The Intent to broadcast; all receivers matching this
1276 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001277 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001278 * @param receiverPermission String naming a permissions that
1279 * a receiver must hold in order to receive your broadcast.
1280 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001281 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1282 * receiver of the broadcast.
1283 * @param scheduler A custom Handler with which to schedule the
1284 * resultReceiver callback; if null it will be
1285 * scheduled in the Context's main thread.
1286 * @param initialCode An initial value for the result code. Often
1287 * Activity.RESULT_OK.
1288 * @param initialData An initial value for the result data. Often
1289 * null.
1290 * @param initialExtras An initial value for the result extras. Often
1291 * null.
1292 *
1293 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1294 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001295 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001296 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001297 int initialCode, String initialData, Bundle initialExtras);
1298
1299 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001300 * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1301 * Intent you are sending stays around after the broadcast is complete,
1302 * so that others can quickly retrieve that data through the return
1303 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1304 * all other ways, this behaves the same as
1305 * {@link #sendBroadcast(Intent)}.
1306 *
1307 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1308 * permission in order to use this API. If you do not hold that
1309 * permission, {@link SecurityException} will be thrown.
1310 *
1311 * @param intent The Intent to broadcast; all receivers matching this
1312 * Intent will receive the broadcast, and the Intent will be held to
1313 * be re-broadcast to future receivers.
1314 *
1315 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001316 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001317 */
1318 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001319
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001320 /**
1321 * Version of {@link #sendStickyBroadcast} that allows you to
1322 * receive data back from the broadcast. This is accomplished by
1323 * supplying your own BroadcastReceiver when calling, which will be
1324 * treated as a final receiver at the end of the broadcast -- its
1325 * {@link BroadcastReceiver#onReceive} method will be called with
1326 * the result values collected from the other receivers. The broadcast will
1327 * be serialized in the same way as calling
1328 * {@link #sendOrderedBroadcast(Intent, String)}.
1329 *
1330 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1331 * asynchronous; it will return before
1332 * resultReceiver.onReceive() is called. Note that the sticky data
1333 * stored is only the data you initially supply to the broadcast, not
1334 * the result of any changes made by the receivers.
1335 *
1336 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1337 *
1338 * @param intent The Intent to broadcast; all receivers matching this
1339 * Intent will receive the broadcast.
1340 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1341 * receiver of the broadcast.
1342 * @param scheduler A custom Handler with which to schedule the
1343 * resultReceiver callback; if null it will be
1344 * scheduled in the Context's main thread.
1345 * @param initialCode An initial value for the result code. Often
1346 * Activity.RESULT_OK.
1347 * @param initialData An initial value for the result data. Often
1348 * null.
1349 * @param initialExtras An initial value for the result extras. Often
1350 * null.
1351 *
1352 * @see #sendBroadcast(Intent)
1353 * @see #sendBroadcast(Intent, String)
1354 * @see #sendOrderedBroadcast(Intent, String)
1355 * @see #sendStickyBroadcast(Intent)
1356 * @see android.content.BroadcastReceiver
1357 * @see #registerReceiver
1358 * @see android.app.Activity#RESULT_OK
1359 */
1360 public abstract void sendStickyOrderedBroadcast(Intent intent,
1361 BroadcastReceiver resultReceiver,
1362 Handler scheduler, int initialCode, String initialData,
1363 Bundle initialExtras);
1364
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 /**
1366 * Remove the data previously sent with {@link #sendStickyBroadcast},
1367 * so that it is as if the sticky broadcast had never happened.
1368 *
1369 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1370 * permission in order to use this API. If you do not hold that
1371 * permission, {@link SecurityException} will be thrown.
1372 *
1373 * @param intent The Intent that was previously broadcast.
1374 *
1375 * @see #sendStickyBroadcast
1376 */
1377 public abstract void removeStickyBroadcast(Intent intent);
1378
1379 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001380 * Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
1381 * user the broadcast will be sent to. This is not available to applications
1382 * that are not pre-installed on the system image. Using it requires holding
1383 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001384 *
1385 * @param intent The Intent to broadcast; all receivers matching this
1386 * Intent will receive the broadcast, and the Intent will be held to
1387 * be re-broadcast to future receivers.
1388 * @param user UserHandle to send the intent to.
1389 *
1390 * @see #sendBroadcast(Intent)
1391 */
1392 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1393
1394 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001395 * Version of
1396 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1397 * that allows you to specify the
1398 * user the broadcast will be sent to. This is not available to applications
1399 * that are not pre-installed on the system image. Using it requires holding
1400 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001401 *
1402 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1403 *
1404 * @param intent The Intent to broadcast; all receivers matching this
1405 * Intent will receive the broadcast.
1406 * @param user UserHandle to send the intent to.
1407 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1408 * receiver of the broadcast.
1409 * @param scheduler A custom Handler with which to schedule the
1410 * resultReceiver callback; if null it will be
1411 * scheduled in the Context's main thread.
1412 * @param initialCode An initial value for the result code. Often
1413 * Activity.RESULT_OK.
1414 * @param initialData An initial value for the result data. Often
1415 * null.
1416 * @param initialExtras An initial value for the result extras. Often
1417 * null.
1418 *
1419 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1420 */
1421 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1422 UserHandle user, BroadcastReceiver resultReceiver,
1423 Handler scheduler, int initialCode, String initialData,
1424 Bundle initialExtras);
1425
1426 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001427 * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
1428 * user the broadcast will be sent to. This is not available to applications
1429 * that are not pre-installed on the system image. Using it requires holding
1430 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001431 *
1432 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1433 * permission in order to use this API. If you do not hold that
1434 * permission, {@link SecurityException} will be thrown.
1435 *
1436 * @param intent The Intent that was previously broadcast.
1437 * @param user UserHandle to remove the sticky broadcast from.
1438 *
1439 * @see #sendStickyBroadcastAsUser
1440 */
1441 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1442
1443 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07001444 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 * <var>receiver</var> will be called with any broadcast Intent that
1446 * matches <var>filter</var>, in the main application thread.
1447 *
1448 * <p>The system may broadcast Intents that are "sticky" -- these stay
1449 * around after the broadcast as finished, to be sent to any later
1450 * registrations. If your IntentFilter matches one of these sticky
1451 * Intents, that Intent will be returned by this function
1452 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1453 * been broadcast.
1454 *
1455 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1456 * in which case each of these will be sent to <var>receiver</var>. In
1457 * this case, only one of these can be returned directly by the function;
1458 * which of these that is returned is arbitrarily decided by the system.
1459 *
1460 * <p>If you know the Intent your are registering for is sticky, you can
1461 * supply null for your <var>receiver</var>. In this case, no receiver is
1462 * registered -- the function simply returns the sticky Intent that
1463 * matches <var>filter</var>. In the case of multiple matches, the same
1464 * rules as described above apply.
1465 *
1466 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1467 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001468 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1469 * registered with this method will correctly respect the
1470 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1471 * Prior to that, it would be ignored and delivered to all matching registered
1472 * receivers. Be careful if using this for security.</p>
1473 *
Chris Tatea34df8a22009-04-02 23:15:58 -07001474 * <p class="note">Note: this method <em>cannot be called from a
1475 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1476 * that is declared in an application's manifest. It is okay, however, to call
1477 * this method from another BroadcastReceiver that has itself been registered
1478 * at run time with {@link #registerReceiver}, since the lifetime of such a
1479 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 *
1481 * @param receiver The BroadcastReceiver to handle the broadcast.
1482 * @param filter Selects the Intent broadcasts to be received.
1483 *
1484 * @return The first sticky intent found that matches <var>filter</var>,
1485 * or null if there are none.
1486 *
1487 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1488 * @see #sendBroadcast
1489 * @see #unregisterReceiver
1490 */
1491 public abstract Intent registerReceiver(BroadcastReceiver receiver,
1492 IntentFilter filter);
1493
1494 /**
1495 * Register to receive intent broadcasts, to run in the context of
1496 * <var>scheduler</var>. See
1497 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1498 * information. This allows you to enforce permissions on who can
1499 * broadcast intents to your receiver, or have the receiver run in
1500 * a different thread than the main application thread.
1501 *
1502 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1503 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001504 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1505 * registered with this method will correctly respect the
1506 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1507 * Prior to that, it would be ignored and delivered to all matching registered
1508 * receivers. Be careful if using this for security.</p>
1509 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 * @param receiver The BroadcastReceiver to handle the broadcast.
1511 * @param filter Selects the Intent broadcasts to be received.
1512 * @param broadcastPermission String naming a permissions that a
1513 * broadcaster must hold in order to send an Intent to you. If null,
1514 * no permission is required.
1515 * @param scheduler Handler identifying the thread that will receive
1516 * the Intent. If null, the main thread of the process will be used.
1517 *
1518 * @return The first sticky intent found that matches <var>filter</var>,
1519 * or null if there are none.
1520 *
1521 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1522 * @see #sendBroadcast
1523 * @see #unregisterReceiver
1524 */
1525 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Dianne Hackborn20e80982012-08-31 19:00:44 -07001526 IntentFilter filter, String broadcastPermission, Handler scheduler);
1527
1528 /**
1529 * @hide
1530 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1531 * but for a specific user. This receiver will receiver broadcasts that
1532 * are sent to the requested user. It
1533 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1534 * permission.
1535 *
1536 * @param receiver The BroadcastReceiver to handle the broadcast.
1537 * @param user UserHandle to send the intent to.
1538 * @param filter Selects the Intent broadcasts to be received.
1539 * @param broadcastPermission String naming a permissions that a
1540 * broadcaster must hold in order to send an Intent to you. If null,
1541 * no permission is required.
1542 * @param scheduler Handler identifying the thread that will receive
1543 * the Intent. If null, the main thread of the process will be used.
1544 *
1545 * @return The first sticky intent found that matches <var>filter</var>,
1546 * or null if there are none.
1547 *
1548 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1549 * @see #sendBroadcast
1550 * @see #unregisterReceiver
1551 */
1552 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
1553 UserHandle user, IntentFilter filter, String broadcastPermission,
1554 Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555
1556 /**
1557 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1558 * filters that have been registered for this BroadcastReceiver will be
1559 * removed.
1560 *
1561 * @param receiver The BroadcastReceiver to unregister.
1562 *
1563 * @see #registerReceiver
1564 */
1565 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1566
1567 /**
1568 * Request that a given application service be started. The Intent
1569 * can either contain the complete class name of a specific service
1570 * implementation to start, or an abstract definition through the
1571 * action and other fields of the kind of service to start. If this service
1572 * is not already running, it will be instantiated and started (creating a
1573 * process for it if needed); if it is running then it remains running.
1574 *
1575 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001576 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 * with the <var>intent</var> given here. This provides a convenient way
1578 * to submit jobs to a service without having to bind and call on to its
1579 * interface.
1580 *
1581 * <p>Using startService() overrides the default service lifetime that is
1582 * managed by {@link #bindService}: it requires the service to remain
1583 * running until {@link #stopService} is called, regardless of whether
1584 * any clients are connected to it. Note that calls to startService()
1585 * are not nesting: no matter how many times you call startService(),
1586 * a single call to {@link #stopService} will stop it.
1587 *
1588 * <p>The system attempts to keep running services around as much as
1589 * possible. The only time they should be stopped is if the current
1590 * foreground application is using so many resources that the service needs
1591 * to be killed. If any errors happen in the service's process, it will
1592 * automatically be restarted.
1593 *
1594 * <p>This function will throw {@link SecurityException} if you do not
1595 * have permission to start the given service.
1596 *
1597 * @param service Identifies the service to be started. The Intent may
1598 * specify either an explicit component name to start, or a logical
1599 * description (action, category, etc) to match an
1600 * {@link IntentFilter} published by a service. Additional values
1601 * may be included in the Intent extras to supply arguments along with
1602 * this specific start call.
1603 *
1604 * @return If the service is being started or is already running, the
1605 * {@link ComponentName} of the actual service that was started is
1606 * returned; else if the service does not exist null is returned.
1607 *
1608 * @throws SecurityException
1609 *
1610 * @see #stopService
1611 * @see #bindService
1612 */
1613 public abstract ComponentName startService(Intent service);
1614
1615 /**
1616 * Request that a given application service be stopped. If the service is
1617 * not running, nothing happens. Otherwise it is stopped. Note that calls
1618 * to startService() are not counted -- this stops the service no matter
1619 * how many times it was started.
1620 *
1621 * <p>Note that if a stopped service still has {@link ServiceConnection}
1622 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1623 * not be destroyed until all of these bindings are removed. See
1624 * the {@link android.app.Service} documentation for more details on a
1625 * service's lifecycle.
1626 *
1627 * <p>This function will throw {@link SecurityException} if you do not
1628 * have permission to stop the given service.
1629 *
1630 * @param service Description of the service to be stopped. The Intent may
1631 * specify either an explicit component name to start, or a logical
1632 * description (action, category, etc) to match an
1633 * {@link IntentFilter} published by a service.
1634 *
1635 * @return If there is a service matching the given Intent that is already
1636 * running, then it is stopped and true is returned; else false is returned.
1637 *
1638 * @throws SecurityException
1639 *
1640 * @see #startService
1641 */
1642 public abstract boolean stopService(Intent service);
1643
1644 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001645 * @hide like {@link #startService(Intent)} but for a specific user.
1646 */
1647 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1648
1649 /**
1650 * @hide like {@link #stopService(Intent)} but for a specific user.
1651 */
1652 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
1653
1654 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 * Connect to an application service, creating it if needed. This defines
1656 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001657 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001658 * told if it dies and restarts. The service will be considered required
1659 * by the system only for as long as the calling context exists. For
1660 * example, if this Context is an Activity that is stopped, the service will
1661 * not be required to continue running until the Activity is resumed.
1662 *
1663 * <p>This function will throw {@link SecurityException} if you do not
1664 * have permission to bind to the given service.
1665 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001666 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001668 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 * {@link #startService} with the arguments containing the command to be
1670 * sent, with the service calling its
1671 * {@link android.app.Service#stopSelf(int)} method when done executing
1672 * that command. See the API demo App/Service/Service Start Arguments
1673 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001674 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1676 * is tied to another object (the one that registered it).</p>
1677 *
1678 * @param service Identifies the service to connect to. The Intent may
1679 * specify either an explicit component name, or a logical
1680 * description (action, category, etc) to match an
1681 * {@link IntentFilter} published by a service.
1682 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07001683 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07001684 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07001685 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1686 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1687 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1688 * {@link #BIND_WAIVE_PRIORITY}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 * @return If you have successfully bound to the service, true is returned;
1690 * false is returned if the connection is not made so you will not
1691 * receive the service object.
1692 *
1693 * @throws SecurityException
1694 *
1695 * @see #unbindService
1696 * @see #startService
1697 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07001698 * @see #BIND_DEBUG_UNBIND
1699 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 */
1701 public abstract boolean bindService(Intent service, ServiceConnection conn,
1702 int flags);
1703
1704 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001705 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001706 * argument for use by system server and other multi-user aware code.
1707 * @hide
1708 */
Amith Yamasani27b89e62013-01-16 12:30:11 -08001709 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001710 throw new RuntimeException("Not implemented. Must override in a subclass.");
1711 }
1712
1713 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 * Disconnect from an application service. You will no longer receive
1715 * calls as the service is restarted, and the service is now allowed to
1716 * stop at any time.
1717 *
1718 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07001719 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 *
1721 * @see #bindService
1722 */
1723 public abstract void unbindService(ServiceConnection conn);
1724
1725 /**
1726 * Start executing an {@link android.app.Instrumentation} class. The given
1727 * Instrumentation component will be run by killing its target application
1728 * (if currently running), starting the target process, instantiating the
1729 * instrumentation component, and then letting it drive the application.
1730 *
1731 * <p>This function is not synchronous -- it returns as soon as the
1732 * instrumentation has started and while it is running.
1733 *
1734 * <p>Instrumentation is normally only allowed to run against a package
1735 * that is either unsigned or signed with a signature that the
1736 * the instrumentation package is also signed with (ensuring the target
1737 * trusts the instrumentation).
1738 *
1739 * @param className Name of the Instrumentation component to be run.
1740 * @param profileFile Optional path to write profiling data as the
1741 * instrumentation runs, or null for no profiling.
1742 * @param arguments Additional optional arguments to pass to the
1743 * instrumentation, or null.
1744 *
1745 * @return Returns true if the instrumentation was successfully started,
1746 * else false if it could not be found.
1747 */
1748 public abstract boolean startInstrumentation(ComponentName className,
1749 String profileFile, Bundle arguments);
1750
1751 /**
1752 * Return the handle to a system-level service by name. The class of the
1753 * returned object varies by the requested name. Currently available names
1754 * are:
Scott Main4b5da682010-10-21 11:49:12 -07001755 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 * <dl>
1757 * <dt> {@link #WINDOW_SERVICE} ("window")
1758 * <dd> The top-level window manager in which you can place custom
1759 * windows. The returned object is a {@link android.view.WindowManager}.
1760 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
1761 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
1762 * in this context.
1763 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
1764 * <dd> A {@link android.app.ActivityManager} for interacting with the
1765 * global activity state of the system.
1766 * <dt> {@link #POWER_SERVICE} ("power")
1767 * <dd> A {@link android.os.PowerManager} for controlling power
1768 * management.
1769 * <dt> {@link #ALARM_SERVICE} ("alarm")
1770 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
1771 * time of your choosing.
1772 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
1773 * <dd> A {@link android.app.NotificationManager} for informing the user
1774 * of background events.
1775 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
1776 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
1777 * <dt> {@link #LOCATION_SERVICE} ("location")
1778 * <dd> A {@link android.location.LocationManager} for controlling location
1779 * (e.g., GPS) updates.
1780 * <dt> {@link #SEARCH_SERVICE} ("search")
1781 * <dd> A {@link android.app.SearchManager} for handling search.
1782 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
1783 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
1784 * hardware.
1785 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
1786 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
1787 * handling management of network connections.
1788 * <dt> {@link #WIFI_SERVICE} ("wifi")
1789 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
1790 * Wi-Fi connectivity.
1791 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
1792 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
1793 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08001794 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
1795 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07001796 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07001797 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07001799 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 * <p>Note: System services obtained via this API may be closely associated with
1801 * the Context in which they are obtained from. In general, do not share the
1802 * service objects between various different contexts (Activities, Applications,
1803 * Services, Providers, etc.)
1804 *
1805 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07001806 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07001808 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 * @see #WINDOW_SERVICE
1810 * @see android.view.WindowManager
1811 * @see #LAYOUT_INFLATER_SERVICE
1812 * @see android.view.LayoutInflater
1813 * @see #ACTIVITY_SERVICE
1814 * @see android.app.ActivityManager
1815 * @see #POWER_SERVICE
1816 * @see android.os.PowerManager
1817 * @see #ALARM_SERVICE
1818 * @see android.app.AlarmManager
1819 * @see #NOTIFICATION_SERVICE
1820 * @see android.app.NotificationManager
1821 * @see #KEYGUARD_SERVICE
1822 * @see android.app.KeyguardManager
1823 * @see #LOCATION_SERVICE
1824 * @see android.location.LocationManager
1825 * @see #SEARCH_SERVICE
1826 * @see android.app.SearchManager
1827 * @see #SENSOR_SERVICE
1828 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08001829 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08001830 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 * @see #VIBRATOR_SERVICE
1832 * @see android.os.Vibrator
1833 * @see #CONNECTIVITY_SERVICE
1834 * @see android.net.ConnectivityManager
1835 * @see #WIFI_SERVICE
1836 * @see android.net.wifi.WifiManager
1837 * @see #AUDIO_SERVICE
1838 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07001839 * @see #MEDIA_ROUTER_SERVICE
1840 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001841 * @see #TELEPHONY_SERVICE
1842 * @see android.telephony.TelephonyManager
1843 * @see #INPUT_METHOD_SERVICE
1844 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08001845 * @see #UI_MODE_SERVICE
1846 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07001847 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07001848 * @see android.app.DownloadManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001849 */
1850 public abstract Object getSystemService(String name);
1851
1852 /**
1853 * Use with {@link #getSystemService} to retrieve a
1854 * {@link android.os.PowerManager} for controlling power management,
1855 * including "wake locks," which let you keep the device on while
1856 * you're running long tasks.
1857 */
1858 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07001859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 /**
1861 * Use with {@link #getSystemService} to retrieve a
1862 * {@link android.view.WindowManager} for accessing the system's window
1863 * manager.
1864 *
1865 * @see #getSystemService
1866 * @see android.view.WindowManager
1867 */
1868 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07001869
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001870 /**
1871 * Use with {@link #getSystemService} to retrieve a
1872 * {@link android.view.LayoutInflater} for inflating layout resources in this
1873 * context.
1874 *
1875 * @see #getSystemService
1876 * @see android.view.LayoutInflater
1877 */
1878 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07001879
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 /**
1881 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07001882 * {@link android.accounts.AccountManager} for receiving intents at a
1883 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07001884 *
1885 * @see #getSystemService
1886 * @see android.accounts.AccountManager
1887 */
1888 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07001889
Fred Quintana60307342009-03-24 22:48:12 -07001890 /**
1891 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 * {@link android.app.ActivityManager} for interacting with the global
1893 * system state.
1894 *
1895 * @see #getSystemService
1896 * @see android.app.ActivityManager
1897 */
1898 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07001899
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900 /**
1901 * Use with {@link #getSystemService} to retrieve a
1902 * {@link android.app.AlarmManager} for receiving intents at a
1903 * time of your choosing.
1904 *
1905 * @see #getSystemService
1906 * @see android.app.AlarmManager
1907 */
1908 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07001909
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 /**
1911 * Use with {@link #getSystemService} to retrieve a
1912 * {@link android.app.NotificationManager} for informing the user of
1913 * background events.
1914 *
1915 * @see #getSystemService
1916 * @see android.app.NotificationManager
1917 */
1918 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07001919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 /**
1921 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07001922 * {@link android.view.accessibility.AccessibilityManager} for giving the user
1923 * feedback for UI events through the registered event listeners.
1924 *
1925 * @see #getSystemService
1926 * @see android.view.accessibility.AccessibilityManager
1927 */
1928 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07001929
svetoslavganov75986cf2009-05-14 22:28:01 -07001930 /**
1931 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932 * {@link android.app.NotificationManager} for controlling keyguard.
1933 *
1934 * @see #getSystemService
1935 * @see android.app.KeyguardManager
1936 */
1937 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 /**
1940 * Use with {@link #getSystemService} to retrieve a {@link
1941 * android.location.LocationManager} for controlling location
1942 * updates.
1943 *
1944 * @see #getSystemService
1945 * @see android.location.LocationManager
1946 */
1947 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08001948
1949 /**
1950 * Use with {@link #getSystemService} to retrieve a
1951 * {@link android.location.CountryDetector} for detecting the country that
1952 * the user is in.
1953 *
1954 * @hide
1955 */
1956 public static final String COUNTRY_DETECTOR = "country_detector";
1957
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958 /**
1959 * Use with {@link #getSystemService} to retrieve a {@link
1960 * android.app.SearchManager} for handling searches.
1961 *
1962 * @see #getSystemService
1963 * @see android.app.SearchManager
1964 */
1965 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07001966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001967 /**
1968 * Use with {@link #getSystemService} to retrieve a {@link
1969 * android.hardware.SensorManager} for accessing sensors.
1970 *
1971 * @see #getSystemService
1972 * @see android.hardware.SensorManager
1973 */
1974 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07001975
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 /**
San Mehatc9d81752010-02-01 10:23:27 -08001977 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07001978 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08001979 * functions.
1980 *
1981 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08001982 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08001983 */
1984 public static final String STORAGE_SERVICE = "storage";
1985
1986 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 * Use with {@link #getSystemService} to retrieve a
1988 * com.android.server.WallpaperService for accessing wallpapers.
1989 *
1990 * @see #getSystemService
1991 */
1992 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07001993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 /**
1995 * Use with {@link #getSystemService} to retrieve a {@link
1996 * android.os.Vibrator} for interacting with the vibration hardware.
1997 *
1998 * @see #getSystemService
1999 * @see android.os.Vibrator
2000 */
2001 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002003 /**
2004 * Use with {@link #getSystemService} to retrieve a {@link
2005 * android.app.StatusBarManager} for interacting with the status bar.
2006 *
2007 * @see #getSystemService
2008 * @see android.app.StatusBarManager
2009 * @hide
2010 */
2011 public static final String STATUS_BAR_SERVICE = "statusbar";
2012
2013 /**
2014 * Use with {@link #getSystemService} to retrieve a {@link
2015 * android.net.ConnectivityManager} for handling management of
2016 * network connections.
2017 *
2018 * @see #getSystemService
2019 * @see android.net.ConnectivityManager
2020 */
2021 public static final String CONNECTIVITY_SERVICE = "connectivity";
2022
2023 /**
2024 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002025 * android.os.IUpdateLock} for managing runtime sequences that
2026 * must not be interrupted by headless OTA application or similar.
2027 *
2028 * @hide
2029 * @see #getSystemService
2030 * @see android.os.UpdateLock
2031 */
2032 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2033
2034 /**
2035 * Use with {@link #getSystemService} to retrieve a {@link
San Mehatd1df8ac2010-01-26 06:17:26 -08002036 * android.net.NetworkManagementService} for handling management of
2037 * system network services
2038 *
2039 * @hide
2040 * @see #getSystemService
2041 * @see android.net.NetworkManagementService
2042 */
2043 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2044
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002045 /** {@hide} */
Jeff Sharkey75279902011-05-24 18:39:45 -07002046 public static final String NETWORK_STATS_SERVICE = "netstats";
2047 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002048 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2049
San Mehatd1df8ac2010-01-26 06:17:26 -08002050 /**
2051 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 * android.net.wifi.WifiManager} for handling management of
2053 * Wi-Fi access.
2054 *
2055 * @see #getSystemService
2056 * @see android.net.wifi.WifiManager
2057 */
2058 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 /**
repo sync55bc5f32011-06-24 14:23:07 -07002061 * Use with {@link #getSystemService} to retrieve a {@link
2062 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002063 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002064 *
2065 * @see #getSystemService
2066 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002067 */
2068 public static final String WIFI_P2P_SERVICE = "wifip2p";
2069
2070 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002071 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002072 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002073 * discovery
2074 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002075 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002076 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002077 */
2078 public static final String NSD_SERVICE = "servicediscovery";
2079
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002080 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 * Use with {@link #getSystemService} to retrieve a
2082 * {@link android.media.AudioManager} for handling management of volume,
2083 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002084 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002085 * @see #getSystemService
2086 * @see android.media.AudioManager
2087 */
2088 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002089
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 /**
2091 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002092 * {@link android.media.MediaRouter} for controlling and managing
2093 * routing of media.
2094 *
2095 * @see #getSystemService
2096 * @see android.media.MediaRouter
2097 */
2098 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2099
2100 /**
2101 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 * {@link android.telephony.TelephonyManager} for handling management the
2103 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002104 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002105 * @see #getSystemService
2106 * @see android.telephony.TelephonyManager
2107 */
2108 public static final String TELEPHONY_SERVICE = "phone";
2109
2110 /**
2111 * Use with {@link #getSystemService} to retrieve a
2112 * {@link android.text.ClipboardManager} for accessing and modifying
2113 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002114 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 * @see #getSystemService
2116 * @see android.text.ClipboardManager
2117 */
2118 public static final String CLIPBOARD_SERVICE = "clipboard";
2119
2120 /**
Scott Main4b5da682010-10-21 11:49:12 -07002121 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2123 * methods.
2124 *
2125 * @see #getSystemService
2126 */
2127 public static final String INPUT_METHOD_SERVICE = "input_method";
2128
2129 /**
2130 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002131 * {@link android.view.textservice.TextServicesManager} for accessing
2132 * text services.
2133 *
2134 * @see #getSystemService
2135 */
2136 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2137
2138 /**
2139 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002140 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002141 *
2142 * @hide
2143 * @see #getSystemService
2144 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002145 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002146
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002148 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002149 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002150 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002151 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002152 *
Christopher Tate487529a2009-04-29 14:03:25 -07002153 * @see #getSystemService
2154 */
2155 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002156
2157 /**
2158 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002159 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002160 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002161 * @see #getSystemService
2162 */
2163 public static final String DROPBOX_SERVICE = "dropbox";
2164
Christopher Tate487529a2009-04-29 14:03:25 -07002165 /**
Scott Main4b5da682010-10-21 11:49:12 -07002166 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002167 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002168 * device policy management.
2169 *
2170 * @see #getSystemService
2171 */
2172 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2173
2174 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002175 * Use with {@link #getSystemService} to retrieve a
2176 * {@link android.app.UiModeManager} for controlling UI modes.
2177 *
2178 * @see #getSystemService
2179 */
2180 public static final String UI_MODE_SERVICE = "uimode";
2181
2182 /**
Steve Howarda2709362010-07-02 17:12:48 -07002183 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002184 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002185 *
2186 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002187 */
2188 public static final String DOWNLOAD_SERVICE = "download";
2189
2190 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002191 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002192 * {@link android.nfc.NfcManager} for using NFC.
2193 *
2194 * @see #getSystemService
2195 */
2196 public static final String NFC_SERVICE = "nfc";
2197
2198 /**
2199 * Use with {@link #getSystemService} to retrieve a
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002200 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2201 *
2202 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002203 */
2204 public static final String BLUETOOTH_SERVICE = "bluetooth";
2205
2206 /**
2207 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002208 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2209 *
2210 * @see #getSystemService
2211 */
2212 /** @hide */
2213 public static final String SIP_SERVICE = "sip";
2214
2215 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002216 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002217 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002218 * and for controlling this device's behavior as a USB device.
2219 *
2220 * @see #getSystemService
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002221 * @see android.harware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002222 */
2223 public static final String USB_SERVICE = "usb";
2224
2225 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002226 * Use with {@link #getSystemService} to retrieve a {@link
2227 * android.hardware.SerialManager} for access to serial ports.
2228 *
2229 * @see #getSystemService
2230 * @see android.harware.SerialManager
2231 *
2232 * @hide
2233 */
2234 public static final String SERIAL_SERVICE = "serial";
2235
2236 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002237 * Use with {@link #getSystemService} to retrieve a
2238 * {@link android.hardware.input.InputManager} for interacting with input devices.
2239 *
2240 * @see #getSystemService
2241 * @see android.hardware.input.InputManager
2242 */
2243 public static final String INPUT_SERVICE = "input";
2244
2245 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002246 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002247 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2248 *
2249 * @see #getSystemService
2250 * @see android.hardware.display.DisplayManager
2251 */
2252 public static final String DISPLAY_SERVICE = "display";
2253
2254 /**
2255 * Use with {@link #getSystemService} to retrieve a
Glenn Kasten07b04652012-04-23 15:00:43 -07002256 * {@link android.os.SchedulingPolicyService} for managing scheduling policy.
2257 *
2258 * @see #getSystemService
2259 * @see android.os.SchedulingPolicyService
2260 *
2261 * @hide
2262 */
2263 public static final String SCHEDULING_POLICY_SERVICE = "scheduling_policy";
2264
2265 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002266 * Use with {@link #getSystemService} to retrieve a
2267 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2268 *
2269 * @see #getSystemService
2270 * @see android.os.UserManager
2271 */
2272 public static final String USER_SERVICE = "user";
2273
2274 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002275 * Use with {@link #getSystemService} to retrieve a
2276 * {@link android.app.AppOpsManager} for tracking application operations
2277 * on the device.
2278 *
2279 * @see #getSystemService
2280 * @see android.app.AppOpsManager
2281 *
2282 * @hide
2283 */
2284 public static final String APP_OPS_SERVICE = "appops";
2285
2286 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002287 * Determine whether the given permission is allowed for a particular
2288 * process and user ID running in the system.
2289 *
2290 * @param permission The name of the permission being checked.
2291 * @param pid The process ID being checked against. Must be > 0.
2292 * @param uid The user ID being checked against. A uid of 0 is the root
2293 * user, which will pass every permission check.
2294 *
2295 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
2296 * pid/uid is allowed that permission, or
2297 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2298 *
2299 * @see PackageManager#checkPermission(String, String)
2300 * @see #checkCallingPermission
2301 */
2302 public abstract int checkPermission(String permission, int pid, int uid);
2303
2304 /**
2305 * Determine whether the calling process of an IPC you are handling has been
2306 * granted a particular permission. This is basically the same as calling
2307 * {@link #checkPermission(String, int, int)} with the pid and uid returned
2308 * by {@link android.os.Binder#getCallingPid} and
2309 * {@link android.os.Binder#getCallingUid}. One important difference
2310 * is that if you are not currently processing an IPC, this function
2311 * will always fail. This is done to protect against accidentally
2312 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2313 * to avoid this protection.
2314 *
2315 * @param permission The name of the permission being checked.
2316 *
2317 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
2318 * pid/uid is allowed that permission, or
2319 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2320 *
2321 * @see PackageManager#checkPermission(String, String)
2322 * @see #checkPermission
2323 * @see #checkCallingOrSelfPermission
2324 */
2325 public abstract int checkCallingPermission(String permission);
2326
2327 /**
2328 * Determine whether the calling process of an IPC <em>or you</em> have been
2329 * granted a particular permission. This is the same as
2330 * {@link #checkCallingPermission}, except it grants your own permissions
2331 * if you are not currently processing an IPC. Use with care!
2332 *
2333 * @param permission The name of the permission being checked.
2334 *
2335 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the calling
2336 * pid/uid is allowed that permission, or
2337 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2338 *
2339 * @see PackageManager#checkPermission(String, String)
2340 * @see #checkPermission
2341 * @see #checkCallingPermission
2342 */
2343 public abstract int checkCallingOrSelfPermission(String permission);
2344
2345 /**
2346 * If the given permission is not allowed for a particular process
2347 * and user ID running in the system, throw a {@link SecurityException}.
2348 *
2349 * @param permission The name of the permission being checked.
2350 * @param pid The process ID being checked against. Must be &gt; 0.
2351 * @param uid The user ID being checked against. A uid of 0 is the root
2352 * user, which will pass every permission check.
2353 * @param message A message to include in the exception if it is thrown.
2354 *
2355 * @see #checkPermission(String, int, int)
2356 */
2357 public abstract void enforcePermission(
2358 String permission, int pid, int uid, String message);
2359
2360 /**
2361 * If the calling process of an IPC you are handling has not been
2362 * granted a particular permission, throw a {@link
2363 * SecurityException}. This is basically the same as calling
2364 * {@link #enforcePermission(String, int, int, String)} with the
2365 * pid and uid returned by {@link android.os.Binder#getCallingPid}
2366 * and {@link android.os.Binder#getCallingUid}. One important
2367 * difference is that if you are not currently processing an IPC,
2368 * this function will always throw the SecurityException. This is
2369 * done to protect against accidentally leaking permissions; you
2370 * can use {@link #enforceCallingOrSelfPermission} to avoid this
2371 * protection.
2372 *
2373 * @param permission The name of the permission being checked.
2374 * @param message A message to include in the exception if it is thrown.
2375 *
2376 * @see #checkCallingPermission(String)
2377 */
2378 public abstract void enforceCallingPermission(
2379 String permission, String message);
2380
2381 /**
2382 * If neither you nor the calling process of an IPC you are
2383 * handling has been granted a particular permission, throw a
2384 * {@link SecurityException}. This is the same as {@link
2385 * #enforceCallingPermission}, except it grants your own
2386 * permissions if you are not currently processing an IPC. Use
2387 * with care!
2388 *
2389 * @param permission The name of the permission being checked.
2390 * @param message A message to include in the exception if it is thrown.
2391 *
2392 * @see #checkCallingOrSelfPermission(String)
2393 */
2394 public abstract void enforceCallingOrSelfPermission(
2395 String permission, String message);
2396
2397 /**
2398 * Grant permission to access a specific Uri to another package, regardless
2399 * of whether that package has general permission to access the Uri's
2400 * content provider. This can be used to grant specific, temporary
2401 * permissions, typically in response to user interaction (such as the
2402 * user opening an attachment that you would like someone else to
2403 * display).
2404 *
2405 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2406 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2407 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2408 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
2409 * start an activity instead of this function directly. If you use this
2410 * function directly, you should be sure to call
2411 * {@link #revokeUriPermission} when the target should no longer be allowed
2412 * to access it.
2413 *
2414 * <p>To succeed, the content provider owning the Uri must have set the
2415 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
2416 * grantUriPermissions} attribute in its manifest or included the
2417 * {@link android.R.styleable#AndroidManifestGrantUriPermission
2418 * &lt;grant-uri-permissions&gt;} tag.
2419 *
2420 * @param toPackage The package you would like to allow to access the Uri.
2421 * @param uri The Uri you would like to grant access to.
2422 * @param modeFlags The desired access modes. Any combination of
2423 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2424 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2425 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2426 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2427 *
2428 * @see #revokeUriPermission
2429 */
2430 public abstract void grantUriPermission(String toPackage, Uri uri,
2431 int modeFlags);
2432
2433 /**
2434 * Remove all permissions to access a particular content provider Uri
2435 * that were previously added with {@link #grantUriPermission}. The given
2436 * Uri will match all previously granted Uris that are the same or a
2437 * sub-path of the given Uri. That is, revoking "content://foo/one" will
2438 * revoke both "content://foo/target" and "content://foo/target/sub", but not
2439 * "content://foo".
2440 *
2441 * @param uri The Uri you would like to revoke access to.
2442 * @param modeFlags The desired access modes. Any combination of
2443 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2444 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2445 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2446 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2447 *
2448 * @see #grantUriPermission
2449 */
2450 public abstract void revokeUriPermission(Uri uri, int modeFlags);
2451
2452 /**
2453 * Determine whether a particular process and user ID has been granted
2454 * permission to access a specific URI. This only checks for permissions
2455 * that have been explicitly granted -- if the given process/uid has
2456 * more general access to the URI's content provider then this check will
2457 * always fail.
2458 *
2459 * @param uri The uri that is being checked.
2460 * @param pid The process ID being checked against. Must be &gt; 0.
2461 * @param uid The user ID being checked against. A uid of 0 is the root
2462 * user, which will pass every permission check.
2463 * @param modeFlags The type of access to grant. May be one or both of
2464 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2465 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2466 *
2467 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the given
2468 * pid/uid is allowed to access that uri, or
2469 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2470 *
2471 * @see #checkCallingUriPermission
2472 */
2473 public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags);
2474
2475 /**
2476 * Determine whether the calling process and user ID has been
2477 * granted permission to access a specific URI. This is basically
2478 * the same as calling {@link #checkUriPermission(Uri, int, int,
2479 * int)} with the pid and uid returned by {@link
2480 * android.os.Binder#getCallingPid} and {@link
2481 * android.os.Binder#getCallingUid}. One important difference is
2482 * that if you are not currently processing an IPC, this function
2483 * will always fail.
2484 *
2485 * @param uri The uri that is being checked.
2486 * @param modeFlags The type of access to grant. May be one or both of
2487 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2488 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2489 *
2490 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2491 * is allowed to access that uri, or
2492 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2493 *
2494 * @see #checkUriPermission(Uri, int, int, int)
2495 */
2496 public abstract int checkCallingUriPermission(Uri uri, int modeFlags);
2497
2498 /**
2499 * Determine whether the calling process of an IPC <em>or you</em> has been granted
2500 * permission to access a specific URI. This is the same as
2501 * {@link #checkCallingUriPermission}, except it grants your own permissions
2502 * if you are not currently processing an IPC. Use with care!
2503 *
2504 * @param uri The uri that is being checked.
2505 * @param modeFlags The type of access to grant. May be one or both of
2506 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2507 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2508 *
2509 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2510 * is allowed to access that uri, or
2511 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2512 *
2513 * @see #checkCallingUriPermission
2514 */
2515 public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags);
2516
2517 /**
2518 * Check both a Uri and normal permission. This allows you to perform
2519 * both {@link #checkPermission} and {@link #checkUriPermission} in one
2520 * call.
2521 *
2522 * @param uri The Uri whose permission is to be checked, or null to not
2523 * do this check.
2524 * @param readPermission The permission that provides overall read access,
2525 * or null to not do this check.
2526 * @param writePermission The permission that provides overall write
2527 * acess, or null to not do this check.
2528 * @param pid The process ID being checked against. Must be &gt; 0.
2529 * @param uid The user ID being checked against. A uid of 0 is the root
2530 * user, which will pass every permission check.
2531 * @param modeFlags The type of access to grant. May be one or both of
2532 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2533 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2534 *
2535 * @return Returns {@link PackageManager#PERMISSION_GRANTED} if the caller
2536 * is allowed to access that uri or holds one of the given permissions, or
2537 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2538 */
2539 public abstract int checkUriPermission(Uri uri, String readPermission,
2540 String writePermission, int pid, int uid, int modeFlags);
2541
2542 /**
2543 * If a particular process and user ID has not been granted
2544 * permission to access a specific URI, throw {@link
2545 * SecurityException}. This only checks for permissions that have
2546 * been explicitly granted -- if the given process/uid has more
2547 * general access to the URI's content provider then this check
2548 * will always fail.
2549 *
2550 * @param uri The uri that is being checked.
2551 * @param pid The process ID being checked against. Must be &gt; 0.
2552 * @param uid The user ID being checked against. A uid of 0 is the root
2553 * user, which will pass every permission check.
2554 * @param modeFlags The type of access to grant. May be one or both of
2555 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2556 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2557 * @param message A message to include in the exception if it is thrown.
2558 *
2559 * @see #checkUriPermission(Uri, int, int, int)
2560 */
2561 public abstract void enforceUriPermission(
2562 Uri uri, int pid, int uid, int modeFlags, String message);
2563
2564 /**
2565 * If the calling process and user ID has not been granted
2566 * permission to access a specific URI, throw {@link
2567 * SecurityException}. This is basically the same as calling
2568 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
2569 * the pid and uid returned by {@link
2570 * android.os.Binder#getCallingPid} and {@link
2571 * android.os.Binder#getCallingUid}. One important difference is
2572 * that if you are not currently processing an IPC, this function
2573 * will always throw a SecurityException.
2574 *
2575 * @param uri The uri that is being checked.
2576 * @param modeFlags The type of access to grant. May be one or both of
2577 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2578 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2579 * @param message A message to include in the exception if it is thrown.
2580 *
2581 * @see #checkCallingUriPermission(Uri, int)
2582 */
2583 public abstract void enforceCallingUriPermission(
2584 Uri uri, int modeFlags, String message);
2585
2586 /**
2587 * If the calling process of an IPC <em>or you</em> has not been
2588 * granted permission to access a specific URI, throw {@link
2589 * SecurityException}. This is the same as {@link
2590 * #enforceCallingUriPermission}, except it grants your own
2591 * permissions if you are not currently processing an IPC. Use
2592 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07002593 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 * @param uri The uri that is being checked.
2595 * @param modeFlags The type of access to grant. May be one or both of
2596 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2597 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2598 * @param message A message to include in the exception if it is thrown.
2599 *
2600 * @see #checkCallingOrSelfUriPermission(Uri, int)
2601 */
2602 public abstract void enforceCallingOrSelfUriPermission(
2603 Uri uri, int modeFlags, String message);
2604
2605 /**
2606 * Enforce both a Uri and normal permission. This allows you to perform
2607 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
2608 * call.
Scott Main4b5da682010-10-21 11:49:12 -07002609 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 * @param uri The Uri whose permission is to be checked, or null to not
2611 * do this check.
2612 * @param readPermission The permission that provides overall read access,
2613 * or null to not do this check.
2614 * @param writePermission The permission that provides overall write
2615 * acess, or null to not do this check.
2616 * @param pid The process ID being checked against. Must be &gt; 0.
2617 * @param uid The user ID being checked against. A uid of 0 is the root
2618 * user, which will pass every permission check.
2619 * @param modeFlags The type of access to grant. May be one or both of
2620 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2621 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2622 * @param message A message to include in the exception if it is thrown.
2623 *
2624 * @see #checkUriPermission(Uri, String, String, int, int, int)
2625 */
2626 public abstract void enforceUriPermission(
2627 Uri uri, String readPermission, String writePermission,
2628 int pid, int uid, int modeFlags, String message);
2629
2630 /**
2631 * Flag for use with {@link #createPackageContext}: include the application
2632 * code with the context. This means loading code into the caller's
2633 * process, so that {@link #getClassLoader()} can be used to instantiate
2634 * the application's classes. Setting this flags imposes security
2635 * restrictions on what application context you can access; if the
2636 * requested application can not be safely loaded into your process,
2637 * java.lang.SecurityException will be thrown. If this flag is not set,
2638 * there will be no restrictions on the packages that can be loaded,
2639 * but {@link #getClassLoader} will always return the default system
2640 * class loader.
2641 */
2642 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
2643
2644 /**
2645 * Flag for use with {@link #createPackageContext}: ignore any security
2646 * restrictions on the Context being requested, allowing it to always
2647 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
2648 * to be loaded into a process even when it isn't safe to do so. Use
2649 * with extreme care!
2650 */
2651 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07002652
Romain Guy870e09f2009-07-06 16:35:25 -07002653 /**
2654 * Flag for use with {@link #createPackageContext}: a restricted context may
2655 * disable specific features. For instance, a View associated with a restricted
2656 * context would ignore particular XML attributes.
2657 */
2658 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659
2660 /**
2661 * Return a new Context object for the given application name. This
2662 * Context is the same as what the named application gets when it is
2663 * launched, containing the same resources and class loader. Each call to
2664 * this method returns a new instance of a Context object; Context objects
2665 * are not shared, however they share common state (Resources, ClassLoader,
2666 * etc) so the Context instance itself is fairly lightweight.
2667 *
2668 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
2669 * application with the given package name.
2670 *
2671 * <p>Throws {@link java.lang.SecurityException} if the Context requested
2672 * can not be loaded into the caller's process for security reasons (see
2673 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
2674 *
2675 * @param packageName Name of the application's package.
2676 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
2677 * or {@link #CONTEXT_IGNORE_SECURITY}.
2678 *
2679 * @return A Context for the application.
2680 *
2681 * @throws java.lang.SecurityException
2682 * @throws PackageManager.NameNotFoundException if there is no application with
2683 * the given package name
2684 */
2685 public abstract Context createPackageContext(String packageName,
2686 int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07002687
2688 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07002689 * Similar to {@link #createPackageContext(String, int)}, but with a
2690 * different {@link UserHandle}. For example, {@link #getContentResolver()}
2691 * will open any {@link Uri} as the given user.
2692 *
2693 * @hide
2694 */
2695 public abstract Context createPackageContextAsUser(
2696 String packageName, int flags, UserHandle user)
2697 throws PackageManager.NameNotFoundException;
2698
2699 /**
Jim Millera75a8832013-02-07 16:53:32 -08002700 * Get the userId associated with this context
2701 * @return user id
2702 *
2703 * @hide
2704 */
2705 public abstract int getUserId();
2706
2707 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07002708 * Return a new Context object for the current Context but whose resources
2709 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07002710 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07002711 * shared, however common state (ClassLoader, other Resources for the
2712 * same configuration) may be so the Context itself can be fairly lightweight.
2713 *
2714 * @param overrideConfiguration A {@link Configuration} specifying what
2715 * values to modify in the base Configuration of the original Context's
2716 * resources. If the base configuration changes (such as due to an
2717 * orientation change), the resources of this context will also change except
2718 * for those that have been explicitly overridden with a value here.
2719 *
Jeff Browna492c3a2012-08-23 19:48:44 -07002720 * @return A Context with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07002721 */
2722 public abstract Context createConfigurationContext(Configuration overrideConfiguration);
2723
2724 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07002725 * Return a new Context object for the current Context but whose resources
2726 * are adjusted to match the metrics of the given Display. Each call to this method
2727 * returns a new instance of a Context object; Context objects are not
2728 * shared, however common state (ClassLoader, other Resources for the
2729 * same configuration) may be so the Context itself can be fairly lightweight.
2730 *
2731 * The returned display Context provides a {@link WindowManager}
2732 * (see {@link #getSystemService(String)}) that is configured to show windows
2733 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
2734 * method can be used to retrieve the Display from the returned Context.
2735 *
2736 * @param display A {@link Display} object specifying the display
2737 * for whose metrics the Context's resources should be tailored and upon which
2738 * new windows should be shown.
2739 *
2740 * @return A Context for the display.
2741 */
2742 public abstract Context createDisplayContext(Display display);
2743
2744 /**
Jeff Brown98365d72012-08-19 20:30:52 -07002745 * Gets the compatibility info holder for this context. This information
2746 * is provided on a per-application basis and is used to simulate lower density
2747 * display metrics for legacy applications.
2748 *
Jeff Browna492c3a2012-08-23 19:48:44 -07002749 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07002750 * @return The compatibility info holder, or null if not required by the application.
2751 * @hide
2752 */
Jeff Browna492c3a2012-08-23 19:48:44 -07002753 public abstract CompatibilityInfoHolder getCompatibilityInfo(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07002754
2755 /**
Romain Guy870e09f2009-07-06 16:35:25 -07002756 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07002757 *
Romain Guy870e09f2009-07-06 16:35:25 -07002758 * @return True if this Context is restricted, false otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07002759 *
Romain Guy870e09f2009-07-06 16:35:25 -07002760 * @see #CONTEXT_RESTRICTED
2761 */
2762 public boolean isRestricted() {
2763 return false;
2764 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765}