blob: f896274ed8b358f38322c78e1541206d32aff8d5 [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;
Bo Liu58a57662019-03-06 20:21:45 +000020import android.annotation.CallbackExecutor;
Tor Norbye1c2bf032015-03-02 10:57:08 -080021import android.annotation.CheckResult;
Tor Norbye3e4cda72015-06-10 08:14:31 -070022import android.annotation.ColorInt;
23import android.annotation.ColorRes;
24import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070025import android.annotation.IntDef;
26import android.annotation.NonNull;
27import android.annotation.Nullable;
Tor Norbye788fc2b2015-07-05 16:10:42 -070028import android.annotation.RequiresPermission;
Tor Norbyed9273d62013-05-30 15:59:53 -070029import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070030import android.annotation.StringRes;
31import android.annotation.StyleRes;
32import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090033import android.annotation.SystemApi;
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -070034import android.annotation.TestApi;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010035import android.annotation.UnsupportedAppUsage;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070036import android.annotation.UserIdInt;
Selim Cinek7fa385a2018-01-24 08:35:28 -080037import android.app.ActivityManager;
Tony Mak46aabe52016-11-14 12:53:06 +000038import android.app.IApplicationThread;
39import android.app.IServiceConnection;
Zak Cohen56345f42017-01-26 13:54:28 -080040import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070041import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.content.pm.PackageManager;
43import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080044import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070045import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.content.res.Resources;
47import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070048import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.database.sqlite.SQLiteDatabase;
50import android.database.sqlite.SQLiteDatabase.CursorFactory;
51import android.graphics.Bitmap;
52import android.graphics.drawable.Drawable;
53import android.net.Uri;
Patrick Baumannef4c4072018-02-01 08:54:05 -080054import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070056import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.os.Handler;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070058import android.os.HandlerExecutor;
Dianne Hackbornff170242014-11-19 10:59:01 -080059import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070061import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070062import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070063import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060064import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070065import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070067import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070068import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070069import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070070import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070071import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070072import android.view.autofill.AutofillManager.AutofillClient;
Adam He6240eab2019-02-25 13:34:45 -080073import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000074import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075
76import java.io.File;
77import java.io.FileInputStream;
78import java.io.FileNotFoundException;
79import java.io.FileOutputStream;
80import java.io.IOException;
81import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070082import java.lang.annotation.Retention;
83import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070084import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085
86/**
87 * Interface to global information about an application environment. This is
88 * an abstract class whose implementation is provided by
89 * the Android system. It
90 * allows access to application-specific resources and classes, as well as
91 * up-calls for application-level operations such as launching activities,
92 * broadcasting and receiving intents, etc.
93 */
94public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060095 /** @hide */
96 @IntDef(flag = true, prefix = { "MODE_" }, value = {
97 MODE_PRIVATE,
98 MODE_WORLD_READABLE,
99 MODE_WORLD_WRITEABLE,
100 MODE_APPEND,
101 })
102 @Retention(RetentionPolicy.SOURCE)
103 public @interface FileMode {}
104
105 /** @hide */
106 @IntDef(flag = true, prefix = { "MODE_" }, value = {
107 MODE_PRIVATE,
108 MODE_WORLD_READABLE,
109 MODE_WORLD_WRITEABLE,
110 MODE_MULTI_PROCESS,
111 })
112 @Retention(RetentionPolicy.SOURCE)
113 public @interface PreferencesMode {}
114
115 /** @hide */
116 @IntDef(flag = true, prefix = { "MODE_" }, value = {
117 MODE_PRIVATE,
118 MODE_WORLD_READABLE,
119 MODE_WORLD_WRITEABLE,
120 MODE_ENABLE_WRITE_AHEAD_LOGGING,
121 MODE_NO_LOCALIZED_COLLATORS,
122 })
123 @Retention(RetentionPolicy.SOURCE)
124 public @interface DatabaseMode {}
125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 /**
127 * File creation mode: the default mode, where the created file can only
128 * be accessed by the calling application (or all applications sharing the
129 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 */
131 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700134 * File creation mode: allow all other applications to have read access to
135 * the created file.
136 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700137 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
138 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700139 *
Nick Kralevich15069212013-01-09 15:54:56 -0800140 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700141 * to cause security holes in applications. It is strongly
142 * discouraged; instead, applications should use more formal
143 * mechanism for interactions such as {@link ContentProvider},
144 * {@link BroadcastReceiver}, and {@link android.app.Service}.
145 * There are no guarantees that this access mode will remain on
146 * a file, such as when it goes through a backup and restore.
147 * @see android.support.v4.content.FileProvider
148 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700150 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700152
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700154 * File creation mode: allow all other applications to have write access to
155 * the created file.
156 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700157 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700158 * mode will throw a {@link SecurityException}.
159 *
Nick Kralevich15069212013-01-09 15:54:56 -0800160 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700161 * to cause security holes in applications. It is strongly
162 * discouraged; instead, applications should use more formal
163 * mechanism for interactions such as {@link ContentProvider},
164 * {@link BroadcastReceiver}, and {@link android.app.Service}.
165 * There are no guarantees that this access mode will remain on
166 * a file, such as when it goes through a backup and restore.
167 * @see android.support.v4.content.FileProvider
168 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700170 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700172
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 /**
174 * File creation mode: for use with {@link #openFileOutput}, if the file
175 * already exists then write data to the end of the existing file
176 * instead of erasing it.
177 * @see #openFileOutput
178 */
179 public static final int MODE_APPEND = 0x8000;
180
181 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800182 * SharedPreference loading flag: when set, the file on disk will
183 * be checked for modification even if the shared preferences
184 * instance is already loaded in this process. This behavior is
185 * sometimes desired in cases where the application has multiple
186 * processes, all writing to the same SharedPreferences file.
187 * Generally there are better forms of communication between
188 * processes, though.
189 *
190 * <p>This was the legacy (but undocumented) behavior in and
191 * before Gingerbread (Android 2.3) and this flag is implied when
kopriva219f7dc2018-10-09 13:42:28 -0700192 * targeting such releases. For applications targeting SDK
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800193 * versions <em>greater than</em> Android 2.3, this flag must be
194 * explicitly set if desired.
195 *
196 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700197 *
198 * @deprecated MODE_MULTI_PROCESS does not work reliably in
199 * some versions of Android, and furthermore does not provide any
200 * mechanism for reconciling concurrent modifications across
201 * processes. Applications should not attempt to use it. Instead,
202 * they should use an explicit cross-process data management
203 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800204 */
Christopher Tated5748b82015-05-08 18:14:01 -0700205 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800206 public static final int MODE_MULTI_PROCESS = 0x0004;
207
208 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700209 * Database open flag: when set, the database is opened with write-ahead
210 * logging enabled by default.
211 *
212 * @see #openOrCreateDatabase(String, int, CursorFactory)
213 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
214 * @see SQLiteDatabase#enableWriteAheadLogging
215 */
216 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
217
Sunny Goyala21e6b22015-12-02 09:51:02 -0800218 /**
219 * Database open flag: when set, the database is opened without support for
220 * localized collators.
221 *
222 * @see #openOrCreateDatabase(String, int, CursorFactory)
223 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
224 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
225 */
226 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
227
Tor Norbyed9273d62013-05-30 15:59:53 -0700228 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700229 @IntDef(flag = true, prefix = { "BIND_" }, value = {
230 BIND_AUTO_CREATE,
231 BIND_DEBUG_UNBIND,
232 BIND_NOT_FOREGROUND,
233 BIND_ABOVE_CLIENT,
234 BIND_ALLOW_OOM_MANAGEMENT,
235 BIND_WAIVE_PRIORITY,
236 BIND_IMPORTANT,
237 BIND_ADJUST_WITH_ACTIVITY
238 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700239 @Retention(RetentionPolicy.SOURCE)
240 public @interface BindServiceFlags {}
241
Jeff Brown47847f32012-03-22 19:13:11 -0700242 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 * Flag for {@link #bindService}: automatically create the service as long
244 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700245 * its {@link android.app.Service#onStartCommand}
246 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 * explicit call to {@link #startService}. Even without that, though,
248 * this still provides you with access to the service object while the
249 * service is created.
250 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700251 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
252 * not supplying this flag would also impact how important the system
253 * consider's the target service's process to be. When set, the only way
254 * for it to be raised was by binding from a service in which case it will
255 * only be important when that activity is in the foreground. Now to
256 * achieve this behavior you must explicitly supply the new flag
257 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
258 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
259 * the flags {@link #BIND_WAIVE_PRIORITY} and
260 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
261 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800262 */
263 public static final int BIND_AUTO_CREATE = 0x0001;
264
265 /**
266 * Flag for {@link #bindService}: include debugging help for mismatched
267 * calls to unbind. When this flag is set, the callstack of the following
268 * {@link #unbindService} call is retained, to be printed if a later
269 * incorrect unbind call is made. Note that doing this requires retaining
270 * information about the binding that was made for the lifetime of the app,
271 * resulting in a leak -- this should only be used for debugging.
272 */
273 public static final int BIND_DEBUG_UNBIND = 0x0002;
274
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800275 /**
276 * Flag for {@link #bindService}: don't allow this binding to raise
277 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700278 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800279 * as the client (so that its process will not be killable in any
280 * situation where the client is not killable), but for CPU scheduling
281 * purposes it may be left in the background. This only has an impact
282 * in the situation where the binding client is a foreground process
283 * and the target service is in a background process.
284 */
285 public static final int BIND_NOT_FOREGROUND = 0x0004;
286
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700287 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700288 * Flag for {@link #bindService}: indicates that the client application
289 * binding to this service considers the service to be more important than
290 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700291 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700292 * this is not guaranteed to be the case.
293 */
294 public static final int BIND_ABOVE_CLIENT = 0x0008;
295
296 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700297 * Flag for {@link #bindService}: allow the process hosting the bound
298 * service to go through its normal memory management. It will be
299 * treated more like a running service, allowing the system to
300 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700301 * whim it may have, and being more aggressive about making it a candidate
302 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700303 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700304 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
305
306 /**
307 * Flag for {@link #bindService}: don't impact the scheduling or
308 * memory management priority of the target service's hosting process.
309 * Allows the service's process to be managed on the background LRU list
310 * just like a regular application process in the background.
311 */
312 public static final int BIND_WAIVE_PRIORITY = 0x0020;
313
314 /**
315 * Flag for {@link #bindService}: this service is very important to
316 * the client, so should be brought to the foreground process level
317 * when the client is. Normally a process can only be raised to the
318 * visibility level by a client, even if that client is in the foreground.
319 */
320 public static final int BIND_IMPORTANT = 0x0040;
321
322 /**
323 * Flag for {@link #bindService}: If binding from an activity, allow the
324 * target service's process importance to be raised based on whether the
325 * activity is visible to the user, regardless whether another flag is
326 * used to reduce the amount that the client process's overall importance
327 * is used to impact it.
328 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700329 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
330
331 /**
Amith Yamasanie5bfeee2018-09-05 18:52:35 -0700332 * Flag for {@link #bindService}: If binding from something better than perceptible,
333 * still set the adjust below perceptible. This would be used for bound services that can
334 * afford to be evicted when under extreme memory pressure, but should be restarted as soon
335 * as possible.
336 * @hide
337 */
338 public static final int BIND_ADJUST_BELOW_PERCEPTIBLE = 0x0100;
339
340 /**
Dianne Hackbornc390aa82019-01-09 16:38:22 -0800341 * @hide Flag for {@link #bindService}: the service being bound to represents a
342 * protected system component, so must have association restrictions applied to it.
343 * That is, a system config must have one or more allow-association tags limiting
344 * which packages it can interact with. If it does not have any such association
345 * restrictions, a default empty set will be created.
346 */
347 public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000;
348
349 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800350 * @hide Flag for {@link #bindService}: allows binding to a service provided
351 * by an instant app. Note that the caller may not have access to the instant
352 * app providing the service which is a violation of the instant app sandbox.
353 * This flag is intended ONLY for development/testing and should be used with
354 * great care. Only the system is allowed to use this flag.
355 */
356 public static final int BIND_ALLOW_INSTANT = 0x00400000;
357
358 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700359 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
360 * up in to the important background state (instead of transient).
361 */
362 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
363
364 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700365 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
366 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
367 */
368 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
369
370 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700371 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
372 * but only applies while the device is awake.
373 */
374 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
375
376 /**
377 * @hide Flag for {@link #bindService}: For only the case where the binding
378 * is coming from the system, set the process state to FOREGROUND_SERVICE
379 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
380 * saying that the process shouldn't participate in the normal power reduction
381 * modes (removing network access etc).
382 */
383 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
384
385 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700386 * @hide Flag for {@link #bindService}: Treat the binding as hosting
387 * an activity, an unbinding as the activity going in the background.
388 * That is, when unbinding, the process when empty will go on the activity
389 * LRU list instead of the regular one, keeping it around more aggressively
390 * than it otherwise would be. This is intended for use with IMEs to try
391 * to keep IME processes around for faster keyboard switching.
392 */
393 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
394
395 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700396 * @hide An idea that is not yet implemented.
397 * Flag for {@link #bindService}: If binding from an activity, consider
398 * this service to be visible like the binding activity is. That is,
399 * it will be treated as something more important to keep around than
400 * invisible background activities. This will impact the number of
401 * recent activities the user can switch between without having them
402 * restart. There is no guarantee this will be respected, as the system
403 * tries to balance such requests from one app vs. the importantance of
404 * keeping other apps around.
405 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700406 public static final int BIND_VISIBLE = 0x10000000;
407
408 /**
409 * @hide
410 * Flag for {@link #bindService}: Consider this binding to be causing the target
411 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
412 * away.
413 */
414 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700415
416 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700417 * Flag for {@link #bindService}: Don't consider the bound service to be
418 * visible, even if the caller is visible.
419 * @hide
420 */
421 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700422
Alan Viverette713a5cd2015-12-16 15:46:32 -0500423 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500424 * Flag for {@link #bindService}: The service being bound is an
425 * {@link android.R.attr#isolatedProcess isolated},
426 * {@link android.R.attr#externalService external} service. This binds the service into the
427 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400428 * <p>
429 * When using this flag, the code for the service being bound will execute under the calling
430 * application's package name and user ID. Because the service must be an isolated process,
431 * it will not have direct access to the application's data, though.
432 *
433 * The purpose of this flag is to allow applications to provide services that are attributed
434 * to the app using the service, rather than the application providing the service.
435 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500436 */
437 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
438
Dianne Hackborna631d562018-11-20 15:58:15 -0800439 /**
440 * These bind flags reduce the strength of the binding such that we shouldn't
441 * consider it as pulling the process up to the level of the one that is bound to it.
442 * @hide
443 */
444 public static final int BIND_REDUCTION_FLAGS =
445 Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
446 | Context.BIND_ADJUST_BELOW_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;
447
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700448 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700449 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
450 RECEIVER_VISIBLE_TO_INSTANT_APPS
451 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700452 @Retention(RetentionPolicy.SOURCE)
453 public @interface RegisterReceiverFlags {}
454
455 /**
456 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
457 */
458 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
459
Robert Sesekb9a86662015-12-09 16:22:45 -0500460 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500461 * Returns an AssetManager instance for the application's package.
462 * <p>
463 * <strong>Note:</strong> Implementations of this method should return
464 * an AssetManager instance that is consistent with the Resources instance
465 * returned by {@link #getResources()}. For example, they should share the
466 * same {@link Configuration} object.
467 *
468 * @return an AssetManager instance for the application's package
469 * @see #getResources()
470 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 public abstract AssetManager getAssets();
472
Alan Viverette713a5cd2015-12-16 15:46:32 -0500473 /**
474 * Returns a Resources instance for the application's package.
475 * <p>
476 * <strong>Note:</strong> Implementations of this method should return
477 * a Resources instance that is consistent with the AssetManager instance
478 * returned by {@link #getAssets()}. For example, they should share the
479 * same {@link Configuration} object.
480 *
481 * @return a Resources instance for the application's package
482 * @see #getAssets()
483 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 public abstract Resources getResources();
485
486 /** Return PackageManager instance to find global package information. */
487 public abstract PackageManager getPackageManager();
488
489 /** Return a ContentResolver instance for your application's package. */
490 public abstract ContentResolver getContentResolver();
491
492 /**
493 * Return the Looper for the main thread of the current process. This is
494 * the thread used to dispatch calls to application components (activities,
495 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700496 * <p>
497 * By definition, this method returns the same result as would be obtained
498 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
499 * </p>
500 *
501 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 */
503 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700506 * Return an {@link Executor} that will run enqueued tasks on the main
507 * thread associated with this context. This is the thread used to dispatch
508 * calls to application components (activities, services, etc).
509 */
510 public Executor getMainExecutor() {
511 // This is pretty inefficient, which is why ContextImpl overrides it
512 return new HandlerExecutor(new Handler(getMainLooper()));
513 }
514
515 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800517 * current process. This generally should only be used if you need a
518 * Context whose lifecycle is separate from the current context, that is
519 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700520 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800521 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800522 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800523 * <ul>
524 * <li> <p>If used from an Activity context, the receiver is being registered
525 * within that activity. This means that you are expected to unregister
526 * before the activity is done being destroyed; in fact if you do not do
527 * so, the framework will clean up your leaked registration as it removes
528 * the activity and log an error. Thus, if you use the Activity context
529 * to register a receiver that is static (global to the process, not
530 * associated with an Activity instance) then that registration will be
531 * removed on you at whatever point the activity you used is destroyed.
532 * <li> <p>If used from the Context returned here, the receiver is being
533 * registered with the global state associated with your application. Thus
534 * it will never be unregistered for you. This is necessary if the receiver
535 * is associated with static data, not a particular component. However
536 * using the ApplicationContext elsewhere can easily lead to serious leaks
537 * if you forget to unregister, unbind, etc.
538 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 */
540 public abstract Context getApplicationContext();
541
Phil Weaver846cda932017-06-15 10:10:06 -0700542 /** Non-activity related autofill ids are unique in the app */
543 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700544
545 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700546 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700547 *
Phil Weaver846cda932017-06-15 10:10:06 -0700548 * <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 -0700549 * returned will be unique.
550 *
551 * @return A ID that is unique in the process
552 *
553 * {@hide}
554 */
Phil Weaver846cda932017-06-15 10:10:06 -0700555 public int getNextAutofillId() {
556 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
557 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700558 }
559
Phil Weaver846cda932017-06-15 10:10:06 -0700560 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700561
Phil Weaver846cda932017-06-15 10:10:06 -0700562 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700563 }
564
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700566 * Add a new {@link ComponentCallbacks} to the base application of the
567 * Context, which will be called at the same times as the ComponentCallbacks
568 * methods of activities and other components are called. Note that you
569 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
570 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700571 *
572 * @param callback The interface to call. This can be either a
573 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700574 */
575 public void registerComponentCallbacks(ComponentCallbacks callback) {
576 getApplicationContext().registerComponentCallbacks(callback);
577 }
578
579 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400580 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700581 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
582 */
583 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
584 getApplicationContext().unregisterComponentCallbacks(callback);
585 }
586
587 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 * Return a localized, styled CharSequence from the application's package's
589 * default string table.
590 *
591 * @param resId Resource id for the CharSequence text
592 */
Chris Craikceb26932018-02-01 15:51:34 -0800593 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700594 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 return getResources().getText(resId);
596 }
597
598 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700599 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 * default string table.
601 *
602 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700603 * @return The string data associated with the resource, stripped of styled
604 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700606 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700607 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 return getResources().getString(resId);
609 }
610
611 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700612 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 * default string table, substituting the format arguments as defined in
614 * {@link java.util.Formatter} and {@link java.lang.String#format}.
615 *
616 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700617 * @param formatArgs The format arguments that will be used for
618 * substitution.
619 * @return The string data associated with the resource, formatted and
620 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800621 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700622 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700623 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 return getResources().getString(resId, formatArgs);
625 }
626
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800627 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800628 * Returns a color associated with a particular resource ID and styled for
629 * the current theme.
630 *
631 * @param id The desired resource identifier, as generated by the aapt
632 * tool. This integer encodes the package, type, and resource
633 * entry. The value 0 is an invalid identifier.
634 * @return A single color value in the form 0xAARRGGBB.
635 * @throws android.content.res.Resources.NotFoundException if the given ID
636 * does not exist.
637 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700638 @ColorInt
639 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800640 return getResources().getColor(id, getTheme());
641 }
642
643 /**
644 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800645 * styled for the current theme.
646 *
647 * @param id The desired resource identifier, as generated by the aapt
648 * tool. This integer encodes the package, type, and resource
649 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800650 * @return An object that can be used to draw this resource.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800651 * @throws android.content.res.Resources.NotFoundException if the given ID
652 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800653 */
Chris Craik1194b0b2018-03-23 13:36:24 -0700654 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700655 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800656 return getResources().getDrawable(id, getTheme());
657 }
658
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800659 /**
660 * Returns a color state list associated with a particular resource ID and
661 * styled for the current theme.
662 *
663 * @param id The desired resource identifier, as generated by the aapt
664 * tool. This integer encodes the package, type, and resource
665 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800666 * @return A color state list.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800667 * @throws android.content.res.Resources.NotFoundException if the given ID
668 * does not exist.
669 */
Chris Craikceb26932018-02-01 15:51:34 -0800670 @NonNull
Tor Norbye3e4cda72015-06-10 08:14:31 -0700671 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800672 return getResources().getColorStateList(id, getTheme());
673 }
674
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 /**
676 * Set the base theme for this context. Note that this should be called
677 * before any views are instantiated in the Context (for example before
678 * calling {@link android.app.Activity#setContentView} or
679 * {@link android.view.LayoutInflater#inflate}).
680 *
681 * @param resid The style resource describing the theme.
682 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700683 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684
Dianne Hackborn247fe742011-01-08 17:25:57 -0800685 /** @hide Needed for some internal implementation... not public because
686 * you can't assume this actually means anything. */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100687 @UnsupportedAppUsage
Dianne Hackborn247fe742011-01-08 17:25:57 -0800688 public int getThemeResId() {
689 return 0;
690 }
691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800692 /**
693 * Return the Theme object associated with this Context.
694 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700695 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 public abstract Resources.Theme getTheme();
697
698 /**
699 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800700 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 * for more information.
702 *
Jeff Brown6e539312015-02-24 18:53:21 -0800703 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800705 @NonNull
706 public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 return getTheme().obtainStyledAttributes(attrs);
708 }
709
710 /**
711 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800712 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800713 * for more information.
714 *
Jeff Brown6e539312015-02-24 18:53:21 -0800715 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800716 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800717 @NonNull
718 public final TypedArray obtainStyledAttributes(@StyleRes int resid,
719 @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 return getTheme().obtainStyledAttributes(resid, attrs);
721 }
722
723 /**
724 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800725 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 * for more information.
727 *
Jeff Brown6e539312015-02-24 18:53:21 -0800728 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800730 @NonNull
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 public final TypedArray obtainStyledAttributes(
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800732 @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
734 }
735
736 /**
737 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800738 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 * for more information.
740 *
Jeff Brown6e539312015-02-24 18:53:21 -0800741 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800743 @NonNull
744 public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set,
745 @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
Tor Norbyec91531a2015-04-01 17:41:55 -0700746 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 return getTheme().obtainStyledAttributes(
748 set, attrs, defStyleAttr, defStyleRes);
749 }
750
751 /**
752 * Return a class loader you can use to retrieve classes in this package.
753 */
754 public abstract ClassLoader getClassLoader();
755
756 /** Return the name of this application's package. */
757 public abstract String getPackageName();
758
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900759 /**
760 * @hide Return the name of the base context this context is derived from.
761 * This is the same as {@link #getOpPackageName()} except in
762 * cases where system components are loaded into other app processes, in which
763 * case {@link #getOpPackageName()} will be the name of the primary package in
764 * that process (so that app ops uid verification will work with the name).
765 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100766 @UnsupportedAppUsage
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800767 public abstract String getBasePackageName();
768
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900769 /**
770 * Return the package name that should be used for {@link android.app.AppOpsManager} calls from
771 * this context, so that app ops manager's uid verification will work with the name.
772 * <p>
773 * This is not generally intended for third party application developers.
774 */
Adrian Roosebc927c2019-02-28 16:21:18 +0100775 @NonNull
Adrian Roosfe6aeaf2019-01-22 16:58:56 +0100776 public String getOpPackageName() {
777 throw new RuntimeException("Not implemented. Must override in a subclass.");
778 }
Dianne Hackborn95d78532013-09-11 09:51:14 -0700779
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700780 /** Return the full application info for this context's package. */
781 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700782
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 /**
Kenny Root32148392010-01-21 15:40:47 -0800784 * Return the full path to this context's primary Android package.
785 * The Android package is a ZIP file which contains the application's
786 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 *
788 * <p>Note: this is not generally useful for applications, since they should
789 * not be directly accessing the file system.
790 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 * @return String Path to the resources.
792 */
793 public abstract String getPackageResourcePath();
794
795 /**
Kenny Root32148392010-01-21 15:40:47 -0800796 * Return the full path to this context's primary Android package.
797 * The Android package is a ZIP file which contains application's
798 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800799 *
800 * <p>Note: this is not generally useful for applications, since they should
801 * not be directly accessing the file system.
802 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 * @return String Path to the code and assets.
804 */
805 public abstract String getPackageCodePath();
806
807 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700808 * @hide
809 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700810 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700811 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100812 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700813 public File getSharedPrefsFile(String name) {
814 return getSharedPreferencesPath(name);
815 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700816
817 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 * Retrieve and hold the contents of the preferences file 'name', returning
819 * a SharedPreferences through which you can retrieve and modify its
820 * values. Only one instance of the SharedPreferences object is returned
821 * to any callers for the same name, meaning they will see each other's
822 * edits as soon as they are made.
823 *
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700824 * This method is thead-safe.
825 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 * @param name Desired preferences file. If a preferences file by this name
827 * does not exist, it will be created when you retrieve an
828 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600829 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400831 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800832 * to retrieve and modify the preference values.
833 *
834 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800835 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600836 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700837
838 /**
839 * Retrieve and hold the contents of the preferences file, returning
840 * a SharedPreferences through which you can retrieve and modify its
841 * values. Only one instance of the SharedPreferences object is returned
842 * to any callers for the same name, meaning they will see each other's
843 * edits as soon as they are made.
844 *
845 * @param file Desired preferences file. If a preferences file by this name
846 * does not exist, it will be created when you retrieve an
847 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600848 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700849 *
850 * @return The single {@link SharedPreferences} instance that can be used
851 * to retrieve and modify the preference values.
852 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700853 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700854 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600855 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700856 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600857 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858
859 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600860 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700861 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600862 * storage locations after an upgrade, such as moving to device protected
863 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700864 *
865 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600866 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700867 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600868 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700869 * preferences didn't exist in the source context, otherwise
870 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600871 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700872 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600873 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
874
Jeff Sharkey35871f22016-01-29 17:13:29 -0700875 /**
876 * Delete an existing shared preferences file.
877 *
878 * @param name The name (unique in the application package) of the shared
879 * preferences file.
880 * @return {@code true} if the shared preferences file was successfully
881 * deleted; else {@code false}.
882 * @see #getSharedPreferences(String, int)
883 */
884 public abstract boolean deleteSharedPreferences(String name);
885
Christopher Tatefe2368c2017-05-17 15:42:35 -0700886 /** @hide */
887 public abstract void reloadSharedPreferences();
888
Jeff Sharkey35871f22016-01-29 17:13:29 -0700889 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800890 * Open a private file associated with this Context's application package
891 * for reading.
892 *
893 * @param name The name of the file to open; can not contain path
894 * separators.
895 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400896 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897 *
898 * @see #openFileOutput
899 * @see #fileList
900 * @see #deleteFile
901 * @see java.io.FileInputStream#FileInputStream(String)
902 */
903 public abstract FileInputStream openFileInput(String name)
904 throws FileNotFoundException;
905
906 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800907 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700908 * for writing. Creates the file if it doesn't already exist.
909 * <p>
910 * No additional permissions are required for the calling app to read or
911 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700912 *
Nick Kralevich15069212013-01-09 15:54:56 -0800913 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700914 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600915 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400916 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800917 * @see #MODE_APPEND
918 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800919 * @see #openFileInput
920 * @see #fileList
921 * @see #deleteFile
922 * @see java.io.FileOutputStream#FileOutputStream(String)
923 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600924 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 throws FileNotFoundException;
926
927 /**
928 * Delete the given private file associated with this Context's
929 * application package.
930 *
931 * @param name The name of the file to delete; can not contain path
932 * separators.
933 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400934 * @return {@code true} if the file was successfully deleted; else
935 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 *
937 * @see #openFileInput
938 * @see #openFileOutput
939 * @see #fileList
940 * @see java.io.File#delete()
941 */
942 public abstract boolean deleteFile(String name);
943
944 /**
945 * Returns the absolute path on the filesystem where a file created with
946 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700947 * <p>
948 * The returned path may change over time if the calling app is moved to an
949 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 *
951 * @param name The name of the file for which you would like to get
952 * its path.
953 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400954 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 *
956 * @see #openFileOutput
957 * @see #getFilesDir
958 * @see #getDir
959 */
960 public abstract File getFileStreamPath(String name);
961
962 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700963 * Returns the absolute path on the filesystem where a file created with
964 * {@link #getSharedPreferences(String, int)} is stored.
965 * <p>
966 * The returned path may change over time if the calling app is moved to an
967 * adopted storage device, so only relative paths should be persisted.
968 *
969 * @param name The name of the shared preferences for which you would like
970 * to get a path.
971 * @return An absolute path to the given file.
972 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600973 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700974 */
975 public abstract File getSharedPreferencesPath(String name);
976
977 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700978 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600979 * private files belonging to this app are stored. Apps should not use this
980 * path directly; they should instead use {@link #getFilesDir()},
981 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
982 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700983 * <p>
984 * The returned path may change over time if the calling app is moved to an
985 * adopted storage device, so only relative paths should be persisted.
986 * <p>
987 * No additional permissions are required for the calling app to read or
988 * write files under the returned path.
989 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600990 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700991 */
992 public abstract File getDataDir();
993
994 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700995 * Returns the absolute path to the directory on the filesystem where files
996 * created with {@link #openFileOutput} are stored.
997 * <p>
998 * The returned path may change over time if the calling app is moved to an
999 * adopted storage device, so only relative paths should be persisted.
1000 * <p>
1001 * No additional permissions are required for the calling app to read or
1002 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -07001003 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001004 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001005 * @see #openFileOutput
1006 * @see #getFileStreamPath
1007 * @see #getDir
1008 */
1009 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -07001010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001011 /**
Christopher Tatea7835b62014-07-11 17:25:57 -07001012 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001013 * {@link #getFilesDir()}. The difference is that files placed under this
1014 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -07001015 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1016 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001017 * <p>
1018 * The returned path may change over time if the calling app is moved to an
1019 * adopted storage device, so only relative paths should be persisted.
1020 * <p>
1021 * No additional permissions are required for the calling app to read or
1022 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -07001023 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001024 * @return The path of the directory holding application files that will not
1025 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -07001026 * @see #openFileOutput
1027 * @see #getFileStreamPath
1028 * @see #getDir
1029 * @see android.app.backup.BackupAgent
1030 */
1031 public abstract File getNoBackupFilesDir();
1032
1033 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001034 * Returns the absolute path to the directory on the primary shared/external
1035 * storage device where the application can place persistent files it owns.
1036 * These files are internal to the applications, and not typically visible
1037 * to the user as media.
1038 * <p>
1039 * This is like {@link #getFilesDir()} in that these files will be deleted
1040 * when the application is uninstalled, however there are some important
1041 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001042 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001043 * <li>Shared storage may not always be available, since removable media can
1044 * be ejected by the user. Media state can be checked using
1045 * {@link Environment#getExternalStorageState(File)}.
1046 * <li>There is no security enforced with these files. For example, any
1047 * application holding
1048 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001049 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001050 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001051 * <p>
1052 * If a shared storage device is emulated (as determined by
1053 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1054 * backed by a private user data partition, which means there is little
1055 * benefit to storing data here instead of the private directories returned
1056 * by {@link #getFilesDir()}, etc.
1057 * <p>
1058 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001059 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001060 * accessible to the calling app. This only applies to paths generated for
1061 * package name of the calling application. To access paths belonging to
1062 * other packages,
1063 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1064 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1065 * <p>
1066 * On devices with multiple users (as described by {@link UserManager}),
1067 * each user has their own isolated shared storage. Applications only have
1068 * access to the shared storage for the user they're running as.
1069 * <p>
1070 * The returned path may change over time if different shared storage media
1071 * is inserted, so only relative paths should be persisted.
1072 * <p>
1073 * Here is an example of typical code to manipulate a file in an
1074 * application's shared storage:
1075 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001076 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1077 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001078 * <p>
1079 * If you supply a non-null <var>type</var> to this function, the returned
1080 * file will be a path to a sub-directory of the given type. Though these
1081 * files are not automatically scanned by the media scanner, you can
1082 * explicitly add them to the media database with
1083 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1084 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001085 * {@link android.os.Environment#getExternalStoragePublicDirectory
1086 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001087 * directories of media shared by all applications. The directories returned
1088 * here are owned by the application, and their contents will be removed
1089 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001090 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001091 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1092 * here will be automatically created for you.
1093 * <p>
1094 * Here is an example of typical code to manipulate a picture in an
1095 * application's shared storage and add it to the media database:
1096 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001097 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1098 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001099 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001100 * @param type The type of files directory to return. May be {@code null}
1101 * for the root of the files directory or one of the following
1102 * constants for a subdirectory:
1103 * {@link android.os.Environment#DIRECTORY_MUSIC},
1104 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1105 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1106 * {@link android.os.Environment#DIRECTORY_ALARMS},
1107 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1108 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1109 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1110 * @return the absolute path to application-specific directory. May return
1111 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001112 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001113 * @see #getExternalFilesDirs(String)
1114 * @see Environment#getExternalStorageState(File)
1115 * @see Environment#isExternalStorageEmulated(File)
1116 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001117 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001118 @Nullable
1119 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001120
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001121 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001122 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001123 * shared/external storage devices where the application can place
1124 * persistent files it owns. These files are internal to the application,
1125 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001126 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001127 * This is like {@link #getFilesDir()} in that these files will be deleted
1128 * when the application is uninstalled, however there are some important
1129 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001130 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001131 * <li>Shared storage may not always be available, since removable media can
1132 * be ejected by the user. Media state can be checked using
1133 * {@link Environment#getExternalStorageState(File)}.
1134 * <li>There is no security enforced with these files. For example, any
1135 * application holding
1136 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1137 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001138 * </ul>
1139 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001140 * If a shared storage device is emulated (as determined by
1141 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1142 * backed by a private user data partition, which means there is little
1143 * benefit to storing data here instead of the private directories returned
1144 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001145 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001146 * Shared storage devices returned here are considered a stable part of the
1147 * device, including physical media slots under a protective cover. The
1148 * returned paths do not include transient devices, such as USB flash drives
1149 * connected to handheld devices.
1150 * <p>
1151 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001152 * example, an app may choose to store large files on the device with the
1153 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001154 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001155 * No additional permissions are required for the calling app to read or
1156 * write files under the returned path. Write access outside of these paths
1157 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001158 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001159 * The returned path may change over time if different shared storage media
1160 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001161 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001162 * @param type The type of files directory to return. May be {@code null}
1163 * for the root of the files directory or one of the following
1164 * constants for a subdirectory:
1165 * {@link android.os.Environment#DIRECTORY_MUSIC},
1166 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1167 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1168 * {@link android.os.Environment#DIRECTORY_ALARMS},
1169 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1170 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1171 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1172 * @return the absolute paths to application-specific directories. Some
1173 * individual paths may be {@code null} if that shared storage is
1174 * not currently available. The first path returned is the same as
1175 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001176 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001177 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001178 * @see Environment#isExternalStorageEmulated(File)
1179 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001180 */
1181 public abstract File[] getExternalFilesDirs(String type);
1182
1183 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001184 * Return the primary shared/external storage directory where this
1185 * application's OBB files (if there are any) can be found. Note if the
1186 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001187 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001188 * This is like {@link #getFilesDir()} in that these files will be deleted
1189 * when the application is uninstalled, however there are some important
1190 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001191 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001192 * <li>Shared storage may not always be available, since removable media can
1193 * be ejected by the user. Media state can be checked using
1194 * {@link Environment#getExternalStorageState(File)}.
1195 * <li>There is no security enforced with these files. For example, any
1196 * application holding
1197 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001198 * these files.
1199 * </ul>
1200 * <p>
1201 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001202 * are required to read or write to the path that this method returns.
1203 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1204 * to read the OBB expansion files, you must declare the
1205 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1206 * permission at runtime as follows:
1207 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001208 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001209 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1210 * android:maxSdkVersion="23" />}
1211 * </p>
1212 * <p>
1213 * Starting from {@link android.os.Build.VERSION_CODES#N},
1214 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1215 * permission is not required, so don’t ask for this
1216 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1217 * and if it fails, you must request
1218 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1219 * </p>
1220 *
1221 * <p>
1222 * The following code snippet shows how to do this:
1223 * </p>
1224 *
1225 * <pre>
1226 * File obb = new File(obb_filename);
1227 * boolean open_failed = false;
1228 *
1229 * try {
1230 * BufferedReader br = new BufferedReader(new FileReader(obb));
1231 * open_failed = false;
1232 * ReadObbFile(br);
1233 * } catch (IOException e) {
1234 * open_failed = true;
1235 * }
1236 *
1237 * if (open_failed) {
1238 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1239 * ReadObbFileWithPermission();
1240 * }
1241 * </pre>
1242 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001243 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001244 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001245 * should ensure that multiple instances running under different users don't
1246 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001247 *
1248 * @return the absolute path to application-specific directory. May return
1249 * {@code null} if shared storage is not currently available.
1250 * @see #getObbDirs()
1251 * @see Environment#getExternalStorageState(File)
1252 * @see Environment#isExternalStorageEmulated(File)
1253 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001254 */
1255 public abstract File getObbDir();
1256
1257 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001258 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001259 * shared/external storage devices where the application's OBB files (if
1260 * there are any) can be found. Note if the application does not have any
1261 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001262 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001263 * This is like {@link #getFilesDir()} in that these files will be deleted
1264 * when the application is uninstalled, however there are some important
1265 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001266 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001267 * <li>Shared storage may not always be available, since removable media can
1268 * be ejected by the user. Media state can be checked using
1269 * {@link Environment#getExternalStorageState(File)}.
1270 * <li>There is no security enforced with these files. For example, any
1271 * application holding
1272 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1273 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001274 * </ul>
1275 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001276 * Shared storage devices returned here are considered a stable part of the
1277 * device, including physical media slots under a protective cover. The
1278 * returned paths do not include transient devices, such as USB flash drives
1279 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001280 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001281 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001282 * example, an app may choose to store large files on the device with the
1283 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001284 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001285 * No additional permissions are required for the calling app to read or
1286 * write files under the returned path. Write access outside of these paths
1287 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001288 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001289 * @return the absolute paths to application-specific directories. Some
1290 * individual paths may be {@code null} if that shared storage is
1291 * not currently available. The first path returned is the same as
1292 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001293 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001294 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001295 * @see Environment#isExternalStorageEmulated(File)
1296 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001297 */
1298 public abstract File[] getObbDirs();
1299
1300 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001301 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001302 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001303 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001304 * The system will automatically delete files in this directory as disk
1305 * space is needed elsewhere on the device. The system will always delete
1306 * older files first, as reported by {@link File#lastModified()}. If
1307 * desired, you can exert more control over how files are deleted using
1308 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1309 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1310 * <p>
1311 * Apps are strongly encouraged to keep their usage of cache space below the
1312 * quota returned by
1313 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1314 * goes above this quota, your cached files will be some of the first to be
1315 * deleted when additional disk space is needed. Conversely, if your app
1316 * stays under this quota, your cached files will be some of the last to be
1317 * deleted when additional disk space is needed.
1318 * <p>
1319 * Note that your cache quota will change over time depending on how
1320 * frequently the user interacts with your app, and depending on how much
1321 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001322 * <p>
1323 * The returned path may change over time if the calling app is moved to an
1324 * adopted storage device, so only relative paths should be persisted.
1325 * <p>
1326 * Apps require no extra permissions to read or write to the returned path,
1327 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001328 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001329 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 * @see #openFileOutput
1331 * @see #getFileStreamPath
1332 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001333 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001334 */
1335 public abstract File getCacheDir();
1336
1337 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001338 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001339 * the filesystem designed for storing cached code.
1340 * <p>
1341 * The system will delete any files stored in this location both when your
1342 * specific application is upgraded, and when the entire platform is
1343 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001344 * <p>
1345 * This location is optimal for storing compiled or optimized code generated
1346 * by your application at runtime.
1347 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001348 * The returned path may change over time if the calling app is moved to an
1349 * adopted storage device, so only relative paths should be persisted.
1350 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001351 * Apps require no extra permissions to read or write to the returned path,
1352 * since this path lives in their private storage.
1353 *
1354 * @return The path of the directory holding application code cache files.
1355 */
1356 public abstract File getCodeCacheDir();
1357
1358 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001359 * Returns absolute path to application-specific directory on the primary
1360 * shared/external storage device 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.
1363 * <p>
1364 * 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:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001367 * <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
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001380 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001381 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001382 * <p>
1383 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001384 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001385 * 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()}.
1388 * <p>
1389 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001390 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001391 * accessible to the calling app. This only applies to paths generated for
1392 * package name of the calling application. To access paths belonging to
1393 * other packages,
1394 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1395 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1396 * <p>
1397 * On devices with multiple users (as described by {@link UserManager}),
1398 * each user has their own isolated shared storage. Applications only have
1399 * access to the shared storage for the user they're running as.
1400 * <p>
1401 * The returned path may change over time if different shared storage media
1402 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001403 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001404 * @return the absolute path to application-specific directory. May return
1405 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001406 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001407 * @see #getExternalCacheDirs()
1408 * @see Environment#getExternalStorageState(File)
1409 * @see Environment#isExternalStorageEmulated(File)
1410 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001411 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001412 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001413 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001414
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001415 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001416 * Returns absolute path to application-specific directory in the preloaded cache.
1417 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1418 * There is no guarantee when these files will be deleted.
1419 * @hide
1420 */
1421 @Nullable
1422 @SystemApi
1423 public abstract File getPreloadsFileCache();
1424
1425 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001426 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001427 * shared/external storage devices where the application can place cache
1428 * files it owns. These files are internal to the application, and not
1429 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001430 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001431 * This is like {@link #getCacheDir()} in that these files will be deleted
1432 * when the application is uninstalled, however there are some important
1433 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001434 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001435 * <li>The platform does not always monitor the space available in shared
1436 * storage, and thus may not automatically delete these files. Apps should
1437 * always manage the maximum space used in this location. Currently the only
1438 * time files here will be deleted by the platform is when running on
1439 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1440 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1441 * <li>Shared storage may not always be available, since removable media can
1442 * be ejected by the user. Media state can be checked using
1443 * {@link Environment#getExternalStorageState(File)}.
1444 * <li>There is no security enforced with these files. For example, any
1445 * application holding
1446 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1447 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001448 * </ul>
1449 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001450 * If a shared storage device is emulated (as determined by
1451 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1452 * backed by a private user data partition, which means there is little
1453 * benefit to storing data here instead of the private directory returned by
1454 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001455 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001456 * Shared storage devices returned here are considered a stable part of the
1457 * device, including physical media slots under a protective cover. The
1458 * returned paths do not include transient devices, such as USB flash drives
1459 * connected to handheld devices.
1460 * <p>
1461 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001462 * example, an app may choose to store large files on the device with the
1463 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001464 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001465 * No additional permissions are required for the calling app to read or
1466 * write files under the returned path. Write access outside of these paths
1467 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001468 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001469 * The returned paths may change over time if different shared storage media
1470 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001471 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001472 * @return the absolute paths to application-specific directories. Some
1473 * individual paths may be {@code null} if that shared storage is
1474 * not currently available. The first path returned is the same as
1475 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001476 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001477 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001478 * @see Environment#isExternalStorageEmulated(File)
1479 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001480 */
1481 public abstract File[] getExternalCacheDirs();
1482
1483 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001484 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001485 * shared/external storage devices where the application can place media
1486 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001487 * {@link MediaStore}.
1488 * <p>
1489 * This is like {@link #getExternalFilesDirs} in that these files will be
1490 * deleted when the application is uninstalled, however there are some
1491 * important differences:
1492 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001493 * <li>Shared storage may not always be available, since removable media can
1494 * be ejected by the user. Media state can be checked using
1495 * {@link Environment#getExternalStorageState(File)}.
1496 * <li>There is no security enforced with these files. For example, any
1497 * application holding
1498 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1499 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001500 * </ul>
1501 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001502 * Shared storage devices returned here are considered a stable part of the
1503 * device, including physical media slots under a protective cover. The
1504 * returned paths do not include transient devices, such as USB flash drives
1505 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001506 * <p>
1507 * An application may store data on any or all of the returned devices. For
1508 * example, an app may choose to store large files on the device with the
1509 * most available space, as measured by {@link StatFs}.
1510 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001511 * No additional permissions are required for the calling app to read or
1512 * write files under the returned path. Write access outside of these paths
1513 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001514 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001515 * The returned paths may change over time if different shared storage media
1516 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001517 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001518 * @return the absolute paths to application-specific directories. Some
1519 * individual paths may be {@code null} if that shared storage is
1520 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001521 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001522 * @see Environment#isExternalStorageEmulated(File)
1523 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001524 */
1525 public abstract File[] getExternalMediaDirs();
1526
1527 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 * Returns an array of strings naming the private files associated with
1529 * this Context's application package.
1530 *
1531 * @return Array of strings naming the private files.
1532 *
1533 * @see #openFileInput
1534 * @see #openFileOutput
1535 * @see #deleteFile
1536 */
1537 public abstract String[] fileList();
1538
1539 /**
1540 * Retrieve, creating if needed, a new directory in which the application
1541 * can place its own custom data files. You can use the returned File
1542 * object to create and access files in this directory. Note that files
1543 * created through a File object will only be accessible by your own
1544 * application; you can only set the mode of the entire directory, not
1545 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001546 * <p>
1547 * The returned path may change over time if the calling app is moved to an
1548 * adopted storage device, so only relative paths should be persisted.
1549 * <p>
1550 * Apps require no extra permissions to read or write to the returned path,
1551 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001552 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001553 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001554 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001555 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001556 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001557 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001558 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001559 *
1560 * @see #openFileOutput(String, int)
1561 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001562 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563
1564 /**
1565 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001566 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001567 *
1568 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001569 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001570 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001571 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001572 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001573 * @throws android.database.sqlite.SQLiteException if the database file
1574 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001576 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001577 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 * @see #deleteDatabase
1579 */
1580 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001581 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582
1583 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001584 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001585 * application package. Creates the database file if it doesn't exist.
1586 * <p>
1587 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1588 * to be used to handle corruption when sqlite reports database corruption.
1589 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001590 *
1591 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001592 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001593 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001594 * cursor when query is called.
1595 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1596 * sqlite reports database corruption. if null,
1597 * {@link android.database.DefaultDatabaseErrorHandler} is
1598 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001599 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001600 * @throws android.database.sqlite.SQLiteException if the database file
1601 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001602 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001603 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001604 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001605 * @see #deleteDatabase
1606 */
1607 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001608 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001609 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001610
1611 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001612 * Move an existing database file from the given source storage context to
1613 * this context. This is typically used to migrate data between storage
1614 * locations after an upgrade, such as migrating to device protected
1615 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001616 * <p>
1617 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001618 *
1619 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001620 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001621 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001622 * @return {@code true} if the move was successful or if the database didn't
1623 * exist in the source context, otherwise {@code false}.
1624 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001625 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001626 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1627
Jeff Sharkey35871f22016-01-29 17:13:29 -07001628 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 * Delete an existing private SQLiteDatabase associated with this Context's
1630 * application package.
1631 *
1632 * @param name The name (unique in the application package) of the
1633 * database.
1634 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001635 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 *
1637 * @see #openOrCreateDatabase
1638 */
1639 public abstract boolean deleteDatabase(String name);
1640
1641 /**
1642 * Returns the absolute path on the filesystem where a database created with
1643 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001644 * <p>
1645 * The returned path may change over time if the calling app is moved to an
1646 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 *
1648 * @param name The name of the database for which you would like to get
1649 * its path.
1650 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001651 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 *
1653 * @see #openOrCreateDatabase
1654 */
1655 public abstract File getDatabasePath(String name);
1656
1657 /**
1658 * Returns an array of strings naming the private databases associated with
1659 * this Context's application package.
1660 *
1661 * @return Array of strings naming the private databases.
1662 *
1663 * @see #openOrCreateDatabase
1664 * @see #deleteDatabase
1665 */
1666 public abstract String[] databaseList();
1667
1668 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001669 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001670 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001672 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001673 public abstract Drawable getWallpaper();
1674
1675 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001676 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001677 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001679 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 public abstract Drawable peekWallpaper();
1681
1682 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001683 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1684 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001685 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001686 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 public abstract int getWallpaperDesiredMinimumWidth();
1688
1689 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001690 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1691 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001693 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 public abstract int getWallpaperDesiredMinimumHeight();
1695
1696 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001697 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001698 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001699 * <p>This method requires the caller to hold the permission
1700 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001702 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1704
1705 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001706 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001707 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001708 * <p>This method requires the caller to hold the permission
1709 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001711 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712 public abstract void setWallpaper(InputStream data) throws IOException;
1713
1714 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001715 * @deprecated Use {@link android.app.WallpaperManager#clear
1716 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001717 * <p>This method requires the caller to hold the permission
1718 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001720 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 public abstract void clearWallpaper() throws IOException;
1722
1723 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001724 * Same as {@link #startActivity(Intent, Bundle)} with no options
1725 * specified.
1726 *
1727 * @param intent The description of the activity to start.
1728 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001729 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001730 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001731 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001732 * @see PackageManager#resolveActivity
1733 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001734 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001735
1736 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001737 * Version of {@link #startActivity(Intent)} that allows you to specify the
1738 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001739 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001740 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001741 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001742 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001743 * @hide
1744 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001745 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07001746 @SystemApi
Adrian Roosebc927c2019-02-28 16:21:18 +01001747 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1748 @NonNull UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001749 throw new RuntimeException("Not implemented. Must override in a subclass.");
1750 }
1751
1752 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 * Launch a new activity. You will not receive any information about when
1754 * the activity exits.
1755 *
1756 * <p>Note that if this method is being called from outside of an
1757 * {@link android.app.Activity} Context, then the Intent must include
1758 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1759 * without being started from an existing Activity, there is no existing
1760 * task in which to place the new activity and thus it needs to be placed
1761 * in its own separate task.
1762 *
1763 * <p>This method throws {@link ActivityNotFoundException}
1764 * if there was no Activity found to run the given Intent.
1765 *
1766 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001767 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001768 * May be null if there are no options. See {@link android.app.ActivityOptions}
1769 * for how to build the Bundle supplied here; there are no supported definitions
1770 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001772 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001773 *
Scott Main60dd5202012-06-23 00:01:22 -07001774 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 * @see PackageManager#resolveActivity
1776 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001777 public abstract void startActivity(@RequiresPermission Intent intent,
1778 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001779
1780 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001781 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1782 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001783 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001784 * @param intent The description of the activity to start.
1785 * @param options Additional options for how the Activity should be started.
1786 * May be null if there are no options. See {@link android.app.ActivityOptions}
1787 * for how to build the Bundle supplied here; there are no supported definitions
1788 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001789 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001790 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001791 * @hide
1792 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001793 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001794 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001795 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1796 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001797 throw new RuntimeException("Not implemented. Must override in a subclass.");
1798 }
1799
1800 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001801 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1802 * is only supported for Views and Fragments.
1803 * @param who The identifier for the calling element that will receive the result.
1804 * @param intent The intent to start.
1805 * @param requestCode The code that will be returned with onActivityResult() identifying this
1806 * request.
1807 * @param options Additional options for how the Activity should be started.
1808 * May be null if there are no options. See {@link android.app.ActivityOptions}
1809 * for how to build the Bundle supplied here; there are no supported definitions
1810 * for building it manually.
1811 * @hide
1812 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001813 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001814 public void startActivityForResult(
1815 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1816 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1817 + "Check canStartActivityForResult() before calling.");
1818 }
1819
1820 /**
1821 * Identifies whether this Context instance will be able to process calls to
1822 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1823 * @hide
1824 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001825 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001826 public boolean canStartActivityForResult() {
1827 return false;
1828 }
1829
1830 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001831 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1832 * specified.
1833 *
1834 * @param intents An array of Intents to be started.
1835 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001836 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001837 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001838 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001839 * @see PackageManager#resolveActivity
1840 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001841 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842
1843 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001844 * Launch multiple new activities. This is generally the same as calling
1845 * {@link #startActivity(Intent)} for the first Intent in the array,
1846 * that activity during its creation calling {@link #startActivity(Intent)}
1847 * for the second entry, etc. Note that unlike that approach, generally
1848 * none of the activities except the last in the array will be created
1849 * at this point, but rather will be created when the user first visits
1850 * them (due to pressing back from the activity on top).
1851 *
1852 * <p>This method throws {@link ActivityNotFoundException}
1853 * if there was no Activity found for <em>any</em> given Intent. In this
1854 * case the state of the activity stack is undefined (some Intents in the
1855 * list may be on it, some not), so you probably want to avoid such situations.
1856 *
1857 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001858 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001859 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001860 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001861 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001862 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001863 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001864 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001865 * @see PackageManager#resolveActivity
1866 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001867 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001868
1869 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001870 * @hide
1871 * Launch multiple new activities. This is generally the same as calling
1872 * {@link #startActivity(Intent)} for the first Intent in the array,
1873 * that activity during its creation calling {@link #startActivity(Intent)}
1874 * for the second entry, etc. Note that unlike that approach, generally
1875 * none of the activities except the last in the array will be created
1876 * at this point, but rather will be created when the user first visits
1877 * them (due to pressing back from the activity on top).
1878 *
1879 * <p>This method throws {@link ActivityNotFoundException}
1880 * if there was no Activity found for <em>any</em> given Intent. In this
1881 * case the state of the activity stack is undefined (some Intents in the
1882 * list may be on it, some not), so you probably want to avoid such situations.
1883 *
1884 * @param intents An array of Intents to be started.
1885 * @param options Additional options for how the Activity should be started.
1886 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001887 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001888 * Context.startActivity(Intent, Bundle)} for more details.
1889 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001890 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1891 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1892 * successful.
1893 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001894 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001895 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001896 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001897 * @see PackageManager#resolveActivity
1898 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001899 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001900 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001901 throw new RuntimeException("Not implemented. Must override in a subclass.");
1902 }
1903
1904 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001905 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1906 * with no options specified.
1907 *
1908 * @param intent The IntentSender to launch.
1909 * @param fillInIntent If non-null, this will be provided as the
1910 * intent parameter to {@link IntentSender#sendIntent}.
1911 * @param flagsMask Intent flags in the original IntentSender that you
1912 * would like to change.
1913 * @param flagsValues Desired values for any bits set in
1914 * <var>flagsMask</var>
1915 * @param extraFlags Always set to 0.
1916 *
1917 * @see #startActivity(Intent)
1918 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1919 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001920 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1921 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1922 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001923
1924 /**
1925 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001926 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001927 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001928 * here; otherwise, its associated action will be executed (such as
1929 * sending a broadcast) as if you had called
1930 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001931 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001932 * @param intent The IntentSender to launch.
1933 * @param fillInIntent If non-null, this will be provided as the
1934 * intent parameter to {@link IntentSender#sendIntent}.
1935 * @param flagsMask Intent flags in the original IntentSender that you
1936 * would like to change.
1937 * @param flagsValues Desired values for any bits set in
1938 * <var>flagsMask</var>
1939 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001940 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001941 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001942 * Context.startActivity(Intent, Bundle)} for more details. If options
1943 * have also been supplied by the IntentSender, options given here will
1944 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001945 *
1946 * @see #startActivity(Intent, Bundle)
1947 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001948 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001949 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1950 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1951 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001952
1953 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 * Broadcast the given intent to all interested BroadcastReceivers. This
1955 * call is asynchronous; it returns immediately, and you will continue
1956 * executing while the receivers are run. No results are propagated from
1957 * receivers and receivers can not abort the broadcast. If you want
1958 * to allow receivers to propagate results or abort the broadcast, you must
1959 * send an ordered broadcast using
1960 * {@link #sendOrderedBroadcast(Intent, String)}.
1961 *
1962 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1963 *
1964 * @param intent The Intent to broadcast; all receivers matching this
1965 * Intent will receive the broadcast.
1966 *
1967 * @see android.content.BroadcastReceiver
1968 * @see #registerReceiver
1969 * @see #sendBroadcast(Intent, String)
1970 * @see #sendOrderedBroadcast(Intent, String)
1971 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1972 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001973 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001974
1975 /**
1976 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1977 * an optional required permission to be enforced. This
1978 * call is asynchronous; it returns immediately, and you will continue
1979 * executing while the receivers are run. No results are propagated from
1980 * receivers and receivers can not abort the broadcast. If you want
1981 * to allow receivers to propagate results or abort the broadcast, you must
1982 * send an ordered broadcast using
1983 * {@link #sendOrderedBroadcast(Intent, String)}.
1984 *
1985 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1986 *
1987 * @param intent The Intent to broadcast; all receivers matching this
1988 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001989 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001990 * a receiver must hold in order to receive your broadcast.
1991 * If null, no permission is required.
1992 *
1993 * @see android.content.BroadcastReceiver
1994 * @see #registerReceiver
1995 * @see #sendBroadcast(Intent)
1996 * @see #sendOrderedBroadcast(Intent, String)
1997 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1998 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001999 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002000 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002002
2003 /**
2004 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2005 * an array of required permissions to be enforced. This call is asynchronous; it returns
2006 * immediately, and you will continue executing while the receivers are run. No results are
2007 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2008 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2009 * using {@link #sendOrderedBroadcast(Intent, String)}.
2010 *
2011 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2012 *
2013 * @param intent The Intent to broadcast; all receivers matching this
2014 * Intent will receive the broadcast.
2015 * @param receiverPermissions Array of names of permissions that a receiver must hold
2016 * in order to receive your broadcast.
2017 * If null or empty, no permissions are required.
2018 *
2019 * @see android.content.BroadcastReceiver
2020 * @see #registerReceiver
2021 * @see #sendBroadcast(Intent)
2022 * @see #sendOrderedBroadcast(Intent, String)
2023 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2024 * @hide
2025 */
2026 public abstract void sendBroadcastMultiplePermissions(Intent intent,
2027 String[] receiverPermissions);
2028
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002029 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002030 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07002031 * an array of required permissions to be enforced. This call is asynchronous; it returns
2032 * immediately, and you will continue executing while the receivers are run. No results are
2033 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2034 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2035 * using {@link #sendOrderedBroadcast(Intent, String)}.
2036 *
2037 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2038 *
2039 * @param intent The Intent to broadcast; all receivers matching this
2040 * Intent will receive the broadcast.
2041 * @param user The user to send the broadcast to.
2042 * @param receiverPermissions Array of names of permissions that a receiver must hold
2043 * in order to receive your broadcast.
2044 * If null or empty, no permissions are required.
2045 *
2046 * @see android.content.BroadcastReceiver
2047 * @see #registerReceiver
2048 * @see #sendBroadcast(Intent)
2049 * @see #sendOrderedBroadcast(Intent, String)
2050 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2051 * @hide
2052 */
2053 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2054 String[] receiverPermissions);
2055
2056 /**
2057 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002058 * an optional required permission to be enforced. This
2059 * call is asynchronous; it returns immediately, and you will continue
2060 * executing while the receivers are run. No results are propagated from
2061 * receivers and receivers can not abort the broadcast. If you want
2062 * to allow receivers to propagate results or abort the broadcast, you must
2063 * send an ordered broadcast using
2064 * {@link #sendOrderedBroadcast(Intent, String)}.
2065 *
2066 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2067 *
2068 * @param intent The Intent to broadcast; all receivers matching this
2069 * Intent will receive the broadcast.
2070 * @param receiverPermission (optional) String naming a permission that
2071 * a receiver must hold in order to receive your broadcast.
2072 * If null, no permission is required.
2073 * @param options (optional) Additional sending options, generated from a
2074 * {@link android.app.BroadcastOptions}.
2075 *
2076 * @see android.content.BroadcastReceiver
2077 * @see #registerReceiver
2078 * @see #sendBroadcast(Intent)
2079 * @see #sendOrderedBroadcast(Intent, String)
2080 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2081 * @hide
2082 */
2083 @SystemApi
2084 public abstract void sendBroadcast(Intent intent,
2085 @Nullable String receiverPermission,
2086 @Nullable Bundle options);
2087
2088 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002089 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002090 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002091 * @hide
2092 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002093 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002094 public abstract void sendBroadcast(Intent intent,
2095 String receiverPermission, int appOp);
2096
2097 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2099 * them one at a time to allow more preferred receivers to consume the
2100 * broadcast before it is delivered to less preferred receivers. This
2101 * call is asynchronous; it returns immediately, and you will continue
2102 * executing while the receivers are run.
2103 *
2104 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2105 *
2106 * @param intent The Intent to broadcast; all receivers matching this
2107 * Intent will receive the broadcast.
2108 * @param receiverPermission (optional) String naming a permissions that
2109 * a receiver must hold in order to receive your broadcast.
2110 * If null, no permission is required.
2111 *
2112 * @see android.content.BroadcastReceiver
2113 * @see #registerReceiver
2114 * @see #sendBroadcast(Intent)
2115 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2116 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002117 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002118 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002119
2120 /**
2121 * Version of {@link #sendBroadcast(Intent)} that allows you to
2122 * receive data back from the broadcast. This is accomplished by
2123 * supplying your own BroadcastReceiver when calling, which will be
2124 * treated as a final receiver at the end of the broadcast -- its
2125 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002126 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002127 * be serialized in the same way as calling
2128 * {@link #sendOrderedBroadcast(Intent, String)}.
2129 *
2130 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2131 * asynchronous; it will return before
2132 * resultReceiver.onReceive() is called.
2133 *
2134 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2135 *
2136 * @param intent The Intent to broadcast; all receivers matching this
2137 * Intent will receive the broadcast.
2138 * @param receiverPermission String naming a permissions that
2139 * a receiver must hold in order to receive your broadcast.
2140 * If null, no permission is required.
2141 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2142 * receiver of the broadcast.
2143 * @param scheduler A custom Handler with which to schedule the
2144 * resultReceiver callback; if null it will be
2145 * scheduled in the Context's main thread.
2146 * @param initialCode An initial value for the result code. Often
2147 * Activity.RESULT_OK.
2148 * @param initialData An initial value for the result data. Often
2149 * null.
2150 * @param initialExtras An initial value for the result extras. Often
2151 * null.
2152 *
2153 * @see #sendBroadcast(Intent)
2154 * @see #sendBroadcast(Intent, String)
2155 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002156 * @see android.content.BroadcastReceiver
2157 * @see #registerReceiver
2158 * @see android.app.Activity#RESULT_OK
2159 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002160 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002161 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002162 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2163 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002164
2165 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002166 * Version of {@link #sendBroadcast(Intent)} that allows you to
2167 * receive data back from the broadcast. This is accomplished by
2168 * supplying your own BroadcastReceiver when calling, which will be
2169 * treated as a final receiver at the end of the broadcast -- its
2170 * {@link BroadcastReceiver#onReceive} method will be called with
2171 * the result values collected from the other receivers. The broadcast will
2172 * be serialized in the same way as calling
2173 * {@link #sendOrderedBroadcast(Intent, String)}.
2174 *
2175 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2176 * asynchronous; it will return before
2177 * resultReceiver.onReceive() is called.
2178 *
2179 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2180 *
2181 *
2182 * @param intent The Intent to broadcast; all receivers matching this
2183 * Intent will receive the broadcast.
2184 * @param receiverPermission String naming a permissions that
2185 * a receiver must hold in order to receive your broadcast.
2186 * If null, no permission is required.
2187 * @param options (optional) Additional sending options, generated from a
2188 * {@link android.app.BroadcastOptions}.
2189 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2190 * receiver of the broadcast.
2191 * @param scheduler A custom Handler with which to schedule the
2192 * resultReceiver callback; if null it will be
2193 * scheduled in the Context's main thread.
2194 * @param initialCode An initial value for the result code. Often
2195 * Activity.RESULT_OK.
2196 * @param initialData An initial value for the result data. Often
2197 * null.
2198 * @param initialExtras An initial value for the result extras. Often
2199 * null.
2200 * @see #sendBroadcast(Intent)
2201 * @see #sendBroadcast(Intent, String)
2202 * @see #sendOrderedBroadcast(Intent, String)
2203 * @see android.content.BroadcastReceiver
2204 * @see #registerReceiver
2205 * @see android.app.Activity#RESULT_OK
2206 * @hide
2207 */
2208 @SystemApi
2209 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2210 @Nullable String receiverPermission, @Nullable Bundle options,
2211 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2212 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2213
2214 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002215 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2216 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002217 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002218 * @hide
2219 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002220 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002221 public abstract void sendOrderedBroadcast(Intent intent,
2222 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2223 Handler scheduler, int initialCode, String initialData,
2224 Bundle initialExtras);
2225
2226 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002227 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2228 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002229 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002230 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002231 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002232 * @see #sendBroadcast(Intent)
2233 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002234 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002235 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2236 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002237
2238 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002239 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2240 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002241 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002242 *
2243 * @param intent The Intent to broadcast; all receivers matching this
2244 * Intent will receive the broadcast.
2245 * @param user UserHandle to send the intent to.
2246 * @param receiverPermission (optional) String naming a permission that
2247 * a receiver must hold in order to receive your broadcast.
2248 * If null, no permission is required.
2249 *
2250 * @see #sendBroadcast(Intent, String)
2251 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002252 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002253 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2254 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002255
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002256 /**
2257 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2258 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002259 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002260 *
2261 * @param intent The Intent to broadcast; all receivers matching this
2262 * Intent will receive the broadcast.
2263 * @param user UserHandle to send the intent to.
2264 * @param receiverPermission (optional) String naming a permission that
2265 * a receiver must hold in order to receive your broadcast.
2266 * If null, no permission is required.
2267 * @param options (optional) Additional sending options, generated from a
2268 * {@link android.app.BroadcastOptions}.
2269 *
2270 * @see #sendBroadcast(Intent, String, Bundle)
2271 * @hide
2272 */
2273 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002274 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002275 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2276 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002277
2278 /**
2279 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2280 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002281 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002282 *
2283 * @param intent The Intent to broadcast; all receivers matching this
2284 * Intent will receive the broadcast.
2285 * @param user UserHandle to send the intent to.
2286 * @param receiverPermission (optional) String naming a permission that
2287 * a receiver must hold in order to receive your broadcast.
2288 * If null, no permission is required.
2289 * @param appOp The app op associated with the broadcast.
2290 *
2291 * @see #sendBroadcast(Intent, String)
2292 *
2293 * @hide
2294 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002295 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002296 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002297 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2298 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002299
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002300 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002301 * Version of
2302 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2303 * that allows you to specify the
2304 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002305 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002306 *
2307 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2308 *
2309 * @param intent The Intent to broadcast; all receivers matching this
2310 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002311 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002312 * @param receiverPermission String naming a permissions that
2313 * a receiver must hold in order to receive your broadcast.
2314 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002315 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2316 * receiver of the broadcast.
2317 * @param scheduler A custom Handler with which to schedule the
2318 * resultReceiver callback; if null it will be
2319 * scheduled in the Context's main thread.
2320 * @param initialCode An initial value for the result code. Often
2321 * Activity.RESULT_OK.
2322 * @param initialData An initial value for the result data. Often
2323 * null.
2324 * @param initialExtras An initial value for the result extras. Often
2325 * null.
2326 *
2327 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2328 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002329 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002330 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2331 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002332 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2333 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002334
2335 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002336 * Similar to above but takes an appOp as well, to enforce restrictions.
2337 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2338 * BroadcastReceiver, Handler, int, String, Bundle)
2339 * @hide
2340 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002341 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002342 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002343 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2344 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2345 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2346 @Nullable Bundle initialExtras);
2347
2348 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002349 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2350 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2351 * BroadcastReceiver, Handler, int, String, Bundle)
2352 * @hide
2353 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002354 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002355 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002356 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2357 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2358 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2359 @Nullable String initialData, @Nullable Bundle initialExtras);
2360
2361 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002362 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002363 * Intent you are sending stays around after the broadcast is complete,
2364 * so that others can quickly retrieve that data through the return
2365 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2366 * all other ways, this behaves the same as
2367 * {@link #sendBroadcast(Intent)}.
2368 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002369 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2370 * can access them), no protection (anyone can modify them), and many other problems.
2371 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2372 * has changed, with another mechanism for apps to retrieve the current value whenever
2373 * desired.
2374 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375 * @param intent The Intent to broadcast; all receivers matching this
2376 * Intent will receive the broadcast, and the Intent will be held to
2377 * be re-broadcast to future receivers.
2378 *
2379 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002380 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002381 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002382 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002383 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002384 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002385
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002386 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002387 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002388 * receive data back from the broadcast. This is accomplished by
2389 * supplying your own BroadcastReceiver when calling, which will be
2390 * treated as a final receiver at the end of the broadcast -- its
2391 * {@link BroadcastReceiver#onReceive} method will be called with
2392 * the result values collected from the other receivers. The broadcast will
2393 * be serialized in the same way as calling
2394 * {@link #sendOrderedBroadcast(Intent, String)}.
2395 *
2396 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2397 * asynchronous; it will return before
2398 * resultReceiver.onReceive() is called. Note that the sticky data
2399 * stored is only the data you initially supply to the broadcast, not
2400 * the result of any changes made by the receivers.
2401 *
2402 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2403 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002404 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2405 * can access them), no protection (anyone can modify them), and many other problems.
2406 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2407 * has changed, with another mechanism for apps to retrieve the current value whenever
2408 * desired.
2409 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002410 * @param intent The Intent to broadcast; all receivers matching this
2411 * Intent will receive the broadcast.
2412 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2413 * receiver of the broadcast.
2414 * @param scheduler A custom Handler with which to schedule the
2415 * resultReceiver callback; if null it will be
2416 * scheduled in the Context's main thread.
2417 * @param initialCode An initial value for the result code. Often
2418 * Activity.RESULT_OK.
2419 * @param initialData An initial value for the result data. Often
2420 * null.
2421 * @param initialExtras An initial value for the result extras. Often
2422 * null.
2423 *
2424 * @see #sendBroadcast(Intent)
2425 * @see #sendBroadcast(Intent, String)
2426 * @see #sendOrderedBroadcast(Intent, String)
2427 * @see #sendStickyBroadcast(Intent)
2428 * @see android.content.BroadcastReceiver
2429 * @see #registerReceiver
2430 * @see android.app.Activity#RESULT_OK
2431 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002432 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002433 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002434 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002435 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002436 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2437 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002439 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002440 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002441 * so that it is as if the sticky broadcast had never happened.
2442 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002443 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2444 * can access them), no protection (anyone can modify them), and many other problems.
2445 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2446 * has changed, with another mechanism for apps to retrieve the current value whenever
2447 * desired.
2448 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002449 * @param intent The Intent that was previously broadcast.
2450 *
2451 * @see #sendStickyBroadcast
2452 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002453 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002454 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002455 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002456
2457 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002458 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002459 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002460 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002461 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002462 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2463 * can access them), no protection (anyone can modify them), and many other problems.
2464 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2465 * has changed, with another mechanism for apps to retrieve the current value whenever
2466 * desired.
2467 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002468 * @param intent The Intent to broadcast; all receivers matching this
2469 * Intent will receive the broadcast, and the Intent will be held to
2470 * be re-broadcast to future receivers.
2471 * @param user UserHandle to send the intent to.
2472 *
2473 * @see #sendBroadcast(Intent)
2474 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002475 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002476 @RequiresPermission(allOf = {
2477 android.Manifest.permission.INTERACT_ACROSS_USERS,
2478 android.Manifest.permission.BROADCAST_STICKY
2479 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002480 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2481 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002482
2483 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002484 * @hide
2485 * This is just here for sending CONNECTIVITY_ACTION.
2486 */
2487 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002488 @RequiresPermission(allOf = {
2489 android.Manifest.permission.INTERACT_ACROSS_USERS,
2490 android.Manifest.permission.BROADCAST_STICKY
2491 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002492 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2493 UserHandle user, Bundle options);
2494
2495 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002496 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002497 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2498 * that allows you to specify the
2499 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002500 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002501 *
2502 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2503 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002504 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2505 * can access them), no protection (anyone can modify them), and many other problems.
2506 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2507 * has changed, with another mechanism for apps to retrieve the current value whenever
2508 * desired.
2509 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002510 * @param intent The Intent to broadcast; all receivers matching this
2511 * Intent will receive the broadcast.
2512 * @param user UserHandle to send the intent to.
2513 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2514 * receiver of the broadcast.
2515 * @param scheduler A custom Handler with which to schedule the
2516 * resultReceiver callback; if null it will be
2517 * scheduled in the Context's main thread.
2518 * @param initialCode An initial value for the result code. Often
2519 * Activity.RESULT_OK.
2520 * @param initialData An initial value for the result data. Often
2521 * null.
2522 * @param initialExtras An initial value for the result extras. Often
2523 * null.
2524 *
2525 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2526 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002527 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002528 @RequiresPermission(allOf = {
2529 android.Manifest.permission.INTERACT_ACROSS_USERS,
2530 android.Manifest.permission.BROADCAST_STICKY
2531 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002532 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002533 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002534 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2535 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002536
2537 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002538 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002539 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002540 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002541 *
2542 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2543 * permission in order to use this API. If you do not hold that
2544 * permission, {@link SecurityException} will be thrown.
2545 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002546 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2547 * can access them), no protection (anyone can modify them), and many other problems.
2548 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2549 * has changed, with another mechanism for apps to retrieve the current value whenever
2550 * desired.
2551 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002552 * @param intent The Intent that was previously broadcast.
2553 * @param user UserHandle to remove the sticky broadcast from.
2554 *
2555 * @see #sendStickyBroadcastAsUser
2556 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002557 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002558 @RequiresPermission(allOf = {
2559 android.Manifest.permission.INTERACT_ACROSS_USERS,
2560 android.Manifest.permission.BROADCAST_STICKY
2561 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002562 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2563 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002564
2565 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002566 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 * <var>receiver</var> will be called with any broadcast Intent that
2568 * matches <var>filter</var>, in the main application thread.
2569 *
2570 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002571 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 * registrations. If your IntentFilter matches one of these sticky
2573 * Intents, that Intent will be returned by this function
2574 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2575 * been broadcast.
2576 *
2577 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2578 * in which case each of these will be sent to <var>receiver</var>. In
2579 * this case, only one of these can be returned directly by the function;
2580 * which of these that is returned is arbitrarily decided by the system.
2581 *
2582 * <p>If you know the Intent your are registering for is sticky, you can
2583 * supply null for your <var>receiver</var>. In this case, no receiver is
2584 * registered -- the function simply returns the sticky Intent that
2585 * matches <var>filter</var>. In the case of multiple matches, the same
2586 * rules as described above apply.
2587 *
2588 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2589 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002590 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2591 * registered with this method will correctly respect the
2592 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2593 * Prior to that, it would be ignored and delivered to all matching registered
2594 * receivers. Be careful if using this for security.</p>
2595 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002596 * <p class="note">Note: this method <em>cannot be called from a
2597 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2598 * that is declared in an application's manifest. It is okay, however, to call
2599 * this method from another BroadcastReceiver that has itself been registered
2600 * at run time with {@link #registerReceiver}, since the lifetime of such a
2601 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002602 *
2603 * @param receiver The BroadcastReceiver to handle the broadcast.
2604 * @param filter Selects the Intent broadcasts to be received.
2605 *
2606 * @return The first sticky intent found that matches <var>filter</var>,
2607 * or null if there are none.
2608 *
2609 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2610 * @see #sendBroadcast
2611 * @see #unregisterReceiver
2612 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002613 @Nullable
2614 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002615 IntentFilter filter);
2616
2617 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002618 * Register to receive intent broadcasts, with the receiver optionally being
2619 * exposed to Instant Apps. See
2620 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2621 * information. By default Instant Apps cannot interact with receivers in other
2622 * applications, this allows you to expose a receiver that Instant Apps can
2623 * interact with.
2624 *
2625 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2626 *
2627 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2628 * registered with this method will correctly respect the
2629 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2630 * Prior to that, it would be ignored and delivered to all matching registered
2631 * receivers. Be careful if using this for security.</p>
2632 *
2633 * @param receiver The BroadcastReceiver to handle the broadcast.
2634 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002635 * @param flags Additional options for the receiver. May be 0 or
2636 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002637 *
2638 * @return The first sticky intent found that matches <var>filter</var>,
2639 * or null if there are none.
2640 *
2641 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2642 * @see #sendBroadcast
2643 * @see #unregisterReceiver
2644 */
2645 @Nullable
2646 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2647 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002648 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002649
2650 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 * Register to receive intent broadcasts, to run in the context of
2652 * <var>scheduler</var>. See
2653 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2654 * information. This allows you to enforce permissions on who can
2655 * broadcast intents to your receiver, or have the receiver run in
2656 * a different thread than the main application thread.
2657 *
2658 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2659 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002660 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2661 * registered with this method will correctly respect the
2662 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2663 * Prior to that, it would be ignored and delivered to all matching registered
2664 * receivers. Be careful if using this for security.</p>
2665 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002666 * @param receiver The BroadcastReceiver to handle the broadcast.
2667 * @param filter Selects the Intent broadcasts to be received.
2668 * @param broadcastPermission String naming a permissions that a
2669 * broadcaster must hold in order to send an Intent to you. If null,
2670 * no permission is required.
2671 * @param scheduler Handler identifying the thread that will receive
2672 * the Intent. If null, the main thread of the process will be used.
2673 *
2674 * @return The first sticky intent found that matches <var>filter</var>,
2675 * or null if there are none.
2676 *
2677 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2678 * @see #sendBroadcast
2679 * @see #unregisterReceiver
2680 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002681 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002683 IntentFilter filter, @Nullable String broadcastPermission,
2684 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002685
2686 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002687 * Register to receive intent broadcasts, to run in the context of
2688 * <var>scheduler</var>. See
2689 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002690 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2691 * for more information.
2692 *
2693 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2694 *
2695 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2696 * registered with this method will correctly respect the
2697 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2698 * Prior to that, it would be ignored and delivered to all matching registered
2699 * receivers. Be careful if using this for security.</p>
2700 *
2701 * @param receiver The BroadcastReceiver to handle the broadcast.
2702 * @param filter Selects the Intent broadcasts to be received.
2703 * @param broadcastPermission String naming a permissions that a
2704 * broadcaster must hold in order to send an Intent to you. If null,
2705 * no permission is required.
2706 * @param scheduler Handler identifying the thread that will receive
2707 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002708 * @param flags Additional options for the receiver. May be 0 or
2709 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002710 *
2711 * @return The first sticky intent found that matches <var>filter</var>,
2712 * or null if there are none.
2713 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002714 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002715 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2716 * @see #sendBroadcast
2717 * @see #unregisterReceiver
2718 */
2719 @Nullable
2720 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2721 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002722 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002723
2724 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002725 * @hide
2726 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2727 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002728 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002729 *
2730 * @param receiver The BroadcastReceiver to handle the broadcast.
2731 * @param user UserHandle to send the intent to.
2732 * @param filter Selects the Intent broadcasts to be received.
2733 * @param broadcastPermission String naming a permissions that a
2734 * broadcaster must hold in order to send an Intent to you. If null,
2735 * no permission is required.
2736 * @param scheduler Handler identifying the thread that will receive
2737 * the Intent. If null, the main thread of the process will be used.
2738 *
2739 * @return The first sticky intent found that matches <var>filter</var>,
2740 * or null if there are none.
2741 *
Jeff Brown6e539312015-02-24 18:53:21 -08002742 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002743 * @see #sendBroadcast
2744 * @see #unregisterReceiver
2745 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002746 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002747 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002748 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002749 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002750 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2751 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752
2753 /**
2754 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2755 * filters that have been registered for this BroadcastReceiver will be
2756 * removed.
2757 *
2758 * @param receiver The BroadcastReceiver to unregister.
2759 *
2760 * @see #registerReceiver
2761 */
2762 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2763
2764 /**
2765 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002766 * should either contain the complete class name of a specific service
2767 * implementation to start, or a specific package name to target. If the
2768 * Intent is less specified, it logs a warning about this. In this case any of the
2769 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 * is not already running, it will be instantiated and started (creating a
2771 * process for it if needed); if it is running then it remains running.
2772 *
2773 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002774 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002775 * with the <var>intent</var> given here. This provides a convenient way
2776 * to submit jobs to a service without having to bind and call on to its
2777 * interface.
2778 *
2779 * <p>Using startService() overrides the default service lifetime that is
2780 * managed by {@link #bindService}: it requires the service to remain
2781 * running until {@link #stopService} is called, regardless of whether
2782 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002783 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002784 * a single call to {@link #stopService} will stop it.
2785 *
2786 * <p>The system attempts to keep running services around as much as
2787 * possible. The only time they should be stopped is if the current
2788 * foreground application is using so many resources that the service needs
2789 * to be killed. If any errors happen in the service's process, it will
2790 * automatically be restarted.
2791 *
2792 * <p>This function will throw {@link SecurityException} if you do not
2793 * have permission to start the given service.
2794 *
Chris Craik1e353522016-04-18 10:20:50 -07002795 * <p class="note"><strong>Note:</strong> Each call to startService()
2796 * results in significant work done by the system to manage service
2797 * lifecycle surrounding the processing of the intent, which can take
2798 * multiple milliseconds of CPU time. Due to this cost, startService()
2799 * should not be used for frequent intent delivery to a service, and only
2800 * for scheduling significant work. Use {@link #bindService bound services}
2801 * for high frequency calls.
2802 * </p>
2803 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002804 * @param service Identifies the service to be started. The Intent must be
2805 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 * may be included in the Intent extras to supply arguments along with
2807 * this specific start call.
2808 *
2809 * @return If the service is being started or is already running, the
2810 * {@link ComponentName} of the actual service that was started is
2811 * returned; else if the service does not exist null is returned.
2812 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002813 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002814 * or the service can not be found.
2815 * @throws IllegalStateException If the application is in a state where the service
2816 * 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 -08002817 *
2818 * @see #stopService
2819 * @see #bindService
2820 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002821 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002822 public abstract ComponentName startService(Intent service);
2823
2824 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002825 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002826 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2827 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002828 * an amount of time comparable to the ANR interval to do this, otherwise the system
2829 * will automatically stop the service and declare the app ANR.
2830 *
2831 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2832 * at any time, regardless of whether the app hosting the service is in a foreground
2833 * state.
2834 *
2835 * @param service Identifies the service to be started. The Intent must be
2836 * fully explicit (supplying a component name). Additional values
2837 * may be included in the Intent extras to supply arguments along with
2838 * this specific start call.
2839 *
2840 * @return If the service is being started or is already running, the
2841 * {@link ComponentName} of the actual service that was started is
2842 * returned; else if the service does not exist null is returned.
2843 *
2844 * @throws SecurityException If the caller does not have permission to access the service
2845 * or the service can not be found.
2846 *
2847 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002848 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002849 */
2850 @Nullable
2851 public abstract ComponentName startForegroundService(Intent service);
2852
2853 /**
2854 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2855 */
2856 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002857 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002858 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2859
2860 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002861 * Request that a given application service be stopped. If the service is
2862 * not running, nothing happens. Otherwise it is stopped. Note that calls
2863 * to startService() are not counted -- this stops the service no matter
2864 * how many times it was started.
2865 *
2866 * <p>Note that if a stopped service still has {@link ServiceConnection}
2867 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2868 * not be destroyed until all of these bindings are removed. See
2869 * the {@link android.app.Service} documentation for more details on a
2870 * service's lifecycle.
2871 *
2872 * <p>This function will throw {@link SecurityException} if you do not
2873 * have permission to stop the given service.
2874 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002875 * @param service Description of the service to be stopped. The Intent must be either
2876 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07002877 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 *
2879 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002880 * 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 -08002881 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002882 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002883 * or the service can not be found.
2884 * @throws IllegalStateException If the application is in a state where the service
2885 * 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 -08002886 *
2887 * @see #startService
2888 */
2889 public abstract boolean stopService(Intent service);
2890
2891 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002892 * @hide like {@link #startService(Intent)} but for a specific user.
2893 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002894 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002895 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002896 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002897 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2898
2899 /**
2900 * @hide like {@link #stopService(Intent)} but for a specific user.
2901 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002902 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002903 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002904
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002905 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002906 * Connect to an application service, creating it if needed. This defines
2907 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002908 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002909 * told if it dies and restarts. The service will be considered required
2910 * by the system only for as long as the calling context exists. For
2911 * example, if this Context is an Activity that is stopped, the service will
2912 * not be required to continue running until the Activity is resumed.
2913 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002914 * <p>If the service does not support binding, it may return {@code null} from
2915 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
2916 * the ServiceConnection's
2917 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
2918 * will be invoked instead of
2919 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
2920 *
2921 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 * have permission to bind to the given service.
2923 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002924 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002926 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 * {@link #startService} with the arguments containing the command to be
2928 * sent, with the service calling its
2929 * {@link android.app.Service#stopSelf(int)} method when done executing
2930 * that command. See the API demo App/Service/Service Start Arguments
2931 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002932 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2934 * is tied to another object (the one that registered it).</p>
2935 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002936 * @param service Identifies the service to connect to. The Intent must
2937 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002939 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002940 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002941 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2942 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
Dianne Hackborn27b4d942018-11-12 15:01:40 -08002943 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
2944 * {@link #BIND_IMPORTANT}, or
2945 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07002946 * @return {@code true} if the system is in the process of bringing up a
2947 * service that your client has permission to bind to; {@code false}
2948 * if the system couldn't find the service or if your client doesn't
2949 * have permission to bind to it. If this value is {@code true}, you
2950 * should later call {@link #unbindService} to release the
2951 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002953 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002954 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 *
2956 * @see #unbindService
2957 * @see #startService
2958 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002959 * @see #BIND_DEBUG_UNBIND
2960 * @see #BIND_NOT_FOREGROUND
Dianne Hackborn27b4d942018-11-12 15:01:40 -08002961 * @see #BIND_ABOVE_CLIENT
2962 * @see #BIND_ALLOW_OOM_MANAGEMENT
2963 * @see #BIND_WAIVE_PRIORITY
2964 * @see #BIND_IMPORTANT
2965 * @see #BIND_ADJUST_WITH_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002967 public abstract boolean bindService(@RequiresPermission Intent service,
2968 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002969
2970 /**
Bo Liu58a57662019-03-06 20:21:45 +00002971 * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control
2972 * ServiceConnection callbacks.
2973 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
2974 * instance for the same instance of ServiceConnection.
2975 */
2976 public boolean bindService(@RequiresPermission @NonNull Intent service,
2977 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
2978 @NonNull ServiceConnection conn) {
2979 throw new RuntimeException("Not implemented. Must override in a subclass.");
2980 }
2981
2982 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08002983 * Variation of {@link #bindService} that, in the specific case of isolated
2984 * services, allows the caller to generate multiple instances of a service
2985 * from a single component declaration.
2986 *
2987 * @param service Identifies the service to connect to. The Intent must
2988 * specify an explicit component name.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08002989 * @param flags Operation options for the binding as per {@link #bindService}.
2990 * @param instanceName Unique identifier for the service instance. Each unique
2991 * name here will result in a different service instance being created.
2992 * @return Returns success of binding as per {@link #bindService}.
Bo Liu58a57662019-03-06 20:21:45 +00002993 * @param executor Callbacks on ServiceConnection will be called on executor.
2994 * Must use same instance for the same instance of ServiceConnection.
2995 * @param conn Receives information as the service is started and stopped.
2996 * This must be a valid ServiceConnection object; it must not be null.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08002997 *
2998 * @throws SecurityException If the caller does not have permission to access the service
2999 *
3000 * @see #bindService
3001 */
Adrian Roosebc927c2019-02-28 16:21:18 +01003002 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
Bo Liu58a57662019-03-06 20:21:45 +00003003 @BindServiceFlags int flags, @NonNull String instanceName,
3004 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003005 throw new RuntimeException("Not implemented. Must override in a subclass.");
3006 }
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003007
3008 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003009 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003010 * argument for use by system server and other multi-user aware code.
3011 * @hide
3012 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07003013 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08003014 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003015 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07003016 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08003017 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003018 throw new RuntimeException("Not implemented. Must override in a subclass.");
3019 }
3020
3021 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003022 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
Adrian Roos691546e2016-02-09 10:13:41 -08003023 * explicit non-null Handler to run the ServiceConnection callbacks on.
3024 *
3025 * @hide
3026 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003027 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003028 @UnsupportedAppUsage
Adrian Roos691546e2016-02-09 10:13:41 -08003029 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3030 Handler handler, UserHandle user) {
3031 throw new RuntimeException("Not implemented. Must override in a subclass.");
3032 }
3033
3034 /**
Dianne Hackborna631d562018-11-20 15:58:15 -08003035 * For a service previously bound with {@link #bindService} or a related method, change
3036 * how the system manages that service's process in relation to other processes. This
3037 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3038 * how the process will be managed in some cases based on those flags. Currently only
3039 * works on isolated processes (will be ignored for non-isolated processes).
3040 *
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -08003041 * <p>Note that this call does not take immediate effect, but will be applied the next
3042 * time the impacted process is adjusted for some other reason. Typically you would
3043 * call this before then calling a new {@link #bindIsolatedService} on the service
3044 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3045 *
Dianne Hackborna631d562018-11-20 15:58:15 -08003046 * @param conn The connection interface previously supplied to bindService(). This
3047 * parameter must not be null.
3048 * @param group A group to put this connection's process in. Upon calling here, this
3049 * will override any previous group that was set for that process. The group
3050 * tells the system about processes that are logically grouped together, so
3051 * should be managed as one unit of importance (such as when being considered
3052 * a recently used app). All processes in the same app with the same group
3053 * are considered to be related. Supplying 0 reverts to the default behavior
3054 * of not grouping.
3055 * @param importance Additional importance of the processes within a group. Upon calling
3056 * here, this will override any previous group that was set for that
3057 * process. This fine-tunes process killing of all processes within
3058 * a related groups -- higher importance values will be killed before
3059 * lower ones.
3060 */
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003061 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3062 int importance) {
3063 throw new RuntimeException("Not implemented. Must override in a subclass.");
3064 }
Dianne Hackborna631d562018-11-20 15:58:15 -08003065
3066 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003067 * Disconnect from an application service. You will no longer receive
3068 * calls as the service is restarted, and the service is now allowed to
3069 * stop at any time.
3070 *
3071 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07003072 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 *
3074 * @see #bindService
3075 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003076 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003077
3078 /**
3079 * Start executing an {@link android.app.Instrumentation} class. The given
3080 * Instrumentation component will be run by killing its target application
3081 * (if currently running), starting the target process, instantiating the
3082 * instrumentation component, and then letting it drive the application.
3083 *
3084 * <p>This function is not synchronous -- it returns as soon as the
3085 * instrumentation has started and while it is running.
3086 *
3087 * <p>Instrumentation is normally only allowed to run against a package
3088 * that is either unsigned or signed with a signature that the
3089 * the instrumentation package is also signed with (ensuring the target
3090 * trusts the instrumentation).
3091 *
3092 * @param className Name of the Instrumentation component to be run.
3093 * @param profileFile Optional path to write profiling data as the
3094 * instrumentation runs, or null for no profiling.
3095 * @param arguments Additional optional arguments to pass to the
3096 * instrumentation, or null.
3097 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003098 * @return {@code true} if the instrumentation was successfully started,
3099 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003100 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003101 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3102 @Nullable String profileFile, @Nullable Bundle arguments);
3103
3104 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07003105 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07003106 POWER_SERVICE,
3107 WINDOW_SERVICE,
3108 LAYOUT_INFLATER_SERVICE,
3109 ACCOUNT_SERVICE,
3110 ACTIVITY_SERVICE,
3111 ALARM_SERVICE,
3112 NOTIFICATION_SERVICE,
3113 ACCESSIBILITY_SERVICE,
3114 CAPTIONING_SERVICE,
3115 KEYGUARD_SERVICE,
3116 LOCATION_SERVICE,
3117 //@hide: COUNTRY_DETECTOR,
3118 SEARCH_SERVICE,
3119 SENSOR_SERVICE,
Chad Brubaker90f391f2018-10-19 10:26:19 -07003120 SENSOR_PRIVACY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003121 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003122 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003123 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003124 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003125 VIBRATOR_SERVICE,
3126 //@hide: STATUS_BAR_SERVICE,
3127 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003128 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003129 IPSEC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003130 //@hide: UPDATE_LOCK_SERVICE,
3131 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003132 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003133 //@hide: NETWORK_POLICY_SERVICE,
3134 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003135 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003136 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003137 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003138 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003139 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003140 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003141 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003142 NSD_SERVICE,
3143 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003144 FINGERPRINT_SERVICE,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003145 //@hide: FACE_SERVICE,
Kevin Chyn05c21502018-09-18 13:07:19 -07003146 BIOMETRIC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003147 MEDIA_ROUTER_SERVICE,
3148 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003149 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003150 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003151 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003152 CLIPBOARD_SERVICE,
3153 INPUT_METHOD_SERVICE,
3154 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003155 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003156 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003157 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003158 //@hide: BACKUP_SERVICE,
Richard Uhlerb29f1452018-09-12 16:38:15 +01003159 ROLLBACK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003160 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003161 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003162 DEVICE_POLICY_SERVICE,
3163 UI_MODE_SERVICE,
3164 DOWNLOAD_SERVICE,
3165 NFC_SERVICE,
3166 BLUETOOTH_SERVICE,
3167 //@hide: SIP_SERVICE,
3168 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003169 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003170 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003171 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003172 INPUT_SERVICE,
3173 DISPLAY_SERVICE,
Christine Franks39b03112018-07-03 14:46:07 -07003174 //@hide COLOR_DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003175 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003176 RESTRICTIONS_SERVICE,
3177 APP_OPS_SERVICE,
Hai Zhangb7776682018-09-25 15:10:57 -07003178 ROLE_SERVICE,
Hai Zhanga4959e52019-03-06 12:21:07 -08003179 //@hide ROLE_CONTROLLER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003180 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003181 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003182 CONSUMER_IR_SERVICE,
3183 //@hide: TRUST_SERVICE,
3184 TV_INPUT_SERVICE,
3185 //@hide: NETWORK_SCORE_SERVICE,
3186 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003187 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003188 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003189 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003190 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003191 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003192 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003193 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003194 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003195 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003196 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003197 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003198 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003199 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003200 //@hide: INCIDENT_SERVICE,
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08003201 //@hide: INCIDENT_COMPANION_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003202 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003203 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003204 CROSS_PROFILE_APPS_SERVICE,
3205 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerfeeee682018-05-30 14:35:24 +01003206 //@hide: TIME_DETECTOR_SERVICE,
Philip P. Moltmann039678e2018-09-18 13:04:38 -07003207 PERMISSION_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003208 })
3209 @Retention(RetentionPolicy.SOURCE)
3210 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211
3212 /**
3213 * Return the handle to a system-level service by name. The class of the
3214 * returned object varies by the requested name. Currently available names
3215 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003216 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003217 * <dl>
3218 * <dt> {@link #WINDOW_SERVICE} ("window")
3219 * <dd> The top-level window manager in which you can place custom
3220 * windows. The returned object is a {@link android.view.WindowManager}.
3221 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3222 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3223 * in this context.
3224 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3225 * <dd> A {@link android.app.ActivityManager} for interacting with the
3226 * global activity state of the system.
3227 * <dt> {@link #POWER_SERVICE} ("power")
3228 * <dd> A {@link android.os.PowerManager} for controlling power
3229 * management.
3230 * <dt> {@link #ALARM_SERVICE} ("alarm")
3231 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3232 * time of your choosing.
3233 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3234 * <dd> A {@link android.app.NotificationManager} for informing the user
3235 * of background events.
3236 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3237 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3238 * <dt> {@link #LOCATION_SERVICE} ("location")
3239 * <dd> A {@link android.location.LocationManager} for controlling location
3240 * (e.g., GPS) updates.
3241 * <dt> {@link #SEARCH_SERVICE} ("search")
3242 * <dd> A {@link android.app.SearchManager} for handling search.
3243 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3244 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3245 * hardware.
3246 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3247 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3248 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003249 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3250 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3251 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003252 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003253 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3254 * connectivity. On releases before NYC, it should only be obtained from an application
3255 * context, and not from any other derived context to avoid memory leaks within the calling
3256 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003257 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3258 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3259 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003260 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3261 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3262 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3264 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3265 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003266 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3267 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003268 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003269 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003270 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003271 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003272 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3273 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003274 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3275 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3276 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003277 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003278 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003280 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003281 * <p>Note: System services obtained via this API may be closely associated with
3282 * the Context in which they are obtained from. In general, do not share the
3283 * service objects between various different contexts (Activities, Applications,
3284 * Services, Providers, etc.)
3285 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003286 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3287 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003288 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3289 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3290 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3291 * return <code>null</code>. Generally, if you are running as an instant app you should always
3292 * check whether the result of this method is null.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003293 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003294 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003295 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003297 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003298 * @see #WINDOW_SERVICE
3299 * @see android.view.WindowManager
3300 * @see #LAYOUT_INFLATER_SERVICE
3301 * @see android.view.LayoutInflater
3302 * @see #ACTIVITY_SERVICE
3303 * @see android.app.ActivityManager
3304 * @see #POWER_SERVICE
3305 * @see android.os.PowerManager
3306 * @see #ALARM_SERVICE
3307 * @see android.app.AlarmManager
3308 * @see #NOTIFICATION_SERVICE
3309 * @see android.app.NotificationManager
3310 * @see #KEYGUARD_SERVICE
3311 * @see android.app.KeyguardManager
3312 * @see #LOCATION_SERVICE
3313 * @see android.location.LocationManager
3314 * @see #SEARCH_SERVICE
3315 * @see android.app.SearchManager
3316 * @see #SENSOR_SERVICE
3317 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003318 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003319 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 * @see #VIBRATOR_SERVICE
3321 * @see android.os.Vibrator
3322 * @see #CONNECTIVITY_SERVICE
3323 * @see android.net.ConnectivityManager
3324 * @see #WIFI_SERVICE
3325 * @see android.net.wifi.WifiManager
3326 * @see #AUDIO_SERVICE
3327 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003328 * @see #MEDIA_ROUTER_SERVICE
3329 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 * @see #TELEPHONY_SERVICE
3331 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003332 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3333 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003334 * @see #CARRIER_CONFIG_SERVICE
3335 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 * @see #INPUT_METHOD_SERVICE
3337 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003338 * @see #UI_MODE_SERVICE
3339 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003340 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003341 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003342 * @see #BATTERY_SERVICE
3343 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003344 * @see #JOB_SCHEDULER_SERVICE
3345 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003346 * @see #NETWORK_STATS_SERVICE
3347 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003348 * @see android.os.HardwarePropertiesManager
3349 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003351 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352
3353 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003354 * Return the handle to a system-level service by class.
3355 * <p>
3356 * Currently available classes are:
3357 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3358 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3359 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3360 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3361 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3362 * {@link android.net.ConnectivityManager},
3363 * {@link android.net.wifi.WifiManager},
3364 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3365 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3366 * {@link android.view.inputmethod.InputMethodManager},
3367 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003368 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3369 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08003370 * </p><p>
3371 * Note: System services obtained via this API may be closely associated with
3372 * the Context in which they are obtained from. In general, do not share the
3373 * service objects between various different contexts (Activities, Applications,
3374 * Services, Providers, etc.)
3375 * </p>
3376 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003377 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3378 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003379 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3380 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3381 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3382 * return <code>null</code>. Generally, if you are running as an instant app you should always
3383 * check whether the result of this method is null.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003384 *
Jeff Brown6e539312015-02-24 18:53:21 -08003385 * @param serviceClass The class of the desired service.
3386 * @return The service or null if the class is not a supported system service.
3387 */
3388 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003389 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003390 // Because subclasses may override getSystemService(String) we cannot
3391 // perform a lookup by class alone. We must first map the class to its
3392 // service name then invoke the string-based method.
3393 String serviceName = getSystemServiceName(serviceClass);
3394 return serviceName != null ? (T)getSystemService(serviceName) : null;
3395 }
3396
3397 /**
3398 * Gets the name of the system-level service that is represented by the specified class.
3399 *
3400 * @param serviceClass The class of the desired service.
3401 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003402 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003403 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003404
3405 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003406 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003407 * {@link android.os.PowerManager} for controlling power management,
3408 * including "wake locks," which let you keep the device on while
3409 * you're running long tasks.
3410 */
3411 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003412
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003413 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003414 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003415 * {@link android.os.RecoverySystem} for accessing the recovery system
3416 * service.
3417 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003418 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003419 * @hide
3420 */
3421 public static final String RECOVERY_SERVICE = "recovery";
3422
3423 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003424 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003425 * {@link android.os.SystemUpdateManager} for accessing the system update
3426 * manager service.
3427 *
3428 * @see #getSystemService(String)
3429 * @hide
3430 */
3431 @SystemApi
3432 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3433
3434 /**
3435 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 * {@link android.view.WindowManager} for accessing the system's window
3437 * manager.
3438 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003439 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 * @see android.view.WindowManager
3441 */
3442 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003445 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 * {@link android.view.LayoutInflater} for inflating layout resources in this
3447 * context.
3448 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003449 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 * @see android.view.LayoutInflater
3451 */
3452 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003453
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003455 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003456 * {@link android.accounts.AccountManager} for receiving intents at a
3457 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003458 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003459 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003460 * @see android.accounts.AccountManager
3461 */
3462 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003463
Fred Quintana60307342009-03-24 22:48:12 -07003464 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003465 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 * {@link android.app.ActivityManager} for interacting with the global
3467 * system state.
3468 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003469 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 * @see android.app.ActivityManager
3471 */
3472 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003475 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale65ebd952018-04-25 15:41:44 -07003476 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
3477 *
3478 * @see #getSystemService(String)
3479 * @see android.app.ActivityTaskManager
3480 * @hide
3481 */
3482 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
3483
3484 /**
3485 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07003486 * {@link android.app.UriGrantsManager} for interacting with the global system state.
3487 *
3488 * @see #getSystemService(String)
3489 * @see android.app.UriGrantsManager
3490 * @hide
3491 */
3492 public static final String URI_GRANTS_SERVICE = "uri_grants";
3493
3494 /**
3495 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003496 * {@link android.app.AlarmManager} for receiving intents at a
3497 * time of your choosing.
3498 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003499 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003500 * @see android.app.AlarmManager
3501 */
3502 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003504 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003505 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003506 * {@link android.app.NotificationManager} for informing the user of
3507 * background events.
3508 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003509 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 * @see android.app.NotificationManager
3511 */
3512 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003513
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003515 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003516 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3517 * feedback for UI events through the registered event listeners.
3518 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003519 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003520 * @see android.view.accessibility.AccessibilityManager
3521 */
3522 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003523
svetoslavganov75986cf2009-05-14 22:28:01 -07003524 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003525 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003526 * {@link android.view.accessibility.CaptioningManager} for obtaining
3527 * captioning properties and listening for changes in captioning
3528 * preferences.
3529 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003530 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003531 * @see android.view.accessibility.CaptioningManager
3532 */
3533 public static final String CAPTIONING_SERVICE = "captioning";
3534
3535 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003536 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003537 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003538 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003539 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 * @see android.app.KeyguardManager
3541 */
3542 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003543
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003545 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003546 * android.location.LocationManager} for controlling location
3547 * updates.
3548 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003549 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 * @see android.location.LocationManager
3551 */
3552 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003553
3554 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003555 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003556 * {@link android.location.CountryDetector} for detecting the country that
3557 * the user is in.
3558 *
3559 * @hide
3560 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01003561 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003562 public static final String COUNTRY_DETECTOR = "country_detector";
3563
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003564 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003565 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003566 * android.app.SearchManager} for handling searches.
3567 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003568 * <p>
3569 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3570 * {@link android.app.SearchManager}.
3571 *
3572 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003573 * @see android.app.SearchManager
3574 */
3575 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003577 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003578 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 * android.hardware.SensorManager} for accessing sensors.
3580 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003581 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 * @see android.hardware.SensorManager
3583 */
3584 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003587 * Use with {@link #getSystemService(String)} to retrieve a {@link
Chad Brubaker90f391f2018-10-19 10:26:19 -07003588 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
3589 * functions.
3590 *
3591 * @see #getSystemService(String)
3592 * @see android.hardware.SensorPrivacyManager
3593 *
3594 * @hide
3595 */
3596 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
3597
3598 /**
3599 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003600 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003601 * functions.
3602 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003603 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003604 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003605 */
3606 public static final String STORAGE_SERVICE = "storage";
3607
3608 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003609 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003610 * android.app.usage.StorageStatsManager} for accessing system storage
3611 * statistics.
3612 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003613 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003614 * @see android.app.usage.StorageStatsManager
3615 */
3616 public static final String STORAGE_STATS_SERVICE = "storagestats";
3617
3618 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003619 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 * com.android.server.WallpaperService for accessing wallpapers.
3621 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003622 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 */
3624 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003626 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003627 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 * android.os.Vibrator} for interacting with the vibration hardware.
3629 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003630 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003631 * @see android.os.Vibrator
3632 */
3633 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003634
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003635 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003636 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003637 * android.app.StatusBarManager} for interacting with the status bar.
3638 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003639 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 * @see android.app.StatusBarManager
Evan Lairdedd016f2019-01-23 18:36:29 -05003641 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 * @hide
3643 */
Evan Lairdedd016f2019-01-23 18:36:29 -05003644 @SystemApi
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 public static final String STATUS_BAR_SERVICE = "statusbar";
3646
3647 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003648 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 * android.net.ConnectivityManager} for handling management of
3650 * network connections.
3651 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003652 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 * @see android.net.ConnectivityManager
3654 */
3655 public static final String CONNECTIVITY_SERVICE = "connectivity";
3656
3657 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003658 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003659 * {@link android.net.INetd} for communicating with the network stack
3660 * @hide
3661 * @see #getSystemService(String)
3662 * @hide
3663 */
3664 @SystemApi
3665 public static final String NETD_SERVICE = "netd";
3666
3667 /**
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003668 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3669 * {@link NetworkStackClient} IBinder for communicating with the network stack
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003670 * @hide
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003671 * @see NetworkStackClient
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003672 */
3673 public static final String NETWORK_STACK_SERVICE = "network_stack";
3674
3675 /**
3676 * Use with {@link #getSystemService(String)} to retrieve a
Chalard Jean8c141bd2018-12-04 20:20:56 +09003677 * {@link android.net.IpMemoryStore} to store and read information about
3678 * known networks.
3679 * @hide
3680 */
3681 public static final String IP_MEMORY_STORE_SERVICE = "ipmemorystore";
3682
3683 /**
3684 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003685 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3686 * IPSec.
3687 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003688 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003689 */
3690 public static final String IPSEC_SERVICE = "ipsec";
3691
3692 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003693 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003694 * android.os.IUpdateLock} for managing runtime sequences that
3695 * must not be interrupted by headless OTA application or similar.
3696 *
3697 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003698 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003699 * @see android.os.UpdateLock
3700 */
3701 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3702
3703 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003704 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003705 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003706 */
3707 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3708
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003709 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003710 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003711 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3712 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003713 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003714 */
3715 public static final String SLICE_SERVICE = "slice";
3716
3717 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003718 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003719 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3720 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003721 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003722 * @see android.app.usage.NetworkStatsManager
3723 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003724 public static final String NETWORK_STATS_SERVICE = "netstats";
3725 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003726 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003727 /** {@hide} */
3728 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003729
San Mehatd1df8ac2010-01-26 06:17:26 -08003730 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003731 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003732 * android.net.wifi.WifiManager} for handling management of
3733 * Wi-Fi access.
3734 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003735 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003736 * @see android.net.wifi.WifiManager
3737 */
3738 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003739
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003740 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003741 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003742 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003743 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003744 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003745 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003746 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003747 */
3748 public static final String WIFI_P2P_SERVICE = "wifip2p";
3749
3750 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003751 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003752 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3753 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003754 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003755 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003756 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003757 */
Etan Cohen04133272016-10-26 11:22:06 -07003758 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003759
3760 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003761 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003762 * android.net.wifi.WifiScanner} for scanning the wifi universe
3763 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003764 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003765 * @see android.net.wifi.WifiScanner
3766 * @hide
3767 */
Wei Wang35d552f2014-07-08 21:37:01 -07003768 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003769 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3770
3771 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003772 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003773 * android.net.wifi.RttManager} for ranging devices with wifi
3774 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003775 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003776 * @see android.net.wifi.RttManager
3777 * @hide
3778 */
3779 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08003780 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07003781 public static final String WIFI_RTT_SERVICE = "rttmanager";
3782
3783 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003784 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohen17ba4722017-08-21 10:52:17 -07003785 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi
3786 *
3787 * Note: this is a replacement for WIFI_RTT_SERVICE above. It will
3788 * be renamed once final implementation in place.
3789 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003790 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003791 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003792 */
Etan Cohen091d7772018-01-04 17:47:37 -08003793 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003794
3795 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003796 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003797 * android.net.lowpan.LowpanManager} for handling management of
3798 * LoWPAN access.
3799 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003800 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003801 * @see android.net.lowpan.LowpanManager
3802 *
3803 * @hide
3804 */
3805 public static final String LOWPAN_SERVICE = "lowpan";
3806
3807 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003808 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003809 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003810 * Ethernet access.
3811 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003812 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003813 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003814 *
3815 * @hide
3816 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003817 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003818 public static final String ETHERNET_SERVICE = "ethernet";
3819
3820 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003821 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003822 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003823 * discovery
3824 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003825 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003826 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003827 */
3828 public static final String NSD_SERVICE = "servicediscovery";
3829
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003830 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003831 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 * {@link android.media.AudioManager} for handling management of volume,
3833 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003834 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003835 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003836 * @see android.media.AudioManager
3837 */
3838 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003840 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003841 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003842 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003843 * of fingerprints.
3844 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003845 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07003846 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003847 */
3848 public static final String FINGERPRINT_SERVICE = "fingerprint";
3849
3850 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003851 * Use with {@link #getSystemService(String)} to retrieve a
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003852 * {@link android.hardware.face.FaceManager} for handling management
3853 * of face authentication.
3854 *
3855 * @hide
3856 * @see #getSystemService
3857 * @see android.hardware.face.FaceManager
3858 */
3859 public static final String FACE_SERVICE = "face";
3860
3861 /**
Kevin Chyn05c21502018-09-18 13:07:19 -07003862 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn51676d22018-11-05 18:00:43 -08003863 * {@link android.hardware.iris.IrisManager} for handling management
3864 * of iris authentication.
3865 *
3866 * @hide
3867 * @see #getSystemService
3868 * @see android.hardware.iris.IrisManager
3869 */
3870 public static final String IRIS_SERVICE = "iris";
3871
3872 /**
3873 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn05c21502018-09-18 13:07:19 -07003874 * {@link android.hardware.biometrics.BiometricManager} for handling management
3875 * of face authentication.
3876 *
3877 * @see #getSystemService
3878 * @see android.hardware.biometrics.BiometricManager
3879 */
3880 public static final String BIOMETRIC_SERVICE = "biometric";
3881
3882 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003883 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003884 * {@link android.media.MediaRouter} for controlling and managing
3885 * routing of media.
3886 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003887 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003888 * @see android.media.MediaRouter
3889 */
3890 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3891
3892 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003893 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003894 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003895 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003896 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07003897 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003898 */
3899 public static final String MEDIA_SESSION_SERVICE = "media_session";
3900
3901 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003902 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003903 * {@link android.telephony.TelephonyManager} for handling management the
3904 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003905 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003906 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003907 * @see android.telephony.TelephonyManager
3908 */
3909 public static final String TELEPHONY_SERVICE = "phone";
3910
3911 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003912 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003913 * {@link android.telephony.SubscriptionManager} for handling management the
3914 * telephony subscriptions of the device.
3915 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003916 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08003917 * @see android.telephony.SubscriptionManager
3918 */
3919 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3920
3921 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003922 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003923 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003924 * of the device.
3925 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003926 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003927 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003928 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003929 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003930
3931 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003932 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003933 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3934 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003935 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003936 * @see android.telephony.CarrierConfigManager
3937 */
3938 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3939
3940 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003941 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08003942 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
3943 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003944 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08003945 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08003946 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08003947 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08003948
3949 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003950 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003951 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
3952 *
3953 * @see #getSystemService(String)
3954 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003955 * @hide
3956 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08003957 @SystemApi
3958 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003959
3960 /**
3961 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08003962 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003963 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003964 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003965 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08003966 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 */
3968 public static final String CLIPBOARD_SERVICE = "clipboard";
3969
3970 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003971 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003972 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003973 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003974 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003975 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003976 */
3977 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
3978
3979 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003980 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003981 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3982 * methods.
3983 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003984 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003985 */
3986 public static final String INPUT_METHOD_SERVICE = "input_method";
3987
3988 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003989 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09003990 * {@link android.view.textservice.TextServicesManager} for accessing
3991 * text services.
3992 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003993 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09003994 */
3995 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3996
3997 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003998 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003999 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004000 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004001 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004002 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004003 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07004004
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004005 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07004006 * Official published name of the (internal) voice interaction manager service.
4007 *
4008 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004009 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07004010 */
4011 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4012
4013 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08004014 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07004015 *
4016 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004017 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07004018 */
Felipe Leme640f30a2017-03-06 15:44:06 -08004019 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07004020
4021 /**
Felipe Leme749b8892018-12-03 16:30:30 -08004022 * Official published name of the content capture service.
Felipe Lemee348dc32018-11-05 12:35:29 -08004023 *
4024 * @hide
4025 * @see #getSystemService(String)
4026 */
Felipe Leme749b8892018-12-03 16:30:30 -08004027 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
Felipe Lemee348dc32018-11-05 12:35:29 -08004028
4029 /**
Winson Chung3fb0f252019-01-08 17:41:55 -08004030 * Used for getting content selections and classifications for task snapshots.
4031 *
4032 * @hide
4033 * @see #getSystemService(String)
4034 */
4035 @SystemApi
4036 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
4037
4038 /**
Sunny Goyal54e91342018-11-14 11:59:02 -08004039 * Official published name of the app prediction service.
4040 *
4041 * @hide
4042 * @see #getSystemService(String)
4043 */
4044 @SystemApi
4045 public static final String APP_PREDICTION_SERVICE = "app_prediction";
4046
4047 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004048 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004049 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
4050 *
4051 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004052 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004053 */
4054 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
4055
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004056 /**
4057 * Official published name of the (internal) permission service.
4058 *
4059 * @see #getSystemService(String)
4060 * @hide
4061 */
4062 @SystemApi
4063 public static final String PERMISSION_SERVICE = "permission";
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004064
4065 /**
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08004066 * Official published name of the (internal) permission controller service.
4067 *
4068 * @see #getSystemService(String)
4069 * @hide
4070 */
4071 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
4072
4073 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004074 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08004075 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07004076 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07004077 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07004078 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004079 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07004080 */
Christopher Tated5cf7222014-07-29 16:53:09 -07004081 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07004082 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07004083
4084 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +01004085 * Use with {@link #getSystemService(String)} to retrieve an
4086 * {@link android.content.rollback.RollbackManager} for communicating
4087 * with the rollback manager
4088 *
4089 * @see #getSystemService(String)
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004090 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +01004091 */
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004092 @SystemApi
Richard Uhlerb29f1452018-09-12 16:38:15 +01004093 public static final String ROLLBACK_SERVICE = "rollback";
4094
4095 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004096 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08004097 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07004098 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004099 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07004100 */
4101 public static final String DROPBOX_SERVICE = "dropbox";
4102
Christopher Tate487529a2009-04-29 14:03:25 -07004103 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07004104 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004105 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004106 * @hide
4107 */
4108 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
4109
4110 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004111 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08004112 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08004113 * device policy management.
4114 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004115 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08004116 */
4117 public static final String DEVICE_POLICY_SERVICE = "device_policy";
4118
4119 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004120 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08004121 * {@link android.app.UiModeManager} for controlling UI modes.
4122 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004123 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08004124 */
4125 public static final String UI_MODE_SERVICE = "uimode";
4126
4127 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004128 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07004129 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07004130 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004131 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07004132 */
4133 public static final String DOWNLOAD_SERVICE = "download";
4134
4135 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004136 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08004137 * {@link android.os.BatteryManager} for managing battery state.
4138 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004139 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08004140 */
4141 public static final String BATTERY_SERVICE = "batterymanager";
4142
4143 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004144 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004145 * {@link android.nfc.NfcManager} for using NFC.
4146 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004147 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004148 */
4149 public static final String NFC_SERVICE = "nfc";
4150
4151 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004152 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00004153 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004154 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004155 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004156 */
4157 public static final String BLUETOOTH_SERVICE = "bluetooth";
4158
4159 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004160 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08004161 * {@link android.net.sip.SipManager} for accessing the SIP related service.
4162 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004163 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08004164 */
4165 /** @hide */
4166 public static final String SIP_SERVICE = "sip";
4167
4168 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004169 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08004170 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004171 * and for controlling this device's behavior as a USB device.
4172 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004173 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04004174 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004175 */
4176 public static final String USB_SERVICE = "usb";
4177
4178 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004179 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Rootf74bfde2018-01-18 15:42:48 -08004180 * Use with {@link #getSystemService} to retrieve a {@link
4181 * android.debug.AdbManager} for access to ADB debug functions.
4182 *
4183 * @see #getSystemService(String)
4184 * @see android.debug.AdbManager
4185 *
4186 * @hide
4187 */
4188 public static final String ADB_SERVICE = "adb";
4189
4190 /**
4191 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004192 * android.hardware.SerialManager} for access to serial ports.
4193 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004194 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004195 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004196 *
4197 * @hide
4198 */
4199 public static final String SERIAL_SERVICE = "serial";
4200
4201 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004202 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09004203 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
4204 * HDMI-CEC protocol.
4205 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004206 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09004207 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004208 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09004209 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004210 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09004211 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09004212
4213 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004214 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004215 * {@link android.hardware.input.InputManager} for interacting with input devices.
4216 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004217 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004218 * @see android.hardware.input.InputManager
4219 */
4220 public static final String INPUT_SERVICE = "input";
4221
4222 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004223 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07004224 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
4225 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004226 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07004227 * @see android.hardware.display.DisplayManager
4228 */
4229 public static final String DISPLAY_SERVICE = "display";
4230
4231 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004232 * Use with {@link #getSystemService(String)} to retrieve a
Christine Franks39b03112018-07-03 14:46:07 -07004233 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
4234 *
4235 * @see #getSystemService(String)
4236 * @see android.hardware.display.ColorDisplayManager
4237 * @hide
4238 */
4239 public static final String COLOR_DISPLAY_SERVICE = "color_display";
4240
4241 /**
4242 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07004243 * {@link android.os.UserManager} for managing users on devices that support multiple users.
4244 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004245 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07004246 * @see android.os.UserManager
4247 */
4248 public static final String USER_SERVICE = "user";
4249
4250 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004251 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08004252 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
4253 * profiles of a user.
4254 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004255 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08004256 * @see android.content.pm.LauncherApps
4257 */
4258 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4259
4260 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004261 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004262 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4263 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004264 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004265 * @see android.content.RestrictionsManager
4266 */
4267 public static final String RESTRICTIONS_SERVICE = "restrictions";
4268
4269 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004270 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004271 * {@link android.app.AppOpsManager} for tracking application operations
4272 * on the device.
4273 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004274 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004275 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004276 */
4277 public static final String APP_OPS_SERVICE = "appops";
4278
4279 /**
Hai Zhangb7776682018-09-25 15:10:57 -07004280 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
4281 * for managing roles.
4282 *
4283 * @see #getSystemService(String)
4284 * @see android.app.role.RoleManager
4285 */
4286 public static final String ROLE_SERVICE = "role";
4287
4288 /**
Hai Zhanga4959e52019-03-06 12:21:07 -08004289 * Official published name of the (internal) role controller service.
4290 *
4291 * @see #getSystemService(String)
4292 * @see android.app.role.RoleControllerService
4293 *
4294 * @hide
4295 */
4296 public static final String ROLE_CONTROLLER_SERVICE = "role_controller";
4297
4298 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004299 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004300 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004301 * camera devices.
4302 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004303 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004304 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004305 */
4306 public static final String CAMERA_SERVICE = "camera";
4307
4308 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004309 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004310 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004311 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004312 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004313 * @see android.print.PrintManager
4314 */
4315 public static final String PRINT_SERVICE = "print";
4316
4317 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004318 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004319 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4320 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004321 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004322 * @see android.companion.CompanionDeviceManager
4323 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004324 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004325
4326 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004327 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004328 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4329 * signals from the device.
4330 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004331 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004332 * @see android.hardware.ConsumerIrManager
4333 */
4334 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4335
4336 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004337 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004338 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004339 * @see android.app.trust.TrustManager
4340 * @hide
4341 */
4342 public static final String TRUST_SERVICE = "trust";
4343
4344 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004345 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004346 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4347 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004348 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004349 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004350 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004351 */
4352 public static final String TV_INPUT_SERVICE = "tv_input";
4353
4354 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004355 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004356 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004357 * @see android.net.NetworkScoreManager
4358 * @hide
4359 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004360 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004361 public static final String NETWORK_SCORE_SERVICE = "network_score";
4362
4363 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004364 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004365 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004366 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004367 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004368 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004369 */
4370 public static final String USAGE_STATS_SERVICE = "usagestats";
4371
4372 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004373 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004374 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004375 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004376 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004377 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004378 */
Christopher Tate7060b042014-06-09 19:50:00 -07004379 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004380
4381 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004382 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004383 * android.service.persistentdata.PersistentDataBlockManager} instance
4384 * for interacting with a storage device that lives across factory resets.
4385 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004386 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004387 * @see android.service.persistentdata.PersistentDataBlockManager
4388 * @hide
4389 */
Andres Morales33df9372014-09-26 17:08:59 -07004390 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004391 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4392
4393 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004394 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004395 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4396 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004397 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004398 * @see android.service.oemlock.OemLockManager
4399 * @hide
4400 */
4401 @SystemApi
4402 public static final String OEM_LOCK_SERVICE = "oem_lock";
4403
4404 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004405 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004406 * android.media.projection.MediaProjectionManager} instance for managing
4407 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004408 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004409 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004410 */
4411 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4412
4413 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004414 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004415 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004416 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004417 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004418 */
4419 public static final String MIDI_SERVICE = "midi";
4420
Eric Laurent2035ac82015-03-05 15:18:44 -08004421
4422 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004423 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004424 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4425 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004426 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004427 * @hide
4428 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004429 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004430
Paul McLeana33be212015-02-20 07:52:45 -08004431 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004432 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004433 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4434 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004435 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004436 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004437 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004438
4439 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004440 * Use with {@link #getSystemService(String)} to retrieve a
Wei Wangbad7c202018-11-01 11:57:39 -07004441 * {@link android.os.ThermalService} for accessing the thermal service.
4442 *
4443 * @see #getSystemService(String)
4444 * @hide
4445 */
4446 public static final String THERMAL_SERVICE = "thermalservice";
4447
4448 /**
4449 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004450 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004451 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004452 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004453 * @see android.content.pm.ShortcutManager
4454 */
4455 public static final String SHORTCUT_SERVICE = "shortcut";
4456
4457 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004458 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004459 * android.hardware.location.ContextHubManager} for accessing context hubs.
4460 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004461 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004462 * @see android.hardware.location.ContextHubManager
4463 *
4464 * @hide
4465 */
4466 @SystemApi
4467 public static final String CONTEXTHUB_SERVICE = "contexthub";
4468
4469 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004470 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004471 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4472 * memory, etc) metrics.
4473 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004474 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004475 */
4476 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4477
4478 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004479 * Gatekeeper Service.
4480 * @hide
4481 */
4482 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4483
4484 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004485 * Service defining the policy for access to device identifiers.
4486 * @hide
4487 */
4488 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4489
4490 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004491 * Service to report a system health "incident"
4492 * @hide
4493 */
4494 public static final String INCIDENT_SERVICE = "incident";
4495
4496 /**
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08004497 * Service to assist incidentd and dumpstated in reporting status to the user
4498 * and in confirming authorization to take an incident report or bugreport
4499 * @hide
4500 */
4501 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
4502
4503 /**
Bookatz94726412017-08-31 09:26:15 -07004504 * Service to assist statsd in obtaining general stats.
4505 * @hide
4506 */
4507 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4508
4509 /**
Bookatzc6977972018-01-16 16:55:05 -08004510 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004511 * @hide
4512 */
4513 @SystemApi
4514 public static final String STATS_MANAGER = "stats";
4515
4516 /**
Nandana Duttd11850c2018-12-12 17:26:57 +00004517 * Service to capture a bugreport.
4518 * @see #getSystemService(String)
4519 * @see android.os.BugreportManager
4520 * @hide
4521 */
4522 // TODO: Expose API when the implementation is more complete.
4523 // @SystemApi
4524 public static final String BUGREPORT_SERVICE = "bugreport";
4525
4526 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004527 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004528 * android.content.om.OverlayManager} for managing overlay packages.
4529 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004530 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004531 * @see android.content.om.OverlayManager
4532 * @hide
4533 */
4534 public static final String OVERLAY_SERVICE = "overlay";
4535
4536 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004537 * Use with {@link #getSystemService(String)} to retrieve a
MÃ¥rten Kongstad06a1ac82018-09-20 13:09:47 +02004538 * {android.os.IIdmap2} for managing idmap files (used by overlay
4539 * packages).
4540 *
4541 * @see #getSystemService(String)
4542 * @hide
4543 */
4544 public static final String IDMAP_SERVICE = "idmap";
4545
4546 /**
4547 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004548 * {@link VrManager} for accessing the VR service.
4549 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004550 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004551 * @hide
4552 */
4553 @SystemApi
4554 public static final String VR_SERVICE = "vrmanager";
4555
4556 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004557 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004558 * {@link android.app.timezone.ITimeZoneRulesManager}.
4559 * @hide
4560 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004561 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004562 */
4563 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4564
4565 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004566 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004567 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004568 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004569 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004570 */
4571 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4572
4573 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004574 * Use with {@link #getSystemService} to retrieve a
4575 * {@link android.se.omapi.ISecureElementService}
4576 * for accessing the SecureElementService.
4577 *
4578 * @hide
4579 */
4580 @SystemApi
4581 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4582
4583 /**
Neil Fullerfeeee682018-05-30 14:35:24 +01004584 * Use with {@link #getSystemService(String)} to retrieve an
4585 * {@link android.app.timedetector.ITimeDetectorService}.
4586 * @hide
4587 *
4588 * @see #getSystemService(String)
4589 */
4590 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4591
4592 /**
Makoto Onukidf7e4812018-09-24 14:31:25 -07004593 * Binder service name for {@link AppBindingService}.
4594 * @hide
4595 */
4596 public static final String APP_BINDING_SERVICE = "app_binding";
4597
4598 /**
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004599 * Use with {@link #getSystemService(String)} to retrieve an
Sahin Caliskan84dd3062018-12-03 14:06:39 -08004600 * {@link android.telephony.ims.RcsManager}.
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004601 * @hide
4602 */
4603 public static final String TELEPHONY_RCS_SERVICE = "ircs";
4604
Howard Chen0a947642019-01-07 14:10:44 +08004605 /**
4606 * Use with {@link #getSystemService(String)} to retrieve an
4607 * {@link android.os.DynamicAndroidManager}.
4608 * @hide
4609 */
4610 @SystemApi
4611 public static final String DYNAMIC_ANDROID_SERVICE = "dynamic_android";
4612
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004613 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004614 * Determine whether the given permission is allowed for a particular
4615 * process and user ID running in the system.
4616 *
4617 * @param permission The name of the permission being checked.
4618 * @param pid The process ID being checked against. Must be > 0.
4619 * @param uid The user ID being checked against. A uid of 0 is the root
4620 * user, which will pass every permission check.
4621 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004622 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004623 * pid/uid is allowed that permission, or
4624 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4625 *
4626 * @see PackageManager#checkPermission(String, String)
4627 * @see #checkCallingPermission
4628 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004629 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004630 @PackageManager.PermissionResult
4631 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004632
Dianne Hackbornff170242014-11-19 10:59:01 -08004633 /** @hide */
4634 @PackageManager.PermissionResult
Mathew Inwood5c0d3542018-08-14 13:54:31 +01004635 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08004636 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4637 IBinder callerToken);
4638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 /**
4640 * Determine whether the calling process of an IPC you are handling has been
4641 * granted a particular permission. This is basically the same as calling
4642 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4643 * by {@link android.os.Binder#getCallingPid} and
4644 * {@link android.os.Binder#getCallingUid}. One important difference
4645 * is that if you are not currently processing an IPC, this function
4646 * will always fail. This is done to protect against accidentally
4647 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4648 * to avoid this protection.
4649 *
4650 * @param permission The name of the permission being checked.
4651 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004652 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004653 * pid/uid is allowed that permission, or
4654 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4655 *
4656 * @see PackageManager#checkPermission(String, String)
4657 * @see #checkPermission
4658 * @see #checkCallingOrSelfPermission
4659 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004660 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004661 @PackageManager.PermissionResult
4662 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004663
4664 /**
4665 * Determine whether the calling process of an IPC <em>or you</em> have been
4666 * granted a particular permission. This is the same as
4667 * {@link #checkCallingPermission}, except it grants your own permissions
4668 * if you are not currently processing an IPC. Use with care!
4669 *
4670 * @param permission The name of the permission being checked.
4671 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004672 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004673 * pid/uid is allowed that permission, or
4674 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4675 *
4676 * @see PackageManager#checkPermission(String, String)
4677 * @see #checkPermission
4678 * @see #checkCallingPermission
4679 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004680 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004681 @PackageManager.PermissionResult
4682 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004683
4684 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004685 * Determine whether <em>you</em> have been granted a particular permission.
4686 *
4687 * @param permission The name of the permission being checked.
4688 *
4689 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4690 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4691 *
4692 * @see PackageManager#checkPermission(String, String)
4693 * @see #checkCallingPermission(String)
4694 */
4695 @PackageManager.PermissionResult
4696 public abstract int checkSelfPermission(@NonNull String permission);
4697
4698 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004699 * If the given permission is not allowed for a particular process
4700 * and user ID running in the system, throw a {@link SecurityException}.
4701 *
4702 * @param permission The name of the permission being checked.
4703 * @param pid The process ID being checked against. Must be &gt; 0.
4704 * @param uid The user ID being checked against. A uid of 0 is the root
4705 * user, which will pass every permission check.
4706 * @param message A message to include in the exception if it is thrown.
4707 *
4708 * @see #checkPermission(String, int, int)
4709 */
4710 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004711 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004712
4713 /**
4714 * If the calling process of an IPC you are handling has not been
4715 * granted a particular permission, throw a {@link
4716 * SecurityException}. This is basically the same as calling
4717 * {@link #enforcePermission(String, int, int, String)} with the
4718 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4719 * and {@link android.os.Binder#getCallingUid}. One important
4720 * difference is that if you are not currently processing an IPC,
4721 * this function will always throw the SecurityException. This is
4722 * done to protect against accidentally leaking permissions; you
4723 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4724 * protection.
4725 *
4726 * @param permission The name of the permission being checked.
4727 * @param message A message to include in the exception if it is thrown.
4728 *
4729 * @see #checkCallingPermission(String)
4730 */
4731 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004732 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004733
4734 /**
4735 * If neither you nor the calling process of an IPC you are
4736 * handling has been granted a particular permission, throw a
4737 * {@link SecurityException}. This is the same as {@link
4738 * #enforceCallingPermission}, except it grants your own
4739 * permissions if you are not currently processing an IPC. Use
4740 * with care!
4741 *
4742 * @param permission The name of the permission being checked.
4743 * @param message A message to include in the exception if it is thrown.
4744 *
4745 * @see #checkCallingOrSelfPermission(String)
4746 */
4747 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004748 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004749
4750 /**
4751 * Grant permission to access a specific Uri to another package, regardless
4752 * of whether that package has general permission to access the Uri's
4753 * content provider. This can be used to grant specific, temporary
4754 * permissions, typically in response to user interaction (such as the
4755 * user opening an attachment that you would like someone else to
4756 * display).
4757 *
4758 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4759 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4760 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4761 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4762 * start an activity instead of this function directly. If you use this
4763 * function directly, you should be sure to call
4764 * {@link #revokeUriPermission} when the target should no longer be allowed
4765 * to access it.
4766 *
4767 * <p>To succeed, the content provider owning the Uri must have set the
4768 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4769 * grantUriPermissions} attribute in its manifest or included the
4770 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4771 * &lt;grant-uri-permissions&gt;} tag.
4772 *
4773 * @param toPackage The package you would like to allow to access the Uri.
4774 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004775 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004776 *
4777 * @see #revokeUriPermission
4778 */
4779 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004780 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004781
4782 /**
4783 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004784 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4785 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004786 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004787 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004788 * "content://foo". It will not remove any prefix grants that exist at a
4789 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004791 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004792 * regular permission access to a Uri, but had received access to it through
4793 * a specific Uri permission grant, you could not revoke that grant with this
4794 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004795 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4796 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004797 * (or none).</p>
4798 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004799 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4800 * grants matching the given Uri, for any package they had been granted to, through any
4801 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4802 * service start, etc). That means this can be potentially dangerous to use, as it can
4803 * revoke grants that another app could be strongly expecting to stick around.</p>
4804 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004806 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004807 *
4808 * @see #grantUriPermission
4809 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004810 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004811
4812 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004813 * Remove permissions to access a particular content provider Uri
4814 * that were previously added with {@link #grantUriPermission} for a specific target
4815 * package. The given Uri will match all previously granted Uris that are the same or a
4816 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4817 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4818 * "content://foo". It will not remove any prefix grants that exist at a
4819 * higher level.
4820 *
4821 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4822 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4823 * and only for the package specified. Any matching grants that have happened through
4824 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4825 * removed.</p>
4826 *
4827 * @param toPackage The package you had previously granted access to.
4828 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004829 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004830 *
4831 * @see #grantUriPermission
4832 */
4833 public abstract void revokeUriPermission(String toPackage, Uri uri,
4834 @Intent.AccessUriMode int modeFlags);
4835
4836 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004837 * Determine whether a particular process and user ID has been granted
4838 * permission to access a specific URI. This only checks for permissions
4839 * that have been explicitly granted -- if the given process/uid has
4840 * more general access to the URI's content provider then this check will
4841 * always fail.
4842 *
4843 * @param uri The uri that is being checked.
4844 * @param pid The process ID being checked against. Must be &gt; 0.
4845 * @param uid The user ID being checked against. A uid of 0 is the root
4846 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004847 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004848 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004849 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004850 * pid/uid is allowed to access that uri, or
4851 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4852 *
4853 * @see #checkCallingUriPermission
4854 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004855 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004856 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004857 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004858 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004859
Dianne Hackbornff170242014-11-19 10:59:01 -08004860 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004861 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08004862 public abstract int checkUriPermission(Uri uri, int pid, int uid,
4863 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004865 /**
4866 * Determine whether the calling process and user ID has been
4867 * granted permission to access a specific URI. This is basically
4868 * the same as calling {@link #checkUriPermission(Uri, int, int,
4869 * int)} with the pid and uid returned by {@link
4870 * android.os.Binder#getCallingPid} and {@link
4871 * android.os.Binder#getCallingUid}. One important difference is
4872 * that if you are not currently processing an IPC, this function
4873 * will always fail.
4874 *
4875 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004876 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004877 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004878 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004879 * is allowed to access that uri, or
4880 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4881 *
4882 * @see #checkUriPermission(Uri, int, int, int)
4883 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004884 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004885 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07004886 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004887
4888 /**
4889 * Determine whether the calling process of an IPC <em>or you</em> has been granted
4890 * permission to access a specific URI. This is the same as
4891 * {@link #checkCallingUriPermission}, except it grants your own permissions
4892 * if you are not currently processing an IPC. Use with care!
4893 *
4894 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004895 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004896 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004897 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 * is allowed to access that uri, or
4899 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4900 *
4901 * @see #checkCallingUriPermission
4902 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004903 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004904 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004905 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004906 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004907
4908 /**
4909 * Check both a Uri and normal permission. This allows you to perform
4910 * both {@link #checkPermission} and {@link #checkUriPermission} in one
4911 * call.
4912 *
4913 * @param uri The Uri whose permission is to be checked, or null to not
4914 * do this check.
4915 * @param readPermission The permission that provides overall read access,
4916 * or null to not do this check.
4917 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004918 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 * @param pid The process ID being checked against. Must be &gt; 0.
4920 * @param uid The user ID being checked against. A uid of 0 is the root
4921 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004922 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004923 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004924 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004925 * is allowed to access that uri or holds one of the given permissions, or
4926 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4927 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004928 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004929 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004930 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
4931 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004932 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933
4934 /**
4935 * If a particular process and user ID has not been granted
4936 * permission to access a specific URI, throw {@link
4937 * SecurityException}. This only checks for permissions that have
4938 * been explicitly granted -- if the given process/uid has more
4939 * general access to the URI's content provider then this check
4940 * will always fail.
4941 *
4942 * @param uri The uri that is being checked.
4943 * @param pid The process ID being checked against. Must be &gt; 0.
4944 * @param uid The user ID being checked against. A uid of 0 is the root
4945 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004946 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004947 * @param message A message to include in the exception if it is thrown.
4948 *
4949 * @see #checkUriPermission(Uri, int, int, int)
4950 */
4951 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004952 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004953
4954 /**
4955 * If the calling process and user ID has not been granted
4956 * permission to access a specific URI, throw {@link
4957 * SecurityException}. This is basically the same as calling
4958 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
4959 * the pid and uid returned by {@link
4960 * android.os.Binder#getCallingPid} and {@link
4961 * android.os.Binder#getCallingUid}. One important difference is
4962 * that if you are not currently processing an IPC, this function
4963 * will always throw a SecurityException.
4964 *
4965 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004966 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004967 * @param message A message to include in the exception if it is thrown.
4968 *
4969 * @see #checkCallingUriPermission(Uri, int)
4970 */
4971 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004972 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004973
4974 /**
4975 * If the calling process of an IPC <em>or you</em> has not been
4976 * granted permission to access a specific URI, throw {@link
4977 * SecurityException}. This is the same as {@link
4978 * #enforceCallingUriPermission}, except it grants your own
4979 * permissions if you are not currently processing an IPC. Use
4980 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07004981 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004983 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004984 * @param message A message to include in the exception if it is thrown.
4985 *
4986 * @see #checkCallingOrSelfUriPermission(Uri, int)
4987 */
4988 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004989 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004990
4991 /**
4992 * Enforce both a Uri and normal permission. This allows you to perform
4993 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4994 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004995 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004996 * @param uri The Uri whose permission is to be checked, or null to not
4997 * do this check.
4998 * @param readPermission The permission that provides overall read access,
4999 * or null to not do this check.
5000 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005001 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005002 * @param pid The process ID being checked against. Must be &gt; 0.
5003 * @param uid The user ID being checked against. A uid of 0 is the root
5004 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005005 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005006 * @param message A message to include in the exception if it is thrown.
5007 *
5008 * @see #checkUriPermission(Uri, String, String, int, int, int)
5009 */
5010 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005011 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005012 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07005013 @Nullable String message);
5014
5015 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005016 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
5017 CONTEXT_INCLUDE_CODE,
5018 CONTEXT_IGNORE_SECURITY,
5019 CONTEXT_RESTRICTED,
5020 CONTEXT_DEVICE_PROTECTED_STORAGE,
5021 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
5022 CONTEXT_REGISTER_PACKAGE,
5023 })
Tor Norbyed9273d62013-05-30 15:59:53 -07005024 @Retention(RetentionPolicy.SOURCE)
5025 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005026
5027 /**
5028 * Flag for use with {@link #createPackageContext}: include the application
5029 * code with the context. This means loading code into the caller's
5030 * process, so that {@link #getClassLoader()} can be used to instantiate
5031 * the application's classes. Setting this flags imposes security
5032 * restrictions on what application context you can access; if the
5033 * requested application can not be safely loaded into your process,
5034 * java.lang.SecurityException will be thrown. If this flag is not set,
5035 * there will be no restrictions on the packages that can be loaded,
5036 * but {@link #getClassLoader} will always return the default system
5037 * class loader.
5038 */
5039 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
5040
5041 /**
5042 * Flag for use with {@link #createPackageContext}: ignore any security
5043 * restrictions on the Context being requested, allowing it to always
5044 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
5045 * to be loaded into a process even when it isn't safe to do so. Use
5046 * with extreme care!
5047 */
5048 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07005049
Romain Guy870e09f2009-07-06 16:35:25 -07005050 /**
5051 * Flag for use with {@link #createPackageContext}: a restricted context may
5052 * disable specific features. For instance, a View associated with a restricted
5053 * context would ignore particular XML attributes.
5054 */
5055 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005056
5057 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005058 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005059 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005060 *
5061 * @hide
5062 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005063 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005064
5065 /**
5066 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005067 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005068 *
5069 * @hide
5070 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005071 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005072
5073 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07005074 * @hide Used to indicate we should tell the activity manager about the process
5075 * loading this code.
5076 */
5077 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
5078
5079 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005080 * Return a new Context object for the given application name. This
5081 * Context is the same as what the named application gets when it is
5082 * launched, containing the same resources and class loader. Each call to
5083 * this method returns a new instance of a Context object; Context objects
5084 * are not shared, however they share common state (Resources, ClassLoader,
5085 * etc) so the Context instance itself is fairly lightweight.
5086 *
Jeff Brown6e539312015-02-24 18:53:21 -08005087 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005088 * application with the given package name.
5089 *
5090 * <p>Throws {@link java.lang.SecurityException} if the Context requested
5091 * can not be loaded into the caller's process for security reasons (see
5092 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
5093 *
5094 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005095 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005096 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005097 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005098 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005099 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005100 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04005101 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005102 */
5103 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07005104 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07005105
5106 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07005107 * Similar to {@link #createPackageContext(String, int)}, but with a
5108 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5109 * will open any {@link Uri} as the given user.
5110 *
5111 * @hide
5112 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08005113 @SystemApi
Jeff Sharkeyec5f7d12018-08-08 09:15:04 -06005114 @TestApi
Patrick Baumannef4c4072018-02-01 08:54:05 -08005115 public Context createPackageContextAsUser(
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005116 String packageName, @CreatePackageOptions int flags, UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08005117 throws PackageManager.NameNotFoundException {
5118 if (Build.IS_ENG) {
5119 throw new IllegalStateException("createPackageContextAsUser not overridden!");
5120 }
5121 return this;
5122 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07005123
5124 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07005125 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
5126 *
5127 * @hide
5128 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005129 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07005130 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005131 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07005132
5133 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08005134 * Return a new Context object for the given split name. The new Context has a ClassLoader and
5135 * Resources object that can access the split's and all of its dependencies' code/resources.
5136 * Each call to this method returns a new instance of a Context object;
5137 * Context objects are not shared, however common state (ClassLoader, other Resources for
5138 * the same split) may be so the Context itself can be fairly lightweight.
5139 *
5140 * @param splitName The name of the split to include, as declared in the split's
5141 * <code>AndroidManifest.xml</code>.
5142 * @return A {@link Context} with the given split's code and/or resources loaded.
5143 */
5144 public abstract Context createContextForSplit(String splitName)
5145 throws PackageManager.NameNotFoundException;
5146
5147 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005148 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08005149 * @hide
5150 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07005151 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005152 public UserHandle getUser() {
5153 return android.os.Process.myUserHandle();
5154 }
5155
5156 /**
5157 * Get the user associated with this context
5158 * @hide
5159 */
5160 @TestApi
5161 public @UserIdInt int getUserId() {
5162 return android.os.UserHandle.myUserId();
5163 }
Jim Millera75a8832013-02-07 16:53:32 -08005164
5165 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07005166 * Return a new Context object for the current Context but whose resources
5167 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07005168 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07005169 * shared, however common state (ClassLoader, other Resources for the
5170 * same configuration) may be so the Context itself can be fairly lightweight.
5171 *
5172 * @param overrideConfiguration A {@link Configuration} specifying what
5173 * values to modify in the base Configuration of the original Context's
5174 * resources. If the base configuration changes (such as due to an
5175 * orientation change), the resources of this context will also change except
5176 * for those that have been explicitly overridden with a value here.
5177 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005178 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07005179 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005180 public abstract Context createConfigurationContext(
5181 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07005182
5183 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07005184 * Return a new Context object for the current Context but whose resources
5185 * are adjusted to match the metrics of the given Display. Each call to this method
5186 * returns a new instance of a Context object; Context objects are not
5187 * shared, however common state (ClassLoader, other Resources for the
5188 * same configuration) may be so the Context itself can be fairly lightweight.
5189 *
5190 * The returned display Context provides a {@link WindowManager}
5191 * (see {@link #getSystemService(String)}) that is configured to show windows
5192 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
5193 * method can be used to retrieve the Display from the returned Context.
5194 *
5195 * @param display A {@link Display} object specifying the display
5196 * for whose metrics the Context's resources should be tailored and upon which
5197 * new windows should be shown.
5198 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005199 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07005200 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005201 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07005202
5203 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005204 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005205 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005206 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005207 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005208 * with a key tied to the physical device, and it can be accessed
5209 * immediately after the device has booted successfully, both
5210 * <em>before and after</em> the user has authenticated with their
5211 * credentials (such as a lock pattern or PIN).
5212 * <p>
5213 * Because device-protected data is available without user authentication,
5214 * you should carefully limit the data you store using this Context. For
5215 * example, storing sensitive authentication tokens or passwords in the
5216 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005217 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005218 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005219 * device-protected and credential-protected data using different keys, then
5220 * both storage areas will become available at the same time. They remain as
5221 * two distinct storage locations on disk, and only the window of
5222 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005223 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005224 * Each call to this method returns a new instance of a Context object;
5225 * Context objects are not shared, however common state (ClassLoader, other
5226 * Resources for the same configuration) may be so the Context itself can be
5227 * fairly lightweight.
5228 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005229 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005230 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005231 public abstract Context createDeviceProtectedStorageContext();
5232
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005233 /**
5234 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005235 * APIs are backed by credential-protected storage. This is the default
5236 * storage area for apps unless
5237 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005238 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005239 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005240 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005241 * <em>only after</em> the user has entered their credentials (such as a
5242 * lock pattern or PIN).
5243 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005244 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005245 * device-protected and credential-protected data using different keys, then
5246 * both storage areas will become available at the same time. They remain as
5247 * two distinct storage locations on disk, and only the window of
5248 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005249 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005250 * Each call to this method returns a new instance of a Context object;
5251 * Context objects are not shared, however common state (ClassLoader, other
5252 * Resources for the same configuration) may be so the Context itself can be
5253 * fairly lightweight.
5254 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005255 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005256 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005257 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005258 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005259 public abstract Context createCredentialProtectedStorageContext();
5260
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005261 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07005262 * Gets the display adjustments holder for this context. This information
5263 * is provided on a per-application or activity basis and is used to simulate lower density
5264 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07005265 *
Jeff Browna492c3a2012-08-23 19:48:44 -07005266 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07005267 * @return The compatibility info holder, or null if not required by the application.
5268 * @hide
5269 */
Craig Mautner48d0d182013-06-11 07:53:06 -07005270 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07005271
5272 /**
Wale Ogunwale691af682019-02-11 03:09:10 -08005273 * @return Returns the {@link Display} object this context is associated with.
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005274 * @hide
5275 */
Wale Ogunwale691af682019-02-11 03:09:10 -08005276 @TestApi
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005277 public abstract Display getDisplay();
5278
5279 /**
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005280 * Gets the display ID.
5281 *
5282 * @return display ID associated with this {@link Context}.
5283 * @hide
5284 */
5285 public abstract int getDisplayId();
5286
5287 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08005288 * @hide
5289 */
5290 public abstract void updateDisplay(int displayId);
5291
5292 /**
Romain Guy870e09f2009-07-06 16:35:25 -07005293 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07005294 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005295 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07005296 *
Romain Guy870e09f2009-07-06 16:35:25 -07005297 * @see #CONTEXT_RESTRICTED
5298 */
5299 public boolean isRestricted() {
5300 return false;
5301 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005302
5303 /**
5304 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005305 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005306 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005307 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005308 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005309 public abstract boolean isDeviceProtectedStorage();
5310
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005311 /**
5312 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005313 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005314 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005315 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005316 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005317 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005318 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005319 public abstract boolean isCredentialProtectedStorage();
5320
Tony Mak46aabe52016-11-14 12:53:06 +00005321 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005322 * Returns true if the context can load unsafe resources, e.g. fonts.
5323 * @hide
5324 */
5325 public abstract boolean canLoadUnsafeResources();
5326
5327 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005328 * @hide
5329 */
5330 public IBinder getActivityToken() {
5331 throw new RuntimeException("Not implemented. Must override in a subclass.");
5332 }
5333
5334 /**
5335 * @hide
5336 */
5337 @Nullable
5338 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
5339 int flags) {
5340 throw new RuntimeException("Not implemented. Must override in a subclass.");
5341 }
5342
5343 /**
5344 * @hide
5345 */
5346 public IApplicationThread getIApplicationThread() {
5347 throw new RuntimeException("Not implemented. Must override in a subclass.");
5348 }
Tony Makbf9928d2016-12-22 11:02:45 +00005349
5350 /**
5351 * @hide
5352 */
5353 public Handler getMainThreadHandler() {
5354 throw new RuntimeException("Not implemented. Must override in a subclass.");
5355 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07005356
5357 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07005358 * @hide
5359 */
5360 public AutofillClient getAutofillClient() {
5361 return null;
5362 }
5363
5364 /**
5365 * @hide
5366 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005367 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005368 }
5369
5370 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005371 * @hide
5372 */
Adam He6240eab2019-02-25 13:34:45 -08005373 @Nullable
5374 public ContentCaptureClient getContentCaptureClient() {
5375 return null;
5376 }
5377
5378 /**
5379 * @hide
5380 */
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005381 public final boolean isAutofillCompatibilityEnabled() {
5382 final AutofillOptions options = getAutofillOptions();
5383 return options != null && options.compatModeEnabled;
5384 }
5385
5386 /**
5387 * @hide
5388 */
5389 @Nullable
5390 public AutofillOptions getAutofillOptions() {
5391 return null;
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005392 }
5393
5394 /**
5395 * @hide
5396 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005397 @TestApi
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005398 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005399 }
5400
5401 /**
Felipe Leme326f15a2019-02-19 09:42:24 -08005402 * Gets the Content Capture options for this context, or {@code null} if it's not whitelisted.
Felipe Lemeecb08be2018-11-27 15:48:47 -08005403 *
5404 * @hide
5405 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005406 @Nullable
5407 public ContentCaptureOptions getContentCaptureOptions() {
5408 return null;
Felipe Lemeecb08be2018-11-27 15:48:47 -08005409 }
5410
5411 /**
5412 * @hide
5413 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005414 @TestApi
5415 public void setContentCaptureOptions(
5416 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08005417 }
5418
5419 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005420 * Throws an exception if the Context is using system resources,
5421 * which are non-runtime-overlay-themable and may show inconsistent UI.
5422 * @hide
5423 */
5424 public void assertRuntimeOverlayThemable() {
5425 // Resources.getSystem() is a singleton and the only Resources not managed by
5426 // ResourcesManager; therefore Resources.getSystem() is not themable.
5427 if (getResources() == Resources.getSystem()) {
5428 throw new IllegalArgumentException("Non-UI context used to display UI; "
5429 + "get a UI context from ActivityThread#getSystemUiContext()");
5430 }
5431 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005432}