blob: a8c1216b80b2d2877e7f85ca76bc6ab5fb65e1d2 [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;
Felipe Lemecbf7f262019-04-17 13:57:59 -070073import 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
atrosta6a4d602019-08-21 16:48:56 +010076import com.android.internal.compat.IPlatformCompat;
atrostff948d82019-10-10 19:27:31 +010077import com.android.internal.compat.IPlatformCompatNative;
atrosta6a4d602019-08-21 16:48:56 +010078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079import java.io.File;
80import java.io.FileInputStream;
81import java.io.FileNotFoundException;
82import java.io.FileOutputStream;
83import java.io.IOException;
84import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070085import java.lang.annotation.Retention;
86import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070087import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088
89/**
90 * Interface to global information about an application environment. This is
91 * an abstract class whose implementation is provided by
92 * the Android system. It
93 * allows access to application-specific resources and classes, as well as
94 * up-calls for application-level operations such as launching activities,
95 * broadcasting and receiving intents, etc.
96 */
97public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060098 /** @hide */
99 @IntDef(flag = true, prefix = { "MODE_" }, value = {
100 MODE_PRIVATE,
101 MODE_WORLD_READABLE,
102 MODE_WORLD_WRITEABLE,
103 MODE_APPEND,
104 })
105 @Retention(RetentionPolicy.SOURCE)
106 public @interface FileMode {}
107
108 /** @hide */
109 @IntDef(flag = true, prefix = { "MODE_" }, value = {
110 MODE_PRIVATE,
111 MODE_WORLD_READABLE,
112 MODE_WORLD_WRITEABLE,
113 MODE_MULTI_PROCESS,
114 })
115 @Retention(RetentionPolicy.SOURCE)
116 public @interface PreferencesMode {}
117
118 /** @hide */
119 @IntDef(flag = true, prefix = { "MODE_" }, value = {
120 MODE_PRIVATE,
121 MODE_WORLD_READABLE,
122 MODE_WORLD_WRITEABLE,
123 MODE_ENABLE_WRITE_AHEAD_LOGGING,
124 MODE_NO_LOCALIZED_COLLATORS,
125 })
126 @Retention(RetentionPolicy.SOURCE)
127 public @interface DatabaseMode {}
128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 /**
130 * File creation mode: the default mode, where the created file can only
131 * be accessed by the calling application (or all applications sharing the
132 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 */
134 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700135
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700137 * File creation mode: allow all other applications to have read access to
138 * the created file.
139 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700140 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
141 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700142 *
Nick Kralevich15069212013-01-09 15:54:56 -0800143 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700144 * to cause security holes in applications. It is strongly
145 * discouraged; instead, applications should use more formal
146 * mechanism for interactions such as {@link ContentProvider},
147 * {@link BroadcastReceiver}, and {@link android.app.Service}.
148 * There are no guarantees that this access mode will remain on
149 * a file, such as when it goes through a backup and restore.
150 * @see android.support.v4.content.FileProvider
151 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700153 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700157 * File creation mode: allow all other applications to have write access to
158 * the created file.
159 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700160 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700161 * mode will throw a {@link SecurityException}.
162 *
Nick Kralevich15069212013-01-09 15:54:56 -0800163 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700164 * to cause security holes in applications. It is strongly
165 * discouraged; instead, applications should use more formal
166 * mechanism for interactions such as {@link ContentProvider},
167 * {@link BroadcastReceiver}, and {@link android.app.Service}.
168 * There are no guarantees that this access mode will remain on
169 * a file, such as when it goes through a backup and restore.
170 * @see android.support.v4.content.FileProvider
171 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700173 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700175
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 /**
177 * File creation mode: for use with {@link #openFileOutput}, if the file
178 * already exists then write data to the end of the existing file
179 * instead of erasing it.
180 * @see #openFileOutput
181 */
182 public static final int MODE_APPEND = 0x8000;
183
184 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800185 * SharedPreference loading flag: when set, the file on disk will
186 * be checked for modification even if the shared preferences
187 * instance is already loaded in this process. This behavior is
188 * sometimes desired in cases where the application has multiple
189 * processes, all writing to the same SharedPreferences file.
190 * Generally there are better forms of communication between
191 * processes, though.
192 *
193 * <p>This was the legacy (but undocumented) behavior in and
194 * before Gingerbread (Android 2.3) and this flag is implied when
kopriva219f7dc2018-10-09 13:42:28 -0700195 * targeting such releases. For applications targeting SDK
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800196 * versions <em>greater than</em> Android 2.3, this flag must be
197 * explicitly set if desired.
198 *
199 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700200 *
201 * @deprecated MODE_MULTI_PROCESS does not work reliably in
202 * some versions of Android, and furthermore does not provide any
203 * mechanism for reconciling concurrent modifications across
204 * processes. Applications should not attempt to use it. Instead,
205 * they should use an explicit cross-process data management
206 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800207 */
Christopher Tated5748b82015-05-08 18:14:01 -0700208 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800209 public static final int MODE_MULTI_PROCESS = 0x0004;
210
211 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700212 * Database open flag: when set, the database is opened with write-ahead
213 * logging enabled by default.
214 *
215 * @see #openOrCreateDatabase(String, int, CursorFactory)
216 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
217 * @see SQLiteDatabase#enableWriteAheadLogging
218 */
219 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
220
Sunny Goyala21e6b22015-12-02 09:51:02 -0800221 /**
222 * Database open flag: when set, the database is opened without support for
223 * localized collators.
224 *
225 * @see #openOrCreateDatabase(String, int, CursorFactory)
226 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
227 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
228 */
229 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
230
Tor Norbyed9273d62013-05-30 15:59:53 -0700231 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700232 @IntDef(flag = true, prefix = { "BIND_" }, value = {
233 BIND_AUTO_CREATE,
234 BIND_DEBUG_UNBIND,
235 BIND_NOT_FOREGROUND,
236 BIND_ABOVE_CLIENT,
237 BIND_ALLOW_OOM_MANAGEMENT,
238 BIND_WAIVE_PRIORITY,
239 BIND_IMPORTANT,
Amith Yamasani5016a782019-06-17 16:20:24 -0700240 BIND_ADJUST_WITH_ACTIVITY,
241 BIND_NOT_PERCEPTIBLE,
242 BIND_INCLUDE_CAPABILITIES
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700243 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700244 @Retention(RetentionPolicy.SOURCE)
245 public @interface BindServiceFlags {}
246
Jeff Brown47847f32012-03-22 19:13:11 -0700247 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 * Flag for {@link #bindService}: automatically create the service as long
249 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700250 * its {@link android.app.Service#onStartCommand}
251 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 * explicit call to {@link #startService}. Even without that, though,
253 * this still provides you with access to the service object while the
254 * service is created.
255 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700256 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
257 * not supplying this flag would also impact how important the system
258 * consider's the target service's process to be. When set, the only way
259 * for it to be raised was by binding from a service in which case it will
260 * only be important when that activity is in the foreground. Now to
261 * achieve this behavior you must explicitly supply the new flag
262 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
263 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
264 * the flags {@link #BIND_WAIVE_PRIORITY} and
265 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
266 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 */
268 public static final int BIND_AUTO_CREATE = 0x0001;
269
270 /**
271 * Flag for {@link #bindService}: include debugging help for mismatched
272 * calls to unbind. When this flag is set, the callstack of the following
273 * {@link #unbindService} call is retained, to be printed if a later
274 * incorrect unbind call is made. Note that doing this requires retaining
275 * information about the binding that was made for the lifetime of the app,
276 * resulting in a leak -- this should only be used for debugging.
277 */
278 public static final int BIND_DEBUG_UNBIND = 0x0002;
279
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800280 /**
281 * Flag for {@link #bindService}: don't allow this binding to raise
282 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700283 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800284 * as the client (so that its process will not be killable in any
285 * situation where the client is not killable), but for CPU scheduling
286 * purposes it may be left in the background. This only has an impact
287 * in the situation where the binding client is a foreground process
288 * and the target service is in a background process.
289 */
290 public static final int BIND_NOT_FOREGROUND = 0x0004;
291
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700292 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700293 * Flag for {@link #bindService}: indicates that the client application
294 * binding to this service considers the service to be more important than
295 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700296 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700297 * this is not guaranteed to be the case.
298 */
299 public static final int BIND_ABOVE_CLIENT = 0x0008;
300
301 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700302 * Flag for {@link #bindService}: allow the process hosting the bound
303 * service to go through its normal memory management. It will be
304 * treated more like a running service, allowing the system to
305 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700306 * whim it may have, and being more aggressive about making it a candidate
307 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700308 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700309 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
310
311 /**
312 * Flag for {@link #bindService}: don't impact the scheduling or
313 * memory management priority of the target service's hosting process.
314 * Allows the service's process to be managed on the background LRU list
315 * just like a regular application process in the background.
316 */
317 public static final int BIND_WAIVE_PRIORITY = 0x0020;
318
319 /**
320 * Flag for {@link #bindService}: this service is very important to
321 * the client, so should be brought to the foreground process level
322 * when the client is. Normally a process can only be raised to the
323 * visibility level by a client, even if that client is in the foreground.
324 */
325 public static final int BIND_IMPORTANT = 0x0040;
326
327 /**
328 * Flag for {@link #bindService}: If binding from an activity, allow the
329 * target service's process importance to be raised based on whether the
330 * activity is visible to the user, regardless whether another flag is
331 * used to reduce the amount that the client process's overall importance
332 * is used to impact it.
333 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700334 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
335
336 /**
Amith Yamasani5016a782019-06-17 16:20:24 -0700337 * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible,
338 * lower the target service's importance to below the perceptible level. This allows
339 * the system to (temporarily) expunge the bound process from memory to make room for more
340 * important user-perceptible processes.
341 */
342 public static final int BIND_NOT_PERCEPTIBLE = 0x00000100;
343
344 /**
Amith Yamasanif178c962019-03-21 19:40:11 -0700345 * Flag for {@link #bindService}: If binding from an app that has specific capabilities
346 * due to its foreground state such as an activity or foreground service, then this flag will
347 * allow the bound app to get the same capabilities, as long as it has the required permissions
348 * as well.
349 */
Amith Yamasani5016a782019-06-17 16:20:24 -0700350 public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000;
Amith Yamasanif178c962019-03-21 19:40:11 -0700351
Amith Yamasani0b3ae0e2019-05-10 10:29:47 -0700352 /*********** Public flags above this line ***********/
353 /*********** Hidden flags below this line ***********/
354
355 /**
Yohei Yukawa59730962019-03-18 10:47:22 -0700356 * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust
357 * the scheduling policy for IMEs (and any other out-of-process user-visible components that
358 * work closely with the top app) so that UI hosted in such services can have the same
359 * scheduling policy (e.g. SCHED_FIFO when it is enabled and TOP_APP_PRIORITY_BOOST otherwise)
360 * as the actual top-app.
361 * @hide
362 */
363 public static final int BIND_SCHEDULE_LIKE_TOP_APP = 0x00080000;
364
365 /**
Michal Karpinskie069b002019-03-07 16:15:14 +0000366 * Flag for {@link #bindService}: allow background activity starts from the bound service's
367 * process.
368 * This flag is only respected if the caller is holding
369 * {@link android.Manifest.permission#START_ACTIVITIES_FROM_BACKGROUND}.
370 * @hide
371 */
372 public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 0x00100000;
373
374 /**
Dianne Hackbornc390aa82019-01-09 16:38:22 -0800375 * @hide Flag for {@link #bindService}: the service being bound to represents a
376 * protected system component, so must have association restrictions applied to it.
377 * That is, a system config must have one or more allow-association tags limiting
378 * which packages it can interact with. If it does not have any such association
379 * restrictions, a default empty set will be created.
380 */
381 public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000;
382
383 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800384 * @hide Flag for {@link #bindService}: allows binding to a service provided
385 * by an instant app. Note that the caller may not have access to the instant
386 * app providing the service which is a violation of the instant app sandbox.
387 * This flag is intended ONLY for development/testing and should be used with
388 * great care. Only the system is allowed to use this flag.
389 */
390 public static final int BIND_ALLOW_INSTANT = 0x00400000;
391
392 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700393 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
394 * up in to the important background state (instead of transient).
395 */
396 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
397
398 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700399 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
400 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
401 */
402 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
403
404 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700405 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
406 * but only applies while the device is awake.
407 */
408 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
409
410 /**
411 * @hide Flag for {@link #bindService}: For only the case where the binding
412 * is coming from the system, set the process state to FOREGROUND_SERVICE
413 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
414 * saying that the process shouldn't participate in the normal power reduction
415 * modes (removing network access etc).
416 */
417 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
418
419 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700420 * @hide Flag for {@link #bindService}: Treat the binding as hosting
421 * an activity, an unbinding as the activity going in the background.
422 * That is, when unbinding, the process when empty will go on the activity
423 * LRU list instead of the regular one, keeping it around more aggressively
424 * than it otherwise would be. This is intended for use with IMEs to try
425 * to keep IME processes around for faster keyboard switching.
426 */
427 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
428
429 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700430 * @hide An idea that is not yet implemented.
431 * Flag for {@link #bindService}: If binding from an activity, consider
432 * this service to be visible like the binding activity is. That is,
433 * it will be treated as something more important to keep around than
434 * invisible background activities. This will impact the number of
435 * recent activities the user can switch between without having them
436 * restart. There is no guarantee this will be respected, as the system
Amith Yamasanif235d0b2019-03-20 22:49:43 -0700437 * tries to balance such requests from one app vs. the importance of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700438 * keeping other apps around.
439 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700440 public static final int BIND_VISIBLE = 0x10000000;
441
442 /**
443 * @hide
444 * Flag for {@link #bindService}: Consider this binding to be causing the target
445 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
446 * away.
447 */
448 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700449
450 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700451 * Flag for {@link #bindService}: Don't consider the bound service to be
452 * visible, even if the caller is visible.
453 * @hide
454 */
455 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700456
Alan Viverette713a5cd2015-12-16 15:46:32 -0500457 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500458 * Flag for {@link #bindService}: The service being bound is an
459 * {@link android.R.attr#isolatedProcess isolated},
460 * {@link android.R.attr#externalService external} service. This binds the service into the
461 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400462 * <p>
463 * When using this flag, the code for the service being bound will execute under the calling
464 * application's package name and user ID. Because the service must be an isolated process,
465 * it will not have direct access to the application's data, though.
466 *
467 * The purpose of this flag is to allow applications to provide services that are attributed
468 * to the app using the service, rather than the application providing the service.
469 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500470 */
471 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
472
Dianne Hackborna631d562018-11-20 15:58:15 -0800473 /**
474 * These bind flags reduce the strength of the binding such that we shouldn't
475 * consider it as pulling the process up to the level of the one that is bound to it.
476 * @hide
477 */
478 public static final int BIND_REDUCTION_FLAGS =
479 Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
Amith Yamasani5016a782019-06-17 16:20:24 -0700480 | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;
Dianne Hackborna631d562018-11-20 15:58:15 -0800481
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700482 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700483 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
484 RECEIVER_VISIBLE_TO_INSTANT_APPS
485 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700486 @Retention(RetentionPolicy.SOURCE)
487 public @interface RegisterReceiverFlags {}
488
489 /**
490 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
491 */
492 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
493
Robert Sesekb9a86662015-12-09 16:22:45 -0500494 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500495 * Returns an AssetManager instance for the application's package.
496 * <p>
497 * <strong>Note:</strong> Implementations of this method should return
498 * an AssetManager instance that is consistent with the Resources instance
499 * returned by {@link #getResources()}. For example, they should share the
500 * same {@link Configuration} object.
501 *
502 * @return an AssetManager instance for the application's package
503 * @see #getResources()
504 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 public abstract AssetManager getAssets();
506
Alan Viverette713a5cd2015-12-16 15:46:32 -0500507 /**
508 * Returns a Resources instance for the application's package.
509 * <p>
510 * <strong>Note:</strong> Implementations of this method should return
511 * a Resources instance that is consistent with the AssetManager instance
512 * returned by {@link #getAssets()}. For example, they should share the
513 * same {@link Configuration} object.
514 *
515 * @return a Resources instance for the application's package
516 * @see #getAssets()
517 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 public abstract Resources getResources();
519
520 /** Return PackageManager instance to find global package information. */
521 public abstract PackageManager getPackageManager();
522
523 /** Return a ContentResolver instance for your application's package. */
524 public abstract ContentResolver getContentResolver();
525
526 /**
527 * Return the Looper for the main thread of the current process. This is
528 * the thread used to dispatch calls to application components (activities,
529 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700530 * <p>
531 * By definition, this method returns the same result as would be obtained
532 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
533 * </p>
534 *
535 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 */
537 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700540 * Return an {@link Executor} that will run enqueued tasks on the main
541 * thread associated with this context. This is the thread used to dispatch
542 * calls to application components (activities, services, etc).
543 */
544 public Executor getMainExecutor() {
545 // This is pretty inefficient, which is why ContextImpl overrides it
546 return new HandlerExecutor(new Handler(getMainLooper()));
547 }
548
549 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800551 * current process. This generally should only be used if you need a
552 * Context whose lifecycle is separate from the current context, that is
553 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700554 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800555 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800556 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800557 * <ul>
558 * <li> <p>If used from an Activity context, the receiver is being registered
559 * within that activity. This means that you are expected to unregister
560 * before the activity is done being destroyed; in fact if you do not do
561 * so, the framework will clean up your leaked registration as it removes
562 * the activity and log an error. Thus, if you use the Activity context
563 * to register a receiver that is static (global to the process, not
564 * associated with an Activity instance) then that registration will be
565 * removed on you at whatever point the activity you used is destroyed.
566 * <li> <p>If used from the Context returned here, the receiver is being
567 * registered with the global state associated with your application. Thus
568 * it will never be unregistered for you. This is necessary if the receiver
569 * is associated with static data, not a particular component. However
570 * using the ApplicationContext elsewhere can easily lead to serious leaks
571 * if you forget to unregister, unbind, etc.
572 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 */
574 public abstract Context getApplicationContext();
575
Phil Weaver846cda932017-06-15 10:10:06 -0700576 /** Non-activity related autofill ids are unique in the app */
577 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700578
579 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700580 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700581 *
Phil Weaver846cda932017-06-15 10:10:06 -0700582 * <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 -0700583 * returned will be unique.
584 *
585 * @return A ID that is unique in the process
586 *
587 * {@hide}
588 */
Phil Weaver846cda932017-06-15 10:10:06 -0700589 public int getNextAutofillId() {
590 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
591 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700592 }
593
Phil Weaver846cda932017-06-15 10:10:06 -0700594 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700595
Phil Weaver846cda932017-06-15 10:10:06 -0700596 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700597 }
598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800599 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700600 * Add a new {@link ComponentCallbacks} to the base application of the
601 * Context, which will be called at the same times as the ComponentCallbacks
602 * methods of activities and other components are called. Note that you
603 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
604 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700605 *
606 * @param callback The interface to call. This can be either a
607 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700608 */
609 public void registerComponentCallbacks(ComponentCallbacks callback) {
610 getApplicationContext().registerComponentCallbacks(callback);
611 }
612
613 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400614 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700615 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
616 */
617 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
618 getApplicationContext().unregisterComponentCallbacks(callback);
619 }
620
621 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800622 * Return a localized, styled CharSequence from the application's package's
623 * default string table.
624 *
625 * @param resId Resource id for the CharSequence text
626 */
Chris Craikceb26932018-02-01 15:51:34 -0800627 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700628 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 return getResources().getText(resId);
630 }
631
632 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700633 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 * default string table.
635 *
636 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700637 * @return The string data associated with the resource, stripped of styled
638 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800639 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700640 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700641 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 return getResources().getString(resId);
643 }
644
645 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700646 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800647 * default string table, substituting the format arguments as defined in
648 * {@link java.util.Formatter} and {@link java.lang.String#format}.
649 *
650 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700651 * @param formatArgs The format arguments that will be used for
652 * substitution.
653 * @return The string data associated with the resource, formatted and
654 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700656 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700657 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800658 return getResources().getString(resId, formatArgs);
659 }
660
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800661 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800662 * Returns a color associated with a particular resource ID and styled for
663 * the current theme.
664 *
665 * @param id The desired resource identifier, as generated by the aapt
666 * tool. This integer encodes the package, type, and resource
667 * entry. The value 0 is an invalid identifier.
668 * @return A single color value in the form 0xAARRGGBB.
669 * @throws android.content.res.Resources.NotFoundException if the given ID
670 * does not exist.
671 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700672 @ColorInt
673 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800674 return getResources().getColor(id, getTheme());
675 }
676
677 /**
678 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800679 * styled for the current theme.
680 *
681 * @param id The desired resource identifier, as generated by the aapt
682 * tool. This integer encodes the package, type, and resource
683 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800684 * @return An object that can be used to draw this resource.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800685 * @throws android.content.res.Resources.NotFoundException if the given ID
686 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800687 */
Chris Craik1194b0b2018-03-23 13:36:24 -0700688 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700689 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800690 return getResources().getDrawable(id, getTheme());
691 }
692
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800693 /**
694 * Returns a color state list associated with a particular resource ID and
695 * styled for the current theme.
696 *
697 * @param id The desired resource identifier, as generated by the aapt
698 * tool. This integer encodes the package, type, and resource
699 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800700 * @return A color state list.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800701 * @throws android.content.res.Resources.NotFoundException if the given ID
702 * does not exist.
703 */
Chris Craikceb26932018-02-01 15:51:34 -0800704 @NonNull
Tor Norbye3e4cda72015-06-10 08:14:31 -0700705 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800706 return getResources().getColorStateList(id, getTheme());
707 }
708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800709 /**
710 * Set the base theme for this context. Note that this should be called
711 * before any views are instantiated in the Context (for example before
712 * calling {@link android.app.Activity#setContentView} or
713 * {@link android.view.LayoutInflater#inflate}).
714 *
715 * @param resid The style resource describing the theme.
716 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700717 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800718
Dianne Hackborn247fe742011-01-08 17:25:57 -0800719 /** @hide Needed for some internal implementation... not public because
720 * you can't assume this actually means anything. */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100721 @UnsupportedAppUsage
Dianne Hackborn247fe742011-01-08 17:25:57 -0800722 public int getThemeResId() {
723 return 0;
724 }
725
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800726 /**
727 * Return the Theme object associated with this Context.
728 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700729 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800730 public abstract Resources.Theme getTheme();
731
732 /**
733 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800734 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800735 * for more information.
736 *
Jeff Brown6e539312015-02-24 18:53:21 -0800737 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800738 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800739 @NonNull
740 public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 return getTheme().obtainStyledAttributes(attrs);
742 }
743
744 /**
745 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800746 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800747 * for more information.
748 *
Jeff Brown6e539312015-02-24 18:53:21 -0800749 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800751 @NonNull
752 public final TypedArray obtainStyledAttributes(@StyleRes int resid,
753 @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 return getTheme().obtainStyledAttributes(resid, attrs);
755 }
756
757 /**
758 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800759 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800760 * for more information.
761 *
Jeff Brown6e539312015-02-24 18:53:21 -0800762 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800764 @NonNull
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 public final TypedArray obtainStyledAttributes(
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800766 @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
768 }
769
770 /**
771 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800772 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 * for more information.
774 *
Jeff Brown6e539312015-02-24 18:53:21 -0800775 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800777 @NonNull
778 public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set,
779 @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
Tor Norbyec91531a2015-04-01 17:41:55 -0700780 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800781 return getTheme().obtainStyledAttributes(
782 set, attrs, defStyleAttr, defStyleRes);
783 }
784
785 /**
786 * Return a class loader you can use to retrieve classes in this package.
787 */
788 public abstract ClassLoader getClassLoader();
789
790 /** Return the name of this application's package. */
791 public abstract String getPackageName();
792
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900793 /**
794 * @hide Return the name of the base context this context is derived from.
795 * This is the same as {@link #getOpPackageName()} except in
796 * cases where system components are loaded into other app processes, in which
797 * case {@link #getOpPackageName()} will be the name of the primary package in
798 * that process (so that app ops uid verification will work with the name).
799 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100800 @UnsupportedAppUsage
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800801 public abstract String getBasePackageName();
802
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900803 /**
804 * Return the package name that should be used for {@link android.app.AppOpsManager} calls from
805 * this context, so that app ops manager's uid verification will work with the name.
806 * <p>
807 * This is not generally intended for third party application developers.
808 */
Adrian Roosebc927c2019-02-28 16:21:18 +0100809 @NonNull
Adrian Roosfe6aeaf2019-01-22 16:58:56 +0100810 public String getOpPackageName() {
811 throw new RuntimeException("Not implemented. Must override in a subclass.");
812 }
Dianne Hackborn95d78532013-09-11 09:51:14 -0700813
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700814 /** Return the full application info for this context's package. */
815 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700816
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800817 /**
Kenny Root32148392010-01-21 15:40:47 -0800818 * Return the full path to this context's primary Android package.
819 * The Android package is a ZIP file which contains the application's
820 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 *
822 * <p>Note: this is not generally useful for applications, since they should
823 * not be directly accessing the file system.
824 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800825 * @return String Path to the resources.
826 */
827 public abstract String getPackageResourcePath();
828
829 /**
Kenny Root32148392010-01-21 15:40:47 -0800830 * Return the full path to this context's primary Android package.
831 * The Android package is a ZIP file which contains application's
832 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 *
834 * <p>Note: this is not generally useful for applications, since they should
835 * not be directly accessing the file system.
836 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 * @return String Path to the code and assets.
838 */
839 public abstract String getPackageCodePath();
840
841 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700842 * @hide
843 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700844 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700845 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100846 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700847 public File getSharedPrefsFile(String name) {
848 return getSharedPreferencesPath(name);
849 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700850
851 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 * Retrieve and hold the contents of the preferences file 'name', returning
853 * a SharedPreferences through which you can retrieve and modify its
854 * values. Only one instance of the SharedPreferences object is returned
855 * to any callers for the same name, meaning they will see each other's
856 * edits as soon as they are made.
857 *
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700858 * This method is thead-safe.
859 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 * @param name Desired preferences file. If a preferences file by this name
861 * does not exist, it will be created when you retrieve an
862 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600863 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400865 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 * to retrieve and modify the preference values.
867 *
868 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600870 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700871
872 /**
873 * Retrieve and hold the contents of the preferences file, returning
874 * a SharedPreferences through which you can retrieve and modify its
875 * values. Only one instance of the SharedPreferences object is returned
876 * to any callers for the same name, meaning they will see each other's
877 * edits as soon as they are made.
878 *
879 * @param file Desired preferences file. If a preferences file by this name
880 * does not exist, it will be created when you retrieve an
881 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600882 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700883 *
884 * @return The single {@link SharedPreferences} instance that can be used
885 * to retrieve and modify the preference values.
886 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700887 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700888 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600889 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700890 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600891 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800892
893 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600894 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700895 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600896 * storage locations after an upgrade, such as moving to device protected
897 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700898 *
899 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600900 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700901 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600902 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700903 * preferences didn't exist in the source context, otherwise
904 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600905 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700906 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600907 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
908
Jeff Sharkey35871f22016-01-29 17:13:29 -0700909 /**
910 * Delete an existing shared preferences file.
911 *
912 * @param name The name (unique in the application package) of the shared
913 * preferences file.
914 * @return {@code true} if the shared preferences file was successfully
915 * deleted; else {@code false}.
916 * @see #getSharedPreferences(String, int)
917 */
918 public abstract boolean deleteSharedPreferences(String name);
919
Christopher Tatefe2368c2017-05-17 15:42:35 -0700920 /** @hide */
921 public abstract void reloadSharedPreferences();
922
Jeff Sharkey35871f22016-01-29 17:13:29 -0700923 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 * Open a private file associated with this Context's application package
925 * for reading.
926 *
927 * @param name The name of the file to open; can not contain path
928 * separators.
929 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400930 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 *
932 * @see #openFileOutput
933 * @see #fileList
934 * @see #deleteFile
935 * @see java.io.FileInputStream#FileInputStream(String)
936 */
937 public abstract FileInputStream openFileInput(String name)
938 throws FileNotFoundException;
939
940 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800941 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700942 * for writing. Creates the file if it doesn't already exist.
943 * <p>
944 * No additional permissions are required for the calling app to read or
945 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700946 *
Nick Kralevich15069212013-01-09 15:54:56 -0800947 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700948 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600949 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400950 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800951 * @see #MODE_APPEND
952 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 * @see #openFileInput
954 * @see #fileList
955 * @see #deleteFile
956 * @see java.io.FileOutputStream#FileOutputStream(String)
957 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600958 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 throws FileNotFoundException;
960
961 /**
962 * Delete the given private file associated with this Context's
963 * application package.
964 *
965 * @param name The name of the file to delete; can not contain path
966 * separators.
967 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400968 * @return {@code true} if the file was successfully deleted; else
969 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 *
971 * @see #openFileInput
972 * @see #openFileOutput
973 * @see #fileList
974 * @see java.io.File#delete()
975 */
976 public abstract boolean deleteFile(String name);
977
978 /**
979 * Returns the absolute path on the filesystem where a file created with
980 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700981 * <p>
982 * The returned path may change over time if the calling app is moved to an
983 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 *
985 * @param name The name of the file for which you would like to get
986 * its path.
987 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400988 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 *
990 * @see #openFileOutput
991 * @see #getFilesDir
992 * @see #getDir
993 */
994 public abstract File getFileStreamPath(String name);
995
996 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700997 * Returns the absolute path on the filesystem where a file created with
998 * {@link #getSharedPreferences(String, int)} is stored.
999 * <p>
1000 * The returned path may change over time if the calling app is moved to an
1001 * adopted storage device, so only relative paths should be persisted.
1002 *
1003 * @param name The name of the shared preferences for which you would like
1004 * to get a path.
1005 * @return An absolute path to the given file.
1006 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001007 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001008 */
1009 public abstract File getSharedPreferencesPath(String name);
1010
1011 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001012 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001013 * private files belonging to this app are stored. Apps should not use this
1014 * path directly; they should instead use {@link #getFilesDir()},
1015 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1016 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -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.
1023 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001024 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001025 */
1026 public abstract File getDataDir();
1027
1028 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001029 * Returns the absolute path to the directory on the filesystem where files
1030 * created with {@link #openFileOutput} are stored.
1031 * <p>
1032 * The returned path may change over time if the calling app is moved to an
1033 * adopted storage device, so only relative paths should be persisted.
1034 * <p>
1035 * No additional permissions are required for the calling app to read or
1036 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -07001037 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001038 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 * @see #openFileOutput
1040 * @see #getFileStreamPath
1041 * @see #getDir
1042 */
1043 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -07001044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 /**
Christopher Tatea7835b62014-07-11 17:25:57 -07001046 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001047 * {@link #getFilesDir()}. The difference is that files placed under this
1048 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -07001049 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1050 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001051 * <p>
1052 * The returned path may change over time if the calling app is moved to an
1053 * adopted storage device, so only relative paths should be persisted.
1054 * <p>
1055 * No additional permissions are required for the calling app to read or
1056 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -07001057 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001058 * @return The path of the directory holding application files that will not
1059 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -07001060 * @see #openFileOutput
1061 * @see #getFileStreamPath
1062 * @see #getDir
1063 * @see android.app.backup.BackupAgent
1064 */
1065 public abstract File getNoBackupFilesDir();
1066
1067 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001068 * Returns the absolute path to the directory on the primary shared/external
1069 * storage device where the application can place persistent files it owns.
1070 * These files are internal to the applications, and not typically visible
1071 * to the user as media.
1072 * <p>
1073 * This is like {@link #getFilesDir()} in that these files will be deleted
1074 * when the application is uninstalled, however there are some important
1075 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001076 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001077 * <li>Shared storage may not always be available, since removable media can
1078 * be ejected by the user. Media state can be checked using
1079 * {@link Environment#getExternalStorageState(File)}.
1080 * <li>There is no security enforced with these files. For example, any
1081 * application holding
1082 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001083 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001084 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001085 * <p>
1086 * If a shared storage device is emulated (as determined by
1087 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1088 * backed by a private user data partition, which means there is little
1089 * benefit to storing data here instead of the private directories returned
1090 * by {@link #getFilesDir()}, etc.
1091 * <p>
1092 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001093 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001094 * accessible to the calling app. This only applies to paths generated for
1095 * package name of the calling application. To access paths belonging to
1096 * other packages,
1097 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1098 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1099 * <p>
1100 * On devices with multiple users (as described by {@link UserManager}),
1101 * each user has their own isolated shared storage. Applications only have
1102 * access to the shared storage for the user they're running as.
1103 * <p>
1104 * The returned path may change over time if different shared storage media
1105 * is inserted, so only relative paths should be persisted.
1106 * <p>
1107 * Here is an example of typical code to manipulate a file in an
1108 * application's shared storage:
1109 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001110 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1111 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001112 * <p>
1113 * If you supply a non-null <var>type</var> to this function, the returned
1114 * file will be a path to a sub-directory of the given type. Though these
1115 * files are not automatically scanned by the media scanner, you can
1116 * explicitly add them to the media database with
1117 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1118 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001119 * {@link android.os.Environment#getExternalStoragePublicDirectory
1120 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001121 * directories of media shared by all applications. The directories returned
1122 * here are owned by the application, and their contents will be removed
1123 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001124 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001125 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1126 * here will be automatically created for you.
1127 * <p>
1128 * Here is an example of typical code to manipulate a picture in an
1129 * application's shared storage and add it to the media database:
1130 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001131 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1132 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001133 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001134 * @param type The type of files directory to return. May be {@code null}
1135 * for the root of the files directory or one of the following
1136 * constants for a subdirectory:
1137 * {@link android.os.Environment#DIRECTORY_MUSIC},
1138 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1139 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1140 * {@link android.os.Environment#DIRECTORY_ALARMS},
1141 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1142 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1143 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1144 * @return the absolute path to application-specific directory. May return
1145 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001146 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001147 * @see #getExternalFilesDirs(String)
1148 * @see Environment#getExternalStorageState(File)
1149 * @see Environment#isExternalStorageEmulated(File)
1150 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001151 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001152 @Nullable
1153 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001154
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001155 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001156 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001157 * shared/external storage devices where the application can place
1158 * persistent files it owns. These files are internal to the application,
1159 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001160 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001161 * This is like {@link #getFilesDir()} in that these files will be deleted
1162 * when the application is uninstalled, however there are some important
1163 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001164 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001165 * <li>Shared storage may not always be available, since removable media can
1166 * be ejected by the user. Media state can be checked using
1167 * {@link Environment#getExternalStorageState(File)}.
1168 * <li>There is no security enforced with these files. For example, any
1169 * application holding
1170 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1171 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001172 * </ul>
1173 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001174 * If a shared storage device is emulated (as determined by
1175 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1176 * backed by a private user data partition, which means there is little
1177 * benefit to storing data here instead of the private directories returned
1178 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001179 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001180 * Shared storage devices returned here are considered a stable part of the
1181 * device, including physical media slots under a protective cover. The
1182 * returned paths do not include transient devices, such as USB flash drives
1183 * connected to handheld devices.
1184 * <p>
1185 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001186 * example, an app may choose to store large files on the device with the
1187 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001188 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001189 * No additional permissions are required for the calling app to read or
1190 * write files under the returned path. Write access outside of these paths
1191 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001192 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001193 * The returned path may change over time if different shared storage media
1194 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001195 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001196 * @param type The type of files directory to return. May be {@code null}
1197 * for the root of the files directory or one of the following
1198 * constants for a subdirectory:
1199 * {@link android.os.Environment#DIRECTORY_MUSIC},
1200 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1201 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1202 * {@link android.os.Environment#DIRECTORY_ALARMS},
1203 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1204 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1205 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1206 * @return the absolute paths to application-specific directories. Some
1207 * individual paths may be {@code null} if that shared storage is
1208 * not currently available. The first path returned is the same as
1209 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001210 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001211 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001212 * @see Environment#isExternalStorageEmulated(File)
1213 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001214 */
1215 public abstract File[] getExternalFilesDirs(String type);
1216
1217 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001218 * Return the primary shared/external storage directory where this
1219 * application's OBB files (if there are any) can be found. Note if the
1220 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001221 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001222 * This is like {@link #getFilesDir()} in that these files will be deleted
1223 * when the application is uninstalled, however there are some important
1224 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001225 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001226 * <li>Shared storage may not always be available, since removable media can
1227 * be ejected by the user. Media state can be checked using
1228 * {@link Environment#getExternalStorageState(File)}.
1229 * <li>There is no security enforced with these files. For example, any
1230 * application holding
1231 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001232 * these files.
1233 * </ul>
1234 * <p>
1235 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001236 * are required to read or write to the path that this method returns.
1237 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1238 * to read the OBB expansion files, you must declare the
1239 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1240 * permission at runtime as follows:
1241 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001242 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001243 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1244 * android:maxSdkVersion="23" />}
1245 * </p>
1246 * <p>
1247 * Starting from {@link android.os.Build.VERSION_CODES#N},
1248 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1249 * permission is not required, so don’t ask for this
1250 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1251 * and if it fails, you must request
1252 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1253 * </p>
1254 *
1255 * <p>
1256 * The following code snippet shows how to do this:
1257 * </p>
1258 *
1259 * <pre>
1260 * File obb = new File(obb_filename);
1261 * boolean open_failed = false;
1262 *
1263 * try {
1264 * BufferedReader br = new BufferedReader(new FileReader(obb));
1265 * open_failed = false;
1266 * ReadObbFile(br);
1267 * } catch (IOException e) {
1268 * open_failed = true;
1269 * }
1270 *
1271 * if (open_failed) {
1272 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1273 * ReadObbFileWithPermission();
1274 * }
1275 * </pre>
1276 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001277 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001278 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001279 * should ensure that multiple instances running under different users don't
1280 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001281 *
1282 * @return the absolute path to application-specific directory. May return
1283 * {@code null} if shared storage is not currently available.
1284 * @see #getObbDirs()
1285 * @see Environment#getExternalStorageState(File)
1286 * @see Environment#isExternalStorageEmulated(File)
1287 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001288 */
1289 public abstract File getObbDir();
1290
1291 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001292 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001293 * shared/external storage devices where the application's OBB files (if
1294 * there are any) can be found. Note if the application does not have any
1295 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001296 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001297 * This is like {@link #getFilesDir()} in that these files will be deleted
1298 * when the application is uninstalled, however there are some important
1299 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001300 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001301 * <li>Shared storage may not always be available, since removable media can
1302 * be ejected by the user. Media state can be checked using
1303 * {@link Environment#getExternalStorageState(File)}.
1304 * <li>There is no security enforced with these files. For example, any
1305 * application holding
1306 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1307 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001308 * </ul>
1309 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001310 * Shared storage devices returned here are considered a stable part of the
1311 * device, including physical media slots under a protective cover. The
1312 * returned paths do not include transient devices, such as USB flash drives
1313 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001314 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001315 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001316 * example, an app may choose to store large files on the device with the
1317 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001318 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001319 * No additional permissions are required for the calling app to read or
1320 * write files under the returned path. Write access outside of these paths
1321 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001322 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001323 * @return the absolute paths to application-specific directories. Some
1324 * individual paths may be {@code null} if that shared storage is
1325 * not currently available. The first path returned is the same as
1326 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001327 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001328 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001329 * @see Environment#isExternalStorageEmulated(File)
1330 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001331 */
1332 public abstract File[] getObbDirs();
1333
1334 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001335 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001336 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001337 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001338 * The system will automatically delete files in this directory as disk
1339 * space is needed elsewhere on the device. The system will always delete
1340 * older files first, as reported by {@link File#lastModified()}. If
1341 * desired, you can exert more control over how files are deleted using
1342 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1343 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1344 * <p>
1345 * Apps are strongly encouraged to keep their usage of cache space below the
1346 * quota returned by
1347 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1348 * goes above this quota, your cached files will be some of the first to be
1349 * deleted when additional disk space is needed. Conversely, if your app
1350 * stays under this quota, your cached files will be some of the last to be
1351 * deleted when additional disk space is needed.
1352 * <p>
1353 * Note that your cache quota will change over time depending on how
1354 * frequently the user interacts with your app, and depending on how much
1355 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001356 * <p>
1357 * The returned path may change over time if the calling app is moved to an
1358 * adopted storage device, so only relative paths should be persisted.
1359 * <p>
1360 * Apps require no extra permissions to read or write to the returned path,
1361 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001362 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001363 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001364 * @see #openFileOutput
1365 * @see #getFileStreamPath
1366 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001367 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001368 */
1369 public abstract File getCacheDir();
1370
1371 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001372 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001373 * the filesystem designed for storing cached code.
1374 * <p>
1375 * The system will delete any files stored in this location both when your
1376 * specific application is upgraded, and when the entire platform is
1377 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001378 * <p>
1379 * This location is optimal for storing compiled or optimized code generated
1380 * by your application at runtime.
1381 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001382 * The returned path may change over time if the calling app is moved to an
1383 * adopted storage device, so only relative paths should be persisted.
1384 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001385 * Apps require no extra permissions to read or write to the returned path,
1386 * since this path lives in their private storage.
1387 *
1388 * @return The path of the directory holding application code cache files.
1389 */
1390 public abstract File getCodeCacheDir();
1391
1392 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001393 * Returns absolute path to application-specific directory on the primary
1394 * shared/external storage device where the application can place cache
1395 * files it owns. These files are internal to the application, and not
1396 * typically visible to the user as media.
1397 * <p>
1398 * This is like {@link #getCacheDir()} in that these files will be deleted
1399 * when the application is uninstalled, however there are some important
1400 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001401 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001402 * <li>The platform does not always monitor the space available in shared
1403 * storage, and thus may not automatically delete these files. Apps should
1404 * always manage the maximum space used in this location. Currently the only
1405 * time files here will be deleted by the platform is when running on
1406 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1407 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1408 * <li>Shared storage may not always be available, since removable media can
1409 * be ejected by the user. Media state can be checked using
1410 * {@link Environment#getExternalStorageState(File)}.
1411 * <li>There is no security enforced with these files. For example, any
1412 * application holding
1413 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001414 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001415 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001416 * <p>
1417 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001418 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001419 * backed by a private user data partition, which means there is little
1420 * benefit to storing data here instead of the private directory returned by
1421 * {@link #getCacheDir()}.
1422 * <p>
1423 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001424 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001425 * accessible to the calling app. This only applies to paths generated for
1426 * package name of the calling application. To access paths belonging to
1427 * other packages,
1428 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1429 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1430 * <p>
1431 * On devices with multiple users (as described by {@link UserManager}),
1432 * each user has their own isolated shared storage. Applications only have
1433 * access to the shared storage for the user they're running as.
1434 * <p>
1435 * The returned path may change over time if different shared storage media
1436 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001437 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001438 * @return the absolute path to application-specific directory. May return
1439 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001440 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001441 * @see #getExternalCacheDirs()
1442 * @see Environment#getExternalStorageState(File)
1443 * @see Environment#isExternalStorageEmulated(File)
1444 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001445 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001446 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001447 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001448
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001449 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001450 * Returns absolute path to application-specific directory in the preloaded cache.
1451 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1452 * There is no guarantee when these files will be deleted.
1453 * @hide
1454 */
1455 @Nullable
1456 @SystemApi
1457 public abstract File getPreloadsFileCache();
1458
1459 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001460 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001461 * shared/external storage devices where the application can place cache
1462 * files it owns. These files are internal to the application, and not
1463 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001464 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001465 * This is like {@link #getCacheDir()} in that these files will be deleted
1466 * when the application is uninstalled, however there are some important
1467 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001468 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001469 * <li>The platform does not always monitor the space available in shared
1470 * storage, and thus may not automatically delete these files. Apps should
1471 * always manage the maximum space used in this location. Currently the only
1472 * time files here will be deleted by the platform is when running on
1473 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1474 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1475 * <li>Shared storage may not always be available, since removable media can
1476 * be ejected by the user. Media state can be checked using
1477 * {@link Environment#getExternalStorageState(File)}.
1478 * <li>There is no security enforced with these files. For example, any
1479 * application holding
1480 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1481 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001482 * </ul>
1483 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001484 * If a shared storage device is emulated (as determined by
1485 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1486 * backed by a private user data partition, which means there is little
1487 * benefit to storing data here instead of the private directory returned by
1488 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001489 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001490 * Shared storage devices returned here are considered a stable part of the
1491 * device, including physical media slots under a protective cover. The
1492 * returned paths do not include transient devices, such as USB flash drives
1493 * connected to handheld devices.
1494 * <p>
1495 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001496 * example, an app may choose to store large files on the device with the
1497 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001498 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001499 * No additional permissions are required for the calling app to read or
1500 * write files under the returned path. Write access outside of these paths
1501 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001502 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001503 * The returned paths may change over time if different shared storage media
1504 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001505 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001506 * @return the absolute paths to application-specific directories. Some
1507 * individual paths may be {@code null} if that shared storage is
1508 * not currently available. The first path returned is the same as
1509 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001510 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001511 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001512 * @see Environment#isExternalStorageEmulated(File)
1513 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001514 */
1515 public abstract File[] getExternalCacheDirs();
1516
1517 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001518 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001519 * shared/external storage devices where the application can place media
1520 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001521 * {@link MediaStore}.
1522 * <p>
1523 * This is like {@link #getExternalFilesDirs} in that these files will be
1524 * deleted when the application is uninstalled, however there are some
1525 * important differences:
1526 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001527 * <li>Shared storage may not always be available, since removable media can
1528 * be ejected by the user. Media state can be checked using
1529 * {@link Environment#getExternalStorageState(File)}.
1530 * <li>There is no security enforced with these files. For example, any
1531 * application holding
1532 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1533 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001534 * </ul>
1535 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001536 * Shared storage devices returned here are considered a stable part of the
1537 * device, including physical media slots under a protective cover. The
1538 * returned paths do not include transient devices, such as USB flash drives
1539 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001540 * <p>
1541 * An application may store data on any or all of the returned devices. For
1542 * example, an app may choose to store large files on the device with the
1543 * most available space, as measured by {@link StatFs}.
1544 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001545 * No additional permissions are required for the calling app to read or
1546 * write files under the returned path. Write access outside of these paths
1547 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001548 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001549 * The returned paths may change over time if different shared storage media
1550 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001551 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001552 * @return the absolute paths to application-specific directories. Some
1553 * individual paths may be {@code null} if that shared storage is
1554 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001555 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001556 * @see Environment#isExternalStorageEmulated(File)
1557 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001558 */
1559 public abstract File[] getExternalMediaDirs();
1560
1561 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001562 * Returns an array of strings naming the private files associated with
1563 * this Context's application package.
1564 *
1565 * @return Array of strings naming the private files.
1566 *
1567 * @see #openFileInput
1568 * @see #openFileOutput
1569 * @see #deleteFile
1570 */
1571 public abstract String[] fileList();
1572
1573 /**
1574 * Retrieve, creating if needed, a new directory in which the application
1575 * can place its own custom data files. You can use the returned File
1576 * object to create and access files in this directory. Note that files
1577 * created through a File object will only be accessible by your own
1578 * application; you can only set the mode of the entire directory, not
1579 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001580 * <p>
1581 * The returned path may change over time if the calling app is moved to an
1582 * adopted storage device, so only relative paths should be persisted.
1583 * <p>
1584 * Apps require no extra permissions to read or write to the returned path,
1585 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001587 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001588 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001589 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001590 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001591 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001592 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 *
1594 * @see #openFileOutput(String, int)
1595 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001596 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597
1598 /**
1599 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001600 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001601 *
1602 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001603 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001605 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001606 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001607 * @throws android.database.sqlite.SQLiteException if the database file
1608 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001610 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001611 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 * @see #deleteDatabase
1613 */
1614 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001615 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616
1617 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001618 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001619 * application package. Creates the database file if it doesn't exist.
1620 * <p>
1621 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1622 * to be used to handle corruption when sqlite reports database corruption.
1623 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001624 *
1625 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001626 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001627 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001628 * cursor when query is called.
1629 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1630 * sqlite reports database corruption. if null,
1631 * {@link android.database.DefaultDatabaseErrorHandler} is
1632 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001633 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001634 * @throws android.database.sqlite.SQLiteException if the database file
1635 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001636 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001637 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001638 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001639 * @see #deleteDatabase
1640 */
1641 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001642 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001643 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001644
1645 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001646 * Move an existing database file from the given source storage context to
1647 * this context. This is typically used to migrate data between storage
1648 * locations after an upgrade, such as migrating to device protected
1649 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001650 * <p>
1651 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001652 *
1653 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001654 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001655 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001656 * @return {@code true} if the move was successful or if the database didn't
1657 * exist in the source context, otherwise {@code false}.
1658 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001659 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001660 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1661
Jeff Sharkey35871f22016-01-29 17:13:29 -07001662 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 * Delete an existing private SQLiteDatabase associated with this Context's
1664 * application package.
1665 *
1666 * @param name The name (unique in the application package) of the
1667 * database.
1668 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001669 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 *
1671 * @see #openOrCreateDatabase
1672 */
1673 public abstract boolean deleteDatabase(String name);
1674
1675 /**
1676 * Returns the absolute path on the filesystem where a database created with
1677 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001678 * <p>
1679 * The returned path may change over time if the calling app is moved to an
1680 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 *
1682 * @param name The name of the database for which you would like to get
1683 * its path.
1684 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001685 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001686 *
1687 * @see #openOrCreateDatabase
1688 */
1689 public abstract File getDatabasePath(String name);
1690
1691 /**
1692 * Returns an array of strings naming the private databases associated with
1693 * this Context's application package.
1694 *
1695 * @return Array of strings naming the private databases.
1696 *
1697 * @see #openOrCreateDatabase
1698 * @see #deleteDatabase
1699 */
1700 public abstract String[] databaseList();
1701
1702 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001703 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001704 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001706 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 public abstract Drawable getWallpaper();
1708
1709 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001710 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001711 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001712 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001713 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001714 public abstract Drawable peekWallpaper();
1715
1716 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001717 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1718 * WallpaperManager.getDesiredMinimumWidth()} instead.
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 int getWallpaperDesiredMinimumWidth();
1722
1723 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001724 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1725 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001727 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 public abstract int getWallpaperDesiredMinimumHeight();
1729
1730 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001731 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001732 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001733 * <p>This method requires the caller to hold the permission
1734 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001736 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001737 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1738
1739 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001740 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001741 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001742 * <p>This method requires the caller to hold the permission
1743 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001744 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001745 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001746 public abstract void setWallpaper(InputStream data) throws IOException;
1747
1748 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001749 * @deprecated Use {@link android.app.WallpaperManager#clear
1750 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001751 * <p>This method requires the caller to hold the permission
1752 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001753 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001754 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001755 public abstract void clearWallpaper() throws IOException;
1756
1757 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001758 * Same as {@link #startActivity(Intent, Bundle)} with no options
1759 * specified.
1760 *
1761 * @param intent The description of the activity to start.
1762 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001763 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001764 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001765 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001766 * @see PackageManager#resolveActivity
1767 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001768 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001769
1770 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001771 * Version of {@link #startActivity(Intent)} that allows you to specify the
1772 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001773 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001774 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001775 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001776 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001777 * @hide
1778 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001779 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07001780 @SystemApi
Adrian Roosebc927c2019-02-28 16:21:18 +01001781 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1782 @NonNull UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001783 throw new RuntimeException("Not implemented. Must override in a subclass.");
1784 }
1785
1786 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 * Launch a new activity. You will not receive any information about when
1788 * the activity exits.
1789 *
1790 * <p>Note that if this method is being called from outside of an
1791 * {@link android.app.Activity} Context, then the Intent must include
1792 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1793 * without being started from an existing Activity, there is no existing
1794 * task in which to place the new activity and thus it needs to be placed
1795 * in its own separate task.
1796 *
1797 * <p>This method throws {@link ActivityNotFoundException}
1798 * if there was no Activity found to run the given Intent.
1799 *
1800 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001801 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001802 * May be null if there are no options. See {@link android.app.ActivityOptions}
1803 * for how to build the Bundle supplied here; there are no supported definitions
1804 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001806 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 *
Scott Main60dd5202012-06-23 00:01:22 -07001808 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 * @see PackageManager#resolveActivity
1810 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001811 public abstract void startActivity(@RequiresPermission Intent intent,
1812 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001813
1814 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001815 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1816 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001817 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001818 * @param intent The description of the activity to start.
1819 * @param options Additional options for how the Activity should be started.
1820 * May be null if there are no options. See {@link android.app.ActivityOptions}
1821 * for how to build the Bundle supplied here; there are no supported definitions
1822 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001823 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001824 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001825 * @hide
1826 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001827 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001828 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001829 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1830 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001831 throw new RuntimeException("Not implemented. Must override in a subclass.");
1832 }
1833
1834 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001835 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1836 * is only supported for Views and Fragments.
1837 * @param who The identifier for the calling element that will receive the result.
1838 * @param intent The intent to start.
1839 * @param requestCode The code that will be returned with onActivityResult() identifying this
1840 * request.
1841 * @param options Additional options for how the Activity should be started.
1842 * May be null if there are no options. See {@link android.app.ActivityOptions}
1843 * for how to build the Bundle supplied here; there are no supported definitions
1844 * for building it manually.
1845 * @hide
1846 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001847 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001848 public void startActivityForResult(
1849 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1850 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1851 + "Check canStartActivityForResult() before calling.");
1852 }
1853
1854 /**
1855 * Identifies whether this Context instance will be able to process calls to
1856 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1857 * @hide
1858 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001859 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001860 public boolean canStartActivityForResult() {
1861 return false;
1862 }
1863
1864 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001865 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1866 * specified.
1867 *
1868 * @param intents An array of Intents to be started.
1869 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001870 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001871 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001872 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001873 * @see PackageManager#resolveActivity
1874 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001875 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001876
1877 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001878 * Launch multiple new activities. This is generally the same as calling
1879 * {@link #startActivity(Intent)} for the first Intent in the array,
1880 * that activity during its creation calling {@link #startActivity(Intent)}
1881 * for the second entry, etc. Note that unlike that approach, generally
1882 * none of the activities except the last in the array will be created
1883 * at this point, but rather will be created when the user first visits
1884 * them (due to pressing back from the activity on top).
1885 *
1886 * <p>This method throws {@link ActivityNotFoundException}
1887 * if there was no Activity found for <em>any</em> given Intent. In this
1888 * case the state of the activity stack is undefined (some Intents in the
1889 * list may be on it, some not), so you probably want to avoid such situations.
1890 *
1891 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001892 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001893 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001894 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001895 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001896 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001897 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001898 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001899 * @see PackageManager#resolveActivity
1900 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001901 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001902
1903 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001904 * @hide
1905 * Launch multiple new activities. This is generally the same as calling
1906 * {@link #startActivity(Intent)} for the first Intent in the array,
1907 * that activity during its creation calling {@link #startActivity(Intent)}
1908 * for the second entry, etc. Note that unlike that approach, generally
1909 * none of the activities except the last in the array will be created
1910 * at this point, but rather will be created when the user first visits
1911 * them (due to pressing back from the activity on top).
1912 *
1913 * <p>This method throws {@link ActivityNotFoundException}
1914 * if there was no Activity found for <em>any</em> given Intent. In this
1915 * case the state of the activity stack is undefined (some Intents in the
1916 * list may be on it, some not), so you probably want to avoid such situations.
1917 *
1918 * @param intents An array of Intents to be started.
1919 * @param options Additional options for how the Activity should be started.
1920 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001921 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001922 * Context.startActivity(Intent, Bundle)} for more details.
1923 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001924 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1925 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1926 * successful.
1927 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001928 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001929 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001930 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001931 * @see PackageManager#resolveActivity
1932 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001933 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001934 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001935 throw new RuntimeException("Not implemented. Must override in a subclass.");
1936 }
1937
1938 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001939 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1940 * with no options specified.
1941 *
1942 * @param intent The IntentSender to launch.
1943 * @param fillInIntent If non-null, this will be provided as the
1944 * intent parameter to {@link IntentSender#sendIntent}.
1945 * @param flagsMask Intent flags in the original IntentSender that you
1946 * would like to change.
1947 * @param flagsValues Desired values for any bits set in
1948 * <var>flagsMask</var>
1949 * @param extraFlags Always set to 0.
1950 *
1951 * @see #startActivity(Intent)
1952 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1953 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001954 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1955 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1956 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001957
1958 /**
1959 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001960 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001961 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001962 * here; otherwise, its associated action will be executed (such as
1963 * sending a broadcast) as if you had called
1964 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001965 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001966 * @param intent The IntentSender to launch.
1967 * @param fillInIntent If non-null, this will be provided as the
1968 * intent parameter to {@link IntentSender#sendIntent}.
1969 * @param flagsMask Intent flags in the original IntentSender that you
1970 * would like to change.
1971 * @param flagsValues Desired values for any bits set in
1972 * <var>flagsMask</var>
1973 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001974 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001975 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001976 * Context.startActivity(Intent, Bundle)} for more details. If options
1977 * have also been supplied by the IntentSender, options given here will
1978 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001979 *
1980 * @see #startActivity(Intent, Bundle)
1981 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001982 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001983 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1984 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1985 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001986
1987 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 * Broadcast the given intent to all interested BroadcastReceivers. This
1989 * call is asynchronous; it returns immediately, and you will continue
1990 * executing while the receivers are run. No results are propagated from
1991 * receivers and receivers can not abort the broadcast. If you want
1992 * to allow receivers to propagate results or abort the broadcast, you must
1993 * send an ordered broadcast using
1994 * {@link #sendOrderedBroadcast(Intent, String)}.
1995 *
1996 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1997 *
1998 * @param intent The Intent to broadcast; all receivers matching this
1999 * Intent will receive the broadcast.
2000 *
2001 * @see android.content.BroadcastReceiver
2002 * @see #registerReceiver
2003 * @see #sendBroadcast(Intent, String)
2004 * @see #sendOrderedBroadcast(Intent, String)
2005 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2006 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002007 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002008
2009 /**
2010 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2011 * an optional required permission to be enforced. This
2012 * call is asynchronous; it returns immediately, and you will continue
2013 * executing while the receivers are run. No results are propagated from
2014 * receivers and receivers can not abort the broadcast. If you want
2015 * to allow receivers to propagate results or abort the broadcast, you must
2016 * send an ordered broadcast using
2017 * {@link #sendOrderedBroadcast(Intent, String)}.
2018 *
2019 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2020 *
2021 * @param intent The Intent to broadcast; all receivers matching this
2022 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08002023 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 * a receiver must hold in order to receive your broadcast.
2025 * If null, no permission is required.
2026 *
2027 * @see android.content.BroadcastReceiver
2028 * @see #registerReceiver
2029 * @see #sendBroadcast(Intent)
2030 * @see #sendOrderedBroadcast(Intent, String)
2031 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2032 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002033 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002034 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002035
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002036
2037 /**
2038 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2039 * an array of required permissions to be enforced. This call is asynchronous; it returns
2040 * immediately, and you will continue executing while the receivers are run. No results are
2041 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2042 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2043 * using {@link #sendOrderedBroadcast(Intent, String)}.
2044 *
2045 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2046 *
2047 * @param intent The Intent to broadcast; all receivers matching this
2048 * Intent will receive the broadcast.
2049 * @param receiverPermissions Array of names of permissions that a receiver must hold
2050 * in order to receive your broadcast.
2051 * If null or empty, no permissions are required.
2052 *
2053 * @see android.content.BroadcastReceiver
2054 * @see #registerReceiver
2055 * @see #sendBroadcast(Intent)
2056 * @see #sendOrderedBroadcast(Intent, String)
2057 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2058 * @hide
2059 */
2060 public abstract void sendBroadcastMultiplePermissions(Intent intent,
2061 String[] receiverPermissions);
2062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002064 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07002065 * an array of required permissions to be enforced. This call is asynchronous; it returns
2066 * immediately, and you will continue executing while the receivers are run. No results are
2067 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2068 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2069 * using {@link #sendOrderedBroadcast(Intent, String)}.
2070 *
2071 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2072 *
2073 * @param intent The Intent to broadcast; all receivers matching this
2074 * Intent will receive the broadcast.
2075 * @param user The user to send the broadcast to.
2076 * @param receiverPermissions Array of names of permissions that a receiver must hold
2077 * in order to receive your broadcast.
2078 * If null or empty, no permissions are required.
2079 *
2080 * @see android.content.BroadcastReceiver
2081 * @see #registerReceiver
2082 * @see #sendBroadcast(Intent)
2083 * @see #sendOrderedBroadcast(Intent, String)
2084 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2085 * @hide
2086 */
2087 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2088 String[] receiverPermissions);
2089
2090 /**
2091 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002092 * an optional required permission to be enforced. This
2093 * call is asynchronous; it returns immediately, and you will continue
2094 * executing while the receivers are run. No results are propagated from
2095 * receivers and receivers can not abort the broadcast. If you want
2096 * to allow receivers to propagate results or abort the broadcast, you must
2097 * send an ordered broadcast using
2098 * {@link #sendOrderedBroadcast(Intent, String)}.
2099 *
2100 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2101 *
2102 * @param intent The Intent to broadcast; all receivers matching this
2103 * Intent will receive the broadcast.
2104 * @param receiverPermission (optional) String naming a permission that
2105 * a receiver must hold in order to receive your broadcast.
2106 * If null, no permission is required.
2107 * @param options (optional) Additional sending options, generated from a
2108 * {@link android.app.BroadcastOptions}.
2109 *
2110 * @see android.content.BroadcastReceiver
2111 * @see #registerReceiver
2112 * @see #sendBroadcast(Intent)
2113 * @see #sendOrderedBroadcast(Intent, String)
2114 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2115 * @hide
2116 */
2117 @SystemApi
2118 public abstract void sendBroadcast(Intent intent,
2119 @Nullable String receiverPermission,
2120 @Nullable Bundle options);
2121
2122 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002123 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002124 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002125 * @hide
2126 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002127 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002128 public abstract void sendBroadcast(Intent intent,
2129 String receiverPermission, int appOp);
2130
2131 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2133 * them one at a time to allow more preferred receivers to consume the
2134 * broadcast before it is delivered to less preferred receivers. This
2135 * call is asynchronous; it returns immediately, and you will continue
2136 * executing while the receivers are run.
2137 *
2138 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2139 *
2140 * @param intent The Intent to broadcast; all receivers matching this
2141 * Intent will receive the broadcast.
2142 * @param receiverPermission (optional) String naming a permissions that
2143 * a receiver must hold in order to receive your broadcast.
2144 * If null, no permission is required.
2145 *
2146 * @see android.content.BroadcastReceiver
2147 * @see #registerReceiver
2148 * @see #sendBroadcast(Intent)
2149 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2150 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002151 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002152 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153
2154 /**
2155 * Version of {@link #sendBroadcast(Intent)} that allows you to
2156 * receive data back from the broadcast. This is accomplished by
2157 * supplying your own BroadcastReceiver when calling, which will be
2158 * treated as a final receiver at the end of the broadcast -- its
2159 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002160 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002161 * be serialized in the same way as calling
2162 * {@link #sendOrderedBroadcast(Intent, String)}.
2163 *
2164 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2165 * asynchronous; it will return before
2166 * resultReceiver.onReceive() is called.
2167 *
2168 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2169 *
2170 * @param intent The Intent to broadcast; all receivers matching this
2171 * Intent will receive the broadcast.
2172 * @param receiverPermission String naming a permissions that
2173 * a receiver must hold in order to receive your broadcast.
2174 * If null, no permission is required.
2175 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2176 * receiver of the broadcast.
2177 * @param scheduler A custom Handler with which to schedule the
2178 * resultReceiver callback; if null it will be
2179 * scheduled in the Context's main thread.
2180 * @param initialCode An initial value for the result code. Often
2181 * Activity.RESULT_OK.
2182 * @param initialData An initial value for the result data. Often
2183 * null.
2184 * @param initialExtras An initial value for the result extras. Often
2185 * null.
2186 *
2187 * @see #sendBroadcast(Intent)
2188 * @see #sendBroadcast(Intent, String)
2189 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 * @see android.content.BroadcastReceiver
2191 * @see #registerReceiver
2192 * @see android.app.Activity#RESULT_OK
2193 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002194 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002195 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002196 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2197 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002198
2199 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002200 * Version of {@link #sendBroadcast(Intent)} that allows you to
2201 * receive data back from the broadcast. This is accomplished by
2202 * supplying your own BroadcastReceiver when calling, which will be
2203 * treated as a final receiver at the end of the broadcast -- its
2204 * {@link BroadcastReceiver#onReceive} method will be called with
2205 * the result values collected from the other receivers. The broadcast will
2206 * be serialized in the same way as calling
2207 * {@link #sendOrderedBroadcast(Intent, String)}.
2208 *
2209 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2210 * asynchronous; it will return before
2211 * resultReceiver.onReceive() is called.
2212 *
2213 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2214 *
2215 *
2216 * @param intent The Intent to broadcast; all receivers matching this
2217 * Intent will receive the broadcast.
2218 * @param receiverPermission String naming a permissions that
2219 * a receiver must hold in order to receive your broadcast.
2220 * If null, no permission is required.
2221 * @param options (optional) Additional sending options, generated from a
2222 * {@link android.app.BroadcastOptions}.
2223 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2224 * receiver of the broadcast.
2225 * @param scheduler A custom Handler with which to schedule the
2226 * resultReceiver callback; if null it will be
2227 * scheduled in the Context's main thread.
2228 * @param initialCode An initial value for the result code. Often
2229 * Activity.RESULT_OK.
2230 * @param initialData An initial value for the result data. Often
2231 * null.
2232 * @param initialExtras An initial value for the result extras. Often
2233 * null.
2234 * @see #sendBroadcast(Intent)
2235 * @see #sendBroadcast(Intent, String)
2236 * @see #sendOrderedBroadcast(Intent, String)
2237 * @see android.content.BroadcastReceiver
2238 * @see #registerReceiver
2239 * @see android.app.Activity#RESULT_OK
2240 * @hide
2241 */
2242 @SystemApi
2243 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2244 @Nullable String receiverPermission, @Nullable Bundle options,
2245 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2246 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2247
2248 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002249 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2250 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002251 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002252 * @hide
2253 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002254 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002255 public abstract void sendOrderedBroadcast(Intent intent,
2256 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2257 Handler scheduler, int initialCode, String initialData,
2258 Bundle initialExtras);
2259
2260 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002261 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2262 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002263 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002264 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002265 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002266 * @see #sendBroadcast(Intent)
2267 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002268 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002269 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2270 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002271
2272 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002273 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2274 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002275 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002276 *
2277 * @param intent The Intent to broadcast; all receivers matching this
2278 * Intent will receive the broadcast.
2279 * @param user UserHandle to send the intent to.
2280 * @param receiverPermission (optional) String naming a permission that
2281 * a receiver must hold in order to receive your broadcast.
2282 * If null, no permission is required.
2283 *
2284 * @see #sendBroadcast(Intent, String)
2285 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002286 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002287 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2288 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002289
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002290 /**
2291 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2292 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002293 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002294 *
2295 * @param intent The Intent to broadcast; all receivers matching this
2296 * Intent will receive the broadcast.
2297 * @param user UserHandle to send the intent to.
2298 * @param receiverPermission (optional) String naming a permission that
2299 * a receiver must hold in order to receive your broadcast.
2300 * If null, no permission is required.
2301 * @param options (optional) Additional sending options, generated from a
2302 * {@link android.app.BroadcastOptions}.
2303 *
2304 * @see #sendBroadcast(Intent, String, Bundle)
2305 * @hide
2306 */
2307 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002308 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002309 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2310 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002311
2312 /**
2313 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2314 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002315 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002316 *
2317 * @param intent The Intent to broadcast; all receivers matching this
2318 * Intent will receive the broadcast.
2319 * @param user UserHandle to send the intent to.
2320 * @param receiverPermission (optional) String naming a permission that
2321 * a receiver must hold in order to receive your broadcast.
2322 * If null, no permission is required.
2323 * @param appOp The app op associated with the broadcast.
2324 *
2325 * @see #sendBroadcast(Intent, String)
2326 *
2327 * @hide
2328 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002329 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002330 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002331 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2332 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002333
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002334 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002335 * Version of
2336 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2337 * that allows you to specify the
2338 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002339 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002340 *
2341 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2342 *
2343 * @param intent The Intent to broadcast; all receivers matching this
2344 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002345 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002346 * @param receiverPermission String naming a permissions that
2347 * a receiver must hold in order to receive your broadcast.
2348 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002349 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2350 * receiver of the broadcast.
2351 * @param scheduler A custom Handler with which to schedule the
2352 * resultReceiver callback; if null it will be
2353 * scheduled in the Context's main thread.
2354 * @param initialCode An initial value for the result code. Often
2355 * Activity.RESULT_OK.
2356 * @param initialData An initial value for the result data. Often
2357 * null.
2358 * @param initialExtras An initial value for the result extras. Often
2359 * null.
2360 *
2361 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2362 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002363 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002364 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2365 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002366 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2367 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002368
2369 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002370 * Similar to above but takes an appOp as well, to enforce restrictions.
2371 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2372 * BroadcastReceiver, Handler, int, String, Bundle)
2373 * @hide
2374 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002375 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002376 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002377 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2378 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2379 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2380 @Nullable Bundle initialExtras);
2381
2382 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002383 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2384 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2385 * BroadcastReceiver, Handler, int, String, Bundle)
2386 * @hide
2387 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002388 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002389 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002390 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2391 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2392 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2393 @Nullable String initialData, @Nullable Bundle initialExtras);
2394
2395 /**
Jordan Liua32e6fc2019-10-29 10:33:55 -07002396 * Version of
2397 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2398 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2399 * the broadcast will be sent to.
2400 *
2401 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2402 *
2403 * @param intent The Intent to broadcast; all receivers matching this
2404 * Intent will receive the broadcast.
2405 * @param receiverPermission String naming a permissions that
2406 * a receiver must hold in order to receive your broadcast.
2407 * If null, no permission is required.
2408 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2409 * required. If both receiverAppOp and receiverPermission are non-null,
2410 * a receiver must have both of them to
2411 * 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 #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2425 */
2426 public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2427 @Nullable String receiverPermission, @Nullable String receiverAppOp,
2428 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2429 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras) {
2430 throw new RuntimeException("Not implemented. Must override in a subclass.");
2431 }
2432
2433 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002434 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002435 * Intent you are sending stays around after the broadcast is complete,
2436 * so that others can quickly retrieve that data through the return
2437 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2438 * all other ways, this behaves the same as
2439 * {@link #sendBroadcast(Intent)}.
2440 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002441 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2442 * can access them), no protection (anyone can modify them), and many other problems.
2443 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2444 * has changed, with another mechanism for apps to retrieve the current value whenever
2445 * desired.
2446 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002447 * @param intent The Intent to broadcast; all receivers matching this
2448 * Intent will receive the broadcast, and the Intent will be held to
2449 * be re-broadcast to future receivers.
2450 *
2451 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002452 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002453 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002454 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002455 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002456 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002457
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002458 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002459 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002460 * receive data back from the broadcast. This is accomplished by
2461 * supplying your own BroadcastReceiver when calling, which will be
2462 * treated as a final receiver at the end of the broadcast -- its
2463 * {@link BroadcastReceiver#onReceive} method will be called with
2464 * the result values collected from the other receivers. The broadcast will
2465 * be serialized in the same way as calling
2466 * {@link #sendOrderedBroadcast(Intent, String)}.
2467 *
2468 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2469 * asynchronous; it will return before
2470 * resultReceiver.onReceive() is called. Note that the sticky data
2471 * stored is only the data you initially supply to the broadcast, not
2472 * the result of any changes made by the receivers.
2473 *
2474 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2475 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002476 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2477 * can access them), no protection (anyone can modify them), and many other problems.
2478 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2479 * has changed, with another mechanism for apps to retrieve the current value whenever
2480 * desired.
2481 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002482 * @param intent The Intent to broadcast; all receivers matching this
2483 * Intent will receive the broadcast.
2484 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2485 * receiver of the broadcast.
2486 * @param scheduler A custom Handler with which to schedule the
2487 * resultReceiver callback; if null it will be
2488 * scheduled in the Context's main thread.
2489 * @param initialCode An initial value for the result code. Often
2490 * Activity.RESULT_OK.
2491 * @param initialData An initial value for the result data. Often
2492 * null.
2493 * @param initialExtras An initial value for the result extras. Often
2494 * null.
2495 *
2496 * @see #sendBroadcast(Intent)
2497 * @see #sendBroadcast(Intent, String)
2498 * @see #sendOrderedBroadcast(Intent, String)
2499 * @see #sendStickyBroadcast(Intent)
2500 * @see android.content.BroadcastReceiver
2501 * @see #registerReceiver
2502 * @see android.app.Activity#RESULT_OK
2503 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002504 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002505 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002506 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002507 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002508 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2509 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002511 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002512 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 * so that it is as if the sticky broadcast had never happened.
2514 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002515 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2516 * can access them), no protection (anyone can modify them), and many other problems.
2517 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2518 * has changed, with another mechanism for apps to retrieve the current value whenever
2519 * desired.
2520 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002521 * @param intent The Intent that was previously broadcast.
2522 *
2523 * @see #sendStickyBroadcast
2524 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002525 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002526 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002527 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528
2529 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002530 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002531 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002532 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002533 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002534 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2535 * can access them), no protection (anyone can modify them), and many other problems.
2536 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2537 * has changed, with another mechanism for apps to retrieve the current value whenever
2538 * desired.
2539 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002540 * @param intent The Intent to broadcast; all receivers matching this
2541 * Intent will receive the broadcast, and the Intent will be held to
2542 * be re-broadcast to future receivers.
2543 * @param user UserHandle to send the intent to.
2544 *
2545 * @see #sendBroadcast(Intent)
2546 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002547 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002548 @RequiresPermission(allOf = {
2549 android.Manifest.permission.INTERACT_ACROSS_USERS,
2550 android.Manifest.permission.BROADCAST_STICKY
2551 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002552 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2553 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002554
2555 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002556 * @hide
2557 * This is just here for sending CONNECTIVITY_ACTION.
2558 */
2559 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002560 @RequiresPermission(allOf = {
2561 android.Manifest.permission.INTERACT_ACROSS_USERS,
2562 android.Manifest.permission.BROADCAST_STICKY
2563 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002564 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2565 UserHandle user, Bundle options);
2566
2567 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002568 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002569 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2570 * that allows you to specify the
2571 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002572 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002573 *
2574 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2575 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002576 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2577 * can access them), no protection (anyone can modify them), and many other problems.
2578 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2579 * has changed, with another mechanism for apps to retrieve the current value whenever
2580 * desired.
2581 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002582 * @param intent The Intent to broadcast; all receivers matching this
2583 * Intent will receive the broadcast.
2584 * @param user UserHandle to send the intent to.
2585 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2586 * receiver of the broadcast.
2587 * @param scheduler A custom Handler with which to schedule the
2588 * resultReceiver callback; if null it will be
2589 * scheduled in the Context's main thread.
2590 * @param initialCode An initial value for the result code. Often
2591 * Activity.RESULT_OK.
2592 * @param initialData An initial value for the result data. Often
2593 * null.
2594 * @param initialExtras An initial value for the result extras. Often
2595 * null.
2596 *
2597 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2598 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002599 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002600 @RequiresPermission(allOf = {
2601 android.Manifest.permission.INTERACT_ACROSS_USERS,
2602 android.Manifest.permission.BROADCAST_STICKY
2603 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002604 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002605 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002606 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2607 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002608
2609 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002610 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002611 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002612 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002613 *
2614 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2615 * permission in order to use this API. If you do not hold that
2616 * permission, {@link SecurityException} will be thrown.
2617 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002618 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2619 * can access them), no protection (anyone can modify them), and many other problems.
2620 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2621 * has changed, with another mechanism for apps to retrieve the current value whenever
2622 * desired.
2623 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002624 * @param intent The Intent that was previously broadcast.
2625 * @param user UserHandle to remove the sticky broadcast from.
2626 *
2627 * @see #sendStickyBroadcastAsUser
2628 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002629 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002630 @RequiresPermission(allOf = {
2631 android.Manifest.permission.INTERACT_ACROSS_USERS,
2632 android.Manifest.permission.BROADCAST_STICKY
2633 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002634 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2635 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002636
2637 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002638 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 * <var>receiver</var> will be called with any broadcast Intent that
2640 * matches <var>filter</var>, in the main application thread.
2641 *
2642 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002643 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 * registrations. If your IntentFilter matches one of these sticky
2645 * Intents, that Intent will be returned by this function
2646 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2647 * been broadcast.
2648 *
2649 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2650 * in which case each of these will be sent to <var>receiver</var>. In
2651 * this case, only one of these can be returned directly by the function;
2652 * which of these that is returned is arbitrarily decided by the system.
2653 *
2654 * <p>If you know the Intent your are registering for is sticky, you can
2655 * supply null for your <var>receiver</var>. In this case, no receiver is
2656 * registered -- the function simply returns the sticky Intent that
2657 * matches <var>filter</var>. In the case of multiple matches, the same
2658 * rules as described above apply.
2659 *
2660 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2661 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002662 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2663 * registered with this method will correctly respect the
2664 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2665 * Prior to that, it would be ignored and delivered to all matching registered
2666 * receivers. Be careful if using this for security.</p>
2667 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002668 * <p class="note">Note: this method <em>cannot be called from a
2669 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2670 * that is declared in an application's manifest. It is okay, however, to call
2671 * this method from another BroadcastReceiver that has itself been registered
2672 * at run time with {@link #registerReceiver}, since the lifetime of such a
2673 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 *
2675 * @param receiver The BroadcastReceiver to handle the broadcast.
2676 * @param filter Selects the Intent broadcasts to be received.
2677 *
2678 * @return The first sticky intent found that matches <var>filter</var>,
2679 * or null if there are none.
2680 *
2681 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2682 * @see #sendBroadcast
2683 * @see #unregisterReceiver
2684 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002685 @Nullable
2686 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 IntentFilter filter);
2688
2689 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002690 * Register to receive intent broadcasts, with the receiver optionally being
2691 * exposed to Instant Apps. See
2692 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2693 * information. By default Instant Apps cannot interact with receivers in other
2694 * applications, this allows you to expose a receiver that Instant Apps can
2695 * interact with.
2696 *
2697 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2698 *
2699 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2700 * registered with this method will correctly respect the
2701 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2702 * Prior to that, it would be ignored and delivered to all matching registered
2703 * receivers. Be careful if using this for security.</p>
2704 *
2705 * @param receiver The BroadcastReceiver to handle the broadcast.
2706 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002707 * @param flags Additional options for the receiver. May be 0 or
2708 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002709 *
2710 * @return The first sticky intent found that matches <var>filter</var>,
2711 * or null if there are none.
2712 *
2713 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2714 * @see #sendBroadcast
2715 * @see #unregisterReceiver
2716 */
2717 @Nullable
2718 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2719 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002720 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002721
2722 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002723 * Register to receive intent broadcasts, to run in the context of
2724 * <var>scheduler</var>. See
2725 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2726 * information. This allows you to enforce permissions on who can
2727 * broadcast intents to your receiver, or have the receiver run in
2728 * a different thread than the main application thread.
2729 *
2730 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2731 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002732 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2733 * registered with this method will correctly respect the
2734 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2735 * Prior to that, it would be ignored and delivered to all matching registered
2736 * receivers. Be careful if using this for security.</p>
2737 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002738 * @param receiver The BroadcastReceiver to handle the broadcast.
2739 * @param filter Selects the Intent broadcasts to be received.
2740 * @param broadcastPermission String naming a permissions that a
2741 * broadcaster must hold in order to send an Intent to you. If null,
2742 * no permission is required.
2743 * @param scheduler Handler identifying the thread that will receive
2744 * the Intent. If null, the main thread of the process will be used.
2745 *
2746 * @return The first sticky intent found that matches <var>filter</var>,
2747 * or null if there are none.
2748 *
2749 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2750 * @see #sendBroadcast
2751 * @see #unregisterReceiver
2752 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002753 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002755 IntentFilter filter, @Nullable String broadcastPermission,
2756 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002757
2758 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002759 * Register to receive intent broadcasts, to run in the context of
2760 * <var>scheduler</var>. See
2761 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002762 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2763 * for more information.
2764 *
2765 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2766 *
2767 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2768 * registered with this method will correctly respect the
2769 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2770 * Prior to that, it would be ignored and delivered to all matching registered
2771 * receivers. Be careful if using this for security.</p>
2772 *
2773 * @param receiver The BroadcastReceiver to handle the broadcast.
2774 * @param filter Selects the Intent broadcasts to be received.
2775 * @param broadcastPermission String naming a permissions that a
2776 * broadcaster must hold in order to send an Intent to you. If null,
2777 * no permission is required.
2778 * @param scheduler Handler identifying the thread that will receive
2779 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002780 * @param flags Additional options for the receiver. May be 0 or
2781 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002782 *
2783 * @return The first sticky intent found that matches <var>filter</var>,
2784 * or null if there are none.
2785 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002786 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002787 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2788 * @see #sendBroadcast
2789 * @see #unregisterReceiver
2790 */
2791 @Nullable
2792 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2793 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002794 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002795
2796 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002797 * @hide
2798 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2799 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002800 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002801 *
2802 * @param receiver The BroadcastReceiver to handle the broadcast.
2803 * @param user UserHandle to send the intent to.
2804 * @param filter Selects the Intent broadcasts to be received.
2805 * @param broadcastPermission String naming a permissions that a
2806 * broadcaster must hold in order to send an Intent to you. If null,
2807 * no permission is required.
2808 * @param scheduler Handler identifying the thread that will receive
2809 * the Intent. If null, the main thread of the process will be used.
2810 *
2811 * @return The first sticky intent found that matches <var>filter</var>,
2812 * or null if there are none.
2813 *
Jeff Brown6e539312015-02-24 18:53:21 -08002814 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002815 * @see #sendBroadcast
2816 * @see #unregisterReceiver
2817 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002818 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002819 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002820 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002821 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002822 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2823 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002824
2825 /**
2826 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2827 * filters that have been registered for this BroadcastReceiver will be
2828 * removed.
2829 *
2830 * @param receiver The BroadcastReceiver to unregister.
2831 *
2832 * @see #registerReceiver
2833 */
2834 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2835
2836 /**
2837 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002838 * should either contain the complete class name of a specific service
2839 * implementation to start, or a specific package name to target. If the
2840 * Intent is less specified, it logs a warning about this. In this case any of the
2841 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002842 * is not already running, it will be instantiated and started (creating a
2843 * process for it if needed); if it is running then it remains running.
2844 *
2845 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002846 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 * with the <var>intent</var> given here. This provides a convenient way
2848 * to submit jobs to a service without having to bind and call on to its
2849 * interface.
2850 *
2851 * <p>Using startService() overrides the default service lifetime that is
2852 * managed by {@link #bindService}: it requires the service to remain
2853 * running until {@link #stopService} is called, regardless of whether
2854 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002855 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002856 * a single call to {@link #stopService} will stop it.
2857 *
2858 * <p>The system attempts to keep running services around as much as
2859 * possible. The only time they should be stopped is if the current
2860 * foreground application is using so many resources that the service needs
2861 * to be killed. If any errors happen in the service's process, it will
2862 * automatically be restarted.
2863 *
2864 * <p>This function will throw {@link SecurityException} if you do not
2865 * have permission to start the given service.
2866 *
Chris Craik1e353522016-04-18 10:20:50 -07002867 * <p class="note"><strong>Note:</strong> Each call to startService()
2868 * results in significant work done by the system to manage service
2869 * lifecycle surrounding the processing of the intent, which can take
2870 * multiple milliseconds of CPU time. Due to this cost, startService()
2871 * should not be used for frequent intent delivery to a service, and only
2872 * for scheduling significant work. Use {@link #bindService bound services}
2873 * for high frequency calls.
2874 * </p>
2875 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002876 * @param service Identifies the service to be started. The Intent must be
2877 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002878 * may be included in the Intent extras to supply arguments along with
2879 * this specific start call.
2880 *
2881 * @return If the service is being started or is already running, the
2882 * {@link ComponentName} of the actual service that was started is
2883 * returned; else if the service does not exist null is returned.
2884 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002885 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002886 * or the service can not be found.
2887 * @throws IllegalStateException If the application is in a state where the service
2888 * 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 -08002889 *
2890 * @see #stopService
2891 * @see #bindService
2892 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002893 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 public abstract ComponentName startService(Intent service);
2895
2896 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002897 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002898 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2899 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002900 * an amount of time comparable to the ANR interval to do this, otherwise the system
2901 * will automatically stop the service and declare the app ANR.
2902 *
2903 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2904 * at any time, regardless of whether the app hosting the service is in a foreground
2905 * state.
2906 *
2907 * @param service Identifies the service to be started. The Intent must be
2908 * fully explicit (supplying a component name). Additional values
2909 * may be included in the Intent extras to supply arguments along with
2910 * this specific start call.
2911 *
2912 * @return If the service is being started or is already running, the
2913 * {@link ComponentName} of the actual service that was started is
2914 * returned; else if the service does not exist null is returned.
2915 *
2916 * @throws SecurityException If the caller does not have permission to access the service
2917 * or the service can not be found.
2918 *
2919 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002920 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002921 */
2922 @Nullable
2923 public abstract ComponentName startForegroundService(Intent service);
2924
2925 /**
2926 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2927 */
2928 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002929 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002930 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2931
2932 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002933 * Request that a given application service be stopped. If the service is
2934 * not running, nothing happens. Otherwise it is stopped. Note that calls
2935 * to startService() are not counted -- this stops the service no matter
2936 * how many times it was started.
2937 *
2938 * <p>Note that if a stopped service still has {@link ServiceConnection}
2939 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2940 * not be destroyed until all of these bindings are removed. See
2941 * the {@link android.app.Service} documentation for more details on a
2942 * service's lifecycle.
2943 *
2944 * <p>This function will throw {@link SecurityException} if you do not
2945 * have permission to stop the given service.
2946 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002947 * @param service Description of the service to be stopped. The Intent must be either
2948 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07002949 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950 *
2951 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002952 * 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 -08002953 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002954 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002955 * or the service can not be found.
2956 * @throws IllegalStateException If the application is in a state where the service
2957 * 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 -08002958 *
2959 * @see #startService
2960 */
2961 public abstract boolean stopService(Intent service);
2962
2963 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002964 * @hide like {@link #startService(Intent)} but for a specific user.
2965 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002966 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002967 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002968 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002969 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2970
2971 /**
2972 * @hide like {@link #stopService(Intent)} but for a specific user.
2973 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002974 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002975 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002976
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002977 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002978 * Connect to an application service, creating it if needed. This defines
2979 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002980 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 * told if it dies and restarts. The service will be considered required
2982 * by the system only for as long as the calling context exists. For
2983 * example, if this Context is an Activity that is stopped, the service will
2984 * not be required to continue running until the Activity is resumed.
2985 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002986 * <p>If the service does not support binding, it may return {@code null} from
2987 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
2988 * the ServiceConnection's
2989 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
2990 * will be invoked instead of
2991 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
2992 *
2993 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002994 * have permission to bind to the given service.
2995 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002996 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002998 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002999 * {@link #startService} with the arguments containing the command to be
3000 * sent, with the service calling its
3001 * {@link android.app.Service#stopSelf(int)} method when done executing
3002 * that command. See the API demo App/Service/Service Start Arguments
3003 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003004 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003005 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
3006 * is tied to another object (the one that registered it).</p>
3007 *
Mark Lu94ebbe02016-12-13 16:29:51 -08003008 * @param service Identifies the service to connect to. The Intent must
3009 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003010 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07003011 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07003012 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07003013 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
3014 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003015 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
3016 * {@link #BIND_IMPORTANT}, or
3017 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07003018 * @return {@code true} if the system is in the process of bringing up a
3019 * service that your client has permission to bind to; {@code false}
3020 * if the system couldn't find the service or if your client doesn't
3021 * have permission to bind to it. If this value is {@code true}, you
3022 * should later call {@link #unbindService} to release the
3023 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003025 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003026 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003027 *
3028 * @see #unbindService
3029 * @see #startService
3030 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07003031 * @see #BIND_DEBUG_UNBIND
3032 * @see #BIND_NOT_FOREGROUND
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003033 * @see #BIND_ABOVE_CLIENT
3034 * @see #BIND_ALLOW_OOM_MANAGEMENT
3035 * @see #BIND_WAIVE_PRIORITY
3036 * @see #BIND_IMPORTANT
3037 * @see #BIND_ADJUST_WITH_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003038 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07003039 public abstract boolean bindService(@RequiresPermission Intent service,
3040 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003041
3042 /**
Bo Liu58a57662019-03-06 20:21:45 +00003043 * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control
3044 * ServiceConnection callbacks.
3045 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
3046 * instance for the same instance of ServiceConnection.
3047 */
3048 public boolean bindService(@RequiresPermission @NonNull Intent service,
3049 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
3050 @NonNull ServiceConnection conn) {
3051 throw new RuntimeException("Not implemented. Must override in a subclass.");
3052 }
3053
3054 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003055 * Variation of {@link #bindService} that, in the specific case of isolated
3056 * services, allows the caller to generate multiple instances of a service
Dianne Hackborncc67f962019-04-29 16:32:44 -07003057 * from a single component declaration. In other words, you can use this to bind
3058 * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
3059 * addition to the existing behavior of running in an isolated process, you can
3060 * also through the arguments here have the system bring up multiple concurrent
3061 * processes hosting their own instances of that service. The <var>instanceName</var>
3062 * you provide here identifies the different instances, and you can use
3063 * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
3064 * should manage each of these instances.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003065 *
3066 * @param service Identifies the service to connect to. The Intent must
3067 * specify an explicit component name.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003068 * @param flags Operation options for the binding as per {@link #bindService}.
3069 * @param instanceName Unique identifier for the service instance. Each unique
Robert Seseke3a5bc62019-04-22 17:43:03 -04003070 * name here will result in a different service instance being created. Identifiers
3071 * must only contain ASCII letters, digits, underscores, and periods.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003072 * @return Returns success of binding as per {@link #bindService}.
Bo Liu58a57662019-03-06 20:21:45 +00003073 * @param executor Callbacks on ServiceConnection will be called on executor.
3074 * Must use same instance for the same instance of ServiceConnection.
3075 * @param conn Receives information as the service is started and stopped.
3076 * This must be a valid ServiceConnection object; it must not be null.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003077 *
3078 * @throws SecurityException If the caller does not have permission to access the service
Robert Seseke3a5bc62019-04-22 17:43:03 -04003079 * @throws IllegalArgumentException If the instanceName is invalid.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003080 *
3081 * @see #bindService
Dianne Hackborncc67f962019-04-29 16:32:44 -07003082 * @see #updateServiceGroup
3083 * @see android.R.attr#isolatedProcess
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003084 */
Adrian Roosebc927c2019-02-28 16:21:18 +01003085 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
Bo Liu58a57662019-03-06 20:21:45 +00003086 @BindServiceFlags int flags, @NonNull String instanceName,
3087 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003088 throw new RuntimeException("Not implemented. Must override in a subclass.");
3089 }
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003090
3091 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003092 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003093 * argument for use by system server and other multi-user aware code.
3094 * @hide
3095 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07003096 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08003097 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003098 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07003099 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08003100 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003101 throw new RuntimeException("Not implemented. Must override in a subclass.");
3102 }
3103
3104 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003105 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
Adrian Roos691546e2016-02-09 10:13:41 -08003106 * explicit non-null Handler to run the ServiceConnection callbacks on.
3107 *
3108 * @hide
3109 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003110 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood7bcc1742019-07-04 11:39:42 +01003111 @UnsupportedAppUsage(trackingBug = 136728678)
Adrian Roos691546e2016-02-09 10:13:41 -08003112 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3113 Handler handler, UserHandle user) {
3114 throw new RuntimeException("Not implemented. Must override in a subclass.");
3115 }
3116
3117 /**
Dianne Hackborna631d562018-11-20 15:58:15 -08003118 * For a service previously bound with {@link #bindService} or a related method, change
3119 * how the system manages that service's process in relation to other processes. This
3120 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3121 * how the process will be managed in some cases based on those flags. Currently only
3122 * works on isolated processes (will be ignored for non-isolated processes).
3123 *
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -08003124 * <p>Note that this call does not take immediate effect, but will be applied the next
3125 * time the impacted process is adjusted for some other reason. Typically you would
3126 * call this before then calling a new {@link #bindIsolatedService} on the service
3127 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3128 *
Dianne Hackborna631d562018-11-20 15:58:15 -08003129 * @param conn The connection interface previously supplied to bindService(). This
3130 * parameter must not be null.
3131 * @param group A group to put this connection's process in. Upon calling here, this
3132 * will override any previous group that was set for that process. The group
3133 * tells the system about processes that are logically grouped together, so
3134 * should be managed as one unit of importance (such as when being considered
3135 * a recently used app). All processes in the same app with the same group
3136 * are considered to be related. Supplying 0 reverts to the default behavior
3137 * of not grouping.
3138 * @param importance Additional importance of the processes within a group. Upon calling
Dianne Hackborncc67f962019-04-29 16:32:44 -07003139 * here, this will override any previous importance that was set for that
3140 * process. The most important process is 0, and higher values are
3141 * successively less important. You can view this as describing how
3142 * to order the processes in an array, with the processes at the end of
3143 * the array being the least important. This value has no meaning besides
3144 * indicating how processes should be ordered in that array one after the
3145 * other. This provides a way to fine-tune the system's process killing,
3146 * guiding it to kill processes at the end of the array first.
3147 *
3148 * @see #bindIsolatedService
Dianne Hackborna631d562018-11-20 15:58:15 -08003149 */
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003150 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3151 int importance) {
3152 throw new RuntimeException("Not implemented. Must override in a subclass.");
3153 }
Dianne Hackborna631d562018-11-20 15:58:15 -08003154
3155 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 * Disconnect from an application service. You will no longer receive
3157 * calls as the service is restarted, and the service is now allowed to
3158 * stop at any time.
3159 *
3160 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07003161 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 *
3163 * @see #bindService
3164 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003165 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166
3167 /**
3168 * Start executing an {@link android.app.Instrumentation} class. The given
3169 * Instrumentation component will be run by killing its target application
3170 * (if currently running), starting the target process, instantiating the
3171 * instrumentation component, and then letting it drive the application.
3172 *
3173 * <p>This function is not synchronous -- it returns as soon as the
3174 * instrumentation has started and while it is running.
3175 *
3176 * <p>Instrumentation is normally only allowed to run against a package
3177 * that is either unsigned or signed with a signature that the
3178 * the instrumentation package is also signed with (ensuring the target
3179 * trusts the instrumentation).
3180 *
3181 * @param className Name of the Instrumentation component to be run.
3182 * @param profileFile Optional path to write profiling data as the
3183 * instrumentation runs, or null for no profiling.
3184 * @param arguments Additional optional arguments to pass to the
3185 * instrumentation, or null.
3186 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003187 * @return {@code true} if the instrumentation was successfully started,
3188 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003189 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003190 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3191 @Nullable String profileFile, @Nullable Bundle arguments);
3192
3193 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07003194 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07003195 POWER_SERVICE,
3196 WINDOW_SERVICE,
3197 LAYOUT_INFLATER_SERVICE,
3198 ACCOUNT_SERVICE,
3199 ACTIVITY_SERVICE,
3200 ALARM_SERVICE,
3201 NOTIFICATION_SERVICE,
3202 ACCESSIBILITY_SERVICE,
3203 CAPTIONING_SERVICE,
3204 KEYGUARD_SERVICE,
3205 LOCATION_SERVICE,
3206 //@hide: COUNTRY_DETECTOR,
3207 SEARCH_SERVICE,
3208 SENSOR_SERVICE,
Chad Brubaker90f391f2018-10-19 10:26:19 -07003209 SENSOR_PRIVACY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003210 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003211 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003212 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003213 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003214 VIBRATOR_SERVICE,
3215 //@hide: STATUS_BAR_SERVICE,
3216 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003217 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003218 IPSEC_SERVICE,
Benedict Wong99a48412018-11-09 14:45:34 -08003219 TEST_NETWORK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003220 //@hide: UPDATE_LOCK_SERVICE,
3221 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003222 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003223 //@hide: NETWORK_POLICY_SERVICE,
3224 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003225 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003226 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003227 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003228 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003229 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003230 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003231 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003232 NSD_SERVICE,
3233 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003234 FINGERPRINT_SERVICE,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003235 //@hide: FACE_SERVICE,
Kevin Chyn05c21502018-09-18 13:07:19 -07003236 BIOMETRIC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003237 MEDIA_ROUTER_SERVICE,
3238 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003239 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003240 CARRIER_CONFIG_SERVICE,
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003241 EUICC_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003242 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003243 CLIPBOARD_SERVICE,
3244 INPUT_METHOD_SERVICE,
3245 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003246 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003247 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003248 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003249 //@hide: BACKUP_SERVICE,
Richard Uhlerb29f1452018-09-12 16:38:15 +01003250 ROLLBACK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003251 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003252 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003253 DEVICE_POLICY_SERVICE,
3254 UI_MODE_SERVICE,
3255 DOWNLOAD_SERVICE,
3256 NFC_SERVICE,
3257 BLUETOOTH_SERVICE,
3258 //@hide: SIP_SERVICE,
3259 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003260 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003261 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003262 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003263 INPUT_SERVICE,
3264 DISPLAY_SERVICE,
Christine Franks39b03112018-07-03 14:46:07 -07003265 //@hide COLOR_DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003266 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003267 RESTRICTIONS_SERVICE,
3268 APP_OPS_SERVICE,
Hai Zhangb7776682018-09-25 15:10:57 -07003269 ROLE_SERVICE,
Hai Zhanga4959e52019-03-06 12:21:07 -08003270 //@hide ROLE_CONTROLLER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003271 CAMERA_SERVICE,
atrost8266ae32019-08-15 16:53:01 +01003272 //@hide: PLATFORM_COMPAT_SERVICE,
atrostff948d82019-10-10 19:27:31 +01003273 //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003274 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003275 CONSUMER_IR_SERVICE,
3276 //@hide: TRUST_SERVICE,
3277 TV_INPUT_SERVICE,
3278 //@hide: NETWORK_SCORE_SERVICE,
3279 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003280 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003281 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003282 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003283 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003284 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003285 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003286 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003287 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003288 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003289 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003290 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003291 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003292 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003293 //@hide: INCIDENT_SERVICE,
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08003294 //@hide: INCIDENT_COMPANION_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003295 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003296 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003297 CROSS_PROFILE_APPS_SERVICE,
3298 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerfeeee682018-05-30 14:35:24 +01003299 //@hide: TIME_DETECTOR_SERVICE,
Philip P. Moltmann039678e2018-09-18 13:04:38 -07003300 PERMISSION_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003301 })
3302 @Retention(RetentionPolicy.SOURCE)
3303 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003304
3305 /**
3306 * Return the handle to a system-level service by name. The class of the
3307 * returned object varies by the requested name. Currently available names
3308 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003309 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310 * <dl>
3311 * <dt> {@link #WINDOW_SERVICE} ("window")
3312 * <dd> The top-level window manager in which you can place custom
3313 * windows. The returned object is a {@link android.view.WindowManager}.
3314 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3315 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3316 * in this context.
3317 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3318 * <dd> A {@link android.app.ActivityManager} for interacting with the
3319 * global activity state of the system.
3320 * <dt> {@link #POWER_SERVICE} ("power")
3321 * <dd> A {@link android.os.PowerManager} for controlling power
3322 * management.
3323 * <dt> {@link #ALARM_SERVICE} ("alarm")
3324 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3325 * time of your choosing.
3326 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3327 * <dd> A {@link android.app.NotificationManager} for informing the user
3328 * of background events.
3329 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3330 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3331 * <dt> {@link #LOCATION_SERVICE} ("location")
3332 * <dd> A {@link android.location.LocationManager} for controlling location
3333 * (e.g., GPS) updates.
3334 * <dt> {@link #SEARCH_SERVICE} ("search")
3335 * <dd> A {@link android.app.SearchManager} for handling search.
3336 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3337 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3338 * hardware.
3339 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3340 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3341 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003342 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3343 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3344 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003345 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003346 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3347 * connectivity. On releases before NYC, it should only be obtained from an application
3348 * context, and not from any other derived context to avoid memory leaks within the calling
3349 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003350 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3351 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3352 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003353 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3354 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3355 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3357 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3358 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003359 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3360 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003361 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003362 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003363 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003364 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003365 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3366 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003367 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3368 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3369 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003370 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003371 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003373 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 * <p>Note: System services obtained via this API may be closely associated with
3375 * the Context in which they are obtained from. In general, do not share the
3376 * service objects between various different contexts (Activities, Applications,
3377 * Services, Providers, etc.)
3378 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003379 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3380 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003381 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3382 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3383 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3384 * return <code>null</code>. Generally, if you are running as an instant app you should always
Felipe Leme4685b862019-03-06 10:32:33 -08003385 * check whether the result of this method is {@code null}.
3386 *
3387 * <p>Note: When implementing this method, keep in mind that new services can be added on newer
3388 * Android releases, so if you're looking for just the explicit names mentioned above, make sure
3389 * to return {@code null} when you don't recognize the name &mdash; if you throw a
3390 * {@link RuntimeException} exception instead, you're app might break on new Android releases.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003391 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003393 *
Felipe Leme4685b862019-03-06 10:32:33 -08003394 * @return The service or {@code null} if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003395 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003396 * @see #WINDOW_SERVICE
3397 * @see android.view.WindowManager
3398 * @see #LAYOUT_INFLATER_SERVICE
3399 * @see android.view.LayoutInflater
3400 * @see #ACTIVITY_SERVICE
3401 * @see android.app.ActivityManager
3402 * @see #POWER_SERVICE
3403 * @see android.os.PowerManager
3404 * @see #ALARM_SERVICE
3405 * @see android.app.AlarmManager
3406 * @see #NOTIFICATION_SERVICE
3407 * @see android.app.NotificationManager
3408 * @see #KEYGUARD_SERVICE
3409 * @see android.app.KeyguardManager
3410 * @see #LOCATION_SERVICE
3411 * @see android.location.LocationManager
3412 * @see #SEARCH_SERVICE
3413 * @see android.app.SearchManager
3414 * @see #SENSOR_SERVICE
3415 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003416 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003417 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418 * @see #VIBRATOR_SERVICE
3419 * @see android.os.Vibrator
3420 * @see #CONNECTIVITY_SERVICE
3421 * @see android.net.ConnectivityManager
3422 * @see #WIFI_SERVICE
3423 * @see android.net.wifi.WifiManager
3424 * @see #AUDIO_SERVICE
3425 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003426 * @see #MEDIA_ROUTER_SERVICE
3427 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 * @see #TELEPHONY_SERVICE
3429 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003430 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3431 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003432 * @see #CARRIER_CONFIG_SERVICE
3433 * @see android.telephony.CarrierConfigManager
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003434 * @see #EUICC_SERVICE
3435 * @see android.telephony.euicc.EuiccManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 * @see #INPUT_METHOD_SERVICE
3437 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003438 * @see #UI_MODE_SERVICE
3439 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003440 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003441 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003442 * @see #BATTERY_SERVICE
3443 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003444 * @see #JOB_SCHEDULER_SERVICE
3445 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003446 * @see #NETWORK_STATS_SERVICE
3447 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003448 * @see android.os.HardwarePropertiesManager
3449 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003451 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452
3453 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003454 * Return the handle to a system-level service by class.
3455 * <p>
3456 * Currently available classes are:
3457 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3458 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3459 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3460 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3461 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3462 * {@link android.net.ConnectivityManager},
3463 * {@link android.net.wifi.WifiManager},
3464 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3465 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3466 * {@link android.view.inputmethod.InputMethodManager},
3467 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003468 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3469 * {@link android.app.usage.NetworkStatsManager}.
Felipe Leme4685b862019-03-06 10:32:33 -08003470 * </p>
3471 *
3472 * <p>
Jeff Brown6e539312015-02-24 18:53:21 -08003473 * Note: System services obtained via this API may be closely associated with
3474 * the Context in which they are obtained from. In general, do not share the
3475 * service objects between various different contexts (Activities, Applications,
3476 * Services, Providers, etc.)
3477 * </p>
3478 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003479 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3480 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003481 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3482 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3483 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
Felipe Leme4685b862019-03-06 10:32:33 -08003484 * return {@code null}. Generally, if you are running as an instant app you should always
3485 * check whether the result of this method is {@code null}.
3486 * </p>
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003487 *
Jeff Brown6e539312015-02-24 18:53:21 -08003488 * @param serviceClass The class of the desired service.
Felipe Leme4685b862019-03-06 10:32:33 -08003489 * @return The service or {@code null} if the class is not a supported system service. Note:
3490 * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
Jeff Brown6e539312015-02-24 18:53:21 -08003491 */
3492 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003493 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003494 // Because subclasses may override getSystemService(String) we cannot
3495 // perform a lookup by class alone. We must first map the class to its
3496 // service name then invoke the string-based method.
3497 String serviceName = getSystemServiceName(serviceClass);
3498 return serviceName != null ? (T)getSystemService(serviceName) : null;
3499 }
3500
3501 /**
3502 * Gets the name of the system-level service that is represented by the specified class.
3503 *
3504 * @param serviceClass The class of the desired service.
3505 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003506 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003507 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003508
3509 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003510 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003511 * {@link android.os.PowerManager} for controlling power management,
3512 * including "wake locks," which let you keep the device on while
3513 * you're running long tasks.
3514 */
3515 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003516
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003517 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003518 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003519 * {@link android.os.RecoverySystem} for accessing the recovery system
3520 * service.
3521 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003522 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003523 * @hide
3524 */
3525 public static final String RECOVERY_SERVICE = "recovery";
3526
3527 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003528 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003529 * {@link android.os.SystemUpdateManager} for accessing the system update
3530 * manager service.
3531 *
3532 * @see #getSystemService(String)
3533 * @hide
3534 */
3535 @SystemApi
3536 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3537
3538 /**
3539 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 * {@link android.view.WindowManager} for accessing the system's window
3541 * manager.
3542 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003543 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 * @see android.view.WindowManager
3545 */
3546 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003547
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003549 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003550 * {@link android.view.LayoutInflater} for inflating layout resources in this
3551 * context.
3552 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003553 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003554 * @see android.view.LayoutInflater
3555 */
3556 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003557
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003558 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003559 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003560 * {@link android.accounts.AccountManager} for receiving intents at a
3561 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003562 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003563 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003564 * @see android.accounts.AccountManager
3565 */
3566 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003567
Fred Quintana60307342009-03-24 22:48:12 -07003568 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003569 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003570 * {@link android.app.ActivityManager} for interacting with the global
3571 * system state.
3572 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003573 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 * @see android.app.ActivityManager
3575 */
3576 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003577
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003579 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale65ebd952018-04-25 15:41:44 -07003580 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
3581 *
3582 * @see #getSystemService(String)
3583 * @see android.app.ActivityTaskManager
3584 * @hide
3585 */
3586 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
3587
3588 /**
3589 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07003590 * {@link android.app.UriGrantsManager} for interacting with the global system state.
3591 *
3592 * @see #getSystemService(String)
3593 * @see android.app.UriGrantsManager
3594 * @hide
3595 */
3596 public static final String URI_GRANTS_SERVICE = "uri_grants";
3597
3598 /**
3599 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003600 * {@link android.app.AlarmManager} for receiving intents at a
3601 * time of your choosing.
3602 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003603 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003604 * @see android.app.AlarmManager
3605 */
3606 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003608 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003609 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003610 * {@link android.app.NotificationManager} for informing the user of
3611 * background events.
3612 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003613 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 * @see android.app.NotificationManager
3615 */
3616 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003619 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003620 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3621 * feedback for UI events through the registered event listeners.
3622 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003623 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003624 * @see android.view.accessibility.AccessibilityManager
3625 */
3626 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003627
svetoslavganov75986cf2009-05-14 22:28:01 -07003628 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003629 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003630 * {@link android.view.accessibility.CaptioningManager} for obtaining
3631 * captioning properties and listening for changes in captioning
3632 * preferences.
3633 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003634 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003635 * @see android.view.accessibility.CaptioningManager
3636 */
3637 public static final String CAPTIONING_SERVICE = "captioning";
3638
3639 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003640 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003641 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003643 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 * @see android.app.KeyguardManager
3645 */
3646 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003647
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003649 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003650 * android.location.LocationManager} for controlling location
3651 * updates.
3652 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003653 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 * @see android.location.LocationManager
3655 */
3656 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003657
3658 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003659 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003660 * {@link android.location.CountryDetector} for detecting the country that
3661 * the user is in.
3662 *
3663 * @hide
3664 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01003665 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003666 public static final String COUNTRY_DETECTOR = "country_detector";
3667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003669 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003670 * android.app.SearchManager} for handling searches.
3671 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003672 * <p>
3673 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3674 * {@link android.app.SearchManager}.
3675 *
3676 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 * @see android.app.SearchManager
3678 */
3679 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003681 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003682 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 * android.hardware.SensorManager} for accessing sensors.
3684 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003685 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 * @see android.hardware.SensorManager
3687 */
3688 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003691 * Use with {@link #getSystemService(String)} to retrieve a {@link
Chad Brubaker90f391f2018-10-19 10:26:19 -07003692 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
3693 * functions.
3694 *
3695 * @see #getSystemService(String)
3696 * @see android.hardware.SensorPrivacyManager
3697 *
3698 * @hide
3699 */
3700 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
3701
3702 /**
3703 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003704 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003705 * functions.
3706 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003707 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003708 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003709 */
3710 public static final String STORAGE_SERVICE = "storage";
3711
3712 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003713 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003714 * android.app.usage.StorageStatsManager} for accessing system storage
3715 * statistics.
3716 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003717 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003718 * @see android.app.usage.StorageStatsManager
3719 */
3720 public static final String STORAGE_STATS_SERVICE = "storagestats";
3721
3722 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003723 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 * com.android.server.WallpaperService for accessing wallpapers.
3725 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003726 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003727 */
3728 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003729
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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.os.Vibrator} for interacting with the vibration hardware.
3733 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003734 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003735 * @see android.os.Vibrator
3736 */
3737 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003738
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003740 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 * android.app.StatusBarManager} for interacting with the status bar.
3742 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003743 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 * @see android.app.StatusBarManager
Evan Lairdedd016f2019-01-23 18:36:29 -05003745 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003746 * @hide
3747 */
Evan Lairdedd016f2019-01-23 18:36:29 -05003748 @SystemApi
Evan Laird418ba8f2019-04-17 15:55:21 -04003749 @TestApi
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 public static final String STATUS_BAR_SERVICE = "statusbar";
3751
3752 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003753 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003754 * android.net.ConnectivityManager} for handling management of
3755 * network connections.
3756 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003757 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003758 * @see android.net.ConnectivityManager
3759 */
3760 public static final String CONNECTIVITY_SERVICE = "connectivity";
3761
3762 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003763 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003764 * {@link android.net.INetd} for communicating with the network stack
3765 * @hide
3766 * @see #getSystemService(String)
3767 * @hide
3768 */
3769 @SystemApi
3770 public static final String NETD_SERVICE = "netd";
3771
3772 /**
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003773 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3774 * {@link NetworkStackClient} IBinder for communicating with the network stack
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003775 * @hide
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003776 * @see NetworkStackClient
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003777 */
3778 public static final String NETWORK_STACK_SERVICE = "network_stack";
3779
3780 /**
3781 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003782 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3783 * IPSec.
3784 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003785 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003786 */
3787 public static final String IPSEC_SERVICE = "ipsec";
3788
3789 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003790 * Use with {@link #getSystemService(String)} to retrieve a {@link
Benedict Wong99a48412018-11-09 14:45:34 -08003791 * android.net.TestNetworkManager} for building TUNs and limited-use Networks
3792 *
3793 * @see #getSystemService(String)
3794 * @hide
3795 */
3796 @TestApi public static final String TEST_NETWORK_SERVICE = "test_network";
3797
3798 /**
3799 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003800 * android.os.IUpdateLock} for managing runtime sequences that
3801 * must not be interrupted by headless OTA application or similar.
3802 *
3803 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003804 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003805 * @see android.os.UpdateLock
3806 */
3807 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3808
3809 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003810 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003811 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003812 */
3813 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3814
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003815 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003816 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003817 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3818 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003819 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003820 */
3821 public static final String SLICE_SERVICE = "slice";
3822
3823 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003824 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003825 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3826 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003827 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003828 * @see android.app.usage.NetworkStatsManager
3829 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003830 public static final String NETWORK_STATS_SERVICE = "netstats";
3831 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003832 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003833 /** {@hide} */
3834 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003835
San Mehatd1df8ac2010-01-26 06:17:26 -08003836 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003837 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 * android.net.wifi.WifiManager} for handling management of
3839 * Wi-Fi access.
3840 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003841 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003842 * @see android.net.wifi.WifiManager
3843 */
3844 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003845
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003846 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003847 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003848 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003849 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003850 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003851 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003852 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003853 */
3854 public static final String WIFI_P2P_SERVICE = "wifip2p";
3855
3856 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003857 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003858 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3859 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003860 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003861 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003862 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003863 */
Etan Cohen04133272016-10-26 11:22:06 -07003864 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003865
3866 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003867 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003868 * android.net.wifi.WifiScanner} for scanning the wifi universe
3869 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003870 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003871 * @see android.net.wifi.WifiScanner
3872 * @hide
3873 */
Wei Wang35d552f2014-07-08 21:37:01 -07003874 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003875 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3876
3877 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003878 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003879 * android.net.wifi.RttManager} for ranging devices with wifi
3880 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003881 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003882 * @see android.net.wifi.RttManager
3883 * @hide
3884 */
3885 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08003886 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07003887 public static final String WIFI_RTT_SERVICE = "rttmanager";
3888
3889 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003890 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohenf4062a92019-04-11 07:00:42 -07003891 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
Etan Cohen17ba4722017-08-21 10:52:17 -07003892 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003893 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003894 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003895 */
Etan Cohen091d7772018-01-04 17:47:37 -08003896 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003897
3898 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003899 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003900 * android.net.lowpan.LowpanManager} for handling management of
3901 * LoWPAN access.
3902 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003903 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003904 * @see android.net.lowpan.LowpanManager
3905 *
3906 * @hide
3907 */
3908 public static final String LOWPAN_SERVICE = "lowpan";
3909
3910 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003911 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003912 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003913 * Ethernet access.
3914 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003915 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003916 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003917 *
3918 * @hide
3919 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003920 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003921 public static final String ETHERNET_SERVICE = "ethernet";
3922
3923 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003924 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003925 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003926 * discovery
3927 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003928 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003929 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003930 */
3931 public static final String NSD_SERVICE = "servicediscovery";
3932
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003933 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003934 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003935 * {@link android.media.AudioManager} for handling management of volume,
3936 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003937 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003938 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003939 * @see android.media.AudioManager
3940 */
3941 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003944 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003945 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003946 * of fingerprints.
3947 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003948 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07003949 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003950 */
3951 public static final String FINGERPRINT_SERVICE = "fingerprint";
3952
3953 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003954 * Use with {@link #getSystemService(String)} to retrieve a
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003955 * {@link android.hardware.face.FaceManager} for handling management
3956 * of face authentication.
3957 *
3958 * @hide
3959 * @see #getSystemService
3960 * @see android.hardware.face.FaceManager
3961 */
3962 public static final String FACE_SERVICE = "face";
3963
3964 /**
Kevin Chyn05c21502018-09-18 13:07:19 -07003965 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn51676d22018-11-05 18:00:43 -08003966 * {@link android.hardware.iris.IrisManager} for handling management
3967 * of iris authentication.
3968 *
3969 * @hide
3970 * @see #getSystemService
3971 * @see android.hardware.iris.IrisManager
3972 */
3973 public static final String IRIS_SERVICE = "iris";
3974
3975 /**
3976 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn05c21502018-09-18 13:07:19 -07003977 * {@link android.hardware.biometrics.BiometricManager} for handling management
3978 * of face authentication.
3979 *
3980 * @see #getSystemService
3981 * @see android.hardware.biometrics.BiometricManager
3982 */
3983 public static final String BIOMETRIC_SERVICE = "biometric";
3984
3985 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003986 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003987 * {@link android.media.MediaRouter} for controlling and managing
3988 * routing of media.
3989 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003990 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003991 * @see android.media.MediaRouter
3992 */
3993 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3994
3995 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003996 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003997 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003998 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003999 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07004000 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08004001 */
4002 public static final String MEDIA_SESSION_SERVICE = "media_session";
4003
4004 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004005 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004006 * {@link android.telephony.TelephonyManager} for handling management the
4007 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07004008 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004009 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004010 * @see android.telephony.TelephonyManager
4011 */
4012 public static final String TELEPHONY_SERVICE = "phone";
4013
4014 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004015 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08004016 * {@link android.telephony.SubscriptionManager} for handling management the
4017 * telephony subscriptions of the device.
4018 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004019 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08004020 * @see android.telephony.SubscriptionManager
4021 */
4022 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
4023
4024 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004025 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004026 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07004027 * of the device.
4028 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004029 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004030 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07004031 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004032 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07004033
4034 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004035 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004036 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
4037 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004038 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004039 * @see android.telephony.CarrierConfigManager
4040 */
4041 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
4042
4043 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004044 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08004045 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
4046 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004047 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08004048 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08004049 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004050 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08004051
4052 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004053 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004054 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
4055 *
4056 * @see #getSystemService(String)
4057 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004058 * @hide
4059 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004060 @SystemApi
4061 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004062
4063 /**
4064 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08004065 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004066 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07004067 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004068 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004069 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004070 */
4071 public static final String CLIPBOARD_SERVICE = "clipboard";
4072
4073 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004074 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004075 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004076 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004077 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004078 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004079 */
4080 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
4081
4082 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004083 * Use with {@link #getSystemService(String)} to retrieve a
Alex Salo5f5b5f42019-02-27 10:49:00 -08004084 * {@link com.android.server.attention.AttentionManagerService} for attention services.
4085 *
4086 * @see #getSystemService(String)
4087 * @see android.server.attention.AttentionManagerService
4088 * @hide
4089 */
4090 public static final String ATTENTION_SERVICE = "attention";
4091
4092 /**
4093 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004094 * {@link android.view.inputmethod.InputMethodManager} for accessing input
4095 * methods.
4096 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004097 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 */
4099 public static final String INPUT_METHOD_SERVICE = "input_method";
4100
4101 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004102 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09004103 * {@link android.view.textservice.TextServicesManager} for accessing
4104 * text services.
4105 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004106 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09004107 */
4108 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
4109
4110 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004111 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08004112 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004113 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004114 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004115 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004116 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07004117
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004118 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07004119 * Official published name of the (internal) voice interaction manager service.
4120 *
4121 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004122 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07004123 */
4124 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4125
4126 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08004127 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07004128 *
4129 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004130 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07004131 */
Felipe Leme640f30a2017-03-06 15:44:06 -08004132 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07004133
4134 /**
Felipe Leme749b8892018-12-03 16:30:30 -08004135 * Official published name of the content capture service.
Felipe Lemee348dc32018-11-05 12:35:29 -08004136 *
4137 * @hide
4138 * @see #getSystemService(String)
4139 */
Felipe Lemea7e4ca62019-05-23 13:32:40 -07004140 @TestApi
Felipe Leme749b8892018-12-03 16:30:30 -08004141 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
Felipe Lemee348dc32018-11-05 12:35:29 -08004142
4143 /**
Winson Chung3fb0f252019-01-08 17:41:55 -08004144 * Used for getting content selections and classifications for task snapshots.
4145 *
4146 * @hide
4147 * @see #getSystemService(String)
4148 */
4149 @SystemApi
4150 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
4151
4152 /**
Sunny Goyal54e91342018-11-14 11:59:02 -08004153 * Official published name of the app prediction service.
4154 *
4155 * @hide
4156 * @see #getSystemService(String)
4157 */
4158 @SystemApi
4159 public static final String APP_PREDICTION_SERVICE = "app_prediction";
4160
4161 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004162 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004163 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
4164 *
4165 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004166 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004167 */
4168 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
4169
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004170 /**
4171 * Official published name of the (internal) permission service.
4172 *
4173 * @see #getSystemService(String)
4174 * @hide
4175 */
Winsonf27394e2019-06-07 14:44:40 -07004176 @TestApi
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004177 @SystemApi
4178 public static final String PERMISSION_SERVICE = "permission";
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004179
4180 /**
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08004181 * Official published name of the (internal) permission controller service.
4182 *
4183 * @see #getSystemService(String)
4184 * @hide
4185 */
4186 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
4187
4188 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004189 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08004190 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07004191 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07004192 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07004193 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004194 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07004195 */
Christopher Tated5cf7222014-07-29 16:53:09 -07004196 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07004197 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07004198
4199 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +01004200 * Use with {@link #getSystemService(String)} to retrieve an
4201 * {@link android.content.rollback.RollbackManager} for communicating
4202 * with the rollback manager
4203 *
4204 * @see #getSystemService(String)
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004205 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +01004206 */
Richard Uhler8a977452019-03-08 13:27:17 +00004207 @SystemApi @TestApi
Richard Uhlerb29f1452018-09-12 16:38:15 +01004208 public static final String ROLLBACK_SERVICE = "rollback";
4209
4210 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004211 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08004212 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07004213 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004214 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07004215 */
4216 public static final String DROPBOX_SERVICE = "dropbox";
4217
Christopher Tate487529a2009-04-29 14:03:25 -07004218 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07004219 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004220 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004221 * @hide
4222 */
4223 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
4224
4225 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004226 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08004227 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08004228 * device policy management.
4229 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004230 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08004231 */
4232 public static final String DEVICE_POLICY_SERVICE = "device_policy";
4233
4234 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004235 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08004236 * {@link android.app.UiModeManager} for controlling UI modes.
4237 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004238 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08004239 */
4240 public static final String UI_MODE_SERVICE = "uimode";
4241
4242 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004243 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07004244 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07004245 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004246 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07004247 */
4248 public static final String DOWNLOAD_SERVICE = "download";
4249
4250 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004251 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08004252 * {@link android.os.BatteryManager} for managing battery state.
4253 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004254 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08004255 */
4256 public static final String BATTERY_SERVICE = "batterymanager";
4257
4258 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004259 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004260 * {@link android.nfc.NfcManager} for using NFC.
4261 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004262 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004263 */
4264 public static final String NFC_SERVICE = "nfc";
4265
4266 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004267 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00004268 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004269 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004270 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004271 */
4272 public static final String BLUETOOTH_SERVICE = "bluetooth";
4273
4274 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004275 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08004276 * {@link android.net.sip.SipManager} for accessing the SIP related service.
4277 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004278 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08004279 */
4280 /** @hide */
4281 public static final String SIP_SERVICE = "sip";
4282
4283 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004284 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08004285 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004286 * and for controlling this device's behavior as a USB device.
4287 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004288 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04004289 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004290 */
4291 public static final String USB_SERVICE = "usb";
4292
4293 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004294 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Rootf74bfde2018-01-18 15:42:48 -08004295 * Use with {@link #getSystemService} to retrieve a {@link
4296 * android.debug.AdbManager} for access to ADB debug functions.
4297 *
4298 * @see #getSystemService(String)
4299 * @see android.debug.AdbManager
4300 *
4301 * @hide
4302 */
4303 public static final String ADB_SERVICE = "adb";
4304
4305 /**
4306 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004307 * android.hardware.SerialManager} for access to serial ports.
4308 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004309 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004310 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004311 *
4312 * @hide
4313 */
4314 public static final String SERIAL_SERVICE = "serial";
4315
4316 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004317 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09004318 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
4319 * HDMI-CEC protocol.
4320 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004321 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09004322 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004323 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09004324 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004325 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09004326 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09004327
4328 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004329 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004330 * {@link android.hardware.input.InputManager} for interacting with input devices.
4331 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004332 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004333 * @see android.hardware.input.InputManager
4334 */
4335 public static final String INPUT_SERVICE = "input";
4336
4337 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004338 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07004339 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
4340 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004341 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07004342 * @see android.hardware.display.DisplayManager
4343 */
4344 public static final String DISPLAY_SERVICE = "display";
4345
4346 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004347 * Use with {@link #getSystemService(String)} to retrieve a
Christine Franks39b03112018-07-03 14:46:07 -07004348 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
4349 *
4350 * @see #getSystemService(String)
4351 * @see android.hardware.display.ColorDisplayManager
4352 * @hide
4353 */
4354 public static final String COLOR_DISPLAY_SERVICE = "color_display";
4355
4356 /**
4357 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07004358 * {@link android.os.UserManager} for managing users on devices that support multiple users.
4359 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004360 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07004361 * @see android.os.UserManager
4362 */
4363 public static final String USER_SERVICE = "user";
4364
4365 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004366 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08004367 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
4368 * profiles of a user.
4369 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004370 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08004371 * @see android.content.pm.LauncherApps
4372 */
4373 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4374
4375 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004376 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004377 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4378 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004379 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004380 * @see android.content.RestrictionsManager
4381 */
4382 public static final String RESTRICTIONS_SERVICE = "restrictions";
4383
4384 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004385 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004386 * {@link android.app.AppOpsManager} for tracking application operations
4387 * on the device.
4388 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004389 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004390 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004391 */
4392 public static final String APP_OPS_SERVICE = "appops";
4393
4394 /**
Hai Zhangb7776682018-09-25 15:10:57 -07004395 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
4396 * for managing roles.
4397 *
4398 * @see #getSystemService(String)
4399 * @see android.app.role.RoleManager
4400 */
4401 public static final String ROLE_SERVICE = "role";
4402
4403 /**
Hai Zhanga4959e52019-03-06 12:21:07 -08004404 * Official published name of the (internal) role controller service.
4405 *
4406 * @see #getSystemService(String)
4407 * @see android.app.role.RoleControllerService
4408 *
4409 * @hide
4410 */
4411 public static final String ROLE_CONTROLLER_SERVICE = "role_controller";
4412
4413 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004414 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004415 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004416 * camera devices.
4417 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004418 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004419 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004420 */
4421 public static final String CAMERA_SERVICE = "camera";
4422
4423 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004424 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004425 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004426 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004427 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004428 * @see android.print.PrintManager
4429 */
4430 public static final String PRINT_SERVICE = "print";
4431
4432 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004433 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004434 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4435 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004436 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004437 * @see android.companion.CompanionDeviceManager
4438 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004439 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004440
4441 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004442 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004443 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4444 * signals from the device.
4445 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004446 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004447 * @see android.hardware.ConsumerIrManager
4448 */
4449 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4450
4451 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004452 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004453 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004454 * @see android.app.trust.TrustManager
4455 * @hide
4456 */
4457 public static final String TRUST_SERVICE = "trust";
4458
4459 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004460 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004461 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4462 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004463 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004464 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004465 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004466 */
4467 public static final String TV_INPUT_SERVICE = "tv_input";
4468
4469 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004470 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004471 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004472 * @see android.net.NetworkScoreManager
4473 * @hide
4474 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004475 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004476 public static final String NETWORK_SCORE_SERVICE = "network_score";
4477
4478 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004479 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004480 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004481 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004482 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004483 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004484 */
4485 public static final String USAGE_STATS_SERVICE = "usagestats";
4486
4487 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004488 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004489 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004490 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004491 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004492 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004493 */
Christopher Tate7060b042014-06-09 19:50:00 -07004494 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004495
4496 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004497 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004498 * android.service.persistentdata.PersistentDataBlockManager} instance
4499 * for interacting with a storage device that lives across factory resets.
4500 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004501 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004502 * @see android.service.persistentdata.PersistentDataBlockManager
4503 * @hide
4504 */
Andres Morales33df9372014-09-26 17:08:59 -07004505 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004506 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4507
4508 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004509 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004510 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4511 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004512 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004513 * @see android.service.oemlock.OemLockManager
4514 * @hide
4515 */
4516 @SystemApi
4517 public static final String OEM_LOCK_SERVICE = "oem_lock";
4518
4519 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004520 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004521 * android.media.projection.MediaProjectionManager} instance for managing
4522 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004523 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004524 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004525 */
4526 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4527
4528 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004529 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004530 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004531 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004532 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004533 */
4534 public static final String MIDI_SERVICE = "midi";
4535
Eric Laurent2035ac82015-03-05 15:18:44 -08004536
4537 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004538 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004539 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4540 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004541 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004542 * @hide
4543 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004544 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004545
Paul McLeana33be212015-02-20 07:52:45 -08004546 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004547 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004548 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4549 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004550 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004551 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004552 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004553
4554 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004555 * Use with {@link #getSystemService(String)} to retrieve a
Wei Wangbad7c202018-11-01 11:57:39 -07004556 * {@link android.os.ThermalService} for accessing the thermal service.
4557 *
4558 * @see #getSystemService(String)
4559 * @hide
4560 */
4561 public static final String THERMAL_SERVICE = "thermalservice";
4562
4563 /**
4564 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004565 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004566 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004567 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004568 * @see android.content.pm.ShortcutManager
4569 */
4570 public static final String SHORTCUT_SERVICE = "shortcut";
4571
4572 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004573 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004574 * android.hardware.location.ContextHubManager} for accessing context hubs.
4575 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004576 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004577 * @see android.hardware.location.ContextHubManager
4578 *
4579 * @hide
4580 */
4581 @SystemApi
4582 public static final String CONTEXTHUB_SERVICE = "contexthub";
4583
4584 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004585 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004586 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4587 * memory, etc) metrics.
4588 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004589 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004590 */
4591 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4592
4593 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004594 * Gatekeeper Service.
4595 * @hide
4596 */
4597 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4598
4599 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004600 * Service defining the policy for access to device identifiers.
4601 * @hide
4602 */
4603 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4604
4605 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004606 * Service to report a system health "incident"
4607 * @hide
4608 */
4609 public static final String INCIDENT_SERVICE = "incident";
4610
4611 /**
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08004612 * Service to assist incidentd and dumpstated in reporting status to the user
4613 * and in confirming authorization to take an incident report or bugreport
4614 * @hide
4615 */
4616 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
4617
4618 /**
Bookatz94726412017-08-31 09:26:15 -07004619 * Service to assist statsd in obtaining general stats.
4620 * @hide
4621 */
4622 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4623
4624 /**
Bookatzc6977972018-01-16 16:55:05 -08004625 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004626 * @hide
4627 */
4628 @SystemApi
4629 public static final String STATS_MANAGER = "stats";
4630
4631 /**
atrost8266ae32019-08-15 16:53:01 +01004632 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4633 * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
4634 * @hide
4635 */
4636 public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
4637
4638 /**
atrostff948d82019-10-10 19:27:31 +01004639 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4640 * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
4641 * service.
4642 * @hide
4643 */
4644 public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
4645
4646 /**
Nandana Duttd11850c2018-12-12 17:26:57 +00004647 * Service to capture a bugreport.
4648 * @see #getSystemService(String)
4649 * @see android.os.BugreportManager
4650 * @hide
4651 */
Nandana Duttd7e8d5a2019-04-11 17:27:45 +01004652 @SystemApi @TestApi
Nandana Duttd11850c2018-12-12 17:26:57 +00004653 public static final String BUGREPORT_SERVICE = "bugreport";
4654
4655 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004656 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004657 * android.content.om.OverlayManager} for managing overlay packages.
4658 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004659 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004660 * @see android.content.om.OverlayManager
4661 * @hide
4662 */
4663 public static final String OVERLAY_SERVICE = "overlay";
4664
4665 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004666 * Use with {@link #getSystemService(String)} to retrieve a
MÃ¥rten Kongstad06a1ac82018-09-20 13:09:47 +02004667 * {android.os.IIdmap2} for managing idmap files (used by overlay
4668 * packages).
4669 *
4670 * @see #getSystemService(String)
4671 * @hide
4672 */
4673 public static final String IDMAP_SERVICE = "idmap";
4674
4675 /**
4676 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004677 * {@link VrManager} for accessing the VR service.
4678 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004679 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004680 * @hide
4681 */
4682 @SystemApi
4683 public static final String VR_SERVICE = "vrmanager";
4684
4685 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004686 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004687 * {@link android.app.timezone.ITimeZoneRulesManager}.
4688 * @hide
4689 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004690 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004691 */
4692 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4693
4694 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004695 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004696 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004697 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004698 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004699 */
4700 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4701
4702 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004703 * Use with {@link #getSystemService} to retrieve a
4704 * {@link android.se.omapi.ISecureElementService}
4705 * for accessing the SecureElementService.
4706 *
4707 * @hide
4708 */
4709 @SystemApi
4710 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4711
4712 /**
Neil Fullerfeeee682018-05-30 14:35:24 +01004713 * Use with {@link #getSystemService(String)} to retrieve an
4714 * {@link android.app.timedetector.ITimeDetectorService}.
4715 * @hide
4716 *
4717 * @see #getSystemService(String)
4718 */
4719 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4720
4721 /**
Makoto Onukidf7e4812018-09-24 14:31:25 -07004722 * Binder service name for {@link AppBindingService}.
4723 * @hide
4724 */
4725 public static final String APP_BINDING_SERVICE = "app_binding";
4726
4727 /**
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004728 * Use with {@link #getSystemService(String)} to retrieve an
James.cf Lin2bc9cd42019-11-04 20:23:36 +08004729 * {@link android.telephony.ims.ImsManager}.
4730 * @hide
4731 */
4732 public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
4733
4734 /**
4735 * Use with {@link #getSystemService(String)} to retrieve an
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004736 * {@link android.telephony.ims.RcsMessageManager}.
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004737 * @hide
4738 */
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004739 public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004740
Howard Chen0a947642019-01-07 14:10:44 +08004741 /**
4742 * Use with {@link #getSystemService(String)} to retrieve an
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004743 * {@link android.os.image.DynamicSystemManager}.
Howard Chen0a947642019-01-07 14:10:44 +08004744 * @hide
4745 */
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004746 public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
Howard Chen0a947642019-01-07 14:10:44 +08004747
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004748 /**
Chen Xu1f1c25e2019-09-15 18:28:21 -07004749 * Use with {@link #getSystemService(String)} to retrieve an
4750 * {@link android.os.telephony.TelephonyRegistryManager}.
4751 * @hide
4752 */
4753 @SystemApi
4754 public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
4755
4756 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004757 * Determine whether the given permission is allowed for a particular
4758 * process and user ID running in the system.
4759 *
4760 * @param permission The name of the permission being checked.
4761 * @param pid The process ID being checked against. Must be > 0.
4762 * @param uid The user ID being checked against. A uid of 0 is the root
4763 * user, which will pass every permission check.
4764 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004765 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004766 * pid/uid is allowed that permission, or
4767 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4768 *
4769 * @see PackageManager#checkPermission(String, String)
4770 * @see #checkCallingPermission
4771 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004772 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004773 @PackageManager.PermissionResult
4774 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004775
Dianne Hackbornff170242014-11-19 10:59:01 -08004776 /** @hide */
4777 @PackageManager.PermissionResult
Mathew Inwood5c0d3542018-08-14 13:54:31 +01004778 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08004779 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4780 IBinder callerToken);
4781
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004782 /**
4783 * Determine whether the calling process of an IPC you are handling has been
4784 * granted a particular permission. This is basically the same as calling
4785 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4786 * by {@link android.os.Binder#getCallingPid} and
4787 * {@link android.os.Binder#getCallingUid}. One important difference
4788 * is that if you are not currently processing an IPC, this function
4789 * will always fail. This is done to protect against accidentally
4790 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4791 * to avoid this protection.
4792 *
4793 * @param permission The name of the permission being checked.
4794 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004795 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004796 * pid/uid is allowed that permission, or
4797 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4798 *
4799 * @see PackageManager#checkPermission(String, String)
4800 * @see #checkPermission
4801 * @see #checkCallingOrSelfPermission
4802 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004803 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004804 @PackageManager.PermissionResult
4805 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004806
4807 /**
4808 * Determine whether the calling process of an IPC <em>or you</em> have been
4809 * granted a particular permission. This is the same as
4810 * {@link #checkCallingPermission}, except it grants your own permissions
4811 * if you are not currently processing an IPC. Use with care!
4812 *
4813 * @param permission The name of the permission being checked.
4814 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004815 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004816 * pid/uid is allowed that permission, or
4817 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4818 *
4819 * @see PackageManager#checkPermission(String, String)
4820 * @see #checkPermission
4821 * @see #checkCallingPermission
4822 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004823 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004824 @PackageManager.PermissionResult
4825 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004826
4827 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004828 * Determine whether <em>you</em> have been granted a particular permission.
4829 *
4830 * @param permission The name of the permission being checked.
4831 *
4832 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4833 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4834 *
4835 * @see PackageManager#checkPermission(String, String)
4836 * @see #checkCallingPermission(String)
4837 */
4838 @PackageManager.PermissionResult
4839 public abstract int checkSelfPermission(@NonNull String permission);
4840
4841 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004842 * If the given permission is not allowed for a particular process
4843 * and user ID running in the system, throw a {@link SecurityException}.
4844 *
4845 * @param permission The name of the permission being checked.
4846 * @param pid The process ID being checked against. Must be &gt; 0.
4847 * @param uid The user ID being checked against. A uid of 0 is the root
4848 * user, which will pass every permission check.
4849 * @param message A message to include in the exception if it is thrown.
4850 *
4851 * @see #checkPermission(String, int, int)
4852 */
4853 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004854 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855
4856 /**
4857 * If the calling process of an IPC you are handling has not been
4858 * granted a particular permission, throw a {@link
4859 * SecurityException}. This is basically the same as calling
4860 * {@link #enforcePermission(String, int, int, String)} with the
4861 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4862 * and {@link android.os.Binder#getCallingUid}. One important
4863 * difference is that if you are not currently processing an IPC,
4864 * this function will always throw the SecurityException. This is
4865 * done to protect against accidentally leaking permissions; you
4866 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4867 * protection.
4868 *
4869 * @param permission The name of the permission being checked.
4870 * @param message A message to include in the exception if it is thrown.
4871 *
4872 * @see #checkCallingPermission(String)
4873 */
4874 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004875 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004876
4877 /**
4878 * If neither you nor the calling process of an IPC you are
4879 * handling has been granted a particular permission, throw a
4880 * {@link SecurityException}. This is the same as {@link
4881 * #enforceCallingPermission}, except it grants your own
4882 * permissions if you are not currently processing an IPC. Use
4883 * with care!
4884 *
4885 * @param permission The name of the permission being checked.
4886 * @param message A message to include in the exception if it is thrown.
4887 *
4888 * @see #checkCallingOrSelfPermission(String)
4889 */
4890 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004891 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004892
4893 /**
4894 * Grant permission to access a specific Uri to another package, regardless
4895 * of whether that package has general permission to access the Uri's
4896 * content provider. This can be used to grant specific, temporary
4897 * permissions, typically in response to user interaction (such as the
4898 * user opening an attachment that you would like someone else to
4899 * display).
4900 *
4901 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4902 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4903 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4904 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4905 * start an activity instead of this function directly. If you use this
4906 * function directly, you should be sure to call
4907 * {@link #revokeUriPermission} when the target should no longer be allowed
4908 * to access it.
4909 *
4910 * <p>To succeed, the content provider owning the Uri must have set the
4911 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4912 * grantUriPermissions} attribute in its manifest or included the
4913 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4914 * &lt;grant-uri-permissions&gt;} tag.
4915 *
4916 * @param toPackage The package you would like to allow to access the Uri.
4917 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004918 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004919 *
4920 * @see #revokeUriPermission
4921 */
4922 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004923 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004924
4925 /**
4926 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004927 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4928 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004929 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004930 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004931 * "content://foo". It will not remove any prefix grants that exist at a
4932 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004934 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004935 * regular permission access to a Uri, but had received access to it through
4936 * a specific Uri permission grant, you could not revoke that grant with this
4937 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004938 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4939 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004940 * (or none).</p>
4941 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004942 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4943 * grants matching the given Uri, for any package they had been granted to, through any
4944 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4945 * service start, etc). That means this can be potentially dangerous to use, as it can
4946 * revoke grants that another app could be strongly expecting to stick around.</p>
4947 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004948 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004949 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950 *
4951 * @see #grantUriPermission
4952 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004953 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004954
4955 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004956 * Remove permissions to access a particular content provider Uri
4957 * that were previously added with {@link #grantUriPermission} for a specific target
4958 * package. The given Uri will match all previously granted Uris that are the same or a
4959 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4960 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4961 * "content://foo". It will not remove any prefix grants that exist at a
4962 * higher level.
4963 *
4964 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4965 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4966 * and only for the package specified. Any matching grants that have happened through
4967 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4968 * removed.</p>
4969 *
4970 * @param toPackage The package you had previously granted access to.
4971 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004972 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004973 *
4974 * @see #grantUriPermission
4975 */
4976 public abstract void revokeUriPermission(String toPackage, Uri uri,
4977 @Intent.AccessUriMode int modeFlags);
4978
4979 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004980 * Determine whether a particular process and user ID has been granted
4981 * permission to access a specific URI. This only checks for permissions
4982 * that have been explicitly granted -- if the given process/uid has
4983 * more general access to the URI's content provider then this check will
4984 * always fail.
4985 *
4986 * @param uri The uri that is being checked.
4987 * @param pid The process ID being checked against. Must be &gt; 0.
4988 * @param uid The user ID being checked against. A uid of 0 is the root
4989 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004990 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004991 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004992 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004993 * pid/uid is allowed to access that uri, or
4994 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4995 *
4996 * @see #checkCallingUriPermission
4997 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004998 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004999 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005000 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005001 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005002
Dianne Hackbornff170242014-11-19 10:59:01 -08005003 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005004 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08005005 public abstract int checkUriPermission(Uri uri, int pid, int uid,
5006 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
5007
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005008 /**
5009 * Determine whether the calling process and user ID has been
5010 * granted permission to access a specific URI. This is basically
5011 * the same as calling {@link #checkUriPermission(Uri, int, int,
5012 * int)} with the pid and uid returned by {@link
5013 * android.os.Binder#getCallingPid} and {@link
5014 * android.os.Binder#getCallingUid}. One important difference is
5015 * that if you are not currently processing an IPC, this function
5016 * will always fail.
5017 *
5018 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005019 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005020 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005021 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005022 * is allowed to access that uri, or
5023 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5024 *
5025 * @see #checkUriPermission(Uri, int, int, int)
5026 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005027 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005028 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07005029 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005030
5031 /**
5032 * Determine whether the calling process of an IPC <em>or you</em> has been granted
5033 * permission to access a specific URI. This is the same as
5034 * {@link #checkCallingUriPermission}, except it grants your own permissions
5035 * if you are not currently processing an IPC. Use with care!
5036 *
5037 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005038 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005039 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005040 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 * is allowed to access that uri, or
5042 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5043 *
5044 * @see #checkCallingUriPermission
5045 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005046 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005047 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005048 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005049 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005050
5051 /**
5052 * Check both a Uri and normal permission. This allows you to perform
5053 * both {@link #checkPermission} and {@link #checkUriPermission} in one
5054 * call.
5055 *
5056 * @param uri The Uri whose permission is to be checked, or null to not
5057 * do this check.
5058 * @param readPermission The permission that provides overall read access,
5059 * or null to not do this check.
5060 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005061 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005062 * @param pid The process ID being checked against. Must be &gt; 0.
5063 * @param uid The user ID being checked against. A uid of 0 is the root
5064 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005065 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005066 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005067 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005068 * is allowed to access that uri or holds one of the given permissions, or
5069 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5070 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005071 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005072 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005073 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
5074 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005075 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005076
5077 /**
5078 * If a particular process and user ID has not been granted
5079 * permission to access a specific URI, throw {@link
5080 * SecurityException}. This only checks for permissions that have
5081 * been explicitly granted -- if the given process/uid has more
5082 * general access to the URI's content provider then this check
5083 * will always fail.
5084 *
5085 * @param uri The uri that is being checked.
5086 * @param pid The process ID being checked against. Must be &gt; 0.
5087 * @param uid The user ID being checked against. A uid of 0 is the root
5088 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005089 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005090 * @param message A message to include in the exception if it is thrown.
5091 *
5092 * @see #checkUriPermission(Uri, int, int, int)
5093 */
5094 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005095 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005096
5097 /**
5098 * If the calling process and user ID has not been granted
5099 * permission to access a specific URI, throw {@link
5100 * SecurityException}. This is basically the same as calling
5101 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
5102 * the pid and uid returned by {@link
5103 * android.os.Binder#getCallingPid} and {@link
5104 * android.os.Binder#getCallingUid}. One important difference is
5105 * that if you are not currently processing an IPC, this function
5106 * will always throw a SecurityException.
5107 *
5108 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005109 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005110 * @param message A message to include in the exception if it is thrown.
5111 *
5112 * @see #checkCallingUriPermission(Uri, int)
5113 */
5114 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005115 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005116
5117 /**
5118 * If the calling process of an IPC <em>or you</em> has not been
5119 * granted permission to access a specific URI, throw {@link
5120 * SecurityException}. This is the same as {@link
5121 * #enforceCallingUriPermission}, except it grants your own
5122 * permissions if you are not currently processing an IPC. Use
5123 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07005124 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005125 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005126 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005127 * @param message A message to include in the exception if it is thrown.
5128 *
5129 * @see #checkCallingOrSelfUriPermission(Uri, int)
5130 */
5131 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005132 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005133
5134 /**
5135 * Enforce both a Uri and normal permission. This allows you to perform
5136 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
5137 * call.
Scott Main4b5da682010-10-21 11:49:12 -07005138 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005139 * @param uri The Uri whose permission is to be checked, or null to not
5140 * do this check.
5141 * @param readPermission The permission that provides overall read access,
5142 * or null to not do this check.
5143 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005144 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005145 * @param pid The process ID being checked against. Must be &gt; 0.
5146 * @param uid The user ID being checked against. A uid of 0 is the root
5147 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005148 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005149 * @param message A message to include in the exception if it is thrown.
5150 *
5151 * @see #checkUriPermission(Uri, String, String, int, int, int)
5152 */
5153 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005154 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005155 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07005156 @Nullable String message);
5157
5158 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005159 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
5160 CONTEXT_INCLUDE_CODE,
5161 CONTEXT_IGNORE_SECURITY,
5162 CONTEXT_RESTRICTED,
5163 CONTEXT_DEVICE_PROTECTED_STORAGE,
5164 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
5165 CONTEXT_REGISTER_PACKAGE,
5166 })
Tor Norbyed9273d62013-05-30 15:59:53 -07005167 @Retention(RetentionPolicy.SOURCE)
5168 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005169
5170 /**
5171 * Flag for use with {@link #createPackageContext}: include the application
5172 * code with the context. This means loading code into the caller's
5173 * process, so that {@link #getClassLoader()} can be used to instantiate
5174 * the application's classes. Setting this flags imposes security
5175 * restrictions on what application context you can access; if the
5176 * requested application can not be safely loaded into your process,
5177 * java.lang.SecurityException will be thrown. If this flag is not set,
5178 * there will be no restrictions on the packages that can be loaded,
5179 * but {@link #getClassLoader} will always return the default system
5180 * class loader.
5181 */
5182 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
5183
5184 /**
5185 * Flag for use with {@link #createPackageContext}: ignore any security
5186 * restrictions on the Context being requested, allowing it to always
5187 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
5188 * to be loaded into a process even when it isn't safe to do so. Use
5189 * with extreme care!
5190 */
5191 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07005192
Romain Guy870e09f2009-07-06 16:35:25 -07005193 /**
5194 * Flag for use with {@link #createPackageContext}: a restricted context may
5195 * disable specific features. For instance, a View associated with a restricted
5196 * context would ignore particular XML attributes.
5197 */
5198 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005199
5200 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005201 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005202 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005203 *
5204 * @hide
5205 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005206 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005207
5208 /**
5209 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005210 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005211 *
5212 * @hide
5213 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005214 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005215
5216 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07005217 * @hide Used to indicate we should tell the activity manager about the process
5218 * loading this code.
5219 */
5220 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
5221
5222 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005223 * Return a new Context object for the given application name. This
5224 * Context is the same as what the named application gets when it is
5225 * launched, containing the same resources and class loader. Each call to
5226 * this method returns a new instance of a Context object; Context objects
5227 * are not shared, however they share common state (Resources, ClassLoader,
5228 * etc) so the Context instance itself is fairly lightweight.
5229 *
Jeff Brown6e539312015-02-24 18:53:21 -08005230 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 * application with the given package name.
5232 *
5233 * <p>Throws {@link java.lang.SecurityException} if the Context requested
5234 * can not be loaded into the caller's process for security reasons (see
5235 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
5236 *
5237 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005238 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005239 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005240 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005241 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005242 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005243 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04005244 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 */
5246 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07005247 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07005248
5249 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07005250 * Similar to {@link #createPackageContext(String, int)}, but with a
5251 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5252 * will open any {@link Uri} as the given user.
5253 *
5254 * @hide
5255 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08005256 @SystemApi
Jeff Sharkeyec5f7d12018-08-08 09:15:04 -06005257 @TestApi
Patrick Baumannef4c4072018-02-01 08:54:05 -08005258 public Context createPackageContextAsUser(
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005259 String packageName, @CreatePackageOptions int flags, UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08005260 throws PackageManager.NameNotFoundException {
5261 if (Build.IS_ENG) {
5262 throw new IllegalStateException("createPackageContextAsUser not overridden!");
5263 }
5264 return this;
5265 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07005266
5267 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07005268 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
5269 *
5270 * @hide
5271 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005272 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07005273 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005274 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07005275
5276 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08005277 * Return a new Context object for the given split name. The new Context has a ClassLoader and
5278 * Resources object that can access the split's and all of its dependencies' code/resources.
5279 * Each call to this method returns a new instance of a Context object;
5280 * Context objects are not shared, however common state (ClassLoader, other Resources for
5281 * the same split) may be so the Context itself can be fairly lightweight.
5282 *
5283 * @param splitName The name of the split to include, as declared in the split's
5284 * <code>AndroidManifest.xml</code>.
5285 * @return A {@link Context} with the given split's code and/or resources loaded.
5286 */
5287 public abstract Context createContextForSplit(String splitName)
5288 throws PackageManager.NameNotFoundException;
5289
5290 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005291 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08005292 * @hide
5293 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07005294 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005295 public UserHandle getUser() {
5296 return android.os.Process.myUserHandle();
5297 }
5298
5299 /**
5300 * Get the user associated with this context
5301 * @hide
5302 */
5303 @TestApi
5304 public @UserIdInt int getUserId() {
5305 return android.os.UserHandle.myUserId();
5306 }
Jim Millera75a8832013-02-07 16:53:32 -08005307
5308 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07005309 * Return a new Context object for the current Context but whose resources
5310 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07005311 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07005312 * shared, however common state (ClassLoader, other Resources for the
5313 * same configuration) may be so the Context itself can be fairly lightweight.
5314 *
5315 * @param overrideConfiguration A {@link Configuration} specifying what
5316 * values to modify in the base Configuration of the original Context's
5317 * resources. If the base configuration changes (such as due to an
5318 * orientation change), the resources of this context will also change except
5319 * for those that have been explicitly overridden with a value here.
5320 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005321 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07005322 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005323 public abstract Context createConfigurationContext(
5324 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07005325
5326 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07005327 * Return a new Context object for the current Context but whose resources
5328 * are adjusted to match the metrics of the given Display. Each call to this method
5329 * returns a new instance of a Context object; Context objects are not
5330 * shared, however common state (ClassLoader, other Resources for the
5331 * same configuration) may be so the Context itself can be fairly lightweight.
5332 *
5333 * The returned display Context provides a {@link WindowManager}
5334 * (see {@link #getSystemService(String)}) that is configured to show windows
5335 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
5336 * method can be used to retrieve the Display from the returned Context.
5337 *
5338 * @param display A {@link Display} object specifying the display
5339 * for whose metrics the Context's resources should be tailored and upon which
5340 * new windows should be shown.
5341 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005342 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07005343 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005344 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07005345
5346 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005347 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005348 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005349 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005350 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005351 * with a key tied to the physical device, and it can be accessed
5352 * immediately after the device has booted successfully, both
5353 * <em>before and after</em> the user has authenticated with their
5354 * credentials (such as a lock pattern or PIN).
5355 * <p>
5356 * Because device-protected data is available without user authentication,
5357 * you should carefully limit the data you store using this Context. For
5358 * example, storing sensitive authentication tokens or passwords in the
5359 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005360 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005361 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005362 * device-protected and credential-protected data using different keys, then
5363 * both storage areas will become available at the same time. They remain as
5364 * two distinct storage locations on disk, and only the window of
5365 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005366 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005367 * Each call to this method returns a new instance of a Context object;
5368 * Context objects are not shared, however common state (ClassLoader, other
5369 * Resources for the same configuration) may be so the Context itself can be
5370 * fairly lightweight.
5371 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005372 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005373 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005374 public abstract Context createDeviceProtectedStorageContext();
5375
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005376 /**
5377 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005378 * APIs are backed by credential-protected storage. This is the default
5379 * storage area for apps unless
5380 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005381 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005382 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005383 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005384 * <em>only after</em> the user has entered their credentials (such as a
5385 * lock pattern or PIN).
5386 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005387 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005388 * device-protected and credential-protected data using different keys, then
5389 * both storage areas will become available at the same time. They remain as
5390 * two distinct storage locations on disk, and only the window of
5391 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005392 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005393 * Each call to this method returns a new instance of a Context object;
5394 * Context objects are not shared, however common state (ClassLoader, other
5395 * Resources for the same configuration) may be so the Context itself can be
5396 * fairly lightweight.
5397 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005398 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005399 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005400 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005401 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005402 public abstract Context createCredentialProtectedStorageContext();
5403
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005404 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07005405 * Gets the display adjustments holder for this context. This information
5406 * is provided on a per-application or activity basis and is used to simulate lower density
5407 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07005408 *
Jeff Browna492c3a2012-08-23 19:48:44 -07005409 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07005410 * @return The compatibility info holder, or null if not required by the application.
5411 * @hide
5412 */
Craig Mautner48d0d182013-06-11 07:53:06 -07005413 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07005414
5415 /**
Wale Ogunwale691af682019-02-11 03:09:10 -08005416 * @return Returns the {@link Display} object this context is associated with.
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005417 * @hide
5418 */
Wale Ogunwale691af682019-02-11 03:09:10 -08005419 @TestApi
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005420 public abstract Display getDisplay();
5421
5422 /**
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005423 * Gets the display ID.
5424 *
5425 * @return display ID associated with this {@link Context}.
5426 * @hide
5427 */
wilsonshih5db7b392019-02-20 23:08:45 +08005428 @TestApi
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005429 public abstract int getDisplayId();
5430
5431 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08005432 * @hide
5433 */
5434 public abstract void updateDisplay(int displayId);
5435
5436 /**
Romain Guy870e09f2009-07-06 16:35:25 -07005437 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07005438 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005439 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07005440 *
Romain Guy870e09f2009-07-06 16:35:25 -07005441 * @see #CONTEXT_RESTRICTED
5442 */
5443 public boolean isRestricted() {
5444 return false;
5445 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005446
5447 /**
5448 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005449 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005450 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005451 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005452 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005453 public abstract boolean isDeviceProtectedStorage();
5454
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005455 /**
5456 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005457 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005458 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005459 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005460 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005461 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005462 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005463 public abstract boolean isCredentialProtectedStorage();
5464
Tony Mak46aabe52016-11-14 12:53:06 +00005465 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005466 * Returns true if the context can load unsafe resources, e.g. fonts.
5467 * @hide
5468 */
5469 public abstract boolean canLoadUnsafeResources();
5470
5471 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005472 * @hide
5473 */
5474 public IBinder getActivityToken() {
5475 throw new RuntimeException("Not implemented. Must override in a subclass.");
5476 }
5477
5478 /**
5479 * @hide
5480 */
5481 @Nullable
5482 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
5483 int flags) {
5484 throw new RuntimeException("Not implemented. Must override in a subclass.");
5485 }
5486
5487 /**
5488 * @hide
5489 */
5490 public IApplicationThread getIApplicationThread() {
5491 throw new RuntimeException("Not implemented. Must override in a subclass.");
5492 }
Tony Makbf9928d2016-12-22 11:02:45 +00005493
5494 /**
5495 * @hide
5496 */
5497 public Handler getMainThreadHandler() {
5498 throw new RuntimeException("Not implemented. Must override in a subclass.");
5499 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07005500
5501 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07005502 * @hide
5503 */
5504 public AutofillClient getAutofillClient() {
5505 return null;
5506 }
5507
5508 /**
5509 * @hide
5510 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005511 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005512 }
5513
5514 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005515 * @hide
5516 */
Felipe Lemecbf7f262019-04-17 13:57:59 -07005517 @Nullable
5518 public ContentCaptureClient getContentCaptureClient() {
5519 return null;
5520 }
5521
5522 /**
5523 * @hide
5524 */
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005525 public final boolean isAutofillCompatibilityEnabled() {
5526 final AutofillOptions options = getAutofillOptions();
5527 return options != null && options.compatModeEnabled;
5528 }
5529
5530 /**
5531 * @hide
5532 */
5533 @Nullable
5534 public AutofillOptions getAutofillOptions() {
5535 return null;
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005536 }
5537
5538 /**
5539 * @hide
5540 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005541 @TestApi
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005542 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005543 }
5544
5545 /**
Felipe Leme326f15a2019-02-19 09:42:24 -08005546 * Gets the Content Capture options for this context, or {@code null} if it's not whitelisted.
Felipe Lemeecb08be2018-11-27 15:48:47 -08005547 *
5548 * @hide
5549 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005550 @Nullable
5551 public ContentCaptureOptions getContentCaptureOptions() {
5552 return null;
Felipe Lemeecb08be2018-11-27 15:48:47 -08005553 }
5554
5555 /**
5556 * @hide
5557 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005558 @TestApi
5559 public void setContentCaptureOptions(
5560 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08005561 }
5562
5563 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005564 * Throws an exception if the Context is using system resources,
5565 * which are non-runtime-overlay-themable and may show inconsistent UI.
5566 * @hide
5567 */
5568 public void assertRuntimeOverlayThemable() {
5569 // Resources.getSystem() is a singleton and the only Resources not managed by
5570 // ResourcesManager; therefore Resources.getSystem() is not themable.
5571 if (getResources() == Resources.getSystem()) {
5572 throw new IllegalArgumentException("Non-UI context used to display UI; "
5573 + "get a UI context from ActivityThread#getSystemUiContext()");
5574 }
5575 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005576}