blob: 916fb7c59b11e0ef22b83546758565308ba694de [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;
Tony Mak46aabe52016-11-14 12:53:06 +000035import android.app.IApplicationThread;
36import android.app.IServiceConnection;
Ian Pedowitz4e9806c2017-08-11 14:23:17 -070037import android.app.Notification;
Zak Cohen56345f42017-01-26 13:54:28 -080038import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070039import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.content.pm.PackageManager;
41import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080042import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070043import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.content.res.Resources;
45import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070046import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.database.sqlite.SQLiteDatabase;
48import android.database.sqlite.SQLiteDatabase.CursorFactory;
49import android.graphics.Bitmap;
50import android.graphics.drawable.Drawable;
51import android.net.Uri;
52import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070053import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Handler;
Dianne Hackbornff170242014-11-19 10:59:01 -080055import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070057import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070058import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070059import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060060import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070061import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070063import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070064import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070065import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070066import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070067import android.view.WindowManager;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000068import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
70import java.io.File;
71import java.io.FileInputStream;
72import java.io.FileNotFoundException;
73import java.io.FileOutputStream;
74import java.io.IOException;
75import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070076import java.lang.annotation.Retention;
77import java.lang.annotation.RetentionPolicy;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
79/**
80 * Interface to global information about an application environment. This is
81 * an abstract class whose implementation is provided by
82 * the Android system. It
83 * allows access to application-specific resources and classes, as well as
84 * up-calls for application-level operations such as launching activities,
85 * broadcasting and receiving intents, etc.
86 */
87public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060088 /** @hide */
89 @IntDef(flag = true, prefix = { "MODE_" }, value = {
90 MODE_PRIVATE,
91 MODE_WORLD_READABLE,
92 MODE_WORLD_WRITEABLE,
93 MODE_APPEND,
94 })
95 @Retention(RetentionPolicy.SOURCE)
96 public @interface FileMode {}
97
98 /** @hide */
99 @IntDef(flag = true, prefix = { "MODE_" }, value = {
100 MODE_PRIVATE,
101 MODE_WORLD_READABLE,
102 MODE_WORLD_WRITEABLE,
103 MODE_MULTI_PROCESS,
104 })
105 @Retention(RetentionPolicy.SOURCE)
106 public @interface PreferencesMode {}
107
108 /** @hide */
109 @IntDef(flag = true, prefix = { "MODE_" }, value = {
110 MODE_PRIVATE,
111 MODE_WORLD_READABLE,
112 MODE_WORLD_WRITEABLE,
113 MODE_ENABLE_WRITE_AHEAD_LOGGING,
114 MODE_NO_LOCALIZED_COLLATORS,
115 })
116 @Retention(RetentionPolicy.SOURCE)
117 public @interface DatabaseMode {}
118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 /**
120 * File creation mode: the default mode, where the created file can only
121 * be accessed by the calling application (or all applications sharing the
122 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 */
124 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700127 * File creation mode: allow all other applications to have read access to
128 * the created file.
129 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700130 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
131 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700132 *
Nick Kralevich15069212013-01-09 15:54:56 -0800133 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700134 * to cause security holes in applications. It is strongly
135 * discouraged; instead, applications should use more formal
136 * mechanism for interactions such as {@link ContentProvider},
137 * {@link BroadcastReceiver}, and {@link android.app.Service}.
138 * There are no guarantees that this access mode will remain on
139 * a file, such as when it goes through a backup and restore.
140 * @see android.support.v4.content.FileProvider
141 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700143 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700147 * File creation mode: allow all other applications to have write access to
148 * the created file.
149 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700150 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700151 * mode will throw a {@link SecurityException}.
152 *
Nick Kralevich15069212013-01-09 15:54:56 -0800153 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700154 * to cause security holes in applications. It is strongly
155 * discouraged; instead, applications should use more formal
156 * mechanism for interactions such as {@link ContentProvider},
157 * {@link BroadcastReceiver}, and {@link android.app.Service}.
158 * There are no guarantees that this access mode will remain on
159 * a file, such as when it goes through a backup and restore.
160 * @see android.support.v4.content.FileProvider
161 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800162 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700163 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 /**
167 * File creation mode: for use with {@link #openFileOutput}, if the file
168 * already exists then write data to the end of the existing file
169 * instead of erasing it.
170 * @see #openFileOutput
171 */
172 public static final int MODE_APPEND = 0x8000;
173
174 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800175 * SharedPreference loading flag: when set, the file on disk will
176 * be checked for modification even if the shared preferences
177 * instance is already loaded in this process. This behavior is
178 * sometimes desired in cases where the application has multiple
179 * processes, all writing to the same SharedPreferences file.
180 * Generally there are better forms of communication between
181 * processes, though.
182 *
183 * <p>This was the legacy (but undocumented) behavior in and
184 * before Gingerbread (Android 2.3) and this flag is implied when
185 * targetting such releases. For applications targetting SDK
186 * versions <em>greater than</em> Android 2.3, this flag must be
187 * explicitly set if desired.
188 *
189 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700190 *
191 * @deprecated MODE_MULTI_PROCESS does not work reliably in
192 * some versions of Android, and furthermore does not provide any
193 * mechanism for reconciling concurrent modifications across
194 * processes. Applications should not attempt to use it. Instead,
195 * they should use an explicit cross-process data management
196 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800197 */
Christopher Tated5748b82015-05-08 18:14:01 -0700198 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800199 public static final int MODE_MULTI_PROCESS = 0x0004;
200
201 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700202 * Database open flag: when set, the database is opened with write-ahead
203 * logging enabled by default.
204 *
205 * @see #openOrCreateDatabase(String, int, CursorFactory)
206 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
207 * @see SQLiteDatabase#enableWriteAheadLogging
208 */
209 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
210
Sunny Goyala21e6b22015-12-02 09:51:02 -0800211 /**
212 * Database open flag: when set, the database is opened without support for
213 * localized collators.
214 *
215 * @see #openOrCreateDatabase(String, int, CursorFactory)
216 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
217 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
218 */
219 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
220
Tor Norbyed9273d62013-05-30 15:59:53 -0700221 /** @hide */
222 @IntDef(flag = true,
223 value = {
224 BIND_AUTO_CREATE,
Tor Norbyed9273d62013-05-30 15:59:53 -0700225 BIND_DEBUG_UNBIND,
226 BIND_NOT_FOREGROUND,
227 BIND_ABOVE_CLIENT,
228 BIND_ALLOW_OOM_MANAGEMENT,
Tor Norbyece1c67c2014-12-02 13:59:17 -0800229 BIND_WAIVE_PRIORITY,
230 BIND_IMPORTANT,
231 BIND_ADJUST_WITH_ACTIVITY
Tor Norbyed9273d62013-05-30 15:59:53 -0700232 })
233 @Retention(RetentionPolicy.SOURCE)
234 public @interface BindServiceFlags {}
235
Jeff Brown47847f32012-03-22 19:13:11 -0700236 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 * Flag for {@link #bindService}: automatically create the service as long
238 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700239 * its {@link android.app.Service#onStartCommand}
240 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 * explicit call to {@link #startService}. Even without that, though,
242 * this still provides you with access to the service object while the
243 * service is created.
244 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700245 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
246 * not supplying this flag would also impact how important the system
247 * consider's the target service's process to be. When set, the only way
248 * for it to be raised was by binding from a service in which case it will
249 * only be important when that activity is in the foreground. Now to
250 * achieve this behavior you must explicitly supply the new flag
251 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
252 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
253 * the flags {@link #BIND_WAIVE_PRIORITY} and
254 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
255 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 */
257 public static final int BIND_AUTO_CREATE = 0x0001;
258
259 /**
260 * Flag for {@link #bindService}: include debugging help for mismatched
261 * calls to unbind. When this flag is set, the callstack of the following
262 * {@link #unbindService} call is retained, to be printed if a later
263 * incorrect unbind call is made. Note that doing this requires retaining
264 * information about the binding that was made for the lifetime of the app,
265 * resulting in a leak -- this should only be used for debugging.
266 */
267 public static final int BIND_DEBUG_UNBIND = 0x0002;
268
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800269 /**
270 * Flag for {@link #bindService}: don't allow this binding to raise
271 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700272 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800273 * as the client (so that its process will not be killable in any
274 * situation where the client is not killable), but for CPU scheduling
275 * purposes it may be left in the background. This only has an impact
276 * in the situation where the binding client is a foreground process
277 * and the target service is in a background process.
278 */
279 public static final int BIND_NOT_FOREGROUND = 0x0004;
280
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700281 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700282 * Flag for {@link #bindService}: indicates that the client application
283 * binding to this service considers the service to be more important than
284 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700285 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700286 * this is not guaranteed to be the case.
287 */
288 public static final int BIND_ABOVE_CLIENT = 0x0008;
289
290 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700291 * Flag for {@link #bindService}: allow the process hosting the bound
292 * service to go through its normal memory management. It will be
293 * treated more like a running service, allowing the system to
294 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700295 * whim it may have, and being more aggressive about making it a candidate
296 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700297 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700298 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
299
300 /**
301 * Flag for {@link #bindService}: don't impact the scheduling or
302 * memory management priority of the target service's hosting process.
303 * Allows the service's process to be managed on the background LRU list
304 * just like a regular application process in the background.
305 */
306 public static final int BIND_WAIVE_PRIORITY = 0x0020;
307
308 /**
309 * Flag for {@link #bindService}: this service is very important to
310 * the client, so should be brought to the foreground process level
311 * when the client is. Normally a process can only be raised to the
312 * visibility level by a client, even if that client is in the foreground.
313 */
314 public static final int BIND_IMPORTANT = 0x0040;
315
316 /**
317 * Flag for {@link #bindService}: If binding from an activity, allow the
318 * target service's process importance to be raised based on whether the
319 * activity is visible to the user, regardless whether another flag is
320 * used to reduce the amount that the client process's overall importance
321 * is used to impact it.
322 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700323 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
324
325 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700326 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
327 * up in to the important background state (instead of transient).
328 */
329 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
330
331 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700332 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
333 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
334 */
335 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
336
337 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700338 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
339 * but only applies while the device is awake.
340 */
341 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
342
343 /**
344 * @hide Flag for {@link #bindService}: For only the case where the binding
345 * is coming from the system, set the process state to FOREGROUND_SERVICE
346 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
347 * saying that the process shouldn't participate in the normal power reduction
348 * modes (removing network access etc).
349 */
350 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
351
352 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700353 * @hide Flag for {@link #bindService}: Treat the binding as hosting
354 * an activity, an unbinding as the activity going in the background.
355 * That is, when unbinding, the process when empty will go on the activity
356 * LRU list instead of the regular one, keeping it around more aggressively
357 * than it otherwise would be. This is intended for use with IMEs to try
358 * to keep IME processes around for faster keyboard switching.
359 */
360 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
361
362 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700363 * @hide An idea that is not yet implemented.
364 * Flag for {@link #bindService}: If binding from an activity, consider
365 * this service to be visible like the binding activity is. That is,
366 * it will be treated as something more important to keep around than
367 * invisible background activities. This will impact the number of
368 * recent activities the user can switch between without having them
369 * restart. There is no guarantee this will be respected, as the system
370 * tries to balance such requests from one app vs. the importantance of
371 * keeping other apps around.
372 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700373 public static final int BIND_VISIBLE = 0x10000000;
374
375 /**
376 * @hide
377 * Flag for {@link #bindService}: Consider this binding to be causing the target
378 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
379 * away.
380 */
381 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700382
383 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700384 * Flag for {@link #bindService}: Don't consider the bound service to be
385 * visible, even if the caller is visible.
386 * @hide
387 */
388 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700389
Alan Viverette713a5cd2015-12-16 15:46:32 -0500390 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500391 * Flag for {@link #bindService}: The service being bound is an
392 * {@link android.R.attr#isolatedProcess isolated},
393 * {@link android.R.attr#externalService external} service. This binds the service into the
394 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400395 * <p>
396 * When using this flag, the code for the service being bound will execute under the calling
397 * application's package name and user ID. Because the service must be an isolated process,
398 * it will not have direct access to the application's data, though.
399 *
400 * The purpose of this flag is to allow applications to provide services that are attributed
401 * to the app using the service, rather than the application providing the service.
402 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500403 */
404 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
405
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700406 /** @hide */
407 @IntDef(flag = true,
408 value = {
409 RECEIVER_VISIBLE_TO_INSTANT_APPS
410 })
411 @Retention(RetentionPolicy.SOURCE)
412 public @interface RegisterReceiverFlags {}
413
414 /**
415 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
416 */
417 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
418
Robert Sesekb9a86662015-12-09 16:22:45 -0500419 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500420 * Returns an AssetManager instance for the application's package.
421 * <p>
422 * <strong>Note:</strong> Implementations of this method should return
423 * an AssetManager instance that is consistent with the Resources instance
424 * returned by {@link #getResources()}. For example, they should share the
425 * same {@link Configuration} object.
426 *
427 * @return an AssetManager instance for the application's package
428 * @see #getResources()
429 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 public abstract AssetManager getAssets();
431
Alan Viverette713a5cd2015-12-16 15:46:32 -0500432 /**
433 * Returns a Resources instance for the application's package.
434 * <p>
435 * <strong>Note:</strong> Implementations of this method should return
436 * a Resources instance that is consistent with the AssetManager instance
437 * returned by {@link #getAssets()}. For example, they should share the
438 * same {@link Configuration} object.
439 *
440 * @return a Resources instance for the application's package
441 * @see #getAssets()
442 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 public abstract Resources getResources();
444
445 /** Return PackageManager instance to find global package information. */
446 public abstract PackageManager getPackageManager();
447
448 /** Return a ContentResolver instance for your application's package. */
449 public abstract ContentResolver getContentResolver();
450
451 /**
452 * Return the Looper for the main thread of the current process. This is
453 * the thread used to dispatch calls to application components (activities,
454 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700455 * <p>
456 * By definition, this method returns the same result as would be obtained
457 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
458 * </p>
459 *
460 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 */
462 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700463
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 /**
465 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800466 * current process. This generally should only be used if you need a
467 * Context whose lifecycle is separate from the current context, that is
468 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700469 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800470 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800471 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800472 * <ul>
473 * <li> <p>If used from an Activity context, the receiver is being registered
474 * within that activity. This means that you are expected to unregister
475 * before the activity is done being destroyed; in fact if you do not do
476 * so, the framework will clean up your leaked registration as it removes
477 * the activity and log an error. Thus, if you use the Activity context
478 * to register a receiver that is static (global to the process, not
479 * associated with an Activity instance) then that registration will be
480 * removed on you at whatever point the activity you used is destroyed.
481 * <li> <p>If used from the Context returned here, the receiver is being
482 * registered with the global state associated with your application. Thus
483 * it will never be unregistered for you. This is necessary if the receiver
484 * is associated with static data, not a particular component. However
485 * using the ApplicationContext elsewhere can easily lead to serious leaks
486 * if you forget to unregister, unbind, etc.
487 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 */
489 public abstract Context getApplicationContext();
490
Phil Weaver846cda932017-06-15 10:10:06 -0700491 /** Non-activity related autofill ids are unique in the app */
492 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700493
494 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700495 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700496 *
Phil Weaver846cda932017-06-15 10:10:06 -0700497 * <p>All IDs will be smaller or the same as {@link View#LAST_APP_AUTOFILL_ID}. All IDs
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700498 * returned will be unique.
499 *
500 * @return A ID that is unique in the process
501 *
502 * {@hide}
503 */
Phil Weaver846cda932017-06-15 10:10:06 -0700504 public int getNextAutofillId() {
505 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
506 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700507 }
508
Phil Weaver846cda932017-06-15 10:10:06 -0700509 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700510
Phil Weaver846cda932017-06-15 10:10:06 -0700511 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700512 }
513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700515 * Add a new {@link ComponentCallbacks} to the base application of the
516 * Context, which will be called at the same times as the ComponentCallbacks
517 * methods of activities and other components are called. Note that you
518 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
519 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700520 *
521 * @param callback The interface to call. This can be either a
522 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700523 */
524 public void registerComponentCallbacks(ComponentCallbacks callback) {
525 getApplicationContext().registerComponentCallbacks(callback);
526 }
527
528 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400529 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700530 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
531 */
532 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
533 getApplicationContext().unregisterComponentCallbacks(callback);
534 }
535
536 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 * Return a localized, styled CharSequence from the application's package's
538 * default string table.
539 *
540 * @param resId Resource id for the CharSequence text
541 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700542 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543 return getResources().getText(resId);
544 }
545
546 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700547 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800548 * default string table.
549 *
550 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700551 * @return The string data associated with the resource, stripped of styled
552 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700554 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700555 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800556 return getResources().getString(resId);
557 }
558
559 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700560 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 * default string table, substituting the format arguments as defined in
562 * {@link java.util.Formatter} and {@link java.lang.String#format}.
563 *
564 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700565 * @param formatArgs The format arguments that will be used for
566 * substitution.
567 * @return The string data associated with the resource, formatted and
568 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700570 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700571 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 return getResources().getString(resId, formatArgs);
573 }
574
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800575 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800576 * Returns a color associated with a particular resource ID and styled for
577 * the current theme.
578 *
579 * @param id The desired resource identifier, as generated by the aapt
580 * tool. This integer encodes the package, type, and resource
581 * entry. The value 0 is an invalid identifier.
582 * @return A single color value in the form 0xAARRGGBB.
583 * @throws android.content.res.Resources.NotFoundException if the given ID
584 * does not exist.
585 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700586 @ColorInt
587 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800588 return getResources().getColor(id, getTheme());
589 }
590
591 /**
592 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800593 * styled for the current theme.
594 *
595 * @param id The desired resource identifier, as generated by the aapt
596 * tool. This integer encodes the package, type, and resource
597 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800598 * @return An object that can be used to draw this resource, or
599 * {@code null} if the resource could not be resolved.
600 * @throws android.content.res.Resources.NotFoundException if the given ID
601 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800602 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800603 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700604 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800605 return getResources().getDrawable(id, getTheme());
606 }
607
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800608 /**
609 * Returns a color state list associated with a particular resource ID and
610 * styled for the current theme.
611 *
612 * @param id The desired resource identifier, as generated by the aapt
613 * tool. This integer encodes the package, type, and resource
614 * entry. The value 0 is an invalid identifier.
615 * @return A color state list, or {@code null} if the resource could not be
616 * resolved.
617 * @throws android.content.res.Resources.NotFoundException if the given ID
618 * does not exist.
619 */
620 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700621 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800622 return getResources().getColorStateList(id, getTheme());
623 }
624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 /**
626 * Set the base theme for this context. Note that this should be called
627 * before any views are instantiated in the Context (for example before
628 * calling {@link android.app.Activity#setContentView} or
629 * {@link android.view.LayoutInflater#inflate}).
630 *
631 * @param resid The style resource describing the theme.
632 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700633 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634
Dianne Hackborn247fe742011-01-08 17:25:57 -0800635 /** @hide Needed for some internal implementation... not public because
636 * you can't assume this actually means anything. */
637 public int getThemeResId() {
638 return 0;
639 }
640
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 /**
642 * Return the Theme object associated with this Context.
643 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700644 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 public abstract Resources.Theme getTheme();
646
647 /**
648 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800649 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800650 * for more information.
651 *
Jeff Brown6e539312015-02-24 18:53:21 -0800652 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700654 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 return getTheme().obtainStyledAttributes(attrs);
656 }
657
658 /**
659 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800660 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 * for more information.
662 *
Jeff Brown6e539312015-02-24 18:53:21 -0800663 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800664 */
665 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700666 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 return getTheme().obtainStyledAttributes(resid, attrs);
668 }
669
670 /**
671 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800672 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 * for more information.
674 *
Jeff Brown6e539312015-02-24 18:53:21 -0800675 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 */
677 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700678 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800679 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
680 }
681
682 /**
683 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800684 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 * for more information.
686 *
Jeff Brown6e539312015-02-24 18:53:21 -0800687 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800688 */
689 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700690 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
691 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 return getTheme().obtainStyledAttributes(
693 set, attrs, defStyleAttr, defStyleRes);
694 }
695
696 /**
697 * Return a class loader you can use to retrieve classes in this package.
698 */
699 public abstract ClassLoader getClassLoader();
700
701 /** Return the name of this application's package. */
702 public abstract String getPackageName();
703
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800704 /** @hide Return the name of the base context this context is derived from. */
705 public abstract String getBasePackageName();
706
Dianne Hackborn95d78532013-09-11 09:51:14 -0700707 /** @hide Return the package name that should be used for app ops calls from
708 * this context. This is the same as {@link #getBasePackageName()} except in
709 * cases where system components are loaded into other app processes, in which
710 * case this will be the name of the primary package in that process (so that app
711 * ops uid verification will work with the name). */
712 public abstract String getOpPackageName();
713
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700714 /** Return the full application info for this context's package. */
715 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700716
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 /**
Kenny Root32148392010-01-21 15:40:47 -0800718 * Return the full path to this context's primary Android package.
719 * The Android package is a ZIP file which contains the application's
720 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800721 *
722 * <p>Note: this is not generally useful for applications, since they should
723 * not be directly accessing the file system.
724 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800725 * @return String Path to the resources.
726 */
727 public abstract String getPackageResourcePath();
728
729 /**
Kenny Root32148392010-01-21 15:40:47 -0800730 * Return the full path to this context's primary Android package.
731 * The Android package is a ZIP file which contains application's
732 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 *
734 * <p>Note: this is not generally useful for applications, since they should
735 * not be directly accessing the file system.
736 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 * @return String Path to the code and assets.
738 */
739 public abstract String getPackageCodePath();
740
741 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700742 * @hide
743 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700744 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700745 @Deprecated
746 public File getSharedPrefsFile(String name) {
747 return getSharedPreferencesPath(name);
748 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700749
750 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 * Retrieve and hold the contents of the preferences file 'name', returning
752 * a SharedPreferences through which you can retrieve and modify its
753 * values. Only one instance of the SharedPreferences object is returned
754 * to any callers for the same name, meaning they will see each other's
755 * edits as soon as they are made.
756 *
757 * @param name Desired preferences file. If a preferences file by this name
758 * does not exist, it will be created when you retrieve an
759 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600760 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400762 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 * to retrieve and modify the preference values.
764 *
765 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600767 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700768
769 /**
770 * Retrieve and hold the contents of the preferences file, returning
771 * a SharedPreferences through which you can retrieve and modify its
772 * values. Only one instance of the SharedPreferences object is returned
773 * to any callers for the same name, meaning they will see each other's
774 * edits as soon as they are made.
775 *
776 * @param file Desired preferences file. If a preferences file by this name
777 * does not exist, it will be created when you retrieve an
778 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600779 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700780 *
781 * @return The single {@link SharedPreferences} instance that can be used
782 * to retrieve and modify the preference values.
783 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700784 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700785 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600786 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700787 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600788 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789
790 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600791 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700792 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600793 * storage locations after an upgrade, such as moving to device protected
794 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700795 *
796 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600797 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700798 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600799 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700800 * preferences didn't exist in the source context, otherwise
801 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600802 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700803 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600804 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
805
Jeff Sharkey35871f22016-01-29 17:13:29 -0700806 /**
807 * Delete an existing shared preferences file.
808 *
809 * @param name The name (unique in the application package) of the shared
810 * preferences file.
811 * @return {@code true} if the shared preferences file was successfully
812 * deleted; else {@code false}.
813 * @see #getSharedPreferences(String, int)
814 */
815 public abstract boolean deleteSharedPreferences(String name);
816
Christopher Tatefe2368c2017-05-17 15:42:35 -0700817 /** @hide */
818 public abstract void reloadSharedPreferences();
819
Jeff Sharkey35871f22016-01-29 17:13:29 -0700820 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 * Open a private file associated with this Context's application package
822 * for reading.
823 *
824 * @param name The name of the file to open; can not contain path
825 * separators.
826 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400827 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 *
829 * @see #openFileOutput
830 * @see #fileList
831 * @see #deleteFile
832 * @see java.io.FileInputStream#FileInputStream(String)
833 */
834 public abstract FileInputStream openFileInput(String name)
835 throws FileNotFoundException;
836
837 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800838 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700839 * for writing. Creates the file if it doesn't already exist.
840 * <p>
841 * No additional permissions are required for the calling app to read or
842 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700843 *
Nick Kralevich15069212013-01-09 15:54:56 -0800844 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700845 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600846 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400847 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 * @see #MODE_APPEND
849 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 * @see #openFileInput
851 * @see #fileList
852 * @see #deleteFile
853 * @see java.io.FileOutputStream#FileOutputStream(String)
854 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600855 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 throws FileNotFoundException;
857
858 /**
859 * Delete the given private file associated with this Context's
860 * application package.
861 *
862 * @param name The name of the file to delete; can not contain path
863 * separators.
864 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400865 * @return {@code true} if the file was successfully deleted; else
866 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 *
868 * @see #openFileInput
869 * @see #openFileOutput
870 * @see #fileList
871 * @see java.io.File#delete()
872 */
873 public abstract boolean deleteFile(String name);
874
875 /**
876 * Returns the absolute path on the filesystem where a file created with
877 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700878 * <p>
879 * The returned path may change over time if the calling app is moved to an
880 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 *
882 * @param name The name of the file for which you would like to get
883 * its path.
884 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400885 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 *
887 * @see #openFileOutput
888 * @see #getFilesDir
889 * @see #getDir
890 */
891 public abstract File getFileStreamPath(String name);
892
893 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700894 * Returns the absolute path on the filesystem where a file created with
895 * {@link #getSharedPreferences(String, int)} is stored.
896 * <p>
897 * The returned path may change over time if the calling app is moved to an
898 * adopted storage device, so only relative paths should be persisted.
899 *
900 * @param name The name of the shared preferences for which you would like
901 * to get a path.
902 * @return An absolute path to the given file.
903 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600904 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700905 */
906 public abstract File getSharedPreferencesPath(String name);
907
908 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700909 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600910 * private files belonging to this app are stored. Apps should not use this
911 * path directly; they should instead use {@link #getFilesDir()},
912 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
913 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700914 * <p>
915 * The returned path may change over time if the calling app is moved to an
916 * adopted storage device, so only relative paths should be persisted.
917 * <p>
918 * No additional permissions are required for the calling app to read or
919 * write files under the returned path.
920 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600921 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700922 */
923 public abstract File getDataDir();
924
925 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700926 * Returns the absolute path to the directory on the filesystem where files
927 * created with {@link #openFileOutput} are stored.
928 * <p>
929 * The returned path may change over time if the calling app is moved to an
930 * adopted storage device, so only relative paths should be persisted.
931 * <p>
932 * No additional permissions are required for the calling app to read or
933 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700934 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400935 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 * @see #openFileOutput
937 * @see #getFileStreamPath
938 * @see #getDir
939 */
940 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700941
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700943 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700944 * {@link #getFilesDir()}. The difference is that files placed under this
945 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700946 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
947 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700948 * <p>
949 * The returned path may change over time if the calling app is moved to an
950 * adopted storage device, so only relative paths should be persisted.
951 * <p>
952 * No additional permissions are required for the calling app to read or
953 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700954 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700955 * @return The path of the directory holding application files that will not
956 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700957 * @see #openFileOutput
958 * @see #getFileStreamPath
959 * @see #getDir
960 * @see android.app.backup.BackupAgent
961 */
962 public abstract File getNoBackupFilesDir();
963
964 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700965 * Returns the absolute path to the directory on the primary shared/external
966 * storage device where the application can place persistent files it owns.
967 * These files are internal to the applications, and not typically visible
968 * to the user as media.
969 * <p>
970 * This is like {@link #getFilesDir()} in that these files will be deleted
971 * when the application is uninstalled, however there are some important
972 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800973 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700974 * <li>Shared storage may not always be available, since removable media can
975 * be ejected by the user. Media state can be checked using
976 * {@link Environment#getExternalStorageState(File)}.
977 * <li>There is no security enforced with these files. For example, any
978 * application holding
979 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700980 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800981 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700982 * <p>
983 * If a shared storage device is emulated (as determined by
984 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
985 * backed by a private user data partition, which means there is little
986 * benefit to storing data here instead of the private directories returned
987 * by {@link #getFilesDir()}, etc.
988 * <p>
989 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700990 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700991 * accessible to the calling app. This only applies to paths generated for
992 * package name of the calling application. To access paths belonging to
993 * other packages,
994 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
995 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
996 * <p>
997 * On devices with multiple users (as described by {@link UserManager}),
998 * each user has their own isolated shared storage. Applications only have
999 * access to the shared storage for the user they're running as.
1000 * <p>
1001 * The returned path may change over time if different shared storage media
1002 * is inserted, so only relative paths should be persisted.
1003 * <p>
1004 * Here is an example of typical code to manipulate a file in an
1005 * application's shared storage:
1006 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001007 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1008 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001009 * <p>
1010 * If you supply a non-null <var>type</var> to this function, the returned
1011 * file will be a path to a sub-directory of the given type. Though these
1012 * files are not automatically scanned by the media scanner, you can
1013 * explicitly add them to the media database with
1014 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1015 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001016 * {@link android.os.Environment#getExternalStoragePublicDirectory
1017 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001018 * directories of media shared by all applications. The directories returned
1019 * here are owned by the application, and their contents will be removed
1020 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001021 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001022 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1023 * here will be automatically created for you.
1024 * <p>
1025 * Here is an example of typical code to manipulate a picture in an
1026 * application's shared storage and add it to the media database:
1027 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001028 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1029 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001030 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001031 * @param type The type of files directory to return. May be {@code null}
1032 * for the root of the files directory or one of the following
1033 * constants for a subdirectory:
1034 * {@link android.os.Environment#DIRECTORY_MUSIC},
1035 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1036 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1037 * {@link android.os.Environment#DIRECTORY_ALARMS},
1038 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1039 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1040 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1041 * @return the absolute path to application-specific directory. May return
1042 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001043 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001044 * @see #getExternalFilesDirs(String)
1045 * @see Environment#getExternalStorageState(File)
1046 * @see Environment#isExternalStorageEmulated(File)
1047 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001048 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001049 @Nullable
1050 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001051
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001052 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001053 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001054 * shared/external storage devices where the application can place
1055 * persistent files it owns. These files are internal to the application,
1056 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001057 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001058 * This is like {@link #getFilesDir()} in that these files will be deleted
1059 * when the application is uninstalled, however there are some important
1060 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001061 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001062 * <li>Shared storage may not always be available, since removable media can
1063 * be ejected by the user. Media state can be checked using
1064 * {@link Environment#getExternalStorageState(File)}.
1065 * <li>There is no security enforced with these files. For example, any
1066 * application holding
1067 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1068 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001069 * </ul>
1070 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001071 * If a shared storage device is emulated (as determined by
1072 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1073 * backed by a private user data partition, which means there is little
1074 * benefit to storing data here instead of the private directories returned
1075 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001076 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001077 * Shared storage devices returned here are considered a stable part of the
1078 * device, including physical media slots under a protective cover. The
1079 * returned paths do not include transient devices, such as USB flash drives
1080 * connected to handheld devices.
1081 * <p>
1082 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001083 * example, an app may choose to store large files on the device with the
1084 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001085 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001086 * No additional permissions are required for the calling app to read or
1087 * write files under the returned path. Write access outside of these paths
1088 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001089 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001090 * The returned path may change over time if different shared storage media
1091 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001092 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001093 * @param type The type of files directory to return. May be {@code null}
1094 * for the root of the files directory or one of the following
1095 * constants for a subdirectory:
1096 * {@link android.os.Environment#DIRECTORY_MUSIC},
1097 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1098 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1099 * {@link android.os.Environment#DIRECTORY_ALARMS},
1100 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1101 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1102 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1103 * @return the absolute paths to application-specific directories. Some
1104 * individual paths may be {@code null} if that shared storage is
1105 * not currently available. The first path returned is the same as
1106 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001107 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001108 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001109 * @see Environment#isExternalStorageEmulated(File)
1110 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001111 */
1112 public abstract File[] getExternalFilesDirs(String type);
1113
1114 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001115 * Return the primary shared/external storage directory where this
1116 * application's OBB files (if there are any) can be found. Note if the
1117 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001118 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001119 * This is like {@link #getFilesDir()} in that these files will be deleted
1120 * when the application is uninstalled, however there are some important
1121 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001122 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001123 * <li>Shared storage may not always be available, since removable media can
1124 * be ejected by the user. Media state can be checked using
1125 * {@link Environment#getExternalStorageState(File)}.
1126 * <li>There is no security enforced with these files. For example, any
1127 * application holding
1128 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001129 * these files.
1130 * </ul>
1131 * <p>
1132 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001133 * are required to read or write to the path that this method returns.
1134 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1135 * to read the OBB expansion files, you must declare the
1136 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1137 * permission at runtime as follows:
1138 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001139 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001140 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1141 * android:maxSdkVersion="23" />}
1142 * </p>
1143 * <p>
1144 * Starting from {@link android.os.Build.VERSION_CODES#N},
1145 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1146 * permission is not required, so don’t ask for this
1147 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1148 * and if it fails, you must request
1149 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1150 * </p>
1151 *
1152 * <p>
1153 * The following code snippet shows how to do this:
1154 * </p>
1155 *
1156 * <pre>
1157 * File obb = new File(obb_filename);
1158 * boolean open_failed = false;
1159 *
1160 * try {
1161 * BufferedReader br = new BufferedReader(new FileReader(obb));
1162 * open_failed = false;
1163 * ReadObbFile(br);
1164 * } catch (IOException e) {
1165 * open_failed = true;
1166 * }
1167 *
1168 * if (open_failed) {
1169 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1170 * ReadObbFileWithPermission();
1171 * }
1172 * </pre>
1173 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001174 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001175 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001176 * should ensure that multiple instances running under different users don't
1177 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001178 *
1179 * @return the absolute path to application-specific directory. May return
1180 * {@code null} if shared storage is not currently available.
1181 * @see #getObbDirs()
1182 * @see Environment#getExternalStorageState(File)
1183 * @see Environment#isExternalStorageEmulated(File)
1184 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001185 */
1186 public abstract File getObbDir();
1187
1188 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001189 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001190 * shared/external storage devices where the application's OBB files (if
1191 * there are any) can be found. Note if the application does not have any
1192 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001193 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001194 * This is like {@link #getFilesDir()} in that these files will be deleted
1195 * when the application is uninstalled, however there are some important
1196 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001197 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001198 * <li>Shared storage may not always be available, since removable media can
1199 * be ejected by the user. Media state can be checked using
1200 * {@link Environment#getExternalStorageState(File)}.
1201 * <li>There is no security enforced with these files. For example, any
1202 * application holding
1203 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1204 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001205 * </ul>
1206 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001207 * Shared storage devices returned here are considered a stable part of the
1208 * device, including physical media slots under a protective cover. The
1209 * returned paths do not include transient devices, such as USB flash drives
1210 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001211 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001212 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001213 * example, an app may choose to store large files on the device with the
1214 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001215 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001216 * No additional permissions are required for the calling app to read or
1217 * write files under the returned path. Write access outside of these paths
1218 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001219 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001220 * @return the absolute paths to application-specific directories. Some
1221 * individual paths may be {@code null} if that shared storage is
1222 * not currently available. The first path returned is the same as
1223 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001224 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001225 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001226 * @see Environment#isExternalStorageEmulated(File)
1227 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001228 */
1229 public abstract File[] getObbDirs();
1230
1231 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001232 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001233 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001234 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001235 * The system will automatically delete files in this directory as disk
1236 * space is needed elsewhere on the device. The system will always delete
1237 * older files first, as reported by {@link File#lastModified()}. If
1238 * desired, you can exert more control over how files are deleted using
1239 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1240 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1241 * <p>
1242 * Apps are strongly encouraged to keep their usage of cache space below the
1243 * quota returned by
1244 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1245 * goes above this quota, your cached files will be some of the first to be
1246 * deleted when additional disk space is needed. Conversely, if your app
1247 * stays under this quota, your cached files will be some of the last to be
1248 * deleted when additional disk space is needed.
1249 * <p>
1250 * Note that your cache quota will change over time depending on how
1251 * frequently the user interacts with your app, and depending on how much
1252 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001253 * <p>
1254 * The returned path may change over time if the calling app is moved to an
1255 * adopted storage device, so only relative paths should be persisted.
1256 * <p>
1257 * Apps require no extra permissions to read or write to the returned path,
1258 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001259 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001260 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001261 * @see #openFileOutput
1262 * @see #getFileStreamPath
1263 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001264 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 */
1266 public abstract File getCacheDir();
1267
1268 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001269 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001270 * the filesystem designed for storing cached code.
1271 * <p>
1272 * The system will delete any files stored in this location both when your
1273 * specific application is upgraded, and when the entire platform is
1274 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001275 * <p>
1276 * This location is optimal for storing compiled or optimized code generated
1277 * by your application at runtime.
1278 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001279 * The returned path may change over time if the calling app is moved to an
1280 * adopted storage device, so only relative paths should be persisted.
1281 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001282 * Apps require no extra permissions to read or write to the returned path,
1283 * since this path lives in their private storage.
1284 *
1285 * @return The path of the directory holding application code cache files.
1286 */
1287 public abstract File getCodeCacheDir();
1288
1289 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001290 * Returns absolute path to application-specific directory on the primary
1291 * shared/external storage device where the application can place cache
1292 * files it owns. These files are internal to the application, and not
1293 * typically visible to the user as media.
1294 * <p>
1295 * This is like {@link #getCacheDir()} in that these files will be deleted
1296 * when the application is uninstalled, however there are some important
1297 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001298 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001299 * <li>The platform does not always monitor the space available in shared
1300 * storage, and thus may not automatically delete these files. Apps should
1301 * always manage the maximum space used in this location. Currently the only
1302 * time files here will be deleted by the platform is when running on
1303 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1304 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1305 * <li>Shared storage may not always be available, since removable media can
1306 * be ejected by the user. Media state can be checked using
1307 * {@link Environment#getExternalStorageState(File)}.
1308 * <li>There is no security enforced with these files. For example, any
1309 * application holding
1310 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001311 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001312 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001313 * <p>
1314 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001315 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001316 * backed by a private user data partition, which means there is little
1317 * benefit to storing data here instead of the private directory returned by
1318 * {@link #getCacheDir()}.
1319 * <p>
1320 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001321 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001322 * accessible to the calling app. This only applies to paths generated for
1323 * package name of the calling application. To access paths belonging to
1324 * other packages,
1325 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1326 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1327 * <p>
1328 * On devices with multiple users (as described by {@link UserManager}),
1329 * each user has their own isolated shared storage. Applications only have
1330 * access to the shared storage for the user they're running as.
1331 * <p>
1332 * The returned path may change over time if different shared storage media
1333 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001334 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001335 * @return the absolute path to application-specific directory. May return
1336 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001337 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001338 * @see #getExternalCacheDirs()
1339 * @see Environment#getExternalStorageState(File)
1340 * @see Environment#isExternalStorageEmulated(File)
1341 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001342 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001343 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001344 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001345
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001346 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001347 * Returns absolute path to application-specific directory in the preloaded cache.
1348 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1349 * There is no guarantee when these files will be deleted.
1350 * @hide
1351 */
1352 @Nullable
1353 @SystemApi
1354 public abstract File getPreloadsFileCache();
1355
1356 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001357 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001358 * shared/external storage devices where the application can place cache
1359 * files it owns. These files are internal to the application, and not
1360 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001361 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001362 * This is like {@link #getCacheDir()} in that these files will be deleted
1363 * when the application is uninstalled, however there are some important
1364 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001365 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001366 * <li>The platform does not always monitor the space available in shared
1367 * storage, and thus may not automatically delete these files. Apps should
1368 * always manage the maximum space used in this location. Currently the only
1369 * time files here will be deleted by the platform is when running on
1370 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1371 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1372 * <li>Shared storage may not always be available, since removable media can
1373 * be ejected by the user. Media state can be checked using
1374 * {@link Environment#getExternalStorageState(File)}.
1375 * <li>There is no security enforced with these files. For example, any
1376 * application holding
1377 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1378 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001379 * </ul>
1380 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001381 * If a shared storage device is emulated (as determined by
1382 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1383 * backed by a private user data partition, which means there is little
1384 * benefit to storing data here instead of the private directory returned by
1385 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001386 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001387 * Shared storage devices returned here are considered a stable part of the
1388 * device, including physical media slots under a protective cover. The
1389 * returned paths do not include transient devices, such as USB flash drives
1390 * connected to handheld devices.
1391 * <p>
1392 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001393 * example, an app may choose to store large files on the device with the
1394 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001395 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001396 * No additional permissions are required for the calling app to read or
1397 * write files under the returned path. Write access outside of these paths
1398 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001399 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001400 * The returned paths may change over time if different shared storage media
1401 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001402 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001403 * @return the absolute paths to application-specific directories. Some
1404 * individual paths may be {@code null} if that shared storage is
1405 * not currently available. The first path returned is the same as
1406 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001407 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001408 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001409 * @see Environment#isExternalStorageEmulated(File)
1410 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001411 */
1412 public abstract File[] getExternalCacheDirs();
1413
1414 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001415 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001416 * shared/external storage devices where the application can place media
1417 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001418 * {@link MediaStore}.
1419 * <p>
1420 * This is like {@link #getExternalFilesDirs} in that these files will be
1421 * deleted when the application is uninstalled, however there are some
1422 * important differences:
1423 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001424 * <li>Shared storage may not always be available, since removable media can
1425 * be ejected by the user. Media state can be checked using
1426 * {@link Environment#getExternalStorageState(File)}.
1427 * <li>There is no security enforced with these files. For example, any
1428 * application holding
1429 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1430 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001431 * </ul>
1432 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001433 * Shared storage devices returned here are considered a stable part of the
1434 * device, including physical media slots under a protective cover. The
1435 * returned paths do not include transient devices, such as USB flash drives
1436 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001437 * <p>
1438 * An application may store data on any or all of the returned devices. For
1439 * example, an app may choose to store large files on the device with the
1440 * most available space, as measured by {@link StatFs}.
1441 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001442 * No additional permissions are required for the calling app to read or
1443 * write files under the returned path. Write access outside of these paths
1444 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001445 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001446 * The returned paths may change over time if different shared storage media
1447 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001448 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001449 * @return the absolute paths to application-specific directories. Some
1450 * individual paths may be {@code null} if that shared storage is
1451 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001452 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001453 * @see Environment#isExternalStorageEmulated(File)
1454 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001455 */
1456 public abstract File[] getExternalMediaDirs();
1457
1458 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 * Returns an array of strings naming the private files associated with
1460 * this Context's application package.
1461 *
1462 * @return Array of strings naming the private files.
1463 *
1464 * @see #openFileInput
1465 * @see #openFileOutput
1466 * @see #deleteFile
1467 */
1468 public abstract String[] fileList();
1469
1470 /**
1471 * Retrieve, creating if needed, a new directory in which the application
1472 * can place its own custom data files. You can use the returned File
1473 * object to create and access files in this directory. Note that files
1474 * created through a File object will only be accessible by your own
1475 * application; you can only set the mode of the entire directory, not
1476 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001477 * <p>
1478 * The returned path may change over time if the calling app is moved to an
1479 * adopted storage device, so only relative paths should be persisted.
1480 * <p>
1481 * Apps require no extra permissions to read or write to the returned path,
1482 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001483 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001484 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001485 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001486 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001487 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001488 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001489 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001490 *
1491 * @see #openFileOutput(String, int)
1492 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001493 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001494
1495 /**
1496 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001497 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001498 *
1499 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001500 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001502 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001504 * @throws android.database.sqlite.SQLiteException if the database file
1505 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001507 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001508 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001509 * @see #deleteDatabase
1510 */
1511 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001512 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001513
1514 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001515 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001516 * application package. Creates the database file if it doesn't exist.
1517 * <p>
1518 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1519 * to be used to handle corruption when sqlite reports database corruption.
1520 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001521 *
1522 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001523 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001524 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001525 * cursor when query is called.
1526 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1527 * sqlite reports database corruption. if null,
1528 * {@link android.database.DefaultDatabaseErrorHandler} is
1529 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001530 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001531 * @throws android.database.sqlite.SQLiteException if the database file
1532 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001533 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001534 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001535 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001536 * @see #deleteDatabase
1537 */
1538 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001539 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001540 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001541
1542 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001543 * Move an existing database file from the given source storage context to
1544 * this context. This is typically used to migrate data between storage
1545 * locations after an upgrade, such as migrating to device protected
1546 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001547 * <p>
1548 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001549 *
1550 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001551 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001552 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001553 * @return {@code true} if the move was successful or if the database didn't
1554 * exist in the source context, otherwise {@code false}.
1555 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001556 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001557 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1558
Jeff Sharkey35871f22016-01-29 17:13:29 -07001559 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001560 * Delete an existing private SQLiteDatabase associated with this Context's
1561 * application package.
1562 *
1563 * @param name The name (unique in the application package) of the
1564 * database.
1565 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001566 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 *
1568 * @see #openOrCreateDatabase
1569 */
1570 public abstract boolean deleteDatabase(String name);
1571
1572 /**
1573 * Returns the absolute path on the filesystem where a database created with
1574 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001575 * <p>
1576 * The returned path may change over time if the calling app is moved to an
1577 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 *
1579 * @param name The name of the database for which you would like to get
1580 * its path.
1581 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001582 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001583 *
1584 * @see #openOrCreateDatabase
1585 */
1586 public abstract File getDatabasePath(String name);
1587
1588 /**
1589 * Returns an array of strings naming the private databases associated with
1590 * this Context's application package.
1591 *
1592 * @return Array of strings naming the private databases.
1593 *
1594 * @see #openOrCreateDatabase
1595 * @see #deleteDatabase
1596 */
1597 public abstract String[] databaseList();
1598
1599 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001600 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001601 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001603 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 public abstract Drawable getWallpaper();
1605
1606 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001607 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001608 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001610 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 public abstract Drawable peekWallpaper();
1612
1613 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001614 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1615 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001617 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 public abstract int getWallpaperDesiredMinimumWidth();
1619
1620 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001621 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1622 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001624 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 public abstract int getWallpaperDesiredMinimumHeight();
1626
1627 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001628 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001629 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001630 * <p>This method requires the caller to hold the permission
1631 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001633 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1635
1636 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001637 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001638 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001639 * <p>This method requires the caller to hold the permission
1640 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001642 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 public abstract void setWallpaper(InputStream data) throws IOException;
1644
1645 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001646 * @deprecated Use {@link android.app.WallpaperManager#clear
1647 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001648 * <p>This method requires the caller to hold the permission
1649 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001651 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 public abstract void clearWallpaper() throws IOException;
1653
1654 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001655 * Same as {@link #startActivity(Intent, Bundle)} with no options
1656 * specified.
1657 *
1658 * @param intent The description of the activity to start.
1659 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001660 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001661 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001662 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001663 * @see PackageManager#resolveActivity
1664 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001665 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001666
1667 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001668 * Version of {@link #startActivity(Intent)} that allows you to specify the
1669 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001670 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001671 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001672 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001673 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001674 * @hide
1675 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001676 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Tor Norbye788fc2b2015-07-05 16:10:42 -07001677 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001678 throw new RuntimeException("Not implemented. Must override in a subclass.");
1679 }
1680
1681 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 * Launch a new activity. You will not receive any information about when
1683 * the activity exits.
1684 *
1685 * <p>Note that if this method is being called from outside of an
1686 * {@link android.app.Activity} Context, then the Intent must include
1687 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1688 * without being started from an existing Activity, there is no existing
1689 * task in which to place the new activity and thus it needs to be placed
1690 * in its own separate task.
1691 *
1692 * <p>This method throws {@link ActivityNotFoundException}
1693 * if there was no Activity found to run the given Intent.
1694 *
1695 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001696 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001697 * May be null if there are no options. See {@link android.app.ActivityOptions}
1698 * for how to build the Bundle supplied here; there are no supported definitions
1699 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001700 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001701 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702 *
Scott Main60dd5202012-06-23 00:01:22 -07001703 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 * @see PackageManager#resolveActivity
1705 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001706 public abstract void startActivity(@RequiresPermission Intent intent,
1707 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001708
1709 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001710 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1711 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001712 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001713 * @param intent The description of the activity to start.
1714 * @param options Additional options for how the Activity should be started.
1715 * May be null if there are no options. See {@link android.app.ActivityOptions}
1716 * for how to build the Bundle supplied here; there are no supported definitions
1717 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001718 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001719 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001720 * @hide
1721 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001722 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Tor Norbye788fc2b2015-07-05 16:10:42 -07001723 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1724 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001725 throw new RuntimeException("Not implemented. Must override in a subclass.");
1726 }
1727
1728 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001729 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1730 * is only supported for Views and Fragments.
1731 * @param who The identifier for the calling element that will receive the result.
1732 * @param intent The intent to start.
1733 * @param requestCode The code that will be returned with onActivityResult() identifying this
1734 * request.
1735 * @param options Additional options for how the Activity should be started.
1736 * May be null if there are no options. See {@link android.app.ActivityOptions}
1737 * for how to build the Bundle supplied here; there are no supported definitions
1738 * for building it manually.
1739 * @hide
1740 */
1741 public void startActivityForResult(
1742 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1743 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1744 + "Check canStartActivityForResult() before calling.");
1745 }
1746
1747 /**
1748 * Identifies whether this Context instance will be able to process calls to
1749 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1750 * @hide
1751 */
1752 public boolean canStartActivityForResult() {
1753 return false;
1754 }
1755
1756 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001757 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1758 * specified.
1759 *
1760 * @param intents An array of Intents to be started.
1761 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001762 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001763 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001764 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001765 * @see PackageManager#resolveActivity
1766 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001767 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768
1769 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001770 * Launch multiple new activities. This is generally the same as calling
1771 * {@link #startActivity(Intent)} for the first Intent in the array,
1772 * that activity during its creation calling {@link #startActivity(Intent)}
1773 * for the second entry, etc. Note that unlike that approach, generally
1774 * none of the activities except the last in the array will be created
1775 * at this point, but rather will be created when the user first visits
1776 * them (due to pressing back from the activity on top).
1777 *
1778 * <p>This method throws {@link ActivityNotFoundException}
1779 * if there was no Activity found for <em>any</em> given Intent. In this
1780 * case the state of the activity stack is undefined (some Intents in the
1781 * list may be on it, some not), so you probably want to avoid such situations.
1782 *
1783 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001784 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001785 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001786 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001787 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001788 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001789 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001790 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001791 * @see PackageManager#resolveActivity
1792 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001793 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001794
1795 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001796 * @hide
1797 * Launch multiple new activities. This is generally the same as calling
1798 * {@link #startActivity(Intent)} for the first Intent in the array,
1799 * that activity during its creation calling {@link #startActivity(Intent)}
1800 * for the second entry, etc. Note that unlike that approach, generally
1801 * none of the activities except the last in the array will be created
1802 * at this point, but rather will be created when the user first visits
1803 * them (due to pressing back from the activity on top).
1804 *
1805 * <p>This method throws {@link ActivityNotFoundException}
1806 * if there was no Activity found for <em>any</em> given Intent. In this
1807 * case the state of the activity stack is undefined (some Intents in the
1808 * list may be on it, some not), so you probably want to avoid such situations.
1809 *
1810 * @param intents An array of Intents to be started.
1811 * @param options Additional options for how the Activity should be started.
1812 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001813 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001814 * Context.startActivity(Intent, Bundle)} for more details.
1815 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001816 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001817 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001818 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001819 * @see PackageManager#resolveActivity
1820 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001821 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001822 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1823 throw new RuntimeException("Not implemented. Must override in a subclass.");
1824 }
1825
1826 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001827 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1828 * with no options specified.
1829 *
1830 * @param intent The IntentSender to launch.
1831 * @param fillInIntent If non-null, this will be provided as the
1832 * intent parameter to {@link IntentSender#sendIntent}.
1833 * @param flagsMask Intent flags in the original IntentSender that you
1834 * would like to change.
1835 * @param flagsValues Desired values for any bits set in
1836 * <var>flagsMask</var>
1837 * @param extraFlags Always set to 0.
1838 *
1839 * @see #startActivity(Intent)
1840 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1841 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001842 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1843 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1844 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001845
1846 /**
1847 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001848 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001849 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001850 * here; otherwise, its associated action will be executed (such as
1851 * sending a broadcast) as if you had called
1852 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001853 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001854 * @param intent The IntentSender to launch.
1855 * @param fillInIntent If non-null, this will be provided as the
1856 * intent parameter to {@link IntentSender#sendIntent}.
1857 * @param flagsMask Intent flags in the original IntentSender that you
1858 * would like to change.
1859 * @param flagsValues Desired values for any bits set in
1860 * <var>flagsMask</var>
1861 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001862 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001863 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001864 * Context.startActivity(Intent, Bundle)} for more details. If options
1865 * have also been supplied by the IntentSender, options given here will
1866 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001867 *
1868 * @see #startActivity(Intent, Bundle)
1869 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001870 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001871 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1872 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1873 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001874
1875 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876 * Broadcast the given intent to all interested BroadcastReceivers. This
1877 * call is asynchronous; it returns immediately, and you will continue
1878 * executing while the receivers are run. No results are propagated from
1879 * receivers and receivers can not abort the broadcast. If you want
1880 * to allow receivers to propagate results or abort the broadcast, you must
1881 * send an ordered broadcast using
1882 * {@link #sendOrderedBroadcast(Intent, String)}.
1883 *
1884 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1885 *
1886 * @param intent The Intent to broadcast; all receivers matching this
1887 * Intent will receive the broadcast.
1888 *
1889 * @see android.content.BroadcastReceiver
1890 * @see #registerReceiver
1891 * @see #sendBroadcast(Intent, String)
1892 * @see #sendOrderedBroadcast(Intent, String)
1893 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1894 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001895 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896
1897 /**
1898 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1899 * an optional required permission to be enforced. This
1900 * call is asynchronous; it returns immediately, and you will continue
1901 * executing while the receivers are run. No results are propagated from
1902 * receivers and receivers can not abort the broadcast. If you want
1903 * to allow receivers to propagate results or abort the broadcast, you must
1904 * send an ordered broadcast using
1905 * {@link #sendOrderedBroadcast(Intent, String)}.
1906 *
1907 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1908 *
1909 * @param intent The Intent to broadcast; all receivers matching this
1910 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001911 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001912 * a receiver must hold in order to receive your broadcast.
1913 * If null, no permission is required.
1914 *
1915 * @see android.content.BroadcastReceiver
1916 * @see #registerReceiver
1917 * @see #sendBroadcast(Intent)
1918 * @see #sendOrderedBroadcast(Intent, String)
1919 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1920 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001921 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001922 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001924
1925 /**
1926 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1927 * an array of required permissions to be enforced. This call is asynchronous; it returns
1928 * immediately, and you will continue executing while the receivers are run. No results are
1929 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1930 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1931 * using {@link #sendOrderedBroadcast(Intent, String)}.
1932 *
1933 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1934 *
1935 * @param intent The Intent to broadcast; all receivers matching this
1936 * Intent will receive the broadcast.
1937 * @param receiverPermissions Array of names of permissions that a receiver must hold
1938 * in order to receive your broadcast.
1939 * If null or empty, no permissions are required.
1940 *
1941 * @see android.content.BroadcastReceiver
1942 * @see #registerReceiver
1943 * @see #sendBroadcast(Intent)
1944 * @see #sendOrderedBroadcast(Intent, String)
1945 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1946 * @hide
1947 */
1948 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1949 String[] receiverPermissions);
1950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001952 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1953 * an optional required permission to be enforced. This
1954 * call is asynchronous; it returns immediately, and you will continue
1955 * executing while the receivers are run. No results are propagated from
1956 * receivers and receivers can not abort the broadcast. If you want
1957 * to allow receivers to propagate results or abort the broadcast, you must
1958 * send an ordered broadcast using
1959 * {@link #sendOrderedBroadcast(Intent, String)}.
1960 *
1961 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1962 *
1963 * @param intent The Intent to broadcast; all receivers matching this
1964 * Intent will receive the broadcast.
1965 * @param receiverPermission (optional) String naming a permission that
1966 * a receiver must hold in order to receive your broadcast.
1967 * If null, no permission is required.
1968 * @param options (optional) Additional sending options, generated from a
1969 * {@link android.app.BroadcastOptions}.
1970 *
1971 * @see android.content.BroadcastReceiver
1972 * @see #registerReceiver
1973 * @see #sendBroadcast(Intent)
1974 * @see #sendOrderedBroadcast(Intent, String)
1975 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1976 * @hide
1977 */
1978 @SystemApi
1979 public abstract void sendBroadcast(Intent intent,
1980 @Nullable String receiverPermission,
1981 @Nullable Bundle options);
1982
1983 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001984 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001985 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001986 * @hide
1987 */
1988 public abstract void sendBroadcast(Intent intent,
1989 String receiverPermission, int appOp);
1990
1991 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1993 * them one at a time to allow more preferred receivers to consume the
1994 * broadcast before it is delivered to less preferred receivers. This
1995 * call is asynchronous; it returns immediately, and you will continue
1996 * executing while the receivers are run.
1997 *
1998 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1999 *
2000 * @param intent The Intent to broadcast; all receivers matching this
2001 * Intent will receive the broadcast.
2002 * @param receiverPermission (optional) String naming a permissions that
2003 * a receiver must hold in order to receive your broadcast.
2004 * If null, no permission is required.
2005 *
2006 * @see android.content.BroadcastReceiver
2007 * @see #registerReceiver
2008 * @see #sendBroadcast(Intent)
2009 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2010 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002011 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002012 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002013
2014 /**
2015 * Version of {@link #sendBroadcast(Intent)} that allows you to
2016 * receive data back from the broadcast. This is accomplished by
2017 * supplying your own BroadcastReceiver when calling, which will be
2018 * treated as a final receiver at the end of the broadcast -- its
2019 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002020 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 * be serialized in the same way as calling
2022 * {@link #sendOrderedBroadcast(Intent, String)}.
2023 *
2024 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2025 * asynchronous; it will return before
2026 * resultReceiver.onReceive() is called.
2027 *
2028 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2029 *
2030 * @param intent The Intent to broadcast; all receivers matching this
2031 * Intent will receive the broadcast.
2032 * @param receiverPermission String naming a permissions that
2033 * a receiver must hold in order to receive your broadcast.
2034 * If null, no permission is required.
2035 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2036 * receiver of the broadcast.
2037 * @param scheduler A custom Handler with which to schedule the
2038 * resultReceiver callback; if null it will be
2039 * scheduled in the Context's main thread.
2040 * @param initialCode An initial value for the result code. Often
2041 * Activity.RESULT_OK.
2042 * @param initialData An initial value for the result data. Often
2043 * null.
2044 * @param initialExtras An initial value for the result extras. Often
2045 * null.
2046 *
2047 * @see #sendBroadcast(Intent)
2048 * @see #sendBroadcast(Intent, String)
2049 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 * @see android.content.BroadcastReceiver
2051 * @see #registerReceiver
2052 * @see android.app.Activity#RESULT_OK
2053 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002054 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002055 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002056 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2057 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002058
2059 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002060 * Version of {@link #sendBroadcast(Intent)} that allows you to
2061 * receive data back from the broadcast. This is accomplished by
2062 * supplying your own BroadcastReceiver when calling, which will be
2063 * treated as a final receiver at the end of the broadcast -- its
2064 * {@link BroadcastReceiver#onReceive} method will be called with
2065 * the result values collected from the other receivers. The broadcast will
2066 * be serialized in the same way as calling
2067 * {@link #sendOrderedBroadcast(Intent, String)}.
2068 *
2069 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2070 * asynchronous; it will return before
2071 * resultReceiver.onReceive() is called.
2072 *
2073 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2074 *
2075 *
2076 * @param intent The Intent to broadcast; all receivers matching this
2077 * Intent will receive the broadcast.
2078 * @param receiverPermission String naming a permissions that
2079 * a receiver must hold in order to receive your broadcast.
2080 * If null, no permission is required.
2081 * @param options (optional) Additional sending options, generated from a
2082 * {@link android.app.BroadcastOptions}.
2083 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2084 * receiver of the broadcast.
2085 * @param scheduler A custom Handler with which to schedule the
2086 * resultReceiver callback; if null it will be
2087 * scheduled in the Context's main thread.
2088 * @param initialCode An initial value for the result code. Often
2089 * Activity.RESULT_OK.
2090 * @param initialData An initial value for the result data. Often
2091 * null.
2092 * @param initialExtras An initial value for the result extras. Often
2093 * null.
2094 * @see #sendBroadcast(Intent)
2095 * @see #sendBroadcast(Intent, String)
2096 * @see #sendOrderedBroadcast(Intent, String)
2097 * @see android.content.BroadcastReceiver
2098 * @see #registerReceiver
2099 * @see android.app.Activity#RESULT_OK
2100 * @hide
2101 */
2102 @SystemApi
2103 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2104 @Nullable String receiverPermission, @Nullable Bundle options,
2105 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2106 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2107
2108 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002109 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2110 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002111 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002112 * @hide
2113 */
2114 public abstract void sendOrderedBroadcast(Intent intent,
2115 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2116 Handler scheduler, int initialCode, String initialData,
2117 Bundle initialExtras);
2118
2119 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002120 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2121 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002122 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002123 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002124 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002125 * @see #sendBroadcast(Intent)
2126 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002127 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002128 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2129 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002130
2131 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002132 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2133 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002134 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002135 *
2136 * @param intent The Intent to broadcast; all receivers matching this
2137 * Intent will receive the broadcast.
2138 * @param user UserHandle to send the intent to.
2139 * @param receiverPermission (optional) String naming a permission that
2140 * a receiver must hold in order to receive your broadcast.
2141 * If null, no permission is required.
2142 *
2143 * @see #sendBroadcast(Intent, String)
2144 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002145 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002146 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2147 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002148
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002149 /**
2150 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2151 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002152 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002153 *
2154 * @param intent The Intent to broadcast; all receivers matching this
2155 * Intent will receive the broadcast.
2156 * @param user UserHandle to send the intent to.
2157 * @param receiverPermission (optional) String naming a permission that
2158 * a receiver must hold in order to receive your broadcast.
2159 * If null, no permission is required.
2160 * @param options (optional) Additional sending options, generated from a
2161 * {@link android.app.BroadcastOptions}.
2162 *
2163 * @see #sendBroadcast(Intent, String, Bundle)
2164 * @hide
2165 */
2166 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002167 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002168 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2169 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002170
2171 /**
2172 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2173 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002174 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002175 *
2176 * @param intent The Intent to broadcast; all receivers matching this
2177 * Intent will receive the broadcast.
2178 * @param user UserHandle to send the intent to.
2179 * @param receiverPermission (optional) String naming a permission that
2180 * a receiver must hold in order to receive your broadcast.
2181 * If null, no permission is required.
2182 * @param appOp The app op associated with the broadcast.
2183 *
2184 * @see #sendBroadcast(Intent, String)
2185 *
2186 * @hide
2187 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002188 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002189 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2190 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002191
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002192 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002193 * Version of
2194 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2195 * that allows you to specify the
2196 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002197 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002198 *
2199 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2200 *
2201 * @param intent The Intent to broadcast; all receivers matching this
2202 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002203 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002204 * @param receiverPermission String naming a permissions that
2205 * a receiver must hold in order to receive your broadcast.
2206 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002207 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2208 * receiver of the broadcast.
2209 * @param scheduler A custom Handler with which to schedule the
2210 * resultReceiver callback; if null it will be
2211 * scheduled in the Context's main thread.
2212 * @param initialCode An initial value for the result code. Often
2213 * Activity.RESULT_OK.
2214 * @param initialData An initial value for the result data. Often
2215 * null.
2216 * @param initialExtras An initial value for the result extras. Often
2217 * null.
2218 *
2219 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2220 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002221 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002222 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2223 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002224 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2225 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002226
2227 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002228 * Similar to above but takes an appOp as well, to enforce restrictions.
2229 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2230 * BroadcastReceiver, Handler, int, String, Bundle)
2231 * @hide
2232 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002233 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Amith Yamasani3cf75722014-05-16 12:37:29 -07002234 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2235 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2236 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2237 @Nullable Bundle initialExtras);
2238
2239 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002240 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2241 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2242 * BroadcastReceiver, Handler, int, String, Bundle)
2243 * @hide
2244 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002245 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002246 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2247 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2248 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2249 @Nullable String initialData, @Nullable Bundle initialExtras);
2250
2251 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002252 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002253 * Intent you are sending stays around after the broadcast is complete,
2254 * so that others can quickly retrieve that data through the return
2255 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2256 * all other ways, this behaves the same as
2257 * {@link #sendBroadcast(Intent)}.
2258 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002259 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2260 * can access them), no protection (anyone can modify them), and many other problems.
2261 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2262 * has changed, with another mechanism for apps to retrieve the current value whenever
2263 * desired.
2264 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 * @param intent The Intent to broadcast; all receivers matching this
2266 * Intent will receive the broadcast, and the Intent will be held to
2267 * be re-broadcast to future receivers.
2268 *
2269 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002270 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002271 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002272 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002273 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002274 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002275
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002276 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002277 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002278 * receive data back from the broadcast. This is accomplished by
2279 * supplying your own BroadcastReceiver when calling, which will be
2280 * treated as a final receiver at the end of the broadcast -- its
2281 * {@link BroadcastReceiver#onReceive} method will be called with
2282 * the result values collected from the other receivers. The broadcast will
2283 * be serialized in the same way as calling
2284 * {@link #sendOrderedBroadcast(Intent, String)}.
2285 *
2286 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2287 * asynchronous; it will return before
2288 * resultReceiver.onReceive() is called. Note that the sticky data
2289 * stored is only the data you initially supply to the broadcast, not
2290 * the result of any changes made by the receivers.
2291 *
2292 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2293 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002294 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2295 * can access them), no protection (anyone can modify them), and many other problems.
2296 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2297 * has changed, with another mechanism for apps to retrieve the current value whenever
2298 * desired.
2299 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002300 * @param intent The Intent to broadcast; all receivers matching this
2301 * Intent will receive the broadcast.
2302 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2303 * receiver of the broadcast.
2304 * @param scheduler A custom Handler with which to schedule the
2305 * resultReceiver callback; if null it will be
2306 * scheduled in the Context's main thread.
2307 * @param initialCode An initial value for the result code. Often
2308 * Activity.RESULT_OK.
2309 * @param initialData An initial value for the result data. Often
2310 * null.
2311 * @param initialExtras An initial value for the result extras. Often
2312 * null.
2313 *
2314 * @see #sendBroadcast(Intent)
2315 * @see #sendBroadcast(Intent, String)
2316 * @see #sendOrderedBroadcast(Intent, String)
2317 * @see #sendStickyBroadcast(Intent)
2318 * @see android.content.BroadcastReceiver
2319 * @see #registerReceiver
2320 * @see android.app.Activity#RESULT_OK
2321 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002322 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002323 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002324 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002325 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002326 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2327 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002328
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002329 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002330 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 * so that it is as if the sticky broadcast had never happened.
2332 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002333 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2334 * can access them), no protection (anyone can modify them), and many other problems.
2335 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2336 * has changed, with another mechanism for apps to retrieve the current value whenever
2337 * desired.
2338 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002339 * @param intent The Intent that was previously broadcast.
2340 *
2341 * @see #sendStickyBroadcast
2342 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002343 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002344 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002345 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002346
2347 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002348 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002349 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002350 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002351 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002352 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2353 * can access them), no protection (anyone can modify them), and many other problems.
2354 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2355 * has changed, with another mechanism for apps to retrieve the current value whenever
2356 * desired.
2357 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002358 * @param intent The Intent to broadcast; all receivers matching this
2359 * Intent will receive the broadcast, and the Intent will be held to
2360 * be re-broadcast to future receivers.
2361 * @param user UserHandle to send the intent to.
2362 *
2363 * @see #sendBroadcast(Intent)
2364 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002365 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002366 @RequiresPermission(allOf = {
2367 android.Manifest.permission.INTERACT_ACROSS_USERS,
2368 android.Manifest.permission.BROADCAST_STICKY
2369 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002370 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2371 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002372
2373 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002374 * @hide
2375 * This is just here for sending CONNECTIVITY_ACTION.
2376 */
2377 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002378 @RequiresPermission(allOf = {
2379 android.Manifest.permission.INTERACT_ACROSS_USERS,
2380 android.Manifest.permission.BROADCAST_STICKY
2381 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002382 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2383 UserHandle user, Bundle options);
2384
2385 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002386 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002387 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2388 * that allows you to specify the
2389 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002390 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002391 *
2392 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2393 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002394 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2395 * can access them), no protection (anyone can modify them), and many other problems.
2396 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2397 * has changed, with another mechanism for apps to retrieve the current value whenever
2398 * desired.
2399 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002400 * @param intent The Intent to broadcast; all receivers matching this
2401 * Intent will receive the broadcast.
2402 * @param user UserHandle to send the intent to.
2403 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2404 * receiver of the broadcast.
2405 * @param scheduler A custom Handler with which to schedule the
2406 * resultReceiver callback; if null it will be
2407 * scheduled in the Context's main thread.
2408 * @param initialCode An initial value for the result code. Often
2409 * Activity.RESULT_OK.
2410 * @param initialData An initial value for the result data. Often
2411 * null.
2412 * @param initialExtras An initial value for the result extras. Often
2413 * null.
2414 *
2415 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2416 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002417 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002418 @RequiresPermission(allOf = {
2419 android.Manifest.permission.INTERACT_ACROSS_USERS,
2420 android.Manifest.permission.BROADCAST_STICKY
2421 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002422 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002423 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002424 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2425 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002426
2427 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002428 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002429 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002430 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002431 *
2432 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2433 * permission in order to use this API. If you do not hold that
2434 * permission, {@link SecurityException} will be thrown.
2435 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002436 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2437 * can access them), no protection (anyone can modify them), and many other problems.
2438 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2439 * has changed, with another mechanism for apps to retrieve the current value whenever
2440 * desired.
2441 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002442 * @param intent The Intent that was previously broadcast.
2443 * @param user UserHandle to remove the sticky broadcast from.
2444 *
2445 * @see #sendStickyBroadcastAsUser
2446 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002447 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002448 @RequiresPermission(allOf = {
2449 android.Manifest.permission.INTERACT_ACROSS_USERS,
2450 android.Manifest.permission.BROADCAST_STICKY
2451 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002452 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2453 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002454
2455 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002456 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 * <var>receiver</var> will be called with any broadcast Intent that
2458 * matches <var>filter</var>, in the main application thread.
2459 *
2460 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002461 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002462 * registrations. If your IntentFilter matches one of these sticky
2463 * Intents, that Intent will be returned by this function
2464 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2465 * been broadcast.
2466 *
2467 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2468 * in which case each of these will be sent to <var>receiver</var>. In
2469 * this case, only one of these can be returned directly by the function;
2470 * which of these that is returned is arbitrarily decided by the system.
2471 *
2472 * <p>If you know the Intent your are registering for is sticky, you can
2473 * supply null for your <var>receiver</var>. In this case, no receiver is
2474 * registered -- the function simply returns the sticky Intent that
2475 * matches <var>filter</var>. In the case of multiple matches, the same
2476 * rules as described above apply.
2477 *
2478 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2479 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002480 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2481 * registered with this method will correctly respect the
2482 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2483 * Prior to that, it would be ignored and delivered to all matching registered
2484 * receivers. Be careful if using this for security.</p>
2485 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002486 * <p class="note">Note: this method <em>cannot be called from a
2487 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2488 * that is declared in an application's manifest. It is okay, however, to call
2489 * this method from another BroadcastReceiver that has itself been registered
2490 * at run time with {@link #registerReceiver}, since the lifetime of such a
2491 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 *
2493 * @param receiver The BroadcastReceiver to handle the broadcast.
2494 * @param filter Selects the Intent broadcasts to be received.
2495 *
2496 * @return The first sticky intent found that matches <var>filter</var>,
2497 * or null if there are none.
2498 *
2499 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2500 * @see #sendBroadcast
2501 * @see #unregisterReceiver
2502 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002503 @Nullable
2504 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002505 IntentFilter filter);
2506
2507 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002508 * Register to receive intent broadcasts, with the receiver optionally being
2509 * exposed to Instant Apps. See
2510 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2511 * information. By default Instant Apps cannot interact with receivers in other
2512 * applications, this allows you to expose a receiver that Instant Apps can
2513 * interact with.
2514 *
2515 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2516 *
2517 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2518 * registered with this method will correctly respect the
2519 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2520 * Prior to that, it would be ignored and delivered to all matching registered
2521 * receivers. Be careful if using this for security.</p>
2522 *
2523 * @param receiver The BroadcastReceiver to handle the broadcast.
2524 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002525 * @param flags Additional options for the receiver. May be 0 or
2526 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002527 *
2528 * @return The first sticky intent found that matches <var>filter</var>,
2529 * or null if there are none.
2530 *
2531 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2532 * @see #sendBroadcast
2533 * @see #unregisterReceiver
2534 */
2535 @Nullable
2536 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2537 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002538 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002539
2540 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002541 * Register to receive intent broadcasts, to run in the context of
2542 * <var>scheduler</var>. See
2543 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2544 * information. This allows you to enforce permissions on who can
2545 * broadcast intents to your receiver, or have the receiver run in
2546 * a different thread than the main application thread.
2547 *
2548 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2549 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002550 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2551 * registered with this method will correctly respect the
2552 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2553 * Prior to that, it would be ignored and delivered to all matching registered
2554 * receivers. Be careful if using this for security.</p>
2555 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 * @param receiver The BroadcastReceiver to handle the broadcast.
2557 * @param filter Selects the Intent broadcasts to be received.
2558 * @param broadcastPermission String naming a permissions that a
2559 * broadcaster must hold in order to send an Intent to you. If null,
2560 * no permission is required.
2561 * @param scheduler Handler identifying the thread that will receive
2562 * the Intent. If null, the main thread of the process will be used.
2563 *
2564 * @return The first sticky intent found that matches <var>filter</var>,
2565 * or null if there are none.
2566 *
2567 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2568 * @see #sendBroadcast
2569 * @see #unregisterReceiver
2570 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002571 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002573 IntentFilter filter, @Nullable String broadcastPermission,
2574 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002575
2576 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002577 * Register to receive intent broadcasts, to run in the context of
2578 * <var>scheduler</var>. See
2579 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002580 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2581 * for more information.
2582 *
2583 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2584 *
2585 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2586 * registered with this method will correctly respect the
2587 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2588 * Prior to that, it would be ignored and delivered to all matching registered
2589 * receivers. Be careful if using this for security.</p>
2590 *
2591 * @param receiver The BroadcastReceiver to handle the broadcast.
2592 * @param filter Selects the Intent broadcasts to be received.
2593 * @param broadcastPermission String naming a permissions that a
2594 * broadcaster must hold in order to send an Intent to you. If null,
2595 * no permission is required.
2596 * @param scheduler Handler identifying the thread that will receive
2597 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002598 * @param flags Additional options for the receiver. May be 0 or
2599 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002600 *
2601 * @return The first sticky intent found that matches <var>filter</var>,
2602 * or null if there are none.
2603 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002604 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002605 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2606 * @see #sendBroadcast
2607 * @see #unregisterReceiver
2608 */
2609 @Nullable
2610 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2611 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002612 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002613
2614 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002615 * @hide
2616 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2617 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002618 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002619 *
2620 * @param receiver The BroadcastReceiver to handle the broadcast.
2621 * @param user UserHandle to send the intent to.
2622 * @param filter Selects the Intent broadcasts to be received.
2623 * @param broadcastPermission String naming a permissions that a
2624 * broadcaster must hold in order to send an Intent to you. If null,
2625 * no permission is required.
2626 * @param scheduler Handler identifying the thread that will receive
2627 * the Intent. If null, the main thread of the process will be used.
2628 *
2629 * @return The first sticky intent found that matches <var>filter</var>,
2630 * or null if there are none.
2631 *
Jeff Brown6e539312015-02-24 18:53:21 -08002632 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002633 * @see #sendBroadcast
2634 * @see #unregisterReceiver
2635 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002636 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002637 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002638 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002639 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2640 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641
2642 /**
2643 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2644 * filters that have been registered for this BroadcastReceiver will be
2645 * removed.
2646 *
2647 * @param receiver The BroadcastReceiver to unregister.
2648 *
2649 * @see #registerReceiver
2650 */
2651 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2652
2653 /**
2654 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002655 * should either contain the complete class name of a specific service
2656 * implementation to start, or a specific package name to target. If the
2657 * Intent is less specified, it logs a warning about this. In this case any of the
2658 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 * is not already running, it will be instantiated and started (creating a
2660 * process for it if needed); if it is running then it remains running.
2661 *
2662 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002663 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002664 * with the <var>intent</var> given here. This provides a convenient way
2665 * to submit jobs to a service without having to bind and call on to its
2666 * interface.
2667 *
2668 * <p>Using startService() overrides the default service lifetime that is
2669 * managed by {@link #bindService}: it requires the service to remain
2670 * running until {@link #stopService} is called, regardless of whether
2671 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002672 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002673 * a single call to {@link #stopService} will stop it.
2674 *
2675 * <p>The system attempts to keep running services around as much as
2676 * possible. The only time they should be stopped is if the current
2677 * foreground application is using so many resources that the service needs
2678 * to be killed. If any errors happen in the service's process, it will
2679 * automatically be restarted.
2680 *
2681 * <p>This function will throw {@link SecurityException} if you do not
2682 * have permission to start the given service.
2683 *
Chris Craik1e353522016-04-18 10:20:50 -07002684 * <p class="note"><strong>Note:</strong> Each call to startService()
2685 * results in significant work done by the system to manage service
2686 * lifecycle surrounding the processing of the intent, which can take
2687 * multiple milliseconds of CPU time. Due to this cost, startService()
2688 * should not be used for frequent intent delivery to a service, and only
2689 * for scheduling significant work. Use {@link #bindService bound services}
2690 * for high frequency calls.
2691 * </p>
2692 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002693 * @param service Identifies the service to be started. The Intent must be
2694 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 * may be included in the Intent extras to supply arguments along with
2696 * this specific start call.
2697 *
2698 * @return If the service is being started or is already running, the
2699 * {@link ComponentName} of the actual service that was started is
2700 * returned; else if the service does not exist null is returned.
2701 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002702 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002703 * or the service can not be found.
2704 * @throws IllegalStateException If the application is in a state where the service
2705 * can not be started (such as not in the foreground in a state when services are allowed).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002706 *
2707 * @see #stopService
2708 * @see #bindService
2709 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002710 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002711 public abstract ComponentName startService(Intent service);
2712
2713 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002714 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Ian Pedowitz4e9806c2017-08-11 14:23:17 -07002715 * Service will call {@link android.app.Service#startForeground(int, Notification)
2716 * startForeground(int, Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002717 * an amount of time comparable to the ANR interval to do this, otherwise the system
2718 * will automatically stop the service and declare the app ANR.
2719 *
2720 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2721 * at any time, regardless of whether the app hosting the service is in a foreground
2722 * state.
2723 *
2724 * @param service Identifies the service to be started. The Intent must be
2725 * fully explicit (supplying a component name). Additional values
2726 * may be included in the Intent extras to supply arguments along with
2727 * this specific start call.
2728 *
2729 * @return If the service is being started or is already running, the
2730 * {@link ComponentName} of the actual service that was started is
2731 * returned; else if the service does not exist null is returned.
2732 *
2733 * @throws SecurityException If the caller does not have permission to access the service
2734 * or the service can not be found.
2735 *
2736 * @see #stopService
Ian Pedowitz4e9806c2017-08-11 14:23:17 -07002737 * @see android.app.Service#startForeground(int, Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002738 */
2739 @Nullable
2740 public abstract ComponentName startForegroundService(Intent service);
2741
2742 /**
2743 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2744 */
2745 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002746 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002747 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2748
2749 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 * Request that a given application service be stopped. If the service is
2751 * not running, nothing happens. Otherwise it is stopped. Note that calls
2752 * to startService() are not counted -- this stops the service no matter
2753 * how many times it was started.
2754 *
2755 * <p>Note that if a stopped service still has {@link ServiceConnection}
2756 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2757 * not be destroyed until all of these bindings are removed. See
2758 * the {@link android.app.Service} documentation for more details on a
2759 * service's lifecycle.
2760 *
2761 * <p>This function will throw {@link SecurityException} if you do not
2762 * have permission to stop the given service.
2763 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002764 * @param service Description of the service to be stopped. The Intent must be either
2765 * fully explicit (supplying a component name) or specify a specific package
2766 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002767 *
2768 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002769 * 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 -08002770 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002771 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002772 * or the service can not be found.
2773 * @throws IllegalStateException If the application is in a state where the service
2774 * can not be started (such as not in the foreground in a state when services are allowed).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 *
2776 * @see #startService
2777 */
2778 public abstract boolean stopService(Intent service);
2779
2780 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002781 * @hide like {@link #startService(Intent)} but for a specific user.
2782 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002783 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002784 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002785 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2786
2787 /**
2788 * @hide like {@link #stopService(Intent)} but for a specific user.
2789 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002790 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002791 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002792
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002793 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002794 * Connect to an application service, creating it if needed. This defines
2795 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002796 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 * told if it dies and restarts. The service will be considered required
2798 * by the system only for as long as the calling context exists. For
2799 * example, if this Context is an Activity that is stopped, the service will
2800 * not be required to continue running until the Activity is resumed.
2801 *
2802 * <p>This function will throw {@link SecurityException} if you do not
2803 * have permission to bind to the given service.
2804 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002805 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002807 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 * {@link #startService} with the arguments containing the command to be
2809 * sent, with the service calling its
2810 * {@link android.app.Service#stopSelf(int)} method when done executing
2811 * that command. See the API demo App/Service/Service Start Arguments
2812 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002813 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002814 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2815 * is tied to another object (the one that registered it).</p>
2816 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002817 * @param service Identifies the service to connect to. The Intent must
2818 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002820 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002821 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002822 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2823 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2824 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2825 * {@link #BIND_WAIVE_PRIORITY}.
John Spurlock6098c5d2013-06-17 10:32:46 -04002826 * @return If you have successfully bound to the service, {@code true} is returned;
2827 * {@code false} is returned if the connection is not made so you will not
Andrew Solovay2b035112017-04-07 15:38:33 -07002828 * receive the service object. However, you should still call
2829 * {@link #unbindService} to release the connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002831 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002832 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 *
2834 * @see #unbindService
2835 * @see #startService
2836 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002837 * @see #BIND_DEBUG_UNBIND
2838 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002840 public abstract boolean bindService(@RequiresPermission Intent service,
2841 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842
2843 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002844 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002845 * argument for use by system server and other multi-user aware code.
2846 * @hide
2847 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002848 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002849 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002850 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002851 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002852 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002853 throw new RuntimeException("Not implemented. Must override in a subclass.");
2854 }
2855
2856 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002857 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2858 * explicit non-null Handler to run the ServiceConnection callbacks on.
2859 *
2860 * @hide
2861 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002862 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Adrian Roos691546e2016-02-09 10:13:41 -08002863 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2864 Handler handler, UserHandle user) {
2865 throw new RuntimeException("Not implemented. Must override in a subclass.");
2866 }
2867
2868 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002869 * Disconnect from an application service. You will no longer receive
2870 * calls as the service is restarted, and the service is now allowed to
2871 * stop at any time.
2872 *
2873 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002874 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002875 *
2876 * @see #bindService
2877 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002878 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879
2880 /**
2881 * Start executing an {@link android.app.Instrumentation} class. The given
2882 * Instrumentation component will be run by killing its target application
2883 * (if currently running), starting the target process, instantiating the
2884 * instrumentation component, and then letting it drive the application.
2885 *
2886 * <p>This function is not synchronous -- it returns as soon as the
2887 * instrumentation has started and while it is running.
2888 *
2889 * <p>Instrumentation is normally only allowed to run against a package
2890 * that is either unsigned or signed with a signature that the
2891 * the instrumentation package is also signed with (ensuring the target
2892 * trusts the instrumentation).
2893 *
2894 * @param className Name of the Instrumentation component to be run.
2895 * @param profileFile Optional path to write profiling data as the
2896 * instrumentation runs, or null for no profiling.
2897 * @param arguments Additional optional arguments to pass to the
2898 * instrumentation, or null.
2899 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002900 * @return {@code true} if the instrumentation was successfully started,
2901 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002902 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002903 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2904 @Nullable String profileFile, @Nullable Bundle arguments);
2905
2906 /** @hide */
2907 @StringDef({
2908 POWER_SERVICE,
2909 WINDOW_SERVICE,
2910 LAYOUT_INFLATER_SERVICE,
2911 ACCOUNT_SERVICE,
2912 ACTIVITY_SERVICE,
2913 ALARM_SERVICE,
2914 NOTIFICATION_SERVICE,
2915 ACCESSIBILITY_SERVICE,
2916 CAPTIONING_SERVICE,
2917 KEYGUARD_SERVICE,
2918 LOCATION_SERVICE,
2919 //@hide: COUNTRY_DETECTOR,
2920 SEARCH_SERVICE,
2921 SENSOR_SERVICE,
2922 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07002923 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002924 WALLPAPER_SERVICE,
2925 VIBRATOR_SERVICE,
2926 //@hide: STATUS_BAR_SERVICE,
2927 CONNECTIVITY_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08002928 IPSEC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002929 //@hide: UPDATE_LOCK_SERVICE,
2930 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002931 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002932 //@hide: NETWORK_POLICY_SERVICE,
2933 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07002934 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002935 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002936 WIFI_SCANNING_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002937 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002938 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002939 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002940 NSD_SERVICE,
2941 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002942 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002943 MEDIA_ROUTER_SERVICE,
2944 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002945 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002946 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002947 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002948 CLIPBOARD_SERVICE,
2949 INPUT_METHOD_SERVICE,
2950 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01002951 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002952 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002953 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002954 //@hide: BACKUP_SERVICE,
2955 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07002956 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07002957 DEVICE_POLICY_SERVICE,
2958 UI_MODE_SERVICE,
2959 DOWNLOAD_SERVICE,
2960 NFC_SERVICE,
2961 BLUETOOTH_SERVICE,
2962 //@hide: SIP_SERVICE,
2963 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002964 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002965 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002966 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002967 INPUT_SERVICE,
2968 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002969 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002970 RESTRICTIONS_SERVICE,
2971 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002972 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002973 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002974 CONSUMER_IR_SERVICE,
2975 //@hide: TRUST_SERVICE,
2976 TV_INPUT_SERVICE,
2977 //@hide: NETWORK_SCORE_SERVICE,
2978 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002979 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002980 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002981 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002982 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00002983 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002984 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002985 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002986 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002987 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08002988 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08002989 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08002990 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08002991 SYSTEM_HEALTH_SERVICE,
2992 //@hide: INCIDENT_SERVICE
Tor Norbyed9273d62013-05-30 15:59:53 -07002993 })
2994 @Retention(RetentionPolicy.SOURCE)
2995 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996
2997 /**
2998 * Return the handle to a system-level service by name. The class of the
2999 * returned object varies by the requested name. Currently available names
3000 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003001 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 * <dl>
3003 * <dt> {@link #WINDOW_SERVICE} ("window")
3004 * <dd> The top-level window manager in which you can place custom
3005 * windows. The returned object is a {@link android.view.WindowManager}.
3006 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3007 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3008 * in this context.
3009 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3010 * <dd> A {@link android.app.ActivityManager} for interacting with the
3011 * global activity state of the system.
3012 * <dt> {@link #POWER_SERVICE} ("power")
3013 * <dd> A {@link android.os.PowerManager} for controlling power
3014 * management.
3015 * <dt> {@link #ALARM_SERVICE} ("alarm")
3016 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3017 * time of your choosing.
3018 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3019 * <dd> A {@link android.app.NotificationManager} for informing the user
3020 * of background events.
3021 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3022 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3023 * <dt> {@link #LOCATION_SERVICE} ("location")
3024 * <dd> A {@link android.location.LocationManager} for controlling location
3025 * (e.g., GPS) updates.
3026 * <dt> {@link #SEARCH_SERVICE} ("search")
3027 * <dd> A {@link android.app.SearchManager} for handling search.
3028 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3029 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3030 * hardware.
3031 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3032 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3033 * handling management of network connections.
3034 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003035 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3036 * connectivity. On releases before NYC, it should only be obtained from an application
3037 * context, and not from any other derived context to avoid memory leaks within the calling
3038 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003039 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3040 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3041 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003042 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3043 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3044 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003045 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3046 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3047 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003048 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3049 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003050 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003051 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003052 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003053 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003054 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3055 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003056 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3057 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3058 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003059 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003060 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003061 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003062 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003063 * <p>Note: System services obtained via this API may be closely associated with
3064 * the Context in which they are obtained from. In general, do not share the
3065 * service objects between various different contexts (Activities, Applications,
3066 * Services, Providers, etc.)
3067 *
3068 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003069 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003070 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003071 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003072 * @see #WINDOW_SERVICE
3073 * @see android.view.WindowManager
3074 * @see #LAYOUT_INFLATER_SERVICE
3075 * @see android.view.LayoutInflater
3076 * @see #ACTIVITY_SERVICE
3077 * @see android.app.ActivityManager
3078 * @see #POWER_SERVICE
3079 * @see android.os.PowerManager
3080 * @see #ALARM_SERVICE
3081 * @see android.app.AlarmManager
3082 * @see #NOTIFICATION_SERVICE
3083 * @see android.app.NotificationManager
3084 * @see #KEYGUARD_SERVICE
3085 * @see android.app.KeyguardManager
3086 * @see #LOCATION_SERVICE
3087 * @see android.location.LocationManager
3088 * @see #SEARCH_SERVICE
3089 * @see android.app.SearchManager
3090 * @see #SENSOR_SERVICE
3091 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003092 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003093 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003094 * @see #VIBRATOR_SERVICE
3095 * @see android.os.Vibrator
3096 * @see #CONNECTIVITY_SERVICE
3097 * @see android.net.ConnectivityManager
3098 * @see #WIFI_SERVICE
3099 * @see android.net.wifi.WifiManager
3100 * @see #AUDIO_SERVICE
3101 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003102 * @see #MEDIA_ROUTER_SERVICE
3103 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 * @see #TELEPHONY_SERVICE
3105 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003106 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3107 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003108 * @see #CARRIER_CONFIG_SERVICE
3109 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003110 * @see #INPUT_METHOD_SERVICE
3111 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003112 * @see #UI_MODE_SERVICE
3113 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003114 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003115 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003116 * @see #BATTERY_SERVICE
3117 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003118 * @see #JOB_SCHEDULER_SERVICE
3119 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003120 * @see #NETWORK_STATS_SERVICE
3121 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003122 * @see android.os.HardwarePropertiesManager
3123 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003124 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003125 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003126
3127 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003128 * Return the handle to a system-level service by class.
3129 * <p>
3130 * Currently available classes are:
3131 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3132 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3133 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3134 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3135 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3136 * {@link android.net.ConnectivityManager},
3137 * {@link android.net.wifi.WifiManager},
3138 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3139 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3140 * {@link android.view.inputmethod.InputMethodManager},
3141 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003142 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3143 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08003144 * </p><p>
3145 * Note: System services obtained via this API may be closely associated with
3146 * the Context in which they are obtained from. In general, do not share the
3147 * service objects between various different contexts (Activities, Applications,
3148 * Services, Providers, etc.)
3149 * </p>
3150 *
3151 * @param serviceClass The class of the desired service.
3152 * @return The service or null if the class is not a supported system service.
3153 */
3154 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003155 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003156 // Because subclasses may override getSystemService(String) we cannot
3157 // perform a lookup by class alone. We must first map the class to its
3158 // service name then invoke the string-based method.
3159 String serviceName = getSystemServiceName(serviceClass);
3160 return serviceName != null ? (T)getSystemService(serviceName) : null;
3161 }
3162
3163 /**
3164 * Gets the name of the system-level service that is represented by the specified class.
3165 *
3166 * @param serviceClass The class of the desired service.
3167 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003168 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003169 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003170
3171 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003172 * Use with {@link #getSystemService} to retrieve a
3173 * {@link android.os.PowerManager} for controlling power management,
3174 * including "wake locks," which let you keep the device on while
3175 * you're running long tasks.
3176 */
3177 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003179 /**
3180 * Use with {@link #getSystemService} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003181 * {@link android.os.RecoverySystem} for accessing the recovery system
3182 * service.
3183 *
3184 * @see #getSystemService
3185 * @hide
3186 */
3187 public static final String RECOVERY_SERVICE = "recovery";
3188
3189 /**
3190 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 * {@link android.view.WindowManager} for accessing the system's window
3192 * manager.
3193 *
3194 * @see #getSystemService
3195 * @see android.view.WindowManager
3196 */
3197 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003199 /**
3200 * Use with {@link #getSystemService} to retrieve a
3201 * {@link android.view.LayoutInflater} for inflating layout resources in this
3202 * context.
3203 *
3204 * @see #getSystemService
3205 * @see android.view.LayoutInflater
3206 */
3207 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003208
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003209 /**
3210 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003211 * {@link android.accounts.AccountManager} for receiving intents at a
3212 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003213 *
3214 * @see #getSystemService
3215 * @see android.accounts.AccountManager
3216 */
3217 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003218
Fred Quintana60307342009-03-24 22:48:12 -07003219 /**
3220 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003221 * {@link android.app.ActivityManager} for interacting with the global
3222 * system state.
3223 *
3224 * @see #getSystemService
3225 * @see android.app.ActivityManager
3226 */
3227 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003229 /**
3230 * Use with {@link #getSystemService} to retrieve a
3231 * {@link android.app.AlarmManager} for receiving intents at a
3232 * time of your choosing.
3233 *
3234 * @see #getSystemService
3235 * @see android.app.AlarmManager
3236 */
3237 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 /**
3240 * Use with {@link #getSystemService} to retrieve a
3241 * {@link android.app.NotificationManager} for informing the user of
3242 * background events.
3243 *
3244 * @see #getSystemService
3245 * @see android.app.NotificationManager
3246 */
3247 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003249 /**
3250 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003251 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3252 * feedback for UI events through the registered event listeners.
3253 *
3254 * @see #getSystemService
3255 * @see android.view.accessibility.AccessibilityManager
3256 */
3257 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003258
svetoslavganov75986cf2009-05-14 22:28:01 -07003259 /**
3260 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003261 * {@link android.view.accessibility.CaptioningManager} for obtaining
3262 * captioning properties and listening for changes in captioning
3263 * preferences.
3264 *
3265 * @see #getSystemService
3266 * @see android.view.accessibility.CaptioningManager
3267 */
3268 public static final String CAPTIONING_SERVICE = "captioning";
3269
3270 /**
3271 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 * {@link android.app.NotificationManager} for controlling keyguard.
3273 *
3274 * @see #getSystemService
3275 * @see android.app.KeyguardManager
3276 */
3277 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 /**
3280 * Use with {@link #getSystemService} to retrieve a {@link
3281 * android.location.LocationManager} for controlling location
3282 * updates.
3283 *
3284 * @see #getSystemService
3285 * @see android.location.LocationManager
3286 */
3287 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003288
3289 /**
3290 * Use with {@link #getSystemService} to retrieve a
3291 * {@link android.location.CountryDetector} for detecting the country that
3292 * the user is in.
3293 *
3294 * @hide
3295 */
3296 public static final String COUNTRY_DETECTOR = "country_detector";
3297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 /**
3299 * Use with {@link #getSystemService} to retrieve a {@link
3300 * android.app.SearchManager} for handling searches.
3301 *
3302 * @see #getSystemService
3303 * @see android.app.SearchManager
3304 */
3305 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003307 /**
3308 * Use with {@link #getSystemService} to retrieve a {@link
3309 * android.hardware.SensorManager} for accessing sensors.
3310 *
3311 * @see #getSystemService
3312 * @see android.hardware.SensorManager
3313 */
3314 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 /**
San Mehatc9d81752010-02-01 10:23:27 -08003317 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003318 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003319 * functions.
3320 *
3321 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08003322 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003323 */
3324 public static final String STORAGE_SERVICE = "storage";
3325
3326 /**
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003327 * Use with {@link #getSystemService} to retrieve a {@link
3328 * android.app.usage.StorageStatsManager} for accessing system storage
3329 * statistics.
3330 *
3331 * @see #getSystemService
3332 * @see android.app.usage.StorageStatsManager
3333 */
3334 public static final String STORAGE_STATS_SERVICE = "storagestats";
3335
3336 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003337 * Use with {@link #getSystemService} to retrieve a
3338 * com.android.server.WallpaperService for accessing wallpapers.
3339 *
3340 * @see #getSystemService
3341 */
3342 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003343
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344 /**
3345 * Use with {@link #getSystemService} to retrieve a {@link
3346 * android.os.Vibrator} for interacting with the vibration hardware.
3347 *
3348 * @see #getSystemService
3349 * @see android.os.Vibrator
3350 */
3351 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003352
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003353 /**
3354 * Use with {@link #getSystemService} to retrieve a {@link
3355 * android.app.StatusBarManager} for interacting with the status bar.
3356 *
3357 * @see #getSystemService
3358 * @see android.app.StatusBarManager
3359 * @hide
3360 */
3361 public static final String STATUS_BAR_SERVICE = "statusbar";
3362
3363 /**
3364 * Use with {@link #getSystemService} to retrieve a {@link
3365 * android.net.ConnectivityManager} for handling management of
3366 * network connections.
3367 *
3368 * @see #getSystemService
3369 * @see android.net.ConnectivityManager
3370 */
3371 public static final String CONNECTIVITY_SERVICE = "connectivity";
3372
3373 /**
Nathan Harold330e1082017-01-12 18:38:57 -08003374 * Use with {@link #getSystemService} to retrieve a
3375 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3376 * IPSec.
3377 *
Nathan Haroldac11ccb2017-04-25 14:21:52 -07003378 * @hide
Nathan Harold330e1082017-01-12 18:38:57 -08003379 * @see #getSystemService
3380 */
3381 public static final String IPSEC_SERVICE = "ipsec";
3382
3383 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003385 * android.os.IUpdateLock} for managing runtime sequences that
3386 * must not be interrupted by headless OTA application or similar.
3387 *
3388 * @hide
3389 * @see #getSystemService
3390 * @see android.os.UpdateLock
3391 */
3392 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3393
3394 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003395 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003396 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003397 */
3398 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3399
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003400 /**
3401 * Use with {@link #getSystemService} to retrieve a {@link
3402 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3403 *
3404 * @see #getSystemService
3405 * @see android.app.usage.NetworkStatsManager
3406 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003407 public static final String NETWORK_STATS_SERVICE = "netstats";
3408 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003409 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
3410
San Mehatd1df8ac2010-01-26 06:17:26 -08003411 /**
3412 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 * android.net.wifi.WifiManager} for handling management of
3414 * Wi-Fi access.
3415 *
3416 * @see #getSystemService
3417 * @see android.net.wifi.WifiManager
3418 */
3419 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003421 /**
repo sync55bc5f32011-06-24 14:23:07 -07003422 * Use with {@link #getSystemService} to retrieve a {@link
3423 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003424 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003425 *
3426 * @see #getSystemService
3427 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003428 */
3429 public static final String WIFI_P2P_SERVICE = "wifip2p";
3430
3431 /**
Etan Cohen20d329b2015-09-29 13:49:02 -07003432 * Use with {@link #getSystemService} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003433 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3434 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003435 *
3436 * @see #getSystemService
Etan Cohen04133272016-10-26 11:22:06 -07003437 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003438 */
Etan Cohen04133272016-10-26 11:22:06 -07003439 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003440
3441 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003442 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003443 * android.net.wifi.WifiScanner} for scanning the wifi universe
3444 *
3445 * @see #getSystemService
3446 * @see android.net.wifi.WifiScanner
3447 * @hide
3448 */
Wei Wang35d552f2014-07-08 21:37:01 -07003449 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003450 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3451
3452 /**
3453 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003454 * android.net.wifi.RttManager} for ranging devices with wifi
3455 *
3456 * @see #getSystemService
3457 * @see android.net.wifi.RttManager
3458 * @hide
3459 */
3460 @SystemApi
3461 public static final String WIFI_RTT_SERVICE = "rttmanager";
3462
3463 /**
3464 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003465 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003466 * Ethernet access.
3467 *
3468 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003469 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003470 *
3471 * @hide
3472 */
3473 public static final String ETHERNET_SERVICE = "ethernet";
3474
3475 /**
3476 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003477 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003478 * discovery
3479 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003480 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003481 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003482 */
3483 public static final String NSD_SERVICE = "servicediscovery";
3484
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003485 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003486 * Use with {@link #getSystemService} to retrieve a
3487 * {@link android.media.AudioManager} for handling management of volume,
3488 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003489 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 * @see #getSystemService
3491 * @see android.media.AudioManager
3492 */
3493 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003494
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 /**
3496 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003497 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003498 * of fingerprints.
3499 *
3500 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07003501 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003502 */
3503 public static final String FINGERPRINT_SERVICE = "fingerprint";
3504
3505 /**
3506 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003507 * {@link android.media.MediaRouter} for controlling and managing
3508 * routing of media.
3509 *
3510 * @see #getSystemService
3511 * @see android.media.MediaRouter
3512 */
3513 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3514
3515 /**
3516 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003517 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003518 *
3519 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07003520 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003521 */
3522 public static final String MEDIA_SESSION_SERVICE = "media_session";
3523
3524 /**
3525 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526 * {@link android.telephony.TelephonyManager} for handling management the
3527 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003528 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003529 * @see #getSystemService
3530 * @see android.telephony.TelephonyManager
3531 */
3532 public static final String TELEPHONY_SERVICE = "phone";
3533
3534 /**
3535 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003536 * {@link android.telephony.SubscriptionManager} for handling management the
3537 * telephony subscriptions of the device.
3538 *
3539 * @see #getSystemService
3540 * @see android.telephony.SubscriptionManager
3541 */
3542 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3543
3544 /**
3545 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003546 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003547 * of the device.
3548 *
3549 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003550 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003551 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003552 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003553
3554 /**
3555 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003556 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3557 *
3558 * @see #getSystemService
3559 * @see android.telephony.CarrierConfigManager
3560 */
3561 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3562
3563 /**
3564 * Use with {@link #getSystemService} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08003565 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
3566 *
3567 * @see #getSystemService
3568 * @see android.telephony.euicc.EuiccManager
3569 * TODO(b/35851809): Unhide this API.
3570 * @hide
3571 */
3572 public static final String EUICC_SERVICE = "euicc_service";
3573
3574 /**
3575 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003576 * {@link android.text.ClipboardManager} for accessing and modifying
Jeff Brown6e539312015-02-24 18:53:21 -08003577 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003579 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003580 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003581 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 */
3583 public static final String CLIPBOARD_SERVICE = "clipboard";
3584
3585 /**
Scott Main4b5da682010-10-21 11:49:12 -07003586 * Use with {@link #getSystemService} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003587 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003588 *
3589 * @see #getSystemService
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003590 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003591 */
3592 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
3593
3594 /**
3595 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003596 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3597 * methods.
3598 *
3599 * @see #getSystemService
3600 */
3601 public static final String INPUT_METHOD_SERVICE = "input_method";
3602
3603 /**
3604 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09003605 * {@link android.view.textservice.TextServicesManager} for accessing
3606 * text services.
3607 *
3608 * @see #getSystemService
3609 */
3610 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3611
3612 /**
3613 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003614 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003615 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 * @see #getSystemService
3617 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003618 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003619
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003621 * Official published name of the (internal) voice interaction manager service.
3622 *
3623 * @hide
3624 * @see #getSystemService
3625 */
3626 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3627
3628 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08003629 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07003630 *
3631 * @hide
3632 * @see #getSystemService
3633 */
Felipe Leme640f30a2017-03-06 15:44:06 -08003634 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07003635
3636 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003637 * Use with {@link #getSystemService} to access the
3638 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3639 *
3640 * @hide
3641 * @see #getSystemService
3642 */
3643 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3644
3645
3646 /**
Christopher Tate487529a2009-04-29 14:03:25 -07003647 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003648 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003649 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003650 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003651 *
Christopher Tate487529a2009-04-29 14:03:25 -07003652 * @see #getSystemService
3653 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003654 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003655 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003656
3657 /**
3658 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003659 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003660 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07003661 * @see #getSystemService
3662 */
3663 public static final String DROPBOX_SERVICE = "dropbox";
3664
Christopher Tate487529a2009-04-29 14:03:25 -07003665 /**
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003666 * System service name for the DeviceIdleController. There is no Java API for this.
3667 * @see #getSystemService
3668 * @hide
3669 */
3670 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3671
3672 /**
Scott Main4b5da682010-10-21 11:49:12 -07003673 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003674 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003675 * device policy management.
3676 *
3677 * @see #getSystemService
3678 */
3679 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3680
3681 /**
Tobias Haamel53332882010-02-18 16:15:43 -08003682 * Use with {@link #getSystemService} to retrieve a
3683 * {@link android.app.UiModeManager} for controlling UI modes.
3684 *
3685 * @see #getSystemService
3686 */
3687 public static final String UI_MODE_SERVICE = "uimode";
3688
3689 /**
Steve Howarda2709362010-07-02 17:12:48 -07003690 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003691 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003692 *
3693 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07003694 */
3695 public static final String DOWNLOAD_SERVICE = "download";
3696
3697 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08003698 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003699 * {@link android.os.BatteryManager} for managing battery state.
3700 *
3701 * @see #getSystemService
3702 */
3703 public static final String BATTERY_SERVICE = "batterymanager";
3704
3705 /**
3706 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003707 * {@link android.nfc.NfcManager} for using NFC.
3708 *
3709 * @see #getSystemService
3710 */
3711 public static final String NFC_SERVICE = "nfc";
3712
3713 /**
3714 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003715 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003716 *
3717 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003718 */
3719 public static final String BLUETOOTH_SERVICE = "bluetooth";
3720
3721 /**
3722 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003723 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3724 *
3725 * @see #getSystemService
3726 */
3727 /** @hide */
3728 public static final String SIP_SERVICE = "sip";
3729
3730 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003731 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003732 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003733 * and for controlling this device's behavior as a USB device.
3734 *
3735 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04003736 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003737 */
3738 public static final String USB_SERVICE = "usb";
3739
3740 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003741 * Use with {@link #getSystemService} to retrieve a {@link
3742 * android.hardware.SerialManager} for access to serial ports.
3743 *
3744 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003745 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003746 *
3747 * @hide
3748 */
3749 public static final String SERIAL_SERVICE = "serial";
3750
3751 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003752 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003753 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3754 * HDMI-CEC protocol.
3755 *
3756 * @see #getSystemService
3757 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003758 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003759 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003760 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003761 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003762
3763 /**
3764 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003765 * {@link android.hardware.input.InputManager} for interacting with input devices.
3766 *
3767 * @see #getSystemService
3768 * @see android.hardware.input.InputManager
3769 */
3770 public static final String INPUT_SERVICE = "input";
3771
3772 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07003773 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003774 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3775 *
3776 * @see #getSystemService
3777 * @see android.hardware.display.DisplayManager
3778 */
3779 public static final String DISPLAY_SERVICE = "display";
3780
3781 /**
3782 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003783 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3784 *
3785 * @see #getSystemService
3786 * @see android.os.UserManager
3787 */
3788 public static final String USER_SERVICE = "user";
3789
3790 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003791 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003792 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3793 * profiles of a user.
3794 *
3795 * @see #getSystemService
3796 * @see android.content.pm.LauncherApps
3797 */
3798 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3799
3800 /**
3801 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003802 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3803 * and requesting permissions for restricted operations.
3804 * @see #getSystemService
3805 * @see android.content.RestrictionsManager
3806 */
3807 public static final String RESTRICTIONS_SERVICE = "restrictions";
3808
3809 /**
3810 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003811 * {@link android.app.AppOpsManager} for tracking application operations
3812 * on the device.
3813 *
3814 * @see #getSystemService
3815 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003816 */
3817 public static final String APP_OPS_SERVICE = "appops";
3818
3819 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003820 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003821 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003822 * camera devices.
3823 *
3824 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003825 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003826 */
3827 public static final String CAMERA_SERVICE = "camera";
3828
3829 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003830 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003831 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003832 *
3833 * @see #getSystemService
3834 * @see android.print.PrintManager
3835 */
3836 public static final String PRINT_SERVICE = "print";
3837
3838 /**
Eugene Susla4160be12017-04-18 12:29:10 -07003839 * Use with {@link #getSystemService} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08003840 * {@link android.companion.CompanionDeviceManager} for managing companion devices
3841 *
3842 * @see #getSystemService
3843 * @see android.companion.CompanionDeviceManager
3844 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07003845 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08003846
3847 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003848 * Use with {@link #getSystemService} to retrieve a
3849 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3850 * signals from the device.
3851 *
3852 * @see #getSystemService
3853 * @see android.hardware.ConsumerIrManager
3854 */
3855 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3856
3857 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003858 * {@link android.app.trust.TrustManager} for managing trust agents.
3859 * @see #getSystemService
3860 * @see android.app.trust.TrustManager
3861 * @hide
3862 */
3863 public static final String TRUST_SERVICE = "trust";
3864
3865 /**
Jae Seo39570912014-02-20 18:23:25 -08003866 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003867 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3868 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003869 *
3870 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003871 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003872 */
3873 public static final String TV_INPUT_SERVICE = "tv_input";
3874
3875 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003876 * {@link android.net.NetworkScoreManager} for managing network scoring.
3877 * @see #getSystemService
3878 * @see android.net.NetworkScoreManager
3879 * @hide
3880 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003881 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003882 public static final String NETWORK_SCORE_SERVICE = "network_score";
3883
3884 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003885 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003886 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003887 *
3888 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003889 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003890 */
3891 public static final String USAGE_STATS_SERVICE = "usagestats";
3892
3893 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003894 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003895 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003896 * background tasks.
3897 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003898 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003899 */
Christopher Tate7060b042014-06-09 19:50:00 -07003900 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003901
3902 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003903 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003904 * android.service.persistentdata.PersistentDataBlockManager} instance
3905 * for interacting with a storage device that lives across factory resets.
3906 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003907 * @see #getSystemService
3908 * @see android.service.persistentdata.PersistentDataBlockManager
3909 * @hide
3910 */
Andres Morales33df9372014-09-26 17:08:59 -07003911 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003912 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3913
3914 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003915 * Use with {@link #getSystemService} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003916 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
3917 *
3918 * @see #getSystemService
3919 * @see android.service.oemlock.OemLockManager
3920 * @hide
3921 */
3922 @SystemApi
3923 public static final String OEM_LOCK_SERVICE = "oem_lock";
3924
3925 /**
3926 * Use with {@link #getSystemService} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07003927 * android.media.projection.MediaProjectionManager} instance for managing
3928 * media projection sessions.
3929 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003930 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003931 */
3932 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3933
3934 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003935 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003936 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003937 *
3938 * @see #getSystemService
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003939 */
3940 public static final String MIDI_SERVICE = "midi";
3941
Eric Laurent2035ac82015-03-05 15:18:44 -08003942
3943 /**
3944 * Use with {@link #getSystemService} to retrieve a
3945 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3946 *
3947 * @see #getSystemService
3948 * @hide
3949 */
3950 public static final String RADIO_SERVICE = "radio";
3951
Paul McLeana33be212015-02-20 07:52:45 -08003952 /**
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003953 * Use with {@link #getSystemService} to retrieve a
3954 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
3955 *
3956 * @see #getSystemService
3957 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01003958 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003959
3960 /**
Makoto Onukib5a012f2016-06-21 11:13:53 -07003961 * Use with {@link #getSystemService} to retrieve a
3962 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003963 *
3964 * @see #getSystemService
3965 * @see android.content.pm.ShortcutManager
3966 */
3967 public static final String SHORTCUT_SERVICE = "shortcut";
3968
3969 /**
Peng Xu9ff7d222016-02-11 13:02:05 -08003970 * Use with {@link #getSystemService} to retrieve a {@link
3971 * android.hardware.location.ContextHubManager} for accessing context hubs.
3972 *
3973 * @see #getSystemService
3974 * @see android.hardware.location.ContextHubManager
3975 *
3976 * @hide
3977 */
3978 @SystemApi
3979 public static final String CONTEXTHUB_SERVICE = "contexthub";
3980
3981 /**
Joe Onorato713fec82016-03-04 10:34:02 -08003982 * Use with {@link #getSystemService} to retrieve a
3983 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
3984 * memory, etc) metrics.
3985 *
3986 * @see #getSystemService
3987 */
3988 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
3989
3990 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07003991 * Gatekeeper Service.
3992 * @hide
3993 */
3994 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
3995
3996 /**
Svet Ganov37e43272016-09-09 16:01:32 -07003997 * Service defining the policy for access to device identifiers.
3998 * @hide
3999 */
4000 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4001
4002 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004003 * Service to report a system health "incident"
4004 * @hide
4005 */
4006 public static final String INCIDENT_SERVICE = "incident";
4007
4008 /**
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004009 * Use with {@link #getSystemService} to retrieve a {@link
4010 * android.content.om.OverlayManager} for managing overlay packages.
4011 *
4012 * @see #getSystemService
4013 * @see android.content.om.OverlayManager
4014 * @hide
4015 */
4016 public static final String OVERLAY_SERVICE = "overlay";
4017
4018 /**
Zak Cohen56345f42017-01-26 13:54:28 -08004019 * Use with {@link #getSystemService} to retrieve a
4020 * {@link VrManager} for accessing the VR service.
4021 *
4022 * @see #getSystemService
4023 * @hide
4024 */
4025 @SystemApi
4026 public static final String VR_SERVICE = "vrmanager";
4027
4028 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004029 * Determine whether the given permission is allowed for a particular
4030 * process and user ID running in the system.
4031 *
4032 * @param permission The name of the permission being checked.
4033 * @param pid The process ID being checked against. Must be > 0.
4034 * @param uid The user ID being checked against. A uid of 0 is the root
4035 * user, which will pass every permission check.
4036 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004037 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004038 * pid/uid is allowed that permission, or
4039 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4040 *
4041 * @see PackageManager#checkPermission(String, String)
4042 * @see #checkCallingPermission
4043 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004044 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004045 @PackageManager.PermissionResult
4046 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004047
Dianne Hackbornff170242014-11-19 10:59:01 -08004048 /** @hide */
4049 @PackageManager.PermissionResult
4050 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4051 IBinder callerToken);
4052
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004053 /**
4054 * Determine whether the calling process of an IPC you are handling has been
4055 * granted a particular permission. This is basically the same as calling
4056 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4057 * by {@link android.os.Binder#getCallingPid} and
4058 * {@link android.os.Binder#getCallingUid}. One important difference
4059 * is that if you are not currently processing an IPC, this function
4060 * will always fail. This is done to protect against accidentally
4061 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4062 * to avoid this protection.
4063 *
4064 * @param permission The name of the permission being checked.
4065 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004066 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 * pid/uid is allowed that permission, or
4068 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4069 *
4070 * @see PackageManager#checkPermission(String, String)
4071 * @see #checkPermission
4072 * @see #checkCallingOrSelfPermission
4073 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004074 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004075 @PackageManager.PermissionResult
4076 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077
4078 /**
4079 * Determine whether the calling process of an IPC <em>or you</em> have been
4080 * granted a particular permission. This is the same as
4081 * {@link #checkCallingPermission}, except it grants your own permissions
4082 * if you are not currently processing an IPC. Use with care!
4083 *
4084 * @param permission The name of the permission being checked.
4085 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004086 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004087 * pid/uid is allowed that permission, or
4088 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4089 *
4090 * @see PackageManager#checkPermission(String, String)
4091 * @see #checkPermission
4092 * @see #checkCallingPermission
4093 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004094 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004095 @PackageManager.PermissionResult
4096 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097
4098 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004099 * Determine whether <em>you</em> have been granted a particular permission.
4100 *
4101 * @param permission The name of the permission being checked.
4102 *
4103 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4104 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4105 *
4106 * @see PackageManager#checkPermission(String, String)
4107 * @see #checkCallingPermission(String)
4108 */
4109 @PackageManager.PermissionResult
4110 public abstract int checkSelfPermission(@NonNull String permission);
4111
4112 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 * If the given permission is not allowed for a particular process
4114 * and user ID running in the system, throw a {@link SecurityException}.
4115 *
4116 * @param permission The name of the permission being checked.
4117 * @param pid The process ID being checked against. Must be &gt; 0.
4118 * @param uid The user ID being checked against. A uid of 0 is the root
4119 * user, which will pass every permission check.
4120 * @param message A message to include in the exception if it is thrown.
4121 *
4122 * @see #checkPermission(String, int, int)
4123 */
4124 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004125 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004126
4127 /**
4128 * If the calling process of an IPC you are handling has not been
4129 * granted a particular permission, throw a {@link
4130 * SecurityException}. This is basically the same as calling
4131 * {@link #enforcePermission(String, int, int, String)} with the
4132 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4133 * and {@link android.os.Binder#getCallingUid}. One important
4134 * difference is that if you are not currently processing an IPC,
4135 * this function will always throw the SecurityException. This is
4136 * done to protect against accidentally leaking permissions; you
4137 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4138 * protection.
4139 *
4140 * @param permission The name of the permission being checked.
4141 * @param message A message to include in the exception if it is thrown.
4142 *
4143 * @see #checkCallingPermission(String)
4144 */
4145 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004146 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004147
4148 /**
4149 * If neither you nor the calling process of an IPC you are
4150 * handling has been granted a particular permission, throw a
4151 * {@link SecurityException}. This is the same as {@link
4152 * #enforceCallingPermission}, except it grants your own
4153 * permissions if you are not currently processing an IPC. Use
4154 * with care!
4155 *
4156 * @param permission The name of the permission being checked.
4157 * @param message A message to include in the exception if it is thrown.
4158 *
4159 * @see #checkCallingOrSelfPermission(String)
4160 */
4161 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004162 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004163
4164 /**
4165 * Grant permission to access a specific Uri to another package, regardless
4166 * of whether that package has general permission to access the Uri's
4167 * content provider. This can be used to grant specific, temporary
4168 * permissions, typically in response to user interaction (such as the
4169 * user opening an attachment that you would like someone else to
4170 * display).
4171 *
4172 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4173 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4174 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4175 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4176 * start an activity instead of this function directly. If you use this
4177 * function directly, you should be sure to call
4178 * {@link #revokeUriPermission} when the target should no longer be allowed
4179 * to access it.
4180 *
4181 * <p>To succeed, the content provider owning the Uri must have set the
4182 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4183 * grantUriPermissions} attribute in its manifest or included the
4184 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4185 * &lt;grant-uri-permissions&gt;} tag.
4186 *
4187 * @param toPackage The package you would like to allow to access the Uri.
4188 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004189 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 *
4191 * @see #revokeUriPermission
4192 */
4193 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004194 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004195
4196 /**
4197 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004198 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4199 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004200 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004201 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004202 * "content://foo". It will not remove any prefix grants that exist at a
4203 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004204 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004205 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004206 * regular permission access to a Uri, but had received access to it through
4207 * a specific Uri permission grant, you could not revoke that grant with this
4208 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004209 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4210 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004211 * (or none).</p>
4212 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004213 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4214 * grants matching the given Uri, for any package they had been granted to, through any
4215 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4216 * service start, etc). That means this can be potentially dangerous to use, as it can
4217 * revoke grants that another app could be strongly expecting to stick around.</p>
4218 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004219 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004220 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221 *
4222 * @see #grantUriPermission
4223 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004224 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004225
4226 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004227 * Remove permissions to access a particular content provider Uri
4228 * that were previously added with {@link #grantUriPermission} for a specific target
4229 * package. The given Uri will match all previously granted Uris that are the same or a
4230 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4231 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4232 * "content://foo". It will not remove any prefix grants that exist at a
4233 * higher level.
4234 *
4235 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4236 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4237 * and only for the package specified. Any matching grants that have happened through
4238 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4239 * removed.</p>
4240 *
4241 * @param toPackage The package you had previously granted access to.
4242 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004243 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004244 *
4245 * @see #grantUriPermission
4246 */
4247 public abstract void revokeUriPermission(String toPackage, Uri uri,
4248 @Intent.AccessUriMode int modeFlags);
4249
4250 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004251 * Determine whether a particular process and user ID has been granted
4252 * permission to access a specific URI. This only checks for permissions
4253 * that have been explicitly granted -- if the given process/uid has
4254 * more general access to the URI's content provider then this check will
4255 * always fail.
4256 *
4257 * @param uri The uri that is being checked.
4258 * @param pid The process ID being checked against. Must be &gt; 0.
4259 * @param uid The user ID being checked against. A uid of 0 is the root
4260 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004261 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004262 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004263 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004264 * pid/uid is allowed to access that uri, or
4265 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4266 *
4267 * @see #checkCallingUriPermission
4268 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004269 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004270 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004271 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004272 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273
Dianne Hackbornff170242014-11-19 10:59:01 -08004274 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004275 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08004276 public abstract int checkUriPermission(Uri uri, int pid, int uid,
4277 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004279 /**
4280 * Determine whether the calling process and user ID has been
4281 * granted permission to access a specific URI. This is basically
4282 * the same as calling {@link #checkUriPermission(Uri, int, int,
4283 * int)} with the pid and uid returned by {@link
4284 * android.os.Binder#getCallingPid} and {@link
4285 * android.os.Binder#getCallingUid}. One important difference is
4286 * that if you are not currently processing an IPC, this function
4287 * will always fail.
4288 *
4289 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004290 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004292 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004293 * is allowed to access that uri, or
4294 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4295 *
4296 * @see #checkUriPermission(Uri, int, int, int)
4297 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004298 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004299 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07004300 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004301
4302 /**
4303 * Determine whether the calling process of an IPC <em>or you</em> has been granted
4304 * permission to access a specific URI. This is the same as
4305 * {@link #checkCallingUriPermission}, except it grants your own permissions
4306 * if you are not currently processing an IPC. Use with care!
4307 *
4308 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004309 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004310 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004311 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 * is allowed to access that uri, or
4313 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4314 *
4315 * @see #checkCallingUriPermission
4316 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004317 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004318 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004319 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004320 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321
4322 /**
4323 * Check both a Uri and normal permission. This allows you to perform
4324 * both {@link #checkPermission} and {@link #checkUriPermission} in one
4325 * call.
4326 *
4327 * @param uri The Uri whose permission is to be checked, or null to not
4328 * do this check.
4329 * @param readPermission The permission that provides overall read access,
4330 * or null to not do this check.
4331 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004332 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004333 * @param pid The process ID being checked against. Must be &gt; 0.
4334 * @param uid The user ID being checked against. A uid of 0 is the root
4335 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004336 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004337 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004338 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 * is allowed to access that uri or holds one of the given permissions, or
4340 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4341 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004342 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004343 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004344 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
4345 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004346 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004347
4348 /**
4349 * If a particular process and user ID has not been granted
4350 * permission to access a specific URI, throw {@link
4351 * SecurityException}. This only checks for permissions that have
4352 * been explicitly granted -- if the given process/uid has more
4353 * general access to the URI's content provider then this check
4354 * will always fail.
4355 *
4356 * @param uri The uri that is being checked.
4357 * @param pid The process ID being checked against. Must be &gt; 0.
4358 * @param uid The user ID being checked against. A uid of 0 is the root
4359 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004360 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004361 * @param message A message to include in the exception if it is thrown.
4362 *
4363 * @see #checkUriPermission(Uri, int, int, int)
4364 */
4365 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004366 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004367
4368 /**
4369 * If the calling process and user ID has not been granted
4370 * permission to access a specific URI, throw {@link
4371 * SecurityException}. This is basically the same as calling
4372 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
4373 * the pid and uid returned by {@link
4374 * android.os.Binder#getCallingPid} and {@link
4375 * android.os.Binder#getCallingUid}. One important difference is
4376 * that if you are not currently processing an IPC, this function
4377 * will always throw a SecurityException.
4378 *
4379 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004380 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 * @param message A message to include in the exception if it is thrown.
4382 *
4383 * @see #checkCallingUriPermission(Uri, int)
4384 */
4385 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004386 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387
4388 /**
4389 * If the calling process of an IPC <em>or you</em> has not been
4390 * granted permission to access a specific URI, throw {@link
4391 * SecurityException}. This is the same as {@link
4392 * #enforceCallingUriPermission}, except it grants your own
4393 * permissions if you are not currently processing an IPC. Use
4394 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07004395 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004396 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004397 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004398 * @param message A message to include in the exception if it is thrown.
4399 *
4400 * @see #checkCallingOrSelfUriPermission(Uri, int)
4401 */
4402 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004403 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404
4405 /**
4406 * Enforce both a Uri and normal permission. This allows you to perform
4407 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4408 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004409 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004410 * @param uri The Uri whose permission is to be checked, or null to not
4411 * do this check.
4412 * @param readPermission The permission that provides overall read access,
4413 * or null to not do this check.
4414 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004415 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004416 * @param pid The process ID being checked against. Must be &gt; 0.
4417 * @param uid The user ID being checked against. A uid of 0 is the root
4418 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004419 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004420 * @param message A message to include in the exception if it is thrown.
4421 *
4422 * @see #checkUriPermission(Uri, String, String, int, int, int)
4423 */
4424 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004425 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004426 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004427 @Nullable String message);
4428
4429 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004430 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
4431 CONTEXT_INCLUDE_CODE,
4432 CONTEXT_IGNORE_SECURITY,
4433 CONTEXT_RESTRICTED,
4434 CONTEXT_DEVICE_PROTECTED_STORAGE,
4435 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
4436 CONTEXT_REGISTER_PACKAGE,
4437 })
Tor Norbyed9273d62013-05-30 15:59:53 -07004438 @Retention(RetentionPolicy.SOURCE)
4439 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004440
4441 /**
4442 * Flag for use with {@link #createPackageContext}: include the application
4443 * code with the context. This means loading code into the caller's
4444 * process, so that {@link #getClassLoader()} can be used to instantiate
4445 * the application's classes. Setting this flags imposes security
4446 * restrictions on what application context you can access; if the
4447 * requested application can not be safely loaded into your process,
4448 * java.lang.SecurityException will be thrown. If this flag is not set,
4449 * there will be no restrictions on the packages that can be loaded,
4450 * but {@link #getClassLoader} will always return the default system
4451 * class loader.
4452 */
4453 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4454
4455 /**
4456 * Flag for use with {@link #createPackageContext}: ignore any security
4457 * restrictions on the Context being requested, allowing it to always
4458 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4459 * to be loaded into a process even when it isn't safe to do so. Use
4460 * with extreme care!
4461 */
4462 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004463
Romain Guy870e09f2009-07-06 16:35:25 -07004464 /**
4465 * Flag for use with {@link #createPackageContext}: a restricted context may
4466 * disable specific features. For instance, a View associated with a restricted
4467 * context would ignore particular XML attributes.
4468 */
4469 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004470
4471 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004472 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004473 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004474 *
4475 * @hide
4476 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004477 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004478
4479 /**
4480 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004481 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004482 *
4483 * @hide
4484 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004485 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004486
4487 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004488 * @hide Used to indicate we should tell the activity manager about the process
4489 * loading this code.
4490 */
4491 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4492
4493 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 * Return a new Context object for the given application name. This
4495 * Context is the same as what the named application gets when it is
4496 * launched, containing the same resources and class loader. Each call to
4497 * this method returns a new instance of a Context object; Context objects
4498 * are not shared, however they share common state (Resources, ClassLoader,
4499 * etc) so the Context instance itself is fairly lightweight.
4500 *
Jeff Brown6e539312015-02-24 18:53:21 -08004501 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004502 * application with the given package name.
4503 *
4504 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4505 * can not be loaded into the caller's process for security reasons (see
4506 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4507 *
4508 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004509 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004510 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004511 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004512 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004513 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004514 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004515 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004516 */
4517 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004518 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004519
4520 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004521 * Similar to {@link #createPackageContext(String, int)}, but with a
4522 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4523 * will open any {@link Uri} as the given user.
4524 *
4525 * @hide
4526 */
4527 public abstract Context createPackageContextAsUser(
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004528 String packageName, @CreatePackageOptions int flags, UserHandle user)
Jeff Sharkey6d515712012-09-20 16:06:08 -07004529 throws PackageManager.NameNotFoundException;
4530
4531 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004532 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4533 *
4534 * @hide
4535 */
4536 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004537 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07004538
4539 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08004540 * Return a new Context object for the given split name. The new Context has a ClassLoader and
4541 * Resources object that can access the split's and all of its dependencies' code/resources.
4542 * Each call to this method returns a new instance of a Context object;
4543 * Context objects are not shared, however common state (ClassLoader, other Resources for
4544 * the same split) may be so the Context itself can be fairly lightweight.
4545 *
4546 * @param splitName The name of the split to include, as declared in the split's
4547 * <code>AndroidManifest.xml</code>.
4548 * @return A {@link Context} with the given split's code and/or resources loaded.
4549 */
4550 public abstract Context createContextForSplit(String splitName)
4551 throws PackageManager.NameNotFoundException;
4552
4553 /**
Jim Millera75a8832013-02-07 16:53:32 -08004554 * Get the userId associated with this context
4555 * @return user id
4556 *
4557 * @hide
4558 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004559 @TestApi
Jeff Sharkey8588bc12016-01-06 16:47:42 -07004560 public abstract @UserIdInt int getUserId();
Jim Millera75a8832013-02-07 16:53:32 -08004561
4562 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004563 * Return a new Context object for the current Context but whose resources
4564 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004565 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004566 * shared, however common state (ClassLoader, other Resources for the
4567 * same configuration) may be so the Context itself can be fairly lightweight.
4568 *
4569 * @param overrideConfiguration A {@link Configuration} specifying what
4570 * values to modify in the base Configuration of the original Context's
4571 * resources. If the base configuration changes (such as due to an
4572 * orientation change), the resources of this context will also change except
4573 * for those that have been explicitly overridden with a value here.
4574 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004575 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004576 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004577 public abstract Context createConfigurationContext(
4578 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004579
4580 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004581 * Return a new Context object for the current Context but whose resources
4582 * are adjusted to match the metrics of the given Display. Each call to this method
4583 * returns a new instance of a Context object; Context objects are not
4584 * shared, however common state (ClassLoader, other Resources for the
4585 * same configuration) may be so the Context itself can be fairly lightweight.
4586 *
4587 * The returned display Context provides a {@link WindowManager}
4588 * (see {@link #getSystemService(String)}) that is configured to show windows
4589 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4590 * method can be used to retrieve the Display from the returned Context.
4591 *
4592 * @param display A {@link Display} object specifying the display
4593 * for whose metrics the Context's resources should be tailored and upon which
4594 * new windows should be shown.
4595 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004596 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004597 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004598 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004599
4600 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004601 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004602 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004603 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004604 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004605 * with a key tied to the physical device, and it can be accessed
4606 * immediately after the device has booted successfully, both
4607 * <em>before and after</em> the user has authenticated with their
4608 * credentials (such as a lock pattern or PIN).
4609 * <p>
4610 * Because device-protected data is available without user authentication,
4611 * you should carefully limit the data you store using this Context. For
4612 * example, storing sensitive authentication tokens or passwords in the
4613 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004614 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004615 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004616 * device-protected and credential-protected data using different keys, then
4617 * both storage areas will become available at the same time. They remain as
4618 * two distinct storage locations on disk, and only the window of
4619 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004620 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004621 * Each call to this method returns a new instance of a Context object;
4622 * Context objects are not shared, however common state (ClassLoader, other
4623 * Resources for the same configuration) may be so the Context itself can be
4624 * fairly lightweight.
4625 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004626 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004627 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004628 public abstract Context createDeviceProtectedStorageContext();
4629
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004630 /**
4631 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004632 * APIs are backed by credential-protected storage. This is the default
4633 * storage area for apps unless
4634 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004635 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004636 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004637 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004638 * <em>only after</em> the user has entered their credentials (such as a
4639 * lock pattern or PIN).
4640 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004641 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004642 * device-protected and credential-protected data using different keys, then
4643 * both storage areas will become available at the same time. They remain as
4644 * two distinct storage locations on disk, and only the window of
4645 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004646 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004647 * Each call to this method returns a new instance of a Context object;
4648 * Context objects are not shared, however common state (ClassLoader, other
4649 * Resources for the same configuration) may be so the Context itself can be
4650 * fairly lightweight.
4651 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004652 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004653 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004654 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004655 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004656 public abstract Context createCredentialProtectedStorageContext();
4657
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004658 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004659 * Gets the display adjustments holder for this context. This information
4660 * is provided on a per-application or activity basis and is used to simulate lower density
4661 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004662 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004663 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004664 * @return The compatibility info holder, or null if not required by the application.
4665 * @hide
4666 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004667 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004668
4669 /**
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004670 * @hide
4671 */
4672 public abstract Display getDisplay();
4673
4674 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08004675 * @hide
4676 */
4677 public abstract void updateDisplay(int displayId);
4678
4679 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004680 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004681 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004682 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004683 *
Romain Guy870e09f2009-07-06 16:35:25 -07004684 * @see #CONTEXT_RESTRICTED
4685 */
4686 public boolean isRestricted() {
4687 return false;
4688 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004689
4690 /**
4691 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004692 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004693 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004694 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004695 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004696 public abstract boolean isDeviceProtectedStorage();
4697
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004698 /**
4699 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004700 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004701 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004702 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004703 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004704 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004705 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004706 public abstract boolean isCredentialProtectedStorage();
4707
Tony Mak46aabe52016-11-14 12:53:06 +00004708 /**
Seigo Nonakab7773ce2017-06-22 08:22:18 -07004709 * Returns true if the context can load unsafe resources, e.g. fonts.
4710 * @hide
4711 */
4712 public abstract boolean canLoadUnsafeResources();
4713
4714 /**
Tony Mak46aabe52016-11-14 12:53:06 +00004715 * @hide
4716 */
4717 public IBinder getActivityToken() {
4718 throw new RuntimeException("Not implemented. Must override in a subclass.");
4719 }
4720
4721 /**
4722 * @hide
4723 */
4724 @Nullable
4725 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
4726 int flags) {
4727 throw new RuntimeException("Not implemented. Must override in a subclass.");
4728 }
4729
4730 /**
4731 * @hide
4732 */
4733 public IApplicationThread getIApplicationThread() {
4734 throw new RuntimeException("Not implemented. Must override in a subclass.");
4735 }
Tony Makbf9928d2016-12-22 11:02:45 +00004736
4737 /**
4738 * @hide
4739 */
4740 public Handler getMainThreadHandler() {
4741 throw new RuntimeException("Not implemented. Must override in a subclass.");
4742 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07004743
4744 /**
4745 * Throws an exception if the Context is using system resources,
4746 * which are non-runtime-overlay-themable and may show inconsistent UI.
4747 * @hide
4748 */
4749 public void assertRuntimeOverlayThemable() {
4750 // Resources.getSystem() is a singleton and the only Resources not managed by
4751 // ResourcesManager; therefore Resources.getSystem() is not themable.
4752 if (getResources() == Resources.getSystem()) {
4753 throw new IllegalArgumentException("Non-UI context used to display UI; "
4754 + "get a UI context from ActivityThread#getSystemUiContext()");
4755 }
4756 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004757}