blob: b935b256b88056950544bdf46a468dd10bef98a6 [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 Sesekb9a86662015-12-09 16:22:45 -0500345 */
346 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
347
348 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500349 * Returns an AssetManager instance for the application's package.
350 * <p>
351 * <strong>Note:</strong> Implementations of this method should return
352 * an AssetManager instance that is consistent with the Resources instance
353 * returned by {@link #getResources()}. For example, they should share the
354 * same {@link Configuration} object.
355 *
356 * @return an AssetManager instance for the application's package
357 * @see #getResources()
358 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 public abstract AssetManager getAssets();
360
Alan Viverette713a5cd2015-12-16 15:46:32 -0500361 /**
362 * Returns a Resources instance for the application's package.
363 * <p>
364 * <strong>Note:</strong> Implementations of this method should return
365 * a Resources instance that is consistent with the AssetManager instance
366 * returned by {@link #getAssets()}. For example, they should share the
367 * same {@link Configuration} object.
368 *
369 * @return a Resources instance for the application's package
370 * @see #getAssets()
371 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800372 public abstract Resources getResources();
373
374 /** Return PackageManager instance to find global package information. */
375 public abstract PackageManager getPackageManager();
376
377 /** Return a ContentResolver instance for your application's package. */
378 public abstract ContentResolver getContentResolver();
379
380 /**
381 * Return the Looper for the main thread of the current process. This is
382 * the thread used to dispatch calls to application components (activities,
383 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700384 * <p>
385 * By definition, this method returns the same result as would be obtained
386 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
387 * </p>
388 *
389 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 */
391 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 /**
394 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800395 * current process. This generally should only be used if you need a
396 * Context whose lifecycle is separate from the current context, that is
397 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700398 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800399 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800400 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800401 * <ul>
402 * <li> <p>If used from an Activity context, the receiver is being registered
403 * within that activity. This means that you are expected to unregister
404 * before the activity is done being destroyed; in fact if you do not do
405 * so, the framework will clean up your leaked registration as it removes
406 * the activity and log an error. Thus, if you use the Activity context
407 * to register a receiver that is static (global to the process, not
408 * associated with an Activity instance) then that registration will be
409 * removed on you at whatever point the activity you used is destroyed.
410 * <li> <p>If used from the Context returned here, the receiver is being
411 * registered with the global state associated with your application. Thus
412 * it will never be unregistered for you. This is necessary if the receiver
413 * is associated with static data, not a particular component. However
414 * using the ApplicationContext elsewhere can easily lead to serious leaks
415 * if you forget to unregister, unbind, etc.
416 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800417 */
418 public abstract Context getApplicationContext();
419
420 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700421 * Add a new {@link ComponentCallbacks} to the base application of the
422 * Context, which will be called at the same times as the ComponentCallbacks
423 * methods of activities and other components are called. Note that you
424 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
425 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700426 *
427 * @param callback The interface to call. This can be either a
428 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700429 */
430 public void registerComponentCallbacks(ComponentCallbacks callback) {
431 getApplicationContext().registerComponentCallbacks(callback);
432 }
433
434 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400435 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700436 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
437 */
438 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
439 getApplicationContext().unregisterComponentCallbacks(callback);
440 }
441
442 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 * Return a localized, styled CharSequence from the application's package's
444 * default string table.
445 *
446 * @param resId Resource id for the CharSequence text
447 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700448 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449 return getResources().getText(resId);
450 }
451
452 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700453 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800454 * default string table.
455 *
456 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700457 * @return The string data associated with the resource, stripped of styled
458 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800459 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700460 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700461 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 return getResources().getString(resId);
463 }
464
465 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700466 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 * default string table, substituting the format arguments as defined in
468 * {@link java.util.Formatter} and {@link java.lang.String#format}.
469 *
470 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700471 * @param formatArgs The format arguments that will be used for
472 * substitution.
473 * @return The string data associated with the resource, formatted and
474 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700476 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700477 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478 return getResources().getString(resId, formatArgs);
479 }
480
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800481 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800482 * Returns a color associated with a particular resource ID and styled for
483 * the current theme.
484 *
485 * @param id The desired resource identifier, as generated by the aapt
486 * tool. This integer encodes the package, type, and resource
487 * entry. The value 0 is an invalid identifier.
488 * @return A single color value in the form 0xAARRGGBB.
489 * @throws android.content.res.Resources.NotFoundException if the given ID
490 * does not exist.
491 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700492 @ColorInt
493 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800494 return getResources().getColor(id, getTheme());
495 }
496
497 /**
498 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800499 * styled for the current theme.
500 *
501 * @param id The desired resource identifier, as generated by the aapt
502 * tool. This integer encodes the package, type, and resource
503 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800504 * @return An object that can be used to draw this resource, or
505 * {@code null} if the resource could not be resolved.
506 * @throws android.content.res.Resources.NotFoundException if the given ID
507 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800508 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800509 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700510 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800511 return getResources().getDrawable(id, getTheme());
512 }
513
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800514 /**
515 * Returns a color state list associated with a particular resource ID and
516 * styled for the current theme.
517 *
518 * @param id The desired resource identifier, as generated by the aapt
519 * tool. This integer encodes the package, type, and resource
520 * entry. The value 0 is an invalid identifier.
521 * @return A color state list, or {@code null} if the resource could not be
522 * resolved.
523 * @throws android.content.res.Resources.NotFoundException if the given ID
524 * does not exist.
525 */
526 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700527 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800528 return getResources().getColorStateList(id, getTheme());
529 }
530
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 /**
532 * Set the base theme for this context. Note that this should be called
533 * before any views are instantiated in the Context (for example before
534 * calling {@link android.app.Activity#setContentView} or
535 * {@link android.view.LayoutInflater#inflate}).
536 *
537 * @param resid The style resource describing the theme.
538 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700539 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540
Dianne Hackborn247fe742011-01-08 17:25:57 -0800541 /** @hide Needed for some internal implementation... not public because
542 * you can't assume this actually means anything. */
543 public int getThemeResId() {
544 return 0;
545 }
546
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 /**
548 * Return the Theme object associated with this Context.
549 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700550 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 public abstract Resources.Theme getTheme();
552
553 /**
554 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800555 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 * for more information.
557 *
Jeff Brown6e539312015-02-24 18:53:21 -0800558 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700560 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 return getTheme().obtainStyledAttributes(attrs);
562 }
563
564 /**
565 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800566 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567 * for more information.
568 *
Jeff Brown6e539312015-02-24 18:53:21 -0800569 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 */
571 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700572 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 return getTheme().obtainStyledAttributes(resid, attrs);
574 }
575
576 /**
577 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800578 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 * for more information.
580 *
Jeff Brown6e539312015-02-24 18:53:21 -0800581 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 */
583 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700584 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
586 }
587
588 /**
589 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800590 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591 * for more information.
592 *
Jeff Brown6e539312015-02-24 18:53:21 -0800593 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 */
595 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700596 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
597 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598 return getTheme().obtainStyledAttributes(
599 set, attrs, defStyleAttr, defStyleRes);
600 }
601
602 /**
603 * Return a class loader you can use to retrieve classes in this package.
604 */
605 public abstract ClassLoader getClassLoader();
606
607 /** Return the name of this application's package. */
608 public abstract String getPackageName();
609
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800610 /** @hide Return the name of the base context this context is derived from. */
611 public abstract String getBasePackageName();
612
Dianne Hackborn95d78532013-09-11 09:51:14 -0700613 /** @hide Return the package name that should be used for app ops calls from
614 * this context. This is the same as {@link #getBasePackageName()} except in
615 * cases where system components are loaded into other app processes, in which
616 * case this will be the name of the primary package in that process (so that app
617 * ops uid verification will work with the name). */
618 public abstract String getOpPackageName();
619
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700620 /** Return the full application info for this context's package. */
621 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700622
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 /**
Kenny Root32148392010-01-21 15:40:47 -0800624 * Return the full path to this context's primary Android package.
625 * The Android package is a ZIP file which contains the application's
626 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 *
628 * <p>Note: this is not generally useful for applications, since they should
629 * not be directly accessing the file system.
630 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 * @return String Path to the resources.
632 */
633 public abstract String getPackageResourcePath();
634
635 /**
Kenny Root32148392010-01-21 15:40:47 -0800636 * Return the full path to this context's primary Android package.
637 * The Android package is a ZIP file which contains application's
638 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 *
640 * <p>Note: this is not generally useful for applications, since they should
641 * not be directly accessing the file system.
642 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 * @return String Path to the code and assets.
644 */
645 public abstract String getPackageCodePath();
646
647 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700648 * @hide
649 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700650 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700651 @Deprecated
652 public File getSharedPrefsFile(String name) {
653 return getSharedPreferencesPath(name);
654 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700655
656 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 * Retrieve and hold the contents of the preferences file 'name', returning
658 * a SharedPreferences through which you can retrieve and modify its
659 * values. Only one instance of the SharedPreferences object is returned
660 * to any callers for the same name, meaning they will see each other's
661 * edits as soon as they are made.
662 *
663 * @param name Desired preferences file. If a preferences file by this name
664 * does not exist, it will be created when you retrieve an
665 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
666 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700667 * default operation.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400669 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 * to retrieve and modify the preference values.
671 *
672 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 */
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700674 public abstract SharedPreferences getSharedPreferences(String name, int mode);
675
676 /**
677 * Retrieve and hold the contents of the preferences file, returning
678 * a SharedPreferences through which you can retrieve and modify its
679 * values. Only one instance of the SharedPreferences object is returned
680 * to any callers for the same name, meaning they will see each other's
681 * edits as soon as they are made.
682 *
683 * @param file Desired preferences file. If a preferences file by this name
684 * does not exist, it will be created when you retrieve an
685 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
686 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700687 * default operation.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700688 *
689 * @return The single {@link SharedPreferences} instance that can be used
690 * to retrieve and modify the preference values.
691 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700692 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700693 * @see #MODE_PRIVATE
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700694 */
695 public abstract SharedPreferences getSharedPreferences(File file, int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696
697 /**
Jeff Sharkey35871f22016-01-29 17:13:29 -0700698 * Migrate an existing shared preferences file from the given source storage
699 * context to this context. This is typically used to migrate data between
700 * storage locations after an upgrade, such as migrating from credential
701 * encrypted to device encrypted storage.
702 *
703 * @param sourceContext The source context which contains the existing
704 * shared preferences to migrate.
705 * @param name The name of the shared preferences file.
706 * @return {@code true} if the migration was successful or if the shared
707 * preferences didn't exist in the source context, otherwise
708 * {@code false}.
709 * @see #createDeviceEncryptedStorageContext()
710 */
711 public abstract boolean migrateSharedPreferencesFrom(Context sourceContext, String name);
712
713 /**
714 * Delete an existing shared preferences file.
715 *
716 * @param name The name (unique in the application package) of the shared
717 * preferences file.
718 * @return {@code true} if the shared preferences file was successfully
719 * deleted; else {@code false}.
720 * @see #getSharedPreferences(String, int)
721 */
722 public abstract boolean deleteSharedPreferences(String name);
723
724 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 * Open a private file associated with this Context's application package
726 * for reading.
727 *
728 * @param name The name of the file to open; can not contain path
729 * separators.
730 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400731 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 *
733 * @see #openFileOutput
734 * @see #fileList
735 * @see #deleteFile
736 * @see java.io.FileInputStream#FileInputStream(String)
737 */
738 public abstract FileInputStream openFileInput(String name)
739 throws FileNotFoundException;
740
741 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800742 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700743 * for writing. Creates the file if it doesn't already exist.
744 * <p>
745 * No additional permissions are required for the calling app to read or
746 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700747 *
Nick Kralevich15069212013-01-09 15:54:56 -0800748 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700749 * separators.
750 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700751 * default operation. Use {@link #MODE_APPEND} to append to an
752 * existing file.
John Spurlock6098c5d2013-06-17 10:32:46 -0400753 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 * @see #MODE_APPEND
755 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 * @see #openFileInput
757 * @see #fileList
758 * @see #deleteFile
759 * @see java.io.FileOutputStream#FileOutputStream(String)
760 */
761 public abstract FileOutputStream openFileOutput(String name, int mode)
762 throws FileNotFoundException;
763
764 /**
765 * Delete the given private file associated with this Context's
766 * application package.
767 *
768 * @param name The name of the file to delete; can not contain path
769 * separators.
770 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400771 * @return {@code true} if the file was successfully deleted; else
772 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 *
774 * @see #openFileInput
775 * @see #openFileOutput
776 * @see #fileList
777 * @see java.io.File#delete()
778 */
779 public abstract boolean deleteFile(String name);
780
781 /**
782 * Returns the absolute path on the filesystem where a file created with
783 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700784 * <p>
785 * The returned path may change over time if the calling app is moved to an
786 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 *
788 * @param name The name of the file for which you would like to get
789 * its path.
790 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400791 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 *
793 * @see #openFileOutput
794 * @see #getFilesDir
795 * @see #getDir
796 */
797 public abstract File getFileStreamPath(String name);
798
799 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700800 * Returns the absolute path on the filesystem where a file created with
801 * {@link #getSharedPreferences(String, int)} is stored.
802 * <p>
803 * The returned path may change over time if the calling app is moved to an
804 * adopted storage device, so only relative paths should be persisted.
805 *
806 * @param name The name of the shared preferences for which you would like
807 * to get a path.
808 * @return An absolute path to the given file.
809 * @see #getSharedPreferences(String, int)
810 */
811 public abstract File getSharedPreferencesPath(String name);
812
813 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700814 * Returns the absolute path to the directory on the filesystem where all
815 * private files belonging to this app are stored. This is the top-level
816 * directory under which {@link #getFilesDir()}, {@link #getCacheDir()}, etc
817 * are contained. Apps should <em>not</em> create any files or directories
818 * as direct children of this directory, since it's a reserved namespace
819 * belonging to the platform. Instead, use {@link #getDir(String, int)} or
820 * other storage APIs.
821 * <p>
822 * The returned path may change over time if the calling app is moved to an
823 * adopted storage device, so only relative paths should be persisted.
824 * <p>
825 * No additional permissions are required for the calling app to read or
826 * write files under the returned path.
827 *
828 * @see #getDir(String, int)
829 */
830 public abstract File getDataDir();
831
832 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700833 * Returns the absolute path to the directory on the filesystem where files
834 * created with {@link #openFileOutput} are stored.
835 * <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.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700841 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400842 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 * @see #openFileOutput
844 * @see #getFileStreamPath
845 * @see #getDir
846 */
847 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700848
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700850 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700851 * {@link #getFilesDir()}. The difference is that files placed under this
852 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700853 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
854 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700855 * <p>
856 * The returned path may change over time if the calling app is moved to an
857 * adopted storage device, so only relative paths should be persisted.
858 * <p>
859 * No additional permissions are required for the calling app to read or
860 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700861 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700862 * @return The path of the directory holding application files that will not
863 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700864 * @see #openFileOutput
865 * @see #getFileStreamPath
866 * @see #getDir
867 * @see android.app.backup.BackupAgent
868 */
869 public abstract File getNoBackupFilesDir();
870
871 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700872 * Returns the absolute path to the directory on the primary shared/external
873 * storage device where the application can place persistent files it owns.
874 * These files are internal to the applications, and not typically visible
875 * to the user as media.
876 * <p>
877 * This is like {@link #getFilesDir()} in that these files will be deleted
878 * when the application is uninstalled, however there are some important
879 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800880 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700881 * <li>Shared storage may not always be available, since removable media can
882 * be ejected by the user. Media state can be checked using
883 * {@link Environment#getExternalStorageState(File)}.
884 * <li>There is no security enforced with these files. For example, any
885 * application holding
886 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700887 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800888 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700889 * <p>
890 * If a shared storage device is emulated (as determined by
891 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
892 * backed by a private user data partition, which means there is little
893 * benefit to storing data here instead of the private directories returned
894 * by {@link #getFilesDir()}, etc.
895 * <p>
896 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700897 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700898 * accessible to the calling app. This only applies to paths generated for
899 * package name of the calling application. To access paths belonging to
900 * other packages,
901 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
902 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
903 * <p>
904 * On devices with multiple users (as described by {@link UserManager}),
905 * each user has their own isolated shared storage. Applications only have
906 * access to the shared storage for the user they're running as.
907 * <p>
908 * The returned path may change over time if different shared storage media
909 * is inserted, so only relative paths should be persisted.
910 * <p>
911 * Here is an example of typical code to manipulate a file in an
912 * application's shared storage:
913 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800914 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
915 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700916 * <p>
917 * If you supply a non-null <var>type</var> to this function, the returned
918 * file will be a path to a sub-directory of the given type. Though these
919 * files are not automatically scanned by the media scanner, you can
920 * explicitly add them to the media database with
921 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
922 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800923 * {@link android.os.Environment#getExternalStoragePublicDirectory
924 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700925 * directories of media shared by all applications. The directories returned
926 * here are owned by the application, and their contents will be removed
927 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800928 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700929 * Environment.getExternalStoragePublicDirectory()}, the directory returned
930 * here will be automatically created for you.
931 * <p>
932 * Here is an example of typical code to manipulate a picture in an
933 * application's shared storage and add it to the media database:
934 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800935 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
936 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700937 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700938 * @param type The type of files directory to return. May be {@code null}
939 * for the root of the files directory or one of the following
940 * constants for a subdirectory:
941 * {@link android.os.Environment#DIRECTORY_MUSIC},
942 * {@link android.os.Environment#DIRECTORY_PODCASTS},
943 * {@link android.os.Environment#DIRECTORY_RINGTONES},
944 * {@link android.os.Environment#DIRECTORY_ALARMS},
945 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
946 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
947 * {@link android.os.Environment#DIRECTORY_MOVIES}.
948 * @return the absolute path to application-specific directory. May return
949 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800950 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700951 * @see #getExternalFilesDirs(String)
952 * @see Environment#getExternalStorageState(File)
953 * @see Environment#isExternalStorageEmulated(File)
954 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800955 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700956 @Nullable
957 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700958
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800959 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700960 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700961 * shared/external storage devices where the application can place
962 * persistent files it owns. These files are internal to the application,
963 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700964 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700965 * This is like {@link #getFilesDir()} in that these files will be deleted
966 * when the application is uninstalled, however there are some important
967 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700968 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700969 * <li>Shared storage may not always be available, since removable media can
970 * be ejected by the user. Media state can be checked using
971 * {@link Environment#getExternalStorageState(File)}.
972 * <li>There is no security enforced with these files. For example, any
973 * application holding
974 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
975 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700976 * </ul>
977 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700978 * If a shared storage device is emulated (as determined by
979 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
980 * backed by a private user data partition, which means there is little
981 * benefit to storing data here instead of the private directories returned
982 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700983 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700984 * Shared storage devices returned here are considered a stable part of the
985 * device, including physical media slots under a protective cover. The
986 * returned paths do not include transient devices, such as USB flash drives
987 * connected to handheld devices.
988 * <p>
989 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700990 * example, an app may choose to store large files on the device with the
991 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700992 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700993 * No additional permissions are required for the calling app to read or
994 * write files under the returned path. Write access outside of these paths
995 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700996 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700997 * The returned path may change over time if different shared storage media
998 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -0700999 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001000 * @param type The type of files directory to return. May be {@code null}
1001 * for the root of the files directory or one of the following
1002 * constants for a subdirectory:
1003 * {@link android.os.Environment#DIRECTORY_MUSIC},
1004 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1005 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1006 * {@link android.os.Environment#DIRECTORY_ALARMS},
1007 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1008 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1009 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1010 * @return the absolute paths to application-specific directories. Some
1011 * individual paths may be {@code null} if that shared storage is
1012 * not currently available. The first path returned is the same as
1013 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001014 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001015 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001016 * @see Environment#isExternalStorageEmulated(File)
1017 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001018 */
1019 public abstract File[] getExternalFilesDirs(String type);
1020
1021 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001022 * Return the primary shared/external storage directory where this
1023 * application's OBB files (if there are any) can be found. Note if the
1024 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001025 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001026 * This is like {@link #getFilesDir()} in that these files will be deleted
1027 * when the application is uninstalled, however there are some important
1028 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001029 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001030 * <li>Shared storage may not always be available, since removable media can
1031 * be ejected by the user. Media state can be checked using
1032 * {@link Environment#getExternalStorageState(File)}.
1033 * <li>There is no security enforced with these files. For example, any
1034 * application holding
1035 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001036 * these files.
1037 * </ul>
1038 * <p>
1039 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1040 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001041 * accessible to the calling app. This only applies to paths generated for
1042 * package name of the calling application. To access paths belonging to
1043 * other packages,
1044 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1045 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001046 * <p>
1047 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001048 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001049 * should ensure that multiple instances running under different users don't
1050 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001051 *
1052 * @return the absolute path to application-specific directory. May return
1053 * {@code null} if shared storage is not currently available.
1054 * @see #getObbDirs()
1055 * @see Environment#getExternalStorageState(File)
1056 * @see Environment#isExternalStorageEmulated(File)
1057 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001058 */
1059 public abstract File getObbDir();
1060
1061 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001062 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001063 * shared/external storage devices where the application's OBB files (if
1064 * there are any) can be found. Note if the application does not have any
1065 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001066 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001067 * This is like {@link #getFilesDir()} in that these files will be deleted
1068 * when the application is uninstalled, however there are some important
1069 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001070 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001071 * <li>Shared storage may not always be available, since removable media can
1072 * be ejected by the user. Media state can be checked using
1073 * {@link Environment#getExternalStorageState(File)}.
1074 * <li>There is no security enforced with these files. For example, any
1075 * application holding
1076 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1077 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001078 * </ul>
1079 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001080 * Shared storage devices returned here are considered a stable part of the
1081 * device, including physical media slots under a protective cover. The
1082 * returned paths do not include transient devices, such as USB flash drives
1083 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001084 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001085 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001086 * example, an app may choose to store large files on the device with the
1087 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001088 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001089 * No additional permissions are required for the calling app to read or
1090 * write files under the returned path. Write access outside of these paths
1091 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001092 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001093 * @return the absolute paths to application-specific directories. Some
1094 * individual paths may be {@code null} if that shared storage is
1095 * not currently available. The first path returned is the same as
1096 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001097 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001098 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001099 * @see Environment#isExternalStorageEmulated(File)
1100 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001101 */
1102 public abstract File[] getObbDirs();
1103
1104 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001105 * Returns the absolute path to the application specific cache directory on
1106 * the filesystem. These files will be ones that get deleted first when the
1107 * device runs low on storage. There is no guarantee when these files will
1108 * be deleted.
1109 * <p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001110 * <strong>Note: you should not <em>rely</em> on the system deleting these
1111 * files for you; you should always have a reasonable maximum, such as 1 MB,
1112 * for the amount of space you consume with cache files, and prune those
1113 * files when exceeding that space.</strong>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001114 * <p>
1115 * The returned path may change over time if the calling app is moved to an
1116 * adopted storage device, so only relative paths should be persisted.
1117 * <p>
1118 * Apps require no extra permissions to read or write to the returned path,
1119 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001120 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001121 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001122 * @see #openFileOutput
1123 * @see #getFileStreamPath
1124 * @see #getDir
1125 */
1126 public abstract File getCacheDir();
1127
1128 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001129 * Returns the absolute path to the application specific cache directory on
1130 * the filesystem designed for storing cached code. The system will delete
1131 * any files stored in this location both when your specific application is
1132 * upgraded, and when the entire platform is upgraded.
1133 * <p>
1134 * This location is optimal for storing compiled or optimized code generated
1135 * by your application at runtime.
1136 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001137 * The returned path may change over time if the calling app is moved to an
1138 * adopted storage device, so only relative paths should be persisted.
1139 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001140 * Apps require no extra permissions to read or write to the returned path,
1141 * since this path lives in their private storage.
1142 *
1143 * @return The path of the directory holding application code cache files.
1144 */
1145 public abstract File getCodeCacheDir();
1146
1147 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001148 * Returns absolute path to application-specific directory on the primary
1149 * shared/external storage device where the application can place cache
1150 * files it owns. These files are internal to the application, and not
1151 * typically visible to the user as media.
1152 * <p>
1153 * This is like {@link #getCacheDir()} in that these files will be deleted
1154 * when the application is uninstalled, however there are some important
1155 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001156 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001157 * <li>The platform does not always monitor the space available in shared
1158 * storage, and thus may not automatically delete these files. Apps should
1159 * always manage the maximum space used in this location. Currently the only
1160 * time files here will be deleted by the platform is when running on
1161 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1162 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1163 * <li>Shared storage may not always be available, since removable media can
1164 * be ejected by the user. Media state can be checked using
1165 * {@link Environment#getExternalStorageState(File)}.
1166 * <li>There is no security enforced with these files. For example, any
1167 * application holding
1168 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001169 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001170 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001171 * <p>
1172 * If a shared storage device is emulated (as determined by
1173 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1174 * backed by a private user data partition, which means there is little
1175 * benefit to storing data here instead of the private directory returned by
1176 * {@link #getCacheDir()}.
1177 * <p>
1178 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001179 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001180 * accessible to the calling app. This only applies to paths generated for
1181 * package name of the calling application. To access paths belonging to
1182 * other packages,
1183 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1184 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1185 * <p>
1186 * On devices with multiple users (as described by {@link UserManager}),
1187 * each user has their own isolated shared storage. Applications only have
1188 * access to the shared storage for the user they're running as.
1189 * <p>
1190 * The returned path may change over time if different shared storage media
1191 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001192 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001193 * @return the absolute path to application-specific directory. May return
1194 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001195 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001196 * @see #getExternalCacheDirs()
1197 * @see Environment#getExternalStorageState(File)
1198 * @see Environment#isExternalStorageEmulated(File)
1199 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001200 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001201 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001202 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001203
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001204 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001205 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001206 * shared/external storage devices where the application can place cache
1207 * files it owns. These files are internal to the application, and not
1208 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001209 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001210 * This is like {@link #getCacheDir()} in that these files will be deleted
1211 * when the application is uninstalled, however there are some important
1212 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001213 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001214 * <li>The platform does not always monitor the space available in shared
1215 * storage, and thus may not automatically delete these files. Apps should
1216 * always manage the maximum space used in this location. Currently the only
1217 * time files here will be deleted by the platform is when running on
1218 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1219 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1220 * <li>Shared storage may not always be available, since removable media can
1221 * be ejected by the user. Media state can be checked using
1222 * {@link Environment#getExternalStorageState(File)}.
1223 * <li>There is no security enforced with these files. For example, any
1224 * application holding
1225 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1226 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001227 * </ul>
1228 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001229 * If a shared storage device is emulated (as determined by
1230 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1231 * backed by a private user data partition, which means there is little
1232 * benefit to storing data here instead of the private directory returned by
1233 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001234 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001235 * Shared storage devices returned here are considered a stable part of the
1236 * device, including physical media slots under a protective cover. The
1237 * returned paths do not include transient devices, such as USB flash drives
1238 * connected to handheld devices.
1239 * <p>
1240 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001241 * example, an app may choose to store large files on the device with the
1242 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001243 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001244 * No additional permissions are required for the calling app to read or
1245 * write files under the returned path. Write access outside of these paths
1246 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001247 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001248 * The returned paths may change over time if different shared storage media
1249 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001250 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001251 * @return the absolute paths to application-specific directories. Some
1252 * individual paths may be {@code null} if that shared storage is
1253 * not currently available. The first path returned is the same as
1254 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001255 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001256 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001257 * @see Environment#isExternalStorageEmulated(File)
1258 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001259 */
1260 public abstract File[] getExternalCacheDirs();
1261
1262 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001263 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001264 * shared/external storage devices where the application can place media
1265 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001266 * {@link MediaStore}.
1267 * <p>
1268 * This is like {@link #getExternalFilesDirs} in that these files will be
1269 * deleted when the application is uninstalled, however there are some
1270 * important differences:
1271 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001272 * <li>Shared storage may not always be available, since removable media can
1273 * be ejected by the user. Media state can be checked using
1274 * {@link Environment#getExternalStorageState(File)}.
1275 * <li>There is no security enforced with these files. For example, any
1276 * application holding
1277 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1278 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001279 * </ul>
1280 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001281 * Shared storage devices returned here are considered a stable part of the
1282 * device, including physical media slots under a protective cover. The
1283 * returned paths do not include transient devices, such as USB flash drives
1284 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001285 * <p>
1286 * An application may store data on any or all of the returned devices. For
1287 * example, an app may choose to store large files on the device with the
1288 * most available space, as measured by {@link StatFs}.
1289 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001290 * No additional permissions are required for the calling app to read or
1291 * write files under the returned path. Write access outside of these paths
1292 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001293 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001294 * The returned paths may change over time if different shared storage media
1295 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001296 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001297 * @return the absolute paths to application-specific directories. Some
1298 * individual paths may be {@code null} if that shared storage is
1299 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001300 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001301 * @see Environment#isExternalStorageEmulated(File)
1302 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001303 */
1304 public abstract File[] getExternalMediaDirs();
1305
1306 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001307 * Returns an array of strings naming the private files associated with
1308 * this Context's application package.
1309 *
1310 * @return Array of strings naming the private files.
1311 *
1312 * @see #openFileInput
1313 * @see #openFileOutput
1314 * @see #deleteFile
1315 */
1316 public abstract String[] fileList();
1317
1318 /**
1319 * Retrieve, creating if needed, a new directory in which the application
1320 * can place its own custom data files. You can use the returned File
1321 * object to create and access files in this directory. Note that files
1322 * created through a File object will only be accessible by your own
1323 * application; you can only set the mode of the entire directory, not
1324 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001325 * <p>
1326 * The returned path may change over time if the calling app is moved to an
1327 * adopted storage device, so only relative paths should be persisted.
1328 * <p>
1329 * Apps require no extra permissions to read or write to the returned path,
1330 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001331 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001332 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001333 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001334 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -07001335 * default operation.
Nick Kralevich15069212013-01-09 15:54:56 -08001336 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001337 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001338 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001339 *
1340 * @see #openFileOutput(String, int)
1341 */
1342 public abstract File getDir(String name, int mode);
1343
1344 /**
1345 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001346 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001347 *
1348 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001349 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1350 * default operation. Use
1351 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1352 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1353 * to disable localized collators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001354 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001355 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001356 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001357 * @throws android.database.sqlite.SQLiteException if the database file
1358 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001359 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001360 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001361 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 * @see #deleteDatabase
1363 */
1364 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1365 int mode, CursorFactory factory);
1366
1367 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001368 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001369 * application package. Creates the database file if it doesn't exist.
1370 * <p>
1371 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1372 * to be used to handle corruption when sqlite reports database corruption.
1373 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001374 *
1375 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001376 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1377 * default operation. Use
1378 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1379 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1380 * to disable localized collators.
Vasu Nori74f170f2010-06-01 18:06:18 -07001381 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001382 * cursor when query is called.
1383 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1384 * sqlite reports database corruption. if null,
1385 * {@link android.database.DefaultDatabaseErrorHandler} is
1386 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001387 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001388 * @throws android.database.sqlite.SQLiteException if the database file
1389 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001390 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001391 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001392 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001393 * @see #deleteDatabase
1394 */
1395 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001396 int mode, CursorFactory factory,
1397 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001398
1399 /**
Jeff Sharkey35871f22016-01-29 17:13:29 -07001400 * Migrate an existing database file from the given source storage context
1401 * to this context. This is typically used to migrate data between storage
1402 * locations after an upgrade, such as migrating from credential encrypted
1403 * to device encrypted storage.
1404 *
1405 * @param sourceContext The source context which contains the existing
1406 * database to migrate.
1407 * @param name The name of the database file.
1408 * @return {@code true} if the migration was successful or if the database
1409 * didn't exist in the source context, otherwise {@code false}.
1410 * @see #createDeviceEncryptedStorageContext()
1411 */
1412 public abstract boolean migrateDatabaseFrom(Context sourceContext, String name);
1413
1414 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001415 * Delete an existing private SQLiteDatabase associated with this Context's
1416 * application package.
1417 *
1418 * @param name The name (unique in the application package) of the
1419 * database.
1420 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001421 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001422 *
1423 * @see #openOrCreateDatabase
1424 */
1425 public abstract boolean deleteDatabase(String name);
1426
1427 /**
1428 * Returns the absolute path on the filesystem where a database created with
1429 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001430 * <p>
1431 * The returned path may change over time if the calling app is moved to an
1432 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001433 *
1434 * @param name The name of the database for which you would like to get
1435 * its path.
1436 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001437 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 *
1439 * @see #openOrCreateDatabase
1440 */
1441 public abstract File getDatabasePath(String name);
1442
1443 /**
1444 * Returns an array of strings naming the private databases associated with
1445 * this Context's application package.
1446 *
1447 * @return Array of strings naming the private databases.
1448 *
1449 * @see #openOrCreateDatabase
1450 * @see #deleteDatabase
1451 */
1452 public abstract String[] databaseList();
1453
1454 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001455 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001456 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001457 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001458 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 public abstract Drawable getWallpaper();
1460
1461 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001462 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001463 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001464 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001465 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001466 public abstract Drawable peekWallpaper();
1467
1468 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001469 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1470 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001472 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 public abstract int getWallpaperDesiredMinimumWidth();
1474
1475 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001476 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1477 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001479 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001480 public abstract int getWallpaperDesiredMinimumHeight();
1481
1482 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001483 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001484 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001485 * <p>This method requires the caller to hold the permission
1486 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001488 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001489 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1490
1491 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001492 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001493 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001494 * <p>This method requires the caller to hold the permission
1495 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001497 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 public abstract void setWallpaper(InputStream data) throws IOException;
1499
1500 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001501 * @deprecated Use {@link android.app.WallpaperManager#clear
1502 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001503 * <p>This method requires the caller to hold the permission
1504 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001506 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 public abstract void clearWallpaper() throws IOException;
1508
1509 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001510 * Same as {@link #startActivity(Intent, Bundle)} with no options
1511 * specified.
1512 *
1513 * @param intent The description of the activity to start.
1514 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001515 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001516 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001517 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001518 * @see PackageManager#resolveActivity
1519 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001520 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001521
1522 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001523 * Version of {@link #startActivity(Intent)} that allows you to specify the
1524 * user the activity will be started for. This is not available to applications
1525 * that are not pre-installed on the system image. Using it requires holding
1526 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001527 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001528 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001529 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001530 * @hide
1531 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001532 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001533 throw new RuntimeException("Not implemented. Must override in a subclass.");
1534 }
1535
1536 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 * Launch a new activity. You will not receive any information about when
1538 * the activity exits.
1539 *
1540 * <p>Note that if this method is being called from outside of an
1541 * {@link android.app.Activity} Context, then the Intent must include
1542 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1543 * without being started from an existing Activity, there is no existing
1544 * task in which to place the new activity and thus it needs to be placed
1545 * in its own separate task.
1546 *
1547 * <p>This method throws {@link ActivityNotFoundException}
1548 * if there was no Activity found to run the given Intent.
1549 *
1550 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001551 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001552 * May be null if there are no options. See {@link android.app.ActivityOptions}
1553 * for how to build the Bundle supplied here; there are no supported definitions
1554 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001555 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001556 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001557 *
Scott Main60dd5202012-06-23 00:01:22 -07001558 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 * @see PackageManager#resolveActivity
1560 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001561 public abstract void startActivity(@RequiresPermission Intent intent,
1562 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001563
1564 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001565 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1566 * user the activity will be started for. This is not available to applications
1567 * that are not pre-installed on the system image. Using it requires holding
1568 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001569 * @param intent The description of the activity to start.
1570 * @param options Additional options for how the Activity should be started.
1571 * May be null if there are no options. See {@link android.app.ActivityOptions}
1572 * for how to build the Bundle supplied here; there are no supported definitions
1573 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001574 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001575 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001576 * @hide
1577 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001578 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1579 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001580 throw new RuntimeException("Not implemented. Must override in a subclass.");
1581 }
1582
1583 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001584 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1585 * is only supported for Views and Fragments.
1586 * @param who The identifier for the calling element that will receive the result.
1587 * @param intent The intent to start.
1588 * @param requestCode The code that will be returned with onActivityResult() identifying this
1589 * request.
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.
1594 * @hide
1595 */
1596 public void startActivityForResult(
1597 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1598 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1599 + "Check canStartActivityForResult() before calling.");
1600 }
1601
1602 /**
1603 * Identifies whether this Context instance will be able to process calls to
1604 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1605 * @hide
1606 */
1607 public boolean canStartActivityForResult() {
1608 return false;
1609 }
1610
1611 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001612 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1613 * specified.
1614 *
1615 * @param intents An array of Intents to be started.
1616 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001617 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001618 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001619 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001620 * @see PackageManager#resolveActivity
1621 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001622 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623
1624 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001625 * Launch multiple new activities. This is generally the same as calling
1626 * {@link #startActivity(Intent)} for the first Intent in the array,
1627 * that activity during its creation calling {@link #startActivity(Intent)}
1628 * for the second entry, etc. Note that unlike that approach, generally
1629 * none of the activities except the last in the array will be created
1630 * at this point, but rather will be created when the user first visits
1631 * them (due to pressing back from the activity on top).
1632 *
1633 * <p>This method throws {@link ActivityNotFoundException}
1634 * if there was no Activity found for <em>any</em> given Intent. In this
1635 * case the state of the activity stack is undefined (some Intents in the
1636 * list may be on it, some not), so you probably want to avoid such situations.
1637 *
1638 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001639 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001640 * See {@link android.content.Context#startActivity(Intent, Bundle)
1641 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001642 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001643 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001644 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001645 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001646 * @see PackageManager#resolveActivity
1647 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001648 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001649
1650 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001651 * @hide
1652 * Launch multiple new activities. This is generally the same as calling
1653 * {@link #startActivity(Intent)} for the first Intent in the array,
1654 * that activity during its creation calling {@link #startActivity(Intent)}
1655 * for the second entry, etc. Note that unlike that approach, generally
1656 * none of the activities except the last in the array will be created
1657 * at this point, but rather will be created when the user first visits
1658 * them (due to pressing back from the activity on top).
1659 *
1660 * <p>This method throws {@link ActivityNotFoundException}
1661 * if there was no Activity found for <em>any</em> given Intent. In this
1662 * case the state of the activity stack is undefined (some Intents in the
1663 * list may be on it, some not), so you probably want to avoid such situations.
1664 *
1665 * @param intents An array of Intents to be started.
1666 * @param options Additional options for how the Activity should be started.
1667 * @param userHandle The user for whom to launch the activities
1668 * See {@link android.content.Context#startActivity(Intent, Bundle)
1669 * Context.startActivity(Intent, Bundle)} for more details.
1670 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001671 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001672 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001673 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001674 * @see PackageManager#resolveActivity
1675 */
1676 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1677 throw new RuntimeException("Not implemented. Must override in a subclass.");
1678 }
1679
1680 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001681 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1682 * with no options specified.
1683 *
1684 * @param intent The IntentSender to launch.
1685 * @param fillInIntent If non-null, this will be provided as the
1686 * intent parameter to {@link IntentSender#sendIntent}.
1687 * @param flagsMask Intent flags in the original IntentSender that you
1688 * would like to change.
1689 * @param flagsValues Desired values for any bits set in
1690 * <var>flagsMask</var>
1691 * @param extraFlags Always set to 0.
1692 *
1693 * @see #startActivity(Intent)
1694 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1695 */
1696 public abstract void startIntentSender(IntentSender intent,
1697 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1698 throws IntentSender.SendIntentException;
1699
1700 /**
1701 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001702 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001703 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001704 * here; otherwise, its associated action will be executed (such as
1705 * sending a broadcast) as if you had called
1706 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001707 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001708 * @param intent The IntentSender to launch.
1709 * @param fillInIntent If non-null, this will be provided as the
1710 * intent parameter to {@link IntentSender#sendIntent}.
1711 * @param flagsMask Intent flags in the original IntentSender that you
1712 * would like to change.
1713 * @param flagsValues Desired values for any bits set in
1714 * <var>flagsMask</var>
1715 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001716 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001717 * See {@link android.content.Context#startActivity(Intent, Bundle)
1718 * Context.startActivity(Intent, Bundle)} for more details. If options
1719 * have also been supplied by the IntentSender, options given here will
1720 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001721 *
1722 * @see #startActivity(Intent, Bundle)
1723 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001724 */
1725 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001726 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001727 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001728
1729 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 * Broadcast the given intent to all interested BroadcastReceivers. This
1731 * call is asynchronous; it returns immediately, and you will continue
1732 * executing while the receivers are run. No results are propagated from
1733 * receivers and receivers can not abort the broadcast. If you want
1734 * to allow receivers to propagate results or abort the broadcast, you must
1735 * send an ordered broadcast using
1736 * {@link #sendOrderedBroadcast(Intent, String)}.
1737 *
1738 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1739 *
1740 * @param intent The Intent to broadcast; all receivers matching this
1741 * Intent will receive the broadcast.
1742 *
1743 * @see android.content.BroadcastReceiver
1744 * @see #registerReceiver
1745 * @see #sendBroadcast(Intent, String)
1746 * @see #sendOrderedBroadcast(Intent, String)
1747 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1748 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001749 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750
1751 /**
1752 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1753 * an optional required permission to be enforced. This
1754 * call is asynchronous; it returns immediately, and you will continue
1755 * executing while the receivers are run. No results are propagated from
1756 * receivers and receivers can not abort the broadcast. If you want
1757 * to allow receivers to propagate results or abort the broadcast, you must
1758 * send an ordered broadcast using
1759 * {@link #sendOrderedBroadcast(Intent, String)}.
1760 *
1761 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1762 *
1763 * @param intent The Intent to broadcast; all receivers matching this
1764 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001765 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 * a receiver must hold in order to receive your broadcast.
1767 * If null, no permission is required.
1768 *
1769 * @see android.content.BroadcastReceiver
1770 * @see #registerReceiver
1771 * @see #sendBroadcast(Intent)
1772 * @see #sendOrderedBroadcast(Intent, String)
1773 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1774 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001775 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001776 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001778
1779 /**
1780 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1781 * an array of required permissions to be enforced. This call is asynchronous; it returns
1782 * immediately, and you will continue executing while the receivers are run. No results are
1783 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1784 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1785 * using {@link #sendOrderedBroadcast(Intent, String)}.
1786 *
1787 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1788 *
1789 * @param intent The Intent to broadcast; all receivers matching this
1790 * Intent will receive the broadcast.
1791 * @param receiverPermissions Array of names of permissions that a receiver must hold
1792 * in order to receive your broadcast.
1793 * If null or empty, no permissions are required.
1794 *
1795 * @see android.content.BroadcastReceiver
1796 * @see #registerReceiver
1797 * @see #sendBroadcast(Intent)
1798 * @see #sendOrderedBroadcast(Intent, String)
1799 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1800 * @hide
1801 */
1802 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1803 String[] receiverPermissions);
1804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001806 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1807 * an optional required permission to be enforced. This
1808 * call is asynchronous; it returns immediately, and you will continue
1809 * executing while the receivers are run. No results are propagated from
1810 * receivers and receivers can not abort the broadcast. If you want
1811 * to allow receivers to propagate results or abort the broadcast, you must
1812 * send an ordered broadcast using
1813 * {@link #sendOrderedBroadcast(Intent, String)}.
1814 *
1815 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1816 *
1817 * @param intent The Intent to broadcast; all receivers matching this
1818 * Intent will receive the broadcast.
1819 * @param receiverPermission (optional) String naming a permission that
1820 * a receiver must hold in order to receive your broadcast.
1821 * If null, no permission is required.
1822 * @param options (optional) Additional sending options, generated from a
1823 * {@link android.app.BroadcastOptions}.
1824 *
1825 * @see android.content.BroadcastReceiver
1826 * @see #registerReceiver
1827 * @see #sendBroadcast(Intent)
1828 * @see #sendOrderedBroadcast(Intent, String)
1829 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1830 * @hide
1831 */
1832 @SystemApi
1833 public abstract void sendBroadcast(Intent intent,
1834 @Nullable String receiverPermission,
1835 @Nullable Bundle options);
1836
1837 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001838 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001839 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001840 * @hide
1841 */
1842 public abstract void sendBroadcast(Intent intent,
1843 String receiverPermission, int appOp);
1844
1845 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1847 * them one at a time to allow more preferred receivers to consume the
1848 * broadcast before it is delivered to less preferred receivers. This
1849 * call is asynchronous; it returns immediately, and you will continue
1850 * executing while the receivers are run.
1851 *
1852 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1853 *
1854 * @param intent The Intent to broadcast; all receivers matching this
1855 * Intent will receive the broadcast.
1856 * @param receiverPermission (optional) String naming a permissions that
1857 * a receiver must hold in order to receive your broadcast.
1858 * If null, no permission is required.
1859 *
1860 * @see android.content.BroadcastReceiver
1861 * @see #registerReceiver
1862 * @see #sendBroadcast(Intent)
1863 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1864 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001865 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001866 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001867
1868 /**
1869 * Version of {@link #sendBroadcast(Intent)} that allows you to
1870 * receive data back from the broadcast. This is accomplished by
1871 * supplying your own BroadcastReceiver when calling, which will be
1872 * treated as a final receiver at the end of the broadcast -- its
1873 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001874 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001875 * be serialized in the same way as calling
1876 * {@link #sendOrderedBroadcast(Intent, String)}.
1877 *
1878 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1879 * asynchronous; it will return before
1880 * resultReceiver.onReceive() is called.
1881 *
1882 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1883 *
1884 * @param intent The Intent to broadcast; all receivers matching this
1885 * Intent will receive the broadcast.
1886 * @param receiverPermission String naming a permissions that
1887 * a receiver must hold in order to receive your broadcast.
1888 * If null, no permission is required.
1889 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1890 * receiver of the broadcast.
1891 * @param scheduler A custom Handler with which to schedule the
1892 * resultReceiver callback; if null it will be
1893 * scheduled in the Context's main thread.
1894 * @param initialCode An initial value for the result code. Often
1895 * Activity.RESULT_OK.
1896 * @param initialData An initial value for the result data. Often
1897 * null.
1898 * @param initialExtras An initial value for the result extras. Often
1899 * null.
1900 *
1901 * @see #sendBroadcast(Intent)
1902 * @see #sendBroadcast(Intent, String)
1903 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 * @see android.content.BroadcastReceiver
1905 * @see #registerReceiver
1906 * @see android.app.Activity#RESULT_OK
1907 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001908 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07001909 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001910 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1911 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912
1913 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001914 * Version of {@link #sendBroadcast(Intent)} that allows you to
1915 * receive data back from the broadcast. This is accomplished by
1916 * supplying your own BroadcastReceiver when calling, which will be
1917 * treated as a final receiver at the end of the broadcast -- its
1918 * {@link BroadcastReceiver#onReceive} method will be called with
1919 * the result values collected from the other receivers. The broadcast will
1920 * be serialized in the same way as calling
1921 * {@link #sendOrderedBroadcast(Intent, String)}.
1922 *
1923 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1924 * asynchronous; it will return before
1925 * resultReceiver.onReceive() is called.
1926 *
1927 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1928 *
1929 *
1930 * @param intent The Intent to broadcast; all receivers matching this
1931 * Intent will receive the broadcast.
1932 * @param receiverPermission String naming a permissions that
1933 * a receiver must hold in order to receive your broadcast.
1934 * If null, no permission is required.
1935 * @param options (optional) Additional sending options, generated from a
1936 * {@link android.app.BroadcastOptions}.
1937 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1938 * receiver of the broadcast.
1939 * @param scheduler A custom Handler with which to schedule the
1940 * resultReceiver callback; if null it will be
1941 * scheduled in the Context's main thread.
1942 * @param initialCode An initial value for the result code. Often
1943 * Activity.RESULT_OK.
1944 * @param initialData An initial value for the result data. Often
1945 * null.
1946 * @param initialExtras An initial value for the result extras. Often
1947 * null.
1948 * @see #sendBroadcast(Intent)
1949 * @see #sendBroadcast(Intent, String)
1950 * @see #sendOrderedBroadcast(Intent, String)
1951 * @see android.content.BroadcastReceiver
1952 * @see #registerReceiver
1953 * @see android.app.Activity#RESULT_OK
1954 * @hide
1955 */
1956 @SystemApi
1957 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1958 @Nullable String receiverPermission, @Nullable Bundle options,
1959 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
1960 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
1961
1962 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001963 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1964 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001965 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001966 * @hide
1967 */
1968 public abstract void sendOrderedBroadcast(Intent intent,
1969 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1970 Handler scheduler, int initialCode, String initialData,
1971 Bundle initialExtras);
1972
1973 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001974 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
1975 * user the broadcast will be sent to. This is not available to applications
1976 * that are not pre-installed on the system image. Using it requires holding
1977 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001978 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001979 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001980 * @see #sendBroadcast(Intent)
1981 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001982 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
1983 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001984
1985 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001986 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1987 * user the broadcast will be sent to. This is not available to applications
1988 * that are not pre-installed on the system image. Using it requires holding
1989 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001990 *
1991 * @param intent The Intent to broadcast; all receivers matching this
1992 * Intent will receive the broadcast.
1993 * @param user UserHandle to send the intent to.
1994 * @param receiverPermission (optional) String naming a permission that
1995 * a receiver must hold in order to receive your broadcast.
1996 * If null, no permission is required.
1997 *
1998 * @see #sendBroadcast(Intent, String)
1999 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002000 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2001 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002002
Svet Ganov16a16892015-04-16 10:32:04 -07002003
2004 /**
2005 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2006 * user the broadcast will be sent to. This is not available to applications
2007 * that are not pre-installed on the system image. Using it requires holding
2008 * the INTERACT_ACROSS_USERS permission.
2009 *
2010 * @param intent The Intent to broadcast; all receivers matching this
2011 * Intent will receive the broadcast.
2012 * @param user UserHandle to send the intent to.
2013 * @param receiverPermission (optional) String naming a permission that
2014 * a receiver must hold in order to receive your broadcast.
2015 * If null, no permission is required.
2016 * @param appOp The app op associated with the broadcast.
2017 *
2018 * @see #sendBroadcast(Intent, String)
2019 *
2020 * @hide
2021 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002022 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2023 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002024
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002025 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002026 * Version of
2027 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2028 * that allows you to specify the
2029 * user the broadcast will be sent to. This is not available to applications
2030 * that are not pre-installed on the system image. Using it requires holding
2031 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002032 *
2033 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2034 *
2035 * @param intent The Intent to broadcast; all receivers matching this
2036 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002037 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002038 * @param receiverPermission String naming a permissions that
2039 * a receiver must hold in order to receive your broadcast.
2040 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002041 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2042 * receiver of the broadcast.
2043 * @param scheduler A custom Handler with which to schedule the
2044 * resultReceiver callback; if null it will be
2045 * scheduled in the Context's main thread.
2046 * @param initialCode An initial value for the result code. Often
2047 * Activity.RESULT_OK.
2048 * @param initialData An initial value for the result data. Often
2049 * null.
2050 * @param initialExtras An initial value for the result extras. Often
2051 * null.
2052 *
2053 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2054 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002055 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2056 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002057 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2058 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002059
2060 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002061 * Similar to above but takes an appOp as well, to enforce restrictions.
2062 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2063 * BroadcastReceiver, Handler, int, String, Bundle)
2064 * @hide
2065 */
2066 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2067 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2068 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2069 @Nullable Bundle initialExtras);
2070
2071 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002072 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2073 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2074 * BroadcastReceiver, Handler, int, String, Bundle)
2075 * @hide
2076 */
2077 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2078 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2079 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2080 @Nullable String initialData, @Nullable Bundle initialExtras);
2081
2082 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002083 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 * Intent you are sending stays around after the broadcast is complete,
2085 * so that others can quickly retrieve that data through the return
2086 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2087 * all other ways, this behaves the same as
2088 * {@link #sendBroadcast(Intent)}.
2089 *
2090 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2091 * permission in order to use this API. If you do not hold that
2092 * permission, {@link SecurityException} will be thrown.
2093 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002094 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2095 * can access them), no protection (anyone can modify them), and many other problems.
2096 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2097 * has changed, with another mechanism for apps to retrieve the current value whenever
2098 * desired.
2099 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002100 * @param intent The Intent to broadcast; all receivers matching this
2101 * Intent will receive the broadcast, and the Intent will be held to
2102 * be re-broadcast to future receivers.
2103 *
2104 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002105 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002106 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002107 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002108 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002109
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002110 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002111 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002112 * receive data back from the broadcast. This is accomplished by
2113 * supplying your own BroadcastReceiver when calling, which will be
2114 * treated as a final receiver at the end of the broadcast -- its
2115 * {@link BroadcastReceiver#onReceive} method will be called with
2116 * the result values collected from the other receivers. The broadcast will
2117 * be serialized in the same way as calling
2118 * {@link #sendOrderedBroadcast(Intent, String)}.
2119 *
2120 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2121 * asynchronous; it will return before
2122 * resultReceiver.onReceive() is called. Note that the sticky data
2123 * stored is only the data you initially supply to the broadcast, not
2124 * the result of any changes made by the receivers.
2125 *
2126 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2127 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002128 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2129 * can access them), no protection (anyone can modify them), and many other problems.
2130 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2131 * has changed, with another mechanism for apps to retrieve the current value whenever
2132 * desired.
2133 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002134 * @param intent The Intent to broadcast; all receivers matching this
2135 * Intent will receive the broadcast.
2136 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2137 * receiver of the broadcast.
2138 * @param scheduler A custom Handler with which to schedule the
2139 * resultReceiver callback; if null it will be
2140 * scheduled in the Context's main thread.
2141 * @param initialCode An initial value for the result code. Often
2142 * Activity.RESULT_OK.
2143 * @param initialData An initial value for the result data. Often
2144 * null.
2145 * @param initialExtras An initial value for the result extras. Often
2146 * null.
2147 *
2148 * @see #sendBroadcast(Intent)
2149 * @see #sendBroadcast(Intent, String)
2150 * @see #sendOrderedBroadcast(Intent, String)
2151 * @see #sendStickyBroadcast(Intent)
2152 * @see android.content.BroadcastReceiver
2153 * @see #registerReceiver
2154 * @see android.app.Activity#RESULT_OK
2155 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002156 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002157 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002158 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002159 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2160 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002161
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002163 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164 * so that it is as if the sticky broadcast had never happened.
2165 *
2166 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2167 * permission in order to use this API. If you do not hold that
2168 * permission, {@link SecurityException} will be thrown.
2169 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002170 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2171 * can access them), no protection (anyone can modify them), and many other problems.
2172 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2173 * has changed, with another mechanism for apps to retrieve the current value whenever
2174 * desired.
2175 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 * @param intent The Intent that was previously broadcast.
2177 *
2178 * @see #sendStickyBroadcast
2179 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002180 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002181 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002182
2183 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002184 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002185 * user the broadcast will be sent to. This is not available to applications
2186 * that are not pre-installed on the system image. Using it requires holding
2187 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002188 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002189 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2190 * can access them), no protection (anyone can modify them), and many other problems.
2191 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2192 * has changed, with another mechanism for apps to retrieve the current value whenever
2193 * desired.
2194 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002195 * @param intent The Intent to broadcast; all receivers matching this
2196 * Intent will receive the broadcast, and the Intent will be held to
2197 * be re-broadcast to future receivers.
2198 * @param user UserHandle to send the intent to.
2199 *
2200 * @see #sendBroadcast(Intent)
2201 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002202 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002203 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2204 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002205
2206 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002207 * @hide
2208 * This is just here for sending CONNECTIVITY_ACTION.
2209 */
2210 @Deprecated
2211 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2212 UserHandle user, Bundle options);
2213
2214 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002215 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002216 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2217 * that allows you to specify the
2218 * user the broadcast will be sent to. This is not available to applications
2219 * that are not pre-installed on the system image. Using it requires holding
2220 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002221 *
2222 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2223 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002224 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2225 * can access them), no protection (anyone can modify them), and many other problems.
2226 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2227 * has changed, with another mechanism for apps to retrieve the current value whenever
2228 * desired.
2229 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002230 * @param intent The Intent to broadcast; all receivers matching this
2231 * Intent will receive the broadcast.
2232 * @param user UserHandle to send the intent to.
2233 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2234 * receiver of the broadcast.
2235 * @param scheduler A custom Handler with which to schedule the
2236 * resultReceiver callback; if null it will be
2237 * scheduled in the Context's main thread.
2238 * @param initialCode An initial value for the result code. Often
2239 * Activity.RESULT_OK.
2240 * @param initialData An initial value for the result data. Often
2241 * null.
2242 * @param initialExtras An initial value for the result extras. Often
2243 * null.
2244 *
2245 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2246 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002247 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002248 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002249 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002250 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2251 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002252
2253 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002254 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002255 * user the broadcast will be sent to. This is not available to applications
2256 * that are not pre-installed on the system image. Using it requires holding
2257 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002258 *
2259 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2260 * permission in order to use this API. If you do not hold that
2261 * permission, {@link SecurityException} will be thrown.
2262 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002263 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2264 * can access them), no protection (anyone can modify them), and many other problems.
2265 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2266 * has changed, with another mechanism for apps to retrieve the current value whenever
2267 * desired.
2268 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002269 * @param intent The Intent that was previously broadcast.
2270 * @param user UserHandle to remove the sticky broadcast from.
2271 *
2272 * @see #sendStickyBroadcastAsUser
2273 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002274 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002275 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2276 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002277
2278 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002279 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002280 * <var>receiver</var> will be called with any broadcast Intent that
2281 * matches <var>filter</var>, in the main application thread.
2282 *
2283 * <p>The system may broadcast Intents that are "sticky" -- these stay
2284 * around after the broadcast as finished, to be sent to any later
2285 * registrations. If your IntentFilter matches one of these sticky
2286 * Intents, that Intent will be returned by this function
2287 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2288 * been broadcast.
2289 *
2290 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2291 * in which case each of these will be sent to <var>receiver</var>. In
2292 * this case, only one of these can be returned directly by the function;
2293 * which of these that is returned is arbitrarily decided by the system.
2294 *
2295 * <p>If you know the Intent your are registering for is sticky, you can
2296 * supply null for your <var>receiver</var>. In this case, no receiver is
2297 * registered -- the function simply returns the sticky Intent that
2298 * matches <var>filter</var>. In the case of multiple matches, the same
2299 * rules as described above apply.
2300 *
2301 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2302 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002303 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2304 * registered with this method will correctly respect the
2305 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2306 * Prior to that, it would be ignored and delivered to all matching registered
2307 * receivers. Be careful if using this for security.</p>
2308 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002309 * <p class="note">Note: this method <em>cannot be called from a
2310 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2311 * that is declared in an application's manifest. It is okay, however, to call
2312 * this method from another BroadcastReceiver that has itself been registered
2313 * at run time with {@link #registerReceiver}, since the lifetime of such a
2314 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002315 *
2316 * @param receiver The BroadcastReceiver to handle the broadcast.
2317 * @param filter Selects the Intent broadcasts to be received.
2318 *
2319 * @return The first sticky intent found that matches <var>filter</var>,
2320 * or null if there are none.
2321 *
2322 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2323 * @see #sendBroadcast
2324 * @see #unregisterReceiver
2325 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002326 @Nullable
2327 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 IntentFilter filter);
2329
2330 /**
2331 * Register to receive intent broadcasts, to run in the context of
2332 * <var>scheduler</var>. See
2333 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2334 * information. This allows you to enforce permissions on who can
2335 * broadcast intents to your receiver, or have the receiver run in
2336 * a different thread than the main application thread.
2337 *
2338 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2339 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002340 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2341 * registered with this method will correctly respect the
2342 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2343 * Prior to that, it would be ignored and delivered to all matching registered
2344 * receivers. Be careful if using this for security.</p>
2345 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346 * @param receiver The BroadcastReceiver to handle the broadcast.
2347 * @param filter Selects the Intent broadcasts to be received.
2348 * @param broadcastPermission String naming a permissions that a
2349 * broadcaster must hold in order to send an Intent to you. If null,
2350 * no permission is required.
2351 * @param scheduler Handler identifying the thread that will receive
2352 * the Intent. If null, the main thread of the process will be used.
2353 *
2354 * @return The first sticky intent found that matches <var>filter</var>,
2355 * or null if there are none.
2356 *
2357 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2358 * @see #sendBroadcast
2359 * @see #unregisterReceiver
2360 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002361 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002362 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002363 IntentFilter filter, @Nullable String broadcastPermission,
2364 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002365
2366 /**
2367 * @hide
2368 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2369 * but for a specific user. This receiver will receiver broadcasts that
2370 * are sent to the requested user. It
2371 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
2372 * permission.
2373 *
2374 * @param receiver The BroadcastReceiver to handle the broadcast.
2375 * @param user UserHandle to send the intent to.
2376 * @param filter Selects the Intent broadcasts to be received.
2377 * @param broadcastPermission String naming a permissions that a
2378 * broadcaster must hold in order to send an Intent to you. If null,
2379 * no permission is required.
2380 * @param scheduler Handler identifying the thread that will receive
2381 * the Intent. If null, the main thread of the process will be used.
2382 *
2383 * @return The first sticky intent found that matches <var>filter</var>,
2384 * or null if there are none.
2385 *
Jeff Brown6e539312015-02-24 18:53:21 -08002386 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002387 * @see #sendBroadcast
2388 * @see #unregisterReceiver
2389 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002390 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07002391 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002392 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2393 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002394
2395 /**
2396 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2397 * filters that have been registered for this BroadcastReceiver will be
2398 * removed.
2399 *
2400 * @param receiver The BroadcastReceiver to unregister.
2401 *
2402 * @see #registerReceiver
2403 */
2404 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2405
2406 /**
2407 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07002408 * should contain either contain the complete class name of a specific service
2409 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07002410 * Intent is less specified, it log a warning about this and which of the
2411 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002412 * is not already running, it will be instantiated and started (creating a
2413 * process for it if needed); if it is running then it remains running.
2414 *
2415 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002416 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 * with the <var>intent</var> given here. This provides a convenient way
2418 * to submit jobs to a service without having to bind and call on to its
2419 * interface.
2420 *
2421 * <p>Using startService() overrides the default service lifetime that is
2422 * managed by {@link #bindService}: it requires the service to remain
2423 * running until {@link #stopService} is called, regardless of whether
2424 * any clients are connected to it. Note that calls to startService()
2425 * are not nesting: no matter how many times you call startService(),
2426 * a single call to {@link #stopService} will stop it.
2427 *
2428 * <p>The system attempts to keep running services around as much as
2429 * possible. The only time they should be stopped is if the current
2430 * foreground application is using so many resources that the service needs
2431 * to be killed. If any errors happen in the service's process, it will
2432 * automatically be restarted.
2433 *
2434 * <p>This function will throw {@link SecurityException} if you do not
2435 * have permission to start the given service.
2436 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002437 * @param service Identifies the service to be started. The Intent must be either
2438 * fully explicit (supplying a component name) or specify a specific package
2439 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002440 * may be included in the Intent extras to supply arguments along with
2441 * this specific start call.
2442 *
2443 * @return If the service is being started or is already running, the
2444 * {@link ComponentName} of the actual service that was started is
2445 * returned; else if the service does not exist null is returned.
2446 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002447 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002448 *
2449 * @see #stopService
2450 * @see #bindService
2451 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002452 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 public abstract ComponentName startService(Intent service);
2454
2455 /**
2456 * Request that a given application service be stopped. If the service is
2457 * not running, nothing happens. Otherwise it is stopped. Note that calls
2458 * to startService() are not counted -- this stops the service no matter
2459 * how many times it was started.
2460 *
2461 * <p>Note that if a stopped service still has {@link ServiceConnection}
2462 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2463 * not be destroyed until all of these bindings are removed. See
2464 * the {@link android.app.Service} documentation for more details on a
2465 * service's lifecycle.
2466 *
2467 * <p>This function will throw {@link SecurityException} if you do not
2468 * have permission to stop the given service.
2469 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002470 * @param service Description of the service to be stopped. The Intent must be either
2471 * fully explicit (supplying a component name) or specify a specific package
2472 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002473 *
2474 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002475 * 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 -08002476 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002477 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 *
2479 * @see #startService
2480 */
2481 public abstract boolean stopService(Intent service);
2482
2483 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002484 * @hide like {@link #startService(Intent)} but for a specific user.
2485 */
2486 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2487
2488 /**
2489 * @hide like {@link #stopService(Intent)} but for a specific user.
2490 */
2491 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002492
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002493 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 * Connect to an application service, creating it if needed. This defines
2495 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002496 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 * told if it dies and restarts. The service will be considered required
2498 * by the system only for as long as the calling context exists. For
2499 * example, if this Context is an Activity that is stopped, the service will
2500 * not be required to continue running until the Activity is resumed.
2501 *
2502 * <p>This function will throw {@link SecurityException} if you do not
2503 * have permission to bind to the given service.
2504 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002505 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002507 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002508 * {@link #startService} with the arguments containing the command to be
2509 * sent, with the service calling its
2510 * {@link android.app.Service#stopSelf(int)} method when done executing
2511 * that command. See the API demo App/Service/Service Start Arguments
2512 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002513 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002514 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2515 * is tied to another object (the one that registered it).</p>
2516 *
2517 * @param service Identifies the service to connect to. The Intent may
2518 * specify either an explicit component name, or a logical
2519 * description (action, category, etc) to match an
2520 * {@link IntentFilter} published by a service.
2521 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002522 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002523 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002524 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2525 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2526 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2527 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002528 * @return If you have successfully bound to the service, {@code true} is returned;
2529 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 * receive the service object.
2531 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002532 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533 *
2534 * @see #unbindService
2535 * @see #startService
2536 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002537 * @see #BIND_DEBUG_UNBIND
2538 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002540 public abstract boolean bindService(@RequiresPermission Intent service,
2541 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542
2543 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002544 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002545 * argument for use by system server and other multi-user aware code.
2546 * @hide
2547 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002548 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002549 @SuppressWarnings("unused")
Tor Norbye788fc2b2015-07-05 16:10:42 -07002550 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002551 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002552 throw new RuntimeException("Not implemented. Must override in a subclass.");
2553 }
2554
2555 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002556 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2557 * explicit non-null Handler to run the ServiceConnection callbacks on.
2558 *
2559 * @hide
2560 */
2561 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2562 Handler handler, UserHandle user) {
2563 throw new RuntimeException("Not implemented. Must override in a subclass.");
2564 }
2565
2566 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 * Disconnect from an application service. You will no longer receive
2568 * calls as the service is restarted, and the service is now allowed to
2569 * stop at any time.
2570 *
2571 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002572 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002573 *
2574 * @see #bindService
2575 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002576 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002577
2578 /**
2579 * Start executing an {@link android.app.Instrumentation} class. The given
2580 * Instrumentation component will be run by killing its target application
2581 * (if currently running), starting the target process, instantiating the
2582 * instrumentation component, and then letting it drive the application.
2583 *
2584 * <p>This function is not synchronous -- it returns as soon as the
2585 * instrumentation has started and while it is running.
2586 *
2587 * <p>Instrumentation is normally only allowed to run against a package
2588 * that is either unsigned or signed with a signature that the
2589 * the instrumentation package is also signed with (ensuring the target
2590 * trusts the instrumentation).
2591 *
2592 * @param className Name of the Instrumentation component to be run.
2593 * @param profileFile Optional path to write profiling data as the
2594 * instrumentation runs, or null for no profiling.
2595 * @param arguments Additional optional arguments to pass to the
2596 * instrumentation, or null.
2597 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002598 * @return {@code true} if the instrumentation was successfully started,
2599 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002600 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002601 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2602 @Nullable String profileFile, @Nullable Bundle arguments);
2603
2604 /** @hide */
2605 @StringDef({
2606 POWER_SERVICE,
2607 WINDOW_SERVICE,
2608 LAYOUT_INFLATER_SERVICE,
2609 ACCOUNT_SERVICE,
2610 ACTIVITY_SERVICE,
2611 ALARM_SERVICE,
2612 NOTIFICATION_SERVICE,
2613 ACCESSIBILITY_SERVICE,
2614 CAPTIONING_SERVICE,
2615 KEYGUARD_SERVICE,
2616 LOCATION_SERVICE,
2617 //@hide: COUNTRY_DETECTOR,
2618 SEARCH_SERVICE,
2619 SENSOR_SERVICE,
2620 STORAGE_SERVICE,
2621 WALLPAPER_SERVICE,
2622 VIBRATOR_SERVICE,
2623 //@hide: STATUS_BAR_SERVICE,
2624 CONNECTIVITY_SERVICE,
2625 //@hide: UPDATE_LOCK_SERVICE,
2626 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002627 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002628 //@hide: NETWORK_POLICY_SERVICE,
2629 WIFI_SERVICE,
Etan Cohen20d329b2015-09-29 13:49:02 -07002630 WIFI_NAN_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002631 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002632 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002633 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002634 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002635 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002636 NSD_SERVICE,
2637 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002638 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002639 MEDIA_ROUTER_SERVICE,
2640 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002641 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002642 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002643 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002644 CLIPBOARD_SERVICE,
2645 INPUT_METHOD_SERVICE,
2646 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002647 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002648 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002649 //@hide: BACKUP_SERVICE,
2650 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07002651 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07002652 DEVICE_POLICY_SERVICE,
2653 UI_MODE_SERVICE,
2654 DOWNLOAD_SERVICE,
2655 NFC_SERVICE,
2656 BLUETOOTH_SERVICE,
2657 //@hide: SIP_SERVICE,
2658 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002659 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002660 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002661 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002662 INPUT_SERVICE,
2663 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002664 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002665 RESTRICTIONS_SERVICE,
2666 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002667 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002668 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002669 CONSUMER_IR_SERVICE,
2670 //@hide: TRUST_SERVICE,
2671 TV_INPUT_SERVICE,
2672 //@hide: NETWORK_SCORE_SERVICE,
2673 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002674 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002675 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002676 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002677 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002678 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002679 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002680 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002681 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08002682 //@hide: SOUND_TRIGGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002683 })
2684 @Retention(RetentionPolicy.SOURCE)
2685 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686
2687 /**
2688 * Return the handle to a system-level service by name. The class of the
2689 * returned object varies by the requested name. Currently available names
2690 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002691 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 * <dl>
2693 * <dt> {@link #WINDOW_SERVICE} ("window")
2694 * <dd> The top-level window manager in which you can place custom
2695 * windows. The returned object is a {@link android.view.WindowManager}.
2696 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2697 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2698 * in this context.
2699 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2700 * <dd> A {@link android.app.ActivityManager} for interacting with the
2701 * global activity state of the system.
2702 * <dt> {@link #POWER_SERVICE} ("power")
2703 * <dd> A {@link android.os.PowerManager} for controlling power
2704 * management.
2705 * <dt> {@link #ALARM_SERVICE} ("alarm")
2706 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2707 * time of your choosing.
2708 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2709 * <dd> A {@link android.app.NotificationManager} for informing the user
2710 * of background events.
2711 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2712 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2713 * <dt> {@link #LOCATION_SERVICE} ("location")
2714 * <dd> A {@link android.location.LocationManager} for controlling location
2715 * (e.g., GPS) updates.
2716 * <dt> {@link #SEARCH_SERVICE} ("search")
2717 * <dd> A {@link android.app.SearchManager} for handling search.
2718 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2719 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2720 * hardware.
2721 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2722 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2723 * handling management of network connections.
2724 * <dt> {@link #WIFI_SERVICE} ("wifi")
2725 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2726 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002727 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2728 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2729 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2731 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2732 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002733 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2734 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002735 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002736 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002737 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002738 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002739 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2740 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002741 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
2742 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
2743 * usage statistics.
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002744 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardwareproperties")
2745 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002747 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 * <p>Note: System services obtained via this API may be closely associated with
2749 * the Context in which they are obtained from. In general, do not share the
2750 * service objects between various different contexts (Activities, Applications,
2751 * Services, Providers, etc.)
2752 *
2753 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002754 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002755 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002756 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002757 * @see #WINDOW_SERVICE
2758 * @see android.view.WindowManager
2759 * @see #LAYOUT_INFLATER_SERVICE
2760 * @see android.view.LayoutInflater
2761 * @see #ACTIVITY_SERVICE
2762 * @see android.app.ActivityManager
2763 * @see #POWER_SERVICE
2764 * @see android.os.PowerManager
2765 * @see #ALARM_SERVICE
2766 * @see android.app.AlarmManager
2767 * @see #NOTIFICATION_SERVICE
2768 * @see android.app.NotificationManager
2769 * @see #KEYGUARD_SERVICE
2770 * @see android.app.KeyguardManager
2771 * @see #LOCATION_SERVICE
2772 * @see android.location.LocationManager
2773 * @see #SEARCH_SERVICE
2774 * @see android.app.SearchManager
2775 * @see #SENSOR_SERVICE
2776 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002777 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002778 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 * @see #VIBRATOR_SERVICE
2780 * @see android.os.Vibrator
2781 * @see #CONNECTIVITY_SERVICE
2782 * @see android.net.ConnectivityManager
2783 * @see #WIFI_SERVICE
2784 * @see android.net.wifi.WifiManager
2785 * @see #AUDIO_SERVICE
2786 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002787 * @see #MEDIA_ROUTER_SERVICE
2788 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 * @see #TELEPHONY_SERVICE
2790 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002791 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2792 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002793 * @see #CARRIER_CONFIG_SERVICE
2794 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002795 * @see #INPUT_METHOD_SERVICE
2796 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002797 * @see #UI_MODE_SERVICE
2798 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002799 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002800 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002801 * @see #BATTERY_SERVICE
2802 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002803 * @see #JOB_SCHEDULER_SERVICE
2804 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002805 * @see #NETWORK_STATS_SERVICE
2806 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002807 * @see android.os.HardwarePropertiesManager
2808 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002810 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002811
2812 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002813 * Return the handle to a system-level service by class.
2814 * <p>
2815 * Currently available classes are:
2816 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2817 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2818 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2819 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2820 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2821 * {@link android.net.ConnectivityManager},
2822 * {@link android.net.wifi.WifiManager},
2823 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2824 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2825 * {@link android.view.inputmethod.InputMethodManager},
2826 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002827 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
2828 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08002829 * </p><p>
2830 * Note: System services obtained via this API may be closely associated with
2831 * the Context in which they are obtained from. In general, do not share the
2832 * service objects between various different contexts (Activities, Applications,
2833 * Services, Providers, etc.)
2834 * </p>
2835 *
2836 * @param serviceClass The class of the desired service.
2837 * @return The service or null if the class is not a supported system service.
2838 */
2839 @SuppressWarnings("unchecked")
2840 public final <T> T getSystemService(Class<T> serviceClass) {
2841 // Because subclasses may override getSystemService(String) we cannot
2842 // perform a lookup by class alone. We must first map the class to its
2843 // service name then invoke the string-based method.
2844 String serviceName = getSystemServiceName(serviceClass);
2845 return serviceName != null ? (T)getSystemService(serviceName) : null;
2846 }
2847
2848 /**
2849 * Gets the name of the system-level service that is represented by the specified class.
2850 *
2851 * @param serviceClass The class of the desired service.
2852 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08002853 */
2854 public abstract String getSystemServiceName(Class<?> serviceClass);
2855
2856 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 * Use with {@link #getSystemService} to retrieve a
2858 * {@link android.os.PowerManager} for controlling power management,
2859 * including "wake locks," which let you keep the device on while
2860 * you're running long tasks.
2861 */
2862 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002863
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002864 /**
2865 * Use with {@link #getSystemService} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08002866 * {@link android.os.RecoverySystem} for accessing the recovery system
2867 * service.
2868 *
2869 * @see #getSystemService
2870 * @hide
2871 */
2872 public static final String RECOVERY_SERVICE = "recovery";
2873
2874 /**
2875 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 * {@link android.view.WindowManager} for accessing the system's window
2877 * manager.
2878 *
2879 * @see #getSystemService
2880 * @see android.view.WindowManager
2881 */
2882 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002883
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 /**
2885 * Use with {@link #getSystemService} to retrieve a
2886 * {@link android.view.LayoutInflater} for inflating layout resources in this
2887 * context.
2888 *
2889 * @see #getSystemService
2890 * @see android.view.LayoutInflater
2891 */
2892 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002893
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 /**
2895 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002896 * {@link android.accounts.AccountManager} for receiving intents at a
2897 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002898 *
2899 * @see #getSystemService
2900 * @see android.accounts.AccountManager
2901 */
2902 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002903
Fred Quintana60307342009-03-24 22:48:12 -07002904 /**
2905 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 * {@link android.app.ActivityManager} for interacting with the global
2907 * system state.
2908 *
2909 * @see #getSystemService
2910 * @see android.app.ActivityManager
2911 */
2912 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002913
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914 /**
2915 * Use with {@link #getSystemService} to retrieve a
2916 * {@link android.app.AlarmManager} for receiving intents at a
2917 * time of your choosing.
2918 *
2919 * @see #getSystemService
2920 * @see android.app.AlarmManager
2921 */
2922 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002923
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 /**
2925 * Use with {@link #getSystemService} to retrieve a
2926 * {@link android.app.NotificationManager} for informing the user of
2927 * background events.
2928 *
2929 * @see #getSystemService
2930 * @see android.app.NotificationManager
2931 */
2932 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 /**
2935 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002936 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2937 * feedback for UI events through the registered event listeners.
2938 *
2939 * @see #getSystemService
2940 * @see android.view.accessibility.AccessibilityManager
2941 */
2942 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002943
svetoslavganov75986cf2009-05-14 22:28:01 -07002944 /**
2945 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002946 * {@link android.view.accessibility.CaptioningManager} for obtaining
2947 * captioning properties and listening for changes in captioning
2948 * preferences.
2949 *
2950 * @see #getSystemService
2951 * @see android.view.accessibility.CaptioningManager
2952 */
2953 public static final String CAPTIONING_SERVICE = "captioning";
2954
2955 /**
2956 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 * {@link android.app.NotificationManager} for controlling keyguard.
2958 *
2959 * @see #getSystemService
2960 * @see android.app.KeyguardManager
2961 */
2962 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 /**
2965 * Use with {@link #getSystemService} to retrieve a {@link
2966 * android.location.LocationManager} for controlling location
2967 * updates.
2968 *
2969 * @see #getSystemService
2970 * @see android.location.LocationManager
2971 */
2972 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002973
2974 /**
2975 * Use with {@link #getSystemService} to retrieve a
2976 * {@link android.location.CountryDetector} for detecting the country that
2977 * the user is in.
2978 *
2979 * @hide
2980 */
2981 public static final String COUNTRY_DETECTOR = "country_detector";
2982
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 /**
2984 * Use with {@link #getSystemService} to retrieve a {@link
2985 * android.app.SearchManager} for handling searches.
2986 *
2987 * @see #getSystemService
2988 * @see android.app.SearchManager
2989 */
2990 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07002991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002992 /**
2993 * Use with {@link #getSystemService} to retrieve a {@link
2994 * android.hardware.SensorManager} for accessing sensors.
2995 *
2996 * @see #getSystemService
2997 * @see android.hardware.SensorManager
2998 */
2999 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003000
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 /**
San Mehatc9d81752010-02-01 10:23:27 -08003002 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003003 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003004 * functions.
3005 *
3006 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08003007 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003008 */
3009 public static final String STORAGE_SERVICE = "storage";
3010
3011 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 * Use with {@link #getSystemService} to retrieve a
3013 * com.android.server.WallpaperService for accessing wallpapers.
3014 *
3015 * @see #getSystemService
3016 */
3017 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003018
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 /**
3020 * Use with {@link #getSystemService} to retrieve a {@link
3021 * android.os.Vibrator} for interacting with the vibration hardware.
3022 *
3023 * @see #getSystemService
3024 * @see android.os.Vibrator
3025 */
3026 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003028 /**
3029 * Use with {@link #getSystemService} to retrieve a {@link
3030 * android.app.StatusBarManager} for interacting with the status bar.
3031 *
3032 * @see #getSystemService
3033 * @see android.app.StatusBarManager
3034 * @hide
3035 */
3036 public static final String STATUS_BAR_SERVICE = "statusbar";
3037
3038 /**
3039 * Use with {@link #getSystemService} to retrieve a {@link
3040 * android.net.ConnectivityManager} for handling management of
3041 * network connections.
3042 *
3043 * @see #getSystemService
3044 * @see android.net.ConnectivityManager
3045 */
3046 public static final String CONNECTIVITY_SERVICE = "connectivity";
3047
3048 /**
3049 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003050 * android.os.IUpdateLock} for managing runtime sequences that
3051 * must not be interrupted by headless OTA application or similar.
3052 *
3053 * @hide
3054 * @see #getSystemService
3055 * @see android.os.UpdateLock
3056 */
3057 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3058
3059 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003060 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003061 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003062 */
3063 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3064
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003065 /**
3066 * Use with {@link #getSystemService} to retrieve a {@link
3067 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3068 *
3069 * @see #getSystemService
3070 * @see android.app.usage.NetworkStatsManager
3071 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003072 public static final String NETWORK_STATS_SERVICE = "netstats";
3073 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003074 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
3075
San Mehatd1df8ac2010-01-26 06:17:26 -08003076 /**
3077 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 * android.net.wifi.WifiManager} for handling management of
3079 * Wi-Fi access.
3080 *
3081 * @see #getSystemService
3082 * @see android.net.wifi.WifiManager
3083 */
3084 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 /**
repo sync55bc5f32011-06-24 14:23:07 -07003087 * Use with {@link #getSystemService} to retrieve a {@link
3088 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003089 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003090 *
3091 * @see #getSystemService
3092 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003093 */
3094 public static final String WIFI_P2P_SERVICE = "wifip2p";
3095
3096 /**
Etan Cohen20d329b2015-09-29 13:49:02 -07003097 * Use with {@link #getSystemService} to retrieve a
3098 * {@link android.net.wifi.nan.WifiNanManager} for handling management of
3099 * Wi-Fi NAN discovery and connections.
3100 *
3101 * @see #getSystemService
3102 * @see android.net.wifi.nan.WifiNanManager
3103 * @hide PROPOSED_NAN_API
3104 */
3105 public static final String WIFI_NAN_SERVICE = "wifinan";
3106
3107 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003108 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003109 * android.net.wifi.WifiScanner} for scanning the wifi universe
3110 *
3111 * @see #getSystemService
3112 * @see android.net.wifi.WifiScanner
3113 * @hide
3114 */
Wei Wang35d552f2014-07-08 21:37:01 -07003115 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003116 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3117
3118 /**
3119 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003120 * android.net.wifi.RttManager} for ranging devices with wifi
3121 *
3122 * @see #getSystemService
3123 * @see android.net.wifi.RttManager
3124 * @hide
3125 */
3126 @SystemApi
3127 public static final String WIFI_RTT_SERVICE = "rttmanager";
3128
3129 /**
3130 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003131 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003132 * Ethernet access.
3133 *
3134 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003135 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003136 *
3137 * @hide
3138 */
3139 public static final String ETHERNET_SERVICE = "ethernet";
3140
3141 /**
3142 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003143 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003144 * discovery
3145 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003146 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003147 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003148 */
3149 public static final String NSD_SERVICE = "servicediscovery";
3150
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003151 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 * Use with {@link #getSystemService} to retrieve a
3153 * {@link android.media.AudioManager} for handling management of volume,
3154 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003155 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 * @see #getSystemService
3157 * @see android.media.AudioManager
3158 */
3159 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 /**
3162 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003163 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003164 * of fingerprints.
3165 *
3166 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07003167 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003168 */
3169 public static final String FINGERPRINT_SERVICE = "fingerprint";
3170
3171 /**
3172 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003173 * {@link android.media.MediaRouter} for controlling and managing
3174 * routing of media.
3175 *
3176 * @see #getSystemService
3177 * @see android.media.MediaRouter
3178 */
3179 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3180
3181 /**
3182 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003183 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003184 *
3185 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07003186 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003187 */
3188 public static final String MEDIA_SESSION_SERVICE = "media_session";
3189
3190 /**
3191 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 * {@link android.telephony.TelephonyManager} for handling management the
3193 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003194 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003195 * @see #getSystemService
3196 * @see android.telephony.TelephonyManager
3197 */
3198 public static final String TELEPHONY_SERVICE = "phone";
3199
3200 /**
3201 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003202 * {@link android.telephony.SubscriptionManager} for handling management the
3203 * telephony subscriptions of the device.
3204 *
3205 * @see #getSystemService
3206 * @see android.telephony.SubscriptionManager
3207 */
3208 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3209
3210 /**
3211 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003212 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003213 * of the device.
3214 *
3215 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003216 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003217 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003218 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003219
3220 /**
3221 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003222 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3223 *
3224 * @see #getSystemService
3225 * @see android.telephony.CarrierConfigManager
3226 */
3227 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3228
3229 /**
3230 * Use with {@link #getSystemService} to retrieve a
3231 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08003232 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003234 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003236 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 */
3238 public static final String CLIPBOARD_SERVICE = "clipboard";
3239
3240 /**
Scott Main4b5da682010-10-21 11:49:12 -07003241 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003242 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3243 * methods.
3244 *
3245 * @see #getSystemService
3246 */
3247 public static final String INPUT_METHOD_SERVICE = "input_method";
3248
3249 /**
3250 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09003251 * {@link android.view.textservice.TextServicesManager} for accessing
3252 * text services.
3253 *
3254 * @see #getSystemService
3255 */
3256 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3257
3258 /**
3259 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003260 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003261 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 * @see #getSystemService
3263 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003264 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003265
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003267 * Official published name of the (internal) voice interaction manager service.
3268 *
3269 * @hide
3270 * @see #getSystemService
3271 */
3272 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3273
3274 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003275 * Use with {@link #getSystemService} to access the
3276 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3277 *
3278 * @hide
3279 * @see #getSystemService
3280 */
3281 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3282
3283
3284 /**
Christopher Tate487529a2009-04-29 14:03:25 -07003285 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003286 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003287 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003288 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003289 *
Christopher Tate487529a2009-04-29 14:03:25 -07003290 * @see #getSystemService
3291 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003292 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003293 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003294
3295 /**
3296 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003297 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003298 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07003299 * @see #getSystemService
3300 */
3301 public static final String DROPBOX_SERVICE = "dropbox";
3302
Christopher Tate487529a2009-04-29 14:03:25 -07003303 /**
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003304 * System service name for the DeviceIdleController. There is no Java API for this.
3305 * @see #getSystemService
3306 * @hide
3307 */
3308 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3309
3310 /**
Scott Main4b5da682010-10-21 11:49:12 -07003311 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003312 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003313 * device policy management.
3314 *
3315 * @see #getSystemService
3316 */
3317 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3318
3319 /**
Tobias Haamel53332882010-02-18 16:15:43 -08003320 * Use with {@link #getSystemService} to retrieve a
3321 * {@link android.app.UiModeManager} for controlling UI modes.
3322 *
3323 * @see #getSystemService
3324 */
3325 public static final String UI_MODE_SERVICE = "uimode";
3326
3327 /**
Steve Howarda2709362010-07-02 17:12:48 -07003328 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003329 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003330 *
3331 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07003332 */
3333 public static final String DOWNLOAD_SERVICE = "download";
3334
3335 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08003336 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003337 * {@link android.os.BatteryManager} for managing battery state.
3338 *
3339 * @see #getSystemService
3340 */
3341 public static final String BATTERY_SERVICE = "batterymanager";
3342
3343 /**
3344 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003345 * {@link android.nfc.NfcManager} for using NFC.
3346 *
3347 * @see #getSystemService
3348 */
3349 public static final String NFC_SERVICE = "nfc";
3350
3351 /**
3352 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003353 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003354 *
3355 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003356 */
3357 public static final String BLUETOOTH_SERVICE = "bluetooth";
3358
3359 /**
3360 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003361 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3362 *
3363 * @see #getSystemService
3364 */
3365 /** @hide */
3366 public static final String SIP_SERVICE = "sip";
3367
3368 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003369 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003370 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003371 * and for controlling this device's behavior as a USB device.
3372 *
3373 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04003374 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003375 */
3376 public static final String USB_SERVICE = "usb";
3377
3378 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003379 * Use with {@link #getSystemService} to retrieve a {@link
3380 * android.hardware.SerialManager} for access to serial ports.
3381 *
3382 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003383 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003384 *
3385 * @hide
3386 */
3387 public static final String SERIAL_SERVICE = "serial";
3388
3389 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003390 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003391 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3392 * HDMI-CEC protocol.
3393 *
3394 * @see #getSystemService
3395 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003396 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003397 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003398 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003399 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003400
3401 /**
3402 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003403 * {@link android.hardware.input.InputManager} for interacting with input devices.
3404 *
3405 * @see #getSystemService
3406 * @see android.hardware.input.InputManager
3407 */
3408 public static final String INPUT_SERVICE = "input";
3409
3410 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07003411 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003412 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3413 *
3414 * @see #getSystemService
3415 * @see android.hardware.display.DisplayManager
3416 */
3417 public static final String DISPLAY_SERVICE = "display";
3418
3419 /**
3420 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003421 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3422 *
3423 * @see #getSystemService
3424 * @see android.os.UserManager
3425 */
3426 public static final String USER_SERVICE = "user";
3427
3428 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003429 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003430 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3431 * profiles of a user.
3432 *
3433 * @see #getSystemService
3434 * @see android.content.pm.LauncherApps
3435 */
3436 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3437
3438 /**
3439 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003440 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3441 * and requesting permissions for restricted operations.
3442 * @see #getSystemService
3443 * @see android.content.RestrictionsManager
3444 */
3445 public static final String RESTRICTIONS_SERVICE = "restrictions";
3446
3447 /**
3448 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003449 * {@link android.app.AppOpsManager} for tracking application operations
3450 * on the device.
3451 *
3452 * @see #getSystemService
3453 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003454 */
3455 public static final String APP_OPS_SERVICE = "appops";
3456
3457 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003458 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003459 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003460 * camera devices.
3461 *
3462 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003463 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003464 */
3465 public static final String CAMERA_SERVICE = "camera";
3466
3467 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003468 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003469 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003470 *
3471 * @see #getSystemService
3472 * @see android.print.PrintManager
3473 */
3474 public static final String PRINT_SERVICE = "print";
3475
3476 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003477 * Use with {@link #getSystemService} to retrieve a
3478 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3479 * signals from the device.
3480 *
3481 * @see #getSystemService
3482 * @see android.hardware.ConsumerIrManager
3483 */
3484 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3485
3486 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003487 * {@link android.app.trust.TrustManager} for managing trust agents.
3488 * @see #getSystemService
3489 * @see android.app.trust.TrustManager
3490 * @hide
3491 */
3492 public static final String TRUST_SERVICE = "trust";
3493
3494 /**
Jae Seo39570912014-02-20 18:23:25 -08003495 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003496 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3497 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003498 *
3499 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003500 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003501 */
3502 public static final String TV_INPUT_SERVICE = "tv_input";
3503
3504 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003505 * {@link android.net.NetworkScoreManager} for managing network scoring.
3506 * @see #getSystemService
3507 * @see android.net.NetworkScoreManager
3508 * @hide
3509 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003510 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003511 public static final String NETWORK_SCORE_SERVICE = "network_score";
3512
3513 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003514 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003515 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003516 *
3517 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003518 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003519 */
3520 public static final String USAGE_STATS_SERVICE = "usagestats";
3521
3522 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003523 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003524 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003525 * background tasks.
3526 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003527 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003528 */
Christopher Tate7060b042014-06-09 19:50:00 -07003529 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003530
3531 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003532 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003533 * android.service.persistentdata.PersistentDataBlockManager} instance
3534 * for interacting with a storage device that lives across factory resets.
3535 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003536 * @see #getSystemService
3537 * @see android.service.persistentdata.PersistentDataBlockManager
3538 * @hide
3539 */
Andres Morales33df9372014-09-26 17:08:59 -07003540 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003541 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3542
3543 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003544 * Use with {@link #getSystemService} to retrieve a {@link
3545 * android.media.projection.MediaProjectionManager} instance for managing
3546 * media projection sessions.
3547 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003548 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003549 */
3550 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3551
3552 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003553 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003554 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003555 *
3556 * @see #getSystemService
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003557 */
3558 public static final String MIDI_SERVICE = "midi";
3559
Eric Laurent2035ac82015-03-05 15:18:44 -08003560
3561 /**
3562 * Use with {@link #getSystemService} to retrieve a
3563 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3564 *
3565 * @see #getSystemService
3566 * @hide
3567 */
3568 public static final String RADIO_SERVICE = "radio";
3569
Paul McLeana33be212015-02-20 07:52:45 -08003570 /**
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003571 * Use with {@link #getSystemService} to retrieve a
3572 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
3573 *
3574 * @see #getSystemService
3575 */
3576 public static final String HARDWARE_PROPERTIES_SERVICE = "hardwareproperties";
3577
3578 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 * Determine whether the given permission is allowed for a particular
3580 * process and user ID running in the system.
3581 *
3582 * @param permission The name of the permission being checked.
3583 * @param pid The process ID being checked against. Must be > 0.
3584 * @param uid The user ID being checked against. A uid of 0 is the root
3585 * user, which will pass every permission check.
3586 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003587 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 * pid/uid is allowed that permission, or
3589 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3590 *
3591 * @see PackageManager#checkPermission(String, String)
3592 * @see #checkCallingPermission
3593 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003594 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003595 @PackageManager.PermissionResult
3596 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597
Dianne Hackbornff170242014-11-19 10:59:01 -08003598 /** @hide */
3599 @PackageManager.PermissionResult
3600 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3601 IBinder callerToken);
3602
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003603 /**
3604 * Determine whether the calling process of an IPC you are handling has been
3605 * granted a particular permission. This is basically the same as calling
3606 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3607 * by {@link android.os.Binder#getCallingPid} and
3608 * {@link android.os.Binder#getCallingUid}. One important difference
3609 * is that if you are not currently processing an IPC, this function
3610 * will always fail. This is done to protect against accidentally
3611 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3612 * to avoid this protection.
3613 *
3614 * @param permission The name of the permission being checked.
3615 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003616 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003617 * pid/uid is allowed that permission, or
3618 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3619 *
3620 * @see PackageManager#checkPermission(String, String)
3621 * @see #checkPermission
3622 * @see #checkCallingOrSelfPermission
3623 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003624 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003625 @PackageManager.PermissionResult
3626 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003627
3628 /**
3629 * Determine whether the calling process of an IPC <em>or you</em> have been
3630 * granted a particular permission. This is the same as
3631 * {@link #checkCallingPermission}, except it grants your own permissions
3632 * if you are not currently processing an IPC. Use with care!
3633 *
3634 * @param permission The name of the permission being checked.
3635 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003636 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 * pid/uid is allowed that permission, or
3638 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3639 *
3640 * @see PackageManager#checkPermission(String, String)
3641 * @see #checkPermission
3642 * @see #checkCallingPermission
3643 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003644 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003645 @PackageManager.PermissionResult
3646 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647
3648 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08003649 * Determine whether <em>you</em> have been granted a particular permission.
3650 *
3651 * @param permission The name of the permission being checked.
3652 *
3653 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
3654 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
3655 *
3656 * @see PackageManager#checkPermission(String, String)
3657 * @see #checkCallingPermission(String)
3658 */
3659 @PackageManager.PermissionResult
3660 public abstract int checkSelfPermission(@NonNull String permission);
3661
3662 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 * If the given permission is not allowed for a particular process
3664 * and user ID running in the system, throw a {@link SecurityException}.
3665 *
3666 * @param permission The name of the permission being checked.
3667 * @param pid The process ID being checked against. Must be &gt; 0.
3668 * @param uid The user ID being checked against. A uid of 0 is the root
3669 * user, which will pass every permission check.
3670 * @param message A message to include in the exception if it is thrown.
3671 *
3672 * @see #checkPermission(String, int, int)
3673 */
3674 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003675 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003676
3677 /**
3678 * If the calling process of an IPC you are handling has not been
3679 * granted a particular permission, throw a {@link
3680 * SecurityException}. This is basically the same as calling
3681 * {@link #enforcePermission(String, int, int, String)} with the
3682 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3683 * and {@link android.os.Binder#getCallingUid}. One important
3684 * difference is that if you are not currently processing an IPC,
3685 * this function will always throw the SecurityException. This is
3686 * done to protect against accidentally leaking permissions; you
3687 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3688 * protection.
3689 *
3690 * @param permission The name of the permission being checked.
3691 * @param message A message to include in the exception if it is thrown.
3692 *
3693 * @see #checkCallingPermission(String)
3694 */
3695 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003696 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003697
3698 /**
3699 * If neither you nor the calling process of an IPC you are
3700 * handling has been granted a particular permission, throw a
3701 * {@link SecurityException}. This is the same as {@link
3702 * #enforceCallingPermission}, except it grants your own
3703 * permissions if you are not currently processing an IPC. Use
3704 * with care!
3705 *
3706 * @param permission The name of the permission being checked.
3707 * @param message A message to include in the exception if it is thrown.
3708 *
3709 * @see #checkCallingOrSelfPermission(String)
3710 */
3711 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003712 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713
3714 /**
3715 * Grant permission to access a specific Uri to another package, regardless
3716 * of whether that package has general permission to access the Uri's
3717 * content provider. This can be used to grant specific, temporary
3718 * permissions, typically in response to user interaction (such as the
3719 * user opening an attachment that you would like someone else to
3720 * display).
3721 *
3722 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3723 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3724 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3725 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3726 * start an activity instead of this function directly. If you use this
3727 * function directly, you should be sure to call
3728 * {@link #revokeUriPermission} when the target should no longer be allowed
3729 * to access it.
3730 *
3731 * <p>To succeed, the content provider owning the Uri must have set the
3732 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3733 * grantUriPermissions} attribute in its manifest or included the
3734 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3735 * &lt;grant-uri-permissions&gt;} tag.
3736 *
3737 * @param toPackage The package you would like to allow to access the Uri.
3738 * @param uri The Uri you would like to grant access to.
3739 * @param modeFlags The desired access modes. Any combination of
3740 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003741 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003743 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3744 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3745 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3746 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3747 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 *
3749 * @see #revokeUriPermission
3750 */
3751 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003752 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003753
3754 /**
3755 * Remove all permissions to access a particular content provider Uri
3756 * that were previously added with {@link #grantUriPermission}. The given
3757 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003758 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003759 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003760 * "content://foo". It will not remove any prefix grants that exist at a
3761 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003763 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003764 * regular permission access to a Uri, but had received access to it through
3765 * a specific Uri permission grant, you could not revoke that grant with this
3766 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003767 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003768 * but will remove whatever permission grants to the Uri had been given to the app
3769 * (or none).</p>
3770 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 * @param uri The Uri you would like to revoke access to.
3772 * @param modeFlags The desired access modes. Any combination of
3773 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3774 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3775 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3776 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3777 *
3778 * @see #grantUriPermission
3779 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003780 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781
3782 /**
3783 * Determine whether a particular process and user ID has been granted
3784 * permission to access a specific URI. This only checks for permissions
3785 * that have been explicitly granted -- if the given process/uid has
3786 * more general access to the URI's content provider then this check will
3787 * always fail.
3788 *
3789 * @param uri The uri that is being checked.
3790 * @param pid The process ID being checked against. Must be &gt; 0.
3791 * @param uid The user ID being checked against. A uid of 0 is the root
3792 * user, which will pass every permission check.
3793 * @param modeFlags The type of access to grant. May be one or both of
3794 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3795 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3796 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003797 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 * pid/uid is allowed to access that uri, or
3799 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3800 *
3801 * @see #checkCallingUriPermission
3802 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003803 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003804 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003805 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806
Dianne Hackbornff170242014-11-19 10:59:01 -08003807 /** @hide */
3808 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3809 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 /**
3812 * Determine whether the calling process and user ID has been
3813 * granted permission to access a specific URI. This is basically
3814 * the same as calling {@link #checkUriPermission(Uri, int, int,
3815 * int)} with the pid and uid returned by {@link
3816 * android.os.Binder#getCallingPid} and {@link
3817 * android.os.Binder#getCallingUid}. One important difference is
3818 * that if you are not currently processing an IPC, this function
3819 * will always fail.
3820 *
3821 * @param uri The uri that is being checked.
3822 * @param modeFlags The type of access to grant. May be one or both of
3823 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3824 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3825 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003826 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003827 * is allowed to access that uri, or
3828 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3829 *
3830 * @see #checkUriPermission(Uri, int, int, int)
3831 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003832 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003833 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834
3835 /**
3836 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3837 * permission to access a specific URI. This is the same as
3838 * {@link #checkCallingUriPermission}, except it grants your own permissions
3839 * if you are not currently processing an IPC. Use with care!
3840 *
3841 * @param uri The uri that is being checked.
3842 * @param modeFlags The type of access to grant. May be one or both of
3843 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3844 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3845 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003846 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 * is allowed to access that uri, or
3848 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3849 *
3850 * @see #checkCallingUriPermission
3851 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003852 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003853 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003854 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003855
3856 /**
3857 * Check both a Uri and normal permission. This allows you to perform
3858 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3859 * call.
3860 *
3861 * @param uri The Uri whose permission is to be checked, or null to not
3862 * do this check.
3863 * @param readPermission The permission that provides overall read access,
3864 * or null to not do this check.
3865 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003866 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 * @param pid The process ID being checked against. Must be &gt; 0.
3868 * @param uid The user ID being checked against. A uid of 0 is the root
3869 * user, which will pass every permission check.
3870 * @param modeFlags The type of access to grant. May be one or both of
3871 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3872 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3873 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003874 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 * is allowed to access that uri or holds one of the given permissions, or
3876 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3877 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003878 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003879 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3880 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003881 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003882
3883 /**
3884 * If a particular process and user ID has not been granted
3885 * permission to access a specific URI, throw {@link
3886 * SecurityException}. This only checks for permissions that have
3887 * been explicitly granted -- if the given process/uid has more
3888 * general access to the URI's content provider then this check
3889 * will always fail.
3890 *
3891 * @param uri The uri that is being checked.
3892 * @param pid The process ID being checked against. Must be &gt; 0.
3893 * @param uid The user ID being checked against. A uid of 0 is the root
3894 * user, which will pass every permission check.
3895 * @param modeFlags The type of access to grant. May be one or both of
3896 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3897 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3898 * @param message A message to include in the exception if it is thrown.
3899 *
3900 * @see #checkUriPermission(Uri, int, int, int)
3901 */
3902 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003903 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003904
3905 /**
3906 * If the calling process and user ID has not been granted
3907 * permission to access a specific URI, throw {@link
3908 * SecurityException}. This is basically the same as calling
3909 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3910 * the pid and uid returned by {@link
3911 * android.os.Binder#getCallingPid} and {@link
3912 * android.os.Binder#getCallingUid}. One important difference is
3913 * that if you are not currently processing an IPC, this function
3914 * will always throw a SecurityException.
3915 *
3916 * @param uri The uri that is being checked.
3917 * @param modeFlags The type of access to grant. May be one or both of
3918 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3919 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3920 * @param message A message to include in the exception if it is thrown.
3921 *
3922 * @see #checkCallingUriPermission(Uri, int)
3923 */
3924 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003925 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003926
3927 /**
3928 * If the calling process of an IPC <em>or you</em> has not been
3929 * granted permission to access a specific URI, throw {@link
3930 * SecurityException}. This is the same as {@link
3931 * #enforceCallingUriPermission}, except it grants your own
3932 * permissions if you are not currently processing an IPC. Use
3933 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003934 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003935 * @param uri The uri that is being checked.
3936 * @param modeFlags The type of access to grant. May be one or both of
3937 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3938 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3939 * @param message A message to include in the exception if it is thrown.
3940 *
3941 * @see #checkCallingOrSelfUriPermission(Uri, int)
3942 */
3943 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003944 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003945
3946 /**
3947 * Enforce both a Uri and normal permission. This allows you to perform
3948 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
3949 * call.
Scott Main4b5da682010-10-21 11:49:12 -07003950 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003951 * @param uri The Uri whose permission is to be checked, or null to not
3952 * do this check.
3953 * @param readPermission The permission that provides overall read access,
3954 * or null to not do this check.
3955 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003956 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003957 * @param pid The process ID being checked against. Must be &gt; 0.
3958 * @param uid The user ID being checked against. A uid of 0 is the root
3959 * user, which will pass every permission check.
3960 * @param modeFlags The type of access to grant. May be one or both of
3961 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3962 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3963 * @param message A message to include in the exception if it is thrown.
3964 *
3965 * @see #checkUriPermission(Uri, String, String, int, int, int)
3966 */
3967 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003968 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003969 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07003970 @Nullable String message);
3971
3972 /** @hide */
3973 @IntDef(flag = true,
3974 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
3975 @Retention(RetentionPolicy.SOURCE)
3976 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003977
3978 /**
3979 * Flag for use with {@link #createPackageContext}: include the application
3980 * code with the context. This means loading code into the caller's
3981 * process, so that {@link #getClassLoader()} can be used to instantiate
3982 * the application's classes. Setting this flags imposes security
3983 * restrictions on what application context you can access; if the
3984 * requested application can not be safely loaded into your process,
3985 * java.lang.SecurityException will be thrown. If this flag is not set,
3986 * there will be no restrictions on the packages that can be loaded,
3987 * but {@link #getClassLoader} will always return the default system
3988 * class loader.
3989 */
3990 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
3991
3992 /**
3993 * Flag for use with {@link #createPackageContext}: ignore any security
3994 * restrictions on the Context being requested, allowing it to always
3995 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
3996 * to be loaded into a process even when it isn't safe to do so. Use
3997 * with extreme care!
3998 */
3999 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004000
Romain Guy870e09f2009-07-06 16:35:25 -07004001 /**
4002 * Flag for use with {@link #createPackageContext}: a restricted context may
4003 * disable specific features. For instance, a View associated with a restricted
4004 * context would ignore particular XML attributes.
4005 */
4006 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004007
4008 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004009 * Flag for use with {@link #createPackageContext}: point all file APIs at
4010 * device-encrypted storage.
4011 *
4012 * @hide
4013 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004014 public static final int CONTEXT_DEVICE_ENCRYPTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004015
4016 /**
4017 * Flag for use with {@link #createPackageContext}: point all file APIs at
4018 * credential-encrypted storage.
4019 *
4020 * @hide
4021 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004022 public static final int CONTEXT_CREDENTIAL_ENCRYPTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004023
4024 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004025 * @hide Used to indicate we should tell the activity manager about the process
4026 * loading this code.
4027 */
4028 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4029
4030 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 * Return a new Context object for the given application name. This
4032 * Context is the same as what the named application gets when it is
4033 * launched, containing the same resources and class loader. Each call to
4034 * this method returns a new instance of a Context object; Context objects
4035 * are not shared, however they share common state (Resources, ClassLoader,
4036 * etc) so the Context instance itself is fairly lightweight.
4037 *
Jeff Brown6e539312015-02-24 18:53:21 -08004038 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004039 * application with the given package name.
4040 *
4041 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4042 * can not be loaded into the caller's process for security reasons (see
4043 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4044 *
4045 * @param packageName Name of the application's package.
4046 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
4047 * or {@link #CONTEXT_IGNORE_SECURITY}.
4048 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004049 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004050 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004051 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004053 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004054 */
4055 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004056 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004057
4058 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004059 * Similar to {@link #createPackageContext(String, int)}, but with a
4060 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4061 * will open any {@link Uri} as the given user.
4062 *
4063 * @hide
4064 */
4065 public abstract Context createPackageContextAsUser(
4066 String packageName, int flags, UserHandle user)
4067 throws PackageManager.NameNotFoundException;
4068
4069 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004070 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4071 *
4072 * @hide
4073 */
4074 public abstract Context createApplicationContext(ApplicationInfo application,
4075 int flags) throws PackageManager.NameNotFoundException;
4076
4077 /**
Jim Millera75a8832013-02-07 16:53:32 -08004078 * Get the userId associated with this context
4079 * @return user id
4080 *
4081 * @hide
4082 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004083 @TestApi
Jeff Sharkey8588bc12016-01-06 16:47:42 -07004084 public abstract @UserIdInt int getUserId();
Jim Millera75a8832013-02-07 16:53:32 -08004085
4086 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004087 * Return a new Context object for the current Context but whose resources
4088 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004089 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004090 * shared, however common state (ClassLoader, other Resources for the
4091 * same configuration) may be so the Context itself can be fairly lightweight.
4092 *
4093 * @param overrideConfiguration A {@link Configuration} specifying what
4094 * values to modify in the base Configuration of the original Context's
4095 * resources. If the base configuration changes (such as due to an
4096 * orientation change), the resources of this context will also change except
4097 * for those that have been explicitly overridden with a value here.
4098 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004099 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004100 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004101 public abstract Context createConfigurationContext(
4102 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004103
4104 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004105 * Return a new Context object for the current Context but whose resources
4106 * are adjusted to match the metrics of the given Display. Each call to this method
4107 * returns a new instance of a Context object; Context objects are not
4108 * shared, however common state (ClassLoader, other Resources for the
4109 * same configuration) may be so the Context itself can be fairly lightweight.
4110 *
4111 * The returned display Context provides a {@link WindowManager}
4112 * (see {@link #getSystemService(String)}) that is configured to show windows
4113 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4114 * method can be used to retrieve the Display from the returned Context.
4115 *
4116 * @param display A {@link Display} object specifying the display
4117 * for whose metrics the Context's resources should be tailored and upon which
4118 * new windows should be shown.
4119 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004120 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004121 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004122 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004123
4124 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004125 * Return a new Context object for the current Context but whose storage
4126 * APIs are backed by device-encrypted storage.
4127 * <p>
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004128 * Data stored in device-encrypted storage is typically encrypted with a key
4129 * tied to the physical device, and it can be accessed when the device has
4130 * booted successfully, both <em>before and after</em> the user has
4131 * authenticated with their credentials (such as a lock pattern or PIN).
4132 * Because device-encrypted data is available before user authentication,
4133 * you should carefully consider what data you store using this Context.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004134 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004135 * If the underlying device does not have the ability to store
4136 * device-encrypted and credential-encrypted data using different keys, then
4137 * both storage areas will become available at the same time. They remain
4138 * two distinct storage areas, and only the window of availability changes.
4139 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004140 * Each call to this method returns a new instance of a Context object;
4141 * Context objects are not shared, however common state (ClassLoader, other
4142 * Resources for the same configuration) may be so the Context itself can be
4143 * fairly lightweight.
4144 *
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004145 * @see #isDeviceEncryptedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004146 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004147 public abstract Context createDeviceEncryptedStorageContext();
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004148
4149 /**
4150 * Return a new Context object for the current Context but whose storage
4151 * APIs are backed by credential-encrypted storage.
4152 * <p>
4153 * Data stored in credential-encrypted storage is typically encrypted with a
4154 * key tied to user credentials, and they can be accessed
4155 * <em>only after</em> the user has entered their credentials (such as a
4156 * lock pattern or PIN).
4157 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004158 * If the underlying device does not have the ability to store
4159 * device-encrypted and credential-encrypted data using different keys, then
4160 * both storage areas will become available at the same time. They remain
4161 * two distinct storage areas, and only the window of availability changes.
4162 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004163 * Each call to this method returns a new instance of a Context object;
4164 * Context objects are not shared, however common state (ClassLoader, other
4165 * Resources for the same configuration) may be so the Context itself can be
4166 * fairly lightweight.
4167 *
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004168 * @see #isCredentialEncryptedStorage()
4169 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004170 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004171 @SystemApi
4172 public abstract Context createCredentialEncryptedStorageContext();
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004173
4174 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004175 * Gets the display adjustments holder for this context. This information
4176 * is provided on a per-application or activity basis and is used to simulate lower density
4177 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004178 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004179 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004180 * @return The compatibility info holder, or null if not required by the application.
4181 * @hide
4182 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004183 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004184
4185 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004186 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004187 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004188 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004189 *
Romain Guy870e09f2009-07-06 16:35:25 -07004190 * @see #CONTEXT_RESTRICTED
4191 */
4192 public boolean isRestricted() {
4193 return false;
4194 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004195
4196 /**
4197 * Indicates if the storage APIs of this Context are backed by
4198 * device-encrypted storage.
4199 *
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004200 * @see #createDeviceEncryptedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004201 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004202 public abstract boolean isDeviceEncryptedStorage();
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004203
4204 /**
4205 * Indicates if the storage APIs of this Context are backed by
4206 * credential-encrypted storage.
4207 *
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004208 * @see #createCredentialEncryptedStorageContext()
4209 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004210 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004211 @SystemApi
4212 public abstract boolean isCredentialEncryptedStorage();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004213}