blob: 370f61cd7b30dcdbd8ba2b712932d75990c71469 [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 Norbyed9273d62013-05-30 15:59:53 -070021import android.annotation.IntDef;
22import android.annotation.NonNull;
23import android.annotation.Nullable;
24import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070025import android.annotation.StringRes;
26import android.annotation.StyleRes;
27import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090028import android.annotation.SystemApi;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070029import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.content.pm.PackageManager;
31import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080032import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070033import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.content.res.Resources;
35import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070036import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.database.sqlite.SQLiteDatabase;
38import android.database.sqlite.SQLiteDatabase.CursorFactory;
39import android.graphics.Bitmap;
40import android.graphics.drawable.Drawable;
41import android.net.Uri;
42import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070043import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.os.Handler;
Dianne Hackbornff170242014-11-19 10:59:01 -080045import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070047import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070048import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070049import android.os.UserManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070050import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051import android.util.AttributeSet;
Craig Mautner48d0d182013-06-11 07:53:06 -070052import android.view.DisplayAdjustments;
Jeff Browna492c3a2012-08-23 19:48:44 -070053import android.view.Display;
Jon Miranda836c0a82014-08-11 12:32:26 -070054import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070055import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056
57import java.io.File;
58import java.io.FileInputStream;
59import java.io.FileNotFoundException;
60import java.io.FileOutputStream;
61import java.io.IOException;
62import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070063import java.lang.annotation.Retention;
64import java.lang.annotation.RetentionPolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065
66/**
67 * Interface to global information about an application environment. This is
68 * an abstract class whose implementation is provided by
69 * the Android system. It
70 * allows access to application-specific resources and classes, as well as
71 * up-calls for application-level operations such as launching activities,
72 * broadcasting and receiving intents, etc.
73 */
74public abstract class Context {
75 /**
76 * File creation mode: the default mode, where the created file can only
77 * be accessed by the calling application (or all applications sharing the
78 * same user ID).
79 * @see #MODE_WORLD_READABLE
80 * @see #MODE_WORLD_WRITEABLE
81 */
82 public static final int MODE_PRIVATE = 0x0000;
83 /**
Nick Kralevich15069212013-01-09 15:54:56 -080084 * @deprecated Creating world-readable files is very dangerous, and likely
85 * to cause security holes in applications. It is strongly discouraged;
86 * instead, applications should use more formal mechanism for interactions
87 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
88 * {@link android.app.Service}. There are no guarantees that this
89 * access mode will remain on a file, such as when it goes through a
90 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 * File creation mode: allow all other applications to have read access
92 * to the created file.
93 * @see #MODE_PRIVATE
94 * @see #MODE_WORLD_WRITEABLE
95 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -070096 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080097 public static final int MODE_WORLD_READABLE = 0x0001;
98 /**
Nick Kralevich15069212013-01-09 15:54:56 -080099 * @deprecated Creating world-writable files is very dangerous, and likely
100 * to cause security holes in applications. It is strongly discouraged;
101 * instead, applications should use more formal mechanism for interactions
102 * such as {@link ContentProvider}, {@link BroadcastReceiver}, and
103 * {@link android.app.Service}. There are no guarantees that this
104 * access mode will remain on a file, such as when it goes through a
105 * backup and restore.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 * File creation mode: allow all other applications to have write access
107 * to the created file.
108 * @see #MODE_PRIVATE
109 * @see #MODE_WORLD_READABLE
110 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700111 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 public static final int MODE_WORLD_WRITEABLE = 0x0002;
113 /**
114 * File creation mode: for use with {@link #openFileOutput}, if the file
115 * already exists then write data to the end of the existing file
116 * instead of erasing it.
117 * @see #openFileOutput
118 */
119 public static final int MODE_APPEND = 0x8000;
120
121 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800122 * SharedPreference loading flag: when set, the file on disk will
123 * be checked for modification even if the shared preferences
124 * instance is already loaded in this process. This behavior is
125 * sometimes desired in cases where the application has multiple
126 * processes, all writing to the same SharedPreferences file.
127 * Generally there are better forms of communication between
128 * processes, though.
129 *
130 * <p>This was the legacy (but undocumented) behavior in and
131 * before Gingerbread (Android 2.3) and this flag is implied when
132 * targetting such releases. For applications targetting SDK
133 * versions <em>greater than</em> Android 2.3, this flag must be
134 * explicitly set if desired.
135 *
136 * @see #getSharedPreferences
137 */
138 public static final int MODE_MULTI_PROCESS = 0x0004;
139
140 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700141 * Database open flag: when set, the database is opened with write-ahead
142 * logging enabled by default.
143 *
144 * @see #openOrCreateDatabase(String, int, CursorFactory)
145 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
146 * @see SQLiteDatabase#enableWriteAheadLogging
147 */
148 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
149
Tor Norbyed9273d62013-05-30 15:59:53 -0700150 /** @hide */
151 @IntDef(flag = true,
152 value = {
153 BIND_AUTO_CREATE,
Tor Norbyed9273d62013-05-30 15:59:53 -0700154 BIND_DEBUG_UNBIND,
155 BIND_NOT_FOREGROUND,
156 BIND_ABOVE_CLIENT,
157 BIND_ALLOW_OOM_MANAGEMENT,
Tor Norbyece1c67c2014-12-02 13:59:17 -0800158 BIND_WAIVE_PRIORITY,
159 BIND_IMPORTANT,
160 BIND_ADJUST_WITH_ACTIVITY
Tor Norbyed9273d62013-05-30 15:59:53 -0700161 })
162 @Retention(RetentionPolicy.SOURCE)
163 public @interface BindServiceFlags {}
164
Jeff Brown47847f32012-03-22 19:13:11 -0700165 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 * Flag for {@link #bindService}: automatically create the service as long
167 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700168 * its {@link android.app.Service#onStartCommand}
169 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 * explicit call to {@link #startService}. Even without that, though,
171 * this still provides you with access to the service object while the
172 * service is created.
173 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700174 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
175 * not supplying this flag would also impact how important the system
176 * consider's the target service's process to be. When set, the only way
177 * for it to be raised was by binding from a service in which case it will
178 * only be important when that activity is in the foreground. Now to
179 * achieve this behavior you must explicitly supply the new flag
180 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
181 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
182 * the flags {@link #BIND_WAIVE_PRIORITY} and
183 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
184 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 */
186 public static final int BIND_AUTO_CREATE = 0x0001;
187
188 /**
189 * Flag for {@link #bindService}: include debugging help for mismatched
190 * calls to unbind. When this flag is set, the callstack of the following
191 * {@link #unbindService} call is retained, to be printed if a later
192 * incorrect unbind call is made. Note that doing this requires retaining
193 * information about the binding that was made for the lifetime of the app,
194 * resulting in a leak -- this should only be used for debugging.
195 */
196 public static final int BIND_DEBUG_UNBIND = 0x0002;
197
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800198 /**
199 * Flag for {@link #bindService}: don't allow this binding to raise
200 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700201 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800202 * as the client (so that its process will not be killable in any
203 * situation where the client is not killable), but for CPU scheduling
204 * purposes it may be left in the background. This only has an impact
205 * in the situation where the binding client is a foreground process
206 * and the target service is in a background process.
207 */
208 public static final int BIND_NOT_FOREGROUND = 0x0004;
209
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700210 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700211 * Flag for {@link #bindService}: indicates that the client application
212 * binding to this service considers the service to be more important than
213 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700214 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700215 * this is not guaranteed to be the case.
216 */
217 public static final int BIND_ABOVE_CLIENT = 0x0008;
218
219 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700220 * Flag for {@link #bindService}: allow the process hosting the bound
221 * service to go through its normal memory management. It will be
222 * treated more like a running service, allowing the system to
223 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700224 * whim it may have, and being more aggressive about making it a candidate
225 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700226 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700227 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
228
229 /**
230 * Flag for {@link #bindService}: don't impact the scheduling or
231 * memory management priority of the target service's hosting process.
232 * Allows the service's process to be managed on the background LRU list
233 * just like a regular application process in the background.
234 */
235 public static final int BIND_WAIVE_PRIORITY = 0x0020;
236
237 /**
238 * Flag for {@link #bindService}: this service is very important to
239 * the client, so should be brought to the foreground process level
240 * when the client is. Normally a process can only be raised to the
241 * visibility level by a client, even if that client is in the foreground.
242 */
243 public static final int BIND_IMPORTANT = 0x0040;
244
245 /**
246 * Flag for {@link #bindService}: If binding from an activity, allow the
247 * target service's process importance to be raised based on whether the
248 * activity is visible to the user, regardless whether another flag is
249 * used to reduce the amount that the client process's overall importance
250 * is used to impact it.
251 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700252 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
253
254 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700255 * @hide Flag for {@link #bindService}: Treat the binding as hosting
256 * an activity, an unbinding as the activity going in the background.
257 * That is, when unbinding, the process when empty will go on the activity
258 * LRU list instead of the regular one, keeping it around more aggressively
259 * than it otherwise would be. This is intended for use with IMEs to try
260 * to keep IME processes around for faster keyboard switching.
261 */
262 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
263
264 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700265 * @hide An idea that is not yet implemented.
266 * Flag for {@link #bindService}: If binding from an activity, consider
267 * this service to be visible like the binding activity is. That is,
268 * it will be treated as something more important to keep around than
269 * invisible background activities. This will impact the number of
270 * recent activities the user can switch between without having them
271 * restart. There is no guarantee this will be respected, as the system
272 * tries to balance such requests from one app vs. the importantance of
273 * keeping other apps around.
274 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700275 public static final int BIND_VISIBLE = 0x10000000;
276
277 /**
278 * @hide
279 * Flag for {@link #bindService}: Consider this binding to be causing the target
280 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
281 * away.
282 */
283 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700284
285 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700286 * Flag for {@link #bindService}: Don't consider the bound service to be
287 * visible, even if the caller is visible.
288 * @hide
289 */
290 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700291
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800292 /** Return an AssetManager instance for your application's package. */
293 public abstract AssetManager getAssets();
294
295 /** Return a Resources instance for your application's package. */
296 public abstract Resources getResources();
297
298 /** Return PackageManager instance to find global package information. */
299 public abstract PackageManager getPackageManager();
300
301 /** Return a ContentResolver instance for your application's package. */
302 public abstract ContentResolver getContentResolver();
303
304 /**
305 * Return the Looper for the main thread of the current process. This is
306 * the thread used to dispatch calls to application components (activities,
307 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700308 * <p>
309 * By definition, this method returns the same result as would be obtained
310 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
311 * </p>
312 *
313 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 */
315 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 /**
318 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800319 * current process. This generally should only be used if you need a
320 * Context whose lifecycle is separate from the current context, that is
321 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700322 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800323 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800324 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800325 * <ul>
326 * <li> <p>If used from an Activity context, the receiver is being registered
327 * within that activity. This means that you are expected to unregister
328 * before the activity is done being destroyed; in fact if you do not do
329 * so, the framework will clean up your leaked registration as it removes
330 * the activity and log an error. Thus, if you use the Activity context
331 * to register a receiver that is static (global to the process, not
332 * associated with an Activity instance) then that registration will be
333 * removed on you at whatever point the activity you used is destroyed.
334 * <li> <p>If used from the Context returned here, the receiver is being
335 * registered with the global state associated with your application. Thus
336 * it will never be unregistered for you. This is necessary if the receiver
337 * is associated with static data, not a particular component. However
338 * using the ApplicationContext elsewhere can easily lead to serious leaks
339 * if you forget to unregister, unbind, etc.
340 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800341 */
342 public abstract Context getApplicationContext();
343
344 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700345 * Add a new {@link ComponentCallbacks} to the base application of the
346 * Context, which will be called at the same times as the ComponentCallbacks
347 * methods of activities and other components are called. Note that you
348 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
349 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700350 *
351 * @param callback The interface to call. This can be either a
352 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700353 */
354 public void registerComponentCallbacks(ComponentCallbacks callback) {
355 getApplicationContext().registerComponentCallbacks(callback);
356 }
357
358 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400359 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700360 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
361 */
362 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
363 getApplicationContext().unregisterComponentCallbacks(callback);
364 }
365
366 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 * Return a localized, styled CharSequence from the application's package's
368 * default string table.
369 *
370 * @param resId Resource id for the CharSequence text
371 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700372 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 return getResources().getText(resId);
374 }
375
376 /**
377 * Return a localized string from the application's package's
378 * default string table.
379 *
380 * @param resId Resource id for the string
381 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700382 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 return getResources().getString(resId);
384 }
385
386 /**
387 * Return a localized formatted string from the application's package's
388 * default string table, substituting the format arguments as defined in
389 * {@link java.util.Formatter} and {@link java.lang.String#format}.
390 *
391 * @param resId Resource id for the format string
392 * @param formatArgs The format arguments that will be used for substitution.
393 */
394
Tor Norbye7b9c9122013-05-30 16:48:33 -0700395 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 return getResources().getString(resId, formatArgs);
397 }
398
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800399 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800400 * Returns a color associated with a particular resource ID and styled for
401 * the current theme.
402 *
403 * @param id The desired resource identifier, as generated by the aapt
404 * tool. This integer encodes the package, type, and resource
405 * entry. The value 0 is an invalid identifier.
406 * @return A single color value in the form 0xAARRGGBB.
407 * @throws android.content.res.Resources.NotFoundException if the given ID
408 * does not exist.
409 */
410 @Nullable
411 public final int getColor(int id) {
412 return getResources().getColor(id, getTheme());
413 }
414
415 /**
416 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800417 * styled for the current theme.
418 *
419 * @param id The desired resource identifier, as generated by the aapt
420 * tool. This integer encodes the package, type, and resource
421 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800422 * @return An object that can be used to draw this resource, or
423 * {@code null} if the resource could not be resolved.
424 * @throws android.content.res.Resources.NotFoundException if the given ID
425 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800426 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800427 @Nullable
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800428 public final Drawable getDrawable(int id) {
429 return getResources().getDrawable(id, getTheme());
430 }
431
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800432 /**
433 * Returns a color state list associated with a particular resource ID and
434 * styled for the current theme.
435 *
436 * @param id The desired resource identifier, as generated by the aapt
437 * tool. This integer encodes the package, type, and resource
438 * entry. The value 0 is an invalid identifier.
439 * @return A color state list, or {@code null} if the resource could not be
440 * resolved.
441 * @throws android.content.res.Resources.NotFoundException if the given ID
442 * does not exist.
443 */
444 @Nullable
445 public final ColorStateList getColorStateList(int id) {
446 return getResources().getColorStateList(id, getTheme());
447 }
448
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 /**
450 * Set the base theme for this context. Note that this should be called
451 * before any views are instantiated in the Context (for example before
452 * calling {@link android.app.Activity#setContentView} or
453 * {@link android.view.LayoutInflater#inflate}).
454 *
455 * @param resid The style resource describing the theme.
456 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700457 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800458
Dianne Hackborn247fe742011-01-08 17:25:57 -0800459 /** @hide Needed for some internal implementation... not public because
460 * you can't assume this actually means anything. */
461 public int getThemeResId() {
462 return 0;
463 }
464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 /**
466 * Return the Theme object associated with this Context.
467 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700468 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 public abstract Resources.Theme getTheme();
470
471 /**
472 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800473 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 * for more information.
475 *
Jeff Brown6e539312015-02-24 18:53:21 -0800476 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700478 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 return getTheme().obtainStyledAttributes(attrs);
480 }
481
482 /**
483 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800484 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 * for more information.
486 *
Jeff Brown6e539312015-02-24 18:53:21 -0800487 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 */
489 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700490 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800491 return getTheme().obtainStyledAttributes(resid, attrs);
492 }
493
494 /**
495 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800496 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 * for more information.
498 *
Jeff Brown6e539312015-02-24 18:53:21 -0800499 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 */
501 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700502 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800503 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
504 }
505
506 /**
507 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800508 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 * for more information.
510 *
Jeff Brown6e539312015-02-24 18:53:21 -0800511 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 */
513 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700514 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
515 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 return getTheme().obtainStyledAttributes(
517 set, attrs, defStyleAttr, defStyleRes);
518 }
519
520 /**
521 * Return a class loader you can use to retrieve classes in this package.
522 */
523 public abstract ClassLoader getClassLoader();
524
525 /** Return the name of this application's package. */
526 public abstract String getPackageName();
527
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800528 /** @hide Return the name of the base context this context is derived from. */
529 public abstract String getBasePackageName();
530
Dianne Hackborn95d78532013-09-11 09:51:14 -0700531 /** @hide Return the package name that should be used for app ops calls from
532 * this context. This is the same as {@link #getBasePackageName()} except in
533 * cases where system components are loaded into other app processes, in which
534 * case this will be the name of the primary package in that process (so that app
535 * ops uid verification will work with the name). */
536 public abstract String getOpPackageName();
537
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700538 /** Return the full application info for this context's package. */
539 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 /**
Kenny Root32148392010-01-21 15:40:47 -0800542 * Return the full path to this context's primary Android package.
543 * The Android package is a ZIP file which contains the application's
544 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 *
546 * <p>Note: this is not generally useful for applications, since they should
547 * not be directly accessing the file system.
548 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 * @return String Path to the resources.
550 */
551 public abstract String getPackageResourcePath();
552
553 /**
Kenny Root32148392010-01-21 15:40:47 -0800554 * Return the full path to this context's primary Android package.
555 * The Android package is a ZIP file which contains application's
556 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 *
558 * <p>Note: this is not generally useful for applications, since they should
559 * not be directly accessing the file system.
560 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 * @return String Path to the code and assets.
562 */
563 public abstract String getPackageCodePath();
564
565 /**
Joe Onorato23ecae32009-06-10 17:07:15 -0700566 * {@hide}
567 * Return the full path to the shared prefs file for the given prefs group name.
568 *
569 * <p>Note: this is not generally useful for applications, since they should
570 * not be directly accessing the file system.
571 */
572 public abstract File getSharedPrefsFile(String name);
573
574 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 * Retrieve and hold the contents of the preferences file 'name', returning
576 * a SharedPreferences through which you can retrieve and modify its
577 * values. Only one instance of the SharedPreferences object is returned
578 * to any callers for the same name, meaning they will see each other's
579 * edits as soon as they are made.
580 *
581 * @param name Desired preferences file. If a preferences file by this name
582 * does not exist, it will be created when you retrieve an
583 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
584 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
585 * default operation, {@link #MODE_WORLD_READABLE}
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800586 * and {@link #MODE_WORLD_WRITEABLE} to control permissions. The bit
587 * {@link #MODE_MULTI_PROCESS} can also be used if multiple processes
588 * are mutating the same SharedPreferences file. {@link #MODE_MULTI_PROCESS}
Tor Norbyed9273d62013-05-30 15:59:53 -0700589 * is always on in apps targeting Gingerbread (Android 2.3) and below, and
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800590 * off by default in later versions.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400592 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 * to retrieve and modify the preference values.
594 *
595 * @see #MODE_PRIVATE
596 * @see #MODE_WORLD_READABLE
597 * @see #MODE_WORLD_WRITEABLE
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800598 * @see #MODE_MULTI_PROCESS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 */
600 public abstract SharedPreferences getSharedPreferences(String name,
601 int mode);
602
603 /**
604 * Open a private file associated with this Context's application package
605 * for reading.
606 *
607 * @param name The name of the file to open; can not contain path
608 * separators.
609 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400610 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800611 *
612 * @see #openFileOutput
613 * @see #fileList
614 * @see #deleteFile
615 * @see java.io.FileInputStream#FileInputStream(String)
616 */
617 public abstract FileInputStream openFileInput(String name)
618 throws FileNotFoundException;
619
620 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800621 * Open a private file associated with this Context's application package
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 * for writing. Creates the file if it doesn't already exist.
623 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700624 * <p>No permissions are required to invoke this method, since it uses internal
625 * storage.
626 *
Nick Kralevich15069212013-01-09 15:54:56 -0800627 * @param name The name of the file to open; can not contain path
628 * separators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -0800630 * default operation, {@link #MODE_APPEND} to append to an existing file,
631 * {@link #MODE_WORLD_READABLE} and {@link #MODE_WORLD_WRITEABLE} to control
632 * permissions.
633 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400634 * @return The resulting {@link FileOutputStream}.
Nick Kralevich15069212013-01-09 15:54:56 -0800635 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 * @see #MODE_APPEND
637 * @see #MODE_PRIVATE
638 * @see #MODE_WORLD_READABLE
639 * @see #MODE_WORLD_WRITEABLE
640 * @see #openFileInput
641 * @see #fileList
642 * @see #deleteFile
643 * @see java.io.FileOutputStream#FileOutputStream(String)
644 */
645 public abstract FileOutputStream openFileOutput(String name, int mode)
646 throws FileNotFoundException;
647
648 /**
649 * Delete the given private file associated with this Context's
650 * application package.
651 *
652 * @param name The name of the file to delete; can not contain path
653 * separators.
654 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400655 * @return {@code true} if the file was successfully deleted; else
656 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 *
658 * @see #openFileInput
659 * @see #openFileOutput
660 * @see #fileList
661 * @see java.io.File#delete()
662 */
663 public abstract boolean deleteFile(String name);
664
665 /**
666 * Returns the absolute path on the filesystem where a file created with
667 * {@link #openFileOutput} is stored.
668 *
669 * @param name The name of the file for which you would like to get
670 * its path.
671 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400672 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 *
674 * @see #openFileOutput
675 * @see #getFilesDir
676 * @see #getDir
677 */
678 public abstract File getFileStreamPath(String name);
679
680 /**
681 * Returns the absolute path to the directory on the filesystem where
682 * files created with {@link #openFileOutput} are stored.
683 *
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700684 * <p>No permissions are required to read or write to the returned path, since this
685 * path is internal storage.
686 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400687 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 *
689 * @see #openFileOutput
690 * @see #getFileStreamPath
691 * @see #getDir
692 */
693 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700694
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700696 * Returns the absolute path to the directory on the filesystem similar to
697 * {@link #getFilesDir()}. The difference is that files placed under this
698 * directory will be excluded from automatic backup to remote storage. See
699 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
700 * of the automatic backup mechanism in Android.
701 *
702 * <p>No permissions are required to read or write to the returned path, since this
703 * path is internal storage.
704 *
705 * @return The path of the directory holding application files that will not be
706 * automatically backed up to remote storage.
707 *
708 * @see #openFileOutput
709 * @see #getFileStreamPath
710 * @see #getDir
711 * @see android.app.backup.BackupAgent
712 */
713 public abstract File getNoBackupFilesDir();
714
715 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700716 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800717 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700718 * Environment.getExternalStorageDirectory()}) where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700719 * place persistent files it owns. These files are internal to the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800720 * applications, and not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700721 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800722 * <p>This is like {@link #getFilesDir()} in that these
723 * files will be deleted when the application is uninstalled, however there
724 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700725 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800726 * <ul>
727 * <li>External files are not always available: they will disappear if the
728 * user mounts the external storage on a computer or removes it. See the
729 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700730 * <li>There is no security enforced with these files. For example, any application
731 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
732 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800733 * </ul>
Scott Main4b5da682010-10-21 11:49:12 -0700734 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700735 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
736 * are required to read or write to the returned path; it's always
737 * accessible to the calling app. This only applies to paths generated for
738 * package name of the calling application. To access paths belonging
739 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
740 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
741 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700742 * <p>On devices with multiple users (as described by {@link UserManager}),
743 * each user has their own isolated external storage. Applications only
744 * have access to the external storage for the user they're running as.</p>
745 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800746 * <p>Here is an example of typical code to manipulate a file in
747 * an application's private storage:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700748 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800749 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
750 * private_file}
751 *
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700752 * <p>If you supply a non-null <var>type</var> to this function, the returned
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800753 * file will be a path to a sub-directory of the given type. Though these files
754 * are not automatically scanned by the media scanner, you can explicitly
755 * add them to the media database with
756 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[],
Jeff Brown6e539312015-02-24 18:53:21 -0800757 * android.media.MediaScannerConnection.OnScanCompletedListener)
758 * MediaScannerConnection.scanFile}.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800759 * Note that this is not the same as
760 * {@link android.os.Environment#getExternalStoragePublicDirectory
761 * Environment.getExternalStoragePublicDirectory()}, which provides
762 * directories of media shared by all applications. The
763 * directories returned here are
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700764 * owned by the application, and their contents will be removed when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800765 * application is uninstalled. Unlike
766 * {@link android.os.Environment#getExternalStoragePublicDirectory
767 * Environment.getExternalStoragePublicDirectory()}, the directory
768 * returned here will be automatically created for you.
Scott Main4b5da682010-10-21 11:49:12 -0700769 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800770 * <p>Here is an example of typical code to manipulate a picture in
771 * an application's private storage and add it to the media database:</p>
Scott Main4b5da682010-10-21 11:49:12 -0700772 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800773 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
774 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700775 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800776 * @param type The type of files directory to return. May be null for
777 * the root of the files directory or one of
778 * the following Environment constants for a subdirectory:
779 * {@link android.os.Environment#DIRECTORY_MUSIC},
780 * {@link android.os.Environment#DIRECTORY_PODCASTS},
781 * {@link android.os.Environment#DIRECTORY_RINGTONES},
782 * {@link android.os.Environment#DIRECTORY_ALARMS},
783 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
784 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
785 * {@link android.os.Environment#DIRECTORY_MOVIES}.
Scott Main4b5da682010-10-21 11:49:12 -0700786 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400787 * @return The path of the directory holding application files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800788 * on external storage. Returns null if external storage is not currently
789 * mounted so it could not ensure the path exists; you will need to call
790 * this method again when it is available.
791 *
792 * @see #getFilesDir
Dianne Hackbornacaf0282010-03-30 14:39:35 -0700793 * @see android.os.Environment#getExternalStoragePublicDirectory
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800794 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700795 @Nullable
796 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700797
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800798 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700799 * Returns absolute paths to application-specific directories on all
800 * external storage devices where the application can place persistent files
801 * it owns. These files are internal to the application, and not typically
802 * visible to the user as media.
803 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700804 * This is like {@link #getFilesDir()} in that these files will be deleted when
805 * the application is uninstalled, however there are some important differences:
806 * <ul>
807 * <li>External files are not always available: they will disappear if the
808 * user mounts the external storage on a computer or removes it.
809 * <li>There is no security enforced with these files.
810 * </ul>
811 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700812 * External storage devices returned here are considered a permanent part of
813 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700814 * slots, such as SD cards in a battery compartment. The returned paths do
815 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700816 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700817 * An application may store data on any or all of the returned devices. For
818 * example, an app may choose to store large files on the device with the
819 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700820 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700821 * No permissions are required to read or write to the returned paths; they
822 * are always accessible to the calling app. Write access outside of these
823 * paths on secondary external storage devices is not available.
824 * <p>
825 * The first path returned is the same as {@link #getExternalFilesDir(String)}.
826 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700827 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700828 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800829 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700830 */
831 public abstract File[] getExternalFilesDirs(String type);
832
833 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700834 * Return the primary external storage directory where this application's OBB
835 * files (if there are any) can be found. Note if the application does not have
836 * any OBB files, this directory may not exist.
837 * <p>
838 * This is like {@link #getFilesDir()} in that these files will be deleted when
839 * the application is uninstalled, however there are some important differences:
840 * <ul>
841 * <li>External files are not always available: they will disappear if the
842 * user mounts the external storage on a computer or removes it.
843 * <li>There is no security enforced with these files. For example, any application
844 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
845 * these files.
846 * </ul>
847 * <p>
848 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
849 * are required to read or write to the returned path; it's always
850 * accessible to the calling app. This only applies to paths generated for
851 * package name of the calling application. To access paths belonging
852 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
853 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700854 * <p>
855 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -0700856 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700857 * should ensure that multiple instances running under different users don't
858 * interfere with each other.
Dianne Hackborn805fd7e2011-01-16 18:30:29 -0800859 */
860 public abstract File getObbDir();
861
862 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700863 * Returns absolute paths to application-specific directories on all
864 * external storage devices where the application's OBB files (if there are
865 * any) can be found. Note if the application does not have any OBB files,
866 * these directories may not exist.
867 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700868 * This is like {@link #getFilesDir()} in that these files will be deleted when
869 * the application is uninstalled, however there are some important differences:
870 * <ul>
871 * <li>External files are not always available: they will disappear if the
872 * user mounts the external storage on a computer or removes it.
873 * <li>There is no security enforced with these files.
874 * </ul>
875 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700876 * External storage devices returned here are considered a permanent part of
877 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700878 * slots, such as SD cards in a battery compartment. The returned paths do
879 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700880 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700881 * An application may store data on any or all of the returned devices. For
882 * example, an app may choose to store large files on the device with the
883 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700884 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700885 * No permissions are required to read or write to the returned paths; they
886 * are always accessible to the calling app. Write access outside of these
887 * paths on secondary external storage devices is not available.
888 * <p>
889 * The first path returned is the same as {@link #getObbDir()}.
890 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700891 *
892 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -0800893 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700894 */
895 public abstract File[] getObbDirs();
896
897 /**
Scott Main4b5da682010-10-21 11:49:12 -0700898 * Returns the absolute path to the application specific cache directory
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800899 * on the filesystem. These files will be ones that get deleted first when the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800900 * device runs low on storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800901 * There is no guarantee when these files will be deleted.
Scott Main4b5da682010-10-21 11:49:12 -0700902 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800903 * <strong>Note: you should not <em>rely</em> on the system deleting these
904 * files for you; you should always have a reasonable maximum, such as 1 MB,
905 * for the amount of space you consume with cache files, and prune those
906 * files when exceeding that space.</strong>
Scott Main4b5da682010-10-21 11:49:12 -0700907 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400908 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909 *
910 * @see #openFileOutput
911 * @see #getFileStreamPath
912 * @see #getDir
913 */
914 public abstract File getCacheDir();
915
916 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -0700917 * Returns the absolute path to the application specific cache directory on
918 * the filesystem designed for storing cached code. The system will delete
919 * any files stored in this location both when your specific application is
920 * upgraded, and when the entire platform is upgraded.
921 * <p>
922 * This location is optimal for storing compiled or optimized code generated
923 * by your application at runtime.
924 * <p>
925 * Apps require no extra permissions to read or write to the returned path,
926 * since this path lives in their private storage.
927 *
928 * @return The path of the directory holding application code cache files.
929 */
930 public abstract File getCodeCacheDir();
931
932 /**
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700933 * Returns the absolute path to the directory on the primary external filesystem
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800934 * (that is somewhere on {@link android.os.Environment#getExternalStorageDirectory()
935 * Environment.getExternalStorageDirectory()} where the application can
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700936 * place cache files it owns. These files are internal to the application, and
937 * not typically visible to the user as media.
Scott Main4b5da682010-10-21 11:49:12 -0700938 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800939 * <p>This is like {@link #getCacheDir()} in that these
940 * files will be deleted when the application is uninstalled, however there
941 * are some important differences:
Scott Main4b5da682010-10-21 11:49:12 -0700942 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800943 * <ul>
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700944 * <li>The platform does not always monitor the space available in external
945 * storage, and thus may not automatically delete these files. Currently
946 * the only time files here will be deleted by the platform is when running
947 * on {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
948 * {@link android.os.Environment#isExternalStorageEmulated()
949 * Environment.isExternalStorageEmulated()} returns true. Note that you should
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800950 * be managing the maximum space you will use for these anyway, just like
951 * with {@link #getCacheDir()}.
952 * <li>External files are not always available: they will disappear if the
953 * user mounts the external storage on a computer or removes it. See the
954 * APIs on {@link android.os.Environment} for information in the storage state.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700955 * <li>There is no security enforced with these files. For example, any application
956 * holding {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
957 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800958 * </ul>
959 *
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700960 * <p>Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
961 * are required to read or write to the returned path; it's always
962 * accessible to the calling app. This only applies to paths generated for
963 * package name of the calling application. To access paths belonging
964 * to other packages, {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
965 * and/or {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
966 *
Jeff Sharkey8c165792012-10-22 14:08:29 -0700967 * <p>On devices with multiple users (as described by {@link UserManager}),
968 * each user has their own isolated external storage. Applications only
969 * have access to the external storage for the user they're running as.</p>
Jeff Sharkey8c165792012-10-22 14:08:29 -0700970 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400971 * @return The path of the directory holding application cache files
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800972 * on external storage. Returns null if external storage is not currently
973 * mounted so it could not ensure the path exists; you will need to call
974 * this method again when it is available.
975 *
976 * @see #getCacheDir
977 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700978 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800979 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -0700980
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800981 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700982 * Returns absolute paths to application-specific directories on all
983 * external storage devices where the application can place cache files it
984 * owns. These files are internal to the application, and not typically
985 * visible to the user as media.
986 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700987 * This is like {@link #getCacheDir()} in that these files will be deleted when
988 * the application is uninstalled, however there are some important differences:
989 * <ul>
990 * <li>External files are not always available: they will disappear if the
991 * user mounts the external storage on a computer or removes it.
992 * <li>There is no security enforced with these files.
993 * </ul>
994 * <p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700995 * External storage devices returned here are considered a permanent part of
996 * the device, including both emulated external storage and physical media
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700997 * slots, such as SD cards in a battery compartment. The returned paths do
998 * not include transient devices, such as USB flash drives.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700999 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001000 * An application may store data on any or all of the returned devices. For
1001 * example, an app may choose to store large files on the device with the
1002 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001003 * <p>
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001004 * No permissions are required to read or write to the returned paths; they
1005 * are always accessible to the calling app. Write access outside of these
1006 * paths on secondary external storage devices is not available.
1007 * <p>
1008 * The first path returned is the same as {@link #getExternalCacheDir()}.
1009 * Returned paths may be {@code null} if a storage device is unavailable.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001010 *
1011 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001012 * @see Environment#getExternalStorageState(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001013 */
1014 public abstract File[] getExternalCacheDirs();
1015
1016 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001017 * Returns absolute paths to application-specific directories on all
1018 * external storage devices where the application can place media files.
1019 * These files are scanned and made available to other apps through
1020 * {@link MediaStore}.
1021 * <p>
1022 * This is like {@link #getExternalFilesDirs} in that these files will be
1023 * deleted when the application is uninstalled, however there are some
1024 * important differences:
1025 * <ul>
1026 * <li>External files are not always available: they will disappear if the
1027 * user mounts the external storage on a computer or removes it.
1028 * <li>There is no security enforced with these files.
1029 * </ul>
1030 * <p>
1031 * External storage devices returned here are considered a permanent part of
1032 * the device, including both emulated external storage and physical media
1033 * slots, such as SD cards in a battery compartment. The returned paths do
1034 * not include transient devices, such as USB flash drives.
1035 * <p>
1036 * An application may store data on any or all of the returned devices. For
1037 * example, an app may choose to store large files on the device with the
1038 * most available space, as measured by {@link StatFs}.
1039 * <p>
1040 * No permissions are required to read or write to the returned paths; they
1041 * are always accessible to the calling app. Write access outside of these
1042 * paths on secondary external storage devices is not available.
1043 * <p>
1044 * Returned paths may be {@code null} if a storage device is unavailable.
1045 *
1046 * @see Environment#getExternalStorageState(File)
1047 */
1048 public abstract File[] getExternalMediaDirs();
1049
1050 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 * Returns an array of strings naming the private files associated with
1052 * this Context's application package.
1053 *
1054 * @return Array of strings naming the private files.
1055 *
1056 * @see #openFileInput
1057 * @see #openFileOutput
1058 * @see #deleteFile
1059 */
1060 public abstract String[] fileList();
1061
1062 /**
1063 * Retrieve, creating if needed, a new directory in which the application
1064 * can place its own custom data files. You can use the returned File
1065 * object to create and access files in this directory. Note that files
1066 * created through a File object will only be accessible by your own
1067 * application; you can only set the mode of the entire directory, not
1068 * of individual files.
1069 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001070 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001071 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001072 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Nick Kralevich15069212013-01-09 15:54:56 -08001073 * default operation, {@link #MODE_WORLD_READABLE} and
1074 * {@link #MODE_WORLD_WRITEABLE} to control permissions.
1075 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001076 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001077 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001078 *
1079 * @see #openFileOutput(String, int)
1080 */
1081 public abstract File getDir(String name, int mode);
1082
1083 /**
1084 * Open a new private SQLiteDatabase associated with this Context's
1085 * application package. Create the database file if it doesn't exist.
1086 *
1087 * @param name The name (unique in the application package) of the database.
1088 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1089 * default operation, {@link #MODE_WORLD_READABLE}
1090 * and {@link #MODE_WORLD_WRITEABLE} to control permissions.
Jeff Brown47847f32012-03-22 19:13:11 -07001091 * Use {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead logging by default.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001092 * @param factory An optional factory class that is called to instantiate a
1093 * cursor when query is called.
Nick Kralevich15069212013-01-09 15:54:56 -08001094 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 * @return The contents of a newly created database with the given name.
1096 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001097 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001098 * @see #MODE_PRIVATE
1099 * @see #MODE_WORLD_READABLE
1100 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001101 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001102 * @see #deleteDatabase
1103 */
1104 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1105 int mode, CursorFactory factory);
1106
1107 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001108 * Open a new private SQLiteDatabase associated with this Context's
1109 * application package. Creates the database file if it doesn't exist.
1110 *
1111 * <p>Accepts input param: a concrete instance of {@link DatabaseErrorHandler} to be
1112 * used to handle corruption when sqlite reports database corruption.</p>
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.
Vasu Nori74f170f2010-06-01 18:06:18 -07001119 * @param factory An optional factory class that is called to instantiate a
1120 * cursor when query is called.
1121 * @param errorHandler the {@link DatabaseErrorHandler} to be used when sqlite reports database
Nick Kralevich15069212013-01-09 15:54:56 -08001122 * corruption. if null, {@link android.database.DefaultDatabaseErrorHandler} is assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001123 * @return The contents of a newly created database with the given name.
1124 * @throws android.database.sqlite.SQLiteException if the database file could not be opened.
Nick Kralevich15069212013-01-09 15:54:56 -08001125 *
Vasu Nori74f170f2010-06-01 18:06:18 -07001126 * @see #MODE_PRIVATE
1127 * @see #MODE_WORLD_READABLE
1128 * @see #MODE_WORLD_WRITEABLE
Jeff Brown47847f32012-03-22 19:13:11 -07001129 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Vasu Nori74f170f2010-06-01 18:06:18 -07001130 * @see #deleteDatabase
1131 */
1132 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001133 int mode, CursorFactory factory,
1134 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001135
1136 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 * Delete an existing private SQLiteDatabase associated with this Context's
1138 * application package.
1139 *
1140 * @param name The name (unique in the application package) of the
1141 * database.
1142 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001143 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 *
1145 * @see #openOrCreateDatabase
1146 */
1147 public abstract boolean deleteDatabase(String name);
1148
1149 /**
1150 * Returns the absolute path on the filesystem where a database created with
1151 * {@link #openOrCreateDatabase} is stored.
1152 *
1153 * @param name The name of the database for which you would like to get
1154 * its path.
1155 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001156 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 *
1158 * @see #openOrCreateDatabase
1159 */
1160 public abstract File getDatabasePath(String name);
1161
1162 /**
1163 * Returns an array of strings naming the private databases associated with
1164 * this Context's application package.
1165 *
1166 * @return Array of strings naming the private databases.
1167 *
1168 * @see #openOrCreateDatabase
1169 * @see #deleteDatabase
1170 */
1171 public abstract String[] databaseList();
1172
1173 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001174 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001175 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001177 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001178 public abstract Drawable getWallpaper();
1179
1180 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001181 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001182 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001184 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001185 public abstract Drawable peekWallpaper();
1186
1187 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001188 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1189 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001190 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001191 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 public abstract int getWallpaperDesiredMinimumWidth();
1193
1194 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001195 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1196 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001198 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 public abstract int getWallpaperDesiredMinimumHeight();
1200
1201 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001202 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001203 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001204 * <p>This method requires the caller to hold the permission
1205 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001206 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001207 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001208 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1209
1210 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001211 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001212 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001213 * <p>This method requires the caller to hold the permission
1214 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001215 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001216 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001217 public abstract void setWallpaper(InputStream data) throws IOException;
1218
1219 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001220 * @deprecated Use {@link android.app.WallpaperManager#clear
1221 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001222 * <p>This method requires the caller to hold the permission
1223 * {@link android.Manifest.permission#SET_WALLPAPER}.
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 void clearWallpaper() throws IOException;
1227
1228 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001229 * Same as {@link #startActivity(Intent, Bundle)} with no options
1230 * specified.
1231 *
1232 * @param intent The description of the activity to start.
1233 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001234 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001235 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001236 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001237 * @see PackageManager#resolveActivity
1238 */
1239 public abstract void startActivity(Intent intent);
1240
1241 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001242 * Version of {@link #startActivity(Intent)} that allows you to specify the
1243 * user the activity will be started for. This is not available to applications
1244 * that are not pre-installed on the system image. Using it requires holding
1245 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001246 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001247 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001248 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001249 * @hide
1250 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001251 public void startActivityAsUser(Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001252 throw new RuntimeException("Not implemented. Must override in a subclass.");
1253 }
1254
1255 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001256 * Launch a new activity. You will not receive any information about when
1257 * the activity exits.
1258 *
1259 * <p>Note that if this method is being called from outside of an
1260 * {@link android.app.Activity} Context, then the Intent must include
1261 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1262 * without being started from an existing Activity, there is no existing
1263 * task in which to place the new activity and thus it needs to be placed
1264 * in its own separate task.
1265 *
1266 * <p>This method throws {@link ActivityNotFoundException}
1267 * if there was no Activity found to run the given Intent.
1268 *
1269 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001270 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001271 * May be null if there are no options. See {@link android.app.ActivityOptions}
1272 * for how to build the Bundle supplied here; there are no supported definitions
1273 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001274 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001275 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001276 *
Scott Main60dd5202012-06-23 00:01:22 -07001277 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 * @see PackageManager#resolveActivity
1279 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001280 public abstract void startActivity(Intent intent, @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001281
1282 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001283 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1284 * user the activity will be started for. This is not available to applications
1285 * that are not pre-installed on the system image. Using it requires holding
1286 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001287 * @param intent The description of the activity to start.
1288 * @param options Additional options for how the Activity should be started.
1289 * May be null if there are no options. See {@link android.app.ActivityOptions}
1290 * for how to build the Bundle supplied here; there are no supported definitions
1291 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001292 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001293 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001294 * @hide
1295 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001296 public void startActivityAsUser(Intent intent, @Nullable Bundle options, UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001297 throw new RuntimeException("Not implemented. Must override in a subclass.");
1298 }
1299
1300 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001301 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1302 * is only supported for Views and Fragments.
1303 * @param who The identifier for the calling element that will receive the result.
1304 * @param intent The intent to start.
1305 * @param requestCode The code that will be returned with onActivityResult() identifying this
1306 * request.
1307 * @param options Additional options for how the Activity should be started.
1308 * May be null if there are no options. See {@link android.app.ActivityOptions}
1309 * for how to build the Bundle supplied here; there are no supported definitions
1310 * for building it manually.
1311 * @hide
1312 */
1313 public void startActivityForResult(
1314 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1315 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1316 + "Check canStartActivityForResult() before calling.");
1317 }
1318
1319 /**
1320 * Identifies whether this Context instance will be able to process calls to
1321 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1322 * @hide
1323 */
1324 public boolean canStartActivityForResult() {
1325 return false;
1326 }
1327
1328 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001329 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1330 * specified.
1331 *
1332 * @param intents An array of Intents to be started.
1333 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001334 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001335 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001336 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001337 * @see PackageManager#resolveActivity
1338 */
1339 public abstract void startActivities(Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001340
1341 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001342 * Launch multiple new activities. This is generally the same as calling
1343 * {@link #startActivity(Intent)} for the first Intent in the array,
1344 * that activity during its creation calling {@link #startActivity(Intent)}
1345 * for the second entry, etc. Note that unlike that approach, generally
1346 * none of the activities except the last in the array will be created
1347 * at this point, but rather will be created when the user first visits
1348 * them (due to pressing back from the activity on top).
1349 *
1350 * <p>This method throws {@link ActivityNotFoundException}
1351 * if there was no Activity found for <em>any</em> given Intent. In this
1352 * case the state of the activity stack is undefined (some Intents in the
1353 * list may be on it, some not), so you probably want to avoid such situations.
1354 *
1355 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001356 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001357 * See {@link android.content.Context#startActivity(Intent, Bundle)
1358 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001359 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001360 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001361 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001362 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001363 * @see PackageManager#resolveActivity
1364 */
Dianne Hackborna4972e92012-03-14 10:38:05 -07001365 public abstract void startActivities(Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001366
1367 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001368 * @hide
1369 * 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.
1383 * @param options Additional options for how the Activity should be started.
1384 * @param userHandle The user for whom to launch the activities
1385 * See {@link android.content.Context#startActivity(Intent, Bundle)
1386 * Context.startActivity(Intent, Bundle)} for more details.
1387 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001388 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001389 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001390 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001391 * @see PackageManager#resolveActivity
1392 */
1393 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1394 throw new RuntimeException("Not implemented. Must override in a subclass.");
1395 }
1396
1397 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001398 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1399 * with no options specified.
1400 *
1401 * @param intent The IntentSender to launch.
1402 * @param fillInIntent If non-null, this will be provided as the
1403 * intent parameter to {@link IntentSender#sendIntent}.
1404 * @param flagsMask Intent flags in the original IntentSender that you
1405 * would like to change.
1406 * @param flagsValues Desired values for any bits set in
1407 * <var>flagsMask</var>
1408 * @param extraFlags Always set to 0.
1409 *
1410 * @see #startActivity(Intent)
1411 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1412 */
1413 public abstract void startIntentSender(IntentSender intent,
1414 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1415 throws IntentSender.SendIntentException;
1416
1417 /**
1418 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001419 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001420 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001421 * here; otherwise, its associated action will be executed (such as
1422 * sending a broadcast) as if you had called
1423 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001424 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001425 * @param intent The IntentSender to launch.
1426 * @param fillInIntent If non-null, this will be provided as the
1427 * intent parameter to {@link IntentSender#sendIntent}.
1428 * @param flagsMask Intent flags in the original IntentSender that you
1429 * would like to change.
1430 * @param flagsValues Desired values for any bits set in
1431 * <var>flagsMask</var>
1432 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001433 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001434 * See {@link android.content.Context#startActivity(Intent, Bundle)
1435 * Context.startActivity(Intent, Bundle)} for more details. If options
1436 * have also been supplied by the IntentSender, options given here will
1437 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001438 *
1439 * @see #startActivity(Intent, Bundle)
1440 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001441 */
1442 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001443 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001444 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001445
1446 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001447 * Broadcast the given intent to all interested BroadcastReceivers. This
1448 * call is asynchronous; it returns immediately, and you will continue
1449 * executing while the receivers are run. No results are propagated from
1450 * receivers and receivers can not abort the broadcast. If you want
1451 * to allow receivers to propagate results or abort the broadcast, you must
1452 * send an ordered broadcast using
1453 * {@link #sendOrderedBroadcast(Intent, String)}.
1454 *
1455 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1456 *
1457 * @param intent The Intent to broadcast; all receivers matching this
1458 * Intent will receive the broadcast.
1459 *
1460 * @see android.content.BroadcastReceiver
1461 * @see #registerReceiver
1462 * @see #sendBroadcast(Intent, String)
1463 * @see #sendOrderedBroadcast(Intent, String)
1464 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1465 */
1466 public abstract void sendBroadcast(Intent intent);
1467
1468 /**
1469 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1470 * an optional required permission to be enforced. This
1471 * call is asynchronous; it returns immediately, and you will continue
1472 * executing while the receivers are run. No results are propagated from
1473 * receivers and receivers can not abort the broadcast. If you want
1474 * to allow receivers to propagate results or abort the broadcast, you must
1475 * send an ordered broadcast using
1476 * {@link #sendOrderedBroadcast(Intent, String)}.
1477 *
1478 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1479 *
1480 * @param intent The Intent to broadcast; all receivers matching this
1481 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001482 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 * a receiver must hold in order to receive your broadcast.
1484 * If null, no permission is required.
1485 *
1486 * @see android.content.BroadcastReceiver
1487 * @see #registerReceiver
1488 * @see #sendBroadcast(Intent)
1489 * @see #sendOrderedBroadcast(Intent, String)
1490 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1491 */
1492 public abstract void sendBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001493 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494
1495 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001496 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001497 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001498 * @hide
1499 */
1500 public abstract void sendBroadcast(Intent intent,
1501 String receiverPermission, int appOp);
1502
1503 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1505 * them one at a time to allow more preferred receivers to consume the
1506 * broadcast before it is delivered to less preferred receivers. This
1507 * call is asynchronous; it returns immediately, and you will continue
1508 * executing while the receivers are run.
1509 *
1510 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1511 *
1512 * @param intent The Intent to broadcast; all receivers matching this
1513 * Intent will receive the broadcast.
1514 * @param receiverPermission (optional) String naming a permissions that
1515 * a receiver must hold in order to receive your broadcast.
1516 * If null, no permission is required.
1517 *
1518 * @see android.content.BroadcastReceiver
1519 * @see #registerReceiver
1520 * @see #sendBroadcast(Intent)
1521 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1522 */
1523 public abstract void sendOrderedBroadcast(Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001524 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525
1526 /**
1527 * Version of {@link #sendBroadcast(Intent)} that allows you to
1528 * receive data back from the broadcast. This is accomplished by
1529 * supplying your own BroadcastReceiver when calling, which will be
1530 * treated as a final receiver at the end of the broadcast -- its
1531 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001532 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 * be serialized in the same way as calling
1534 * {@link #sendOrderedBroadcast(Intent, String)}.
1535 *
1536 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1537 * asynchronous; it will return before
1538 * resultReceiver.onReceive() is called.
1539 *
1540 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1541 *
1542 * @param intent The Intent to broadcast; all receivers matching this
1543 * Intent will receive the broadcast.
1544 * @param receiverPermission String naming a permissions that
1545 * a receiver must hold in order to receive your broadcast.
1546 * If null, no permission is required.
1547 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1548 * receiver of the broadcast.
1549 * @param scheduler A custom Handler with which to schedule the
1550 * resultReceiver callback; if null it will be
1551 * scheduled in the Context's main thread.
1552 * @param initialCode An initial value for the result code. Often
1553 * Activity.RESULT_OK.
1554 * @param initialData An initial value for the result data. Often
1555 * null.
1556 * @param initialExtras An initial value for the result extras. Often
1557 * null.
1558 *
1559 * @see #sendBroadcast(Intent)
1560 * @see #sendBroadcast(Intent, String)
1561 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 * @see android.content.BroadcastReceiver
1563 * @see #registerReceiver
1564 * @see android.app.Activity#RESULT_OK
1565 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001566 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1567 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1568 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1569 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570
1571 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001572 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1573 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001574 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001575 * @hide
1576 */
1577 public abstract void sendOrderedBroadcast(Intent intent,
1578 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1579 Handler scheduler, int initialCode, String initialData,
1580 Bundle initialExtras);
1581
1582 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001583 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1584 * user the broadcast will be sent to. This is not available to applications
1585 * that are not pre-installed on the system image. Using it requires holding
1586 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001587 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001588 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001589 * @see #sendBroadcast(Intent)
1590 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001591 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001592
1593 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001594 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1595 * user the broadcast will be sent to. This is not available to applications
1596 * that are not pre-installed on the system image. Using it requires holding
1597 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001598 *
1599 * @param intent The Intent to broadcast; all receivers matching this
1600 * Intent will receive the broadcast.
1601 * @param user UserHandle to send the intent to.
1602 * @param receiverPermission (optional) String naming a permission that
1603 * a receiver must hold in order to receive your broadcast.
1604 * If null, no permission is required.
1605 *
1606 * @see #sendBroadcast(Intent, String)
1607 */
1608 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001609 @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001610
1611 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001612 * Version of
1613 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1614 * that allows you to specify the
1615 * user the broadcast will be sent to. This is not available to applications
1616 * that are not pre-installed on the system image. Using it requires holding
1617 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001618 *
1619 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1620 *
1621 * @param intent The Intent to broadcast; all receivers matching this
1622 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001623 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001624 * @param receiverPermission String naming a permissions that
1625 * a receiver must hold in order to receive your broadcast.
1626 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001627 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1628 * receiver of the broadcast.
1629 * @param scheduler A custom Handler with which to schedule the
1630 * resultReceiver callback; if null it will be
1631 * scheduled in the Context's main thread.
1632 * @param initialCode An initial value for the result code. Often
1633 * Activity.RESULT_OK.
1634 * @param initialData An initial value for the result data. Often
1635 * null.
1636 * @param initialExtras An initial value for the result extras. Often
1637 * null.
1638 *
1639 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1640 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001641 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001642 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1643 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1644 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001645
1646 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07001647 * Similar to above but takes an appOp as well, to enforce restrictions.
1648 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1649 * BroadcastReceiver, Handler, int, String, Bundle)
1650 * @hide
1651 */
1652 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1653 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1654 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1655 @Nullable Bundle initialExtras);
1656
1657 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001658 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 * Intent you are sending stays around after the broadcast is complete,
1660 * so that others can quickly retrieve that data through the return
1661 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1662 * all other ways, this behaves the same as
1663 * {@link #sendBroadcast(Intent)}.
1664 *
1665 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1666 * permission in order to use this API. If you do not hold that
1667 * permission, {@link SecurityException} will be thrown.
1668 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001669 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1670 * can access them), no protection (anyone can modify them), and many other problems.
1671 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1672 * has changed, with another mechanism for apps to retrieve the current value whenever
1673 * desired.
1674 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 * @param intent The Intent to broadcast; all receivers matching this
1676 * Intent will receive the broadcast, and the Intent will be held to
1677 * be re-broadcast to future receivers.
1678 *
1679 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001680 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001682 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001683 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001684
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001685 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001686 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001687 * receive data back from the broadcast. This is accomplished by
1688 * supplying your own BroadcastReceiver when calling, which will be
1689 * treated as a final receiver at the end of the broadcast -- its
1690 * {@link BroadcastReceiver#onReceive} method will be called with
1691 * the result values collected from the other receivers. The broadcast will
1692 * be serialized in the same way as calling
1693 * {@link #sendOrderedBroadcast(Intent, String)}.
1694 *
1695 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1696 * asynchronous; it will return before
1697 * resultReceiver.onReceive() is called. Note that the sticky data
1698 * stored is only the data you initially supply to the broadcast, not
1699 * the result of any changes made by the receivers.
1700 *
1701 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1702 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001703 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1704 * can access them), no protection (anyone can modify them), and many other problems.
1705 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1706 * has changed, with another mechanism for apps to retrieve the current value whenever
1707 * desired.
1708 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001709 * @param intent The Intent to broadcast; all receivers matching this
1710 * Intent will receive the broadcast.
1711 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1712 * receiver of the broadcast.
1713 * @param scheduler A custom Handler with which to schedule the
1714 * resultReceiver callback; if null it will be
1715 * scheduled in the Context's main thread.
1716 * @param initialCode An initial value for the result code. Often
1717 * Activity.RESULT_OK.
1718 * @param initialData An initial value for the result data. Often
1719 * null.
1720 * @param initialExtras An initial value for the result extras. Often
1721 * null.
1722 *
1723 * @see #sendBroadcast(Intent)
1724 * @see #sendBroadcast(Intent, String)
1725 * @see #sendOrderedBroadcast(Intent, String)
1726 * @see #sendStickyBroadcast(Intent)
1727 * @see android.content.BroadcastReceiver
1728 * @see #registerReceiver
1729 * @see android.app.Activity#RESULT_OK
1730 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001731 @Deprecated
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001732 public abstract void sendStickyOrderedBroadcast(Intent intent,
1733 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001734 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1735 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001737 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001738 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001739 * so that it is as if the sticky broadcast had never happened.
1740 *
1741 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1742 * permission in order to use this API. If you do not hold that
1743 * permission, {@link SecurityException} will be thrown.
1744 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001745 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1746 * can access them), no protection (anyone can modify them), and many other problems.
1747 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1748 * has changed, with another mechanism for apps to retrieve the current value whenever
1749 * desired.
1750 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001751 * @param intent The Intent that was previously broadcast.
1752 *
1753 * @see #sendStickyBroadcast
1754 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001755 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 public abstract void removeStickyBroadcast(Intent intent);
1757
1758 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001759 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001760 * user the broadcast will be sent to. This is not available to applications
1761 * that are not pre-installed on the system image. Using it requires holding
1762 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001763 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001764 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1765 * can access them), no protection (anyone can modify them), and many other problems.
1766 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1767 * has changed, with another mechanism for apps to retrieve the current value whenever
1768 * desired.
1769 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001770 * @param intent The Intent to broadcast; all receivers matching this
1771 * Intent will receive the broadcast, and the Intent will be held to
1772 * be re-broadcast to future receivers.
1773 * @param user UserHandle to send the intent to.
1774 *
1775 * @see #sendBroadcast(Intent)
1776 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001777 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001778 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1779
1780 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001781 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07001782 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1783 * that allows you to specify the
1784 * user the broadcast will be sent to. This is not available to applications
1785 * that are not pre-installed on the system image. Using it requires holding
1786 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001787 *
1788 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1789 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001790 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1791 * can access them), no protection (anyone can modify them), and many other problems.
1792 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1793 * has changed, with another mechanism for apps to retrieve the current value whenever
1794 * desired.
1795 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001796 * @param intent The Intent to broadcast; all receivers matching this
1797 * Intent will receive the broadcast.
1798 * @param user UserHandle to send the intent to.
1799 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1800 * receiver of the broadcast.
1801 * @param scheduler A custom Handler with which to schedule the
1802 * resultReceiver callback; if null it will be
1803 * scheduled in the Context's main thread.
1804 * @param initialCode An initial value for the result code. Often
1805 * Activity.RESULT_OK.
1806 * @param initialData An initial value for the result data. Often
1807 * null.
1808 * @param initialExtras An initial value for the result extras. Often
1809 * null.
1810 *
1811 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1812 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001813 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001814 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1815 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001816 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1817 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001818
1819 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001820 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001821 * user the broadcast will be sent to. This is not available to applications
1822 * that are not pre-installed on the system image. Using it requires holding
1823 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001824 *
1825 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1826 * permission in order to use this API. If you do not hold that
1827 * permission, {@link SecurityException} will be thrown.
1828 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001829 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1830 * can access them), no protection (anyone can modify them), and many other problems.
1831 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1832 * has changed, with another mechanism for apps to retrieve the current value whenever
1833 * desired.
1834 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001835 * @param intent The Intent that was previously broadcast.
1836 * @param user UserHandle to remove the sticky broadcast from.
1837 *
1838 * @see #sendStickyBroadcastAsUser
1839 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001840 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001841 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1842
1843 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07001844 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001845 * <var>receiver</var> will be called with any broadcast Intent that
1846 * matches <var>filter</var>, in the main application thread.
1847 *
1848 * <p>The system may broadcast Intents that are "sticky" -- these stay
1849 * around after the broadcast as finished, to be sent to any later
1850 * registrations. If your IntentFilter matches one of these sticky
1851 * Intents, that Intent will be returned by this function
1852 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1853 * been broadcast.
1854 *
1855 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1856 * in which case each of these will be sent to <var>receiver</var>. In
1857 * this case, only one of these can be returned directly by the function;
1858 * which of these that is returned is arbitrarily decided by the system.
1859 *
1860 * <p>If you know the Intent your are registering for is sticky, you can
1861 * supply null for your <var>receiver</var>. In this case, no receiver is
1862 * registered -- the function simply returns the sticky Intent that
1863 * matches <var>filter</var>. In the case of multiple matches, the same
1864 * rules as described above apply.
1865 *
1866 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1867 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001868 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1869 * registered with this method will correctly respect the
1870 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1871 * Prior to that, it would be ignored and delivered to all matching registered
1872 * receivers. Be careful if using this for security.</p>
1873 *
Chris Tatea34df8a22009-04-02 23:15:58 -07001874 * <p class="note">Note: this method <em>cannot be called from a
1875 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1876 * that is declared in an application's manifest. It is okay, however, to call
1877 * this method from another BroadcastReceiver that has itself been registered
1878 * at run time with {@link #registerReceiver}, since the lifetime of such a
1879 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 *
1881 * @param receiver The BroadcastReceiver to handle the broadcast.
1882 * @param filter Selects the Intent broadcasts to be received.
1883 *
1884 * @return The first sticky intent found that matches <var>filter</var>,
1885 * or null if there are none.
1886 *
1887 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1888 * @see #sendBroadcast
1889 * @see #unregisterReceiver
1890 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001891 @Nullable
1892 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001893 IntentFilter filter);
1894
1895 /**
1896 * Register to receive intent broadcasts, to run in the context of
1897 * <var>scheduler</var>. See
1898 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1899 * information. This allows you to enforce permissions on who can
1900 * broadcast intents to your receiver, or have the receiver run in
1901 * a different thread than the main application thread.
1902 *
1903 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1904 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001905 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1906 * registered with this method will correctly respect the
1907 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1908 * Prior to that, it would be ignored and delivered to all matching registered
1909 * receivers. Be careful if using this for security.</p>
1910 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 * @param receiver The BroadcastReceiver to handle the broadcast.
1912 * @param filter Selects the Intent broadcasts to be received.
1913 * @param broadcastPermission String naming a permissions that a
1914 * broadcaster must hold in order to send an Intent to you. If null,
1915 * no permission is required.
1916 * @param scheduler Handler identifying the thread that will receive
1917 * the Intent. If null, the main thread of the process will be used.
1918 *
1919 * @return The first sticky intent found that matches <var>filter</var>,
1920 * or null if there are none.
1921 *
1922 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1923 * @see #sendBroadcast
1924 * @see #unregisterReceiver
1925 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001926 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001928 IntentFilter filter, @Nullable String broadcastPermission,
1929 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07001930
1931 /**
1932 * @hide
1933 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1934 * but for a specific user. This receiver will receiver broadcasts that
1935 * are sent to the requested user. It
1936 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1937 * permission.
1938 *
1939 * @param receiver The BroadcastReceiver to handle the broadcast.
1940 * @param user UserHandle to send the intent to.
1941 * @param filter Selects the Intent broadcasts to be received.
1942 * @param broadcastPermission String naming a permissions that a
1943 * broadcaster must hold in order to send an Intent to you. If null,
1944 * no permission is required.
1945 * @param scheduler Handler identifying the thread that will receive
1946 * the Intent. If null, the main thread of the process will be used.
1947 *
1948 * @return The first sticky intent found that matches <var>filter</var>,
1949 * or null if there are none.
1950 *
Jeff Brown6e539312015-02-24 18:53:21 -08001951 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07001952 * @see #sendBroadcast
1953 * @see #unregisterReceiver
1954 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001955 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07001956 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001957 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1958 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001959
1960 /**
1961 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1962 * filters that have been registered for this BroadcastReceiver will be
1963 * removed.
1964 *
1965 * @param receiver The BroadcastReceiver to unregister.
1966 *
1967 * @see #registerReceiver
1968 */
1969 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1970
1971 /**
1972 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07001973 * should contain either contain the complete class name of a specific service
1974 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07001975 * Intent is less specified, it log a warning about this and which of the
1976 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 * is not already running, it will be instantiated and started (creating a
1978 * process for it if needed); if it is running then it remains running.
1979 *
1980 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07001981 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001982 * with the <var>intent</var> given here. This provides a convenient way
1983 * to submit jobs to a service without having to bind and call on to its
1984 * interface.
1985 *
1986 * <p>Using startService() overrides the default service lifetime that is
1987 * managed by {@link #bindService}: it requires the service to remain
1988 * running until {@link #stopService} is called, regardless of whether
1989 * any clients are connected to it. Note that calls to startService()
1990 * are not nesting: no matter how many times you call startService(),
1991 * a single call to {@link #stopService} will stop it.
1992 *
1993 * <p>The system attempts to keep running services around as much as
1994 * possible. The only time they should be stopped is if the current
1995 * foreground application is using so many resources that the service needs
1996 * to be killed. If any errors happen in the service's process, it will
1997 * automatically be restarted.
1998 *
1999 * <p>This function will throw {@link SecurityException} if you do not
2000 * have permission to start the given service.
2001 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002002 * @param service Identifies the service to be started. The Intent must be either
2003 * fully explicit (supplying a component name) or specify a specific package
2004 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 * may be included in the Intent extras to supply arguments along with
2006 * this specific start call.
2007 *
2008 * @return If the service is being started or is already running, the
2009 * {@link ComponentName} of the actual service that was started is
2010 * returned; else if the service does not exist null is returned.
2011 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002012 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013 *
2014 * @see #stopService
2015 * @see #bindService
2016 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002017 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 public abstract ComponentName startService(Intent service);
2019
2020 /**
2021 * Request that a given application service be stopped. If the service is
2022 * not running, nothing happens. Otherwise it is stopped. Note that calls
2023 * to startService() are not counted -- this stops the service no matter
2024 * how many times it was started.
2025 *
2026 * <p>Note that if a stopped service still has {@link ServiceConnection}
2027 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2028 * not be destroyed until all of these bindings are removed. See
2029 * the {@link android.app.Service} documentation for more details on a
2030 * service's lifecycle.
2031 *
2032 * <p>This function will throw {@link SecurityException} if you do not
2033 * have permission to stop the given service.
2034 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002035 * @param service Description of the service to be stopped. The Intent must be either
2036 * fully explicit (supplying a component name) or specify a specific package
2037 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 *
2039 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002040 * 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 -08002041 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002042 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 *
2044 * @see #startService
2045 */
2046 public abstract boolean stopService(Intent service);
2047
2048 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002049 * @hide like {@link #startService(Intent)} but for a specific user.
2050 */
2051 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2052
2053 /**
2054 * @hide like {@link #stopService(Intent)} but for a specific user.
2055 */
2056 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002057
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002058 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 * Connect to an application service, creating it if needed. This defines
2060 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002061 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002062 * told if it dies and restarts. The service will be considered required
2063 * by the system only for as long as the calling context exists. For
2064 * example, if this Context is an Activity that is stopped, the service will
2065 * not be required to continue running until the Activity is resumed.
2066 *
2067 * <p>This function will throw {@link SecurityException} if you do not
2068 * have permission to bind to the given service.
2069 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002070 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002071 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002072 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002073 * {@link #startService} with the arguments containing the command to be
2074 * sent, with the service calling its
2075 * {@link android.app.Service#stopSelf(int)} method when done executing
2076 * that command. See the API demo App/Service/Service Start Arguments
2077 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002078 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2080 * is tied to another object (the one that registered it).</p>
2081 *
2082 * @param service Identifies the service to connect to. The Intent may
2083 * specify either an explicit component name, or a logical
2084 * description (action, category, etc) to match an
2085 * {@link IntentFilter} published by a service.
2086 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002087 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002088 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002089 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2090 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2091 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2092 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002093 * @return If you have successfully bound to the service, {@code true} is returned;
2094 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 * receive the service object.
2096 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002097 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 *
2099 * @see #unbindService
2100 * @see #startService
2101 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002102 * @see #BIND_DEBUG_UNBIND
2103 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002104 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002105 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
2106 @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002107
2108 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002109 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002110 * argument for use by system server and other multi-user aware code.
2111 * @hide
2112 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002113 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002114 @SuppressWarnings("unused")
2115 public boolean bindServiceAsUser(Intent service, ServiceConnection conn,
2116 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002117 throw new RuntimeException("Not implemented. Must override in a subclass.");
2118 }
2119
2120 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121 * Disconnect from an application service. You will no longer receive
2122 * calls as the service is restarted, and the service is now allowed to
2123 * stop at any time.
2124 *
2125 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002126 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 *
2128 * @see #bindService
2129 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002130 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131
2132 /**
2133 * Start executing an {@link android.app.Instrumentation} class. The given
2134 * Instrumentation component will be run by killing its target application
2135 * (if currently running), starting the target process, instantiating the
2136 * instrumentation component, and then letting it drive the application.
2137 *
2138 * <p>This function is not synchronous -- it returns as soon as the
2139 * instrumentation has started and while it is running.
2140 *
2141 * <p>Instrumentation is normally only allowed to run against a package
2142 * that is either unsigned or signed with a signature that the
2143 * the instrumentation package is also signed with (ensuring the target
2144 * trusts the instrumentation).
2145 *
2146 * @param className Name of the Instrumentation component to be run.
2147 * @param profileFile Optional path to write profiling data as the
2148 * instrumentation runs, or null for no profiling.
2149 * @param arguments Additional optional arguments to pass to the
2150 * instrumentation, or null.
2151 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002152 * @return {@code true} if the instrumentation was successfully started,
2153 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002155 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2156 @Nullable String profileFile, @Nullable Bundle arguments);
2157
2158 /** @hide */
2159 @StringDef({
2160 POWER_SERVICE,
2161 WINDOW_SERVICE,
2162 LAYOUT_INFLATER_SERVICE,
2163 ACCOUNT_SERVICE,
2164 ACTIVITY_SERVICE,
2165 ALARM_SERVICE,
2166 NOTIFICATION_SERVICE,
2167 ACCESSIBILITY_SERVICE,
2168 CAPTIONING_SERVICE,
2169 KEYGUARD_SERVICE,
2170 LOCATION_SERVICE,
2171 //@hide: COUNTRY_DETECTOR,
2172 SEARCH_SERVICE,
2173 SENSOR_SERVICE,
2174 STORAGE_SERVICE,
2175 WALLPAPER_SERVICE,
2176 VIBRATOR_SERVICE,
2177 //@hide: STATUS_BAR_SERVICE,
2178 CONNECTIVITY_SERVICE,
2179 //@hide: UPDATE_LOCK_SERVICE,
2180 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002181 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002182 //@hide: NETWORK_POLICY_SERVICE,
2183 WIFI_SERVICE,
Yuhao Zhenga4864472014-04-10 11:45:42 -07002184 WIFI_PASSPOINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002185 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002186 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002187 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002188 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002189 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002190 NSD_SERVICE,
2191 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002192 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002193 MEDIA_ROUTER_SERVICE,
2194 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002195 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002196 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002197 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002198 CLIPBOARD_SERVICE,
2199 INPUT_METHOD_SERVICE,
2200 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002201 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002202 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002203 //@hide: BACKUP_SERVICE,
2204 DROPBOX_SERVICE,
2205 DEVICE_POLICY_SERVICE,
2206 UI_MODE_SERVICE,
2207 DOWNLOAD_SERVICE,
2208 NFC_SERVICE,
2209 BLUETOOTH_SERVICE,
2210 //@hide: SIP_SERVICE,
2211 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002212 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002213 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002214 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002215 INPUT_SERVICE,
2216 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002217 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002218 RESTRICTIONS_SERVICE,
2219 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002220 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002221 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002222 CONSUMER_IR_SERVICE,
2223 //@hide: TRUST_SERVICE,
2224 TV_INPUT_SERVICE,
2225 //@hide: NETWORK_SCORE_SERVICE,
2226 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002227 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002228 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002229 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002230 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002231 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002232 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002233 RADIO_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002234 })
2235 @Retention(RetentionPolicy.SOURCE)
2236 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002237
2238 /**
2239 * Return the handle to a system-level service by name. The class of the
2240 * returned object varies by the requested name. Currently available names
2241 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002242 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 * <dl>
2244 * <dt> {@link #WINDOW_SERVICE} ("window")
2245 * <dd> The top-level window manager in which you can place custom
2246 * windows. The returned object is a {@link android.view.WindowManager}.
2247 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2248 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2249 * in this context.
2250 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2251 * <dd> A {@link android.app.ActivityManager} for interacting with the
2252 * global activity state of the system.
2253 * <dt> {@link #POWER_SERVICE} ("power")
2254 * <dd> A {@link android.os.PowerManager} for controlling power
2255 * management.
2256 * <dt> {@link #ALARM_SERVICE} ("alarm")
2257 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2258 * time of your choosing.
2259 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2260 * <dd> A {@link android.app.NotificationManager} for informing the user
2261 * of background events.
2262 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2263 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2264 * <dt> {@link #LOCATION_SERVICE} ("location")
2265 * <dd> A {@link android.location.LocationManager} for controlling location
2266 * (e.g., GPS) updates.
2267 * <dt> {@link #SEARCH_SERVICE} ("search")
2268 * <dd> A {@link android.app.SearchManager} for handling search.
2269 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2270 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2271 * hardware.
2272 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2273 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2274 * handling management of network connections.
2275 * <dt> {@link #WIFI_SERVICE} ("wifi")
2276 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2277 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002278 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2279 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2280 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002281 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2282 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2283 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002284 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2285 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002286 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002287 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002288 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002289 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002290 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2291 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002292 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
2293 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
2294 * usage statistics.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002295 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002296 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 * <p>Note: System services obtained via this API may be closely associated with
2298 * the Context in which they are obtained from. In general, do not share the
2299 * service objects between various different contexts (Activities, Applications,
2300 * Services, Providers, etc.)
2301 *
2302 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002303 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002304 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002305 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002306 * @see #WINDOW_SERVICE
2307 * @see android.view.WindowManager
2308 * @see #LAYOUT_INFLATER_SERVICE
2309 * @see android.view.LayoutInflater
2310 * @see #ACTIVITY_SERVICE
2311 * @see android.app.ActivityManager
2312 * @see #POWER_SERVICE
2313 * @see android.os.PowerManager
2314 * @see #ALARM_SERVICE
2315 * @see android.app.AlarmManager
2316 * @see #NOTIFICATION_SERVICE
2317 * @see android.app.NotificationManager
2318 * @see #KEYGUARD_SERVICE
2319 * @see android.app.KeyguardManager
2320 * @see #LOCATION_SERVICE
2321 * @see android.location.LocationManager
2322 * @see #SEARCH_SERVICE
2323 * @see android.app.SearchManager
2324 * @see #SENSOR_SERVICE
2325 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002326 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002327 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 * @see #VIBRATOR_SERVICE
2329 * @see android.os.Vibrator
2330 * @see #CONNECTIVITY_SERVICE
2331 * @see android.net.ConnectivityManager
2332 * @see #WIFI_SERVICE
2333 * @see android.net.wifi.WifiManager
2334 * @see #AUDIO_SERVICE
2335 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002336 * @see #MEDIA_ROUTER_SERVICE
2337 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 * @see #TELEPHONY_SERVICE
2339 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002340 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2341 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002342 * @see #CARRIER_CONFIG_SERVICE
2343 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002344 * @see #INPUT_METHOD_SERVICE
2345 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002346 * @see #UI_MODE_SERVICE
2347 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002348 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002349 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002350 * @see #BATTERY_SERVICE
2351 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002352 * @see #JOB_SCHEDULER_SERVICE
2353 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002354 * @see #NETWORK_STATS_SERVICE
2355 * @see android.app.usage.NetworkStatsManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002356 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002357 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358
2359 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002360 * Return the handle to a system-level service by class.
2361 * <p>
2362 * Currently available classes are:
2363 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2364 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2365 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2366 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2367 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2368 * {@link android.net.ConnectivityManager},
2369 * {@link android.net.wifi.WifiManager},
2370 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2371 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2372 * {@link android.view.inputmethod.InputMethodManager},
2373 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002374 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
2375 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08002376 * </p><p>
2377 * Note: System services obtained via this API may be closely associated with
2378 * the Context in which they are obtained from. In general, do not share the
2379 * service objects between various different contexts (Activities, Applications,
2380 * Services, Providers, etc.)
2381 * </p>
2382 *
2383 * @param serviceClass The class of the desired service.
2384 * @return The service or null if the class is not a supported system service.
2385 */
2386 @SuppressWarnings("unchecked")
2387 public final <T> T getSystemService(Class<T> serviceClass) {
2388 // Because subclasses may override getSystemService(String) we cannot
2389 // perform a lookup by class alone. We must first map the class to its
2390 // service name then invoke the string-based method.
2391 String serviceName = getSystemServiceName(serviceClass);
2392 return serviceName != null ? (T)getSystemService(serviceName) : null;
2393 }
2394
2395 /**
2396 * Gets the name of the system-level service that is represented by the specified class.
2397 *
2398 * @param serviceClass The class of the desired service.
2399 * @return The service name or null if the class is not a supported system service.
2400 *
2401 * @hide
2402 */
2403 public abstract String getSystemServiceName(Class<?> serviceClass);
2404
2405 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 * Use with {@link #getSystemService} to retrieve a
2407 * {@link android.os.PowerManager} for controlling power management,
2408 * including "wake locks," which let you keep the device on while
2409 * you're running long tasks.
2410 */
2411 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413 /**
2414 * Use with {@link #getSystemService} to retrieve a
2415 * {@link android.view.WindowManager} for accessing the system's window
2416 * manager.
2417 *
2418 * @see #getSystemService
2419 * @see android.view.WindowManager
2420 */
2421 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 /**
2424 * Use with {@link #getSystemService} to retrieve a
2425 * {@link android.view.LayoutInflater} for inflating layout resources in this
2426 * context.
2427 *
2428 * @see #getSystemService
2429 * @see android.view.LayoutInflater
2430 */
2431 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002432
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002433 /**
2434 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002435 * {@link android.accounts.AccountManager} for receiving intents at a
2436 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002437 *
2438 * @see #getSystemService
2439 * @see android.accounts.AccountManager
2440 */
2441 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002442
Fred Quintana60307342009-03-24 22:48:12 -07002443 /**
2444 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 * {@link android.app.ActivityManager} for interacting with the global
2446 * system state.
2447 *
2448 * @see #getSystemService
2449 * @see android.app.ActivityManager
2450 */
2451 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002452
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 /**
2454 * Use with {@link #getSystemService} to retrieve a
2455 * {@link android.app.AlarmManager} for receiving intents at a
2456 * time of your choosing.
2457 *
2458 * @see #getSystemService
2459 * @see android.app.AlarmManager
2460 */
2461 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002463 /**
2464 * Use with {@link #getSystemService} to retrieve a
2465 * {@link android.app.NotificationManager} for informing the user of
2466 * background events.
2467 *
2468 * @see #getSystemService
2469 * @see android.app.NotificationManager
2470 */
2471 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 /**
2474 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002475 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2476 * feedback for UI events through the registered event listeners.
2477 *
2478 * @see #getSystemService
2479 * @see android.view.accessibility.AccessibilityManager
2480 */
2481 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002482
svetoslavganov75986cf2009-05-14 22:28:01 -07002483 /**
2484 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002485 * {@link android.view.accessibility.CaptioningManager} for obtaining
2486 * captioning properties and listening for changes in captioning
2487 * preferences.
2488 *
2489 * @see #getSystemService
2490 * @see android.view.accessibility.CaptioningManager
2491 */
2492 public static final String CAPTIONING_SERVICE = "captioning";
2493
2494 /**
2495 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 * {@link android.app.NotificationManager} for controlling keyguard.
2497 *
2498 * @see #getSystemService
2499 * @see android.app.KeyguardManager
2500 */
2501 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002502
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002503 /**
2504 * Use with {@link #getSystemService} to retrieve a {@link
2505 * android.location.LocationManager} for controlling location
2506 * updates.
2507 *
2508 * @see #getSystemService
2509 * @see android.location.LocationManager
2510 */
2511 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002512
2513 /**
2514 * Use with {@link #getSystemService} to retrieve a
2515 * {@link android.location.CountryDetector} for detecting the country that
2516 * the user is in.
2517 *
2518 * @hide
2519 */
2520 public static final String COUNTRY_DETECTOR = "country_detector";
2521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002522 /**
2523 * Use with {@link #getSystemService} to retrieve a {@link
2524 * android.app.SearchManager} for handling searches.
2525 *
2526 * @see #getSystemService
2527 * @see android.app.SearchManager
2528 */
2529 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 /**
2532 * Use with {@link #getSystemService} to retrieve a {@link
2533 * android.hardware.SensorManager} for accessing sensors.
2534 *
2535 * @see #getSystemService
2536 * @see android.hardware.SensorManager
2537 */
2538 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07002539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002540 /**
San Mehatc9d81752010-02-01 10:23:27 -08002541 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07002542 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08002543 * functions.
2544 *
2545 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08002546 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08002547 */
2548 public static final String STORAGE_SERVICE = "storage";
2549
2550 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 * Use with {@link #getSystemService} to retrieve a
2552 * com.android.server.WallpaperService for accessing wallpapers.
2553 *
2554 * @see #getSystemService
2555 */
2556 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07002557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 /**
2559 * Use with {@link #getSystemService} to retrieve a {@link
2560 * android.os.Vibrator} for interacting with the vibration hardware.
2561 *
2562 * @see #getSystemService
2563 * @see android.os.Vibrator
2564 */
2565 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002566
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 /**
2568 * Use with {@link #getSystemService} to retrieve a {@link
2569 * android.app.StatusBarManager} for interacting with the status bar.
2570 *
2571 * @see #getSystemService
2572 * @see android.app.StatusBarManager
2573 * @hide
2574 */
2575 public static final String STATUS_BAR_SERVICE = "statusbar";
2576
2577 /**
2578 * Use with {@link #getSystemService} to retrieve a {@link
2579 * android.net.ConnectivityManager} for handling management of
2580 * network connections.
2581 *
2582 * @see #getSystemService
2583 * @see android.net.ConnectivityManager
2584 */
2585 public static final String CONNECTIVITY_SERVICE = "connectivity";
2586
2587 /**
2588 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002589 * android.os.IUpdateLock} for managing runtime sequences that
2590 * must not be interrupted by headless OTA application or similar.
2591 *
2592 * @hide
2593 * @see #getSystemService
2594 * @see android.os.UpdateLock
2595 */
2596 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2597
2598 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002599 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07002600 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08002601 */
2602 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2603
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002604 /**
2605 * Use with {@link #getSystemService} to retrieve a {@link
2606 * android.app.usage.NetworkStatsManager} for querying network usage stats.
2607 *
2608 * @see #getSystemService
2609 * @see android.app.usage.NetworkStatsManager
2610 */
Jeff Sharkey75279902011-05-24 18:39:45 -07002611 public static final String NETWORK_STATS_SERVICE = "netstats";
2612 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002613 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2614
San Mehatd1df8ac2010-01-26 06:17:26 -08002615 /**
2616 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 * android.net.wifi.WifiManager} for handling management of
2618 * Wi-Fi access.
2619 *
2620 * @see #getSystemService
2621 * @see android.net.wifi.WifiManager
2622 */
2623 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 /**
repo sync55bc5f32011-06-24 14:23:07 -07002626 * Use with {@link #getSystemService} to retrieve a {@link
Roger Chang7fee7232014-05-15 14:46:49 -07002627 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
Yuhao Zhenga4864472014-04-10 11:45:42 -07002628 * Wi-Fi passpoint access.
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002629 *
2630 * @see #getSystemService
Roger Chang7fee7232014-05-15 14:46:49 -07002631 * @see android.net.wifi.passpoint.WifiPasspointManager
Yuhao Zheng0cb59f22014-05-27 10:35:02 -07002632 * @hide
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002633 */
Yuhao Zhenga4864472014-04-10 11:45:42 -07002634 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002635
2636 /**
2637 * Use with {@link #getSystemService} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07002638 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002639 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002640 *
2641 * @see #getSystemService
2642 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002643 */
2644 public static final String WIFI_P2P_SERVICE = "wifip2p";
2645
2646 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002647 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002648 * android.net.wifi.WifiScanner} for scanning the wifi universe
2649 *
2650 * @see #getSystemService
2651 * @see android.net.wifi.WifiScanner
2652 * @hide
2653 */
Wei Wang35d552f2014-07-08 21:37:01 -07002654 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002655 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2656
2657 /**
2658 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07002659 * android.net.wifi.RttManager} for ranging devices with wifi
2660 *
2661 * @see #getSystemService
2662 * @see android.net.wifi.RttManager
2663 * @hide
2664 */
2665 @SystemApi
2666 public static final String WIFI_RTT_SERVICE = "rttmanager";
2667
2668 /**
2669 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002670 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002671 * Ethernet access.
2672 *
2673 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002674 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002675 *
2676 * @hide
2677 */
2678 public static final String ETHERNET_SERVICE = "ethernet";
2679
2680 /**
2681 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002682 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002683 * discovery
2684 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002685 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002686 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002687 */
2688 public static final String NSD_SERVICE = "servicediscovery";
2689
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002690 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 * Use with {@link #getSystemService} to retrieve a
2692 * {@link android.media.AudioManager} for handling management of volume,
2693 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002694 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 * @see #getSystemService
2696 * @see android.media.AudioManager
2697 */
2698 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002699
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 /**
2701 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07002702 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07002703 * of fingerprints.
2704 *
2705 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07002706 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07002707 */
2708 public static final String FINGERPRINT_SERVICE = "fingerprint";
2709
2710 /**
2711 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002712 * {@link android.media.MediaRouter} for controlling and managing
2713 * routing of media.
2714 *
2715 * @see #getSystemService
2716 * @see android.media.MediaRouter
2717 */
2718 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2719
2720 /**
2721 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07002722 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08002723 *
2724 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07002725 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08002726 */
2727 public static final String MEDIA_SESSION_SERVICE = "media_session";
2728
2729 /**
2730 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 * {@link android.telephony.TelephonyManager} for handling management the
2732 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002733 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002734 * @see #getSystemService
2735 * @see android.telephony.TelephonyManager
2736 */
2737 public static final String TELEPHONY_SERVICE = "phone";
2738
2739 /**
2740 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08002741 * {@link android.telephony.SubscriptionManager} for handling management the
2742 * telephony subscriptions of the device.
2743 *
2744 * @see #getSystemService
2745 * @see android.telephony.SubscriptionManager
2746 */
2747 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
2748
2749 /**
2750 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002751 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07002752 * of the device.
2753 *
2754 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002755 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07002756 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002757 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07002758
2759 /**
2760 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002761 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
2762 *
2763 * @see #getSystemService
2764 * @see android.telephony.CarrierConfigManager
2765 */
2766 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
2767
2768 /**
2769 * Use with {@link #getSystemService} to retrieve a
2770 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08002771 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002772 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002773 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002774 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08002775 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 */
2777 public static final String CLIPBOARD_SERVICE = "clipboard";
2778
2779 /**
Scott Main4b5da682010-10-21 11:49:12 -07002780 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002781 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2782 * methods.
2783 *
2784 * @see #getSystemService
2785 */
2786 public static final String INPUT_METHOD_SERVICE = "input_method";
2787
2788 /**
2789 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002790 * {@link android.view.textservice.TextServicesManager} for accessing
2791 * text services.
2792 *
2793 * @see #getSystemService
2794 */
2795 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2796
2797 /**
2798 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002799 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002800 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 * @see #getSystemService
2802 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002803 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002805 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07002806 * Official published name of the (internal) voice interaction manager service.
2807 *
2808 * @hide
2809 * @see #getSystemService
2810 */
2811 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2812
2813 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002814 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002815 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002816 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002817 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002818 *
Christopher Tate487529a2009-04-29 14:03:25 -07002819 * @see #getSystemService
2820 */
Christopher Tated5cf7222014-07-29 16:53:09 -07002821 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07002822 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002823
2824 /**
2825 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002826 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002827 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002828 * @see #getSystemService
2829 */
2830 public static final String DROPBOX_SERVICE = "dropbox";
2831
Christopher Tate487529a2009-04-29 14:03:25 -07002832 /**
Scott Main4b5da682010-10-21 11:49:12 -07002833 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002834 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002835 * device policy management.
2836 *
2837 * @see #getSystemService
2838 */
2839 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2840
2841 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002842 * Use with {@link #getSystemService} to retrieve a
2843 * {@link android.app.UiModeManager} for controlling UI modes.
2844 *
2845 * @see #getSystemService
2846 */
2847 public static final String UI_MODE_SERVICE = "uimode";
2848
2849 /**
Steve Howarda2709362010-07-02 17:12:48 -07002850 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002851 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002852 *
2853 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002854 */
2855 public static final String DOWNLOAD_SERVICE = "download";
2856
2857 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002858 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08002859 * {@link android.os.BatteryManager} for managing battery state.
2860 *
2861 * @see #getSystemService
2862 */
2863 public static final String BATTERY_SERVICE = "batterymanager";
2864
2865 /**
2866 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002867 * {@link android.nfc.NfcManager} for using NFC.
2868 *
2869 * @see #getSystemService
2870 */
2871 public static final String NFC_SERVICE = "nfc";
2872
2873 /**
2874 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00002875 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002876 *
2877 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002878 */
2879 public static final String BLUETOOTH_SERVICE = "bluetooth";
2880
2881 /**
2882 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002883 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2884 *
2885 * @see #getSystemService
2886 */
2887 /** @hide */
2888 public static final String SIP_SERVICE = "sip";
2889
2890 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002891 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002892 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002893 * and for controlling this device's behavior as a USB device.
2894 *
2895 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04002896 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002897 */
2898 public static final String USB_SERVICE = "usb";
2899
2900 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002901 * Use with {@link #getSystemService} to retrieve a {@link
2902 * android.hardware.SerialManager} for access to serial ports.
2903 *
2904 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002905 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002906 *
2907 * @hide
2908 */
2909 public static final String SERIAL_SERVICE = "serial";
2910
2911 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002912 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09002913 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2914 * HDMI-CEC protocol.
2915 *
2916 * @see #getSystemService
2917 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002918 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09002919 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002920 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09002921 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09002922
2923 /**
2924 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002925 * {@link android.hardware.input.InputManager} for interacting with input devices.
2926 *
2927 * @see #getSystemService
2928 * @see android.hardware.input.InputManager
2929 */
2930 public static final String INPUT_SERVICE = "input";
2931
2932 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002933 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002934 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2935 *
2936 * @see #getSystemService
2937 * @see android.hardware.display.DisplayManager
2938 */
2939 public static final String DISPLAY_SERVICE = "display";
2940
2941 /**
2942 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07002943 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2944 *
2945 * @see #getSystemService
2946 * @see android.os.UserManager
2947 */
2948 public static final String USER_SERVICE = "user";
2949
2950 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002951 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08002952 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
2953 * profiles of a user.
2954 *
2955 * @see #getSystemService
2956 * @see android.content.pm.LauncherApps
2957 */
2958 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
2959
2960 /**
2961 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07002962 * {@link android.content.RestrictionsManager} for retrieving application restrictions
2963 * and requesting permissions for restricted operations.
2964 * @see #getSystemService
2965 * @see android.content.RestrictionsManager
2966 */
2967 public static final String RESTRICTIONS_SERVICE = "restrictions";
2968
2969 /**
2970 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002971 * {@link android.app.AppOpsManager} for tracking application operations
2972 * on the device.
2973 *
2974 * @see #getSystemService
2975 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002976 */
2977 public static final String APP_OPS_SERVICE = "appops";
2978
2979 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002980 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07002981 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002982 * camera devices.
2983 *
2984 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07002985 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08002986 */
2987 public static final String CAMERA_SERVICE = "camera";
2988
2989 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002990 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07002991 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07002992 *
2993 * @see #getSystemService
2994 * @see android.print.PrintManager
2995 */
2996 public static final String PRINT_SERVICE = "print";
2997
2998 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07002999 * Use with {@link #getSystemService} to retrieve a
3000 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3001 * signals from the device.
3002 *
3003 * @see #getSystemService
3004 * @see android.hardware.ConsumerIrManager
3005 */
3006 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3007
3008 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003009 * {@link android.app.trust.TrustManager} for managing trust agents.
3010 * @see #getSystemService
3011 * @see android.app.trust.TrustManager
3012 * @hide
3013 */
3014 public static final String TRUST_SERVICE = "trust";
3015
3016 /**
Jae Seo39570912014-02-20 18:23:25 -08003017 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003018 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3019 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003020 *
3021 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003022 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003023 */
3024 public static final String TV_INPUT_SERVICE = "tv_input";
3025
3026 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003027 * {@link android.net.NetworkScoreManager} for managing network scoring.
3028 * @see #getSystemService
3029 * @see android.net.NetworkScoreManager
3030 * @hide
3031 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003032 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003033 public static final String NETWORK_SCORE_SERVICE = "network_score";
3034
3035 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003036 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003037 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003038 *
3039 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003040 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003041 */
3042 public static final String USAGE_STATS_SERVICE = "usagestats";
3043
3044 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003045 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003046 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003047 * background tasks.
3048 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003049 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003050 */
Christopher Tate7060b042014-06-09 19:50:00 -07003051 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003052
3053 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003054 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003055 * android.service.persistentdata.PersistentDataBlockManager} instance
3056 * for interacting with a storage device that lives across factory resets.
3057 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003058 * @see #getSystemService
3059 * @see android.service.persistentdata.PersistentDataBlockManager
3060 * @hide
3061 */
Andres Morales33df9372014-09-26 17:08:59 -07003062 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003063 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3064
3065 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003066 * Use with {@link #getSystemService} to retrieve a {@link
3067 * android.media.projection.MediaProjectionManager} instance for managing
3068 * media projection sessions.
3069 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003070 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003071 */
3072 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3073
3074 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003075 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003076 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003077 *
3078 * @see #getSystemService
3079 * @hide
3080 */
3081 public static final String MIDI_SERVICE = "midi";
3082
Eric Laurent2035ac82015-03-05 15:18:44 -08003083
3084 /**
3085 * Use with {@link #getSystemService} to retrieve a
3086 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3087 *
3088 * @see #getSystemService
3089 * @hide
3090 */
3091 public static final String RADIO_SERVICE = "radio";
3092
Paul McLeana33be212015-02-20 07:52:45 -08003093 /**
3094 * Use with {@link #getSystemService} to retrieve a
3095 * {@link android.media.AudioDevicesManager} for handling device enumeration & notification.
3096 *
3097 * @see #getSystemService
3098 * @see android.media.AudioDevicesManager
3099 */
3100 public static final String AUDIO_DEVICES_SERVICE = "audio_devices_manager";
3101
Eric Laurent2035ac82015-03-05 15:18:44 -08003102
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003103 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 * Determine whether the given permission is allowed for a particular
3105 * process and user ID running in the system.
3106 *
3107 * @param permission The name of the permission being checked.
3108 * @param pid The process ID being checked against. Must be > 0.
3109 * @param uid The user ID being checked against. A uid of 0 is the root
3110 * user, which will pass every permission check.
3111 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003112 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003113 * pid/uid is allowed that permission, or
3114 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3115 *
3116 * @see PackageManager#checkPermission(String, String)
3117 * @see #checkCallingPermission
3118 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003119 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003120 @PackageManager.PermissionResult
3121 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122
Dianne Hackbornff170242014-11-19 10:59:01 -08003123 /** @hide */
3124 @PackageManager.PermissionResult
3125 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3126 IBinder callerToken);
3127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 /**
3129 * Determine whether the calling process of an IPC you are handling has been
3130 * granted a particular permission. This is basically the same as calling
3131 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3132 * by {@link android.os.Binder#getCallingPid} and
3133 * {@link android.os.Binder#getCallingUid}. One important difference
3134 * is that if you are not currently processing an IPC, this function
3135 * will always fail. This is done to protect against accidentally
3136 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3137 * to avoid this protection.
3138 *
3139 * @param permission The name of the permission being checked.
3140 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003141 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003142 * pid/uid is allowed that permission, or
3143 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3144 *
3145 * @see PackageManager#checkPermission(String, String)
3146 * @see #checkPermission
3147 * @see #checkCallingOrSelfPermission
3148 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003149 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003150 @PackageManager.PermissionResult
3151 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152
3153 /**
3154 * Determine whether the calling process of an IPC <em>or you</em> have been
3155 * granted a particular permission. This is the same as
3156 * {@link #checkCallingPermission}, except it grants your own permissions
3157 * if you are not currently processing an IPC. Use with care!
3158 *
3159 * @param permission The name of the permission being checked.
3160 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003161 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 * pid/uid is allowed that permission, or
3163 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3164 *
3165 * @see PackageManager#checkPermission(String, String)
3166 * @see #checkPermission
3167 * @see #checkCallingPermission
3168 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003169 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003170 @PackageManager.PermissionResult
3171 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172
3173 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08003174 * Determine whether <em>you</em> have been granted a particular permission.
3175 *
3176 * @param permission The name of the permission being checked.
3177 *
3178 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
3179 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
3180 *
3181 * @see PackageManager#checkPermission(String, String)
3182 * @see #checkCallingPermission(String)
3183 */
3184 @PackageManager.PermissionResult
3185 public abstract int checkSelfPermission(@NonNull String permission);
3186
3187 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003188 * If the given permission is not allowed for a particular process
3189 * and user ID running in the system, throw a {@link SecurityException}.
3190 *
3191 * @param permission The name of the permission being checked.
3192 * @param pid The process ID being checked against. Must be &gt; 0.
3193 * @param uid The user ID being checked against. A uid of 0 is the root
3194 * user, which will pass every permission check.
3195 * @param message A message to include in the exception if it is thrown.
3196 *
3197 * @see #checkPermission(String, int, int)
3198 */
3199 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003200 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201
3202 /**
3203 * If the calling process of an IPC you are handling has not been
3204 * granted a particular permission, throw a {@link
3205 * SecurityException}. This is basically the same as calling
3206 * {@link #enforcePermission(String, int, int, String)} with the
3207 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3208 * and {@link android.os.Binder#getCallingUid}. One important
3209 * difference is that if you are not currently processing an IPC,
3210 * this function will always throw the SecurityException. This is
3211 * done to protect against accidentally leaking permissions; you
3212 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3213 * protection.
3214 *
3215 * @param permission The name of the permission being checked.
3216 * @param message A message to include in the exception if it is thrown.
3217 *
3218 * @see #checkCallingPermission(String)
3219 */
3220 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003221 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222
3223 /**
3224 * If neither you nor the calling process of an IPC you are
3225 * handling has been granted a particular permission, throw a
3226 * {@link SecurityException}. This is the same as {@link
3227 * #enforceCallingPermission}, except it grants your own
3228 * permissions if you are not currently processing an IPC. Use
3229 * with care!
3230 *
3231 * @param permission The name of the permission being checked.
3232 * @param message A message to include in the exception if it is thrown.
3233 *
3234 * @see #checkCallingOrSelfPermission(String)
3235 */
3236 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003237 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003238
3239 /**
3240 * Grant permission to access a specific Uri to another package, regardless
3241 * of whether that package has general permission to access the Uri's
3242 * content provider. This can be used to grant specific, temporary
3243 * permissions, typically in response to user interaction (such as the
3244 * user opening an attachment that you would like someone else to
3245 * display).
3246 *
3247 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3248 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3249 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3250 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3251 * start an activity instead of this function directly. If you use this
3252 * function directly, you should be sure to call
3253 * {@link #revokeUriPermission} when the target should no longer be allowed
3254 * to access it.
3255 *
3256 * <p>To succeed, the content provider owning the Uri must have set the
3257 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3258 * grantUriPermissions} attribute in its manifest or included the
3259 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3260 * &lt;grant-uri-permissions&gt;} tag.
3261 *
3262 * @param toPackage The package you would like to allow to access the Uri.
3263 * @param uri The Uri you would like to grant access to.
3264 * @param modeFlags The desired access modes. Any combination of
3265 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003266 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003267 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003268 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3269 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3270 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3271 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3272 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003273 *
3274 * @see #revokeUriPermission
3275 */
3276 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003277 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278
3279 /**
3280 * Remove all permissions to access a particular content provider Uri
3281 * that were previously added with {@link #grantUriPermission}. The given
3282 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003283 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003285 * "content://foo". It will not remove any prefix grants that exist at a
3286 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003287 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003288 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003289 * regular permission access to a Uri, but had received access to it through
3290 * a specific Uri permission grant, you could not revoke that grant with this
3291 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003292 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003293 * but will remove whatever permission grants to the Uri had been given to the app
3294 * (or none).</p>
3295 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 * @param uri The Uri you would like to revoke access to.
3297 * @param modeFlags The desired access modes. Any combination of
3298 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3299 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3300 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3301 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3302 *
3303 * @see #grantUriPermission
3304 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003305 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306
3307 /**
3308 * Determine whether a particular process and user ID has been granted
3309 * permission to access a specific URI. This only checks for permissions
3310 * that have been explicitly granted -- if the given process/uid has
3311 * more general access to the URI's content provider then this check will
3312 * always fail.
3313 *
3314 * @param uri The uri that is being checked.
3315 * @param pid The process ID being checked against. Must be &gt; 0.
3316 * @param uid The user ID being checked against. A uid of 0 is the root
3317 * user, which will pass every permission check.
3318 * @param modeFlags The type of access to grant. May be one or both of
3319 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3320 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3321 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003322 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003323 * pid/uid is allowed to access that uri, or
3324 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3325 *
3326 * @see #checkCallingUriPermission
3327 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003328 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003329 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003330 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003331
Dianne Hackbornff170242014-11-19 10:59:01 -08003332 /** @hide */
3333 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3334 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 /**
3337 * Determine whether the calling process and user ID has been
3338 * granted permission to access a specific URI. This is basically
3339 * the same as calling {@link #checkUriPermission(Uri, int, int,
3340 * int)} with the pid and uid returned by {@link
3341 * android.os.Binder#getCallingPid} and {@link
3342 * android.os.Binder#getCallingUid}. One important difference is
3343 * that if you are not currently processing an IPC, this function
3344 * will always fail.
3345 *
3346 * @param uri The uri that is being checked.
3347 * @param modeFlags The type of access to grant. May be one or both of
3348 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3349 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3350 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003351 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 * is allowed to access that uri, or
3353 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3354 *
3355 * @see #checkUriPermission(Uri, int, int, int)
3356 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003357 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003358 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003359
3360 /**
3361 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3362 * permission to access a specific URI. This is the same as
3363 * {@link #checkCallingUriPermission}, except it grants your own permissions
3364 * if you are not currently processing an IPC. Use with care!
3365 *
3366 * @param uri The uri that is being checked.
3367 * @param modeFlags The type of access to grant. May be one or both of
3368 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3369 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3370 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003371 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 * is allowed to access that uri, or
3373 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3374 *
3375 * @see #checkCallingUriPermission
3376 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003377 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003378 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003379 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380
3381 /**
3382 * Check both a Uri and normal permission. This allows you to perform
3383 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3384 * call.
3385 *
3386 * @param uri The Uri whose permission is to be checked, or null to not
3387 * do this check.
3388 * @param readPermission The permission that provides overall read access,
3389 * or null to not do this check.
3390 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003391 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 * @param pid The process ID being checked against. Must be &gt; 0.
3393 * @param uid The user ID being checked against. A uid of 0 is the root
3394 * user, which will pass every permission check.
3395 * @param modeFlags The type of access to grant. May be one or both of
3396 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3397 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3398 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003399 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 * is allowed to access that uri or holds one of the given permissions, or
3401 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3402 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003403 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003404 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3405 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003406 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407
3408 /**
3409 * If a particular process and user ID has not been granted
3410 * permission to access a specific URI, throw {@link
3411 * SecurityException}. This only checks for permissions that have
3412 * been explicitly granted -- if the given process/uid has more
3413 * general access to the URI's content provider then this check
3414 * will always fail.
3415 *
3416 * @param uri The uri that is being checked.
3417 * @param pid The process ID being checked against. Must be &gt; 0.
3418 * @param uid The user ID being checked against. A uid of 0 is the root
3419 * user, which will pass every permission check.
3420 * @param modeFlags The type of access to grant. May be one or both of
3421 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3422 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3423 * @param message A message to include in the exception if it is thrown.
3424 *
3425 * @see #checkUriPermission(Uri, int, int, int)
3426 */
3427 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003428 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429
3430 /**
3431 * If the calling process and user ID has not been granted
3432 * permission to access a specific URI, throw {@link
3433 * SecurityException}. This is basically the same as calling
3434 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3435 * the pid and uid returned by {@link
3436 * android.os.Binder#getCallingPid} and {@link
3437 * android.os.Binder#getCallingUid}. One important difference is
3438 * that if you are not currently processing an IPC, this function
3439 * will always throw a SecurityException.
3440 *
3441 * @param uri The uri that is being checked.
3442 * @param modeFlags The type of access to grant. May be one or both of
3443 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3444 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3445 * @param message A message to include in the exception if it is thrown.
3446 *
3447 * @see #checkCallingUriPermission(Uri, int)
3448 */
3449 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003450 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451
3452 /**
3453 * If the calling process of an IPC <em>or you</em> has not been
3454 * granted permission to access a specific URI, throw {@link
3455 * SecurityException}. This is the same as {@link
3456 * #enforceCallingUriPermission}, except it grants your own
3457 * permissions if you are not currently processing an IPC. Use
3458 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003459 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 * @param uri The uri that is being checked.
3461 * @param modeFlags The type of access to grant. May be one or both of
3462 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3463 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3464 * @param message A message to include in the exception if it is thrown.
3465 *
3466 * @see #checkCallingOrSelfUriPermission(Uri, int)
3467 */
3468 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003469 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470
3471 /**
3472 * Enforce both a Uri and normal permission. This allows you to perform
3473 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3474 * call.
Scott Main4b5da682010-10-21 11:49:12 -07003475 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 * @param uri The Uri whose permission is to be checked, or null to not
3477 * do this check.
3478 * @param readPermission The permission that provides overall read access,
3479 * or null to not do this check.
3480 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003481 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 * @param pid The process ID being checked against. Must be &gt; 0.
3483 * @param uid The user ID being checked against. A uid of 0 is the root
3484 * user, which will pass every permission check.
3485 * @param modeFlags The type of access to grant. May be one or both of
3486 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3487 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3488 * @param message A message to include in the exception if it is thrown.
3489 *
3490 * @see #checkUriPermission(Uri, String, String, int, int, int)
3491 */
3492 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003493 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003494 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07003495 @Nullable String message);
3496
3497 /** @hide */
3498 @IntDef(flag = true,
3499 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3500 @Retention(RetentionPolicy.SOURCE)
3501 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502
3503 /**
3504 * Flag for use with {@link #createPackageContext}: include the application
3505 * code with the context. This means loading code into the caller's
3506 * process, so that {@link #getClassLoader()} can be used to instantiate
3507 * the application's classes. Setting this flags imposes security
3508 * restrictions on what application context you can access; if the
3509 * requested application can not be safely loaded into your process,
3510 * java.lang.SecurityException will be thrown. If this flag is not set,
3511 * there will be no restrictions on the packages that can be loaded,
3512 * but {@link #getClassLoader} will always return the default system
3513 * class loader.
3514 */
3515 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3516
3517 /**
3518 * Flag for use with {@link #createPackageContext}: ignore any security
3519 * restrictions on the Context being requested, allowing it to always
3520 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3521 * to be loaded into a process even when it isn't safe to do so. Use
3522 * with extreme care!
3523 */
3524 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07003525
Romain Guy870e09f2009-07-06 16:35:25 -07003526 /**
3527 * Flag for use with {@link #createPackageContext}: a restricted context may
3528 * disable specific features. For instance, a View associated with a restricted
3529 * context would ignore particular XML attributes.
3530 */
3531 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532
3533 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003534 * @hide Used to indicate we should tell the activity manager about the process
3535 * loading this code.
3536 */
3537 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
3538
3539 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 * Return a new Context object for the given application name. This
3541 * Context is the same as what the named application gets when it is
3542 * launched, containing the same resources and class loader. Each call to
3543 * this method returns a new instance of a Context object; Context objects
3544 * are not shared, however they share common state (Resources, ClassLoader,
3545 * etc) so the Context instance itself is fairly lightweight.
3546 *
Jeff Brown6e539312015-02-24 18:53:21 -08003547 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 * application with the given package name.
3549 *
3550 * <p>Throws {@link java.lang.SecurityException} if the Context requested
3551 * can not be loaded into the caller's process for security reasons (see
3552 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3553 *
3554 * @param packageName Name of the application's package.
3555 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3556 * or {@link #CONTEXT_IGNORE_SECURITY}.
3557 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003558 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003559 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003560 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003561 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04003562 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003563 */
3564 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07003565 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07003566
3567 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07003568 * Similar to {@link #createPackageContext(String, int)}, but with a
3569 * different {@link UserHandle}. For example, {@link #getContentResolver()}
3570 * will open any {@link Uri} as the given user.
3571 *
3572 * @hide
3573 */
3574 public abstract Context createPackageContextAsUser(
3575 String packageName, int flags, UserHandle user)
3576 throws PackageManager.NameNotFoundException;
3577
3578 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07003579 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
3580 *
3581 * @hide
3582 */
3583 public abstract Context createApplicationContext(ApplicationInfo application,
3584 int flags) throws PackageManager.NameNotFoundException;
3585
3586 /**
Jim Millera75a8832013-02-07 16:53:32 -08003587 * Get the userId associated with this context
3588 * @return user id
3589 *
3590 * @hide
3591 */
3592 public abstract int getUserId();
3593
3594 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07003595 * Return a new Context object for the current Context but whose resources
3596 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07003597 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07003598 * shared, however common state (ClassLoader, other Resources for the
3599 * same configuration) may be so the Context itself can be fairly lightweight.
3600 *
3601 * @param overrideConfiguration A {@link Configuration} specifying what
3602 * values to modify in the base Configuration of the original Context's
3603 * resources. If the base configuration changes (such as due to an
3604 * orientation change), the resources of this context will also change except
3605 * for those that have been explicitly overridden with a value here.
3606 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003607 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07003608 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003609 public abstract Context createConfigurationContext(
3610 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07003611
3612 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07003613 * Return a new Context object for the current Context but whose resources
3614 * are adjusted to match the metrics of the given Display. Each call to this method
3615 * returns a new instance of a Context object; Context objects are not
3616 * shared, however common state (ClassLoader, other Resources for the
3617 * same configuration) may be so the Context itself can be fairly lightweight.
3618 *
3619 * The returned display Context provides a {@link WindowManager}
3620 * (see {@link #getSystemService(String)}) that is configured to show windows
3621 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
3622 * method can be used to retrieve the Display from the returned Context.
3623 *
3624 * @param display A {@link Display} object specifying the display
3625 * for whose metrics the Context's resources should be tailored and upon which
3626 * new windows should be shown.
3627 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003628 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07003629 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003630 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07003631
3632 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07003633 * Gets the display adjustments holder for this context. This information
3634 * is provided on a per-application or activity basis and is used to simulate lower density
3635 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07003636 *
Jeff Browna492c3a2012-08-23 19:48:44 -07003637 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07003638 * @return The compatibility info holder, or null if not required by the application.
3639 * @hide
3640 */
Craig Mautner48d0d182013-06-11 07:53:06 -07003641 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07003642
3643 /**
Romain Guy870e09f2009-07-06 16:35:25 -07003644 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07003645 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003646 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07003647 *
Romain Guy870e09f2009-07-06 16:35:25 -07003648 * @see #CONTEXT_RESTRICTED
3649 */
3650 public boolean isRestricted() {
3651 return false;
3652 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653}