blob: 6eeeb3e47a7ed0a9ce9e2361557af1066e63be16 [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;
Zak Cohen56345f42017-01-26 13:54:28 -080037import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070038import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039import android.content.pm.PackageManager;
40import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080041import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070042import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.content.res.Resources;
44import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070045import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.database.sqlite.SQLiteDatabase;
47import android.database.sqlite.SQLiteDatabase.CursorFactory;
48import android.graphics.Bitmap;
49import android.graphics.drawable.Drawable;
50import android.net.Uri;
51import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070052import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.os.Handler;
Dianne Hackbornff170242014-11-19 10:59:01 -080054import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070056import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070057import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070058import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060059import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070060import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070062import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070063import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070064import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070065import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070066import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070067import android.view.autofill.AutofillManager.AutofillClient;
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 *
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700757 * This method is thead-safe.
758 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 * @param name Desired preferences file. If a preferences file by this name
760 * does not exist, it will be created when you retrieve an
761 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600762 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400764 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 * to retrieve and modify the preference values.
766 *
767 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600769 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700770
771 /**
772 * Retrieve and hold the contents of the preferences file, returning
773 * a SharedPreferences through which you can retrieve and modify its
774 * values. Only one instance of the SharedPreferences object is returned
775 * to any callers for the same name, meaning they will see each other's
776 * edits as soon as they are made.
777 *
778 * @param file Desired preferences file. If a preferences file by this name
779 * does not exist, it will be created when you retrieve an
780 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600781 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700782 *
783 * @return The single {@link SharedPreferences} instance that can be used
784 * to retrieve and modify the preference values.
785 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700786 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700787 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600788 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700789 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600790 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791
792 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600793 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700794 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600795 * storage locations after an upgrade, such as moving to device protected
796 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700797 *
798 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600799 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700800 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600801 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700802 * preferences didn't exist in the source context, otherwise
803 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600804 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700805 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600806 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
807
Jeff Sharkey35871f22016-01-29 17:13:29 -0700808 /**
809 * Delete an existing shared preferences file.
810 *
811 * @param name The name (unique in the application package) of the shared
812 * preferences file.
813 * @return {@code true} if the shared preferences file was successfully
814 * deleted; else {@code false}.
815 * @see #getSharedPreferences(String, int)
816 */
817 public abstract boolean deleteSharedPreferences(String name);
818
Christopher Tatefe2368c2017-05-17 15:42:35 -0700819 /** @hide */
820 public abstract void reloadSharedPreferences();
821
Jeff Sharkey35871f22016-01-29 17:13:29 -0700822 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800823 * Open a private file associated with this Context's application package
824 * for reading.
825 *
826 * @param name The name of the file to open; can not contain path
827 * separators.
828 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400829 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 *
831 * @see #openFileOutput
832 * @see #fileList
833 * @see #deleteFile
834 * @see java.io.FileInputStream#FileInputStream(String)
835 */
836 public abstract FileInputStream openFileInput(String name)
837 throws FileNotFoundException;
838
839 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800840 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700841 * for writing. Creates the file if it doesn't already exist.
842 * <p>
843 * No additional permissions are required for the calling app to read or
844 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700845 *
Nick Kralevich15069212013-01-09 15:54:56 -0800846 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700847 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600848 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400849 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 * @see #MODE_APPEND
851 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 * @see #openFileInput
853 * @see #fileList
854 * @see #deleteFile
855 * @see java.io.FileOutputStream#FileOutputStream(String)
856 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600857 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 throws FileNotFoundException;
859
860 /**
861 * Delete the given private file associated with this Context's
862 * application package.
863 *
864 * @param name The name of the file to delete; can not contain path
865 * separators.
866 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400867 * @return {@code true} if the file was successfully deleted; else
868 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 *
870 * @see #openFileInput
871 * @see #openFileOutput
872 * @see #fileList
873 * @see java.io.File#delete()
874 */
875 public abstract boolean deleteFile(String name);
876
877 /**
878 * Returns the absolute path on the filesystem where a file created with
879 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700880 * <p>
881 * The returned path may change over time if the calling app is moved to an
882 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 *
884 * @param name The name of the file for which you would like to get
885 * its path.
886 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400887 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800888 *
889 * @see #openFileOutput
890 * @see #getFilesDir
891 * @see #getDir
892 */
893 public abstract File getFileStreamPath(String name);
894
895 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700896 * Returns the absolute path on the filesystem where a file created with
897 * {@link #getSharedPreferences(String, int)} is stored.
898 * <p>
899 * The returned path may change over time if the calling app is moved to an
900 * adopted storage device, so only relative paths should be persisted.
901 *
902 * @param name The name of the shared preferences for which you would like
903 * to get a path.
904 * @return An absolute path to the given file.
905 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600906 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700907 */
908 public abstract File getSharedPreferencesPath(String name);
909
910 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700911 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600912 * private files belonging to this app are stored. Apps should not use this
913 * path directly; they should instead use {@link #getFilesDir()},
914 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
915 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700916 * <p>
917 * The returned path may change over time if the calling app is moved to an
918 * adopted storage device, so only relative paths should be persisted.
919 * <p>
920 * No additional permissions are required for the calling app to read or
921 * write files under the returned path.
922 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600923 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700924 */
925 public abstract File getDataDir();
926
927 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700928 * Returns the absolute path to the directory on the filesystem where files
929 * created with {@link #openFileOutput} are stored.
930 * <p>
931 * The returned path may change over time if the calling app is moved to an
932 * adopted storage device, so only relative paths should be persisted.
933 * <p>
934 * No additional permissions are required for the calling app to read or
935 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700936 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400937 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 * @see #openFileOutput
939 * @see #getFileStreamPath
940 * @see #getDir
941 */
942 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800944 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700945 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700946 * {@link #getFilesDir()}. The difference is that files placed under this
947 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700948 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
949 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700950 * <p>
951 * The returned path may change over time if the calling app is moved to an
952 * adopted storage device, so only relative paths should be persisted.
953 * <p>
954 * No additional permissions are required for the calling app to read or
955 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700956 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700957 * @return The path of the directory holding application files that will not
958 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700959 * @see #openFileOutput
960 * @see #getFileStreamPath
961 * @see #getDir
962 * @see android.app.backup.BackupAgent
963 */
964 public abstract File getNoBackupFilesDir();
965
966 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700967 * Returns the absolute path to the directory on the primary shared/external
968 * storage device where the application can place persistent files it owns.
969 * These files are internal to the applications, and not typically visible
970 * to the user as media.
971 * <p>
972 * This is like {@link #getFilesDir()} in that these files will be deleted
973 * when the application is uninstalled, however there are some important
974 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800975 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700976 * <li>Shared storage may not always be available, since removable media can
977 * be ejected by the user. Media state can be checked using
978 * {@link Environment#getExternalStorageState(File)}.
979 * <li>There is no security enforced with these files. For example, any
980 * application holding
981 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700982 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800983 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700984 * <p>
985 * If a shared storage device is emulated (as determined by
986 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
987 * backed by a private user data partition, which means there is little
988 * benefit to storing data here instead of the private directories returned
989 * by {@link #getFilesDir()}, etc.
990 * <p>
991 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -0700992 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700993 * accessible to the calling app. This only applies to paths generated for
994 * package name of the calling application. To access paths belonging to
995 * other packages,
996 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
997 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
998 * <p>
999 * On devices with multiple users (as described by {@link UserManager}),
1000 * each user has their own isolated shared storage. Applications only have
1001 * access to the shared storage for the user they're running as.
1002 * <p>
1003 * The returned path may change over time if different shared storage media
1004 * is inserted, so only relative paths should be persisted.
1005 * <p>
1006 * Here is an example of typical code to manipulate a file in an
1007 * application's shared storage:
1008 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001009 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1010 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001011 * <p>
1012 * If you supply a non-null <var>type</var> to this function, the returned
1013 * file will be a path to a sub-directory of the given type. Though these
1014 * files are not automatically scanned by the media scanner, you can
1015 * explicitly add them to the media database with
1016 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1017 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001018 * {@link android.os.Environment#getExternalStoragePublicDirectory
1019 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001020 * directories of media shared by all applications. The directories returned
1021 * here are owned by the application, and their contents will be removed
1022 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001023 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001024 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1025 * here will be automatically created for you.
1026 * <p>
1027 * Here is an example of typical code to manipulate a picture in an
1028 * application's shared storage and add it to the media database:
1029 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001030 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1031 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001032 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001033 * @param type The type of files directory to return. May be {@code null}
1034 * for the root of the files directory or one of the following
1035 * constants for a subdirectory:
1036 * {@link android.os.Environment#DIRECTORY_MUSIC},
1037 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1038 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1039 * {@link android.os.Environment#DIRECTORY_ALARMS},
1040 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1041 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1042 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1043 * @return the absolute path to application-specific directory. May return
1044 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001045 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001046 * @see #getExternalFilesDirs(String)
1047 * @see Environment#getExternalStorageState(File)
1048 * @see Environment#isExternalStorageEmulated(File)
1049 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001050 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001051 @Nullable
1052 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001053
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001054 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001055 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001056 * shared/external storage devices where the application can place
1057 * persistent files it owns. These files are internal to the application,
1058 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001059 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001060 * This is like {@link #getFilesDir()} in that these files will be deleted
1061 * when the application is uninstalled, however there are some important
1062 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001063 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001064 * <li>Shared storage may not always be available, since removable media can
1065 * be ejected by the user. Media state can be checked using
1066 * {@link Environment#getExternalStorageState(File)}.
1067 * <li>There is no security enforced with these files. For example, any
1068 * application holding
1069 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1070 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001071 * </ul>
1072 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001073 * If a shared storage device is emulated (as determined by
1074 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1075 * backed by a private user data partition, which means there is little
1076 * benefit to storing data here instead of the private directories returned
1077 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001078 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001079 * Shared storage devices returned here are considered a stable part of the
1080 * device, including physical media slots under a protective cover. The
1081 * returned paths do not include transient devices, such as USB flash drives
1082 * connected to handheld devices.
1083 * <p>
1084 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001085 * example, an app may choose to store large files on the device with the
1086 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001087 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001088 * No additional permissions are required for the calling app to read or
1089 * write files under the returned path. Write access outside of these paths
1090 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001091 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001092 * The returned path may change over time if different shared storage media
1093 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001094 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001095 * @param type The type of files directory to return. May be {@code null}
1096 * for the root of the files directory or one of the following
1097 * constants for a subdirectory:
1098 * {@link android.os.Environment#DIRECTORY_MUSIC},
1099 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1100 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1101 * {@link android.os.Environment#DIRECTORY_ALARMS},
1102 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1103 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1104 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1105 * @return the absolute paths to application-specific directories. Some
1106 * individual paths may be {@code null} if that shared storage is
1107 * not currently available. The first path returned is the same as
1108 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001109 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001110 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001111 * @see Environment#isExternalStorageEmulated(File)
1112 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001113 */
1114 public abstract File[] getExternalFilesDirs(String type);
1115
1116 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001117 * Return the primary shared/external storage directory where this
1118 * application's OBB files (if there are any) can be found. Note if the
1119 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001120 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001121 * This is like {@link #getFilesDir()} in that these files will be deleted
1122 * when the application is uninstalled, however there are some important
1123 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001124 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001125 * <li>Shared storage may not always be available, since removable media can
1126 * be ejected by the user. Media state can be checked using
1127 * {@link Environment#getExternalStorageState(File)}.
1128 * <li>There is no security enforced with these files. For example, any
1129 * application holding
1130 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001131 * these files.
1132 * </ul>
1133 * <p>
1134 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001135 * are required to read or write to the path that this method returns.
1136 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1137 * to read the OBB expansion files, you must declare the
1138 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1139 * permission at runtime as follows:
1140 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001141 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001142 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1143 * android:maxSdkVersion="23" />}
1144 * </p>
1145 * <p>
1146 * Starting from {@link android.os.Build.VERSION_CODES#N},
1147 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1148 * permission is not required, so don’t ask for this
1149 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1150 * and if it fails, you must request
1151 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1152 * </p>
1153 *
1154 * <p>
1155 * The following code snippet shows how to do this:
1156 * </p>
1157 *
1158 * <pre>
1159 * File obb = new File(obb_filename);
1160 * boolean open_failed = false;
1161 *
1162 * try {
1163 * BufferedReader br = new BufferedReader(new FileReader(obb));
1164 * open_failed = false;
1165 * ReadObbFile(br);
1166 * } catch (IOException e) {
1167 * open_failed = true;
1168 * }
1169 *
1170 * if (open_failed) {
1171 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1172 * ReadObbFileWithPermission();
1173 * }
1174 * </pre>
1175 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001176 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001177 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001178 * should ensure that multiple instances running under different users don't
1179 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001180 *
1181 * @return the absolute path to application-specific directory. May return
1182 * {@code null} if shared storage is not currently available.
1183 * @see #getObbDirs()
1184 * @see Environment#getExternalStorageState(File)
1185 * @see Environment#isExternalStorageEmulated(File)
1186 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001187 */
1188 public abstract File getObbDir();
1189
1190 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001191 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001192 * shared/external storage devices where the application's OBB files (if
1193 * there are any) can be found. Note if the application does not have any
1194 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001195 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001196 * This is like {@link #getFilesDir()} in that these files will be deleted
1197 * when the application is uninstalled, however there are some important
1198 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001199 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001200 * <li>Shared storage may not always be available, since removable media can
1201 * be ejected by the user. Media state can be checked using
1202 * {@link Environment#getExternalStorageState(File)}.
1203 * <li>There is no security enforced with these files. For example, any
1204 * application holding
1205 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1206 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001207 * </ul>
1208 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001209 * Shared storage devices returned here are considered a stable part of the
1210 * device, including physical media slots under a protective cover. The
1211 * returned paths do not include transient devices, such as USB flash drives
1212 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001213 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001214 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001215 * example, an app may choose to store large files on the device with the
1216 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001217 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001218 * No additional permissions are required for the calling app to read or
1219 * write files under the returned path. Write access outside of these paths
1220 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001221 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001222 * @return the absolute paths to application-specific directories. Some
1223 * individual paths may be {@code null} if that shared storage is
1224 * not currently available. The first path returned is the same as
1225 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001226 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001227 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001228 * @see Environment#isExternalStorageEmulated(File)
1229 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001230 */
1231 public abstract File[] getObbDirs();
1232
1233 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001234 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001235 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001236 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001237 * The system will automatically delete files in this directory as disk
1238 * space is needed elsewhere on the device. The system will always delete
1239 * older files first, as reported by {@link File#lastModified()}. If
1240 * desired, you can exert more control over how files are deleted using
1241 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1242 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1243 * <p>
1244 * Apps are strongly encouraged to keep their usage of cache space below the
1245 * quota returned by
1246 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1247 * goes above this quota, your cached files will be some of the first to be
1248 * deleted when additional disk space is needed. Conversely, if your app
1249 * stays under this quota, your cached files will be some of the last to be
1250 * deleted when additional disk space is needed.
1251 * <p>
1252 * Note that your cache quota will change over time depending on how
1253 * frequently the user interacts with your app, and depending on how much
1254 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001255 * <p>
1256 * The returned path may change over time if the calling app is moved to an
1257 * adopted storage device, so only relative paths should be persisted.
1258 * <p>
1259 * Apps require no extra permissions to read or write to the returned path,
1260 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001261 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001262 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 * @see #openFileOutput
1264 * @see #getFileStreamPath
1265 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001266 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 */
1268 public abstract File getCacheDir();
1269
1270 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001271 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001272 * the filesystem designed for storing cached code.
1273 * <p>
1274 * The system will delete any files stored in this location both when your
1275 * specific application is upgraded, and when the entire platform is
1276 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001277 * <p>
1278 * This location is optimal for storing compiled or optimized code generated
1279 * by your application at runtime.
1280 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001281 * The returned path may change over time if the calling app is moved to an
1282 * adopted storage device, so only relative paths should be persisted.
1283 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001284 * Apps require no extra permissions to read or write to the returned path,
1285 * since this path lives in their private storage.
1286 *
1287 * @return The path of the directory holding application code cache files.
1288 */
1289 public abstract File getCodeCacheDir();
1290
1291 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001292 * Returns absolute path to application-specific directory on the primary
1293 * shared/external storage device where the application can place cache
1294 * files it owns. These files are internal to the application, and not
1295 * typically visible to the user as media.
1296 * <p>
1297 * This is like {@link #getCacheDir()} in that these files will be deleted
1298 * when the application is uninstalled, however there are some important
1299 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001300 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001301 * <li>The platform does not always monitor the space available in shared
1302 * storage, and thus may not automatically delete these files. Apps should
1303 * always manage the maximum space used in this location. Currently the only
1304 * time files here will be deleted by the platform is when running on
1305 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1306 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1307 * <li>Shared storage may not always be available, since removable media can
1308 * be ejected by the user. Media state can be checked using
1309 * {@link Environment#getExternalStorageState(File)}.
1310 * <li>There is no security enforced with these files. For example, any
1311 * application holding
1312 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001313 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001314 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001315 * <p>
1316 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001317 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001318 * backed by a private user data partition, which means there is little
1319 * benefit to storing data here instead of the private directory returned by
1320 * {@link #getCacheDir()}.
1321 * <p>
1322 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001323 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001324 * accessible to the calling app. This only applies to paths generated for
1325 * package name of the calling application. To access paths belonging to
1326 * other packages,
1327 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1328 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1329 * <p>
1330 * On devices with multiple users (as described by {@link UserManager}),
1331 * each user has their own isolated shared storage. Applications only have
1332 * access to the shared storage for the user they're running as.
1333 * <p>
1334 * The returned path may change over time if different shared storage media
1335 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001336 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001337 * @return the absolute path to application-specific directory. May return
1338 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001339 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001340 * @see #getExternalCacheDirs()
1341 * @see Environment#getExternalStorageState(File)
1342 * @see Environment#isExternalStorageEmulated(File)
1343 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001344 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001345 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001346 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001347
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001348 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001349 * Returns absolute path to application-specific directory in the preloaded cache.
1350 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1351 * There is no guarantee when these files will be deleted.
1352 * @hide
1353 */
1354 @Nullable
1355 @SystemApi
1356 public abstract File getPreloadsFileCache();
1357
1358 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001359 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001360 * shared/external storage devices where the application can place cache
1361 * files it owns. These files are internal to the application, and not
1362 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001363 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001364 * This is like {@link #getCacheDir()} in that these files will be deleted
1365 * when the application is uninstalled, however there are some important
1366 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001367 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001368 * <li>The platform does not always monitor the space available in shared
1369 * storage, and thus may not automatically delete these files. Apps should
1370 * always manage the maximum space used in this location. Currently the only
1371 * time files here will be deleted by the platform is when running on
1372 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1373 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1374 * <li>Shared storage may not always be available, since removable media can
1375 * be ejected by the user. Media state can be checked using
1376 * {@link Environment#getExternalStorageState(File)}.
1377 * <li>There is no security enforced with these files. For example, any
1378 * application holding
1379 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1380 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001381 * </ul>
1382 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001383 * If a shared storage device is emulated (as determined by
1384 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1385 * backed by a private user data partition, which means there is little
1386 * benefit to storing data here instead of the private directory returned by
1387 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001388 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001389 * Shared storage devices returned here are considered a stable part of the
1390 * device, including physical media slots under a protective cover. The
1391 * returned paths do not include transient devices, such as USB flash drives
1392 * connected to handheld devices.
1393 * <p>
1394 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001395 * example, an app may choose to store large files on the device with the
1396 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001397 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001398 * No additional permissions are required for the calling app to read or
1399 * write files under the returned path. Write access outside of these paths
1400 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001401 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001402 * The returned paths may change over time if different shared storage media
1403 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001404 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001405 * @return the absolute paths to application-specific directories. Some
1406 * individual paths may be {@code null} if that shared storage is
1407 * not currently available. The first path returned is the same as
1408 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001409 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001410 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001411 * @see Environment#isExternalStorageEmulated(File)
1412 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001413 */
1414 public abstract File[] getExternalCacheDirs();
1415
1416 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001417 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001418 * shared/external storage devices where the application can place media
1419 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001420 * {@link MediaStore}.
1421 * <p>
1422 * This is like {@link #getExternalFilesDirs} in that these files will be
1423 * deleted when the application is uninstalled, however there are some
1424 * important differences:
1425 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001426 * <li>Shared storage may not always be available, since removable media can
1427 * be ejected by the user. Media state can be checked using
1428 * {@link Environment#getExternalStorageState(File)}.
1429 * <li>There is no security enforced with these files. For example, any
1430 * application holding
1431 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1432 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001433 * </ul>
1434 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001435 * Shared storage devices returned here are considered a stable part of the
1436 * device, including physical media slots under a protective cover. The
1437 * returned paths do not include transient devices, such as USB flash drives
1438 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001439 * <p>
1440 * An application may store data on any or all of the returned devices. For
1441 * example, an app may choose to store large files on the device with the
1442 * most available space, as measured by {@link StatFs}.
1443 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001444 * No additional permissions are required for the calling app to read or
1445 * write files under the returned path. Write access outside of these paths
1446 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001447 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001448 * The returned paths may change over time if different shared storage media
1449 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001450 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001451 * @return the absolute paths to application-specific directories. Some
1452 * individual paths may be {@code null} if that shared storage is
1453 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001454 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001455 * @see Environment#isExternalStorageEmulated(File)
1456 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001457 */
1458 public abstract File[] getExternalMediaDirs();
1459
1460 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 * Returns an array of strings naming the private files associated with
1462 * this Context's application package.
1463 *
1464 * @return Array of strings naming the private files.
1465 *
1466 * @see #openFileInput
1467 * @see #openFileOutput
1468 * @see #deleteFile
1469 */
1470 public abstract String[] fileList();
1471
1472 /**
1473 * Retrieve, creating if needed, a new directory in which the application
1474 * can place its own custom data files. You can use the returned File
1475 * object to create and access files in this directory. Note that files
1476 * created through a File object will only be accessible by your own
1477 * application; you can only set the mode of the entire directory, not
1478 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001479 * <p>
1480 * The returned path may change over time if the calling app is moved to an
1481 * adopted storage device, so only relative paths should be persisted.
1482 * <p>
1483 * Apps require no extra permissions to read or write to the returned path,
1484 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001485 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001486 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001487 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001488 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001489 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001490 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001491 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001492 *
1493 * @see #openFileOutput(String, int)
1494 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001495 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496
1497 /**
1498 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001499 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001500 *
1501 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001502 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001503 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001504 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001506 * @throws android.database.sqlite.SQLiteException if the database file
1507 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001509 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001510 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 * @see #deleteDatabase
1512 */
1513 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001514 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515
1516 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001517 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001518 * application package. Creates the database file if it doesn't exist.
1519 * <p>
1520 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1521 * to be used to handle corruption when sqlite reports database corruption.
1522 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001523 *
1524 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001525 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001526 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001527 * cursor when query is called.
1528 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1529 * sqlite reports database corruption. if null,
1530 * {@link android.database.DefaultDatabaseErrorHandler} is
1531 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001532 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001533 * @throws android.database.sqlite.SQLiteException if the database file
1534 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001535 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001536 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001537 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001538 * @see #deleteDatabase
1539 */
1540 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001541 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001542 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001543
1544 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001545 * Move an existing database file from the given source storage context to
1546 * this context. This is typically used to migrate data between storage
1547 * locations after an upgrade, such as migrating to device protected
1548 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001549 * <p>
1550 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001551 *
1552 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001553 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001554 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001555 * @return {@code true} if the move was successful or if the database didn't
1556 * exist in the source context, otherwise {@code false}.
1557 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001558 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001559 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1560
Jeff Sharkey35871f22016-01-29 17:13:29 -07001561 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 * Delete an existing private SQLiteDatabase associated with this Context's
1563 * application package.
1564 *
1565 * @param name The name (unique in the application package) of the
1566 * database.
1567 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001568 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001569 *
1570 * @see #openOrCreateDatabase
1571 */
1572 public abstract boolean deleteDatabase(String name);
1573
1574 /**
1575 * Returns the absolute path on the filesystem where a database created with
1576 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001577 * <p>
1578 * The returned path may change over time if the calling app is moved to an
1579 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001580 *
1581 * @param name The name of the database for which you would like to get
1582 * its path.
1583 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001584 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 *
1586 * @see #openOrCreateDatabase
1587 */
1588 public abstract File getDatabasePath(String name);
1589
1590 /**
1591 * Returns an array of strings naming the private databases associated with
1592 * this Context's application package.
1593 *
1594 * @return Array of strings naming the private databases.
1595 *
1596 * @see #openOrCreateDatabase
1597 * @see #deleteDatabase
1598 */
1599 public abstract String[] databaseList();
1600
1601 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001602 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001603 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001605 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 public abstract Drawable getWallpaper();
1607
1608 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001609 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001610 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001612 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 public abstract Drawable peekWallpaper();
1614
1615 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001616 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1617 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001619 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001620 public abstract int getWallpaperDesiredMinimumWidth();
1621
1622 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001623 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1624 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001626 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 public abstract int getWallpaperDesiredMinimumHeight();
1628
1629 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001630 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001631 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001632 * <p>This method requires the caller to hold the permission
1633 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001634 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001635 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1637
1638 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001639 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001640 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001641 * <p>This method requires the caller to hold the permission
1642 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001644 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 public abstract void setWallpaper(InputStream data) throws IOException;
1646
1647 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001648 * @deprecated Use {@link android.app.WallpaperManager#clear
1649 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001650 * <p>This method requires the caller to hold the permission
1651 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001653 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 public abstract void clearWallpaper() throws IOException;
1655
1656 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001657 * Same as {@link #startActivity(Intent, Bundle)} with no options
1658 * specified.
1659 *
1660 * @param intent The description of the activity to start.
1661 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001662 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001663 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001664 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001665 * @see PackageManager#resolveActivity
1666 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001667 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001668
1669 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001670 * Version of {@link #startActivity(Intent)} that allows you to specify the
1671 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001672 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001673 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001674 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001675 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001676 * @hide
1677 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001678 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Tor Norbye788fc2b2015-07-05 16:10:42 -07001679 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001680 throw new RuntimeException("Not implemented. Must override in a subclass.");
1681 }
1682
1683 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 * Launch a new activity. You will not receive any information about when
1685 * the activity exits.
1686 *
1687 * <p>Note that if this method is being called from outside of an
1688 * {@link android.app.Activity} Context, then the Intent must include
1689 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1690 * without being started from an existing Activity, there is no existing
1691 * task in which to place the new activity and thus it needs to be placed
1692 * in its own separate task.
1693 *
1694 * <p>This method throws {@link ActivityNotFoundException}
1695 * if there was no Activity found to run the given Intent.
1696 *
1697 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001698 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001699 * May be null if there are no options. See {@link android.app.ActivityOptions}
1700 * for how to build the Bundle supplied here; there are no supported definitions
1701 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001702 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001703 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 *
Scott Main60dd5202012-06-23 00:01:22 -07001705 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 * @see PackageManager#resolveActivity
1707 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001708 public abstract void startActivity(@RequiresPermission Intent intent,
1709 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001710
1711 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001712 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1713 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001714 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001715 * @param intent The description of the activity to start.
1716 * @param options Additional options for how the Activity should be started.
1717 * May be null if there are no options. See {@link android.app.ActivityOptions}
1718 * for how to build the Bundle supplied here; there are no supported definitions
1719 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001720 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001721 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001722 * @hide
1723 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001724 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Tor Norbye788fc2b2015-07-05 16:10:42 -07001725 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1726 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001727 throw new RuntimeException("Not implemented. Must override in a subclass.");
1728 }
1729
1730 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001731 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1732 * is only supported for Views and Fragments.
1733 * @param who The identifier for the calling element that will receive the result.
1734 * @param intent The intent to start.
1735 * @param requestCode The code that will be returned with onActivityResult() identifying this
1736 * request.
1737 * @param options Additional options for how the Activity should be started.
1738 * May be null if there are no options. See {@link android.app.ActivityOptions}
1739 * for how to build the Bundle supplied here; there are no supported definitions
1740 * for building it manually.
1741 * @hide
1742 */
1743 public void startActivityForResult(
1744 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1745 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1746 + "Check canStartActivityForResult() before calling.");
1747 }
1748
1749 /**
1750 * Identifies whether this Context instance will be able to process calls to
1751 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1752 * @hide
1753 */
1754 public boolean canStartActivityForResult() {
1755 return false;
1756 }
1757
1758 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001759 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1760 * specified.
1761 *
1762 * @param intents An array of Intents to be started.
1763 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001764 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001765 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001766 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001767 * @see PackageManager#resolveActivity
1768 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001769 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770
1771 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001772 * Launch multiple new activities. This is generally the same as calling
1773 * {@link #startActivity(Intent)} for the first Intent in the array,
1774 * that activity during its creation calling {@link #startActivity(Intent)}
1775 * for the second entry, etc. Note that unlike that approach, generally
1776 * none of the activities except the last in the array will be created
1777 * at this point, but rather will be created when the user first visits
1778 * them (due to pressing back from the activity on top).
1779 *
1780 * <p>This method throws {@link ActivityNotFoundException}
1781 * if there was no Activity found for <em>any</em> given Intent. In this
1782 * case the state of the activity stack is undefined (some Intents in the
1783 * list may be on it, some not), so you probably want to avoid such situations.
1784 *
1785 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001786 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001787 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001788 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001789 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001790 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001791 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001792 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001793 * @see PackageManager#resolveActivity
1794 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001795 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001796
1797 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001798 * @hide
1799 * Launch multiple new activities. This is generally the same as calling
1800 * {@link #startActivity(Intent)} for the first Intent in the array,
1801 * that activity during its creation calling {@link #startActivity(Intent)}
1802 * for the second entry, etc. Note that unlike that approach, generally
1803 * none of the activities except the last in the array will be created
1804 * at this point, but rather will be created when the user first visits
1805 * them (due to pressing back from the activity on top).
1806 *
1807 * <p>This method throws {@link ActivityNotFoundException}
1808 * if there was no Activity found for <em>any</em> given Intent. In this
1809 * case the state of the activity stack is undefined (some Intents in the
1810 * list may be on it, some not), so you probably want to avoid such situations.
1811 *
1812 * @param intents An array of Intents to be started.
1813 * @param options Additional options for how the Activity should be started.
1814 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001815 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001816 * Context.startActivity(Intent, Bundle)} for more details.
1817 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001818 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001819 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001820 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001821 * @see PackageManager#resolveActivity
1822 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001823 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001824 public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
1825 throw new RuntimeException("Not implemented. Must override in a subclass.");
1826 }
1827
1828 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001829 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1830 * with no options specified.
1831 *
1832 * @param intent The IntentSender to launch.
1833 * @param fillInIntent If non-null, this will be provided as the
1834 * intent parameter to {@link IntentSender#sendIntent}.
1835 * @param flagsMask Intent flags in the original IntentSender that you
1836 * would like to change.
1837 * @param flagsValues Desired values for any bits set in
1838 * <var>flagsMask</var>
1839 * @param extraFlags Always set to 0.
1840 *
1841 * @see #startActivity(Intent)
1842 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1843 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001844 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1845 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1846 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001847
1848 /**
1849 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001850 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001851 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001852 * here; otherwise, its associated action will be executed (such as
1853 * sending a broadcast) as if you had called
1854 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001855 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001856 * @param intent The IntentSender to launch.
1857 * @param fillInIntent If non-null, this will be provided as the
1858 * intent parameter to {@link IntentSender#sendIntent}.
1859 * @param flagsMask Intent flags in the original IntentSender that you
1860 * would like to change.
1861 * @param flagsValues Desired values for any bits set in
1862 * <var>flagsMask</var>
1863 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001864 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001865 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001866 * Context.startActivity(Intent, Bundle)} for more details. If options
1867 * have also been supplied by the IntentSender, options given here will
1868 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001869 *
1870 * @see #startActivity(Intent, Bundle)
1871 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001872 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001873 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1874 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1875 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001876
1877 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001878 * Broadcast the given intent to all interested BroadcastReceivers. This
1879 * call is asynchronous; it returns immediately, and you will continue
1880 * executing while the receivers are run. No results are propagated from
1881 * receivers and receivers can not abort the broadcast. If you want
1882 * to allow receivers to propagate results or abort the broadcast, you must
1883 * send an ordered broadcast using
1884 * {@link #sendOrderedBroadcast(Intent, String)}.
1885 *
1886 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1887 *
1888 * @param intent The Intent to broadcast; all receivers matching this
1889 * Intent will receive the broadcast.
1890 *
1891 * @see android.content.BroadcastReceiver
1892 * @see #registerReceiver
1893 * @see #sendBroadcast(Intent, String)
1894 * @see #sendOrderedBroadcast(Intent, String)
1895 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1896 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001897 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898
1899 /**
1900 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1901 * an optional required permission to be enforced. This
1902 * call is asynchronous; it returns immediately, and you will continue
1903 * executing while the receivers are run. No results are propagated from
1904 * receivers and receivers can not abort the broadcast. If you want
1905 * to allow receivers to propagate results or abort the broadcast, you must
1906 * send an ordered broadcast using
1907 * {@link #sendOrderedBroadcast(Intent, String)}.
1908 *
1909 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1910 *
1911 * @param intent The Intent to broadcast; all receivers matching this
1912 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001913 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001914 * a receiver must hold in order to receive your broadcast.
1915 * If null, no permission is required.
1916 *
1917 * @see android.content.BroadcastReceiver
1918 * @see #registerReceiver
1919 * @see #sendBroadcast(Intent)
1920 * @see #sendOrderedBroadcast(Intent, String)
1921 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1922 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001923 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001924 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001925
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001926
1927 /**
1928 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1929 * an array of required permissions to be enforced. This call is asynchronous; it returns
1930 * immediately, and you will continue executing while the receivers are run. No results are
1931 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1932 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1933 * using {@link #sendOrderedBroadcast(Intent, String)}.
1934 *
1935 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1936 *
1937 * @param intent The Intent to broadcast; all receivers matching this
1938 * Intent will receive the broadcast.
1939 * @param receiverPermissions Array of names of permissions that a receiver must hold
1940 * in order to receive your broadcast.
1941 * If null or empty, no permissions are required.
1942 *
1943 * @see android.content.BroadcastReceiver
1944 * @see #registerReceiver
1945 * @see #sendBroadcast(Intent)
1946 * @see #sendOrderedBroadcast(Intent, String)
1947 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1948 * @hide
1949 */
1950 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1951 String[] receiverPermissions);
1952
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001953 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001954 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1955 * an optional required permission to be enforced. This
1956 * call is asynchronous; it returns immediately, and you will continue
1957 * executing while the receivers are run. No results are propagated from
1958 * receivers and receivers can not abort the broadcast. If you want
1959 * to allow receivers to propagate results or abort the broadcast, you must
1960 * send an ordered broadcast using
1961 * {@link #sendOrderedBroadcast(Intent, String)}.
1962 *
1963 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1964 *
1965 * @param intent The Intent to broadcast; all receivers matching this
1966 * Intent will receive the broadcast.
1967 * @param receiverPermission (optional) String naming a permission that
1968 * a receiver must hold in order to receive your broadcast.
1969 * If null, no permission is required.
1970 * @param options (optional) Additional sending options, generated from a
1971 * {@link android.app.BroadcastOptions}.
1972 *
1973 * @see android.content.BroadcastReceiver
1974 * @see #registerReceiver
1975 * @see #sendBroadcast(Intent)
1976 * @see #sendOrderedBroadcast(Intent, String)
1977 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1978 * @hide
1979 */
1980 @SystemApi
1981 public abstract void sendBroadcast(Intent intent,
1982 @Nullable String receiverPermission,
1983 @Nullable Bundle options);
1984
1985 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001986 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07001987 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08001988 * @hide
1989 */
1990 public abstract void sendBroadcast(Intent intent,
1991 String receiverPermission, int appOp);
1992
1993 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 * Broadcast the given intent to all interested BroadcastReceivers, delivering
1995 * them one at a time to allow more preferred receivers to consume the
1996 * broadcast before it is delivered to less preferred receivers. This
1997 * call is asynchronous; it returns immediately, and you will continue
1998 * executing while the receivers are run.
1999 *
2000 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2001 *
2002 * @param intent The Intent to broadcast; all receivers matching this
2003 * Intent will receive the broadcast.
2004 * @param receiverPermission (optional) String naming a permissions that
2005 * a receiver must hold in order to receive your broadcast.
2006 * If null, no permission is required.
2007 *
2008 * @see android.content.BroadcastReceiver
2009 * @see #registerReceiver
2010 * @see #sendBroadcast(Intent)
2011 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2012 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002013 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002014 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002015
2016 /**
2017 * Version of {@link #sendBroadcast(Intent)} that allows you to
2018 * receive data back from the broadcast. This is accomplished by
2019 * supplying your own BroadcastReceiver when calling, which will be
2020 * treated as a final receiver at the end of the broadcast -- its
2021 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002022 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 * be serialized in the same way as calling
2024 * {@link #sendOrderedBroadcast(Intent, String)}.
2025 *
2026 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2027 * asynchronous; it will return before
2028 * resultReceiver.onReceive() is called.
2029 *
2030 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2031 *
2032 * @param intent The Intent to broadcast; all receivers matching this
2033 * Intent will receive the broadcast.
2034 * @param receiverPermission String naming a permissions that
2035 * a receiver must hold in order to receive your broadcast.
2036 * If null, no permission is required.
2037 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2038 * receiver of the broadcast.
2039 * @param scheduler A custom Handler with which to schedule the
2040 * resultReceiver callback; if null it will be
2041 * scheduled in the Context's main thread.
2042 * @param initialCode An initial value for the result code. Often
2043 * Activity.RESULT_OK.
2044 * @param initialData An initial value for the result data. Often
2045 * null.
2046 * @param initialExtras An initial value for the result extras. Often
2047 * null.
2048 *
2049 * @see #sendBroadcast(Intent)
2050 * @see #sendBroadcast(Intent, String)
2051 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002052 * @see android.content.BroadcastReceiver
2053 * @see #registerReceiver
2054 * @see android.app.Activity#RESULT_OK
2055 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002056 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002057 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002058 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2059 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060
2061 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002062 * Version of {@link #sendBroadcast(Intent)} that allows you to
2063 * receive data back from the broadcast. This is accomplished by
2064 * supplying your own BroadcastReceiver when calling, which will be
2065 * treated as a final receiver at the end of the broadcast -- its
2066 * {@link BroadcastReceiver#onReceive} method will be called with
2067 * the result values collected from the other receivers. The broadcast will
2068 * be serialized in the same way as calling
2069 * {@link #sendOrderedBroadcast(Intent, String)}.
2070 *
2071 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2072 * asynchronous; it will return before
2073 * resultReceiver.onReceive() is called.
2074 *
2075 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2076 *
2077 *
2078 * @param intent The Intent to broadcast; all receivers matching this
2079 * Intent will receive the broadcast.
2080 * @param receiverPermission String naming a permissions that
2081 * a receiver must hold in order to receive your broadcast.
2082 * If null, no permission is required.
2083 * @param options (optional) Additional sending options, generated from a
2084 * {@link android.app.BroadcastOptions}.
2085 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2086 * receiver of the broadcast.
2087 * @param scheduler A custom Handler with which to schedule the
2088 * resultReceiver callback; if null it will be
2089 * scheduled in the Context's main thread.
2090 * @param initialCode An initial value for the result code. Often
2091 * Activity.RESULT_OK.
2092 * @param initialData An initial value for the result data. Often
2093 * null.
2094 * @param initialExtras An initial value for the result extras. Often
2095 * null.
2096 * @see #sendBroadcast(Intent)
2097 * @see #sendBroadcast(Intent, String)
2098 * @see #sendOrderedBroadcast(Intent, String)
2099 * @see android.content.BroadcastReceiver
2100 * @see #registerReceiver
2101 * @see android.app.Activity#RESULT_OK
2102 * @hide
2103 */
2104 @SystemApi
2105 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2106 @Nullable String receiverPermission, @Nullable Bundle options,
2107 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2108 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2109
2110 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002111 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2112 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002113 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002114 * @hide
2115 */
2116 public abstract void sendOrderedBroadcast(Intent intent,
2117 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2118 Handler scheduler, int initialCode, String initialData,
2119 Bundle initialExtras);
2120
2121 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002122 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2123 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002124 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002125 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002126 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002127 * @see #sendBroadcast(Intent)
2128 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002129 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002130 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2131 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002132
2133 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002134 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2135 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002136 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002137 *
2138 * @param intent The Intent to broadcast; all receivers matching this
2139 * Intent will receive the broadcast.
2140 * @param user UserHandle to send the intent to.
2141 * @param receiverPermission (optional) String naming a permission that
2142 * a receiver must hold in order to receive your broadcast.
2143 * If null, no permission is required.
2144 *
2145 * @see #sendBroadcast(Intent, String)
2146 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002147 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002148 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2149 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002150
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002151 /**
2152 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2153 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002154 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002155 *
2156 * @param intent The Intent to broadcast; all receivers matching this
2157 * Intent will receive the broadcast.
2158 * @param user UserHandle to send the intent to.
2159 * @param receiverPermission (optional) String naming a permission that
2160 * a receiver must hold in order to receive your broadcast.
2161 * If null, no permission is required.
2162 * @param options (optional) Additional sending options, generated from a
2163 * {@link android.app.BroadcastOptions}.
2164 *
2165 * @see #sendBroadcast(Intent, String, Bundle)
2166 * @hide
2167 */
2168 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002169 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002170 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2171 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002172
2173 /**
2174 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2175 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002176 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002177 *
2178 * @param intent The Intent to broadcast; all receivers matching this
2179 * Intent will receive the broadcast.
2180 * @param user UserHandle to send the intent to.
2181 * @param receiverPermission (optional) String naming a permission that
2182 * a receiver must hold in order to receive your broadcast.
2183 * If null, no permission is required.
2184 * @param appOp The app op associated with the broadcast.
2185 *
2186 * @see #sendBroadcast(Intent, String)
2187 *
2188 * @hide
2189 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002190 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002191 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2192 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002193
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002194 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002195 * Version of
2196 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2197 * that allows you to specify the
2198 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002199 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002200 *
2201 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2202 *
2203 * @param intent The Intent to broadcast; all receivers matching this
2204 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002205 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002206 * @param receiverPermission String naming a permissions that
2207 * a receiver must hold in order to receive your broadcast.
2208 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002209 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2210 * receiver of the broadcast.
2211 * @param scheduler A custom Handler with which to schedule the
2212 * resultReceiver callback; if null it will be
2213 * scheduled in the Context's main thread.
2214 * @param initialCode An initial value for the result code. Often
2215 * Activity.RESULT_OK.
2216 * @param initialData An initial value for the result data. Often
2217 * null.
2218 * @param initialExtras An initial value for the result extras. Often
2219 * null.
2220 *
2221 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2222 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002223 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002224 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2225 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002226 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2227 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002228
2229 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002230 * Similar to above but takes an appOp as well, to enforce restrictions.
2231 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2232 * BroadcastReceiver, Handler, int, String, Bundle)
2233 * @hide
2234 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002235 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Amith Yamasani3cf75722014-05-16 12:37:29 -07002236 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2237 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2238 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2239 @Nullable Bundle initialExtras);
2240
2241 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002242 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2243 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2244 * BroadcastReceiver, Handler, int, String, Bundle)
2245 * @hide
2246 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002247 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002248 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2249 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2250 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2251 @Nullable String initialData, @Nullable Bundle initialExtras);
2252
2253 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002254 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002255 * Intent you are sending stays around after the broadcast is complete,
2256 * so that others can quickly retrieve that data through the return
2257 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2258 * all other ways, this behaves the same as
2259 * {@link #sendBroadcast(Intent)}.
2260 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002261 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2262 * can access them), no protection (anyone can modify them), and many other problems.
2263 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2264 * has changed, with another mechanism for apps to retrieve the current value whenever
2265 * desired.
2266 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002267 * @param intent The Intent to broadcast; all receivers matching this
2268 * Intent will receive the broadcast, and the Intent will be held to
2269 * be re-broadcast to future receivers.
2270 *
2271 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002272 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002273 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002274 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002275 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002276 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002277
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002278 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002279 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002280 * receive data back from the broadcast. This is accomplished by
2281 * supplying your own BroadcastReceiver when calling, which will be
2282 * treated as a final receiver at the end of the broadcast -- its
2283 * {@link BroadcastReceiver#onReceive} method will be called with
2284 * the result values collected from the other receivers. The broadcast will
2285 * be serialized in the same way as calling
2286 * {@link #sendOrderedBroadcast(Intent, String)}.
2287 *
2288 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2289 * asynchronous; it will return before
2290 * resultReceiver.onReceive() is called. Note that the sticky data
2291 * stored is only the data you initially supply to the broadcast, not
2292 * the result of any changes made by the receivers.
2293 *
2294 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2295 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002296 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2297 * can access them), no protection (anyone can modify them), and many other problems.
2298 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2299 * has changed, with another mechanism for apps to retrieve the current value whenever
2300 * desired.
2301 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002302 * @param intent The Intent to broadcast; all receivers matching this
2303 * Intent will receive the broadcast.
2304 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2305 * receiver of the broadcast.
2306 * @param scheduler A custom Handler with which to schedule the
2307 * resultReceiver callback; if null it will be
2308 * scheduled in the Context's main thread.
2309 * @param initialCode An initial value for the result code. Often
2310 * Activity.RESULT_OK.
2311 * @param initialData An initial value for the result data. Often
2312 * null.
2313 * @param initialExtras An initial value for the result extras. Often
2314 * null.
2315 *
2316 * @see #sendBroadcast(Intent)
2317 * @see #sendBroadcast(Intent, String)
2318 * @see #sendOrderedBroadcast(Intent, String)
2319 * @see #sendStickyBroadcast(Intent)
2320 * @see android.content.BroadcastReceiver
2321 * @see #registerReceiver
2322 * @see android.app.Activity#RESULT_OK
2323 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002324 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002325 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002326 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002327 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002328 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2329 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002331 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002332 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002333 * so that it is as if the sticky broadcast had never happened.
2334 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002335 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2336 * can access them), no protection (anyone can modify them), and many other problems.
2337 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2338 * has changed, with another mechanism for apps to retrieve the current value whenever
2339 * desired.
2340 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002341 * @param intent The Intent that was previously broadcast.
2342 *
2343 * @see #sendStickyBroadcast
2344 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002345 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002346 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002347 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348
2349 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002350 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002351 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002352 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002353 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002354 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2355 * can access them), no protection (anyone can modify them), and many other problems.
2356 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2357 * has changed, with another mechanism for apps to retrieve the current value whenever
2358 * desired.
2359 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002360 * @param intent The Intent to broadcast; all receivers matching this
2361 * Intent will receive the broadcast, and the Intent will be held to
2362 * be re-broadcast to future receivers.
2363 * @param user UserHandle to send the intent to.
2364 *
2365 * @see #sendBroadcast(Intent)
2366 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002367 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002368 @RequiresPermission(allOf = {
2369 android.Manifest.permission.INTERACT_ACROSS_USERS,
2370 android.Manifest.permission.BROADCAST_STICKY
2371 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002372 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2373 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002374
2375 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002376 * @hide
2377 * This is just here for sending CONNECTIVITY_ACTION.
2378 */
2379 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002380 @RequiresPermission(allOf = {
2381 android.Manifest.permission.INTERACT_ACROSS_USERS,
2382 android.Manifest.permission.BROADCAST_STICKY
2383 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002384 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2385 UserHandle user, Bundle options);
2386
2387 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002388 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002389 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2390 * that allows you to specify the
2391 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002392 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002393 *
2394 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2395 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002396 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2397 * can access them), no protection (anyone can modify them), and many other problems.
2398 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2399 * has changed, with another mechanism for apps to retrieve the current value whenever
2400 * desired.
2401 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002402 * @param intent The Intent to broadcast; all receivers matching this
2403 * Intent will receive the broadcast.
2404 * @param user UserHandle to send the intent to.
2405 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2406 * receiver of the broadcast.
2407 * @param scheduler A custom Handler with which to schedule the
2408 * resultReceiver callback; if null it will be
2409 * scheduled in the Context's main thread.
2410 * @param initialCode An initial value for the result code. Often
2411 * Activity.RESULT_OK.
2412 * @param initialData An initial value for the result data. Often
2413 * null.
2414 * @param initialExtras An initial value for the result extras. Often
2415 * null.
2416 *
2417 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2418 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002419 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002420 @RequiresPermission(allOf = {
2421 android.Manifest.permission.INTERACT_ACROSS_USERS,
2422 android.Manifest.permission.BROADCAST_STICKY
2423 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002424 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002425 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002426 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2427 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002428
2429 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002430 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002431 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002432 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002433 *
2434 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2435 * permission in order to use this API. If you do not hold that
2436 * permission, {@link SecurityException} will be thrown.
2437 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002438 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2439 * can access them), no protection (anyone can modify them), and many other problems.
2440 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2441 * has changed, with another mechanism for apps to retrieve the current value whenever
2442 * desired.
2443 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002444 * @param intent The Intent that was previously broadcast.
2445 * @param user UserHandle to remove the sticky broadcast from.
2446 *
2447 * @see #sendStickyBroadcastAsUser
2448 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002449 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002450 @RequiresPermission(allOf = {
2451 android.Manifest.permission.INTERACT_ACROSS_USERS,
2452 android.Manifest.permission.BROADCAST_STICKY
2453 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002454 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2455 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002456
2457 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002458 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002459 * <var>receiver</var> will be called with any broadcast Intent that
2460 * matches <var>filter</var>, in the main application thread.
2461 *
2462 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002463 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 * registrations. If your IntentFilter matches one of these sticky
2465 * Intents, that Intent will be returned by this function
2466 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2467 * been broadcast.
2468 *
2469 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2470 * in which case each of these will be sent to <var>receiver</var>. In
2471 * this case, only one of these can be returned directly by the function;
2472 * which of these that is returned is arbitrarily decided by the system.
2473 *
2474 * <p>If you know the Intent your are registering for is sticky, you can
2475 * supply null for your <var>receiver</var>. In this case, no receiver is
2476 * registered -- the function simply returns the sticky Intent that
2477 * matches <var>filter</var>. In the case of multiple matches, the same
2478 * rules as described above apply.
2479 *
2480 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2481 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002482 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2483 * registered with this method will correctly respect the
2484 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2485 * Prior to that, it would be ignored and delivered to all matching registered
2486 * receivers. Be careful if using this for security.</p>
2487 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002488 * <p class="note">Note: this method <em>cannot be called from a
2489 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2490 * that is declared in an application's manifest. It is okay, however, to call
2491 * this method from another BroadcastReceiver that has itself been registered
2492 * at run time with {@link #registerReceiver}, since the lifetime of such a
2493 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 *
2495 * @param receiver The BroadcastReceiver to handle the broadcast.
2496 * @param filter Selects the Intent broadcasts to be received.
2497 *
2498 * @return The first sticky intent found that matches <var>filter</var>,
2499 * or null if there are none.
2500 *
2501 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2502 * @see #sendBroadcast
2503 * @see #unregisterReceiver
2504 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002505 @Nullable
2506 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002507 IntentFilter filter);
2508
2509 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002510 * Register to receive intent broadcasts, with the receiver optionally being
2511 * exposed to Instant Apps. See
2512 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2513 * information. By default Instant Apps cannot interact with receivers in other
2514 * applications, this allows you to expose a receiver that Instant Apps can
2515 * interact with.
2516 *
2517 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2518 *
2519 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2520 * registered with this method will correctly respect the
2521 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2522 * Prior to that, it would be ignored and delivered to all matching registered
2523 * receivers. Be careful if using this for security.</p>
2524 *
2525 * @param receiver The BroadcastReceiver to handle the broadcast.
2526 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002527 * @param flags Additional options for the receiver. May be 0 or
2528 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002529 *
2530 * @return The first sticky intent found that matches <var>filter</var>,
2531 * or null if there are none.
2532 *
2533 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2534 * @see #sendBroadcast
2535 * @see #unregisterReceiver
2536 */
2537 @Nullable
2538 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2539 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002540 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002541
2542 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002543 * Register to receive intent broadcasts, to run in the context of
2544 * <var>scheduler</var>. See
2545 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2546 * information. This allows you to enforce permissions on who can
2547 * broadcast intents to your receiver, or have the receiver run in
2548 * a different thread than the main application thread.
2549 *
2550 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2551 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002552 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2553 * registered with this method will correctly respect the
2554 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2555 * Prior to that, it would be ignored and delivered to all matching registered
2556 * receivers. Be careful if using this for security.</p>
2557 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002558 * @param receiver The BroadcastReceiver to handle the broadcast.
2559 * @param filter Selects the Intent broadcasts to be received.
2560 * @param broadcastPermission String naming a permissions that a
2561 * broadcaster must hold in order to send an Intent to you. If null,
2562 * no permission is required.
2563 * @param scheduler Handler identifying the thread that will receive
2564 * the Intent. If null, the main thread of the process will be used.
2565 *
2566 * @return The first sticky intent found that matches <var>filter</var>,
2567 * or null if there are none.
2568 *
2569 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2570 * @see #sendBroadcast
2571 * @see #unregisterReceiver
2572 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002573 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002574 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002575 IntentFilter filter, @Nullable String broadcastPermission,
2576 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002577
2578 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002579 * Register to receive intent broadcasts, to run in the context of
2580 * <var>scheduler</var>. See
2581 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002582 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2583 * for more information.
2584 *
2585 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2586 *
2587 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2588 * registered with this method will correctly respect the
2589 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2590 * Prior to that, it would be ignored and delivered to all matching registered
2591 * receivers. Be careful if using this for security.</p>
2592 *
2593 * @param receiver The BroadcastReceiver to handle the broadcast.
2594 * @param filter Selects the Intent broadcasts to be received.
2595 * @param broadcastPermission String naming a permissions that a
2596 * broadcaster must hold in order to send an Intent to you. If null,
2597 * no permission is required.
2598 * @param scheduler Handler identifying the thread that will receive
2599 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002600 * @param flags Additional options for the receiver. May be 0 or
2601 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002602 *
2603 * @return The first sticky intent found that matches <var>filter</var>,
2604 * or null if there are none.
2605 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002606 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002607 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2608 * @see #sendBroadcast
2609 * @see #unregisterReceiver
2610 */
2611 @Nullable
2612 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2613 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002614 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002615
2616 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002617 * @hide
2618 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2619 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002620 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002621 *
2622 * @param receiver The BroadcastReceiver to handle the broadcast.
2623 * @param user UserHandle to send the intent to.
2624 * @param filter Selects the Intent broadcasts to be received.
2625 * @param broadcastPermission String naming a permissions that a
2626 * broadcaster must hold in order to send an Intent to you. If null,
2627 * no permission is required.
2628 * @param scheduler Handler identifying the thread that will receive
2629 * the Intent. If null, the main thread of the process will be used.
2630 *
2631 * @return The first sticky intent found that matches <var>filter</var>,
2632 * or null if there are none.
2633 *
Jeff Brown6e539312015-02-24 18:53:21 -08002634 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002635 * @see #sendBroadcast
2636 * @see #unregisterReceiver
2637 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002638 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002639 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002640 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002641 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2642 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643
2644 /**
2645 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2646 * filters that have been registered for this BroadcastReceiver will be
2647 * removed.
2648 *
2649 * @param receiver The BroadcastReceiver to unregister.
2650 *
2651 * @see #registerReceiver
2652 */
2653 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2654
2655 /**
2656 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002657 * should either contain the complete class name of a specific service
2658 * implementation to start, or a specific package name to target. If the
2659 * Intent is less specified, it logs a warning about this. In this case any of the
2660 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 * is not already running, it will be instantiated and started (creating a
2662 * process for it if needed); if it is running then it remains running.
2663 *
2664 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002665 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 * with the <var>intent</var> given here. This provides a convenient way
2667 * to submit jobs to a service without having to bind and call on to its
2668 * interface.
2669 *
2670 * <p>Using startService() overrides the default service lifetime that is
2671 * managed by {@link #bindService}: it requires the service to remain
2672 * running until {@link #stopService} is called, regardless of whether
2673 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002674 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002675 * a single call to {@link #stopService} will stop it.
2676 *
2677 * <p>The system attempts to keep running services around as much as
2678 * possible. The only time they should be stopped is if the current
2679 * foreground application is using so many resources that the service needs
2680 * to be killed. If any errors happen in the service's process, it will
2681 * automatically be restarted.
2682 *
2683 * <p>This function will throw {@link SecurityException} if you do not
2684 * have permission to start the given service.
2685 *
Chris Craik1e353522016-04-18 10:20:50 -07002686 * <p class="note"><strong>Note:</strong> Each call to startService()
2687 * results in significant work done by the system to manage service
2688 * lifecycle surrounding the processing of the intent, which can take
2689 * multiple milliseconds of CPU time. Due to this cost, startService()
2690 * should not be used for frequent intent delivery to a service, and only
2691 * for scheduling significant work. Use {@link #bindService bound services}
2692 * for high frequency calls.
2693 * </p>
2694 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002695 * @param service Identifies the service to be started. The Intent must be
2696 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 * may be included in the Intent extras to supply arguments along with
2698 * this specific start call.
2699 *
2700 * @return If the service is being started or is already running, the
2701 * {@link ComponentName} of the actual service that was started is
2702 * returned; else if the service does not exist null is returned.
2703 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002704 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002705 * or the service can not be found.
2706 * @throws IllegalStateException If the application is in a state where the service
2707 * 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 -08002708 *
2709 * @see #stopService
2710 * @see #bindService
2711 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002712 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 public abstract ComponentName startService(Intent service);
2714
2715 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002716 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002717 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2718 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002719 * an amount of time comparable to the ANR interval to do this, otherwise the system
2720 * will automatically stop the service and declare the app ANR.
2721 *
2722 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2723 * at any time, regardless of whether the app hosting the service is in a foreground
2724 * state.
2725 *
2726 * @param service Identifies the service to be started. The Intent must be
2727 * fully explicit (supplying a component name). Additional values
2728 * may be included in the Intent extras to supply arguments along with
2729 * this specific start call.
2730 *
2731 * @return If the service is being started or is already running, the
2732 * {@link ComponentName} of the actual service that was started is
2733 * returned; else if the service does not exist null is returned.
2734 *
2735 * @throws SecurityException If the caller does not have permission to access the service
2736 * or the service can not be found.
2737 *
2738 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002739 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002740 */
2741 @Nullable
2742 public abstract ComponentName startForegroundService(Intent service);
2743
2744 /**
2745 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2746 */
2747 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002748 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002749 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2750
2751 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 * Request that a given application service be stopped. If the service is
2753 * not running, nothing happens. Otherwise it is stopped. Note that calls
2754 * to startService() are not counted -- this stops the service no matter
2755 * how many times it was started.
2756 *
2757 * <p>Note that if a stopped service still has {@link ServiceConnection}
2758 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2759 * not be destroyed until all of these bindings are removed. See
2760 * the {@link android.app.Service} documentation for more details on a
2761 * service's lifecycle.
2762 *
2763 * <p>This function will throw {@link SecurityException} if you do not
2764 * have permission to stop the given service.
2765 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002766 * @param service Description of the service to be stopped. The Intent must be either
2767 * fully explicit (supplying a component name) or specify a specific package
2768 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002769 *
2770 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002771 * 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 -08002772 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002773 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002774 * or the service can not be found.
2775 * @throws IllegalStateException If the application is in a state where the service
2776 * 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 -08002777 *
2778 * @see #startService
2779 */
2780 public abstract boolean stopService(Intent service);
2781
2782 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002783 * @hide like {@link #startService(Intent)} but for a specific user.
2784 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002785 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002786 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002787 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2788
2789 /**
2790 * @hide like {@link #stopService(Intent)} but for a specific user.
2791 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002792 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002793 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002794
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002795 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 * Connect to an application service, creating it if needed. This defines
2797 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002798 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002799 * told if it dies and restarts. The service will be considered required
2800 * by the system only for as long as the calling context exists. For
2801 * example, if this Context is an Activity that is stopped, the service will
2802 * not be required to continue running until the Activity is resumed.
2803 *
2804 * <p>This function will throw {@link SecurityException} if you do not
2805 * have permission to bind to the given service.
2806 *
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002807 * <p class="note">Note: this method <em>can not be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002808 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002809 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002810 * {@link #startService} with the arguments containing the command to be
2811 * sent, with the service calling its
2812 * {@link android.app.Service#stopSelf(int)} method when done executing
2813 * that command. See the API demo App/Service/Service Start Arguments
2814 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002815 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2817 * is tied to another object (the one that registered it).</p>
2818 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002819 * @param service Identifies the service to connect to. The Intent must
2820 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002822 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002823 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002824 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2825 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2826 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2827 * {@link #BIND_WAIVE_PRIORITY}.
Kevin Hufnagled195a992017-06-29 15:58:48 -07002828 * @return {@code true} if the system is in the process of bringing up a
2829 * service that your client has permission to bind to; {@code false}
2830 * if the system couldn't find the service or if your client doesn't
2831 * have permission to bind to it. If this value is {@code true}, you
2832 * should later call {@link #unbindService} to release the
2833 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002834 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002835 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002836 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002837 *
2838 * @see #unbindService
2839 * @see #startService
2840 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002841 * @see #BIND_DEBUG_UNBIND
2842 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002843 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002844 public abstract boolean bindService(@RequiresPermission Intent service,
2845 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002846
2847 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002848 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002849 * argument for use by system server and other multi-user aware code.
2850 * @hide
2851 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002852 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002853 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002854 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002855 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002856 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002857 throw new RuntimeException("Not implemented. Must override in a subclass.");
2858 }
2859
2860 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002861 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2862 * explicit non-null Handler to run the ServiceConnection callbacks on.
2863 *
2864 * @hide
2865 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002866 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Adrian Roos691546e2016-02-09 10:13:41 -08002867 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2868 Handler handler, UserHandle user) {
2869 throw new RuntimeException("Not implemented. Must override in a subclass.");
2870 }
2871
2872 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 * Disconnect from an application service. You will no longer receive
2874 * calls as the service is restarted, and the service is now allowed to
2875 * stop at any time.
2876 *
2877 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002878 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 *
2880 * @see #bindService
2881 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002882 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002883
2884 /**
2885 * Start executing an {@link android.app.Instrumentation} class. The given
2886 * Instrumentation component will be run by killing its target application
2887 * (if currently running), starting the target process, instantiating the
2888 * instrumentation component, and then letting it drive the application.
2889 *
2890 * <p>This function is not synchronous -- it returns as soon as the
2891 * instrumentation has started and while it is running.
2892 *
2893 * <p>Instrumentation is normally only allowed to run against a package
2894 * that is either unsigned or signed with a signature that the
2895 * the instrumentation package is also signed with (ensuring the target
2896 * trusts the instrumentation).
2897 *
2898 * @param className Name of the Instrumentation component to be run.
2899 * @param profileFile Optional path to write profiling data as the
2900 * instrumentation runs, or null for no profiling.
2901 * @param arguments Additional optional arguments to pass to the
2902 * instrumentation, or null.
2903 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002904 * @return {@code true} if the instrumentation was successfully started,
2905 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002907 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2908 @Nullable String profileFile, @Nullable Bundle arguments);
2909
2910 /** @hide */
2911 @StringDef({
2912 POWER_SERVICE,
2913 WINDOW_SERVICE,
2914 LAYOUT_INFLATER_SERVICE,
2915 ACCOUNT_SERVICE,
2916 ACTIVITY_SERVICE,
2917 ALARM_SERVICE,
2918 NOTIFICATION_SERVICE,
2919 ACCESSIBILITY_SERVICE,
2920 CAPTIONING_SERVICE,
2921 KEYGUARD_SERVICE,
2922 LOCATION_SERVICE,
2923 //@hide: COUNTRY_DETECTOR,
2924 SEARCH_SERVICE,
2925 SENSOR_SERVICE,
2926 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07002927 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002928 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00002929 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002930 VIBRATOR_SERVICE,
2931 //@hide: STATUS_BAR_SERVICE,
2932 CONNECTIVITY_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08002933 IPSEC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002934 //@hide: UPDATE_LOCK_SERVICE,
2935 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002936 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002937 //@hide: NETWORK_POLICY_SERVICE,
2938 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07002939 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002940 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002941 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07002942 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002943 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002944 //@hide: ETHERNET_SERVICE,
Vinit Deshpande7686c062014-06-30 15:25:01 -07002945 WIFI_RTT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002946 NSD_SERVICE,
2947 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002948 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002949 MEDIA_ROUTER_SERVICE,
2950 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002951 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002952 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002953 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002954 CLIPBOARD_SERVICE,
2955 INPUT_METHOD_SERVICE,
2956 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01002957 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002958 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002959 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002960 //@hide: BACKUP_SERVICE,
2961 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07002962 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07002963 DEVICE_POLICY_SERVICE,
2964 UI_MODE_SERVICE,
2965 DOWNLOAD_SERVICE,
2966 NFC_SERVICE,
2967 BLUETOOTH_SERVICE,
2968 //@hide: SIP_SERVICE,
2969 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08002970 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002971 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002972 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002973 INPUT_SERVICE,
2974 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002975 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002976 RESTRICTIONS_SERVICE,
2977 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002978 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002979 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002980 CONSUMER_IR_SERVICE,
2981 //@hide: TRUST_SERVICE,
2982 TV_INPUT_SERVICE,
2983 //@hide: NETWORK_SCORE_SERVICE,
2984 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08002985 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08002986 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07002987 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002988 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00002989 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08002990 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08002991 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08002992 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01002993 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08002994 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08002995 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08002996 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08002997 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07002998 //@hide: INCIDENT_SERVICE,
2999 COMPANION_DEVICE_SERVICE
Tor Norbyed9273d62013-05-30 15:59:53 -07003000 })
3001 @Retention(RetentionPolicy.SOURCE)
3002 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003
3004 /**
3005 * Return the handle to a system-level service by name. The class of the
3006 * returned object varies by the requested name. Currently available names
3007 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003008 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 * <dl>
3010 * <dt> {@link #WINDOW_SERVICE} ("window")
3011 * <dd> The top-level window manager in which you can place custom
3012 * windows. The returned object is a {@link android.view.WindowManager}.
3013 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3014 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3015 * in this context.
3016 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3017 * <dd> A {@link android.app.ActivityManager} for interacting with the
3018 * global activity state of the system.
3019 * <dt> {@link #POWER_SERVICE} ("power")
3020 * <dd> A {@link android.os.PowerManager} for controlling power
3021 * management.
3022 * <dt> {@link #ALARM_SERVICE} ("alarm")
3023 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3024 * time of your choosing.
3025 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3026 * <dd> A {@link android.app.NotificationManager} for informing the user
3027 * of background events.
3028 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3029 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3030 * <dt> {@link #LOCATION_SERVICE} ("location")
3031 * <dd> A {@link android.location.LocationManager} for controlling location
3032 * (e.g., GPS) updates.
3033 * <dt> {@link #SEARCH_SERVICE} ("search")
3034 * <dd> A {@link android.app.SearchManager} for handling search.
3035 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3036 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3037 * hardware.
3038 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3039 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3040 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003041 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3042 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3043 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003044 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003045 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3046 * connectivity. On releases before NYC, it should only be obtained from an application
3047 * context, and not from any other derived context to avoid memory leaks within the calling
3048 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003049 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3050 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3051 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003052 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3053 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3054 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003055 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3056 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3057 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003058 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3059 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003060 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003061 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003062 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003063 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003064 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3065 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003066 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3067 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3068 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003069 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003070 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003071 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003072 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 * <p>Note: System services obtained via this API may be closely associated with
3074 * the Context in which they are obtained from. In general, do not share the
3075 * service objects between various different contexts (Activities, Applications,
3076 * Services, Providers, etc.)
3077 *
3078 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003079 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003080 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003081 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003082 * @see #WINDOW_SERVICE
3083 * @see android.view.WindowManager
3084 * @see #LAYOUT_INFLATER_SERVICE
3085 * @see android.view.LayoutInflater
3086 * @see #ACTIVITY_SERVICE
3087 * @see android.app.ActivityManager
3088 * @see #POWER_SERVICE
3089 * @see android.os.PowerManager
3090 * @see #ALARM_SERVICE
3091 * @see android.app.AlarmManager
3092 * @see #NOTIFICATION_SERVICE
3093 * @see android.app.NotificationManager
3094 * @see #KEYGUARD_SERVICE
3095 * @see android.app.KeyguardManager
3096 * @see #LOCATION_SERVICE
3097 * @see android.location.LocationManager
3098 * @see #SEARCH_SERVICE
3099 * @see android.app.SearchManager
3100 * @see #SENSOR_SERVICE
3101 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003102 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003103 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 * @see #VIBRATOR_SERVICE
3105 * @see android.os.Vibrator
3106 * @see #CONNECTIVITY_SERVICE
3107 * @see android.net.ConnectivityManager
3108 * @see #WIFI_SERVICE
3109 * @see android.net.wifi.WifiManager
3110 * @see #AUDIO_SERVICE
3111 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003112 * @see #MEDIA_ROUTER_SERVICE
3113 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003114 * @see #TELEPHONY_SERVICE
3115 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003116 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3117 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003118 * @see #CARRIER_CONFIG_SERVICE
3119 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 * @see #INPUT_METHOD_SERVICE
3121 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003122 * @see #UI_MODE_SERVICE
3123 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003124 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003125 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003126 * @see #BATTERY_SERVICE
3127 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003128 * @see #JOB_SCHEDULER_SERVICE
3129 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003130 * @see #NETWORK_STATS_SERVICE
3131 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003132 * @see android.os.HardwarePropertiesManager
3133 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003135 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136
3137 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003138 * Return the handle to a system-level service by class.
3139 * <p>
3140 * Currently available classes are:
3141 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3142 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3143 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3144 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3145 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3146 * {@link android.net.ConnectivityManager},
3147 * {@link android.net.wifi.WifiManager},
3148 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3149 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3150 * {@link android.view.inputmethod.InputMethodManager},
3151 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003152 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3153 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08003154 * </p><p>
3155 * Note: System services obtained via this API may be closely associated with
3156 * the Context in which they are obtained from. In general, do not share the
3157 * service objects between various different contexts (Activities, Applications,
3158 * Services, Providers, etc.)
3159 * </p>
3160 *
3161 * @param serviceClass The class of the desired service.
3162 * @return The service or null if the class is not a supported system service.
3163 */
3164 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003165 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003166 // Because subclasses may override getSystemService(String) we cannot
3167 // perform a lookup by class alone. We must first map the class to its
3168 // service name then invoke the string-based method.
3169 String serviceName = getSystemServiceName(serviceClass);
3170 return serviceName != null ? (T)getSystemService(serviceName) : null;
3171 }
3172
3173 /**
3174 * Gets the name of the system-level service that is represented by the specified class.
3175 *
3176 * @param serviceClass The class of the desired service.
3177 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003178 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003179 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003180
3181 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182 * Use with {@link #getSystemService} to retrieve a
3183 * {@link android.os.PowerManager} for controlling power management,
3184 * including "wake locks," which let you keep the device on while
3185 * you're running long tasks.
3186 */
3187 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003188
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 /**
3190 * Use with {@link #getSystemService} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003191 * {@link android.os.RecoverySystem} for accessing the recovery system
3192 * service.
3193 *
3194 * @see #getSystemService
3195 * @hide
3196 */
3197 public static final String RECOVERY_SERVICE = "recovery";
3198
3199 /**
3200 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003201 * {@link android.view.WindowManager} for accessing the system's window
3202 * manager.
3203 *
3204 * @see #getSystemService
3205 * @see android.view.WindowManager
3206 */
3207 public static final String WINDOW_SERVICE = "window";
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
3211 * {@link android.view.LayoutInflater} for inflating layout resources in this
3212 * context.
3213 *
3214 * @see #getSystemService
3215 * @see android.view.LayoutInflater
3216 */
3217 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003219 /**
3220 * Use with {@link #getSystemService} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003221 * {@link android.accounts.AccountManager} for receiving intents at a
3222 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003223 *
3224 * @see #getSystemService
3225 * @see android.accounts.AccountManager
3226 */
3227 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003228
Fred Quintana60307342009-03-24 22:48:12 -07003229 /**
3230 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003231 * {@link android.app.ActivityManager} for interacting with the global
3232 * system state.
3233 *
3234 * @see #getSystemService
3235 * @see android.app.ActivityManager
3236 */
3237 public static final String ACTIVITY_SERVICE = "activity";
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.AlarmManager} for receiving intents at a
3242 * time of your choosing.
3243 *
3244 * @see #getSystemService
3245 * @see android.app.AlarmManager
3246 */
3247 public static final String ALARM_SERVICE = "alarm";
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
3251 * {@link android.app.NotificationManager} for informing the user of
3252 * background events.
3253 *
3254 * @see #getSystemService
3255 * @see android.app.NotificationManager
3256 */
3257 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003259 /**
3260 * Use with {@link #getSystemService} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003261 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3262 * feedback for UI events through the registered event listeners.
3263 *
3264 * @see #getSystemService
3265 * @see android.view.accessibility.AccessibilityManager
3266 */
3267 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003268
svetoslavganov75986cf2009-05-14 22:28:01 -07003269 /**
3270 * Use with {@link #getSystemService} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003271 * {@link android.view.accessibility.CaptioningManager} for obtaining
3272 * captioning properties and listening for changes in captioning
3273 * preferences.
3274 *
3275 * @see #getSystemService
3276 * @see android.view.accessibility.CaptioningManager
3277 */
3278 public static final String CAPTIONING_SERVICE = "captioning";
3279
3280 /**
3281 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003282 * {@link android.app.NotificationManager} for controlling keyguard.
3283 *
3284 * @see #getSystemService
3285 * @see android.app.KeyguardManager
3286 */
3287 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 /**
3290 * Use with {@link #getSystemService} to retrieve a {@link
3291 * android.location.LocationManager} for controlling location
3292 * updates.
3293 *
3294 * @see #getSystemService
3295 * @see android.location.LocationManager
3296 */
3297 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003298
3299 /**
3300 * Use with {@link #getSystemService} to retrieve a
3301 * {@link android.location.CountryDetector} for detecting the country that
3302 * the user is in.
3303 *
3304 * @hide
3305 */
3306 public static final String COUNTRY_DETECTOR = "country_detector";
3307
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 /**
3309 * Use with {@link #getSystemService} to retrieve a {@link
3310 * android.app.SearchManager} for handling searches.
3311 *
3312 * @see #getSystemService
3313 * @see android.app.SearchManager
3314 */
3315 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 /**
3318 * Use with {@link #getSystemService} to retrieve a {@link
3319 * android.hardware.SensorManager} for accessing sensors.
3320 *
3321 * @see #getSystemService
3322 * @see android.hardware.SensorManager
3323 */
3324 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 /**
San Mehatc9d81752010-02-01 10:23:27 -08003327 * Use with {@link #getSystemService} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003328 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003329 * functions.
3330 *
3331 * @see #getSystemService
San Mehatb1043402010-02-05 08:26:50 -08003332 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003333 */
3334 public static final String STORAGE_SERVICE = "storage";
3335
3336 /**
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003337 * Use with {@link #getSystemService} to retrieve a {@link
3338 * android.app.usage.StorageStatsManager} for accessing system storage
3339 * statistics.
3340 *
3341 * @see #getSystemService
3342 * @see android.app.usage.StorageStatsManager
3343 */
3344 public static final String STORAGE_STATS_SERVICE = "storagestats";
3345
3346 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003347 * Use with {@link #getSystemService} to retrieve a
3348 * com.android.server.WallpaperService for accessing wallpapers.
3349 *
3350 * @see #getSystemService
3351 */
3352 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003354 /**
3355 * Use with {@link #getSystemService} to retrieve a {@link
3356 * android.os.Vibrator} for interacting with the vibration hardware.
3357 *
3358 * @see #getSystemService
3359 * @see android.os.Vibrator
3360 */
3361 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003363 /**
3364 * Use with {@link #getSystemService} to retrieve a {@link
3365 * android.app.StatusBarManager} for interacting with the status bar.
3366 *
3367 * @see #getSystemService
3368 * @see android.app.StatusBarManager
3369 * @hide
3370 */
3371 public static final String STATUS_BAR_SERVICE = "statusbar";
3372
3373 /**
3374 * Use with {@link #getSystemService} to retrieve a {@link
3375 * android.net.ConnectivityManager} for handling management of
3376 * network connections.
3377 *
3378 * @see #getSystemService
3379 * @see android.net.ConnectivityManager
3380 */
3381 public static final String CONNECTIVITY_SERVICE = "connectivity";
3382
3383 /**
Nathan Harold330e1082017-01-12 18:38:57 -08003384 * Use with {@link #getSystemService} to retrieve a
3385 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3386 * IPSec.
3387 *
3388 * @see #getSystemService
3389 */
3390 public static final String IPSEC_SERVICE = "ipsec";
3391
3392 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003393 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003394 * android.os.IUpdateLock} for managing runtime sequences that
3395 * must not be interrupted by headless OTA application or similar.
3396 *
3397 * @hide
3398 * @see #getSystemService
3399 * @see android.os.UpdateLock
3400 */
3401 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3402
3403 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003404 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003405 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003406 */
3407 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3408
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003409 /**
3410 * Use with {@link #getSystemService} to retrieve a {@link
3411 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3412 *
3413 * @see #getSystemService
3414 * @see android.app.usage.NetworkStatsManager
3415 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003416 public static final String NETWORK_STATS_SERVICE = "netstats";
3417 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003418 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
3419
San Mehatd1df8ac2010-01-26 06:17:26 -08003420 /**
3421 * Use with {@link #getSystemService} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003422 * android.net.wifi.WifiManager} for handling management of
3423 * Wi-Fi access.
3424 *
3425 * @see #getSystemService
3426 * @see android.net.wifi.WifiManager
3427 */
3428 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 /**
repo sync55bc5f32011-06-24 14:23:07 -07003431 * Use with {@link #getSystemService} to retrieve a {@link
3432 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003433 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003434 *
3435 * @see #getSystemService
3436 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003437 */
3438 public static final String WIFI_P2P_SERVICE = "wifip2p";
3439
3440 /**
Etan Cohen20d329b2015-09-29 13:49:02 -07003441 * Use with {@link #getSystemService} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003442 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3443 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003444 *
3445 * @see #getSystemService
Etan Cohen04133272016-10-26 11:22:06 -07003446 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003447 */
Etan Cohen04133272016-10-26 11:22:06 -07003448 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003449
3450 /**
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003451 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003452 * android.net.wifi.WifiScanner} for scanning the wifi universe
3453 *
3454 * @see #getSystemService
3455 * @see android.net.wifi.WifiScanner
3456 * @hide
3457 */
Wei Wang35d552f2014-07-08 21:37:01 -07003458 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003459 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3460
3461 /**
3462 * Use with {@link #getSystemService} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003463 * android.net.wifi.RttManager} for ranging devices with wifi
3464 *
3465 * @see #getSystemService
3466 * @see android.net.wifi.RttManager
3467 * @hide
3468 */
3469 @SystemApi
3470 public static final String WIFI_RTT_SERVICE = "rttmanager";
3471
3472 /**
3473 * Use with {@link #getSystemService} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003474 * android.net.lowpan.LowpanManager} for handling management of
3475 * LoWPAN access.
3476 *
3477 * @see #getSystemService
3478 * @see android.net.lowpan.LowpanManager
3479 *
3480 * @hide
3481 */
3482 public static final String LOWPAN_SERVICE = "lowpan";
3483
3484 /**
3485 * Use with {@link #getSystemService} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003486 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003487 * Ethernet access.
3488 *
3489 * @see #getSystemService
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003490 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003491 *
3492 * @hide
3493 */
3494 public static final String ETHERNET_SERVICE = "ethernet";
3495
3496 /**
3497 * Use with {@link #getSystemService} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003498 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003499 * discovery
3500 *
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003501 * @see #getSystemService
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003502 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003503 */
3504 public static final String NSD_SERVICE = "servicediscovery";
3505
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003506 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 * Use with {@link #getSystemService} to retrieve a
3508 * {@link android.media.AudioManager} for handling management of volume,
3509 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003510 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 * @see #getSystemService
3512 * @see android.media.AudioManager
3513 */
3514 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003516 /**
3517 * Use with {@link #getSystemService} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003518 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003519 * of fingerprints.
3520 *
3521 * @see #getSystemService
Jim Millerce7eb6d2015-04-03 19:29:13 -07003522 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003523 */
3524 public static final String FINGERPRINT_SERVICE = "fingerprint";
3525
3526 /**
3527 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003528 * {@link android.media.MediaRouter} for controlling and managing
3529 * routing of media.
3530 *
3531 * @see #getSystemService
3532 * @see android.media.MediaRouter
3533 */
3534 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3535
3536 /**
3537 * Use with {@link #getSystemService} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003538 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003539 *
3540 * @see #getSystemService
RoboErik42ea7ee2014-05-16 16:27:35 -07003541 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003542 */
3543 public static final String MEDIA_SESSION_SERVICE = "media_session";
3544
3545 /**
3546 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 * {@link android.telephony.TelephonyManager} for handling management the
3548 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003549 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 * @see #getSystemService
3551 * @see android.telephony.TelephonyManager
3552 */
3553 public static final String TELEPHONY_SERVICE = "phone";
3554
3555 /**
3556 * Use with {@link #getSystemService} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003557 * {@link android.telephony.SubscriptionManager} for handling management the
3558 * telephony subscriptions of the device.
3559 *
3560 * @see #getSystemService
3561 * @see android.telephony.SubscriptionManager
3562 */
3563 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3564
3565 /**
3566 * Use with {@link #getSystemService} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003567 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003568 * of the device.
3569 *
3570 * @see #getSystemService
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003571 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003572 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003573 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003574
3575 /**
3576 * Use with {@link #getSystemService} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003577 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3578 *
3579 * @see #getSystemService
3580 * @see android.telephony.CarrierConfigManager
3581 */
3582 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3583
3584 /**
3585 * Use with {@link #getSystemService} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08003586 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
3587 *
3588 * @see #getSystemService
3589 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08003590 */
Holly Jiuyu Sun052fbab2017-12-12 20:17:09 -08003591 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08003592
3593 /**
Holly Jiuyu Sun3d6b53c2017-12-21 18:44:59 -08003594 * Use with {@link #getSystemService(String)} to retrieve a
3595 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
3596 *
3597 * @see #getSystemService(String)
3598 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun3d6b53c2017-12-21 18:44:59 -08003599 * @hide
3600 */
Holly Jiuyu Sun052fbab2017-12-12 20:17:09 -08003601 @SystemApi
3602 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun3d6b53c2017-12-21 18:44:59 -08003603
3604 /**
3605 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08003606 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003607 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003608 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003609 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003610 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003611 */
3612 public static final String CLIPBOARD_SERVICE = "clipboard";
3613
3614 /**
Scott Main4b5da682010-10-21 11:49:12 -07003615 * Use with {@link #getSystemService} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003616 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003617 *
3618 * @see #getSystemService
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003619 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003620 */
3621 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
3622
3623 /**
3624 * Use with {@link #getSystemService} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003625 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3626 * methods.
3627 *
3628 * @see #getSystemService
3629 */
3630 public static final String INPUT_METHOD_SERVICE = "input_method";
3631
3632 /**
3633 * Use with {@link #getSystemService} to retrieve a
satok988323c2011-06-22 16:38:13 +09003634 * {@link android.view.textservice.TextServicesManager} for accessing
3635 * text services.
3636 *
3637 * @see #getSystemService
3638 */
3639 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3640
3641 /**
3642 * Use with {@link #getSystemService} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003643 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 * @see #getSystemService
3646 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003647 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003648
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003650 * Official published name of the (internal) voice interaction manager service.
3651 *
3652 * @hide
3653 * @see #getSystemService
3654 */
3655 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3656
3657 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08003658 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07003659 *
3660 * @hide
3661 * @see #getSystemService
3662 */
Felipe Leme640f30a2017-03-06 15:44:06 -08003663 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07003664
3665 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003666 * Use with {@link #getSystemService} to access the
3667 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3668 *
3669 * @hide
3670 * @see #getSystemService
3671 */
3672 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3673
3674
3675 /**
Christopher Tate487529a2009-04-29 14:03:25 -07003676 * Use with {@link #getSystemService} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003677 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003678 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003679 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003680 *
Christopher Tate487529a2009-04-29 14:03:25 -07003681 * @see #getSystemService
3682 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003683 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003684 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003685
3686 /**
3687 * Use with {@link #getSystemService} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003688 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003689 * diagnostic logs.
Dan Egnor95240272009-10-27 18:23:39 -07003690 * @see #getSystemService
3691 */
3692 public static final String DROPBOX_SERVICE = "dropbox";
3693
Christopher Tate487529a2009-04-29 14:03:25 -07003694 /**
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003695 * System service name for the DeviceIdleController. There is no Java API for this.
3696 * @see #getSystemService
3697 * @hide
3698 */
3699 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3700
3701 /**
Scott Main4b5da682010-10-21 11:49:12 -07003702 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003703 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003704 * device policy management.
3705 *
3706 * @see #getSystemService
3707 */
3708 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3709
3710 /**
Tobias Haamel53332882010-02-18 16:15:43 -08003711 * Use with {@link #getSystemService} to retrieve a
3712 * {@link android.app.UiModeManager} for controlling UI modes.
3713 *
3714 * @see #getSystemService
3715 */
3716 public static final String UI_MODE_SERVICE = "uimode";
3717
3718 /**
Steve Howarda2709362010-07-02 17:12:48 -07003719 * Use with {@link #getSystemService} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003720 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003721 *
3722 * @see #getSystemService
Steve Howarda2709362010-07-02 17:12:48 -07003723 */
3724 public static final String DOWNLOAD_SERVICE = "download";
3725
3726 /**
Chung-yih Wang2d942312010-08-05 12:17:37 +08003727 * Use with {@link #getSystemService} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003728 * {@link android.os.BatteryManager} for managing battery state.
3729 *
3730 * @see #getSystemService
3731 */
3732 public static final String BATTERY_SERVICE = "batterymanager";
3733
3734 /**
3735 * Use with {@link #getSystemService} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003736 * {@link android.nfc.NfcManager} for using NFC.
3737 *
3738 * @see #getSystemService
3739 */
3740 public static final String NFC_SERVICE = "nfc";
3741
3742 /**
3743 * Use with {@link #getSystemService} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003744 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003745 *
3746 * @see #getSystemService
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003747 */
3748 public static final String BLUETOOTH_SERVICE = "bluetooth";
3749
3750 /**
3751 * Use with {@link #getSystemService} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003752 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3753 *
3754 * @see #getSystemService
3755 */
3756 /** @hide */
3757 public static final String SIP_SERVICE = "sip";
3758
3759 /**
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003760 * Use with {@link #getSystemService} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003761 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003762 * and for controlling this device's behavior as a USB device.
3763 *
3764 * @see #getSystemService
John Spurlock6098c5d2013-06-17 10:32:46 -04003765 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003766 */
3767 public static final String USB_SERVICE = "usb";
3768
3769 /**
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003770 * Use with {@link #getSystemService} to retrieve a {@link
3771 * android.hardware.SerialManager} for access to serial ports.
3772 *
3773 * @see #getSystemService
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003774 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003775 *
3776 * @hide
3777 */
3778 public static final String SERIAL_SERVICE = "serial";
3779
3780 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003781 * Use with {@link #getSystemService} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003782 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3783 * HDMI-CEC protocol.
3784 *
3785 * @see #getSystemService
3786 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003787 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003788 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003789 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003790 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003791
3792 /**
3793 * Use with {@link #getSystemService} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003794 * {@link android.hardware.input.InputManager} for interacting with input devices.
3795 *
3796 * @see #getSystemService
3797 * @see android.hardware.input.InputManager
3798 */
3799 public static final String INPUT_SERVICE = "input";
3800
3801 /**
Glenn Kasten07b04652012-04-23 15:00:43 -07003802 * Use with {@link #getSystemService} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003803 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3804 *
3805 * @see #getSystemService
3806 * @see android.hardware.display.DisplayManager
3807 */
3808 public static final String DISPLAY_SERVICE = "display";
3809
3810 /**
3811 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003812 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3813 *
3814 * @see #getSystemService
3815 * @see android.os.UserManager
3816 */
3817 public static final String USER_SERVICE = "user";
3818
3819 /**
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003820 * Use with {@link #getSystemService} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003821 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3822 * profiles of a user.
3823 *
3824 * @see #getSystemService
3825 * @see android.content.pm.LauncherApps
3826 */
3827 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3828
3829 /**
3830 * Use with {@link #getSystemService} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003831 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3832 * and requesting permissions for restricted operations.
3833 * @see #getSystemService
3834 * @see android.content.RestrictionsManager
3835 */
3836 public static final String RESTRICTIONS_SERVICE = "restrictions";
3837
3838 /**
3839 * Use with {@link #getSystemService} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003840 * {@link android.app.AppOpsManager} for tracking application operations
3841 * on the device.
3842 *
3843 * @see #getSystemService
3844 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003845 */
3846 public static final String APP_OPS_SERVICE = "appops";
3847
3848 /**
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003849 * Use with {@link #getSystemService} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003850 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003851 * camera devices.
3852 *
3853 * @see #getSystemService
Dianne Hackborn221ea892013-08-04 16:50:16 -07003854 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003855 */
3856 public static final String CAMERA_SERVICE = "camera";
3857
3858 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003859 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003860 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003861 *
3862 * @see #getSystemService
3863 * @see android.print.PrintManager
3864 */
3865 public static final String PRINT_SERVICE = "print";
3866
3867 /**
Eugene Susla4160be12017-04-18 12:29:10 -07003868 * Use with {@link #getSystemService} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08003869 * {@link android.companion.CompanionDeviceManager} for managing companion devices
3870 *
3871 * @see #getSystemService
3872 * @see android.companion.CompanionDeviceManager
3873 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07003874 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08003875
3876 /**
Erik Gilling51e95df2013-06-26 11:06:51 -07003877 * Use with {@link #getSystemService} to retrieve a
3878 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3879 * signals from the device.
3880 *
3881 * @see #getSystemService
3882 * @see android.hardware.ConsumerIrManager
3883 */
3884 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3885
3886 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003887 * {@link android.app.trust.TrustManager} for managing trust agents.
3888 * @see #getSystemService
3889 * @see android.app.trust.TrustManager
3890 * @hide
3891 */
3892 public static final String TRUST_SERVICE = "trust";
3893
3894 /**
Jae Seo39570912014-02-20 18:23:25 -08003895 * Use with {@link #getSystemService} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003896 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3897 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003898 *
3899 * @see #getSystemService
Jae Seod5cc4a22014-05-30 16:57:43 -07003900 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003901 */
3902 public static final String TV_INPUT_SERVICE = "tv_input";
3903
3904 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003905 * {@link android.net.NetworkScoreManager} for managing network scoring.
3906 * @see #getSystemService
3907 * @see android.net.NetworkScoreManager
3908 * @hide
3909 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003910 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003911 public static final String NETWORK_SCORE_SERVICE = "network_score";
3912
3913 /**
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003914 * Use with {@link #getSystemService} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08003915 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003916 *
3917 * @see #getSystemService
Dianne Hackbornff170242014-11-19 10:59:01 -08003918 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07003919 */
3920 public static final String USAGE_STATS_SERVICE = "usagestats";
3921
3922 /**
Christopher Tatefa380e92014-05-19 13:46:29 -07003923 * Use with {@link #getSystemService} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07003924 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07003925 * background tasks.
3926 * @see #getSystemService
Christopher Tate7060b042014-06-09 19:50:00 -07003927 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07003928 */
Christopher Tate7060b042014-06-09 19:50:00 -07003929 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07003930
3931 /**
Andres Morales68d4acd2014-07-01 19:40:41 -07003932 * Use with {@link #getSystemService} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07003933 * android.service.persistentdata.PersistentDataBlockManager} instance
3934 * for interacting with a storage device that lives across factory resets.
3935 *
Andres Morales68d4acd2014-07-01 19:40:41 -07003936 * @see #getSystemService
3937 * @see android.service.persistentdata.PersistentDataBlockManager
3938 * @hide
3939 */
Andres Morales33df9372014-09-26 17:08:59 -07003940 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07003941 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
3942
3943 /**
Michael Wrightc39d47a2014-07-08 18:07:36 -07003944 * Use with {@link #getSystemService} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003945 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
3946 *
3947 * @see #getSystemService
3948 * @see android.service.oemlock.OemLockManager
3949 * @hide
3950 */
3951 @SystemApi
3952 public static final String OEM_LOCK_SERVICE = "oem_lock";
3953
3954 /**
3955 * Use with {@link #getSystemService} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07003956 * android.media.projection.MediaProjectionManager} instance for managing
3957 * media projection sessions.
3958 * @see #getSystemService
Jeff Brown6e539312015-02-24 18:53:21 -08003959 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07003960 */
3961 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
3962
3963 /**
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003964 * Use with {@link #getSystemService} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08003965 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003966 *
3967 * @see #getSystemService
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003968 */
3969 public static final String MIDI_SERVICE = "midi";
3970
Eric Laurent2035ac82015-03-05 15:18:44 -08003971
3972 /**
3973 * Use with {@link #getSystemService} to retrieve a
3974 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
3975 *
3976 * @see #getSystemService
3977 * @hide
3978 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07003979 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08003980
Paul McLeana33be212015-02-20 07:52:45 -08003981 /**
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003982 * Use with {@link #getSystemService} to retrieve a
3983 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
3984 *
3985 * @see #getSystemService
3986 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01003987 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003988
3989 /**
Makoto Onukib5a012f2016-06-21 11:13:53 -07003990 * Use with {@link #getSystemService} to retrieve a
3991 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003992 *
3993 * @see #getSystemService
3994 * @see android.content.pm.ShortcutManager
3995 */
3996 public static final String SHORTCUT_SERVICE = "shortcut";
3997
3998 /**
Peng Xu9ff7d222016-02-11 13:02:05 -08003999 * Use with {@link #getSystemService} to retrieve a {@link
4000 * android.hardware.location.ContextHubManager} for accessing context hubs.
4001 *
4002 * @see #getSystemService
4003 * @see android.hardware.location.ContextHubManager
4004 *
4005 * @hide
4006 */
4007 @SystemApi
4008 public static final String CONTEXTHUB_SERVICE = "contexthub";
4009
4010 /**
Joe Onorato713fec82016-03-04 10:34:02 -08004011 * Use with {@link #getSystemService} to retrieve a
4012 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4013 * memory, etc) metrics.
4014 *
4015 * @see #getSystemService
4016 */
4017 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4018
4019 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004020 * Gatekeeper Service.
4021 * @hide
4022 */
4023 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4024
4025 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004026 * Service defining the policy for access to device identifiers.
4027 * @hide
4028 */
4029 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4030
4031 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004032 * Service to report a system health "incident"
4033 * @hide
4034 */
4035 public static final String INCIDENT_SERVICE = "incident";
4036
4037 /**
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004038 * Use with {@link #getSystemService} to retrieve a {@link
4039 * android.content.om.OverlayManager} for managing overlay packages.
4040 *
4041 * @see #getSystemService
4042 * @see android.content.om.OverlayManager
4043 * @hide
4044 */
4045 public static final String OVERLAY_SERVICE = "overlay";
4046
4047 /**
Zak Cohen56345f42017-01-26 13:54:28 -08004048 * Use with {@link #getSystemService} to retrieve a
4049 * {@link VrManager} for accessing the VR service.
4050 *
4051 * @see #getSystemService
4052 * @hide
4053 */
4054 @SystemApi
4055 public static final String VR_SERVICE = "vrmanager";
4056
4057 /**
Neil Fullerfe6ec562017-03-16 18:29:36 +00004058 * Use with {@link #getSystemService} to retrieve an
4059 * {@link android.app.timezone.ITimeZoneRulesManager}.
4060 * @hide
4061 *
4062 * @see #getSystemService
4063 */
4064 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4065
4066 /**
Ruchi Kandoidcf4c6d2018-01-03 16:14:57 -08004067 * Use with {@link #getSystemService} to retrieve a
4068 * {@link android.se.omapi.ISecureElementService}
4069 * for accessing the SecureElementService.
4070 *
4071 * @hide
4072 */
4073 @SystemApi
4074 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4075
4076 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004077 * Determine whether the given permission is allowed for a particular
4078 * process and user ID running in the system.
4079 *
4080 * @param permission The name of the permission being checked.
4081 * @param pid The process ID being checked against. Must be > 0.
4082 * @param uid The user ID being checked against. A uid of 0 is the root
4083 * user, which will pass every permission check.
4084 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004085 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004086 * pid/uid is allowed that permission, or
4087 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4088 *
4089 * @see PackageManager#checkPermission(String, String)
4090 * @see #checkCallingPermission
4091 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004092 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004093 @PackageManager.PermissionResult
4094 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004095
Dianne Hackbornff170242014-11-19 10:59:01 -08004096 /** @hide */
4097 @PackageManager.PermissionResult
4098 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4099 IBinder callerToken);
4100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004101 /**
4102 * Determine whether the calling process of an IPC you are handling has been
4103 * granted a particular permission. This is basically the same as calling
4104 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4105 * by {@link android.os.Binder#getCallingPid} and
4106 * {@link android.os.Binder#getCallingUid}. One important difference
4107 * is that if you are not currently processing an IPC, this function
4108 * will always fail. This is done to protect against accidentally
4109 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4110 * to avoid this protection.
4111 *
4112 * @param permission The name of the permission being checked.
4113 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004114 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 * pid/uid is allowed that permission, or
4116 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4117 *
4118 * @see PackageManager#checkPermission(String, String)
4119 * @see #checkPermission
4120 * @see #checkCallingOrSelfPermission
4121 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004122 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004123 @PackageManager.PermissionResult
4124 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004125
4126 /**
4127 * Determine whether the calling process of an IPC <em>or you</em> have been
4128 * granted a particular permission. This is the same as
4129 * {@link #checkCallingPermission}, except it grants your own permissions
4130 * if you are not currently processing an IPC. Use with care!
4131 *
4132 * @param permission The name of the permission being checked.
4133 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004134 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004135 * pid/uid is allowed that permission, or
4136 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4137 *
4138 * @see PackageManager#checkPermission(String, String)
4139 * @see #checkPermission
4140 * @see #checkCallingPermission
4141 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004142 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004143 @PackageManager.PermissionResult
4144 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004145
4146 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004147 * Determine whether <em>you</em> have been granted a particular permission.
4148 *
4149 * @param permission The name of the permission being checked.
4150 *
4151 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4152 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4153 *
4154 * @see PackageManager#checkPermission(String, String)
4155 * @see #checkCallingPermission(String)
4156 */
4157 @PackageManager.PermissionResult
4158 public abstract int checkSelfPermission(@NonNull String permission);
4159
4160 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004161 * If the given permission is not allowed for a particular process
4162 * and user ID running in the system, throw a {@link SecurityException}.
4163 *
4164 * @param permission The name of the permission being checked.
4165 * @param pid The process ID being checked against. Must be &gt; 0.
4166 * @param uid The user ID being checked against. A uid of 0 is the root
4167 * user, which will pass every permission check.
4168 * @param message A message to include in the exception if it is thrown.
4169 *
4170 * @see #checkPermission(String, int, int)
4171 */
4172 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004173 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004174
4175 /**
4176 * If the calling process of an IPC you are handling has not been
4177 * granted a particular permission, throw a {@link
4178 * SecurityException}. This is basically the same as calling
4179 * {@link #enforcePermission(String, int, int, String)} with the
4180 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4181 * and {@link android.os.Binder#getCallingUid}. One important
4182 * difference is that if you are not currently processing an IPC,
4183 * this function will always throw the SecurityException. This is
4184 * done to protect against accidentally leaking permissions; you
4185 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4186 * protection.
4187 *
4188 * @param permission The name of the permission being checked.
4189 * @param message A message to include in the exception if it is thrown.
4190 *
4191 * @see #checkCallingPermission(String)
4192 */
4193 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004194 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004195
4196 /**
4197 * If neither you nor the calling process of an IPC you are
4198 * handling has been granted a particular permission, throw a
4199 * {@link SecurityException}. This is the same as {@link
4200 * #enforceCallingPermission}, except it grants your own
4201 * permissions if you are not currently processing an IPC. Use
4202 * with care!
4203 *
4204 * @param permission The name of the permission being checked.
4205 * @param message A message to include in the exception if it is thrown.
4206 *
4207 * @see #checkCallingOrSelfPermission(String)
4208 */
4209 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004210 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211
4212 /**
4213 * Grant permission to access a specific Uri to another package, regardless
4214 * of whether that package has general permission to access the Uri's
4215 * content provider. This can be used to grant specific, temporary
4216 * permissions, typically in response to user interaction (such as the
4217 * user opening an attachment that you would like someone else to
4218 * display).
4219 *
4220 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4221 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4222 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4223 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4224 * start an activity instead of this function directly. If you use this
4225 * function directly, you should be sure to call
4226 * {@link #revokeUriPermission} when the target should no longer be allowed
4227 * to access it.
4228 *
4229 * <p>To succeed, the content provider owning the Uri must have set the
4230 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4231 * grantUriPermissions} attribute in its manifest or included the
4232 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4233 * &lt;grant-uri-permissions&gt;} tag.
4234 *
4235 * @param toPackage The package you would like to allow to access the Uri.
4236 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004237 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004238 *
4239 * @see #revokeUriPermission
4240 */
4241 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004242 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004243
4244 /**
4245 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004246 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4247 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004248 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004249 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004250 * "content://foo". It will not remove any prefix grants that exist at a
4251 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004253 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004254 * regular permission access to a Uri, but had received access to it through
4255 * a specific Uri permission grant, you could not revoke that grant with this
4256 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004257 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4258 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004259 * (or none).</p>
4260 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004261 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4262 * grants matching the given Uri, for any package they had been granted to, through any
4263 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4264 * service start, etc). That means this can be potentially dangerous to use, as it can
4265 * revoke grants that another app could be strongly expecting to stick around.</p>
4266 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004268 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 *
4270 * @see #grantUriPermission
4271 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004272 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273
4274 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004275 * Remove permissions to access a particular content provider Uri
4276 * that were previously added with {@link #grantUriPermission} for a specific target
4277 * package. The given Uri will match all previously granted Uris that are the same or a
4278 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4279 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4280 * "content://foo". It will not remove any prefix grants that exist at a
4281 * higher level.
4282 *
4283 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4284 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4285 * and only for the package specified. Any matching grants that have happened through
4286 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4287 * removed.</p>
4288 *
4289 * @param toPackage The package you had previously granted access to.
4290 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004291 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004292 *
4293 * @see #grantUriPermission
4294 */
4295 public abstract void revokeUriPermission(String toPackage, Uri uri,
4296 @Intent.AccessUriMode int modeFlags);
4297
4298 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 * Determine whether a particular process and user ID has been granted
4300 * permission to access a specific URI. This only checks for permissions
4301 * that have been explicitly granted -- if the given process/uid has
4302 * more general access to the URI's content provider then this check will
4303 * always fail.
4304 *
4305 * @param uri The uri that is being checked.
4306 * @param pid The process ID being checked against. Must be &gt; 0.
4307 * @param uid The user ID being checked against. A uid of 0 is the root
4308 * user, which will pass every permission check.
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 given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004312 * pid/uid 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="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004318 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004319 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004320 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004321
Dianne Hackbornff170242014-11-19 10:59:01 -08004322 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004323 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08004324 public abstract int checkUriPermission(Uri uri, int pid, int uid,
4325 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004327 /**
4328 * Determine whether the calling process and user ID has been
4329 * granted permission to access a specific URI. This is basically
4330 * the same as calling {@link #checkUriPermission(Uri, int, int,
4331 * int)} with the pid and uid returned by {@link
4332 * android.os.Binder#getCallingPid} and {@link
4333 * android.os.Binder#getCallingUid}. One important difference is
4334 * that if you are not currently processing an IPC, this function
4335 * will always fail.
4336 *
4337 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004338 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004340 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004341 * is allowed to access that uri, or
4342 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4343 *
4344 * @see #checkUriPermission(Uri, int, int, int)
4345 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004346 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004347 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07004348 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004349
4350 /**
4351 * Determine whether the calling process of an IPC <em>or you</em> has been granted
4352 * permission to access a specific URI. This is the same as
4353 * {@link #checkCallingUriPermission}, except it grants your own permissions
4354 * if you are not currently processing an IPC. Use with care!
4355 *
4356 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004357 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004359 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004360 * is allowed to access that uri, or
4361 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4362 *
4363 * @see #checkCallingUriPermission
4364 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004365 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004366 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004367 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004368 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369
4370 /**
4371 * Check both a Uri and normal permission. This allows you to perform
4372 * both {@link #checkPermission} and {@link #checkUriPermission} in one
4373 * call.
4374 *
4375 * @param uri The Uri whose permission is to be checked, or null to not
4376 * do this check.
4377 * @param readPermission The permission that provides overall read access,
4378 * or null to not do this check.
4379 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004380 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004381 * @param pid The process ID being checked against. Must be &gt; 0.
4382 * @param uid The user ID being checked against. A uid of 0 is the root
4383 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004384 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004385 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004386 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004387 * is allowed to access that uri or holds one of the given permissions, or
4388 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4389 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004390 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004391 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004392 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
4393 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004394 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395
4396 /**
4397 * If a particular process and user ID has not been granted
4398 * permission to access a specific URI, throw {@link
4399 * SecurityException}. This only checks for permissions that have
4400 * been explicitly granted -- if the given process/uid has more
4401 * general access to the URI's content provider then this check
4402 * will always fail.
4403 *
4404 * @param uri The uri that is being checked.
4405 * @param pid The process ID being checked against. Must be &gt; 0.
4406 * @param uid The user ID being checked against. A uid of 0 is the root
4407 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004408 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004409 * @param message A message to include in the exception if it is thrown.
4410 *
4411 * @see #checkUriPermission(Uri, int, int, int)
4412 */
4413 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004414 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004415
4416 /**
4417 * If the calling process and user ID has not been granted
4418 * permission to access a specific URI, throw {@link
4419 * SecurityException}. This is basically the same as calling
4420 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
4421 * the pid and uid returned by {@link
4422 * android.os.Binder#getCallingPid} and {@link
4423 * android.os.Binder#getCallingUid}. One important difference is
4424 * that if you are not currently processing an IPC, this function
4425 * will always throw a SecurityException.
4426 *
4427 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004428 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004429 * @param message A message to include in the exception if it is thrown.
4430 *
4431 * @see #checkCallingUriPermission(Uri, int)
4432 */
4433 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004434 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435
4436 /**
4437 * If the calling process of an IPC <em>or you</em> has not been
4438 * granted permission to access a specific URI, throw {@link
4439 * SecurityException}. This is the same as {@link
4440 * #enforceCallingUriPermission}, except it grants your own
4441 * permissions if you are not currently processing an IPC. Use
4442 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07004443 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004444 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004445 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004446 * @param message A message to include in the exception if it is thrown.
4447 *
4448 * @see #checkCallingOrSelfUriPermission(Uri, int)
4449 */
4450 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004451 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004452
4453 /**
4454 * Enforce both a Uri and normal permission. This allows you to perform
4455 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4456 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004457 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004458 * @param uri The Uri whose permission is to be checked, or null to not
4459 * do this check.
4460 * @param readPermission The permission that provides overall read access,
4461 * or null to not do this check.
4462 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004463 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004464 * @param pid The process ID being checked against. Must be &gt; 0.
4465 * @param uid The user ID being checked against. A uid of 0 is the root
4466 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004467 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004468 * @param message A message to include in the exception if it is thrown.
4469 *
4470 * @see #checkUriPermission(Uri, String, String, int, int, int)
4471 */
4472 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004473 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004474 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004475 @Nullable String message);
4476
4477 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004478 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
4479 CONTEXT_INCLUDE_CODE,
4480 CONTEXT_IGNORE_SECURITY,
4481 CONTEXT_RESTRICTED,
4482 CONTEXT_DEVICE_PROTECTED_STORAGE,
4483 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
4484 CONTEXT_REGISTER_PACKAGE,
4485 })
Tor Norbyed9273d62013-05-30 15:59:53 -07004486 @Retention(RetentionPolicy.SOURCE)
4487 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004488
4489 /**
4490 * Flag for use with {@link #createPackageContext}: include the application
4491 * code with the context. This means loading code into the caller's
4492 * process, so that {@link #getClassLoader()} can be used to instantiate
4493 * the application's classes. Setting this flags imposes security
4494 * restrictions on what application context you can access; if the
4495 * requested application can not be safely loaded into your process,
4496 * java.lang.SecurityException will be thrown. If this flag is not set,
4497 * there will be no restrictions on the packages that can be loaded,
4498 * but {@link #getClassLoader} will always return the default system
4499 * class loader.
4500 */
4501 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4502
4503 /**
4504 * Flag for use with {@link #createPackageContext}: ignore any security
4505 * restrictions on the Context being requested, allowing it to always
4506 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4507 * to be loaded into a process even when it isn't safe to do so. Use
4508 * with extreme care!
4509 */
4510 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004511
Romain Guy870e09f2009-07-06 16:35:25 -07004512 /**
4513 * Flag for use with {@link #createPackageContext}: a restricted context may
4514 * disable specific features. For instance, a View associated with a restricted
4515 * context would ignore particular XML attributes.
4516 */
4517 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004518
4519 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004520 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004521 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004522 *
4523 * @hide
4524 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004525 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004526
4527 /**
4528 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004529 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004530 *
4531 * @hide
4532 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004533 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004534
4535 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004536 * @hide Used to indicate we should tell the activity manager about the process
4537 * loading this code.
4538 */
4539 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4540
4541 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 * Return a new Context object for the given application name. This
4543 * Context is the same as what the named application gets when it is
4544 * launched, containing the same resources and class loader. Each call to
4545 * this method returns a new instance of a Context object; Context objects
4546 * are not shared, however they share common state (Resources, ClassLoader,
4547 * etc) so the Context instance itself is fairly lightweight.
4548 *
Jeff Brown6e539312015-02-24 18:53:21 -08004549 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004550 * application with the given package name.
4551 *
4552 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4553 * can not be loaded into the caller's process for security reasons (see
4554 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4555 *
4556 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004557 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004558 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004559 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004560 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004561 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004562 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004563 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004564 */
4565 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004566 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004567
4568 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004569 * Similar to {@link #createPackageContext(String, int)}, but with a
4570 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4571 * will open any {@link Uri} as the given user.
4572 *
4573 * @hide
4574 */
4575 public abstract Context createPackageContextAsUser(
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004576 String packageName, @CreatePackageOptions int flags, UserHandle user)
Jeff Sharkey6d515712012-09-20 16:06:08 -07004577 throws PackageManager.NameNotFoundException;
4578
4579 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004580 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4581 *
4582 * @hide
4583 */
4584 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004585 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07004586
4587 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08004588 * Return a new Context object for the given split name. The new Context has a ClassLoader and
4589 * Resources object that can access the split's and all of its dependencies' code/resources.
4590 * Each call to this method returns a new instance of a Context object;
4591 * Context objects are not shared, however common state (ClassLoader, other Resources for
4592 * the same split) may be so the Context itself can be fairly lightweight.
4593 *
4594 * @param splitName The name of the split to include, as declared in the split's
4595 * <code>AndroidManifest.xml</code>.
4596 * @return A {@link Context} with the given split's code and/or resources loaded.
4597 */
4598 public abstract Context createContextForSplit(String splitName)
4599 throws PackageManager.NameNotFoundException;
4600
4601 /**
Jim Millera75a8832013-02-07 16:53:32 -08004602 * Get the userId associated with this context
4603 * @return user id
4604 *
4605 * @hide
4606 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004607 @TestApi
Jeff Sharkey8588bc12016-01-06 16:47:42 -07004608 public abstract @UserIdInt int getUserId();
Jim Millera75a8832013-02-07 16:53:32 -08004609
4610 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004611 * Return a new Context object for the current Context but whose resources
4612 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004613 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004614 * shared, however common state (ClassLoader, other Resources for the
4615 * same configuration) may be so the Context itself can be fairly lightweight.
4616 *
4617 * @param overrideConfiguration A {@link Configuration} specifying what
4618 * values to modify in the base Configuration of the original Context's
4619 * resources. If the base configuration changes (such as due to an
4620 * orientation change), the resources of this context will also change except
4621 * for those that have been explicitly overridden with a value here.
4622 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004623 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004624 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004625 public abstract Context createConfigurationContext(
4626 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004627
4628 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004629 * Return a new Context object for the current Context but whose resources
4630 * are adjusted to match the metrics of the given Display. Each call to this method
4631 * returns a new instance of a Context object; Context objects are not
4632 * shared, however common state (ClassLoader, other Resources for the
4633 * same configuration) may be so the Context itself can be fairly lightweight.
4634 *
4635 * The returned display Context provides a {@link WindowManager}
4636 * (see {@link #getSystemService(String)}) that is configured to show windows
4637 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4638 * method can be used to retrieve the Display from the returned Context.
4639 *
4640 * @param display A {@link Display} object specifying the display
4641 * for whose metrics the Context's resources should be tailored and upon which
4642 * new windows should be shown.
4643 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004644 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004645 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004646 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004647
4648 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004649 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004650 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004651 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004652 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004653 * with a key tied to the physical device, and it can be accessed
4654 * immediately after the device has booted successfully, both
4655 * <em>before and after</em> the user has authenticated with their
4656 * credentials (such as a lock pattern or PIN).
4657 * <p>
4658 * Because device-protected data is available without user authentication,
4659 * you should carefully limit the data you store using this Context. For
4660 * example, storing sensitive authentication tokens or passwords in the
4661 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004662 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004663 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004664 * device-protected and credential-protected data using different keys, then
4665 * both storage areas will become available at the same time. They remain as
4666 * two distinct storage locations on disk, and only the window of
4667 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004668 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004669 * Each call to this method returns a new instance of a Context object;
4670 * Context objects are not shared, however common state (ClassLoader, other
4671 * Resources for the same configuration) may be so the Context itself can be
4672 * fairly lightweight.
4673 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004674 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004675 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004676 public abstract Context createDeviceProtectedStorageContext();
4677
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004678 /**
4679 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004680 * APIs are backed by credential-protected storage. This is the default
4681 * storage area for apps unless
4682 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004683 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004684 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004685 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004686 * <em>only after</em> the user has entered their credentials (such as a
4687 * lock pattern or PIN).
4688 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004689 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004690 * device-protected and credential-protected data using different keys, then
4691 * both storage areas will become available at the same time. They remain as
4692 * two distinct storage locations on disk, and only the window of
4693 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004694 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004695 * Each call to this method returns a new instance of a Context object;
4696 * Context objects are not shared, however common state (ClassLoader, other
4697 * Resources for the same configuration) may be so the Context itself can be
4698 * fairly lightweight.
4699 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004700 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004701 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004702 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004703 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004704 public abstract Context createCredentialProtectedStorageContext();
4705
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004706 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004707 * Gets the display adjustments holder for this context. This information
4708 * is provided on a per-application or activity basis and is used to simulate lower density
4709 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004710 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004711 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004712 * @return The compatibility info holder, or null if not required by the application.
4713 * @hide
4714 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004715 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004716
4717 /**
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004718 * @hide
4719 */
4720 public abstract Display getDisplay();
4721
4722 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08004723 * @hide
4724 */
4725 public abstract void updateDisplay(int displayId);
4726
4727 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004728 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004729 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004730 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004731 *
Romain Guy870e09f2009-07-06 16:35:25 -07004732 * @see #CONTEXT_RESTRICTED
4733 */
4734 public boolean isRestricted() {
4735 return false;
4736 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004737
4738 /**
4739 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004740 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004741 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004742 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004743 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004744 public abstract boolean isDeviceProtectedStorage();
4745
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004746 /**
4747 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004748 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004749 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004750 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004751 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004752 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004753 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004754 public abstract boolean isCredentialProtectedStorage();
4755
Tony Mak46aabe52016-11-14 12:53:06 +00004756 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07004757 * Returns true if the context can load unsafe resources, e.g. fonts.
4758 * @hide
4759 */
4760 public abstract boolean canLoadUnsafeResources();
4761
4762 /**
Tony Mak46aabe52016-11-14 12:53:06 +00004763 * @hide
4764 */
4765 public IBinder getActivityToken() {
4766 throw new RuntimeException("Not implemented. Must override in a subclass.");
4767 }
4768
4769 /**
4770 * @hide
4771 */
4772 @Nullable
4773 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
4774 int flags) {
4775 throw new RuntimeException("Not implemented. Must override in a subclass.");
4776 }
4777
4778 /**
4779 * @hide
4780 */
4781 public IApplicationThread getIApplicationThread() {
4782 throw new RuntimeException("Not implemented. Must override in a subclass.");
4783 }
Tony Makbf9928d2016-12-22 11:02:45 +00004784
4785 /**
4786 * @hide
4787 */
4788 public Handler getMainThreadHandler() {
4789 throw new RuntimeException("Not implemented. Must override in a subclass.");
4790 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07004791
4792 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07004793 * @hide
4794 */
4795 public AutofillClient getAutofillClient() {
4796 return null;
4797 }
4798
4799 /**
4800 * @hide
4801 */
4802 public void setAutofillClient(AutofillClient client) {
4803 }
4804
4805 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07004806 * Throws an exception if the Context is using system resources,
4807 * which are non-runtime-overlay-themable and may show inconsistent UI.
4808 * @hide
4809 */
4810 public void assertRuntimeOverlayThemable() {
4811 // Resources.getSystem() is a singleton and the only Resources not managed by
4812 // ResourcesManager; therefore Resources.getSystem() is not themable.
4813 if (getResources() == Resources.getSystem()) {
4814 throw new IllegalArgumentException("Non-UI context used to display UI; "
4815 + "get a UI context from ActivityThread#getSystemUiContext()");
4816 }
4817 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004818}