blob: 80b5e0b98e7ce9c5dff0505eb15a27b8ea8e3aa6 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Tor Norbye1c2bf032015-03-02 10:57:08 -080019import android.annotation.CheckResult;
Tor Norbyed9273d62013-05-30 15:59:53 -070020import android.annotation.IntDef;
21import android.annotation.NonNull;
22import android.annotation.Nullable;
23import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070024import android.annotation.StringRes;
25import android.annotation.StyleRes;
26import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090027import android.annotation.SystemApi;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070028import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.content.pm.PackageManager;
30import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080031import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070032import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.res.Resources;
34import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070035import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.database.sqlite.SQLiteDatabase;
37import android.database.sqlite.SQLiteDatabase.CursorFactory;
38import android.graphics.Bitmap;
39import android.graphics.drawable.Drawable;
40import android.net.Uri;
41import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070042import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.os.Handler;
Dianne Hackbornff170242014-11-19 10:59:01 -080044import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070046import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070047import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070048import android.os.UserManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070049import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.util.AttributeSet;
Craig Mautner48d0d182013-06-11 07:53:06 -070051import android.view.DisplayAdjustments;
Jeff Browna492c3a2012-08-23 19:48:44 -070052import android.view.Display;
Jon Miranda836c0a82014-08-11 12:32:26 -070053import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070054import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
56import java.io.File;
57import java.io.FileInputStream;
58import java.io.FileNotFoundException;
59import java.io.FileOutputStream;
60import java.io.IOException;
61import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070062import java.lang.annotation.Retention;
63import java.lang.annotation.RetentionPolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064
65/**
66 * Interface to global information about an application environment. This is
67 * an abstract class whose implementation is provided by
68 * the Android system. It
69 * allows access to application-specific resources and classes, as well as
70 * up-calls for application-level operations such as launching activities,
71 * broadcasting and receiving intents, etc.
72 */
73public abstract class Context {
74 /**
75 * File creation mode: the default mode, where the created file can only
76 * be accessed by the calling application (or all applications sharing the
77 * same user ID).
78 * @see #MODE_WORLD_READABLE
79 * @see #MODE_WORLD_WRITEABLE
80 */
81 public static final int MODE_PRIVATE = 0x0000;
82 /**
Nick Kralevich15069212013-01-09 15:54:56 -080083 * @deprecated Creating world-readable files is very dangerous, and likely
84 * to cause security holes in applications. It is strongly discouraged;
85 * instead, applications should use more formal mechanism for interactions
86 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
87 * {@link android.app.Service}. There are no guarantees that this
88 * access mode will remain on a file, such as when it goes through a
89 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090 * File creation mode: allow all other applications to have read access
91 * to the created file.
92 * @see #MODE_PRIVATE
93 * @see #MODE_WORLD_WRITEABLE
94 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070095 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 public static final int MODE_WORLD_READABLE = 0x0001;
97 /**
Nick Kralevich15069212013-01-09 15:54:56 -080098 * @deprecated Creating world-writable files is very dangerous, and likely
99 * to cause security holes in applications. It is strongly discouraged;
100 * instead, applications should use more formal mechanism for interactions
101 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
102 * {@link android.app.Service}. There are no guarantees that this
103 * access mode will remain on a file, such as when it goes through a
104 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 * File creation mode: allow all other applications to have write access
106 * to the created file.
107 * @see #MODE_PRIVATE
108 * @see #MODE_WORLD_READABLE
109 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700110 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 public static final int MODE_WORLD_WRITEABLE = 0x0002;
112 /**
113 * File creation mode: for use with {@link #openFileOutput}, if the file
114 * already exists then write data to the end of the existing file
115 * instead of erasing it.
116 * @see #openFileOutput
117 */
118 public static final int MODE_APPEND = 0x8000;
119
120 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800121 * SharedPreference loading flag: when set, the file on disk will
122 * be checked for modification even if the shared preferences
123 * instance is already loaded in this process. This behavior is
124 * sometimes desired in cases where the application has multiple
125 * processes, all writing to the same SharedPreferences file.
126 * Generally there are better forms of communication between
127 * processes, though.
128 *
129 * <p>This was the legacy (but undocumented) behavior in and
130 * before Gingerbread (Android 2.3) and this flag is implied when
131 * targetting such releases. For applications targetting SDK
132 * versions <em>greater than</em> Android 2.3, this flag must be
133 * explicitly set if desired.
134 *
135 * @see #getSharedPreferences
136 */
137 public static final int MODE_MULTI_PROCESS = 0x0004;
138
139 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700140 * Database open flag: when set, the database is opened with write-ahead
141 * logging enabled by default.
142 *
143 * @see #openOrCreateDatabase(String, int, CursorFactory)
144 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
145 * @see SQLiteDatabase#enableWriteAheadLogging
146 */
147 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
148
Tor Norbyed9273d62013-05-30 15:59:53 -0700149 /** @hide */
150 @IntDef(flag = true,
151 value = {
152 BIND_AUTO_CREATE,
Tor Norbyed9273d62013-05-30 15:59:53 -0700153 BIND_DEBUG_UNBIND,
154 BIND_NOT_FOREGROUND,
155 BIND_ABOVE_CLIENT,
156 BIND_ALLOW_OOM_MANAGEMENT,
Tor Norbyece1c67c2014-12-02 13:59:17 -0800157 BIND_WAIVE_PRIORITY,
158 BIND_IMPORTANT,
159 BIND_ADJUST_WITH_ACTIVITY
Tor Norbyed9273d62013-05-30 15:59:53 -0700160 })
161 @Retention(RetentionPolicy.SOURCE)
162 public @interface BindServiceFlags {}
163
Jeff Brown47847f32012-03-22 19:13:11 -0700164 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 * Flag for {@link #bindService}: automatically create the service as long
166 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700167 * its {@link android.app.Service#onStartCommand}
168 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 * explicit call to {@link #startService}. Even without that, though,
170 * this still provides you with access to the service object while the
171 * service is created.
172 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700173 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
174 * not supplying this flag would also impact how important the system
175 * consider's the target service's process to be. When set, the only way
176 * for it to be raised was by binding from a service in which case it will
177 * only be important when that activity is in the foreground. Now to
178 * achieve this behavior you must explicitly supply the new flag
179 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
180 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
181 * the flags {@link #BIND_WAIVE_PRIORITY} and
182 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
183 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 */
185 public static final int BIND_AUTO_CREATE = 0x0001;
186
187 /**
188 * Flag for {@link #bindService}: include debugging help for mismatched
189 * calls to unbind. When this flag is set, the callstack of the following
190 * {@link #unbindService} call is retained, to be printed if a later
191 * incorrect unbind call is made. Note that doing this requires retaining
192 * information about the binding that was made for the lifetime of the app,
193 * resulting in a leak -- this should only be used for debugging.
194 */
195 public static final int BIND_DEBUG_UNBIND = 0x0002;
196
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800197 /**
198 * Flag for {@link #bindService}: don't allow this binding to raise
199 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700200 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800201 * as the client (so that its process will not be killable in any
202 * situation where the client is not killable), but for CPU scheduling
203 * purposes it may be left in the background. This only has an impact
204 * in the situation where the binding client is a foreground process
205 * and the target service is in a background process.
206 */
207 public static final int BIND_NOT_FOREGROUND = 0x0004;
208
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700209 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700210 * Flag for {@link #bindService}: indicates that the client application
211 * binding to this service considers the service to be more important than
212 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700213 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700214 * this is not guaranteed to be the case.
215 */
216 public static final int BIND_ABOVE_CLIENT = 0x0008;
217
218 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700219 * Flag for {@link #bindService}: allow the process hosting the bound
220 * service to go through its normal memory management. It will be
221 * treated more like a running service, allowing the system to
222 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700223 * whim it may have, and being more aggressive about making it a candidate
224 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700225 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700226 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
227
228 /**
229 * Flag for {@link #bindService}: don't impact the scheduling or
230 * memory management priority of the target service's hosting process.
231 * Allows the service's process to be managed on the background LRU list
232 * just like a regular application process in the background.
233 */
234 public static final int BIND_WAIVE_PRIORITY = 0x0020;
235
236 /**
237 * Flag for {@link #bindService}: this service is very important to
238 * the client, so should be brought to the foreground process level
239 * when the client is. Normally a process can only be raised to the
240 * visibility level by a client, even if that client is in the foreground.
241 */
242 public static final int BIND_IMPORTANT = 0x0040;
243
244 /**
245 * Flag for {@link #bindService}: If binding from an activity, allow the
246 * target service's process importance to be raised based on whether the
247 * activity is visible to the user, regardless whether another flag is
248 * used to reduce the amount that the client process's overall importance
249 * is used to impact it.
250 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700251 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
252
253 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700254 * @hide Flag for {@link #bindService}: Treat the binding as hosting
255 * an activity, an unbinding as the activity going in the background.
256 * That is, when unbinding, the process when empty will go on the activity
257 * LRU list instead of the regular one, keeping it around more aggressively
258 * than it otherwise would be. This is intended for use with IMEs to try
259 * to keep IME processes around for faster keyboard switching.
260 */
261 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
262
263 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700264 * @hide An idea that is not yet implemented.
265 * Flag for {@link #bindService}: If binding from an activity, consider
266 * this service to be visible like the binding activity is. That is,
267 * it will be treated as something more important to keep around than
268 * invisible background activities. This will impact the number of
269 * recent activities the user can switch between without having them
270 * restart. There is no guarantee this will be respected, as the system
271 * tries to balance such requests from one app vs. the importantance of
272 * keeping other apps around.
273 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700274 public static final int BIND_VISIBLE = 0x10000000;
275
276 /**
277 * @hide
278 * Flag for {@link #bindService}: Consider this binding to be causing the target
279 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
280 * away.
281 */
282 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700283
284 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700285 * Flag for {@link #bindService}: Don't consider the bound service to be
286 * visible, even if the caller is visible.
287 * @hide
288 */
289 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 /** Return an AssetManager instance for your application's package. */
292 public abstract AssetManager getAssets();
293
294 /** Return a Resources instance for your application's package. */
295 public abstract Resources getResources();
296
297 /** Return PackageManager instance to find global package information. */
298 public abstract PackageManager getPackageManager();
299
300 /** Return a ContentResolver instance for your application's package. */
301 public abstract ContentResolver getContentResolver();
302
303 /**
304 * Return the Looper for the main thread of the current process. This is
305 * the thread used to dispatch calls to application components (activities,
306 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700307 * <p>
308 * By definition, this method returns the same result as would be obtained
309 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
310 * </p>
311 *
312 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 */
314 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 /**
317 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800318 * current process. This generally should only be used if you need a
319 * Context whose lifecycle is separate from the current context, that is
320 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700321 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800322 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800323 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800324 * <ul>
325 * <li> <p>If used from an Activity context, the receiver is being registered
326 * within that activity. This means that you are expected to unregister
327 * before the activity is done being destroyed; in fact if you do not do
328 * so, the framework will clean up your leaked registration as it removes
329 * the activity and log an error. Thus, if you use the Activity context
330 * to register a receiver that is static (global to the process, not
331 * associated with an Activity instance) then that registration will be
332 * removed on you at whatever point the activity you used is destroyed.
333 * <li> <p>If used from the Context returned here, the receiver is being
334 * registered with the global state associated with your application. Thus
335 * it will never be unregistered for you. This is necessary if the receiver
336 * is associated with static data, not a particular component. However
337 * using the ApplicationContext elsewhere can easily lead to serious leaks
338 * if you forget to unregister, unbind, etc.
339 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 */
341 public abstract Context getApplicationContext();
342
343 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700344 * Add a new {@link ComponentCallbacks} to the base application of the
345 * Context, which will be called at the same times as the ComponentCallbacks
346 * methods of activities and other components are called. Note that you
347 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
348 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700349 *
350 * @param callback The interface to call. This can be either a
351 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700352 */
353 public void registerComponentCallbacks(ComponentCallbacks callback) {
354 getApplicationContext().registerComponentCallbacks(callback);
355 }
356
357 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400358 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700359 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
360 */
361 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
362 getApplicationContext().unregisterComponentCallbacks(callback);
363 }
364
365 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 * Return a localized, styled CharSequence from the application's package's
367 * default string table.
368 *
369 * @param resId Resource id for the CharSequence text
370 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700371 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 return getResources().getText(resId);
373 }
374
375 /**
376 * Return a localized string from the application's package's
377 * default string table.
378 *
379 * @param resId Resource id for the string
380 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700381 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 return getResources().getString(resId);
383 }
384
385 /**
386 * Return a localized formatted string from the application's package's
387 * default string table, substituting the format arguments as defined in
388 * {@link java.util.Formatter} and {@link java.lang.String#format}.
389 *
390 * @param resId Resource id for the format string
391 * @param formatArgs The format arguments that will be used for substitution.
392 */
393
Tor Norbye7b9c9122013-05-30 16:48:33 -0700394 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 return getResources().getString(resId, formatArgs);
396 }
397
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800398 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800399 * Returns a color associated with a particular resource ID and styled for
400 * the current theme.
401 *
402 * @param id The desired resource identifier, as generated by the aapt
403 * tool. This integer encodes the package, type, and resource
404 * entry. The value 0 is an invalid identifier.
405 * @return A single color value in the form 0xAARRGGBB.
406 * @throws android.content.res.Resources.NotFoundException if the given ID
407 * does not exist.
408 */
409 @Nullable
410 public final int getColor(int id) {
411 return getResources().getColor(id, getTheme());
412 }
413
414 /**
415 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800416 * styled for the current theme.
417 *
418 * @param id The desired resource identifier, as generated by the aapt
419 * tool. This integer encodes the package, type, and resource
420 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800421 * @return An object that can be used to draw this resource, or
422 * {@code null} if the resource could not be resolved.
423 * @throws android.content.res.Resources.NotFoundException if the given ID
424 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800425 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800426 @Nullable
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800427 public final Drawable getDrawable(int id) {
428 return getResources().getDrawable(id, getTheme());
429 }
430
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800431 /**
432 * Returns a color state list associated with a particular resource ID and
433 * styled for the current theme.
434 *
435 * @param id The desired resource identifier, as generated by the aapt
436 * tool. This integer encodes the package, type, and resource
437 * entry. The value 0 is an invalid identifier.
438 * @return A color state list, or {@code null} if the resource could not be
439 * resolved.
440 * @throws android.content.res.Resources.NotFoundException if the given ID
441 * does not exist.
442 */
443 @Nullable
444 public final ColorStateList getColorStateList(int id) {
445 return getResources().getColorStateList(id, getTheme());
446 }
447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 /**
449 * Set the base theme for this context. Note that this should be called
450 * before any views are instantiated in the Context (for example before
451 * calling {@link android.app.Activity#setContentView} or
452 * {@link android.view.LayoutInflater#inflate}).
453 *
454 * @param resid The style resource describing the theme.
455 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700456 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457
Dianne Hackborn247fe742011-01-08 17:25:57 -0800458 /** @hide Needed for some internal implementation... not public because
459 * you can't assume this actually means anything. */
460 public int getThemeResId() {
461 return 0;
462 }
463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 /**
465 * Return the Theme object associated with this Context.
466 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700467 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 public abstract Resources.Theme getTheme();
469
470 /**
471 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800472 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 * for more information.
474 *
Jeff Brown6e539312015-02-24 18:53:21 -0800475 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 */
477 public final TypedArray obtainStyledAttributes(
478 int[] attrs) {
479 return getTheme().obtainStyledAttributes(attrs);
480 }
481
482 /**
483 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800484 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 * for more information.
486 *
Jeff Brown6e539312015-02-24 18:53:21 -0800487 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 */
489 public final TypedArray obtainStyledAttributes(
Tor Norbye7b9c9122013-05-30 16:48:33 -0700490 @StyleableRes int resid, int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 return getTheme().obtainStyledAttributes(resid, attrs);
492 }
493
494 /**
495 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800496 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 * for more information.
498 *
Jeff Brown6e539312015-02-24 18:53:21 -0800499 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 */
501 public final TypedArray obtainStyledAttributes(
502 AttributeSet set, int[] attrs) {
503 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
504 }
505
506 /**
507 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800508 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 * for more information.
510 *
Jeff Brown6e539312015-02-24 18:53:21 -0800511 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 */
513 public final TypedArray obtainStyledAttributes(
514 AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
515 return getTheme().obtainStyledAttributes(
516 set, attrs, defStyleAttr, defStyleRes);
517 }
518
519 /**
520 * Return a class loader you can use to retrieve classes in this package.
521 */
522 public abstract ClassLoader getClassLoader();
523
524 /** Return the name of this application's package. */
525 public abstract String getPackageName();
526
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800527 /** @hide Return the name of the base context this context is derived from. */
528 public abstract String getBasePackageName();
529
Dianne Hackborn95d78532013-09-11 09:51:14 -0700530 /** @hide Return the package name that should be used for app ops calls from
531 * this context. This is the same as {@link #getBasePackageName()} except in
532 * cases where system components are loaded into other app processes, in which
533 * case this will be the name of the primary package in that process (so that app
534 * ops uid verification will work with the name). */
535 public abstract String getOpPackageName();
536
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700537 /** Return the full application info for this context's package. */
538 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 /**
Kenny Root32148392010-01-21 15:40:47 -0800541 * Return the full path to this context's primary Android package.
542 * The Android package is a ZIP file which contains the application's
543 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 *
545 * <p>Note: this is not generally useful for applications, since they should
546 * not be directly accessing the file system.
547 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 * @return String Path to the resources.
549 */
550 public abstract String getPackageResourcePath();
551
552 /**
Kenny Root32148392010-01-21 15:40:47 -0800553 * Return the full path to this context's primary Android package.
554 * The Android package is a ZIP file which contains application's
555 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 *
557 * <p>Note: this is not generally useful for applications, since they should
558 * not be directly accessing the file system.
559 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 * @return String Path to the code and assets.
561 */
562 public abstract String getPackageCodePath();
563
564 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700565 * {@hide}
566 * Return the full path to the shared prefs file for the given prefs group name.
567 *
568 * <p>Note: this is not generally useful for applications, since they should
569 * not be directly accessing the file system.
570 */
571 public abstract File getSharedPrefsFile(String name);
572
573 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 * Retrieve and hold the contents of the preferences file 'name', returning
575 * a SharedPreferences through which you can retrieve and modify its
576 * values. Only one instance of the SharedPreferences object is returned
577 * to any callers for the same name, meaning they will see each other's
578 * edits as soon as they are made.
579 *
580 * @param name Desired preferences file. If a preferences file by this name
581 * does not exist, it will be created when you retrieve an
582 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
583 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
584 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800585 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
586 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
587 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
Tor Norbyed9273d62013-05-30 15:59:53 -0700588 * is always on in apps targeting Gingerbread (Android 2.3) and below, and
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800589 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400591 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 * to retrieve and modify the preference values.
593 *
594 * @see #MODE_PRIVATE
595 * @see #MODE_WORLD_READABLE
596 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800597 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 */
599 public abstract SharedPreferences getSharedPreferences(String name,
600 int mode);
601
602 /**
603 * Open a private file associated with this Context's application package
604 * for reading.
605 *
606 * @param name The name of the file to open; can not contain path
607 * separators.
608 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400609 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 *
611 * @see #openFileOutput
612 * @see #fileList
613 * @see #deleteFile
614 * @see java.io.FileInputStream#FileInputStream(String)
615 */
616 public abstract FileInputStream openFileInput(String name)
617 throws FileNotFoundException;
618
619 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800620 * Open a private file associated with this Context's application package
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 * for writing. Creates the file if it doesn't already exist.
622 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700623 * <p>No permissions are required to invoke this method, since it uses internal
624 * storage.
625 *
Nick Kralevich15069212013-01-09 15:54:56 -0800626 * @param name The name of the file to open; can not contain path
627 * separators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800629 * default operation, {@link #MODE_APPEND} to append to an existing file,
630 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
631 * permissions.
632 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400633 * @return The resulting {@link FileOutputStream}.
Nick Kralevich15069212013-01-09 15:54:56 -0800634 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 * @see #MODE_APPEND
636 * @see #MODE_PRIVATE
637 * @see #MODE_WORLD_READABLE
638 * @see #MODE_WORLD_WRITEABLE
639 * @see #openFileInput
640 * @see #fileList
641 * @see #deleteFile
642 * @see java.io.FileOutputStream#FileOutputStream(String)
643 */
644 public abstract FileOutputStream openFileOutput(String name, int mode)
645 throws FileNotFoundException;
646
647 /**
648 * Delete the given private file associated with this Context's
649 * application package.
650 *
651 * @param name The name of the file to delete; can not contain path
652 * separators.
653 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400654 * @return {@code true} if the file was successfully deleted; else
655 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 *
657 * @see #openFileInput
658 * @see #openFileOutput
659 * @see #fileList
660 * @see java.io.File#delete()
661 */
662 public abstract boolean deleteFile(String name);
663
664 /**
665 * Returns the absolute path on the filesystem where a file created with
666 * {@link #openFileOutput} is stored.
667 *
668 * @param name The name of the file for which you would like to get
669 * its path.
670 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400671 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 *
673 * @see #openFileOutput
674 * @see #getFilesDir
675 * @see #getDir
676 */
677 public abstract File getFileStreamPath(String name);
678
679 /**
680 * Returns the absolute path to the directory on the filesystem where
681 * files created with {@link #openFileOutput} are stored.
682 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700683 * <p>No permissions are required to read or write to the returned path, since this
684 * path is internal storage.
685 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400686 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 *
688 * @see #openFileOutput
689 * @see #getFileStreamPath
690 * @see #getDir
691 */
692 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800694 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700695 * Returns the absolute path to the directory on the filesystem similar to
696 * {@link #getFilesDir()}. The difference is that files placed under this
697 * directory will be excluded from automatic backup to remote storage. See
698 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
699 * of the automatic backup mechanism in Android.
700 *
701 * <p>No permissions are required to read or write to the returned path, since this
702 * path is internal storage.
703 *
704 * @return The path of the directory holding application files that will not be
705 * automatically backed up to remote storage.
706 *
707 * @see #openFileOutput
708 * @see #getFileStreamPath
709 * @see #getDir
710 * @see android.app.backup.BackupAgent
711 */
712 public abstract File getNoBackupFilesDir();
713
714 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700715 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800716 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700717 * Environment.getExternalStorageDirectory()}) where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700718 * place persistent files it owns. These files are internal to the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800719 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700720 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800721 * <p>This is like {@link #getFilesDir()} in that these
722 * files will be deleted when the application is uninstalled, however there
723 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700724 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800725 * <ul>
726 * <li>External files are not always available: they will disappear if the
727 * user mounts the external storage on a computer or removes it. See the
728 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700729 * <li>There is no security enforced with these files. For example, any application
730 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
731 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800732 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700733 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700734 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
735 * are required to read or write to the returned path; it's always
736 * accessible to the calling app. This only applies to paths generated for
737 * package name of the calling application. To access paths belonging
738 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
739 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
740 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700741 * <p>On devices with multiple users (as described by {@link UserManager}),
742 * each user has their own isolated external storage. Applications only
743 * have access to the external storage for the user they're running as.</p>
744 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800745 * <p>Here is an example of typical code to manipulate a file in
746 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700747 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800748 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
749 * private_file}
750 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700751 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800752 * file will be a path to a sub-directory of the given type. Though these files
753 * are not automatically scanned by the media scanner, you can explicitly
754 * add them to the media database with
755 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Jeff Brown6e539312015-02-24 18:53:21 -0800756 * android.media.MediaScannerConnection.OnScanCompletedListener)
757 * MediaScannerConnection.scanFile}.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800758 * Note that this is not the same as
759 * {@link android.os.Environment#getExternalStoragePublicDirectory
760 * Environment.getExternalStoragePublicDirectory()}, which provides
761 * directories of media shared by all applications. The
762 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700763 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800764 * application is uninstalled. Unlike
765 * {@link android.os.Environment#getExternalStoragePublicDirectory
766 * Environment.getExternalStoragePublicDirectory()}, the directory
767 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700768 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800769 * <p>Here is an example of typical code to manipulate a picture in
770 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700771 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800772 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
773 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700774 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800775 * @param type The type of files directory to return. May be null for
776 * the root of the files directory or one of
777 * the following Environment constants for a subdirectory:
778 * {@link android.os.Environment#DIRECTORY_MUSIC},
779 * {@link android.os.Environment#DIRECTORY_PODCASTS},
780 * {@link android.os.Environment#DIRECTORY_RINGTONES},
781 * {@link android.os.Environment#DIRECTORY_ALARMS},
782 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
783 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
784 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700785 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400786 * @return The path of the directory holding application files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800787 * on external storage. Returns null if external storage is not currently
788 * mounted so it could not ensure the path exists; you will need to call
789 * this method again when it is available.
790 *
791 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700792 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800793 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700794 @Nullable
795 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700796
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800797 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700798 * Returns absolute paths to application-specific directories on all
799 * external storage devices where the application can place persistent files
800 * it owns. These files are internal to the application, and not typically
801 * visible to the user as media.
802 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700803 * This is like {@link #getFilesDir()} in that these files will be deleted when
804 * the application is uninstalled, however there are some important differences:
805 * <ul>
806 * <li>External files are not always available: they will disappear if the
807 * user mounts the external storage on a computer or removes it.
808 * <li>There is no security enforced with these files.
809 * </ul>
810 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700811 * External storage devices returned here are considered a permanent part of
812 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700813 * slots, such as SD cards in a battery compartment. The returned paths do
814 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700815 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700816 * An application may store data on any or all of the returned devices. For
817 * example, an app may choose to store large files on the device with the
818 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700819 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700820 * No permissions are required to read or write to the returned paths; they
821 * are always accessible to the calling app. Write access outside of these
822 * paths on secondary external storage devices is not available.
823 * <p>
824 * The first path returned is the same as {@link #getExternalFilesDir(String)}.
825 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700826 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700827 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800828 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700829 */
830 public abstract File[] getExternalFilesDirs(String type);
831
832 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700833 * Return the primary external storage directory where this application's OBB
834 * files (if there are any) can be found. Note if the application does not have
835 * any OBB files, this directory may not exist.
836 * <p>
837 * This is like {@link #getFilesDir()} in that these files will be deleted when
838 * the application is uninstalled, however there are some important differences:
839 * <ul>
840 * <li>External files are not always available: they will disappear if the
841 * user mounts the external storage on a computer or removes it.
842 * <li>There is no security enforced with these files. For example, any application
843 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
844 * these files.
845 * </ul>
846 * <p>
847 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
848 * are required to read or write to the returned path; it's always
849 * accessible to the calling app. This only applies to paths generated for
850 * package name of the calling application. To access paths belonging
851 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
852 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700853 * <p>
854 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -0700855 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700856 * should ensure that multiple instances running under different users don't
857 * interfere with each other.
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800858 */
859 public abstract File getObbDir();
860
861 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700862 * Returns absolute paths to application-specific directories on all
863 * external storage devices where the application's OBB files (if there are
864 * any) can be found. Note if the application does not have any OBB files,
865 * these directories may not exist.
866 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700867 * This is like {@link #getFilesDir()} in that these files will be deleted when
868 * the application is uninstalled, however there are some important differences:
869 * <ul>
870 * <li>External files are not always available: they will disappear if the
871 * user mounts the external storage on a computer or removes it.
872 * <li>There is no security enforced with these files.
873 * </ul>
874 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700875 * External storage devices returned here are considered a permanent part of
876 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700877 * slots, such as SD cards in a battery compartment. The returned paths do
878 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700879 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700880 * An application may store data on any or all of the returned devices. For
881 * example, an app may choose to store large files on the device with the
882 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700883 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700884 * No permissions are required to read or write to the returned paths; they
885 * are always accessible to the calling app. Write access outside of these
886 * paths on secondary external storage devices is not available.
887 * <p>
888 * The first path returned is the same as {@link #getObbDir()}.
889 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700890 *
891 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800892 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700893 */
894 public abstract File[] getObbDirs();
895
896 /**
Scott Main4b5da682010-10-21 11:49:12 -0700897 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800899 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800900 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700901 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800902 * <strong>Note: you should not <em>rely</em> on the system deleting these
903 * files for you; you should always have a reasonable maximum, such as 1 MB,
904 * for the amount of space you consume with cache files, and prune those
905 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700906 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400907 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 *
909 * @see #openFileOutput
910 * @see #getFileStreamPath
911 * @see #getDir
912 */
913 public abstract File getCacheDir();
914
915 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -0700916 * Returns the absolute path to the application specific cache directory on
917 * the filesystem designed for storing cached code. The system will delete
918 * any files stored in this location both when your specific application is
919 * upgraded, and when the entire platform is upgraded.
920 * <p>
921 * This location is optimal for storing compiled or optimized code generated
922 * by your application at runtime.
923 * <p>
924 * Apps require no extra permissions to read or write to the returned path,
925 * since this path lives in their private storage.
926 *
927 * @return The path of the directory holding application code cache files.
928 */
929 public abstract File getCodeCacheDir();
930
931 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700932 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800933 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
934 * Environment.getExternalStorageDirectory()} where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700935 * place cache files it owns. These files are internal to the application, and
936 * not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700937 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800938 * <p>This is like {@link #getCacheDir()} in that these
939 * files will be deleted when the application is uninstalled, however there
940 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700941 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800942 * <ul>
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700943 * <li>The platform does not always monitor the space available in external
944 * storage, and thus may not automatically delete these files. Currently
945 * the only time files here will be deleted by the platform is when running
946 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
947 * {@link android.os.Environment#isExternalStorageEmulated()
948 * Environment.isExternalStorageEmulated()} returns true. Note that you should
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800949 * be managing the maximum space you will use for these anyway, just like
950 * with {@link #getCacheDir()}.
951 * <li>External files are not always available: they will disappear if the
952 * user mounts the external storage on a computer or removes it. See the
953 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700954 * <li>There is no security enforced with these files. For example, any application
955 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
956 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800957 * </ul>
958 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700959 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
960 * are required to read or write to the returned path; it's always
961 * accessible to the calling app. This only applies to paths generated for
962 * package name of the calling application. To access paths belonging
963 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
964 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
965 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700966 * <p>On devices with multiple users (as described by {@link UserManager}),
967 * each user has their own isolated external storage. Applications only
968 * have access to the external storage for the user they're running as.</p>
Jeff Sharkey8c165792012-10-22 14:08:29 -0700969 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400970 * @return The path of the directory holding application cache files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800971 * on external storage. Returns null if external storage is not currently
972 * mounted so it could not ensure the path exists; you will need to call
973 * this method again when it is available.
974 *
975 * @see #getCacheDir
976 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700977 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800978 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700979
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800980 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700981 * Returns absolute paths to application-specific directories on all
982 * external storage devices where the application can place cache files it
983 * owns. These files are internal to the application, and not typically
984 * visible to the user as media.
985 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700986 * This is like {@link #getCacheDir()} in that these files will be deleted when
987 * the application is uninstalled, however there are some important differences:
988 * <ul>
989 * <li>External files are not always available: they will disappear if the
990 * user mounts the external storage on a computer or removes it.
991 * <li>There is no security enforced with these files.
992 * </ul>
993 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700994 * External storage devices returned here are considered a permanent part of
995 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700996 * slots, such as SD cards in a battery compartment. The returned paths do
997 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700998 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700999 * An application may store data on any or all of the returned devices. For
1000 * example, an app may choose to store large files on the device with the
1001 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001002 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001003 * No permissions are required to read or write to the returned paths; they
1004 * are always accessible to the calling app. Write access outside of these
1005 * paths on secondary external storage devices is not available.
1006 * <p>
1007 * The first path returned is the same as {@link #getExternalCacheDir()}.
1008 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001009 *
1010 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001011 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001012 */
1013 public abstract File[] getExternalCacheDirs();
1014
1015 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001016 * Returns absolute paths to application-specific directories on all
1017 * external storage devices where the application can place media files.
1018 * These files are scanned and made available to other apps through
1019 * {@link MediaStore}.
1020 * <p>
1021 * This is like {@link #getExternalFilesDirs} in that these files will be
1022 * deleted when the application is uninstalled, however there are some
1023 * important differences:
1024 * <ul>
1025 * <li>External files are not always available: they will disappear if the
1026 * user mounts the external storage on a computer or removes it.
1027 * <li>There is no security enforced with these files.
1028 * </ul>
1029 * <p>
1030 * External storage devices returned here are considered a permanent part of
1031 * the device, including both emulated external storage and physical media
1032 * slots, such as SD cards in a battery compartment. The returned paths do
1033 * not include transient devices, such as USB flash drives.
1034 * <p>
1035 * An application may store data on any or all of the returned devices. For
1036 * example, an app may choose to store large files on the device with the
1037 * most available space, as measured by {@link StatFs}.
1038 * <p>
1039 * No permissions are required to read or write to the returned paths; they
1040 * are always accessible to the calling app. Write access outside of these
1041 * paths on secondary external storage devices is not available.
1042 * <p>
1043 * Returned paths may be {@code null} if a storage device is unavailable.
1044 *
1045 * @see Environment#getExternalStorageState(File)
1046 */
1047 public abstract File[] getExternalMediaDirs();
1048
1049 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 * Returns an array of strings naming the private files associated with
1051 * this Context's application package.
1052 *
1053 * @return Array of strings naming the private files.
1054 *
1055 * @see #openFileInput
1056 * @see #openFileOutput
1057 * @see #deleteFile
1058 */
1059 public abstract String[] fileList();
1060
1061 /**
1062 * Retrieve, creating if needed, a new directory in which the application
1063 * can place its own custom data files. You can use the returned File
1064 * object to create and access files in this directory. Note that files
1065 * created through a File object will only be accessible by your own
1066 * application; you can only set the mode of the entire directory, not
1067 * of individual files.
1068 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001069 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001070 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001071 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -08001072 * default operation, {@link #MODE_WORLD_READABLE} and
1073 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
1074 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001075 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001076 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077 *
1078 * @see #openFileOutput(String, int)
1079 */
1080 public abstract File getDir(String name, int mode);
1081
1082 /**
1083 * Open a new private SQLiteDatabase associated with this Context's
1084 * application package. Create the database file if it doesn't exist.
1085 *
1086 * @param name The name (unique in the application package) of the database.
1087 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1088 * default operation, {@link #MODE_WORLD_READABLE}
1089 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001090 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001091 * @param factory An optional factory class that is called to instantiate a
1092 * cursor when query is called.
Nick Kralevich15069212013-01-09 15:54:56 -08001093 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001094 * @return The contents of a newly created database with the given name.
1095 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001096 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 * @see #MODE_PRIVATE
1098 * @see #MODE_WORLD_READABLE
1099 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001100 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001101 * @see #deleteDatabase
1102 */
1103 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1104 int mode, CursorFactory factory);
1105
1106 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001107 * Open a new private SQLiteDatabase associated with this Context's
1108 * application package. Creates the database file if it doesn't exist.
1109 *
1110 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
1111 * used to handle corruption when sqlite reports database corruption.</p>
1112 *
1113 * @param name The name (unique in the application package) of the database.
1114 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1115 * default operation, {@link #MODE_WORLD_READABLE}
1116 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001117 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -07001118 * @param factory An optional factory class that is called to instantiate a
1119 * cursor when query is called.
1120 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Nick Kralevich15069212013-01-09 15:54:56 -08001121 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001122 * @return The contents of a newly created database with the given name.
1123 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001124 *
Vasu Nori74f170f2010-06-01 18:06:18 -07001125 * @see #MODE_PRIVATE
1126 * @see #MODE_WORLD_READABLE
1127 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001128 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -07001129 * @see #deleteDatabase
1130 */
1131 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001132 int mode, CursorFactory factory,
1133 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001134
1135 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 * Delete an existing private SQLiteDatabase associated with this Context's
1137 * application package.
1138 *
1139 * @param name The name (unique in the application package) of the
1140 * database.
1141 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001142 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 *
1144 * @see #openOrCreateDatabase
1145 */
1146 public abstract boolean deleteDatabase(String name);
1147
1148 /**
1149 * Returns the absolute path on the filesystem where a database created with
1150 * {@link #openOrCreateDatabase} is stored.
1151 *
1152 * @param name The name of the database for which you would like to get
1153 * its path.
1154 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001155 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 *
1157 * @see #openOrCreateDatabase
1158 */
1159 public abstract File getDatabasePath(String name);
1160
1161 /**
1162 * Returns an array of strings naming the private databases associated with
1163 * this Context's application package.
1164 *
1165 * @return Array of strings naming the private databases.
1166 *
1167 * @see #openOrCreateDatabase
1168 * @see #deleteDatabase
1169 */
1170 public abstract String[] databaseList();
1171
1172 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001173 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001174 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001176 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 public abstract Drawable getWallpaper();
1178
1179 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001180 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001181 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001182 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001183 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 public abstract Drawable peekWallpaper();
1185
1186 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001187 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1188 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001189 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001190 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 public abstract int getWallpaperDesiredMinimumWidth();
1192
1193 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001194 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1195 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001196 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001197 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001198 public abstract int getWallpaperDesiredMinimumHeight();
1199
1200 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001201 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001202 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001203 * <p>This method requires the caller to hold the permission
1204 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001206 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1208
1209 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001210 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001211 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001212 * <p>This method requires the caller to hold the permission
1213 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001215 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 public abstract void setWallpaper(InputStream data) throws IOException;
1217
1218 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001219 * @deprecated Use {@link android.app.WallpaperManager#clear
1220 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001221 * <p>This method requires the caller to hold the permission
1222 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001223 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001224 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225 public abstract void clearWallpaper() throws IOException;
1226
1227 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001228 * Same as {@link #startActivity(Intent, Bundle)} with no options
1229 * specified.
1230 *
1231 * @param intent The description of the activity to start.
1232 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001233 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001234 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001235 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001236 * @see PackageManager#resolveActivity
1237 */
1238 public abstract void startActivity(Intent intent);
1239
1240 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001241 * Version of {@link #startActivity(Intent)} that allows you to specify the
1242 * user the activity will be started for. This is not available to applications
1243 * that are not pre-installed on the system image. Using it requires holding
1244 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001245 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001246 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001247 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001248 * @hide
1249 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001250 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001251 throw new RuntimeException("Not implemented. Must override in a subclass.");
1252 }
1253
1254 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 * Launch a new activity. You will not receive any information about when
1256 * the activity exits.
1257 *
1258 * <p>Note that if this method is being called from outside of an
1259 * {@link android.app.Activity} Context, then the Intent must include
1260 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1261 * without being started from an existing Activity, there is no existing
1262 * task in which to place the new activity and thus it needs to be placed
1263 * in its own separate task.
1264 *
1265 * <p>This method throws {@link ActivityNotFoundException}
1266 * if there was no Activity found to run the given Intent.
1267 *
1268 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001269 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001270 * May be null if there are no options. See {@link android.app.ActivityOptions}
1271 * for how to build the Bundle supplied here; there are no supported definitions
1272 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001273 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001274 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001275 *
Scott Main60dd5202012-06-23 00:01:22 -07001276 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 * @see PackageManager#resolveActivity
1278 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001279 public abstract void startActivity(Intent intent, @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001280
1281 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001282 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1283 * user the activity will be started for. This is not available to applications
1284 * that are not pre-installed on the system image. Using it requires holding
1285 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001286 * @param intent The description of the activity to start.
1287 * @param options Additional options for how the Activity should be started.
1288 * May be null if there are no options. See {@link android.app.ActivityOptions}
1289 * for how to build the Bundle supplied here; there are no supported definitions
1290 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001291 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001292 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001293 * @hide
1294 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001295 public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001296 throw new RuntimeException("Not implemented. Must override in a subclass.");
1297 }
1298
1299 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001300 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1301 * specified.
1302 *
1303 * @param intents An array of Intents to be started.
1304 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001305 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001306 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001307 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001308 * @see PackageManager#resolveActivity
1309 */
1310 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001311
1312 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001313 * Launch multiple new activities. This is generally the same as calling
1314 * {@link #startActivity(Intent)} for the first Intent in the array,
1315 * that activity during its creation calling {@link #startActivity(Intent)}
1316 * for the second entry, etc. Note that unlike that approach, generally
1317 * none of the activities except the last in the array will be created
1318 * at this point, but rather will be created when the user first visits
1319 * them (due to pressing back from the activity on top).
1320 *
1321 * <p>This method throws {@link ActivityNotFoundException}
1322 * if there was no Activity found for <em>any</em> given Intent. In this
1323 * case the state of the activity stack is undefined (some Intents in the
1324 * list may be on it, some not), so you probably want to avoid such situations.
1325 *
1326 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001327 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001328 * See {@link android.content.Context#startActivity(Intent, Bundle)
1329 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001330 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001331 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001332 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001333 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001334 * @see PackageManager#resolveActivity
1335 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001336 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001337
1338 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001339 * @hide
1340 * Launch multiple new activities. This is generally the same as calling
1341 * {@link #startActivity(Intent)} for the first Intent in the array,
1342 * that activity during its creation calling {@link #startActivity(Intent)}
1343 * for the second entry, etc. Note that unlike that approach, generally
1344 * none of the activities except the last in the array will be created
1345 * at this point, but rather will be created when the user first visits
1346 * them (due to pressing back from the activity on top).
1347 *
1348 * <p>This method throws {@link ActivityNotFoundException}
1349 * if there was no Activity found for <em>any</em> given Intent. In this
1350 * case the state of the activity stack is undefined (some Intents in the
1351 * list may be on it, some not), so you probably want to avoid such situations.
1352 *
1353 * @param intents An array of Intents to be started.
1354 * @param options Additional options for how the Activity should be started.
1355 * @param userHandle The user for whom to launch the activities
1356 * See {@link android.content.Context#startActivity(Intent, Bundle)
1357 * Context.startActivity(Intent, Bundle)} for more details.
1358 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001359 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001360 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001361 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001362 * @see PackageManager#resolveActivity
1363 */
1364 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1365 throw new RuntimeException("Not implemented. Must override in a subclass.");
1366 }
1367
1368 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001369 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1370 * with no options specified.
1371 *
1372 * @param intent The IntentSender to launch.
1373 * @param fillInIntent If non-null, this will be provided as the
1374 * intent parameter to {@link IntentSender#sendIntent}.
1375 * @param flagsMask Intent flags in the original IntentSender that you
1376 * would like to change.
1377 * @param flagsValues Desired values for any bits set in
1378 * <var>flagsMask</var>
1379 * @param extraFlags Always set to 0.
1380 *
1381 * @see #startActivity(Intent)
1382 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1383 */
1384 public abstract void startIntentSender(IntentSender intent,
1385 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1386 throws IntentSender.SendIntentException;
1387
1388 /**
1389 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001390 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001391 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001392 * here; otherwise, its associated action will be executed (such as
1393 * sending a broadcast) as if you had called
1394 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001395 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001396 * @param intent The IntentSender to launch.
1397 * @param fillInIntent If non-null, this will be provided as the
1398 * intent parameter to {@link IntentSender#sendIntent}.
1399 * @param flagsMask Intent flags in the original IntentSender that you
1400 * would like to change.
1401 * @param flagsValues Desired values for any bits set in
1402 * <var>flagsMask</var>
1403 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001404 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001405 * See {@link android.content.Context#startActivity(Intent, Bundle)
1406 * Context.startActivity(Intent, Bundle)} for more details. If options
1407 * have also been supplied by the IntentSender, options given here will
1408 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001409 *
1410 * @see #startActivity(Intent, Bundle)
1411 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001412 */
1413 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001414 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001415 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001416
1417 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001418 * Broadcast the given intent to all interested BroadcastReceivers. This
1419 * call is asynchronous; it returns immediately, and you will continue
1420 * executing while the receivers are run. No results are propagated from
1421 * receivers and receivers can not abort the broadcast. If you want
1422 * to allow receivers to propagate results or abort the broadcast, you must
1423 * send an ordered broadcast using
1424 * {@link #sendOrderedBroadcast(Intent, String)}.
1425 *
1426 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1427 *
1428 * @param intent The Intent to broadcast; all receivers matching this
1429 * Intent will receive the broadcast.
1430 *
1431 * @see android.content.BroadcastReceiver
1432 * @see #registerReceiver
1433 * @see #sendBroadcast(Intent, String)
1434 * @see #sendOrderedBroadcast(Intent, String)
1435 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1436 */
1437 public abstract void sendBroadcast(Intent intent);
1438
1439 /**
1440 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1441 * an optional required permission to be enforced. This
1442 * call is asynchronous; it returns immediately, and you will continue
1443 * executing while the receivers are run. No results are propagated from
1444 * receivers and receivers can not abort the broadcast. If you want
1445 * to allow receivers to propagate results or abort the broadcast, you must
1446 * send an ordered broadcast using
1447 * {@link #sendOrderedBroadcast(Intent, String)}.
1448 *
1449 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1450 *
1451 * @param intent The Intent to broadcast; all receivers matching this
1452 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001453 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001454 * a receiver must hold in order to receive your broadcast.
1455 * If null, no permission is required.
1456 *
1457 * @see android.content.BroadcastReceiver
1458 * @see #registerReceiver
1459 * @see #sendBroadcast(Intent)
1460 * @see #sendOrderedBroadcast(Intent, String)
1461 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1462 */
1463 public abstract void sendBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001464 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001465
1466 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001467 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001468 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001469 * @hide
1470 */
1471 public abstract void sendBroadcast(Intent intent,
1472 String receiverPermission, int appOp);
1473
1474 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001475 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1476 * them one at a time to allow more preferred receivers to consume the
1477 * broadcast before it is delivered to less preferred receivers. This
1478 * call is asynchronous; it returns immediately, and you will continue
1479 * executing while the receivers are run.
1480 *
1481 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1482 *
1483 * @param intent The Intent to broadcast; all receivers matching this
1484 * Intent will receive the broadcast.
1485 * @param receiverPermission (optional) String naming a permissions that
1486 * a receiver must hold in order to receive your broadcast.
1487 * If null, no permission is required.
1488 *
1489 * @see android.content.BroadcastReceiver
1490 * @see #registerReceiver
1491 * @see #sendBroadcast(Intent)
1492 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1493 */
1494 public abstract void sendOrderedBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001495 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496
1497 /**
1498 * Version of {@link #sendBroadcast(Intent)} that allows you to
1499 * receive data back from the broadcast. This is accomplished by
1500 * supplying your own BroadcastReceiver when calling, which will be
1501 * treated as a final receiver at the end of the broadcast -- its
1502 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001503 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 * be serialized in the same way as calling
1505 * {@link #sendOrderedBroadcast(Intent, String)}.
1506 *
1507 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1508 * asynchronous; it will return before
1509 * resultReceiver.onReceive() is called.
1510 *
1511 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1512 *
1513 * @param intent The Intent to broadcast; all receivers matching this
1514 * Intent will receive the broadcast.
1515 * @param receiverPermission String naming a permissions that
1516 * a receiver must hold in order to receive your broadcast.
1517 * If null, no permission is required.
1518 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1519 * receiver of the broadcast.
1520 * @param scheduler A custom Handler with which to schedule the
1521 * resultReceiver callback; if null it will be
1522 * scheduled in the Context's main thread.
1523 * @param initialCode An initial value for the result code. Often
1524 * Activity.RESULT_OK.
1525 * @param initialData An initial value for the result data. Often
1526 * null.
1527 * @param initialExtras An initial value for the result extras. Often
1528 * null.
1529 *
1530 * @see #sendBroadcast(Intent)
1531 * @see #sendBroadcast(Intent, String)
1532 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 * @see android.content.BroadcastReceiver
1534 * @see #registerReceiver
1535 * @see android.app.Activity#RESULT_OK
1536 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001537 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1538 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1539 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1540 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001541
1542 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001543 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1544 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001545 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001546 * @hide
1547 */
1548 public abstract void sendOrderedBroadcast(Intent intent,
1549 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1550 Handler scheduler, int initialCode, String initialData,
1551 Bundle initialExtras);
1552
1553 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001554 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1555 * user the broadcast will be sent to. This is not available to applications
1556 * that are not pre-installed on the system image. Using it requires holding
1557 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001558 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001559 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001560 * @see #sendBroadcast(Intent)
1561 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001562 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001563
1564 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001565 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1566 * user the broadcast will be sent to. This is not available to applications
1567 * that are not pre-installed on the system image. Using it requires holding
1568 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001569 *
1570 * @param intent The Intent to broadcast; all receivers matching this
1571 * Intent will receive the broadcast.
1572 * @param user UserHandle to send the intent to.
1573 * @param receiverPermission (optional) String naming a permission that
1574 * a receiver must hold in order to receive your broadcast.
1575 * If null, no permission is required.
1576 *
1577 * @see #sendBroadcast(Intent, String)
1578 */
1579 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001580 @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001581
1582 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001583 * Version of
1584 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1585 * that allows you to specify the
1586 * user the broadcast will be sent to. This is not available to applications
1587 * that are not pre-installed on the system image. Using it requires holding
1588 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001589 *
1590 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1591 *
1592 * @param intent The Intent to broadcast; all receivers matching this
1593 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001594 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001595 * @param receiverPermission String naming a permissions that
1596 * a receiver must hold in order to receive your broadcast.
1597 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001598 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1599 * receiver of the broadcast.
1600 * @param scheduler A custom Handler with which to schedule the
1601 * resultReceiver callback; if null it will be
1602 * scheduled in the Context's main thread.
1603 * @param initialCode An initial value for the result code. Often
1604 * Activity.RESULT_OK.
1605 * @param initialData An initial value for the result data. Often
1606 * null.
1607 * @param initialExtras An initial value for the result extras. Often
1608 * null.
1609 *
1610 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1611 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001612 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001613 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1614 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1615 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001616
1617 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07001618 * Similar to above but takes an appOp as well, to enforce restrictions.
1619 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1620 * BroadcastReceiver, Handler, int, String, Bundle)
1621 * @hide
1622 */
1623 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1624 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1625 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1626 @Nullable Bundle initialExtras);
1627
1628 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001629 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 * Intent you are sending stays around after the broadcast is complete,
1631 * so that others can quickly retrieve that data through the return
1632 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1633 * all other ways, this behaves the same as
1634 * {@link #sendBroadcast(Intent)}.
1635 *
1636 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1637 * permission in order to use this API. If you do not hold that
1638 * permission, {@link SecurityException} will be thrown.
1639 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001640 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1641 * can access them), no protection (anyone can modify them), and many other problems.
1642 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1643 * has changed, with another mechanism for apps to retrieve the current value whenever
1644 * desired.
1645 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 * @param intent The Intent to broadcast; all receivers matching this
1647 * Intent will receive the broadcast, and the Intent will be held to
1648 * be re-broadcast to future receivers.
1649 *
1650 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001651 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001653 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001655
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001656 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001657 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001658 * receive data back from the broadcast. This is accomplished by
1659 * supplying your own BroadcastReceiver when calling, which will be
1660 * treated as a final receiver at the end of the broadcast -- its
1661 * {@link BroadcastReceiver#onReceive} method will be called with
1662 * the result values collected from the other receivers. The broadcast will
1663 * be serialized in the same way as calling
1664 * {@link #sendOrderedBroadcast(Intent, String)}.
1665 *
1666 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1667 * asynchronous; it will return before
1668 * resultReceiver.onReceive() is called. Note that the sticky data
1669 * stored is only the data you initially supply to the broadcast, not
1670 * the result of any changes made by the receivers.
1671 *
1672 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1673 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001674 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1675 * can access them), no protection (anyone can modify them), and many other problems.
1676 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1677 * has changed, with another mechanism for apps to retrieve the current value whenever
1678 * desired.
1679 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001680 * @param intent The Intent to broadcast; all receivers matching this
1681 * Intent will receive the broadcast.
1682 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1683 * receiver of the broadcast.
1684 * @param scheduler A custom Handler with which to schedule the
1685 * resultReceiver callback; if null it will be
1686 * scheduled in the Context's main thread.
1687 * @param initialCode An initial value for the result code. Often
1688 * Activity.RESULT_OK.
1689 * @param initialData An initial value for the result data. Often
1690 * null.
1691 * @param initialExtras An initial value for the result extras. Often
1692 * null.
1693 *
1694 * @see #sendBroadcast(Intent)
1695 * @see #sendBroadcast(Intent, String)
1696 * @see #sendOrderedBroadcast(Intent, String)
1697 * @see #sendStickyBroadcast(Intent)
1698 * @see android.content.BroadcastReceiver
1699 * @see #registerReceiver
1700 * @see android.app.Activity#RESULT_OK
1701 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001702 @Deprecated
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001703 public abstract void sendStickyOrderedBroadcast(Intent intent,
1704 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001705 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1706 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001707
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001709 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 * so that it is as if the sticky broadcast had never happened.
1711 *
1712 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1713 * permission in order to use this API. If you do not hold that
1714 * permission, {@link SecurityException} will be thrown.
1715 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001716 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1717 * can access them), no protection (anyone can modify them), and many other problems.
1718 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1719 * has changed, with another mechanism for apps to retrieve the current value whenever
1720 * desired.
1721 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 * @param intent The Intent that was previously broadcast.
1723 *
1724 * @see #sendStickyBroadcast
1725 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001726 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001727 public abstract void removeStickyBroadcast(Intent intent);
1728
1729 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001730 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001731 * user the broadcast will be sent to. This is not available to applications
1732 * that are not pre-installed on the system image. Using it requires holding
1733 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001734 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001735 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1736 * can access them), no protection (anyone can modify them), and many other problems.
1737 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1738 * has changed, with another mechanism for apps to retrieve the current value whenever
1739 * desired.
1740 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001741 * @param intent The Intent to broadcast; all receivers matching this
1742 * Intent will receive the broadcast, and the Intent will be held to
1743 * be re-broadcast to future receivers.
1744 * @param user UserHandle to send the intent to.
1745 *
1746 * @see #sendBroadcast(Intent)
1747 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001748 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001749 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1750
1751 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001752 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07001753 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1754 * that allows you to specify the
1755 * user the broadcast will be sent to. This is not available to applications
1756 * that are not pre-installed on the system image. Using it requires holding
1757 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001758 *
1759 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1760 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001761 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1762 * can access them), no protection (anyone can modify them), and many other problems.
1763 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1764 * has changed, with another mechanism for apps to retrieve the current value whenever
1765 * desired.
1766 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001767 * @param intent The Intent to broadcast; all receivers matching this
1768 * Intent will receive the broadcast.
1769 * @param user UserHandle to send the intent to.
1770 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1771 * receiver of the broadcast.
1772 * @param scheduler A custom Handler with which to schedule the
1773 * resultReceiver callback; if null it will be
1774 * scheduled in the Context's main thread.
1775 * @param initialCode An initial value for the result code. Often
1776 * Activity.RESULT_OK.
1777 * @param initialData An initial value for the result data. Often
1778 * null.
1779 * @param initialExtras An initial value for the result extras. Often
1780 * null.
1781 *
1782 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1783 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001784 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001785 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1786 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001787 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1788 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001789
1790 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001791 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001792 * user the broadcast will be sent to. This is not available to applications
1793 * that are not pre-installed on the system image. Using it requires holding
1794 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001795 *
1796 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1797 * permission in order to use this API. If you do not hold that
1798 * permission, {@link SecurityException} will be thrown.
1799 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001800 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1801 * can access them), no protection (anyone can modify them), and many other problems.
1802 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1803 * has changed, with another mechanism for apps to retrieve the current value whenever
1804 * desired.
1805 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001806 * @param intent The Intent that was previously broadcast.
1807 * @param user UserHandle to remove the sticky broadcast from.
1808 *
1809 * @see #sendStickyBroadcastAsUser
1810 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001811 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001812 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1813
1814 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07001815 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 * <var>receiver</var> will be called with any broadcast Intent that
1817 * matches <var>filter</var>, in the main application thread.
1818 *
1819 * <p>The system may broadcast Intents that are "sticky" -- these stay
1820 * around after the broadcast as finished, to be sent to any later
1821 * registrations. If your IntentFilter matches one of these sticky
1822 * Intents, that Intent will be returned by this function
1823 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1824 * been broadcast.
1825 *
1826 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1827 * in which case each of these will be sent to <var>receiver</var>. In
1828 * this case, only one of these can be returned directly by the function;
1829 * which of these that is returned is arbitrarily decided by the system.
1830 *
1831 * <p>If you know the Intent your are registering for is sticky, you can
1832 * supply null for your <var>receiver</var>. In this case, no receiver is
1833 * registered -- the function simply returns the sticky Intent that
1834 * matches <var>filter</var>. In the case of multiple matches, the same
1835 * rules as described above apply.
1836 *
1837 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1838 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001839 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1840 * registered with this method will correctly respect the
1841 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1842 * Prior to that, it would be ignored and delivered to all matching registered
1843 * receivers. Be careful if using this for security.</p>
1844 *
Chris Tatea34df8a22009-04-02 23:15:58 -07001845 * <p class="note">Note: this method <em>cannot be called from a
1846 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1847 * that is declared in an application's manifest. It is okay, however, to call
1848 * this method from another BroadcastReceiver that has itself been registered
1849 * at run time with {@link #registerReceiver}, since the lifetime of such a
1850 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001851 *
1852 * @param receiver The BroadcastReceiver to handle the broadcast.
1853 * @param filter Selects the Intent broadcasts to be received.
1854 *
1855 * @return The first sticky intent found that matches <var>filter</var>,
1856 * or null if there are none.
1857 *
1858 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1859 * @see #sendBroadcast
1860 * @see #unregisterReceiver
1861 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001862 @Nullable
1863 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001864 IntentFilter filter);
1865
1866 /**
1867 * Register to receive intent broadcasts, to run in the context of
1868 * <var>scheduler</var>. See
1869 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1870 * information. This allows you to enforce permissions on who can
1871 * broadcast intents to your receiver, or have the receiver run in
1872 * a different thread than the main application thread.
1873 *
1874 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1875 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001876 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1877 * registered with this method will correctly respect the
1878 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1879 * Prior to that, it would be ignored and delivered to all matching registered
1880 * receivers. Be careful if using this for security.</p>
1881 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882 * @param receiver The BroadcastReceiver to handle the broadcast.
1883 * @param filter Selects the Intent broadcasts to be received.
1884 * @param broadcastPermission String naming a permissions that a
1885 * broadcaster must hold in order to send an Intent to you. If null,
1886 * no permission is required.
1887 * @param scheduler Handler identifying the thread that will receive
1888 * the Intent. If null, the main thread of the process will be used.
1889 *
1890 * @return The first sticky intent found that matches <var>filter</var>,
1891 * or null if there are none.
1892 *
1893 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1894 * @see #sendBroadcast
1895 * @see #unregisterReceiver
1896 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001897 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001899 IntentFilter filter, @Nullable String broadcastPermission,
1900 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07001901
1902 /**
1903 * @hide
1904 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1905 * but for a specific user. This receiver will receiver broadcasts that
1906 * are sent to the requested user. It
1907 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1908 * permission.
1909 *
1910 * @param receiver The BroadcastReceiver to handle the broadcast.
1911 * @param user UserHandle to send the intent to.
1912 * @param filter Selects the Intent broadcasts to be received.
1913 * @param broadcastPermission String naming a permissions that a
1914 * broadcaster must hold in order to send an Intent to you. If null,
1915 * no permission is required.
1916 * @param scheduler Handler identifying the thread that will receive
1917 * the Intent. If null, the main thread of the process will be used.
1918 *
1919 * @return The first sticky intent found that matches <var>filter</var>,
1920 * or null if there are none.
1921 *
Jeff Brown6e539312015-02-24 18:53:21 -08001922 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07001923 * @see #sendBroadcast
1924 * @see #unregisterReceiver
1925 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001926 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07001927 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001928 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1929 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930
1931 /**
1932 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1933 * filters that have been registered for this BroadcastReceiver will be
1934 * removed.
1935 *
1936 * @param receiver The BroadcastReceiver to unregister.
1937 *
1938 * @see #registerReceiver
1939 */
1940 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1941
1942 /**
1943 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07001944 * should contain either contain the complete class name of a specific service
1945 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07001946 * Intent is less specified, it log a warning about this and which of the
1947 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001948 * is not already running, it will be instantiated and started (creating a
1949 * process for it if needed); if it is running then it remains running.
1950 *
1951 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001952 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 * with the <var>intent</var> given here. This provides a convenient way
1954 * to submit jobs to a service without having to bind and call on to its
1955 * interface.
1956 *
1957 * <p>Using startService() overrides the default service lifetime that is
1958 * managed by {@link #bindService}: it requires the service to remain
1959 * running until {@link #stopService} is called, regardless of whether
1960 * any clients are connected to it. Note that calls to startService()
1961 * are not nesting: no matter how many times you call startService(),
1962 * a single call to {@link #stopService} will stop it.
1963 *
1964 * <p>The system attempts to keep running services around as much as
1965 * possible. The only time they should be stopped is if the current
1966 * foreground application is using so many resources that the service needs
1967 * to be killed. If any errors happen in the service's process, it will
1968 * automatically be restarted.
1969 *
1970 * <p>This function will throw {@link SecurityException} if you do not
1971 * have permission to start the given service.
1972 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07001973 * @param service Identifies the service to be started. The Intent must be either
1974 * fully explicit (supplying a component name) or specify a specific package
1975 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 * may be included in the Intent extras to supply arguments along with
1977 * this specific start call.
1978 *
1979 * @return If the service is being started or is already running, the
1980 * {@link ComponentName} of the actual service that was started is
1981 * returned; else if the service does not exist null is returned.
1982 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001983 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 *
1985 * @see #stopService
1986 * @see #bindService
1987 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001988 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 public abstract ComponentName startService(Intent service);
1990
1991 /**
1992 * Request that a given application service be stopped. If the service is
1993 * not running, nothing happens. Otherwise it is stopped. Note that calls
1994 * to startService() are not counted -- this stops the service no matter
1995 * how many times it was started.
1996 *
1997 * <p>Note that if a stopped service still has {@link ServiceConnection}
1998 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
1999 * not be destroyed until all of these bindings are removed. See
2000 * the {@link android.app.Service} documentation for more details on a
2001 * service's lifecycle.
2002 *
2003 * <p>This function will throw {@link SecurityException} if you do not
2004 * have permission to stop the given service.
2005 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002006 * @param service Description of the service to be stopped. The Intent must be either
2007 * fully explicit (supplying a component name) or specify a specific package
2008 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009 *
2010 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002011 * 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 -08002012 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002013 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 *
2015 * @see #startService
2016 */
2017 public abstract boolean stopService(Intent service);
2018
2019 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002020 * @hide like {@link #startService(Intent)} but for a specific user.
2021 */
2022 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2023
2024 /**
2025 * @hide like {@link #stopService(Intent)} but for a specific user.
2026 */
2027 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002028
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002029 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 * Connect to an application service, creating it if needed. This defines
2031 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002032 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 * told if it dies and restarts. The service will be considered required
2034 * by the system only for as long as the calling context exists. For
2035 * example, if this Context is an Activity that is stopped, the service will
2036 * not be required to continue running until the Activity is resumed.
2037 *
2038 * <p>This function will throw {@link SecurityException} if you do not
2039 * have permission to bind to the given service.
2040 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002041 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002043 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002044 * {@link #startService} with the arguments containing the command to be
2045 * sent, with the service calling its
2046 * {@link android.app.Service#stopSelf(int)} method when done executing
2047 * that command. See the API demo App/Service/Service Start Arguments
2048 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002049 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2051 * is tied to another object (the one that registered it).</p>
2052 *
2053 * @param service Identifies the service to connect to. The Intent may
2054 * specify either an explicit component name, or a logical
2055 * description (action, category, etc) to match an
2056 * {@link IntentFilter} published by a service.
2057 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002058 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002059 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002060 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2061 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2062 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2063 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002064 * @return If you have successfully bound to the service, {@code true} is returned;
2065 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 * receive the service object.
2067 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002068 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 *
2070 * @see #unbindService
2071 * @see #startService
2072 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002073 * @see #BIND_DEBUG_UNBIND
2074 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002076 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
2077 @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078
2079 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002080 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002081 * argument for use by system server and other multi-user aware code.
2082 * @hide
2083 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002084 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002085 @SuppressWarnings("unused")
2086 public boolean bindServiceAsUser(Intent service, ServiceConnection conn,
2087 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002088 throw new RuntimeException("Not implemented. Must override in a subclass.");
2089 }
2090
2091 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 * Disconnect from an application service. You will no longer receive
2093 * calls as the service is restarted, and the service is now allowed to
2094 * stop at any time.
2095 *
2096 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002097 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 *
2099 * @see #bindService
2100 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002101 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102
2103 /**
2104 * Start executing an {@link android.app.Instrumentation} class. The given
2105 * Instrumentation component will be run by killing its target application
2106 * (if currently running), starting the target process, instantiating the
2107 * instrumentation component, and then letting it drive the application.
2108 *
2109 * <p>This function is not synchronous -- it returns as soon as the
2110 * instrumentation has started and while it is running.
2111 *
2112 * <p>Instrumentation is normally only allowed to run against a package
2113 * that is either unsigned or signed with a signature that the
2114 * the instrumentation package is also signed with (ensuring the target
2115 * trusts the instrumentation).
2116 *
2117 * @param className Name of the Instrumentation component to be run.
2118 * @param profileFile Optional path to write profiling data as the
2119 * instrumentation runs, or null for no profiling.
2120 * @param arguments Additional optional arguments to pass to the
2121 * instrumentation, or null.
2122 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002123 * @return {@code true} if the instrumentation was successfully started,
2124 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002125 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002126 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2127 @Nullable String profileFile, @Nullable Bundle arguments);
2128
2129 /** @hide */
2130 @StringDef({
2131 POWER_SERVICE,
2132 WINDOW_SERVICE,
2133 LAYOUT_INFLATER_SERVICE,
2134 ACCOUNT_SERVICE,
2135 ACTIVITY_SERVICE,
2136 ALARM_SERVICE,
2137 NOTIFICATION_SERVICE,
2138 ACCESSIBILITY_SERVICE,
2139 CAPTIONING_SERVICE,
2140 KEYGUARD_SERVICE,
2141 LOCATION_SERVICE,
2142 //@hide: COUNTRY_DETECTOR,
2143 SEARCH_SERVICE,
2144 SENSOR_SERVICE,
2145 STORAGE_SERVICE,
2146 WALLPAPER_SERVICE,
2147 VIBRATOR_SERVICE,
2148 //@hide: STATUS_BAR_SERVICE,
2149 CONNECTIVITY_SERVICE,
2150 //@hide: UPDATE_LOCK_SERVICE,
2151 //@hide: NETWORKMANAGEMENT_SERVICE,
2152 //@hide: NETWORK_STATS_SERVICE,
2153 //@hide: NETWORK_POLICY_SERVICE,
2154 WIFI_SERVICE,
Yuhao Zhenga4864472014-04-10 11:45:42 -07002155 WIFI_PASSPOINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002156 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002157 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002158 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002159 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002160 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002161 NSD_SERVICE,
2162 AUDIO_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002163 //@hide: FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002164 MEDIA_ROUTER_SERVICE,
2165 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002166 TELEPHONY_SUBSCRIPTION_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002167 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002168 CLIPBOARD_SERVICE,
2169 INPUT_METHOD_SERVICE,
2170 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002171 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002172 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002173 //@hide: BACKUP_SERVICE,
2174 DROPBOX_SERVICE,
2175 DEVICE_POLICY_SERVICE,
2176 UI_MODE_SERVICE,
2177 DOWNLOAD_SERVICE,
2178 NFC_SERVICE,
2179 BLUETOOTH_SERVICE,
2180 //@hide: SIP_SERVICE,
2181 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002182 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002183 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002184 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002185 INPUT_SERVICE,
2186 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002187 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002188 RESTRICTIONS_SERVICE,
2189 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002190 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002191 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002192 CONSUMER_IR_SERVICE,
2193 //@hide: TRUST_SERVICE,
2194 TV_INPUT_SERVICE,
2195 //@hide: NETWORK_SCORE_SERVICE,
2196 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002197 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002198 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002199 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002200 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002201 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002202 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002203 RADIO_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002204 })
2205 @Retention(RetentionPolicy.SOURCE)
2206 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207
2208 /**
2209 * Return the handle to a system-level service by name. The class of the
2210 * returned object varies by the requested name. Currently available names
2211 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002212 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213 * <dl>
2214 * <dt> {@link #WINDOW_SERVICE} ("window")
2215 * <dd> The top-level window manager in which you can place custom
2216 * windows. The returned object is a {@link android.view.WindowManager}.
2217 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2218 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2219 * in this context.
2220 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2221 * <dd> A {@link android.app.ActivityManager} for interacting with the
2222 * global activity state of the system.
2223 * <dt> {@link #POWER_SERVICE} ("power")
2224 * <dd> A {@link android.os.PowerManager} for controlling power
2225 * management.
2226 * <dt> {@link #ALARM_SERVICE} ("alarm")
2227 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2228 * time of your choosing.
2229 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2230 * <dd> A {@link android.app.NotificationManager} for informing the user
2231 * of background events.
2232 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2233 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2234 * <dt> {@link #LOCATION_SERVICE} ("location")
2235 * <dd> A {@link android.location.LocationManager} for controlling location
2236 * (e.g., GPS) updates.
2237 * <dt> {@link #SEARCH_SERVICE} ("search")
2238 * <dd> A {@link android.app.SearchManager} for handling search.
2239 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2240 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2241 * hardware.
2242 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2243 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2244 * handling management of network connections.
2245 * <dt> {@link #WIFI_SERVICE} ("wifi")
2246 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2247 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002248 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2249 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2250 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2252 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2253 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002254 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2255 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002256 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002257 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002258 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002259 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002260 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2261 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002263 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002264 * <p>Note: System services obtained via this API may be closely associated with
2265 * the Context in which they are obtained from. In general, do not share the
2266 * service objects between various different contexts (Activities, Applications,
2267 * Services, Providers, etc.)
2268 *
2269 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002270 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002272 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 * @see #WINDOW_SERVICE
2274 * @see android.view.WindowManager
2275 * @see #LAYOUT_INFLATER_SERVICE
2276 * @see android.view.LayoutInflater
2277 * @see #ACTIVITY_SERVICE
2278 * @see android.app.ActivityManager
2279 * @see #POWER_SERVICE
2280 * @see android.os.PowerManager
2281 * @see #ALARM_SERVICE
2282 * @see android.app.AlarmManager
2283 * @see #NOTIFICATION_SERVICE
2284 * @see android.app.NotificationManager
2285 * @see #KEYGUARD_SERVICE
2286 * @see android.app.KeyguardManager
2287 * @see #LOCATION_SERVICE
2288 * @see android.location.LocationManager
2289 * @see #SEARCH_SERVICE
2290 * @see android.app.SearchManager
2291 * @see #SENSOR_SERVICE
2292 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002293 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002294 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 * @see #VIBRATOR_SERVICE
2296 * @see android.os.Vibrator
2297 * @see #CONNECTIVITY_SERVICE
2298 * @see android.net.ConnectivityManager
2299 * @see #WIFI_SERVICE
2300 * @see android.net.wifi.WifiManager
2301 * @see #AUDIO_SERVICE
2302 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002303 * @see #MEDIA_ROUTER_SERVICE
2304 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002305 * @see #TELEPHONY_SERVICE
2306 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002307 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2308 * @see android.telephony.SubscriptionManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002309 * @see #INPUT_METHOD_SERVICE
2310 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002311 * @see #UI_MODE_SERVICE
2312 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002313 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002314 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002315 * @see #BATTERY_SERVICE
2316 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002317 * @see #JOB_SCHEDULER_SERVICE
2318 * @see android.app.job.JobScheduler
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002320 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002321
2322 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002323 * Return the handle to a system-level service by class.
2324 * <p>
2325 * Currently available classes are:
2326 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2327 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2328 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2329 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2330 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2331 * {@link android.net.ConnectivityManager},
2332 * {@link android.net.wifi.WifiManager},
2333 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2334 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2335 * {@link android.view.inputmethod.InputMethodManager},
2336 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
2337 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler}.
2338 * </p><p>
2339 * Note: System services obtained via this API may be closely associated with
2340 * the Context in which they are obtained from. In general, do not share the
2341 * service objects between various different contexts (Activities, Applications,
2342 * Services, Providers, etc.)
2343 * </p>
2344 *
2345 * @param serviceClass The class of the desired service.
2346 * @return The service or null if the class is not a supported system service.
2347 */
2348 @SuppressWarnings("unchecked")
2349 public final <T> T getSystemService(Class<T> serviceClass) {
2350 // Because subclasses may override getSystemService(String) we cannot
2351 // perform a lookup by class alone. We must first map the class to its
2352 // service name then invoke the string-based method.
2353 String serviceName = getSystemServiceName(serviceClass);
2354 return serviceName != null ? (T)getSystemService(serviceName) : null;
2355 }
2356
2357 /**
2358 * Gets the name of the system-level service that is represented by the specified class.
2359 *
2360 * @param serviceClass The class of the desired service.
2361 * @return The service name or null if the class is not a supported system service.
2362 *
2363 * @hide
2364 */
2365 public abstract String getSystemServiceName(Class<?> serviceClass);
2366
2367 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 * Use with {@link #getSystemService} to retrieve a
2369 * {@link android.os.PowerManager} for controlling power management,
2370 * including "wake locks," which let you keep the device on while
2371 * you're running long tasks.
2372 */
2373 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002374
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 /**
2376 * Use with {@link #getSystemService} to retrieve a
2377 * {@link android.view.WindowManager} for accessing the system's window
2378 * manager.
2379 *
2380 * @see #getSystemService
2381 * @see android.view.WindowManager
2382 */
2383 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 /**
2386 * Use with {@link #getSystemService} to retrieve a
2387 * {@link android.view.LayoutInflater} for inflating layout resources in this
2388 * context.
2389 *
2390 * @see #getSystemService
2391 * @see android.view.LayoutInflater
2392 */
2393 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002394
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 /**
2396 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002397 * {@link android.accounts.AccountManager} for receiving intents at a
2398 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002399 *
2400 * @see #getSystemService
2401 * @see android.accounts.AccountManager
2402 */
2403 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002404
Fred Quintana60307342009-03-24 22:48:12 -07002405 /**
2406 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 * {@link android.app.ActivityManager} for interacting with the global
2408 * system state.
2409 *
2410 * @see #getSystemService
2411 * @see android.app.ActivityManager
2412 */
2413 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 /**
2416 * Use with {@link #getSystemService} to retrieve a
2417 * {@link android.app.AlarmManager} for receiving intents at a
2418 * time of your choosing.
2419 *
2420 * @see #getSystemService
2421 * @see android.app.AlarmManager
2422 */
2423 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425 /**
2426 * Use with {@link #getSystemService} to retrieve a
2427 * {@link android.app.NotificationManager} for informing the user of
2428 * background events.
2429 *
2430 * @see #getSystemService
2431 * @see android.app.NotificationManager
2432 */
2433 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 /**
2436 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002437 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2438 * feedback for UI events through the registered event listeners.
2439 *
2440 * @see #getSystemService
2441 * @see android.view.accessibility.AccessibilityManager
2442 */
2443 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002444
svetoslavganov75986cf2009-05-14 22:28:01 -07002445 /**
2446 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002447 * {@link android.view.accessibility.CaptioningManager} for obtaining
2448 * captioning properties and listening for changes in captioning
2449 * preferences.
2450 *
2451 * @see #getSystemService
2452 * @see android.view.accessibility.CaptioningManager
2453 */
2454 public static final String CAPTIONING_SERVICE = "captioning";
2455
2456 /**
2457 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002458 * {@link android.app.NotificationManager} for controlling keyguard.
2459 *
2460 * @see #getSystemService
2461 * @see android.app.KeyguardManager
2462 */
2463 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002465 /**
2466 * Use with {@link #getSystemService} to retrieve a {@link
2467 * android.location.LocationManager} for controlling location
2468 * updates.
2469 *
2470 * @see #getSystemService
2471 * @see android.location.LocationManager
2472 */
2473 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002474
2475 /**
2476 * Use with {@link #getSystemService} to retrieve a
2477 * {@link android.location.CountryDetector} for detecting the country that
2478 * the user is in.
2479 *
2480 * @hide
2481 */
2482 public static final String COUNTRY_DETECTOR = "country_detector";
2483
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002484 /**
2485 * Use with {@link #getSystemService} to retrieve a {@link
2486 * android.app.SearchManager} for handling searches.
2487 *
2488 * @see #getSystemService
2489 * @see android.app.SearchManager
2490 */
2491 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002492
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002493 /**
2494 * Use with {@link #getSystemService} to retrieve a {@link
2495 * android.hardware.SensorManager} for accessing sensors.
2496 *
2497 * @see #getSystemService
2498 * @see android.hardware.SensorManager
2499 */
2500 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07002501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 /**
San Mehatc9d81752010-02-01 10:23:27 -08002503 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07002504 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08002505 * functions.
2506 *
2507 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08002508 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08002509 */
2510 public static final String STORAGE_SERVICE = "storage";
2511
2512 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 * Use with {@link #getSystemService} to retrieve a
2514 * com.android.server.WallpaperService for accessing wallpapers.
2515 *
2516 * @see #getSystemService
2517 */
2518 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07002519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002520 /**
2521 * Use with {@link #getSystemService} to retrieve a {@link
2522 * android.os.Vibrator} for interacting with the vibration hardware.
2523 *
2524 * @see #getSystemService
2525 * @see android.os.Vibrator
2526 */
2527 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002528
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 /**
2530 * Use with {@link #getSystemService} to retrieve a {@link
2531 * android.app.StatusBarManager} for interacting with the status bar.
2532 *
2533 * @see #getSystemService
2534 * @see android.app.StatusBarManager
2535 * @hide
2536 */
2537 public static final String STATUS_BAR_SERVICE = "statusbar";
2538
2539 /**
2540 * Use with {@link #getSystemService} to retrieve a {@link
2541 * android.net.ConnectivityManager} for handling management of
2542 * network connections.
2543 *
2544 * @see #getSystemService
2545 * @see android.net.ConnectivityManager
2546 */
2547 public static final String CONNECTIVITY_SERVICE = "connectivity";
2548
2549 /**
2550 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002551 * android.os.IUpdateLock} for managing runtime sequences that
2552 * must not be interrupted by headless OTA application or similar.
2553 *
2554 * @hide
2555 * @see #getSystemService
2556 * @see android.os.UpdateLock
2557 */
2558 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2559
2560 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002561 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07002562 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08002563 */
2564 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2565
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002566 /** {@hide} */
Jeff Sharkey75279902011-05-24 18:39:45 -07002567 public static final String NETWORK_STATS_SERVICE = "netstats";
2568 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002569 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2570
San Mehatd1df8ac2010-01-26 06:17:26 -08002571 /**
2572 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 * android.net.wifi.WifiManager} for handling management of
2574 * Wi-Fi access.
2575 *
2576 * @see #getSystemService
2577 * @see android.net.wifi.WifiManager
2578 */
2579 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002581 /**
repo sync55bc5f32011-06-24 14:23:07 -07002582 * Use with {@link #getSystemService} to retrieve a {@link
Roger Chang7fee7232014-05-15 14:46:49 -07002583 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
Yuhao Zhenga4864472014-04-10 11:45:42 -07002584 * Wi-Fi passpoint access.
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002585 *
2586 * @see #getSystemService
Roger Chang7fee7232014-05-15 14:46:49 -07002587 * @see android.net.wifi.passpoint.WifiPasspointManager
Yuhao Zheng0cb59f22014-05-27 10:35:02 -07002588 * @hide
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002589 */
Yuhao Zhenga4864472014-04-10 11:45:42 -07002590 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002591
2592 /**
2593 * Use with {@link #getSystemService} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07002594 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002595 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002596 *
2597 * @see #getSystemService
2598 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002599 */
2600 public static final String WIFI_P2P_SERVICE = "wifip2p";
2601
2602 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002603 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002604 * android.net.wifi.WifiScanner} for scanning the wifi universe
2605 *
2606 * @see #getSystemService
2607 * @see android.net.wifi.WifiScanner
2608 * @hide
2609 */
Wei Wang35d552f2014-07-08 21:37:01 -07002610 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002611 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2612
2613 /**
2614 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07002615 * android.net.wifi.RttManager} for ranging devices with wifi
2616 *
2617 * @see #getSystemService
2618 * @see android.net.wifi.RttManager
2619 * @hide
2620 */
2621 @SystemApi
2622 public static final String WIFI_RTT_SERVICE = "rttmanager";
2623
2624 /**
2625 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002626 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002627 * Ethernet access.
2628 *
2629 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002630 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002631 *
2632 * @hide
2633 */
2634 public static final String ETHERNET_SERVICE = "ethernet";
2635
2636 /**
2637 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002638 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002639 * discovery
2640 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002641 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002642 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002643 */
2644 public static final String NSD_SERVICE = "servicediscovery";
2645
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002646 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 * Use with {@link #getSystemService} to retrieve a
2648 * {@link android.media.AudioManager} for handling management of volume,
2649 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002650 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 * @see #getSystemService
2652 * @see android.media.AudioManager
2653 */
2654 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002656 /**
2657 * Use with {@link #getSystemService} to retrieve a
Jim Miller08fa40c2014-04-29 18:18:47 -07002658 * {@link android.service.fingerprint.FingerprintManager} for handling management
2659 * of fingerprints.
2660 *
2661 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08002662 * @see android.service.fingerprint.FingerprintManager
Jim Miller777f5b22014-08-25 15:03:50 -07002663 * @hide
Jim Miller08fa40c2014-04-29 18:18:47 -07002664 */
2665 public static final String FINGERPRINT_SERVICE = "fingerprint";
2666
2667 /**
2668 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002669 * {@link android.media.MediaRouter} for controlling and managing
2670 * routing of media.
2671 *
2672 * @see #getSystemService
2673 * @see android.media.MediaRouter
2674 */
2675 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2676
2677 /**
2678 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07002679 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08002680 *
2681 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07002682 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08002683 */
2684 public static final String MEDIA_SESSION_SERVICE = "media_session";
2685
2686 /**
2687 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 * {@link android.telephony.TelephonyManager} for handling management the
2689 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002690 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 * @see #getSystemService
2692 * @see android.telephony.TelephonyManager
2693 */
2694 public static final String TELEPHONY_SERVICE = "phone";
2695
2696 /**
2697 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08002698 * {@link android.telephony.SubscriptionManager} for handling management the
2699 * telephony subscriptions of the device.
2700 *
2701 * @see #getSystemService
2702 * @see android.telephony.SubscriptionManager
2703 */
2704 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
2705
2706 /**
2707 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002708 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07002709 * of the device.
2710 *
2711 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002712 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07002713 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002714 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07002715
2716 /**
2717 * Use with {@link #getSystemService} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08002718 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002719 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002720 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002721 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08002722 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002723 */
2724 public static final String CLIPBOARD_SERVICE = "clipboard";
2725
2726 /**
Scott Main4b5da682010-10-21 11:49:12 -07002727 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2729 * methods.
2730 *
2731 * @see #getSystemService
2732 */
2733 public static final String INPUT_METHOD_SERVICE = "input_method";
2734
2735 /**
2736 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002737 * {@link android.view.textservice.TextServicesManager} for accessing
2738 * text services.
2739 *
2740 * @see #getSystemService
2741 */
2742 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2743
2744 /**
2745 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002746 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 * @see #getSystemService
2749 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002750 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07002753 * Official published name of the (internal) voice interaction manager service.
2754 *
2755 * @hide
2756 * @see #getSystemService
2757 */
2758 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2759
2760 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002761 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002762 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002763 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002764 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002765 *
Christopher Tate487529a2009-04-29 14:03:25 -07002766 * @see #getSystemService
2767 */
Christopher Tated5cf7222014-07-29 16:53:09 -07002768 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07002769 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002770
2771 /**
2772 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002773 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002774 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002775 * @see #getSystemService
2776 */
2777 public static final String DROPBOX_SERVICE = "dropbox";
2778
Christopher Tate487529a2009-04-29 14:03:25 -07002779 /**
Scott Main4b5da682010-10-21 11:49:12 -07002780 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002781 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002782 * device policy management.
2783 *
2784 * @see #getSystemService
2785 */
2786 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2787
2788 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002789 * Use with {@link #getSystemService} to retrieve a
2790 * {@link android.app.UiModeManager} for controlling UI modes.
2791 *
2792 * @see #getSystemService
2793 */
2794 public static final String UI_MODE_SERVICE = "uimode";
2795
2796 /**
Steve Howarda2709362010-07-02 17:12:48 -07002797 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002798 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002799 *
2800 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002801 */
2802 public static final String DOWNLOAD_SERVICE = "download";
2803
2804 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002805 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08002806 * {@link android.os.BatteryManager} for managing battery state.
2807 *
2808 * @see #getSystemService
2809 */
2810 public static final String BATTERY_SERVICE = "batterymanager";
2811
2812 /**
2813 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002814 * {@link android.nfc.NfcManager} for using NFC.
2815 *
2816 * @see #getSystemService
2817 */
2818 public static final String NFC_SERVICE = "nfc";
2819
2820 /**
2821 * Use with {@link #getSystemService} to retrieve a
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002822 * {@link android.bluetooth.BluetoothAdapter} for using Bluetooth.
2823 *
2824 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002825 */
2826 public static final String BLUETOOTH_SERVICE = "bluetooth";
2827
2828 /**
2829 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002830 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2831 *
2832 * @see #getSystemService
2833 */
2834 /** @hide */
2835 public static final String SIP_SERVICE = "sip";
2836
2837 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002838 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002839 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002840 * and for controlling this device's behavior as a USB device.
2841 *
2842 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04002843 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002844 */
2845 public static final String USB_SERVICE = "usb";
2846
2847 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002848 * Use with {@link #getSystemService} to retrieve a {@link
2849 * android.hardware.SerialManager} for access to serial ports.
2850 *
2851 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002852 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002853 *
2854 * @hide
2855 */
2856 public static final String SERIAL_SERVICE = "serial";
2857
2858 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002859 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09002860 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2861 * HDMI-CEC protocol.
2862 *
2863 * @see #getSystemService
2864 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002865 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09002866 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002867 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09002868 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09002869
2870 /**
2871 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002872 * {@link android.hardware.input.InputManager} for interacting with input devices.
2873 *
2874 * @see #getSystemService
2875 * @see android.hardware.input.InputManager
2876 */
2877 public static final String INPUT_SERVICE = "input";
2878
2879 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002880 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002881 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2882 *
2883 * @see #getSystemService
2884 * @see android.hardware.display.DisplayManager
2885 */
2886 public static final String DISPLAY_SERVICE = "display";
2887
2888 /**
2889 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07002890 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2891 *
2892 * @see #getSystemService
2893 * @see android.os.UserManager
2894 */
2895 public static final String USER_SERVICE = "user";
2896
2897 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002898 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08002899 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
2900 * profiles of a user.
2901 *
2902 * @see #getSystemService
2903 * @see android.content.pm.LauncherApps
2904 */
2905 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
2906
2907 /**
2908 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07002909 * {@link android.content.RestrictionsManager} for retrieving application restrictions
2910 * and requesting permissions for restricted operations.
2911 * @see #getSystemService
2912 * @see android.content.RestrictionsManager
2913 */
2914 public static final String RESTRICTIONS_SERVICE = "restrictions";
2915
2916 /**
2917 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002918 * {@link android.app.AppOpsManager} for tracking application operations
2919 * on the device.
2920 *
2921 * @see #getSystemService
2922 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002923 */
2924 public static final String APP_OPS_SERVICE = "appops";
2925
2926 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002927 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07002928 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002929 * camera devices.
2930 *
2931 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07002932 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002933 */
2934 public static final String CAMERA_SERVICE = "camera";
2935
2936 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002937 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07002938 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002939 *
2940 * @see #getSystemService
2941 * @see android.print.PrintManager
2942 */
2943 public static final String PRINT_SERVICE = "print";
2944
2945 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07002946 * Use with {@link #getSystemService} to retrieve a
2947 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
2948 * signals from the device.
2949 *
2950 * @see #getSystemService
2951 * @see android.hardware.ConsumerIrManager
2952 */
2953 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
2954
2955 /**
Adrian Roos82142c22014-03-27 14:56:59 +01002956 * {@link android.app.trust.TrustManager} for managing trust agents.
2957 * @see #getSystemService
2958 * @see android.app.trust.TrustManager
2959 * @hide
2960 */
2961 public static final String TRUST_SERVICE = "trust";
2962
2963 /**
Jae Seo39570912014-02-20 18:23:25 -08002964 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07002965 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
2966 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08002967 *
2968 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07002969 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08002970 */
2971 public static final String TV_INPUT_SERVICE = "tv_input";
2972
2973 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07002974 * {@link android.net.NetworkScoreManager} for managing network scoring.
2975 * @see #getSystemService
2976 * @see android.net.NetworkScoreManager
2977 * @hide
2978 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07002979 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07002980 public static final String NETWORK_SCORE_SERVICE = "network_score";
2981
2982 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07002983 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08002984 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07002985 *
2986 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08002987 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07002988 */
2989 public static final String USAGE_STATS_SERVICE = "usagestats";
2990
2991 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07002992 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07002993 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07002994 * background tasks.
2995 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07002996 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07002997 */
Christopher Tate7060b042014-06-09 19:50:00 -07002998 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07002999
3000 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003001 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003002 * android.service.persistentdata.PersistentDataBlockManager} instance
3003 * for interacting with a storage device that lives across factory resets.
3004 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003005 * @see #getSystemService
3006 * @see android.service.persistentdata.PersistentDataBlockManager
3007 * @hide
3008 */
Andres Morales33df9372014-09-26 17:08:59 -07003009 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003010 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3011
3012 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003013 * Use with {@link #getSystemService} to retrieve a {@link
3014 * android.media.projection.MediaProjectionManager} instance for managing
3015 * media projection sessions.
3016 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003017 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003018 */
3019 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3020
3021 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003022 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003023 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003024 *
3025 * @see #getSystemService
3026 * @hide
3027 */
3028 public static final String MIDI_SERVICE = "midi";
3029
Eric Laurent2035ac82015-03-05 15:18:44 -08003030
3031 /**
3032 * Use with {@link #getSystemService} to retrieve a
3033 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3034 *
3035 * @see #getSystemService
3036 * @hide
3037 */
3038 public static final String RADIO_SERVICE = "radio";
3039
3040
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003041 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 * Determine whether the given permission is allowed for a particular
3043 * process and user ID running in the system.
3044 *
3045 * @param permission The name of the permission being checked.
3046 * @param pid The process ID being checked against. Must be > 0.
3047 * @param uid The user ID being checked against. A uid of 0 is the root
3048 * user, which will pass every permission check.
3049 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003050 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 * pid/uid is allowed that permission, or
3052 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3053 *
3054 * @see PackageManager#checkPermission(String, String)
3055 * @see #checkCallingPermission
3056 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003057 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003058 @PackageManager.PermissionResult
3059 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060
Dianne Hackbornff170242014-11-19 10:59:01 -08003061 /** @hide */
3062 @PackageManager.PermissionResult
3063 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3064 IBinder callerToken);
3065
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003066 /**
3067 * Determine whether the calling process of an IPC you are handling has been
3068 * granted a particular permission. This is basically the same as calling
3069 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3070 * by {@link android.os.Binder#getCallingPid} and
3071 * {@link android.os.Binder#getCallingUid}. One important difference
3072 * is that if you are not currently processing an IPC, this function
3073 * will always fail. This is done to protect against accidentally
3074 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3075 * to avoid this protection.
3076 *
3077 * @param permission The name of the permission being checked.
3078 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003079 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 * pid/uid is allowed that permission, or
3081 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3082 *
3083 * @see PackageManager#checkPermission(String, String)
3084 * @see #checkPermission
3085 * @see #checkCallingOrSelfPermission
3086 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003087 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003088 @PackageManager.PermissionResult
3089 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003090
3091 /**
3092 * Determine whether the calling process of an IPC <em>or you</em> have been
3093 * granted a particular permission. This is the same as
3094 * {@link #checkCallingPermission}, except it grants your own permissions
3095 * if you are not currently processing an IPC. Use with care!
3096 *
3097 * @param permission The name of the permission being checked.
3098 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003099 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 * pid/uid is allowed that permission, or
3101 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3102 *
3103 * @see PackageManager#checkPermission(String, String)
3104 * @see #checkPermission
3105 * @see #checkCallingPermission
3106 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003107 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003108 @PackageManager.PermissionResult
3109 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110
3111 /**
3112 * If the given permission is not allowed for a particular process
3113 * and user ID running in the system, throw a {@link SecurityException}.
3114 *
3115 * @param permission The name of the permission being checked.
3116 * @param pid The process ID being checked against. Must be &gt; 0.
3117 * @param uid The user ID being checked against. A uid of 0 is the root
3118 * user, which will pass every permission check.
3119 * @param message A message to include in the exception if it is thrown.
3120 *
3121 * @see #checkPermission(String, int, int)
3122 */
3123 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003124 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125
3126 /**
3127 * If the calling process of an IPC you are handling has not been
3128 * granted a particular permission, throw a {@link
3129 * SecurityException}. This is basically the same as calling
3130 * {@link #enforcePermission(String, int, int, String)} with the
3131 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3132 * and {@link android.os.Binder#getCallingUid}. One important
3133 * difference is that if you are not currently processing an IPC,
3134 * this function will always throw the SecurityException. This is
3135 * done to protect against accidentally leaking permissions; you
3136 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3137 * protection.
3138 *
3139 * @param permission The name of the permission being checked.
3140 * @param message A message to include in the exception if it is thrown.
3141 *
3142 * @see #checkCallingPermission(String)
3143 */
3144 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003145 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146
3147 /**
3148 * If neither you nor the calling process of an IPC you are
3149 * handling has been granted a particular permission, throw a
3150 * {@link SecurityException}. This is the same as {@link
3151 * #enforceCallingPermission}, except it grants your own
3152 * permissions if you are not currently processing an IPC. Use
3153 * with care!
3154 *
3155 * @param permission The name of the permission being checked.
3156 * @param message A message to include in the exception if it is thrown.
3157 *
3158 * @see #checkCallingOrSelfPermission(String)
3159 */
3160 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003161 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162
3163 /**
3164 * Grant permission to access a specific Uri to another package, regardless
3165 * of whether that package has general permission to access the Uri's
3166 * content provider. This can be used to grant specific, temporary
3167 * permissions, typically in response to user interaction (such as the
3168 * user opening an attachment that you would like someone else to
3169 * display).
3170 *
3171 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3172 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3173 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3174 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3175 * start an activity instead of this function directly. If you use this
3176 * function directly, you should be sure to call
3177 * {@link #revokeUriPermission} when the target should no longer be allowed
3178 * to access it.
3179 *
3180 * <p>To succeed, the content provider owning the Uri must have set the
3181 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3182 * grantUriPermissions} attribute in its manifest or included the
3183 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3184 * &lt;grant-uri-permissions&gt;} tag.
3185 *
3186 * @param toPackage The package you would like to allow to access the Uri.
3187 * @param uri The Uri you would like to grant access to.
3188 * @param modeFlags The desired access modes. Any combination of
3189 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003190 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003192 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3193 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3194 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3195 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3196 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 *
3198 * @see #revokeUriPermission
3199 */
3200 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003201 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202
3203 /**
3204 * Remove all permissions to access a particular content provider Uri
3205 * that were previously added with {@link #grantUriPermission}. The given
3206 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003207 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003209 * "content://foo". It will not remove any prefix grants that exist at a
3210 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003212 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003213 * regular permission access to a Uri, but had received access to it through
3214 * a specific Uri permission grant, you could not revoke that grant with this
3215 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003216 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003217 * but will remove whatever permission grants to the Uri had been given to the app
3218 * (or none).</p>
3219 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003220 * @param uri The Uri you would like to revoke access to.
3221 * @param modeFlags The desired access modes. Any combination of
3222 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3223 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3224 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3225 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3226 *
3227 * @see #grantUriPermission
3228 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003229 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230
3231 /**
3232 * Determine whether a particular process and user ID has been granted
3233 * permission to access a specific URI. This only checks for permissions
3234 * that have been explicitly granted -- if the given process/uid has
3235 * more general access to the URI's content provider then this check will
3236 * always fail.
3237 *
3238 * @param uri The uri that is being checked.
3239 * @param pid The process ID being checked against. Must be &gt; 0.
3240 * @param uid The user ID being checked against. A uid of 0 is the root
3241 * user, which will pass every permission check.
3242 * @param modeFlags The type of access to grant. May be one or both of
3243 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3244 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3245 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003246 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003247 * pid/uid is allowed to access that uri, or
3248 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3249 *
3250 * @see #checkCallingUriPermission
3251 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003252 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003253 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003254 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003255
Dianne Hackbornff170242014-11-19 10:59:01 -08003256 /** @hide */
3257 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3258 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3259
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 /**
3261 * Determine whether the calling process and user ID has been
3262 * granted permission to access a specific URI. This is basically
3263 * the same as calling {@link #checkUriPermission(Uri, int, int,
3264 * int)} with the pid and uid returned by {@link
3265 * android.os.Binder#getCallingPid} and {@link
3266 * android.os.Binder#getCallingUid}. One important difference is
3267 * that if you are not currently processing an IPC, this function
3268 * will always fail.
3269 *
3270 * @param uri The uri that is being checked.
3271 * @param modeFlags The type of access to grant. May be one or both of
3272 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3273 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3274 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003275 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 * is allowed to access that uri, or
3277 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3278 *
3279 * @see #checkUriPermission(Uri, int, int, int)
3280 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003281 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003282 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283
3284 /**
3285 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3286 * permission to access a specific URI. This is the same as
3287 * {@link #checkCallingUriPermission}, except it grants your own permissions
3288 * if you are not currently processing an IPC. Use with care!
3289 *
3290 * @param uri The uri that is being checked.
3291 * @param modeFlags The type of access to grant. May be one or both of
3292 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3293 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3294 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003295 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 * is allowed to access that uri, or
3297 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3298 *
3299 * @see #checkCallingUriPermission
3300 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003301 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003302 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003303 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304
3305 /**
3306 * Check both a Uri and normal permission. This allows you to perform
3307 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3308 * call.
3309 *
3310 * @param uri The Uri whose permission is to be checked, or null to not
3311 * do this check.
3312 * @param readPermission The permission that provides overall read access,
3313 * or null to not do this check.
3314 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003315 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 * @param pid The process ID being checked against. Must be &gt; 0.
3317 * @param uid The user ID being checked against. A uid of 0 is the root
3318 * user, which will pass every permission check.
3319 * @param modeFlags The type of access to grant. May be one or both of
3320 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3321 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3322 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003323 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003324 * is allowed to access that uri or holds one of the given permissions, or
3325 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3326 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003327 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003328 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3329 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003330 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331
3332 /**
3333 * If a particular process and user ID has not been granted
3334 * permission to access a specific URI, throw {@link
3335 * SecurityException}. This only checks for permissions that have
3336 * been explicitly granted -- if the given process/uid has more
3337 * general access to the URI's content provider then this check
3338 * will always fail.
3339 *
3340 * @param uri The uri that is being checked.
3341 * @param pid The process ID being checked against. Must be &gt; 0.
3342 * @param uid The user ID being checked against. A uid of 0 is the root
3343 * user, which will pass every permission check.
3344 * @param modeFlags The type of access to grant. May be one or both of
3345 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3346 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3347 * @param message A message to include in the exception if it is thrown.
3348 *
3349 * @see #checkUriPermission(Uri, int, int, int)
3350 */
3351 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003352 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353
3354 /**
3355 * If the calling process and user ID has not been granted
3356 * permission to access a specific URI, throw {@link
3357 * SecurityException}. This is basically the same as calling
3358 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3359 * the pid and uid returned by {@link
3360 * android.os.Binder#getCallingPid} and {@link
3361 * android.os.Binder#getCallingUid}. One important difference is
3362 * that if you are not currently processing an IPC, this function
3363 * will always throw a SecurityException.
3364 *
3365 * @param uri The uri that is being checked.
3366 * @param modeFlags The type of access to grant. May be one or both of
3367 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3368 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3369 * @param message A message to include in the exception if it is thrown.
3370 *
3371 * @see #checkCallingUriPermission(Uri, int)
3372 */
3373 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003374 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003375
3376 /**
3377 * If the calling process of an IPC <em>or you</em> has not been
3378 * granted permission to access a specific URI, throw {@link
3379 * SecurityException}. This is the same as {@link
3380 * #enforceCallingUriPermission}, except it grants your own
3381 * permissions if you are not currently processing an IPC. Use
3382 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003383 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 * @param uri The uri that is being checked.
3385 * @param modeFlags The type of access to grant. May be one or both of
3386 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3387 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3388 * @param message A message to include in the exception if it is thrown.
3389 *
3390 * @see #checkCallingOrSelfUriPermission(Uri, int)
3391 */
3392 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003393 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394
3395 /**
3396 * Enforce both a Uri and normal permission. This allows you to perform
3397 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3398 * call.
Scott Main4b5da682010-10-21 11:49:12 -07003399 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 * @param uri The Uri whose permission is to be checked, or null to not
3401 * do this check.
3402 * @param readPermission The permission that provides overall read access,
3403 * or null to not do this check.
3404 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003405 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 * @param pid The process ID being checked against. Must be &gt; 0.
3407 * @param uid The user ID being checked against. A uid of 0 is the root
3408 * user, which will pass every permission check.
3409 * @param modeFlags The type of access to grant. May be one or both of
3410 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3411 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3412 * @param message A message to include in the exception if it is thrown.
3413 *
3414 * @see #checkUriPermission(Uri, String, String, int, int, int)
3415 */
3416 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003417 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003418 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07003419 @Nullable String message);
3420
3421 /** @hide */
3422 @IntDef(flag = true,
3423 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3424 @Retention(RetentionPolicy.SOURCE)
3425 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426
3427 /**
3428 * Flag for use with {@link #createPackageContext}: include the application
3429 * code with the context. This means loading code into the caller's
3430 * process, so that {@link #getClassLoader()} can be used to instantiate
3431 * the application's classes. Setting this flags imposes security
3432 * restrictions on what application context you can access; if the
3433 * requested application can not be safely loaded into your process,
3434 * java.lang.SecurityException will be thrown. If this flag is not set,
3435 * there will be no restrictions on the packages that can be loaded,
3436 * but {@link #getClassLoader} will always return the default system
3437 * class loader.
3438 */
3439 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3440
3441 /**
3442 * Flag for use with {@link #createPackageContext}: ignore any security
3443 * restrictions on the Context being requested, allowing it to always
3444 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3445 * to be loaded into a process even when it isn't safe to do so. Use
3446 * with extreme care!
3447 */
3448 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07003449
Romain Guy870e09f2009-07-06 16:35:25 -07003450 /**
3451 * Flag for use with {@link #createPackageContext}: a restricted context may
3452 * disable specific features. For instance, a View associated with a restricted
3453 * context would ignore particular XML attributes.
3454 */
3455 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003456
3457 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003458 * @hide Used to indicate we should tell the activity manager about the process
3459 * loading this code.
3460 */
3461 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
3462
3463 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003464 * Return a new Context object for the given application name. This
3465 * Context is the same as what the named application gets when it is
3466 * launched, containing the same resources and class loader. Each call to
3467 * this method returns a new instance of a Context object; Context objects
3468 * are not shared, however they share common state (Resources, ClassLoader,
3469 * etc) so the Context instance itself is fairly lightweight.
3470 *
Jeff Brown6e539312015-02-24 18:53:21 -08003471 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 * application with the given package name.
3473 *
3474 * <p>Throws {@link java.lang.SecurityException} if the Context requested
3475 * can not be loaded into the caller's process for security reasons (see
3476 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3477 *
3478 * @param packageName Name of the application's package.
3479 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3480 * or {@link #CONTEXT_IGNORE_SECURITY}.
3481 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003482 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003483 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003484 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04003486 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 */
3488 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07003489 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07003490
3491 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07003492 * Similar to {@link #createPackageContext(String, int)}, but with a
3493 * different {@link UserHandle}. For example, {@link #getContentResolver()}
3494 * will open any {@link Uri} as the given user.
3495 *
3496 * @hide
3497 */
3498 public abstract Context createPackageContextAsUser(
3499 String packageName, int flags, UserHandle user)
3500 throws PackageManager.NameNotFoundException;
3501
3502 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07003503 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
3504 *
3505 * @hide
3506 */
3507 public abstract Context createApplicationContext(ApplicationInfo application,
3508 int flags) throws PackageManager.NameNotFoundException;
3509
3510 /**
Jim Millera75a8832013-02-07 16:53:32 -08003511 * Get the userId associated with this context
3512 * @return user id
3513 *
3514 * @hide
3515 */
3516 public abstract int getUserId();
3517
3518 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07003519 * Return a new Context object for the current Context but whose resources
3520 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07003521 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07003522 * shared, however common state (ClassLoader, other Resources for the
3523 * same configuration) may be so the Context itself can be fairly lightweight.
3524 *
3525 * @param overrideConfiguration A {@link Configuration} specifying what
3526 * values to modify in the base Configuration of the original Context's
3527 * resources. If the base configuration changes (such as due to an
3528 * orientation change), the resources of this context will also change except
3529 * for those that have been explicitly overridden with a value here.
3530 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003531 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07003532 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003533 public abstract Context createConfigurationContext(
3534 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07003535
3536 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07003537 * Return a new Context object for the current Context but whose resources
3538 * are adjusted to match the metrics of the given Display. Each call to this method
3539 * returns a new instance of a Context object; Context objects are not
3540 * shared, however common state (ClassLoader, other Resources for the
3541 * same configuration) may be so the Context itself can be fairly lightweight.
3542 *
3543 * The returned display Context provides a {@link WindowManager}
3544 * (see {@link #getSystemService(String)}) that is configured to show windows
3545 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
3546 * method can be used to retrieve the Display from the returned Context.
3547 *
3548 * @param display A {@link Display} object specifying the display
3549 * for whose metrics the Context's resources should be tailored and upon which
3550 * new windows should be shown.
3551 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003552 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07003553 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003554 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07003555
3556 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07003557 * Gets the display adjustments holder for this context. This information
3558 * is provided on a per-application or activity basis and is used to simulate lower density
3559 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07003560 *
Jeff Browna492c3a2012-08-23 19:48:44 -07003561 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07003562 * @return The compatibility info holder, or null if not required by the application.
3563 * @hide
3564 */
Craig Mautner48d0d182013-06-11 07:53:06 -07003565 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07003566
3567 /**
Romain Guy870e09f2009-07-06 16:35:25 -07003568 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07003569 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003570 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07003571 *
Romain Guy870e09f2009-07-06 16:35:25 -07003572 * @see #CONTEXT_RESTRICTED
3573 */
3574 public boolean isRestricted() {
3575 return false;
3576 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577}