blob: 8349d3da686080d04b576ab39acbd555286daabb [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 Sharkeycf3f0a12016-03-17 19:57:58 -0600694 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700695 */
696 public abstract SharedPreferences getSharedPreferences(File file, int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800697
698 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600699 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700700 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600701 * storage locations after an upgrade, such as moving to device protected
702 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700703 *
704 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600705 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700706 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600707 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700708 * preferences didn't exist in the source context, otherwise
709 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600710 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700711 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600712 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
713
714 /** @removed */
715 @Deprecated
716 public boolean migrateSharedPreferencesFrom(Context sourceContext, String name) {
717 return moveSharedPreferencesFrom(sourceContext, name);
718 }
Jeff Sharkey35871f22016-01-29 17:13:29 -0700719
720 /**
721 * Delete an existing shared preferences file.
722 *
723 * @param name The name (unique in the application package) of the shared
724 * preferences file.
725 * @return {@code true} if the shared preferences file was successfully
726 * deleted; else {@code false}.
727 * @see #getSharedPreferences(String, int)
728 */
729 public abstract boolean deleteSharedPreferences(String name);
730
731 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 * Open a private file associated with this Context's application package
733 * for reading.
734 *
735 * @param name The name of the file to open; can not contain path
736 * separators.
737 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400738 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 *
740 * @see #openFileOutput
741 * @see #fileList
742 * @see #deleteFile
743 * @see java.io.FileInputStream#FileInputStream(String)
744 */
745 public abstract FileInputStream openFileInput(String name)
746 throws FileNotFoundException;
747
748 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800749 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700750 * for writing. Creates the file if it doesn't already exist.
751 * <p>
752 * No additional permissions are required for the calling app to read or
753 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700754 *
Nick Kralevich15069212013-01-09 15:54:56 -0800755 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700756 * separators.
757 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -0700758 * default operation. Use {@link #MODE_APPEND} to append to an
759 * existing file.
John Spurlock6098c5d2013-06-17 10:32:46 -0400760 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 * @see #MODE_APPEND
762 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 * @see #openFileInput
764 * @see #fileList
765 * @see #deleteFile
766 * @see java.io.FileOutputStream#FileOutputStream(String)
767 */
768 public abstract FileOutputStream openFileOutput(String name, int mode)
769 throws FileNotFoundException;
770
771 /**
772 * Delete the given private file associated with this Context's
773 * application package.
774 *
775 * @param name The name of the file to delete; can not contain path
776 * separators.
777 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400778 * @return {@code true} if the file was successfully deleted; else
779 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 *
781 * @see #openFileInput
782 * @see #openFileOutput
783 * @see #fileList
784 * @see java.io.File#delete()
785 */
786 public abstract boolean deleteFile(String name);
787
788 /**
789 * Returns the absolute path on the filesystem where a file created with
790 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700791 * <p>
792 * The returned path may change over time if the calling app is moved to an
793 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 *
795 * @param name The name of the file for which you would like to get
796 * its path.
797 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400798 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 *
800 * @see #openFileOutput
801 * @see #getFilesDir
802 * @see #getDir
803 */
804 public abstract File getFileStreamPath(String name);
805
806 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700807 * Returns the absolute path on the filesystem where a file created with
808 * {@link #getSharedPreferences(String, int)} is stored.
809 * <p>
810 * The returned path may change over time if the calling app is moved to an
811 * adopted storage device, so only relative paths should be persisted.
812 *
813 * @param name The name of the shared preferences for which you would like
814 * to get a path.
815 * @return An absolute path to the given file.
816 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600817 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700818 */
819 public abstract File getSharedPreferencesPath(String name);
820
821 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700822 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600823 * private files belonging to this app are stored. Apps should not use this
824 * path directly; they should instead use {@link #getFilesDir()},
825 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
826 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700827 * <p>
828 * The returned path may change over time if the calling app is moved to an
829 * adopted storage device, so only relative paths should be persisted.
830 * <p>
831 * No additional permissions are required for the calling app to read or
832 * write files under the returned path.
833 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600834 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700835 */
836 public abstract File getDataDir();
837
838 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700839 * Returns the absolute path to the directory on the filesystem where files
840 * created with {@link #openFileOutput} are stored.
841 * <p>
842 * The returned path may change over time if the calling app is moved to an
843 * adopted storage device, so only relative paths should be persisted.
844 * <p>
845 * No additional permissions are required for the calling app to read or
846 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700847 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400848 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 * @see #openFileOutput
850 * @see #getFileStreamPath
851 * @see #getDir
852 */
853 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700856 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700857 * {@link #getFilesDir()}. The difference is that files placed under this
858 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700859 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
860 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700861 * <p>
862 * The returned path may change over time if the calling app is moved to an
863 * adopted storage device, so only relative paths should be persisted.
864 * <p>
865 * No additional permissions are required for the calling app to read or
866 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700867 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700868 * @return The path of the directory holding application files that will not
869 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700870 * @see #openFileOutput
871 * @see #getFileStreamPath
872 * @see #getDir
873 * @see android.app.backup.BackupAgent
874 */
875 public abstract File getNoBackupFilesDir();
876
877 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700878 * Returns the absolute path to the directory on the primary shared/external
879 * storage device where the application can place persistent files it owns.
880 * These files are internal to the applications, and not typically visible
881 * to the user as media.
882 * <p>
883 * This is like {@link #getFilesDir()} in that these files will be deleted
884 * when the application is uninstalled, however there are some important
885 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800886 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700887 * <li>Shared storage may not always be available, since removable media can
888 * be ejected by the user. Media state can be checked using
889 * {@link Environment#getExternalStorageState(File)}.
890 * <li>There is no security enforced with these files. For example, any
891 * application holding
892 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700893 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800894 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700895 * <p>
896 * If a shared storage device is emulated (as determined by
897 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
898 * backed by a private user data partition, which means there is little
899 * benefit to storing data here instead of the private directories returned
900 * by {@link #getFilesDir()}, etc.
901 * <p>
902 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700903 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700904 * accessible to the calling app. This only applies to paths generated for
905 * package name of the calling application. To access paths belonging to
906 * other packages,
907 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
908 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
909 * <p>
910 * On devices with multiple users (as described by {@link UserManager}),
911 * each user has their own isolated shared storage. Applications only have
912 * access to the shared storage for the user they're running as.
913 * <p>
914 * The returned path may change over time if different shared storage media
915 * is inserted, so only relative paths should be persisted.
916 * <p>
917 * Here is an example of typical code to manipulate a file in an
918 * application's shared storage:
919 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800920 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
921 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700922 * <p>
923 * If you supply a non-null <var>type</var> to this function, the returned
924 * file will be a path to a sub-directory of the given type. Though these
925 * files are not automatically scanned by the media scanner, you can
926 * explicitly add them to the media database with
927 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
928 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800929 * {@link android.os.Environment#getExternalStoragePublicDirectory
930 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700931 * directories of media shared by all applications. The directories returned
932 * here are owned by the application, and their contents will be removed
933 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800934 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700935 * Environment.getExternalStoragePublicDirectory()}, the directory returned
936 * here will be automatically created for you.
937 * <p>
938 * Here is an example of typical code to manipulate a picture in an
939 * application's shared storage and add it to the media database:
940 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800941 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
942 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -0700943 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700944 * @param type The type of files directory to return. May be {@code null}
945 * for the root of the files directory or one of the following
946 * constants for a subdirectory:
947 * {@link android.os.Environment#DIRECTORY_MUSIC},
948 * {@link android.os.Environment#DIRECTORY_PODCASTS},
949 * {@link android.os.Environment#DIRECTORY_RINGTONES},
950 * {@link android.os.Environment#DIRECTORY_ALARMS},
951 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
952 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
953 * {@link android.os.Environment#DIRECTORY_MOVIES}.
954 * @return the absolute path to application-specific directory. May return
955 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800956 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700957 * @see #getExternalFilesDirs(String)
958 * @see Environment#getExternalStorageState(File)
959 * @see Environment#isExternalStorageEmulated(File)
960 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800961 */
Tor Norbyed9273d62013-05-30 15:59:53 -0700962 @Nullable
963 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -0700964
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800965 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700966 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700967 * shared/external storage devices where the application can place
968 * persistent files it owns. These files are internal to the application,
969 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700970 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700971 * This is like {@link #getFilesDir()} in that these files will be deleted
972 * when the application is uninstalled, however there are some important
973 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700974 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700975 * <li>Shared storage may not always be available, since removable media can
976 * be ejected by the user. Media state can be checked using
977 * {@link Environment#getExternalStorageState(File)}.
978 * <li>There is no security enforced with these files. For example, any
979 * application holding
980 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
981 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700982 * </ul>
983 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700984 * If a shared storage device is emulated (as determined by
985 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
986 * backed by a private user data partition, which means there is little
987 * benefit to storing data here instead of the private directories returned
988 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700989 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700990 * Shared storage devices returned here are considered a stable part of the
991 * device, including physical media slots under a protective cover. The
992 * returned paths do not include transient devices, such as USB flash drives
993 * connected to handheld devices.
994 * <p>
995 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700996 * example, an app may choose to store large files on the device with the
997 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -0700998 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700999 * No additional permissions are required for the calling app to read or
1000 * write files under the returned path. Write access outside of these paths
1001 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001002 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001003 * The returned path may change over time if different shared storage media
1004 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001005 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001006 * @param type The type of files directory to return. May be {@code null}
1007 * for the root of the files directory or one of the following
1008 * constants for a subdirectory:
1009 * {@link android.os.Environment#DIRECTORY_MUSIC},
1010 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1011 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1012 * {@link android.os.Environment#DIRECTORY_ALARMS},
1013 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1014 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1015 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1016 * @return the absolute paths to application-specific directories. Some
1017 * individual paths may be {@code null} if that shared storage is
1018 * not currently available. The first path returned is the same as
1019 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001020 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001021 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001022 * @see Environment#isExternalStorageEmulated(File)
1023 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001024 */
1025 public abstract File[] getExternalFilesDirs(String type);
1026
1027 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001028 * Return the primary shared/external storage directory where this
1029 * application's OBB files (if there are any) can be found. Note if the
1030 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001031 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001032 * This is like {@link #getFilesDir()} in that these files will be deleted
1033 * when the application is uninstalled, however there are some important
1034 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001035 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001036 * <li>Shared storage may not always be available, since removable media can
1037 * be ejected by the user. Media state can be checked using
1038 * {@link Environment#getExternalStorageState(File)}.
1039 * <li>There is no security enforced with these files. For example, any
1040 * application holding
1041 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001042 * these files.
1043 * </ul>
1044 * <p>
1045 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1046 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001047 * accessible to the calling app. This only applies to paths generated for
1048 * package name of the calling application. To access paths belonging to
1049 * other packages,
1050 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1051 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001052 * <p>
1053 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001054 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001055 * should ensure that multiple instances running under different users don't
1056 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001057 *
1058 * @return the absolute path to application-specific directory. May return
1059 * {@code null} if shared storage is not currently available.
1060 * @see #getObbDirs()
1061 * @see Environment#getExternalStorageState(File)
1062 * @see Environment#isExternalStorageEmulated(File)
1063 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001064 */
1065 public abstract File getObbDir();
1066
1067 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001068 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001069 * shared/external storage devices where the application's OBB files (if
1070 * there are any) can be found. Note if the application does not have any
1071 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001072 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001073 * This is like {@link #getFilesDir()} in that these files will be deleted
1074 * when the application is uninstalled, however there are some important
1075 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001076 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001077 * <li>Shared storage may not always be available, since removable media can
1078 * be ejected by the user. Media state can be checked using
1079 * {@link Environment#getExternalStorageState(File)}.
1080 * <li>There is no security enforced with these files. For example, any
1081 * application holding
1082 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1083 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001084 * </ul>
1085 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001086 * Shared storage devices returned here are considered a stable part of the
1087 * device, including physical media slots under a protective cover. The
1088 * returned paths do not include transient devices, such as USB flash drives
1089 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001090 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001091 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001092 * example, an app may choose to store large files on the device with the
1093 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001094 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001095 * No additional permissions are required for the calling app to read or
1096 * write files under the returned path. Write access outside of these paths
1097 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001098 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001099 * @return the absolute paths to application-specific directories. Some
1100 * individual paths may be {@code null} if that shared storage is
1101 * not currently available. The first path returned is the same as
1102 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001103 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001104 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001105 * @see Environment#isExternalStorageEmulated(File)
1106 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001107 */
1108 public abstract File[] getObbDirs();
1109
1110 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001111 * Returns the absolute path to the application specific cache directory on
1112 * the filesystem. These files will be ones that get deleted first when the
1113 * device runs low on storage. There is no guarantee when these files will
1114 * be deleted.
1115 * <p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001116 * <strong>Note: you should not <em>rely</em> on the system deleting these
1117 * files for you; you should always have a reasonable maximum, such as 1 MB,
1118 * for the amount of space you consume with cache files, and prune those
1119 * files when exceeding that space.</strong>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001120 * <p>
1121 * The returned path may change over time if the calling app is moved to an
1122 * adopted storage device, so only relative paths should be persisted.
1123 * <p>
1124 * Apps require no extra permissions to read or write to the returned path,
1125 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001126 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001127 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 * @see #openFileOutput
1129 * @see #getFileStreamPath
1130 * @see #getDir
1131 */
1132 public abstract File getCacheDir();
1133
1134 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001135 * Returns the absolute path to the application specific cache directory on
1136 * the filesystem designed for storing cached code. The system will delete
1137 * any files stored in this location both when your specific application is
1138 * upgraded, and when the entire platform is upgraded.
1139 * <p>
1140 * This location is optimal for storing compiled or optimized code generated
1141 * by your application at runtime.
1142 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001143 * The returned path may change over time if the calling app is moved to an
1144 * adopted storage device, so only relative paths should be persisted.
1145 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001146 * Apps require no extra permissions to read or write to the returned path,
1147 * since this path lives in their private storage.
1148 *
1149 * @return The path of the directory holding application code cache files.
1150 */
1151 public abstract File getCodeCacheDir();
1152
1153 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001154 * Returns absolute path to application-specific directory on the primary
1155 * shared/external storage device where the application can place cache
1156 * files it owns. These files are internal to the application, and not
1157 * typically visible to the user as media.
1158 * <p>
1159 * This is like {@link #getCacheDir()} in that these files will be deleted
1160 * when the application is uninstalled, however there are some important
1161 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001162 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001163 * <li>The platform does not always monitor the space available in shared
1164 * storage, and thus may not automatically delete these files. Apps should
1165 * always manage the maximum space used in this location. Currently the only
1166 * time files here will be deleted by the platform is when running on
1167 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1168 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1169 * <li>Shared storage may not always be available, since removable media can
1170 * be ejected by the user. Media state can be checked using
1171 * {@link Environment#getExternalStorageState(File)}.
1172 * <li>There is no security enforced with these files. For example, any
1173 * application holding
1174 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001175 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001176 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001177 * <p>
1178 * If a shared storage device is emulated (as determined by
1179 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1180 * backed by a private user data partition, which means there is little
1181 * benefit to storing data here instead of the private directory returned by
1182 * {@link #getCacheDir()}.
1183 * <p>
1184 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001185 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001186 * accessible to the calling app. This only applies to paths generated for
1187 * package name of the calling application. To access paths belonging to
1188 * other packages,
1189 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1190 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1191 * <p>
1192 * On devices with multiple users (as described by {@link UserManager}),
1193 * each user has their own isolated shared storage. Applications only have
1194 * access to the shared storage for the user they're running as.
1195 * <p>
1196 * The returned path may change over time if different shared storage media
1197 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001198 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001199 * @return the absolute path to application-specific directory. May return
1200 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001201 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001202 * @see #getExternalCacheDirs()
1203 * @see Environment#getExternalStorageState(File)
1204 * @see Environment#isExternalStorageEmulated(File)
1205 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001206 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001207 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001208 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001209
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001210 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001211 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001212 * shared/external storage devices where the application can place cache
1213 * files it owns. These files are internal to the application, and not
1214 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001215 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001216 * This is like {@link #getCacheDir()} in that these files will be deleted
1217 * when the application is uninstalled, however there are some important
1218 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001219 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001220 * <li>The platform does not always monitor the space available in shared
1221 * storage, and thus may not automatically delete these files. Apps should
1222 * always manage the maximum space used in this location. Currently the only
1223 * time files here will be deleted by the platform is when running on
1224 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1225 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1226 * <li>Shared storage may not always be available, since removable media can
1227 * be ejected by the user. Media state can be checked using
1228 * {@link Environment#getExternalStorageState(File)}.
1229 * <li>There is no security enforced with these files. For example, any
1230 * application holding
1231 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1232 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001233 * </ul>
1234 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001235 * If a shared storage device is emulated (as determined by
1236 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1237 * backed by a private user data partition, which means there is little
1238 * benefit to storing data here instead of the private directory returned by
1239 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001240 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001241 * Shared storage devices returned here are considered a stable part of the
1242 * device, including physical media slots under a protective cover. The
1243 * returned paths do not include transient devices, such as USB flash drives
1244 * connected to handheld devices.
1245 * <p>
1246 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001247 * example, an app may choose to store large files on the device with the
1248 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001249 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001250 * No additional permissions are required for the calling app to read or
1251 * write files under the returned path. Write access outside of these paths
1252 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001253 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001254 * The returned paths may change over time if different shared storage media
1255 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001256 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001257 * @return the absolute paths to application-specific directories. Some
1258 * individual paths may be {@code null} if that shared storage is
1259 * not currently available. The first path returned is the same as
1260 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001261 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001262 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001263 * @see Environment#isExternalStorageEmulated(File)
1264 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001265 */
1266 public abstract File[] getExternalCacheDirs();
1267
1268 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001269 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001270 * shared/external storage devices where the application can place media
1271 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001272 * {@link MediaStore}.
1273 * <p>
1274 * This is like {@link #getExternalFilesDirs} in that these files will be
1275 * deleted when the application is uninstalled, however there are some
1276 * important differences:
1277 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001278 * <li>Shared storage may not always be available, since removable media can
1279 * be ejected by the user. Media state can be checked using
1280 * {@link Environment#getExternalStorageState(File)}.
1281 * <li>There is no security enforced with these files. For example, any
1282 * application holding
1283 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1284 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001285 * </ul>
1286 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001287 * Shared storage devices returned here are considered a stable part of the
1288 * device, including physical media slots under a protective cover. The
1289 * returned paths do not include transient devices, such as USB flash drives
1290 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001291 * <p>
1292 * An application may store data on any or all of the returned devices. For
1293 * example, an app may choose to store large files on the device with the
1294 * most available space, as measured by {@link StatFs}.
1295 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001296 * No additional permissions are required for the calling app to read or
1297 * write files under the returned path. Write access outside of these paths
1298 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001299 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001300 * The returned paths may change over time if different shared storage media
1301 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001302 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001303 * @return the absolute paths to application-specific directories. Some
1304 * individual paths may be {@code null} if that shared storage is
1305 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001306 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001307 * @see Environment#isExternalStorageEmulated(File)
1308 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001309 */
1310 public abstract File[] getExternalMediaDirs();
1311
1312 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001313 * Returns an array of strings naming the private files associated with
1314 * this Context's application package.
1315 *
1316 * @return Array of strings naming the private files.
1317 *
1318 * @see #openFileInput
1319 * @see #openFileOutput
1320 * @see #deleteFile
1321 */
1322 public abstract String[] fileList();
1323
1324 /**
1325 * Retrieve, creating if needed, a new directory in which the application
1326 * can place its own custom data files. You can use the returned File
1327 * object to create and access files in this directory. Note that files
1328 * created through a File object will only be accessible by your own
1329 * application; you can only set the mode of the entire directory, not
1330 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001331 * <p>
1332 * The returned path may change over time if the calling app is moved to an
1333 * adopted storage device, so only relative paths should be persisted.
1334 * <p>
1335 * Apps require no extra permissions to read or write to the returned path,
1336 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001337 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001338 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001339 * that is created as part of your application data.
Nick Kralevich92091fa2012-12-12 16:24:31 -08001340 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
Jeff Sharkey634dc422016-01-30 17:44:15 -07001341 * default operation.
Nick Kralevich15069212013-01-09 15:54:56 -08001342 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001343 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001344 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001345 *
1346 * @see #openFileOutput(String, int)
1347 */
1348 public abstract File getDir(String name, int mode);
1349
1350 /**
1351 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001352 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001353 *
1354 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001355 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1356 * default operation. Use
1357 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1358 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1359 * to disable localized collators.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001360 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001361 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001362 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001363 * @throws android.database.sqlite.SQLiteException if the database file
1364 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001366 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001367 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 * @see #deleteDatabase
1369 */
1370 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1371 int mode, CursorFactory factory);
1372
1373 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001374 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001375 * application package. Creates the database file if it doesn't exist.
1376 * <p>
1377 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1378 * to be used to handle corruption when sqlite reports database corruption.
1379 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001380 *
1381 * @param name The name (unique in the application package) of the database.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001382 * @param mode Operating mode. Use 0 or {@link #MODE_PRIVATE} for the
1383 * default operation. Use
1384 * {@link #MODE_ENABLE_WRITE_AHEAD_LOGGING} to enable write-ahead
1385 * logging by default. Use {@link #MODE_NO_LOCALIZED_COLLATORS}
1386 * to disable localized collators.
Vasu Nori74f170f2010-06-01 18:06:18 -07001387 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001388 * cursor when query is called.
1389 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1390 * sqlite reports database corruption. if null,
1391 * {@link android.database.DefaultDatabaseErrorHandler} is
1392 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001393 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001394 * @throws android.database.sqlite.SQLiteException if the database file
1395 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001396 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001397 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001398 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001399 * @see #deleteDatabase
1400 */
1401 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Tor Norbyed9273d62013-05-30 15:59:53 -07001402 int mode, CursorFactory factory,
1403 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001404
1405 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001406 * Move an existing database file from the given source storage context to
1407 * this context. This is typically used to migrate data between storage
1408 * locations after an upgrade, such as migrating to device protected
1409 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001410 *
1411 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001412 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001413 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001414 * @return {@code true} if the move was successful or if the database didn't
1415 * exist in the source context, otherwise {@code false}.
1416 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001417 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001418 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1419
1420 /** @removed */
1421 @Deprecated
1422 public boolean migrateDatabaseFrom(Context sourceContext, String name) {
1423 return moveDatabaseFrom(sourceContext, name);
1424 }
Jeff Sharkey35871f22016-01-29 17:13:29 -07001425
1426 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001427 * Delete an existing private SQLiteDatabase associated with this Context's
1428 * application package.
1429 *
1430 * @param name The name (unique in the application package) of the
1431 * database.
1432 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001433 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 *
1435 * @see #openOrCreateDatabase
1436 */
1437 public abstract boolean deleteDatabase(String name);
1438
1439 /**
1440 * Returns the absolute path on the filesystem where a database created with
1441 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001442 * <p>
1443 * The returned path may change over time if the calling app is moved to an
1444 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001445 *
1446 * @param name The name of the database for which you would like to get
1447 * its path.
1448 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001449 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001450 *
1451 * @see #openOrCreateDatabase
1452 */
1453 public abstract File getDatabasePath(String name);
1454
1455 /**
1456 * Returns an array of strings naming the private databases associated with
1457 * this Context's application package.
1458 *
1459 * @return Array of strings naming the private databases.
1460 *
1461 * @see #openOrCreateDatabase
1462 * @see #deleteDatabase
1463 */
1464 public abstract String[] databaseList();
1465
1466 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001467 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001468 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001469 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001470 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001471 public abstract Drawable getWallpaper();
1472
1473 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001474 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001475 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001476 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001477 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001478 public abstract Drawable peekWallpaper();
1479
1480 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001481 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1482 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001484 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 public abstract int getWallpaperDesiredMinimumWidth();
1486
1487 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001488 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1489 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001491 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 public abstract int getWallpaperDesiredMinimumHeight();
1493
1494 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001495 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001496 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001497 * <p>This method requires the caller to hold the permission
1498 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001500 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1502
1503 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001504 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001505 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001506 * <p>This method requires the caller to hold the permission
1507 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001509 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 public abstract void setWallpaper(InputStream data) throws IOException;
1511
1512 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001513 * @deprecated Use {@link android.app.WallpaperManager#clear
1514 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001515 * <p>This method requires the caller to hold the permission
1516 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001518 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 public abstract void clearWallpaper() throws IOException;
1520
1521 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001522 * Same as {@link #startActivity(Intent, Bundle)} with no options
1523 * specified.
1524 *
1525 * @param intent The description of the activity to start.
1526 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001527 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001528 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001529 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001530 * @see PackageManager#resolveActivity
1531 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001532 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001533
1534 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001535 * Version of {@link #startActivity(Intent)} that allows you to specify the
1536 * user the activity will be started for. This is not available to applications
1537 * that are not pre-installed on the system image. Using it requires holding
1538 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani82644082012-08-03 13:09:11 -07001539 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001540 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001541 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001542 * @hide
1543 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001544 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001545 throw new RuntimeException("Not implemented. Must override in a subclass.");
1546 }
1547
1548 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001549 * Launch a new activity. You will not receive any information about when
1550 * the activity exits.
1551 *
1552 * <p>Note that if this method is being called from outside of an
1553 * {@link android.app.Activity} Context, then the Intent must include
1554 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1555 * without being started from an existing Activity, there is no existing
1556 * task in which to place the new activity and thus it needs to be placed
1557 * in its own separate task.
1558 *
1559 * <p>This method throws {@link ActivityNotFoundException}
1560 * if there was no Activity found to run the given Intent.
1561 *
1562 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001563 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001564 * May be null if there are no options. See {@link android.app.ActivityOptions}
1565 * for how to build the Bundle supplied here; there are no supported definitions
1566 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001568 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 *
Scott Main60dd5202012-06-23 00:01:22 -07001570 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001571 * @see PackageManager#resolveActivity
1572 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001573 public abstract void startActivity(@RequiresPermission Intent intent,
1574 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001575
1576 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001577 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1578 * user the activity will be started for. This is not available to applications
1579 * that are not pre-installed on the system image. Using it requires holding
1580 * the INTERACT_ACROSS_USERS_FULL permission.
Amith Yamasani258848d2012-08-10 17:06:33 -07001581 * @param intent The description of the activity to start.
1582 * @param options Additional options for how the Activity should be started.
1583 * May be null if there are no options. See {@link android.app.ActivityOptions}
1584 * for how to build the Bundle supplied here; there are no supported definitions
1585 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001586 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001587 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001588 * @hide
1589 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001590 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1591 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001592 throw new RuntimeException("Not implemented. Must override in a subclass.");
1593 }
1594
1595 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001596 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1597 * is only supported for Views and Fragments.
1598 * @param who The identifier for the calling element that will receive the result.
1599 * @param intent The intent to start.
1600 * @param requestCode The code that will be returned with onActivityResult() identifying this
1601 * request.
1602 * @param options Additional options for how the Activity should be started.
1603 * May be null if there are no options. See {@link android.app.ActivityOptions}
1604 * for how to build the Bundle supplied here; there are no supported definitions
1605 * for building it manually.
1606 * @hide
1607 */
1608 public void startActivityForResult(
1609 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1610 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1611 + "Check canStartActivityForResult() before calling.");
1612 }
1613
1614 /**
1615 * Identifies whether this Context instance will be able to process calls to
1616 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1617 * @hide
1618 */
1619 public boolean canStartActivityForResult() {
1620 return false;
1621 }
1622
1623 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001624 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1625 * specified.
1626 *
1627 * @param intents An array of Intents to be started.
1628 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001629 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001630 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001631 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001632 * @see PackageManager#resolveActivity
1633 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001634 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635
1636 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001637 * Launch multiple new activities. This is generally the same as calling
1638 * {@link #startActivity(Intent)} for the first Intent in the array,
1639 * that activity during its creation calling {@link #startActivity(Intent)}
1640 * for the second entry, etc. Note that unlike that approach, generally
1641 * none of the activities except the last in the array will be created
1642 * at this point, but rather will be created when the user first visits
1643 * them (due to pressing back from the activity on top).
1644 *
1645 * <p>This method throws {@link ActivityNotFoundException}
1646 * if there was no Activity found for <em>any</em> given Intent. In this
1647 * case the state of the activity stack is undefined (some Intents in the
1648 * list may be on it, some not), so you probably want to avoid such situations.
1649 *
1650 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001651 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001652 * See {@link android.content.Context#startActivity(Intent, Bundle)
1653 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001654 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001655 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001656 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001657 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001658 * @see PackageManager#resolveActivity
1659 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001660 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001661
1662 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001663 * @hide
1664 * Launch multiple new activities. This is generally the same as calling
1665 * {@link #startActivity(Intent)} for the first Intent in the array,
1666 * that activity during its creation calling {@link #startActivity(Intent)}
1667 * for the second entry, etc. Note that unlike that approach, generally
1668 * none of the activities except the last in the array will be created
1669 * at this point, but rather will be created when the user first visits
1670 * them (due to pressing back from the activity on top).
1671 *
1672 * <p>This method throws {@link ActivityNotFoundException}
1673 * if there was no Activity found for <em>any</em> given Intent. In this
1674 * case the state of the activity stack is undefined (some Intents in the
1675 * list may be on it, some not), so you probably want to avoid such situations.
1676 *
1677 * @param intents An array of Intents to be started.
1678 * @param options Additional options for how the Activity should be started.
1679 * @param userHandle The user for whom to launch the activities
1680 * See {@link android.content.Context#startActivity(Intent, Bundle)
1681 * Context.startActivity(Intent, Bundle)} for more details.
1682 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001683 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001684 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001685 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001686 * @see PackageManager#resolveActivity
1687 */
1688 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1689 throw new RuntimeException("Not implemented. Must override in a subclass.");
1690 }
1691
1692 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001693 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1694 * with no options specified.
1695 *
1696 * @param intent The IntentSender to launch.
1697 * @param fillInIntent If non-null, this will be provided as the
1698 * intent parameter to {@link IntentSender#sendIntent}.
1699 * @param flagsMask Intent flags in the original IntentSender that you
1700 * would like to change.
1701 * @param flagsValues Desired values for any bits set in
1702 * <var>flagsMask</var>
1703 * @param extraFlags Always set to 0.
1704 *
1705 * @see #startActivity(Intent)
1706 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1707 */
1708 public abstract void startIntentSender(IntentSender intent,
1709 Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
1710 throws IntentSender.SendIntentException;
1711
1712 /**
1713 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001714 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001715 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001716 * here; otherwise, its associated action will be executed (such as
1717 * sending a broadcast) as if you had called
1718 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001719 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001720 * @param intent The IntentSender to launch.
1721 * @param fillInIntent If non-null, this will be provided as the
1722 * intent parameter to {@link IntentSender#sendIntent}.
1723 * @param flagsMask Intent flags in the original IntentSender that you
1724 * would like to change.
1725 * @param flagsValues Desired values for any bits set in
1726 * <var>flagsMask</var>
1727 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001728 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001729 * See {@link android.content.Context#startActivity(Intent, Bundle)
1730 * Context.startActivity(Intent, Bundle)} for more details. If options
1731 * have also been supplied by the IntentSender, options given here will
1732 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001733 *
1734 * @see #startActivity(Intent, Bundle)
1735 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001736 */
1737 public abstract void startIntentSender(IntentSender intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001738 @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
Dianne Hackborna4972e92012-03-14 10:38:05 -07001739 Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001740
1741 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001742 * Broadcast the given intent to all interested BroadcastReceivers. This
1743 * call is asynchronous; it returns immediately, and you will continue
1744 * executing while the receivers are run. No results are propagated from
1745 * receivers and receivers can not abort the broadcast. If you want
1746 * to allow receivers to propagate results or abort the broadcast, you must
1747 * send an ordered broadcast using
1748 * {@link #sendOrderedBroadcast(Intent, String)}.
1749 *
1750 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1751 *
1752 * @param intent The Intent to broadcast; all receivers matching this
1753 * Intent will receive the broadcast.
1754 *
1755 * @see android.content.BroadcastReceiver
1756 * @see #registerReceiver
1757 * @see #sendBroadcast(Intent, String)
1758 * @see #sendOrderedBroadcast(Intent, String)
1759 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1760 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001761 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762
1763 /**
1764 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1765 * an optional required permission to be enforced. This
1766 * call is asynchronous; it returns immediately, and you will continue
1767 * executing while the receivers are run. No results are propagated from
1768 * receivers and receivers can not abort the broadcast. If you want
1769 * to allow receivers to propagate results or abort the broadcast, you must
1770 * send an ordered broadcast using
1771 * {@link #sendOrderedBroadcast(Intent, String)}.
1772 *
1773 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1774 *
1775 * @param intent The Intent to broadcast; all receivers matching this
1776 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001777 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001778 * a receiver must hold in order to receive your broadcast.
1779 * If null, no permission is required.
1780 *
1781 * @see android.content.BroadcastReceiver
1782 * @see #registerReceiver
1783 * @see #sendBroadcast(Intent)
1784 * @see #sendOrderedBroadcast(Intent, String)
1785 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1786 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001787 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001788 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001789
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001790
1791 /**
1792 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1793 * an array of required permissions to be enforced. This call is asynchronous; it returns
1794 * immediately, and you will continue executing while the receivers are run. No results are
1795 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1796 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1797 * using {@link #sendOrderedBroadcast(Intent, String)}.
1798 *
1799 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1800 *
1801 * @param intent The Intent to broadcast; all receivers matching this
1802 * Intent will receive the broadcast.
1803 * @param receiverPermissions Array of names of permissions that a receiver must hold
1804 * in order to receive your broadcast.
1805 * If null or empty, no permissions are required.
1806 *
1807 * @see android.content.BroadcastReceiver
1808 * @see #registerReceiver
1809 * @see #sendBroadcast(Intent)
1810 * @see #sendOrderedBroadcast(Intent, String)
1811 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1812 * @hide
1813 */
1814 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1815 String[] receiverPermissions);
1816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001818 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1819 * an optional required permission to be enforced. This
1820 * call is asynchronous; it returns immediately, and you will continue
1821 * executing while the receivers are run. No results are propagated from
1822 * receivers and receivers can not abort the broadcast. If you want
1823 * to allow receivers to propagate results or abort the broadcast, you must
1824 * send an ordered broadcast using
1825 * {@link #sendOrderedBroadcast(Intent, String)}.
1826 *
1827 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1828 *
1829 * @param intent The Intent to broadcast; all receivers matching this
1830 * Intent will receive the broadcast.
1831 * @param receiverPermission (optional) String naming a permission that
1832 * a receiver must hold in order to receive your broadcast.
1833 * If null, no permission is required.
1834 * @param options (optional) Additional sending options, generated from a
1835 * {@link android.app.BroadcastOptions}.
1836 *
1837 * @see android.content.BroadcastReceiver
1838 * @see #registerReceiver
1839 * @see #sendBroadcast(Intent)
1840 * @see #sendOrderedBroadcast(Intent, String)
1841 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1842 * @hide
1843 */
1844 @SystemApi
1845 public abstract void sendBroadcast(Intent intent,
1846 @Nullable String receiverPermission,
1847 @Nullable Bundle options);
1848
1849 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001850 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001851 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001852 * @hide
1853 */
1854 public abstract void sendBroadcast(Intent intent,
1855 String receiverPermission, int appOp);
1856
1857 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1859 * them one at a time to allow more preferred receivers to consume the
1860 * broadcast before it is delivered to less preferred receivers. This
1861 * call is asynchronous; it returns immediately, and you will continue
1862 * executing while the receivers are run.
1863 *
1864 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1865 *
1866 * @param intent The Intent to broadcast; all receivers matching this
1867 * Intent will receive the broadcast.
1868 * @param receiverPermission (optional) String naming a permissions that
1869 * a receiver must hold in order to receive your broadcast.
1870 * If null, no permission is required.
1871 *
1872 * @see android.content.BroadcastReceiver
1873 * @see #registerReceiver
1874 * @see #sendBroadcast(Intent)
1875 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1876 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001877 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001878 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001879
1880 /**
1881 * Version of {@link #sendBroadcast(Intent)} that allows you to
1882 * receive data back from the broadcast. This is accomplished by
1883 * supplying your own BroadcastReceiver when calling, which will be
1884 * treated as a final receiver at the end of the broadcast -- its
1885 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07001886 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001887 * be serialized in the same way as calling
1888 * {@link #sendOrderedBroadcast(Intent, String)}.
1889 *
1890 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1891 * asynchronous; it will return before
1892 * resultReceiver.onReceive() is called.
1893 *
1894 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1895 *
1896 * @param intent The Intent to broadcast; all receivers matching this
1897 * Intent will receive the broadcast.
1898 * @param receiverPermission String naming a permissions that
1899 * a receiver must hold in order to receive your broadcast.
1900 * If null, no permission is required.
1901 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1902 * receiver of the broadcast.
1903 * @param scheduler A custom Handler with which to schedule the
1904 * resultReceiver callback; if null it will be
1905 * scheduled in the Context's main thread.
1906 * @param initialCode An initial value for the result code. Often
1907 * Activity.RESULT_OK.
1908 * @param initialData An initial value for the result data. Often
1909 * null.
1910 * @param initialExtras An initial value for the result extras. Often
1911 * null.
1912 *
1913 * @see #sendBroadcast(Intent)
1914 * @see #sendBroadcast(Intent, String)
1915 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 * @see android.content.BroadcastReceiver
1917 * @see #registerReceiver
1918 * @see android.app.Activity#RESULT_OK
1919 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001920 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07001921 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07001922 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
1923 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001924
1925 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001926 * Version of {@link #sendBroadcast(Intent)} that allows you to
1927 * receive data back from the broadcast. This is accomplished by
1928 * supplying your own BroadcastReceiver when calling, which will be
1929 * treated as a final receiver at the end of the broadcast -- its
1930 * {@link BroadcastReceiver#onReceive} method will be called with
1931 * the result values collected from the other receivers. The broadcast will
1932 * be serialized in the same way as calling
1933 * {@link #sendOrderedBroadcast(Intent, String)}.
1934 *
1935 * <p>Like {@link #sendBroadcast(Intent)}, this method is
1936 * asynchronous; it will return before
1937 * resultReceiver.onReceive() is called.
1938 *
1939 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1940 *
1941 *
1942 * @param intent The Intent to broadcast; all receivers matching this
1943 * Intent will receive the broadcast.
1944 * @param receiverPermission String naming a permissions that
1945 * a receiver must hold in order to receive your broadcast.
1946 * If null, no permission is required.
1947 * @param options (optional) Additional sending options, generated from a
1948 * {@link android.app.BroadcastOptions}.
1949 * @param resultReceiver Your own BroadcastReceiver to treat as the final
1950 * receiver of the broadcast.
1951 * @param scheduler A custom Handler with which to schedule the
1952 * resultReceiver callback; if null it will be
1953 * scheduled in the Context's main thread.
1954 * @param initialCode An initial value for the result code. Often
1955 * Activity.RESULT_OK.
1956 * @param initialData An initial value for the result data. Often
1957 * null.
1958 * @param initialExtras An initial value for the result extras. Often
1959 * null.
1960 * @see #sendBroadcast(Intent)
1961 * @see #sendBroadcast(Intent, String)
1962 * @see #sendOrderedBroadcast(Intent, String)
1963 * @see android.content.BroadcastReceiver
1964 * @see #registerReceiver
1965 * @see android.app.Activity#RESULT_OK
1966 * @hide
1967 */
1968 @SystemApi
1969 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
1970 @Nullable String receiverPermission, @Nullable Bundle options,
1971 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
1972 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
1973
1974 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001975 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
1976 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001977 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001978 * @hide
1979 */
1980 public abstract void sendOrderedBroadcast(Intent intent,
1981 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
1982 Handler scheduler, int initialCode, String initialData,
1983 Bundle initialExtras);
1984
1985 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001986 * Version of {@link #sendBroadcast(Intent)} 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 Hackborn7d19e022012-08-07 19:12:33 -07001990 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001991 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001992 * @see #sendBroadcast(Intent)
1993 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001994 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
1995 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07001996
1997 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001998 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
1999 * user the broadcast will be sent to. This is not available to applications
2000 * that are not pre-installed on the system image. Using it requires holding
2001 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002002 *
2003 * @param intent The Intent to broadcast; all receivers matching this
2004 * Intent will receive the broadcast.
2005 * @param user UserHandle to send the intent to.
2006 * @param receiverPermission (optional) String naming a permission that
2007 * a receiver must hold in order to receive your broadcast.
2008 * If null, no permission is required.
2009 *
2010 * @see #sendBroadcast(Intent, String)
2011 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002012 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2013 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002014
Svet Ganov16a16892015-04-16 10:32:04 -07002015
2016 /**
2017 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2018 * user the broadcast will be sent to. This is not available to applications
2019 * that are not pre-installed on the system image. Using it requires holding
2020 * the INTERACT_ACROSS_USERS permission.
2021 *
2022 * @param intent The Intent to broadcast; all receivers matching this
2023 * Intent will receive the broadcast.
2024 * @param user UserHandle to send the intent to.
2025 * @param receiverPermission (optional) String naming a permission that
2026 * a receiver must hold in order to receive your broadcast.
2027 * If null, no permission is required.
2028 * @param appOp The app op associated with the broadcast.
2029 *
2030 * @see #sendBroadcast(Intent, String)
2031 *
2032 * @hide
2033 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002034 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2035 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002036
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002037 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002038 * Version of
2039 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2040 * that allows you to specify the
2041 * user the broadcast will be sent to. This is not available to applications
2042 * that are not pre-installed on the system image. Using it requires holding
2043 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002044 *
2045 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2046 *
2047 * @param intent The Intent to broadcast; all receivers matching this
2048 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002049 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002050 * @param receiverPermission String naming a permissions that
2051 * a receiver must hold in order to receive your broadcast.
2052 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002053 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2054 * receiver of the broadcast.
2055 * @param scheduler A custom Handler with which to schedule the
2056 * resultReceiver callback; if null it will be
2057 * scheduled in the Context's main thread.
2058 * @param initialCode An initial value for the result code. Often
2059 * Activity.RESULT_OK.
2060 * @param initialData An initial value for the result data. Often
2061 * null.
2062 * @param initialExtras An initial value for the result extras. Often
2063 * null.
2064 *
2065 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2066 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002067 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2068 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002069 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2070 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002071
2072 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002073 * Similar to above but takes an appOp as well, to enforce restrictions.
2074 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2075 * BroadcastReceiver, Handler, int, String, Bundle)
2076 * @hide
2077 */
2078 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2079 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2080 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2081 @Nullable Bundle initialExtras);
2082
2083 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002084 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2085 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2086 * BroadcastReceiver, Handler, int, String, Bundle)
2087 * @hide
2088 */
2089 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2090 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2091 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2092 @Nullable String initialData, @Nullable Bundle initialExtras);
2093
2094 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002095 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002096 * Intent you are sending stays around after the broadcast is complete,
2097 * so that others can quickly retrieve that data through the return
2098 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2099 * all other ways, this behaves the same as
2100 * {@link #sendBroadcast(Intent)}.
2101 *
2102 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2103 * permission in order to use this API. If you do not hold that
2104 * permission, {@link SecurityException} will be thrown.
2105 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002106 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2107 * can access them), no protection (anyone can modify them), and many other problems.
2108 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2109 * has changed, with another mechanism for apps to retrieve the current value whenever
2110 * desired.
2111 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002112 * @param intent The Intent to broadcast; all receivers matching this
2113 * Intent will receive the broadcast, and the Intent will be held to
2114 * be re-broadcast to future receivers.
2115 *
2116 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002117 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002118 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002119 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002120 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002121
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002122 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002123 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002124 * receive data back from the broadcast. This is accomplished by
2125 * supplying your own BroadcastReceiver when calling, which will be
2126 * treated as a final receiver at the end of the broadcast -- its
2127 * {@link BroadcastReceiver#onReceive} method will be called with
2128 * the result values collected from the other receivers. The broadcast will
2129 * be serialized in the same way as calling
2130 * {@link #sendOrderedBroadcast(Intent, String)}.
2131 *
2132 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2133 * asynchronous; it will return before
2134 * resultReceiver.onReceive() is called. Note that the sticky data
2135 * stored is only the data you initially supply to the broadcast, not
2136 * the result of any changes made by the receivers.
2137 *
2138 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2139 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002140 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2141 * can access them), no protection (anyone can modify them), and many other problems.
2142 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2143 * has changed, with another mechanism for apps to retrieve the current value whenever
2144 * desired.
2145 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002146 * @param intent The Intent to broadcast; all receivers matching this
2147 * Intent will receive the broadcast.
2148 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2149 * receiver of the broadcast.
2150 * @param scheduler A custom Handler with which to schedule the
2151 * resultReceiver callback; if null it will be
2152 * scheduled in the Context's main thread.
2153 * @param initialCode An initial value for the result code. Often
2154 * Activity.RESULT_OK.
2155 * @param initialData An initial value for the result data. Often
2156 * null.
2157 * @param initialExtras An initial value for the result extras. Often
2158 * null.
2159 *
2160 * @see #sendBroadcast(Intent)
2161 * @see #sendBroadcast(Intent, String)
2162 * @see #sendOrderedBroadcast(Intent, String)
2163 * @see #sendStickyBroadcast(Intent)
2164 * @see android.content.BroadcastReceiver
2165 * @see #registerReceiver
2166 * @see android.app.Activity#RESULT_OK
2167 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002168 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002169 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002170 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002171 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2172 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002174 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002175 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 * so that it is as if the sticky broadcast had never happened.
2177 *
2178 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2179 * permission in order to use this API. If you do not hold that
2180 * permission, {@link SecurityException} will be thrown.
2181 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002182 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2183 * can access them), no protection (anyone can modify them), and many other problems.
2184 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2185 * has changed, with another mechanism for apps to retrieve the current value whenever
2186 * desired.
2187 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002188 * @param intent The Intent that was previously broadcast.
2189 *
2190 * @see #sendStickyBroadcast
2191 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002192 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002193 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002194
2195 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002196 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002197 * user the broadcast will be sent to. This is not available to applications
2198 * that are not pre-installed on the system image. Using it requires holding
2199 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002200 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002201 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2202 * can access them), no protection (anyone can modify them), and many other problems.
2203 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2204 * has changed, with another mechanism for apps to retrieve the current value whenever
2205 * desired.
2206 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002207 * @param intent The Intent to broadcast; all receivers matching this
2208 * Intent will receive the broadcast, and the Intent will be held to
2209 * be re-broadcast to future receivers.
2210 * @param user UserHandle to send the intent to.
2211 *
2212 * @see #sendBroadcast(Intent)
2213 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002214 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002215 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2216 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002217
2218 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002219 * @hide
2220 * This is just here for sending CONNECTIVITY_ACTION.
2221 */
2222 @Deprecated
2223 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2224 UserHandle user, Bundle options);
2225
2226 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002227 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002228 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2229 * that allows you to specify the
2230 * user the broadcast will be sent to. This is not available to applications
2231 * that are not pre-installed on the system image. Using it requires holding
2232 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002233 *
2234 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2235 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002236 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2237 * can access them), no protection (anyone can modify them), and many other problems.
2238 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2239 * has changed, with another mechanism for apps to retrieve the current value whenever
2240 * desired.
2241 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002242 * @param intent The Intent to broadcast; all receivers matching this
2243 * Intent will receive the broadcast.
2244 * @param user UserHandle to send the intent to.
2245 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2246 * receiver of the broadcast.
2247 * @param scheduler A custom Handler with which to schedule the
2248 * resultReceiver callback; if null it will be
2249 * scheduled in the Context's main thread.
2250 * @param initialCode An initial value for the result code. Often
2251 * Activity.RESULT_OK.
2252 * @param initialData An initial value for the result data. Often
2253 * null.
2254 * @param initialExtras An initial value for the result extras. Often
2255 * null.
2256 *
2257 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2258 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002259 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002260 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002261 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002262 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2263 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002264
2265 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002266 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002267 * user the broadcast will be sent to. This is not available to applications
2268 * that are not pre-installed on the system image. Using it requires holding
2269 * the INTERACT_ACROSS_USERS permission.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002270 *
2271 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2272 * permission in order to use this API. If you do not hold that
2273 * permission, {@link SecurityException} will be thrown.
2274 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002275 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2276 * can access them), no protection (anyone can modify them), and many other problems.
2277 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2278 * has changed, with another mechanism for apps to retrieve the current value whenever
2279 * desired.
2280 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002281 * @param intent The Intent that was previously broadcast.
2282 * @param user UserHandle to remove the sticky broadcast from.
2283 *
2284 * @see #sendStickyBroadcastAsUser
2285 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002286 @Deprecated
Tor Norbye788fc2b2015-07-05 16:10:42 -07002287 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2288 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002289
2290 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002291 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 * <var>receiver</var> will be called with any broadcast Intent that
2293 * matches <var>filter</var>, in the main application thread.
2294 *
2295 * <p>The system may broadcast Intents that are "sticky" -- these stay
2296 * around after the broadcast as finished, to be sent to any later
2297 * registrations. If your IntentFilter matches one of these sticky
2298 * Intents, that Intent will be returned by this function
2299 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2300 * been broadcast.
2301 *
2302 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2303 * in which case each of these will be sent to <var>receiver</var>. In
2304 * this case, only one of these can be returned directly by the function;
2305 * which of these that is returned is arbitrarily decided by the system.
2306 *
2307 * <p>If you know the Intent your are registering for is sticky, you can
2308 * supply null for your <var>receiver</var>. In this case, no receiver is
2309 * registered -- the function simply returns the sticky Intent that
2310 * matches <var>filter</var>. In the case of multiple matches, the same
2311 * rules as described above apply.
2312 *
2313 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2314 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002315 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2316 * registered with this method will correctly respect the
2317 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2318 * Prior to that, it would be ignored and delivered to all matching registered
2319 * receivers. Be careful if using this for security.</p>
2320 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002321 * <p class="note">Note: this method <em>cannot be called from a
2322 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2323 * that is declared in an application's manifest. It is okay, however, to call
2324 * this method from another BroadcastReceiver that has itself been registered
2325 * at run time with {@link #registerReceiver}, since the lifetime of such a
2326 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002327 *
2328 * @param receiver The BroadcastReceiver to handle the broadcast.
2329 * @param filter Selects the Intent broadcasts to be received.
2330 *
2331 * @return The first sticky intent found that matches <var>filter</var>,
2332 * or null if there are none.
2333 *
2334 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2335 * @see #sendBroadcast
2336 * @see #unregisterReceiver
2337 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002338 @Nullable
2339 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002340 IntentFilter filter);
2341
2342 /**
2343 * Register to receive intent broadcasts, to run in the context of
2344 * <var>scheduler</var>. See
2345 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2346 * information. This allows you to enforce permissions on who can
2347 * broadcast intents to your receiver, or have the receiver run in
2348 * a different thread than the main application thread.
2349 *
2350 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2351 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002352 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2353 * registered with this method will correctly respect the
2354 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2355 * Prior to that, it would be ignored and delivered to all matching registered
2356 * receivers. Be careful if using this for security.</p>
2357 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358 * @param receiver The BroadcastReceiver to handle the broadcast.
2359 * @param filter Selects the Intent broadcasts to be received.
2360 * @param broadcastPermission String naming a permissions that a
2361 * broadcaster must hold in order to send an Intent to you. If null,
2362 * no permission is required.
2363 * @param scheduler Handler identifying the thread that will receive
2364 * the Intent. If null, the main thread of the process will be used.
2365 *
2366 * @return The first sticky intent found that matches <var>filter</var>,
2367 * or null if there are none.
2368 *
2369 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2370 * @see #sendBroadcast
2371 * @see #unregisterReceiver
2372 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002373 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002374 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002375 IntentFilter filter, @Nullable String broadcastPermission,
2376 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002377
2378 /**
2379 * @hide
2380 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2381 * but for a specific user. This receiver will receiver broadcasts that
2382 * are sent to the requested user. It
2383 * requires holding the {@link android.Manifest.permission#INTERACT_ACROSS_USERS_FULL}
2384 * permission.
2385 *
2386 * @param receiver The BroadcastReceiver to handle the broadcast.
2387 * @param user UserHandle to send the intent to.
2388 * @param filter Selects the Intent broadcasts to be received.
2389 * @param broadcastPermission String naming a permissions that a
2390 * broadcaster must hold in order to send an Intent to you. If null,
2391 * no permission is required.
2392 * @param scheduler Handler identifying the thread that will receive
2393 * the Intent. If null, the main thread of the process will be used.
2394 *
2395 * @return The first sticky intent found that matches <var>filter</var>,
2396 * or null if there are none.
2397 *
Jeff Brown6e539312015-02-24 18:53:21 -08002398 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002399 * @see #sendBroadcast
2400 * @see #unregisterReceiver
2401 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002402 @Nullable
Dianne Hackborn20e80982012-08-31 19:00:44 -07002403 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002404 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2405 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406
2407 /**
2408 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2409 * filters that have been registered for this BroadcastReceiver will be
2410 * removed.
2411 *
2412 * @param receiver The BroadcastReceiver to unregister.
2413 *
2414 * @see #registerReceiver
2415 */
2416 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2417
2418 /**
2419 * Request that a given application service be started. The Intent
Dianne Hackborn221ea892013-08-04 16:50:16 -07002420 * should contain either contain the complete class name of a specific service
2421 * implementation to start or a specific package name to target. If the
Dianne Hackborn6bc37892013-10-03 11:05:14 -07002422 * Intent is less specified, it log a warning about this and which of the
2423 * multiple matching services it finds and uses will be undefined. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002424 * is not already running, it will be instantiated and started (creating a
2425 * process for it if needed); if it is running then it remains running.
2426 *
2427 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002428 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002429 * with the <var>intent</var> given here. This provides a convenient way
2430 * to submit jobs to a service without having to bind and call on to its
2431 * interface.
2432 *
2433 * <p>Using startService() overrides the default service lifetime that is
2434 * managed by {@link #bindService}: it requires the service to remain
2435 * running until {@link #stopService} is called, regardless of whether
2436 * any clients are connected to it. Note that calls to startService()
2437 * are not nesting: no matter how many times you call startService(),
2438 * a single call to {@link #stopService} will stop it.
2439 *
2440 * <p>The system attempts to keep running services around as much as
2441 * possible. The only time they should be stopped is if the current
2442 * foreground application is using so many resources that the service needs
2443 * to be killed. If any errors happen in the service's process, it will
2444 * automatically be restarted.
2445 *
2446 * <p>This function will throw {@link SecurityException} if you do not
2447 * have permission to start the given service.
2448 *
Chris Craik1e353522016-04-18 10:20:50 -07002449 * <p class="note"><strong>Note:</strong> Each call to startService()
2450 * results in significant work done by the system to manage service
2451 * lifecycle surrounding the processing of the intent, which can take
2452 * multiple milliseconds of CPU time. Due to this cost, startService()
2453 * should not be used for frequent intent delivery to a service, and only
2454 * for scheduling significant work. Use {@link #bindService bound services}
2455 * for high frequency calls.
2456 * </p>
2457 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002458 * @param service Identifies the service to be started. The Intent must be either
2459 * fully explicit (supplying a component name) or specify a specific package
2460 * name it is targetted to. Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002461 * may be included in the Intent extras to supply arguments along with
2462 * this specific start call.
2463 *
2464 * @return If the service is being started or is already running, the
2465 * {@link ComponentName} of the actual service that was started is
2466 * returned; else if the service does not exist null is returned.
2467 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002468 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 *
2470 * @see #stopService
2471 * @see #bindService
2472 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002473 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002474 public abstract ComponentName startService(Intent service);
2475
2476 /**
2477 * Request that a given application service be stopped. If the service is
2478 * not running, nothing happens. Otherwise it is stopped. Note that calls
2479 * to startService() are not counted -- this stops the service no matter
2480 * how many times it was started.
2481 *
2482 * <p>Note that if a stopped service still has {@link ServiceConnection}
2483 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2484 * not be destroyed until all of these bindings are removed. See
2485 * the {@link android.app.Service} documentation for more details on a
2486 * service's lifecycle.
2487 *
2488 * <p>This function will throw {@link SecurityException} if you do not
2489 * have permission to stop the given service.
2490 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002491 * @param service Description of the service to be stopped. The Intent must be either
2492 * fully explicit (supplying a component name) or specify a specific package
2493 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 *
2495 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002496 * 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 -08002497 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002498 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002499 *
2500 * @see #startService
2501 */
2502 public abstract boolean stopService(Intent service);
2503
2504 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002505 * @hide like {@link #startService(Intent)} but for a specific user.
2506 */
2507 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2508
2509 /**
2510 * @hide like {@link #stopService(Intent)} but for a specific user.
2511 */
2512 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002513
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002514 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 * Connect to an application service, creating it if needed. This defines
2516 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002517 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 * told if it dies and restarts. The service will be considered required
2519 * by the system only for as long as the calling context exists. For
2520 * example, if this Context is an Activity that is stopped, the service will
2521 * not be required to continue running until the Activity is resumed.
2522 *
2523 * <p>This function will throw {@link SecurityException} if you do not
2524 * have permission to bind to the given service.
2525 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002526 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002528 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 * {@link #startService} with the arguments containing the command to be
2530 * sent, with the service calling its
2531 * {@link android.app.Service#stopSelf(int)} method when done executing
2532 * that command. See the API demo App/Service/Service Start Arguments
2533 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002534 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002535 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2536 * is tied to another object (the one that registered it).</p>
2537 *
2538 * @param service Identifies the service to connect to. The Intent may
2539 * specify either an explicit component name, or a logical
2540 * description (action, category, etc) to match an
2541 * {@link IntentFilter} published by a service.
2542 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002543 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002544 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002545 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2546 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2547 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2548 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002549 * @return If you have successfully bound to the service, {@code true} is returned;
2550 * {@code false} is returned if the connection is not made so you will not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002551 * receive the service object.
2552 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002553 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 *
2555 * @see #unbindService
2556 * @see #startService
2557 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002558 * @see #BIND_DEBUG_UNBIND
2559 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002560 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002561 public abstract boolean bindService(@RequiresPermission Intent service,
2562 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002563
2564 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002565 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002566 * argument for use by system server and other multi-user aware code.
2567 * @hide
2568 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002569 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002570 @SuppressWarnings("unused")
Tor Norbye788fc2b2015-07-05 16:10:42 -07002571 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002572 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002573 throw new RuntimeException("Not implemented. Must override in a subclass.");
2574 }
2575
2576 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002577 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2578 * explicit non-null Handler to run the ServiceConnection callbacks on.
2579 *
2580 * @hide
2581 */
2582 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2583 Handler handler, UserHandle user) {
2584 throw new RuntimeException("Not implemented. Must override in a subclass.");
2585 }
2586
2587 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002588 * Disconnect from an application service. You will no longer receive
2589 * calls as the service is restarted, and the service is now allowed to
2590 * stop at any time.
2591 *
2592 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002593 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002594 *
2595 * @see #bindService
2596 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002597 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598
2599 /**
2600 * Start executing an {@link android.app.Instrumentation} class. The given
2601 * Instrumentation component will be run by killing its target application
2602 * (if currently running), starting the target process, instantiating the
2603 * instrumentation component, and then letting it drive the application.
2604 *
2605 * <p>This function is not synchronous -- it returns as soon as the
2606 * instrumentation has started and while it is running.
2607 *
2608 * <p>Instrumentation is normally only allowed to run against a package
2609 * that is either unsigned or signed with a signature that the
2610 * the instrumentation package is also signed with (ensuring the target
2611 * trusts the instrumentation).
2612 *
2613 * @param className Name of the Instrumentation component to be run.
2614 * @param profileFile Optional path to write profiling data as the
2615 * instrumentation runs, or null for no profiling.
2616 * @param arguments Additional optional arguments to pass to the
2617 * instrumentation, or null.
2618 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002619 * @return {@code true} if the instrumentation was successfully started,
2620 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002622 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2623 @Nullable String profileFile, @Nullable Bundle arguments);
2624
2625 /** @hide */
2626 @StringDef({
2627 POWER_SERVICE,
2628 WINDOW_SERVICE,
2629 LAYOUT_INFLATER_SERVICE,
2630 ACCOUNT_SERVICE,
2631 ACTIVITY_SERVICE,
2632 ALARM_SERVICE,
2633 NOTIFICATION_SERVICE,
2634 ACCESSIBILITY_SERVICE,
2635 CAPTIONING_SERVICE,
2636 KEYGUARD_SERVICE,
2637 LOCATION_SERVICE,
2638 //@hide: COUNTRY_DETECTOR,
2639 SEARCH_SERVICE,
2640 SENSOR_SERVICE,
2641 STORAGE_SERVICE,
2642 WALLPAPER_SERVICE,
2643 VIBRATOR_SERVICE,
2644 //@hide: STATUS_BAR_SERVICE,
2645 CONNECTIVITY_SERVICE,
2646 //@hide: UPDATE_LOCK_SERVICE,
2647 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002648 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002649 //@hide: NETWORK_POLICY_SERVICE,
2650 WIFI_SERVICE,
Etan Cohen20d329b2015-09-29 13:49:02 -07002651 WIFI_NAN_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002652 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002653 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002654 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002655 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002656 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002657 NSD_SERVICE,
2658 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002659 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002660 MEDIA_ROUTER_SERVICE,
2661 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002662 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002663 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002664 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002665 CLIPBOARD_SERVICE,
2666 INPUT_METHOD_SERVICE,
2667 TEXT_SERVICES_MANAGER_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002668 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002669 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002670 //@hide: BACKUP_SERVICE,
2671 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07002672 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07002673 DEVICE_POLICY_SERVICE,
2674 UI_MODE_SERVICE,
2675 DOWNLOAD_SERVICE,
2676 NFC_SERVICE,
2677 BLUETOOTH_SERVICE,
2678 //@hide: SIP_SERVICE,
2679 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002680 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002681 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002682 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002683 INPUT_SERVICE,
2684 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002685 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002686 RESTRICTIONS_SERVICE,
2687 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002688 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002689 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002690 CONSUMER_IR_SERVICE,
2691 //@hide: TRUST_SERVICE,
2692 TV_INPUT_SERVICE,
2693 //@hide: NETWORK_SCORE_SERVICE,
2694 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002695 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002696 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002697 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002698 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002699 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002700 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002701 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002702 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08002703 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08002704 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08002705 //@hide: CONTEXTHUB_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002706 })
2707 @Retention(RetentionPolicy.SOURCE)
2708 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709
2710 /**
2711 * Return the handle to a system-level service by name. The class of the
2712 * returned object varies by the requested name. Currently available names
2713 * are:
Scott Main4b5da682010-10-21 11:49:12 -07002714 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 * <dl>
2716 * <dt> {@link #WINDOW_SERVICE} ("window")
2717 * <dd> The top-level window manager in which you can place custom
2718 * windows. The returned object is a {@link android.view.WindowManager}.
2719 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
2720 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
2721 * in this context.
2722 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
2723 * <dd> A {@link android.app.ActivityManager} for interacting with the
2724 * global activity state of the system.
2725 * <dt> {@link #POWER_SERVICE} ("power")
2726 * <dd> A {@link android.os.PowerManager} for controlling power
2727 * management.
2728 * <dt> {@link #ALARM_SERVICE} ("alarm")
2729 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
2730 * time of your choosing.
2731 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
2732 * <dd> A {@link android.app.NotificationManager} for informing the user
2733 * of background events.
2734 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
2735 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
2736 * <dt> {@link #LOCATION_SERVICE} ("location")
2737 * <dd> A {@link android.location.LocationManager} for controlling location
2738 * (e.g., GPS) updates.
2739 * <dt> {@link #SEARCH_SERVICE} ("search")
2740 * <dd> A {@link android.app.SearchManager} for handling search.
2741 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
2742 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
2743 * hardware.
2744 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
2745 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
2746 * handling management of network connections.
2747 * <dt> {@link #WIFI_SERVICE} ("wifi")
2748 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of
2749 * Wi-Fi connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002750 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
2751 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
2752 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002753 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
2754 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
2755 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08002756 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
2757 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07002758 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07002759 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08002760 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07002761 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07002762 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
2763 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002764 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
2765 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
2766 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01002767 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002768 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002769 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07002770 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 * <p>Note: System services obtained via this API may be closely associated with
2772 * the Context in which they are obtained from. In general, do not share the
2773 * service objects between various different contexts (Activities, Applications,
2774 * Services, Providers, etc.)
2775 *
2776 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07002777 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002778 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07002779 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 * @see #WINDOW_SERVICE
2781 * @see android.view.WindowManager
2782 * @see #LAYOUT_INFLATER_SERVICE
2783 * @see android.view.LayoutInflater
2784 * @see #ACTIVITY_SERVICE
2785 * @see android.app.ActivityManager
2786 * @see #POWER_SERVICE
2787 * @see android.os.PowerManager
2788 * @see #ALARM_SERVICE
2789 * @see android.app.AlarmManager
2790 * @see #NOTIFICATION_SERVICE
2791 * @see android.app.NotificationManager
2792 * @see #KEYGUARD_SERVICE
2793 * @see android.app.KeyguardManager
2794 * @see #LOCATION_SERVICE
2795 * @see android.location.LocationManager
2796 * @see #SEARCH_SERVICE
2797 * @see android.app.SearchManager
2798 * @see #SENSOR_SERVICE
2799 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08002800 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08002801 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 * @see #VIBRATOR_SERVICE
2803 * @see android.os.Vibrator
2804 * @see #CONNECTIVITY_SERVICE
2805 * @see android.net.ConnectivityManager
2806 * @see #WIFI_SERVICE
2807 * @see android.net.wifi.WifiManager
2808 * @see #AUDIO_SERVICE
2809 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07002810 * @see #MEDIA_ROUTER_SERVICE
2811 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002812 * @see #TELEPHONY_SERVICE
2813 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08002814 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
2815 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002816 * @see #CARRIER_CONFIG_SERVICE
2817 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 * @see #INPUT_METHOD_SERVICE
2819 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08002820 * @see #UI_MODE_SERVICE
2821 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07002822 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07002823 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08002824 * @see #BATTERY_SERVICE
2825 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07002826 * @see #JOB_SCHEDULER_SERVICE
2827 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002828 * @see #NETWORK_STATS_SERVICE
2829 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002830 * @see android.os.HardwarePropertiesManager
2831 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002832 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002833 public abstract Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834
2835 /**
Jeff Brown6e539312015-02-24 18:53:21 -08002836 * Return the handle to a system-level service by class.
2837 * <p>
2838 * Currently available classes are:
2839 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
2840 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
2841 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
2842 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
2843 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
2844 * {@link android.net.ConnectivityManager},
2845 * {@link android.net.wifi.WifiManager},
2846 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
2847 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
2848 * {@link android.view.inputmethod.InputMethodManager},
2849 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002850 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
2851 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08002852 * </p><p>
2853 * Note: System services obtained via this API may be closely associated with
2854 * the Context in which they are obtained from. In general, do not share the
2855 * service objects between various different contexts (Activities, Applications,
2856 * Services, Providers, etc.)
2857 * </p>
2858 *
2859 * @param serviceClass The class of the desired service.
2860 * @return The service or null if the class is not a supported system service.
2861 */
2862 @SuppressWarnings("unchecked")
2863 public final <T> T getSystemService(Class<T> serviceClass) {
2864 // Because subclasses may override getSystemService(String) we cannot
2865 // perform a lookup by class alone. We must first map the class to its
2866 // service name then invoke the string-based method.
2867 String serviceName = getSystemServiceName(serviceClass);
2868 return serviceName != null ? (T)getSystemService(serviceName) : null;
2869 }
2870
2871 /**
2872 * Gets the name of the system-level service that is represented by the specified class.
2873 *
2874 * @param serviceClass The class of the desired service.
2875 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08002876 */
2877 public abstract String getSystemServiceName(Class<?> serviceClass);
2878
2879 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002880 * Use with {@link #getSystemService} to retrieve a
2881 * {@link android.os.PowerManager} for controlling power management,
2882 * including "wake locks," which let you keep the device on while
2883 * you're running long tasks.
2884 */
2885 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07002886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 /**
2888 * Use with {@link #getSystemService} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08002889 * {@link android.os.RecoverySystem} for accessing the recovery system
2890 * service.
2891 *
2892 * @see #getSystemService
2893 * @hide
2894 */
2895 public static final String RECOVERY_SERVICE = "recovery";
2896
2897 /**
2898 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002899 * {@link android.view.WindowManager} for accessing the system's window
2900 * manager.
2901 *
2902 * @see #getSystemService
2903 * @see android.view.WindowManager
2904 */
2905 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07002906
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 /**
2908 * Use with {@link #getSystemService} to retrieve a
2909 * {@link android.view.LayoutInflater} for inflating layout resources in this
2910 * context.
2911 *
2912 * @see #getSystemService
2913 * @see android.view.LayoutInflater
2914 */
2915 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07002916
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 /**
2918 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07002919 * {@link android.accounts.AccountManager} for receiving intents at a
2920 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07002921 *
2922 * @see #getSystemService
2923 * @see android.accounts.AccountManager
2924 */
2925 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07002926
Fred Quintana60307342009-03-24 22:48:12 -07002927 /**
2928 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 * {@link android.app.ActivityManager} for interacting with the global
2930 * system state.
2931 *
2932 * @see #getSystemService
2933 * @see android.app.ActivityManager
2934 */
2935 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07002936
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 /**
2938 * Use with {@link #getSystemService} to retrieve a
2939 * {@link android.app.AlarmManager} for receiving intents at a
2940 * time of your choosing.
2941 *
2942 * @see #getSystemService
2943 * @see android.app.AlarmManager
2944 */
2945 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07002946
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 /**
2948 * Use with {@link #getSystemService} to retrieve a
2949 * {@link android.app.NotificationManager} for informing the user of
2950 * background events.
2951 *
2952 * @see #getSystemService
2953 * @see android.app.NotificationManager
2954 */
2955 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07002956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 /**
2958 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07002959 * {@link android.view.accessibility.AccessibilityManager} for giving the user
2960 * feedback for UI events through the registered event listeners.
2961 *
2962 * @see #getSystemService
2963 * @see android.view.accessibility.AccessibilityManager
2964 */
2965 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07002966
svetoslavganov75986cf2009-05-14 22:28:01 -07002967 /**
2968 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07002969 * {@link android.view.accessibility.CaptioningManager} for obtaining
2970 * captioning properties and listening for changes in captioning
2971 * preferences.
2972 *
2973 * @see #getSystemService
2974 * @see android.view.accessibility.CaptioningManager
2975 */
2976 public static final String CAPTIONING_SERVICE = "captioning";
2977
2978 /**
2979 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 * {@link android.app.NotificationManager} for controlling keyguard.
2981 *
2982 * @see #getSystemService
2983 * @see android.app.KeyguardManager
2984 */
2985 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07002986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002987 /**
2988 * Use with {@link #getSystemService} to retrieve a {@link
2989 * android.location.LocationManager} for controlling location
2990 * updates.
2991 *
2992 * @see #getSystemService
2993 * @see android.location.LocationManager
2994 */
2995 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08002996
2997 /**
2998 * Use with {@link #getSystemService} to retrieve a
2999 * {@link android.location.CountryDetector} for detecting the country that
3000 * the user is in.
3001 *
3002 * @hide
3003 */
3004 public static final String COUNTRY_DETECTOR = "country_detector";
3005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 /**
3007 * Use with {@link #getSystemService} to retrieve a {@link
3008 * android.app.SearchManager} for handling searches.
3009 *
3010 * @see #getSystemService
3011 * @see android.app.SearchManager
3012 */
3013 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003014
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015 /**
3016 * Use with {@link #getSystemService} to retrieve a {@link
3017 * android.hardware.SensorManager} for accessing sensors.
3018 *
3019 * @see #getSystemService
3020 * @see android.hardware.SensorManager
3021 */
3022 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 /**
San Mehatc9d81752010-02-01 10:23:27 -08003025 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003026 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003027 * functions.
3028 *
3029 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08003030 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003031 */
3032 public static final String STORAGE_SERVICE = "storage";
3033
3034 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003035 * Use with {@link #getSystemService} to retrieve a
3036 * com.android.server.WallpaperService for accessing wallpapers.
3037 *
3038 * @see #getSystemService
3039 */
3040 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 /**
3043 * Use with {@link #getSystemService} to retrieve a {@link
3044 * android.os.Vibrator} for interacting with the vibration hardware.
3045 *
3046 * @see #getSystemService
3047 * @see android.os.Vibrator
3048 */
3049 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003051 /**
3052 * Use with {@link #getSystemService} to retrieve a {@link
3053 * android.app.StatusBarManager} for interacting with the status bar.
3054 *
3055 * @see #getSystemService
3056 * @see android.app.StatusBarManager
3057 * @hide
3058 */
3059 public static final String STATUS_BAR_SERVICE = "statusbar";
3060
3061 /**
3062 * Use with {@link #getSystemService} to retrieve a {@link
3063 * android.net.ConnectivityManager} for handling management of
3064 * network connections.
3065 *
3066 * @see #getSystemService
3067 * @see android.net.ConnectivityManager
3068 */
3069 public static final String CONNECTIVITY_SERVICE = "connectivity";
3070
3071 /**
3072 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003073 * android.os.IUpdateLock} for managing runtime sequences that
3074 * must not be interrupted by headless OTA application or similar.
3075 *
3076 * @hide
3077 * @see #getSystemService
3078 * @see android.os.UpdateLock
3079 */
3080 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3081
3082 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003083 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003084 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003085 */
3086 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3087
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003088 /**
3089 * Use with {@link #getSystemService} to retrieve a {@link
3090 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3091 *
3092 * @see #getSystemService
3093 * @see android.app.usage.NetworkStatsManager
3094 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003095 public static final String NETWORK_STATS_SERVICE = "netstats";
3096 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003097 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
3098
San Mehatd1df8ac2010-01-26 06:17:26 -08003099 /**
3100 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 * android.net.wifi.WifiManager} for handling management of
3102 * Wi-Fi access.
3103 *
3104 * @see #getSystemService
3105 * @see android.net.wifi.WifiManager
3106 */
3107 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003109 /**
repo sync55bc5f32011-06-24 14:23:07 -07003110 * Use with {@link #getSystemService} to retrieve a {@link
3111 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003112 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003113 *
3114 * @see #getSystemService
3115 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003116 */
3117 public static final String WIFI_P2P_SERVICE = "wifip2p";
3118
3119 /**
Etan Cohen20d329b2015-09-29 13:49:02 -07003120 * Use with {@link #getSystemService} to retrieve a
3121 * {@link android.net.wifi.nan.WifiNanManager} for handling management of
3122 * Wi-Fi NAN discovery and connections.
3123 *
3124 * @see #getSystemService
3125 * @see android.net.wifi.nan.WifiNanManager
3126 * @hide PROPOSED_NAN_API
3127 */
3128 public static final String WIFI_NAN_SERVICE = "wifinan";
3129
3130 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003131 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003132 * android.net.wifi.WifiScanner} for scanning the wifi universe
3133 *
3134 * @see #getSystemService
3135 * @see android.net.wifi.WifiScanner
3136 * @hide
3137 */
Wei Wang35d552f2014-07-08 21:37:01 -07003138 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003139 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3140
3141 /**
3142 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003143 * android.net.wifi.RttManager} for ranging devices with wifi
3144 *
3145 * @see #getSystemService
3146 * @see android.net.wifi.RttManager
3147 * @hide
3148 */
3149 @SystemApi
3150 public static final String WIFI_RTT_SERVICE = "rttmanager";
3151
3152 /**
3153 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003154 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003155 * Ethernet access.
3156 *
3157 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003158 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003159 *
3160 * @hide
3161 */
3162 public static final String ETHERNET_SERVICE = "ethernet";
3163
3164 /**
3165 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003166 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003167 * discovery
3168 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003169 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003170 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003171 */
3172 public static final String NSD_SERVICE = "servicediscovery";
3173
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003174 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003175 * Use with {@link #getSystemService} to retrieve a
3176 * {@link android.media.AudioManager} for handling management of volume,
3177 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003178 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 * @see #getSystemService
3180 * @see android.media.AudioManager
3181 */
3182 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 /**
3185 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003186 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003187 * of fingerprints.
3188 *
3189 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07003190 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003191 */
3192 public static final String FINGERPRINT_SERVICE = "fingerprint";
3193
3194 /**
3195 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003196 * {@link android.media.MediaRouter} for controlling and managing
3197 * routing of media.
3198 *
3199 * @see #getSystemService
3200 * @see android.media.MediaRouter
3201 */
3202 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3203
3204 /**
3205 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003206 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003207 *
3208 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07003209 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003210 */
3211 public static final String MEDIA_SESSION_SERVICE = "media_session";
3212
3213 /**
3214 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003215 * {@link android.telephony.TelephonyManager} for handling management the
3216 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003217 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 * @see #getSystemService
3219 * @see android.telephony.TelephonyManager
3220 */
3221 public static final String TELEPHONY_SERVICE = "phone";
3222
3223 /**
3224 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003225 * {@link android.telephony.SubscriptionManager} for handling management the
3226 * telephony subscriptions of the device.
3227 *
3228 * @see #getSystemService
3229 * @see android.telephony.SubscriptionManager
3230 */
3231 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3232
3233 /**
3234 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003235 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003236 * of the device.
3237 *
3238 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003239 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003240 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003241 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003242
3243 /**
3244 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003245 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3246 *
3247 * @see #getSystemService
3248 * @see android.telephony.CarrierConfigManager
3249 */
3250 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3251
3252 /**
3253 * Use with {@link #getSystemService} to retrieve a
3254 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08003255 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003256 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003257 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003258 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003259 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003260 */
3261 public static final String CLIPBOARD_SERVICE = "clipboard";
3262
3263 /**
Scott Main4b5da682010-10-21 11:49:12 -07003264 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003265 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3266 * methods.
3267 *
3268 * @see #getSystemService
3269 */
3270 public static final String INPUT_METHOD_SERVICE = "input_method";
3271
3272 /**
3273 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09003274 * {@link android.view.textservice.TextServicesManager} for accessing
3275 * text services.
3276 *
3277 * @see #getSystemService
3278 */
3279 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3280
3281 /**
3282 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003283 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 * @see #getSystemService
3286 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003287 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003290 * Official published name of the (internal) voice interaction manager service.
3291 *
3292 * @hide
3293 * @see #getSystemService
3294 */
3295 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3296
3297 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003298 * Use with {@link #getSystemService} to access the
3299 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3300 *
3301 * @hide
3302 * @see #getSystemService
3303 */
3304 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3305
3306
3307 /**
Christopher Tate487529a2009-04-29 14:03:25 -07003308 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003309 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003310 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003311 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003312 *
Christopher Tate487529a2009-04-29 14:03:25 -07003313 * @see #getSystemService
3314 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003315 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003316 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003317
3318 /**
3319 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003320 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003321 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07003322 * @see #getSystemService
3323 */
3324 public static final String DROPBOX_SERVICE = "dropbox";
3325
Christopher Tate487529a2009-04-29 14:03:25 -07003326 /**
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003327 * System service name for the DeviceIdleController. There is no Java API for this.
3328 * @see #getSystemService
3329 * @hide
3330 */
3331 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3332
3333 /**
Scott Main4b5da682010-10-21 11:49:12 -07003334 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003335 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003336 * device policy management.
3337 *
3338 * @see #getSystemService
3339 */
3340 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3341
3342 /**
Tobias Haamel53332882010-02-18 16:15:43 -08003343 * Use with {@link #getSystemService} to retrieve a
3344 * {@link android.app.UiModeManager} for controlling UI modes.
3345 *
3346 * @see #getSystemService
3347 */
3348 public static final String UI_MODE_SERVICE = "uimode";
3349
3350 /**
Steve Howarda2709362010-07-02 17:12:48 -07003351 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003352 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003353 *
3354 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07003355 */
3356 public static final String DOWNLOAD_SERVICE = "download";
3357
3358 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08003359 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003360 * {@link android.os.BatteryManager} for managing battery state.
3361 *
3362 * @see #getSystemService
3363 */
3364 public static final String BATTERY_SERVICE = "batterymanager";
3365
3366 /**
3367 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003368 * {@link android.nfc.NfcManager} for using NFC.
3369 *
3370 * @see #getSystemService
3371 */
3372 public static final String NFC_SERVICE = "nfc";
3373
3374 /**
3375 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003376 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003377 *
3378 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003379 */
3380 public static final String BLUETOOTH_SERVICE = "bluetooth";
3381
3382 /**
3383 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003384 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3385 *
3386 * @see #getSystemService
3387 */
3388 /** @hide */
3389 public static final String SIP_SERVICE = "sip";
3390
3391 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003392 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003393 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003394 * and for controlling this device's behavior as a USB device.
3395 *
3396 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04003397 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003398 */
3399 public static final String USB_SERVICE = "usb";
3400
3401 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003402 * Use with {@link #getSystemService} to retrieve a {@link
3403 * android.hardware.SerialManager} for access to serial ports.
3404 *
3405 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003406 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003407 *
3408 * @hide
3409 */
3410 public static final String SERIAL_SERVICE = "serial";
3411
3412 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003413 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003414 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3415 * HDMI-CEC protocol.
3416 *
3417 * @see #getSystemService
3418 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003419 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003420 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003421 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003422 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003423
3424 /**
3425 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003426 * {@link android.hardware.input.InputManager} for interacting with input devices.
3427 *
3428 * @see #getSystemService
3429 * @see android.hardware.input.InputManager
3430 */
3431 public static final String INPUT_SERVICE = "input";
3432
3433 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07003434 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003435 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3436 *
3437 * @see #getSystemService
3438 * @see android.hardware.display.DisplayManager
3439 */
3440 public static final String DISPLAY_SERVICE = "display";
3441
3442 /**
3443 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003444 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3445 *
3446 * @see #getSystemService
3447 * @see android.os.UserManager
3448 */
3449 public static final String USER_SERVICE = "user";
3450
3451 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003452 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003453 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3454 * profiles of a user.
3455 *
3456 * @see #getSystemService
3457 * @see android.content.pm.LauncherApps
3458 */
3459 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3460
3461 /**
3462 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003463 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3464 * and requesting permissions for restricted operations.
3465 * @see #getSystemService
3466 * @see android.content.RestrictionsManager
3467 */
3468 public static final String RESTRICTIONS_SERVICE = "restrictions";
3469
3470 /**
3471 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003472 * {@link android.app.AppOpsManager} for tracking application operations
3473 * on the device.
3474 *
3475 * @see #getSystemService
3476 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003477 */
3478 public static final String APP_OPS_SERVICE = "appops";
3479
3480 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003481 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003482 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003483 * camera devices.
3484 *
3485 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003486 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003487 */
3488 public static final String CAMERA_SERVICE = "camera";
3489
3490 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003491 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003492 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003493 *
3494 * @see #getSystemService
3495 * @see android.print.PrintManager
3496 */
3497 public static final String PRINT_SERVICE = "print";
3498
3499 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003500 * Use with {@link #getSystemService} to retrieve a
3501 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3502 * signals from the device.
3503 *
3504 * @see #getSystemService
3505 * @see android.hardware.ConsumerIrManager
3506 */
3507 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3508
3509 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003510 * {@link android.app.trust.TrustManager} for managing trust agents.
3511 * @see #getSystemService
3512 * @see android.app.trust.TrustManager
3513 * @hide
3514 */
3515 public static final String TRUST_SERVICE = "trust";
3516
3517 /**
Jae Seo39570912014-02-20 18:23:25 -08003518 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003519 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3520 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003521 *
3522 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003523 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003524 */
3525 public static final String TV_INPUT_SERVICE = "tv_input";
3526
3527 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003528 * {@link android.net.NetworkScoreManager} for managing network scoring.
3529 * @see #getSystemService
3530 * @see android.net.NetworkScoreManager
3531 * @hide
3532 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003533 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003534 public static final String NETWORK_SCORE_SERVICE = "network_score";
3535
3536 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003537 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003538 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003539 *
3540 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003541 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003542 */
3543 public static final String USAGE_STATS_SERVICE = "usagestats";
3544
3545 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003546 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003547 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003548 * background tasks.
3549 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003550 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003551 */
Christopher Tate7060b042014-06-09 19:50:00 -07003552 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003553
3554 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003555 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003556 * android.service.persistentdata.PersistentDataBlockManager} instance
3557 * for interacting with a storage device that lives across factory resets.
3558 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003559 * @see #getSystemService
3560 * @see android.service.persistentdata.PersistentDataBlockManager
3561 * @hide
3562 */
Andres Morales33df9372014-09-26 17:08:59 -07003563 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003564 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3565
3566 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003567 * Use with {@link #getSystemService} to retrieve a {@link
3568 * android.media.projection.MediaProjectionManager} instance for managing
3569 * media projection sessions.
3570 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003571 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003572 */
3573 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3574
3575 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003576 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003577 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003578 *
3579 * @see #getSystemService
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003580 */
3581 public static final String MIDI_SERVICE = "midi";
3582
Eric Laurent2035ac82015-03-05 15:18:44 -08003583
3584 /**
3585 * Use with {@link #getSystemService} to retrieve a
3586 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3587 *
3588 * @see #getSystemService
3589 * @hide
3590 */
3591 public static final String RADIO_SERVICE = "radio";
3592
Paul McLeana33be212015-02-20 07:52:45 -08003593 /**
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003594 * Use with {@link #getSystemService} to retrieve a
3595 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
3596 *
3597 * @see #getSystemService
3598 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01003599 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003600
3601 /**
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003602 * TODO Javadoc
3603 *
3604 * @see #getSystemService
3605 * @see android.content.pm.ShortcutManager
3606 */
3607 public static final String SHORTCUT_SERVICE = "shortcut";
3608
3609 /**
Peng Xu9ff7d222016-02-11 13:02:05 -08003610 * Use with {@link #getSystemService} to retrieve a {@link
3611 * android.hardware.location.ContextHubManager} for accessing context hubs.
3612 *
3613 * @see #getSystemService
3614 * @see android.hardware.location.ContextHubManager
3615 *
3616 * @hide
3617 */
3618 @SystemApi
3619 public static final String CONTEXTHUB_SERVICE = "contexthub";
3620
3621 /**
Joe Onorato713fec82016-03-04 10:34:02 -08003622 * Use with {@link #getSystemService} to retrieve a
3623 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
3624 * memory, etc) metrics.
3625 *
3626 * @see #getSystemService
3627 */
3628 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
3629
3630 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 * Determine whether the given permission is allowed for a particular
3632 * process and user ID running in the system.
3633 *
3634 * @param permission The name of the permission being checked.
3635 * @param pid The process ID being checked against. Must be > 0.
3636 * @param uid The user ID being checked against. A uid of 0 is the root
3637 * user, which will pass every permission check.
3638 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003639 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 * pid/uid is allowed that permission, or
3641 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3642 *
3643 * @see PackageManager#checkPermission(String, String)
3644 * @see #checkCallingPermission
3645 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003646 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003647 @PackageManager.PermissionResult
3648 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649
Dianne Hackbornff170242014-11-19 10:59:01 -08003650 /** @hide */
3651 @PackageManager.PermissionResult
3652 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
3653 IBinder callerToken);
3654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 /**
3656 * Determine whether the calling process of an IPC you are handling has been
3657 * granted a particular permission. This is basically the same as calling
3658 * {@link #checkPermission(String, int, int)} with the pid and uid returned
3659 * by {@link android.os.Binder#getCallingPid} and
3660 * {@link android.os.Binder#getCallingUid}. One important difference
3661 * is that if you are not currently processing an IPC, this function
3662 * will always fail. This is done to protect against accidentally
3663 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
3664 * to avoid this protection.
3665 *
3666 * @param permission The name of the permission being checked.
3667 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003668 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 * pid/uid is allowed that permission, or
3670 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3671 *
3672 * @see PackageManager#checkPermission(String, String)
3673 * @see #checkPermission
3674 * @see #checkCallingOrSelfPermission
3675 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003676 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003677 @PackageManager.PermissionResult
3678 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679
3680 /**
3681 * Determine whether the calling process of an IPC <em>or you</em> have been
3682 * granted a particular permission. This is the same as
3683 * {@link #checkCallingPermission}, except it grants your own permissions
3684 * if you are not currently processing an IPC. Use with care!
3685 *
3686 * @param permission The name of the permission being checked.
3687 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003688 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003689 * pid/uid is allowed that permission, or
3690 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3691 *
3692 * @see PackageManager#checkPermission(String, String)
3693 * @see #checkPermission
3694 * @see #checkCallingPermission
3695 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003696 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003697 @PackageManager.PermissionResult
3698 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699
3700 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08003701 * Determine whether <em>you</em> have been granted a particular permission.
3702 *
3703 * @param permission The name of the permission being checked.
3704 *
3705 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
3706 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
3707 *
3708 * @see PackageManager#checkPermission(String, String)
3709 * @see #checkCallingPermission(String)
3710 */
3711 @PackageManager.PermissionResult
3712 public abstract int checkSelfPermission(@NonNull String permission);
3713
3714 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 * If the given permission is not allowed for a particular process
3716 * and user ID running in the system, throw a {@link SecurityException}.
3717 *
3718 * @param permission The name of the permission being checked.
3719 * @param pid The process ID being checked against. Must be &gt; 0.
3720 * @param uid The user ID being checked against. A uid of 0 is the root
3721 * user, which will pass every permission check.
3722 * @param message A message to include in the exception if it is thrown.
3723 *
3724 * @see #checkPermission(String, int, int)
3725 */
3726 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003727 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728
3729 /**
3730 * If the calling process of an IPC you are handling has not been
3731 * granted a particular permission, throw a {@link
3732 * SecurityException}. This is basically the same as calling
3733 * {@link #enforcePermission(String, int, int, String)} with the
3734 * pid and uid returned by {@link android.os.Binder#getCallingPid}
3735 * and {@link android.os.Binder#getCallingUid}. One important
3736 * difference is that if you are not currently processing an IPC,
3737 * this function will always throw the SecurityException. This is
3738 * done to protect against accidentally leaking permissions; you
3739 * can use {@link #enforceCallingOrSelfPermission} to avoid this
3740 * protection.
3741 *
3742 * @param permission The name of the permission being checked.
3743 * @param message A message to include in the exception if it is thrown.
3744 *
3745 * @see #checkCallingPermission(String)
3746 */
3747 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003748 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003749
3750 /**
3751 * If neither you nor the calling process of an IPC you are
3752 * handling has been granted a particular permission, throw a
3753 * {@link SecurityException}. This is the same as {@link
3754 * #enforceCallingPermission}, except it grants your own
3755 * permissions if you are not currently processing an IPC. Use
3756 * with care!
3757 *
3758 * @param permission The name of the permission being checked.
3759 * @param message A message to include in the exception if it is thrown.
3760 *
3761 * @see #checkCallingOrSelfPermission(String)
3762 */
3763 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07003764 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003765
3766 /**
3767 * Grant permission to access a specific Uri to another package, regardless
3768 * of whether that package has general permission to access the Uri's
3769 * content provider. This can be used to grant specific, temporary
3770 * permissions, typically in response to user interaction (such as the
3771 * user opening an attachment that you would like someone else to
3772 * display).
3773 *
3774 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3775 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3776 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3777 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
3778 * start an activity instead of this function directly. If you use this
3779 * function directly, you should be sure to call
3780 * {@link #revokeUriPermission} when the target should no longer be allowed
3781 * to access it.
3782 *
3783 * <p>To succeed, the content provider owning the Uri must have set the
3784 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
3785 * grantUriPermissions} attribute in its manifest or included the
3786 * {@link android.R.styleable#AndroidManifestGrantUriPermission
3787 * &lt;grant-uri-permissions&gt;} tag.
3788 *
3789 * @param toPackage The package you would like to allow to access the Uri.
3790 * @param uri The Uri you would like to grant access to.
3791 * @param modeFlags The desired access modes. Any combination of
3792 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003793 * Intent.FLAG_GRANT_READ_URI_PERMISSION},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003794 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Jeff Sharkey846318a2014-04-04 12:12:41 -07003795 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION},
3796 * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION
3797 * Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION}, or
3798 * {@link Intent#FLAG_GRANT_PREFIX_URI_PERMISSION
3799 * Intent.FLAG_GRANT_PREFIX_URI_PERMISSION}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003800 *
3801 * @see #revokeUriPermission
3802 */
3803 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07003804 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805
3806 /**
3807 * Remove all permissions to access a particular content provider Uri
3808 * that were previously added with {@link #grantUriPermission}. The given
3809 * Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07003810 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07003812 * "content://foo". It will not remove any prefix grants that exist at a
3813 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003814 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003815 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07003816 * regular permission access to a Uri, but had received access to it through
3817 * a specific Uri permission grant, you could not revoke that grant with this
3818 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborn955d8d62014-10-07 20:17:19 -07003819 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security exception,
Dianne Hackborn192679a2014-09-10 14:28:48 -07003820 * but will remove whatever permission grants to the Uri had been given to the app
3821 * (or none).</p>
3822 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 * @param uri The Uri you would like to revoke access to.
3824 * @param modeFlags The desired access modes. Any combination of
3825 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
3826 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3827 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
3828 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3829 *
3830 * @see #grantUriPermission
3831 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07003832 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003833
3834 /**
3835 * Determine whether a particular process and user ID has been granted
3836 * permission to access a specific URI. This only checks for permissions
3837 * that have been explicitly granted -- if the given process/uid has
3838 * more general access to the URI's content provider then this check will
3839 * always fail.
3840 *
3841 * @param uri The uri that is being checked.
3842 * @param pid The process ID being checked against. Must be &gt; 0.
3843 * @param uid The user ID being checked against. A uid of 0 is the root
3844 * user, which will pass every permission check.
3845 * @param modeFlags The type of access to grant. May be one or both of
3846 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3847 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3848 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003849 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003850 * pid/uid is allowed to access that uri, or
3851 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3852 *
3853 * @see #checkCallingUriPermission
3854 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003855 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003856 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003857 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858
Dianne Hackbornff170242014-11-19 10:59:01 -08003859 /** @hide */
3860 public abstract int checkUriPermission(Uri uri, int pid, int uid,
3861 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
3862
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003863 /**
3864 * Determine whether the calling process and user ID has been
3865 * granted permission to access a specific URI. This is basically
3866 * the same as calling {@link #checkUriPermission(Uri, int, int,
3867 * int)} with the pid and uid returned by {@link
3868 * android.os.Binder#getCallingPid} and {@link
3869 * android.os.Binder#getCallingUid}. One important difference is
3870 * that if you are not currently processing an IPC, this function
3871 * will always fail.
3872 *
3873 * @param uri The uri that is being checked.
3874 * @param modeFlags The type of access to grant. May be one or both of
3875 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3876 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3877 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003878 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 * is allowed to access that uri, or
3880 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3881 *
3882 * @see #checkUriPermission(Uri, int, int, int)
3883 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003884 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey846318a2014-04-04 12:12:41 -07003885 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003886
3887 /**
3888 * Determine whether the calling process of an IPC <em>or you</em> has been granted
3889 * permission to access a specific URI. This is the same as
3890 * {@link #checkCallingUriPermission}, except it grants your own permissions
3891 * if you are not currently processing an IPC. Use with care!
3892 *
3893 * @param uri The uri that is being checked.
3894 * @param modeFlags The type of access to grant. May be one or both of
3895 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3896 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3897 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003898 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003899 * is allowed to access that uri, or
3900 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3901 *
3902 * @see #checkCallingUriPermission
3903 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003904 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003905 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003906 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907
3908 /**
3909 * Check both a Uri and normal permission. This allows you to perform
3910 * both {@link #checkPermission} and {@link #checkUriPermission} in one
3911 * call.
3912 *
3913 * @param uri The Uri whose permission is to be checked, or null to not
3914 * do this check.
3915 * @param readPermission The permission that provides overall read access,
3916 * or null to not do this check.
3917 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07003918 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003919 * @param pid The process ID being checked against. Must be &gt; 0.
3920 * @param uid The user ID being checked against. A uid of 0 is the root
3921 * user, which will pass every permission check.
3922 * @param modeFlags The type of access to grant. May be one or both of
3923 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3924 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3925 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003926 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 * is allowed to access that uri or holds one of the given permissions, or
3928 * {@link PackageManager#PERMISSION_DENIED} if it is not.
3929 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08003930 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07003931 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
3932 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07003933 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934
3935 /**
3936 * If a particular process and user ID has not been granted
3937 * permission to access a specific URI, throw {@link
3938 * SecurityException}. This only checks for permissions that have
3939 * been explicitly granted -- if the given process/uid has more
3940 * general access to the URI's content provider then this check
3941 * will always fail.
3942 *
3943 * @param uri The uri that is being checked.
3944 * @param pid The process ID being checked against. Must be &gt; 0.
3945 * @param uid The user ID being checked against. A uid of 0 is the root
3946 * user, which will pass every permission check.
3947 * @param modeFlags The type of access to grant. May be one or both of
3948 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3949 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3950 * @param message A message to include in the exception if it is thrown.
3951 *
3952 * @see #checkUriPermission(Uri, int, int, int)
3953 */
3954 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003955 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956
3957 /**
3958 * If the calling process and user ID has not been granted
3959 * permission to access a specific URI, throw {@link
3960 * SecurityException}. This is basically the same as calling
3961 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
3962 * the pid and uid returned by {@link
3963 * android.os.Binder#getCallingPid} and {@link
3964 * android.os.Binder#getCallingUid}. One important difference is
3965 * that if you are not currently processing an IPC, this function
3966 * will always throw a SecurityException.
3967 *
3968 * @param uri The uri that is being checked.
3969 * @param modeFlags The type of access to grant. May be one or both of
3970 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3971 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3972 * @param message A message to include in the exception if it is thrown.
3973 *
3974 * @see #checkCallingUriPermission(Uri, int)
3975 */
3976 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003977 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003978
3979 /**
3980 * If the calling process of an IPC <em>or you</em> has not been
3981 * granted permission to access a specific URI, throw {@link
3982 * SecurityException}. This is the same as {@link
3983 * #enforceCallingUriPermission}, except it grants your own
3984 * permissions if you are not currently processing an IPC. Use
3985 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07003986 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003987 * @param uri The uri that is being checked.
3988 * @param modeFlags The type of access to grant. May be one or both of
3989 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
3990 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
3991 * @param message A message to include in the exception if it is thrown.
3992 *
3993 * @see #checkCallingOrSelfUriPermission(Uri, int)
3994 */
3995 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07003996 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003997
3998 /**
3999 * Enforce both a Uri and normal permission. This allows you to perform
4000 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4001 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004002 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004003 * @param uri The Uri whose permission is to be checked, or null to not
4004 * do this check.
4005 * @param readPermission The permission that provides overall read access,
4006 * or null to not do this check.
4007 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004008 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 * @param pid The process ID being checked against. Must be &gt; 0.
4010 * @param uid The user ID being checked against. A uid of 0 is the root
4011 * user, which will pass every permission check.
4012 * @param modeFlags The type of access to grant. May be one or both of
4013 * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4014 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_WRITE_URI_PERMISSION}.
4015 * @param message A message to include in the exception if it is thrown.
4016 *
4017 * @see #checkUriPermission(Uri, String, String, int, int, int)
4018 */
4019 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004020 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004021 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004022 @Nullable String message);
4023
4024 /** @hide */
4025 @IntDef(flag = true,
4026 value = {CONTEXT_INCLUDE_CODE, CONTEXT_IGNORE_SECURITY, CONTEXT_RESTRICTED})
4027 @Retention(RetentionPolicy.SOURCE)
4028 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029
4030 /**
4031 * Flag for use with {@link #createPackageContext}: include the application
4032 * code with the context. This means loading code into the caller's
4033 * process, so that {@link #getClassLoader()} can be used to instantiate
4034 * the application's classes. Setting this flags imposes security
4035 * restrictions on what application context you can access; if the
4036 * requested application can not be safely loaded into your process,
4037 * java.lang.SecurityException will be thrown. If this flag is not set,
4038 * there will be no restrictions on the packages that can be loaded,
4039 * but {@link #getClassLoader} will always return the default system
4040 * class loader.
4041 */
4042 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4043
4044 /**
4045 * Flag for use with {@link #createPackageContext}: ignore any security
4046 * restrictions on the Context being requested, allowing it to always
4047 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4048 * to be loaded into a process even when it isn't safe to do so. Use
4049 * with extreme care!
4050 */
4051 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004052
Romain Guy870e09f2009-07-06 16:35:25 -07004053 /**
4054 * Flag for use with {@link #createPackageContext}: a restricted context may
4055 * disable specific features. For instance, a View associated with a restricted
4056 * context would ignore particular XML attributes.
4057 */
4058 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004059
4060 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004061 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004062 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004063 *
4064 * @hide
4065 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004066 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004067
4068 /**
4069 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004070 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004071 *
4072 * @hide
4073 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004074 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004075
4076 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004077 * @hide Used to indicate we should tell the activity manager about the process
4078 * loading this code.
4079 */
4080 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4081
4082 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004083 * Return a new Context object for the given application name. This
4084 * Context is the same as what the named application gets when it is
4085 * launched, containing the same resources and class loader. Each call to
4086 * this method returns a new instance of a Context object; Context objects
4087 * are not shared, however they share common state (Resources, ClassLoader,
4088 * etc) so the Context instance itself is fairly lightweight.
4089 *
Jeff Brown6e539312015-02-24 18:53:21 -08004090 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004091 * application with the given package name.
4092 *
4093 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4094 * can not be loaded into the caller's process for security reasons (see
4095 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4096 *
4097 * @param packageName Name of the application's package.
4098 * @param flags Option flags, one of {@link #CONTEXT_INCLUDE_CODE}
4099 * or {@link #CONTEXT_IGNORE_SECURITY}.
4100 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004101 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004103 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004104 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004105 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004106 */
4107 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004108 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004109
4110 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004111 * Similar to {@link #createPackageContext(String, int)}, but with a
4112 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4113 * will open any {@link Uri} as the given user.
4114 *
4115 * @hide
4116 */
4117 public abstract Context createPackageContextAsUser(
4118 String packageName, int flags, UserHandle user)
4119 throws PackageManager.NameNotFoundException;
4120
4121 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004122 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4123 *
4124 * @hide
4125 */
4126 public abstract Context createApplicationContext(ApplicationInfo application,
4127 int flags) throws PackageManager.NameNotFoundException;
4128
4129 /**
Jim Millera75a8832013-02-07 16:53:32 -08004130 * Get the userId associated with this context
4131 * @return user id
4132 *
4133 * @hide
4134 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004135 @TestApi
Jeff Sharkey8588bc12016-01-06 16:47:42 -07004136 public abstract @UserIdInt int getUserId();
Jim Millera75a8832013-02-07 16:53:32 -08004137
4138 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004139 * Return a new Context object for the current Context but whose resources
4140 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004141 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004142 * shared, however common state (ClassLoader, other Resources for the
4143 * same configuration) may be so the Context itself can be fairly lightweight.
4144 *
4145 * @param overrideConfiguration A {@link Configuration} specifying what
4146 * values to modify in the base Configuration of the original Context's
4147 * resources. If the base configuration changes (such as due to an
4148 * orientation change), the resources of this context will also change except
4149 * for those that have been explicitly overridden with a value here.
4150 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004151 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004152 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004153 public abstract Context createConfigurationContext(
4154 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004155
4156 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004157 * Return a new Context object for the current Context but whose resources
4158 * are adjusted to match the metrics of the given Display. Each call to this method
4159 * returns a new instance of a Context object; Context objects are not
4160 * shared, however common state (ClassLoader, other Resources for the
4161 * same configuration) may be so the Context itself can be fairly lightweight.
4162 *
4163 * The returned display Context provides a {@link WindowManager}
4164 * (see {@link #getSystemService(String)}) that is configured to show windows
4165 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4166 * method can be used to retrieve the Display from the returned Context.
4167 *
4168 * @param display A {@link Display} object specifying the display
4169 * for whose metrics the Context's resources should be tailored and upon which
4170 * new windows should be shown.
4171 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004172 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004173 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004174 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004175
4176 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004177 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004178 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004179 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004180 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004181 * with a key tied to the physical device, and it can be accessed
4182 * immediately after the device has booted successfully, both
4183 * <em>before and after</em> the user has authenticated with their
4184 * credentials (such as a lock pattern or PIN).
4185 * <p>
4186 * Because device-protected data is available without user authentication,
4187 * you should carefully limit the data you store using this Context. For
4188 * example, storing sensitive authentication tokens or passwords in the
4189 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004190 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004191 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004192 * device-protected and credential-protected data using different keys, then
4193 * both storage areas will become available at the same time. They remain as
4194 * two distinct storage locations on disk, and only the window of
4195 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004196 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004197 * Each call to this method returns a new instance of a Context object;
4198 * Context objects are not shared, however common state (ClassLoader, other
4199 * Resources for the same configuration) may be so the Context itself can be
4200 * fairly lightweight.
4201 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004202 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004203 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004204 public abstract Context createDeviceProtectedStorageContext();
4205
4206 /** @removed */
4207 @Deprecated
4208 public Context createDeviceEncryptedStorageContext() {
4209 return createDeviceProtectedStorageContext();
4210 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004211
4212 /**
4213 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004214 * APIs are backed by credential-protected storage. This is the default
4215 * storage area for apps unless
4216 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004217 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004218 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004219 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004220 * <em>only after</em> the user has entered their credentials (such as a
4221 * lock pattern or PIN).
4222 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004223 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004224 * device-protected and credential-protected data using different keys, then
4225 * both storage areas will become available at the same time. They remain as
4226 * two distinct storage locations on disk, and only the window of
4227 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004228 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004229 * Each call to this method returns a new instance of a Context object;
4230 * Context objects are not shared, however common state (ClassLoader, other
4231 * Resources for the same configuration) may be so the Context itself can be
4232 * fairly lightweight.
4233 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004234 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004235 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004236 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004237 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004238 public abstract Context createCredentialProtectedStorageContext();
4239
4240 /** @removed */
4241 @Deprecated
4242 public Context createCredentialEncryptedStorageContext() {
4243 return createCredentialProtectedStorageContext();
4244 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004245
4246 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004247 * Gets the display adjustments holder for this context. This information
4248 * is provided on a per-application or activity basis and is used to simulate lower density
4249 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004250 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004251 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004252 * @return The compatibility info holder, or null if not required by the application.
4253 * @hide
4254 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004255 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004256
4257 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004258 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004259 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004260 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004261 *
Romain Guy870e09f2009-07-06 16:35:25 -07004262 * @see #CONTEXT_RESTRICTED
4263 */
4264 public boolean isRestricted() {
4265 return false;
4266 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004267
4268 /**
4269 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004270 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004271 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004272 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004273 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004274 public abstract boolean isDeviceProtectedStorage();
4275
4276 /** @removed */
4277 @Deprecated
4278 public boolean isDeviceEncryptedStorage() {
4279 return isDeviceProtectedStorage();
4280 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004281
4282 /**
4283 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004284 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004285 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004286 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004287 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004288 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004289 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004290 public abstract boolean isCredentialProtectedStorage();
4291
4292 /** @removed */
4293 @Deprecated
4294 public boolean isCredentialEncryptedStorage() {
4295 return isCredentialProtectedStorage();
4296 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004297}