blob: 3bf3f855ac0cce527cee5de022afc6c2693149d5 [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
Svet Ganov16a16892015-04-16 10:32:04 -07001611
1612 /**
1613 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1614 * user the broadcast will be sent to. This is not available to applications
1615 * that are not pre-installed on the system image. Using it requires holding
1616 * the INTERACT_ACROSS_USERS permission.
1617 *
1618 * @param intent The Intent to broadcast; all receivers matching this
1619 * Intent will receive the broadcast.
1620 * @param user UserHandle to send the intent to.
1621 * @param receiverPermission (optional) String naming a permission that
1622 * a receiver must hold in order to receive your broadcast.
1623 * If null, no permission is required.
1624 * @param appOp The app op associated with the broadcast.
1625 *
1626 * @see #sendBroadcast(Intent, String)
1627 *
1628 * @hide
1629 */
1630 public abstract void sendBroadcastAsUser(Intent intent, UserHandle user,
1631 @Nullable String receiverPermission, int appOp);
1632
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001633 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001634 * Version of
1635 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
1636 * that allows you to specify the
1637 * user the broadcast will be sent to. This is not available to applications
1638 * that are not pre-installed on the system image. Using it requires holding
1639 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001640 *
1641 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1642 *
1643 * @param intent The Intent to broadcast; all receivers matching this
1644 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001645 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001646 * @param receiverPermission String naming a permissions that
1647 * a receiver must hold in order to receive your broadcast.
1648 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001649 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1650 * receiver of the broadcast.
1651 * @param scheduler A custom Handler with which to schedule the
1652 * resultReceiver callback; if null it will be
1653 * scheduled in the Context's main thread.
1654 * @param initialCode An initial value for the result code. Often
1655 * Activity.RESULT_OK.
1656 * @param initialData An initial value for the result data. Often
1657 * null.
1658 * @param initialExtras An initial value for the result extras. Often
1659 * null.
1660 *
1661 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1662 */
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001663 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
Tor Norbyed9273d62013-05-30 15:59:53 -07001664 @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
1665 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1666 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001667
1668 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07001669 * Similar to above but takes an appOp as well, to enforce restrictions.
1670 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
1671 * BroadcastReceiver, Handler, int, String, Bundle)
1672 * @hide
1673 */
1674 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
1675 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1676 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1677 @Nullable Bundle initialExtras);
1678
1679 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001680 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 * Intent you are sending stays around after the broadcast is complete,
1682 * so that others can quickly retrieve that data through the return
1683 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
1684 * all other ways, this behaves the same as
1685 * {@link #sendBroadcast(Intent)}.
1686 *
1687 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1688 * permission in order to use this API. If you do not hold that
1689 * permission, {@link SecurityException} will be thrown.
1690 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001691 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1692 * can access them), no protection (anyone can modify them), and many other problems.
1693 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1694 * has changed, with another mechanism for apps to retrieve the current value whenever
1695 * desired.
1696 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001697 * @param intent The Intent to broadcast; all receivers matching this
1698 * Intent will receive the broadcast, and the Intent will be held to
1699 * be re-broadcast to future receivers.
1700 *
1701 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001702 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001704 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 public abstract void sendStickyBroadcast(Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07001706
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001707 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001708 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001709 * receive data back from the broadcast. This is accomplished by
1710 * supplying your own BroadcastReceiver when calling, which will be
1711 * treated as a final receiver at the end of the broadcast -- its
1712 * {@link BroadcastReceiver#onReceive} method will be called with
1713 * the result values collected from the other receivers. The broadcast will
1714 * be serialized in the same way as calling
1715 * {@link #sendOrderedBroadcast(Intent, String)}.
1716 *
1717 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1718 * asynchronous; it will return before
1719 * resultReceiver.onReceive() is called. Note that the sticky data
1720 * stored is only the data you initially supply to the broadcast, not
1721 * the result of any changes made by the receivers.
1722 *
1723 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1724 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001725 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1726 * can access them), no protection (anyone can modify them), and many other problems.
1727 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1728 * has changed, with another mechanism for apps to retrieve the current value whenever
1729 * desired.
1730 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001731 * @param intent The Intent to broadcast; all receivers matching this
1732 * Intent will receive the broadcast.
1733 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1734 * receiver of the broadcast.
1735 * @param scheduler A custom Handler with which to schedule the
1736 * resultReceiver callback; if null it will be
1737 * scheduled in the Context's main thread.
1738 * @param initialCode An initial value for the result code. Often
1739 * Activity.RESULT_OK.
1740 * @param initialData An initial value for the result data. Often
1741 * null.
1742 * @param initialExtras An initial value for the result extras. Often
1743 * null.
1744 *
1745 * @see #sendBroadcast(Intent)
1746 * @see #sendBroadcast(Intent, String)
1747 * @see #sendOrderedBroadcast(Intent, String)
1748 * @see #sendStickyBroadcast(Intent)
1749 * @see android.content.BroadcastReceiver
1750 * @see #registerReceiver
1751 * @see android.app.Activity#RESULT_OK
1752 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001753 @Deprecated
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001754 public abstract void sendStickyOrderedBroadcast(Intent intent,
1755 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001756 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1757 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001758
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001760 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761 * so that it is as if the sticky broadcast had never happened.
1762 *
1763 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1764 * permission in order to use this API. If you do not hold that
1765 * permission, {@link SecurityException} will be thrown.
1766 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001767 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1768 * can access them), no protection (anyone can modify them), and many other problems.
1769 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1770 * has changed, with another mechanism for apps to retrieve the current value whenever
1771 * desired.
1772 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001773 * @param intent The Intent that was previously broadcast.
1774 *
1775 * @see #sendStickyBroadcast
1776 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001777 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001778 public abstract void removeStickyBroadcast(Intent intent);
1779
1780 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001781 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001782 * user the broadcast will be sent to. This is not available to applications
1783 * that are not pre-installed on the system image. Using it requires holding
1784 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001785 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001786 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1787 * can access them), no protection (anyone can modify them), and many other problems.
1788 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1789 * has changed, with another mechanism for apps to retrieve the current value whenever
1790 * desired.
1791 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001792 * @param intent The Intent to broadcast; all receivers matching this
1793 * Intent will receive the broadcast, and the Intent will be held to
1794 * be re-broadcast to future receivers.
1795 * @param user UserHandle to send the intent to.
1796 *
1797 * @see #sendBroadcast(Intent)
1798 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001799 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001800 public abstract void sendStickyBroadcastAsUser(Intent intent, UserHandle user);
1801
1802 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001803 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07001804 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
1805 * that allows you to specify the
1806 * user the broadcast will be sent to. This is not available to applications
1807 * that are not pre-installed on the system image. Using it requires holding
1808 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001809 *
1810 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1811 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001812 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1813 * can access them), no protection (anyone can modify them), and many other problems.
1814 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1815 * has changed, with another mechanism for apps to retrieve the current value whenever
1816 * desired.
1817 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001818 * @param intent The Intent to broadcast; all receivers matching this
1819 * Intent will receive the broadcast.
1820 * @param user UserHandle to send the intent to.
1821 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1822 * receiver of the broadcast.
1823 * @param scheduler A custom Handler with which to schedule the
1824 * resultReceiver callback; if null it will be
1825 * scheduled in the Context's main thread.
1826 * @param initialCode An initial value for the result code. Often
1827 * Activity.RESULT_OK.
1828 * @param initialData An initial value for the result data. Often
1829 * null.
1830 * @param initialExtras An initial value for the result extras. Often
1831 * null.
1832 *
1833 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
1834 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001835 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001836 public abstract void sendStickyOrderedBroadcastAsUser(Intent intent,
1837 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001838 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1839 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001840
1841 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07001842 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07001843 * user the broadcast will be sent to. This is not available to applications
1844 * that are not pre-installed on the system image. Using it requires holding
1845 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001846 *
1847 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
1848 * permission in order to use this API. If you do not hold that
1849 * permission, {@link SecurityException} will be thrown.
1850 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07001851 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
1852 * can access them), no protection (anyone can modify them), and many other problems.
1853 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
1854 * has changed, with another mechanism for apps to retrieve the current value whenever
1855 * desired.
1856 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001857 * @param intent The Intent that was previously broadcast.
1858 * @param user UserHandle to remove the sticky broadcast from.
1859 *
1860 * @see #sendStickyBroadcastAsUser
1861 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07001862 @Deprecated
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001863 public abstract void removeStickyBroadcastAsUser(Intent intent, UserHandle user);
1864
1865 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07001866 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867 * <var>receiver</var> will be called with any broadcast Intent that
1868 * matches <var>filter</var>, in the main application thread.
1869 *
1870 * <p>The system may broadcast Intents that are "sticky" -- these stay
1871 * around after the broadcast as finished, to be sent to any later
1872 * registrations. If your IntentFilter matches one of these sticky
1873 * Intents, that Intent will be returned by this function
1874 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
1875 * been broadcast.
1876 *
1877 * <p>There may be multiple sticky Intents that match <var>filter</var>,
1878 * in which case each of these will be sent to <var>receiver</var>. In
1879 * this case, only one of these can be returned directly by the function;
1880 * which of these that is returned is arbitrarily decided by the system.
1881 *
1882 * <p>If you know the Intent your are registering for is sticky, you can
1883 * supply null for your <var>receiver</var>. In this case, no receiver is
1884 * registered -- the function simply returns the sticky Intent that
1885 * matches <var>filter</var>. In the case of multiple matches, the same
1886 * rules as described above apply.
1887 *
1888 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1889 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001890 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1891 * registered with this method will correctly respect the
1892 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1893 * Prior to that, it would be ignored and delivered to all matching registered
1894 * receivers. Be careful if using this for security.</p>
1895 *
Chris Tatea34df8a22009-04-02 23:15:58 -07001896 * <p class="note">Note: this method <em>cannot be called from a
1897 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
1898 * that is declared in an application's manifest. It is okay, however, to call
1899 * this method from another BroadcastReceiver that has itself been registered
1900 * at run time with {@link #registerReceiver}, since the lifetime of such a
1901 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001902 *
1903 * @param receiver The BroadcastReceiver to handle the broadcast.
1904 * @param filter Selects the Intent broadcasts to be received.
1905 *
1906 * @return The first sticky intent found that matches <var>filter</var>,
1907 * or null if there are none.
1908 *
1909 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1910 * @see #sendBroadcast
1911 * @see #unregisterReceiver
1912 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001913 @Nullable
1914 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001915 IntentFilter filter);
1916
1917 /**
1918 * Register to receive intent broadcasts, to run in the context of
1919 * <var>scheduler</var>. See
1920 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
1921 * information. This allows you to enforce permissions on who can
1922 * broadcast intents to your receiver, or have the receiver run in
1923 * a different thread than the main application thread.
1924 *
1925 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1926 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07001927 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
1928 * registered with this method will correctly respect the
1929 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
1930 * Prior to that, it would be ignored and delivered to all matching registered
1931 * receivers. Be careful if using this for security.</p>
1932 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 * @param receiver The BroadcastReceiver to handle the broadcast.
1934 * @param filter Selects the Intent broadcasts to be received.
1935 * @param broadcastPermission String naming a permissions that a
1936 * broadcaster must hold in order to send an Intent to you. If null,
1937 * no permission is required.
1938 * @param scheduler Handler identifying the thread that will receive
1939 * the Intent. If null, the main thread of the process will be used.
1940 *
1941 * @return The first sticky intent found that matches <var>filter</var>,
1942 * or null if there are none.
1943 *
1944 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
1945 * @see #sendBroadcast
1946 * @see #unregisterReceiver
1947 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001948 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001950 IntentFilter filter, @Nullable String broadcastPermission,
1951 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07001952
1953 /**
1954 * @hide
1955 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
1956 * but for a specific user. This receiver will receiver broadcasts that
1957 * are sent to the requested user. It
1958 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
1959 * permission.
1960 *
1961 * @param receiver The BroadcastReceiver to handle the broadcast.
1962 * @param user UserHandle to send the intent to.
1963 * @param filter Selects the Intent broadcasts to be received.
1964 * @param broadcastPermission String naming a permissions that a
1965 * broadcaster must hold in order to send an Intent to you. If null,
1966 * no permission is required.
1967 * @param scheduler Handler identifying the thread that will receive
1968 * the Intent. If null, the main thread of the process will be used.
1969 *
1970 * @return The first sticky intent found that matches <var>filter</var>,
1971 * or null if there are none.
1972 *
Jeff Brown6e539312015-02-24 18:53:21 -08001973 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07001974 * @see #sendBroadcast
1975 * @see #unregisterReceiver
1976 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001977 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07001978 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001979 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
1980 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981
1982 /**
1983 * Unregister a previously registered BroadcastReceiver. <em>All</em>
1984 * filters that have been registered for this BroadcastReceiver will be
1985 * removed.
1986 *
1987 * @param receiver The BroadcastReceiver to unregister.
1988 *
1989 * @see #registerReceiver
1990 */
1991 public abstract void unregisterReceiver(BroadcastReceiver receiver);
1992
1993 /**
1994 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07001995 * should contain either contain the complete class name of a specific service
1996 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07001997 * Intent is less specified, it log a warning about this and which of the
1998 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 * is not already running, it will be instantiated and started (creating a
2000 * process for it if needed); if it is running then it remains running.
2001 *
2002 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002003 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 * with the <var>intent</var> given here. This provides a convenient way
2005 * to submit jobs to a service without having to bind and call on to its
2006 * interface.
2007 *
2008 * <p>Using startService() overrides the default service lifetime that is
2009 * managed by {@link #bindService}: it requires the service to remain
2010 * running until {@link #stopService} is called, regardless of whether
2011 * any clients are connected to it. Note that calls to startService()
2012 * are not nesting: no matter how many times you call startService(),
2013 * a single call to {@link #stopService} will stop it.
2014 *
2015 * <p>The system attempts to keep running services around as much as
2016 * possible. The only time they should be stopped is if the current
2017 * foreground application is using so many resources that the service needs
2018 * to be killed. If any errors happen in the service's process, it will
2019 * automatically be restarted.
2020 *
2021 * <p>This function will throw {@link SecurityException} if you do not
2022 * have permission to start the given service.
2023 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002024 * @param service Identifies the service to be started. The Intent must be either
2025 * fully explicit (supplying a component name) or specify a specific package
2026 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 * may be included in the Intent extras to supply arguments along with
2028 * this specific start call.
2029 *
2030 * @return If the service is being started or is already running, the
2031 * {@link ComponentName} of the actual service that was started is
2032 * returned; else if the service does not exist null is returned.
2033 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002034 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035 *
2036 * @see #stopService
2037 * @see #bindService
2038 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002039 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002040 public abstract ComponentName startService(Intent service);
2041
2042 /**
2043 * Request that a given application service be stopped. If the service is
2044 * not running, nothing happens. Otherwise it is stopped. Note that calls
2045 * to startService() are not counted -- this stops the service no matter
2046 * how many times it was started.
2047 *
2048 * <p>Note that if a stopped service still has {@link ServiceConnection}
2049 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2050 * not be destroyed until all of these bindings are removed. See
2051 * the {@link android.app.Service} documentation for more details on a
2052 * service's lifecycle.
2053 *
2054 * <p>This function will throw {@link SecurityException} if you do not
2055 * have permission to stop the given service.
2056 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002057 * @param service Description of the service to be stopped. The Intent must be either
2058 * fully explicit (supplying a component name) or specify a specific package
2059 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 *
2061 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002062 * 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 -08002063 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002064 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 *
2066 * @see #startService
2067 */
2068 public abstract boolean stopService(Intent service);
2069
2070 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002071 * @hide like {@link #startService(Intent)} but for a specific user.
2072 */
2073 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2074
2075 /**
2076 * @hide like {@link #stopService(Intent)} but for a specific user.
2077 */
2078 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002079
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002080 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 * Connect to an application service, creating it if needed. This defines
2082 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002083 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 * told if it dies and restarts. The service will be considered required
2085 * by the system only for as long as the calling context exists. For
2086 * example, if this Context is an Activity that is stopped, the service will
2087 * not be required to continue running until the Activity is resumed.
2088 *
2089 * <p>This function will throw {@link SecurityException} if you do not
2090 * have permission to bind to the given service.
2091 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002092 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002093 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002094 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 * {@link #startService} with the arguments containing the command to be
2096 * sent, with the service calling its
2097 * {@link android.app.Service#stopSelf(int)} method when done executing
2098 * that command. See the API demo App/Service/Service Start Arguments
2099 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002100 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002101 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2102 * is tied to another object (the one that registered it).</p>
2103 *
2104 * @param service Identifies the service to connect to. The Intent may
2105 * specify either an explicit component name, or a logical
2106 * description (action, category, etc) to match an
2107 * {@link IntentFilter} published by a service.
2108 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002109 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002110 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002111 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2112 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2113 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2114 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002115 * @return If you have successfully bound to the service, {@code true} is returned;
2116 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002117 * receive the service object.
2118 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002119 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 *
2121 * @see #unbindService
2122 * @see #startService
2123 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002124 * @see #BIND_DEBUG_UNBIND
2125 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002127 public abstract boolean bindService(Intent service, @NonNull ServiceConnection conn,
2128 @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002129
2130 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002131 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002132 * argument for use by system server and other multi-user aware code.
2133 * @hide
2134 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002135 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002136 @SuppressWarnings("unused")
2137 public boolean bindServiceAsUser(Intent service, ServiceConnection conn,
2138 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002139 throw new RuntimeException("Not implemented. Must override in a subclass.");
2140 }
2141
2142 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 * Disconnect from an application service. You will no longer receive
2144 * calls as the service is restarted, and the service is now allowed to
2145 * stop at any time.
2146 *
2147 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002148 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002149 *
2150 * @see #bindService
2151 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002152 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153
2154 /**
2155 * Start executing an {@link android.app.Instrumentation} class. The given
2156 * Instrumentation component will be run by killing its target application
2157 * (if currently running), starting the target process, instantiating the
2158 * instrumentation component, and then letting it drive the application.
2159 *
2160 * <p>This function is not synchronous -- it returns as soon as the
2161 * instrumentation has started and while it is running.
2162 *
2163 * <p>Instrumentation is normally only allowed to run against a package
2164 * that is either unsigned or signed with a signature that the
2165 * the instrumentation package is also signed with (ensuring the target
2166 * trusts the instrumentation).
2167 *
2168 * @param className Name of the Instrumentation component to be run.
2169 * @param profileFile Optional path to write profiling data as the
2170 * instrumentation runs, or null for no profiling.
2171 * @param arguments Additional optional arguments to pass to the
2172 * instrumentation, or null.
2173 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002174 * @return {@code true} if the instrumentation was successfully started,
2175 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002177 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2178 @Nullable String profileFile, @Nullable Bundle arguments);
2179
2180 /** @hide */
2181 @StringDef({
2182 POWER_SERVICE,
2183 WINDOW_SERVICE,
2184 LAYOUT_INFLATER_SERVICE,
2185 ACCOUNT_SERVICE,
2186 ACTIVITY_SERVICE,
2187 ALARM_SERVICE,
2188 NOTIFICATION_SERVICE,
2189 ACCESSIBILITY_SERVICE,
2190 CAPTIONING_SERVICE,
2191 KEYGUARD_SERVICE,
2192 LOCATION_SERVICE,
2193 //@hide: COUNTRY_DETECTOR,
2194 SEARCH_SERVICE,
2195 SENSOR_SERVICE,
2196 STORAGE_SERVICE,
2197 WALLPAPER_SERVICE,
2198 VIBRATOR_SERVICE,
2199 //@hide: STATUS_BAR_SERVICE,
2200 CONNECTIVITY_SERVICE,
2201 //@hide: UPDATE_LOCK_SERVICE,
2202 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002203 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002204 //@hide: NETWORK_POLICY_SERVICE,
2205 WIFI_SERVICE,
Yuhao Zhenga4864472014-04-10 11:45:42 -07002206 WIFI_PASSPOINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002207 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002208 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002209 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002210 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002211 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002212 NSD_SERVICE,
2213 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002214 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002215 MEDIA_ROUTER_SERVICE,
2216 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002217 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002218 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002219 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002220 CLIPBOARD_SERVICE,
2221 INPUT_METHOD_SERVICE,
2222 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002223 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002224 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002225 //@hide: BACKUP_SERVICE,
2226 DROPBOX_SERVICE,
2227 DEVICE_POLICY_SERVICE,
2228 UI_MODE_SERVICE,
2229 DOWNLOAD_SERVICE,
2230 NFC_SERVICE,
2231 BLUETOOTH_SERVICE,
2232 //@hide: SIP_SERVICE,
2233 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002234 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002235 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002236 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002237 INPUT_SERVICE,
2238 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002239 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002240 RESTRICTIONS_SERVICE,
2241 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002242 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002243 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002244 CONSUMER_IR_SERVICE,
2245 //@hide: TRUST_SERVICE,
2246 TV_INPUT_SERVICE,
2247 //@hide: NETWORK_SCORE_SERVICE,
2248 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002249 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002250 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002251 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002252 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002253 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002254 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002255 RADIO_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002256 })
2257 @Retention(RetentionPolicy.SOURCE)
2258 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002259
2260 /**
2261 * Return the handle to a system-level service by name. The class of the
2262 * returned object varies by the requested name. Currently available names
2263 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002264 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 * <dl>
2266 * <dt> {@link #WINDOW_SERVICE} ("window")
2267 * <dd> The top-level window manager in which you can place custom
2268 * windows. The returned object is a {@link android.view.WindowManager}.
2269 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2270 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2271 * in this context.
2272 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2273 * <dd> A {@link android.app.ActivityManager} for interacting with the
2274 * global activity state of the system.
2275 * <dt> {@link #POWER_SERVICE} ("power")
2276 * <dd> A {@link android.os.PowerManager} for controlling power
2277 * management.
2278 * <dt> {@link #ALARM_SERVICE} ("alarm")
2279 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2280 * time of your choosing.
2281 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2282 * <dd> A {@link android.app.NotificationManager} for informing the user
2283 * of background events.
2284 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2285 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2286 * <dt> {@link #LOCATION_SERVICE} ("location")
2287 * <dd> A {@link android.location.LocationManager} for controlling location
2288 * (e.g., GPS) updates.
2289 * <dt> {@link #SEARCH_SERVICE} ("search")
2290 * <dd> A {@link android.app.SearchManager} for handling search.
2291 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2292 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2293 * hardware.
2294 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2295 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2296 * handling management of network connections.
2297 * <dt> {@link #WIFI_SERVICE} ("wifi")
2298 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2299 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002300 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2301 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2302 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002303 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2304 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2305 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002306 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2307 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002308 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002309 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002310 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002311 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002312 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2313 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002314 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
2315 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
2316 * usage statistics.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002317 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002318 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 * <p>Note: System services obtained via this API may be closely associated with
2320 * the Context in which they are obtained from. In general, do not share the
2321 * service objects between various different contexts (Activities, Applications,
2322 * Services, Providers, etc.)
2323 *
2324 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002325 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002327 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 * @see #WINDOW_SERVICE
2329 * @see android.view.WindowManager
2330 * @see #LAYOUT_INFLATER_SERVICE
2331 * @see android.view.LayoutInflater
2332 * @see #ACTIVITY_SERVICE
2333 * @see android.app.ActivityManager
2334 * @see #POWER_SERVICE
2335 * @see android.os.PowerManager
2336 * @see #ALARM_SERVICE
2337 * @see android.app.AlarmManager
2338 * @see #NOTIFICATION_SERVICE
2339 * @see android.app.NotificationManager
2340 * @see #KEYGUARD_SERVICE
2341 * @see android.app.KeyguardManager
2342 * @see #LOCATION_SERVICE
2343 * @see android.location.LocationManager
2344 * @see #SEARCH_SERVICE
2345 * @see android.app.SearchManager
2346 * @see #SENSOR_SERVICE
2347 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002348 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002349 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 * @see #VIBRATOR_SERVICE
2351 * @see android.os.Vibrator
2352 * @see #CONNECTIVITY_SERVICE
2353 * @see android.net.ConnectivityManager
2354 * @see #WIFI_SERVICE
2355 * @see android.net.wifi.WifiManager
2356 * @see #AUDIO_SERVICE
2357 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002358 * @see #MEDIA_ROUTER_SERVICE
2359 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 * @see #TELEPHONY_SERVICE
2361 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002362 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2363 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002364 * @see #CARRIER_CONFIG_SERVICE
2365 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 * @see #INPUT_METHOD_SERVICE
2367 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002368 * @see #UI_MODE_SERVICE
2369 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002370 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002371 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002372 * @see #BATTERY_SERVICE
2373 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002374 * @see #JOB_SCHEDULER_SERVICE
2375 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002376 * @see #NETWORK_STATS_SERVICE
2377 * @see android.app.usage.NetworkStatsManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002378 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002379 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380
2381 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002382 * Return the handle to a system-level service by class.
2383 * <p>
2384 * Currently available classes are:
2385 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2386 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2387 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2388 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2389 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2390 * {@link android.net.ConnectivityManager},
2391 * {@link android.net.wifi.WifiManager},
2392 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2393 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2394 * {@link android.view.inputmethod.InputMethodManager},
2395 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002396 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
2397 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08002398 * </p><p>
2399 * Note: System services obtained via this API may be closely associated with
2400 * the Context in which they are obtained from. In general, do not share the
2401 * service objects between various different contexts (Activities, Applications,
2402 * Services, Providers, etc.)
2403 * </p>
2404 *
2405 * @param serviceClass The class of the desired service.
2406 * @return The service or null if the class is not a supported system service.
2407 */
2408 @SuppressWarnings("unchecked")
2409 public final <T> T getSystemService(Class<T> serviceClass) {
2410 // Because subclasses may override getSystemService(String) we cannot
2411 // perform a lookup by class alone. We must first map the class to its
2412 // service name then invoke the string-based method.
2413 String serviceName = getSystemServiceName(serviceClass);
2414 return serviceName != null ? (T)getSystemService(serviceName) : null;
2415 }
2416
2417 /**
2418 * Gets the name of the system-level service that is represented by the specified class.
2419 *
2420 * @param serviceClass The class of the desired service.
2421 * @return The service name or null if the class is not a supported system service.
2422 *
2423 * @hide
2424 */
2425 public abstract String getSystemServiceName(Class<?> serviceClass);
2426
2427 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002428 * Use with {@link #getSystemService} to retrieve a
2429 * {@link android.os.PowerManager} for controlling power management,
2430 * including "wake locks," which let you keep the device on while
2431 * you're running long tasks.
2432 */
2433 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002434
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 /**
2436 * Use with {@link #getSystemService} to retrieve a
2437 * {@link android.view.WindowManager} for accessing the system's window
2438 * manager.
2439 *
2440 * @see #getSystemService
2441 * @see android.view.WindowManager
2442 */
2443 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002445 /**
2446 * Use with {@link #getSystemService} to retrieve a
2447 * {@link android.view.LayoutInflater} for inflating layout resources in this
2448 * context.
2449 *
2450 * @see #getSystemService
2451 * @see android.view.LayoutInflater
2452 */
2453 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002454
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002455 /**
2456 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002457 * {@link android.accounts.AccountManager} for receiving intents at a
2458 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002459 *
2460 * @see #getSystemService
2461 * @see android.accounts.AccountManager
2462 */
2463 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002464
Fred Quintana60307342009-03-24 22:48:12 -07002465 /**
2466 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 * {@link android.app.ActivityManager} for interacting with the global
2468 * system state.
2469 *
2470 * @see #getSystemService
2471 * @see android.app.ActivityManager
2472 */
2473 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002475 /**
2476 * Use with {@link #getSystemService} to retrieve a
2477 * {@link android.app.AlarmManager} for receiving intents at a
2478 * time of your choosing.
2479 *
2480 * @see #getSystemService
2481 * @see android.app.AlarmManager
2482 */
2483 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 /**
2486 * Use with {@link #getSystemService} to retrieve a
2487 * {@link android.app.NotificationManager} for informing the user of
2488 * background events.
2489 *
2490 * @see #getSystemService
2491 * @see android.app.NotificationManager
2492 */
2493 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 /**
2496 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002497 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2498 * feedback for UI events through the registered event listeners.
2499 *
2500 * @see #getSystemService
2501 * @see android.view.accessibility.AccessibilityManager
2502 */
2503 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002504
svetoslavganov75986cf2009-05-14 22:28:01 -07002505 /**
2506 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002507 * {@link android.view.accessibility.CaptioningManager} for obtaining
2508 * captioning properties and listening for changes in captioning
2509 * preferences.
2510 *
2511 * @see #getSystemService
2512 * @see android.view.accessibility.CaptioningManager
2513 */
2514 public static final String CAPTIONING_SERVICE = "captioning";
2515
2516 /**
2517 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 * {@link android.app.NotificationManager} for controlling keyguard.
2519 *
2520 * @see #getSystemService
2521 * @see android.app.KeyguardManager
2522 */
2523 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 /**
2526 * Use with {@link #getSystemService} to retrieve a {@link
2527 * android.location.LocationManager} for controlling location
2528 * updates.
2529 *
2530 * @see #getSystemService
2531 * @see android.location.LocationManager
2532 */
2533 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002534
2535 /**
2536 * Use with {@link #getSystemService} to retrieve a
2537 * {@link android.location.CountryDetector} for detecting the country that
2538 * the user is in.
2539 *
2540 * @hide
2541 */
2542 public static final String COUNTRY_DETECTOR = "country_detector";
2543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 /**
2545 * Use with {@link #getSystemService} to retrieve a {@link
2546 * android.app.SearchManager} for handling searches.
2547 *
2548 * @see #getSystemService
2549 * @see android.app.SearchManager
2550 */
2551 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 /**
2554 * Use with {@link #getSystemService} to retrieve a {@link
2555 * android.hardware.SensorManager} for accessing sensors.
2556 *
2557 * @see #getSystemService
2558 * @see android.hardware.SensorManager
2559 */
2560 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07002561
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 /**
San Mehatc9d81752010-02-01 10:23:27 -08002563 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07002564 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08002565 * functions.
2566 *
2567 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08002568 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08002569 */
2570 public static final String STORAGE_SERVICE = "storage";
2571
2572 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 * Use with {@link #getSystemService} to retrieve a
2574 * com.android.server.WallpaperService for accessing wallpapers.
2575 *
2576 * @see #getSystemService
2577 */
2578 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07002579
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002580 /**
2581 * Use with {@link #getSystemService} to retrieve a {@link
2582 * android.os.Vibrator} for interacting with the vibration hardware.
2583 *
2584 * @see #getSystemService
2585 * @see android.os.Vibrator
2586 */
2587 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07002588
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002589 /**
2590 * Use with {@link #getSystemService} to retrieve a {@link
2591 * android.app.StatusBarManager} for interacting with the status bar.
2592 *
2593 * @see #getSystemService
2594 * @see android.app.StatusBarManager
2595 * @hide
2596 */
2597 public static final String STATUS_BAR_SERVICE = "statusbar";
2598
2599 /**
2600 * Use with {@link #getSystemService} to retrieve a {@link
2601 * android.net.ConnectivityManager} for handling management of
2602 * network connections.
2603 *
2604 * @see #getSystemService
2605 * @see android.net.ConnectivityManager
2606 */
2607 public static final String CONNECTIVITY_SERVICE = "connectivity";
2608
2609 /**
2610 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08002611 * android.os.IUpdateLock} for managing runtime sequences that
2612 * must not be interrupted by headless OTA application or similar.
2613 *
2614 * @hide
2615 * @see #getSystemService
2616 * @see android.os.UpdateLock
2617 */
2618 public static final String UPDATE_LOCK_SERVICE = "updatelock";
2619
2620 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002621 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07002622 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08002623 */
2624 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
2625
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002626 /**
2627 * Use with {@link #getSystemService} to retrieve a {@link
2628 * android.app.usage.NetworkStatsManager} for querying network usage stats.
2629 *
2630 * @see #getSystemService
2631 * @see android.app.usage.NetworkStatsManager
2632 */
Jeff Sharkey75279902011-05-24 18:39:45 -07002633 public static final String NETWORK_STATS_SERVICE = "netstats";
2634 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07002635 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
2636
San Mehatd1df8ac2010-01-26 06:17:26 -08002637 /**
2638 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 * android.net.wifi.WifiManager} for handling management of
2640 * Wi-Fi access.
2641 *
2642 * @see #getSystemService
2643 * @see android.net.wifi.WifiManager
2644 */
2645 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07002646
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002647 /**
repo sync55bc5f32011-06-24 14:23:07 -07002648 * Use with {@link #getSystemService} to retrieve a {@link
Roger Chang7fee7232014-05-15 14:46:49 -07002649 * android.net.wifi.passpoint.WifiPasspointManager} for handling management of
Yuhao Zhenga4864472014-04-10 11:45:42 -07002650 * Wi-Fi passpoint access.
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002651 *
2652 * @see #getSystemService
Roger Chang7fee7232014-05-15 14:46:49 -07002653 * @see android.net.wifi.passpoint.WifiPasspointManager
Yuhao Zheng0cb59f22014-05-27 10:35:02 -07002654 * @hide
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002655 */
Yuhao Zhenga4864472014-04-10 11:45:42 -07002656 public static final String WIFI_PASSPOINT_SERVICE = "wifipasspoint";
Yuhao Zheng10bf6352014-03-25 15:00:45 -07002657
2658 /**
2659 * Use with {@link #getSystemService} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07002660 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07002661 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07002662 *
2663 * @see #getSystemService
2664 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07002665 */
2666 public static final String WIFI_P2P_SERVICE = "wifip2p";
2667
2668 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002669 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002670 * android.net.wifi.WifiScanner} for scanning the wifi universe
2671 *
2672 * @see #getSystemService
2673 * @see android.net.wifi.WifiScanner
2674 * @hide
2675 */
Wei Wang35d552f2014-07-08 21:37:01 -07002676 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002677 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
2678
2679 /**
2680 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07002681 * android.net.wifi.RttManager} for ranging devices with wifi
2682 *
2683 * @see #getSystemService
2684 * @see android.net.wifi.RttManager
2685 * @hide
2686 */
2687 @SystemApi
2688 public static final String WIFI_RTT_SERVICE = "rttmanager";
2689
2690 /**
2691 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002692 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002693 * Ethernet access.
2694 *
2695 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07002696 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07002697 *
2698 * @hide
2699 */
2700 public static final String ETHERNET_SERVICE = "ethernet";
2701
2702 /**
2703 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002704 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002705 * discovery
2706 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002707 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07002708 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002709 */
2710 public static final String NSD_SERVICE = "servicediscovery";
2711
Irfan Sheriff7d024d32012-03-22 17:01:39 -07002712 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 * Use with {@link #getSystemService} to retrieve a
2714 * {@link android.media.AudioManager} for handling management of volume,
2715 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07002716 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 * @see #getSystemService
2718 * @see android.media.AudioManager
2719 */
2720 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07002721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 /**
2723 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07002724 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07002725 * of fingerprints.
2726 *
2727 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07002728 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07002729 */
2730 public static final String FINGERPRINT_SERVICE = "fingerprint";
2731
2732 /**
2733 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002734 * {@link android.media.MediaRouter} for controlling and managing
2735 * routing of media.
2736 *
2737 * @see #getSystemService
2738 * @see android.media.MediaRouter
2739 */
2740 public static final String MEDIA_ROUTER_SERVICE = "media_router";
2741
2742 /**
2743 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07002744 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08002745 *
2746 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07002747 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08002748 */
2749 public static final String MEDIA_SESSION_SERVICE = "media_session";
2750
2751 /**
2752 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 * {@link android.telephony.TelephonyManager} for handling management the
2754 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07002755 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002756 * @see #getSystemService
2757 * @see android.telephony.TelephonyManager
2758 */
2759 public static final String TELEPHONY_SERVICE = "phone";
2760
2761 /**
2762 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08002763 * {@link android.telephony.SubscriptionManager} for handling management the
2764 * telephony subscriptions of the device.
2765 *
2766 * @see #getSystemService
2767 * @see android.telephony.SubscriptionManager
2768 */
2769 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
2770
2771 /**
2772 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002773 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07002774 * of the device.
2775 *
2776 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002777 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07002778 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002779 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07002780
2781 /**
2782 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002783 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
2784 *
2785 * @see #getSystemService
2786 * @see android.telephony.CarrierConfigManager
2787 */
2788 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
2789
2790 /**
2791 * Use with {@link #getSystemService} to retrieve a
2792 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08002793 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07002795 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08002797 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 */
2799 public static final String CLIPBOARD_SERVICE = "clipboard";
2800
2801 /**
Scott Main4b5da682010-10-21 11:49:12 -07002802 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002803 * {@link android.view.inputmethod.InputMethodManager} for accessing input
2804 * methods.
2805 *
2806 * @see #getSystemService
2807 */
2808 public static final String INPUT_METHOD_SERVICE = "input_method";
2809
2810 /**
2811 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09002812 * {@link android.view.textservice.TextServicesManager} for accessing
2813 * text services.
2814 *
2815 * @see #getSystemService
2816 */
2817 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
2818
2819 /**
2820 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08002821 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 * @see #getSystemService
2824 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07002825 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07002826
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002827 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07002828 * Official published name of the (internal) voice interaction manager service.
2829 *
2830 * @hide
2831 * @see #getSystemService
2832 */
2833 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
2834
2835 /**
Christopher Tate487529a2009-04-29 14:03:25 -07002836 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08002837 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07002838 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07002839 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07002840 *
Christopher Tate487529a2009-04-29 14:03:25 -07002841 * @see #getSystemService
2842 */
Christopher Tated5cf7222014-07-29 16:53:09 -07002843 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07002844 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07002845
2846 /**
2847 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08002848 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07002849 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07002850 * @see #getSystemService
2851 */
2852 public static final String DROPBOX_SERVICE = "dropbox";
2853
Christopher Tate487529a2009-04-29 14:03:25 -07002854 /**
Scott Main4b5da682010-10-21 11:49:12 -07002855 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08002856 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08002857 * device policy management.
2858 *
2859 * @see #getSystemService
2860 */
2861 public static final String DEVICE_POLICY_SERVICE = "device_policy";
2862
2863 /**
Tobias Haamel53332882010-02-18 16:15:43 -08002864 * Use with {@link #getSystemService} to retrieve a
2865 * {@link android.app.UiModeManager} for controlling UI modes.
2866 *
2867 * @see #getSystemService
2868 */
2869 public static final String UI_MODE_SERVICE = "uimode";
2870
2871 /**
Steve Howarda2709362010-07-02 17:12:48 -07002872 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07002873 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07002874 *
2875 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07002876 */
2877 public static final String DOWNLOAD_SERVICE = "download";
2878
2879 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08002880 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08002881 * {@link android.os.BatteryManager} for managing battery state.
2882 *
2883 * @see #getSystemService
2884 */
2885 public static final String BATTERY_SERVICE = "batterymanager";
2886
2887 /**
2888 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08002889 * {@link android.nfc.NfcManager} for using NFC.
2890 *
2891 * @see #getSystemService
2892 */
2893 public static final String NFC_SERVICE = "nfc";
2894
2895 /**
2896 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00002897 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002898 *
2899 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08002900 */
2901 public static final String BLUETOOTH_SERVICE = "bluetooth";
2902
2903 /**
2904 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08002905 * {@link android.net.sip.SipManager} for accessing the SIP related service.
2906 *
2907 * @see #getSystemService
2908 */
2909 /** @hide */
2910 public static final String SIP_SERVICE = "sip";
2911
2912 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002913 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08002914 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002915 * and for controlling this device's behavior as a USB device.
2916 *
2917 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04002918 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05002919 */
2920 public static final String USB_SERVICE = "usb";
2921
2922 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002923 * Use with {@link #getSystemService} to retrieve a {@link
2924 * android.hardware.SerialManager} for access to serial ports.
2925 *
2926 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07002927 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04002928 *
2929 * @hide
2930 */
2931 public static final String SERIAL_SERVICE = "serial";
2932
2933 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002934 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09002935 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
2936 * HDMI-CEC protocol.
2937 *
2938 * @see #getSystemService
2939 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002940 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09002941 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09002942 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09002943 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09002944
2945 /**
2946 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07002947 * {@link android.hardware.input.InputManager} for interacting with input devices.
2948 *
2949 * @see #getSystemService
2950 * @see android.hardware.input.InputManager
2951 */
2952 public static final String INPUT_SERVICE = "input";
2953
2954 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07002955 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07002956 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
2957 *
2958 * @see #getSystemService
2959 * @see android.hardware.display.DisplayManager
2960 */
2961 public static final String DISPLAY_SERVICE = "display";
2962
2963 /**
2964 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07002965 * {@link android.os.UserManager} for managing users on devices that support multiple users.
2966 *
2967 * @see #getSystemService
2968 * @see android.os.UserManager
2969 */
2970 public static final String USER_SERVICE = "user";
2971
2972 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002973 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08002974 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
2975 * profiles of a user.
2976 *
2977 * @see #getSystemService
2978 * @see android.content.pm.LauncherApps
2979 */
2980 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
2981
2982 /**
2983 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07002984 * {@link android.content.RestrictionsManager} for retrieving application restrictions
2985 * and requesting permissions for restricted operations.
2986 * @see #getSystemService
2987 * @see android.content.RestrictionsManager
2988 */
2989 public static final String RESTRICTIONS_SERVICE = "restrictions";
2990
2991 /**
2992 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002993 * {@link android.app.AppOpsManager} for tracking application operations
2994 * on the device.
2995 *
2996 * @see #getSystemService
2997 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002998 */
2999 public static final String APP_OPS_SERVICE = "appops";
3000
3001 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003002 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003003 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003004 * camera devices.
3005 *
3006 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003007 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003008 */
3009 public static final String CAMERA_SERVICE = "camera";
3010
3011 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003012 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003013 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003014 *
3015 * @see #getSystemService
3016 * @see android.print.PrintManager
3017 */
3018 public static final String PRINT_SERVICE = "print";
3019
3020 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003021 * Use with {@link #getSystemService} to retrieve a
3022 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3023 * signals from the device.
3024 *
3025 * @see #getSystemService
3026 * @see android.hardware.ConsumerIrManager
3027 */
3028 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3029
3030 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003031 * {@link android.app.trust.TrustManager} for managing trust agents.
3032 * @see #getSystemService
3033 * @see android.app.trust.TrustManager
3034 * @hide
3035 */
3036 public static final String TRUST_SERVICE = "trust";
3037
3038 /**
Jae Seo39570912014-02-20 18:23:25 -08003039 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003040 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3041 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003042 *
3043 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003044 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003045 */
3046 public static final String TV_INPUT_SERVICE = "tv_input";
3047
3048 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003049 * {@link android.net.NetworkScoreManager} for managing network scoring.
3050 * @see #getSystemService
3051 * @see android.net.NetworkScoreManager
3052 * @hide
3053 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003054 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003055 public static final String NETWORK_SCORE_SERVICE = "network_score";
3056
3057 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003058 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003059 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003060 *
3061 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003062 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003063 */
3064 public static final String USAGE_STATS_SERVICE = "usagestats";
3065
3066 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003067 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003068 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003069 * background tasks.
3070 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003071 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003072 */
Christopher Tate7060b042014-06-09 19:50:00 -07003073 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003074
3075 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003076 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003077 * android.service.persistentdata.PersistentDataBlockManager} instance
3078 * for interacting with a storage device that lives across factory resets.
3079 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003080 * @see #getSystemService
3081 * @see android.service.persistentdata.PersistentDataBlockManager
3082 * @hide
3083 */
Andres Morales33df9372014-09-26 17:08:59 -07003084 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003085 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3086
3087 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003088 * Use with {@link #getSystemService} to retrieve a {@link
3089 * android.media.projection.MediaProjectionManager} instance for managing
3090 * media projection sessions.
3091 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003092 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003093 */
3094 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3095
3096 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003097 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003098 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003099 *
3100 * @see #getSystemService
3101 * @hide
3102 */
3103 public static final String MIDI_SERVICE = "midi";
3104
Eric Laurent2035ac82015-03-05 15:18:44 -08003105
3106 /**
3107 * Use with {@link #getSystemService} to retrieve a
3108 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3109 *
3110 * @see #getSystemService
3111 * @hide
3112 */
3113 public static final String RADIO_SERVICE = "radio";
3114
Paul McLeana33be212015-02-20 07:52:45 -08003115 /**
3116 * Use with {@link #getSystemService} to retrieve a
3117 * {@link android.media.AudioDevicesManager} for handling device enumeration & notification.
3118 *
3119 * @see #getSystemService
3120 * @see android.media.AudioDevicesManager
3121 */
3122 public static final String AUDIO_DEVICES_SERVICE = "audio_devices_manager";
3123
Eric Laurent2035ac82015-03-05 15:18:44 -08003124
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003125 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126 * Determine whether the given permission is allowed for a particular
3127 * process and user ID running in the system.
3128 *
3129 * @param permission The name of the permission being checked.
3130 * @param pid The process ID being checked against. Must be > 0.
3131 * @param uid The user ID being checked against. A uid of 0 is the root
3132 * user, which will pass every permission check.
3133 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003134 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 * pid/uid is allowed that permission, or
3136 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3137 *
3138 * @see PackageManager#checkPermission(String, String)
3139 * @see #checkCallingPermission
3140 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003141 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003142 @PackageManager.PermissionResult
3143 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003144
Dianne Hackbornff170242014-11-19 10:59:01 -08003145 /** @hide */
3146 @PackageManager.PermissionResult
3147 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3148 IBinder callerToken);
3149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 /**
3151 * Determine whether the calling process of an IPC you are handling has been
3152 * granted a particular permission. This is basically the same as calling
3153 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3154 * by {@link android.os.Binder#getCallingPid} and
3155 * {@link android.os.Binder#getCallingUid}. One important difference
3156 * is that if you are not currently processing an IPC, this function
3157 * will always fail. This is done to protect against accidentally
3158 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3159 * to avoid this protection.
3160 *
3161 * @param permission The name of the permission being checked.
3162 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003163 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 * pid/uid is allowed that permission, or
3165 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3166 *
3167 * @see PackageManager#checkPermission(String, String)
3168 * @see #checkPermission
3169 * @see #checkCallingOrSelfPermission
3170 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003171 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003172 @PackageManager.PermissionResult
3173 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174
3175 /**
3176 * Determine whether the calling process of an IPC <em>or you</em> have been
3177 * granted a particular permission. This is the same as
3178 * {@link #checkCallingPermission}, except it grants your own permissions
3179 * if you are not currently processing an IPC. Use with care!
3180 *
3181 * @param permission The name of the permission being checked.
3182 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003183 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 * pid/uid is allowed that permission, or
3185 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3186 *
3187 * @see PackageManager#checkPermission(String, String)
3188 * @see #checkPermission
3189 * @see #checkCallingPermission
3190 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003191 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003192 @PackageManager.PermissionResult
3193 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194
3195 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08003196 * Determine whether <em>you</em> have been granted a particular permission.
3197 *
3198 * @param permission The name of the permission being checked.
3199 *
3200 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
3201 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
3202 *
3203 * @see PackageManager#checkPermission(String, String)
3204 * @see #checkCallingPermission(String)
3205 */
3206 @PackageManager.PermissionResult
3207 public abstract int checkSelfPermission(@NonNull String permission);
3208
3209 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003210 * If the given permission is not allowed for a particular process
3211 * and user ID running in the system, throw a {@link SecurityException}.
3212 *
3213 * @param permission The name of the permission being checked.
3214 * @param pid The process ID being checked against. Must be &gt; 0.
3215 * @param uid The user ID being checked against. A uid of 0 is the root
3216 * user, which will pass every permission check.
3217 * @param message A message to include in the exception if it is thrown.
3218 *
3219 * @see #checkPermission(String, int, int)
3220 */
3221 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003222 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223
3224 /**
3225 * If the calling process of an IPC you are handling has not been
3226 * granted a particular permission, throw a {@link
3227 * SecurityException}. This is basically the same as calling
3228 * {@link #enforcePermission(String, int, int, String)} with the
3229 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3230 * and {@link android.os.Binder#getCallingUid}. One important
3231 * difference is that if you are not currently processing an IPC,
3232 * this function will always throw the SecurityException. This is
3233 * done to protect against accidentally leaking permissions; you
3234 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3235 * protection.
3236 *
3237 * @param permission The name of the permission being checked.
3238 * @param message A message to include in the exception if it is thrown.
3239 *
3240 * @see #checkCallingPermission(String)
3241 */
3242 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003243 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003244
3245 /**
3246 * If neither you nor the calling process of an IPC you are
3247 * handling has been granted a particular permission, throw a
3248 * {@link SecurityException}. This is the same as {@link
3249 * #enforceCallingPermission}, except it grants your own
3250 * permissions if you are not currently processing an IPC. Use
3251 * with care!
3252 *
3253 * @param permission The name of the permission being checked.
3254 * @param message A message to include in the exception if it is thrown.
3255 *
3256 * @see #checkCallingOrSelfPermission(String)
3257 */
3258 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003259 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260
3261 /**
3262 * Grant permission to access a specific Uri to another package, regardless
3263 * of whether that package has general permission to access the Uri's
3264 * content provider. This can be used to grant specific, temporary
3265 * permissions, typically in response to user interaction (such as the
3266 * user opening an attachment that you would like someone else to
3267 * display).
3268 *
3269 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3270 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3271 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3272 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3273 * start an activity instead of this function directly. If you use this
3274 * function directly, you should be sure to call
3275 * {@link #revokeUriPermission} when the target should no longer be allowed
3276 * to access it.
3277 *
3278 * <p>To succeed, the content provider owning the Uri must have set the
3279 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3280 * grantUriPermissions} attribute in its manifest or included the
3281 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3282 * &lt;grant-uri-permissions&gt;} tag.
3283 *
3284 * @param toPackage The package you would like to allow to access the Uri.
3285 * @param uri The Uri you would like to grant access to.
3286 * @param modeFlags The desired access modes. Any combination of
3287 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003288 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003290 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3291 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3292 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3293 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3294 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 *
3296 * @see #revokeUriPermission
3297 */
3298 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003299 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300
3301 /**
3302 * Remove all permissions to access a particular content provider Uri
3303 * that were previously added with {@link #grantUriPermission}. The given
3304 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003305 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003307 * "content://foo". It will not remove any prefix grants that exist at a
3308 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003309 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003310 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003311 * regular permission access to a Uri, but had received access to it through
3312 * a specific Uri permission grant, you could not revoke that grant with this
3313 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003314 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003315 * but will remove whatever permission grants to the Uri had been given to the app
3316 * (or none).</p>
3317 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 * @param uri The Uri you would like to revoke access to.
3319 * @param modeFlags The desired access modes. Any combination of
3320 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3321 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3322 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3323 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3324 *
3325 * @see #grantUriPermission
3326 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003327 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328
3329 /**
3330 * Determine whether a particular process and user ID has been granted
3331 * permission to access a specific URI. This only checks for permissions
3332 * that have been explicitly granted -- if the given process/uid has
3333 * more general access to the URI's content provider then this check will
3334 * always fail.
3335 *
3336 * @param uri The uri that is being checked.
3337 * @param pid The process ID being checked against. Must be &gt; 0.
3338 * @param uid The user ID being checked against. A uid of 0 is the root
3339 * user, which will pass every permission check.
3340 * @param modeFlags The type of access to grant. May be one or both of
3341 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3342 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3343 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003344 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 * pid/uid is allowed to access that uri, or
3346 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3347 *
3348 * @see #checkCallingUriPermission
3349 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003350 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003351 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003352 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353
Dianne Hackbornff170242014-11-19 10:59:01 -08003354 /** @hide */
3355 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3356 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3357
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 /**
3359 * Determine whether the calling process and user ID has been
3360 * granted permission to access a specific URI. This is basically
3361 * the same as calling {@link #checkUriPermission(Uri, int, int,
3362 * int)} with the pid and uid returned by {@link
3363 * android.os.Binder#getCallingPid} and {@link
3364 * android.os.Binder#getCallingUid}. One important difference is
3365 * that if you are not currently processing an IPC, this function
3366 * will always fail.
3367 *
3368 * @param uri The uri that is being checked.
3369 * @param modeFlags The type of access to grant. May be one or both of
3370 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3371 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3372 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003373 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 * is allowed to access that uri, or
3375 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3376 *
3377 * @see #checkUriPermission(Uri, int, int, int)
3378 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003379 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003380 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003381
3382 /**
3383 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3384 * permission to access a specific URI. This is the same as
3385 * {@link #checkCallingUriPermission}, except it grants your own permissions
3386 * if you are not currently processing an IPC. Use with care!
3387 *
3388 * @param uri The uri that is being checked.
3389 * @param modeFlags The type of access to grant. May be one or both of
3390 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3391 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3392 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003393 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003394 * is allowed to access that uri, or
3395 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3396 *
3397 * @see #checkCallingUriPermission
3398 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003399 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003400 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003401 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402
3403 /**
3404 * Check both a Uri and normal permission. This allows you to perform
3405 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3406 * call.
3407 *
3408 * @param uri The Uri whose permission is to be checked, or null to not
3409 * do this check.
3410 * @param readPermission The permission that provides overall read access,
3411 * or null to not do this check.
3412 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003413 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003414 * @param pid The process ID being checked against. Must be &gt; 0.
3415 * @param uid The user ID being checked against. A uid of 0 is the root
3416 * user, which will pass every permission check.
3417 * @param modeFlags The type of access to grant. May be one or both of
3418 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3419 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3420 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003421 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 * is allowed to access that uri or holds one of the given permissions, or
3423 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3424 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003425 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003426 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3427 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003428 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429
3430 /**
3431 * If a particular process and user ID has not been granted
3432 * permission to access a specific URI, throw {@link
3433 * SecurityException}. This only checks for permissions that have
3434 * been explicitly granted -- if the given process/uid has more
3435 * general access to the URI's content provider then this check
3436 * will always fail.
3437 *
3438 * @param uri The uri that is being checked.
3439 * @param pid The process ID being checked against. Must be &gt; 0.
3440 * @param uid The user ID being checked against. A uid of 0 is the root
3441 * user, which will pass every permission check.
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 #checkUriPermission(Uri, int, int, int)
3448 */
3449 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003450 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451
3452 /**
3453 * If the calling process and user ID has not been granted
3454 * permission to access a specific URI, throw {@link
3455 * SecurityException}. This is basically the same as calling
3456 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3457 * the pid and uid returned by {@link
3458 * android.os.Binder#getCallingPid} and {@link
3459 * android.os.Binder#getCallingUid}. One important difference is
3460 * that if you are not currently processing an IPC, this function
3461 * will always throw a SecurityException.
3462 *
3463 * @param uri The uri that is being checked.
3464 * @param modeFlags The type of access to grant. May be one or both of
3465 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3466 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3467 * @param message A message to include in the exception if it is thrown.
3468 *
3469 * @see #checkCallingUriPermission(Uri, int)
3470 */
3471 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003472 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473
3474 /**
3475 * If the calling process of an IPC <em>or you</em> has not been
3476 * granted permission to access a specific URI, throw {@link
3477 * SecurityException}. This is the same as {@link
3478 * #enforceCallingUriPermission}, except it grants your own
3479 * permissions if you are not currently processing an IPC. Use
3480 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003481 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003482 * @param uri The uri that is being checked.
3483 * @param modeFlags The type of access to grant. May be one or both of
3484 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3485 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3486 * @param message A message to include in the exception if it is thrown.
3487 *
3488 * @see #checkCallingOrSelfUriPermission(Uri, int)
3489 */
3490 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003491 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492
3493 /**
3494 * Enforce both a Uri and normal permission. This allows you to perform
3495 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3496 * call.
Scott Main4b5da682010-10-21 11:49:12 -07003497 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 * @param uri The Uri whose permission is to be checked, or null to not
3499 * do this check.
3500 * @param readPermission The permission that provides overall read access,
3501 * or null to not do this check.
3502 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003503 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003504 * @param pid The process ID being checked against. Must be &gt; 0.
3505 * @param uid The user ID being checked against. A uid of 0 is the root
3506 * user, which will pass every permission check.
3507 * @param modeFlags The type of access to grant. May be one or both of
3508 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3509 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3510 * @param message A message to include in the exception if it is thrown.
3511 *
3512 * @see #checkUriPermission(Uri, String, String, int, int, int)
3513 */
3514 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003515 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003516 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07003517 @Nullable String message);
3518
3519 /** @hide */
3520 @IntDef(flag = true,
3521 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3522 @Retention(RetentionPolicy.SOURCE)
3523 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524
3525 /**
3526 * Flag for use with {@link #createPackageContext}: include the application
3527 * code with the context. This means loading code into the caller's
3528 * process, so that {@link #getClassLoader()} can be used to instantiate
3529 * the application's classes. Setting this flags imposes security
3530 * restrictions on what application context you can access; if the
3531 * requested application can not be safely loaded into your process,
3532 * java.lang.SecurityException will be thrown. If this flag is not set,
3533 * there will be no restrictions on the packages that can be loaded,
3534 * but {@link #getClassLoader} will always return the default system
3535 * class loader.
3536 */
3537 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3538
3539 /**
3540 * Flag for use with {@link #createPackageContext}: ignore any security
3541 * restrictions on the Context being requested, allowing it to always
3542 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3543 * to be loaded into a process even when it isn't safe to do so. Use
3544 * with extreme care!
3545 */
3546 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07003547
Romain Guy870e09f2009-07-06 16:35:25 -07003548 /**
3549 * Flag for use with {@link #createPackageContext}: a restricted context may
3550 * disable specific features. For instance, a View associated with a restricted
3551 * context would ignore particular XML attributes.
3552 */
3553 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554
3555 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003556 * @hide Used to indicate we should tell the activity manager about the process
3557 * loading this code.
3558 */
3559 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
3560
3561 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003562 * Return a new Context object for the given application name. This
3563 * Context is the same as what the named application gets when it is
3564 * launched, containing the same resources and class loader. Each call to
3565 * this method returns a new instance of a Context object; Context objects
3566 * are not shared, however they share common state (Resources, ClassLoader,
3567 * etc) so the Context instance itself is fairly lightweight.
3568 *
Jeff Brown6e539312015-02-24 18:53:21 -08003569 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 * application with the given package name.
3571 *
3572 * <p>Throws {@link java.lang.SecurityException} if the Context requested
3573 * can not be loaded into the caller's process for security reasons (see
3574 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
3575 *
3576 * @param packageName Name of the application's package.
3577 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
3578 * or {@link #CONTEXT_IGNORE_SECURITY}.
3579 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003580 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003582 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003583 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04003584 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 */
3586 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07003587 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07003588
3589 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07003590 * Similar to {@link #createPackageContext(String, int)}, but with a
3591 * different {@link UserHandle}. For example, {@link #getContentResolver()}
3592 * will open any {@link Uri} as the given user.
3593 *
3594 * @hide
3595 */
3596 public abstract Context createPackageContextAsUser(
3597 String packageName, int flags, UserHandle user)
3598 throws PackageManager.NameNotFoundException;
3599
3600 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07003601 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
3602 *
3603 * @hide
3604 */
3605 public abstract Context createApplicationContext(ApplicationInfo application,
3606 int flags) throws PackageManager.NameNotFoundException;
3607
3608 /**
Jim Millera75a8832013-02-07 16:53:32 -08003609 * Get the userId associated with this context
3610 * @return user id
3611 *
3612 * @hide
3613 */
3614 public abstract int getUserId();
3615
3616 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07003617 * Return a new Context object for the current Context but whose resources
3618 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07003619 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07003620 * shared, however common state (ClassLoader, other Resources for the
3621 * same configuration) may be so the Context itself can be fairly lightweight.
3622 *
3623 * @param overrideConfiguration A {@link Configuration} specifying what
3624 * values to modify in the base Configuration of the original Context's
3625 * resources. If the base configuration changes (such as due to an
3626 * orientation change), the resources of this context will also change except
3627 * for those that have been explicitly overridden with a value here.
3628 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003629 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07003630 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003631 public abstract Context createConfigurationContext(
3632 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07003633
3634 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07003635 * Return a new Context object for the current Context but whose resources
3636 * are adjusted to match the metrics of the given Display. Each call to this method
3637 * returns a new instance of a Context object; Context objects are not
3638 * shared, however common state (ClassLoader, other Resources for the
3639 * same configuration) may be so the Context itself can be fairly lightweight.
3640 *
3641 * The returned display Context provides a {@link WindowManager}
3642 * (see {@link #getSystemService(String)}) that is configured to show windows
3643 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
3644 * method can be used to retrieve the Display from the returned Context.
3645 *
3646 * @param display A {@link Display} object specifying the display
3647 * for whose metrics the Context's resources should be tailored and upon which
3648 * new windows should be shown.
3649 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003650 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07003651 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003652 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07003653
3654 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07003655 * Gets the display adjustments holder for this context. This information
3656 * is provided on a per-application or activity basis and is used to simulate lower density
3657 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07003658 *
Jeff Browna492c3a2012-08-23 19:48:44 -07003659 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07003660 * @return The compatibility info holder, or null if not required by the application.
3661 * @hide
3662 */
Craig Mautner48d0d182013-06-11 07:53:06 -07003663 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07003664
3665 /**
Romain Guy870e09f2009-07-06 16:35:25 -07003666 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07003667 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003668 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07003669 *
Romain Guy870e09f2009-07-06 16:35:25 -07003670 * @see #CONTEXT_RESTRICTED
3671 */
3672 public boolean isRestricted() {
3673 return false;
3674 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003675}