blob: d43e84714abec9ca060bfd608745c2092496881d [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 Norbyec91531a2015-04-01 17:41:55 -070019import android.annotation.AttrRes;
Tor Norbye1c2bf032015-03-02 10:57:08 -080020import android.annotation.CheckResult;
Tor Norbye3e4cda72015-06-10 08:14:31 -070021import android.annotation.ColorInt;
22import android.annotation.ColorRes;
23import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070024import android.annotation.IntDef;
25import android.annotation.NonNull;
26import android.annotation.Nullable;
27import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070028import android.annotation.StringRes;
29import android.annotation.StyleRes;
30import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090031import android.annotation.SystemApi;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070032import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.content.pm.PackageManager;
34import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080035import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070036import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.content.res.Resources;
38import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070039import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.database.sqlite.SQLiteDatabase;
41import android.database.sqlite.SQLiteDatabase.CursorFactory;
42import android.graphics.Bitmap;
43import android.graphics.drawable.Drawable;
44import android.net.Uri;
45import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070046import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.os.Handler;
Dianne Hackbornff170242014-11-19 10:59:01 -080048import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070050import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070051import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070052import android.os.UserManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070053import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.util.AttributeSet;
Craig Mautner48d0d182013-06-11 07:53:06 -070055import android.view.DisplayAdjustments;
Jeff Browna492c3a2012-08-23 19:48:44 -070056import android.view.Display;
Jon Miranda836c0a82014-08-11 12:32:26 -070057import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070058import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
60import java.io.File;
61import java.io.FileInputStream;
62import java.io.FileNotFoundException;
63import java.io.FileOutputStream;
64import java.io.IOException;
65import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070066import java.lang.annotation.Retention;
67import java.lang.annotation.RetentionPolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068
69/**
70 * Interface to global information about an application environment. This is
71 * an abstract class whose implementation is provided by
72 * the Android system. It
73 * allows access to application-specific resources and classes, as well as
74 * up-calls for application-level operations such as launching activities,
75 * broadcasting and receiving intents, etc.
76 */
77public abstract class Context {
78 /**
79 * File creation mode: the default mode, where the created file can only
80 * be accessed by the calling application (or all applications sharing the
81 * same user ID).
82 * @see #MODE_WORLD_READABLE
83 * @see #MODE_WORLD_WRITEABLE
84 */
85 public static final int MODE_PRIVATE = 0x0000;
86 /**
Nick Kralevich15069212013-01-09 15:54:56 -080087 * @deprecated Creating world-readable files is very dangerous, and likely
88 * to cause security holes in applications. It is strongly discouraged;
89 * instead, applications should use more formal mechanism for interactions
90 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
91 * {@link android.app.Service}. There are no guarantees that this
92 * access mode will remain on a file, such as when it goes through a
93 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094 * File creation mode: allow all other applications to have read access
95 * to the created file.
96 * @see #MODE_PRIVATE
97 * @see #MODE_WORLD_WRITEABLE
98 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070099 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 public static final int MODE_WORLD_READABLE = 0x0001;
101 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800102 * @deprecated Creating world-writable files is very dangerous, and likely
103 * to cause security holes in applications. It is strongly discouraged;
104 * instead, applications should use more formal mechanism for interactions
105 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
106 * {@link android.app.Service}. There are no guarantees that this
107 * access mode will remain on a file, such as when it goes through a
108 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800109 * File creation mode: allow all other applications to have write access
110 * to the created file.
111 * @see #MODE_PRIVATE
112 * @see #MODE_WORLD_READABLE
113 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700114 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800115 public static final int MODE_WORLD_WRITEABLE = 0x0002;
116 /**
117 * File creation mode: for use with {@link #openFileOutput}, if the file
118 * already exists then write data to the end of the existing file
119 * instead of erasing it.
120 * @see #openFileOutput
121 */
122 public static final int MODE_APPEND = 0x8000;
123
124 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800125 * SharedPreference loading flag: when set, the file on disk will
126 * be checked for modification even if the shared preferences
127 * instance is already loaded in this process. This behavior is
128 * sometimes desired in cases where the application has multiple
129 * processes, all writing to the same SharedPreferences file.
130 * Generally there are better forms of communication between
131 * processes, though.
132 *
133 * <p>This was the legacy (but undocumented) behavior in and
134 * before Gingerbread (Android 2.3) and this flag is implied when
135 * targetting such releases. For applications targetting SDK
136 * versions <em>greater than</em> Android 2.3, this flag must be
137 * explicitly set if desired.
138 *
139 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700140 *
141 * @deprecated MODE_MULTI_PROCESS does not work reliably in
142 * some versions of Android, and furthermore does not provide any
143 * mechanism for reconciling concurrent modifications across
144 * processes. Applications should not attempt to use it. Instead,
145 * they should use an explicit cross-process data management
146 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800147 */
Christopher Tated5748b82015-05-08 18:14:01 -0700148 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800149 public static final int MODE_MULTI_PROCESS = 0x0004;
150
151 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700152 * Database open flag: when set, the database is opened with write-ahead
153 * logging enabled by default.
154 *
155 * @see #openOrCreateDatabase(String, int, CursorFactory)
156 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
157 * @see SQLiteDatabase#enableWriteAheadLogging
158 */
159 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
160
Tor Norbyed9273d62013-05-30 15:59:53 -0700161 /** @hide */
162 @IntDef(flag = true,
163 value = {
164 BIND_AUTO_CREATE,
Tor Norbyed9273d62013-05-30 15:59:53 -0700165 BIND_DEBUG_UNBIND,
166 BIND_NOT_FOREGROUND,
167 BIND_ABOVE_CLIENT,
168 BIND_ALLOW_OOM_MANAGEMENT,
Tor Norbyece1c67c2014-12-02 13:59:17 -0800169 BIND_WAIVE_PRIORITY,
170 BIND_IMPORTANT,
171 BIND_ADJUST_WITH_ACTIVITY
Tor Norbyed9273d62013-05-30 15:59:53 -0700172 })
173 @Retention(RetentionPolicy.SOURCE)
174 public @interface BindServiceFlags {}
175
Jeff Brown47847f32012-03-22 19:13:11 -0700176 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 * Flag for {@link #bindService}: automatically create the service as long
178 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700179 * its {@link android.app.Service#onStartCommand}
180 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 * explicit call to {@link #startService}. Even without that, though,
182 * this still provides you with access to the service object while the
183 * service is created.
184 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700185 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
186 * not supplying this flag would also impact how important the system
187 * consider's the target service's process to be. When set, the only way
188 * for it to be raised was by binding from a service in which case it will
189 * only be important when that activity is in the foreground. Now to
190 * achieve this behavior you must explicitly supply the new flag
191 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
192 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
193 * the flags {@link #BIND_WAIVE_PRIORITY} and
194 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
195 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 */
197 public static final int BIND_AUTO_CREATE = 0x0001;
198
199 /**
200 * Flag for {@link #bindService}: include debugging help for mismatched
201 * calls to unbind. When this flag is set, the callstack of the following
202 * {@link #unbindService} call is retained, to be printed if a later
203 * incorrect unbind call is made. Note that doing this requires retaining
204 * information about the binding that was made for the lifetime of the app,
205 * resulting in a leak -- this should only be used for debugging.
206 */
207 public static final int BIND_DEBUG_UNBIND = 0x0002;
208
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800209 /**
210 * Flag for {@link #bindService}: don't allow this binding to raise
211 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700212 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800213 * as the client (so that its process will not be killable in any
214 * situation where the client is not killable), but for CPU scheduling
215 * purposes it may be left in the background. This only has an impact
216 * in the situation where the binding client is a foreground process
217 * and the target service is in a background process.
218 */
219 public static final int BIND_NOT_FOREGROUND = 0x0004;
220
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700221 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700222 * Flag for {@link #bindService}: indicates that the client application
223 * binding to this service considers the service to be more important than
224 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700225 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700226 * this is not guaranteed to be the case.
227 */
228 public static final int BIND_ABOVE_CLIENT = 0x0008;
229
230 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700231 * Flag for {@link #bindService}: allow the process hosting the bound
232 * service to go through its normal memory management. It will be
233 * treated more like a running service, allowing the system to
234 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700235 * whim it may have, and being more aggressive about making it a candidate
236 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700237 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700238 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
239
240 /**
241 * Flag for {@link #bindService}: don't impact the scheduling or
242 * memory management priority of the target service's hosting process.
243 * Allows the service's process to be managed on the background LRU list
244 * just like a regular application process in the background.
245 */
246 public static final int BIND_WAIVE_PRIORITY = 0x0020;
247
248 /**
249 * Flag for {@link #bindService}: this service is very important to
250 * the client, so should be brought to the foreground process level
251 * when the client is. Normally a process can only be raised to the
252 * visibility level by a client, even if that client is in the foreground.
253 */
254 public static final int BIND_IMPORTANT = 0x0040;
255
256 /**
257 * Flag for {@link #bindService}: If binding from an activity, allow the
258 * target service's process importance to be raised based on whether the
259 * activity is visible to the user, regardless whether another flag is
260 * used to reduce the amount that the client process's overall importance
261 * is used to impact it.
262 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700263 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
264
265 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700266 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
267 * but only applies while the device is awake.
268 */
269 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
270
271 /**
272 * @hide Flag for {@link #bindService}: For only the case where the binding
273 * is coming from the system, set the process state to FOREGROUND_SERVICE
274 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
275 * saying that the process shouldn't participate in the normal power reduction
276 * modes (removing network access etc).
277 */
278 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
279
280 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700281 * @hide Flag for {@link #bindService}: Treat the binding as hosting
282 * an activity, an unbinding as the activity going in the background.
283 * That is, when unbinding, the process when empty will go on the activity
284 * LRU list instead of the regular one, keeping it around more aggressively
285 * than it otherwise would be. This is intended for use with IMEs to try
286 * to keep IME processes around for faster keyboard switching.
287 */
288 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
289
290 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700291 * @hide An idea that is not yet implemented.
292 * Flag for {@link #bindService}: If binding from an activity, consider
293 * this service to be visible like the binding activity is. That is,
294 * it will be treated as something more important to keep around than
295 * invisible background activities. This will impact the number of
296 * recent activities the user can switch between without having them
297 * restart. There is no guarantee this will be respected, as the system
298 * tries to balance such requests from one app vs. the importantance of
299 * keeping other apps around.
300 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700301 public static final int BIND_VISIBLE = 0x10000000;
302
303 /**
304 * @hide
305 * Flag for {@link #bindService}: Consider this binding to be causing the target
306 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
307 * away.
308 */
309 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700310
311 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700312 * Flag for {@link #bindService}: Don't consider the bound service to be
313 * visible, even if the caller is visible.
314 * @hide
315 */
316 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700317
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 /** Return an AssetManager instance for your application's package. */
319 public abstract AssetManager getAssets();
320
321 /** Return a Resources instance for your application's package. */
322 public abstract Resources getResources();
323
324 /** Return PackageManager instance to find global package information. */
325 public abstract PackageManager getPackageManager();
326
327 /** Return a ContentResolver instance for your application's package. */
328 public abstract ContentResolver getContentResolver();
329
330 /**
331 * Return the Looper for the main thread of the current process. This is
332 * the thread used to dispatch calls to application components (activities,
333 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700334 * <p>
335 * By definition, this method returns the same result as would be obtained
336 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
337 * </p>
338 *
339 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 */
341 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800343 /**
344 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800345 * current process. This generally should only be used if you need a
346 * Context whose lifecycle is separate from the current context, that is
347 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700348 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800349 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800350 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800351 * <ul>
352 * <li> <p>If used from an Activity context, the receiver is being registered
353 * within that activity. This means that you are expected to unregister
354 * before the activity is done being destroyed; in fact if you do not do
355 * so, the framework will clean up your leaked registration as it removes
356 * the activity and log an error. Thus, if you use the Activity context
357 * to register a receiver that is static (global to the process, not
358 * associated with an Activity instance) then that registration will be
359 * removed on you at whatever point the activity you used is destroyed.
360 * <li> <p>If used from the Context returned here, the receiver is being
361 * registered with the global state associated with your application. Thus
362 * it will never be unregistered for you. This is necessary if the receiver
363 * is associated with static data, not a particular component. However
364 * using the ApplicationContext elsewhere can easily lead to serious leaks
365 * if you forget to unregister, unbind, etc.
366 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 */
368 public abstract Context getApplicationContext();
369
370 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700371 * Add a new {@link ComponentCallbacks} to the base application of the
372 * Context, which will be called at the same times as the ComponentCallbacks
373 * methods of activities and other components are called. Note that you
374 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
375 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700376 *
377 * @param callback The interface to call. This can be either a
378 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700379 */
380 public void registerComponentCallbacks(ComponentCallbacks callback) {
381 getApplicationContext().registerComponentCallbacks(callback);
382 }
383
384 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400385 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700386 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
387 */
388 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
389 getApplicationContext().unregisterComponentCallbacks(callback);
390 }
391
392 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 * Return a localized, styled CharSequence from the application's package's
394 * default string table.
395 *
396 * @param resId Resource id for the CharSequence text
397 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700398 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 return getResources().getText(resId);
400 }
401
402 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700403 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 * default string table.
405 *
406 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700407 * @return The string data associated with the resource, stripped of styled
408 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700410 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700411 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 return getResources().getString(resId);
413 }
414
415 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700416 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 * default string table, substituting the format arguments as defined in
418 * {@link java.util.Formatter} and {@link java.lang.String#format}.
419 *
420 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700421 * @param formatArgs The format arguments that will be used for
422 * substitution.
423 * @return The string data associated with the resource, formatted and
424 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700426 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700427 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800428 return getResources().getString(resId, formatArgs);
429 }
430
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800431 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800432 * Returns a color associated with a particular resource ID and styled for
433 * 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 single color value in the form 0xAARRGGBB.
439 * @throws android.content.res.Resources.NotFoundException if the given ID
440 * does not exist.
441 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700442 @ColorInt
443 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800444 return getResources().getColor(id, getTheme());
445 }
446
447 /**
448 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800449 * styled for the current theme.
450 *
451 * @param id The desired resource identifier, as generated by the aapt
452 * tool. This integer encodes the package, type, and resource
453 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800454 * @return An object that can be used to draw this resource, or
455 * {@code null} if the resource could not be resolved.
456 * @throws android.content.res.Resources.NotFoundException if the given ID
457 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800458 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800459 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700460 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800461 return getResources().getDrawable(id, getTheme());
462 }
463
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800464 /**
465 * Returns a color state list associated with a particular resource ID and
466 * styled for the current theme.
467 *
468 * @param id The desired resource identifier, as generated by the aapt
469 * tool. This integer encodes the package, type, and resource
470 * entry. The value 0 is an invalid identifier.
471 * @return A color state list, or {@code null} if the resource could not be
472 * resolved.
473 * @throws android.content.res.Resources.NotFoundException if the given ID
474 * does not exist.
475 */
476 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700477 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800478 return getResources().getColorStateList(id, getTheme());
479 }
480
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 /**
482 * Set the base theme for this context. Note that this should be called
483 * before any views are instantiated in the Context (for example before
484 * calling {@link android.app.Activity#setContentView} or
485 * {@link android.view.LayoutInflater#inflate}).
486 *
487 * @param resid The style resource describing the theme.
488 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700489 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
Dianne Hackborn247fe742011-01-08 17:25:57 -0800491 /** @hide Needed for some internal implementation... not public because
492 * you can't assume this actually means anything. */
493 public int getThemeResId() {
494 return 0;
495 }
496
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 /**
498 * Return the Theme object associated with this Context.
499 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700500 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800501 public abstract Resources.Theme getTheme();
502
503 /**
504 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800505 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 * for more information.
507 *
Jeff Brown6e539312015-02-24 18:53:21 -0800508 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700510 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 return getTheme().obtainStyledAttributes(attrs);
512 }
513
514 /**
515 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800516 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800517 * for more information.
518 *
Jeff Brown6e539312015-02-24 18:53:21 -0800519 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 */
521 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700522 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800523 return getTheme().obtainStyledAttributes(resid, attrs);
524 }
525
526 /**
527 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800528 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 * for more information.
530 *
Jeff Brown6e539312015-02-24 18:53:21 -0800531 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 */
533 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700534 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800535 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
536 }
537
538 /**
539 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800540 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 * for more information.
542 *
Jeff Brown6e539312015-02-24 18:53:21 -0800543 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800544 */
545 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700546 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
547 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 return getTheme().obtainStyledAttributes(
549 set, attrs, defStyleAttr, defStyleRes);
550 }
551
552 /**
553 * Return a class loader you can use to retrieve classes in this package.
554 */
555 public abstract ClassLoader getClassLoader();
556
557 /** Return the name of this application's package. */
558 public abstract String getPackageName();
559
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800560 /** @hide Return the name of the base context this context is derived from. */
561 public abstract String getBasePackageName();
562
Dianne Hackborn95d78532013-09-11 09:51:14 -0700563 /** @hide Return the package name that should be used for app ops calls from
564 * this context. This is the same as {@link #getBasePackageName()} except in
565 * cases where system components are loaded into other app processes, in which
566 * case this will be the name of the primary package in that process (so that app
567 * ops uid verification will work with the name). */
568 public abstract String getOpPackageName();
569
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700570 /** Return the full application info for this context's package. */
571 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700572
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 /**
Kenny Root32148392010-01-21 15:40:47 -0800574 * Return the full path to this context's primary Android package.
575 * The Android package is a ZIP file which contains the application's
576 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 *
578 * <p>Note: this is not generally useful for applications, since they should
579 * not be directly accessing the file system.
580 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 * @return String Path to the resources.
582 */
583 public abstract String getPackageResourcePath();
584
585 /**
Kenny Root32148392010-01-21 15:40:47 -0800586 * Return the full path to this context's primary Android package.
587 * The Android package is a ZIP file which contains application's
588 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 *
590 * <p>Note: this is not generally useful for applications, since they should
591 * not be directly accessing the file system.
592 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 * @return String Path to the code and assets.
594 */
595 public abstract String getPackageCodePath();
596
597 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700598 * {@hide}
599 * Return the full path to the shared prefs file for the given prefs group name.
600 *
601 * <p>Note: this is not generally useful for applications, since they should
602 * not be directly accessing the file system.
603 */
604 public abstract File getSharedPrefsFile(String name);
605
606 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 * Retrieve and hold the contents of the preferences file 'name', returning
608 * a SharedPreferences through which you can retrieve and modify its
609 * values. Only one instance of the SharedPreferences object is returned
610 * to any callers for the same name, meaning they will see each other's
611 * edits as soon as they are made.
612 *
613 * @param name Desired preferences file. If a preferences file by this name
614 * does not exist, it will be created when you retrieve an
615 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
616 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
617 * default operation, {@link #MODE_WORLD_READABLE}
Christopher Tated5748b82015-05-08 18:14:01 -0700618 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800619 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400620 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 * to retrieve and modify the preference values.
622 *
623 * @see #MODE_PRIVATE
624 * @see #MODE_WORLD_READABLE
625 * @see #MODE_WORLD_WRITEABLE
626 */
627 public abstract SharedPreferences getSharedPreferences(String name,
628 int mode);
629
630 /**
631 * Open a private file associated with this Context's application package
632 * for reading.
633 *
634 * @param name The name of the file to open; can not contain path
635 * separators.
636 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400637 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 *
639 * @see #openFileOutput
640 * @see #fileList
641 * @see #deleteFile
642 * @see java.io.FileInputStream#FileInputStream(String)
643 */
644 public abstract FileInputStream openFileInput(String name)
645 throws FileNotFoundException;
646
647 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800648 * Open a private file associated with this Context's application package
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 * for writing. Creates the file if it doesn't already exist.
650 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700651 * <p>No permissions are required to invoke this method, since it uses internal
652 * storage.
653 *
Nick Kralevich15069212013-01-09 15:54:56 -0800654 * @param name The name of the file to open; can not contain path
655 * separators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800657 * default operation, {@link #MODE_APPEND} to append to an existing file,
658 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
659 * permissions.
660 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400661 * @return The resulting {@link FileOutputStream}.
Nick Kralevich15069212013-01-09 15:54:56 -0800662 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 * @see #MODE_APPEND
664 * @see #MODE_PRIVATE
665 * @see #MODE_WORLD_READABLE
666 * @see #MODE_WORLD_WRITEABLE
667 * @see #openFileInput
668 * @see #fileList
669 * @see #deleteFile
670 * @see java.io.FileOutputStream#FileOutputStream(String)
671 */
672 public abstract FileOutputStream openFileOutput(String name, int mode)
673 throws FileNotFoundException;
674
675 /**
676 * Delete the given private file associated with this Context's
677 * application package.
678 *
679 * @param name The name of the file to delete; can not contain path
680 * separators.
681 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400682 * @return {@code true} if the file was successfully deleted; else
683 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 *
685 * @see #openFileInput
686 * @see #openFileOutput
687 * @see #fileList
688 * @see java.io.File#delete()
689 */
690 public abstract boolean deleteFile(String name);
691
692 /**
693 * Returns the absolute path on the filesystem where a file created with
694 * {@link #openFileOutput} is stored.
695 *
696 * @param name The name of the file for which you would like to get
697 * its path.
698 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400699 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 *
701 * @see #openFileOutput
702 * @see #getFilesDir
703 * @see #getDir
704 */
705 public abstract File getFileStreamPath(String name);
706
707 /**
708 * Returns the absolute path to the directory on the filesystem where
709 * files created with {@link #openFileOutput} are stored.
710 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700711 * <p>No permissions are required to read or write to the returned path, since this
712 * path is internal storage.
713 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400714 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800715 *
716 * @see #openFileOutput
717 * @see #getFileStreamPath
718 * @see #getDir
719 */
720 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800722 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700723 * Returns the absolute path to the directory on the filesystem similar to
724 * {@link #getFilesDir()}. The difference is that files placed under this
725 * directory will be excluded from automatic backup to remote storage. See
726 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
727 * of the automatic backup mechanism in Android.
728 *
729 * <p>No permissions are required to read or write to the returned path, since this
730 * path is internal storage.
731 *
732 * @return The path of the directory holding application files that will not be
733 * automatically backed up to remote storage.
734 *
735 * @see #openFileOutput
736 * @see #getFileStreamPath
737 * @see #getDir
738 * @see android.app.backup.BackupAgent
739 */
740 public abstract File getNoBackupFilesDir();
741
742 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700743 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800744 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700745 * Environment.getExternalStorageDirectory()}) where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700746 * place persistent files it owns. These files are internal to the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800747 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700748 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800749 * <p>This is like {@link #getFilesDir()} in that these
750 * files will be deleted when the application is uninstalled, however there
751 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700752 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800753 * <ul>
754 * <li>External files are not always available: they will disappear if the
755 * user mounts the external storage on a computer or removes it. See the
756 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700757 * <li>There is no security enforced with these files. For example, any application
758 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
759 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800760 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700761 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700762 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
763 * are required to read or write to the returned path; it's always
764 * accessible to the calling app. This only applies to paths generated for
765 * package name of the calling application. To access paths belonging
766 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
767 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
768 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700769 * <p>On devices with multiple users (as described by {@link UserManager}),
770 * each user has their own isolated external storage. Applications only
771 * have access to the external storage for the user they're running as.</p>
772 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800773 * <p>Here is an example of typical code to manipulate a file in
774 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700775 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800776 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
777 * private_file}
778 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700779 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800780 * file will be a path to a sub-directory of the given type. Though these files
781 * are not automatically scanned by the media scanner, you can explicitly
782 * add them to the media database with
783 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Jeff Brown6e539312015-02-24 18:53:21 -0800784 * android.media.MediaScannerConnection.OnScanCompletedListener)
785 * MediaScannerConnection.scanFile}.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800786 * Note that this is not the same as
787 * {@link android.os.Environment#getExternalStoragePublicDirectory
788 * Environment.getExternalStoragePublicDirectory()}, which provides
789 * directories of media shared by all applications. The
790 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700791 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800792 * application is uninstalled. Unlike
793 * {@link android.os.Environment#getExternalStoragePublicDirectory
794 * Environment.getExternalStoragePublicDirectory()}, the directory
795 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700796 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800797 * <p>Here is an example of typical code to manipulate a picture in
798 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700799 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800800 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
801 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700802 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800803 * @param type The type of files directory to return. May be null for
804 * the root of the files directory or one of
805 * the following Environment constants for a subdirectory:
806 * {@link android.os.Environment#DIRECTORY_MUSIC},
807 * {@link android.os.Environment#DIRECTORY_PODCASTS},
808 * {@link android.os.Environment#DIRECTORY_RINGTONES},
809 * {@link android.os.Environment#DIRECTORY_ALARMS},
810 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
811 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
812 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700813 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400814 * @return The path of the directory holding application files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800815 * on external storage. Returns null if external storage is not currently
816 * mounted so it could not ensure the path exists; you will need to call
817 * this method again when it is available.
818 *
819 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700820 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800821 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700822 @Nullable
823 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700824
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800825 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700826 * Returns absolute paths to application-specific directories on all
827 * external storage devices where the application can place persistent files
828 * it owns. These files are internal to the application, and not typically
829 * visible to the user as media.
830 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700831 * This is like {@link #getFilesDir()} in that these files will be deleted when
832 * the application is uninstalled, however there are some important differences:
833 * <ul>
834 * <li>External files are not always available: they will disappear if the
835 * user mounts the external storage on a computer or removes it.
836 * <li>There is no security enforced with these files.
837 * </ul>
838 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700839 * External storage devices returned here are considered a permanent part of
840 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700841 * slots, such as SD cards in a battery compartment. The returned paths do
842 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700843 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700844 * An application may store data on any or all of the returned devices. For
845 * example, an app may choose to store large files on the device with the
846 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700847 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700848 * No permissions are required to read or write to the returned paths; they
849 * are always accessible to the calling app. Write access outside of these
850 * paths on secondary external storage devices is not available.
851 * <p>
852 * The first path returned is the same as {@link #getExternalFilesDir(String)}.
853 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700854 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700855 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800856 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700857 */
858 public abstract File[] getExternalFilesDirs(String type);
859
860 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700861 * Return the primary external storage directory where this application's OBB
862 * files (if there are any) can be found. Note if the application does not have
863 * any OBB files, this directory may not exist.
864 * <p>
865 * This is like {@link #getFilesDir()} in that these files will be deleted when
866 * the application is uninstalled, however there are some important differences:
867 * <ul>
868 * <li>External files are not always available: they will disappear if the
869 * user mounts the external storage on a computer or removes it.
870 * <li>There is no security enforced with these files. For example, any application
871 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
872 * these files.
873 * </ul>
874 * <p>
875 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
876 * are required to read or write to the returned path; it's always
877 * accessible to the calling app. This only applies to paths generated for
878 * package name of the calling application. To access paths belonging
879 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
880 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700881 * <p>
882 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -0700883 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700884 * should ensure that multiple instances running under different users don't
885 * interfere with each other.
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800886 */
887 public abstract File getObbDir();
888
889 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700890 * Returns absolute paths to application-specific directories on all
891 * external storage devices where the application's OBB files (if there are
892 * any) can be found. Note if the application does not have any OBB files,
893 * these directories may not exist.
894 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700895 * This is like {@link #getFilesDir()} in that these files will be deleted when
896 * the application is uninstalled, however there are some important differences:
897 * <ul>
898 * <li>External files are not always available: they will disappear if the
899 * user mounts the external storage on a computer or removes it.
900 * <li>There is no security enforced with these files.
901 * </ul>
902 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700903 * External storage devices returned here are considered a permanent part of
904 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700905 * slots, such as SD cards in a battery compartment. The returned paths do
906 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700907 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700908 * An application may store data on any or all of the returned devices. For
909 * example, an app may choose to store large files on the device with the
910 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700911 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700912 * No permissions are required to read or write to the returned paths; they
913 * are always accessible to the calling app. Write access outside of these
914 * paths on secondary external storage devices is not available.
915 * <p>
916 * The first path returned is the same as {@link #getObbDir()}.
917 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700918 *
919 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800920 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700921 */
922 public abstract File[] getObbDirs();
923
924 /**
Scott Main4b5da682010-10-21 11:49:12 -0700925 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800926 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800927 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700929 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800930 * <strong>Note: you should not <em>rely</em> on the system deleting these
931 * files for you; you should always have a reasonable maximum, such as 1 MB,
932 * for the amount of space you consume with cache files, and prune those
933 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700934 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400935 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 *
937 * @see #openFileOutput
938 * @see #getFileStreamPath
939 * @see #getDir
940 */
941 public abstract File getCacheDir();
942
943 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -0700944 * Returns the absolute path to the application specific cache directory on
945 * the filesystem designed for storing cached code. The system will delete
946 * any files stored in this location both when your specific application is
947 * upgraded, and when the entire platform is upgraded.
948 * <p>
949 * This location is optimal for storing compiled or optimized code generated
950 * by your application at runtime.
951 * <p>
952 * Apps require no extra permissions to read or write to the returned path,
953 * since this path lives in their private storage.
954 *
955 * @return The path of the directory holding application code cache files.
956 */
957 public abstract File getCodeCacheDir();
958
959 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700960 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800961 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
962 * Environment.getExternalStorageDirectory()} where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700963 * place cache files it owns. These files are internal to the application, and
964 * not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700965 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800966 * <p>This is like {@link #getCacheDir()} in that these
967 * files will be deleted when the application is uninstalled, however there
968 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700969 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800970 * <ul>
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700971 * <li>The platform does not always monitor the space available in external
972 * storage, and thus may not automatically delete these files. Currently
973 * the only time files here will be deleted by the platform is when running
974 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
975 * {@link android.os.Environment#isExternalStorageEmulated()
976 * Environment.isExternalStorageEmulated()} returns true. Note that you should
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800977 * be managing the maximum space you will use for these anyway, just like
978 * with {@link #getCacheDir()}.
979 * <li>External files are not always available: they will disappear if the
980 * user mounts the external storage on a computer or removes it. See the
981 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700982 * <li>There is no security enforced with these files. For example, any application
983 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
984 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800985 * </ul>
986 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700987 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
988 * are required to read or write to the returned path; it's always
989 * accessible to the calling app. This only applies to paths generated for
990 * package name of the calling application. To access paths belonging
991 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
992 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
993 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700994 * <p>On devices with multiple users (as described by {@link UserManager}),
995 * each user has their own isolated external storage. Applications only
996 * have access to the external storage for the user they're running as.</p>
Jeff Sharkey8c165792012-10-22 14:08:29 -0700997 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400998 * @return The path of the directory holding application cache files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800999 * on external storage. Returns null if external storage is not currently
1000 * mounted so it could not ensure the path exists; you will need to call
1001 * this method again when it is available.
1002 *
1003 * @see #getCacheDir
1004 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001005 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001006 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001007
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001008 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001009 * Returns absolute paths to application-specific directories on all
1010 * external storage devices where the application can place cache files it
1011 * owns. These files are internal to the application, and not typically
1012 * visible to the user as media.
1013 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001014 * This is like {@link #getCacheDir()} in that these files will be deleted when
1015 * the application is uninstalled, however there are some important differences:
1016 * <ul>
1017 * <li>External files are not always available: they will disappear if the
1018 * user mounts the external storage on a computer or removes it.
1019 * <li>There is no security enforced with these files.
1020 * </ul>
1021 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001022 * External storage devices returned here are considered a permanent part of
1023 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001024 * slots, such as SD cards in a battery compartment. The returned paths do
1025 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001026 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001027 * An application may store data on any or all of the returned devices. For
1028 * example, an app may choose to store large files on the device with the
1029 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001030 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001031 * No permissions are required to read or write to the returned paths; they
1032 * are always accessible to the calling app. Write access outside of these
1033 * paths on secondary external storage devices is not available.
1034 * <p>
1035 * The first path returned is the same as {@link #getExternalCacheDir()}.
1036 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001037 *
1038 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001039 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001040 */
1041 public abstract File[] getExternalCacheDirs();
1042
1043 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001044 * Returns absolute paths to application-specific directories on all
1045 * external storage devices where the application can place media files.
1046 * These files are scanned and made available to other apps through
1047 * {@link MediaStore}.
1048 * <p>
1049 * This is like {@link #getExternalFilesDirs} in that these files will be
1050 * deleted when the application is uninstalled, however there are some
1051 * important differences:
1052 * <ul>
1053 * <li>External files are not always available: they will disappear if the
1054 * user mounts the external storage on a computer or removes it.
1055 * <li>There is no security enforced with these files.
1056 * </ul>
1057 * <p>
1058 * External storage devices returned here are considered a permanent part of
1059 * the device, including both emulated external storage and physical media
1060 * slots, such as SD cards in a battery compartment. The returned paths do
1061 * not include transient devices, such as USB flash drives.
1062 * <p>
1063 * An application may store data on any or all of the returned devices. For
1064 * example, an app may choose to store large files on the device with the
1065 * most available space, as measured by {@link StatFs}.
1066 * <p>
1067 * No permissions are required to read or write to the returned paths; they
1068 * are always accessible to the calling app. Write access outside of these
1069 * paths on secondary external storage devices is not available.
1070 * <p>
1071 * Returned paths may be {@code null} if a storage device is unavailable.
1072 *
1073 * @see Environment#getExternalStorageState(File)
1074 */
1075 public abstract File[] getExternalMediaDirs();
1076
1077 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 * Returns an array of strings naming the private files associated with
1079 * this Context's application package.
1080 *
1081 * @return Array of strings naming the private files.
1082 *
1083 * @see #openFileInput
1084 * @see #openFileOutput
1085 * @see #deleteFile
1086 */
1087 public abstract String[] fileList();
1088
1089 /**
1090 * Retrieve, creating if needed, a new directory in which the application
1091 * can place its own custom data files. You can use the returned File
1092 * object to create and access files in this directory. Note that files
1093 * created through a File object will only be accessible by your own
1094 * application; you can only set the mode of the entire directory, not
1095 * of individual files.
1096 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001097 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001098 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001099 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -08001100 * default operation, {@link #MODE_WORLD_READABLE} and
1101 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
1102 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001103 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001104 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 *
1106 * @see #openFileOutput(String, int)
1107 */
1108 public abstract File getDir(String name, int mode);
1109
1110 /**
1111 * Open a new private SQLiteDatabase associated with this Context's
1112 * application package. Create the database file if it doesn't exist.
1113 *
1114 * @param name The name (unique in the application package) of the database.
1115 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1116 * default operation, {@link #MODE_WORLD_READABLE}
1117 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001118 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001119 * @param factory An optional factory class that is called to instantiate a
1120 * cursor when query is called.
Nick Kralevich15069212013-01-09 15:54:56 -08001121 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 * @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 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 * @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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001129 * @see #deleteDatabase
1130 */
1131 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1132 int mode, CursorFactory factory);
1133
1134 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001135 * Open a new private SQLiteDatabase associated with this Context's
1136 * application package. Creates the database file if it doesn't exist.
1137 *
1138 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
1139 * used to handle corruption when sqlite reports database corruption.</p>
1140 *
1141 * @param name The name (unique in the application package) of the database.
1142 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1143 * default operation, {@link #MODE_WORLD_READABLE}
1144 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001145 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
Vasu Nori74f170f2010-06-01 18:06:18 -07001146 * @param factory An optional factory class that is called to instantiate a
1147 * cursor when query is called.
1148 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Nick Kralevich15069212013-01-09 15:54:56 -08001149 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001150 * @return The contents of a newly created database with the given name.
1151 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001152 *
Vasu Nori74f170f2010-06-01 18:06:18 -07001153 * @see #MODE_PRIVATE
1154 * @see #MODE_WORLD_READABLE
1155 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001156 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -07001157 * @see #deleteDatabase
1158 */
1159 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001160 int mode, CursorFactory factory,
1161 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001162
1163 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 * Delete an existing private SQLiteDatabase associated with this Context's
1165 * application package.
1166 *
1167 * @param name The name (unique in the application package) of the
1168 * database.
1169 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001170 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 *
1172 * @see #openOrCreateDatabase
1173 */
1174 public abstract boolean deleteDatabase(String name);
1175
1176 /**
1177 * Returns the absolute path on the filesystem where a database created with
1178 * {@link #openOrCreateDatabase} is stored.
1179 *
1180 * @param name The name of the database for which you would like to get
1181 * its path.
1182 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001183 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 *
1185 * @see #openOrCreateDatabase
1186 */
1187 public abstract File getDatabasePath(String name);
1188
1189 /**
1190 * Returns an array of strings naming the private databases associated with
1191 * this Context's application package.
1192 *
1193 * @return Array of strings naming the private databases.
1194 *
1195 * @see #openOrCreateDatabase
1196 * @see #deleteDatabase
1197 */
1198 public abstract String[] databaseList();
1199
1200 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001201 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001202 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001204 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 public abstract Drawable getWallpaper();
1206
1207 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001208 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001209 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001210 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001211 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 public abstract Drawable peekWallpaper();
1213
1214 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001215 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1216 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001218 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001219 public abstract int getWallpaperDesiredMinimumWidth();
1220
1221 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001222 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1223 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001225 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 public abstract int getWallpaperDesiredMinimumHeight();
1227
1228 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001229 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001230 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001231 * <p>This method requires the caller to hold the permission
1232 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001234 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001235 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1236
1237 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001238 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001239 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001240 * <p>This method requires the caller to hold the permission
1241 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001243 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001244 public abstract void setWallpaper(InputStream data) throws IOException;
1245
1246 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001247 * @deprecated Use {@link android.app.WallpaperManager#clear
1248 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001249 * <p>This method requires the caller to hold the permission
1250 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001251 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001252 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 public abstract void clearWallpaper() throws IOException;
1254
1255 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001256 * Same as {@link #startActivity(Intent, Bundle)} with no options
1257 * specified.
1258 *
1259 * @param intent The description of the activity to start.
1260 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001261 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001262 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001263 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001264 * @see PackageManager#resolveActivity
1265 */
1266 public abstract void startActivity(Intent intent);
1267
1268 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001269 * Version of {@link #startActivity(Intent)} that allows you to specify the
1270 * user the activity will be started for. This is not available to applications
1271 * that are not pre-installed on the system image. Using it requires holding
1272 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001273 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001274 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001275 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001276 * @hide
1277 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001278 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001279 throw new RuntimeException("Not implemented. Must override in a subclass.");
1280 }
1281
1282 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 * Launch a new activity. You will not receive any information about when
1284 * the activity exits.
1285 *
1286 * <p>Note that if this method is being called from outside of an
1287 * {@link android.app.Activity} Context, then the Intent must include
1288 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1289 * without being started from an existing Activity, there is no existing
1290 * task in which to place the new activity and thus it needs to be placed
1291 * in its own separate task.
1292 *
1293 * <p>This method throws {@link ActivityNotFoundException}
1294 * if there was no Activity found to run the given Intent.
1295 *
1296 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001297 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001298 * May be null if there are no options. See {@link android.app.ActivityOptions}
1299 * for how to build the Bundle supplied here; there are no supported definitions
1300 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001301 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001302 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001303 *
Scott Main60dd5202012-06-23 00:01:22 -07001304 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001305 * @see PackageManager#resolveActivity
1306 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001307 public abstract void startActivity(Intent intent, @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001308
1309 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001310 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1311 * user the activity will be started for. This is not available to applications
1312 * that are not pre-installed on the system image. Using it requires holding
1313 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001314 * @param intent The description of the activity to start.
1315 * @param options Additional options for how the Activity should be started.
1316 * May be null if there are no options. See {@link android.app.ActivityOptions}
1317 * for how to build the Bundle supplied here; there are no supported definitions
1318 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001319 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001320 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001321 * @hide
1322 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001323 public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001324 throw new RuntimeException("Not implemented. Must override in a subclass.");
1325 }
1326
1327 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001328 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1329 * is only supported for Views and Fragments.
1330 * @param who The identifier for the calling element that will receive the result.
1331 * @param intent The intent to start.
1332 * @param requestCode The code that will be returned with onActivityResult() identifying this
1333 * request.
1334 * @param options Additional options for how the Activity should be started.
1335 * May be null if there are no options. See {@link android.app.ActivityOptions}
1336 * for how to build the Bundle supplied here; there are no supported definitions
1337 * for building it manually.
1338 * @hide
1339 */
1340 public void startActivityForResult(
1341 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1342 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1343 + "Check canStartActivityForResult() before calling.");
1344 }
1345
1346 /**
1347 * Identifies whether this Context instance will be able to process calls to
1348 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1349 * @hide
1350 */
1351 public boolean canStartActivityForResult() {
1352 return false;
1353 }
1354
1355 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001356 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1357 * specified.
1358 *
1359 * @param intents An array of Intents to be started.
1360 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001361 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001362 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001363 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001364 * @see PackageManager#resolveActivity
1365 */
1366 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001367
1368 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001369 * Launch multiple new activities. This is generally the same as calling
1370 * {@link #startActivity(Intent)} for the first Intent in the array,
1371 * that activity during its creation calling {@link #startActivity(Intent)}
1372 * for the second entry, etc. Note that unlike that approach, generally
1373 * none of the activities except the last in the array will be created
1374 * at this point, but rather will be created when the user first visits
1375 * them (due to pressing back from the activity on top).
1376 *
1377 * <p>This method throws {@link ActivityNotFoundException}
1378 * if there was no Activity found for <em>any</em> given Intent. In this
1379 * case the state of the activity stack is undefined (some Intents in the
1380 * list may be on it, some not), so you probably want to avoid such situations.
1381 *
1382 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001383 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001384 * See {@link android.content.Context#startActivity(Intent, Bundle)
1385 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001386 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001387 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001388 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001389 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001390 * @see PackageManager#resolveActivity
1391 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001392 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001393
1394 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001395 * @hide
1396 * Launch multiple new activities. This is generally the same as calling
1397 * {@link #startActivity(Intent)} for the first Intent in the array,
1398 * that activity during its creation calling {@link #startActivity(Intent)}
1399 * for the second entry, etc. Note that unlike that approach, generally
1400 * none of the activities except the last in the array will be created
1401 * at this point, but rather will be created when the user first visits
1402 * them (due to pressing back from the activity on top).
1403 *
1404 * <p>This method throws {@link ActivityNotFoundException}
1405 * if there was no Activity found for <em>any</em> given Intent. In this
1406 * case the state of the activity stack is undefined (some Intents in the
1407 * list may be on it, some not), so you probably want to avoid such situations.
1408 *
1409 * @param intents An array of Intents to be started.
1410 * @param options Additional options for how the Activity should be started.
1411 * @param userHandle The user for whom to launch the activities
1412 * See {@link android.content.Context#startActivity(Intent, Bundle)
1413 * Context.startActivity(Intent, Bundle)} for more details.
1414 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001415 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001416 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001417 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001418 * @see PackageManager#resolveActivity
1419 */
1420 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1421 throw new RuntimeException("Not implemented. Must override in a subclass.");
1422 }
1423
1424 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001425 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1426 * with no options specified.
1427 *
1428 * @param intent The IntentSender to launch.
1429 * @param fillInIntent If non-null, this will be provided as the
1430 * intent parameter to {@link IntentSender#sendIntent}.
1431 * @param flagsMask Intent flags in the original IntentSender that you
1432 * would like to change.
1433 * @param flagsValues Desired values for any bits set in
1434 * <var>flagsMask</var>
1435 * @param extraFlags Always set to 0.
1436 *
1437 * @see #startActivity(Intent)
1438 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1439 */
1440 public abstract void startIntentSender(IntentSender intent,
1441 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1442 throws IntentSender.SendIntentException;
1443
1444 /**
1445 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001446 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001447 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001448 * here; otherwise, its associated action will be executed (such as
1449 * sending a broadcast) as if you had called
1450 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001451 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001452 * @param intent The IntentSender to launch.
1453 * @param fillInIntent If non-null, this will be provided as the
1454 * intent parameter to {@link IntentSender#sendIntent}.
1455 * @param flagsMask Intent flags in the original IntentSender that you
1456 * would like to change.
1457 * @param flagsValues Desired values for any bits set in
1458 * <var>flagsMask</var>
1459 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001460 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001461 * See {@link android.content.Context#startActivity(Intent, Bundle)
1462 * Context.startActivity(Intent, Bundle)} for more details. If options
1463 * have also been supplied by the IntentSender, options given here will
1464 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001465 *
1466 * @see #startActivity(Intent, Bundle)
1467 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001468 */
1469 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001470 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001471 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001472
1473 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474 * Broadcast the given intent to all interested BroadcastReceivers. This
1475 * call is asynchronous; it returns immediately, and you will continue
1476 * executing while the receivers are run. No results are propagated from
1477 * receivers and receivers can not abort the broadcast. If you want
1478 * to allow receivers to propagate results or abort the broadcast, you must
1479 * send an ordered broadcast using
1480 * {@link #sendOrderedBroadcast(Intent, String)}.
1481 *
1482 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1483 *
1484 * @param intent The Intent to broadcast; all receivers matching this
1485 * Intent will receive the broadcast.
1486 *
1487 * @see android.content.BroadcastReceiver
1488 * @see #registerReceiver
1489 * @see #sendBroadcast(Intent, String)
1490 * @see #sendOrderedBroadcast(Intent, String)
1491 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1492 */
1493 public abstract void sendBroadcast(Intent intent);
1494
1495 /**
1496 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1497 * an optional required permission to be enforced. This
1498 * call is asynchronous; it returns immediately, and you will continue
1499 * executing while the receivers are run. No results are propagated from
1500 * receivers and receivers can not abort the broadcast. If you want
1501 * to allow receivers to propagate results or abort the broadcast, you must
1502 * send an ordered broadcast using
1503 * {@link #sendOrderedBroadcast(Intent, String)}.
1504 *
1505 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1506 *
1507 * @param intent The Intent to broadcast; all receivers matching this
1508 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001509 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 * a receiver must hold in order to receive your broadcast.
1511 * If null, no permission is required.
1512 *
1513 * @see android.content.BroadcastReceiver
1514 * @see #registerReceiver
1515 * @see #sendBroadcast(Intent)
1516 * @see #sendOrderedBroadcast(Intent, String)
1517 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1518 */
1519 public abstract void sendBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001520 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521
1522 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001523 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001524 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001525 * @hide
1526 */
1527 public abstract void sendBroadcast(Intent intent,
1528 String receiverPermission, int appOp);
1529
1530 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1532 * them one at a time to allow more preferred receivers to consume the
1533 * broadcast before it is delivered to less preferred receivers. This
1534 * call is asynchronous; it returns immediately, and you will continue
1535 * executing while the receivers are run.
1536 *
1537 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1538 *
1539 * @param intent The Intent to broadcast; all receivers matching this
1540 * Intent will receive the broadcast.
1541 * @param receiverPermission (optional) String naming a permissions that
1542 * a receiver must hold in order to receive your broadcast.
1543 * If null, no permission is required.
1544 *
1545 * @see android.content.BroadcastReceiver
1546 * @see #registerReceiver
1547 * @see #sendBroadcast(Intent)
1548 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1549 */
1550 public abstract void sendOrderedBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001551 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552
1553 /**
1554 * Version of {@link #sendBroadcast(Intent)} that allows you to
1555 * receive data back from the broadcast. This is accomplished by
1556 * supplying your own BroadcastReceiver when calling, which will be
1557 * treated as a final receiver at the end of the broadcast -- its
1558 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001559 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 * be serialized in the same way as calling
1561 * {@link #sendOrderedBroadcast(Intent, String)}.
1562 *
1563 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1564 * asynchronous; it will return before
1565 * resultReceiver.onReceive() is called.
1566 *
1567 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1568 *
1569 * @param intent The Intent to broadcast; all receivers matching this
1570 * Intent will receive the broadcast.
1571 * @param receiverPermission String naming a permissions that
1572 * a receiver must hold in order to receive your broadcast.
1573 * If null, no permission is required.
1574 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1575 * receiver of the broadcast.
1576 * @param scheduler A custom Handler with which to schedule the
1577 * resultReceiver callback; if null it will be
1578 * scheduled in the Context's main thread.
1579 * @param initialCode An initial value for the result code. Often
1580 * Activity.RESULT_OK.
1581 * @param initialData An initial value for the result data. Often
1582 * null.
1583 * @param initialExtras An initial value for the result extras. Often
1584 * null.
1585 *
1586 * @see #sendBroadcast(Intent)
1587 * @see #sendBroadcast(Intent, String)
1588 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 * @see android.content.BroadcastReceiver
1590 * @see #registerReceiver
1591 * @see android.app.Activity#RESULT_OK
1592 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001593 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1594 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1595 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1596 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597
1598 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001599 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1600 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001601 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001602 * @hide
1603 */
1604 public abstract void sendOrderedBroadcast(Intent intent,
1605 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1606 Handler scheduler, int initialCode, String initialData,
1607 Bundle initialExtras);
1608
1609 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001610 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1611 * user the broadcast will be sent to. This is not available to applications
1612 * that are not pre-installed on the system image. Using it requires holding
1613 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001614 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001615 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001616 * @see #sendBroadcast(Intent)
1617 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001618 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001619
1620 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001621 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1622 * user the broadcast will be sent to. This is not available to applications
1623 * that are not pre-installed on the system image. Using it requires holding
1624 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001625 *
1626 * @param intent The Intent to broadcast; all receivers matching this
1627 * Intent will receive the broadcast.
1628 * @param user UserHandle to send the intent to.
1629 * @param receiverPermission (optional) String naming a permission that
1630 * a receiver must hold in order to receive your broadcast.
1631 * If null, no permission is required.
1632 *
1633 * @see #sendBroadcast(Intent, String)
1634 */
1635 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001636 @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001637
Svet Ganov16a16892015-04-16 10:32:04 -07001638
1639 /**
1640 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1641 * user the broadcast will be sent to. This is not available to applications
1642 * that are not pre-installed on the system image. Using it requires holding
1643 * the INTERACT_ACROSS_USERS permission.
1644 *
1645 * @param intent The Intent to broadcast; all receivers matching this
1646 * Intent will receive the broadcast.
1647 * @param user UserHandle to send the intent to.
1648 * @param receiverPermission (optional) String naming a permission that
1649 * a receiver must hold in order to receive your broadcast.
1650 * If null, no permission is required.
1651 * @param appOp The app op associated with the broadcast.
1652 *
1653 * @see #sendBroadcast(Intent, String)
1654 *
1655 * @hide
1656 */
1657 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1658 @Nullable String receiverPermission, int appOp);
1659
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001660 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001661 * Version of
1662 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1663 * that allows you to specify the
1664 * user the broadcast will be sent to. This is not available to applications
1665 * that are not pre-installed on the system image. Using it requires holding
1666 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001667 *
1668 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1669 *
1670 * @param intent The Intent to broadcast; all receivers matching this
1671 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001672 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001673 * @param receiverPermission String naming a permissions that
1674 * a receiver must hold in order to receive your broadcast.
1675 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001676 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1677 * receiver of the broadcast.
1678 * @param scheduler A custom Handler with which to schedule the
1679 * resultReceiver callback; if null it will be
1680 * scheduled in the Context's main thread.
1681 * @param initialCode An initial value for the result code. Often
1682 * Activity.RESULT_OK.
1683 * @param initialData An initial value for the result data. Often
1684 * null.
1685 * @param initialExtras An initial value for the result extras. Often
1686 * null.
1687 *
1688 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1689 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001690 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001691 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1692 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1693 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001694
1695 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07001696 * Similar to above but takes an appOp as well, to enforce restrictions.
1697 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1698 * BroadcastReceiver, Handler, int, String, Bundle)
1699 * @hide
1700 */
1701 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1702 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1703 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1704 @Nullable Bundle initialExtras);
1705
1706 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001707 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 * Intent you are sending stays around after the broadcast is complete,
1709 * so that others can quickly retrieve that data through the return
1710 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1711 * all other ways, this behaves the same as
1712 * {@link #sendBroadcast(Intent)}.
1713 *
1714 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1715 * permission in order to use this API. If you do not hold that
1716 * permission, {@link SecurityException} will be thrown.
1717 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001718 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1719 * can access them), no protection (anyone can modify them), and many other problems.
1720 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1721 * has changed, with another mechanism for apps to retrieve the current value whenever
1722 * desired.
1723 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 * @param intent The Intent to broadcast; all receivers matching this
1725 * Intent will receive the broadcast, and the Intent will be held to
1726 * be re-broadcast to future receivers.
1727 *
1728 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001729 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001731 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001732 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001733
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001734 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001735 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001736 * receive data back from the broadcast. This is accomplished by
1737 * supplying your own BroadcastReceiver when calling, which will be
1738 * treated as a final receiver at the end of the broadcast -- its
1739 * {@link BroadcastReceiver#onReceive} method will be called with
1740 * the result values collected from the other receivers. The broadcast will
1741 * be serialized in the same way as calling
1742 * {@link #sendOrderedBroadcast(Intent, String)}.
1743 *
1744 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1745 * asynchronous; it will return before
1746 * resultReceiver.onReceive() is called. Note that the sticky data
1747 * stored is only the data you initially supply to the broadcast, not
1748 * the result of any changes made by the receivers.
1749 *
1750 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1751 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001752 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1753 * can access them), no protection (anyone can modify them), and many other problems.
1754 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1755 * has changed, with another mechanism for apps to retrieve the current value whenever
1756 * desired.
1757 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001758 * @param intent The Intent to broadcast; all receivers matching this
1759 * Intent will receive the broadcast.
1760 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1761 * receiver of the broadcast.
1762 * @param scheduler A custom Handler with which to schedule the
1763 * resultReceiver callback; if null it will be
1764 * scheduled in the Context's main thread.
1765 * @param initialCode An initial value for the result code. Often
1766 * Activity.RESULT_OK.
1767 * @param initialData An initial value for the result data. Often
1768 * null.
1769 * @param initialExtras An initial value for the result extras. Often
1770 * null.
1771 *
1772 * @see #sendBroadcast(Intent)
1773 * @see #sendBroadcast(Intent, String)
1774 * @see #sendOrderedBroadcast(Intent, String)
1775 * @see #sendStickyBroadcast(Intent)
1776 * @see android.content.BroadcastReceiver
1777 * @see #registerReceiver
1778 * @see android.app.Activity#RESULT_OK
1779 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001780 @Deprecated
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001781 public abstract void sendStickyOrderedBroadcast(Intent intent,
1782 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001783 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1784 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001787 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 * so that it is as if the sticky broadcast had never happened.
1789 *
1790 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1791 * permission in order to use this API. If you do not hold that
1792 * permission, {@link SecurityException} will be thrown.
1793 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001794 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1795 * can access them), no protection (anyone can modify them), and many other problems.
1796 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1797 * has changed, with another mechanism for apps to retrieve the current value whenever
1798 * desired.
1799 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 * @param intent The Intent that was previously broadcast.
1801 *
1802 * @see #sendStickyBroadcast
1803 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001804 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 public abstract void removeStickyBroadcast(Intent intent);
1806
1807 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001808 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001809 * user the broadcast will be sent to. This is not available to applications
1810 * that are not pre-installed on the system image. Using it requires holding
1811 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001812 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001813 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1814 * can access them), no protection (anyone can modify them), and many other problems.
1815 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1816 * has changed, with another mechanism for apps to retrieve the current value whenever
1817 * desired.
1818 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001819 * @param intent The Intent to broadcast; all receivers matching this
1820 * Intent will receive the broadcast, and the Intent will be held to
1821 * be re-broadcast to future receivers.
1822 * @param user UserHandle to send the intent to.
1823 *
1824 * @see #sendBroadcast(Intent)
1825 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001826 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001827 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1828
1829 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001830 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07001831 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1832 * that allows you to specify the
1833 * user the broadcast will be sent to. This is not available to applications
1834 * that are not pre-installed on the system image. Using it requires holding
1835 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001836 *
1837 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1838 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001839 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1840 * can access them), no protection (anyone can modify them), and many other problems.
1841 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1842 * has changed, with another mechanism for apps to retrieve the current value whenever
1843 * desired.
1844 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001845 * @param intent The Intent to broadcast; all receivers matching this
1846 * Intent will receive the broadcast.
1847 * @param user UserHandle to send the intent to.
1848 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1849 * receiver of the broadcast.
1850 * @param scheduler A custom Handler with which to schedule the
1851 * resultReceiver callback; if null it will be
1852 * scheduled in the Context's main thread.
1853 * @param initialCode An initial value for the result code. Often
1854 * Activity.RESULT_OK.
1855 * @param initialData An initial value for the result data. Often
1856 * null.
1857 * @param initialExtras An initial value for the result extras. Often
1858 * null.
1859 *
1860 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1861 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001862 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001863 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1864 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001865 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1866 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001867
1868 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001869 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001870 * user the broadcast will be sent to. This is not available to applications
1871 * that are not pre-installed on the system image. Using it requires holding
1872 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001873 *
1874 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1875 * permission in order to use this API. If you do not hold that
1876 * permission, {@link SecurityException} will be thrown.
1877 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001878 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1879 * can access them), no protection (anyone can modify them), and many other problems.
1880 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1881 * has changed, with another mechanism for apps to retrieve the current value whenever
1882 * desired.
1883 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001884 * @param intent The Intent that was previously broadcast.
1885 * @param user UserHandle to remove the sticky broadcast from.
1886 *
1887 * @see #sendStickyBroadcastAsUser
1888 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001889 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001890 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1891
1892 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07001893 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001894 * <var>receiver</var> will be called with any broadcast Intent that
1895 * matches <var>filter</var>, in the main application thread.
1896 *
1897 * <p>The system may broadcast Intents that are "sticky" -- these stay
1898 * around after the broadcast as finished, to be sent to any later
1899 * registrations. If your IntentFilter matches one of these sticky
1900 * Intents, that Intent will be returned by this function
1901 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1902 * been broadcast.
1903 *
1904 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1905 * in which case each of these will be sent to <var>receiver</var>. In
1906 * this case, only one of these can be returned directly by the function;
1907 * which of these that is returned is arbitrarily decided by the system.
1908 *
1909 * <p>If you know the Intent your are registering for is sticky, you can
1910 * supply null for your <var>receiver</var>. In this case, no receiver is
1911 * registered -- the function simply returns the sticky Intent that
1912 * matches <var>filter</var>. In the case of multiple matches, the same
1913 * rules as described above apply.
1914 *
1915 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1916 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001917 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1918 * registered with this method will correctly respect the
1919 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1920 * Prior to that, it would be ignored and delivered to all matching registered
1921 * receivers. Be careful if using this for security.</p>
1922 *
Chris Tatea34df8a22009-04-02 23:15:58 -07001923 * <p class="note">Note: this method <em>cannot be called from a
1924 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1925 * that is declared in an application's manifest. It is okay, however, to call
1926 * this method from another BroadcastReceiver that has itself been registered
1927 * at run time with {@link #registerReceiver}, since the lifetime of such a
1928 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 *
1930 * @param receiver The BroadcastReceiver to handle the broadcast.
1931 * @param filter Selects the Intent broadcasts to be received.
1932 *
1933 * @return The first sticky intent found that matches <var>filter</var>,
1934 * or null if there are none.
1935 *
1936 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1937 * @see #sendBroadcast
1938 * @see #unregisterReceiver
1939 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001940 @Nullable
1941 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001942 IntentFilter filter);
1943
1944 /**
1945 * Register to receive intent broadcasts, to run in the context of
1946 * <var>scheduler</var>. See
1947 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1948 * information. This allows you to enforce permissions on who can
1949 * broadcast intents to your receiver, or have the receiver run in
1950 * a different thread than the main application thread.
1951 *
1952 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1953 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001954 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1955 * registered with this method will correctly respect the
1956 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1957 * Prior to that, it would be ignored and delivered to all matching registered
1958 * receivers. Be careful if using this for security.</p>
1959 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 * @param receiver The BroadcastReceiver to handle the broadcast.
1961 * @param filter Selects the Intent broadcasts to be received.
1962 * @param broadcastPermission String naming a permissions that a
1963 * broadcaster must hold in order to send an Intent to you. If null,
1964 * no permission is required.
1965 * @param scheduler Handler identifying the thread that will receive
1966 * the Intent. If null, the main thread of the process will be used.
1967 *
1968 * @return The first sticky intent found that matches <var>filter</var>,
1969 * or null if there are none.
1970 *
1971 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1972 * @see #sendBroadcast
1973 * @see #unregisterReceiver
1974 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001975 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001976 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001977 IntentFilter filter, @Nullable String broadcastPermission,
1978 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07001979
1980 /**
1981 * @hide
1982 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1983 * but for a specific user. This receiver will receiver broadcasts that
1984 * are sent to the requested user. It
1985 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1986 * permission.
1987 *
1988 * @param receiver The BroadcastReceiver to handle the broadcast.
1989 * @param user UserHandle to send the intent to.
1990 * @param filter Selects the Intent broadcasts to be received.
1991 * @param broadcastPermission String naming a permissions that a
1992 * broadcaster must hold in order to send an Intent to you. If null,
1993 * no permission is required.
1994 * @param scheduler Handler identifying the thread that will receive
1995 * the Intent. If null, the main thread of the process will be used.
1996 *
1997 * @return The first sticky intent found that matches <var>filter</var>,
1998 * or null if there are none.
1999 *
Jeff Brown6e539312015-02-24 18:53:21 -08002000 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002001 * @see #sendBroadcast
2002 * @see #unregisterReceiver
2003 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002004 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07002005 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002006 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2007 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008
2009 /**
2010 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2011 * filters that have been registered for this BroadcastReceiver will be
2012 * removed.
2013 *
2014 * @param receiver The BroadcastReceiver to unregister.
2015 *
2016 * @see #registerReceiver
2017 */
2018 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2019
2020 /**
2021 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07002022 * should contain either contain the complete class name of a specific service
2023 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07002024 * Intent is less specified, it log a warning about this and which of the
2025 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002026 * is not already running, it will be instantiated and started (creating a
2027 * process for it if needed); if it is running then it remains running.
2028 *
2029 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002030 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002031 * with the <var>intent</var> given here. This provides a convenient way
2032 * to submit jobs to a service without having to bind and call on to its
2033 * interface.
2034 *
2035 * <p>Using startService() overrides the default service lifetime that is
2036 * managed by {@link #bindService}: it requires the service to remain
2037 * running until {@link #stopService} is called, regardless of whether
2038 * any clients are connected to it. Note that calls to startService()
2039 * are not nesting: no matter how many times you call startService(),
2040 * a single call to {@link #stopService} will stop it.
2041 *
2042 * <p>The system attempts to keep running services around as much as
2043 * possible. The only time they should be stopped is if the current
2044 * foreground application is using so many resources that the service needs
2045 * to be killed. If any errors happen in the service's process, it will
2046 * automatically be restarted.
2047 *
2048 * <p>This function will throw {@link SecurityException} if you do not
2049 * have permission to start the given service.
2050 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002051 * @param service Identifies the service to be started. The Intent must be either
2052 * fully explicit (supplying a component name) or specify a specific package
2053 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002054 * may be included in the Intent extras to supply arguments along with
2055 * this specific start call.
2056 *
2057 * @return If the service is being started or is already running, the
2058 * {@link ComponentName} of the actual service that was started is
2059 * returned; else if the service does not exist null is returned.
2060 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002061 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 *
2063 * @see #stopService
2064 * @see #bindService
2065 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002066 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002067 public abstract ComponentName startService(Intent service);
2068
2069 /**
2070 * Request that a given application service be stopped. If the service is
2071 * not running, nothing happens. Otherwise it is stopped. Note that calls
2072 * to startService() are not counted -- this stops the service no matter
2073 * how many times it was started.
2074 *
2075 * <p>Note that if a stopped service still has {@link ServiceConnection}
2076 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2077 * not be destroyed until all of these bindings are removed. See
2078 * the {@link android.app.Service} documentation for more details on a
2079 * service's lifecycle.
2080 *
2081 * <p>This function will throw {@link SecurityException} if you do not
2082 * have permission to stop the given service.
2083 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002084 * @param service Description of the service to be stopped. The Intent must be either
2085 * fully explicit (supplying a component name) or specify a specific package
2086 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 *
2088 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002089 * 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 -08002090 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002091 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002092 *
2093 * @see #startService
2094 */
2095 public abstract boolean stopService(Intent service);
2096
2097 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002098 * @hide like {@link #startService(Intent)} but for a specific user.
2099 */
2100 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2101
2102 /**
2103 * @hide like {@link #stopService(Intent)} but for a specific user.
2104 */
2105 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002106
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002107 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002108 * Connect to an application service, creating it if needed. This defines
2109 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002110 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002111 * told if it dies and restarts. The service will be considered required
2112 * by the system only for as long as the calling context exists. For
2113 * example, if this Context is an Activity that is stopped, the service will
2114 * not be required to continue running until the Activity is resumed.
2115 *
2116 * <p>This function will throw {@link SecurityException} if you do not
2117 * have permission to bind to the given service.
2118 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002119 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002121 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002122 * {@link #startService} with the arguments containing the command to be
2123 * sent, with the service calling its
2124 * {@link android.app.Service#stopSelf(int)} method when done executing
2125 * that command. See the API demo App/Service/Service Start Arguments
2126 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002127 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002128 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2129 * is tied to another object (the one that registered it).</p>
2130 *
2131 * @param service Identifies the service to connect to. The Intent may
2132 * specify either an explicit component name, or a logical
2133 * description (action, category, etc) to match an
2134 * {@link IntentFilter} published by a service.
2135 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002136 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002137 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002138 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2139 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2140 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2141 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002142 * @return If you have successfully bound to the service, {@code true} is returned;
2143 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 * receive the service object.
2145 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002146 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002147 *
2148 * @see #unbindService
2149 * @see #startService
2150 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002151 * @see #BIND_DEBUG_UNBIND
2152 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002154 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
2155 @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002156
2157 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002158 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002159 * argument for use by system server and other multi-user aware code.
2160 * @hide
2161 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002162 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002163 @SuppressWarnings("unused")
2164 public boolean bindServiceAsUser(Intent service, ServiceConnection conn,
2165 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002166 throw new RuntimeException("Not implemented. Must override in a subclass.");
2167 }
2168
2169 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 * Disconnect from an application service. You will no longer receive
2171 * calls as the service is restarted, and the service is now allowed to
2172 * stop at any time.
2173 *
2174 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002175 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 *
2177 * @see #bindService
2178 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002179 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180
2181 /**
2182 * Start executing an {@link android.app.Instrumentation} class. The given
2183 * Instrumentation component will be run by killing its target application
2184 * (if currently running), starting the target process, instantiating the
2185 * instrumentation component, and then letting it drive the application.
2186 *
2187 * <p>This function is not synchronous -- it returns as soon as the
2188 * instrumentation has started and while it is running.
2189 *
2190 * <p>Instrumentation is normally only allowed to run against a package
2191 * that is either unsigned or signed with a signature that the
2192 * the instrumentation package is also signed with (ensuring the target
2193 * trusts the instrumentation).
2194 *
2195 * @param className Name of the Instrumentation component to be run.
2196 * @param profileFile Optional path to write profiling data as the
2197 * instrumentation runs, or null for no profiling.
2198 * @param arguments Additional optional arguments to pass to the
2199 * instrumentation, or null.
2200 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002201 * @return {@code true} if the instrumentation was successfully started,
2202 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002203 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002204 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2205 @Nullable String profileFile, @Nullable Bundle arguments);
2206
2207 /** @hide */
2208 @StringDef({
2209 POWER_SERVICE,
2210 WINDOW_SERVICE,
2211 LAYOUT_INFLATER_SERVICE,
2212 ACCOUNT_SERVICE,
2213 ACTIVITY_SERVICE,
2214 ALARM_SERVICE,
2215 NOTIFICATION_SERVICE,
2216 ACCESSIBILITY_SERVICE,
2217 CAPTIONING_SERVICE,
2218 KEYGUARD_SERVICE,
2219 LOCATION_SERVICE,
2220 //@hide: COUNTRY_DETECTOR,
2221 SEARCH_SERVICE,
2222 SENSOR_SERVICE,
2223 STORAGE_SERVICE,
2224 WALLPAPER_SERVICE,
2225 VIBRATOR_SERVICE,
2226 //@hide: STATUS_BAR_SERVICE,
2227 CONNECTIVITY_SERVICE,
2228 //@hide: UPDATE_LOCK_SERVICE,
2229 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002230 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002231 //@hide: NETWORK_POLICY_SERVICE,
2232 WIFI_SERVICE,
Yuhao Zhenga4864472014-04-10 11:45:42 -07002233 WIFI_PASSPOINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002234 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002235 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002236 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002237 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002238 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002239 NSD_SERVICE,
2240 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002241 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002242 MEDIA_ROUTER_SERVICE,
2243 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002244 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002245 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002246 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002247 CLIPBOARD_SERVICE,
2248 INPUT_METHOD_SERVICE,
2249 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002250 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002251 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002252 //@hide: BACKUP_SERVICE,
2253 DROPBOX_SERVICE,
2254 DEVICE_POLICY_SERVICE,
2255 UI_MODE_SERVICE,
2256 DOWNLOAD_SERVICE,
2257 NFC_SERVICE,
2258 BLUETOOTH_SERVICE,
2259 //@hide: SIP_SERVICE,
2260 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002261 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002262 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002263 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002264 INPUT_SERVICE,
2265 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002266 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002267 RESTRICTIONS_SERVICE,
2268 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002269 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002270 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002271 CONSUMER_IR_SERVICE,
2272 //@hide: TRUST_SERVICE,
2273 TV_INPUT_SERVICE,
2274 //@hide: NETWORK_SCORE_SERVICE,
2275 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002276 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002277 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002278 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002279 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002280 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002281 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002282 RADIO_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002283 })
2284 @Retention(RetentionPolicy.SOURCE)
2285 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002286
2287 /**
2288 * Return the handle to a system-level service by name. The class of the
2289 * returned object varies by the requested name. Currently available names
2290 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002291 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 * <dl>
2293 * <dt> {@link #WINDOW_SERVICE} ("window")
2294 * <dd> The top-level window manager in which you can place custom
2295 * windows. The returned object is a {@link android.view.WindowManager}.
2296 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2297 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2298 * in this context.
2299 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2300 * <dd> A {@link android.app.ActivityManager} for interacting with the
2301 * global activity state of the system.
2302 * <dt> {@link #POWER_SERVICE} ("power")
2303 * <dd> A {@link android.os.PowerManager} for controlling power
2304 * management.
2305 * <dt> {@link #ALARM_SERVICE} ("alarm")
2306 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2307 * time of your choosing.
2308 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2309 * <dd> A {@link android.app.NotificationManager} for informing the user
2310 * of background events.
2311 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2312 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2313 * <dt> {@link #LOCATION_SERVICE} ("location")
2314 * <dd> A {@link android.location.LocationManager} for controlling location
2315 * (e.g., GPS) updates.
2316 * <dt> {@link #SEARCH_SERVICE} ("search")
2317 * <dd> A {@link android.app.SearchManager} for handling search.
2318 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2319 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2320 * hardware.
2321 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2322 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2323 * handling management of network connections.
2324 * <dt> {@link #WIFI_SERVICE} ("wifi")
2325 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2326 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002327 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2328 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2329 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2331 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2332 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002333 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2334 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002335 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002336 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002337 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002338 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002339 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2340 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002341 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
2342 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
2343 * usage statistics.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002345 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 * <p>Note: System services obtained via this API may be closely associated with
2347 * the Context in which they are obtained from. In general, do not share the
2348 * service objects between various different contexts (Activities, Applications,
2349 * Services, Providers, etc.)
2350 *
2351 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002352 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002354 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 * @see #WINDOW_SERVICE
2356 * @see android.view.WindowManager
2357 * @see #LAYOUT_INFLATER_SERVICE
2358 * @see android.view.LayoutInflater
2359 * @see #ACTIVITY_SERVICE
2360 * @see android.app.ActivityManager
2361 * @see #POWER_SERVICE
2362 * @see android.os.PowerManager
2363 * @see #ALARM_SERVICE
2364 * @see android.app.AlarmManager
2365 * @see #NOTIFICATION_SERVICE
2366 * @see android.app.NotificationManager
2367 * @see #KEYGUARD_SERVICE
2368 * @see android.app.KeyguardManager
2369 * @see #LOCATION_SERVICE
2370 * @see android.location.LocationManager
2371 * @see #SEARCH_SERVICE
2372 * @see android.app.SearchManager
2373 * @see #SENSOR_SERVICE
2374 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002375 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002376 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 * @see #VIBRATOR_SERVICE
2378 * @see android.os.Vibrator
2379 * @see #CONNECTIVITY_SERVICE
2380 * @see android.net.ConnectivityManager
2381 * @see #WIFI_SERVICE
2382 * @see android.net.wifi.WifiManager
2383 * @see #AUDIO_SERVICE
2384 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002385 * @see #MEDIA_ROUTER_SERVICE
2386 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002387 * @see #TELEPHONY_SERVICE
2388 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002389 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2390 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002391 * @see #CARRIER_CONFIG_SERVICE
2392 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 * @see #INPUT_METHOD_SERVICE
2394 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002395 * @see #UI_MODE_SERVICE
2396 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002397 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002398 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002399 * @see #BATTERY_SERVICE
2400 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002401 * @see #JOB_SCHEDULER_SERVICE
2402 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002403 * @see #NETWORK_STATS_SERVICE
2404 * @see android.app.usage.NetworkStatsManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002406 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407
2408 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002409 * Return the handle to a system-level service by class.
2410 * <p>
2411 * Currently available classes are:
2412 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2413 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2414 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2415 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2416 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2417 * {@link android.net.ConnectivityManager},
2418 * {@link android.net.wifi.WifiManager},
2419 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2420 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2421 * {@link android.view.inputmethod.InputMethodManager},
2422 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002423 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
2424 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08002425 * </p><p>
2426 * Note: System services obtained via this API may be closely associated with
2427 * the Context in which they are obtained from. In general, do not share the
2428 * service objects between various different contexts (Activities, Applications,
2429 * Services, Providers, etc.)
2430 * </p>
2431 *
2432 * @param serviceClass The class of the desired service.
2433 * @return The service or null if the class is not a supported system service.
2434 */
2435 @SuppressWarnings("unchecked")
2436 public final <T> T getSystemService(Class<T> serviceClass) {
2437 // Because subclasses may override getSystemService(String) we cannot
2438 // perform a lookup by class alone. We must first map the class to its
2439 // service name then invoke the string-based method.
2440 String serviceName = getSystemServiceName(serviceClass);
2441 return serviceName != null ? (T)getSystemService(serviceName) : null;
2442 }
2443
2444 /**
2445 * Gets the name of the system-level service that is represented by the specified class.
2446 *
2447 * @param serviceClass The class of the desired service.
2448 * @return The service name or null if the class is not a supported system service.
2449 *
2450 * @hide
2451 */
2452 public abstract String getSystemServiceName(Class<?> serviceClass);
2453
2454 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 * Use with {@link #getSystemService} to retrieve a
2456 * {@link android.os.PowerManager} for controlling power management,
2457 * including "wake locks," which let you keep the device on while
2458 * you're running long tasks.
2459 */
2460 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 /**
2463 * Use with {@link #getSystemService} to retrieve a
2464 * {@link android.view.WindowManager} for accessing the system's window
2465 * manager.
2466 *
2467 * @see #getSystemService
2468 * @see android.view.WindowManager
2469 */
2470 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002472 /**
2473 * Use with {@link #getSystemService} to retrieve a
2474 * {@link android.view.LayoutInflater} for inflating layout resources in this
2475 * context.
2476 *
2477 * @see #getSystemService
2478 * @see android.view.LayoutInflater
2479 */
2480 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002481
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 /**
2483 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002484 * {@link android.accounts.AccountManager} for receiving intents at a
2485 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002486 *
2487 * @see #getSystemService
2488 * @see android.accounts.AccountManager
2489 */
2490 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002491
Fred Quintana60307342009-03-24 22:48:12 -07002492 /**
2493 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 * {@link android.app.ActivityManager} for interacting with the global
2495 * system state.
2496 *
2497 * @see #getSystemService
2498 * @see android.app.ActivityManager
2499 */
2500 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 /**
2503 * Use with {@link #getSystemService} to retrieve a
2504 * {@link android.app.AlarmManager} for receiving intents at a
2505 * time of your choosing.
2506 *
2507 * @see #getSystemService
2508 * @see android.app.AlarmManager
2509 */
2510 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002511
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 /**
2513 * Use with {@link #getSystemService} to retrieve a
2514 * {@link android.app.NotificationManager} for informing the user of
2515 * background events.
2516 *
2517 * @see #getSystemService
2518 * @see android.app.NotificationManager
2519 */
2520 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 /**
2523 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002524 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2525 * feedback for UI events through the registered event listeners.
2526 *
2527 * @see #getSystemService
2528 * @see android.view.accessibility.AccessibilityManager
2529 */
2530 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002531
svetoslavganov75986cf2009-05-14 22:28:01 -07002532 /**
2533 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002534 * {@link android.view.accessibility.CaptioningManager} for obtaining
2535 * captioning properties and listening for changes in captioning
2536 * preferences.
2537 *
2538 * @see #getSystemService
2539 * @see android.view.accessibility.CaptioningManager
2540 */
2541 public static final String CAPTIONING_SERVICE = "captioning";
2542
2543 /**
2544 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 * {@link android.app.NotificationManager} for controlling keyguard.
2546 *
2547 * @see #getSystemService
2548 * @see android.app.KeyguardManager
2549 */
2550 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002552 /**
2553 * Use with {@link #getSystemService} to retrieve a {@link
2554 * android.location.LocationManager} for controlling location
2555 * updates.
2556 *
2557 * @see #getSystemService
2558 * @see android.location.LocationManager
2559 */
2560 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002561
2562 /**
2563 * Use with {@link #getSystemService} to retrieve a
2564 * {@link android.location.CountryDetector} for detecting the country that
2565 * the user is in.
2566 *
2567 * @hide
2568 */
2569 public static final String COUNTRY_DETECTOR = "country_detector";
2570
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571 /**
2572 * Use with {@link #getSystemService} to retrieve a {@link
2573 * android.app.SearchManager} for handling searches.
2574 *
2575 * @see #getSystemService
2576 * @see android.app.SearchManager
2577 */
2578 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 /**
2581 * Use with {@link #getSystemService} to retrieve a {@link
2582 * android.hardware.SensorManager} for accessing sensors.
2583 *
2584 * @see #getSystemService
2585 * @see android.hardware.SensorManager
2586 */
2587 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07002588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 /**
San Mehatc9d81752010-02-01 10:23:27 -08002590 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07002591 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08002592 * functions.
2593 *
2594 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08002595 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08002596 */
2597 public static final String STORAGE_SERVICE = "storage";
2598
2599 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 * Use with {@link #getSystemService} to retrieve a
2601 * com.android.server.WallpaperService for accessing wallpapers.
2602 *
2603 * @see #getSystemService
2604 */
2605 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07002606
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002607 /**
2608 * Use with {@link #getSystemService} to retrieve a {@link
2609 * android.os.Vibrator} for interacting with the vibration hardware.
2610 *
2611 * @see #getSystemService
2612 * @see android.os.Vibrator
2613 */
2614 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002615
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002616 /**
2617 * Use with {@link #getSystemService} to retrieve a {@link
2618 * android.app.StatusBarManager} for interacting with the status bar.
2619 *
2620 * @see #getSystemService
2621 * @see android.app.StatusBarManager
2622 * @hide
2623 */
2624 public static final String STATUS_BAR_SERVICE = "statusbar";
2625
2626 /**
2627 * Use with {@link #getSystemService} to retrieve a {@link
2628 * android.net.ConnectivityManager} for handling management of
2629 * network connections.
2630 *
2631 * @see #getSystemService
2632 * @see android.net.ConnectivityManager
2633 */
2634 public static final String CONNECTIVITY_SERVICE = "connectivity";
2635
2636 /**
2637 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002638 * android.os.IUpdateLock} for managing runtime sequences that
2639 * must not be interrupted by headless OTA application or similar.
2640 *
2641 * @hide
2642 * @see #getSystemService
2643 * @see android.os.UpdateLock
2644 */
2645 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2646
2647 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002648 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07002649 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08002650 */
2651 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2652
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002653 /**
2654 * Use with {@link #getSystemService} to retrieve a {@link
2655 * android.app.usage.NetworkStatsManager} for querying network usage stats.
2656 *
2657 * @see #getSystemService
2658 * @see android.app.usage.NetworkStatsManager
2659 */
Jeff Sharkey75279902011-05-24 18:39:45 -07002660 public static final String NETWORK_STATS_SERVICE = "netstats";
2661 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002662 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2663
San Mehatd1df8ac2010-01-26 06:17:26 -08002664 /**
2665 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 * android.net.wifi.WifiManager} for handling management of
2667 * Wi-Fi access.
2668 *
2669 * @see #getSystemService
2670 * @see android.net.wifi.WifiManager
2671 */
2672 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002673
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 /**
repo sync55bc5f32011-06-24 14:23:07 -07002675 * Use with {@link #getSystemService} to retrieve a {@link
Roger Chang7fee7232014-05-15 14:46:49 -07002676 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
Yuhao Zhenga4864472014-04-10 11:45:42 -07002677 * Wi-Fi passpoint access.
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002678 *
2679 * @see #getSystemService
Roger Chang7fee7232014-05-15 14:46:49 -07002680 * @see android.net.wifi.passpoint.WifiPasspointManager
Yuhao Zheng0cb59f22014-05-27 10:35:02 -07002681 * @hide
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002682 */
Yuhao Zhenga4864472014-04-10 11:45:42 -07002683 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002684
2685 /**
2686 * Use with {@link #getSystemService} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07002687 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002688 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002689 *
2690 * @see #getSystemService
2691 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002692 */
2693 public static final String WIFI_P2P_SERVICE = "wifip2p";
2694
2695 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002696 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002697 * android.net.wifi.WifiScanner} for scanning the wifi universe
2698 *
2699 * @see #getSystemService
2700 * @see android.net.wifi.WifiScanner
2701 * @hide
2702 */
Wei Wang35d552f2014-07-08 21:37:01 -07002703 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002704 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2705
2706 /**
2707 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07002708 * android.net.wifi.RttManager} for ranging devices with wifi
2709 *
2710 * @see #getSystemService
2711 * @see android.net.wifi.RttManager
2712 * @hide
2713 */
2714 @SystemApi
2715 public static final String WIFI_RTT_SERVICE = "rttmanager";
2716
2717 /**
2718 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002719 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002720 * Ethernet access.
2721 *
2722 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002723 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002724 *
2725 * @hide
2726 */
2727 public static final String ETHERNET_SERVICE = "ethernet";
2728
2729 /**
2730 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002731 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002732 * discovery
2733 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002734 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002735 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002736 */
2737 public static final String NSD_SERVICE = "servicediscovery";
2738
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002739 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002740 * Use with {@link #getSystemService} to retrieve a
2741 * {@link android.media.AudioManager} for handling management of volume,
2742 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002743 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 * @see #getSystemService
2745 * @see android.media.AudioManager
2746 */
2747 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002748
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002749 /**
2750 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07002751 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07002752 * of fingerprints.
2753 *
2754 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07002755 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07002756 */
2757 public static final String FINGERPRINT_SERVICE = "fingerprint";
2758
2759 /**
2760 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002761 * {@link android.media.MediaRouter} for controlling and managing
2762 * routing of media.
2763 *
2764 * @see #getSystemService
2765 * @see android.media.MediaRouter
2766 */
2767 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2768
2769 /**
2770 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07002771 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08002772 *
2773 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07002774 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08002775 */
2776 public static final String MEDIA_SESSION_SERVICE = "media_session";
2777
2778 /**
2779 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 * {@link android.telephony.TelephonyManager} for handling management the
2781 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002782 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 * @see #getSystemService
2784 * @see android.telephony.TelephonyManager
2785 */
2786 public static final String TELEPHONY_SERVICE = "phone";
2787
2788 /**
2789 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08002790 * {@link android.telephony.SubscriptionManager} for handling management the
2791 * telephony subscriptions of the device.
2792 *
2793 * @see #getSystemService
2794 * @see android.telephony.SubscriptionManager
2795 */
2796 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
2797
2798 /**
2799 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002800 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07002801 * of the device.
2802 *
2803 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002804 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07002805 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002806 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07002807
2808 /**
2809 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002810 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
2811 *
2812 * @see #getSystemService
2813 * @see android.telephony.CarrierConfigManager
2814 */
2815 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
2816
2817 /**
2818 * Use with {@link #getSystemService} to retrieve a
2819 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08002820 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002822 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08002824 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 */
2826 public static final String CLIPBOARD_SERVICE = "clipboard";
2827
2828 /**
Scott Main4b5da682010-10-21 11:49:12 -07002829 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2831 * methods.
2832 *
2833 * @see #getSystemService
2834 */
2835 public static final String INPUT_METHOD_SERVICE = "input_method";
2836
2837 /**
2838 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002839 * {@link android.view.textservice.TextServicesManager} for accessing
2840 * text services.
2841 *
2842 * @see #getSystemService
2843 */
2844 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2845
2846 /**
2847 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002848 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 * @see #getSystemService
2851 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002852 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002853
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002854 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07002855 * Official published name of the (internal) voice interaction manager service.
2856 *
2857 * @hide
2858 * @see #getSystemService
2859 */
2860 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2861
2862 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002863 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002864 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002865 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002866 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002867 *
Christopher Tate487529a2009-04-29 14:03:25 -07002868 * @see #getSystemService
2869 */
Christopher Tated5cf7222014-07-29 16:53:09 -07002870 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07002871 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002872
2873 /**
2874 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002875 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002876 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002877 * @see #getSystemService
2878 */
2879 public static final String DROPBOX_SERVICE = "dropbox";
2880
Christopher Tate487529a2009-04-29 14:03:25 -07002881 /**
Scott Main4b5da682010-10-21 11:49:12 -07002882 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002883 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002884 * device policy management.
2885 *
2886 * @see #getSystemService
2887 */
2888 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2889
2890 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002891 * Use with {@link #getSystemService} to retrieve a
2892 * {@link android.app.UiModeManager} for controlling UI modes.
2893 *
2894 * @see #getSystemService
2895 */
2896 public static final String UI_MODE_SERVICE = "uimode";
2897
2898 /**
Steve Howarda2709362010-07-02 17:12:48 -07002899 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002900 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002901 *
2902 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002903 */
2904 public static final String DOWNLOAD_SERVICE = "download";
2905
2906 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002907 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08002908 * {@link android.os.BatteryManager} for managing battery state.
2909 *
2910 * @see #getSystemService
2911 */
2912 public static final String BATTERY_SERVICE = "batterymanager";
2913
2914 /**
2915 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002916 * {@link android.nfc.NfcManager} for using NFC.
2917 *
2918 * @see #getSystemService
2919 */
2920 public static final String NFC_SERVICE = "nfc";
2921
2922 /**
2923 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00002924 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002925 *
2926 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002927 */
2928 public static final String BLUETOOTH_SERVICE = "bluetooth";
2929
2930 /**
2931 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002932 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2933 *
2934 * @see #getSystemService
2935 */
2936 /** @hide */
2937 public static final String SIP_SERVICE = "sip";
2938
2939 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002940 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002941 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002942 * and for controlling this device's behavior as a USB device.
2943 *
2944 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04002945 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002946 */
2947 public static final String USB_SERVICE = "usb";
2948
2949 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002950 * Use with {@link #getSystemService} to retrieve a {@link
2951 * android.hardware.SerialManager} for access to serial ports.
2952 *
2953 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002954 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002955 *
2956 * @hide
2957 */
2958 public static final String SERIAL_SERVICE = "serial";
2959
2960 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002961 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09002962 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2963 * HDMI-CEC protocol.
2964 *
2965 * @see #getSystemService
2966 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002967 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09002968 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002969 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09002970 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09002971
2972 /**
2973 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002974 * {@link android.hardware.input.InputManager} for interacting with input devices.
2975 *
2976 * @see #getSystemService
2977 * @see android.hardware.input.InputManager
2978 */
2979 public static final String INPUT_SERVICE = "input";
2980
2981 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002982 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002983 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2984 *
2985 * @see #getSystemService
2986 * @see android.hardware.display.DisplayManager
2987 */
2988 public static final String DISPLAY_SERVICE = "display";
2989
2990 /**
2991 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07002992 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2993 *
2994 * @see #getSystemService
2995 * @see android.os.UserManager
2996 */
2997 public static final String USER_SERVICE = "user";
2998
2999 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003000 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003001 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3002 * profiles of a user.
3003 *
3004 * @see #getSystemService
3005 * @see android.content.pm.LauncherApps
3006 */
3007 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3008
3009 /**
3010 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003011 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3012 * and requesting permissions for restricted operations.
3013 * @see #getSystemService
3014 * @see android.content.RestrictionsManager
3015 */
3016 public static final String RESTRICTIONS_SERVICE = "restrictions";
3017
3018 /**
3019 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003020 * {@link android.app.AppOpsManager} for tracking application operations
3021 * on the device.
3022 *
3023 * @see #getSystemService
3024 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003025 */
3026 public static final String APP_OPS_SERVICE = "appops";
3027
3028 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003029 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003030 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003031 * camera devices.
3032 *
3033 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003034 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003035 */
3036 public static final String CAMERA_SERVICE = "camera";
3037
3038 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003039 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003040 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003041 *
3042 * @see #getSystemService
3043 * @see android.print.PrintManager
3044 */
3045 public static final String PRINT_SERVICE = "print";
3046
3047 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003048 * Use with {@link #getSystemService} to retrieve a
3049 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3050 * signals from the device.
3051 *
3052 * @see #getSystemService
3053 * @see android.hardware.ConsumerIrManager
3054 */
3055 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3056
3057 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003058 * {@link android.app.trust.TrustManager} for managing trust agents.
3059 * @see #getSystemService
3060 * @see android.app.trust.TrustManager
3061 * @hide
3062 */
3063 public static final String TRUST_SERVICE = "trust";
3064
3065 /**
Jae Seo39570912014-02-20 18:23:25 -08003066 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003067 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3068 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003069 *
3070 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003071 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003072 */
3073 public static final String TV_INPUT_SERVICE = "tv_input";
3074
3075 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003076 * {@link android.net.NetworkScoreManager} for managing network scoring.
3077 * @see #getSystemService
3078 * @see android.net.NetworkScoreManager
3079 * @hide
3080 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003081 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003082 public static final String NETWORK_SCORE_SERVICE = "network_score";
3083
3084 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003085 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003086 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003087 *
3088 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003089 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003090 */
3091 public static final String USAGE_STATS_SERVICE = "usagestats";
3092
3093 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003094 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003095 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003096 * background tasks.
3097 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003098 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003099 */
Christopher Tate7060b042014-06-09 19:50:00 -07003100 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003101
3102 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003103 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003104 * android.service.persistentdata.PersistentDataBlockManager} instance
3105 * for interacting with a storage device that lives across factory resets.
3106 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003107 * @see #getSystemService
3108 * @see android.service.persistentdata.PersistentDataBlockManager
3109 * @hide
3110 */
Andres Morales33df9372014-09-26 17:08:59 -07003111 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003112 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3113
3114 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003115 * Use with {@link #getSystemService} to retrieve a {@link
3116 * android.media.projection.MediaProjectionManager} instance for managing
3117 * media projection sessions.
3118 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003119 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003120 */
3121 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3122
3123 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003124 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003125 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003126 *
3127 * @see #getSystemService
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003128 */
3129 public static final String MIDI_SERVICE = "midi";
3130
Eric Laurent2035ac82015-03-05 15:18:44 -08003131
3132 /**
3133 * Use with {@link #getSystemService} to retrieve a
3134 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3135 *
3136 * @see #getSystemService
3137 * @hide
3138 */
3139 public static final String RADIO_SERVICE = "radio";
3140
Paul McLeana33be212015-02-20 07:52:45 -08003141 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 * Determine whether the given permission is allowed for a particular
3143 * process and user ID running in the system.
3144 *
3145 * @param permission The name of the permission being checked.
3146 * @param pid The process ID being checked against. Must be > 0.
3147 * @param uid The user ID being checked against. A uid of 0 is the root
3148 * user, which will pass every permission check.
3149 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003150 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 * pid/uid is allowed that permission, or
3152 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3153 *
3154 * @see PackageManager#checkPermission(String, String)
3155 * @see #checkCallingPermission
3156 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003157 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003158 @PackageManager.PermissionResult
3159 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003160
Dianne Hackbornff170242014-11-19 10:59:01 -08003161 /** @hide */
3162 @PackageManager.PermissionResult
3163 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3164 IBinder callerToken);
3165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 /**
3167 * Determine whether the calling process of an IPC you are handling has been
3168 * granted a particular permission. This is basically the same as calling
3169 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3170 * by {@link android.os.Binder#getCallingPid} and
3171 * {@link android.os.Binder#getCallingUid}. One important difference
3172 * is that if you are not currently processing an IPC, this function
3173 * will always fail. This is done to protect against accidentally
3174 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3175 * to avoid this protection.
3176 *
3177 * @param permission The name of the permission being checked.
3178 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003179 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 * pid/uid is allowed that permission, or
3181 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3182 *
3183 * @see PackageManager#checkPermission(String, String)
3184 * @see #checkPermission
3185 * @see #checkCallingOrSelfPermission
3186 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003187 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003188 @PackageManager.PermissionResult
3189 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003190
3191 /**
3192 * Determine whether the calling process of an IPC <em>or you</em> have been
3193 * granted a particular permission. This is the same as
3194 * {@link #checkCallingPermission}, except it grants your own permissions
3195 * if you are not currently processing an IPC. Use with care!
3196 *
3197 * @param permission The name of the permission being checked.
3198 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003199 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003200 * pid/uid is allowed that permission, or
3201 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3202 *
3203 * @see PackageManager#checkPermission(String, String)
3204 * @see #checkPermission
3205 * @see #checkCallingPermission
3206 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003207 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003208 @PackageManager.PermissionResult
3209 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210
3211 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08003212 * Determine whether <em>you</em> have been granted a particular permission.
3213 *
3214 * @param permission The name of the permission being checked.
3215 *
3216 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
3217 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
3218 *
3219 * @see PackageManager#checkPermission(String, String)
3220 * @see #checkCallingPermission(String)
3221 */
3222 @PackageManager.PermissionResult
3223 public abstract int checkSelfPermission(@NonNull String permission);
3224
3225 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 * If the given permission is not allowed for a particular process
3227 * and user ID running in the system, throw a {@link SecurityException}.
3228 *
3229 * @param permission The name of the permission being checked.
3230 * @param pid The process ID being checked against. Must be &gt; 0.
3231 * @param uid The user ID being checked against. A uid of 0 is the root
3232 * user, which will pass every permission check.
3233 * @param message A message to include in the exception if it is thrown.
3234 *
3235 * @see #checkPermission(String, int, int)
3236 */
3237 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003238 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239
3240 /**
3241 * If the calling process of an IPC you are handling has not been
3242 * granted a particular permission, throw a {@link
3243 * SecurityException}. This is basically the same as calling
3244 * {@link #enforcePermission(String, int, int, String)} with the
3245 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3246 * and {@link android.os.Binder#getCallingUid}. One important
3247 * difference is that if you are not currently processing an IPC,
3248 * this function will always throw the SecurityException. This is
3249 * done to protect against accidentally leaking permissions; you
3250 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3251 * protection.
3252 *
3253 * @param permission The name of the permission being checked.
3254 * @param message A message to include in the exception if it is thrown.
3255 *
3256 * @see #checkCallingPermission(String)
3257 */
3258 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003259 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260
3261 /**
3262 * If neither you nor the calling process of an IPC you are
3263 * handling has been granted a particular permission, throw a
3264 * {@link SecurityException}. This is the same as {@link
3265 * #enforceCallingPermission}, except it grants your own
3266 * permissions if you are not currently processing an IPC. Use
3267 * with care!
3268 *
3269 * @param permission The name of the permission being checked.
3270 * @param message A message to include in the exception if it is thrown.
3271 *
3272 * @see #checkCallingOrSelfPermission(String)
3273 */
3274 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003275 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276
3277 /**
3278 * Grant permission to access a specific Uri to another package, regardless
3279 * of whether that package has general permission to access the Uri's
3280 * content provider. This can be used to grant specific, temporary
3281 * permissions, typically in response to user interaction (such as the
3282 * user opening an attachment that you would like someone else to
3283 * display).
3284 *
3285 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3286 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3287 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3288 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3289 * start an activity instead of this function directly. If you use this
3290 * function directly, you should be sure to call
3291 * {@link #revokeUriPermission} when the target should no longer be allowed
3292 * to access it.
3293 *
3294 * <p>To succeed, the content provider owning the Uri must have set the
3295 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3296 * grantUriPermissions} attribute in its manifest or included the
3297 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3298 * &lt;grant-uri-permissions&gt;} tag.
3299 *
3300 * @param toPackage The package you would like to allow to access the Uri.
3301 * @param uri The Uri you would like to grant access to.
3302 * @param modeFlags The desired access modes. Any combination of
3303 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003304 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003305 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003306 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3307 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3308 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3309 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3310 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003311 *
3312 * @see #revokeUriPermission
3313 */
3314 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003315 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316
3317 /**
3318 * Remove all permissions to access a particular content provider Uri
3319 * that were previously added with {@link #grantUriPermission}. The given
3320 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003321 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003323 * "content://foo". It will not remove any prefix grants that exist at a
3324 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003325 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003326 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003327 * regular permission access to a Uri, but had received access to it through
3328 * a specific Uri permission grant, you could not revoke that grant with this
3329 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003330 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003331 * but will remove whatever permission grants to the Uri had been given to the app
3332 * (or none).</p>
3333 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 * @param uri The Uri you would like to revoke access to.
3335 * @param modeFlags The desired access modes. Any combination of
3336 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3337 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3338 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3339 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3340 *
3341 * @see #grantUriPermission
3342 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003343 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344
3345 /**
3346 * Determine whether a particular process and user ID has been granted
3347 * permission to access a specific URI. This only checks for permissions
3348 * that have been explicitly granted -- if the given process/uid has
3349 * more general access to the URI's content provider then this check will
3350 * always fail.
3351 *
3352 * @param uri The uri that is being checked.
3353 * @param pid The process ID being checked against. Must be &gt; 0.
3354 * @param uid The user ID being checked against. A uid of 0 is the root
3355 * user, which will pass every permission check.
3356 * @param modeFlags The type of access to grant. May be one or both of
3357 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3358 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3359 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003360 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003361 * pid/uid is allowed to access that uri, or
3362 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3363 *
3364 * @see #checkCallingUriPermission
3365 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003366 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003367 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003368 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369
Dianne Hackbornff170242014-11-19 10:59:01 -08003370 /** @hide */
3371 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3372 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 /**
3375 * Determine whether the calling process and user ID has been
3376 * granted permission to access a specific URI. This is basically
3377 * the same as calling {@link #checkUriPermission(Uri, int, int,
3378 * int)} with the pid and uid returned by {@link
3379 * android.os.Binder#getCallingPid} and {@link
3380 * android.os.Binder#getCallingUid}. One important difference is
3381 * that if you are not currently processing an IPC, this function
3382 * will always fail.
3383 *
3384 * @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 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003389 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 * is allowed to access that uri, or
3391 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3392 *
3393 * @see #checkUriPermission(Uri, int, int, int)
3394 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003395 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003396 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003397
3398 /**
3399 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3400 * permission to access a specific URI. This is the same as
3401 * {@link #checkCallingUriPermission}, except it grants your own permissions
3402 * if you are not currently processing an IPC. Use with care!
3403 *
3404 * @param uri The uri that is being checked.
3405 * @param modeFlags The type of access to grant. May be one or both of
3406 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3407 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3408 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003409 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 * is allowed to access that uri, or
3411 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3412 *
3413 * @see #checkCallingUriPermission
3414 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003415 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003416 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003417 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418
3419 /**
3420 * Check both a Uri and normal permission. This allows you to perform
3421 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3422 * call.
3423 *
3424 * @param uri The Uri whose permission is to be checked, or null to not
3425 * do this check.
3426 * @param readPermission The permission that provides overall read access,
3427 * or null to not do this check.
3428 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003429 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 * @param pid The process ID being checked against. Must be &gt; 0.
3431 * @param uid The user ID being checked against. A uid of 0 is the root
3432 * user, which will pass every permission check.
3433 * @param modeFlags The type of access to grant. May be one or both of
3434 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3435 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3436 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003437 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 * is allowed to access that uri or holds one of the given permissions, or
3439 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3440 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003441 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003442 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3443 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003444 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003445
3446 /**
3447 * If a particular process and user ID has not been granted
3448 * permission to access a specific URI, throw {@link
3449 * SecurityException}. This only checks for permissions that have
3450 * been explicitly granted -- if the given process/uid has more
3451 * general access to the URI's content provider then this check
3452 * will always fail.
3453 *
3454 * @param uri The uri that is being checked.
3455 * @param pid The process ID being checked against. Must be &gt; 0.
3456 * @param uid The user ID being checked against. A uid of 0 is the root
3457 * user, which will pass every permission check.
3458 * @param modeFlags The type of access to grant. May be one or both of
3459 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3460 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3461 * @param message A message to include in the exception if it is thrown.
3462 *
3463 * @see #checkUriPermission(Uri, int, int, int)
3464 */
3465 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003466 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003467
3468 /**
3469 * If the calling process and user ID has not been granted
3470 * permission to access a specific URI, throw {@link
3471 * SecurityException}. This is basically the same as calling
3472 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3473 * the pid and uid returned by {@link
3474 * android.os.Binder#getCallingPid} and {@link
3475 * android.os.Binder#getCallingUid}. One important difference is
3476 * that if you are not currently processing an IPC, this function
3477 * will always throw a SecurityException.
3478 *
3479 * @param uri The uri that is being checked.
3480 * @param modeFlags The type of access to grant. May be one or both of
3481 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3482 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3483 * @param message A message to include in the exception if it is thrown.
3484 *
3485 * @see #checkCallingUriPermission(Uri, int)
3486 */
3487 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003488 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489
3490 /**
3491 * If the calling process of an IPC <em>or you</em> has not been
3492 * granted permission to access a specific URI, throw {@link
3493 * SecurityException}. This is the same as {@link
3494 * #enforceCallingUriPermission}, except it grants your own
3495 * permissions if you are not currently processing an IPC. Use
3496 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003497 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 * @param uri The uri that is being checked.
3499 * @param modeFlags The type of access to grant. May be one or both of
3500 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3501 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3502 * @param message A message to include in the exception if it is thrown.
3503 *
3504 * @see #checkCallingOrSelfUriPermission(Uri, int)
3505 */
3506 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003507 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508
3509 /**
3510 * Enforce both a Uri and normal permission. This allows you to perform
3511 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3512 * call.
Scott Main4b5da682010-10-21 11:49:12 -07003513 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 * @param uri The Uri whose permission is to be checked, or null to not
3515 * do this check.
3516 * @param readPermission The permission that provides overall read access,
3517 * or null to not do this check.
3518 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003519 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 * @param pid The process ID being checked against. Must be &gt; 0.
3521 * @param uid The user ID being checked against. A uid of 0 is the root
3522 * user, which will pass every permission check.
3523 * @param modeFlags The type of access to grant. May be one or both of
3524 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3525 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3526 * @param message A message to include in the exception if it is thrown.
3527 *
3528 * @see #checkUriPermission(Uri, String, String, int, int, int)
3529 */
3530 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003531 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003532 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07003533 @Nullable String message);
3534
3535 /** @hide */
3536 @IntDef(flag = true,
3537 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3538 @Retention(RetentionPolicy.SOURCE)
3539 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540
3541 /**
3542 * Flag for use with {@link #createPackageContext}: include the application
3543 * code with the context. This means loading code into the caller's
3544 * process, so that {@link #getClassLoader()} can be used to instantiate
3545 * the application's classes. Setting this flags imposes security
3546 * restrictions on what application context you can access; if the
3547 * requested application can not be safely loaded into your process,
3548 * java.lang.SecurityException will be thrown. If this flag is not set,
3549 * there will be no restrictions on the packages that can be loaded,
3550 * but {@link #getClassLoader} will always return the default system
3551 * class loader.
3552 */
3553 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3554
3555 /**
3556 * Flag for use with {@link #createPackageContext}: ignore any security
3557 * restrictions on the Context being requested, allowing it to always
3558 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3559 * to be loaded into a process even when it isn't safe to do so. Use
3560 * with extreme care!
3561 */
3562 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07003563
Romain Guy870e09f2009-07-06 16:35:25 -07003564 /**
3565 * Flag for use with {@link #createPackageContext}: a restricted context may
3566 * disable specific features. For instance, a View associated with a restricted
3567 * context would ignore particular XML attributes.
3568 */
3569 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570
3571 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003572 * @hide Used to indicate we should tell the activity manager about the process
3573 * loading this code.
3574 */
3575 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
3576
3577 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 * Return a new Context object for the given application name. This
3579 * Context is the same as what the named application gets when it is
3580 * launched, containing the same resources and class loader. Each call to
3581 * this method returns a new instance of a Context object; Context objects
3582 * are not shared, however they share common state (Resources, ClassLoader,
3583 * etc) so the Context instance itself is fairly lightweight.
3584 *
Jeff Brown6e539312015-02-24 18:53:21 -08003585 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 * application with the given package name.
3587 *
3588 * <p>Throws {@link java.lang.SecurityException} if the Context requested
3589 * can not be loaded into the caller's process for security reasons (see
3590 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3591 *
3592 * @param packageName Name of the application's package.
3593 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3594 * or {@link #CONTEXT_IGNORE_SECURITY}.
3595 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003596 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003598 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04003600 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003601 */
3602 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07003603 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07003604
3605 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07003606 * Similar to {@link #createPackageContext(String, int)}, but with a
3607 * different {@link UserHandle}. For example, {@link #getContentResolver()}
3608 * will open any {@link Uri} as the given user.
3609 *
3610 * @hide
3611 */
3612 public abstract Context createPackageContextAsUser(
3613 String packageName, int flags, UserHandle user)
3614 throws PackageManager.NameNotFoundException;
3615
3616 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07003617 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
3618 *
3619 * @hide
3620 */
3621 public abstract Context createApplicationContext(ApplicationInfo application,
3622 int flags) throws PackageManager.NameNotFoundException;
3623
3624 /**
Jim Millera75a8832013-02-07 16:53:32 -08003625 * Get the userId associated with this context
3626 * @return user id
3627 *
3628 * @hide
3629 */
3630 public abstract int getUserId();
3631
3632 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07003633 * Return a new Context object for the current Context but whose resources
3634 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07003635 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07003636 * shared, however common state (ClassLoader, other Resources for the
3637 * same configuration) may be so the Context itself can be fairly lightweight.
3638 *
3639 * @param overrideConfiguration A {@link Configuration} specifying what
3640 * values to modify in the base Configuration of the original Context's
3641 * resources. If the base configuration changes (such as due to an
3642 * orientation change), the resources of this context will also change except
3643 * for those that have been explicitly overridden with a value here.
3644 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003645 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07003646 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003647 public abstract Context createConfigurationContext(
3648 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07003649
3650 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07003651 * Return a new Context object for the current Context but whose resources
3652 * are adjusted to match the metrics of the given Display. Each call to this method
3653 * returns a new instance of a Context object; Context objects are not
3654 * shared, however common state (ClassLoader, other Resources for the
3655 * same configuration) may be so the Context itself can be fairly lightweight.
3656 *
3657 * The returned display Context provides a {@link WindowManager}
3658 * (see {@link #getSystemService(String)}) that is configured to show windows
3659 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
3660 * method can be used to retrieve the Display from the returned Context.
3661 *
3662 * @param display A {@link Display} object specifying the display
3663 * for whose metrics the Context's resources should be tailored and upon which
3664 * new windows should be shown.
3665 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003666 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07003667 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003668 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07003669
3670 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07003671 * Gets the display adjustments holder for this context. This information
3672 * is provided on a per-application or activity basis and is used to simulate lower density
3673 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07003674 *
Jeff Browna492c3a2012-08-23 19:48:44 -07003675 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07003676 * @return The compatibility info holder, or null if not required by the application.
3677 * @hide
3678 */
Craig Mautner48d0d182013-06-11 07:53:06 -07003679 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07003680
3681 /**
Romain Guy870e09f2009-07-06 16:35:25 -07003682 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07003683 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003684 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07003685 *
Romain Guy870e09f2009-07-06 16:35:25 -07003686 * @see #CONTEXT_RESTRICTED
3687 */
3688 public boolean isRestricted() {
3689 return false;
3690 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003691}