blob: 7b15e63b4bb091751cb91d279d94bc9fbe357213 [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;
Craig Mautner48d0d182013-06-11 07:53:06 -070038import android.view.DisplayAdjustments;
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;
48
49/**
50 * Interface to global information about an application environment. This is
51 * an abstract class whose implementation is provided by
52 * the Android system. It
53 * allows access to application-specific resources and classes, as well as
54 * up-calls for application-level operations such as launching activities,
55 * broadcasting and receiving intents, etc.
56 */
57public abstract class Context {
58 /**
59 * File creation mode: the default mode, where the created file can only
60 * be accessed by the calling application (or all applications sharing the
61 * same user ID).
62 * @see #MODE_WORLD_READABLE
63 * @see #MODE_WORLD_WRITEABLE
64 */
65 public static final int MODE_PRIVATE = 0x0000;
66 /**
Nick Kralevich15069212013-01-09 15:54:56 -080067 * @deprecated Creating world-readable files is very dangerous, and likely
68 * to cause security holes in applications. It is strongly discouraged;
69 * instead, applications should use more formal mechanism for interactions
70 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
71 * {@link android.app.Service}. There are no guarantees that this
72 * access mode will remain on a file, such as when it goes through a
73 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 * File creation mode: allow all other applications to have read access
75 * to the created file.
76 * @see #MODE_PRIVATE
77 * @see #MODE_WORLD_WRITEABLE
78 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070079 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 public static final int MODE_WORLD_READABLE = 0x0001;
81 /**
Nick Kralevich15069212013-01-09 15:54:56 -080082 * @deprecated Creating world-writable files is very dangerous, and likely
83 * to cause security holes in applications. It is strongly discouraged;
84 * instead, applications should use more formal mechanism for interactions
85 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
86 * {@link android.app.Service}. There are no guarantees that this
87 * access mode will remain on a file, such as when it goes through a
88 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 * File creation mode: allow all other applications to have write access
90 * to the created file.
91 * @see #MODE_PRIVATE
92 * @see #MODE_WORLD_READABLE
93 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070094 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 public static final int MODE_WORLD_WRITEABLE = 0x0002;
96 /**
97 * File creation mode: for use with {@link #openFileOutput}, if the file
98 * already exists then write data to the end of the existing file
99 * instead of erasing it.
100 * @see #openFileOutput
101 */
102 public static final int MODE_APPEND = 0x8000;
103
104 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800105 * SharedPreference loading flag: when set, the file on disk will
106 * be checked for modification even if the shared preferences
107 * instance is already loaded in this process. This behavior is
108 * sometimes desired in cases where the application has multiple
109 * processes, all writing to the same SharedPreferences file.
110 * Generally there are better forms of communication between
111 * processes, though.
112 *
113 * <p>This was the legacy (but undocumented) behavior in and
114 * before Gingerbread (Android 2.3) and this flag is implied when
115 * targetting such releases. For applications targetting SDK
116 * versions <em>greater than</em> Android 2.3, this flag must be
117 * explicitly set if desired.
118 *
119 * @see #getSharedPreferences
120 */
121 public static final int MODE_MULTI_PROCESS = 0x0004;
122
123 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700124 * Database open flag: when set, the database is opened with write-ahead
125 * logging enabled by default.
126 *
127 * @see #openOrCreateDatabase(String, int, CursorFactory)
128 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
129 * @see SQLiteDatabase#enableWriteAheadLogging
130 */
131 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
132
133 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 * Flag for {@link #bindService}: automatically create the service as long
135 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700136 * its {@link android.app.Service#onStartCommand}
137 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 * explicit call to {@link #startService}. Even without that, though,
139 * this still provides you with access to the service object while the
140 * service is created.
141 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700142 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
143 * not supplying this flag would also impact how important the system
144 * consider's the target service's process to be. When set, the only way
145 * for it to be raised was by binding from a service in which case it will
146 * only be important when that activity is in the foreground. Now to
147 * achieve this behavior you must explicitly supply the new flag
148 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
149 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
150 * the flags {@link #BIND_WAIVE_PRIORITY} and
151 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
152 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 */
154 public static final int BIND_AUTO_CREATE = 0x0001;
155
156 /**
157 * Flag for {@link #bindService}: include debugging help for mismatched
158 * calls to unbind. When this flag is set, the callstack of the following
159 * {@link #unbindService} call is retained, to be printed if a later
160 * incorrect unbind call is made. Note that doing this requires retaining
161 * information about the binding that was made for the lifetime of the app,
162 * resulting in a leak -- this should only be used for debugging.
163 */
164 public static final int BIND_DEBUG_UNBIND = 0x0002;
165
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800166 /**
167 * Flag for {@link #bindService}: don't allow this binding to raise
168 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700169 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800170 * as the client (so that its process will not be killable in any
171 * situation where the client is not killable), but for CPU scheduling
172 * purposes it may be left in the background. This only has an impact
173 * in the situation where the binding client is a foreground process
174 * and the target service is in a background process.
175 */
176 public static final int BIND_NOT_FOREGROUND = 0x0004;
177
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700178 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700179 * Flag for {@link #bindService}: indicates that the client application
180 * binding to this service considers the service to be more important than
181 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700182 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700183 * this is not guaranteed to be the case.
184 */
185 public static final int BIND_ABOVE_CLIENT = 0x0008;
186
187 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700188 * Flag for {@link #bindService}: allow the process hosting the bound
189 * service to go through its normal memory management. It will be
190 * treated more like a running service, allowing the system to
191 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700192 * whim it may have, and being more aggressive about making it a candidate
193 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700194 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700195 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
196
197 /**
198 * Flag for {@link #bindService}: don't impact the scheduling or
199 * memory management priority of the target service's hosting process.
200 * Allows the service's process to be managed on the background LRU list
201 * just like a regular application process in the background.
202 */
203 public static final int BIND_WAIVE_PRIORITY = 0x0020;
204
205 /**
206 * Flag for {@link #bindService}: this service is very important to
207 * the client, so should be brought to the foreground process level
208 * when the client is. Normally a process can only be raised to the
209 * visibility level by a client, even if that client is in the foreground.
210 */
211 public static final int BIND_IMPORTANT = 0x0040;
212
213 /**
214 * Flag for {@link #bindService}: If binding from an activity, allow the
215 * target service's process importance to be raised based on whether the
216 * activity is visible to the user, regardless whether another flag is
217 * used to reduce the amount that the client process's overall importance
218 * is used to impact it.
219 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700220 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
221
222 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700223 * @hide An idea that is not yet implemented.
224 * Flag for {@link #bindService}: If binding from an activity, consider
225 * this service to be visible like the binding activity is. That is,
226 * it will be treated as something more important to keep around than
227 * invisible background activities. This will impact the number of
228 * recent activities the user can switch between without having them
229 * restart. There is no guarantee this will be respected, as the system
230 * tries to balance such requests from one app vs. the importantance of
231 * keeping other apps around.
232 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700233 public static final int BIND_VISIBLE = 0x10000000;
234
235 /**
236 * @hide
237 * Flag for {@link #bindService}: Consider this binding to be causing the target
238 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
239 * away.
240 */
241 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700242
243 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700244 * Flag for {@link #bindService}: Don't consider the bound service to be
245 * visible, even if the caller is visible.
246 * @hide
247 */
248 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 /** Return an AssetManager instance for your application's package. */
251 public abstract AssetManager getAssets();
252
253 /** Return a Resources instance for your application's package. */
254 public abstract Resources getResources();
255
256 /** Return PackageManager instance to find global package information. */
257 public abstract PackageManager getPackageManager();
258
259 /** Return a ContentResolver instance for your application's package. */
260 public abstract ContentResolver getContentResolver();
261
262 /**
263 * Return the Looper for the main thread of the current process. This is
264 * the thread used to dispatch calls to application components (activities,
265 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700266 * <p>
267 * By definition, this method returns the same result as would be obtained
268 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
269 * </p>
270 *
271 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 */
273 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700274
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 /**
276 * Return the context of the single, global Application object of the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800277 * current process. This generally should only be used if you need a
278 * Context whose lifecycle is separate from the current context, that is
279 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700280 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800281 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800282 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800283 * <ul>
284 * <li> <p>If used from an Activity context, the receiver is being registered
285 * within that activity. This means that you are expected to unregister
286 * before the activity is done being destroyed; in fact if you do not do
287 * so, the framework will clean up your leaked registration as it removes
288 * the activity and log an error. Thus, if you use the Activity context
289 * to register a receiver that is static (global to the process, not
290 * associated with an Activity instance) then that registration will be
291 * removed on you at whatever point the activity you used is destroyed.
292 * <li> <p>If used from the Context returned here, the receiver is being
293 * registered with the global state associated with your application. Thus
294 * it will never be unregistered for you. This is necessary if the receiver
295 * is associated with static data, not a particular component. However
296 * using the ApplicationContext elsewhere can easily lead to serious leaks
297 * if you forget to unregister, unbind, etc.
298 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800299 */
300 public abstract Context getApplicationContext();
301
302 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700303 * Add a new {@link ComponentCallbacks} to the base application of the
304 * Context, which will be called at the same times as the ComponentCallbacks
305 * methods of activities and other components are called. Note that you
306 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
307 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700308 *
309 * @param callback The interface to call. This can be either a
310 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700311 */
312 public void registerComponentCallbacks(ComponentCallbacks callback) {
313 getApplicationContext().registerComponentCallbacks(callback);
314 }
315
316 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400317 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700318 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
319 */
320 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
321 getApplicationContext().unregisterComponentCallbacks(callback);
322 }
323
324 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 * Return a localized, styled CharSequence from the application's package's
326 * default string table.
327 *
328 * @param resId Resource id for the CharSequence text
329 */
330 public final CharSequence getText(int resId) {
331 return getResources().getText(resId);
332 }
333
334 /**
335 * Return a localized string from the application's package's
336 * default string table.
337 *
338 * @param resId Resource id for the string
339 */
340 public final String getString(int resId) {
341 return getResources().getString(resId);
342 }
343
344 /**
345 * Return a localized formatted string from the application's package's
346 * default string table, substituting the format arguments as defined in
347 * {@link java.util.Formatter} and {@link java.lang.String#format}.
348 *
349 * @param resId Resource id for the format string
350 * @param formatArgs The format arguments that will be used for substitution.
351 */
352
353 public final String getString(int resId, Object... formatArgs) {
354 return getResources().getString(resId, formatArgs);
355 }
356
357 /**
358 * Set the base theme for this context. Note that this should be called
359 * before any views are instantiated in the Context (for example before
360 * calling {@link android.app.Activity#setContentView} or
361 * {@link android.view.LayoutInflater#inflate}).
362 *
363 * @param resid The style resource describing the theme.
364 */
365 public abstract void setTheme(int resid);
366
Dianne Hackborn247fe742011-01-08 17:25:57 -0800367 /** @hide Needed for some internal implementation... not public because
368 * you can't assume this actually means anything. */
369 public int getThemeResId() {
370 return 0;
371 }
372
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 /**
374 * Return the Theme object associated with this Context.
375 */
376 public abstract Resources.Theme getTheme();
377
378 /**
379 * Retrieve styled attribute information in this Context's theme. See
380 * {@link Resources.Theme#obtainStyledAttributes(int[])}
381 * for more information.
382 *
383 * @see Resources.Theme#obtainStyledAttributes(int[])
384 */
385 public final TypedArray obtainStyledAttributes(
386 int[] attrs) {
387 return getTheme().obtainStyledAttributes(attrs);
388 }
389
390 /**
391 * Retrieve styled attribute information in this Context's theme. See
392 * {@link Resources.Theme#obtainStyledAttributes(int, int[])}
393 * for more information.
394 *
395 * @see Resources.Theme#obtainStyledAttributes(int, int[])
396 */
397 public final TypedArray obtainStyledAttributes(
398 int resid, int[] attrs) throws Resources.NotFoundException {
399 return getTheme().obtainStyledAttributes(resid, attrs);
400 }
401
402 /**
403 * Retrieve styled attribute information in this Context's theme. See
404 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
405 * for more information.
406 *
407 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
408 */
409 public final TypedArray obtainStyledAttributes(
410 AttributeSet set, int[] attrs) {
411 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
412 }
413
414 /**
415 * Retrieve styled attribute information in this Context's theme. See
416 * {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
417 * for more information.
418 *
419 * @see Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
420 */
421 public final TypedArray obtainStyledAttributes(
422 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
423 return getTheme().obtainStyledAttributes(
424 set, attrs, defStyleAttr, defStyleRes);
425 }
426
427 /**
428 * Return a class loader you can use to retrieve classes in this package.
429 */
430 public abstract ClassLoader getClassLoader();
431
432 /** Return the name of this application's package. */
433 public abstract String getPackageName();
434
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800435 /** @hide Return the name of the base context this context is derived from. */
436 public abstract String getBasePackageName();
437
Dianne Hackborn95d78532013-09-11 09:51:14 -0700438 /** @hide Return the package name that should be used for app ops calls from
439 * this context. This is the same as {@link #getBasePackageName()} except in
440 * cases where system components are loaded into other app processes, in which
441 * case this will be the name of the primary package in that process (so that app
442 * ops uid verification will work with the name). */
443 public abstract String getOpPackageName();
444
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700445 /** Return the full application info for this context's package. */
446 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 /**
Kenny Root32148392010-01-21 15:40:47 -0800449 * Return the full path to this context's primary Android package.
450 * The Android package is a ZIP file which contains the application's
451 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 *
453 * <p>Note: this is not generally useful for applications, since they should
454 * not be directly accessing the file system.
455 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800456 * @return String Path to the resources.
457 */
458 public abstract String getPackageResourcePath();
459
460 /**
Kenny Root32148392010-01-21 15:40:47 -0800461 * Return the full path to this context's primary Android package.
462 * The Android package is a ZIP file which contains application's
463 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 *
465 * <p>Note: this is not generally useful for applications, since they should
466 * not be directly accessing the file system.
467 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 * @return String Path to the code and assets.
469 */
470 public abstract String getPackageCodePath();
471
472 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700473 * {@hide}
474 * Return the full path to the shared prefs file for the given prefs group name.
475 *
476 * <p>Note: this is not generally useful for applications, since they should
477 * not be directly accessing the file system.
478 */
479 public abstract File getSharedPrefsFile(String name);
480
481 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 * Retrieve and hold the contents of the preferences file 'name', returning
483 * a SharedPreferences through which you can retrieve and modify its
484 * values. Only one instance of the SharedPreferences object is returned
485 * to any callers for the same name, meaning they will see each other's
486 * edits as soon as they are made.
487 *
488 * @param name Desired preferences file. If a preferences file by this name
489 * does not exist, it will be created when you retrieve an
490 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
491 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
492 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800493 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
494 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
495 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
496 * is always on in apps targetting Gingerbread (Android 2.3) and below, and
497 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400499 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 * to retrieve and modify the preference values.
501 *
502 * @see #MODE_PRIVATE
503 * @see #MODE_WORLD_READABLE
504 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800505 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 */
507 public abstract SharedPreferences getSharedPreferences(String name,
508 int mode);
509
510 /**
511 * Open a private file associated with this Context's application package
512 * for reading.
513 *
514 * @param name The name of the file to open; can not contain path
515 * separators.
516 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400517 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 *
519 * @see #openFileOutput
520 * @see #fileList
521 * @see #deleteFile
522 * @see java.io.FileInputStream#FileInputStream(String)
523 */
524 public abstract FileInputStream openFileInput(String name)
525 throws FileNotFoundException;
526
527 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800528 * Open a private file associated with this Context's application package
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 * for writing. Creates the file if it doesn't already exist.
530 *
Nick Kralevich15069212013-01-09 15:54:56 -0800531 * @param name The name of the file to open; can not contain path
532 * separators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800533 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800534 * default operation, {@link #MODE_APPEND} to append to an existing file,
535 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
536 * permissions.
537 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400538 * @return The resulting {@link FileOutputStream}.
Nick Kralevich15069212013-01-09 15:54:56 -0800539 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 * @see #MODE_APPEND
541 * @see #MODE_PRIVATE
542 * @see #MODE_WORLD_READABLE
543 * @see #MODE_WORLD_WRITEABLE
544 * @see #openFileInput
545 * @see #fileList
546 * @see #deleteFile
547 * @see java.io.FileOutputStream#FileOutputStream(String)
548 */
549 public abstract FileOutputStream openFileOutput(String name, int mode)
550 throws FileNotFoundException;
551
552 /**
553 * Delete the given private file associated with this Context's
554 * application package.
555 *
556 * @param name The name of the file to delete; can not contain path
557 * separators.
558 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400559 * @return {@code true} if the file was successfully deleted; else
560 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 *
562 * @see #openFileInput
563 * @see #openFileOutput
564 * @see #fileList
565 * @see java.io.File#delete()
566 */
567 public abstract boolean deleteFile(String name);
568
569 /**
570 * Returns the absolute path on the filesystem where a file created with
571 * {@link #openFileOutput} is stored.
572 *
573 * @param name The name of the file for which you would like to get
574 * its path.
575 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400576 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 *
578 * @see #openFileOutput
579 * @see #getFilesDir
580 * @see #getDir
581 */
582 public abstract File getFileStreamPath(String name);
583
584 /**
585 * Returns the absolute path to the directory on the filesystem where
586 * files created with {@link #openFileOutput} are stored.
587 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400588 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 *
590 * @see #openFileOutput
591 * @see #getFileStreamPath
592 * @see #getDir
593 */
594 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700595
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 /**
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800597 * Returns the absolute path to the directory on the external filesystem
598 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700599 * Environment.getExternalStorageDirectory()}) where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700600 * place persistent files it owns. These files are internal to the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800601 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700602 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800603 * <p>This is like {@link #getFilesDir()} in that these
604 * files will be deleted when the application is uninstalled, however there
605 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700606 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800607 * <ul>
608 * <li>External files are not always available: they will disappear if the
609 * user mounts the external storage on a computer or removes it. See the
610 * APIs on {@link android.os.Environment} for information in the storage state.
611 * <li>There is no security enforced with these files. All applications
612 * can read and write files placed here.
613 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700614 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700615 * <p>On devices with multiple users (as described by {@link UserManager}),
616 * each user has their own isolated external storage. Applications only
617 * have access to the external storage for the user they're running as.</p>
618 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800619 * <p>Here is an example of typical code to manipulate a file in
620 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700621 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800622 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
623 * private_file}
624 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700625 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800626 * file will be a path to a sub-directory of the given type. Though these files
627 * are not automatically scanned by the media scanner, you can explicitly
628 * add them to the media database with
629 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Ray Chenb7c8c762010-03-30 17:21:39 -0700630 * OnScanCompletedListener) MediaScannerConnection.scanFile}.
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800631 * Note that this is not the same as
632 * {@link android.os.Environment#getExternalStoragePublicDirectory
633 * Environment.getExternalStoragePublicDirectory()}, which provides
634 * directories of media shared by all applications. The
635 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700636 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800637 * application is uninstalled. Unlike
638 * {@link android.os.Environment#getExternalStoragePublicDirectory
639 * Environment.getExternalStoragePublicDirectory()}, the directory
640 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700641 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800642 * <p>Here is an example of typical code to manipulate a picture in
643 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700644 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800645 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
646 * private_picture}
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700647 * <p>
Chet Haasee8222dd2013-09-05 07:44:18 -0700648 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700649 * permissions are required for the owning application to read or write to
650 * this path. Otherwise, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
651 * or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700652 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800653 * @param type The type of files directory to return. May be null for
654 * the root of the files directory or one of
655 * the following Environment constants for a subdirectory:
656 * {@link android.os.Environment#DIRECTORY_MUSIC},
657 * {@link android.os.Environment#DIRECTORY_PODCASTS},
658 * {@link android.os.Environment#DIRECTORY_RINGTONES},
659 * {@link android.os.Environment#DIRECTORY_ALARMS},
660 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
661 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
662 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700663 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400664 * @return The path of the directory holding application files
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800665 * on external storage. Returns null if external storage is not currently
666 * mounted so it could not ensure the path exists; you will need to call
667 * this method again when it is available.
668 *
669 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700670 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800671 */
672 public abstract File getExternalFilesDir(String type);
Scott Main4b5da682010-10-21 11:49:12 -0700673
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800674 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700675 * Returns absolute paths to application-specific directories on all
676 * external storage devices where the application can place persistent files
677 * it owns. These files are internal to the application, and not typically
678 * visible to the user as media.
679 * <p>
680 * External storage devices returned here are considered a permanent part of
681 * the device, including both emulated external storage and physical media
682 * slots. This does not include transient devices, such as USB flash drives.
683 * <p>
Chet Haasee8222dd2013-09-05 07:44:18 -0700684 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700685 * permissions are required for the owning application to read or write to
686 * these paths.
687 * <p>
688 * The returned paths include any path that would be returned by
689 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700690 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700691 * @see #getExternalFilesDir(String)
692 */
693 public abstract File[] getExternalFilesDirs(String type);
694
695 /**
696 * Return the directory where this application's OBB files (if there are
697 * any) can be found. Note if the application does not have any OBB files,
698 * this directory may not exist.
699 * <p>
700 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -0700701 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700702 * should ensure that multiple instances running under different users don't
703 * interfere with each other.
704 * <p>
Chet Haasee8222dd2013-09-05 07:44:18 -0700705 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700706 * permissions are required for the owning application to read or write to
707 * this path. Otherwise,
708 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} or
709 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800710 */
711 public abstract File getObbDir();
712
713 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700714 * Returns absolute paths to application-specific directories on all
715 * external storage devices where the application's OBB files (if there are
716 * any) can be found. Note if the application does not have any OBB files,
717 * these directories may not exist.
718 * <p>
719 * External storage devices returned here are considered a permanent part of
720 * the device, including both emulated external storage and physical media
721 * slots. This does not include transient devices, such as USB flash drives.
722 * <p>
Chet Haasee8222dd2013-09-05 07:44:18 -0700723 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700724 * permissions are required for the owning application to read or write to
725 * this path.
726 * <p>
727 * The returned paths include any path that would be returned by
728 * {@link #getObbDir()}
729 *
730 * @see #getObbDir()
731 */
732 public abstract File[] getObbDirs();
733
734 /**
Scott Main4b5da682010-10-21 11:49:12 -0700735 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800737 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700739 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800740 * <strong>Note: you should not <em>rely</em> on the system deleting these
741 * files for you; you should always have a reasonable maximum, such as 1 MB,
742 * for the amount of space you consume with cache files, and prune those
743 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700744 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400745 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 *
747 * @see #openFileOutput
748 * @see #getFileStreamPath
749 * @see #getDir
750 */
751 public abstract File getCacheDir();
752
753 /**
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800754 * Returns the absolute path to the directory on the external filesystem
755 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
756 * Environment.getExternalStorageDirectory()} where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700757 * place cache files it owns. These files are internal to the application, and
758 * not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700759 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800760 * <p>This is like {@link #getCacheDir()} in that these
761 * files will be deleted when the application is uninstalled, however there
762 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700763 *
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800764 * <ul>
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700765 * <li>The platform does not always monitor the space available in external
766 * storage, and thus may not automatically delete these files. Currently
767 * the only time files here will be deleted by the platform is when running
768 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
769 * {@link android.os.Environment#isExternalStorageEmulated()
770 * Environment.isExternalStorageEmulated()} returns true. Note that you should
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800771 * be managing the maximum space you will use for these anyway, just like
772 * with {@link #getCacheDir()}.
773 * <li>External files are not always available: they will disappear if the
774 * user mounts the external storage on a computer or removes it. See the
775 * APIs on {@link android.os.Environment} for information in the storage state.
776 * <li>There is no security enforced with these files. All applications
777 * can read and write files placed here.
778 * </ul>
779 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700780 * <p>On devices with multiple users (as described by {@link UserManager}),
781 * each user has their own isolated external storage. Applications only
782 * have access to the external storage for the user they're running as.</p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700783 * <p>
Chet Haasee8222dd2013-09-05 07:44:18 -0700784 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700785 * permissions are required for the owning application to read or write to
786 * this path. Otherwise,
787 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} or
788 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700789 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400790 * @return The path of the directory holding application cache files
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800791 * on external storage. Returns null if external storage is not currently
792 * mounted so it could not ensure the path exists; you will need to call
793 * this method again when it is available.
794 *
795 * @see #getCacheDir
796 */
797 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700798
Dianne Hackborne83cefc2010-02-04 17:38:14 -0800799 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700800 * Returns absolute paths to application-specific directories on all
801 * external storage devices where the application can place cache files it
802 * owns. These files are internal to the application, and not typically
803 * visible to the user as media.
804 * <p>
805 * External storage devices returned here are considered a permanent part of
806 * the device, including both emulated external storage and physical media
807 * slots. This does not include transient devices, such as USB flash drives.
808 * <p>
Chet Haasee8222dd2013-09-05 07:44:18 -0700809 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700810 * permissions are required for the owning application to read or write to
811 * these paths.
812 * <p>
813 * The returned paths include any path that would be returned by
814 * {@link #getExternalCacheDir()}.
815 *
816 * @see #getExternalCacheDir()
817 */
818 public abstract File[] getExternalCacheDirs();
819
820 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 * Returns an array of strings naming the private files associated with
822 * this Context's application package.
823 *
824 * @return Array of strings naming the private files.
825 *
826 * @see #openFileInput
827 * @see #openFileOutput
828 * @see #deleteFile
829 */
830 public abstract String[] fileList();
831
832 /**
833 * Retrieve, creating if needed, a new directory in which the application
834 * can place its own custom data files. You can use the returned File
835 * object to create and access files in this directory. Note that files
836 * created through a File object will only be accessible by your own
837 * application; you can only set the mode of the entire directory, not
838 * of individual files.
839 *
Nick Kralevich92091fa2012-12-12 16:24:31 -0800840 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -0800841 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -0800842 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800843 * default operation, {@link #MODE_WORLD_READABLE} and
844 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
845 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400846 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -0800847 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 *
849 * @see #openFileOutput(String, int)
850 */
851 public abstract File getDir(String name, int mode);
852
853 /**
854 * Open a new private SQLiteDatabase associated with this Context's
855 * application package. Create the database file if it doesn't exist.
856 *
857 * @param name The name (unique in the application package) of the database.
858 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
859 * default operation, {@link #MODE_WORLD_READABLE}
860 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700861 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 * @param factory An optional factory class that is called to instantiate a
863 * cursor when query is called.
Nick Kralevich15069212013-01-09 15:54:56 -0800864 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 * @return The contents of a newly created database with the given name.
866 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -0800867 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 * @see #MODE_PRIVATE
869 * @see #MODE_WORLD_READABLE
870 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700871 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 * @see #deleteDatabase
873 */
874 public abstract SQLiteDatabase openOrCreateDatabase(String name,
875 int mode, CursorFactory factory);
876
877 /**
Vasu Nori74f170f2010-06-01 18:06:18 -0700878 * Open a new private SQLiteDatabase associated with this Context's
879 * application package. Creates the database file if it doesn't exist.
880 *
881 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
882 * used to handle corruption when sqlite reports database corruption.</p>
883 *
884 * @param name The name (unique in the application package) of the database.
885 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
886 * default operation, {@link #MODE_WORLD_READABLE}
887 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -0700888 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -0700889 * @param factory An optional factory class that is called to instantiate a
890 * cursor when query is called.
891 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Nick Kralevich15069212013-01-09 15:54:56 -0800892 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -0700893 * @return The contents of a newly created database with the given name.
894 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -0800895 *
Vasu Nori74f170f2010-06-01 18:06:18 -0700896 * @see #MODE_PRIVATE
897 * @see #MODE_WORLD_READABLE
898 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -0700899 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -0700900 * @see #deleteDatabase
901 */
902 public abstract SQLiteDatabase openOrCreateDatabase(String name,
903 int mode, CursorFactory factory, DatabaseErrorHandler errorHandler);
904
905 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 * Delete an existing private SQLiteDatabase associated with this Context's
907 * application package.
908 *
909 * @param name The name (unique in the application package) of the
910 * database.
911 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400912 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 *
914 * @see #openOrCreateDatabase
915 */
916 public abstract boolean deleteDatabase(String name);
917
918 /**
919 * Returns the absolute path on the filesystem where a database created with
920 * {@link #openOrCreateDatabase} is stored.
921 *
922 * @param name The name of the database for which you would like to get
923 * its path.
924 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400925 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 *
927 * @see #openOrCreateDatabase
928 */
929 public abstract File getDatabasePath(String name);
930
931 /**
932 * Returns an array of strings naming the private databases associated with
933 * this Context's application package.
934 *
935 * @return Array of strings naming the private databases.
936 *
937 * @see #openOrCreateDatabase
938 * @see #deleteDatabase
939 */
940 public abstract String[] databaseList();
941
942 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700943 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700944 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800945 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700946 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800947 public abstract Drawable getWallpaper();
948
949 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700950 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700951 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700953 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 public abstract Drawable peekWallpaper();
955
956 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700957 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
958 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700960 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 public abstract int getWallpaperDesiredMinimumWidth();
962
963 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700964 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
965 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700967 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 public abstract int getWallpaperDesiredMinimumHeight();
969
970 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700971 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700972 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700973 * <p>This method requires the caller to hold the permission
974 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700976 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
978
979 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -0700980 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700981 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700982 * <p>This method requires the caller to hold the permission
983 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700985 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800986 public abstract void setWallpaper(InputStream data) throws IOException;
987
988 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -0700989 * @deprecated Use {@link android.app.WallpaperManager#clear
990 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -0700991 * <p>This method requires the caller to hold the permission
992 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800993 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700994 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 public abstract void clearWallpaper() throws IOException;
996
997 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -0700998 * Same as {@link #startActivity(Intent, Bundle)} with no options
999 * specified.
1000 *
1001 * @param intent The description of the activity to start.
1002 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001003 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001004 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001005 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001006 * @see PackageManager#resolveActivity
1007 */
1008 public abstract void startActivity(Intent intent);
1009
1010 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001011 * Version of {@link #startActivity(Intent)} that allows you to specify the
1012 * user the activity will be started for. This is not available to applications
1013 * that are not pre-installed on the system image. Using it requires holding
1014 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001015 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001016 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001017 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001018 * @hide
1019 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001020 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001021 throw new RuntimeException("Not implemented. Must override in a subclass.");
1022 }
1023
1024 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001025 * Launch a new activity. You will not receive any information about when
1026 * the activity exits.
1027 *
1028 * <p>Note that if this method is being called from outside of an
1029 * {@link android.app.Activity} Context, then the Intent must include
1030 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1031 * without being started from an existing Activity, there is no existing
1032 * task in which to place the new activity and thus it needs to be placed
1033 * in its own separate task.
1034 *
1035 * <p>This method throws {@link ActivityNotFoundException}
1036 * if there was no Activity found to run the given Intent.
1037 *
1038 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001039 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001040 * May be null if there are no options. See {@link android.app.ActivityOptions}
1041 * for how to build the Bundle supplied here; there are no supported definitions
1042 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001043 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001044 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 *
Scott Main60dd5202012-06-23 00:01:22 -07001046 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 * @see PackageManager#resolveActivity
1048 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001049 public abstract void startActivity(Intent intent, Bundle options);
1050
1051 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001052 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1053 * user the activity will be started for. This is not available to applications
1054 * that are not pre-installed on the system image. Using it requires holding
1055 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001056 * @param intent The description of the activity to start.
1057 * @param options Additional options for how the Activity should be started.
1058 * May be null if there are no options. See {@link android.app.ActivityOptions}
1059 * for how to build the Bundle supplied here; there are no supported definitions
1060 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001061 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001062 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001063 * @hide
1064 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001065 public void startActivityAsUser(Intent intent, Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001066 throw new RuntimeException("Not implemented. Must override in a subclass.");
1067 }
1068
1069 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001070 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1071 * specified.
1072 *
1073 * @param intents An array of Intents to be started.
1074 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001075 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001076 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001077 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001078 * @see PackageManager#resolveActivity
1079 */
1080 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001081
1082 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001083 * Launch multiple new activities. This is generally the same as calling
1084 * {@link #startActivity(Intent)} for the first Intent in the array,
1085 * that activity during its creation calling {@link #startActivity(Intent)}
1086 * for the second entry, etc. Note that unlike that approach, generally
1087 * none of the activities except the last in the array will be created
1088 * at this point, but rather will be created when the user first visits
1089 * them (due to pressing back from the activity on top).
1090 *
1091 * <p>This method throws {@link ActivityNotFoundException}
1092 * if there was no Activity found for <em>any</em> given Intent. In this
1093 * case the state of the activity stack is undefined (some Intents in the
1094 * list may be on it, some not), so you probably want to avoid such situations.
1095 *
1096 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001097 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001098 * See {@link android.content.Context#startActivity(Intent, Bundle)
1099 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001100 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001101 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001102 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001103 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001104 * @see PackageManager#resolveActivity
1105 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001106 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001107
1108 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001109 * @hide
1110 * Launch multiple new activities. This is generally the same as calling
1111 * {@link #startActivity(Intent)} for the first Intent in the array,
1112 * that activity during its creation calling {@link #startActivity(Intent)}
1113 * for the second entry, etc. Note that unlike that approach, generally
1114 * none of the activities except the last in the array will be created
1115 * at this point, but rather will be created when the user first visits
1116 * them (due to pressing back from the activity on top).
1117 *
1118 * <p>This method throws {@link ActivityNotFoundException}
1119 * if there was no Activity found for <em>any</em> given Intent. In this
1120 * case the state of the activity stack is undefined (some Intents in the
1121 * list may be on it, some not), so you probably want to avoid such situations.
1122 *
1123 * @param intents An array of Intents to be started.
1124 * @param options Additional options for how the Activity should be started.
1125 * @param userHandle The user for whom to launch the activities
1126 * See {@link android.content.Context#startActivity(Intent, Bundle)
1127 * Context.startActivity(Intent, Bundle)} for more details.
1128 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001129 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001130 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001131 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001132 * @see PackageManager#resolveActivity
1133 */
1134 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1135 throw new RuntimeException("Not implemented. Must override in a subclass.");
1136 }
1137
1138 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001139 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1140 * with no options specified.
1141 *
1142 * @param intent The IntentSender to launch.
1143 * @param fillInIntent If non-null, this will be provided as the
1144 * intent parameter to {@link IntentSender#sendIntent}.
1145 * @param flagsMask Intent flags in the original IntentSender that you
1146 * would like to change.
1147 * @param flagsValues Desired values for any bits set in
1148 * <var>flagsMask</var>
1149 * @param extraFlags Always set to 0.
1150 *
1151 * @see #startActivity(Intent)
1152 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1153 */
1154 public abstract void startIntentSender(IntentSender intent,
1155 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1156 throws IntentSender.SendIntentException;
1157
1158 /**
1159 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001160 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001161 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001162 * here; otherwise, its associated action will be executed (such as
1163 * sending a broadcast) as if you had called
1164 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001165 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001166 * @param intent The IntentSender to launch.
1167 * @param fillInIntent If non-null, this will be provided as the
1168 * intent parameter to {@link IntentSender#sendIntent}.
1169 * @param flagsMask Intent flags in the original IntentSender that you
1170 * would like to change.
1171 * @param flagsValues Desired values for any bits set in
1172 * <var>flagsMask</var>
1173 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001174 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001175 * See {@link android.content.Context#startActivity(Intent, Bundle)
1176 * Context.startActivity(Intent, Bundle)} for more details. If options
1177 * have also been supplied by the IntentSender, options given here will
1178 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001179 *
1180 * @see #startActivity(Intent, Bundle)
1181 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001182 */
1183 public abstract void startIntentSender(IntentSender intent,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001184 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
1185 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001186
1187 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 * Broadcast the given intent to all interested BroadcastReceivers. This
1189 * call is asynchronous; it returns immediately, and you will continue
1190 * executing while the receivers are run. No results are propagated from
1191 * receivers and receivers can not abort the broadcast. If you want
1192 * to allow receivers to propagate results or abort the broadcast, you must
1193 * send an ordered broadcast using
1194 * {@link #sendOrderedBroadcast(Intent, String)}.
1195 *
1196 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1197 *
1198 * @param intent The Intent to broadcast; all receivers matching this
1199 * Intent will receive the broadcast.
1200 *
1201 * @see android.content.BroadcastReceiver
1202 * @see #registerReceiver
1203 * @see #sendBroadcast(Intent, String)
1204 * @see #sendOrderedBroadcast(Intent, String)
1205 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1206 */
1207 public abstract void sendBroadcast(Intent intent);
1208
1209 /**
1210 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1211 * an optional required permission to be enforced. This
1212 * call is asynchronous; it returns immediately, and you will continue
1213 * executing while the receivers are run. No results are propagated from
1214 * receivers and receivers can not abort the broadcast. If you want
1215 * to allow receivers to propagate results or abort the broadcast, you must
1216 * send an ordered broadcast using
1217 * {@link #sendOrderedBroadcast(Intent, String)}.
1218 *
1219 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1220 *
1221 * @param intent The Intent to broadcast; all receivers matching this
1222 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001223 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 * a receiver must hold in order to receive your broadcast.
1225 * If null, no permission is required.
1226 *
1227 * @see android.content.BroadcastReceiver
1228 * @see #registerReceiver
1229 * @see #sendBroadcast(Intent)
1230 * @see #sendOrderedBroadcast(Intent, String)
1231 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1232 */
1233 public abstract void sendBroadcast(Intent intent,
1234 String receiverPermission);
1235
1236 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001237 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
1238 * of an assocated app op as per {@link android.app.AppOpsManager}.
1239 * @hide
1240 */
1241 public abstract void sendBroadcast(Intent intent,
1242 String receiverPermission, int appOp);
1243
1244 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001245 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1246 * them one at a time to allow more preferred receivers to consume the
1247 * broadcast before it is delivered to less preferred receivers. This
1248 * call is asynchronous; it returns immediately, and you will continue
1249 * executing while the receivers are run.
1250 *
1251 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1252 *
1253 * @param intent The Intent to broadcast; all receivers matching this
1254 * Intent will receive the broadcast.
1255 * @param receiverPermission (optional) String naming a permissions that
1256 * a receiver must hold in order to receive your broadcast.
1257 * If null, no permission is required.
1258 *
1259 * @see android.content.BroadcastReceiver
1260 * @see #registerReceiver
1261 * @see #sendBroadcast(Intent)
1262 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1263 */
1264 public abstract void sendOrderedBroadcast(Intent intent,
1265 String receiverPermission);
1266
1267 /**
1268 * Version of {@link #sendBroadcast(Intent)} that allows you to
1269 * receive data back from the broadcast. This is accomplished by
1270 * supplying your own BroadcastReceiver when calling, which will be
1271 * treated as a final receiver at the end of the broadcast -- its
1272 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001273 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 * be serialized in the same way as calling
1275 * {@link #sendOrderedBroadcast(Intent, String)}.
1276 *
1277 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1278 * asynchronous; it will return before
1279 * resultReceiver.onReceive() is called.
1280 *
1281 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1282 *
1283 * @param intent The Intent to broadcast; all receivers matching this
1284 * Intent will receive the broadcast.
1285 * @param receiverPermission String naming a permissions that
1286 * a receiver must hold in order to receive your broadcast.
1287 * If null, no permission is required.
1288 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1289 * receiver of the broadcast.
1290 * @param scheduler A custom Handler with which to schedule the
1291 * resultReceiver callback; if null it will be
1292 * scheduled in the Context's main thread.
1293 * @param initialCode An initial value for the result code. Often
1294 * Activity.RESULT_OK.
1295 * @param initialData An initial value for the result data. Often
1296 * null.
1297 * @param initialExtras An initial value for the result extras. Often
1298 * null.
1299 *
1300 * @see #sendBroadcast(Intent)
1301 * @see #sendBroadcast(Intent, String)
1302 * @see #sendOrderedBroadcast(Intent, String)
1303 * @see #sendStickyBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001304 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 * @see android.content.BroadcastReceiver
1306 * @see #registerReceiver
1307 * @see android.app.Activity#RESULT_OK
1308 */
1309 public abstract void sendOrderedBroadcast(Intent intent,
1310 String receiverPermission, BroadcastReceiver resultReceiver,
1311 Handler scheduler, int initialCode, String initialData,
1312 Bundle initialExtras);
1313
1314 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001315 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1316 * int, String, android.os.Bundle)}, but also allows specification
1317 * of an assocated app op as per {@link android.app.AppOpsManager}.
1318 * @hide
1319 */
1320 public abstract void sendOrderedBroadcast(Intent intent,
1321 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1322 Handler scheduler, int initialCode, String initialData,
1323 Bundle initialExtras);
1324
1325 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001326 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1327 * user the broadcast will be sent to. This is not available to applications
1328 * that are not pre-installed on the system image. Using it requires holding
1329 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001330 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001331 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001332 * @see #sendBroadcast(Intent)
1333 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001334 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001335
1336 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001337 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1338 * user the broadcast will be sent to. This is not available to applications
1339 * that are not pre-installed on the system image. Using it requires holding
1340 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001341 *
1342 * @param intent The Intent to broadcast; all receivers matching this
1343 * Intent will receive the broadcast.
1344 * @param user UserHandle to send the intent to.
1345 * @param receiverPermission (optional) String naming a permission that
1346 * a receiver must hold in order to receive your broadcast.
1347 * If null, no permission is required.
1348 *
1349 * @see #sendBroadcast(Intent, String)
1350 */
1351 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1352 String receiverPermission);
1353
1354 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001355 * Version of
1356 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1357 * that allows you to specify the
1358 * user the broadcast will be sent to. This is not available to applications
1359 * that are not pre-installed on the system image. Using it requires holding
1360 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001361 *
1362 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1363 *
1364 * @param intent The Intent to broadcast; all receivers matching this
1365 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001366 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001367 * @param receiverPermission String naming a permissions that
1368 * a receiver must hold in order to receive your broadcast.
1369 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001370 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1371 * receiver of the broadcast.
1372 * @param scheduler A custom Handler with which to schedule the
1373 * resultReceiver callback; if null it will be
1374 * scheduled in the Context's main thread.
1375 * @param initialCode An initial value for the result code. Often
1376 * Activity.RESULT_OK.
1377 * @param initialData An initial value for the result data. Often
1378 * null.
1379 * @param initialExtras An initial value for the result extras. Often
1380 * null.
1381 *
1382 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1383 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001384 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001385 String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler,
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001386 int initialCode, String initialData, Bundle initialExtras);
1387
1388 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 * Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
1390 * Intent you are sending stays around after the broadcast is complete,
1391 * so that others can quickly retrieve that data through the return
1392 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1393 * all other ways, this behaves the same as
1394 * {@link #sendBroadcast(Intent)}.
1395 *
1396 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1397 * permission in order to use this API. If you do not hold that
1398 * permission, {@link SecurityException} will be thrown.
1399 *
1400 * @param intent The Intent to broadcast; all receivers matching this
1401 * Intent will receive the broadcast, and the Intent will be held to
1402 * be re-broadcast to future receivers.
1403 *
1404 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001405 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001406 */
1407 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001408
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001409 /**
1410 * Version of {@link #sendStickyBroadcast} that allows you to
1411 * receive data back from the broadcast. This is accomplished by
1412 * supplying your own BroadcastReceiver when calling, which will be
1413 * treated as a final receiver at the end of the broadcast -- its
1414 * {@link BroadcastReceiver#onReceive} method will be called with
1415 * the result values collected from the other receivers. The broadcast will
1416 * be serialized in the same way as calling
1417 * {@link #sendOrderedBroadcast(Intent, String)}.
1418 *
1419 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1420 * asynchronous; it will return before
1421 * resultReceiver.onReceive() is called. Note that the sticky data
1422 * stored is only the data you initially supply to the broadcast, not
1423 * the result of any changes made by the receivers.
1424 *
1425 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1426 *
1427 * @param intent The Intent to broadcast; all receivers matching this
1428 * Intent will receive the broadcast.
1429 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1430 * receiver of the broadcast.
1431 * @param scheduler A custom Handler with which to schedule the
1432 * resultReceiver callback; if null it will be
1433 * scheduled in the Context's main thread.
1434 * @param initialCode An initial value for the result code. Often
1435 * Activity.RESULT_OK.
1436 * @param initialData An initial value for the result data. Often
1437 * null.
1438 * @param initialExtras An initial value for the result extras. Often
1439 * null.
1440 *
1441 * @see #sendBroadcast(Intent)
1442 * @see #sendBroadcast(Intent, String)
1443 * @see #sendOrderedBroadcast(Intent, String)
1444 * @see #sendStickyBroadcast(Intent)
1445 * @see android.content.BroadcastReceiver
1446 * @see #registerReceiver
1447 * @see android.app.Activity#RESULT_OK
1448 */
1449 public abstract void sendStickyOrderedBroadcast(Intent intent,
1450 BroadcastReceiver resultReceiver,
1451 Handler scheduler, int initialCode, String initialData,
1452 Bundle initialExtras);
1453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 /**
1455 * Remove the data previously sent with {@link #sendStickyBroadcast},
1456 * so that it is as if the sticky broadcast had never happened.
1457 *
1458 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1459 * permission in order to use this API. If you do not hold that
1460 * permission, {@link SecurityException} will be thrown.
1461 *
1462 * @param intent The Intent that was previously broadcast.
1463 *
1464 * @see #sendStickyBroadcast
1465 */
1466 public abstract void removeStickyBroadcast(Intent intent);
1467
1468 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001469 * Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
1470 * user the broadcast will be sent to. This is not available to applications
1471 * that are not pre-installed on the system image. Using it requires holding
1472 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001473 *
1474 * @param intent The Intent to broadcast; all receivers matching this
1475 * Intent will receive the broadcast, and the Intent will be held to
1476 * be re-broadcast to future receivers.
1477 * @param user UserHandle to send the intent to.
1478 *
1479 * @see #sendBroadcast(Intent)
1480 */
1481 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1482
1483 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001484 * Version of
1485 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1486 * that allows you to specify the
1487 * user the broadcast will be sent to. This is not available to applications
1488 * that are not pre-installed on the system image. Using it requires holding
1489 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001490 *
1491 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1492 *
1493 * @param intent The Intent to broadcast; all receivers matching this
1494 * Intent will receive the broadcast.
1495 * @param user UserHandle to send the intent to.
1496 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1497 * receiver of the broadcast.
1498 * @param scheduler A custom Handler with which to schedule the
1499 * resultReceiver callback; if null it will be
1500 * scheduled in the Context's main thread.
1501 * @param initialCode An initial value for the result code. Often
1502 * Activity.RESULT_OK.
1503 * @param initialData An initial value for the result data. Often
1504 * null.
1505 * @param initialExtras An initial value for the result extras. Often
1506 * null.
1507 *
1508 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1509 */
1510 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1511 UserHandle user, BroadcastReceiver resultReceiver,
1512 Handler scheduler, int initialCode, String initialData,
1513 Bundle initialExtras);
1514
1515 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001516 * Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
1517 * user the broadcast will be sent to. This is not available to applications
1518 * that are not pre-installed on the system image. Using it requires holding
1519 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001520 *
1521 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1522 * permission in order to use this API. If you do not hold that
1523 * permission, {@link SecurityException} will be thrown.
1524 *
1525 * @param intent The Intent that was previously broadcast.
1526 * @param user UserHandle to remove the sticky broadcast from.
1527 *
1528 * @see #sendStickyBroadcastAsUser
1529 */
1530 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1531
1532 /**
Chris Tatea34df8a2009-04-02 23:15:58 -07001533 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001534 * <var>receiver</var> will be called with any broadcast Intent that
1535 * matches <var>filter</var>, in the main application thread.
1536 *
1537 * <p>The system may broadcast Intents that are "sticky" -- these stay
1538 * around after the broadcast as finished, to be sent to any later
1539 * registrations. If your IntentFilter matches one of these sticky
1540 * Intents, that Intent will be returned by this function
1541 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1542 * been broadcast.
1543 *
1544 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1545 * in which case each of these will be sent to <var>receiver</var>. In
1546 * this case, only one of these can be returned directly by the function;
1547 * which of these that is returned is arbitrarily decided by the system.
1548 *
1549 * <p>If you know the Intent your are registering for is sticky, you can
1550 * supply null for your <var>receiver</var>. In this case, no receiver is
1551 * registered -- the function simply returns the sticky Intent that
1552 * matches <var>filter</var>. In the case of multiple matches, the same
1553 * rules as described above apply.
1554 *
1555 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1556 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001557 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1558 * registered with this method will correctly respect the
1559 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1560 * Prior to that, it would be ignored and delivered to all matching registered
1561 * receivers. Be careful if using this for security.</p>
1562 *
Chris Tatea34df8a2009-04-02 23:15:58 -07001563 * <p class="note">Note: this method <em>cannot be called from a
1564 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1565 * that is declared in an application's manifest. It is okay, however, to call
1566 * this method from another BroadcastReceiver that has itself been registered
1567 * at run time with {@link #registerReceiver}, since the lifetime of such a
1568 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 *
1570 * @param receiver The BroadcastReceiver to handle the broadcast.
1571 * @param filter Selects the Intent broadcasts to be received.
1572 *
1573 * @return The first sticky intent found that matches <var>filter</var>,
1574 * or null if there are none.
1575 *
1576 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1577 * @see #sendBroadcast
1578 * @see #unregisterReceiver
1579 */
1580 public abstract Intent registerReceiver(BroadcastReceiver receiver,
1581 IntentFilter filter);
1582
1583 /**
1584 * Register to receive intent broadcasts, to run in the context of
1585 * <var>scheduler</var>. See
1586 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1587 * information. This allows you to enforce permissions on who can
1588 * broadcast intents to your receiver, or have the receiver run in
1589 * a different thread than the main application thread.
1590 *
1591 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1592 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001593 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1594 * registered with this method will correctly respect the
1595 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1596 * Prior to that, it would be ignored and delivered to all matching registered
1597 * receivers. Be careful if using this for security.</p>
1598 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 * @param receiver The BroadcastReceiver to handle the broadcast.
1600 * @param filter Selects the Intent broadcasts to be received.
1601 * @param broadcastPermission String naming a permissions that a
1602 * broadcaster must hold in order to send an Intent to you. If null,
1603 * no permission is required.
1604 * @param scheduler Handler identifying the thread that will receive
1605 * the Intent. If null, the main thread of the process will be used.
1606 *
1607 * @return The first sticky intent found that matches <var>filter</var>,
1608 * or null if there are none.
1609 *
1610 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1611 * @see #sendBroadcast
1612 * @see #unregisterReceiver
1613 */
1614 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Dianne Hackborn20e80982012-08-31 19:00:44 -07001615 IntentFilter filter, String broadcastPermission, Handler scheduler);
1616
1617 /**
1618 * @hide
1619 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1620 * but for a specific user. This receiver will receiver broadcasts that
1621 * are sent to the requested user. It
1622 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1623 * permission.
1624 *
1625 * @param receiver The BroadcastReceiver to handle the broadcast.
1626 * @param user UserHandle to send the intent to.
1627 * @param filter Selects the Intent broadcasts to be received.
1628 * @param broadcastPermission String naming a permissions that a
1629 * broadcaster must hold in order to send an Intent to you. If null,
1630 * no permission is required.
1631 * @param scheduler Handler identifying the thread that will receive
1632 * the Intent. If null, the main thread of the process will be used.
1633 *
1634 * @return The first sticky intent found that matches <var>filter</var>,
1635 * or null if there are none.
1636 *
1637 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler
1638 * @see #sendBroadcast
1639 * @see #unregisterReceiver
1640 */
1641 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
1642 UserHandle user, IntentFilter filter, String broadcastPermission,
1643 Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001644
1645 /**
1646 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1647 * filters that have been registered for this BroadcastReceiver will be
1648 * removed.
1649 *
1650 * @param receiver The BroadcastReceiver to unregister.
1651 *
1652 * @see #registerReceiver
1653 */
1654 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1655
1656 /**
1657 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07001658 * should contain either contain the complete class name of a specific service
1659 * implementation to start or a specific package name to target. If the
1660 * Intent is less specified, it will either throw an {@link IllegalArgumentException}
Chet Haasee8222dd2013-09-05 07:44:18 -07001661 * (if the caller targets {@link android.os.Build.VERSION_CODES#KITKAT} or later),
Dianne Hackborn221ea892013-08-04 16:50:16 -07001662 * or which of multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 * is not already running, it will be instantiated and started (creating a
1664 * process for it if needed); if it is running then it remains running.
1665 *
1666 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001667 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 * with the <var>intent</var> given here. This provides a convenient way
1669 * to submit jobs to a service without having to bind and call on to its
1670 * interface.
1671 *
1672 * <p>Using startService() overrides the default service lifetime that is
1673 * managed by {@link #bindService}: it requires the service to remain
1674 * running until {@link #stopService} is called, regardless of whether
1675 * any clients are connected to it. Note that calls to startService()
1676 * are not nesting: no matter how many times you call startService(),
1677 * a single call to {@link #stopService} will stop it.
1678 *
1679 * <p>The system attempts to keep running services around as much as
1680 * possible. The only time they should be stopped is if the current
1681 * foreground application is using so many resources that the service needs
1682 * to be killed. If any errors happen in the service's process, it will
1683 * automatically be restarted.
1684 *
1685 * <p>This function will throw {@link SecurityException} if you do not
1686 * have permission to start the given service.
1687 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07001688 * @param service Identifies the service to be started. The Intent must be either
1689 * fully explicit (supplying a component name) or specify a specific package
1690 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001691 * may be included in the Intent extras to supply arguments along with
1692 * this specific start call.
1693 *
1694 * @return If the service is being started or is already running, the
1695 * {@link ComponentName} of the actual service that was started is
1696 * returned; else if the service does not exist null is returned.
1697 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001698 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 *
1700 * @see #stopService
1701 * @see #bindService
1702 */
1703 public abstract ComponentName startService(Intent service);
1704
1705 /**
1706 * Request that a given application service be stopped. If the service is
1707 * not running, nothing happens. Otherwise it is stopped. Note that calls
1708 * to startService() are not counted -- this stops the service no matter
1709 * how many times it was started.
1710 *
1711 * <p>Note that if a stopped service still has {@link ServiceConnection}
1712 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1713 * not be destroyed until all of these bindings are removed. See
1714 * the {@link android.app.Service} documentation for more details on a
1715 * service's lifecycle.
1716 *
1717 * <p>This function will throw {@link SecurityException} if you do not
1718 * have permission to stop the given service.
1719 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07001720 * @param service Description of the service to be stopped. The Intent must be either
1721 * fully explicit (supplying a component name) or specify a specific package
1722 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 *
1724 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04001725 * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001727 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 *
1729 * @see #startService
1730 */
1731 public abstract boolean stopService(Intent service);
1732
1733 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07001734 * @hide like {@link #startService(Intent)} but for a specific user.
1735 */
1736 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
1737
1738 /**
1739 * @hide like {@link #stopService(Intent)} but for a specific user.
1740 */
1741 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
1742
1743 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001744 * Connect to an application service, creating it if needed. This defines
1745 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001746 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001747 * told if it dies and restarts. The service will be considered required
1748 * by the system only for as long as the calling context exists. For
1749 * example, if this Context is an Activity that is stopped, the service will
1750 * not be required to continue running until the Activity is resumed.
1751 *
1752 * <p>This function will throw {@link SecurityException} if you do not
1753 * have permission to bind to the given service.
1754 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001755 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001757 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 * {@link #startService} with the arguments containing the command to be
1759 * sent, with the service calling its
1760 * {@link android.app.Service#stopSelf(int)} method when done executing
1761 * that command. See the API demo App/Service/Service Start Arguments
1762 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09001763 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
1765 * is tied to another object (the one that registered it).</p>
1766 *
1767 * @param service Identifies the service to connect to. The Intent may
1768 * specify either an explicit component name, or a logical
1769 * description (action, category, etc) to match an
1770 * {@link IntentFilter} published by a service.
1771 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07001772 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07001773 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07001774 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
1775 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
1776 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
1777 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04001778 * @return If you have successfully bound to the service, {@code true} is returned;
1779 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001780 * receive the service object.
1781 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001782 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001783 *
1784 * @see #unbindService
1785 * @see #startService
1786 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07001787 * @see #BIND_DEBUG_UNBIND
1788 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789 */
1790 public abstract boolean bindService(Intent service, ServiceConnection conn,
1791 int flags);
1792
1793 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001794 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001795 * argument for use by system server and other multi-user aware code.
1796 * @hide
1797 */
Amith Yamasani27b89e62013-01-16 12:30:11 -08001798 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08001799 throw new RuntimeException("Not implemented. Must override in a subclass.");
1800 }
1801
1802 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 * Disconnect from an application service. You will no longer receive
1804 * calls as the service is restarted, and the service is now allowed to
1805 * stop at any time.
1806 *
1807 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07001808 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 *
1810 * @see #bindService
1811 */
1812 public abstract void unbindService(ServiceConnection conn);
1813
1814 /**
1815 * Start executing an {@link android.app.Instrumentation} class. The given
1816 * Instrumentation component will be run by killing its target application
1817 * (if currently running), starting the target process, instantiating the
1818 * instrumentation component, and then letting it drive the application.
1819 *
1820 * <p>This function is not synchronous -- it returns as soon as the
1821 * instrumentation has started and while it is running.
1822 *
1823 * <p>Instrumentation is normally only allowed to run against a package
1824 * that is either unsigned or signed with a signature that the
1825 * the instrumentation package is also signed with (ensuring the target
1826 * trusts the instrumentation).
1827 *
1828 * @param className Name of the Instrumentation component to be run.
1829 * @param profileFile Optional path to write profiling data as the
1830 * instrumentation runs, or null for no profiling.
1831 * @param arguments Additional optional arguments to pass to the
1832 * instrumentation, or null.
1833 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001834 * @return {@code true} if the instrumentation was successfully started,
1835 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 */
1837 public abstract boolean startInstrumentation(ComponentName className,
1838 String profileFile, Bundle arguments);
1839
1840 /**
1841 * Return the handle to a system-level service by name. The class of the
1842 * returned object varies by the requested name. Currently available names
1843 * are:
Scott Main4b5da682010-10-21 11:49:12 -07001844 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 * <dl>
1846 * <dt> {@link #WINDOW_SERVICE} ("window")
1847 * <dd> The top-level window manager in which you can place custom
1848 * windows. The returned object is a {@link android.view.WindowManager}.
1849 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
1850 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
1851 * in this context.
1852 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
1853 * <dd> A {@link android.app.ActivityManager} for interacting with the
1854 * global activity state of the system.
1855 * <dt> {@link #POWER_SERVICE} ("power")
1856 * <dd> A {@link android.os.PowerManager} for controlling power
1857 * management.
1858 * <dt> {@link #ALARM_SERVICE} ("alarm")
1859 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
1860 * time of your choosing.
1861 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
1862 * <dd> A {@link android.app.NotificationManager} for informing the user
1863 * of background events.
1864 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
1865 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
1866 * <dt> {@link #LOCATION_SERVICE} ("location")
1867 * <dd> A {@link android.location.LocationManager} for controlling location
1868 * (e.g., GPS) updates.
1869 * <dt> {@link #SEARCH_SERVICE} ("search")
1870 * <dd> A {@link android.app.SearchManager} for handling search.
1871 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
1872 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
1873 * hardware.
1874 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
1875 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
1876 * handling management of network connections.
1877 * <dt> {@link #WIFI_SERVICE} ("wifi")
1878 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
1879 * Wi-Fi connectivity.
1880 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
1881 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
1882 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08001883 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
1884 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07001885 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07001886 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07001888 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001889 * <p>Note: System services obtained via this API may be closely associated with
1890 * the Context in which they are obtained from. In general, do not share the
1891 * service objects between various different contexts (Activities, Applications,
1892 * Services, Providers, etc.)
1893 *
1894 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07001895 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07001897 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 * @see #WINDOW_SERVICE
1899 * @see android.view.WindowManager
1900 * @see #LAYOUT_INFLATER_SERVICE
1901 * @see android.view.LayoutInflater
1902 * @see #ACTIVITY_SERVICE
1903 * @see android.app.ActivityManager
1904 * @see #POWER_SERVICE
1905 * @see android.os.PowerManager
1906 * @see #ALARM_SERVICE
1907 * @see android.app.AlarmManager
1908 * @see #NOTIFICATION_SERVICE
1909 * @see android.app.NotificationManager
1910 * @see #KEYGUARD_SERVICE
1911 * @see android.app.KeyguardManager
1912 * @see #LOCATION_SERVICE
1913 * @see android.location.LocationManager
1914 * @see #SEARCH_SERVICE
1915 * @see android.app.SearchManager
1916 * @see #SENSOR_SERVICE
1917 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08001918 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08001919 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 * @see #VIBRATOR_SERVICE
1921 * @see android.os.Vibrator
1922 * @see #CONNECTIVITY_SERVICE
1923 * @see android.net.ConnectivityManager
1924 * @see #WIFI_SERVICE
1925 * @see android.net.wifi.WifiManager
1926 * @see #AUDIO_SERVICE
1927 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07001928 * @see #MEDIA_ROUTER_SERVICE
1929 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 * @see #TELEPHONY_SERVICE
1931 * @see android.telephony.TelephonyManager
1932 * @see #INPUT_METHOD_SERVICE
1933 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08001934 * @see #UI_MODE_SERVICE
1935 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07001936 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07001937 * @see android.app.DownloadManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 */
1939 public abstract Object getSystemService(String name);
1940
1941 /**
1942 * Use with {@link #getSystemService} to retrieve a
1943 * {@link android.os.PowerManager} for controlling power management,
1944 * including "wake locks," which let you keep the device on while
1945 * you're running long tasks.
1946 */
1947 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07001948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 /**
1950 * Use with {@link #getSystemService} to retrieve a
1951 * {@link android.view.WindowManager} for accessing the system's window
1952 * manager.
1953 *
1954 * @see #getSystemService
1955 * @see android.view.WindowManager
1956 */
1957 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07001958
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959 /**
1960 * Use with {@link #getSystemService} to retrieve a
1961 * {@link android.view.LayoutInflater} for inflating layout resources in this
1962 * context.
1963 *
1964 * @see #getSystemService
1965 * @see android.view.LayoutInflater
1966 */
1967 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07001968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 /**
1970 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07001971 * {@link android.accounts.AccountManager} for receiving intents at a
1972 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07001973 *
1974 * @see #getSystemService
1975 * @see android.accounts.AccountManager
1976 */
1977 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07001978
Fred Quintana60307342009-03-24 22:48:12 -07001979 /**
1980 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 * {@link android.app.ActivityManager} for interacting with the global
1982 * system state.
1983 *
1984 * @see #getSystemService
1985 * @see android.app.ActivityManager
1986 */
1987 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07001988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 /**
1990 * Use with {@link #getSystemService} to retrieve a
1991 * {@link android.app.AlarmManager} for receiving intents at a
1992 * time of your choosing.
1993 *
1994 * @see #getSystemService
1995 * @see android.app.AlarmManager
1996 */
1997 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07001998
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 /**
2000 * Use with {@link #getSystemService} to retrieve a
2001 * {@link android.app.NotificationManager} for informing the user of
2002 * background events.
2003 *
2004 * @see #getSystemService
2005 * @see android.app.NotificationManager
2006 */
2007 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002008
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 /**
2010 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002011 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2012 * feedback for UI events through the registered event listeners.
2013 *
2014 * @see #getSystemService
2015 * @see android.view.accessibility.AccessibilityManager
2016 */
2017 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002018
svetoslavganov75986cf2009-05-14 22:28:01 -07002019 /**
2020 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002021 * {@link android.view.accessibility.CaptioningManager} for obtaining
2022 * captioning properties and listening for changes in captioning
2023 * preferences.
2024 *
2025 * @see #getSystemService
2026 * @see android.view.accessibility.CaptioningManager
2027 */
2028 public static final String CAPTIONING_SERVICE = "captioning";
2029
2030 /**
2031 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 * {@link android.app.NotificationManager} for controlling keyguard.
2033 *
2034 * @see #getSystemService
2035 * @see android.app.KeyguardManager
2036 */
2037 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 /**
2040 * Use with {@link #getSystemService} to retrieve a {@link
2041 * android.location.LocationManager} for controlling location
2042 * updates.
2043 *
2044 * @see #getSystemService
2045 * @see android.location.LocationManager
2046 */
2047 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002048
2049 /**
2050 * Use with {@link #getSystemService} to retrieve a
2051 * {@link android.location.CountryDetector} for detecting the country that
2052 * the user is in.
2053 *
2054 * @hide
2055 */
2056 public static final String COUNTRY_DETECTOR = "country_detector";
2057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002058 /**
2059 * Use with {@link #getSystemService} to retrieve a {@link
2060 * android.app.SearchManager} for handling searches.
2061 *
2062 * @see #getSystemService
2063 * @see android.app.SearchManager
2064 */
2065 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002067 /**
2068 * Use with {@link #getSystemService} to retrieve a {@link
2069 * android.hardware.SensorManager} for accessing sensors.
2070 *
2071 * @see #getSystemService
2072 * @see android.hardware.SensorManager
2073 */
2074 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07002075
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 /**
San Mehatc9d81752010-02-01 10:23:27 -08002077 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07002078 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08002079 * functions.
2080 *
2081 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08002082 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08002083 */
2084 public static final String STORAGE_SERVICE = "storage";
2085
2086 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 * Use with {@link #getSystemService} to retrieve a
2088 * com.android.server.WallpaperService for accessing wallpapers.
2089 *
2090 * @see #getSystemService
2091 */
2092 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07002093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 /**
2095 * Use with {@link #getSystemService} to retrieve a {@link
2096 * android.os.Vibrator} for interacting with the vibration hardware.
2097 *
2098 * @see #getSystemService
2099 * @see android.os.Vibrator
2100 */
2101 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002102
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002103 /**
2104 * Use with {@link #getSystemService} to retrieve a {@link
2105 * android.app.StatusBarManager} for interacting with the status bar.
2106 *
2107 * @see #getSystemService
2108 * @see android.app.StatusBarManager
2109 * @hide
2110 */
2111 public static final String STATUS_BAR_SERVICE = "statusbar";
2112
2113 /**
2114 * Use with {@link #getSystemService} to retrieve a {@link
2115 * android.net.ConnectivityManager} for handling management of
2116 * network connections.
2117 *
2118 * @see #getSystemService
2119 * @see android.net.ConnectivityManager
2120 */
2121 public static final String CONNECTIVITY_SERVICE = "connectivity";
2122
2123 /**
2124 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002125 * android.os.IUpdateLock} for managing runtime sequences that
2126 * must not be interrupted by headless OTA application or similar.
2127 *
2128 * @hide
2129 * @see #getSystemService
2130 * @see android.os.UpdateLock
2131 */
2132 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2133
2134 /**
2135 * Use with {@link #getSystemService} to retrieve a {@link
San Mehatd1df8ac2010-01-26 06:17:26 -08002136 * android.net.NetworkManagementService} for handling management of
2137 * system network services
2138 *
2139 * @hide
2140 * @see #getSystemService
2141 * @see android.net.NetworkManagementService
2142 */
2143 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2144
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002145 /** {@hide} */
Jeff Sharkey75279902011-05-24 18:39:45 -07002146 public static final String NETWORK_STATS_SERVICE = "netstats";
2147 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002148 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2149
San Mehatd1df8ac2010-01-26 06:17:26 -08002150 /**
2151 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002152 * android.net.wifi.WifiManager} for handling management of
2153 * Wi-Fi access.
2154 *
2155 * @see #getSystemService
2156 * @see android.net.wifi.WifiManager
2157 */
2158 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002160 /**
repo sync55bc5f32011-06-24 14:23:07 -07002161 * Use with {@link #getSystemService} to retrieve a {@link
2162 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002163 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002164 *
2165 * @see #getSystemService
2166 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002167 */
2168 public static final String WIFI_P2P_SERVICE = "wifip2p";
2169
2170 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002171 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002172 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002173 * discovery
2174 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002175 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002176 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002177 */
2178 public static final String NSD_SERVICE = "servicediscovery";
2179
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002180 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 * Use with {@link #getSystemService} to retrieve a
2182 * {@link android.media.AudioManager} for handling management of volume,
2183 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002184 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 * @see #getSystemService
2186 * @see android.media.AudioManager
2187 */
2188 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 /**
2191 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002192 * {@link android.media.MediaRouter} for controlling and managing
2193 * routing of media.
2194 *
2195 * @see #getSystemService
2196 * @see android.media.MediaRouter
2197 */
2198 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2199
2200 /**
2201 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 * {@link android.telephony.TelephonyManager} for handling management the
2203 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002204 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002205 * @see #getSystemService
2206 * @see android.telephony.TelephonyManager
2207 */
2208 public static final String TELEPHONY_SERVICE = "phone";
2209
2210 /**
2211 * Use with {@link #getSystemService} to retrieve a
2212 * {@link android.text.ClipboardManager} for accessing and modifying
2213 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002214 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002215 * @see #getSystemService
2216 * @see android.text.ClipboardManager
2217 */
2218 public static final String CLIPBOARD_SERVICE = "clipboard";
2219
2220 /**
Scott Main4b5da682010-10-21 11:49:12 -07002221 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002222 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2223 * methods.
2224 *
2225 * @see #getSystemService
2226 */
2227 public static final String INPUT_METHOD_SERVICE = "input_method";
2228
2229 /**
2230 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002231 * {@link android.view.textservice.TextServicesManager} for accessing
2232 * text services.
2233 *
2234 * @see #getSystemService
2235 */
2236 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2237
2238 /**
2239 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002240 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 *
2242 * @hide
2243 * @see #getSystemService
2244 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002245 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002246
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002248 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002249 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002250 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002251 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002252 *
Christopher Tate487529a2009-04-29 14:03:25 -07002253 * @see #getSystemService
2254 */
2255 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002256
2257 /**
2258 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002259 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002260 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002261 * @see #getSystemService
2262 */
2263 public static final String DROPBOX_SERVICE = "dropbox";
2264
Christopher Tate487529a2009-04-29 14:03:25 -07002265 /**
Scott Main4b5da682010-10-21 11:49:12 -07002266 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002267 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002268 * device policy management.
2269 *
2270 * @see #getSystemService
2271 */
2272 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2273
2274 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002275 * Use with {@link #getSystemService} to retrieve a
2276 * {@link android.app.UiModeManager} for controlling UI modes.
2277 *
2278 * @see #getSystemService
2279 */
2280 public static final String UI_MODE_SERVICE = "uimode";
2281
2282 /**
Steve Howarda2709362010-07-02 17:12:48 -07002283 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002284 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002285 *
2286 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002287 */
2288 public static final String DOWNLOAD_SERVICE = "download";
2289
2290 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002291 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002292 * {@link android.nfc.NfcManager} for using NFC.
2293 *
2294 * @see #getSystemService
2295 */
2296 public static final String NFC_SERVICE = "nfc";
2297
2298 /**
2299 * Use with {@link #getSystemService} to retrieve a
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002300 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2301 *
2302 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002303 */
2304 public static final String BLUETOOTH_SERVICE = "bluetooth";
2305
2306 /**
2307 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002308 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2309 *
2310 * @see #getSystemService
2311 */
2312 /** @hide */
2313 public static final String SIP_SERVICE = "sip";
2314
2315 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002316 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002317 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002318 * and for controlling this device's behavior as a USB device.
2319 *
2320 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04002321 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002322 */
2323 public static final String USB_SERVICE = "usb";
2324
2325 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002326 * Use with {@link #getSystemService} to retrieve a {@link
2327 * android.hardware.SerialManager} for access to serial ports.
2328 *
2329 * @see #getSystemService
2330 * @see android.harware.SerialManager
2331 *
2332 * @hide
2333 */
2334 public static final String SERIAL_SERVICE = "serial";
2335
2336 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002337 * Use with {@link #getSystemService} to retrieve a
2338 * {@link android.hardware.input.InputManager} for interacting with input devices.
2339 *
2340 * @see #getSystemService
2341 * @see android.hardware.input.InputManager
2342 */
2343 public static final String INPUT_SERVICE = "input";
2344
2345 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002346 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002347 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2348 *
2349 * @see #getSystemService
2350 * @see android.hardware.display.DisplayManager
2351 */
2352 public static final String DISPLAY_SERVICE = "display";
2353
2354 /**
2355 * Use with {@link #getSystemService} to retrieve a
Glenn Kasten07b04652012-04-23 15:00:43 -07002356 * {@link android.os.SchedulingPolicyService} for managing scheduling policy.
2357 *
2358 * @see #getSystemService
2359 * @see android.os.SchedulingPolicyService
2360 *
2361 * @hide
2362 */
2363 public static final String SCHEDULING_POLICY_SERVICE = "scheduling_policy";
2364
2365 /**
Amith Yamasani258848d2012-08-10 17:06:33 -07002366 * Use with {@link #getSystemService} to retrieve a
2367 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2368 *
2369 * @see #getSystemService
2370 * @see android.os.UserManager
2371 */
2372 public static final String USER_SERVICE = "user";
2373
2374 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002375 * Use with {@link #getSystemService} to retrieve a
2376 * {@link android.app.AppOpsManager} for tracking application operations
2377 * on the device.
2378 *
2379 * @see #getSystemService
2380 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002381 */
2382 public static final String APP_OPS_SERVICE = "appops";
2383
2384 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002385 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07002386 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002387 * camera devices.
2388 *
2389 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07002390 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002391 */
2392 public static final String CAMERA_SERVICE = "camera";
2393
2394 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002395 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07002396 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002397 *
2398 * @see #getSystemService
2399 * @see android.print.PrintManager
2400 */
2401 public static final String PRINT_SERVICE = "print";
2402
2403 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002404 * Determine whether the given permission is allowed for a particular
2405 * process and user ID running in the system.
2406 *
2407 * @param permission The name of the permission being checked.
2408 * @param pid The process ID being checked against. Must be > 0.
2409 * @param uid The user ID being checked against. A uid of 0 is the root
2410 * user, which will pass every permission check.
2411 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002412 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 * pid/uid is allowed that permission, or
2414 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2415 *
2416 * @see PackageManager#checkPermission(String, String)
2417 * @see #checkCallingPermission
2418 */
2419 public abstract int checkPermission(String permission, int pid, int uid);
2420
2421 /**
2422 * Determine whether the calling process of an IPC you are handling has been
2423 * granted a particular permission. This is basically the same as calling
2424 * {@link #checkPermission(String, int, int)} with the pid and uid returned
2425 * by {@link android.os.Binder#getCallingPid} and
2426 * {@link android.os.Binder#getCallingUid}. One important difference
2427 * is that if you are not currently processing an IPC, this function
2428 * will always fail. This is done to protect against accidentally
2429 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
2430 * to avoid this protection.
2431 *
2432 * @param permission The name of the permission being checked.
2433 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002434 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 * pid/uid is allowed that permission, or
2436 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2437 *
2438 * @see PackageManager#checkPermission(String, String)
2439 * @see #checkPermission
2440 * @see #checkCallingOrSelfPermission
2441 */
2442 public abstract int checkCallingPermission(String permission);
2443
2444 /**
2445 * Determine whether the calling process of an IPC <em>or you</em> have been
2446 * granted a particular permission. This is the same as
2447 * {@link #checkCallingPermission}, except it grants your own permissions
2448 * if you are not currently processing an IPC. Use with care!
2449 *
2450 * @param permission The name of the permission being checked.
2451 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002452 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 * pid/uid is allowed that permission, or
2454 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2455 *
2456 * @see PackageManager#checkPermission(String, String)
2457 * @see #checkPermission
2458 * @see #checkCallingPermission
2459 */
2460 public abstract int checkCallingOrSelfPermission(String permission);
2461
2462 /**
2463 * If the given permission is not allowed for a particular process
2464 * and user ID running in the system, throw a {@link SecurityException}.
2465 *
2466 * @param permission The name of the permission being checked.
2467 * @param pid The process ID being checked against. Must be &gt; 0.
2468 * @param uid The user ID being checked against. A uid of 0 is the root
2469 * user, which will pass every permission check.
2470 * @param message A message to include in the exception if it is thrown.
2471 *
2472 * @see #checkPermission(String, int, int)
2473 */
2474 public abstract void enforcePermission(
2475 String permission, int pid, int uid, String message);
2476
2477 /**
2478 * If the calling process of an IPC you are handling has not been
2479 * granted a particular permission, throw a {@link
2480 * SecurityException}. This is basically the same as calling
2481 * {@link #enforcePermission(String, int, int, String)} with the
2482 * pid and uid returned by {@link android.os.Binder#getCallingPid}
2483 * and {@link android.os.Binder#getCallingUid}. One important
2484 * difference is that if you are not currently processing an IPC,
2485 * this function will always throw the SecurityException. This is
2486 * done to protect against accidentally leaking permissions; you
2487 * can use {@link #enforceCallingOrSelfPermission} to avoid this
2488 * protection.
2489 *
2490 * @param permission The name of the permission being checked.
2491 * @param message A message to include in the exception if it is thrown.
2492 *
2493 * @see #checkCallingPermission(String)
2494 */
2495 public abstract void enforceCallingPermission(
2496 String permission, String message);
2497
2498 /**
2499 * If neither you nor the calling process of an IPC you are
2500 * handling has been granted a particular permission, throw a
2501 * {@link SecurityException}. This is the same as {@link
2502 * #enforceCallingPermission}, except it grants your own
2503 * permissions if you are not currently processing an IPC. Use
2504 * with care!
2505 *
2506 * @param permission The name of the permission being checked.
2507 * @param message A message to include in the exception if it is thrown.
2508 *
2509 * @see #checkCallingOrSelfPermission(String)
2510 */
2511 public abstract void enforceCallingOrSelfPermission(
2512 String permission, String message);
2513
2514 /**
2515 * Grant permission to access a specific Uri to another package, regardless
2516 * of whether that package has general permission to access the Uri's
2517 * content provider. This can be used to grant specific, temporary
2518 * permissions, typically in response to user interaction (such as the
2519 * user opening an attachment that you would like someone else to
2520 * display).
2521 *
2522 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2523 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2524 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2525 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
2526 * start an activity instead of this function directly. If you use this
2527 * function directly, you should be sure to call
2528 * {@link #revokeUriPermission} when the target should no longer be allowed
2529 * to access it.
2530 *
2531 * <p>To succeed, the content provider owning the Uri must have set the
2532 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
2533 * grantUriPermissions} attribute in its manifest or included the
2534 * {@link android.R.styleable#AndroidManifestGrantUriPermission
2535 * &lt;grant-uri-permissions&gt;} tag.
2536 *
2537 * @param toPackage The package you would like to allow to access the Uri.
2538 * @param uri The Uri you would like to grant access to.
2539 * @param modeFlags The desired access modes. Any combination of
2540 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2541 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2542 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2543 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2544 *
2545 * @see #revokeUriPermission
2546 */
2547 public abstract void grantUriPermission(String toPackage, Uri uri,
2548 int modeFlags);
2549
2550 /**
2551 * Remove all permissions to access a particular content provider Uri
2552 * that were previously added with {@link #grantUriPermission}. The given
2553 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07002554 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 * revoke both "content://foo/target" and "content://foo/target/sub", but not
2556 * "content://foo".
2557 *
2558 * @param uri The Uri you would like to revoke access to.
2559 * @param modeFlags The desired access modes. Any combination of
2560 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
2561 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2562 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
2563 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2564 *
2565 * @see #grantUriPermission
2566 */
2567 public abstract void revokeUriPermission(Uri uri, int modeFlags);
2568
2569 /**
2570 * Determine whether a particular process and user ID has been granted
2571 * permission to access a specific URI. This only checks for permissions
2572 * that have been explicitly granted -- if the given process/uid has
2573 * more general access to the URI's content provider then this check will
2574 * always fail.
2575 *
2576 * @param uri The uri that is being checked.
2577 * @param pid The process ID being checked against. Must be &gt; 0.
2578 * @param uid The user ID being checked against. A uid of 0 is the root
2579 * user, which will pass every permission check.
2580 * @param modeFlags The type of access to grant. May be one or both of
2581 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2582 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2583 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002584 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002585 * pid/uid is allowed to access that uri, or
2586 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2587 *
2588 * @see #checkCallingUriPermission
2589 */
2590 public abstract int checkUriPermission(Uri uri, int pid, int uid, int modeFlags);
2591
2592 /**
2593 * Determine whether the calling process and user ID has been
2594 * granted permission to access a specific URI. This is basically
2595 * the same as calling {@link #checkUriPermission(Uri, int, int,
2596 * int)} with the pid and uid returned by {@link
2597 * android.os.Binder#getCallingPid} and {@link
2598 * android.os.Binder#getCallingUid}. One important difference is
2599 * that if you are not currently processing an IPC, this function
2600 * will always fail.
2601 *
2602 * @param uri The uri that is being checked.
2603 * @param modeFlags The type of access to grant. May be one or both of
2604 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2605 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2606 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002607 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 * is allowed to access that uri, or
2609 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2610 *
2611 * @see #checkUriPermission(Uri, int, int, int)
2612 */
2613 public abstract int checkCallingUriPermission(Uri uri, int modeFlags);
2614
2615 /**
2616 * Determine whether the calling process of an IPC <em>or you</em> has been granted
2617 * permission to access a specific URI. This is the same as
2618 * {@link #checkCallingUriPermission}, except it grants your own permissions
2619 * if you are not currently processing an IPC. Use with care!
2620 *
2621 * @param uri The uri that is being checked.
2622 * @param modeFlags The type of access to grant. May be one or both of
2623 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2624 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2625 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002626 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002627 * is allowed to access that uri, or
2628 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2629 *
2630 * @see #checkCallingUriPermission
2631 */
2632 public abstract int checkCallingOrSelfUriPermission(Uri uri, int modeFlags);
2633
2634 /**
2635 * Check both a Uri and normal permission. This allows you to perform
2636 * both {@link #checkPermission} and {@link #checkUriPermission} in one
2637 * call.
2638 *
2639 * @param uri The Uri whose permission is to be checked, or null to not
2640 * do this check.
2641 * @param readPermission The permission that provides overall read access,
2642 * or null to not do this check.
2643 * @param writePermission The permission that provides overall write
2644 * acess, or null to not do this check.
2645 * @param pid The process ID being checked against. Must be &gt; 0.
2646 * @param uid The user ID being checked against. A uid of 0 is the root
2647 * user, which will pass every permission check.
2648 * @param modeFlags The type of access to grant. May be one or both of
2649 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2650 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2651 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002652 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 * is allowed to access that uri or holds one of the given permissions, or
2654 * {@link PackageManager#PERMISSION_DENIED} if it is not.
2655 */
2656 public abstract int checkUriPermission(Uri uri, String readPermission,
2657 String writePermission, int pid, int uid, int modeFlags);
2658
2659 /**
2660 * If a particular process and user ID has not been granted
2661 * permission to access a specific URI, throw {@link
2662 * SecurityException}. This only checks for permissions that have
2663 * been explicitly granted -- if the given process/uid has more
2664 * general access to the URI's content provider then this check
2665 * will always fail.
2666 *
2667 * @param uri The uri that is being checked.
2668 * @param pid The process ID being checked against. Must be &gt; 0.
2669 * @param uid The user ID being checked against. A uid of 0 is the root
2670 * user, which will pass every permission check.
2671 * @param modeFlags The type of access to grant. May be one or both of
2672 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2673 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2674 * @param message A message to include in the exception if it is thrown.
2675 *
2676 * @see #checkUriPermission(Uri, int, int, int)
2677 */
2678 public abstract void enforceUriPermission(
2679 Uri uri, int pid, int uid, int modeFlags, String message);
2680
2681 /**
2682 * If the calling process and user ID has not been granted
2683 * permission to access a specific URI, throw {@link
2684 * SecurityException}. This is basically the same as calling
2685 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
2686 * the pid and uid returned by {@link
2687 * android.os.Binder#getCallingPid} and {@link
2688 * android.os.Binder#getCallingUid}. One important difference is
2689 * that if you are not currently processing an IPC, this function
2690 * will always throw a SecurityException.
2691 *
2692 * @param uri The uri that is being checked.
2693 * @param modeFlags The type of access to grant. May be one or both of
2694 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2695 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2696 * @param message A message to include in the exception if it is thrown.
2697 *
2698 * @see #checkCallingUriPermission(Uri, int)
2699 */
2700 public abstract void enforceCallingUriPermission(
2701 Uri uri, int modeFlags, String message);
2702
2703 /**
2704 * If the calling process of an IPC <em>or you</em> has not been
2705 * granted permission to access a specific URI, throw {@link
2706 * SecurityException}. This is the same as {@link
2707 * #enforceCallingUriPermission}, except it grants your own
2708 * permissions if you are not currently processing an IPC. Use
2709 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07002710 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 * @param uri The uri that is being checked.
2712 * @param modeFlags The type of access to grant. May be one or both of
2713 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2714 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2715 * @param message A message to include in the exception if it is thrown.
2716 *
2717 * @see #checkCallingOrSelfUriPermission(Uri, int)
2718 */
2719 public abstract void enforceCallingOrSelfUriPermission(
2720 Uri uri, int modeFlags, String message);
2721
2722 /**
2723 * Enforce both a Uri and normal permission. This allows you to perform
2724 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
2725 * call.
Scott Main4b5da682010-10-21 11:49:12 -07002726 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 * @param uri The Uri whose permission is to be checked, or null to not
2728 * do this check.
2729 * @param readPermission The permission that provides overall read access,
2730 * or null to not do this check.
2731 * @param writePermission The permission that provides overall write
2732 * acess, or null to not do this check.
2733 * @param pid The process ID being checked against. Must be &gt; 0.
2734 * @param uid The user ID being checked against. A uid of 0 is the root
2735 * user, which will pass every permission check.
2736 * @param modeFlags The type of access to grant. May be one or both of
2737 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
2738 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
2739 * @param message A message to include in the exception if it is thrown.
2740 *
2741 * @see #checkUriPermission(Uri, String, String, int, int, int)
2742 */
2743 public abstract void enforceUriPermission(
2744 Uri uri, String readPermission, String writePermission,
2745 int pid, int uid, int modeFlags, String message);
2746
2747 /**
2748 * Flag for use with {@link #createPackageContext}: include the application
2749 * code with the context. This means loading code into the caller's
2750 * process, so that {@link #getClassLoader()} can be used to instantiate
2751 * the application's classes. Setting this flags imposes security
2752 * restrictions on what application context you can access; if the
2753 * requested application can not be safely loaded into your process,
2754 * java.lang.SecurityException will be thrown. If this flag is not set,
2755 * there will be no restrictions on the packages that can be loaded,
2756 * but {@link #getClassLoader} will always return the default system
2757 * class loader.
2758 */
2759 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
2760
2761 /**
2762 * Flag for use with {@link #createPackageContext}: ignore any security
2763 * restrictions on the Context being requested, allowing it to always
2764 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
2765 * to be loaded into a process even when it isn't safe to do so. Use
2766 * with extreme care!
2767 */
2768 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07002769
Romain Guy870e09f2009-07-06 16:35:25 -07002770 /**
2771 * Flag for use with {@link #createPackageContext}: a restricted context may
2772 * disable specific features. For instance, a View associated with a restricted
2773 * context would ignore particular XML attributes.
2774 */
2775 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776
2777 /**
2778 * Return a new Context object for the given application name. This
2779 * Context is the same as what the named application gets when it is
2780 * launched, containing the same resources and class loader. Each call to
2781 * this method returns a new instance of a Context object; Context objects
2782 * are not shared, however they share common state (Resources, ClassLoader,
2783 * etc) so the Context instance itself is fairly lightweight.
2784 *
2785 * <p>Throws {@link PackageManager.NameNotFoundException} if there is no
2786 * application with the given package name.
2787 *
2788 * <p>Throws {@link java.lang.SecurityException} if the Context requested
2789 * can not be loaded into the caller's process for security reasons (see
2790 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
2791 *
2792 * @param packageName Name of the application's package.
2793 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
2794 * or {@link #CONTEXT_IGNORE_SECURITY}.
2795 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002796 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002798 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04002800 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 */
2802 public abstract Context createPackageContext(String packageName,
2803 int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07002804
2805 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07002806 * Similar to {@link #createPackageContext(String, int)}, but with a
2807 * different {@link UserHandle}. For example, {@link #getContentResolver()}
2808 * will open any {@link Uri} as the given user.
2809 *
2810 * @hide
2811 */
2812 public abstract Context createPackageContextAsUser(
2813 String packageName, int flags, UserHandle user)
2814 throws PackageManager.NameNotFoundException;
2815
2816 /**
Jim Millera75a8832013-02-07 16:53:32 -08002817 * Get the userId associated with this context
2818 * @return user id
2819 *
2820 * @hide
2821 */
2822 public abstract int getUserId();
2823
2824 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07002825 * Return a new Context object for the current Context but whose resources
2826 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07002827 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07002828 * shared, however common state (ClassLoader, other Resources for the
2829 * same configuration) may be so the Context itself can be fairly lightweight.
2830 *
2831 * @param overrideConfiguration A {@link Configuration} specifying what
2832 * values to modify in the base Configuration of the original Context's
2833 * resources. If the base configuration changes (such as due to an
2834 * orientation change), the resources of this context will also change except
2835 * for those that have been explicitly overridden with a value here.
2836 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002837 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07002838 */
2839 public abstract Context createConfigurationContext(Configuration overrideConfiguration);
2840
2841 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07002842 * Return a new Context object for the current Context but whose resources
2843 * are adjusted to match the metrics of the given Display. Each call to this method
2844 * returns a new instance of a Context object; Context objects are not
2845 * shared, however common state (ClassLoader, other Resources for the
2846 * same configuration) may be so the Context itself can be fairly lightweight.
2847 *
2848 * The returned display Context provides a {@link WindowManager}
2849 * (see {@link #getSystemService(String)}) that is configured to show windows
2850 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
2851 * method can be used to retrieve the Display from the returned Context.
2852 *
2853 * @param display A {@link Display} object specifying the display
2854 * for whose metrics the Context's resources should be tailored and upon which
2855 * new windows should be shown.
2856 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002857 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07002858 */
2859 public abstract Context createDisplayContext(Display display);
2860
2861 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07002862 * Gets the display adjustments holder for this context. This information
2863 * is provided on a per-application or activity basis and is used to simulate lower density
2864 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07002865 *
Jeff Browna492c3a2012-08-23 19:48:44 -07002866 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07002867 * @return The compatibility info holder, or null if not required by the application.
2868 * @hide
2869 */
Craig Mautner48d0d182013-06-11 07:53:06 -07002870 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07002871
2872 /**
Romain Guy870e09f2009-07-06 16:35:25 -07002873 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07002874 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002875 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07002876 *
Romain Guy870e09f2009-07-06 16:35:25 -07002877 * @see #CONTEXT_RESTRICTED
2878 */
2879 public boolean isRestricted() {
2880 return false;
2881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882}