blob: da64c3a0571496b9aed29bf33c2d27ff505b44ac [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Tor Norbyec91531a2015-04-01 17:41:55 -070019import android.annotation.AttrRes;
Tor Norbye1c2bf032015-03-02 10:57:08 -080020import android.annotation.CheckResult;
Tor Norbye3e4cda72015-06-10 08:14:31 -070021import android.annotation.ColorInt;
22import android.annotation.ColorRes;
23import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070024import android.annotation.IntDef;
25import android.annotation.NonNull;
26import android.annotation.Nullable;
Tor Norbye788fc2b2015-07-05 16:10:42 -070027import android.annotation.RequiresPermission;
Tor Norbyed9273d62013-05-30 15:59:53 -070028import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070029import android.annotation.StringRes;
30import android.annotation.StyleRes;
31import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090032import android.annotation.SystemApi;
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -070033import android.annotation.TestApi;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070034import android.annotation.UserIdInt;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070035import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.content.pm.PackageManager;
37import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080038import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070039import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.content.res.Resources;
41import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070042import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.database.sqlite.SQLiteDatabase;
44import android.database.sqlite.SQLiteDatabase.CursorFactory;
45import android.graphics.Bitmap;
46import android.graphics.drawable.Drawable;
47import android.net.Uri;
48import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070049import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.os.Handler;
Dianne Hackbornff170242014-11-19 10:59:01 -080051import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070053import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070054import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070055import android.os.UserManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070056import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070058import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070059import android.view.DisplayAdjustments;
Jon Miranda836c0a82014-08-11 12:32:26 -070060import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070061import android.view.WindowManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062
63import java.io.File;
64import java.io.FileInputStream;
65import java.io.FileNotFoundException;
66import java.io.FileOutputStream;
67import java.io.IOException;
68import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070069import java.lang.annotation.Retention;
70import java.lang.annotation.RetentionPolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
72/**
73 * Interface to global information about an application environment. This is
74 * an abstract class whose implementation is provided by
75 * the Android system. It
76 * allows access to application-specific resources and classes, as well as
77 * up-calls for application-level operations such as launching activities,
78 * broadcasting and receiving intents, etc.
79 */
80public abstract class Context {
81 /**
82 * File creation mode: the default mode, where the created file can only
83 * be accessed by the calling application (or all applications sharing the
84 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 */
86 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -070087
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -070089 * File creation mode: allow all other applications to have read access to
90 * the created file.
91 * <p>
92 * As of {@link android.os.Build.VERSION_CODES#N} attempting to use this
93 * mode will throw a {@link SecurityException}.
94 *
Nick Kralevich15069212013-01-09 15:54:56 -080095 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -070096 * to cause security holes in applications. It is strongly
97 * discouraged; instead, applications should use more formal
98 * mechanism for interactions such as {@link ContentProvider},
99 * {@link BroadcastReceiver}, and {@link android.app.Service}.
100 * There are no guarantees that this access mode will remain on
101 * a file, such as when it goes through a backup and restore.
102 * @see android.support.v4.content.FileProvider
103 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700105 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700109 * File creation mode: allow all other applications to have write access to
110 * the created file.
111 * <p>
112 * As of {@link android.os.Build.VERSION_CODES#N} attempting to use this
113 * mode will throw a {@link SecurityException}.
114 *
Nick Kralevich15069212013-01-09 15:54:56 -0800115 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700116 * to cause security holes in applications. It is strongly
117 * discouraged; instead, applications should use more formal
118 * mechanism for interactions such as {@link ContentProvider},
119 * {@link BroadcastReceiver}, and {@link android.app.Service}.
120 * There are no guarantees that this access mode will remain on
121 * a file, such as when it goes through a backup and restore.
122 * @see android.support.v4.content.FileProvider
123 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700125 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 /**
129 * File creation mode: for use with {@link #openFileOutput}, if the file
130 * already exists then write data to the end of the existing file
131 * instead of erasing it.
132 * @see #openFileOutput
133 */
134 public static final int MODE_APPEND = 0x8000;
135
136 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800137 * SharedPreference loading flag: when set, the file on disk will
138 * be checked for modification even if the shared preferences
139 * instance is already loaded in this process. This behavior is
140 * sometimes desired in cases where the application has multiple
141 * processes, all writing to the same SharedPreferences file.
142 * Generally there are better forms of communication between
143 * processes, though.
144 *
145 * <p>This was the legacy (but undocumented) behavior in and
146 * before Gingerbread (Android 2.3) and this flag is implied when
147 * targetting such releases. For applications targetting SDK
148 * versions <em>greater than</em> Android 2.3, this flag must be
149 * explicitly set if desired.
150 *
151 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700152 *
153 * @deprecated MODE_MULTI_PROCESS does not work reliably in
154 * some versions of Android, and furthermore does not provide any
155 * mechanism for reconciling concurrent modifications across
156 * processes. Applications should not attempt to use it. Instead,
157 * they should use an explicit cross-process data management
158 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800159 */
Christopher Tated5748b82015-05-08 18:14:01 -0700160 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800161 public static final int MODE_MULTI_PROCESS = 0x0004;
162
163 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700164 * Database open flag: when set, the database is opened with write-ahead
165 * logging enabled by default.
166 *
167 * @see #openOrCreateDatabase(String, int, CursorFactory)
168 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
169 * @see SQLiteDatabase#enableWriteAheadLogging
170 */
171 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
172
Sunny Goyala21e6b22015-12-02 09:51:02 -0800173 /**
174 * Database open flag: when set, the database is opened without support for
175 * localized collators.
176 *
177 * @see #openOrCreateDatabase(String, int, CursorFactory)
178 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
179 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
180 */
181 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
182
Tor Norbyed9273d62013-05-30 15:59:53 -0700183 /** @hide */
184 @IntDef(flag = true,
185 value = {
186 BIND_AUTO_CREATE,
Tor Norbyed9273d62013-05-30 15:59:53 -0700187 BIND_DEBUG_UNBIND,
188 BIND_NOT_FOREGROUND,
189 BIND_ABOVE_CLIENT,
190 BIND_ALLOW_OOM_MANAGEMENT,
Tor Norbyece1c67c2014-12-02 13:59:17 -0800191 BIND_WAIVE_PRIORITY,
192 BIND_IMPORTANT,
193 BIND_ADJUST_WITH_ACTIVITY
Tor Norbyed9273d62013-05-30 15:59:53 -0700194 })
195 @Retention(RetentionPolicy.SOURCE)
196 public @interface BindServiceFlags {}
197
Jeff Brown47847f32012-03-22 19:13:11 -0700198 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 * Flag for {@link #bindService}: automatically create the service as long
200 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700201 * its {@link android.app.Service#onStartCommand}
202 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 * explicit call to {@link #startService}. Even without that, though,
204 * this still provides you with access to the service object while the
205 * service is created.
206 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700207 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
208 * not supplying this flag would also impact how important the system
209 * consider's the target service's process to be. When set, the only way
210 * for it to be raised was by binding from a service in which case it will
211 * only be important when that activity is in the foreground. Now to
212 * achieve this behavior you must explicitly supply the new flag
213 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
214 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
215 * the flags {@link #BIND_WAIVE_PRIORITY} and
216 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
217 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 */
219 public static final int BIND_AUTO_CREATE = 0x0001;
220
221 /**
222 * Flag for {@link #bindService}: include debugging help for mismatched
223 * calls to unbind. When this flag is set, the callstack of the following
224 * {@link #unbindService} call is retained, to be printed if a later
225 * incorrect unbind call is made. Note that doing this requires retaining
226 * information about the binding that was made for the lifetime of the app,
227 * resulting in a leak -- this should only be used for debugging.
228 */
229 public static final int BIND_DEBUG_UNBIND = 0x0002;
230
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800231 /**
232 * Flag for {@link #bindService}: don't allow this binding to raise
233 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700234 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800235 * as the client (so that its process will not be killable in any
236 * situation where the client is not killable), but for CPU scheduling
237 * purposes it may be left in the background. This only has an impact
238 * in the situation where the binding client is a foreground process
239 * and the target service is in a background process.
240 */
241 public static final int BIND_NOT_FOREGROUND = 0x0004;
242
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700243 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700244 * Flag for {@link #bindService}: indicates that the client application
245 * binding to this service considers the service to be more important than
246 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700247 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700248 * this is not guaranteed to be the case.
249 */
250 public static final int BIND_ABOVE_CLIENT = 0x0008;
251
252 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700253 * Flag for {@link #bindService}: allow the process hosting the bound
254 * service to go through its normal memory management. It will be
255 * treated more like a running service, allowing the system to
256 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700257 * whim it may have, and being more aggressive about making it a candidate
258 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700259 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700260 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
261
262 /**
263 * Flag for {@link #bindService}: don't impact the scheduling or
264 * memory management priority of the target service's hosting process.
265 * Allows the service's process to be managed on the background LRU list
266 * just like a regular application process in the background.
267 */
268 public static final int BIND_WAIVE_PRIORITY = 0x0020;
269
270 /**
271 * Flag for {@link #bindService}: this service is very important to
272 * the client, so should be brought to the foreground process level
273 * when the client is. Normally a process can only be raised to the
274 * visibility level by a client, even if that client is in the foreground.
275 */
276 public static final int BIND_IMPORTANT = 0x0040;
277
278 /**
279 * Flag for {@link #bindService}: If binding from an activity, allow the
280 * target service's process importance to be raised based on whether the
281 * activity is visible to the user, regardless whether another flag is
282 * used to reduce the amount that the client process's overall importance
283 * is used to impact it.
284 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700285 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
286
287 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700288 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
289 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
290 */
291 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
292
293 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700294 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
295 * but only applies while the device is awake.
296 */
297 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
298
299 /**
300 * @hide Flag for {@link #bindService}: For only the case where the binding
301 * is coming from the system, set the process state to FOREGROUND_SERVICE
302 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
303 * saying that the process shouldn't participate in the normal power reduction
304 * modes (removing network access etc).
305 */
306 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
307
308 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700309 * @hide Flag for {@link #bindService}: Treat the binding as hosting
310 * an activity, an unbinding as the activity going in the background.
311 * That is, when unbinding, the process when empty will go on the activity
312 * LRU list instead of the regular one, keeping it around more aggressively
313 * than it otherwise would be. This is intended for use with IMEs to try
314 * to keep IME processes around for faster keyboard switching.
315 */
316 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
317
318 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700319 * @hide An idea that is not yet implemented.
320 * Flag for {@link #bindService}: If binding from an activity, consider
321 * this service to be visible like the binding activity is. That is,
322 * it will be treated as something more important to keep around than
323 * invisible background activities. This will impact the number of
324 * recent activities the user can switch between without having them
325 * restart. There is no guarantee this will be respected, as the system
326 * tries to balance such requests from one app vs. the importantance of
327 * keeping other apps around.
328 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700329 public static final int BIND_VISIBLE = 0x10000000;
330
331 /**
332 * @hide
333 * Flag for {@link #bindService}: Consider this binding to be causing the target
334 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
335 * away.
336 */
337 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700338
339 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700340 * Flag for {@link #bindService}: Don't consider the bound service to be
341 * visible, even if the caller is visible.
342 * @hide
343 */
344 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700345
Alan Viverette713a5cd2015-12-16 15:46:32 -0500346 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500347 * Flag for {@link #bindService}: The service being bound is an
348 * {@link android.R.attr#isolatedProcess isolated},
349 * {@link android.R.attr#externalService external} service. This binds the service into the
350 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400351 * <p>
352 * When using this flag, the code for the service being bound will execute under the calling
353 * application's package name and user ID. Because the service must be an isolated process,
354 * it will not have direct access to the application's data, though.
355 *
356 * The purpose of this flag is to allow applications to provide services that are attributed
357 * to the app using the service, rather than the application providing the service.
358 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500359 */
360 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
361
362 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500363 * Returns an AssetManager instance for the application's package.
364 * <p>
365 * <strong>Note:</strong> Implementations of this method should return
366 * an AssetManager instance that is consistent with the Resources instance
367 * returned by {@link #getResources()}. For example, they should share the
368 * same {@link Configuration} object.
369 *
370 * @return an AssetManager instance for the application's package
371 * @see #getResources()
372 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 public abstract AssetManager getAssets();
374
Alan Viverette713a5cd2015-12-16 15:46:32 -0500375 /**
376 * Returns a Resources instance for the application's package.
377 * <p>
378 * <strong>Note:</strong> Implementations of this method should return
379 * a Resources instance that is consistent with the AssetManager instance
380 * returned by {@link #getAssets()}. For example, they should share the
381 * same {@link Configuration} object.
382 *
383 * @return a Resources instance for the application's package
384 * @see #getAssets()
385 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800386 public abstract Resources getResources();
387
388 /** Return PackageManager instance to find global package information. */
389 public abstract PackageManager getPackageManager();
390
391 /** Return a ContentResolver instance for your application's package. */
392 public abstract ContentResolver getContentResolver();
393
394 /**
395 * Return the Looper for the main thread of the current process. This is
396 * the thread used to dispatch calls to application components (activities,
397 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700398 * <p>
399 * By definition, this method returns the same result as would be obtained
400 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
401 * </p>
402 *
403 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 */
405 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800407 /**
408 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800409 * current process. This generally should only be used if you need a
410 * Context whose lifecycle is separate from the current context, that is
411 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700412 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800413 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800414 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800415 * <ul>
416 * <li> <p>If used from an Activity context, the receiver is being registered
417 * within that activity. This means that you are expected to unregister
418 * before the activity is done being destroyed; in fact if you do not do
419 * so, the framework will clean up your leaked registration as it removes
420 * the activity and log an error. Thus, if you use the Activity context
421 * to register a receiver that is static (global to the process, not
422 * associated with an Activity instance) then that registration will be
423 * removed on you at whatever point the activity you used is destroyed.
424 * <li> <p>If used from the Context returned here, the receiver is being
425 * registered with the global state associated with your application. Thus
426 * it will never be unregistered for you. This is necessary if the receiver
427 * is associated with static data, not a particular component. However
428 * using the ApplicationContext elsewhere can easily lead to serious leaks
429 * if you forget to unregister, unbind, etc.
430 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 */
432 public abstract Context getApplicationContext();
433
434 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700435 * Add a new {@link ComponentCallbacks} to the base application of the
436 * Context, which will be called at the same times as the ComponentCallbacks
437 * methods of activities and other components are called. Note that you
438 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
439 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700440 *
441 * @param callback The interface to call. This can be either a
442 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700443 */
444 public void registerComponentCallbacks(ComponentCallbacks callback) {
445 getApplicationContext().registerComponentCallbacks(callback);
446 }
447
448 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400449 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700450 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
451 */
452 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
453 getApplicationContext().unregisterComponentCallbacks(callback);
454 }
455
456 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 * Return a localized, styled CharSequence from the application's package's
458 * default string table.
459 *
460 * @param resId Resource id for the CharSequence text
461 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700462 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 return getResources().getText(resId);
464 }
465
466 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700467 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800468 * default string table.
469 *
470 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700471 * @return The string data associated with the resource, stripped of styled
472 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700474 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700475 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 return getResources().getString(resId);
477 }
478
479 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700480 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800481 * default string table, substituting the format arguments as defined in
482 * {@link java.util.Formatter} and {@link java.lang.String#format}.
483 *
484 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700485 * @param formatArgs The format arguments that will be used for
486 * substitution.
487 * @return The string data associated with the resource, formatted and
488 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800489 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700490 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700491 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 return getResources().getString(resId, formatArgs);
493 }
494
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800495 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800496 * Returns a color associated with a particular resource ID and styled for
497 * the current theme.
498 *
499 * @param id The desired resource identifier, as generated by the aapt
500 * tool. This integer encodes the package, type, and resource
501 * entry. The value 0 is an invalid identifier.
502 * @return A single color value in the form 0xAARRGGBB.
503 * @throws android.content.res.Resources.NotFoundException if the given ID
504 * does not exist.
505 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700506 @ColorInt
507 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800508 return getResources().getColor(id, getTheme());
509 }
510
511 /**
512 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800513 * styled for the current theme.
514 *
515 * @param id The desired resource identifier, as generated by the aapt
516 * tool. This integer encodes the package, type, and resource
517 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800518 * @return An object that can be used to draw this resource, or
519 * {@code null} if the resource could not be resolved.
520 * @throws android.content.res.Resources.NotFoundException if the given ID
521 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800522 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800523 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700524 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800525 return getResources().getDrawable(id, getTheme());
526 }
527
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800528 /**
529 * Returns a color state list associated with a particular resource ID and
530 * styled for the current theme.
531 *
532 * @param id The desired resource identifier, as generated by the aapt
533 * tool. This integer encodes the package, type, and resource
534 * entry. The value 0 is an invalid identifier.
535 * @return A color state list, or {@code null} if the resource could not be
536 * resolved.
537 * @throws android.content.res.Resources.NotFoundException if the given ID
538 * does not exist.
539 */
540 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700541 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800542 return getResources().getColorStateList(id, getTheme());
543 }
544
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545 /**
546 * Set the base theme for this context. Note that this should be called
547 * before any views are instantiated in the Context (for example before
548 * calling {@link android.app.Activity#setContentView} or
549 * {@link android.view.LayoutInflater#inflate}).
550 *
551 * @param resid The style resource describing the theme.
552 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700553 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554
Dianne Hackborn247fe742011-01-08 17:25:57 -0800555 /** @hide Needed for some internal implementation... not public because
556 * you can't assume this actually means anything. */
557 public int getThemeResId() {
558 return 0;
559 }
560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 /**
562 * Return the Theme object associated with this Context.
563 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700564 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 public abstract Resources.Theme getTheme();
566
567 /**
568 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800569 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 * for more information.
571 *
Jeff Brown6e539312015-02-24 18:53:21 -0800572 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700574 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 return getTheme().obtainStyledAttributes(attrs);
576 }
577
578 /**
579 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800580 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 * for more information.
582 *
Jeff Brown6e539312015-02-24 18:53:21 -0800583 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 */
585 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700586 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 return getTheme().obtainStyledAttributes(resid, attrs);
588 }
589
590 /**
591 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800592 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 * for more information.
594 *
Jeff Brown6e539312015-02-24 18:53:21 -0800595 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 */
597 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700598 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
600 }
601
602 /**
603 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800604 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 * for more information.
606 *
Jeff Brown6e539312015-02-24 18:53:21 -0800607 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 */
609 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700610 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
611 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612 return getTheme().obtainStyledAttributes(
613 set, attrs, defStyleAttr, defStyleRes);
614 }
615
616 /**
617 * Return a class loader you can use to retrieve classes in this package.
618 */
619 public abstract ClassLoader getClassLoader();
620
621 /** Return the name of this application's package. */
622 public abstract String getPackageName();
623
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800624 /** @hide Return the name of the base context this context is derived from. */
625 public abstract String getBasePackageName();
626
Dianne Hackborn95d78532013-09-11 09:51:14 -0700627 /** @hide Return the package name that should be used for app ops calls from
628 * this context. This is the same as {@link #getBasePackageName()} except in
629 * cases where system components are loaded into other app processes, in which
630 * case this will be the name of the primary package in that process (so that app
631 * ops uid verification will work with the name). */
632 public abstract String getOpPackageName();
633
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700634 /** Return the full application info for this context's package. */
635 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700636
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800637 /**
Kenny Root32148392010-01-21 15:40:47 -0800638 * Return the full path to this context's primary Android package.
639 * The Android package is a ZIP file which contains the application's
640 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 *
642 * <p>Note: this is not generally useful for applications, since they should
643 * not be directly accessing the file system.
644 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 * @return String Path to the resources.
646 */
647 public abstract String getPackageResourcePath();
648
649 /**
Kenny Root32148392010-01-21 15:40:47 -0800650 * Return the full path to this context's primary Android package.
651 * The Android package is a ZIP file which contains application's
652 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 *
654 * <p>Note: this is not generally useful for applications, since they should
655 * not be directly accessing the file system.
656 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 * @return String Path to the code and assets.
658 */
659 public abstract String getPackageCodePath();
660
661 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700662 * @hide
663 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700664 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700665 @Deprecated
666 public File getSharedPrefsFile(String name) {
667 return getSharedPreferencesPath(name);
668 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700669
670 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671 * Retrieve and hold the contents of the preferences file 'name', returning
672 * a SharedPreferences through which you can retrieve and modify its
673 * values. Only one instance of the SharedPreferences object is returned
674 * to any callers for the same name, meaning they will see each other's
675 * edits as soon as they are made.
676 *
677 * @param name Desired preferences file. If a preferences file by this name
678 * does not exist, it will be created when you retrieve an
679 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
680 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700681 * default operation.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400683 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 * to retrieve and modify the preference values.
685 *
686 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 */
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700688 public abstract SharedPreferences getSharedPreferences(String name, int mode);
689
690 /**
691 * Retrieve and hold the contents of the preferences file, returning
692 * a SharedPreferences through which you can retrieve and modify its
693 * values. Only one instance of the SharedPreferences object is returned
694 * to any callers for the same name, meaning they will see each other's
695 * edits as soon as they are made.
696 *
697 * @param file Desired preferences file. If a preferences file by this name
698 * does not exist, it will be created when you retrieve an
699 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
700 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700701 * default operation.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700702 *
703 * @return The single {@link SharedPreferences} instance that can be used
704 * to retrieve and modify the preference values.
705 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700706 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700707 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600708 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700709 */
710 public abstract SharedPreferences getSharedPreferences(File file, int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711
712 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600713 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700714 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600715 * storage locations after an upgrade, such as moving to device protected
716 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700717 *
718 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600719 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700720 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600721 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700722 * preferences didn't exist in the source context, otherwise
723 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600724 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700725 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600726 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
727
728 /** @removed */
729 @Deprecated
730 public boolean migrateSharedPreferencesFrom(Context sourceContext, String name) {
731 return moveSharedPreferencesFrom(sourceContext, name);
732 }
Jeff Sharkey35871f22016-01-29 17:13:29 -0700733
734 /**
735 * Delete an existing shared preferences file.
736 *
737 * @param name The name (unique in the application package) of the shared
738 * preferences file.
739 * @return {@code true} if the shared preferences file was successfully
740 * deleted; else {@code false}.
741 * @see #getSharedPreferences(String, int)
742 */
743 public abstract boolean deleteSharedPreferences(String name);
744
745 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800746 * Open a private file associated with this Context's application package
747 * for reading.
748 *
749 * @param name The name of the file to open; can not contain path
750 * separators.
751 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400752 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 *
754 * @see #openFileOutput
755 * @see #fileList
756 * @see #deleteFile
757 * @see java.io.FileInputStream#FileInputStream(String)
758 */
759 public abstract FileInputStream openFileInput(String name)
760 throws FileNotFoundException;
761
762 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800763 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700764 * for writing. Creates the file if it doesn't already exist.
765 * <p>
766 * No additional permissions are required for the calling app to read or
767 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700768 *
Nick Kralevich15069212013-01-09 15:54:56 -0800769 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700770 * separators.
771 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700772 * default operation. Use {@link #MODE_APPEND} to append to an
773 * existing file.
John Spurlock6098c5d2013-06-17 10:32:46 -0400774 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 * @see #MODE_APPEND
776 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 * @see #openFileInput
778 * @see #fileList
779 * @see #deleteFile
780 * @see java.io.FileOutputStream#FileOutputStream(String)
781 */
782 public abstract FileOutputStream openFileOutput(String name, int mode)
783 throws FileNotFoundException;
784
785 /**
786 * Delete the given private file associated with this Context's
787 * application package.
788 *
789 * @param name The name of the file to delete; can not contain path
790 * separators.
791 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400792 * @return {@code true} if the file was successfully deleted; else
793 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 *
795 * @see #openFileInput
796 * @see #openFileOutput
797 * @see #fileList
798 * @see java.io.File#delete()
799 */
800 public abstract boolean deleteFile(String name);
801
802 /**
803 * Returns the absolute path on the filesystem where a file created with
804 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700805 * <p>
806 * The returned path may change over time if the calling app is moved to an
807 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 *
809 * @param name The name of the file for which you would like to get
810 * its path.
811 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400812 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813 *
814 * @see #openFileOutput
815 * @see #getFilesDir
816 * @see #getDir
817 */
818 public abstract File getFileStreamPath(String name);
819
820 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700821 * Returns the absolute path on the filesystem where a file created with
822 * {@link #getSharedPreferences(String, int)} is stored.
823 * <p>
824 * The returned path may change over time if the calling app is moved to an
825 * adopted storage device, so only relative paths should be persisted.
826 *
827 * @param name The name of the shared preferences for which you would like
828 * to get a path.
829 * @return An absolute path to the given file.
830 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600831 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700832 */
833 public abstract File getSharedPreferencesPath(String name);
834
835 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700836 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600837 * private files belonging to this app are stored. Apps should not use this
838 * path directly; they should instead use {@link #getFilesDir()},
839 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
840 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700841 * <p>
842 * The returned path may change over time if the calling app is moved to an
843 * adopted storage device, so only relative paths should be persisted.
844 * <p>
845 * No additional permissions are required for the calling app to read or
846 * write files under the returned path.
847 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600848 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700849 */
850 public abstract File getDataDir();
851
852 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700853 * Returns the absolute path to the directory on the filesystem where files
854 * created with {@link #openFileOutput} are stored.
855 * <p>
856 * The returned path may change over time if the calling app is moved to an
857 * adopted storage device, so only relative paths should be persisted.
858 * <p>
859 * No additional permissions are required for the calling app to read or
860 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700861 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400862 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 * @see #openFileOutput
864 * @see #getFileStreamPath
865 * @see #getDir
866 */
867 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700868
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700870 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700871 * {@link #getFilesDir()}. The difference is that files placed under this
872 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700873 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
874 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700875 * <p>
876 * The returned path may change over time if the calling app is moved to an
877 * adopted storage device, so only relative paths should be persisted.
878 * <p>
879 * No additional permissions are required for the calling app to read or
880 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700881 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700882 * @return The path of the directory holding application files that will not
883 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700884 * @see #openFileOutput
885 * @see #getFileStreamPath
886 * @see #getDir
887 * @see android.app.backup.BackupAgent
888 */
889 public abstract File getNoBackupFilesDir();
890
891 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700892 * Returns the absolute path to the directory on the primary shared/external
893 * storage device where the application can place persistent files it owns.
894 * These files are internal to the applications, and not typically visible
895 * to the user as media.
896 * <p>
897 * This is like {@link #getFilesDir()} in that these files will be deleted
898 * when the application is uninstalled, however there are some important
899 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800900 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700901 * <li>Shared storage may not always be available, since removable media can
902 * be ejected by the user. Media state can be checked using
903 * {@link Environment#getExternalStorageState(File)}.
904 * <li>There is no security enforced with these files. For example, any
905 * application holding
906 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700907 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800908 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700909 * <p>
910 * If a shared storage device is emulated (as determined by
911 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
912 * backed by a private user data partition, which means there is little
913 * benefit to storing data here instead of the private directories returned
914 * by {@link #getFilesDir()}, etc.
915 * <p>
916 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700917 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700918 * accessible to the calling app. This only applies to paths generated for
919 * package name of the calling application. To access paths belonging to
920 * other packages,
921 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
922 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
923 * <p>
924 * On devices with multiple users (as described by {@link UserManager}),
925 * each user has their own isolated shared storage. Applications only have
926 * access to the shared storage for the user they're running as.
927 * <p>
928 * The returned path may change over time if different shared storage media
929 * is inserted, so only relative paths should be persisted.
930 * <p>
931 * Here is an example of typical code to manipulate a file in an
932 * application's shared storage:
933 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800934 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
935 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700936 * <p>
937 * If you supply a non-null <var>type</var> to this function, the returned
938 * file will be a path to a sub-directory of the given type. Though these
939 * files are not automatically scanned by the media scanner, you can
940 * explicitly add them to the media database with
941 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
942 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800943 * {@link android.os.Environment#getExternalStoragePublicDirectory
944 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700945 * directories of media shared by all applications. The directories returned
946 * here are owned by the application, and their contents will be removed
947 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800948 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700949 * Environment.getExternalStoragePublicDirectory()}, the directory returned
950 * here will be automatically created for you.
951 * <p>
952 * Here is an example of typical code to manipulate a picture in an
953 * application's shared storage and add it to the media database:
954 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800955 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
956 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700957 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700958 * @param type The type of files directory to return. May be {@code null}
959 * for the root of the files directory or one of the following
960 * constants for a subdirectory:
961 * {@link android.os.Environment#DIRECTORY_MUSIC},
962 * {@link android.os.Environment#DIRECTORY_PODCASTS},
963 * {@link android.os.Environment#DIRECTORY_RINGTONES},
964 * {@link android.os.Environment#DIRECTORY_ALARMS},
965 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
966 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
967 * {@link android.os.Environment#DIRECTORY_MOVIES}.
968 * @return the absolute path to application-specific directory. May return
969 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800970 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700971 * @see #getExternalFilesDirs(String)
972 * @see Environment#getExternalStorageState(File)
973 * @see Environment#isExternalStorageEmulated(File)
974 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800975 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700976 @Nullable
977 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700978
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800979 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700980 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700981 * shared/external storage devices where the application can place
982 * persistent files it owns. These files are internal to the application,
983 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700984 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700985 * This is like {@link #getFilesDir()} in that these files will be deleted
986 * when the application is uninstalled, however there are some important
987 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700988 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700989 * <li>Shared storage may not always be available, since removable media can
990 * be ejected by the user. Media state can be checked using
991 * {@link Environment#getExternalStorageState(File)}.
992 * <li>There is no security enforced with these files. For example, any
993 * application holding
994 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
995 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700996 * </ul>
997 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700998 * If a shared storage device is emulated (as determined by
999 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1000 * backed by a private user data partition, which means there is little
1001 * benefit to storing data here instead of the private directories returned
1002 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001003 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001004 * Shared storage devices returned here are considered a stable part of the
1005 * device, including physical media slots under a protective cover. The
1006 * returned paths do not include transient devices, such as USB flash drives
1007 * connected to handheld devices.
1008 * <p>
1009 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001010 * example, an app may choose to store large files on the device with the
1011 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001012 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001013 * No additional permissions are required for the calling app to read or
1014 * write files under the returned path. Write access outside of these paths
1015 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001016 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001017 * The returned path may change over time if different shared storage media
1018 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001019 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001020 * @param type The type of files directory to return. May be {@code null}
1021 * for the root of the files directory or one of the following
1022 * constants for a subdirectory:
1023 * {@link android.os.Environment#DIRECTORY_MUSIC},
1024 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1025 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1026 * {@link android.os.Environment#DIRECTORY_ALARMS},
1027 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1028 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1029 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1030 * @return the absolute paths to application-specific directories. Some
1031 * individual paths may be {@code null} if that shared storage is
1032 * not currently available. The first path returned is the same as
1033 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001034 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001035 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001036 * @see Environment#isExternalStorageEmulated(File)
1037 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001038 */
1039 public abstract File[] getExternalFilesDirs(String type);
1040
1041 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001042 * Return the primary shared/external storage directory where this
1043 * application's OBB files (if there are any) can be found. Note if the
1044 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001045 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001046 * This is like {@link #getFilesDir()} in that these files will be deleted
1047 * when the application is uninstalled, however there are some important
1048 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001049 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001050 * <li>Shared storage may not always be available, since removable media can
1051 * be ejected by the user. Media state can be checked using
1052 * {@link Environment#getExternalStorageState(File)}.
1053 * <li>There is no security enforced with these files. For example, any
1054 * application holding
1055 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001056 * these files.
1057 * </ul>
1058 * <p>
1059 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1060 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001061 * accessible to the calling app. This only applies to paths generated for
1062 * package name of the calling application. To access paths belonging to
1063 * other packages,
1064 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1065 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001066 * <p>
1067 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001068 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001069 * should ensure that multiple instances running under different users don't
1070 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001071 *
1072 * @return the absolute path to application-specific directory. May return
1073 * {@code null} if shared storage is not currently available.
1074 * @see #getObbDirs()
1075 * @see Environment#getExternalStorageState(File)
1076 * @see Environment#isExternalStorageEmulated(File)
1077 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001078 */
1079 public abstract File getObbDir();
1080
1081 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001082 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001083 * shared/external storage devices where the application's OBB files (if
1084 * there are any) can be found. Note if the application does not have any
1085 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001086 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001087 * This is like {@link #getFilesDir()} in that these files will be deleted
1088 * when the application is uninstalled, however there are some important
1089 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001090 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001091 * <li>Shared storage may not always be available, since removable media can
1092 * be ejected by the user. Media state can be checked using
1093 * {@link Environment#getExternalStorageState(File)}.
1094 * <li>There is no security enforced with these files. For example, any
1095 * application holding
1096 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1097 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001098 * </ul>
1099 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001100 * Shared storage devices returned here are considered a stable part of the
1101 * device, including physical media slots under a protective cover. The
1102 * returned paths do not include transient devices, such as USB flash drives
1103 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001104 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001105 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001106 * example, an app may choose to store large files on the device with the
1107 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001108 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001109 * No additional permissions are required for the calling app to read or
1110 * write files under the returned path. Write access outside of these paths
1111 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001112 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001113 * @return the absolute paths to application-specific directories. Some
1114 * individual paths may be {@code null} if that shared storage is
1115 * not currently available. The first path returned is the same as
1116 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001117 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001118 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001119 * @see Environment#isExternalStorageEmulated(File)
1120 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001121 */
1122 public abstract File[] getObbDirs();
1123
1124 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001125 * Returns the absolute path to the application specific cache directory on
1126 * the filesystem. These files will be ones that get deleted first when the
1127 * device runs low on storage. There is no guarantee when these files will
1128 * be deleted.
1129 * <p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001130 * <strong>Note: you should not <em>rely</em> on the system deleting these
1131 * files for you; you should always have a reasonable maximum, such as 1 MB,
1132 * for the amount of space you consume with cache files, and prune those
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001133 * files when exceeding that space.</strong> If your app requires a larger
1134 * cache (larger than 1 MB), you should use {@link #getExternalCacheDir()}
1135 * instead.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001136 * <p>
1137 * The returned path may change over time if the calling app is moved to an
1138 * adopted storage device, so only relative paths should be persisted.
1139 * <p>
1140 * Apps require no extra permissions to read or write to the returned path,
1141 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001142 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001143 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001144 * @see #openFileOutput
1145 * @see #getFileStreamPath
1146 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001147 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 */
1149 public abstract File getCacheDir();
1150
1151 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001152 * Returns the absolute path to the application specific cache directory on
1153 * the filesystem designed for storing cached code. The system will delete
1154 * any files stored in this location both when your specific application is
1155 * upgraded, and when the entire platform is upgraded.
1156 * <p>
1157 * This location is optimal for storing compiled or optimized code generated
1158 * by your application at runtime.
1159 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001160 * The returned path may change over time if the calling app is moved to an
1161 * adopted storage device, so only relative paths should be persisted.
1162 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001163 * Apps require no extra permissions to read or write to the returned path,
1164 * since this path lives in their private storage.
1165 *
1166 * @return The path of the directory holding application code cache files.
1167 */
1168 public abstract File getCodeCacheDir();
1169
1170 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001171 * Returns absolute path to application-specific directory on the primary
1172 * shared/external storage device where the application can place cache
1173 * files it owns. These files are internal to the application, and not
1174 * typically visible to the user as media.
1175 * <p>
1176 * This is like {@link #getCacheDir()} in that these files will be deleted
1177 * when the application is uninstalled, however there are some important
1178 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001179 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001180 * <li>The platform does not always monitor the space available in shared
1181 * storage, and thus may not automatically delete these files. Apps should
1182 * always manage the maximum space used in this location. Currently the only
1183 * time files here will be deleted by the platform is when running on
1184 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1185 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1186 * <li>Shared storage may not always be available, since removable media can
1187 * be ejected by the user. Media state can be checked using
1188 * {@link Environment#getExternalStorageState(File)}.
1189 * <li>There is no security enforced with these files. For example, any
1190 * application holding
1191 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001192 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001193 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001194 * <p>
1195 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001196 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001197 * backed by a private user data partition, which means there is little
1198 * benefit to storing data here instead of the private directory returned by
1199 * {@link #getCacheDir()}.
1200 * <p>
1201 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001202 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001203 * accessible to the calling app. This only applies to paths generated for
1204 * package name of the calling application. To access paths belonging to
1205 * other packages,
1206 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1207 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1208 * <p>
1209 * On devices with multiple users (as described by {@link UserManager}),
1210 * each user has their own isolated shared storage. Applications only have
1211 * access to the shared storage for the user they're running as.
1212 * <p>
1213 * The returned path may change over time if different shared storage media
1214 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001215 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001216 * @return the absolute path to application-specific directory. May return
1217 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001218 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001219 * @see #getExternalCacheDirs()
1220 * @see Environment#getExternalStorageState(File)
1221 * @see Environment#isExternalStorageEmulated(File)
1222 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001223 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001224 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001225 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001226
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001227 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001228 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001229 * shared/external storage devices where the application can place cache
1230 * files it owns. These files are internal to the application, and not
1231 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001232 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001233 * This is like {@link #getCacheDir()} in that these files will be deleted
1234 * when the application is uninstalled, however there are some important
1235 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001236 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001237 * <li>The platform does not always monitor the space available in shared
1238 * storage, and thus may not automatically delete these files. Apps should
1239 * always manage the maximum space used in this location. Currently the only
1240 * time files here will be deleted by the platform is when running on
1241 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1242 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1243 * <li>Shared storage may not always be available, since removable media can
1244 * be ejected by the user. Media state can be checked using
1245 * {@link Environment#getExternalStorageState(File)}.
1246 * <li>There is no security enforced with these files. For example, any
1247 * application holding
1248 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1249 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001250 * </ul>
1251 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001252 * If a shared storage device is emulated (as determined by
1253 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1254 * backed by a private user data partition, which means there is little
1255 * benefit to storing data here instead of the private directory returned by
1256 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001257 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001258 * Shared storage devices returned here are considered a stable part of the
1259 * device, including physical media slots under a protective cover. The
1260 * returned paths do not include transient devices, such as USB flash drives
1261 * connected to handheld devices.
1262 * <p>
1263 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001264 * example, an app may choose to store large files on the device with the
1265 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001266 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001267 * No additional permissions are required for the calling app to read or
1268 * write files under the returned path. Write access outside of these paths
1269 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001270 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001271 * The returned paths may change over time if different shared storage media
1272 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001273 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001274 * @return the absolute paths to application-specific directories. Some
1275 * individual paths may be {@code null} if that shared storage is
1276 * not currently available. The first path returned is the same as
1277 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001278 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001279 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001280 * @see Environment#isExternalStorageEmulated(File)
1281 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001282 */
1283 public abstract File[] getExternalCacheDirs();
1284
1285 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001286 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001287 * shared/external storage devices where the application can place media
1288 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001289 * {@link MediaStore}.
1290 * <p>
1291 * This is like {@link #getExternalFilesDirs} in that these files will be
1292 * deleted when the application is uninstalled, however there are some
1293 * important differences:
1294 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001295 * <li>Shared storage may not always be available, since removable media can
1296 * be ejected by the user. Media state can be checked using
1297 * {@link Environment#getExternalStorageState(File)}.
1298 * <li>There is no security enforced with these files. For example, any
1299 * application holding
1300 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1301 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001302 * </ul>
1303 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001304 * Shared storage devices returned here are considered a stable part of the
1305 * device, including physical media slots under a protective cover. The
1306 * returned paths do not include transient devices, such as USB flash drives
1307 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001308 * <p>
1309 * An application may store data on any or all of the returned devices. For
1310 * example, an app may choose to store large files on the device with the
1311 * most available space, as measured by {@link StatFs}.
1312 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001313 * No additional permissions are required for the calling app to read or
1314 * write files under the returned path. Write access outside of these paths
1315 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001316 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001317 * The returned paths may change over time if different shared storage media
1318 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001319 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001320 * @return the absolute paths to application-specific directories. Some
1321 * individual paths may be {@code null} if that shared storage is
1322 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001323 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001324 * @see Environment#isExternalStorageEmulated(File)
1325 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001326 */
1327 public abstract File[] getExternalMediaDirs();
1328
1329 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 * Returns an array of strings naming the private files associated with
1331 * this Context's application package.
1332 *
1333 * @return Array of strings naming the private files.
1334 *
1335 * @see #openFileInput
1336 * @see #openFileOutput
1337 * @see #deleteFile
1338 */
1339 public abstract String[] fileList();
1340
1341 /**
1342 * Retrieve, creating if needed, a new directory in which the application
1343 * can place its own custom data files. You can use the returned File
1344 * object to create and access files in this directory. Note that files
1345 * created through a File object will only be accessible by your own
1346 * application; you can only set the mode of the entire directory, not
1347 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001348 * <p>
1349 * The returned path may change over time if the calling app is moved to an
1350 * adopted storage device, so only relative paths should be persisted.
1351 * <p>
1352 * Apps require no extra permissions to read or write to the returned path,
1353 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001355 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001356 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001357 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -07001358 * default operation.
Nick Kralevich15069212013-01-09 15:54:56 -08001359 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001360 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001361 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 *
1363 * @see #openFileOutput(String, int)
1364 */
1365 public abstract File getDir(String name, int mode);
1366
1367 /**
1368 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001369 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 *
1371 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001372 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1373 * default operation. Use
1374 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1375 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1376 * to disable localized collators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001377 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001378 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001380 * @throws android.database.sqlite.SQLiteException if the database file
1381 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001383 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001384 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 * @see #deleteDatabase
1386 */
1387 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1388 int mode, CursorFactory factory);
1389
1390 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001391 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001392 * application package. Creates the database file if it doesn't exist.
1393 * <p>
1394 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1395 * to be used to handle corruption when sqlite reports database corruption.
1396 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001397 *
1398 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001399 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1400 * default operation. Use
1401 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1402 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1403 * to disable localized collators.
Vasu Nori74f170f2010-06-01 18:06:18 -07001404 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001405 * cursor when query is called.
1406 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1407 * sqlite reports database corruption. if null,
1408 * {@link android.database.DefaultDatabaseErrorHandler} is
1409 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001410 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001411 * @throws android.database.sqlite.SQLiteException if the database file
1412 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001413 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001414 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001415 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001416 * @see #deleteDatabase
1417 */
1418 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001419 int mode, CursorFactory factory,
1420 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001421
1422 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001423 * Move an existing database file from the given source storage context to
1424 * this context. This is typically used to migrate data between storage
1425 * locations after an upgrade, such as migrating to device protected
1426 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001427 * <p>
1428 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001429 *
1430 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001431 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001432 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001433 * @return {@code true} if the move was successful or if the database didn't
1434 * exist in the source context, otherwise {@code false}.
1435 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001436 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001437 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1438
1439 /** @removed */
1440 @Deprecated
1441 public boolean migrateDatabaseFrom(Context sourceContext, String name) {
1442 return moveDatabaseFrom(sourceContext, name);
1443 }
Jeff Sharkey35871f22016-01-29 17:13:29 -07001444
1445 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 * Delete an existing private SQLiteDatabase associated with this Context's
1447 * application package.
1448 *
1449 * @param name The name (unique in the application package) of the
1450 * database.
1451 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001452 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 *
1454 * @see #openOrCreateDatabase
1455 */
1456 public abstract boolean deleteDatabase(String name);
1457
1458 /**
1459 * Returns the absolute path on the filesystem where a database created with
1460 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001461 * <p>
1462 * The returned path may change over time if the calling app is moved to an
1463 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 *
1465 * @param name The name of the database for which you would like to get
1466 * its path.
1467 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001468 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 *
1470 * @see #openOrCreateDatabase
1471 */
1472 public abstract File getDatabasePath(String name);
1473
1474 /**
1475 * Returns an array of strings naming the private databases associated with
1476 * this Context's application package.
1477 *
1478 * @return Array of strings naming the private databases.
1479 *
1480 * @see #openOrCreateDatabase
1481 * @see #deleteDatabase
1482 */
1483 public abstract String[] databaseList();
1484
1485 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001486 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001487 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001489 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 public abstract Drawable getWallpaper();
1491
1492 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001493 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001494 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001496 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001497 public abstract Drawable peekWallpaper();
1498
1499 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001500 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1501 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001502 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001503 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001504 public abstract int getWallpaperDesiredMinimumWidth();
1505
1506 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001507 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1508 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001510 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 public abstract int getWallpaperDesiredMinimumHeight();
1512
1513 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001514 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001515 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001516 * <p>This method requires the caller to hold the permission
1517 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001519 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1521
1522 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001523 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001524 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001525 * <p>This method requires the caller to hold the permission
1526 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001528 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529 public abstract void setWallpaper(InputStream data) throws IOException;
1530
1531 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001532 * @deprecated Use {@link android.app.WallpaperManager#clear
1533 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001534 * <p>This method requires the caller to hold the permission
1535 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001537 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 public abstract void clearWallpaper() throws IOException;
1539
1540 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001541 * Same as {@link #startActivity(Intent, Bundle)} with no options
1542 * specified.
1543 *
1544 * @param intent The description of the activity to start.
1545 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001546 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001547 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001548 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001549 * @see PackageManager#resolveActivity
1550 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001551 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001552
1553 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001554 * Version of {@link #startActivity(Intent)} that allows you to specify the
1555 * user the activity will be started for. This is not available to applications
1556 * that are not pre-installed on the system image. Using it requires holding
1557 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001558 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001559 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001560 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001561 * @hide
1562 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001563 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001564 throw new RuntimeException("Not implemented. Must override in a subclass.");
1565 }
1566
1567 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 * Launch a new activity. You will not receive any information about when
1569 * the activity exits.
1570 *
1571 * <p>Note that if this method is being called from outside of an
1572 * {@link android.app.Activity} Context, then the Intent must include
1573 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1574 * without being started from an existing Activity, there is no existing
1575 * task in which to place the new activity and thus it needs to be placed
1576 * in its own separate task.
1577 *
1578 * <p>This method throws {@link ActivityNotFoundException}
1579 * if there was no Activity found to run the given Intent.
1580 *
1581 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001582 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001583 * May be null if there are no options. See {@link android.app.ActivityOptions}
1584 * for how to build the Bundle supplied here; there are no supported definitions
1585 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001587 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001588 *
Scott Main60dd5202012-06-23 00:01:22 -07001589 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001590 * @see PackageManager#resolveActivity
1591 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001592 public abstract void startActivity(@RequiresPermission Intent intent,
1593 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001594
1595 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001596 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1597 * user the activity will be started for. This is not available to applications
1598 * that are not pre-installed on the system image. Using it requires holding
1599 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001600 * @param intent The description of the activity to start.
1601 * @param options Additional options for how the Activity should be started.
1602 * May be null if there are no options. See {@link android.app.ActivityOptions}
1603 * for how to build the Bundle supplied here; there are no supported definitions
1604 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001605 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001606 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001607 * @hide
1608 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001609 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1610 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001611 throw new RuntimeException("Not implemented. Must override in a subclass.");
1612 }
1613
1614 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001615 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1616 * is only supported for Views and Fragments.
1617 * @param who The identifier for the calling element that will receive the result.
1618 * @param intent The intent to start.
1619 * @param requestCode The code that will be returned with onActivityResult() identifying this
1620 * request.
1621 * @param options Additional options for how the Activity should be started.
1622 * May be null if there are no options. See {@link android.app.ActivityOptions}
1623 * for how to build the Bundle supplied here; there are no supported definitions
1624 * for building it manually.
1625 * @hide
1626 */
1627 public void startActivityForResult(
1628 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1629 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1630 + "Check canStartActivityForResult() before calling.");
1631 }
1632
1633 /**
1634 * Identifies whether this Context instance will be able to process calls to
1635 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1636 * @hide
1637 */
1638 public boolean canStartActivityForResult() {
1639 return false;
1640 }
1641
1642 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001643 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1644 * specified.
1645 *
1646 * @param intents An array of Intents to be started.
1647 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001648 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001649 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001650 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001651 * @see PackageManager#resolveActivity
1652 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001653 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654
1655 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001656 * Launch multiple new activities. This is generally the same as calling
1657 * {@link #startActivity(Intent)} for the first Intent in the array,
1658 * that activity during its creation calling {@link #startActivity(Intent)}
1659 * for the second entry, etc. Note that unlike that approach, generally
1660 * none of the activities except the last in the array will be created
1661 * at this point, but rather will be created when the user first visits
1662 * them (due to pressing back from the activity on top).
1663 *
1664 * <p>This method throws {@link ActivityNotFoundException}
1665 * if there was no Activity found for <em>any</em> given Intent. In this
1666 * case the state of the activity stack is undefined (some Intents in the
1667 * list may be on it, some not), so you probably want to avoid such situations.
1668 *
1669 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001670 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001671 * See {@link android.content.Context#startActivity(Intent, Bundle)
1672 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001673 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001674 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001675 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001676 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001677 * @see PackageManager#resolveActivity
1678 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001679 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001680
1681 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001682 * @hide
1683 * Launch multiple new activities. This is generally the same as calling
1684 * {@link #startActivity(Intent)} for the first Intent in the array,
1685 * that activity during its creation calling {@link #startActivity(Intent)}
1686 * for the second entry, etc. Note that unlike that approach, generally
1687 * none of the activities except the last in the array will be created
1688 * at this point, but rather will be created when the user first visits
1689 * them (due to pressing back from the activity on top).
1690 *
1691 * <p>This method throws {@link ActivityNotFoundException}
1692 * if there was no Activity found for <em>any</em> given Intent. In this
1693 * case the state of the activity stack is undefined (some Intents in the
1694 * list may be on it, some not), so you probably want to avoid such situations.
1695 *
1696 * @param intents An array of Intents to be started.
1697 * @param options Additional options for how the Activity should be started.
1698 * @param userHandle The user for whom to launch the activities
1699 * See {@link android.content.Context#startActivity(Intent, Bundle)
1700 * Context.startActivity(Intent, Bundle)} for more details.
1701 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001702 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001703 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001704 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001705 * @see PackageManager#resolveActivity
1706 */
1707 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1708 throw new RuntimeException("Not implemented. Must override in a subclass.");
1709 }
1710
1711 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001712 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1713 * with no options specified.
1714 *
1715 * @param intent The IntentSender to launch.
1716 * @param fillInIntent If non-null, this will be provided as the
1717 * intent parameter to {@link IntentSender#sendIntent}.
1718 * @param flagsMask Intent flags in the original IntentSender that you
1719 * would like to change.
1720 * @param flagsValues Desired values for any bits set in
1721 * <var>flagsMask</var>
1722 * @param extraFlags Always set to 0.
1723 *
1724 * @see #startActivity(Intent)
1725 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1726 */
1727 public abstract void startIntentSender(IntentSender intent,
1728 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1729 throws IntentSender.SendIntentException;
1730
1731 /**
1732 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001733 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001734 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001735 * here; otherwise, its associated action will be executed (such as
1736 * sending a broadcast) as if you had called
1737 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001738 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001739 * @param intent The IntentSender to launch.
1740 * @param fillInIntent If non-null, this will be provided as the
1741 * intent parameter to {@link IntentSender#sendIntent}.
1742 * @param flagsMask Intent flags in the original IntentSender that you
1743 * would like to change.
1744 * @param flagsValues Desired values for any bits set in
1745 * <var>flagsMask</var>
1746 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001747 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001748 * See {@link android.content.Context#startActivity(Intent, Bundle)
1749 * Context.startActivity(Intent, Bundle)} for more details. If options
1750 * have also been supplied by the IntentSender, options given here will
1751 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001752 *
1753 * @see #startActivity(Intent, Bundle)
1754 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001755 */
1756 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001757 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001758 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001759
1760 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761 * Broadcast the given intent to all interested BroadcastReceivers. This
1762 * call is asynchronous; it returns immediately, and you will continue
1763 * executing while the receivers are run. No results are propagated from
1764 * receivers and receivers can not abort the broadcast. If you want
1765 * to allow receivers to propagate results or abort the broadcast, you must
1766 * send an ordered broadcast using
1767 * {@link #sendOrderedBroadcast(Intent, String)}.
1768 *
1769 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1770 *
1771 * @param intent The Intent to broadcast; all receivers matching this
1772 * Intent will receive the broadcast.
1773 *
1774 * @see android.content.BroadcastReceiver
1775 * @see #registerReceiver
1776 * @see #sendBroadcast(Intent, String)
1777 * @see #sendOrderedBroadcast(Intent, String)
1778 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1779 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001780 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001781
1782 /**
1783 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1784 * an optional required permission to be enforced. This
1785 * call is asynchronous; it returns immediately, and you will continue
1786 * executing while the receivers are run. No results are propagated from
1787 * receivers and receivers can not abort the broadcast. If you want
1788 * to allow receivers to propagate results or abort the broadcast, you must
1789 * send an ordered broadcast using
1790 * {@link #sendOrderedBroadcast(Intent, String)}.
1791 *
1792 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1793 *
1794 * @param intent The Intent to broadcast; all receivers matching this
1795 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001796 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 * a receiver must hold in order to receive your broadcast.
1798 * If null, no permission is required.
1799 *
1800 * @see android.content.BroadcastReceiver
1801 * @see #registerReceiver
1802 * @see #sendBroadcast(Intent)
1803 * @see #sendOrderedBroadcast(Intent, String)
1804 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1805 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001806 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001807 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001809
1810 /**
1811 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1812 * an array of required permissions to be enforced. This call is asynchronous; it returns
1813 * immediately, and you will continue executing while the receivers are run. No results are
1814 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1815 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1816 * using {@link #sendOrderedBroadcast(Intent, String)}.
1817 *
1818 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1819 *
1820 * @param intent The Intent to broadcast; all receivers matching this
1821 * Intent will receive the broadcast.
1822 * @param receiverPermissions Array of names of permissions that a receiver must hold
1823 * in order to receive your broadcast.
1824 * If null or empty, no permissions are required.
1825 *
1826 * @see android.content.BroadcastReceiver
1827 * @see #registerReceiver
1828 * @see #sendBroadcast(Intent)
1829 * @see #sendOrderedBroadcast(Intent, String)
1830 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1831 * @hide
1832 */
1833 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1834 String[] receiverPermissions);
1835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001837 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1838 * an optional required permission to be enforced. This
1839 * call is asynchronous; it returns immediately, and you will continue
1840 * executing while the receivers are run. No results are propagated from
1841 * receivers and receivers can not abort the broadcast. If you want
1842 * to allow receivers to propagate results or abort the broadcast, you must
1843 * send an ordered broadcast using
1844 * {@link #sendOrderedBroadcast(Intent, String)}.
1845 *
1846 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1847 *
1848 * @param intent The Intent to broadcast; all receivers matching this
1849 * Intent will receive the broadcast.
1850 * @param receiverPermission (optional) String naming a permission that
1851 * a receiver must hold in order to receive your broadcast.
1852 * If null, no permission is required.
1853 * @param options (optional) Additional sending options, generated from a
1854 * {@link android.app.BroadcastOptions}.
1855 *
1856 * @see android.content.BroadcastReceiver
1857 * @see #registerReceiver
1858 * @see #sendBroadcast(Intent)
1859 * @see #sendOrderedBroadcast(Intent, String)
1860 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1861 * @hide
1862 */
1863 @SystemApi
1864 public abstract void sendBroadcast(Intent intent,
1865 @Nullable String receiverPermission,
1866 @Nullable Bundle options);
1867
1868 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001869 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001870 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001871 * @hide
1872 */
1873 public abstract void sendBroadcast(Intent intent,
1874 String receiverPermission, int appOp);
1875
1876 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1878 * them one at a time to allow more preferred receivers to consume the
1879 * broadcast before it is delivered to less preferred receivers. This
1880 * call is asynchronous; it returns immediately, and you will continue
1881 * executing while the receivers are run.
1882 *
1883 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1884 *
1885 * @param intent The Intent to broadcast; all receivers matching this
1886 * Intent will receive the broadcast.
1887 * @param receiverPermission (optional) String naming a permissions that
1888 * a receiver must hold in order to receive your broadcast.
1889 * If null, no permission is required.
1890 *
1891 * @see android.content.BroadcastReceiver
1892 * @see #registerReceiver
1893 * @see #sendBroadcast(Intent)
1894 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1895 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001896 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001897 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898
1899 /**
1900 * Version of {@link #sendBroadcast(Intent)} that allows you to
1901 * receive data back from the broadcast. This is accomplished by
1902 * supplying your own BroadcastReceiver when calling, which will be
1903 * treated as a final receiver at the end of the broadcast -- its
1904 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001905 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001906 * be serialized in the same way as calling
1907 * {@link #sendOrderedBroadcast(Intent, String)}.
1908 *
1909 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1910 * asynchronous; it will return before
1911 * resultReceiver.onReceive() is called.
1912 *
1913 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1914 *
1915 * @param intent The Intent to broadcast; all receivers matching this
1916 * Intent will receive the broadcast.
1917 * @param receiverPermission String naming a permissions that
1918 * a receiver must hold in order to receive your broadcast.
1919 * If null, no permission is required.
1920 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1921 * receiver of the broadcast.
1922 * @param scheduler A custom Handler with which to schedule the
1923 * resultReceiver callback; if null it will be
1924 * scheduled in the Context's main thread.
1925 * @param initialCode An initial value for the result code. Often
1926 * Activity.RESULT_OK.
1927 * @param initialData An initial value for the result data. Often
1928 * null.
1929 * @param initialExtras An initial value for the result extras. Often
1930 * null.
1931 *
1932 * @see #sendBroadcast(Intent)
1933 * @see #sendBroadcast(Intent, String)
1934 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 * @see android.content.BroadcastReceiver
1936 * @see #registerReceiver
1937 * @see android.app.Activity#RESULT_OK
1938 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001939 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07001940 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001941 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1942 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001943
1944 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001945 * Version of {@link #sendBroadcast(Intent)} that allows you to
1946 * receive data back from the broadcast. This is accomplished by
1947 * supplying your own BroadcastReceiver when calling, which will be
1948 * treated as a final receiver at the end of the broadcast -- its
1949 * {@link BroadcastReceiver#onReceive} method will be called with
1950 * the result values collected from the other receivers. The broadcast will
1951 * be serialized in the same way as calling
1952 * {@link #sendOrderedBroadcast(Intent, String)}.
1953 *
1954 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1955 * asynchronous; it will return before
1956 * resultReceiver.onReceive() is called.
1957 *
1958 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1959 *
1960 *
1961 * @param intent The Intent to broadcast; all receivers matching this
1962 * Intent will receive the broadcast.
1963 * @param receiverPermission String naming a permissions that
1964 * a receiver must hold in order to receive your broadcast.
1965 * If null, no permission is required.
1966 * @param options (optional) Additional sending options, generated from a
1967 * {@link android.app.BroadcastOptions}.
1968 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1969 * receiver of the broadcast.
1970 * @param scheduler A custom Handler with which to schedule the
1971 * resultReceiver callback; if null it will be
1972 * scheduled in the Context's main thread.
1973 * @param initialCode An initial value for the result code. Often
1974 * Activity.RESULT_OK.
1975 * @param initialData An initial value for the result data. Often
1976 * null.
1977 * @param initialExtras An initial value for the result extras. Often
1978 * null.
1979 * @see #sendBroadcast(Intent)
1980 * @see #sendBroadcast(Intent, String)
1981 * @see #sendOrderedBroadcast(Intent, String)
1982 * @see android.content.BroadcastReceiver
1983 * @see #registerReceiver
1984 * @see android.app.Activity#RESULT_OK
1985 * @hide
1986 */
1987 @SystemApi
1988 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1989 @Nullable String receiverPermission, @Nullable Bundle options,
1990 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
1991 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
1992
1993 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001994 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1995 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001996 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001997 * @hide
1998 */
1999 public abstract void sendOrderedBroadcast(Intent intent,
2000 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2001 Handler scheduler, int initialCode, String initialData,
2002 Bundle initialExtras);
2003
2004 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002005 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2006 * user the broadcast will be sent to. This is not available to applications
2007 * that are not pre-installed on the system image. Using it requires holding
2008 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002009 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002010 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002011 * @see #sendBroadcast(Intent)
2012 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002013 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2014 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002015
2016 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002017 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2018 * user the broadcast will be sent to. This is not available to applications
2019 * that are not pre-installed on the system image. Using it requires holding
2020 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002021 *
2022 * @param intent The Intent to broadcast; all receivers matching this
2023 * Intent will receive the broadcast.
2024 * @param user UserHandle to send the intent to.
2025 * @param receiverPermission (optional) String naming a permission that
2026 * a receiver must hold in order to receive your broadcast.
2027 * If null, no permission is required.
2028 *
2029 * @see #sendBroadcast(Intent, String)
2030 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002031 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2032 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002033
Svet Ganov16a16892015-04-16 10:32:04 -07002034
2035 /**
2036 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2037 * user the broadcast will be sent to. This is not available to applications
2038 * that are not pre-installed on the system image. Using it requires holding
2039 * the INTERACT_ACROSS_USERS permission.
2040 *
2041 * @param intent The Intent to broadcast; all receivers matching this
2042 * Intent will receive the broadcast.
2043 * @param user UserHandle to send the intent to.
2044 * @param receiverPermission (optional) String naming a permission that
2045 * a receiver must hold in order to receive your broadcast.
2046 * If null, no permission is required.
2047 * @param appOp The app op associated with the broadcast.
2048 *
2049 * @see #sendBroadcast(Intent, String)
2050 *
2051 * @hide
2052 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002053 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2054 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002055
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002056 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002057 * Version of
2058 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2059 * that allows you to specify the
2060 * user the broadcast will be sent to. This is not available to applications
2061 * that are not pre-installed on the system image. Using it requires holding
2062 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002063 *
2064 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2065 *
2066 * @param intent The Intent to broadcast; all receivers matching this
2067 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002068 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002069 * @param receiverPermission String naming a permissions that
2070 * a receiver must hold in order to receive your broadcast.
2071 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002072 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2073 * receiver of the broadcast.
2074 * @param scheduler A custom Handler with which to schedule the
2075 * resultReceiver callback; if null it will be
2076 * scheduled in the Context's main thread.
2077 * @param initialCode An initial value for the result code. Often
2078 * Activity.RESULT_OK.
2079 * @param initialData An initial value for the result data. Often
2080 * null.
2081 * @param initialExtras An initial value for the result extras. Often
2082 * null.
2083 *
2084 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2085 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002086 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2087 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002088 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2089 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002090
2091 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002092 * Similar to above but takes an appOp as well, to enforce restrictions.
2093 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2094 * BroadcastReceiver, Handler, int, String, Bundle)
2095 * @hide
2096 */
2097 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2098 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2099 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2100 @Nullable Bundle initialExtras);
2101
2102 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002103 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2104 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2105 * BroadcastReceiver, Handler, int, String, Bundle)
2106 * @hide
2107 */
2108 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2109 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2110 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2111 @Nullable String initialData, @Nullable Bundle initialExtras);
2112
2113 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002114 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002115 * Intent you are sending stays around after the broadcast is complete,
2116 * so that others can quickly retrieve that data through the return
2117 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2118 * all other ways, this behaves the same as
2119 * {@link #sendBroadcast(Intent)}.
2120 *
2121 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2122 * permission in order to use this API. If you do not hold that
2123 * permission, {@link SecurityException} will be thrown.
2124 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002125 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2126 * can access them), no protection (anyone can modify them), and many other problems.
2127 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2128 * has changed, with another mechanism for apps to retrieve the current value whenever
2129 * desired.
2130 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131 * @param intent The Intent to broadcast; all receivers matching this
2132 * Intent will receive the broadcast, and the Intent will be held to
2133 * be re-broadcast to future receivers.
2134 *
2135 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002136 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002138 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002139 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002140
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002141 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002142 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002143 * receive data back from the broadcast. This is accomplished by
2144 * supplying your own BroadcastReceiver when calling, which will be
2145 * treated as a final receiver at the end of the broadcast -- its
2146 * {@link BroadcastReceiver#onReceive} method will be called with
2147 * the result values collected from the other receivers. The broadcast will
2148 * be serialized in the same way as calling
2149 * {@link #sendOrderedBroadcast(Intent, String)}.
2150 *
2151 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2152 * asynchronous; it will return before
2153 * resultReceiver.onReceive() is called. Note that the sticky data
2154 * stored is only the data you initially supply to the broadcast, not
2155 * the result of any changes made by the receivers.
2156 *
2157 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2158 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002159 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2160 * can access them), no protection (anyone can modify them), and many other problems.
2161 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2162 * has changed, with another mechanism for apps to retrieve the current value whenever
2163 * desired.
2164 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002165 * @param intent The Intent to broadcast; all receivers matching this
2166 * Intent will receive the broadcast.
2167 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2168 * receiver of the broadcast.
2169 * @param scheduler A custom Handler with which to schedule the
2170 * resultReceiver callback; if null it will be
2171 * scheduled in the Context's main thread.
2172 * @param initialCode An initial value for the result code. Often
2173 * Activity.RESULT_OK.
2174 * @param initialData An initial value for the result data. Often
2175 * null.
2176 * @param initialExtras An initial value for the result extras. Often
2177 * null.
2178 *
2179 * @see #sendBroadcast(Intent)
2180 * @see #sendBroadcast(Intent, String)
2181 * @see #sendOrderedBroadcast(Intent, String)
2182 * @see #sendStickyBroadcast(Intent)
2183 * @see android.content.BroadcastReceiver
2184 * @see #registerReceiver
2185 * @see android.app.Activity#RESULT_OK
2186 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002187 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002188 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002189 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002190 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2191 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002193 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002194 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 * so that it is as if the sticky broadcast had never happened.
2196 *
2197 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2198 * permission in order to use this API. If you do not hold that
2199 * permission, {@link SecurityException} will be thrown.
2200 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002201 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2202 * can access them), no protection (anyone can modify them), and many other problems.
2203 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2204 * has changed, with another mechanism for apps to retrieve the current value whenever
2205 * desired.
2206 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002207 * @param intent The Intent that was previously broadcast.
2208 *
2209 * @see #sendStickyBroadcast
2210 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002211 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002212 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002213
2214 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002215 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002216 * user the broadcast will be sent to. This is not available to applications
2217 * that are not pre-installed on the system image. Using it requires holding
2218 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002219 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002220 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2221 * can access them), no protection (anyone can modify them), and many other problems.
2222 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2223 * has changed, with another mechanism for apps to retrieve the current value whenever
2224 * desired.
2225 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002226 * @param intent The Intent to broadcast; all receivers matching this
2227 * Intent will receive the broadcast, and the Intent will be held to
2228 * be re-broadcast to future receivers.
2229 * @param user UserHandle to send the intent to.
2230 *
2231 * @see #sendBroadcast(Intent)
2232 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002233 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002234 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2235 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002236
2237 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002238 * @hide
2239 * This is just here for sending CONNECTIVITY_ACTION.
2240 */
2241 @Deprecated
2242 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2243 UserHandle user, Bundle options);
2244
2245 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002246 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002247 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2248 * that allows you to specify the
2249 * user the broadcast will be sent to. This is not available to applications
2250 * that are not pre-installed on the system image. Using it requires holding
2251 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002252 *
2253 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2254 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002255 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2256 * can access them), no protection (anyone can modify them), and many other problems.
2257 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2258 * has changed, with another mechanism for apps to retrieve the current value whenever
2259 * desired.
2260 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002261 * @param intent The Intent to broadcast; all receivers matching this
2262 * Intent will receive the broadcast.
2263 * @param user UserHandle to send the intent to.
2264 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2265 * receiver of the broadcast.
2266 * @param scheduler A custom Handler with which to schedule the
2267 * resultReceiver callback; if null it will be
2268 * scheduled in the Context's main thread.
2269 * @param initialCode An initial value for the result code. Often
2270 * Activity.RESULT_OK.
2271 * @param initialData An initial value for the result data. Often
2272 * null.
2273 * @param initialExtras An initial value for the result extras. Often
2274 * null.
2275 *
2276 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2277 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002278 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002279 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002280 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002281 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2282 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002283
2284 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002285 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002286 * user the broadcast will be sent to. This is not available to applications
2287 * that are not pre-installed on the system image. Using it requires holding
2288 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002289 *
2290 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2291 * permission in order to use this API. If you do not hold that
2292 * permission, {@link SecurityException} will be thrown.
2293 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002294 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2295 * can access them), no protection (anyone can modify them), and many other problems.
2296 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2297 * has changed, with another mechanism for apps to retrieve the current value whenever
2298 * desired.
2299 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002300 * @param intent The Intent that was previously broadcast.
2301 * @param user UserHandle to remove the sticky broadcast from.
2302 *
2303 * @see #sendStickyBroadcastAsUser
2304 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002305 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002306 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2307 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002308
2309 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002310 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002311 * <var>receiver</var> will be called with any broadcast Intent that
2312 * matches <var>filter</var>, in the main application thread.
2313 *
2314 * <p>The system may broadcast Intents that are "sticky" -- these stay
2315 * around after the broadcast as finished, to be sent to any later
2316 * registrations. If your IntentFilter matches one of these sticky
2317 * Intents, that Intent will be returned by this function
2318 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2319 * been broadcast.
2320 *
2321 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2322 * in which case each of these will be sent to <var>receiver</var>. In
2323 * this case, only one of these can be returned directly by the function;
2324 * which of these that is returned is arbitrarily decided by the system.
2325 *
2326 * <p>If you know the Intent your are registering for is sticky, you can
2327 * supply null for your <var>receiver</var>. In this case, no receiver is
2328 * registered -- the function simply returns the sticky Intent that
2329 * matches <var>filter</var>. In the case of multiple matches, the same
2330 * rules as described above apply.
2331 *
2332 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2333 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002334 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2335 * registered with this method will correctly respect the
2336 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2337 * Prior to that, it would be ignored and delivered to all matching registered
2338 * receivers. Be careful if using this for security.</p>
2339 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002340 * <p class="note">Note: this method <em>cannot be called from a
2341 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2342 * that is declared in an application's manifest. It is okay, however, to call
2343 * this method from another BroadcastReceiver that has itself been registered
2344 * at run time with {@link #registerReceiver}, since the lifetime of such a
2345 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 *
2347 * @param receiver The BroadcastReceiver to handle the broadcast.
2348 * @param filter Selects the Intent broadcasts to be received.
2349 *
2350 * @return The first sticky intent found that matches <var>filter</var>,
2351 * or null if there are none.
2352 *
2353 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2354 * @see #sendBroadcast
2355 * @see #unregisterReceiver
2356 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002357 @Nullable
2358 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002359 IntentFilter filter);
2360
2361 /**
2362 * Register to receive intent broadcasts, to run in the context of
2363 * <var>scheduler</var>. See
2364 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2365 * information. This allows you to enforce permissions on who can
2366 * broadcast intents to your receiver, or have the receiver run in
2367 * a different thread than the main application thread.
2368 *
2369 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2370 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002371 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2372 * registered with this method will correctly respect the
2373 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2374 * Prior to that, it would be ignored and delivered to all matching registered
2375 * receivers. Be careful if using this for security.</p>
2376 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002377 * @param receiver The BroadcastReceiver to handle the broadcast.
2378 * @param filter Selects the Intent broadcasts to be received.
2379 * @param broadcastPermission String naming a permissions that a
2380 * broadcaster must hold in order to send an Intent to you. If null,
2381 * no permission is required.
2382 * @param scheduler Handler identifying the thread that will receive
2383 * the Intent. If null, the main thread of the process will be used.
2384 *
2385 * @return The first sticky intent found that matches <var>filter</var>,
2386 * or null if there are none.
2387 *
2388 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2389 * @see #sendBroadcast
2390 * @see #unregisterReceiver
2391 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002392 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002393 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002394 IntentFilter filter, @Nullable String broadcastPermission,
2395 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002396
2397 /**
2398 * @hide
2399 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2400 * but for a specific user. This receiver will receiver broadcasts that
2401 * are sent to the requested user. It
2402 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
2403 * permission.
2404 *
2405 * @param receiver The BroadcastReceiver to handle the broadcast.
2406 * @param user UserHandle to send the intent to.
2407 * @param filter Selects the Intent broadcasts to be received.
2408 * @param broadcastPermission String naming a permissions that a
2409 * broadcaster must hold in order to send an Intent to you. If null,
2410 * no permission is required.
2411 * @param scheduler Handler identifying the thread that will receive
2412 * the Intent. If null, the main thread of the process will be used.
2413 *
2414 * @return The first sticky intent found that matches <var>filter</var>,
2415 * or null if there are none.
2416 *
Jeff Brown6e539312015-02-24 18:53:21 -08002417 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002418 * @see #sendBroadcast
2419 * @see #unregisterReceiver
2420 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002421 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07002422 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002423 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2424 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002425
2426 /**
2427 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2428 * filters that have been registered for this BroadcastReceiver will be
2429 * removed.
2430 *
2431 * @param receiver The BroadcastReceiver to unregister.
2432 *
2433 * @see #registerReceiver
2434 */
2435 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2436
2437 /**
2438 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07002439 * should contain either contain the complete class name of a specific service
2440 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07002441 * Intent is less specified, it log a warning about this and which of the
2442 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002443 * is not already running, it will be instantiated and started (creating a
2444 * process for it if needed); if it is running then it remains running.
2445 *
2446 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002447 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 * with the <var>intent</var> given here. This provides a convenient way
2449 * to submit jobs to a service without having to bind and call on to its
2450 * interface.
2451 *
2452 * <p>Using startService() overrides the default service lifetime that is
2453 * managed by {@link #bindService}: it requires the service to remain
2454 * running until {@link #stopService} is called, regardless of whether
2455 * any clients are connected to it. Note that calls to startService()
2456 * are not nesting: no matter how many times you call startService(),
2457 * a single call to {@link #stopService} will stop it.
2458 *
2459 * <p>The system attempts to keep running services around as much as
2460 * possible. The only time they should be stopped is if the current
2461 * foreground application is using so many resources that the service needs
2462 * to be killed. If any errors happen in the service's process, it will
2463 * automatically be restarted.
2464 *
2465 * <p>This function will throw {@link SecurityException} if you do not
2466 * have permission to start the given service.
2467 *
Chris Craik1e353522016-04-18 10:20:50 -07002468 * <p class="note"><strong>Note:</strong> Each call to startService()
2469 * results in significant work done by the system to manage service
2470 * lifecycle surrounding the processing of the intent, which can take
2471 * multiple milliseconds of CPU time. Due to this cost, startService()
2472 * should not be used for frequent intent delivery to a service, and only
2473 * for scheduling significant work. Use {@link #bindService bound services}
2474 * for high frequency calls.
2475 * </p>
2476 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002477 * @param service Identifies the service to be started. The Intent must be
2478 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002479 * may be included in the Intent extras to supply arguments along with
2480 * this specific start call.
2481 *
2482 * @return If the service is being started or is already running, the
2483 * {@link ComponentName} of the actual service that was started is
2484 * returned; else if the service does not exist null is returned.
2485 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002486 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 *
2488 * @see #stopService
2489 * @see #bindService
2490 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002491 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 public abstract ComponentName startService(Intent service);
2493
2494 /**
2495 * Request that a given application service be stopped. If the service is
2496 * not running, nothing happens. Otherwise it is stopped. Note that calls
2497 * to startService() are not counted -- this stops the service no matter
2498 * how many times it was started.
2499 *
2500 * <p>Note that if a stopped service still has {@link ServiceConnection}
2501 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2502 * not be destroyed until all of these bindings are removed. See
2503 * the {@link android.app.Service} documentation for more details on a
2504 * service's lifecycle.
2505 *
2506 * <p>This function will throw {@link SecurityException} if you do not
2507 * have permission to stop the given service.
2508 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002509 * @param service Description of the service to be stopped. The Intent must be either
2510 * fully explicit (supplying a component name) or specify a specific package
2511 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 *
2513 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002514 * 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 -08002515 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002516 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002517 *
2518 * @see #startService
2519 */
2520 public abstract boolean stopService(Intent service);
2521
2522 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002523 * @hide like {@link #startService(Intent)} but for a specific user.
2524 */
2525 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2526
2527 /**
2528 * @hide like {@link #stopService(Intent)} but for a specific user.
2529 */
2530 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002531
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002532 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 * Connect to an application service, creating it if needed. This defines
2534 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002535 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002536 * told if it dies and restarts. The service will be considered required
2537 * by the system only for as long as the calling context exists. For
2538 * example, if this Context is an Activity that is stopped, the service will
2539 * not be required to continue running until the Activity is resumed.
2540 *
2541 * <p>This function will throw {@link SecurityException} if you do not
2542 * have permission to bind to the given service.
2543 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002544 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002546 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002547 * {@link #startService} with the arguments containing the command to be
2548 * sent, with the service calling its
2549 * {@link android.app.Service#stopSelf(int)} method when done executing
2550 * that command. See the API demo App/Service/Service Start Arguments
2551 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002552 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002553 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2554 * is tied to another object (the one that registered it).</p>
2555 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002556 * @param service Identifies the service to connect to. The Intent must
2557 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002559 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002560 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002561 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2562 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2563 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2564 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002565 * @return If you have successfully bound to the service, {@code true} is returned;
2566 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 * receive the service object.
2568 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002569 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002570 *
2571 * @see #unbindService
2572 * @see #startService
2573 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002574 * @see #BIND_DEBUG_UNBIND
2575 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002577 public abstract boolean bindService(@RequiresPermission Intent service,
2578 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002579
2580 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002581 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002582 * argument for use by system server and other multi-user aware code.
2583 * @hide
2584 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002585 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002586 @SuppressWarnings("unused")
Tor Norbye788fc2b2015-07-05 16:10:42 -07002587 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002588 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002589 throw new RuntimeException("Not implemented. Must override in a subclass.");
2590 }
2591
2592 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002593 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2594 * explicit non-null Handler to run the ServiceConnection callbacks on.
2595 *
2596 * @hide
2597 */
2598 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2599 Handler handler, UserHandle user) {
2600 throw new RuntimeException("Not implemented. Must override in a subclass.");
2601 }
2602
2603 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002604 * Disconnect from an application service. You will no longer receive
2605 * calls as the service is restarted, and the service is now allowed to
2606 * stop at any time.
2607 *
2608 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002609 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002610 *
2611 * @see #bindService
2612 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002613 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614
2615 /**
2616 * Start executing an {@link android.app.Instrumentation} class. The given
2617 * Instrumentation component will be run by killing its target application
2618 * (if currently running), starting the target process, instantiating the
2619 * instrumentation component, and then letting it drive the application.
2620 *
2621 * <p>This function is not synchronous -- it returns as soon as the
2622 * instrumentation has started and while it is running.
2623 *
2624 * <p>Instrumentation is normally only allowed to run against a package
2625 * that is either unsigned or signed with a signature that the
2626 * the instrumentation package is also signed with (ensuring the target
2627 * trusts the instrumentation).
2628 *
2629 * @param className Name of the Instrumentation component to be run.
2630 * @param profileFile Optional path to write profiling data as the
2631 * instrumentation runs, or null for no profiling.
2632 * @param arguments Additional optional arguments to pass to the
2633 * instrumentation, or null.
2634 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002635 * @return {@code true} if the instrumentation was successfully started,
2636 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002637 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002638 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2639 @Nullable String profileFile, @Nullable Bundle arguments);
2640
2641 /** @hide */
2642 @StringDef({
2643 POWER_SERVICE,
2644 WINDOW_SERVICE,
2645 LAYOUT_INFLATER_SERVICE,
2646 ACCOUNT_SERVICE,
2647 ACTIVITY_SERVICE,
2648 ALARM_SERVICE,
2649 NOTIFICATION_SERVICE,
2650 ACCESSIBILITY_SERVICE,
2651 CAPTIONING_SERVICE,
2652 KEYGUARD_SERVICE,
2653 LOCATION_SERVICE,
2654 //@hide: COUNTRY_DETECTOR,
2655 SEARCH_SERVICE,
2656 SENSOR_SERVICE,
2657 STORAGE_SERVICE,
2658 WALLPAPER_SERVICE,
2659 VIBRATOR_SERVICE,
2660 //@hide: STATUS_BAR_SERVICE,
2661 CONNECTIVITY_SERVICE,
2662 //@hide: UPDATE_LOCK_SERVICE,
2663 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002664 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002665 //@hide: NETWORK_POLICY_SERVICE,
2666 WIFI_SERVICE,
Etan Cohen20d329b2015-09-29 13:49:02 -07002667 WIFI_NAN_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002668 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002669 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002670 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002671 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002672 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002673 NSD_SERVICE,
2674 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002675 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002676 MEDIA_ROUTER_SERVICE,
2677 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002678 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002679 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002680 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002681 CLIPBOARD_SERVICE,
2682 INPUT_METHOD_SERVICE,
2683 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002684 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002685 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002686 //@hide: BACKUP_SERVICE,
2687 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07002688 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07002689 DEVICE_POLICY_SERVICE,
2690 UI_MODE_SERVICE,
2691 DOWNLOAD_SERVICE,
2692 NFC_SERVICE,
2693 BLUETOOTH_SERVICE,
2694 //@hide: SIP_SERVICE,
2695 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002696 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002697 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002698 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002699 INPUT_SERVICE,
2700 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002701 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002702 RESTRICTIONS_SERVICE,
2703 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002704 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002705 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002706 CONSUMER_IR_SERVICE,
2707 //@hide: TRUST_SERVICE,
2708 TV_INPUT_SERVICE,
2709 //@hide: NETWORK_SCORE_SERVICE,
2710 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002711 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002712 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002713 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002714 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002715 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002716 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002717 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002718 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08002719 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08002720 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08002721 //@hide: CONTEXTHUB_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002722 })
2723 @Retention(RetentionPolicy.SOURCE)
2724 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002725
2726 /**
2727 * Return the handle to a system-level service by name. The class of the
2728 * returned object varies by the requested name. Currently available names
2729 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002730 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002731 * <dl>
2732 * <dt> {@link #WINDOW_SERVICE} ("window")
2733 * <dd> The top-level window manager in which you can place custom
2734 * windows. The returned object is a {@link android.view.WindowManager}.
2735 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2736 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2737 * in this context.
2738 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2739 * <dd> A {@link android.app.ActivityManager} for interacting with the
2740 * global activity state of the system.
2741 * <dt> {@link #POWER_SERVICE} ("power")
2742 * <dd> A {@link android.os.PowerManager} for controlling power
2743 * management.
2744 * <dt> {@link #ALARM_SERVICE} ("alarm")
2745 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2746 * time of your choosing.
2747 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2748 * <dd> A {@link android.app.NotificationManager} for informing the user
2749 * of background events.
2750 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2751 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2752 * <dt> {@link #LOCATION_SERVICE} ("location")
2753 * <dd> A {@link android.location.LocationManager} for controlling location
2754 * (e.g., GPS) updates.
2755 * <dt> {@link #SEARCH_SERVICE} ("search")
2756 * <dd> A {@link android.app.SearchManager} for handling search.
2757 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2758 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2759 * hardware.
2760 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2761 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2762 * handling management of network connections.
2763 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07002764 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
2765 * connectivity. On releases before NYC, it should only be obtained from an application
2766 * context, and not from any other derived context to avoid memory leaks within the calling
2767 * process.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002768 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2769 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2770 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2772 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2773 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002774 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2775 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002776 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002777 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002778 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002779 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002780 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2781 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002782 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
2783 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
2784 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01002785 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002786 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002787 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002788 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 * <p>Note: System services obtained via this API may be closely associated with
2790 * the Context in which they are obtained from. In general, do not share the
2791 * service objects between various different contexts (Activities, Applications,
2792 * Services, Providers, etc.)
2793 *
2794 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002795 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002797 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798 * @see #WINDOW_SERVICE
2799 * @see android.view.WindowManager
2800 * @see #LAYOUT_INFLATER_SERVICE
2801 * @see android.view.LayoutInflater
2802 * @see #ACTIVITY_SERVICE
2803 * @see android.app.ActivityManager
2804 * @see #POWER_SERVICE
2805 * @see android.os.PowerManager
2806 * @see #ALARM_SERVICE
2807 * @see android.app.AlarmManager
2808 * @see #NOTIFICATION_SERVICE
2809 * @see android.app.NotificationManager
2810 * @see #KEYGUARD_SERVICE
2811 * @see android.app.KeyguardManager
2812 * @see #LOCATION_SERVICE
2813 * @see android.location.LocationManager
2814 * @see #SEARCH_SERVICE
2815 * @see android.app.SearchManager
2816 * @see #SENSOR_SERVICE
2817 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002818 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002819 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 * @see #VIBRATOR_SERVICE
2821 * @see android.os.Vibrator
2822 * @see #CONNECTIVITY_SERVICE
2823 * @see android.net.ConnectivityManager
2824 * @see #WIFI_SERVICE
2825 * @see android.net.wifi.WifiManager
2826 * @see #AUDIO_SERVICE
2827 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002828 * @see #MEDIA_ROUTER_SERVICE
2829 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 * @see #TELEPHONY_SERVICE
2831 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002832 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2833 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002834 * @see #CARRIER_CONFIG_SERVICE
2835 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 * @see #INPUT_METHOD_SERVICE
2837 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002838 * @see #UI_MODE_SERVICE
2839 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002840 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002841 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002842 * @see #BATTERY_SERVICE
2843 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002844 * @see #JOB_SCHEDULER_SERVICE
2845 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002846 * @see #NETWORK_STATS_SERVICE
2847 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002848 * @see android.os.HardwarePropertiesManager
2849 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002850 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002851 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852
2853 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002854 * Return the handle to a system-level service by class.
2855 * <p>
2856 * Currently available classes are:
2857 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2858 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2859 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2860 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2861 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2862 * {@link android.net.ConnectivityManager},
2863 * {@link android.net.wifi.WifiManager},
2864 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2865 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2866 * {@link android.view.inputmethod.InputMethodManager},
2867 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002868 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
2869 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08002870 * </p><p>
2871 * Note: System services obtained via this API may be closely associated with
2872 * the Context in which they are obtained from. In general, do not share the
2873 * service objects between various different contexts (Activities, Applications,
2874 * Services, Providers, etc.)
2875 * </p>
2876 *
2877 * @param serviceClass The class of the desired service.
2878 * @return The service or null if the class is not a supported system service.
2879 */
2880 @SuppressWarnings("unchecked")
2881 public final <T> T getSystemService(Class<T> serviceClass) {
2882 // Because subclasses may override getSystemService(String) we cannot
2883 // perform a lookup by class alone. We must first map the class to its
2884 // service name then invoke the string-based method.
2885 String serviceName = getSystemServiceName(serviceClass);
2886 return serviceName != null ? (T)getSystemService(serviceName) : null;
2887 }
2888
2889 /**
2890 * Gets the name of the system-level service that is represented by the specified class.
2891 *
2892 * @param serviceClass The class of the desired service.
2893 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08002894 */
2895 public abstract String getSystemServiceName(Class<?> serviceClass);
2896
2897 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898 * Use with {@link #getSystemService} to retrieve a
2899 * {@link android.os.PowerManager} for controlling power management,
2900 * including "wake locks," which let you keep the device on while
2901 * you're running long tasks.
2902 */
2903 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002904
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 /**
2906 * Use with {@link #getSystemService} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08002907 * {@link android.os.RecoverySystem} for accessing the recovery system
2908 * service.
2909 *
2910 * @see #getSystemService
2911 * @hide
2912 */
2913 public static final String RECOVERY_SERVICE = "recovery";
2914
2915 /**
2916 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 * {@link android.view.WindowManager} for accessing the system's window
2918 * manager.
2919 *
2920 * @see #getSystemService
2921 * @see android.view.WindowManager
2922 */
2923 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 /**
2926 * Use with {@link #getSystemService} to retrieve a
2927 * {@link android.view.LayoutInflater} for inflating layout resources in this
2928 * context.
2929 *
2930 * @see #getSystemService
2931 * @see android.view.LayoutInflater
2932 */
2933 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002934
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 /**
2936 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002937 * {@link android.accounts.AccountManager} for receiving intents at a
2938 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002939 *
2940 * @see #getSystemService
2941 * @see android.accounts.AccountManager
2942 */
2943 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002944
Fred Quintana60307342009-03-24 22:48:12 -07002945 /**
2946 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 * {@link android.app.ActivityManager} for interacting with the global
2948 * system state.
2949 *
2950 * @see #getSystemService
2951 * @see android.app.ActivityManager
2952 */
2953 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 /**
2956 * Use with {@link #getSystemService} to retrieve a
2957 * {@link android.app.AlarmManager} for receiving intents at a
2958 * time of your choosing.
2959 *
2960 * @see #getSystemService
2961 * @see android.app.AlarmManager
2962 */
2963 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002964
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 /**
2966 * Use with {@link #getSystemService} to retrieve a
2967 * {@link android.app.NotificationManager} for informing the user of
2968 * background events.
2969 *
2970 * @see #getSystemService
2971 * @see android.app.NotificationManager
2972 */
2973 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002975 /**
2976 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002977 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2978 * feedback for UI events through the registered event listeners.
2979 *
2980 * @see #getSystemService
2981 * @see android.view.accessibility.AccessibilityManager
2982 */
2983 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002984
svetoslavganov75986cf2009-05-14 22:28:01 -07002985 /**
2986 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002987 * {@link android.view.accessibility.CaptioningManager} for obtaining
2988 * captioning properties and listening for changes in captioning
2989 * preferences.
2990 *
2991 * @see #getSystemService
2992 * @see android.view.accessibility.CaptioningManager
2993 */
2994 public static final String CAPTIONING_SERVICE = "captioning";
2995
2996 /**
2997 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 * {@link android.app.NotificationManager} for controlling keyguard.
2999 *
3000 * @see #getSystemService
3001 * @see android.app.KeyguardManager
3002 */
3003 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 /**
3006 * Use with {@link #getSystemService} to retrieve a {@link
3007 * android.location.LocationManager} for controlling location
3008 * updates.
3009 *
3010 * @see #getSystemService
3011 * @see android.location.LocationManager
3012 */
3013 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003014
3015 /**
3016 * Use with {@link #getSystemService} to retrieve a
3017 * {@link android.location.CountryDetector} for detecting the country that
3018 * the user is in.
3019 *
3020 * @hide
3021 */
3022 public static final String COUNTRY_DETECTOR = "country_detector";
3023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 /**
3025 * Use with {@link #getSystemService} to retrieve a {@link
3026 * android.app.SearchManager} for handling searches.
3027 *
3028 * @see #getSystemService
3029 * @see android.app.SearchManager
3030 */
3031 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003033 /**
3034 * Use with {@link #getSystemService} to retrieve a {@link
3035 * android.hardware.SensorManager} for accessing sensors.
3036 *
3037 * @see #getSystemService
3038 * @see android.hardware.SensorManager
3039 */
3040 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 /**
San Mehatc9d81752010-02-01 10:23:27 -08003043 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003044 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003045 * functions.
3046 *
3047 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08003048 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003049 */
3050 public static final String STORAGE_SERVICE = "storage";
3051
3052 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003053 * Use with {@link #getSystemService} to retrieve a
3054 * com.android.server.WallpaperService for accessing wallpapers.
3055 *
3056 * @see #getSystemService
3057 */
3058 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 /**
3061 * Use with {@link #getSystemService} to retrieve a {@link
3062 * android.os.Vibrator} for interacting with the vibration hardware.
3063 *
3064 * @see #getSystemService
3065 * @see android.os.Vibrator
3066 */
3067 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003069 /**
3070 * Use with {@link #getSystemService} to retrieve a {@link
3071 * android.app.StatusBarManager} for interacting with the status bar.
3072 *
3073 * @see #getSystemService
3074 * @see android.app.StatusBarManager
3075 * @hide
3076 */
3077 public static final String STATUS_BAR_SERVICE = "statusbar";
3078
3079 /**
3080 * Use with {@link #getSystemService} to retrieve a {@link
3081 * android.net.ConnectivityManager} for handling management of
3082 * network connections.
3083 *
3084 * @see #getSystemService
3085 * @see android.net.ConnectivityManager
3086 */
3087 public static final String CONNECTIVITY_SERVICE = "connectivity";
3088
3089 /**
3090 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003091 * android.os.IUpdateLock} for managing runtime sequences that
3092 * must not be interrupted by headless OTA application or similar.
3093 *
3094 * @hide
3095 * @see #getSystemService
3096 * @see android.os.UpdateLock
3097 */
3098 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3099
3100 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003101 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003102 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003103 */
3104 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3105
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003106 /**
3107 * Use with {@link #getSystemService} to retrieve a {@link
3108 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3109 *
3110 * @see #getSystemService
3111 * @see android.app.usage.NetworkStatsManager
3112 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003113 public static final String NETWORK_STATS_SERVICE = "netstats";
3114 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003115 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
3116
San Mehatd1df8ac2010-01-26 06:17:26 -08003117 /**
3118 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003119 * android.net.wifi.WifiManager} for handling management of
3120 * Wi-Fi access.
3121 *
3122 * @see #getSystemService
3123 * @see android.net.wifi.WifiManager
3124 */
3125 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003126
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003127 /**
repo sync55bc5f32011-06-24 14:23:07 -07003128 * Use with {@link #getSystemService} to retrieve a {@link
3129 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003130 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003131 *
3132 * @see #getSystemService
3133 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003134 */
3135 public static final String WIFI_P2P_SERVICE = "wifip2p";
3136
3137 /**
Etan Cohen20d329b2015-09-29 13:49:02 -07003138 * Use with {@link #getSystemService} to retrieve a
3139 * {@link android.net.wifi.nan.WifiNanManager} for handling management of
3140 * Wi-Fi NAN discovery and connections.
3141 *
3142 * @see #getSystemService
3143 * @see android.net.wifi.nan.WifiNanManager
3144 * @hide PROPOSED_NAN_API
3145 */
3146 public static final String WIFI_NAN_SERVICE = "wifinan";
3147
3148 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003149 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003150 * android.net.wifi.WifiScanner} for scanning the wifi universe
3151 *
3152 * @see #getSystemService
3153 * @see android.net.wifi.WifiScanner
3154 * @hide
3155 */
Wei Wang35d552f2014-07-08 21:37:01 -07003156 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003157 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3158
3159 /**
3160 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003161 * android.net.wifi.RttManager} for ranging devices with wifi
3162 *
3163 * @see #getSystemService
3164 * @see android.net.wifi.RttManager
3165 * @hide
3166 */
3167 @SystemApi
3168 public static final String WIFI_RTT_SERVICE = "rttmanager";
3169
3170 /**
3171 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003172 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003173 * Ethernet access.
3174 *
3175 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003176 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003177 *
3178 * @hide
3179 */
3180 public static final String ETHERNET_SERVICE = "ethernet";
3181
3182 /**
3183 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003184 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003185 * discovery
3186 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003187 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003188 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003189 */
3190 public static final String NSD_SERVICE = "servicediscovery";
3191
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003192 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 * Use with {@link #getSystemService} to retrieve a
3194 * {@link android.media.AudioManager} for handling management of volume,
3195 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003196 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 * @see #getSystemService
3198 * @see android.media.AudioManager
3199 */
3200 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 /**
3203 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003204 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003205 * of fingerprints.
3206 *
3207 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07003208 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003209 */
3210 public static final String FINGERPRINT_SERVICE = "fingerprint";
3211
3212 /**
3213 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003214 * {@link android.media.MediaRouter} for controlling and managing
3215 * routing of media.
3216 *
3217 * @see #getSystemService
3218 * @see android.media.MediaRouter
3219 */
3220 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3221
3222 /**
3223 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003224 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003225 *
3226 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07003227 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003228 */
3229 public static final String MEDIA_SESSION_SERVICE = "media_session";
3230
3231 /**
3232 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 * {@link android.telephony.TelephonyManager} for handling management the
3234 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003235 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 * @see #getSystemService
3237 * @see android.telephony.TelephonyManager
3238 */
3239 public static final String TELEPHONY_SERVICE = "phone";
3240
3241 /**
3242 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003243 * {@link android.telephony.SubscriptionManager} for handling management the
3244 * telephony subscriptions of the device.
3245 *
3246 * @see #getSystemService
3247 * @see android.telephony.SubscriptionManager
3248 */
3249 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3250
3251 /**
3252 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003253 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003254 * of the device.
3255 *
3256 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003257 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003258 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003259 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003260
3261 /**
3262 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003263 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3264 *
3265 * @see #getSystemService
3266 * @see android.telephony.CarrierConfigManager
3267 */
3268 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3269
3270 /**
3271 * Use with {@link #getSystemService} to retrieve a
3272 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08003273 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003274 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003275 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003277 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278 */
3279 public static final String CLIPBOARD_SERVICE = "clipboard";
3280
3281 /**
Scott Main4b5da682010-10-21 11:49:12 -07003282 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003283 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3284 * methods.
3285 *
3286 * @see #getSystemService
3287 */
3288 public static final String INPUT_METHOD_SERVICE = "input_method";
3289
3290 /**
3291 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09003292 * {@link android.view.textservice.TextServicesManager} for accessing
3293 * text services.
3294 *
3295 * @see #getSystemService
3296 */
3297 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3298
3299 /**
3300 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003301 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003303 * @see #getSystemService
3304 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003305 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003308 * Official published name of the (internal) voice interaction manager service.
3309 *
3310 * @hide
3311 * @see #getSystemService
3312 */
3313 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3314
3315 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003316 * Use with {@link #getSystemService} to access the
3317 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3318 *
3319 * @hide
3320 * @see #getSystemService
3321 */
3322 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3323
3324
3325 /**
Christopher Tate487529a2009-04-29 14:03:25 -07003326 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003327 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003328 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003329 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003330 *
Christopher Tate487529a2009-04-29 14:03:25 -07003331 * @see #getSystemService
3332 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003333 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003334 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003335
3336 /**
3337 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003338 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003339 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07003340 * @see #getSystemService
3341 */
3342 public static final String DROPBOX_SERVICE = "dropbox";
3343
Christopher Tate487529a2009-04-29 14:03:25 -07003344 /**
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003345 * System service name for the DeviceIdleController. There is no Java API for this.
3346 * @see #getSystemService
3347 * @hide
3348 */
3349 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3350
3351 /**
Scott Main4b5da682010-10-21 11:49:12 -07003352 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003353 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003354 * device policy management.
3355 *
3356 * @see #getSystemService
3357 */
3358 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3359
3360 /**
Tobias Haamel53332882010-02-18 16:15:43 -08003361 * Use with {@link #getSystemService} to retrieve a
3362 * {@link android.app.UiModeManager} for controlling UI modes.
3363 *
3364 * @see #getSystemService
3365 */
3366 public static final String UI_MODE_SERVICE = "uimode";
3367
3368 /**
Steve Howarda2709362010-07-02 17:12:48 -07003369 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003370 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003371 *
3372 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07003373 */
3374 public static final String DOWNLOAD_SERVICE = "download";
3375
3376 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08003377 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003378 * {@link android.os.BatteryManager} for managing battery state.
3379 *
3380 * @see #getSystemService
3381 */
3382 public static final String BATTERY_SERVICE = "batterymanager";
3383
3384 /**
3385 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003386 * {@link android.nfc.NfcManager} for using NFC.
3387 *
3388 * @see #getSystemService
3389 */
3390 public static final String NFC_SERVICE = "nfc";
3391
3392 /**
3393 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003394 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003395 *
3396 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003397 */
3398 public static final String BLUETOOTH_SERVICE = "bluetooth";
3399
3400 /**
3401 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003402 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3403 *
3404 * @see #getSystemService
3405 */
3406 /** @hide */
3407 public static final String SIP_SERVICE = "sip";
3408
3409 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003410 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003411 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003412 * and for controlling this device's behavior as a USB device.
3413 *
3414 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04003415 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003416 */
3417 public static final String USB_SERVICE = "usb";
3418
3419 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003420 * Use with {@link #getSystemService} to retrieve a {@link
3421 * android.hardware.SerialManager} for access to serial ports.
3422 *
3423 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003424 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003425 *
3426 * @hide
3427 */
3428 public static final String SERIAL_SERVICE = "serial";
3429
3430 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003431 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003432 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3433 * HDMI-CEC protocol.
3434 *
3435 * @see #getSystemService
3436 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003437 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003438 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003439 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003440 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003441
3442 /**
3443 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003444 * {@link android.hardware.input.InputManager} for interacting with input devices.
3445 *
3446 * @see #getSystemService
3447 * @see android.hardware.input.InputManager
3448 */
3449 public static final String INPUT_SERVICE = "input";
3450
3451 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07003452 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003453 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3454 *
3455 * @see #getSystemService
3456 * @see android.hardware.display.DisplayManager
3457 */
3458 public static final String DISPLAY_SERVICE = "display";
3459
3460 /**
3461 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003462 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3463 *
3464 * @see #getSystemService
3465 * @see android.os.UserManager
3466 */
3467 public static final String USER_SERVICE = "user";
3468
3469 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003470 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003471 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3472 * profiles of a user.
3473 *
3474 * @see #getSystemService
3475 * @see android.content.pm.LauncherApps
3476 */
3477 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3478
3479 /**
3480 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003481 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3482 * and requesting permissions for restricted operations.
3483 * @see #getSystemService
3484 * @see android.content.RestrictionsManager
3485 */
3486 public static final String RESTRICTIONS_SERVICE = "restrictions";
3487
3488 /**
3489 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003490 * {@link android.app.AppOpsManager} for tracking application operations
3491 * on the device.
3492 *
3493 * @see #getSystemService
3494 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003495 */
3496 public static final String APP_OPS_SERVICE = "appops";
3497
3498 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003499 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003500 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003501 * camera devices.
3502 *
3503 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003504 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003505 */
3506 public static final String CAMERA_SERVICE = "camera";
3507
3508 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003509 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003510 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003511 *
3512 * @see #getSystemService
3513 * @see android.print.PrintManager
3514 */
3515 public static final String PRINT_SERVICE = "print";
3516
3517 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003518 * Use with {@link #getSystemService} to retrieve a
3519 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3520 * signals from the device.
3521 *
3522 * @see #getSystemService
3523 * @see android.hardware.ConsumerIrManager
3524 */
3525 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3526
3527 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003528 * {@link android.app.trust.TrustManager} for managing trust agents.
3529 * @see #getSystemService
3530 * @see android.app.trust.TrustManager
3531 * @hide
3532 */
3533 public static final String TRUST_SERVICE = "trust";
3534
3535 /**
Jae Seo39570912014-02-20 18:23:25 -08003536 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003537 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3538 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003539 *
3540 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003541 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003542 */
3543 public static final String TV_INPUT_SERVICE = "tv_input";
3544
3545 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003546 * {@link android.net.NetworkScoreManager} for managing network scoring.
3547 * @see #getSystemService
3548 * @see android.net.NetworkScoreManager
3549 * @hide
3550 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003551 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003552 public static final String NETWORK_SCORE_SERVICE = "network_score";
3553
3554 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003555 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003556 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003557 *
3558 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003559 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003560 */
3561 public static final String USAGE_STATS_SERVICE = "usagestats";
3562
3563 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003564 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003565 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003566 * background tasks.
3567 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003568 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003569 */
Christopher Tate7060b042014-06-09 19:50:00 -07003570 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003571
3572 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003573 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003574 * android.service.persistentdata.PersistentDataBlockManager} instance
3575 * for interacting with a storage device that lives across factory resets.
3576 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003577 * @see #getSystemService
3578 * @see android.service.persistentdata.PersistentDataBlockManager
3579 * @hide
3580 */
Andres Morales33df9372014-09-26 17:08:59 -07003581 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003582 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3583
3584 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003585 * Use with {@link #getSystemService} to retrieve a {@link
3586 * android.media.projection.MediaProjectionManager} instance for managing
3587 * media projection sessions.
3588 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003589 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003590 */
3591 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3592
3593 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003594 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003595 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003596 *
3597 * @see #getSystemService
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003598 */
3599 public static final String MIDI_SERVICE = "midi";
3600
Eric Laurent2035ac82015-03-05 15:18:44 -08003601
3602 /**
3603 * Use with {@link #getSystemService} to retrieve a
3604 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3605 *
3606 * @see #getSystemService
3607 * @hide
3608 */
3609 public static final String RADIO_SERVICE = "radio";
3610
Paul McLeana33be212015-02-20 07:52:45 -08003611 /**
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003612 * Use with {@link #getSystemService} to retrieve a
3613 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
3614 *
3615 * @see #getSystemService
3616 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01003617 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003618
3619 /**
Makoto Onukib5a012f2016-06-21 11:13:53 -07003620 * Use with {@link #getSystemService} to retrieve a
3621 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003622 *
3623 * @see #getSystemService
3624 * @see android.content.pm.ShortcutManager
3625 */
3626 public static final String SHORTCUT_SERVICE = "shortcut";
3627
3628 /**
Peng Xu9ff7d222016-02-11 13:02:05 -08003629 * Use with {@link #getSystemService} to retrieve a {@link
3630 * android.hardware.location.ContextHubManager} for accessing context hubs.
3631 *
3632 * @see #getSystemService
3633 * @see android.hardware.location.ContextHubManager
3634 *
3635 * @hide
3636 */
3637 @SystemApi
3638 public static final String CONTEXTHUB_SERVICE = "contexthub";
3639
3640 /**
Joe Onorato713fec82016-03-04 10:34:02 -08003641 * Use with {@link #getSystemService} to retrieve a
3642 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
3643 * memory, etc) metrics.
3644 *
3645 * @see #getSystemService
3646 */
3647 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
3648
3649 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07003650 * Gatekeeper Service.
3651 * @hide
3652 */
3653 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
3654
3655 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003656 * Determine whether the given permission is allowed for a particular
3657 * process and user ID running in the system.
3658 *
3659 * @param permission The name of the permission being checked.
3660 * @param pid The process ID being checked against. Must be > 0.
3661 * @param uid The user ID being checked against. A uid of 0 is the root
3662 * user, which will pass every permission check.
3663 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003664 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 * pid/uid is allowed that permission, or
3666 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3667 *
3668 * @see PackageManager#checkPermission(String, String)
3669 * @see #checkCallingPermission
3670 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003671 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003672 @PackageManager.PermissionResult
3673 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674
Dianne Hackbornff170242014-11-19 10:59:01 -08003675 /** @hide */
3676 @PackageManager.PermissionResult
3677 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3678 IBinder callerToken);
3679
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 /**
3681 * Determine whether the calling process of an IPC you are handling has been
3682 * granted a particular permission. This is basically the same as calling
3683 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3684 * by {@link android.os.Binder#getCallingPid} and
3685 * {@link android.os.Binder#getCallingUid}. One important difference
3686 * is that if you are not currently processing an IPC, this function
3687 * will always fail. This is done to protect against accidentally
3688 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3689 * to avoid this protection.
3690 *
3691 * @param permission The name of the permission being checked.
3692 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003693 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 * pid/uid is allowed that permission, or
3695 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3696 *
3697 * @see PackageManager#checkPermission(String, String)
3698 * @see #checkPermission
3699 * @see #checkCallingOrSelfPermission
3700 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003701 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003702 @PackageManager.PermissionResult
3703 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704
3705 /**
3706 * Determine whether the calling process of an IPC <em>or you</em> have been
3707 * granted a particular permission. This is the same as
3708 * {@link #checkCallingPermission}, except it grants your own permissions
3709 * if you are not currently processing an IPC. Use with care!
3710 *
3711 * @param permission The name of the permission being checked.
3712 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003713 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 * pid/uid is allowed that permission, or
3715 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3716 *
3717 * @see PackageManager#checkPermission(String, String)
3718 * @see #checkPermission
3719 * @see #checkCallingPermission
3720 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003721 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003722 @PackageManager.PermissionResult
3723 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724
3725 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08003726 * Determine whether <em>you</em> have been granted a particular permission.
3727 *
3728 * @param permission The name of the permission being checked.
3729 *
3730 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
3731 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
3732 *
3733 * @see PackageManager#checkPermission(String, String)
3734 * @see #checkCallingPermission(String)
3735 */
3736 @PackageManager.PermissionResult
3737 public abstract int checkSelfPermission(@NonNull String permission);
3738
3739 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 * If the given permission is not allowed for a particular process
3741 * and user ID running in the system, throw a {@link SecurityException}.
3742 *
3743 * @param permission The name of the permission being checked.
3744 * @param pid The process ID being checked against. Must be &gt; 0.
3745 * @param uid The user ID being checked against. A uid of 0 is the root
3746 * user, which will pass every permission check.
3747 * @param message A message to include in the exception if it is thrown.
3748 *
3749 * @see #checkPermission(String, int, int)
3750 */
3751 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003752 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753
3754 /**
3755 * If the calling process of an IPC you are handling has not been
3756 * granted a particular permission, throw a {@link
3757 * SecurityException}. This is basically the same as calling
3758 * {@link #enforcePermission(String, int, int, String)} with the
3759 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3760 * and {@link android.os.Binder#getCallingUid}. One important
3761 * difference is that if you are not currently processing an IPC,
3762 * this function will always throw the SecurityException. This is
3763 * done to protect against accidentally leaking permissions; you
3764 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3765 * protection.
3766 *
3767 * @param permission The name of the permission being checked.
3768 * @param message A message to include in the exception if it is thrown.
3769 *
3770 * @see #checkCallingPermission(String)
3771 */
3772 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003773 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003774
3775 /**
3776 * If neither you nor the calling process of an IPC you are
3777 * handling has been granted a particular permission, throw a
3778 * {@link SecurityException}. This is the same as {@link
3779 * #enforceCallingPermission}, except it grants your own
3780 * permissions if you are not currently processing an IPC. Use
3781 * with care!
3782 *
3783 * @param permission The name of the permission being checked.
3784 * @param message A message to include in the exception if it is thrown.
3785 *
3786 * @see #checkCallingOrSelfPermission(String)
3787 */
3788 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003789 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003790
3791 /**
3792 * Grant permission to access a specific Uri to another package, regardless
3793 * of whether that package has general permission to access the Uri's
3794 * content provider. This can be used to grant specific, temporary
3795 * permissions, typically in response to user interaction (such as the
3796 * user opening an attachment that you would like someone else to
3797 * display).
3798 *
3799 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3800 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3801 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3802 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3803 * start an activity instead of this function directly. If you use this
3804 * function directly, you should be sure to call
3805 * {@link #revokeUriPermission} when the target should no longer be allowed
3806 * to access it.
3807 *
3808 * <p>To succeed, the content provider owning the Uri must have set the
3809 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3810 * grantUriPermissions} attribute in its manifest or included the
3811 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3812 * &lt;grant-uri-permissions&gt;} tag.
3813 *
3814 * @param toPackage The package you would like to allow to access the Uri.
3815 * @param uri The Uri you would like to grant access to.
3816 * @param modeFlags The desired access modes. Any combination of
3817 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003818 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003820 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3821 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3822 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3823 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3824 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003825 *
3826 * @see #revokeUriPermission
3827 */
3828 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003829 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830
3831 /**
3832 * Remove all permissions to access a particular content provider Uri
3833 * that were previously added with {@link #grantUriPermission}. The given
3834 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003835 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003837 * "content://foo". It will not remove any prefix grants that exist at a
3838 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003840 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003841 * regular permission access to a Uri, but had received access to it through
3842 * a specific Uri permission grant, you could not revoke that grant with this
3843 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003844 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003845 * but will remove whatever permission grants to the Uri had been given to the app
3846 * (or none).</p>
3847 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003848 * @param uri The Uri you would like to revoke access to.
3849 * @param modeFlags The desired access modes. Any combination of
3850 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3851 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3852 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3853 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3854 *
3855 * @see #grantUriPermission
3856 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003857 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858
3859 /**
3860 * Determine whether a particular process and user ID has been granted
3861 * permission to access a specific URI. This only checks for permissions
3862 * that have been explicitly granted -- if the given process/uid has
3863 * more general access to the URI's content provider then this check will
3864 * always fail.
3865 *
3866 * @param uri The uri that is being checked.
3867 * @param pid The process ID being checked against. Must be &gt; 0.
3868 * @param uid The user ID being checked against. A uid of 0 is the root
3869 * user, which will pass every permission check.
3870 * @param modeFlags The type of access to grant. May be one or both of
3871 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3872 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3873 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003874 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 * pid/uid is allowed to access that uri, or
3876 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3877 *
3878 * @see #checkCallingUriPermission
3879 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003880 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003881 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003882 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883
Dianne Hackbornff170242014-11-19 10:59:01 -08003884 /** @hide */
3885 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3886 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003888 /**
3889 * Determine whether the calling process and user ID has been
3890 * granted permission to access a specific URI. This is basically
3891 * the same as calling {@link #checkUriPermission(Uri, int, int,
3892 * int)} with the pid and uid returned by {@link
3893 * android.os.Binder#getCallingPid} and {@link
3894 * android.os.Binder#getCallingUid}. One important difference is
3895 * that if you are not currently processing an IPC, this function
3896 * will always fail.
3897 *
3898 * @param uri The uri that is being checked.
3899 * @param modeFlags The type of access to grant. May be one or both of
3900 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3901 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3902 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003903 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904 * is allowed to access that uri, or
3905 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3906 *
3907 * @see #checkUriPermission(Uri, int, int, int)
3908 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003909 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003910 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003911
3912 /**
3913 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3914 * permission to access a specific URI. This is the same as
3915 * {@link #checkCallingUriPermission}, except it grants your own permissions
3916 * if you are not currently processing an IPC. Use with care!
3917 *
3918 * @param uri The uri that is being checked.
3919 * @param modeFlags The type of access to grant. May be one or both of
3920 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3921 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3922 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003923 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003924 * is allowed to access that uri, or
3925 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3926 *
3927 * @see #checkCallingUriPermission
3928 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003929 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003930 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003931 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932
3933 /**
3934 * Check both a Uri and normal permission. This allows you to perform
3935 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3936 * call.
3937 *
3938 * @param uri The Uri whose permission is to be checked, or null to not
3939 * do this check.
3940 * @param readPermission The permission that provides overall read access,
3941 * or null to not do this check.
3942 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003943 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944 * @param pid The process ID being checked against. Must be &gt; 0.
3945 * @param uid The user ID being checked against. A uid of 0 is the root
3946 * user, which will pass every permission check.
3947 * @param modeFlags The type of access to grant. May be one or both of
3948 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3949 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3950 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003951 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 * is allowed to access that uri or holds one of the given permissions, or
3953 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3954 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003955 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003956 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3957 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003958 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003959
3960 /**
3961 * If a particular process and user ID has not been granted
3962 * permission to access a specific URI, throw {@link
3963 * SecurityException}. This only checks for permissions that have
3964 * been explicitly granted -- if the given process/uid has more
3965 * general access to the URI's content provider then this check
3966 * will always fail.
3967 *
3968 * @param uri The uri that is being checked.
3969 * @param pid The process ID being checked against. Must be &gt; 0.
3970 * @param uid The user ID being checked against. A uid of 0 is the root
3971 * user, which will pass every permission check.
3972 * @param modeFlags The type of access to grant. May be one or both of
3973 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3974 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3975 * @param message A message to include in the exception if it is thrown.
3976 *
3977 * @see #checkUriPermission(Uri, int, int, int)
3978 */
3979 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003980 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981
3982 /**
3983 * If the calling process and user ID has not been granted
3984 * permission to access a specific URI, throw {@link
3985 * SecurityException}. This is basically the same as calling
3986 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3987 * the pid and uid returned by {@link
3988 * android.os.Binder#getCallingPid} and {@link
3989 * android.os.Binder#getCallingUid}. One important difference is
3990 * that if you are not currently processing an IPC, this function
3991 * will always throw a SecurityException.
3992 *
3993 * @param uri The uri that is being checked.
3994 * @param modeFlags The type of access to grant. May be one or both of
3995 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3996 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3997 * @param message A message to include in the exception if it is thrown.
3998 *
3999 * @see #checkCallingUriPermission(Uri, int)
4000 */
4001 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004002 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003
4004 /**
4005 * If the calling process of an IPC <em>or you</em> has not been
4006 * granted permission to access a specific URI, throw {@link
4007 * SecurityException}. This is the same as {@link
4008 * #enforceCallingUriPermission}, except it grants your own
4009 * permissions if you are not currently processing an IPC. Use
4010 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07004011 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004012 * @param uri The uri that is being checked.
4013 * @param modeFlags The type of access to grant. May be one or both of
4014 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4015 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
4016 * @param message A message to include in the exception if it is thrown.
4017 *
4018 * @see #checkCallingOrSelfUriPermission(Uri, int)
4019 */
4020 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004021 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004022
4023 /**
4024 * Enforce both a Uri and normal permission. This allows you to perform
4025 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4026 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004027 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004028 * @param uri The Uri whose permission is to be checked, or null to not
4029 * do this check.
4030 * @param readPermission The permission that provides overall read access,
4031 * or null to not do this check.
4032 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004033 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004034 * @param pid The process ID being checked against. Must be &gt; 0.
4035 * @param uid The user ID being checked against. A uid of 0 is the root
4036 * user, which will pass every permission check.
4037 * @param modeFlags The type of access to grant. May be one or both of
4038 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4039 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
4040 * @param message A message to include in the exception if it is thrown.
4041 *
4042 * @see #checkUriPermission(Uri, String, String, int, int, int)
4043 */
4044 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004045 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004046 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004047 @Nullable String message);
4048
4049 /** @hide */
4050 @IntDef(flag = true,
4051 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
4052 @Retention(RetentionPolicy.SOURCE)
4053 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054
4055 /**
4056 * Flag for use with {@link #createPackageContext}: include the application
4057 * code with the context. This means loading code into the caller's
4058 * process, so that {@link #getClassLoader()} can be used to instantiate
4059 * the application's classes. Setting this flags imposes security
4060 * restrictions on what application context you can access; if the
4061 * requested application can not be safely loaded into your process,
4062 * java.lang.SecurityException will be thrown. If this flag is not set,
4063 * there will be no restrictions on the packages that can be loaded,
4064 * but {@link #getClassLoader} will always return the default system
4065 * class loader.
4066 */
4067 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4068
4069 /**
4070 * Flag for use with {@link #createPackageContext}: ignore any security
4071 * restrictions on the Context being requested, allowing it to always
4072 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4073 * to be loaded into a process even when it isn't safe to do so. Use
4074 * with extreme care!
4075 */
4076 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004077
Romain Guy870e09f2009-07-06 16:35:25 -07004078 /**
4079 * Flag for use with {@link #createPackageContext}: a restricted context may
4080 * disable specific features. For instance, a View associated with a restricted
4081 * context would ignore particular XML attributes.
4082 */
4083 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084
4085 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004086 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004087 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004088 *
4089 * @hide
4090 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004091 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004092
4093 /**
4094 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004095 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004096 *
4097 * @hide
4098 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004099 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004100
4101 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004102 * @hide Used to indicate we should tell the activity manager about the process
4103 * loading this code.
4104 */
4105 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4106
4107 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004108 * Return a new Context object for the given application name. This
4109 * Context is the same as what the named application gets when it is
4110 * launched, containing the same resources and class loader. Each call to
4111 * this method returns a new instance of a Context object; Context objects
4112 * are not shared, however they share common state (Resources, ClassLoader,
4113 * etc) so the Context instance itself is fairly lightweight.
4114 *
Jeff Brown6e539312015-02-24 18:53:21 -08004115 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 * application with the given package name.
4117 *
4118 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4119 * can not be loaded into the caller's process for security reasons (see
4120 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4121 *
4122 * @param packageName Name of the application's package.
4123 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
4124 * or {@link #CONTEXT_IGNORE_SECURITY}.
4125 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004126 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004127 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004128 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004129 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004130 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004131 */
4132 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004133 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004134
4135 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004136 * Similar to {@link #createPackageContext(String, int)}, but with a
4137 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4138 * will open any {@link Uri} as the given user.
4139 *
4140 * @hide
4141 */
4142 public abstract Context createPackageContextAsUser(
4143 String packageName, int flags, UserHandle user)
4144 throws PackageManager.NameNotFoundException;
4145
4146 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004147 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4148 *
4149 * @hide
4150 */
4151 public abstract Context createApplicationContext(ApplicationInfo application,
4152 int flags) throws PackageManager.NameNotFoundException;
4153
4154 /**
Jim Millera75a8832013-02-07 16:53:32 -08004155 * Get the userId associated with this context
4156 * @return user id
4157 *
4158 * @hide
4159 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004160 @TestApi
Jeff Sharkey8588bc12016-01-06 16:47:42 -07004161 public abstract @UserIdInt int getUserId();
Jim Millera75a8832013-02-07 16:53:32 -08004162
4163 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004164 * Return a new Context object for the current Context but whose resources
4165 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004166 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004167 * shared, however common state (ClassLoader, other Resources for the
4168 * same configuration) may be so the Context itself can be fairly lightweight.
4169 *
4170 * @param overrideConfiguration A {@link Configuration} specifying what
4171 * values to modify in the base Configuration of the original Context's
4172 * resources. If the base configuration changes (such as due to an
4173 * orientation change), the resources of this context will also change except
4174 * for those that have been explicitly overridden with a value here.
4175 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004176 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004177 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004178 public abstract Context createConfigurationContext(
4179 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004180
4181 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004182 * Return a new Context object for the current Context but whose resources
4183 * are adjusted to match the metrics of the given Display. Each call to this method
4184 * returns a new instance of a Context object; Context objects are not
4185 * shared, however common state (ClassLoader, other Resources for the
4186 * same configuration) may be so the Context itself can be fairly lightweight.
4187 *
4188 * The returned display Context provides a {@link WindowManager}
4189 * (see {@link #getSystemService(String)}) that is configured to show windows
4190 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4191 * method can be used to retrieve the Display from the returned Context.
4192 *
4193 * @param display A {@link Display} object specifying the display
4194 * for whose metrics the Context's resources should be tailored and upon which
4195 * new windows should be shown.
4196 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004197 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004198 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004199 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004200
4201 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004202 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004203 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004204 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004205 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004206 * with a key tied to the physical device, and it can be accessed
4207 * immediately after the device has booted successfully, both
4208 * <em>before and after</em> the user has authenticated with their
4209 * credentials (such as a lock pattern or PIN).
4210 * <p>
4211 * Because device-protected data is available without user authentication,
4212 * you should carefully limit the data you store using this Context. For
4213 * example, storing sensitive authentication tokens or passwords in the
4214 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004215 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004216 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004217 * device-protected and credential-protected data using different keys, then
4218 * both storage areas will become available at the same time. They remain as
4219 * two distinct storage locations on disk, and only the window of
4220 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004221 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004222 * Each call to this method returns a new instance of a Context object;
4223 * Context objects are not shared, however common state (ClassLoader, other
4224 * Resources for the same configuration) may be so the Context itself can be
4225 * fairly lightweight.
4226 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004227 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004228 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004229 public abstract Context createDeviceProtectedStorageContext();
4230
4231 /** @removed */
4232 @Deprecated
4233 public Context createDeviceEncryptedStorageContext() {
4234 return createDeviceProtectedStorageContext();
4235 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004236
4237 /**
4238 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004239 * APIs are backed by credential-protected storage. This is the default
4240 * storage area for apps unless
4241 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004242 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004243 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004244 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004245 * <em>only after</em> the user has entered their credentials (such as a
4246 * lock pattern or PIN).
4247 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004248 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004249 * device-protected and credential-protected data using different keys, then
4250 * both storage areas will become available at the same time. They remain as
4251 * two distinct storage locations on disk, and only the window of
4252 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004253 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004254 * Each call to this method returns a new instance of a Context object;
4255 * Context objects are not shared, however common state (ClassLoader, other
4256 * Resources for the same configuration) may be so the Context itself can be
4257 * fairly lightweight.
4258 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004259 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004260 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004261 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004262 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004263 public abstract Context createCredentialProtectedStorageContext();
4264
4265 /** @removed */
4266 @Deprecated
4267 public Context createCredentialEncryptedStorageContext() {
4268 return createCredentialProtectedStorageContext();
4269 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004270
4271 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004272 * Gets the display adjustments holder for this context. This information
4273 * is provided on a per-application or activity basis and is used to simulate lower density
4274 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004275 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004276 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004277 * @return The compatibility info holder, or null if not required by the application.
4278 * @hide
4279 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004280 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004281
4282 /**
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004283 * @hide
4284 */
4285 public abstract Display getDisplay();
4286
4287 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004288 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004289 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004290 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004291 *
Romain Guy870e09f2009-07-06 16:35:25 -07004292 * @see #CONTEXT_RESTRICTED
4293 */
4294 public boolean isRestricted() {
4295 return false;
4296 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004297
4298 /**
4299 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004300 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004301 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004302 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004303 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004304 public abstract boolean isDeviceProtectedStorage();
4305
4306 /** @removed */
4307 @Deprecated
4308 public boolean isDeviceEncryptedStorage() {
4309 return isDeviceProtectedStorage();
4310 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004311
4312 /**
4313 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004314 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004315 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004316 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004317 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004318 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004319 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004320 public abstract boolean isCredentialProtectedStorage();
4321
4322 /** @removed */
4323 @Deprecated
4324 public boolean isCredentialEncryptedStorage() {
4325 return isCredentialProtectedStorage();
4326 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327}