blob: a43d06ed5ae0dcea981bbcbccf34ba08445de7f3 [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 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700288 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
289 * but only applies while the device is awake.
290 */
291 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
292
293 /**
294 * @hide Flag for {@link #bindService}: For only the case where the binding
295 * is coming from the system, set the process state to FOREGROUND_SERVICE
296 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
297 * saying that the process shouldn't participate in the normal power reduction
298 * modes (removing network access etc).
299 */
300 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
301
302 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700303 * @hide Flag for {@link #bindService}: Treat the binding as hosting
304 * an activity, an unbinding as the activity going in the background.
305 * That is, when unbinding, the process when empty will go on the activity
306 * LRU list instead of the regular one, keeping it around more aggressively
307 * than it otherwise would be. This is intended for use with IMEs to try
308 * to keep IME processes around for faster keyboard switching.
309 */
310 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
311
312 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700313 * @hide An idea that is not yet implemented.
314 * Flag for {@link #bindService}: If binding from an activity, consider
315 * this service to be visible like the binding activity is. That is,
316 * it will be treated as something more important to keep around than
317 * invisible background activities. This will impact the number of
318 * recent activities the user can switch between without having them
319 * restart. There is no guarantee this will be respected, as the system
320 * tries to balance such requests from one app vs. the importantance of
321 * keeping other apps around.
322 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700323 public static final int BIND_VISIBLE = 0x10000000;
324
325 /**
326 * @hide
327 * Flag for {@link #bindService}: Consider this binding to be causing the target
328 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
329 * away.
330 */
331 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700332
333 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700334 * Flag for {@link #bindService}: Don't consider the bound service to be
335 * visible, even if the caller is visible.
336 * @hide
337 */
338 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700339
Alan Viverette713a5cd2015-12-16 15:46:32 -0500340 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500341 * Flag for {@link #bindService}: The service being bound is an
342 * {@link android.R.attr#isolatedProcess isolated},
343 * {@link android.R.attr#externalService external} service. This binds the service into the
344 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400345 * <p>
346 * When using this flag, the code for the service being bound will execute under the calling
347 * application's package name and user ID. Because the service must be an isolated process,
348 * it will not have direct access to the application's data, though.
349 *
350 * The purpose of this flag is to allow applications to provide services that are attributed
351 * to the app using the service, rather than the application providing the service.
352 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500353 */
354 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
355
356 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500357 * Returns an AssetManager instance for the application's package.
358 * <p>
359 * <strong>Note:</strong> Implementations of this method should return
360 * an AssetManager instance that is consistent with the Resources instance
361 * returned by {@link #getResources()}. For example, they should share the
362 * same {@link Configuration} object.
363 *
364 * @return an AssetManager instance for the application's package
365 * @see #getResources()
366 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 public abstract AssetManager getAssets();
368
Alan Viverette713a5cd2015-12-16 15:46:32 -0500369 /**
370 * Returns a Resources instance for the application's package.
371 * <p>
372 * <strong>Note:</strong> Implementations of this method should return
373 * a Resources instance that is consistent with the AssetManager instance
374 * returned by {@link #getAssets()}. For example, they should share the
375 * same {@link Configuration} object.
376 *
377 * @return a Resources instance for the application's package
378 * @see #getAssets()
379 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800380 public abstract Resources getResources();
381
382 /** Return PackageManager instance to find global package information. */
383 public abstract PackageManager getPackageManager();
384
385 /** Return a ContentResolver instance for your application's package. */
386 public abstract ContentResolver getContentResolver();
387
388 /**
389 * Return the Looper for the main thread of the current process. This is
390 * the thread used to dispatch calls to application components (activities,
391 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700392 * <p>
393 * By definition, this method returns the same result as would be obtained
394 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
395 * </p>
396 *
397 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800398 */
399 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 /**
402 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800403 * current process. This generally should only be used if you need a
404 * Context whose lifecycle is separate from the current context, that is
405 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700406 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800407 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800408 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800409 * <ul>
410 * <li> <p>If used from an Activity context, the receiver is being registered
411 * within that activity. This means that you are expected to unregister
412 * before the activity is done being destroyed; in fact if you do not do
413 * so, the framework will clean up your leaked registration as it removes
414 * the activity and log an error. Thus, if you use the Activity context
415 * to register a receiver that is static (global to the process, not
416 * associated with an Activity instance) then that registration will be
417 * removed on you at whatever point the activity you used is destroyed.
418 * <li> <p>If used from the Context returned here, the receiver is being
419 * registered with the global state associated with your application. Thus
420 * it will never be unregistered for you. This is necessary if the receiver
421 * is associated with static data, not a particular component. However
422 * using the ApplicationContext elsewhere can easily lead to serious leaks
423 * if you forget to unregister, unbind, etc.
424 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 */
426 public abstract Context getApplicationContext();
427
428 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700429 * Add a new {@link ComponentCallbacks} to the base application of the
430 * Context, which will be called at the same times as the ComponentCallbacks
431 * methods of activities and other components are called. Note that you
432 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
433 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700434 *
435 * @param callback The interface to call. This can be either a
436 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700437 */
438 public void registerComponentCallbacks(ComponentCallbacks callback) {
439 getApplicationContext().registerComponentCallbacks(callback);
440 }
441
442 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400443 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700444 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
445 */
446 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
447 getApplicationContext().unregisterComponentCallbacks(callback);
448 }
449
450 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451 * Return a localized, styled CharSequence from the application's package's
452 * default string table.
453 *
454 * @param resId Resource id for the CharSequence text
455 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700456 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 return getResources().getText(resId);
458 }
459
460 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700461 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 * default string table.
463 *
464 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700465 * @return The string data associated with the resource, stripped of styled
466 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700468 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700469 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 return getResources().getString(resId);
471 }
472
473 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700474 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 * default string table, substituting the format arguments as defined in
476 * {@link java.util.Formatter} and {@link java.lang.String#format}.
477 *
478 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700479 * @param formatArgs The format arguments that will be used for
480 * substitution.
481 * @return The string data associated with the resource, formatted and
482 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700484 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700485 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 return getResources().getString(resId, formatArgs);
487 }
488
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800489 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800490 * Returns a color associated with a particular resource ID and styled for
491 * the current theme.
492 *
493 * @param id The desired resource identifier, as generated by the aapt
494 * tool. This integer encodes the package, type, and resource
495 * entry. The value 0 is an invalid identifier.
496 * @return A single color value in the form 0xAARRGGBB.
497 * @throws android.content.res.Resources.NotFoundException if the given ID
498 * does not exist.
499 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700500 @ColorInt
501 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800502 return getResources().getColor(id, getTheme());
503 }
504
505 /**
506 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800507 * styled for the current theme.
508 *
509 * @param id The desired resource identifier, as generated by the aapt
510 * tool. This integer encodes the package, type, and resource
511 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800512 * @return An object that can be used to draw this resource, or
513 * {@code null} if the resource could not be resolved.
514 * @throws android.content.res.Resources.NotFoundException if the given ID
515 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800516 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800517 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700518 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800519 return getResources().getDrawable(id, getTheme());
520 }
521
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800522 /**
523 * Returns a color state list associated with a particular resource ID and
524 * styled for the current theme.
525 *
526 * @param id The desired resource identifier, as generated by the aapt
527 * tool. This integer encodes the package, type, and resource
528 * entry. The value 0 is an invalid identifier.
529 * @return A color state list, or {@code null} if the resource could not be
530 * resolved.
531 * @throws android.content.res.Resources.NotFoundException if the given ID
532 * does not exist.
533 */
534 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700535 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800536 return getResources().getColorStateList(id, getTheme());
537 }
538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 /**
540 * Set the base theme for this context. Note that this should be called
541 * before any views are instantiated in the Context (for example before
542 * calling {@link android.app.Activity#setContentView} or
543 * {@link android.view.LayoutInflater#inflate}).
544 *
545 * @param resid The style resource describing the theme.
546 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700547 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548
Dianne Hackborn247fe742011-01-08 17:25:57 -0800549 /** @hide Needed for some internal implementation... not public because
550 * you can't assume this actually means anything. */
551 public int getThemeResId() {
552 return 0;
553 }
554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 /**
556 * Return the Theme object associated with this Context.
557 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700558 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 public abstract Resources.Theme getTheme();
560
561 /**
562 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800563 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 * for more information.
565 *
Jeff Brown6e539312015-02-24 18:53:21 -0800566 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700568 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 return getTheme().obtainStyledAttributes(attrs);
570 }
571
572 /**
573 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800574 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 * for more information.
576 *
Jeff Brown6e539312015-02-24 18:53:21 -0800577 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800578 */
579 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700580 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 return getTheme().obtainStyledAttributes(resid, attrs);
582 }
583
584 /**
585 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800586 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 * for more information.
588 *
Jeff Brown6e539312015-02-24 18:53:21 -0800589 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 */
591 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700592 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
594 }
595
596 /**
597 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800598 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 * for more information.
600 *
Jeff Brown6e539312015-02-24 18:53:21 -0800601 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 */
603 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700604 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
605 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 return getTheme().obtainStyledAttributes(
607 set, attrs, defStyleAttr, defStyleRes);
608 }
609
610 /**
611 * Return a class loader you can use to retrieve classes in this package.
612 */
613 public abstract ClassLoader getClassLoader();
614
615 /** Return the name of this application's package. */
616 public abstract String getPackageName();
617
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800618 /** @hide Return the name of the base context this context is derived from. */
619 public abstract String getBasePackageName();
620
Dianne Hackborn95d78532013-09-11 09:51:14 -0700621 /** @hide Return the package name that should be used for app ops calls from
622 * this context. This is the same as {@link #getBasePackageName()} except in
623 * cases where system components are loaded into other app processes, in which
624 * case this will be the name of the primary package in that process (so that app
625 * ops uid verification will work with the name). */
626 public abstract String getOpPackageName();
627
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700628 /** Return the full application info for this context's package. */
629 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700630
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 /**
Kenny Root32148392010-01-21 15:40:47 -0800632 * Return the full path to this context's primary Android package.
633 * The Android package is a ZIP file which contains the application's
634 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 *
636 * <p>Note: this is not generally useful for applications, since they should
637 * not be directly accessing the file system.
638 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 * @return String Path to the resources.
640 */
641 public abstract String getPackageResourcePath();
642
643 /**
Kenny Root32148392010-01-21 15:40:47 -0800644 * Return the full path to this context's primary Android package.
645 * The Android package is a ZIP file which contains application's
646 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 *
648 * <p>Note: this is not generally useful for applications, since they should
649 * not be directly accessing the file system.
650 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 * @return String Path to the code and assets.
652 */
653 public abstract String getPackageCodePath();
654
655 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700656 * @hide
657 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700658 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700659 @Deprecated
660 public File getSharedPrefsFile(String name) {
661 return getSharedPreferencesPath(name);
662 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700663
664 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 * Retrieve and hold the contents of the preferences file 'name', returning
666 * a SharedPreferences through which you can retrieve and modify its
667 * values. Only one instance of the SharedPreferences object is returned
668 * to any callers for the same name, meaning they will see each other's
669 * edits as soon as they are made.
670 *
671 * @param name Desired preferences file. If a preferences file by this name
672 * does not exist, it will be created when you retrieve an
673 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
674 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700675 * default operation.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400677 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 * to retrieve and modify the preference values.
679 *
680 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 */
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700682 public abstract SharedPreferences getSharedPreferences(String name, int mode);
683
684 /**
685 * Retrieve and hold the contents of the preferences file, returning
686 * a SharedPreferences through which you can retrieve and modify its
687 * values. Only one instance of the SharedPreferences object is returned
688 * to any callers for the same name, meaning they will see each other's
689 * edits as soon as they are made.
690 *
691 * @param file Desired preferences file. If a preferences file by this name
692 * does not exist, it will be created when you retrieve an
693 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
694 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700695 * default operation.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700696 *
697 * @return The single {@link SharedPreferences} instance that can be used
698 * to retrieve and modify the preference values.
699 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700700 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700701 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600702 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700703 */
704 public abstract SharedPreferences getSharedPreferences(File file, int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705
706 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600707 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700708 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600709 * storage locations after an upgrade, such as moving to device protected
710 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700711 *
712 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600713 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700714 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600715 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700716 * preferences didn't exist in the source context, otherwise
717 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600718 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700719 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600720 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
721
722 /** @removed */
723 @Deprecated
724 public boolean migrateSharedPreferencesFrom(Context sourceContext, String name) {
725 return moveSharedPreferencesFrom(sourceContext, name);
726 }
Jeff Sharkey35871f22016-01-29 17:13:29 -0700727
728 /**
729 * Delete an existing shared preferences file.
730 *
731 * @param name The name (unique in the application package) of the shared
732 * preferences file.
733 * @return {@code true} if the shared preferences file was successfully
734 * deleted; else {@code false}.
735 * @see #getSharedPreferences(String, int)
736 */
737 public abstract boolean deleteSharedPreferences(String name);
738
739 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 * Open a private file associated with this Context's application package
741 * for reading.
742 *
743 * @param name The name of the file to open; can not contain path
744 * separators.
745 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400746 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 *
748 * @see #openFileOutput
749 * @see #fileList
750 * @see #deleteFile
751 * @see java.io.FileInputStream#FileInputStream(String)
752 */
753 public abstract FileInputStream openFileInput(String name)
754 throws FileNotFoundException;
755
756 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800757 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700758 * for writing. Creates the file if it doesn't already exist.
759 * <p>
760 * No additional permissions are required for the calling app to read or
761 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700762 *
Nick Kralevich15069212013-01-09 15:54:56 -0800763 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700764 * separators.
765 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700766 * default operation. Use {@link #MODE_APPEND} to append to an
767 * existing file.
John Spurlock6098c5d2013-06-17 10:32:46 -0400768 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 * @see #MODE_APPEND
770 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 * @see #openFileInput
772 * @see #fileList
773 * @see #deleteFile
774 * @see java.io.FileOutputStream#FileOutputStream(String)
775 */
776 public abstract FileOutputStream openFileOutput(String name, int mode)
777 throws FileNotFoundException;
778
779 /**
780 * Delete the given private file associated with this Context's
781 * application package.
782 *
783 * @param name The name of the file to delete; can not contain path
784 * separators.
785 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400786 * @return {@code true} if the file was successfully deleted; else
787 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 *
789 * @see #openFileInput
790 * @see #openFileOutput
791 * @see #fileList
792 * @see java.io.File#delete()
793 */
794 public abstract boolean deleteFile(String name);
795
796 /**
797 * Returns the absolute path on the filesystem where a file created with
798 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700799 * <p>
800 * The returned path may change over time if the calling app is moved to an
801 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800802 *
803 * @param name The name of the file for which you would like to get
804 * its path.
805 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400806 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800807 *
808 * @see #openFileOutput
809 * @see #getFilesDir
810 * @see #getDir
811 */
812 public abstract File getFileStreamPath(String name);
813
814 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700815 * Returns the absolute path on the filesystem where a file created with
816 * {@link #getSharedPreferences(String, int)} is stored.
817 * <p>
818 * The returned path may change over time if the calling app is moved to an
819 * adopted storage device, so only relative paths should be persisted.
820 *
821 * @param name The name of the shared preferences for which you would like
822 * to get a path.
823 * @return An absolute path to the given file.
824 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600825 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700826 */
827 public abstract File getSharedPreferencesPath(String name);
828
829 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700830 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600831 * private files belonging to this app are stored. Apps should not use this
832 * path directly; they should instead use {@link #getFilesDir()},
833 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
834 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700835 * <p>
836 * The returned path may change over time if the calling app is moved to an
837 * adopted storage device, so only relative paths should be persisted.
838 * <p>
839 * No additional permissions are required for the calling app to read or
840 * write files under the returned path.
841 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600842 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700843 */
844 public abstract File getDataDir();
845
846 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700847 * Returns the absolute path to the directory on the filesystem where files
848 * created with {@link #openFileOutput} are stored.
849 * <p>
850 * The returned path may change over time if the calling app is moved to an
851 * adopted storage device, so only relative paths should be persisted.
852 * <p>
853 * No additional permissions are required for the calling app to read or
854 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700855 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400856 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800857 * @see #openFileOutput
858 * @see #getFileStreamPath
859 * @see #getDir
860 */
861 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800863 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700864 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700865 * {@link #getFilesDir()}. The difference is that files placed under this
866 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700867 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
868 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700869 * <p>
870 * The returned path may change over time if the calling app is moved to an
871 * adopted storage device, so only relative paths should be persisted.
872 * <p>
873 * No additional permissions are required for the calling app to read or
874 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700875 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700876 * @return The path of the directory holding application files that will not
877 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700878 * @see #openFileOutput
879 * @see #getFileStreamPath
880 * @see #getDir
881 * @see android.app.backup.BackupAgent
882 */
883 public abstract File getNoBackupFilesDir();
884
885 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700886 * Returns the absolute path to the directory on the primary shared/external
887 * storage device where the application can place persistent files it owns.
888 * These files are internal to the applications, and not typically visible
889 * to the user as media.
890 * <p>
891 * This is like {@link #getFilesDir()} in that these files will be deleted
892 * when the application is uninstalled, however there are some important
893 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800894 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700895 * <li>Shared storage may not always be available, since removable media can
896 * be ejected by the user. Media state can be checked using
897 * {@link Environment#getExternalStorageState(File)}.
898 * <li>There is no security enforced with these files. For example, any
899 * application holding
900 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700901 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800902 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700903 * <p>
904 * If a shared storage device is emulated (as determined by
905 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
906 * backed by a private user data partition, which means there is little
907 * benefit to storing data here instead of the private directories returned
908 * by {@link #getFilesDir()}, etc.
909 * <p>
910 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700911 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700912 * accessible to the calling app. This only applies to paths generated for
913 * package name of the calling application. To access paths belonging to
914 * other packages,
915 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
916 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
917 * <p>
918 * On devices with multiple users (as described by {@link UserManager}),
919 * each user has their own isolated shared storage. Applications only have
920 * access to the shared storage for the user they're running as.
921 * <p>
922 * The returned path may change over time if different shared storage media
923 * is inserted, so only relative paths should be persisted.
924 * <p>
925 * Here is an example of typical code to manipulate a file in an
926 * application's shared storage:
927 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800928 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
929 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700930 * <p>
931 * If you supply a non-null <var>type</var> to this function, the returned
932 * file will be a path to a sub-directory of the given type. Though these
933 * files are not automatically scanned by the media scanner, you can
934 * explicitly add them to the media database with
935 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
936 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800937 * {@link android.os.Environment#getExternalStoragePublicDirectory
938 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700939 * directories of media shared by all applications. The directories returned
940 * here are owned by the application, and their contents will be removed
941 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800942 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700943 * Environment.getExternalStoragePublicDirectory()}, the directory returned
944 * here will be automatically created for you.
945 * <p>
946 * Here is an example of typical code to manipulate a picture in an
947 * application's shared storage and add it to the media database:
948 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800949 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
950 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700951 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700952 * @param type The type of files directory to return. May be {@code null}
953 * for the root of the files directory or one of the following
954 * constants for a subdirectory:
955 * {@link android.os.Environment#DIRECTORY_MUSIC},
956 * {@link android.os.Environment#DIRECTORY_PODCASTS},
957 * {@link android.os.Environment#DIRECTORY_RINGTONES},
958 * {@link android.os.Environment#DIRECTORY_ALARMS},
959 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
960 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
961 * {@link android.os.Environment#DIRECTORY_MOVIES}.
962 * @return the absolute path to application-specific directory. May return
963 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800964 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700965 * @see #getExternalFilesDirs(String)
966 * @see Environment#getExternalStorageState(File)
967 * @see Environment#isExternalStorageEmulated(File)
968 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800969 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700970 @Nullable
971 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700972
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800973 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700974 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700975 * shared/external storage devices where the application can place
976 * persistent files it owns. These files are internal to the application,
977 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700978 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700979 * This is like {@link #getFilesDir()} in that these files will be deleted
980 * when the application is uninstalled, however there are some important
981 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700982 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700983 * <li>Shared storage may not always be available, since removable media can
984 * be ejected by the user. Media state can be checked using
985 * {@link Environment#getExternalStorageState(File)}.
986 * <li>There is no security enforced with these files. For example, any
987 * application holding
988 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
989 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700990 * </ul>
991 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700992 * If a shared storage device is emulated (as determined by
993 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
994 * backed by a private user data partition, which means there is little
995 * benefit to storing data here instead of the private directories returned
996 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700997 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700998 * Shared storage devices returned here are considered a stable part of the
999 * device, including physical media slots under a protective cover. The
1000 * returned paths do not include transient devices, such as USB flash drives
1001 * connected to handheld devices.
1002 * <p>
1003 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001004 * example, an app may choose to store large files on the device with the
1005 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001006 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001007 * No additional permissions are required for the calling app to read or
1008 * write files under the returned path. Write access outside of these paths
1009 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001010 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001011 * The returned path may change over time if different shared storage media
1012 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001013 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001014 * @param type The type of files directory to return. May be {@code null}
1015 * for the root of the files directory or one of the following
1016 * constants for a subdirectory:
1017 * {@link android.os.Environment#DIRECTORY_MUSIC},
1018 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1019 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1020 * {@link android.os.Environment#DIRECTORY_ALARMS},
1021 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1022 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1023 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1024 * @return the absolute paths to application-specific directories. Some
1025 * individual paths may be {@code null} if that shared storage is
1026 * not currently available. The first path returned is the same as
1027 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001028 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001029 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001030 * @see Environment#isExternalStorageEmulated(File)
1031 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001032 */
1033 public abstract File[] getExternalFilesDirs(String type);
1034
1035 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001036 * Return the primary shared/external storage directory where this
1037 * application's OBB files (if there are any) can be found. Note if the
1038 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001039 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001040 * This is like {@link #getFilesDir()} in that these files will be deleted
1041 * when the application is uninstalled, however there are some important
1042 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001043 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001044 * <li>Shared storage may not always be available, since removable media can
1045 * be ejected by the user. Media state can be checked using
1046 * {@link Environment#getExternalStorageState(File)}.
1047 * <li>There is no security enforced with these files. For example, any
1048 * application holding
1049 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001050 * these files.
1051 * </ul>
1052 * <p>
1053 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1054 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001055 * accessible to the calling app. This only applies to paths generated for
1056 * package name of the calling application. To access paths belonging to
1057 * other packages,
1058 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1059 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001060 * <p>
1061 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001062 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001063 * should ensure that multiple instances running under different users don't
1064 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001065 *
1066 * @return the absolute path to application-specific directory. May return
1067 * {@code null} if shared storage is not currently available.
1068 * @see #getObbDirs()
1069 * @see Environment#getExternalStorageState(File)
1070 * @see Environment#isExternalStorageEmulated(File)
1071 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001072 */
1073 public abstract File getObbDir();
1074
1075 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001076 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001077 * shared/external storage devices where the application's OBB files (if
1078 * there are any) can be found. Note if the application does not have any
1079 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001080 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001081 * This is like {@link #getFilesDir()} in that these files will be deleted
1082 * when the application is uninstalled, however there are some important
1083 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001084 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001085 * <li>Shared storage may not always be available, since removable media can
1086 * be ejected by the user. Media state can be checked using
1087 * {@link Environment#getExternalStorageState(File)}.
1088 * <li>There is no security enforced with these files. For example, any
1089 * application holding
1090 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1091 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001092 * </ul>
1093 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001094 * Shared storage devices returned here are considered a stable part of the
1095 * device, including physical media slots under a protective cover. The
1096 * returned paths do not include transient devices, such as USB flash drives
1097 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001098 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001099 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001100 * example, an app may choose to store large files on the device with the
1101 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001102 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001103 * No additional permissions are required for the calling app to read or
1104 * write files under the returned path. Write access outside of these paths
1105 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001106 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001107 * @return the absolute paths to application-specific directories. Some
1108 * individual paths may be {@code null} if that shared storage is
1109 * not currently available. The first path returned is the same as
1110 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001111 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001112 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001113 * @see Environment#isExternalStorageEmulated(File)
1114 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001115 */
1116 public abstract File[] getObbDirs();
1117
1118 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001119 * Returns the absolute path to the application specific cache directory on
1120 * the filesystem. These files will be ones that get deleted first when the
1121 * device runs low on storage. There is no guarantee when these files will
1122 * be deleted.
1123 * <p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001124 * <strong>Note: you should not <em>rely</em> on the system deleting these
1125 * files for you; you should always have a reasonable maximum, such as 1 MB,
1126 * for the amount of space you consume with cache files, and prune those
1127 * files when exceeding that space.</strong>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001128 * <p>
1129 * The returned path may change over time if the calling app is moved to an
1130 * adopted storage device, so only relative paths should be persisted.
1131 * <p>
1132 * Apps require no extra permissions to read or write to the returned path,
1133 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001134 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001135 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 * @see #openFileOutput
1137 * @see #getFileStreamPath
1138 * @see #getDir
1139 */
1140 public abstract File getCacheDir();
1141
1142 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001143 * Returns the absolute path to the application specific cache directory on
1144 * the filesystem designed for storing cached code. The system will delete
1145 * any files stored in this location both when your specific application is
1146 * upgraded, and when the entire platform is upgraded.
1147 * <p>
1148 * This location is optimal for storing compiled or optimized code generated
1149 * by your application at runtime.
1150 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001151 * The returned path may change over time if the calling app is moved to an
1152 * adopted storage device, so only relative paths should be persisted.
1153 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001154 * Apps require no extra permissions to read or write to the returned path,
1155 * since this path lives in their private storage.
1156 *
1157 * @return The path of the directory holding application code cache files.
1158 */
1159 public abstract File getCodeCacheDir();
1160
1161 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001162 * Returns absolute path to application-specific directory on the primary
1163 * shared/external storage device where the application can place cache
1164 * files it owns. These files are internal to the application, and not
1165 * typically visible to the user as media.
1166 * <p>
1167 * This is like {@link #getCacheDir()} in that these files will be deleted
1168 * when the application is uninstalled, however there are some important
1169 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001170 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001171 * <li>The platform does not always monitor the space available in shared
1172 * storage, and thus may not automatically delete these files. Apps should
1173 * always manage the maximum space used in this location. Currently the only
1174 * time files here will be deleted by the platform is when running on
1175 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1176 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1177 * <li>Shared storage may not always be available, since removable media can
1178 * be ejected by the user. Media state can be checked using
1179 * {@link Environment#getExternalStorageState(File)}.
1180 * <li>There is no security enforced with these files. For example, any
1181 * application holding
1182 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001183 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001184 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001185 * <p>
1186 * If a shared storage device is emulated (as determined by
1187 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1188 * backed by a private user data partition, which means there is little
1189 * benefit to storing data here instead of the private directory returned by
1190 * {@link #getCacheDir()}.
1191 * <p>
1192 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001193 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001194 * accessible to the calling app. This only applies to paths generated for
1195 * package name of the calling application. To access paths belonging to
1196 * other packages,
1197 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1198 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1199 * <p>
1200 * On devices with multiple users (as described by {@link UserManager}),
1201 * each user has their own isolated shared storage. Applications only have
1202 * access to the shared storage for the user they're running as.
1203 * <p>
1204 * The returned path may change over time if different shared storage media
1205 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001206 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001207 * @return the absolute path to application-specific directory. May return
1208 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001209 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001210 * @see #getExternalCacheDirs()
1211 * @see Environment#getExternalStorageState(File)
1212 * @see Environment#isExternalStorageEmulated(File)
1213 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001214 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001215 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001216 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001217
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001218 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001219 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001220 * shared/external storage devices where the application can place cache
1221 * files it owns. These files are internal to the application, and not
1222 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001223 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001224 * This is like {@link #getCacheDir()} in that these files will be deleted
1225 * when the application is uninstalled, however there are some important
1226 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001227 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001228 * <li>The platform does not always monitor the space available in shared
1229 * storage, and thus may not automatically delete these files. Apps should
1230 * always manage the maximum space used in this location. Currently the only
1231 * time files here will be deleted by the platform is when running on
1232 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1233 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1234 * <li>Shared storage may not always be available, since removable media can
1235 * be ejected by the user. Media state can be checked using
1236 * {@link Environment#getExternalStorageState(File)}.
1237 * <li>There is no security enforced with these files. For example, any
1238 * application holding
1239 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1240 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001241 * </ul>
1242 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001243 * If a shared storage device is emulated (as determined by
1244 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1245 * backed by a private user data partition, which means there is little
1246 * benefit to storing data here instead of the private directory returned by
1247 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001248 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001249 * Shared storage devices returned here are considered a stable part of the
1250 * device, including physical media slots under a protective cover. The
1251 * returned paths do not include transient devices, such as USB flash drives
1252 * connected to handheld devices.
1253 * <p>
1254 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001255 * example, an app may choose to store large files on the device with the
1256 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001257 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001258 * No additional permissions are required for the calling app to read or
1259 * write files under the returned path. Write access outside of these paths
1260 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001261 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001262 * The returned paths may change over time if different shared storage media
1263 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001264 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001265 * @return the absolute paths to application-specific directories. Some
1266 * individual paths may be {@code null} if that shared storage is
1267 * not currently available. The first path returned is the same as
1268 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001269 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001270 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001271 * @see Environment#isExternalStorageEmulated(File)
1272 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001273 */
1274 public abstract File[] getExternalCacheDirs();
1275
1276 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001277 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001278 * shared/external storage devices where the application can place media
1279 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001280 * {@link MediaStore}.
1281 * <p>
1282 * This is like {@link #getExternalFilesDirs} in that these files will be
1283 * deleted when the application is uninstalled, however there are some
1284 * important differences:
1285 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001286 * <li>Shared storage may not always be available, since removable media can
1287 * be ejected by the user. Media state can be checked using
1288 * {@link Environment#getExternalStorageState(File)}.
1289 * <li>There is no security enforced with these files. For example, any
1290 * application holding
1291 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1292 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001293 * </ul>
1294 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001295 * Shared storage devices returned here are considered a stable part of the
1296 * device, including physical media slots under a protective cover. The
1297 * returned paths do not include transient devices, such as USB flash drives
1298 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001299 * <p>
1300 * An application may store data on any or all of the returned devices. For
1301 * example, an app may choose to store large files on the device with the
1302 * most available space, as measured by {@link StatFs}.
1303 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001304 * No additional permissions are required for the calling app to read or
1305 * write files under the returned path. Write access outside of these paths
1306 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001307 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001308 * The returned paths may change over time if different shared storage media
1309 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001310 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001311 * @return the absolute paths to application-specific directories. Some
1312 * individual paths may be {@code null} if that shared storage is
1313 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001314 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001315 * @see Environment#isExternalStorageEmulated(File)
1316 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001317 */
1318 public abstract File[] getExternalMediaDirs();
1319
1320 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 * Returns an array of strings naming the private files associated with
1322 * this Context's application package.
1323 *
1324 * @return Array of strings naming the private files.
1325 *
1326 * @see #openFileInput
1327 * @see #openFileOutput
1328 * @see #deleteFile
1329 */
1330 public abstract String[] fileList();
1331
1332 /**
1333 * Retrieve, creating if needed, a new directory in which the application
1334 * can place its own custom data files. You can use the returned File
1335 * object to create and access files in this directory. Note that files
1336 * created through a File object will only be accessible by your own
1337 * application; you can only set the mode of the entire directory, not
1338 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001339 * <p>
1340 * The returned path may change over time if the calling app is moved to an
1341 * adopted storage device, so only relative paths should be persisted.
1342 * <p>
1343 * Apps require no extra permissions to read or write to the returned path,
1344 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001346 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001347 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001348 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -07001349 * default operation.
Nick Kralevich15069212013-01-09 15:54:56 -08001350 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001351 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001352 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 *
1354 * @see #openFileOutput(String, int)
1355 */
1356 public abstract File getDir(String name, int mode);
1357
1358 /**
1359 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001360 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001361 *
1362 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001363 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1364 * default operation. Use
1365 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1366 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1367 * to disable localized collators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001369 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001371 * @throws android.database.sqlite.SQLiteException if the database file
1372 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001374 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001375 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001376 * @see #deleteDatabase
1377 */
1378 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1379 int mode, CursorFactory factory);
1380
1381 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001382 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001383 * application package. Creates the database file if it doesn't exist.
1384 * <p>
1385 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1386 * to be used to handle corruption when sqlite reports database corruption.
1387 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001388 *
1389 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001390 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1391 * default operation. Use
1392 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1393 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1394 * to disable localized collators.
Vasu Nori74f170f2010-06-01 18:06:18 -07001395 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001396 * cursor when query is called.
1397 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1398 * sqlite reports database corruption. if null,
1399 * {@link android.database.DefaultDatabaseErrorHandler} is
1400 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001401 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001402 * @throws android.database.sqlite.SQLiteException if the database file
1403 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001404 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001405 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001406 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001407 * @see #deleteDatabase
1408 */
1409 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001410 int mode, CursorFactory factory,
1411 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001412
1413 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001414 * Move an existing database file from the given source storage context to
1415 * this context. This is typically used to migrate data between storage
1416 * locations after an upgrade, such as migrating to device protected
1417 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001418 *
1419 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001420 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001421 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001422 * @return {@code true} if the move was successful or if the database didn't
1423 * exist in the source context, otherwise {@code false}.
1424 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001425 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001426 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1427
1428 /** @removed */
1429 @Deprecated
1430 public boolean migrateDatabaseFrom(Context sourceContext, String name) {
1431 return moveDatabaseFrom(sourceContext, name);
1432 }
Jeff Sharkey35871f22016-01-29 17:13:29 -07001433
1434 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 * Delete an existing private SQLiteDatabase associated with this Context's
1436 * application package.
1437 *
1438 * @param name The name (unique in the application package) of the
1439 * database.
1440 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001441 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001442 *
1443 * @see #openOrCreateDatabase
1444 */
1445 public abstract boolean deleteDatabase(String name);
1446
1447 /**
1448 * Returns the absolute path on the filesystem where a database created with
1449 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001450 * <p>
1451 * The returned path may change over time if the calling app is moved to an
1452 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001453 *
1454 * @param name The name of the database for which you would like to get
1455 * its path.
1456 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001457 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 *
1459 * @see #openOrCreateDatabase
1460 */
1461 public abstract File getDatabasePath(String name);
1462
1463 /**
1464 * Returns an array of strings naming the private databases associated with
1465 * this Context's application package.
1466 *
1467 * @return Array of strings naming the private databases.
1468 *
1469 * @see #openOrCreateDatabase
1470 * @see #deleteDatabase
1471 */
1472 public abstract String[] databaseList();
1473
1474 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001475 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001476 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001477 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001478 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001479 public abstract Drawable getWallpaper();
1480
1481 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001482 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001483 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001484 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001485 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 public abstract Drawable peekWallpaper();
1487
1488 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001489 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1490 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001491 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001492 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 public abstract int getWallpaperDesiredMinimumWidth();
1494
1495 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001496 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1497 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001499 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 public abstract int getWallpaperDesiredMinimumHeight();
1501
1502 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001503 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001504 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001505 * <p>This method requires the caller to hold the permission
1506 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001508 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1510
1511 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001512 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001513 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001514 * <p>This method requires the caller to hold the permission
1515 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001517 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001518 public abstract void setWallpaper(InputStream data) throws IOException;
1519
1520 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001521 * @deprecated Use {@link android.app.WallpaperManager#clear
1522 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001523 * <p>This method requires the caller to hold the permission
1524 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001526 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 public abstract void clearWallpaper() throws IOException;
1528
1529 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001530 * Same as {@link #startActivity(Intent, Bundle)} with no options
1531 * specified.
1532 *
1533 * @param intent The description of the activity to start.
1534 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001535 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001536 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001537 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001538 * @see PackageManager#resolveActivity
1539 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001540 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001541
1542 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001543 * Version of {@link #startActivity(Intent)} that allows you to specify the
1544 * user the activity will be started for. This is not available to applications
1545 * that are not pre-installed on the system image. Using it requires holding
1546 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001547 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001548 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001549 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001550 * @hide
1551 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001552 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001553 throw new RuntimeException("Not implemented. Must override in a subclass.");
1554 }
1555
1556 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 * Launch a new activity. You will not receive any information about when
1558 * the activity exits.
1559 *
1560 * <p>Note that if this method is being called from outside of an
1561 * {@link android.app.Activity} Context, then the Intent must include
1562 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1563 * without being started from an existing Activity, there is no existing
1564 * task in which to place the new activity and thus it needs to be placed
1565 * in its own separate task.
1566 *
1567 * <p>This method throws {@link ActivityNotFoundException}
1568 * if there was no Activity found to run the given Intent.
1569 *
1570 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001571 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001572 * May be null if there are no options. See {@link android.app.ActivityOptions}
1573 * for how to build the Bundle supplied here; there are no supported definitions
1574 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001576 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001577 *
Scott Main60dd5202012-06-23 00:01:22 -07001578 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 * @see PackageManager#resolveActivity
1580 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001581 public abstract void startActivity(@RequiresPermission Intent intent,
1582 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001583
1584 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001585 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1586 * user the activity will be started for. This is not available to applications
1587 * that are not pre-installed on the system image. Using it requires holding
1588 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001589 * @param intent The description of the activity to start.
1590 * @param options Additional options for how the Activity should be started.
1591 * May be null if there are no options. See {@link android.app.ActivityOptions}
1592 * for how to build the Bundle supplied here; there are no supported definitions
1593 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001594 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001595 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001596 * @hide
1597 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001598 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1599 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001600 throw new RuntimeException("Not implemented. Must override in a subclass.");
1601 }
1602
1603 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001604 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1605 * is only supported for Views and Fragments.
1606 * @param who The identifier for the calling element that will receive the result.
1607 * @param intent The intent to start.
1608 * @param requestCode The code that will be returned with onActivityResult() identifying this
1609 * request.
1610 * @param options Additional options for how the Activity should be started.
1611 * May be null if there are no options. See {@link android.app.ActivityOptions}
1612 * for how to build the Bundle supplied here; there are no supported definitions
1613 * for building it manually.
1614 * @hide
1615 */
1616 public void startActivityForResult(
1617 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1618 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1619 + "Check canStartActivityForResult() before calling.");
1620 }
1621
1622 /**
1623 * Identifies whether this Context instance will be able to process calls to
1624 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1625 * @hide
1626 */
1627 public boolean canStartActivityForResult() {
1628 return false;
1629 }
1630
1631 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001632 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1633 * specified.
1634 *
1635 * @param intents An array of Intents to be started.
1636 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001637 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001638 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001639 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001640 * @see PackageManager#resolveActivity
1641 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001642 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643
1644 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001645 * Launch multiple new activities. This is generally the same as calling
1646 * {@link #startActivity(Intent)} for the first Intent in the array,
1647 * that activity during its creation calling {@link #startActivity(Intent)}
1648 * for the second entry, etc. Note that unlike that approach, generally
1649 * none of the activities except the last in the array will be created
1650 * at this point, but rather will be created when the user first visits
1651 * them (due to pressing back from the activity on top).
1652 *
1653 * <p>This method throws {@link ActivityNotFoundException}
1654 * if there was no Activity found for <em>any</em> given Intent. In this
1655 * case the state of the activity stack is undefined (some Intents in the
1656 * list may be on it, some not), so you probably want to avoid such situations.
1657 *
1658 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001659 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001660 * See {@link android.content.Context#startActivity(Intent, Bundle)
1661 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001662 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001663 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001664 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001665 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001666 * @see PackageManager#resolveActivity
1667 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001668 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001669
1670 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001671 * @hide
1672 * Launch multiple new activities. This is generally the same as calling
1673 * {@link #startActivity(Intent)} for the first Intent in the array,
1674 * that activity during its creation calling {@link #startActivity(Intent)}
1675 * for the second entry, etc. Note that unlike that approach, generally
1676 * none of the activities except the last in the array will be created
1677 * at this point, but rather will be created when the user first visits
1678 * them (due to pressing back from the activity on top).
1679 *
1680 * <p>This method throws {@link ActivityNotFoundException}
1681 * if there was no Activity found for <em>any</em> given Intent. In this
1682 * case the state of the activity stack is undefined (some Intents in the
1683 * list may be on it, some not), so you probably want to avoid such situations.
1684 *
1685 * @param intents An array of Intents to be started.
1686 * @param options Additional options for how the Activity should be started.
1687 * @param userHandle The user for whom to launch the activities
1688 * See {@link android.content.Context#startActivity(Intent, Bundle)
1689 * Context.startActivity(Intent, Bundle)} for more details.
1690 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001691 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001692 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001693 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001694 * @see PackageManager#resolveActivity
1695 */
1696 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1697 throw new RuntimeException("Not implemented. Must override in a subclass.");
1698 }
1699
1700 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001701 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1702 * with no options specified.
1703 *
1704 * @param intent The IntentSender to launch.
1705 * @param fillInIntent If non-null, this will be provided as the
1706 * intent parameter to {@link IntentSender#sendIntent}.
1707 * @param flagsMask Intent flags in the original IntentSender that you
1708 * would like to change.
1709 * @param flagsValues Desired values for any bits set in
1710 * <var>flagsMask</var>
1711 * @param extraFlags Always set to 0.
1712 *
1713 * @see #startActivity(Intent)
1714 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1715 */
1716 public abstract void startIntentSender(IntentSender intent,
1717 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1718 throws IntentSender.SendIntentException;
1719
1720 /**
1721 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001722 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001723 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001724 * here; otherwise, its associated action will be executed (such as
1725 * sending a broadcast) as if you had called
1726 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001727 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001728 * @param intent The IntentSender to launch.
1729 * @param fillInIntent If non-null, this will be provided as the
1730 * intent parameter to {@link IntentSender#sendIntent}.
1731 * @param flagsMask Intent flags in the original IntentSender that you
1732 * would like to change.
1733 * @param flagsValues Desired values for any bits set in
1734 * <var>flagsMask</var>
1735 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001736 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001737 * See {@link android.content.Context#startActivity(Intent, Bundle)
1738 * Context.startActivity(Intent, Bundle)} for more details. If options
1739 * have also been supplied by the IntentSender, options given here will
1740 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001741 *
1742 * @see #startActivity(Intent, Bundle)
1743 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001744 */
1745 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001746 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001747 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001748
1749 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750 * Broadcast the given intent to all interested BroadcastReceivers. This
1751 * call is asynchronous; it returns immediately, and you will continue
1752 * executing while the receivers are run. No results are propagated from
1753 * receivers and receivers can not abort the broadcast. If you want
1754 * to allow receivers to propagate results or abort the broadcast, you must
1755 * send an ordered broadcast using
1756 * {@link #sendOrderedBroadcast(Intent, String)}.
1757 *
1758 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1759 *
1760 * @param intent The Intent to broadcast; all receivers matching this
1761 * Intent will receive the broadcast.
1762 *
1763 * @see android.content.BroadcastReceiver
1764 * @see #registerReceiver
1765 * @see #sendBroadcast(Intent, String)
1766 * @see #sendOrderedBroadcast(Intent, String)
1767 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1768 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001769 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770
1771 /**
1772 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1773 * an optional required permission to be enforced. This
1774 * call is asynchronous; it returns immediately, and you will continue
1775 * executing while the receivers are run. No results are propagated from
1776 * receivers and receivers can not abort the broadcast. If you want
1777 * to allow receivers to propagate results or abort the broadcast, you must
1778 * send an ordered broadcast using
1779 * {@link #sendOrderedBroadcast(Intent, String)}.
1780 *
1781 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1782 *
1783 * @param intent The Intent to broadcast; all receivers matching this
1784 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001785 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 * a receiver must hold in order to receive your broadcast.
1787 * If null, no permission is required.
1788 *
1789 * @see android.content.BroadcastReceiver
1790 * @see #registerReceiver
1791 * @see #sendBroadcast(Intent)
1792 * @see #sendOrderedBroadcast(Intent, String)
1793 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1794 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001795 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001796 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001798
1799 /**
1800 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1801 * an array of required permissions to be enforced. This call is asynchronous; it returns
1802 * immediately, and you will continue executing while the receivers are run. No results are
1803 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1804 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1805 * using {@link #sendOrderedBroadcast(Intent, String)}.
1806 *
1807 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1808 *
1809 * @param intent The Intent to broadcast; all receivers matching this
1810 * Intent will receive the broadcast.
1811 * @param receiverPermissions Array of names of permissions that a receiver must hold
1812 * in order to receive your broadcast.
1813 * If null or empty, no permissions are required.
1814 *
1815 * @see android.content.BroadcastReceiver
1816 * @see #registerReceiver
1817 * @see #sendBroadcast(Intent)
1818 * @see #sendOrderedBroadcast(Intent, String)
1819 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1820 * @hide
1821 */
1822 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1823 String[] receiverPermissions);
1824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001825 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001826 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1827 * an optional required permission to be enforced. This
1828 * call is asynchronous; it returns immediately, and you will continue
1829 * executing while the receivers are run. No results are propagated from
1830 * receivers and receivers can not abort the broadcast. If you want
1831 * to allow receivers to propagate results or abort the broadcast, you must
1832 * send an ordered broadcast using
1833 * {@link #sendOrderedBroadcast(Intent, String)}.
1834 *
1835 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1836 *
1837 * @param intent The Intent to broadcast; all receivers matching this
1838 * Intent will receive the broadcast.
1839 * @param receiverPermission (optional) String naming a permission that
1840 * a receiver must hold in order to receive your broadcast.
1841 * If null, no permission is required.
1842 * @param options (optional) Additional sending options, generated from a
1843 * {@link android.app.BroadcastOptions}.
1844 *
1845 * @see android.content.BroadcastReceiver
1846 * @see #registerReceiver
1847 * @see #sendBroadcast(Intent)
1848 * @see #sendOrderedBroadcast(Intent, String)
1849 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1850 * @hide
1851 */
1852 @SystemApi
1853 public abstract void sendBroadcast(Intent intent,
1854 @Nullable String receiverPermission,
1855 @Nullable Bundle options);
1856
1857 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001858 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001859 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001860 * @hide
1861 */
1862 public abstract void sendBroadcast(Intent intent,
1863 String receiverPermission, int appOp);
1864
1865 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001866 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1867 * them one at a time to allow more preferred receivers to consume the
1868 * broadcast before it is delivered to less preferred receivers. This
1869 * call is asynchronous; it returns immediately, and you will continue
1870 * executing while the receivers are run.
1871 *
1872 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1873 *
1874 * @param intent The Intent to broadcast; all receivers matching this
1875 * Intent will receive the broadcast.
1876 * @param receiverPermission (optional) String naming a permissions that
1877 * a receiver must hold in order to receive your broadcast.
1878 * If null, no permission is required.
1879 *
1880 * @see android.content.BroadcastReceiver
1881 * @see #registerReceiver
1882 * @see #sendBroadcast(Intent)
1883 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1884 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001885 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001886 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887
1888 /**
1889 * Version of {@link #sendBroadcast(Intent)} that allows you to
1890 * receive data back from the broadcast. This is accomplished by
1891 * supplying your own BroadcastReceiver when calling, which will be
1892 * treated as a final receiver at the end of the broadcast -- its
1893 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001894 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 * be serialized in the same way as calling
1896 * {@link #sendOrderedBroadcast(Intent, String)}.
1897 *
1898 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1899 * asynchronous; it will return before
1900 * resultReceiver.onReceive() is called.
1901 *
1902 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1903 *
1904 * @param intent The Intent to broadcast; all receivers matching this
1905 * Intent will receive the broadcast.
1906 * @param receiverPermission String naming a permissions that
1907 * a receiver must hold in order to receive your broadcast.
1908 * If null, no permission is required.
1909 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1910 * receiver of the broadcast.
1911 * @param scheduler A custom Handler with which to schedule the
1912 * resultReceiver callback; if null it will be
1913 * scheduled in the Context's main thread.
1914 * @param initialCode An initial value for the result code. Often
1915 * Activity.RESULT_OK.
1916 * @param initialData An initial value for the result data. Often
1917 * null.
1918 * @param initialExtras An initial value for the result extras. Often
1919 * null.
1920 *
1921 * @see #sendBroadcast(Intent)
1922 * @see #sendBroadcast(Intent, String)
1923 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924 * @see android.content.BroadcastReceiver
1925 * @see #registerReceiver
1926 * @see android.app.Activity#RESULT_OK
1927 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001928 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07001929 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001930 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1931 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001932
1933 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001934 * Version of {@link #sendBroadcast(Intent)} that allows you to
1935 * receive data back from the broadcast. This is accomplished by
1936 * supplying your own BroadcastReceiver when calling, which will be
1937 * treated as a final receiver at the end of the broadcast -- its
1938 * {@link BroadcastReceiver#onReceive} method will be called with
1939 * the result values collected from the other receivers. The broadcast will
1940 * be serialized in the same way as calling
1941 * {@link #sendOrderedBroadcast(Intent, String)}.
1942 *
1943 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1944 * asynchronous; it will return before
1945 * resultReceiver.onReceive() is called.
1946 *
1947 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1948 *
1949 *
1950 * @param intent The Intent to broadcast; all receivers matching this
1951 * Intent will receive the broadcast.
1952 * @param receiverPermission String naming a permissions that
1953 * a receiver must hold in order to receive your broadcast.
1954 * If null, no permission is required.
1955 * @param options (optional) Additional sending options, generated from a
1956 * {@link android.app.BroadcastOptions}.
1957 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1958 * receiver of the broadcast.
1959 * @param scheduler A custom Handler with which to schedule the
1960 * resultReceiver callback; if null it will be
1961 * scheduled in the Context's main thread.
1962 * @param initialCode An initial value for the result code. Often
1963 * Activity.RESULT_OK.
1964 * @param initialData An initial value for the result data. Often
1965 * null.
1966 * @param initialExtras An initial value for the result extras. Often
1967 * null.
1968 * @see #sendBroadcast(Intent)
1969 * @see #sendBroadcast(Intent, String)
1970 * @see #sendOrderedBroadcast(Intent, String)
1971 * @see android.content.BroadcastReceiver
1972 * @see #registerReceiver
1973 * @see android.app.Activity#RESULT_OK
1974 * @hide
1975 */
1976 @SystemApi
1977 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1978 @Nullable String receiverPermission, @Nullable Bundle options,
1979 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
1980 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
1981
1982 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001983 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1984 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001985 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001986 * @hide
1987 */
1988 public abstract void sendOrderedBroadcast(Intent intent,
1989 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1990 Handler scheduler, int initialCode, String initialData,
1991 Bundle initialExtras);
1992
1993 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001994 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1995 * user the broadcast will be sent to. This is not available to applications
1996 * that are not pre-installed on the system image. Using it requires holding
1997 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001998 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001999 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002000 * @see #sendBroadcast(Intent)
2001 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002002 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2003 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002004
2005 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002006 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2007 * user the broadcast will be sent to. This is not available to applications
2008 * that are not pre-installed on the system image. Using it requires holding
2009 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002010 *
2011 * @param intent The Intent to broadcast; all receivers matching this
2012 * Intent will receive the broadcast.
2013 * @param user UserHandle to send the intent to.
2014 * @param receiverPermission (optional) String naming a permission that
2015 * a receiver must hold in order to receive your broadcast.
2016 * If null, no permission is required.
2017 *
2018 * @see #sendBroadcast(Intent, String)
2019 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002020 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2021 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002022
Svet Ganov16a16892015-04-16 10:32:04 -07002023
2024 /**
2025 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2026 * user the broadcast will be sent to. This is not available to applications
2027 * that are not pre-installed on the system image. Using it requires holding
2028 * the INTERACT_ACROSS_USERS permission.
2029 *
2030 * @param intent The Intent to broadcast; all receivers matching this
2031 * Intent will receive the broadcast.
2032 * @param user UserHandle to send the intent to.
2033 * @param receiverPermission (optional) String naming a permission that
2034 * a receiver must hold in order to receive your broadcast.
2035 * If null, no permission is required.
2036 * @param appOp The app op associated with the broadcast.
2037 *
2038 * @see #sendBroadcast(Intent, String)
2039 *
2040 * @hide
2041 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002042 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2043 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002044
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002045 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002046 * Version of
2047 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2048 * that allows you to specify the
2049 * user the broadcast will be sent to. This is not available to applications
2050 * that are not pre-installed on the system image. Using it requires holding
2051 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002052 *
2053 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2054 *
2055 * @param intent The Intent to broadcast; all receivers matching this
2056 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002057 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002058 * @param receiverPermission String naming a permissions that
2059 * a receiver must hold in order to receive your broadcast.
2060 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002061 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2062 * receiver of the broadcast.
2063 * @param scheduler A custom Handler with which to schedule the
2064 * resultReceiver callback; if null it will be
2065 * scheduled in the Context's main thread.
2066 * @param initialCode An initial value for the result code. Often
2067 * Activity.RESULT_OK.
2068 * @param initialData An initial value for the result data. Often
2069 * null.
2070 * @param initialExtras An initial value for the result extras. Often
2071 * null.
2072 *
2073 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2074 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002075 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2076 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002077 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2078 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002079
2080 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002081 * Similar to above but takes an appOp as well, to enforce restrictions.
2082 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2083 * BroadcastReceiver, Handler, int, String, Bundle)
2084 * @hide
2085 */
2086 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2087 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2088 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2089 @Nullable Bundle initialExtras);
2090
2091 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002092 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
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, @Nullable Bundle options,
2099 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2100 @Nullable String initialData, @Nullable Bundle initialExtras);
2101
2102 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002103 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002104 * Intent you are sending stays around after the broadcast is complete,
2105 * so that others can quickly retrieve that data through the return
2106 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2107 * all other ways, this behaves the same as
2108 * {@link #sendBroadcast(Intent)}.
2109 *
2110 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2111 * permission in order to use this API. If you do not hold that
2112 * permission, {@link SecurityException} will be thrown.
2113 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002114 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2115 * can access them), no protection (anyone can modify them), and many other problems.
2116 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2117 * has changed, with another mechanism for apps to retrieve the current value whenever
2118 * desired.
2119 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002120 * @param intent The Intent to broadcast; all receivers matching this
2121 * Intent will receive the broadcast, and the Intent will be held to
2122 * be re-broadcast to future receivers.
2123 *
2124 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002125 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002126 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002127 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002128 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002129
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002130 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002131 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002132 * receive data back from the broadcast. This is accomplished by
2133 * supplying your own BroadcastReceiver when calling, which will be
2134 * treated as a final receiver at the end of the broadcast -- its
2135 * {@link BroadcastReceiver#onReceive} method will be called with
2136 * the result values collected from the other receivers. The broadcast will
2137 * be serialized in the same way as calling
2138 * {@link #sendOrderedBroadcast(Intent, String)}.
2139 *
2140 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2141 * asynchronous; it will return before
2142 * resultReceiver.onReceive() is called. Note that the sticky data
2143 * stored is only the data you initially supply to the broadcast, not
2144 * the result of any changes made by the receivers.
2145 *
2146 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2147 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002148 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2149 * can access them), no protection (anyone can modify them), and many other problems.
2150 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2151 * has changed, with another mechanism for apps to retrieve the current value whenever
2152 * desired.
2153 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002154 * @param intent The Intent to broadcast; all receivers matching this
2155 * Intent will receive the broadcast.
2156 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2157 * receiver of the broadcast.
2158 * @param scheduler A custom Handler with which to schedule the
2159 * resultReceiver callback; if null it will be
2160 * scheduled in the Context's main thread.
2161 * @param initialCode An initial value for the result code. Often
2162 * Activity.RESULT_OK.
2163 * @param initialData An initial value for the result data. Often
2164 * null.
2165 * @param initialExtras An initial value for the result extras. Often
2166 * null.
2167 *
2168 * @see #sendBroadcast(Intent)
2169 * @see #sendBroadcast(Intent, String)
2170 * @see #sendOrderedBroadcast(Intent, String)
2171 * @see #sendStickyBroadcast(Intent)
2172 * @see android.content.BroadcastReceiver
2173 * @see #registerReceiver
2174 * @see android.app.Activity#RESULT_OK
2175 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002176 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002177 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002178 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002179 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2180 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002181
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002183 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002184 * so that it is as if the sticky broadcast had never happened.
2185 *
2186 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2187 * permission in order to use this API. If you do not hold that
2188 * permission, {@link SecurityException} will be thrown.
2189 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002190 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2191 * can access them), no protection (anyone can modify them), and many other problems.
2192 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2193 * has changed, with another mechanism for apps to retrieve the current value whenever
2194 * desired.
2195 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 * @param intent The Intent that was previously broadcast.
2197 *
2198 * @see #sendStickyBroadcast
2199 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002200 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002201 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202
2203 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002204 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002205 * user the broadcast will be sent to. This is not available to applications
2206 * that are not pre-installed on the system image. Using it requires holding
2207 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002208 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002209 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2210 * can access them), no protection (anyone can modify them), and many other problems.
2211 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2212 * has changed, with another mechanism for apps to retrieve the current value whenever
2213 * desired.
2214 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002215 * @param intent The Intent to broadcast; all receivers matching this
2216 * Intent will receive the broadcast, and the Intent will be held to
2217 * be re-broadcast to future receivers.
2218 * @param user UserHandle to send the intent to.
2219 *
2220 * @see #sendBroadcast(Intent)
2221 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002222 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002223 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2224 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002225
2226 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002227 * @hide
2228 * This is just here for sending CONNECTIVITY_ACTION.
2229 */
2230 @Deprecated
2231 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2232 UserHandle user, Bundle options);
2233
2234 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002235 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002236 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2237 * that allows you to specify the
2238 * user the broadcast will be sent to. This is not available to applications
2239 * that are not pre-installed on the system image. Using it requires holding
2240 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002241 *
2242 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2243 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002244 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2245 * can access them), no protection (anyone can modify them), and many other problems.
2246 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2247 * has changed, with another mechanism for apps to retrieve the current value whenever
2248 * desired.
2249 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002250 * @param intent The Intent to broadcast; all receivers matching this
2251 * Intent will receive the broadcast.
2252 * @param user UserHandle to send the intent to.
2253 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2254 * receiver of the broadcast.
2255 * @param scheduler A custom Handler with which to schedule the
2256 * resultReceiver callback; if null it will be
2257 * scheduled in the Context's main thread.
2258 * @param initialCode An initial value for the result code. Often
2259 * Activity.RESULT_OK.
2260 * @param initialData An initial value for the result data. Often
2261 * null.
2262 * @param initialExtras An initial value for the result extras. Often
2263 * null.
2264 *
2265 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2266 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002267 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002268 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002269 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002270 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2271 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002272
2273 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002274 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002275 * user the broadcast will be sent to. This is not available to applications
2276 * that are not pre-installed on the system image. Using it requires holding
2277 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002278 *
2279 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2280 * permission in order to use this API. If you do not hold that
2281 * permission, {@link SecurityException} will be thrown.
2282 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002283 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2284 * can access them), no protection (anyone can modify them), and many other problems.
2285 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2286 * has changed, with another mechanism for apps to retrieve the current value whenever
2287 * desired.
2288 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002289 * @param intent The Intent that was previously broadcast.
2290 * @param user UserHandle to remove the sticky broadcast from.
2291 *
2292 * @see #sendStickyBroadcastAsUser
2293 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002294 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002295 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2296 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002297
2298 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002299 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002300 * <var>receiver</var> will be called with any broadcast Intent that
2301 * matches <var>filter</var>, in the main application thread.
2302 *
2303 * <p>The system may broadcast Intents that are "sticky" -- these stay
2304 * around after the broadcast as finished, to be sent to any later
2305 * registrations. If your IntentFilter matches one of these sticky
2306 * Intents, that Intent will be returned by this function
2307 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2308 * been broadcast.
2309 *
2310 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2311 * in which case each of these will be sent to <var>receiver</var>. In
2312 * this case, only one of these can be returned directly by the function;
2313 * which of these that is returned is arbitrarily decided by the system.
2314 *
2315 * <p>If you know the Intent your are registering for is sticky, you can
2316 * supply null for your <var>receiver</var>. In this case, no receiver is
2317 * registered -- the function simply returns the sticky Intent that
2318 * matches <var>filter</var>. In the case of multiple matches, the same
2319 * rules as described above apply.
2320 *
2321 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2322 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002323 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2324 * registered with this method will correctly respect the
2325 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2326 * Prior to that, it would be ignored and delivered to all matching registered
2327 * receivers. Be careful if using this for security.</p>
2328 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002329 * <p class="note">Note: this method <em>cannot be called from a
2330 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2331 * that is declared in an application's manifest. It is okay, however, to call
2332 * this method from another BroadcastReceiver that has itself been registered
2333 * at run time with {@link #registerReceiver}, since the lifetime of such a
2334 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002335 *
2336 * @param receiver The BroadcastReceiver to handle the broadcast.
2337 * @param filter Selects the Intent broadcasts to be received.
2338 *
2339 * @return The first sticky intent found that matches <var>filter</var>,
2340 * or null if there are none.
2341 *
2342 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2343 * @see #sendBroadcast
2344 * @see #unregisterReceiver
2345 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002346 @Nullable
2347 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 IntentFilter filter);
2349
2350 /**
2351 * Register to receive intent broadcasts, to run in the context of
2352 * <var>scheduler</var>. See
2353 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2354 * information. This allows you to enforce permissions on who can
2355 * broadcast intents to your receiver, or have the receiver run in
2356 * a different thread than the main application thread.
2357 *
2358 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2359 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002360 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2361 * registered with this method will correctly respect the
2362 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2363 * Prior to that, it would be ignored and delivered to all matching registered
2364 * receivers. Be careful if using this for security.</p>
2365 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002366 * @param receiver The BroadcastReceiver to handle the broadcast.
2367 * @param filter Selects the Intent broadcasts to be received.
2368 * @param broadcastPermission String naming a permissions that a
2369 * broadcaster must hold in order to send an Intent to you. If null,
2370 * no permission is required.
2371 * @param scheduler Handler identifying the thread that will receive
2372 * the Intent. If null, the main thread of the process will be used.
2373 *
2374 * @return The first sticky intent found that matches <var>filter</var>,
2375 * or null if there are none.
2376 *
2377 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2378 * @see #sendBroadcast
2379 * @see #unregisterReceiver
2380 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002381 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002382 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002383 IntentFilter filter, @Nullable String broadcastPermission,
2384 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002385
2386 /**
2387 * @hide
2388 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2389 * but for a specific user. This receiver will receiver broadcasts that
2390 * are sent to the requested user. It
2391 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
2392 * permission.
2393 *
2394 * @param receiver The BroadcastReceiver to handle the broadcast.
2395 * @param user UserHandle to send the intent to.
2396 * @param filter Selects the Intent broadcasts to be received.
2397 * @param broadcastPermission String naming a permissions that a
2398 * broadcaster must hold in order to send an Intent to you. If null,
2399 * no permission is required.
2400 * @param scheduler Handler identifying the thread that will receive
2401 * the Intent. If null, the main thread of the process will be used.
2402 *
2403 * @return The first sticky intent found that matches <var>filter</var>,
2404 * or null if there are none.
2405 *
Jeff Brown6e539312015-02-24 18:53:21 -08002406 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002407 * @see #sendBroadcast
2408 * @see #unregisterReceiver
2409 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002410 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07002411 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002412 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2413 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414
2415 /**
2416 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2417 * filters that have been registered for this BroadcastReceiver will be
2418 * removed.
2419 *
2420 * @param receiver The BroadcastReceiver to unregister.
2421 *
2422 * @see #registerReceiver
2423 */
2424 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2425
2426 /**
2427 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07002428 * should contain either contain the complete class name of a specific service
2429 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07002430 * Intent is less specified, it log a warning about this and which of the
2431 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 * is not already running, it will be instantiated and started (creating a
2433 * process for it if needed); if it is running then it remains running.
2434 *
2435 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002436 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 * with the <var>intent</var> given here. This provides a convenient way
2438 * to submit jobs to a service without having to bind and call on to its
2439 * interface.
2440 *
2441 * <p>Using startService() overrides the default service lifetime that is
2442 * managed by {@link #bindService}: it requires the service to remain
2443 * running until {@link #stopService} is called, regardless of whether
2444 * any clients are connected to it. Note that calls to startService()
2445 * are not nesting: no matter how many times you call startService(),
2446 * a single call to {@link #stopService} will stop it.
2447 *
2448 * <p>The system attempts to keep running services around as much as
2449 * possible. The only time they should be stopped is if the current
2450 * foreground application is using so many resources that the service needs
2451 * to be killed. If any errors happen in the service's process, it will
2452 * automatically be restarted.
2453 *
2454 * <p>This function will throw {@link SecurityException} if you do not
2455 * have permission to start the given service.
2456 *
Chris Craik1e353522016-04-18 10:20:50 -07002457 * <p class="note"><strong>Note:</strong> Each call to startService()
2458 * results in significant work done by the system to manage service
2459 * lifecycle surrounding the processing of the intent, which can take
2460 * multiple milliseconds of CPU time. Due to this cost, startService()
2461 * should not be used for frequent intent delivery to a service, and only
2462 * for scheduling significant work. Use {@link #bindService bound services}
2463 * for high frequency calls.
2464 * </p>
2465 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002466 * @param service Identifies the service to be started. The Intent must be either
2467 * fully explicit (supplying a component name) or specify a specific package
2468 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 * may be included in the Intent extras to supply arguments along with
2470 * this specific start call.
2471 *
2472 * @return If the service is being started or is already running, the
2473 * {@link ComponentName} of the actual service that was started is
2474 * returned; else if the service does not exist null is returned.
2475 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002476 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 *
2478 * @see #stopService
2479 * @see #bindService
2480 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002481 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002482 public abstract ComponentName startService(Intent service);
2483
2484 /**
2485 * Request that a given application service be stopped. If the service is
2486 * not running, nothing happens. Otherwise it is stopped. Note that calls
2487 * to startService() are not counted -- this stops the service no matter
2488 * how many times it was started.
2489 *
2490 * <p>Note that if a stopped service still has {@link ServiceConnection}
2491 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2492 * not be destroyed until all of these bindings are removed. See
2493 * the {@link android.app.Service} documentation for more details on a
2494 * service's lifecycle.
2495 *
2496 * <p>This function will throw {@link SecurityException} if you do not
2497 * have permission to stop the given service.
2498 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002499 * @param service Description of the service to be stopped. The Intent must be either
2500 * fully explicit (supplying a component name) or specify a specific package
2501 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502 *
2503 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002504 * 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 -08002505 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002506 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 *
2508 * @see #startService
2509 */
2510 public abstract boolean stopService(Intent service);
2511
2512 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002513 * @hide like {@link #startService(Intent)} but for a specific user.
2514 */
2515 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2516
2517 /**
2518 * @hide like {@link #stopService(Intent)} but for a specific user.
2519 */
2520 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002521
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002522 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002523 * Connect to an application service, creating it if needed. This defines
2524 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002525 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002526 * told if it dies and restarts. The service will be considered required
2527 * by the system only for as long as the calling context exists. For
2528 * example, if this Context is an Activity that is stopped, the service will
2529 * not be required to continue running until the Activity is resumed.
2530 *
2531 * <p>This function will throw {@link SecurityException} if you do not
2532 * have permission to bind to the given service.
2533 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002534 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002536 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002537 * {@link #startService} with the arguments containing the command to be
2538 * sent, with the service calling its
2539 * {@link android.app.Service#stopSelf(int)} method when done executing
2540 * that command. See the API demo App/Service/Service Start Arguments
2541 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002542 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2544 * is tied to another object (the one that registered it).</p>
2545 *
2546 * @param service Identifies the service to connect to. The Intent may
2547 * specify either an explicit component name, or a logical
2548 * description (action, category, etc) to match an
2549 * {@link IntentFilter} published by a service.
2550 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002551 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002552 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002553 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2554 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2555 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2556 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002557 * @return If you have successfully bound to the service, {@code true} is returned;
2558 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 * receive the service object.
2560 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002561 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002562 *
2563 * @see #unbindService
2564 * @see #startService
2565 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002566 * @see #BIND_DEBUG_UNBIND
2567 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002568 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002569 public abstract boolean bindService(@RequiresPermission Intent service,
2570 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571
2572 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002573 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002574 * argument for use by system server and other multi-user aware code.
2575 * @hide
2576 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002577 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002578 @SuppressWarnings("unused")
Tor Norbye788fc2b2015-07-05 16:10:42 -07002579 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002580 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002581 throw new RuntimeException("Not implemented. Must override in a subclass.");
2582 }
2583
2584 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002585 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2586 * explicit non-null Handler to run the ServiceConnection callbacks on.
2587 *
2588 * @hide
2589 */
2590 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2591 Handler handler, UserHandle user) {
2592 throw new RuntimeException("Not implemented. Must override in a subclass.");
2593 }
2594
2595 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002596 * Disconnect from an application service. You will no longer receive
2597 * calls as the service is restarted, and the service is now allowed to
2598 * stop at any time.
2599 *
2600 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002601 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002602 *
2603 * @see #bindService
2604 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002605 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606
2607 /**
2608 * Start executing an {@link android.app.Instrumentation} class. The given
2609 * Instrumentation component will be run by killing its target application
2610 * (if currently running), starting the target process, instantiating the
2611 * instrumentation component, and then letting it drive the application.
2612 *
2613 * <p>This function is not synchronous -- it returns as soon as the
2614 * instrumentation has started and while it is running.
2615 *
2616 * <p>Instrumentation is normally only allowed to run against a package
2617 * that is either unsigned or signed with a signature that the
2618 * the instrumentation package is also signed with (ensuring the target
2619 * trusts the instrumentation).
2620 *
2621 * @param className Name of the Instrumentation component to be run.
2622 * @param profileFile Optional path to write profiling data as the
2623 * instrumentation runs, or null for no profiling.
2624 * @param arguments Additional optional arguments to pass to the
2625 * instrumentation, or null.
2626 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002627 * @return {@code true} if the instrumentation was successfully started,
2628 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002630 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2631 @Nullable String profileFile, @Nullable Bundle arguments);
2632
2633 /** @hide */
2634 @StringDef({
2635 POWER_SERVICE,
2636 WINDOW_SERVICE,
2637 LAYOUT_INFLATER_SERVICE,
2638 ACCOUNT_SERVICE,
2639 ACTIVITY_SERVICE,
2640 ALARM_SERVICE,
2641 NOTIFICATION_SERVICE,
2642 ACCESSIBILITY_SERVICE,
2643 CAPTIONING_SERVICE,
2644 KEYGUARD_SERVICE,
2645 LOCATION_SERVICE,
2646 //@hide: COUNTRY_DETECTOR,
2647 SEARCH_SERVICE,
2648 SENSOR_SERVICE,
2649 STORAGE_SERVICE,
2650 WALLPAPER_SERVICE,
2651 VIBRATOR_SERVICE,
2652 //@hide: STATUS_BAR_SERVICE,
2653 CONNECTIVITY_SERVICE,
2654 //@hide: UPDATE_LOCK_SERVICE,
2655 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002656 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002657 //@hide: NETWORK_POLICY_SERVICE,
2658 WIFI_SERVICE,
Etan Cohen20d329b2015-09-29 13:49:02 -07002659 WIFI_NAN_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002660 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002661 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002662 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002663 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002664 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002665 NSD_SERVICE,
2666 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002667 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002668 MEDIA_ROUTER_SERVICE,
2669 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002670 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002671 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002672 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002673 CLIPBOARD_SERVICE,
2674 INPUT_METHOD_SERVICE,
2675 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002676 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002677 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002678 //@hide: BACKUP_SERVICE,
2679 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07002680 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07002681 DEVICE_POLICY_SERVICE,
2682 UI_MODE_SERVICE,
2683 DOWNLOAD_SERVICE,
2684 NFC_SERVICE,
2685 BLUETOOTH_SERVICE,
2686 //@hide: SIP_SERVICE,
2687 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002688 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002689 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002690 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002691 INPUT_SERVICE,
2692 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002693 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002694 RESTRICTIONS_SERVICE,
2695 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002696 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002697 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002698 CONSUMER_IR_SERVICE,
2699 //@hide: TRUST_SERVICE,
2700 TV_INPUT_SERVICE,
2701 //@hide: NETWORK_SCORE_SERVICE,
2702 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002703 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002704 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002705 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002706 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002707 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002708 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002709 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002710 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08002711 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08002712 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08002713 //@hide: CONTEXTHUB_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002714 })
2715 @Retention(RetentionPolicy.SOURCE)
2716 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717
2718 /**
2719 * Return the handle to a system-level service by name. The class of the
2720 * returned object varies by the requested name. Currently available names
2721 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002722 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002723 * <dl>
2724 * <dt> {@link #WINDOW_SERVICE} ("window")
2725 * <dd> The top-level window manager in which you can place custom
2726 * windows. The returned object is a {@link android.view.WindowManager}.
2727 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2728 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2729 * in this context.
2730 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2731 * <dd> A {@link android.app.ActivityManager} for interacting with the
2732 * global activity state of the system.
2733 * <dt> {@link #POWER_SERVICE} ("power")
2734 * <dd> A {@link android.os.PowerManager} for controlling power
2735 * management.
2736 * <dt> {@link #ALARM_SERVICE} ("alarm")
2737 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2738 * time of your choosing.
2739 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2740 * <dd> A {@link android.app.NotificationManager} for informing the user
2741 * of background events.
2742 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2743 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2744 * <dt> {@link #LOCATION_SERVICE} ("location")
2745 * <dd> A {@link android.location.LocationManager} for controlling location
2746 * (e.g., GPS) updates.
2747 * <dt> {@link #SEARCH_SERVICE} ("search")
2748 * <dd> A {@link android.app.SearchManager} for handling search.
2749 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2750 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2751 * hardware.
2752 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2753 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2754 * handling management of network connections.
2755 * <dt> {@link #WIFI_SERVICE} ("wifi")
2756 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2757 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002758 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2759 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2760 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2762 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2763 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002764 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2765 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002766 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002767 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002768 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002769 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002770 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2771 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002772 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
2773 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
2774 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01002775 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002776 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002778 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 * <p>Note: System services obtained via this API may be closely associated with
2780 * the Context in which they are obtained from. In general, do not share the
2781 * service objects between various different contexts (Activities, Applications,
2782 * Services, Providers, etc.)
2783 *
2784 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002785 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002787 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 * @see #WINDOW_SERVICE
2789 * @see android.view.WindowManager
2790 * @see #LAYOUT_INFLATER_SERVICE
2791 * @see android.view.LayoutInflater
2792 * @see #ACTIVITY_SERVICE
2793 * @see android.app.ActivityManager
2794 * @see #POWER_SERVICE
2795 * @see android.os.PowerManager
2796 * @see #ALARM_SERVICE
2797 * @see android.app.AlarmManager
2798 * @see #NOTIFICATION_SERVICE
2799 * @see android.app.NotificationManager
2800 * @see #KEYGUARD_SERVICE
2801 * @see android.app.KeyguardManager
2802 * @see #LOCATION_SERVICE
2803 * @see android.location.LocationManager
2804 * @see #SEARCH_SERVICE
2805 * @see android.app.SearchManager
2806 * @see #SENSOR_SERVICE
2807 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002808 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002809 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 * @see #VIBRATOR_SERVICE
2811 * @see android.os.Vibrator
2812 * @see #CONNECTIVITY_SERVICE
2813 * @see android.net.ConnectivityManager
2814 * @see #WIFI_SERVICE
2815 * @see android.net.wifi.WifiManager
2816 * @see #AUDIO_SERVICE
2817 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002818 * @see #MEDIA_ROUTER_SERVICE
2819 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 * @see #TELEPHONY_SERVICE
2821 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002822 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2823 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002824 * @see #CARRIER_CONFIG_SERVICE
2825 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002826 * @see #INPUT_METHOD_SERVICE
2827 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002828 * @see #UI_MODE_SERVICE
2829 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002830 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002831 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002832 * @see #BATTERY_SERVICE
2833 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002834 * @see #JOB_SCHEDULER_SERVICE
2835 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002836 * @see #NETWORK_STATS_SERVICE
2837 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002838 * @see android.os.HardwarePropertiesManager
2839 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002841 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842
2843 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002844 * Return the handle to a system-level service by class.
2845 * <p>
2846 * Currently available classes are:
2847 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2848 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2849 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2850 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2851 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2852 * {@link android.net.ConnectivityManager},
2853 * {@link android.net.wifi.WifiManager},
2854 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2855 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2856 * {@link android.view.inputmethod.InputMethodManager},
2857 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002858 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
2859 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08002860 * </p><p>
2861 * Note: System services obtained via this API may be closely associated with
2862 * the Context in which they are obtained from. In general, do not share the
2863 * service objects between various different contexts (Activities, Applications,
2864 * Services, Providers, etc.)
2865 * </p>
2866 *
2867 * @param serviceClass The class of the desired service.
2868 * @return The service or null if the class is not a supported system service.
2869 */
2870 @SuppressWarnings("unchecked")
2871 public final <T> T getSystemService(Class<T> serviceClass) {
2872 // Because subclasses may override getSystemService(String) we cannot
2873 // perform a lookup by class alone. We must first map the class to its
2874 // service name then invoke the string-based method.
2875 String serviceName = getSystemServiceName(serviceClass);
2876 return serviceName != null ? (T)getSystemService(serviceName) : null;
2877 }
2878
2879 /**
2880 * Gets the name of the system-level service that is represented by the specified class.
2881 *
2882 * @param serviceClass The class of the desired service.
2883 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08002884 */
2885 public abstract String getSystemServiceName(Class<?> serviceClass);
2886
2887 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002888 * Use with {@link #getSystemService} to retrieve a
2889 * {@link android.os.PowerManager} for controlling power management,
2890 * including "wake locks," which let you keep the device on while
2891 * you're running long tasks.
2892 */
2893 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002894
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 /**
2896 * Use with {@link #getSystemService} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08002897 * {@link android.os.RecoverySystem} for accessing the recovery system
2898 * service.
2899 *
2900 * @see #getSystemService
2901 * @hide
2902 */
2903 public static final String RECOVERY_SERVICE = "recovery";
2904
2905 /**
2906 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 * {@link android.view.WindowManager} for accessing the system's window
2908 * manager.
2909 *
2910 * @see #getSystemService
2911 * @see android.view.WindowManager
2912 */
2913 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002914
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002915 /**
2916 * Use with {@link #getSystemService} to retrieve a
2917 * {@link android.view.LayoutInflater} for inflating layout resources in this
2918 * context.
2919 *
2920 * @see #getSystemService
2921 * @see android.view.LayoutInflater
2922 */
2923 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
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
Fred Quintana60307342009-03-24 22:48:12 -07002927 * {@link android.accounts.AccountManager} for receiving intents at a
2928 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002929 *
2930 * @see #getSystemService
2931 * @see android.accounts.AccountManager
2932 */
2933 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002934
Fred Quintana60307342009-03-24 22:48:12 -07002935 /**
2936 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 * {@link android.app.ActivityManager} for interacting with the global
2938 * system state.
2939 *
2940 * @see #getSystemService
2941 * @see android.app.ActivityManager
2942 */
2943 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002944
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002945 /**
2946 * Use with {@link #getSystemService} to retrieve a
2947 * {@link android.app.AlarmManager} for receiving intents at a
2948 * time of your choosing.
2949 *
2950 * @see #getSystemService
2951 * @see android.app.AlarmManager
2952 */
2953 public static final String ALARM_SERVICE = "alarm";
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.NotificationManager} for informing the user of
2958 * background events.
2959 *
2960 * @see #getSystemService
2961 * @see android.app.NotificationManager
2962 */
2963 public static final String NOTIFICATION_SERVICE = "notification";
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
svetoslavganov75986cf2009-05-14 22:28:01 -07002967 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2968 * feedback for UI events through the registered event listeners.
2969 *
2970 * @see #getSystemService
2971 * @see android.view.accessibility.AccessibilityManager
2972 */
2973 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002974
svetoslavganov75986cf2009-05-14 22:28:01 -07002975 /**
2976 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002977 * {@link android.view.accessibility.CaptioningManager} for obtaining
2978 * captioning properties and listening for changes in captioning
2979 * preferences.
2980 *
2981 * @see #getSystemService
2982 * @see android.view.accessibility.CaptioningManager
2983 */
2984 public static final String CAPTIONING_SERVICE = "captioning";
2985
2986 /**
2987 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 * {@link android.app.NotificationManager} for controlling keyguard.
2989 *
2990 * @see #getSystemService
2991 * @see android.app.KeyguardManager
2992 */
2993 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002994
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 /**
2996 * Use with {@link #getSystemService} to retrieve a {@link
2997 * android.location.LocationManager} for controlling location
2998 * updates.
2999 *
3000 * @see #getSystemService
3001 * @see android.location.LocationManager
3002 */
3003 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003004
3005 /**
3006 * Use with {@link #getSystemService} to retrieve a
3007 * {@link android.location.CountryDetector} for detecting the country that
3008 * the user is in.
3009 *
3010 * @hide
3011 */
3012 public static final String COUNTRY_DETECTOR = "country_detector";
3013
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003014 /**
3015 * Use with {@link #getSystemService} to retrieve a {@link
3016 * android.app.SearchManager} for handling searches.
3017 *
3018 * @see #getSystemService
3019 * @see android.app.SearchManager
3020 */
3021 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003022
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003023 /**
3024 * Use with {@link #getSystemService} to retrieve a {@link
3025 * android.hardware.SensorManager} for accessing sensors.
3026 *
3027 * @see #getSystemService
3028 * @see android.hardware.SensorManager
3029 */
3030 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003032 /**
San Mehatc9d81752010-02-01 10:23:27 -08003033 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003034 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003035 * functions.
3036 *
3037 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08003038 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003039 */
3040 public static final String STORAGE_SERVICE = "storage";
3041
3042 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 * Use with {@link #getSystemService} to retrieve a
3044 * com.android.server.WallpaperService for accessing wallpapers.
3045 *
3046 * @see #getSystemService
3047 */
3048 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003050 /**
3051 * Use with {@link #getSystemService} to retrieve a {@link
3052 * android.os.Vibrator} for interacting with the vibration hardware.
3053 *
3054 * @see #getSystemService
3055 * @see android.os.Vibrator
3056 */
3057 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003058
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003059 /**
3060 * Use with {@link #getSystemService} to retrieve a {@link
3061 * android.app.StatusBarManager} for interacting with the status bar.
3062 *
3063 * @see #getSystemService
3064 * @see android.app.StatusBarManager
3065 * @hide
3066 */
3067 public static final String STATUS_BAR_SERVICE = "statusbar";
3068
3069 /**
3070 * Use with {@link #getSystemService} to retrieve a {@link
3071 * android.net.ConnectivityManager} for handling management of
3072 * network connections.
3073 *
3074 * @see #getSystemService
3075 * @see android.net.ConnectivityManager
3076 */
3077 public static final String CONNECTIVITY_SERVICE = "connectivity";
3078
3079 /**
3080 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003081 * android.os.IUpdateLock} for managing runtime sequences that
3082 * must not be interrupted by headless OTA application or similar.
3083 *
3084 * @hide
3085 * @see #getSystemService
3086 * @see android.os.UpdateLock
3087 */
3088 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3089
3090 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003091 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003092 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003093 */
3094 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3095
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003096 /**
3097 * Use with {@link #getSystemService} to retrieve a {@link
3098 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3099 *
3100 * @see #getSystemService
3101 * @see android.app.usage.NetworkStatsManager
3102 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003103 public static final String NETWORK_STATS_SERVICE = "netstats";
3104 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003105 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
3106
San Mehatd1df8ac2010-01-26 06:17:26 -08003107 /**
3108 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 * android.net.wifi.WifiManager} for handling management of
3110 * Wi-Fi access.
3111 *
3112 * @see #getSystemService
3113 * @see android.net.wifi.WifiManager
3114 */
3115 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 /**
repo sync55bc5f32011-06-24 14:23:07 -07003118 * Use with {@link #getSystemService} to retrieve a {@link
3119 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003120 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003121 *
3122 * @see #getSystemService
3123 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003124 */
3125 public static final String WIFI_P2P_SERVICE = "wifip2p";
3126
3127 /**
Etan Cohen20d329b2015-09-29 13:49:02 -07003128 * Use with {@link #getSystemService} to retrieve a
3129 * {@link android.net.wifi.nan.WifiNanManager} for handling management of
3130 * Wi-Fi NAN discovery and connections.
3131 *
3132 * @see #getSystemService
3133 * @see android.net.wifi.nan.WifiNanManager
3134 * @hide PROPOSED_NAN_API
3135 */
3136 public static final String WIFI_NAN_SERVICE = "wifinan";
3137
3138 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003139 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003140 * android.net.wifi.WifiScanner} for scanning the wifi universe
3141 *
3142 * @see #getSystemService
3143 * @see android.net.wifi.WifiScanner
3144 * @hide
3145 */
Wei Wang35d552f2014-07-08 21:37:01 -07003146 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003147 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3148
3149 /**
3150 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003151 * android.net.wifi.RttManager} for ranging devices with wifi
3152 *
3153 * @see #getSystemService
3154 * @see android.net.wifi.RttManager
3155 * @hide
3156 */
3157 @SystemApi
3158 public static final String WIFI_RTT_SERVICE = "rttmanager";
3159
3160 /**
3161 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003162 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003163 * Ethernet access.
3164 *
3165 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003166 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003167 *
3168 * @hide
3169 */
3170 public static final String ETHERNET_SERVICE = "ethernet";
3171
3172 /**
3173 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003174 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003175 * discovery
3176 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003177 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003178 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003179 */
3180 public static final String NSD_SERVICE = "servicediscovery";
3181
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003182 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 * Use with {@link #getSystemService} to retrieve a
3184 * {@link android.media.AudioManager} for handling management of volume,
3185 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003186 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003187 * @see #getSystemService
3188 * @see android.media.AudioManager
3189 */
3190 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 /**
3193 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003194 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003195 * of fingerprints.
3196 *
3197 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07003198 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003199 */
3200 public static final String FINGERPRINT_SERVICE = "fingerprint";
3201
3202 /**
3203 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003204 * {@link android.media.MediaRouter} for controlling and managing
3205 * routing of media.
3206 *
3207 * @see #getSystemService
3208 * @see android.media.MediaRouter
3209 */
3210 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3211
3212 /**
3213 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003214 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003215 *
3216 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07003217 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003218 */
3219 public static final String MEDIA_SESSION_SERVICE = "media_session";
3220
3221 /**
3222 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003223 * {@link android.telephony.TelephonyManager} for handling management the
3224 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003225 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 * @see #getSystemService
3227 * @see android.telephony.TelephonyManager
3228 */
3229 public static final String TELEPHONY_SERVICE = "phone";
3230
3231 /**
3232 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003233 * {@link android.telephony.SubscriptionManager} for handling management the
3234 * telephony subscriptions of the device.
3235 *
3236 * @see #getSystemService
3237 * @see android.telephony.SubscriptionManager
3238 */
3239 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3240
3241 /**
3242 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003243 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003244 * of the device.
3245 *
3246 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003247 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003248 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003249 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003250
3251 /**
3252 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003253 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3254 *
3255 * @see #getSystemService
3256 * @see android.telephony.CarrierConfigManager
3257 */
3258 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3259
3260 /**
3261 * Use with {@link #getSystemService} to retrieve a
3262 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08003263 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003264 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003265 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003267 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 */
3269 public static final String CLIPBOARD_SERVICE = "clipboard";
3270
3271 /**
Scott Main4b5da682010-10-21 11:49:12 -07003272 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003273 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3274 * methods.
3275 *
3276 * @see #getSystemService
3277 */
3278 public static final String INPUT_METHOD_SERVICE = "input_method";
3279
3280 /**
3281 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09003282 * {@link android.view.textservice.TextServicesManager} for accessing
3283 * text services.
3284 *
3285 * @see #getSystemService
3286 */
3287 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3288
3289 /**
3290 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003291 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003293 * @see #getSystemService
3294 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003295 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003296
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003297 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003298 * Official published name of the (internal) voice interaction manager service.
3299 *
3300 * @hide
3301 * @see #getSystemService
3302 */
3303 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3304
3305 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003306 * Use with {@link #getSystemService} to access the
3307 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3308 *
3309 * @hide
3310 * @see #getSystemService
3311 */
3312 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3313
3314
3315 /**
Christopher Tate487529a2009-04-29 14:03:25 -07003316 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003317 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003318 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003319 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003320 *
Christopher Tate487529a2009-04-29 14:03:25 -07003321 * @see #getSystemService
3322 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003323 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003324 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003325
3326 /**
3327 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003328 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003329 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07003330 * @see #getSystemService
3331 */
3332 public static final String DROPBOX_SERVICE = "dropbox";
3333
Christopher Tate487529a2009-04-29 14:03:25 -07003334 /**
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003335 * System service name for the DeviceIdleController. There is no Java API for this.
3336 * @see #getSystemService
3337 * @hide
3338 */
3339 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3340
3341 /**
Scott Main4b5da682010-10-21 11:49:12 -07003342 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003343 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003344 * device policy management.
3345 *
3346 * @see #getSystemService
3347 */
3348 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3349
3350 /**
Tobias Haamel53332882010-02-18 16:15:43 -08003351 * Use with {@link #getSystemService} to retrieve a
3352 * {@link android.app.UiModeManager} for controlling UI modes.
3353 *
3354 * @see #getSystemService
3355 */
3356 public static final String UI_MODE_SERVICE = "uimode";
3357
3358 /**
Steve Howarda2709362010-07-02 17:12:48 -07003359 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003360 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003361 *
3362 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07003363 */
3364 public static final String DOWNLOAD_SERVICE = "download";
3365
3366 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08003367 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003368 * {@link android.os.BatteryManager} for managing battery state.
3369 *
3370 * @see #getSystemService
3371 */
3372 public static final String BATTERY_SERVICE = "batterymanager";
3373
3374 /**
3375 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003376 * {@link android.nfc.NfcManager} for using NFC.
3377 *
3378 * @see #getSystemService
3379 */
3380 public static final String NFC_SERVICE = "nfc";
3381
3382 /**
3383 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003384 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003385 *
3386 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003387 */
3388 public static final String BLUETOOTH_SERVICE = "bluetooth";
3389
3390 /**
3391 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003392 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3393 *
3394 * @see #getSystemService
3395 */
3396 /** @hide */
3397 public static final String SIP_SERVICE = "sip";
3398
3399 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003400 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003401 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003402 * and for controlling this device's behavior as a USB device.
3403 *
3404 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04003405 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003406 */
3407 public static final String USB_SERVICE = "usb";
3408
3409 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003410 * Use with {@link #getSystemService} to retrieve a {@link
3411 * android.hardware.SerialManager} for access to serial ports.
3412 *
3413 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003414 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003415 *
3416 * @hide
3417 */
3418 public static final String SERIAL_SERVICE = "serial";
3419
3420 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003421 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003422 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3423 * HDMI-CEC protocol.
3424 *
3425 * @see #getSystemService
3426 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003427 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003428 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003429 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003430 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003431
3432 /**
3433 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003434 * {@link android.hardware.input.InputManager} for interacting with input devices.
3435 *
3436 * @see #getSystemService
3437 * @see android.hardware.input.InputManager
3438 */
3439 public static final String INPUT_SERVICE = "input";
3440
3441 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07003442 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003443 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3444 *
3445 * @see #getSystemService
3446 * @see android.hardware.display.DisplayManager
3447 */
3448 public static final String DISPLAY_SERVICE = "display";
3449
3450 /**
3451 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003452 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3453 *
3454 * @see #getSystemService
3455 * @see android.os.UserManager
3456 */
3457 public static final String USER_SERVICE = "user";
3458
3459 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003460 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003461 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3462 * profiles of a user.
3463 *
3464 * @see #getSystemService
3465 * @see android.content.pm.LauncherApps
3466 */
3467 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3468
3469 /**
3470 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003471 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3472 * and requesting permissions for restricted operations.
3473 * @see #getSystemService
3474 * @see android.content.RestrictionsManager
3475 */
3476 public static final String RESTRICTIONS_SERVICE = "restrictions";
3477
3478 /**
3479 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003480 * {@link android.app.AppOpsManager} for tracking application operations
3481 * on the device.
3482 *
3483 * @see #getSystemService
3484 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003485 */
3486 public static final String APP_OPS_SERVICE = "appops";
3487
3488 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003489 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003490 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003491 * camera devices.
3492 *
3493 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003494 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003495 */
3496 public static final String CAMERA_SERVICE = "camera";
3497
3498 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003499 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003500 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003501 *
3502 * @see #getSystemService
3503 * @see android.print.PrintManager
3504 */
3505 public static final String PRINT_SERVICE = "print";
3506
3507 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003508 * Use with {@link #getSystemService} to retrieve a
3509 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3510 * signals from the device.
3511 *
3512 * @see #getSystemService
3513 * @see android.hardware.ConsumerIrManager
3514 */
3515 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3516
3517 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003518 * {@link android.app.trust.TrustManager} for managing trust agents.
3519 * @see #getSystemService
3520 * @see android.app.trust.TrustManager
3521 * @hide
3522 */
3523 public static final String TRUST_SERVICE = "trust";
3524
3525 /**
Jae Seo39570912014-02-20 18:23:25 -08003526 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003527 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3528 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003529 *
3530 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003531 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003532 */
3533 public static final String TV_INPUT_SERVICE = "tv_input";
3534
3535 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003536 * {@link android.net.NetworkScoreManager} for managing network scoring.
3537 * @see #getSystemService
3538 * @see android.net.NetworkScoreManager
3539 * @hide
3540 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003541 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003542 public static final String NETWORK_SCORE_SERVICE = "network_score";
3543
3544 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003545 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003546 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003547 *
3548 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003549 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003550 */
3551 public static final String USAGE_STATS_SERVICE = "usagestats";
3552
3553 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003554 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003555 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003556 * background tasks.
3557 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003558 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003559 */
Christopher Tate7060b042014-06-09 19:50:00 -07003560 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003561
3562 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003563 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003564 * android.service.persistentdata.PersistentDataBlockManager} instance
3565 * for interacting with a storage device that lives across factory resets.
3566 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003567 * @see #getSystemService
3568 * @see android.service.persistentdata.PersistentDataBlockManager
3569 * @hide
3570 */
Andres Morales33df9372014-09-26 17:08:59 -07003571 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003572 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3573
3574 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003575 * Use with {@link #getSystemService} to retrieve a {@link
3576 * android.media.projection.MediaProjectionManager} instance for managing
3577 * media projection sessions.
3578 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003579 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003580 */
3581 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3582
3583 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003584 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003585 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003586 *
3587 * @see #getSystemService
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003588 */
3589 public static final String MIDI_SERVICE = "midi";
3590
Eric Laurent2035ac82015-03-05 15:18:44 -08003591
3592 /**
3593 * Use with {@link #getSystemService} to retrieve a
3594 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3595 *
3596 * @see #getSystemService
3597 * @hide
3598 */
3599 public static final String RADIO_SERVICE = "radio";
3600
Paul McLeana33be212015-02-20 07:52:45 -08003601 /**
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003602 * Use with {@link #getSystemService} to retrieve a
3603 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
3604 *
3605 * @see #getSystemService
3606 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01003607 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003608
3609 /**
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003610 * TODO Javadoc
3611 *
3612 * @see #getSystemService
3613 * @see android.content.pm.ShortcutManager
Makoto Onuki538c4402016-05-11 13:56:39 -07003614 *
3615 * @hide
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003616 */
3617 public static final String SHORTCUT_SERVICE = "shortcut";
3618
3619 /**
Peng Xu9ff7d222016-02-11 13:02:05 -08003620 * Use with {@link #getSystemService} to retrieve a {@link
3621 * android.hardware.location.ContextHubManager} for accessing context hubs.
3622 *
3623 * @see #getSystemService
3624 * @see android.hardware.location.ContextHubManager
3625 *
3626 * @hide
3627 */
3628 @SystemApi
3629 public static final String CONTEXTHUB_SERVICE = "contexthub";
3630
3631 /**
Joe Onorato713fec82016-03-04 10:34:02 -08003632 * Use with {@link #getSystemService} to retrieve a
3633 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
3634 * memory, etc) metrics.
3635 *
3636 * @see #getSystemService
3637 */
3638 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
3639
3640 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003641 * Determine whether the given permission is allowed for a particular
3642 * process and user ID running in the system.
3643 *
3644 * @param permission The name of the permission being checked.
3645 * @param pid The process ID being checked against. Must be > 0.
3646 * @param uid The user ID being checked against. A uid of 0 is the root
3647 * user, which will pass every permission check.
3648 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003649 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003650 * pid/uid is allowed that permission, or
3651 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3652 *
3653 * @see PackageManager#checkPermission(String, String)
3654 * @see #checkCallingPermission
3655 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003656 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003657 @PackageManager.PermissionResult
3658 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003659
Dianne Hackbornff170242014-11-19 10:59:01 -08003660 /** @hide */
3661 @PackageManager.PermissionResult
3662 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3663 IBinder callerToken);
3664
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003665 /**
3666 * Determine whether the calling process of an IPC you are handling has been
3667 * granted a particular permission. This is basically the same as calling
3668 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3669 * by {@link android.os.Binder#getCallingPid} and
3670 * {@link android.os.Binder#getCallingUid}. One important difference
3671 * is that if you are not currently processing an IPC, this function
3672 * will always fail. This is done to protect against accidentally
3673 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3674 * to avoid this protection.
3675 *
3676 * @param permission The name of the permission being checked.
3677 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003678 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 * pid/uid is allowed that permission, or
3680 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3681 *
3682 * @see PackageManager#checkPermission(String, String)
3683 * @see #checkPermission
3684 * @see #checkCallingOrSelfPermission
3685 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003686 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003687 @PackageManager.PermissionResult
3688 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689
3690 /**
3691 * Determine whether the calling process of an IPC <em>or you</em> have been
3692 * granted a particular permission. This is the same as
3693 * {@link #checkCallingPermission}, except it grants your own permissions
3694 * if you are not currently processing an IPC. Use with care!
3695 *
3696 * @param permission The name of the permission being checked.
3697 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003698 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 * pid/uid is allowed that permission, or
3700 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3701 *
3702 * @see PackageManager#checkPermission(String, String)
3703 * @see #checkPermission
3704 * @see #checkCallingPermission
3705 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003706 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003707 @PackageManager.PermissionResult
3708 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709
3710 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08003711 * Determine whether <em>you</em> have been granted a particular permission.
3712 *
3713 * @param permission The name of the permission being checked.
3714 *
3715 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
3716 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
3717 *
3718 * @see PackageManager#checkPermission(String, String)
3719 * @see #checkCallingPermission(String)
3720 */
3721 @PackageManager.PermissionResult
3722 public abstract int checkSelfPermission(@NonNull String permission);
3723
3724 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 * If the given permission is not allowed for a particular process
3726 * and user ID running in the system, throw a {@link SecurityException}.
3727 *
3728 * @param permission The name of the permission being checked.
3729 * @param pid The process ID being checked against. Must be &gt; 0.
3730 * @param uid The user ID being checked against. A uid of 0 is the root
3731 * user, which will pass every permission check.
3732 * @param message A message to include in the exception if it is thrown.
3733 *
3734 * @see #checkPermission(String, int, int)
3735 */
3736 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003737 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003738
3739 /**
3740 * If the calling process of an IPC you are handling has not been
3741 * granted a particular permission, throw a {@link
3742 * SecurityException}. This is basically the same as calling
3743 * {@link #enforcePermission(String, int, int, String)} with the
3744 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3745 * and {@link android.os.Binder#getCallingUid}. One important
3746 * difference is that if you are not currently processing an IPC,
3747 * this function will always throw the SecurityException. This is
3748 * done to protect against accidentally leaking permissions; you
3749 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3750 * protection.
3751 *
3752 * @param permission The name of the permission being checked.
3753 * @param message A message to include in the exception if it is thrown.
3754 *
3755 * @see #checkCallingPermission(String)
3756 */
3757 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003758 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759
3760 /**
3761 * If neither you nor the calling process of an IPC you are
3762 * handling has been granted a particular permission, throw a
3763 * {@link SecurityException}. This is the same as {@link
3764 * #enforceCallingPermission}, except it grants your own
3765 * permissions if you are not currently processing an IPC. Use
3766 * with care!
3767 *
3768 * @param permission The name of the permission being checked.
3769 * @param message A message to include in the exception if it is thrown.
3770 *
3771 * @see #checkCallingOrSelfPermission(String)
3772 */
3773 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003774 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775
3776 /**
3777 * Grant permission to access a specific Uri to another package, regardless
3778 * of whether that package has general permission to access the Uri's
3779 * content provider. This can be used to grant specific, temporary
3780 * permissions, typically in response to user interaction (such as the
3781 * user opening an attachment that you would like someone else to
3782 * display).
3783 *
3784 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3785 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3786 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3787 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3788 * start an activity instead of this function directly. If you use this
3789 * function directly, you should be sure to call
3790 * {@link #revokeUriPermission} when the target should no longer be allowed
3791 * to access it.
3792 *
3793 * <p>To succeed, the content provider owning the Uri must have set the
3794 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3795 * grantUriPermissions} attribute in its manifest or included the
3796 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3797 * &lt;grant-uri-permissions&gt;} tag.
3798 *
3799 * @param toPackage The package you would like to allow to access the Uri.
3800 * @param uri The Uri you would like to grant access to.
3801 * @param modeFlags The desired access modes. Any combination of
3802 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003803 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003805 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3806 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3807 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3808 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3809 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 *
3811 * @see #revokeUriPermission
3812 */
3813 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003814 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815
3816 /**
3817 * Remove all permissions to access a particular content provider Uri
3818 * that were previously added with {@link #grantUriPermission}. The given
3819 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003820 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003822 * "content://foo". It will not remove any prefix grants that exist at a
3823 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003825 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003826 * regular permission access to a Uri, but had received access to it through
3827 * a specific Uri permission grant, you could not revoke that grant with this
3828 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003829 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003830 * but will remove whatever permission grants to the Uri had been given to the app
3831 * (or none).</p>
3832 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833 * @param uri The Uri you would like to revoke access to.
3834 * @param modeFlags The desired access modes. Any combination of
3835 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3836 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3837 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3838 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3839 *
3840 * @see #grantUriPermission
3841 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003842 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003843
3844 /**
3845 * Determine whether a particular process and user ID has been granted
3846 * permission to access a specific URI. This only checks for permissions
3847 * that have been explicitly granted -- if the given process/uid has
3848 * more general access to the URI's content provider then this check will
3849 * always fail.
3850 *
3851 * @param uri The uri that is being checked.
3852 * @param pid The process ID being checked against. Must be &gt; 0.
3853 * @param uid The user ID being checked against. A uid of 0 is the root
3854 * user, which will pass every permission check.
3855 * @param modeFlags The type of access to grant. May be one or both of
3856 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3857 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3858 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003859 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003860 * pid/uid is allowed to access that uri, or
3861 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3862 *
3863 * @see #checkCallingUriPermission
3864 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003865 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003866 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003867 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868
Dianne Hackbornff170242014-11-19 10:59:01 -08003869 /** @hide */
3870 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3871 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3872
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003873 /**
3874 * Determine whether the calling process and user ID has been
3875 * granted permission to access a specific URI. This is basically
3876 * the same as calling {@link #checkUriPermission(Uri, int, int,
3877 * int)} with the pid and uid returned by {@link
3878 * android.os.Binder#getCallingPid} and {@link
3879 * android.os.Binder#getCallingUid}. One important difference is
3880 * that if you are not currently processing an IPC, this function
3881 * will always fail.
3882 *
3883 * @param uri The uri that is being checked.
3884 * @param modeFlags The type of access to grant. May be one or both of
3885 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3886 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3887 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003888 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003889 * is allowed to access that uri, or
3890 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3891 *
3892 * @see #checkUriPermission(Uri, int, int, int)
3893 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003894 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003895 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003896
3897 /**
3898 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3899 * permission to access a specific URI. This is the same as
3900 * {@link #checkCallingUriPermission}, except it grants your own permissions
3901 * if you are not currently processing an IPC. Use with care!
3902 *
3903 * @param uri The uri that is being checked.
3904 * @param modeFlags The type of access to grant. May be one or both of
3905 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3906 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3907 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003908 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003909 * is allowed to access that uri, or
3910 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3911 *
3912 * @see #checkCallingUriPermission
3913 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003914 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003915 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003916 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917
3918 /**
3919 * Check both a Uri and normal permission. This allows you to perform
3920 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3921 * call.
3922 *
3923 * @param uri The Uri whose permission is to be checked, or null to not
3924 * do this check.
3925 * @param readPermission The permission that provides overall read access,
3926 * or null to not do this check.
3927 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003928 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 * @param pid The process ID being checked against. Must be &gt; 0.
3930 * @param uid The user ID being checked against. A uid of 0 is the root
3931 * user, which will pass every permission check.
3932 * @param modeFlags The type of access to grant. May be one or both of
3933 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3934 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3935 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003936 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003937 * is allowed to access that uri or holds one of the given permissions, or
3938 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3939 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003940 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003941 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3942 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003943 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003944
3945 /**
3946 * If a particular process and user ID has not been granted
3947 * permission to access a specific URI, throw {@link
3948 * SecurityException}. This only checks for permissions that have
3949 * been explicitly granted -- if the given process/uid has more
3950 * general access to the URI's content provider then this check
3951 * will always fail.
3952 *
3953 * @param uri The uri that is being checked.
3954 * @param pid The process ID being checked against. Must be &gt; 0.
3955 * @param uid The user ID being checked against. A uid of 0 is the root
3956 * user, which will pass every permission check.
3957 * @param modeFlags The type of access to grant. May be one or both of
3958 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3959 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3960 * @param message A message to include in the exception if it is thrown.
3961 *
3962 * @see #checkUriPermission(Uri, int, int, int)
3963 */
3964 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003965 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003966
3967 /**
3968 * If the calling process and user ID has not been granted
3969 * permission to access a specific URI, throw {@link
3970 * SecurityException}. This is basically the same as calling
3971 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3972 * the pid and uid returned by {@link
3973 * android.os.Binder#getCallingPid} and {@link
3974 * android.os.Binder#getCallingUid}. One important difference is
3975 * that if you are not currently processing an IPC, this function
3976 * will always throw a SecurityException.
3977 *
3978 * @param uri The uri that is being checked.
3979 * @param modeFlags The type of access to grant. May be one or both of
3980 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3981 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3982 * @param message A message to include in the exception if it is thrown.
3983 *
3984 * @see #checkCallingUriPermission(Uri, int)
3985 */
3986 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003987 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988
3989 /**
3990 * If the calling process of an IPC <em>or you</em> has not been
3991 * granted permission to access a specific URI, throw {@link
3992 * SecurityException}. This is the same as {@link
3993 * #enforceCallingUriPermission}, except it grants your own
3994 * permissions if you are not currently processing an IPC. Use
3995 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003996 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997 * @param uri The uri that is being checked.
3998 * @param modeFlags The type of access to grant. May be one or both of
3999 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4000 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
4001 * @param message A message to include in the exception if it is thrown.
4002 *
4003 * @see #checkCallingOrSelfUriPermission(Uri, int)
4004 */
4005 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004006 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007
4008 /**
4009 * Enforce both a Uri and normal permission. This allows you to perform
4010 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4011 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004012 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 * @param uri The Uri whose permission is to be checked, or null to not
4014 * do this check.
4015 * @param readPermission The permission that provides overall read access,
4016 * or null to not do this check.
4017 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004018 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004019 * @param pid The process ID being checked against. Must be &gt; 0.
4020 * @param uid The user ID being checked against. A uid of 0 is the root
4021 * user, which will pass every permission check.
4022 * @param modeFlags The type of access to grant. May be one or both of
4023 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4024 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
4025 * @param message A message to include in the exception if it is thrown.
4026 *
4027 * @see #checkUriPermission(Uri, String, String, int, int, int)
4028 */
4029 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004030 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004031 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004032 @Nullable String message);
4033
4034 /** @hide */
4035 @IntDef(flag = true,
4036 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
4037 @Retention(RetentionPolicy.SOURCE)
4038 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039
4040 /**
4041 * Flag for use with {@link #createPackageContext}: include the application
4042 * code with the context. This means loading code into the caller's
4043 * process, so that {@link #getClassLoader()} can be used to instantiate
4044 * the application's classes. Setting this flags imposes security
4045 * restrictions on what application context you can access; if the
4046 * requested application can not be safely loaded into your process,
4047 * java.lang.SecurityException will be thrown. If this flag is not set,
4048 * there will be no restrictions on the packages that can be loaded,
4049 * but {@link #getClassLoader} will always return the default system
4050 * class loader.
4051 */
4052 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4053
4054 /**
4055 * Flag for use with {@link #createPackageContext}: ignore any security
4056 * restrictions on the Context being requested, allowing it to always
4057 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4058 * to be loaded into a process even when it isn't safe to do so. Use
4059 * with extreme care!
4060 */
4061 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004062
Romain Guy870e09f2009-07-06 16:35:25 -07004063 /**
4064 * Flag for use with {@link #createPackageContext}: a restricted context may
4065 * disable specific features. For instance, a View associated with a restricted
4066 * context would ignore particular XML attributes.
4067 */
4068 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004069
4070 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004071 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004072 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004073 *
4074 * @hide
4075 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004076 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004077
4078 /**
4079 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004080 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004081 *
4082 * @hide
4083 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004084 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004085
4086 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004087 * @hide Used to indicate we should tell the activity manager about the process
4088 * loading this code.
4089 */
4090 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4091
4092 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004093 * Return a new Context object for the given application name. This
4094 * Context is the same as what the named application gets when it is
4095 * launched, containing the same resources and class loader. Each call to
4096 * this method returns a new instance of a Context object; Context objects
4097 * are not shared, however they share common state (Resources, ClassLoader,
4098 * etc) so the Context instance itself is fairly lightweight.
4099 *
Jeff Brown6e539312015-02-24 18:53:21 -08004100 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 * application with the given package name.
4102 *
4103 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4104 * can not be loaded into the caller's process for security reasons (see
4105 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4106 *
4107 * @param packageName Name of the application's package.
4108 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
4109 * or {@link #CONTEXT_IGNORE_SECURITY}.
4110 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004111 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004112 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004113 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004114 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004115 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004116 */
4117 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004118 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004119
4120 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004121 * Similar to {@link #createPackageContext(String, int)}, but with a
4122 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4123 * will open any {@link Uri} as the given user.
4124 *
4125 * @hide
4126 */
4127 public abstract Context createPackageContextAsUser(
4128 String packageName, int flags, UserHandle user)
4129 throws PackageManager.NameNotFoundException;
4130
4131 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004132 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4133 *
4134 * @hide
4135 */
4136 public abstract Context createApplicationContext(ApplicationInfo application,
4137 int flags) throws PackageManager.NameNotFoundException;
4138
4139 /**
Jim Millera75a8832013-02-07 16:53:32 -08004140 * Get the userId associated with this context
4141 * @return user id
4142 *
4143 * @hide
4144 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004145 @TestApi
Jeff Sharkey8588bc12016-01-06 16:47:42 -07004146 public abstract @UserIdInt int getUserId();
Jim Millera75a8832013-02-07 16:53:32 -08004147
4148 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004149 * Return a new Context object for the current Context but whose resources
4150 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004151 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004152 * shared, however common state (ClassLoader, other Resources for the
4153 * same configuration) may be so the Context itself can be fairly lightweight.
4154 *
4155 * @param overrideConfiguration A {@link Configuration} specifying what
4156 * values to modify in the base Configuration of the original Context's
4157 * resources. If the base configuration changes (such as due to an
4158 * orientation change), the resources of this context will also change except
4159 * for those that have been explicitly overridden with a value here.
4160 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004161 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004162 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004163 public abstract Context createConfigurationContext(
4164 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004165
4166 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004167 * Return a new Context object for the current Context but whose resources
4168 * are adjusted to match the metrics of the given Display. Each call to this method
4169 * returns a new instance of a Context object; Context objects are not
4170 * shared, however common state (ClassLoader, other Resources for the
4171 * same configuration) may be so the Context itself can be fairly lightweight.
4172 *
4173 * The returned display Context provides a {@link WindowManager}
4174 * (see {@link #getSystemService(String)}) that is configured to show windows
4175 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4176 * method can be used to retrieve the Display from the returned Context.
4177 *
4178 * @param display A {@link Display} object specifying the display
4179 * for whose metrics the Context's resources should be tailored and upon which
4180 * new windows should be shown.
4181 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004182 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004183 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004184 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004185
4186 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004187 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004188 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004189 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004190 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004191 * with a key tied to the physical device, and it can be accessed
4192 * immediately after the device has booted successfully, both
4193 * <em>before and after</em> the user has authenticated with their
4194 * credentials (such as a lock pattern or PIN).
4195 * <p>
4196 * Because device-protected data is available without user authentication,
4197 * you should carefully limit the data you store using this Context. For
4198 * example, storing sensitive authentication tokens or passwords in the
4199 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004200 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004201 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004202 * device-protected and credential-protected data using different keys, then
4203 * both storage areas will become available at the same time. They remain as
4204 * two distinct storage locations on disk, and only the window of
4205 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004206 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004207 * Each call to this method returns a new instance of a Context object;
4208 * Context objects are not shared, however common state (ClassLoader, other
4209 * Resources for the same configuration) may be so the Context itself can be
4210 * fairly lightweight.
4211 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004212 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004213 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004214 public abstract Context createDeviceProtectedStorageContext();
4215
4216 /** @removed */
4217 @Deprecated
4218 public Context createDeviceEncryptedStorageContext() {
4219 return createDeviceProtectedStorageContext();
4220 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004221
4222 /**
4223 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004224 * APIs are backed by credential-protected storage. This is the default
4225 * storage area for apps unless
4226 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004227 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004228 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004229 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004230 * <em>only after</em> the user has entered their credentials (such as a
4231 * lock pattern or PIN).
4232 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004233 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004234 * device-protected and credential-protected data using different keys, then
4235 * both storage areas will become available at the same time. They remain as
4236 * two distinct storage locations on disk, and only the window of
4237 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004238 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004239 * Each call to this method returns a new instance of a Context object;
4240 * Context objects are not shared, however common state (ClassLoader, other
4241 * Resources for the same configuration) may be so the Context itself can be
4242 * fairly lightweight.
4243 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004244 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004245 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004246 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004247 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004248 public abstract Context createCredentialProtectedStorageContext();
4249
4250 /** @removed */
4251 @Deprecated
4252 public Context createCredentialEncryptedStorageContext() {
4253 return createCredentialProtectedStorageContext();
4254 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004255
4256 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004257 * Gets the display adjustments holder for this context. This information
4258 * is provided on a per-application or activity basis and is used to simulate lower density
4259 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004260 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004261 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004262 * @return The compatibility info holder, or null if not required by the application.
4263 * @hide
4264 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004265 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004266
4267 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004268 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004269 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004270 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004271 *
Romain Guy870e09f2009-07-06 16:35:25 -07004272 * @see #CONTEXT_RESTRICTED
4273 */
4274 public boolean isRestricted() {
4275 return false;
4276 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004277
4278 /**
4279 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004280 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004281 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004282 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004283 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004284 public abstract boolean isDeviceProtectedStorage();
4285
4286 /** @removed */
4287 @Deprecated
4288 public boolean isDeviceEncryptedStorage() {
4289 return isDeviceProtectedStorage();
4290 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004291
4292 /**
4293 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004294 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004295 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004296 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004297 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004298 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004299 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004300 public abstract boolean isCredentialProtectedStorage();
4301
4302 /** @removed */
4303 @Deprecated
4304 public boolean isCredentialEncryptedStorage() {
4305 return isCredentialProtectedStorage();
4306 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307}