blob: bb10e1c2ee74e0761848c012f68c9b01aa011c7d [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;
atrost87488352019-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 *
Nate Fischer5272c372019-08-27 16:37:00 -0700858 * <p>This method is thread-safe.
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700859 *
Nate Fischer5272c372019-08-27 16:37:00 -0700860 * <p>If the preferences directory does not already exist, it will be created when this method
861 * is called.
862 *
863 * <p>If a preferences file by this name does not exist, it will be created when you retrieve an
864 * editor ({@link SharedPreferences#edit()}) and then commit changes ({@link
865 * SharedPreferences.Editor#commit()} or {@link SharedPreferences.Editor#apply()}).
866 *
867 * @param name Desired preferences file.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600868 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800869 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400870 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 * to retrieve and modify the preference values.
872 *
873 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600875 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700876
877 /**
878 * Retrieve and hold the contents of the preferences file, returning
879 * a SharedPreferences through which you can retrieve and modify its
880 * values. Only one instance of the SharedPreferences object is returned
881 * to any callers for the same name, meaning they will see each other's
882 * edits as soon as they are made.
883 *
884 * @param file Desired preferences file. If a preferences file by this name
885 * does not exist, it will be created when you retrieve an
886 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600887 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700888 *
889 * @return The single {@link SharedPreferences} instance that can be used
890 * to retrieve and modify the preference values.
891 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700892 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700893 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600894 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700895 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600896 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800897
898 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600899 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700900 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600901 * storage locations after an upgrade, such as moving to device protected
902 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700903 *
904 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600905 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700906 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600907 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700908 * preferences didn't exist in the source context, otherwise
909 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600910 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700911 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600912 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
913
Jeff Sharkey35871f22016-01-29 17:13:29 -0700914 /**
915 * Delete an existing shared preferences file.
916 *
917 * @param name The name (unique in the application package) of the shared
918 * preferences file.
919 * @return {@code true} if the shared preferences file was successfully
920 * deleted; else {@code false}.
921 * @see #getSharedPreferences(String, int)
922 */
923 public abstract boolean deleteSharedPreferences(String name);
924
Christopher Tatefe2368c2017-05-17 15:42:35 -0700925 /** @hide */
926 public abstract void reloadSharedPreferences();
927
Jeff Sharkey35871f22016-01-29 17:13:29 -0700928 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800929 * Open a private file associated with this Context's application package
930 * for reading.
931 *
932 * @param name The name of the file to open; can not contain path
933 * separators.
934 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400935 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936 *
937 * @see #openFileOutput
938 * @see #fileList
939 * @see #deleteFile
940 * @see java.io.FileInputStream#FileInputStream(String)
941 */
942 public abstract FileInputStream openFileInput(String name)
943 throws FileNotFoundException;
944
945 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800946 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700947 * for writing. Creates the file if it doesn't already exist.
948 * <p>
949 * No additional permissions are required for the calling app to read or
950 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700951 *
Nick Kralevich15069212013-01-09 15:54:56 -0800952 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700953 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600954 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400955 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956 * @see #MODE_APPEND
957 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 * @see #openFileInput
959 * @see #fileList
960 * @see #deleteFile
961 * @see java.io.FileOutputStream#FileOutputStream(String)
962 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600963 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 throws FileNotFoundException;
965
966 /**
967 * Delete the given private file associated with this Context's
968 * application package.
969 *
970 * @param name The name of the file to delete; can not contain path
971 * separators.
972 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400973 * @return {@code true} if the file was successfully deleted; else
974 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800975 *
976 * @see #openFileInput
977 * @see #openFileOutput
978 * @see #fileList
979 * @see java.io.File#delete()
980 */
981 public abstract boolean deleteFile(String name);
982
983 /**
984 * Returns the absolute path on the filesystem where a file created with
985 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700986 * <p>
987 * The returned path may change over time if the calling app is moved to an
988 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800989 *
990 * @param name The name of the file for which you would like to get
991 * its path.
992 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400993 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800994 *
995 * @see #openFileOutput
996 * @see #getFilesDir
997 * @see #getDir
998 */
999 public abstract File getFileStreamPath(String name);
1000
1001 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001002 * Returns the absolute path on the filesystem where a file created with
1003 * {@link #getSharedPreferences(String, int)} is stored.
1004 * <p>
1005 * The returned path may change over time if the calling app is moved to an
1006 * adopted storage device, so only relative paths should be persisted.
1007 *
1008 * @param name The name of the shared preferences for which you would like
1009 * to get a path.
1010 * @return An absolute path to the given file.
1011 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001012 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001013 */
1014 public abstract File getSharedPreferencesPath(String name);
1015
1016 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001017 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001018 * private files belonging to this app are stored. Apps should not use this
1019 * path directly; they should instead use {@link #getFilesDir()},
1020 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1021 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001022 * <p>
1023 * The returned path may change over time if the calling app is moved to an
1024 * adopted storage device, so only relative paths should be persisted.
1025 * <p>
1026 * No additional permissions are required for the calling app to read or
1027 * write files under the returned path.
1028 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001029 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001030 */
1031 public abstract File getDataDir();
1032
1033 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001034 * Returns the absolute path to the directory on the filesystem where files
1035 * created with {@link #openFileOutput} are stored.
1036 * <p>
1037 * The returned path may change over time if the calling app is moved to an
1038 * adopted storage device, so only relative paths should be persisted.
1039 * <p>
1040 * No additional permissions are required for the calling app to read or
1041 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -07001042 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001043 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 * @see #openFileOutput
1045 * @see #getFileStreamPath
1046 * @see #getDir
1047 */
1048 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -07001049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001050 /**
Christopher Tatea7835b62014-07-11 17:25:57 -07001051 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001052 * {@link #getFilesDir()}. The difference is that files placed under this
1053 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -07001054 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1055 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001056 * <p>
1057 * The returned path may change over time if the calling app is moved to an
1058 * adopted storage device, so only relative paths should be persisted.
1059 * <p>
1060 * No additional permissions are required for the calling app to read or
1061 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -07001062 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001063 * @return The path of the directory holding application files that will not
1064 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -07001065 * @see #openFileOutput
1066 * @see #getFileStreamPath
1067 * @see #getDir
1068 * @see android.app.backup.BackupAgent
1069 */
1070 public abstract File getNoBackupFilesDir();
1071
1072 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001073 * Returns the absolute path to the directory on the primary shared/external
1074 * storage device where the application can place persistent files it owns.
1075 * These files are internal to the applications, and not typically visible
1076 * to the user as media.
1077 * <p>
1078 * This is like {@link #getFilesDir()} in that these files will be deleted
1079 * when the application is uninstalled, however there are some important
1080 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001081 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001082 * <li>Shared storage may not always be available, since removable media can
1083 * be ejected by the user. Media state can be checked using
1084 * {@link Environment#getExternalStorageState(File)}.
1085 * <li>There is no security enforced with these files. For example, any
1086 * application holding
1087 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001088 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001089 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001090 * <p>
1091 * If a shared storage device is emulated (as determined by
1092 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1093 * backed by a private user data partition, which means there is little
1094 * benefit to storing data here instead of the private directories returned
1095 * by {@link #getFilesDir()}, etc.
1096 * <p>
1097 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001098 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001099 * accessible to the calling app. This only applies to paths generated for
1100 * package name of the calling application. To access paths belonging to
1101 * other packages,
1102 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1103 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1104 * <p>
1105 * On devices with multiple users (as described by {@link UserManager}),
1106 * each user has their own isolated shared storage. Applications only have
1107 * access to the shared storage for the user they're running as.
1108 * <p>
1109 * The returned path may change over time if different shared storage media
1110 * is inserted, so only relative paths should be persisted.
1111 * <p>
1112 * Here is an example of typical code to manipulate a file in an
1113 * application's shared storage:
1114 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001115 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1116 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001117 * <p>
1118 * If you supply a non-null <var>type</var> to this function, the returned
1119 * file will be a path to a sub-directory of the given type. Though these
1120 * files are not automatically scanned by the media scanner, you can
1121 * explicitly add them to the media database with
1122 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1123 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001124 * {@link android.os.Environment#getExternalStoragePublicDirectory
1125 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001126 * directories of media shared by all applications. The directories returned
1127 * here are owned by the application, and their contents will be removed
1128 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001129 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001130 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1131 * here will be automatically created for you.
1132 * <p>
1133 * Here is an example of typical code to manipulate a picture in an
1134 * application's shared storage and add it to the media database:
1135 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001136 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1137 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001138 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001139 * @param type The type of files directory to return. May be {@code null}
1140 * for the root of the files directory or one of the following
1141 * constants for a subdirectory:
1142 * {@link android.os.Environment#DIRECTORY_MUSIC},
1143 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1144 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1145 * {@link android.os.Environment#DIRECTORY_ALARMS},
1146 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1147 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1148 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1149 * @return the absolute path to application-specific directory. May return
1150 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001151 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001152 * @see #getExternalFilesDirs(String)
1153 * @see Environment#getExternalStorageState(File)
1154 * @see Environment#isExternalStorageEmulated(File)
1155 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001156 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001157 @Nullable
1158 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001159
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001160 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001161 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001162 * shared/external storage devices where the application can place
1163 * persistent files it owns. These files are internal to the application,
1164 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001165 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001166 * This is like {@link #getFilesDir()} in that these files will be deleted
1167 * when the application is uninstalled, however there are some important
1168 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001169 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001170 * <li>Shared storage may not always be available, since removable media can
1171 * be ejected by the user. Media state can be checked using
1172 * {@link Environment#getExternalStorageState(File)}.
1173 * <li>There is no security enforced with these files. For example, any
1174 * application holding
1175 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1176 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001177 * </ul>
1178 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001179 * If a shared storage device is emulated (as determined by
1180 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1181 * backed by a private user data partition, which means there is little
1182 * benefit to storing data here instead of the private directories returned
1183 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001184 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001185 * Shared storage devices returned here are considered a stable part of the
1186 * device, including physical media slots under a protective cover. The
1187 * returned paths do not include transient devices, such as USB flash drives
1188 * connected to handheld devices.
1189 * <p>
1190 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001191 * example, an app may choose to store large files on the device with the
1192 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001193 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001194 * No additional permissions are required for the calling app to read or
1195 * write files under the returned path. Write access outside of these paths
1196 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001197 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001198 * The returned path may change over time if different shared storage media
1199 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001200 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001201 * @param type The type of files directory to return. May be {@code null}
1202 * for the root of the files directory or one of the following
1203 * constants for a subdirectory:
1204 * {@link android.os.Environment#DIRECTORY_MUSIC},
1205 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1206 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1207 * {@link android.os.Environment#DIRECTORY_ALARMS},
1208 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1209 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1210 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1211 * @return the absolute paths to application-specific directories. Some
1212 * individual paths may be {@code null} if that shared storage is
1213 * not currently available. The first path returned is the same as
1214 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001215 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001216 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001217 * @see Environment#isExternalStorageEmulated(File)
1218 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001219 */
1220 public abstract File[] getExternalFilesDirs(String type);
1221
1222 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001223 * Return the primary shared/external storage directory where this
1224 * application's OBB files (if there are any) can be found. Note if the
1225 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001226 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001227 * This is like {@link #getFilesDir()} in that these files will be deleted
1228 * when the application is uninstalled, however there are some important
1229 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001230 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001231 * <li>Shared storage may not always be available, since removable media can
1232 * be ejected by the user. Media state can be checked using
1233 * {@link Environment#getExternalStorageState(File)}.
1234 * <li>There is no security enforced with these files. For example, any
1235 * application holding
1236 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001237 * these files.
1238 * </ul>
1239 * <p>
1240 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001241 * are required to read or write to the path that this method returns.
1242 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1243 * to read the OBB expansion files, you must declare the
1244 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1245 * permission at runtime as follows:
1246 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001247 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001248 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1249 * android:maxSdkVersion="23" />}
1250 * </p>
1251 * <p>
1252 * Starting from {@link android.os.Build.VERSION_CODES#N},
1253 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1254 * permission is not required, so don’t ask for this
1255 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1256 * and if it fails, you must request
1257 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1258 * </p>
1259 *
1260 * <p>
1261 * The following code snippet shows how to do this:
1262 * </p>
1263 *
1264 * <pre>
1265 * File obb = new File(obb_filename);
1266 * boolean open_failed = false;
1267 *
1268 * try {
1269 * BufferedReader br = new BufferedReader(new FileReader(obb));
1270 * open_failed = false;
1271 * ReadObbFile(br);
1272 * } catch (IOException e) {
1273 * open_failed = true;
1274 * }
1275 *
1276 * if (open_failed) {
1277 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1278 * ReadObbFileWithPermission();
1279 * }
1280 * </pre>
1281 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001282 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001283 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001284 * should ensure that multiple instances running under different users don't
1285 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001286 *
1287 * @return the absolute path to application-specific directory. May return
1288 * {@code null} if shared storage is not currently available.
1289 * @see #getObbDirs()
1290 * @see Environment#getExternalStorageState(File)
1291 * @see Environment#isExternalStorageEmulated(File)
1292 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001293 */
1294 public abstract File getObbDir();
1295
1296 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001297 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001298 * shared/external storage devices where the application's OBB files (if
1299 * there are any) can be found. Note if the application does not have any
1300 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001301 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001302 * This is like {@link #getFilesDir()} in that these files will be deleted
1303 * when the application is uninstalled, however there are some important
1304 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001305 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001306 * <li>Shared storage may not always be available, since removable media can
1307 * be ejected by the user. Media state can be checked using
1308 * {@link Environment#getExternalStorageState(File)}.
1309 * <li>There is no security enforced with these files. For example, any
1310 * application holding
1311 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1312 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001313 * </ul>
1314 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001315 * Shared storage devices returned here are considered a stable part of the
1316 * device, including physical media slots under a protective cover. The
1317 * returned paths do not include transient devices, such as USB flash drives
1318 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001319 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001320 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001321 * example, an app may choose to store large files on the device with the
1322 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001323 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001324 * No additional permissions are required for the calling app to read or
1325 * write files under the returned path. Write access outside of these paths
1326 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001327 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001328 * @return the absolute paths to application-specific directories. Some
1329 * individual paths may be {@code null} if that shared storage is
1330 * not currently available. The first path returned is the same as
1331 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001332 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001333 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001334 * @see Environment#isExternalStorageEmulated(File)
1335 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001336 */
1337 public abstract File[] getObbDirs();
1338
1339 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001340 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001341 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001342 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001343 * The system will automatically delete files in this directory as disk
1344 * space is needed elsewhere on the device. The system will always delete
1345 * older files first, as reported by {@link File#lastModified()}. If
1346 * desired, you can exert more control over how files are deleted using
1347 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1348 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1349 * <p>
1350 * Apps are strongly encouraged to keep their usage of cache space below the
1351 * quota returned by
1352 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1353 * goes above this quota, your cached files will be some of the first to be
1354 * deleted when additional disk space is needed. Conversely, if your app
1355 * stays under this quota, your cached files will be some of the last to be
1356 * deleted when additional disk space is needed.
1357 * <p>
1358 * Note that your cache quota will change over time depending on how
1359 * frequently the user interacts with your app, and depending on how much
1360 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001361 * <p>
1362 * The returned path may change over time if the calling app is moved to an
1363 * adopted storage device, so only relative paths should be persisted.
1364 * <p>
1365 * Apps require no extra permissions to read or write to the returned path,
1366 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001367 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001368 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 * @see #openFileOutput
1370 * @see #getFileStreamPath
1371 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001372 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001373 */
1374 public abstract File getCacheDir();
1375
1376 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001377 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001378 * the filesystem designed for storing cached code.
1379 * <p>
1380 * The system will delete any files stored in this location both when your
1381 * specific application is upgraded, and when the entire platform is
1382 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001383 * <p>
1384 * This location is optimal for storing compiled or optimized code generated
1385 * by your application at runtime.
1386 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001387 * The returned path may change over time if the calling app is moved to an
1388 * adopted storage device, so only relative paths should be persisted.
1389 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001390 * Apps require no extra permissions to read or write to the returned path,
1391 * since this path lives in their private storage.
1392 *
1393 * @return The path of the directory holding application code cache files.
1394 */
1395 public abstract File getCodeCacheDir();
1396
1397 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001398 * Returns absolute path to application-specific directory on the primary
1399 * shared/external storage device where the application can place cache
1400 * files it owns. These files are internal to the application, and not
1401 * typically visible to the user as media.
1402 * <p>
1403 * This is like {@link #getCacheDir()} in that these files will be deleted
1404 * when the application is uninstalled, however there are some important
1405 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001406 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001407 * <li>The platform does not always monitor the space available in shared
1408 * storage, and thus may not automatically delete these files. Apps should
1409 * always manage the maximum space used in this location. Currently the only
1410 * time files here will be deleted by the platform is when running on
1411 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1412 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1413 * <li>Shared storage may not always be available, since removable media can
1414 * be ejected by the user. Media state can be checked using
1415 * {@link Environment#getExternalStorageState(File)}.
1416 * <li>There is no security enforced with these files. For example, any
1417 * application holding
1418 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001419 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001420 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001421 * <p>
1422 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001423 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001424 * backed by a private user data partition, which means there is little
1425 * benefit to storing data here instead of the private directory returned by
1426 * {@link #getCacheDir()}.
1427 * <p>
1428 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001429 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001430 * accessible to the calling app. This only applies to paths generated for
1431 * package name of the calling application. To access paths belonging to
1432 * other packages,
1433 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1434 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1435 * <p>
1436 * On devices with multiple users (as described by {@link UserManager}),
1437 * each user has their own isolated shared storage. Applications only have
1438 * access to the shared storage for the user they're running as.
1439 * <p>
1440 * The returned path may change over time if different shared storage media
1441 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001442 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001443 * @return the absolute path to application-specific directory. May return
1444 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001445 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001446 * @see #getExternalCacheDirs()
1447 * @see Environment#getExternalStorageState(File)
1448 * @see Environment#isExternalStorageEmulated(File)
1449 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001450 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001451 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001452 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001453
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001454 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001455 * Returns absolute path to application-specific directory in the preloaded cache.
1456 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1457 * There is no guarantee when these files will be deleted.
1458 * @hide
1459 */
1460 @Nullable
1461 @SystemApi
1462 public abstract File getPreloadsFileCache();
1463
1464 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001465 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001466 * shared/external storage devices where the application can place cache
1467 * files it owns. These files are internal to the application, and not
1468 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001469 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001470 * This is like {@link #getCacheDir()} in that these files will be deleted
1471 * when the application is uninstalled, however there are some important
1472 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001473 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001474 * <li>The platform does not always monitor the space available in shared
1475 * storage, and thus may not automatically delete these files. Apps should
1476 * always manage the maximum space used in this location. Currently the only
1477 * time files here will be deleted by the platform is when running on
1478 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1479 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1480 * <li>Shared storage may not always be available, since removable media can
1481 * be ejected by the user. Media state can be checked using
1482 * {@link Environment#getExternalStorageState(File)}.
1483 * <li>There is no security enforced with these files. For example, any
1484 * application holding
1485 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1486 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001487 * </ul>
1488 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001489 * If a shared storage device is emulated (as determined by
1490 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1491 * backed by a private user data partition, which means there is little
1492 * benefit to storing data here instead of the private directory returned by
1493 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001494 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001495 * Shared storage devices returned here are considered a stable part of the
1496 * device, including physical media slots under a protective cover. The
1497 * returned paths do not include transient devices, such as USB flash drives
1498 * connected to handheld devices.
1499 * <p>
1500 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001501 * example, an app may choose to store large files on the device with the
1502 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001503 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001504 * No additional permissions are required for the calling app to read or
1505 * write files under the returned path. Write access outside of these paths
1506 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001507 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001508 * The returned paths may change over time if different shared storage media
1509 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001510 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001511 * @return the absolute paths to application-specific directories. Some
1512 * individual paths may be {@code null} if that shared storage is
1513 * not currently available. The first path returned is the same as
1514 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001515 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001516 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001517 * @see Environment#isExternalStorageEmulated(File)
1518 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001519 */
1520 public abstract File[] getExternalCacheDirs();
1521
1522 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001523 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001524 * shared/external storage devices where the application can place media
1525 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001526 * {@link MediaStore}.
1527 * <p>
1528 * This is like {@link #getExternalFilesDirs} in that these files will be
1529 * deleted when the application is uninstalled, however there are some
1530 * important differences:
1531 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001532 * <li>Shared storage may not always be available, since removable media can
1533 * be ejected by the user. Media state can be checked using
1534 * {@link Environment#getExternalStorageState(File)}.
1535 * <li>There is no security enforced with these files. For example, any
1536 * application holding
1537 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1538 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001539 * </ul>
1540 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001541 * Shared storage devices returned here are considered a stable part of the
1542 * device, including physical media slots under a protective cover. The
1543 * returned paths do not include transient devices, such as USB flash drives
1544 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001545 * <p>
1546 * An application may store data on any or all of the returned devices. For
1547 * example, an app may choose to store large files on the device with the
1548 * most available space, as measured by {@link StatFs}.
1549 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001550 * No additional permissions are required for the calling app to read or
1551 * write files under the returned path. Write access outside of these paths
1552 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001553 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001554 * The returned paths may change over time if different shared storage media
1555 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001556 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001557 * @return the absolute paths to application-specific directories. Some
1558 * individual paths may be {@code null} if that shared storage is
1559 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001560 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001561 * @see Environment#isExternalStorageEmulated(File)
1562 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey588c15e2019-10-10 17:29:58 -06001563 * @deprecated These directories still exist and are scanned, but developers
1564 * are encouraged to migrate to inserting content into a
1565 * {@link MediaStore} collection directly, as any app can
1566 * contribute new media to {@link MediaStore} with no
1567 * permissions required, starting in
1568 * {@link android.os.Build.VERSION_CODES#Q}.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001569 */
Jeff Sharkey588c15e2019-10-10 17:29:58 -06001570 @Deprecated
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001571 public abstract File[] getExternalMediaDirs();
1572
1573 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 * Returns an array of strings naming the private files associated with
1575 * this Context's application package.
1576 *
1577 * @return Array of strings naming the private files.
1578 *
1579 * @see #openFileInput
1580 * @see #openFileOutput
1581 * @see #deleteFile
1582 */
1583 public abstract String[] fileList();
1584
1585 /**
1586 * Retrieve, creating if needed, a new directory in which the application
1587 * can place its own custom data files. You can use the returned File
1588 * object to create and access files in this directory. Note that files
1589 * created through a File object will only be accessible by your own
1590 * application; you can only set the mode of the entire directory, not
1591 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001592 * <p>
1593 * The returned path may change over time if the calling app is moved to an
1594 * adopted storage device, so only relative paths should be persisted.
1595 * <p>
1596 * Apps require no extra permissions to read or write to the returned path,
1597 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001599 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001600 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001601 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001602 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001603 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001604 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 *
1606 * @see #openFileOutput(String, int)
1607 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001608 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001609
1610 /**
1611 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001612 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 *
1614 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001615 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001616 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001617 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001619 * @throws android.database.sqlite.SQLiteException if the database file
1620 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001622 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001623 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 * @see #deleteDatabase
1625 */
1626 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001627 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628
1629 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001630 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001631 * application package. Creates the database file if it doesn't exist.
1632 * <p>
1633 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1634 * to be used to handle corruption when sqlite reports database corruption.
1635 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001636 *
1637 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001638 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001639 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001640 * cursor when query is called.
1641 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1642 * sqlite reports database corruption. if null,
1643 * {@link android.database.DefaultDatabaseErrorHandler} is
1644 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001645 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001646 * @throws android.database.sqlite.SQLiteException if the database file
1647 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001648 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001649 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001650 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001651 * @see #deleteDatabase
1652 */
1653 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001654 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001655 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001656
1657 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001658 * Move an existing database file from the given source storage context to
1659 * this context. This is typically used to migrate data between storage
1660 * locations after an upgrade, such as migrating to device protected
1661 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001662 * <p>
1663 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001664 *
1665 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001666 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001667 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001668 * @return {@code true} if the move was successful or if the database didn't
1669 * exist in the source context, otherwise {@code false}.
1670 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001671 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001672 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1673
Jeff Sharkey35871f22016-01-29 17:13:29 -07001674 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 * Delete an existing private SQLiteDatabase associated with this Context's
1676 * application package.
1677 *
1678 * @param name The name (unique in the application package) of the
1679 * database.
1680 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001681 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 *
1683 * @see #openOrCreateDatabase
1684 */
1685 public abstract boolean deleteDatabase(String name);
1686
1687 /**
1688 * Returns the absolute path on the filesystem where a database created with
1689 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001690 * <p>
1691 * The returned path may change over time if the calling app is moved to an
1692 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001693 *
1694 * @param name The name of the database for which you would like to get
1695 * its path.
1696 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001697 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001698 *
1699 * @see #openOrCreateDatabase
1700 */
1701 public abstract File getDatabasePath(String name);
1702
1703 /**
1704 * Returns an array of strings naming the private databases associated with
1705 * this Context's application package.
1706 *
1707 * @return Array of strings naming the private databases.
1708 *
1709 * @see #openOrCreateDatabase
1710 * @see #deleteDatabase
1711 */
1712 public abstract String[] databaseList();
1713
1714 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001715 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001716 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001717 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001718 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001719 public abstract Drawable getWallpaper();
1720
1721 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001722 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001723 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001725 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 public abstract Drawable peekWallpaper();
1727
1728 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001729 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1730 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001731 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001732 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001733 public abstract int getWallpaperDesiredMinimumWidth();
1734
1735 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001736 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1737 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001739 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 public abstract int getWallpaperDesiredMinimumHeight();
1741
1742 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001743 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001744 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001745 * <p>This method requires the caller to hold the permission
1746 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001747 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001748 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1750
1751 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001752 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001753 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001754 * <p>This method requires the caller to hold the permission
1755 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001757 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 public abstract void setWallpaper(InputStream data) throws IOException;
1759
1760 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001761 * @deprecated Use {@link android.app.WallpaperManager#clear
1762 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001763 * <p>This method requires the caller to hold the permission
1764 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001765 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001766 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001767 public abstract void clearWallpaper() throws IOException;
1768
1769 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001770 * Same as {@link #startActivity(Intent, Bundle)} with no options
1771 * specified.
1772 *
1773 * @param intent The description of the activity to start.
1774 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001775 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001776 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001777 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001778 * @see PackageManager#resolveActivity
1779 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001780 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001781
1782 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001783 * Version of {@link #startActivity(Intent)} that allows you to specify the
1784 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001785 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001786 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001787 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001788 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001789 * @hide
1790 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001791 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07001792 @SystemApi
Adrian Roosebc927c2019-02-28 16:21:18 +01001793 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1794 @NonNull UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001795 throw new RuntimeException("Not implemented. Must override in a subclass.");
1796 }
1797
1798 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 * Launch a new activity. You will not receive any information about when
1800 * the activity exits.
1801 *
1802 * <p>Note that if this method is being called from outside of an
1803 * {@link android.app.Activity} Context, then the Intent must include
1804 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1805 * without being started from an existing Activity, there is no existing
1806 * task in which to place the new activity and thus it needs to be placed
1807 * in its own separate task.
1808 *
1809 * <p>This method throws {@link ActivityNotFoundException}
1810 * if there was no Activity found to run the given Intent.
1811 *
1812 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001813 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001814 * May be null if there are no options. See {@link android.app.ActivityOptions}
1815 * for how to build the Bundle supplied here; there are no supported definitions
1816 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001817 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001818 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 *
Scott Main60dd5202012-06-23 00:01:22 -07001820 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 * @see PackageManager#resolveActivity
1822 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001823 public abstract void startActivity(@RequiresPermission Intent intent,
1824 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001825
1826 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001827 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1828 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001829 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001830 * @param intent The description of the activity to start.
1831 * @param options Additional options for how the Activity should be started.
1832 * May be null if there are no options. See {@link android.app.ActivityOptions}
1833 * for how to build the Bundle supplied here; there are no supported definitions
1834 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001835 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001836 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001837 * @hide
1838 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001839 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001840 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001841 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1842 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001843 throw new RuntimeException("Not implemented. Must override in a subclass.");
1844 }
1845
1846 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001847 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1848 * is only supported for Views and Fragments.
1849 * @param who The identifier for the calling element that will receive the result.
1850 * @param intent The intent to start.
1851 * @param requestCode The code that will be returned with onActivityResult() identifying this
1852 * request.
1853 * @param options Additional options for how the Activity should be started.
1854 * May be null if there are no options. See {@link android.app.ActivityOptions}
1855 * for how to build the Bundle supplied here; there are no supported definitions
1856 * for building it manually.
1857 * @hide
1858 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001859 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001860 public void startActivityForResult(
1861 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1862 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1863 + "Check canStartActivityForResult() before calling.");
1864 }
1865
1866 /**
1867 * Identifies whether this Context instance will be able to process calls to
1868 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1869 * @hide
1870 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001871 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001872 public boolean canStartActivityForResult() {
1873 return false;
1874 }
1875
1876 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001877 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1878 * specified.
1879 *
1880 * @param intents An array of Intents to be started.
1881 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001882 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001883 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001884 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001885 * @see PackageManager#resolveActivity
1886 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001887 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001888
1889 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001890 * Launch multiple new activities. This is generally the same as calling
1891 * {@link #startActivity(Intent)} for the first Intent in the array,
1892 * that activity during its creation calling {@link #startActivity(Intent)}
1893 * for the second entry, etc. Note that unlike that approach, generally
1894 * none of the activities except the last in the array will be created
1895 * at this point, but rather will be created when the user first visits
1896 * them (due to pressing back from the activity on top).
1897 *
1898 * <p>This method throws {@link ActivityNotFoundException}
1899 * if there was no Activity found for <em>any</em> given Intent. In this
1900 * case the state of the activity stack is undefined (some Intents in the
1901 * list may be on it, some not), so you probably want to avoid such situations.
1902 *
1903 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001904 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001905 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001906 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001907 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001908 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001909 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001910 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001911 * @see PackageManager#resolveActivity
1912 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001913 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001914
1915 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001916 * @hide
1917 * Launch multiple new activities. This is generally the same as calling
1918 * {@link #startActivity(Intent)} for the first Intent in the array,
1919 * that activity during its creation calling {@link #startActivity(Intent)}
1920 * for the second entry, etc. Note that unlike that approach, generally
1921 * none of the activities except the last in the array will be created
1922 * at this point, but rather will be created when the user first visits
1923 * them (due to pressing back from the activity on top).
1924 *
1925 * <p>This method throws {@link ActivityNotFoundException}
1926 * if there was no Activity found for <em>any</em> given Intent. In this
1927 * case the state of the activity stack is undefined (some Intents in the
1928 * list may be on it, some not), so you probably want to avoid such situations.
1929 *
1930 * @param intents An array of Intents to be started.
1931 * @param options Additional options for how the Activity should be started.
1932 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001933 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001934 * Context.startActivity(Intent, Bundle)} for more details.
1935 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001936 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1937 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1938 * successful.
1939 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001940 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001941 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001942 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001943 * @see PackageManager#resolveActivity
1944 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001945 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001946 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001947 throw new RuntimeException("Not implemented. Must override in a subclass.");
1948 }
1949
1950 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001951 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1952 * with no options specified.
1953 *
1954 * @param intent The IntentSender to launch.
1955 * @param fillInIntent If non-null, this will be provided as the
1956 * intent parameter to {@link IntentSender#sendIntent}.
1957 * @param flagsMask Intent flags in the original IntentSender that you
1958 * would like to change.
1959 * @param flagsValues Desired values for any bits set in
1960 * <var>flagsMask</var>
1961 * @param extraFlags Always set to 0.
1962 *
1963 * @see #startActivity(Intent)
1964 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1965 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001966 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1967 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1968 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001969
1970 /**
1971 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001972 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001973 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001974 * here; otherwise, its associated action will be executed (such as
1975 * sending a broadcast) as if you had called
1976 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001977 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001978 * @param intent The IntentSender to launch.
1979 * @param fillInIntent If non-null, this will be provided as the
1980 * intent parameter to {@link IntentSender#sendIntent}.
1981 * @param flagsMask Intent flags in the original IntentSender that you
1982 * would like to change.
1983 * @param flagsValues Desired values for any bits set in
1984 * <var>flagsMask</var>
1985 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001986 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001987 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001988 * Context.startActivity(Intent, Bundle)} for more details. If options
1989 * have also been supplied by the IntentSender, options given here will
1990 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001991 *
1992 * @see #startActivity(Intent, Bundle)
1993 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001994 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001995 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1996 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1997 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001998
1999 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002000 * Broadcast the given intent to all interested BroadcastReceivers. This
2001 * call is asynchronous; it returns immediately, and you will continue
2002 * executing while the receivers are run. No results are propagated from
2003 * receivers and receivers can not abort the broadcast. If you want
2004 * to allow receivers to propagate results or abort the broadcast, you must
2005 * send an ordered broadcast using
2006 * {@link #sendOrderedBroadcast(Intent, String)}.
2007 *
2008 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2009 *
2010 * @param intent The Intent to broadcast; all receivers matching this
2011 * Intent will receive the broadcast.
2012 *
2013 * @see android.content.BroadcastReceiver
2014 * @see #registerReceiver
2015 * @see #sendBroadcast(Intent, String)
2016 * @see #sendOrderedBroadcast(Intent, String)
2017 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2018 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002019 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002020
2021 /**
2022 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2023 * an optional required permission to be enforced. This
2024 * call is asynchronous; it returns immediately, and you will continue
2025 * executing while the receivers are run. No results are propagated from
2026 * receivers and receivers can not abort the broadcast. If you want
2027 * to allow receivers to propagate results or abort the broadcast, you must
2028 * send an ordered broadcast using
2029 * {@link #sendOrderedBroadcast(Intent, String)}.
2030 *
2031 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2032 *
2033 * @param intent The Intent to broadcast; all receivers matching this
2034 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08002035 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036 * a receiver must hold in order to receive your broadcast.
2037 * If null, no permission is required.
2038 *
2039 * @see android.content.BroadcastReceiver
2040 * @see #registerReceiver
2041 * @see #sendBroadcast(Intent)
2042 * @see #sendOrderedBroadcast(Intent, String)
2043 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2044 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002045 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002046 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002048
2049 /**
2050 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2051 * an array of required permissions to be enforced. This call is asynchronous; it returns
2052 * immediately, and you will continue executing while the receivers are run. No results are
2053 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2054 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2055 * using {@link #sendOrderedBroadcast(Intent, String)}.
2056 *
2057 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2058 *
2059 * @param intent The Intent to broadcast; all receivers matching this
2060 * Intent will receive the broadcast.
2061 * @param receiverPermissions Array of names of permissions that a receiver must hold
2062 * in order to receive your broadcast.
2063 * If null or empty, no permissions are required.
2064 *
2065 * @see android.content.BroadcastReceiver
2066 * @see #registerReceiver
2067 * @see #sendBroadcast(Intent)
2068 * @see #sendOrderedBroadcast(Intent, String)
2069 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2070 * @hide
2071 */
2072 public abstract void sendBroadcastMultiplePermissions(Intent intent,
2073 String[] receiverPermissions);
2074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002076 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07002077 * an array of required permissions to be enforced. This call is asynchronous; it returns
2078 * immediately, and you will continue executing while the receivers are run. No results are
2079 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2080 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2081 * using {@link #sendOrderedBroadcast(Intent, String)}.
2082 *
2083 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2084 *
2085 * @param intent The Intent to broadcast; all receivers matching this
2086 * Intent will receive the broadcast.
2087 * @param user The user to send the broadcast to.
2088 * @param receiverPermissions Array of names of permissions that a receiver must hold
2089 * in order to receive your broadcast.
2090 * If null or empty, no permissions are required.
2091 *
2092 * @see android.content.BroadcastReceiver
2093 * @see #registerReceiver
2094 * @see #sendBroadcast(Intent)
2095 * @see #sendOrderedBroadcast(Intent, String)
2096 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2097 * @hide
2098 */
2099 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2100 String[] receiverPermissions);
2101
2102 /**
2103 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002104 * an optional required permission to be enforced. This
2105 * call is asynchronous; it returns immediately, and you will continue
2106 * executing while the receivers are run. No results are propagated from
2107 * receivers and receivers can not abort the broadcast. If you want
2108 * to allow receivers to propagate results or abort the broadcast, you must
2109 * send an ordered broadcast using
2110 * {@link #sendOrderedBroadcast(Intent, String)}.
2111 *
2112 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2113 *
2114 * @param intent The Intent to broadcast; all receivers matching this
2115 * Intent will receive the broadcast.
2116 * @param receiverPermission (optional) String naming a permission that
2117 * a receiver must hold in order to receive your broadcast.
2118 * If null, no permission is required.
2119 * @param options (optional) Additional sending options, generated from a
2120 * {@link android.app.BroadcastOptions}.
2121 *
2122 * @see android.content.BroadcastReceiver
2123 * @see #registerReceiver
2124 * @see #sendBroadcast(Intent)
2125 * @see #sendOrderedBroadcast(Intent, String)
2126 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2127 * @hide
2128 */
2129 @SystemApi
2130 public abstract void sendBroadcast(Intent intent,
2131 @Nullable String receiverPermission,
2132 @Nullable Bundle options);
2133
2134 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002135 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002136 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002137 * @hide
2138 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002139 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002140 public abstract void sendBroadcast(Intent intent,
2141 String receiverPermission, int appOp);
2142
2143 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002144 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2145 * them one at a time to allow more preferred receivers to consume the
2146 * broadcast before it is delivered to less preferred receivers. This
2147 * call is asynchronous; it returns immediately, and you will continue
2148 * executing while the receivers are run.
2149 *
2150 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2151 *
2152 * @param intent The Intent to broadcast; all receivers matching this
2153 * Intent will receive the broadcast.
2154 * @param receiverPermission (optional) String naming a permissions that
2155 * a receiver must hold in order to receive your broadcast.
2156 * If null, no permission is required.
2157 *
2158 * @see android.content.BroadcastReceiver
2159 * @see #registerReceiver
2160 * @see #sendBroadcast(Intent)
2161 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2162 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002163 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002164 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002165
2166 /**
2167 * Version of {@link #sendBroadcast(Intent)} that allows you to
2168 * receive data back from the broadcast. This is accomplished by
2169 * supplying your own BroadcastReceiver when calling, which will be
2170 * treated as a final receiver at the end of the broadcast -- its
2171 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002172 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002173 * be serialized in the same way as calling
2174 * {@link #sendOrderedBroadcast(Intent, String)}.
2175 *
2176 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2177 * asynchronous; it will return before
2178 * resultReceiver.onReceive() is called.
2179 *
2180 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2181 *
2182 * @param intent The Intent to broadcast; all receivers matching this
2183 * Intent will receive the broadcast.
2184 * @param receiverPermission String naming a permissions that
2185 * a receiver must hold in order to receive your broadcast.
2186 * If null, no permission is required.
2187 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2188 * receiver of the broadcast.
2189 * @param scheduler A custom Handler with which to schedule the
2190 * resultReceiver callback; if null it will be
2191 * scheduled in the Context's main thread.
2192 * @param initialCode An initial value for the result code. Often
2193 * Activity.RESULT_OK.
2194 * @param initialData An initial value for the result data. Often
2195 * null.
2196 * @param initialExtras An initial value for the result extras. Often
2197 * null.
2198 *
2199 * @see #sendBroadcast(Intent)
2200 * @see #sendBroadcast(Intent, String)
2201 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 * @see android.content.BroadcastReceiver
2203 * @see #registerReceiver
2204 * @see android.app.Activity#RESULT_OK
2205 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002206 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002207 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002208 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2209 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002210
2211 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002212 * Version of {@link #sendBroadcast(Intent)} that allows you to
2213 * receive data back from the broadcast. This is accomplished by
2214 * supplying your own BroadcastReceiver when calling, which will be
2215 * treated as a final receiver at the end of the broadcast -- its
2216 * {@link BroadcastReceiver#onReceive} method will be called with
2217 * the result values collected from the other receivers. The broadcast will
2218 * be serialized in the same way as calling
2219 * {@link #sendOrderedBroadcast(Intent, String)}.
2220 *
2221 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2222 * asynchronous; it will return before
2223 * resultReceiver.onReceive() is called.
2224 *
2225 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2226 *
2227 *
2228 * @param intent The Intent to broadcast; all receivers matching this
2229 * Intent will receive the broadcast.
2230 * @param receiverPermission String naming a permissions that
2231 * a receiver must hold in order to receive your broadcast.
2232 * If null, no permission is required.
2233 * @param options (optional) Additional sending options, generated from a
2234 * {@link android.app.BroadcastOptions}.
2235 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2236 * receiver of the broadcast.
2237 * @param scheduler A custom Handler with which to schedule the
2238 * resultReceiver callback; if null it will be
2239 * scheduled in the Context's main thread.
2240 * @param initialCode An initial value for the result code. Often
2241 * Activity.RESULT_OK.
2242 * @param initialData An initial value for the result data. Often
2243 * null.
2244 * @param initialExtras An initial value for the result extras. Often
2245 * null.
2246 * @see #sendBroadcast(Intent)
2247 * @see #sendBroadcast(Intent, String)
2248 * @see #sendOrderedBroadcast(Intent, String)
2249 * @see android.content.BroadcastReceiver
2250 * @see #registerReceiver
2251 * @see android.app.Activity#RESULT_OK
2252 * @hide
2253 */
2254 @SystemApi
2255 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2256 @Nullable String receiverPermission, @Nullable Bundle options,
2257 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2258 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2259
2260 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002261 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2262 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002263 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002264 * @hide
2265 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002266 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002267 public abstract void sendOrderedBroadcast(Intent intent,
2268 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2269 Handler scheduler, int initialCode, String initialData,
2270 Bundle initialExtras);
2271
2272 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002273 * Version of {@link #sendBroadcast(Intent)} 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 Hackborn7d19e022012-08-07 19:12:33 -07002276 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002277 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002278 * @see #sendBroadcast(Intent)
2279 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002280 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002281 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2282 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002283
2284 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002285 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2286 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002287 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002288 *
2289 * @param intent The Intent to broadcast; all receivers matching this
2290 * Intent will receive the broadcast.
2291 * @param user UserHandle to send the intent to.
2292 * @param receiverPermission (optional) String naming a permission that
2293 * a receiver must hold in order to receive your broadcast.
2294 * If null, no permission is required.
2295 *
2296 * @see #sendBroadcast(Intent, String)
2297 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002298 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002299 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2300 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002301
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002302 /**
2303 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2304 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002305 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002306 *
2307 * @param intent The Intent to broadcast; all receivers matching this
2308 * Intent will receive the broadcast.
2309 * @param user UserHandle to send the intent to.
2310 * @param receiverPermission (optional) String naming a permission that
2311 * a receiver must hold in order to receive your broadcast.
2312 * If null, no permission is required.
2313 * @param options (optional) Additional sending options, generated from a
2314 * {@link android.app.BroadcastOptions}.
2315 *
2316 * @see #sendBroadcast(Intent, String, Bundle)
2317 * @hide
2318 */
2319 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002320 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002321 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2322 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002323
2324 /**
2325 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2326 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002327 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002328 *
2329 * @param intent The Intent to broadcast; all receivers matching this
2330 * Intent will receive the broadcast.
2331 * @param user UserHandle to send the intent to.
2332 * @param receiverPermission (optional) String naming a permission that
2333 * a receiver must hold in order to receive your broadcast.
2334 * If null, no permission is required.
2335 * @param appOp The app op associated with the broadcast.
2336 *
2337 * @see #sendBroadcast(Intent, String)
2338 *
2339 * @hide
2340 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002341 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002342 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002343 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2344 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002345
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002346 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002347 * Version of
2348 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2349 * that allows you to specify the
2350 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002351 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002352 *
2353 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2354 *
2355 * @param intent The Intent to broadcast; all receivers matching this
2356 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002357 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002358 * @param receiverPermission String naming a permissions that
2359 * a receiver must hold in order to receive your broadcast.
2360 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002361 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2362 * receiver of the broadcast.
2363 * @param scheduler A custom Handler with which to schedule the
2364 * resultReceiver callback; if null it will be
2365 * scheduled in the Context's main thread.
2366 * @param initialCode An initial value for the result code. Often
2367 * Activity.RESULT_OK.
2368 * @param initialData An initial value for the result data. Often
2369 * null.
2370 * @param initialExtras An initial value for the result extras. Often
2371 * null.
2372 *
2373 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2374 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002375 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002376 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2377 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002378 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2379 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002380
2381 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002382 * Similar to above but takes an appOp as well, to enforce restrictions.
2383 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2384 * BroadcastReceiver, Handler, int, String, Bundle)
2385 * @hide
2386 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002387 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002388 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002389 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2390 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2391 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2392 @Nullable Bundle initialExtras);
2393
2394 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002395 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2396 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2397 * BroadcastReceiver, Handler, int, String, Bundle)
2398 * @hide
2399 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002400 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002401 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002402 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2403 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2404 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2405 @Nullable String initialData, @Nullable Bundle initialExtras);
2406
2407 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002408 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 * Intent you are sending stays around after the broadcast is complete,
2410 * so that others can quickly retrieve that data through the return
2411 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2412 * all other ways, this behaves the same as
2413 * {@link #sendBroadcast(Intent)}.
2414 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002415 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2416 * can access them), no protection (anyone can modify them), and many other problems.
2417 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2418 * has changed, with another mechanism for apps to retrieve the current value whenever
2419 * desired.
2420 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002421 * @param intent The Intent to broadcast; all receivers matching this
2422 * Intent will receive the broadcast, and the Intent will be held to
2423 * be re-broadcast to future receivers.
2424 *
2425 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002426 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002427 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002428 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002429 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002430 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002431
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002432 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002433 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002434 * receive data back from the broadcast. This is accomplished by
2435 * supplying your own BroadcastReceiver when calling, which will be
2436 * treated as a final receiver at the end of the broadcast -- its
2437 * {@link BroadcastReceiver#onReceive} method will be called with
2438 * the result values collected from the other receivers. The broadcast will
2439 * be serialized in the same way as calling
2440 * {@link #sendOrderedBroadcast(Intent, String)}.
2441 *
2442 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2443 * asynchronous; it will return before
2444 * resultReceiver.onReceive() is called. Note that the sticky data
2445 * stored is only the data you initially supply to the broadcast, not
2446 * the result of any changes made by the receivers.
2447 *
2448 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2449 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002450 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2451 * can access them), no protection (anyone can modify them), and many other problems.
2452 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2453 * has changed, with another mechanism for apps to retrieve the current value whenever
2454 * desired.
2455 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002456 * @param intent The Intent to broadcast; all receivers matching this
2457 * Intent will receive the broadcast.
2458 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2459 * receiver of the broadcast.
2460 * @param scheduler A custom Handler with which to schedule the
2461 * resultReceiver callback; if null it will be
2462 * scheduled in the Context's main thread.
2463 * @param initialCode An initial value for the result code. Often
2464 * Activity.RESULT_OK.
2465 * @param initialData An initial value for the result data. Often
2466 * null.
2467 * @param initialExtras An initial value for the result extras. Often
2468 * null.
2469 *
2470 * @see #sendBroadcast(Intent)
2471 * @see #sendBroadcast(Intent, String)
2472 * @see #sendOrderedBroadcast(Intent, String)
2473 * @see #sendStickyBroadcast(Intent)
2474 * @see android.content.BroadcastReceiver
2475 * @see #registerReceiver
2476 * @see android.app.Activity#RESULT_OK
2477 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002478 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002479 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002480 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002481 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002482 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2483 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002486 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002487 * so that it is as if the sticky broadcast had never happened.
2488 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002489 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2490 * can access them), no protection (anyone can modify them), and many other problems.
2491 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2492 * has changed, with another mechanism for apps to retrieve the current value whenever
2493 * desired.
2494 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002495 * @param intent The Intent that was previously broadcast.
2496 *
2497 * @see #sendStickyBroadcast
2498 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002499 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002500 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002501 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002502
2503 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002504 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002505 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002506 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002507 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002508 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2509 * can access them), no protection (anyone can modify them), and many other problems.
2510 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2511 * has changed, with another mechanism for apps to retrieve the current value whenever
2512 * desired.
2513 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002514 * @param intent The Intent to broadcast; all receivers matching this
2515 * Intent will receive the broadcast, and the Intent will be held to
2516 * be re-broadcast to future receivers.
2517 * @param user UserHandle to send the intent to.
2518 *
2519 * @see #sendBroadcast(Intent)
2520 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002521 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002522 @RequiresPermission(allOf = {
2523 android.Manifest.permission.INTERACT_ACROSS_USERS,
2524 android.Manifest.permission.BROADCAST_STICKY
2525 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002526 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2527 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002528
2529 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002530 * @hide
2531 * This is just here for sending CONNECTIVITY_ACTION.
2532 */
2533 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002534 @RequiresPermission(allOf = {
2535 android.Manifest.permission.INTERACT_ACROSS_USERS,
2536 android.Manifest.permission.BROADCAST_STICKY
2537 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002538 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2539 UserHandle user, Bundle options);
2540
2541 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002542 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002543 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2544 * that allows you to specify the
2545 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002546 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002547 *
2548 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2549 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002550 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2551 * can access them), no protection (anyone can modify them), and many other problems.
2552 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2553 * has changed, with another mechanism for apps to retrieve the current value whenever
2554 * desired.
2555 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002556 * @param intent The Intent to broadcast; all receivers matching this
2557 * Intent will receive the broadcast.
2558 * @param user UserHandle to send the intent to.
2559 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2560 * receiver of the broadcast.
2561 * @param scheduler A custom Handler with which to schedule the
2562 * resultReceiver callback; if null it will be
2563 * scheduled in the Context's main thread.
2564 * @param initialCode An initial value for the result code. Often
2565 * Activity.RESULT_OK.
2566 * @param initialData An initial value for the result data. Often
2567 * null.
2568 * @param initialExtras An initial value for the result extras. Often
2569 * null.
2570 *
2571 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2572 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002573 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002574 @RequiresPermission(allOf = {
2575 android.Manifest.permission.INTERACT_ACROSS_USERS,
2576 android.Manifest.permission.BROADCAST_STICKY
2577 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002578 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002579 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002580 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2581 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002582
2583 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002584 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002585 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002586 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002587 *
2588 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2589 * permission in order to use this API. If you do not hold that
2590 * permission, {@link SecurityException} will be thrown.
2591 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002592 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2593 * can access them), no protection (anyone can modify them), and many other problems.
2594 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2595 * has changed, with another mechanism for apps to retrieve the current value whenever
2596 * desired.
2597 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002598 * @param intent The Intent that was previously broadcast.
2599 * @param user UserHandle to remove the sticky broadcast from.
2600 *
2601 * @see #sendStickyBroadcastAsUser
2602 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002603 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002604 @RequiresPermission(allOf = {
2605 android.Manifest.permission.INTERACT_ACROSS_USERS,
2606 android.Manifest.permission.BROADCAST_STICKY
2607 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002608 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2609 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002610
2611 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002612 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002613 * <var>receiver</var> will be called with any broadcast Intent that
2614 * matches <var>filter</var>, in the main application thread.
2615 *
2616 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002617 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 * registrations. If your IntentFilter matches one of these sticky
2619 * Intents, that Intent will be returned by this function
2620 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2621 * been broadcast.
2622 *
2623 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2624 * in which case each of these will be sent to <var>receiver</var>. In
2625 * this case, only one of these can be returned directly by the function;
2626 * which of these that is returned is arbitrarily decided by the system.
2627 *
2628 * <p>If you know the Intent your are registering for is sticky, you can
2629 * supply null for your <var>receiver</var>. In this case, no receiver is
2630 * registered -- the function simply returns the sticky Intent that
2631 * matches <var>filter</var>. In the case of multiple matches, the same
2632 * rules as described above apply.
2633 *
2634 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2635 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002636 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2637 * registered with this method will correctly respect the
2638 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2639 * Prior to that, it would be ignored and delivered to all matching registered
2640 * receivers. Be careful if using this for security.</p>
2641 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002642 * <p class="note">Note: this method <em>cannot be called from a
2643 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2644 * that is declared in an application's manifest. It is okay, however, to call
2645 * this method from another BroadcastReceiver that has itself been registered
2646 * at run time with {@link #registerReceiver}, since the lifetime of such a
2647 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 *
2649 * @param receiver The BroadcastReceiver to handle the broadcast.
2650 * @param filter Selects the Intent broadcasts to be received.
2651 *
2652 * @return The first sticky intent found that matches <var>filter</var>,
2653 * or null if there are none.
2654 *
2655 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2656 * @see #sendBroadcast
2657 * @see #unregisterReceiver
2658 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002659 @Nullable
2660 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 IntentFilter filter);
2662
2663 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002664 * Register to receive intent broadcasts, with the receiver optionally being
2665 * exposed to Instant Apps. See
2666 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2667 * information. By default Instant Apps cannot interact with receivers in other
2668 * applications, this allows you to expose a receiver that Instant Apps can
2669 * interact with.
2670 *
2671 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2672 *
2673 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2674 * registered with this method will correctly respect the
2675 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2676 * Prior to that, it would be ignored and delivered to all matching registered
2677 * receivers. Be careful if using this for security.</p>
2678 *
2679 * @param receiver The BroadcastReceiver to handle the broadcast.
2680 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002681 * @param flags Additional options for the receiver. May be 0 or
2682 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002683 *
2684 * @return The first sticky intent found that matches <var>filter</var>,
2685 * or null if there are none.
2686 *
2687 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2688 * @see #sendBroadcast
2689 * @see #unregisterReceiver
2690 */
2691 @Nullable
2692 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2693 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002694 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002695
2696 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 * Register to receive intent broadcasts, to run in the context of
2698 * <var>scheduler</var>. See
2699 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2700 * information. This allows you to enforce permissions on who can
2701 * broadcast intents to your receiver, or have the receiver run in
2702 * a different thread than the main application thread.
2703 *
2704 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2705 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002706 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2707 * registered with this method will correctly respect the
2708 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2709 * Prior to that, it would be ignored and delivered to all matching registered
2710 * receivers. Be careful if using this for security.</p>
2711 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 * @param receiver The BroadcastReceiver to handle the broadcast.
2713 * @param filter Selects the Intent broadcasts to be received.
2714 * @param broadcastPermission String naming a permissions that a
2715 * broadcaster must hold in order to send an Intent to you. If null,
2716 * no permission is required.
2717 * @param scheduler Handler identifying the thread that will receive
2718 * the Intent. If null, the main thread of the process will be used.
2719 *
2720 * @return The first sticky intent found that matches <var>filter</var>,
2721 * or null if there are none.
2722 *
2723 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2724 * @see #sendBroadcast
2725 * @see #unregisterReceiver
2726 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002727 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002729 IntentFilter filter, @Nullable String broadcastPermission,
2730 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002731
2732 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002733 * Register to receive intent broadcasts, to run in the context of
2734 * <var>scheduler</var>. See
2735 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002736 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2737 * for more information.
2738 *
2739 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2740 *
2741 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2742 * registered with this method will correctly respect the
2743 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2744 * Prior to that, it would be ignored and delivered to all matching registered
2745 * receivers. Be careful if using this for security.</p>
2746 *
2747 * @param receiver The BroadcastReceiver to handle the broadcast.
2748 * @param filter Selects the Intent broadcasts to be received.
2749 * @param broadcastPermission String naming a permissions that a
2750 * broadcaster must hold in order to send an Intent to you. If null,
2751 * no permission is required.
2752 * @param scheduler Handler identifying the thread that will receive
2753 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002754 * @param flags Additional options for the receiver. May be 0 or
2755 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002756 *
2757 * @return The first sticky intent found that matches <var>filter</var>,
2758 * or null if there are none.
2759 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002760 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002761 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2762 * @see #sendBroadcast
2763 * @see #unregisterReceiver
2764 */
2765 @Nullable
2766 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2767 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002768 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002769
2770 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002771 * @hide
2772 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2773 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002774 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002775 *
2776 * @param receiver The BroadcastReceiver to handle the broadcast.
2777 * @param user UserHandle to send the intent to.
2778 * @param filter Selects the Intent broadcasts to be received.
2779 * @param broadcastPermission String naming a permissions that a
2780 * broadcaster must hold in order to send an Intent to you. If null,
2781 * no permission is required.
2782 * @param scheduler Handler identifying the thread that will receive
2783 * the Intent. If null, the main thread of the process will be used.
2784 *
2785 * @return The first sticky intent found that matches <var>filter</var>,
2786 * or null if there are none.
2787 *
Jeff Brown6e539312015-02-24 18:53:21 -08002788 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002789 * @see #sendBroadcast
2790 * @see #unregisterReceiver
2791 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002792 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002793 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002794 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002795 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002796 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2797 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002798
2799 /**
2800 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2801 * filters that have been registered for this BroadcastReceiver will be
2802 * removed.
2803 *
2804 * @param receiver The BroadcastReceiver to unregister.
2805 *
2806 * @see #registerReceiver
2807 */
2808 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2809
2810 /**
2811 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002812 * should either contain the complete class name of a specific service
2813 * implementation to start, or a specific package name to target. If the
2814 * Intent is less specified, it logs a warning about this. In this case any of the
2815 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 * is not already running, it will be instantiated and started (creating a
2817 * process for it if needed); if it is running then it remains running.
2818 *
2819 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002820 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 * with the <var>intent</var> given here. This provides a convenient way
2822 * to submit jobs to a service without having to bind and call on to its
2823 * interface.
2824 *
2825 * <p>Using startService() overrides the default service lifetime that is
2826 * managed by {@link #bindService}: it requires the service to remain
2827 * running until {@link #stopService} is called, regardless of whether
2828 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002829 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002830 * a single call to {@link #stopService} will stop it.
2831 *
2832 * <p>The system attempts to keep running services around as much as
2833 * possible. The only time they should be stopped is if the current
2834 * foreground application is using so many resources that the service needs
2835 * to be killed. If any errors happen in the service's process, it will
2836 * automatically be restarted.
2837 *
2838 * <p>This function will throw {@link SecurityException} if you do not
2839 * have permission to start the given service.
2840 *
Chris Craik1e353522016-04-18 10:20:50 -07002841 * <p class="note"><strong>Note:</strong> Each call to startService()
2842 * results in significant work done by the system to manage service
2843 * lifecycle surrounding the processing of the intent, which can take
2844 * multiple milliseconds of CPU time. Due to this cost, startService()
2845 * should not be used for frequent intent delivery to a service, and only
2846 * for scheduling significant work. Use {@link #bindService bound services}
2847 * for high frequency calls.
2848 * </p>
2849 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002850 * @param service Identifies the service to be started. The Intent must be
2851 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 * may be included in the Intent extras to supply arguments along with
2853 * this specific start call.
2854 *
2855 * @return If the service is being started or is already running, the
2856 * {@link ComponentName} of the actual service that was started is
2857 * returned; else if the service does not exist null is returned.
2858 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002859 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002860 * or the service can not be found.
2861 * @throws IllegalStateException If the application is in a state where the service
2862 * 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 -08002863 *
2864 * @see #stopService
2865 * @see #bindService
2866 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002867 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 public abstract ComponentName startService(Intent service);
2869
2870 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002871 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002872 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2873 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002874 * an amount of time comparable to the ANR interval to do this, otherwise the system
2875 * will automatically stop the service and declare the app ANR.
2876 *
2877 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2878 * at any time, regardless of whether the app hosting the service is in a foreground
2879 * state.
2880 *
2881 * @param service Identifies the service to be started. The Intent must be
2882 * fully explicit (supplying a component name). Additional values
2883 * may be included in the Intent extras to supply arguments along with
2884 * this specific start call.
2885 *
2886 * @return If the service is being started or is already running, the
2887 * {@link ComponentName} of the actual service that was started is
2888 * returned; else if the service does not exist null is returned.
2889 *
2890 * @throws SecurityException If the caller does not have permission to access the service
2891 * or the service can not be found.
2892 *
2893 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002894 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002895 */
2896 @Nullable
2897 public abstract ComponentName startForegroundService(Intent service);
2898
2899 /**
2900 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2901 */
2902 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002903 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002904 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2905
2906 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002907 * Request that a given application service be stopped. If the service is
2908 * not running, nothing happens. Otherwise it is stopped. Note that calls
2909 * to startService() are not counted -- this stops the service no matter
2910 * how many times it was started.
2911 *
2912 * <p>Note that if a stopped service still has {@link ServiceConnection}
2913 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2914 * not be destroyed until all of these bindings are removed. See
2915 * the {@link android.app.Service} documentation for more details on a
2916 * service's lifecycle.
2917 *
2918 * <p>This function will throw {@link SecurityException} if you do not
2919 * have permission to stop the given service.
2920 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002921 * @param service Description of the service to be stopped. The Intent must be either
2922 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07002923 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002924 *
2925 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002926 * 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 -08002927 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002928 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002929 * or the service can not be found.
2930 * @throws IllegalStateException If the application is in a state where the service
2931 * 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 -08002932 *
2933 * @see #startService
2934 */
2935 public abstract boolean stopService(Intent service);
2936
2937 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002938 * @hide like {@link #startService(Intent)} but for a specific user.
2939 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002940 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002941 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002942 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002943 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2944
2945 /**
2946 * @hide like {@link #stopService(Intent)} but for a specific user.
2947 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002948 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002949 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002950
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002951 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 * Connect to an application service, creating it if needed. This defines
2953 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002954 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 * told if it dies and restarts. The service will be considered required
2956 * by the system only for as long as the calling context exists. For
2957 * example, if this Context is an Activity that is stopped, the service will
2958 * not be required to continue running until the Activity is resumed.
2959 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002960 * <p>If the service does not support binding, it may return {@code null} from
2961 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
2962 * the ServiceConnection's
2963 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
2964 * will be invoked instead of
2965 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
2966 *
2967 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 * have permission to bind to the given service.
2969 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002970 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002971 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002972 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 * {@link #startService} with the arguments containing the command to be
2974 * sent, with the service calling its
2975 * {@link android.app.Service#stopSelf(int)} method when done executing
2976 * that command. See the API demo App/Service/Service Start Arguments
2977 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002978 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2980 * is tied to another object (the one that registered it).</p>
2981 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002982 * @param service Identifies the service to connect to. The Intent must
2983 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002985 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002986 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002987 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2988 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
Dianne Hackborn27b4d942018-11-12 15:01:40 -08002989 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
2990 * {@link #BIND_IMPORTANT}, or
2991 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07002992 * @return {@code true} if the system is in the process of bringing up a
2993 * service that your client has permission to bind to; {@code false}
2994 * if the system couldn't find the service or if your client doesn't
2995 * have permission to bind to it. If this value is {@code true}, you
2996 * should later call {@link #unbindService} to release the
2997 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002999 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003000 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 *
3002 * @see #unbindService
3003 * @see #startService
3004 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07003005 * @see #BIND_DEBUG_UNBIND
3006 * @see #BIND_NOT_FOREGROUND
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003007 * @see #BIND_ABOVE_CLIENT
3008 * @see #BIND_ALLOW_OOM_MANAGEMENT
3009 * @see #BIND_WAIVE_PRIORITY
3010 * @see #BIND_IMPORTANT
3011 * @see #BIND_ADJUST_WITH_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07003013 public abstract boolean bindService(@RequiresPermission Intent service,
3014 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003015
3016 /**
Bo Liu58a57662019-03-06 20:21:45 +00003017 * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control
3018 * ServiceConnection callbacks.
3019 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
3020 * instance for the same instance of ServiceConnection.
3021 */
3022 public boolean bindService(@RequiresPermission @NonNull Intent service,
3023 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
3024 @NonNull ServiceConnection conn) {
3025 throw new RuntimeException("Not implemented. Must override in a subclass.");
3026 }
3027
3028 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003029 * Variation of {@link #bindService} that, in the specific case of isolated
3030 * services, allows the caller to generate multiple instances of a service
Dianne Hackborncc67f962019-04-29 16:32:44 -07003031 * from a single component declaration. In other words, you can use this to bind
3032 * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
3033 * addition to the existing behavior of running in an isolated process, you can
3034 * also through the arguments here have the system bring up multiple concurrent
3035 * processes hosting their own instances of that service. The <var>instanceName</var>
3036 * you provide here identifies the different instances, and you can use
3037 * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
3038 * should manage each of these instances.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003039 *
3040 * @param service Identifies the service to connect to. The Intent must
3041 * specify an explicit component name.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003042 * @param flags Operation options for the binding as per {@link #bindService}.
3043 * @param instanceName Unique identifier for the service instance. Each unique
Robert Seseke3a5bc62019-04-22 17:43:03 -04003044 * name here will result in a different service instance being created. Identifiers
3045 * must only contain ASCII letters, digits, underscores, and periods.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003046 * @return Returns success of binding as per {@link #bindService}.
Bo Liu58a57662019-03-06 20:21:45 +00003047 * @param executor Callbacks on ServiceConnection will be called on executor.
3048 * Must use same instance for the same instance of ServiceConnection.
3049 * @param conn Receives information as the service is started and stopped.
3050 * This must be a valid ServiceConnection object; it must not be null.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003051 *
3052 * @throws SecurityException If the caller does not have permission to access the service
Robert Seseke3a5bc62019-04-22 17:43:03 -04003053 * @throws IllegalArgumentException If the instanceName is invalid.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003054 *
3055 * @see #bindService
Dianne Hackborncc67f962019-04-29 16:32:44 -07003056 * @see #updateServiceGroup
3057 * @see android.R.attr#isolatedProcess
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003058 */
Adrian Roosebc927c2019-02-28 16:21:18 +01003059 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
Bo Liu58a57662019-03-06 20:21:45 +00003060 @BindServiceFlags int flags, @NonNull String instanceName,
3061 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003062 throw new RuntimeException("Not implemented. Must override in a subclass.");
3063 }
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003064
3065 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003066 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003067 * argument for use by system server and other multi-user aware code.
3068 * @hide
3069 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07003070 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08003071 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003072 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07003073 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08003074 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003075 throw new RuntimeException("Not implemented. Must override in a subclass.");
3076 }
3077
3078 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003079 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
Adrian Roos691546e2016-02-09 10:13:41 -08003080 * explicit non-null Handler to run the ServiceConnection callbacks on.
3081 *
3082 * @hide
3083 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003084 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood7bcc1742019-07-04 11:39:42 +01003085 @UnsupportedAppUsage(trackingBug = 136728678)
Adrian Roos691546e2016-02-09 10:13:41 -08003086 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3087 Handler handler, UserHandle user) {
3088 throw new RuntimeException("Not implemented. Must override in a subclass.");
3089 }
3090
3091 /**
Dianne Hackborna631d562018-11-20 15:58:15 -08003092 * For a service previously bound with {@link #bindService} or a related method, change
3093 * how the system manages that service's process in relation to other processes. This
3094 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3095 * how the process will be managed in some cases based on those flags. Currently only
3096 * works on isolated processes (will be ignored for non-isolated processes).
3097 *
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -08003098 * <p>Note that this call does not take immediate effect, but will be applied the next
3099 * time the impacted process is adjusted for some other reason. Typically you would
3100 * call this before then calling a new {@link #bindIsolatedService} on the service
3101 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3102 *
Dianne Hackborna631d562018-11-20 15:58:15 -08003103 * @param conn The connection interface previously supplied to bindService(). This
3104 * parameter must not be null.
3105 * @param group A group to put this connection's process in. Upon calling here, this
3106 * will override any previous group that was set for that process. The group
3107 * tells the system about processes that are logically grouped together, so
3108 * should be managed as one unit of importance (such as when being considered
3109 * a recently used app). All processes in the same app with the same group
3110 * are considered to be related. Supplying 0 reverts to the default behavior
3111 * of not grouping.
3112 * @param importance Additional importance of the processes within a group. Upon calling
Dianne Hackborncc67f962019-04-29 16:32:44 -07003113 * here, this will override any previous importance that was set for that
3114 * process. The most important process is 0, and higher values are
3115 * successively less important. You can view this as describing how
3116 * to order the processes in an array, with the processes at the end of
3117 * the array being the least important. This value has no meaning besides
3118 * indicating how processes should be ordered in that array one after the
3119 * other. This provides a way to fine-tune the system's process killing,
3120 * guiding it to kill processes at the end of the array first.
3121 *
3122 * @see #bindIsolatedService
Dianne Hackborna631d562018-11-20 15:58:15 -08003123 */
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003124 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3125 int importance) {
3126 throw new RuntimeException("Not implemented. Must override in a subclass.");
3127 }
Dianne Hackborna631d562018-11-20 15:58:15 -08003128
3129 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 * Disconnect from an application service. You will no longer receive
3131 * calls as the service is restarted, and the service is now allowed to
3132 * stop at any time.
3133 *
3134 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07003135 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 *
3137 * @see #bindService
3138 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003139 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003140
3141 /**
3142 * Start executing an {@link android.app.Instrumentation} class. The given
3143 * Instrumentation component will be run by killing its target application
3144 * (if currently running), starting the target process, instantiating the
3145 * instrumentation component, and then letting it drive the application.
3146 *
3147 * <p>This function is not synchronous -- it returns as soon as the
3148 * instrumentation has started and while it is running.
3149 *
3150 * <p>Instrumentation is normally only allowed to run against a package
3151 * that is either unsigned or signed with a signature that the
3152 * the instrumentation package is also signed with (ensuring the target
3153 * trusts the instrumentation).
3154 *
3155 * @param className Name of the Instrumentation component to be run.
3156 * @param profileFile Optional path to write profiling data as the
3157 * instrumentation runs, or null for no profiling.
3158 * @param arguments Additional optional arguments to pass to the
3159 * instrumentation, or null.
3160 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003161 * @return {@code true} if the instrumentation was successfully started,
3162 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003164 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3165 @Nullable String profileFile, @Nullable Bundle arguments);
3166
3167 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07003168 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07003169 POWER_SERVICE,
3170 WINDOW_SERVICE,
3171 LAYOUT_INFLATER_SERVICE,
3172 ACCOUNT_SERVICE,
3173 ACTIVITY_SERVICE,
3174 ALARM_SERVICE,
3175 NOTIFICATION_SERVICE,
3176 ACCESSIBILITY_SERVICE,
3177 CAPTIONING_SERVICE,
3178 KEYGUARD_SERVICE,
3179 LOCATION_SERVICE,
3180 //@hide: COUNTRY_DETECTOR,
3181 SEARCH_SERVICE,
3182 SENSOR_SERVICE,
Chad Brubaker90f391f2018-10-19 10:26:19 -07003183 SENSOR_PRIVACY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003184 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003185 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003186 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003187 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003188 VIBRATOR_SERVICE,
3189 //@hide: STATUS_BAR_SERVICE,
3190 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003191 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003192 IPSEC_SERVICE,
Benedict Wong99a48412018-11-09 14:45:34 -08003193 TEST_NETWORK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003194 //@hide: UPDATE_LOCK_SERVICE,
3195 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003196 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003197 //@hide: NETWORK_POLICY_SERVICE,
3198 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003199 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003200 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003201 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003202 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003203 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003204 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003205 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003206 NSD_SERVICE,
3207 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003208 FINGERPRINT_SERVICE,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003209 //@hide: FACE_SERVICE,
Kevin Chyn05c21502018-09-18 13:07:19 -07003210 BIOMETRIC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003211 MEDIA_ROUTER_SERVICE,
3212 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003213 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003214 CARRIER_CONFIG_SERVICE,
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003215 EUICC_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003216 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003217 CLIPBOARD_SERVICE,
3218 INPUT_METHOD_SERVICE,
3219 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003220 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003221 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003222 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003223 //@hide: BACKUP_SERVICE,
Richard Uhlerb29f1452018-09-12 16:38:15 +01003224 ROLLBACK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003225 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003226 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003227 DEVICE_POLICY_SERVICE,
3228 UI_MODE_SERVICE,
3229 DOWNLOAD_SERVICE,
3230 NFC_SERVICE,
3231 BLUETOOTH_SERVICE,
3232 //@hide: SIP_SERVICE,
3233 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003234 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003235 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003236 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003237 INPUT_SERVICE,
3238 DISPLAY_SERVICE,
Christine Franks39b03112018-07-03 14:46:07 -07003239 //@hide COLOR_DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003240 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003241 RESTRICTIONS_SERVICE,
3242 APP_OPS_SERVICE,
Hai Zhangb7776682018-09-25 15:10:57 -07003243 ROLE_SERVICE,
Hai Zhanga4959e52019-03-06 12:21:07 -08003244 //@hide ROLE_CONTROLLER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003245 CAMERA_SERVICE,
atrostde54a8ac2019-08-15 16:53:01 +01003246 //@hide: PLATFORM_COMPAT_SERVICE,
atrost87488352019-10-10 19:27:31 +01003247 //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003248 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003249 CONSUMER_IR_SERVICE,
3250 //@hide: TRUST_SERVICE,
3251 TV_INPUT_SERVICE,
3252 //@hide: NETWORK_SCORE_SERVICE,
3253 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003254 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003255 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003256 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003257 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003258 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003259 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003260 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003261 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003262 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003263 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003264 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003265 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003266 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003267 //@hide: INCIDENT_SERVICE,
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08003268 //@hide: INCIDENT_COMPANION_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003269 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003270 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003271 CROSS_PROFILE_APPS_SERVICE,
3272 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerfeeee682018-05-30 14:35:24 +01003273 //@hide: TIME_DETECTOR_SERVICE,
Philip P. Moltmann039678e2018-09-18 13:04:38 -07003274 PERMISSION_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003275 })
3276 @Retention(RetentionPolicy.SOURCE)
3277 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003278
3279 /**
3280 * Return the handle to a system-level service by name. The class of the
3281 * returned object varies by the requested name. Currently available names
3282 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003283 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003284 * <dl>
3285 * <dt> {@link #WINDOW_SERVICE} ("window")
3286 * <dd> The top-level window manager in which you can place custom
3287 * windows. The returned object is a {@link android.view.WindowManager}.
3288 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3289 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3290 * in this context.
3291 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3292 * <dd> A {@link android.app.ActivityManager} for interacting with the
3293 * global activity state of the system.
3294 * <dt> {@link #POWER_SERVICE} ("power")
3295 * <dd> A {@link android.os.PowerManager} for controlling power
3296 * management.
3297 * <dt> {@link #ALARM_SERVICE} ("alarm")
3298 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3299 * time of your choosing.
3300 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3301 * <dd> A {@link android.app.NotificationManager} for informing the user
3302 * of background events.
3303 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3304 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3305 * <dt> {@link #LOCATION_SERVICE} ("location")
3306 * <dd> A {@link android.location.LocationManager} for controlling location
3307 * (e.g., GPS) updates.
3308 * <dt> {@link #SEARCH_SERVICE} ("search")
3309 * <dd> A {@link android.app.SearchManager} for handling search.
3310 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3311 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3312 * hardware.
Sudheer Shanka09b0ee62019-10-03 14:45:15 -07003313 * <dt> {@link #CONNECTIVITY_SERVICE} ("connectivity")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003314 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3315 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003316 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3317 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3318 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003319 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003320 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3321 * connectivity. On releases before NYC, it should only be obtained from an application
3322 * context, and not from any other derived context to avoid memory leaks within the calling
3323 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003324 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3325 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3326 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003327 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3328 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3329 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003330 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3331 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3332 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003333 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3334 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003335 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003336 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003337 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003338 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003339 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3340 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003341 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3342 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3343 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003344 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003345 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003347 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 * <p>Note: System services obtained via this API may be closely associated with
3349 * the Context in which they are obtained from. In general, do not share the
3350 * service objects between various different contexts (Activities, Applications,
3351 * Services, Providers, etc.)
3352 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003353 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3354 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003355 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3356 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3357 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3358 * return <code>null</code>. Generally, if you are running as an instant app you should always
Felipe Leme4685b862019-03-06 10:32:33 -08003359 * check whether the result of this method is {@code null}.
3360 *
3361 * <p>Note: When implementing this method, keep in mind that new services can be added on newer
3362 * Android releases, so if you're looking for just the explicit names mentioned above, make sure
3363 * to return {@code null} when you don't recognize the name &mdash; if you throw a
3364 * {@link RuntimeException} exception instead, you're app might break on new Android releases.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003365 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003367 *
Felipe Leme4685b862019-03-06 10:32:33 -08003368 * @return The service or {@code null} if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003369 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003370 * @see #WINDOW_SERVICE
3371 * @see android.view.WindowManager
3372 * @see #LAYOUT_INFLATER_SERVICE
3373 * @see android.view.LayoutInflater
3374 * @see #ACTIVITY_SERVICE
3375 * @see android.app.ActivityManager
3376 * @see #POWER_SERVICE
3377 * @see android.os.PowerManager
3378 * @see #ALARM_SERVICE
3379 * @see android.app.AlarmManager
3380 * @see #NOTIFICATION_SERVICE
3381 * @see android.app.NotificationManager
3382 * @see #KEYGUARD_SERVICE
3383 * @see android.app.KeyguardManager
3384 * @see #LOCATION_SERVICE
3385 * @see android.location.LocationManager
3386 * @see #SEARCH_SERVICE
3387 * @see android.app.SearchManager
3388 * @see #SENSOR_SERVICE
3389 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003390 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003391 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 * @see #VIBRATOR_SERVICE
3393 * @see android.os.Vibrator
3394 * @see #CONNECTIVITY_SERVICE
3395 * @see android.net.ConnectivityManager
3396 * @see #WIFI_SERVICE
3397 * @see android.net.wifi.WifiManager
3398 * @see #AUDIO_SERVICE
3399 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003400 * @see #MEDIA_ROUTER_SERVICE
3401 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 * @see #TELEPHONY_SERVICE
3403 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003404 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3405 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003406 * @see #CARRIER_CONFIG_SERVICE
3407 * @see android.telephony.CarrierConfigManager
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003408 * @see #EUICC_SERVICE
3409 * @see android.telephony.euicc.EuiccManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003410 * @see #INPUT_METHOD_SERVICE
3411 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003412 * @see #UI_MODE_SERVICE
3413 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003414 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003415 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003416 * @see #BATTERY_SERVICE
3417 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003418 * @see #JOB_SCHEDULER_SERVICE
3419 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003420 * @see #NETWORK_STATS_SERVICE
3421 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003422 * @see android.os.HardwarePropertiesManager
3423 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003425 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426
3427 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003428 * Return the handle to a system-level service by class.
3429 * <p>
3430 * Currently available classes are:
3431 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3432 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3433 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3434 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3435 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3436 * {@link android.net.ConnectivityManager},
3437 * {@link android.net.wifi.WifiManager},
3438 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3439 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3440 * {@link android.view.inputmethod.InputMethodManager},
3441 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003442 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3443 * {@link android.app.usage.NetworkStatsManager}.
Felipe Leme4685b862019-03-06 10:32:33 -08003444 * </p>
3445 *
3446 * <p>
Jeff Brown6e539312015-02-24 18:53:21 -08003447 * Note: System services obtained via this API may be closely associated with
3448 * the Context in which they are obtained from. In general, do not share the
3449 * service objects between various different contexts (Activities, Applications,
3450 * Services, Providers, etc.)
3451 * </p>
3452 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003453 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3454 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003455 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3456 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3457 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
Felipe Leme4685b862019-03-06 10:32:33 -08003458 * return {@code null}. Generally, if you are running as an instant app you should always
3459 * check whether the result of this method is {@code null}.
3460 * </p>
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003461 *
Jeff Brown6e539312015-02-24 18:53:21 -08003462 * @param serviceClass The class of the desired service.
Felipe Leme4685b862019-03-06 10:32:33 -08003463 * @return The service or {@code null} if the class is not a supported system service. Note:
3464 * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
Jeff Brown6e539312015-02-24 18:53:21 -08003465 */
3466 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003467 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003468 // Because subclasses may override getSystemService(String) we cannot
3469 // perform a lookup by class alone. We must first map the class to its
3470 // service name then invoke the string-based method.
3471 String serviceName = getSystemServiceName(serviceClass);
3472 return serviceName != null ? (T)getSystemService(serviceName) : null;
3473 }
3474
3475 /**
3476 * Gets the name of the system-level service that is represented by the specified class.
3477 *
3478 * @param serviceClass The class of the desired service.
3479 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003480 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003481 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003482
3483 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003484 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 * {@link android.os.PowerManager} for controlling power management,
3486 * including "wake locks," which let you keep the device on while
3487 * you're running long tasks.
3488 */
3489 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003490
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003491 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003492 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003493 * {@link android.os.RecoverySystem} for accessing the recovery system
3494 * service.
3495 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003496 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003497 * @hide
3498 */
3499 public static final String RECOVERY_SERVICE = "recovery";
3500
3501 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003502 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003503 * {@link android.os.SystemUpdateManager} for accessing the system update
3504 * manager service.
3505 *
3506 * @see #getSystemService(String)
3507 * @hide
3508 */
3509 @SystemApi
3510 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3511
3512 /**
3513 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003514 * {@link android.view.WindowManager} for accessing the system's window
3515 * manager.
3516 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003517 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003518 * @see android.view.WindowManager
3519 */
3520 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003521
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003522 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003523 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 * {@link android.view.LayoutInflater} for inflating layout resources in this
3525 * context.
3526 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003527 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003528 * @see android.view.LayoutInflater
3529 */
3530 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003533 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003534 * {@link android.accounts.AccountManager} for receiving intents at a
3535 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003536 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003537 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003538 * @see android.accounts.AccountManager
3539 */
3540 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003541
Fred Quintana60307342009-03-24 22:48:12 -07003542 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003543 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003544 * {@link android.app.ActivityManager} for interacting with the global
3545 * system state.
3546 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003547 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003548 * @see android.app.ActivityManager
3549 */
3550 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003551
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003552 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003553 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale65ebd952018-04-25 15:41:44 -07003554 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
3555 *
3556 * @see #getSystemService(String)
3557 * @see android.app.ActivityTaskManager
3558 * @hide
3559 */
3560 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
3561
3562 /**
3563 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07003564 * {@link android.app.UriGrantsManager} for interacting with the global system state.
3565 *
3566 * @see #getSystemService(String)
3567 * @see android.app.UriGrantsManager
3568 * @hide
3569 */
3570 public static final String URI_GRANTS_SERVICE = "uri_grants";
3571
3572 /**
3573 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003574 * {@link android.app.AlarmManager} for receiving intents at a
3575 * time of your choosing.
3576 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003577 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003578 * @see android.app.AlarmManager
3579 */
3580 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003581
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003583 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003584 * {@link android.app.NotificationManager} for informing the user of
3585 * background events.
3586 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003587 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003588 * @see android.app.NotificationManager
3589 */
3590 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003591
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003592 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003593 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003594 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3595 * feedback for UI events through the registered event listeners.
3596 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003597 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003598 * @see android.view.accessibility.AccessibilityManager
3599 */
3600 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003601
svetoslavganov75986cf2009-05-14 22:28:01 -07003602 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003603 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003604 * {@link android.view.accessibility.CaptioningManager} for obtaining
3605 * captioning properties and listening for changes in captioning
3606 * preferences.
3607 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003608 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003609 * @see android.view.accessibility.CaptioningManager
3610 */
3611 public static final String CAPTIONING_SERVICE = "captioning";
3612
3613 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003614 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003615 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003616 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003617 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 * @see android.app.KeyguardManager
3619 */
3620 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003623 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 * android.location.LocationManager} for controlling location
3625 * updates.
3626 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003627 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 * @see android.location.LocationManager
3629 */
3630 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003631
3632 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003633 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003634 * {@link android.location.CountryDetector} for detecting the country that
3635 * the user is in.
3636 *
3637 * @hide
3638 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01003639 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003640 public static final String COUNTRY_DETECTOR = "country_detector";
3641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003642 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003643 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 * android.app.SearchManager} for handling searches.
3645 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003646 * <p>
3647 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3648 * {@link android.app.SearchManager}.
3649 *
3650 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003651 * @see android.app.SearchManager
3652 */
3653 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003654
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003655 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003656 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003657 * android.hardware.SensorManager} for accessing sensors.
3658 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003659 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003660 * @see android.hardware.SensorManager
3661 */
3662 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003663
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003664 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003665 * Use with {@link #getSystemService(String)} to retrieve a {@link
Chad Brubaker90f391f2018-10-19 10:26:19 -07003666 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
3667 * functions.
3668 *
3669 * @see #getSystemService(String)
3670 * @see android.hardware.SensorPrivacyManager
3671 *
3672 * @hide
3673 */
3674 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
3675
3676 /**
3677 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003678 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003679 * functions.
3680 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003681 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003682 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003683 */
3684 public static final String STORAGE_SERVICE = "storage";
3685
3686 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003687 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003688 * android.app.usage.StorageStatsManager} for accessing system storage
3689 * statistics.
3690 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003691 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003692 * @see android.app.usage.StorageStatsManager
3693 */
3694 public static final String STORAGE_STATS_SERVICE = "storagestats";
3695
3696 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003697 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 * com.android.server.WallpaperService for accessing wallpapers.
3699 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003700 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003701 */
3702 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003704 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003705 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003706 * android.os.Vibrator} for interacting with the vibration hardware.
3707 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003708 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003709 * @see android.os.Vibrator
3710 */
3711 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003712
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003713 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003714 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003715 * android.app.StatusBarManager} for interacting with the status bar.
3716 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003717 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 * @see android.app.StatusBarManager
Evan Lairdedd016f2019-01-23 18:36:29 -05003719 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003720 * @hide
3721 */
Evan Lairdedd016f2019-01-23 18:36:29 -05003722 @SystemApi
Evan Laird418ba8f2019-04-17 15:55:21 -04003723 @TestApi
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 public static final String STATUS_BAR_SERVICE = "statusbar";
3725
3726 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003727 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 * android.net.ConnectivityManager} for handling management of
3729 * network connections.
3730 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003731 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003732 * @see android.net.ConnectivityManager
3733 */
3734 public static final String CONNECTIVITY_SERVICE = "connectivity";
3735
3736 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003737 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003738 * {@link android.net.INetd} for communicating with the network stack
3739 * @hide
3740 * @see #getSystemService(String)
3741 * @hide
3742 */
3743 @SystemApi
3744 public static final String NETD_SERVICE = "netd";
3745
3746 /**
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003747 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3748 * {@link NetworkStackClient} IBinder for communicating with the network stack
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003749 * @hide
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003750 * @see NetworkStackClient
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003751 */
3752 public static final String NETWORK_STACK_SERVICE = "network_stack";
3753
3754 /**
Roshan Pius6f5338d2019-06-14 14:37:14 -07003755 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3756 * {@link android.net.WifiStackClient} IBinder for communicating with the network stack
3757 * @hide
3758 * @see android.net.WifiStackClient
3759 */
3760 public static final String WIFI_STACK_SERVICE = "wifi_stack";
3761
3762 /**
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003763 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003764 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3765 * IPSec.
3766 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003767 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003768 */
3769 public static final String IPSEC_SERVICE = "ipsec";
3770
3771 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003772 * Use with {@link #getSystemService(String)} to retrieve a {@link
Benedict Wong99a48412018-11-09 14:45:34 -08003773 * android.net.TestNetworkManager} for building TUNs and limited-use Networks
3774 *
3775 * @see #getSystemService(String)
3776 * @hide
3777 */
3778 @TestApi public static final String TEST_NETWORK_SERVICE = "test_network";
3779
3780 /**
3781 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003782 * android.os.IUpdateLock} for managing runtime sequences that
3783 * must not be interrupted by headless OTA application or similar.
3784 *
3785 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003786 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003787 * @see android.os.UpdateLock
3788 */
3789 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3790
3791 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003792 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003793 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003794 */
3795 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3796
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003797 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003798 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003799 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3800 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003801 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003802 */
3803 public static final String SLICE_SERVICE = "slice";
3804
3805 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003806 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003807 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3808 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003809 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003810 * @see android.app.usage.NetworkStatsManager
3811 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003812 public static final String NETWORK_STATS_SERVICE = "netstats";
3813 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003814 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003815 /** {@hide} */
3816 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003817
San Mehatd1df8ac2010-01-26 06:17:26 -08003818 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003819 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 * android.net.wifi.WifiManager} for handling management of
3821 * Wi-Fi access.
3822 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003823 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 * @see android.net.wifi.WifiManager
3825 */
3826 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003827
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003829 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003830 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003831 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003832 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003833 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003834 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003835 */
3836 public static final String WIFI_P2P_SERVICE = "wifip2p";
3837
3838 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003839 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003840 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3841 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003842 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003843 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003844 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003845 */
Etan Cohen04133272016-10-26 11:22:06 -07003846 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003847
3848 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003849 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003850 * android.net.wifi.WifiScanner} for scanning the wifi universe
3851 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003852 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003853 * @see android.net.wifi.WifiScanner
3854 * @hide
3855 */
Wei Wang35d552f2014-07-08 21:37:01 -07003856 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003857 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3858
3859 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003860 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003861 * android.net.wifi.RttManager} for ranging devices with wifi
3862 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003863 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003864 * @see android.net.wifi.RttManager
3865 * @hide
3866 */
3867 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08003868 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07003869 public static final String WIFI_RTT_SERVICE = "rttmanager";
3870
3871 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003872 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohenf4062a92019-04-11 07:00:42 -07003873 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
Etan Cohen17ba4722017-08-21 10:52:17 -07003874 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003875 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003876 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003877 */
Etan Cohen091d7772018-01-04 17:47:37 -08003878 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003879
3880 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003881 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003882 * android.net.lowpan.LowpanManager} for handling management of
3883 * LoWPAN access.
3884 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003885 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003886 * @see android.net.lowpan.LowpanManager
3887 *
3888 * @hide
3889 */
3890 public static final String LOWPAN_SERVICE = "lowpan";
3891
3892 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003893 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003894 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003895 * Ethernet access.
3896 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003897 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003898 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003899 *
3900 * @hide
3901 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003902 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003903 public static final String ETHERNET_SERVICE = "ethernet";
3904
3905 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003906 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003907 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003908 * discovery
3909 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003910 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003911 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003912 */
3913 public static final String NSD_SERVICE = "servicediscovery";
3914
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003915 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003916 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003917 * {@link android.media.AudioManager} for handling management of volume,
3918 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003919 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003920 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 * @see android.media.AudioManager
3922 */
3923 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003924
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003925 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003926 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003927 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003928 * of fingerprints.
3929 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003930 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07003931 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003932 */
3933 public static final String FINGERPRINT_SERVICE = "fingerprint";
3934
3935 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003936 * Use with {@link #getSystemService(String)} to retrieve a
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003937 * {@link android.hardware.face.FaceManager} for handling management
3938 * of face authentication.
3939 *
3940 * @hide
3941 * @see #getSystemService
3942 * @see android.hardware.face.FaceManager
3943 */
3944 public static final String FACE_SERVICE = "face";
3945
3946 /**
Kevin Chyn05c21502018-09-18 13:07:19 -07003947 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn51676d22018-11-05 18:00:43 -08003948 * {@link android.hardware.iris.IrisManager} for handling management
3949 * of iris authentication.
3950 *
3951 * @hide
3952 * @see #getSystemService
3953 * @see android.hardware.iris.IrisManager
3954 */
3955 public static final String IRIS_SERVICE = "iris";
3956
3957 /**
3958 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn05c21502018-09-18 13:07:19 -07003959 * {@link android.hardware.biometrics.BiometricManager} for handling management
3960 * of face authentication.
3961 *
3962 * @see #getSystemService
3963 * @see android.hardware.biometrics.BiometricManager
3964 */
3965 public static final String BIOMETRIC_SERVICE = "biometric";
3966
3967 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003968 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003969 * {@link android.media.MediaRouter} for controlling and managing
3970 * routing of media.
3971 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003972 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003973 * @see android.media.MediaRouter
3974 */
3975 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3976
3977 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003978 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003979 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003980 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003981 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07003982 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003983 */
3984 public static final String MEDIA_SESSION_SERVICE = "media_session";
3985
3986 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003987 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003988 * {@link android.telephony.TelephonyManager} for handling management the
3989 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003990 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003991 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003992 * @see android.telephony.TelephonyManager
3993 */
3994 public static final String TELEPHONY_SERVICE = "phone";
3995
3996 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003997 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003998 * {@link android.telephony.SubscriptionManager} for handling management the
3999 * telephony subscriptions of the device.
4000 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004001 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08004002 * @see android.telephony.SubscriptionManager
4003 */
4004 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
4005
4006 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004007 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004008 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07004009 * of the device.
4010 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004011 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004012 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07004013 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004014 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07004015
4016 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004017 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004018 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
4019 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004020 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004021 * @see android.telephony.CarrierConfigManager
4022 */
4023 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
4024
4025 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004026 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08004027 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
4028 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004029 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08004030 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08004031 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004032 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08004033
4034 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004035 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004036 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
4037 *
4038 * @see #getSystemService(String)
4039 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004040 * @hide
4041 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004042 @SystemApi
4043 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004044
4045 /**
4046 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08004047 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004048 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07004049 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004050 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004051 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004052 */
4053 public static final String CLIPBOARD_SERVICE = "clipboard";
4054
4055 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004056 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004057 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004058 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004059 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004060 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004061 */
4062 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
4063
4064 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004065 * Use with {@link #getSystemService(String)} to retrieve a
Alex Salo5f5b5f42019-02-27 10:49:00 -08004066 * {@link com.android.server.attention.AttentionManagerService} for attention services.
4067 *
4068 * @see #getSystemService(String)
4069 * @see android.server.attention.AttentionManagerService
4070 * @hide
4071 */
4072 public static final String ATTENTION_SERVICE = "attention";
4073
4074 /**
4075 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004076 * {@link android.view.inputmethod.InputMethodManager} for accessing input
4077 * methods.
4078 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004079 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080 */
4081 public static final String INPUT_METHOD_SERVICE = "input_method";
4082
4083 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004084 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09004085 * {@link android.view.textservice.TextServicesManager} for accessing
4086 * text services.
4087 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004088 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09004089 */
4090 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
4091
4092 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004093 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08004094 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004095 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004096 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004097 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004098 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07004099
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004100 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07004101 * Official published name of the (internal) voice interaction manager service.
4102 *
4103 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004104 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07004105 */
4106 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4107
4108 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08004109 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07004110 *
4111 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004112 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07004113 */
Felipe Leme640f30a2017-03-06 15:44:06 -08004114 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07004115
4116 /**
Felipe Leme749b8892018-12-03 16:30:30 -08004117 * Official published name of the content capture service.
Felipe Lemee348dc32018-11-05 12:35:29 -08004118 *
4119 * @hide
4120 * @see #getSystemService(String)
4121 */
Felipe Lemea7e4ca62019-05-23 13:32:40 -07004122 @TestApi
Felipe Leme749b8892018-12-03 16:30:30 -08004123 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
Felipe Lemee348dc32018-11-05 12:35:29 -08004124
4125 /**
Winson Chung3fb0f252019-01-08 17:41:55 -08004126 * Used for getting content selections and classifications for task snapshots.
4127 *
4128 * @hide
4129 * @see #getSystemService(String)
4130 */
4131 @SystemApi
4132 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
4133
4134 /**
Sunny Goyal54e91342018-11-14 11:59:02 -08004135 * Official published name of the app prediction service.
4136 *
Felipe Leme6378bd42019-08-14 18:14:55 -07004137 * <p><b>NOTE: </b> this service is optional; callers of
4138 * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}.
4139 *
Sunny Goyal54e91342018-11-14 11:59:02 -08004140 * @hide
4141 * @see #getSystemService(String)
4142 */
4143 @SystemApi
4144 public static final String APP_PREDICTION_SERVICE = "app_prediction";
4145
4146 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004147 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004148 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
4149 *
4150 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004151 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004152 */
4153 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
4154
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004155 /**
4156 * Official published name of the (internal) permission service.
4157 *
4158 * @see #getSystemService(String)
4159 * @hide
4160 */
Winsonf27394e2019-06-07 14:44:40 -07004161 @TestApi
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004162 @SystemApi
4163 public static final String PERMISSION_SERVICE = "permission";
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004164
4165 /**
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08004166 * Official published name of the (internal) permission controller service.
4167 *
4168 * @see #getSystemService(String)
4169 * @hide
4170 */
4171 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
4172
4173 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004174 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08004175 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07004176 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07004177 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07004178 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004179 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07004180 */
Christopher Tated5cf7222014-07-29 16:53:09 -07004181 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07004182 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07004183
4184 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +01004185 * Use with {@link #getSystemService(String)} to retrieve an
4186 * {@link android.content.rollback.RollbackManager} for communicating
4187 * with the rollback manager
4188 *
4189 * @see #getSystemService(String)
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004190 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +01004191 */
Richard Uhler8a977452019-03-08 13:27:17 +00004192 @SystemApi @TestApi
Richard Uhlerb29f1452018-09-12 16:38:15 +01004193 public static final String ROLLBACK_SERVICE = "rollback";
4194
4195 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004196 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08004197 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07004198 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004199 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07004200 */
4201 public static final String DROPBOX_SERVICE = "dropbox";
4202
Christopher Tate487529a2009-04-29 14:03:25 -07004203 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07004204 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004205 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004206 * @hide
4207 */
Makoto Onuki7d6d9ca2019-08-13 11:45:45 -07004208 @TestApi
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004209 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
4210
4211 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004212 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08004213 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08004214 * device policy management.
4215 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004216 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08004217 */
4218 public static final String DEVICE_POLICY_SERVICE = "device_policy";
4219
4220 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004221 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08004222 * {@link android.app.UiModeManager} for controlling UI modes.
4223 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004224 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08004225 */
4226 public static final String UI_MODE_SERVICE = "uimode";
4227
4228 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004229 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07004230 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07004231 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004232 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07004233 */
4234 public static final String DOWNLOAD_SERVICE = "download";
4235
4236 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004237 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08004238 * {@link android.os.BatteryManager} for managing battery state.
4239 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004240 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08004241 */
4242 public static final String BATTERY_SERVICE = "batterymanager";
4243
4244 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004245 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004246 * {@link android.nfc.NfcManager} for using NFC.
4247 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004248 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004249 */
4250 public static final String NFC_SERVICE = "nfc";
4251
4252 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004253 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00004254 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004255 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004256 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004257 */
4258 public static final String BLUETOOTH_SERVICE = "bluetooth";
4259
4260 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004261 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08004262 * {@link android.net.sip.SipManager} for accessing the SIP related service.
4263 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004264 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08004265 */
4266 /** @hide */
4267 public static final String SIP_SERVICE = "sip";
4268
4269 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004270 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08004271 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004272 * and for controlling this device's behavior as a USB device.
4273 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004274 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04004275 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004276 */
4277 public static final String USB_SERVICE = "usb";
4278
4279 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004280 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Rootf74bfde2018-01-18 15:42:48 -08004281 * Use with {@link #getSystemService} to retrieve a {@link
4282 * android.debug.AdbManager} for access to ADB debug functions.
4283 *
4284 * @see #getSystemService(String)
4285 * @see android.debug.AdbManager
4286 *
4287 * @hide
4288 */
4289 public static final String ADB_SERVICE = "adb";
4290
4291 /**
4292 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004293 * android.hardware.SerialManager} for access to serial ports.
4294 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004295 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004296 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004297 *
4298 * @hide
4299 */
4300 public static final String SERIAL_SERVICE = "serial";
4301
4302 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004303 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09004304 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
4305 * HDMI-CEC protocol.
4306 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004307 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09004308 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004309 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09004310 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004311 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09004312 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09004313
4314 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004315 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004316 * {@link android.hardware.input.InputManager} for interacting with input devices.
4317 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004318 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004319 * @see android.hardware.input.InputManager
4320 */
4321 public static final String INPUT_SERVICE = "input";
4322
4323 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004324 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07004325 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
4326 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004327 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07004328 * @see android.hardware.display.DisplayManager
4329 */
4330 public static final String DISPLAY_SERVICE = "display";
4331
4332 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004333 * Use with {@link #getSystemService(String)} to retrieve a
Christine Franks39b03112018-07-03 14:46:07 -07004334 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
4335 *
4336 * @see #getSystemService(String)
4337 * @see android.hardware.display.ColorDisplayManager
4338 * @hide
4339 */
4340 public static final String COLOR_DISPLAY_SERVICE = "color_display";
4341
4342 /**
4343 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07004344 * {@link android.os.UserManager} for managing users on devices that support multiple users.
4345 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004346 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07004347 * @see android.os.UserManager
4348 */
4349 public static final String USER_SERVICE = "user";
4350
4351 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004352 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08004353 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
4354 * profiles of a user.
4355 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004356 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08004357 * @see android.content.pm.LauncherApps
4358 */
4359 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4360
4361 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004362 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004363 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4364 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004365 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004366 * @see android.content.RestrictionsManager
4367 */
4368 public static final String RESTRICTIONS_SERVICE = "restrictions";
4369
4370 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004371 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004372 * {@link android.app.AppOpsManager} for tracking application operations
4373 * on the device.
4374 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004375 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004376 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004377 */
4378 public static final String APP_OPS_SERVICE = "appops";
4379
4380 /**
Hai Zhangb7776682018-09-25 15:10:57 -07004381 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
4382 * for managing roles.
4383 *
4384 * @see #getSystemService(String)
4385 * @see android.app.role.RoleManager
4386 */
4387 public static final String ROLE_SERVICE = "role";
4388
4389 /**
Hai Zhanga4959e52019-03-06 12:21:07 -08004390 * Official published name of the (internal) role controller service.
4391 *
4392 * @see #getSystemService(String)
4393 * @see android.app.role.RoleControllerService
4394 *
4395 * @hide
4396 */
4397 public static final String ROLE_CONTROLLER_SERVICE = "role_controller";
4398
4399 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004400 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004401 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004402 * camera devices.
4403 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004404 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004405 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004406 */
4407 public static final String CAMERA_SERVICE = "camera";
4408
4409 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004410 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004411 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004412 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004413 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004414 * @see android.print.PrintManager
4415 */
4416 public static final String PRINT_SERVICE = "print";
4417
4418 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004419 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004420 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4421 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004422 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004423 * @see android.companion.CompanionDeviceManager
4424 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004425 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004426
4427 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004428 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004429 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4430 * signals from the device.
4431 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004432 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004433 * @see android.hardware.ConsumerIrManager
4434 */
4435 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4436
4437 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004438 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004439 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004440 * @see android.app.trust.TrustManager
4441 * @hide
4442 */
4443 public static final String TRUST_SERVICE = "trust";
4444
4445 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004446 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004447 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4448 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004449 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004450 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004451 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004452 */
4453 public static final String TV_INPUT_SERVICE = "tv_input";
4454
4455 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004456 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004457 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004458 * @see android.net.NetworkScoreManager
4459 * @hide
4460 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004461 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004462 public static final String NETWORK_SCORE_SERVICE = "network_score";
4463
4464 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004465 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004466 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004467 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004468 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004469 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004470 */
4471 public static final String USAGE_STATS_SERVICE = "usagestats";
4472
4473 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004474 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004475 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004476 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004477 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004478 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004479 */
Christopher Tate7060b042014-06-09 19:50:00 -07004480 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004481
4482 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004483 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004484 * android.service.persistentdata.PersistentDataBlockManager} instance
4485 * for interacting with a storage device that lives across factory resets.
4486 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004487 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004488 * @see android.service.persistentdata.PersistentDataBlockManager
4489 * @hide
4490 */
Andres Morales33df9372014-09-26 17:08:59 -07004491 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004492 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4493
4494 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004495 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004496 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4497 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004498 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004499 * @see android.service.oemlock.OemLockManager
4500 * @hide
4501 */
4502 @SystemApi
4503 public static final String OEM_LOCK_SERVICE = "oem_lock";
4504
4505 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004506 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004507 * android.media.projection.MediaProjectionManager} instance for managing
4508 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004509 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004510 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004511 */
4512 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4513
4514 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004515 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004516 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004517 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004518 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004519 */
4520 public static final String MIDI_SERVICE = "midi";
4521
Eric Laurent2035ac82015-03-05 15:18:44 -08004522
4523 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004524 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004525 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4526 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004527 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004528 * @hide
4529 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004530 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004531
Paul McLeana33be212015-02-20 07:52:45 -08004532 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004533 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004534 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4535 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004536 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004537 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004538 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004539
4540 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004541 * Use with {@link #getSystemService(String)} to retrieve a
Wei Wangbad7c202018-11-01 11:57:39 -07004542 * {@link android.os.ThermalService} for accessing the thermal service.
4543 *
4544 * @see #getSystemService(String)
4545 * @hide
4546 */
4547 public static final String THERMAL_SERVICE = "thermalservice";
4548
4549 /**
4550 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004551 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004552 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004553 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004554 * @see android.content.pm.ShortcutManager
4555 */
4556 public static final String SHORTCUT_SERVICE = "shortcut";
4557
4558 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004559 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004560 * android.hardware.location.ContextHubManager} for accessing context hubs.
4561 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004562 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004563 * @see android.hardware.location.ContextHubManager
4564 *
4565 * @hide
4566 */
4567 @SystemApi
4568 public static final String CONTEXTHUB_SERVICE = "contexthub";
4569
4570 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004571 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004572 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4573 * memory, etc) metrics.
4574 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004575 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004576 */
4577 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4578
4579 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004580 * Gatekeeper Service.
4581 * @hide
4582 */
4583 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4584
4585 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004586 * Service defining the policy for access to device identifiers.
4587 * @hide
4588 */
4589 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4590
4591 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004592 * Service to report a system health "incident"
4593 * @hide
4594 */
4595 public static final String INCIDENT_SERVICE = "incident";
4596
4597 /**
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08004598 * Service to assist incidentd and dumpstated in reporting status to the user
4599 * and in confirming authorization to take an incident report or bugreport
4600 * @hide
4601 */
4602 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
4603
4604 /**
Bookatz94726412017-08-31 09:26:15 -07004605 * Service to assist statsd in obtaining general stats.
4606 * @hide
4607 */
4608 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4609
4610 /**
Bookatzc6977972018-01-16 16:55:05 -08004611 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004612 * @hide
4613 */
4614 @SystemApi
4615 public static final String STATS_MANAGER = "stats";
4616
4617 /**
atrostde54a8ac2019-08-15 16:53:01 +01004618 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4619 * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
4620 * @hide
4621 */
4622 public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
4623
4624 /**
atrost87488352019-10-10 19:27:31 +01004625 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4626 * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
4627 * service.
4628 * @hide
4629 */
4630 public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
4631
4632 /**
Nandana Duttd11850c2018-12-12 17:26:57 +00004633 * Service to capture a bugreport.
4634 * @see #getSystemService(String)
4635 * @see android.os.BugreportManager
4636 * @hide
4637 */
Nandana Duttd7e8d5a2019-04-11 17:27:45 +01004638 @SystemApi @TestApi
Nandana Duttd11850c2018-12-12 17:26:57 +00004639 public static final String BUGREPORT_SERVICE = "bugreport";
4640
4641 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004642 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004643 * android.content.om.OverlayManager} for managing overlay packages.
4644 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004645 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004646 * @see android.content.om.OverlayManager
4647 * @hide
4648 */
4649 public static final String OVERLAY_SERVICE = "overlay";
4650
4651 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004652 * Use with {@link #getSystemService(String)} to retrieve a
MÃ¥rten Kongstad06a1ac82018-09-20 13:09:47 +02004653 * {android.os.IIdmap2} for managing idmap files (used by overlay
4654 * packages).
4655 *
4656 * @see #getSystemService(String)
4657 * @hide
4658 */
4659 public static final String IDMAP_SERVICE = "idmap";
4660
4661 /**
4662 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004663 * {@link VrManager} for accessing the VR service.
4664 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004665 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004666 * @hide
4667 */
4668 @SystemApi
4669 public static final String VR_SERVICE = "vrmanager";
4670
4671 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004672 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004673 * {@link android.app.timezone.ITimeZoneRulesManager}.
4674 * @hide
4675 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004676 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004677 */
4678 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4679
4680 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004681 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004682 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004683 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004684 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004685 */
4686 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4687
4688 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004689 * Use with {@link #getSystemService} to retrieve a
4690 * {@link android.se.omapi.ISecureElementService}
4691 * for accessing the SecureElementService.
4692 *
4693 * @hide
4694 */
4695 @SystemApi
4696 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4697
4698 /**
Neil Fullerfeeee682018-05-30 14:35:24 +01004699 * Use with {@link #getSystemService(String)} to retrieve an
4700 * {@link android.app.timedetector.ITimeDetectorService}.
4701 * @hide
4702 *
4703 * @see #getSystemService(String)
4704 */
4705 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4706
4707 /**
Makoto Onukidf7e4812018-09-24 14:31:25 -07004708 * Binder service name for {@link AppBindingService}.
4709 * @hide
4710 */
4711 public static final String APP_BINDING_SERVICE = "app_binding";
4712
4713 /**
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004714 * Use with {@link #getSystemService(String)} to retrieve an
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004715 * {@link android.telephony.ims.RcsMessageManager}.
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004716 * @hide
4717 */
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004718 public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004719
Howard Chen0a947642019-01-07 14:10:44 +08004720 /**
4721 * Use with {@link #getSystemService(String)} to retrieve an
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004722 * {@link android.os.image.DynamicSystemManager}.
Howard Chen0a947642019-01-07 14:10:44 +08004723 * @hide
4724 */
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004725 public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
Howard Chen0a947642019-01-07 14:10:44 +08004726
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004727 /**
Chen Xu288b71c2019-09-15 18:28:21 -07004728 * Use with {@link #getSystemService(String)} to retrieve an
4729 * {@link android.os.telephony.TelephonyRegistryManager}.
4730 * @hide
4731 */
4732 @SystemApi
4733 public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
4734
4735 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004736 * Determine whether the given permission is allowed for a particular
4737 * process and user ID running in the system.
4738 *
4739 * @param permission The name of the permission being checked.
4740 * @param pid The process ID being checked against. Must be > 0.
4741 * @param uid The user ID being checked against. A uid of 0 is the root
4742 * user, which will pass every permission check.
4743 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004744 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004745 * pid/uid is allowed that permission, or
4746 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4747 *
4748 * @see PackageManager#checkPermission(String, String)
4749 * @see #checkCallingPermission
4750 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004751 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004752 @PackageManager.PermissionResult
4753 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004754
Dianne Hackbornff170242014-11-19 10:59:01 -08004755 /** @hide */
4756 @PackageManager.PermissionResult
Mathew Inwood5c0d3542018-08-14 13:54:31 +01004757 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08004758 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4759 IBinder callerToken);
4760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004761 /**
4762 * Determine whether the calling process of an IPC you are handling has been
4763 * granted a particular permission. This is basically the same as calling
4764 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4765 * by {@link android.os.Binder#getCallingPid} and
4766 * {@link android.os.Binder#getCallingUid}. One important difference
4767 * is that if you are not currently processing an IPC, this function
4768 * will always fail. This is done to protect against accidentally
4769 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4770 * to avoid this protection.
4771 *
4772 * @param permission The name of the permission being checked.
4773 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004774 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004775 * pid/uid is allowed that permission, or
4776 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4777 *
4778 * @see PackageManager#checkPermission(String, String)
4779 * @see #checkPermission
4780 * @see #checkCallingOrSelfPermission
4781 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004782 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004783 @PackageManager.PermissionResult
4784 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004785
4786 /**
4787 * Determine whether the calling process of an IPC <em>or you</em> have been
4788 * granted a particular permission. This is the same as
4789 * {@link #checkCallingPermission}, except it grants your own permissions
4790 * if you are not currently processing an IPC. Use with care!
4791 *
4792 * @param permission The name of the permission being checked.
4793 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004794 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004795 * pid/uid is allowed that permission, or
4796 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4797 *
4798 * @see PackageManager#checkPermission(String, String)
4799 * @see #checkPermission
4800 * @see #checkCallingPermission
4801 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004802 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004803 @PackageManager.PermissionResult
4804 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004805
4806 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004807 * Determine whether <em>you</em> have been granted a particular permission.
4808 *
4809 * @param permission The name of the permission being checked.
4810 *
4811 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4812 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4813 *
4814 * @see PackageManager#checkPermission(String, String)
4815 * @see #checkCallingPermission(String)
4816 */
4817 @PackageManager.PermissionResult
4818 public abstract int checkSelfPermission(@NonNull String permission);
4819
4820 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004821 * If the given permission is not allowed for a particular process
4822 * and user ID running in the system, throw a {@link SecurityException}.
4823 *
4824 * @param permission The name of the permission being checked.
4825 * @param pid The process ID being checked against. Must be &gt; 0.
4826 * @param uid The user ID being checked against. A uid of 0 is the root
4827 * user, which will pass every permission check.
4828 * @param message A message to include in the exception if it is thrown.
4829 *
4830 * @see #checkPermission(String, int, int)
4831 */
4832 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004833 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004834
4835 /**
4836 * If the calling process of an IPC you are handling has not been
4837 * granted a particular permission, throw a {@link
4838 * SecurityException}. This is basically the same as calling
4839 * {@link #enforcePermission(String, int, int, String)} with the
4840 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4841 * and {@link android.os.Binder#getCallingUid}. One important
4842 * difference is that if you are not currently processing an IPC,
4843 * this function will always throw the SecurityException. This is
4844 * done to protect against accidentally leaking permissions; you
4845 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4846 * protection.
4847 *
4848 * @param permission The name of the permission being checked.
4849 * @param message A message to include in the exception if it is thrown.
4850 *
4851 * @see #checkCallingPermission(String)
4852 */
4853 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004854 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004855
4856 /**
4857 * If neither you nor the calling process of an IPC you are
4858 * handling has been granted a particular permission, throw a
4859 * {@link SecurityException}. This is the same as {@link
4860 * #enforceCallingPermission}, except it grants your own
4861 * permissions if you are not currently processing an IPC. Use
4862 * with care!
4863 *
4864 * @param permission The name of the permission being checked.
4865 * @param message A message to include in the exception if it is thrown.
4866 *
4867 * @see #checkCallingOrSelfPermission(String)
4868 */
4869 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004870 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004871
4872 /**
4873 * Grant permission to access a specific Uri to another package, regardless
4874 * of whether that package has general permission to access the Uri's
4875 * content provider. This can be used to grant specific, temporary
4876 * permissions, typically in response to user interaction (such as the
4877 * user opening an attachment that you would like someone else to
4878 * display).
4879 *
4880 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4881 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4882 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4883 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4884 * start an activity instead of this function directly. If you use this
4885 * function directly, you should be sure to call
4886 * {@link #revokeUriPermission} when the target should no longer be allowed
4887 * to access it.
4888 *
4889 * <p>To succeed, the content provider owning the Uri must have set the
4890 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4891 * grantUriPermissions} attribute in its manifest or included the
4892 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4893 * &lt;grant-uri-permissions&gt;} tag.
4894 *
4895 * @param toPackage The package you would like to allow to access the Uri.
4896 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004897 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004898 *
4899 * @see #revokeUriPermission
4900 */
4901 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004902 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004903
4904 /**
4905 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004906 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4907 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004908 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004909 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004910 * "content://foo". It will not remove any prefix grants that exist at a
4911 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004912 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004913 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004914 * regular permission access to a Uri, but had received access to it through
4915 * a specific Uri permission grant, you could not revoke that grant with this
4916 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004917 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4918 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004919 * (or none).</p>
4920 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004921 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4922 * grants matching the given Uri, for any package they had been granted to, through any
4923 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4924 * service start, etc). That means this can be potentially dangerous to use, as it can
4925 * revoke grants that another app could be strongly expecting to stick around.</p>
4926 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004927 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004928 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929 *
4930 * @see #grantUriPermission
4931 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004932 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004933
4934 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004935 * Remove permissions to access a particular content provider Uri
4936 * that were previously added with {@link #grantUriPermission} for a specific target
4937 * package. The given Uri will match all previously granted Uris that are the same or a
4938 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4939 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4940 * "content://foo". It will not remove any prefix grants that exist at a
4941 * higher level.
4942 *
4943 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4944 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4945 * and only for the package specified. Any matching grants that have happened through
4946 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4947 * removed.</p>
4948 *
4949 * @param toPackage The package you had previously granted access to.
4950 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004951 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004952 *
4953 * @see #grantUriPermission
4954 */
4955 public abstract void revokeUriPermission(String toPackage, Uri uri,
4956 @Intent.AccessUriMode int modeFlags);
4957
4958 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004959 * Determine whether a particular process and user ID has been granted
4960 * permission to access a specific URI. This only checks for permissions
4961 * that have been explicitly granted -- if the given process/uid has
4962 * more general access to the URI's content provider then this check will
4963 * always fail.
4964 *
4965 * @param uri The uri that is being checked.
4966 * @param pid The process ID being checked against. Must be &gt; 0.
4967 * @param uid The user ID being checked against. A uid of 0 is the root
4968 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004969 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004970 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004971 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004972 * pid/uid is allowed to access that uri, or
4973 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4974 *
4975 * @see #checkCallingUriPermission
4976 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004977 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004978 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004979 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004980 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004981
Dianne Hackbornff170242014-11-19 10:59:01 -08004982 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004983 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08004984 public abstract int checkUriPermission(Uri uri, int pid, int uid,
4985 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4986
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004987 /**
4988 * Determine whether the calling process and user ID has been
4989 * granted permission to access a specific URI. This is basically
4990 * the same as calling {@link #checkUriPermission(Uri, int, int,
4991 * int)} with the pid and uid returned by {@link
4992 * android.os.Binder#getCallingPid} and {@link
4993 * android.os.Binder#getCallingUid}. One important difference is
4994 * that if you are not currently processing an IPC, this function
4995 * will always fail.
4996 *
4997 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004998 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004999 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005000 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005001 * is allowed to access that uri, or
5002 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5003 *
5004 * @see #checkUriPermission(Uri, int, int, int)
5005 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005006 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005007 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07005008 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005009
5010 /**
5011 * Determine whether the calling process of an IPC <em>or you</em> has been granted
5012 * permission to access a specific URI. This is the same as
5013 * {@link #checkCallingUriPermission}, except it grants your own permissions
5014 * if you are not currently processing an IPC. Use with care!
5015 *
5016 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005017 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005018 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005019 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005020 * is allowed to access that uri, or
5021 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5022 *
5023 * @see #checkCallingUriPermission
5024 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005025 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005026 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005027 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005028 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005029
5030 /**
5031 * Check both a Uri and normal permission. This allows you to perform
5032 * both {@link #checkPermission} and {@link #checkUriPermission} in one
5033 * call.
5034 *
5035 * @param uri The Uri whose permission is to be checked, or null to not
5036 * do this check.
5037 * @param readPermission The permission that provides overall read access,
5038 * or null to not do this check.
5039 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005040 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005041 * @param pid The process ID being checked against. Must be &gt; 0.
5042 * @param uid The user ID being checked against. A uid of 0 is the root
5043 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005044 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005046 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005047 * is allowed to access that uri or holds one of the given permissions, or
5048 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5049 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005050 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005051 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005052 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
5053 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005054 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055
5056 /**
5057 * If a particular process and user ID has not been granted
5058 * permission to access a specific URI, throw {@link
5059 * SecurityException}. This only checks for permissions that have
5060 * been explicitly granted -- if the given process/uid has more
5061 * general access to the URI's content provider then this check
5062 * will always fail.
5063 *
5064 * @param uri The uri that is being checked.
5065 * @param pid The process ID being checked against. Must be &gt; 0.
5066 * @param uid The user ID being checked against. A uid of 0 is the root
5067 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005068 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005069 * @param message A message to include in the exception if it is thrown.
5070 *
5071 * @see #checkUriPermission(Uri, int, int, int)
5072 */
5073 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005074 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005075
5076 /**
5077 * If the calling process and user ID has not been granted
5078 * permission to access a specific URI, throw {@link
5079 * SecurityException}. This is basically the same as calling
5080 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
5081 * the pid and uid returned by {@link
5082 * android.os.Binder#getCallingPid} and {@link
5083 * android.os.Binder#getCallingUid}. One important difference is
5084 * that if you are not currently processing an IPC, this function
5085 * will always throw a SecurityException.
5086 *
5087 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005088 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005089 * @param message A message to include in the exception if it is thrown.
5090 *
5091 * @see #checkCallingUriPermission(Uri, int)
5092 */
5093 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005094 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005095
5096 /**
5097 * If the calling process of an IPC <em>or you</em> has not been
5098 * granted permission to access a specific URI, throw {@link
5099 * SecurityException}. This is the same as {@link
5100 * #enforceCallingUriPermission}, except it grants your own
5101 * permissions if you are not currently processing an IPC. Use
5102 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07005103 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005104 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005105 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005106 * @param message A message to include in the exception if it is thrown.
5107 *
5108 * @see #checkCallingOrSelfUriPermission(Uri, int)
5109 */
5110 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005111 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005112
5113 /**
5114 * Enforce both a Uri and normal permission. This allows you to perform
5115 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
5116 * call.
Scott Main4b5da682010-10-21 11:49:12 -07005117 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005118 * @param uri The Uri whose permission is to be checked, or null to not
5119 * do this check.
5120 * @param readPermission The permission that provides overall read access,
5121 * or null to not do this check.
5122 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005123 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124 * @param pid The process ID being checked against. Must be &gt; 0.
5125 * @param uid The user ID being checked against. A uid of 0 is the root
5126 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005127 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005128 * @param message A message to include in the exception if it is thrown.
5129 *
5130 * @see #checkUriPermission(Uri, String, String, int, int, int)
5131 */
5132 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005133 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005134 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07005135 @Nullable String message);
5136
5137 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005138 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
5139 CONTEXT_INCLUDE_CODE,
5140 CONTEXT_IGNORE_SECURITY,
5141 CONTEXT_RESTRICTED,
5142 CONTEXT_DEVICE_PROTECTED_STORAGE,
5143 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
5144 CONTEXT_REGISTER_PACKAGE,
5145 })
Tor Norbyed9273d62013-05-30 15:59:53 -07005146 @Retention(RetentionPolicy.SOURCE)
5147 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005148
5149 /**
5150 * Flag for use with {@link #createPackageContext}: include the application
5151 * code with the context. This means loading code into the caller's
5152 * process, so that {@link #getClassLoader()} can be used to instantiate
5153 * the application's classes. Setting this flags imposes security
5154 * restrictions on what application context you can access; if the
5155 * requested application can not be safely loaded into your process,
5156 * java.lang.SecurityException will be thrown. If this flag is not set,
5157 * there will be no restrictions on the packages that can be loaded,
5158 * but {@link #getClassLoader} will always return the default system
5159 * class loader.
5160 */
5161 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
5162
5163 /**
5164 * Flag for use with {@link #createPackageContext}: ignore any security
5165 * restrictions on the Context being requested, allowing it to always
5166 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
5167 * to be loaded into a process even when it isn't safe to do so. Use
5168 * with extreme care!
5169 */
5170 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07005171
Romain Guy870e09f2009-07-06 16:35:25 -07005172 /**
5173 * Flag for use with {@link #createPackageContext}: a restricted context may
5174 * disable specific features. For instance, a View associated with a restricted
5175 * context would ignore particular XML attributes.
5176 */
5177 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005178
5179 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005180 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005181 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005182 *
5183 * @hide
5184 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005185 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005186
5187 /**
5188 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005189 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005190 *
5191 * @hide
5192 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005193 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005194
5195 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07005196 * @hide Used to indicate we should tell the activity manager about the process
5197 * loading this code.
5198 */
5199 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
5200
5201 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005202 * Return a new Context object for the given application name. This
5203 * Context is the same as what the named application gets when it is
5204 * launched, containing the same resources and class loader. Each call to
5205 * this method returns a new instance of a Context object; Context objects
5206 * are not shared, however they share common state (Resources, ClassLoader,
5207 * etc) so the Context instance itself is fairly lightweight.
5208 *
Jeff Brown6e539312015-02-24 18:53:21 -08005209 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 * application with the given package name.
5211 *
5212 * <p>Throws {@link java.lang.SecurityException} if the Context requested
5213 * can not be loaded into the caller's process for security reasons (see
5214 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
5215 *
5216 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005217 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005218 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005219 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005221 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04005223 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005224 */
5225 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07005226 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07005227
5228 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07005229 * Similar to {@link #createPackageContext(String, int)}, but with a
5230 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5231 * will open any {@link Uri} as the given user.
5232 *
5233 * @hide
5234 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08005235 @SystemApi
Jeff Sharkeyec5f7d12018-08-08 09:15:04 -06005236 @TestApi
Makoto Onukib8440012019-10-09 15:33:11 -07005237 @NonNull
Patrick Baumannef4c4072018-02-01 08:54:05 -08005238 public Context createPackageContextAsUser(
Makoto Onukib8440012019-10-09 15:33:11 -07005239 @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08005240 throws PackageManager.NameNotFoundException {
5241 if (Build.IS_ENG) {
5242 throw new IllegalStateException("createPackageContextAsUser not overridden!");
5243 }
5244 return this;
5245 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07005246
5247 /**
Makoto Onukib8440012019-10-09 15:33:11 -07005248 * Similar to {@link #createPackageContext(String, int)}, but for the own package with a
5249 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5250 * will open any {@link Uri} as the given user.
5251 *
5252 * @hide
5253 */
5254 @SystemApi
5255 @TestApi
5256 @NonNull
Makoto Onukie5449f02019-10-11 20:19:58 -07005257 public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
Makoto Onukib8440012019-10-09 15:33:11 -07005258 if (Build.IS_ENG) {
5259 throw new IllegalStateException("createContextAsUser not overridden!");
5260 }
5261 return this;
5262 }
5263
5264 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07005265 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
5266 *
5267 * @hide
5268 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005269 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07005270 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005271 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07005272
5273 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08005274 * Return a new Context object for the given split name. The new Context has a ClassLoader and
5275 * Resources object that can access the split's and all of its dependencies' code/resources.
5276 * Each call to this method returns a new instance of a Context object;
5277 * Context objects are not shared, however common state (ClassLoader, other Resources for
5278 * the same split) may be so the Context itself can be fairly lightweight.
5279 *
5280 * @param splitName The name of the split to include, as declared in the split's
5281 * <code>AndroidManifest.xml</code>.
5282 * @return A {@link Context} with the given split's code and/or resources loaded.
5283 */
5284 public abstract Context createContextForSplit(String splitName)
5285 throws PackageManager.NameNotFoundException;
5286
5287 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005288 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08005289 * @hide
5290 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07005291 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005292 public UserHandle getUser() {
5293 return android.os.Process.myUserHandle();
5294 }
5295
5296 /**
5297 * Get the user associated with this context
5298 * @hide
5299 */
5300 @TestApi
5301 public @UserIdInt int getUserId() {
5302 return android.os.UserHandle.myUserId();
5303 }
Jim Millera75a8832013-02-07 16:53:32 -08005304
5305 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07005306 * Return a new Context object for the current Context but whose resources
5307 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07005308 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07005309 * shared, however common state (ClassLoader, other Resources for the
5310 * same configuration) may be so the Context itself can be fairly lightweight.
5311 *
5312 * @param overrideConfiguration A {@link Configuration} specifying what
5313 * values to modify in the base Configuration of the original Context's
5314 * resources. If the base configuration changes (such as due to an
5315 * orientation change), the resources of this context will also change except
5316 * for those that have been explicitly overridden with a value here.
5317 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005318 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07005319 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005320 public abstract Context createConfigurationContext(
5321 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07005322
5323 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07005324 * Return a new Context object for the current Context but whose resources
5325 * are adjusted to match the metrics of the given Display. Each call to this method
5326 * returns a new instance of a Context object; Context objects are not
5327 * shared, however common state (ClassLoader, other Resources for the
5328 * same configuration) may be so the Context itself can be fairly lightweight.
5329 *
5330 * The returned display Context provides a {@link WindowManager}
5331 * (see {@link #getSystemService(String)}) that is configured to show windows
5332 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
5333 * method can be used to retrieve the Display from the returned Context.
5334 *
5335 * @param display A {@link Display} object specifying the display
5336 * for whose metrics the Context's resources should be tailored and upon which
5337 * new windows should be shown.
5338 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005339 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07005340 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005341 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07005342
5343 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005344 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005345 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005346 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005347 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005348 * with a key tied to the physical device, and it can be accessed
5349 * immediately after the device has booted successfully, both
5350 * <em>before and after</em> the user has authenticated with their
5351 * credentials (such as a lock pattern or PIN).
5352 * <p>
5353 * Because device-protected data is available without user authentication,
5354 * you should carefully limit the data you store using this Context. For
5355 * example, storing sensitive authentication tokens or passwords in the
5356 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005357 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005358 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005359 * device-protected and credential-protected data using different keys, then
5360 * both storage areas will become available at the same time. They remain as
5361 * two distinct storage locations on disk, and only the window of
5362 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005363 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005364 * Each call to this method returns a new instance of a Context object;
5365 * Context objects are not shared, however common state (ClassLoader, other
5366 * Resources for the same configuration) may be so the Context itself can be
5367 * fairly lightweight.
5368 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005369 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005370 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005371 public abstract Context createDeviceProtectedStorageContext();
5372
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005373 /**
5374 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005375 * APIs are backed by credential-protected storage. This is the default
5376 * storage area for apps unless
5377 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005378 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005379 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005380 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005381 * <em>only after</em> the user has entered their credentials (such as a
5382 * lock pattern or PIN).
5383 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005384 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005385 * device-protected and credential-protected data using different keys, then
5386 * both storage areas will become available at the same time. They remain as
5387 * two distinct storage locations on disk, and only the window of
5388 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005389 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005390 * Each call to this method returns a new instance of a Context object;
5391 * Context objects are not shared, however common state (ClassLoader, other
5392 * Resources for the same configuration) may be so the Context itself can be
5393 * fairly lightweight.
5394 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005395 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005396 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005397 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005398 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005399 public abstract Context createCredentialProtectedStorageContext();
5400
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005401 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07005402 * Gets the display adjustments holder for this context. This information
5403 * is provided on a per-application or activity basis and is used to simulate lower density
5404 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07005405 *
Jeff Browna492c3a2012-08-23 19:48:44 -07005406 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07005407 * @return The compatibility info holder, or null if not required by the application.
5408 * @hide
5409 */
Craig Mautner48d0d182013-06-11 07:53:06 -07005410 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07005411
5412 /**
Wale Ogunwale691af682019-02-11 03:09:10 -08005413 * @return Returns the {@link Display} object this context is associated with.
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005414 * @hide
5415 */
Wale Ogunwale691af682019-02-11 03:09:10 -08005416 @TestApi
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005417 public abstract Display getDisplay();
5418
5419 /**
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005420 * Gets the display ID.
5421 *
5422 * @return display ID associated with this {@link Context}.
5423 * @hide
5424 */
wilsonshih5db7b392019-02-20 23:08:45 +08005425 @TestApi
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005426 public abstract int getDisplayId();
5427
5428 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08005429 * @hide
5430 */
5431 public abstract void updateDisplay(int displayId);
5432
5433 /**
Romain Guy870e09f2009-07-06 16:35:25 -07005434 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07005435 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005436 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07005437 *
Romain Guy870e09f2009-07-06 16:35:25 -07005438 * @see #CONTEXT_RESTRICTED
5439 */
5440 public boolean isRestricted() {
5441 return false;
5442 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005443
5444 /**
5445 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005446 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005447 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005448 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005449 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005450 public abstract boolean isDeviceProtectedStorage();
5451
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005452 /**
5453 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005454 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005455 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005456 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005457 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005458 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005459 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005460 public abstract boolean isCredentialProtectedStorage();
5461
Tony Mak46aabe52016-11-14 12:53:06 +00005462 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005463 * Returns true if the context can load unsafe resources, e.g. fonts.
5464 * @hide
5465 */
5466 public abstract boolean canLoadUnsafeResources();
5467
5468 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005469 * @hide
5470 */
5471 public IBinder getActivityToken() {
5472 throw new RuntimeException("Not implemented. Must override in a subclass.");
5473 }
5474
5475 /**
5476 * @hide
5477 */
5478 @Nullable
5479 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
5480 int flags) {
5481 throw new RuntimeException("Not implemented. Must override in a subclass.");
5482 }
5483
5484 /**
5485 * @hide
5486 */
5487 public IApplicationThread getIApplicationThread() {
5488 throw new RuntimeException("Not implemented. Must override in a subclass.");
5489 }
Tony Makbf9928d2016-12-22 11:02:45 +00005490
5491 /**
5492 * @hide
5493 */
5494 public Handler getMainThreadHandler() {
5495 throw new RuntimeException("Not implemented. Must override in a subclass.");
5496 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07005497
5498 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07005499 * @hide
5500 */
5501 public AutofillClient getAutofillClient() {
5502 return null;
5503 }
5504
5505 /**
5506 * @hide
5507 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005508 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005509 }
5510
5511 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005512 * @hide
5513 */
Felipe Lemecbf7f262019-04-17 13:57:59 -07005514 @Nullable
5515 public ContentCaptureClient getContentCaptureClient() {
5516 return null;
5517 }
5518
5519 /**
5520 * @hide
5521 */
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005522 public final boolean isAutofillCompatibilityEnabled() {
5523 final AutofillOptions options = getAutofillOptions();
5524 return options != null && options.compatModeEnabled;
5525 }
5526
5527 /**
5528 * @hide
5529 */
5530 @Nullable
5531 public AutofillOptions getAutofillOptions() {
5532 return null;
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005533 }
5534
5535 /**
5536 * @hide
5537 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005538 @TestApi
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005539 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005540 }
5541
5542 /**
Felipe Leme326f15a2019-02-19 09:42:24 -08005543 * Gets the Content Capture options for this context, or {@code null} if it's not whitelisted.
Felipe Lemeecb08be2018-11-27 15:48:47 -08005544 *
5545 * @hide
5546 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005547 @Nullable
5548 public ContentCaptureOptions getContentCaptureOptions() {
5549 return null;
Felipe Lemeecb08be2018-11-27 15:48:47 -08005550 }
5551
5552 /**
5553 * @hide
5554 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005555 @TestApi
5556 public void setContentCaptureOptions(
5557 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08005558 }
5559
5560 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005561 * Throws an exception if the Context is using system resources,
5562 * which are non-runtime-overlay-themable and may show inconsistent UI.
5563 * @hide
5564 */
5565 public void assertRuntimeOverlayThemable() {
5566 // Resources.getSystem() is a singleton and the only Resources not managed by
5567 // ResourcesManager; therefore Resources.getSystem() is not themable.
5568 if (getResources() == Resources.getSystem()) {
5569 throw new IllegalArgumentException("Non-UI context used to display UI; "
5570 + "get a UI context from ActivityThread#getSystemUiContext()");
5571 }
5572 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005573}