blob: f2f9051267152630aa555dffb22e373ae1bf17d1 [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;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070035import android.annotation.UserIdInt;
Selim Cinek7fa385a2018-01-24 08:35:28 -080036import android.app.ActivityManager;
Tony Mak46aabe52016-11-14 12:53:06 +000037import android.app.IApplicationThread;
38import android.app.IServiceConnection;
Zak Cohen56345f42017-01-26 13:54:28 -080039import android.app.VrManager;
Artur Satayev76c1d9d2019-12-10 17:47:52 +000040import android.compat.annotation.UnsupportedAppUsage;
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;
Chen Xu8eb62f92019-10-13 17:30:32 -070066import android.telephony.TelephonyRegistryManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070068import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070069import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070070import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070071import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070072import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070073import android.view.autofill.AutofillManager.AutofillClient;
Felipe Lemecbf7f262019-04-17 13:57:59 -070074import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000075import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
atrosta6a4d602019-08-21 16:48:56 +010077import com.android.internal.compat.IPlatformCompat;
atrostff948d82019-10-10 19:27:31 +010078import com.android.internal.compat.IPlatformCompatNative;
atrosta6a4d602019-08-21 16:48:56 +010079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080import java.io.File;
81import java.io.FileInputStream;
82import java.io.FileNotFoundException;
83import java.io.FileOutputStream;
84import java.io.IOException;
85import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070086import java.lang.annotation.Retention;
87import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070088import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
90/**
91 * Interface to global information about an application environment. This is
92 * an abstract class whose implementation is provided by
93 * the Android system. It
94 * allows access to application-specific resources and classes, as well as
95 * up-calls for application-level operations such as launching activities,
96 * broadcasting and receiving intents, etc.
97 */
98public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060099 /** @hide */
100 @IntDef(flag = true, prefix = { "MODE_" }, value = {
101 MODE_PRIVATE,
102 MODE_WORLD_READABLE,
103 MODE_WORLD_WRITEABLE,
104 MODE_APPEND,
105 })
106 @Retention(RetentionPolicy.SOURCE)
107 public @interface FileMode {}
108
109 /** @hide */
110 @IntDef(flag = true, prefix = { "MODE_" }, value = {
111 MODE_PRIVATE,
112 MODE_WORLD_READABLE,
113 MODE_WORLD_WRITEABLE,
114 MODE_MULTI_PROCESS,
115 })
116 @Retention(RetentionPolicy.SOURCE)
117 public @interface PreferencesMode {}
118
119 /** @hide */
120 @IntDef(flag = true, prefix = { "MODE_" }, value = {
121 MODE_PRIVATE,
122 MODE_WORLD_READABLE,
123 MODE_WORLD_WRITEABLE,
124 MODE_ENABLE_WRITE_AHEAD_LOGGING,
125 MODE_NO_LOCALIZED_COLLATORS,
126 })
127 @Retention(RetentionPolicy.SOURCE)
128 public @interface DatabaseMode {}
129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 /**
131 * File creation mode: the default mode, where the created file can only
132 * be accessed by the calling application (or all applications sharing the
133 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 */
135 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700138 * File creation mode: allow all other applications to have read access to
139 * the created file.
140 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700141 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
142 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700143 *
Nick Kralevich15069212013-01-09 15:54:56 -0800144 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700145 * to cause security holes in applications. It is strongly
146 * discouraged; instead, applications should use more formal
147 * mechanism for interactions such as {@link ContentProvider},
148 * {@link BroadcastReceiver}, and {@link android.app.Service}.
149 * There are no guarantees that this access mode will remain on
150 * a file, such as when it goes through a backup and restore.
151 * @see android.support.v4.content.FileProvider
152 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700154 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700158 * File creation mode: allow all other applications to have write access to
159 * the created file.
160 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700161 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700162 * mode will throw a {@link SecurityException}.
163 *
Nick Kralevich15069212013-01-09 15:54:56 -0800164 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700165 * to cause security holes in applications. It is strongly
166 * discouraged; instead, applications should use more formal
167 * mechanism for interactions such as {@link ContentProvider},
168 * {@link BroadcastReceiver}, and {@link android.app.Service}.
169 * There are no guarantees that this access mode will remain on
170 * a file, such as when it goes through a backup and restore.
171 * @see android.support.v4.content.FileProvider
172 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700174 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /**
178 * File creation mode: for use with {@link #openFileOutput}, if the file
179 * already exists then write data to the end of the existing file
180 * instead of erasing it.
181 * @see #openFileOutput
182 */
183 public static final int MODE_APPEND = 0x8000;
184
185 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800186 * SharedPreference loading flag: when set, the file on disk will
187 * be checked for modification even if the shared preferences
188 * instance is already loaded in this process. This behavior is
189 * sometimes desired in cases where the application has multiple
190 * processes, all writing to the same SharedPreferences file.
191 * Generally there are better forms of communication between
192 * processes, though.
193 *
194 * <p>This was the legacy (but undocumented) behavior in and
195 * before Gingerbread (Android 2.3) and this flag is implied when
kopriva219f7dc2018-10-09 13:42:28 -0700196 * targeting such releases. For applications targeting SDK
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800197 * versions <em>greater than</em> Android 2.3, this flag must be
198 * explicitly set if desired.
199 *
200 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700201 *
202 * @deprecated MODE_MULTI_PROCESS does not work reliably in
203 * some versions of Android, and furthermore does not provide any
204 * mechanism for reconciling concurrent modifications across
205 * processes. Applications should not attempt to use it. Instead,
206 * they should use an explicit cross-process data management
207 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800208 */
Christopher Tated5748b82015-05-08 18:14:01 -0700209 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800210 public static final int MODE_MULTI_PROCESS = 0x0004;
211
212 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700213 * Database open flag: when set, the database is opened with write-ahead
214 * logging enabled by default.
215 *
216 * @see #openOrCreateDatabase(String, int, CursorFactory)
217 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
218 * @see SQLiteDatabase#enableWriteAheadLogging
219 */
220 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
221
Sunny Goyala21e6b22015-12-02 09:51:02 -0800222 /**
223 * Database open flag: when set, the database is opened without support for
224 * localized collators.
225 *
226 * @see #openOrCreateDatabase(String, int, CursorFactory)
227 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
228 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
229 */
230 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
231
Tor Norbyed9273d62013-05-30 15:59:53 -0700232 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700233 @IntDef(flag = true, prefix = { "BIND_" }, value = {
234 BIND_AUTO_CREATE,
235 BIND_DEBUG_UNBIND,
236 BIND_NOT_FOREGROUND,
237 BIND_ABOVE_CLIENT,
238 BIND_ALLOW_OOM_MANAGEMENT,
239 BIND_WAIVE_PRIORITY,
240 BIND_IMPORTANT,
Amith Yamasani5016a782019-06-17 16:20:24 -0700241 BIND_ADJUST_WITH_ACTIVITY,
242 BIND_NOT_PERCEPTIBLE,
243 BIND_INCLUDE_CAPABILITIES
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700244 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700245 @Retention(RetentionPolicy.SOURCE)
246 public @interface BindServiceFlags {}
247
Jeff Brown47847f32012-03-22 19:13:11 -0700248 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 * Flag for {@link #bindService}: automatically create the service as long
250 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700251 * its {@link android.app.Service#onStartCommand}
252 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 * explicit call to {@link #startService}. Even without that, though,
254 * this still provides you with access to the service object while the
255 * service is created.
256 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700257 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
258 * not supplying this flag would also impact how important the system
259 * consider's the target service's process to be. When set, the only way
260 * for it to be raised was by binding from a service in which case it will
261 * only be important when that activity is in the foreground. Now to
262 * achieve this behavior you must explicitly supply the new flag
263 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
264 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
265 * the flags {@link #BIND_WAIVE_PRIORITY} and
266 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
267 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 */
269 public static final int BIND_AUTO_CREATE = 0x0001;
270
271 /**
272 * Flag for {@link #bindService}: include debugging help for mismatched
273 * calls to unbind. When this flag is set, the callstack of the following
274 * {@link #unbindService} call is retained, to be printed if a later
275 * incorrect unbind call is made. Note that doing this requires retaining
276 * information about the binding that was made for the lifetime of the app,
277 * resulting in a leak -- this should only be used for debugging.
278 */
279 public static final int BIND_DEBUG_UNBIND = 0x0002;
280
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800281 /**
282 * Flag for {@link #bindService}: don't allow this binding to raise
283 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700284 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800285 * as the client (so that its process will not be killable in any
286 * situation where the client is not killable), but for CPU scheduling
287 * purposes it may be left in the background. This only has an impact
288 * in the situation where the binding client is a foreground process
289 * and the target service is in a background process.
290 */
291 public static final int BIND_NOT_FOREGROUND = 0x0004;
292
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700293 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700294 * Flag for {@link #bindService}: indicates that the client application
295 * binding to this service considers the service to be more important than
296 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700297 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700298 * this is not guaranteed to be the case.
299 */
300 public static final int BIND_ABOVE_CLIENT = 0x0008;
301
302 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700303 * Flag for {@link #bindService}: allow the process hosting the bound
304 * service to go through its normal memory management. It will be
305 * treated more like a running service, allowing the system to
306 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700307 * whim it may have, and being more aggressive about making it a candidate
308 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700309 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700310 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
311
312 /**
313 * Flag for {@link #bindService}: don't impact the scheduling or
314 * memory management priority of the target service's hosting process.
315 * Allows the service's process to be managed on the background LRU list
316 * just like a regular application process in the background.
317 */
318 public static final int BIND_WAIVE_PRIORITY = 0x0020;
319
320 /**
321 * Flag for {@link #bindService}: this service is very important to
322 * the client, so should be brought to the foreground process level
323 * when the client is. Normally a process can only be raised to the
324 * visibility level by a client, even if that client is in the foreground.
325 */
326 public static final int BIND_IMPORTANT = 0x0040;
327
328 /**
329 * Flag for {@link #bindService}: If binding from an activity, allow the
330 * target service's process importance to be raised based on whether the
331 * activity is visible to the user, regardless whether another flag is
332 * used to reduce the amount that the client process's overall importance
333 * is used to impact it.
334 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700335 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
336
337 /**
Amith Yamasani5016a782019-06-17 16:20:24 -0700338 * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible,
339 * lower the target service's importance to below the perceptible level. This allows
340 * the system to (temporarily) expunge the bound process from memory to make room for more
341 * important user-perceptible processes.
342 */
343 public static final int BIND_NOT_PERCEPTIBLE = 0x00000100;
344
345 /**
Amith Yamasanif178c962019-03-21 19:40:11 -0700346 * Flag for {@link #bindService}: If binding from an app that has specific capabilities
347 * due to its foreground state such as an activity or foreground service, then this flag will
348 * allow the bound app to get the same capabilities, as long as it has the required permissions
349 * as well.
350 */
Amith Yamasani5016a782019-06-17 16:20:24 -0700351 public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000;
Amith Yamasanif178c962019-03-21 19:40:11 -0700352
Amith Yamasani0b3ae0e2019-05-10 10:29:47 -0700353 /*********** Public flags above this line ***********/
354 /*********** Hidden flags below this line ***********/
355
356 /**
Yohei Yukawa59730962019-03-18 10:47:22 -0700357 * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust
358 * the scheduling policy for IMEs (and any other out-of-process user-visible components that
359 * work closely with the top app) so that UI hosted in such services can have the same
360 * scheduling policy (e.g. SCHED_FIFO when it is enabled and TOP_APP_PRIORITY_BOOST otherwise)
361 * as the actual top-app.
362 * @hide
363 */
364 public static final int BIND_SCHEDULE_LIKE_TOP_APP = 0x00080000;
365
366 /**
Michal Karpinskie069b002019-03-07 16:15:14 +0000367 * Flag for {@link #bindService}: allow background activity starts from the bound service's
368 * process.
369 * This flag is only respected if the caller is holding
370 * {@link android.Manifest.permission#START_ACTIVITIES_FROM_BACKGROUND}.
371 * @hide
372 */
373 public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 0x00100000;
374
375 /**
Dianne Hackbornc390aa82019-01-09 16:38:22 -0800376 * @hide Flag for {@link #bindService}: the service being bound to represents a
377 * protected system component, so must have association restrictions applied to it.
378 * That is, a system config must have one or more allow-association tags limiting
379 * which packages it can interact with. If it does not have any such association
380 * restrictions, a default empty set will be created.
381 */
382 public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000;
383
384 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800385 * @hide Flag for {@link #bindService}: allows binding to a service provided
386 * by an instant app. Note that the caller may not have access to the instant
387 * app providing the service which is a violation of the instant app sandbox.
388 * This flag is intended ONLY for development/testing and should be used with
389 * great care. Only the system is allowed to use this flag.
390 */
391 public static final int BIND_ALLOW_INSTANT = 0x00400000;
392
393 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700394 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
395 * up in to the important background state (instead of transient).
396 */
397 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
398
399 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700400 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
401 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
402 */
403 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
404
405 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700406 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
407 * but only applies while the device is awake.
408 */
409 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
410
411 /**
412 * @hide Flag for {@link #bindService}: For only the case where the binding
413 * is coming from the system, set the process state to FOREGROUND_SERVICE
414 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
415 * saying that the process shouldn't participate in the normal power reduction
416 * modes (removing network access etc).
417 */
418 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
419
420 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700421 * @hide Flag for {@link #bindService}: Treat the binding as hosting
422 * an activity, an unbinding as the activity going in the background.
423 * That is, when unbinding, the process when empty will go on the activity
424 * LRU list instead of the regular one, keeping it around more aggressively
425 * than it otherwise would be. This is intended for use with IMEs to try
426 * to keep IME processes around for faster keyboard switching.
427 */
428 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
429
430 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700431 * @hide An idea that is not yet implemented.
432 * Flag for {@link #bindService}: If binding from an activity, consider
433 * this service to be visible like the binding activity is. That is,
434 * it will be treated as something more important to keep around than
435 * invisible background activities. This will impact the number of
436 * recent activities the user can switch between without having them
437 * restart. There is no guarantee this will be respected, as the system
Amith Yamasanif235d0b2019-03-20 22:49:43 -0700438 * tries to balance such requests from one app vs. the importance of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700439 * keeping other apps around.
440 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700441 public static final int BIND_VISIBLE = 0x10000000;
442
443 /**
444 * @hide
445 * Flag for {@link #bindService}: Consider this binding to be causing the target
446 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
447 * away.
448 */
449 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700450
451 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700452 * Flag for {@link #bindService}: Don't consider the bound service to be
453 * visible, even if the caller is visible.
454 * @hide
455 */
456 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700457
Alan Viverette713a5cd2015-12-16 15:46:32 -0500458 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500459 * Flag for {@link #bindService}: The service being bound is an
460 * {@link android.R.attr#isolatedProcess isolated},
461 * {@link android.R.attr#externalService external} service. This binds the service into the
462 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400463 * <p>
464 * When using this flag, the code for the service being bound will execute under the calling
465 * application's package name and user ID. Because the service must be an isolated process,
466 * it will not have direct access to the application's data, though.
467 *
468 * The purpose of this flag is to allow applications to provide services that are attributed
469 * to the app using the service, rather than the application providing the service.
470 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500471 */
472 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
473
Dianne Hackborna631d562018-11-20 15:58:15 -0800474 /**
475 * These bind flags reduce the strength of the binding such that we shouldn't
476 * consider it as pulling the process up to the level of the one that is bound to it.
477 * @hide
478 */
479 public static final int BIND_REDUCTION_FLAGS =
480 Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
Amith Yamasani5016a782019-06-17 16:20:24 -0700481 | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;
Dianne Hackborna631d562018-11-20 15:58:15 -0800482
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700483 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700484 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
485 RECEIVER_VISIBLE_TO_INSTANT_APPS
486 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700487 @Retention(RetentionPolicy.SOURCE)
488 public @interface RegisterReceiverFlags {}
489
490 /**
491 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
492 */
493 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
494
Robert Sesekb9a86662015-12-09 16:22:45 -0500495 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500496 * Returns an AssetManager instance for the application's package.
497 * <p>
498 * <strong>Note:</strong> Implementations of this method should return
499 * an AssetManager instance that is consistent with the Resources instance
500 * returned by {@link #getResources()}. For example, they should share the
501 * same {@link Configuration} object.
502 *
503 * @return an AssetManager instance for the application's package
504 * @see #getResources()
505 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 public abstract AssetManager getAssets();
507
Alan Viverette713a5cd2015-12-16 15:46:32 -0500508 /**
509 * Returns a Resources instance for the application's package.
510 * <p>
511 * <strong>Note:</strong> Implementations of this method should return
512 * a Resources instance that is consistent with the AssetManager instance
513 * returned by {@link #getAssets()}. For example, they should share the
514 * same {@link Configuration} object.
515 *
516 * @return a Resources instance for the application's package
517 * @see #getAssets()
518 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 public abstract Resources getResources();
520
521 /** Return PackageManager instance to find global package information. */
522 public abstract PackageManager getPackageManager();
523
524 /** Return a ContentResolver instance for your application's package. */
525 public abstract ContentResolver getContentResolver();
526
527 /**
528 * Return the Looper for the main thread of the current process. This is
529 * the thread used to dispatch calls to application components (activities,
530 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700531 * <p>
532 * By definition, this method returns the same result as would be obtained
533 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
534 * </p>
535 *
536 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 */
538 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700541 * Return an {@link Executor} that will run enqueued tasks on the main
542 * thread associated with this context. This is the thread used to dispatch
543 * calls to application components (activities, services, etc).
544 */
545 public Executor getMainExecutor() {
546 // This is pretty inefficient, which is why ContextImpl overrides it
547 return new HandlerExecutor(new Handler(getMainLooper()));
548 }
549
550 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800552 * current process. This generally should only be used if you need a
553 * Context whose lifecycle is separate from the current context, that is
554 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700555 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800556 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800557 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800558 * <ul>
559 * <li> <p>If used from an Activity context, the receiver is being registered
560 * within that activity. This means that you are expected to unregister
561 * before the activity is done being destroyed; in fact if you do not do
562 * so, the framework will clean up your leaked registration as it removes
563 * the activity and log an error. Thus, if you use the Activity context
564 * to register a receiver that is static (global to the process, not
565 * associated with an Activity instance) then that registration will be
566 * removed on you at whatever point the activity you used is destroyed.
567 * <li> <p>If used from the Context returned here, the receiver is being
568 * registered with the global state associated with your application. Thus
569 * it will never be unregistered for you. This is necessary if the receiver
570 * is associated with static data, not a particular component. However
571 * using the ApplicationContext elsewhere can easily lead to serious leaks
572 * if you forget to unregister, unbind, etc.
573 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 */
575 public abstract Context getApplicationContext();
576
Phil Weaver846cda932017-06-15 10:10:06 -0700577 /** Non-activity related autofill ids are unique in the app */
578 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700579
580 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700581 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700582 *
Phil Weaver846cda932017-06-15 10:10:06 -0700583 * <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 -0700584 * returned will be unique.
585 *
586 * @return A ID that is unique in the process
587 *
588 * {@hide}
589 */
Phil Weaver846cda932017-06-15 10:10:06 -0700590 public int getNextAutofillId() {
591 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
592 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700593 }
594
Phil Weaver846cda932017-06-15 10:10:06 -0700595 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700596
Phil Weaver846cda932017-06-15 10:10:06 -0700597 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700598 }
599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700601 * Add a new {@link ComponentCallbacks} to the base application of the
602 * Context, which will be called at the same times as the ComponentCallbacks
603 * methods of activities and other components are called. Note that you
604 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
605 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700606 *
607 * @param callback The interface to call. This can be either a
608 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700609 */
610 public void registerComponentCallbacks(ComponentCallbacks callback) {
611 getApplicationContext().registerComponentCallbacks(callback);
612 }
613
614 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400615 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700616 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
617 */
618 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
619 getApplicationContext().unregisterComponentCallbacks(callback);
620 }
621
622 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 * Return a localized, styled CharSequence from the application's package's
624 * default string table.
625 *
626 * @param resId Resource id for the CharSequence text
627 */
Chris Craikceb26932018-02-01 15:51:34 -0800628 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700629 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 return getResources().getText(resId);
631 }
632
633 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700634 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 * default string table.
636 *
637 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700638 * @return The string data associated with the resource, stripped of styled
639 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700641 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700642 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 return getResources().getString(resId);
644 }
645
646 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700647 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 * default string table, substituting the format arguments as defined in
649 * {@link java.util.Formatter} and {@link java.lang.String#format}.
650 *
651 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700652 * @param formatArgs The format arguments that will be used for
653 * substitution.
654 * @return The string data associated with the resource, formatted and
655 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700657 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700658 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 return getResources().getString(resId, formatArgs);
660 }
661
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800662 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800663 * Returns a color associated with a particular resource ID and styled for
664 * the current theme.
665 *
666 * @param id The desired resource identifier, as generated by the aapt
667 * tool. This integer encodes the package, type, and resource
668 * entry. The value 0 is an invalid identifier.
669 * @return A single color value in the form 0xAARRGGBB.
670 * @throws android.content.res.Resources.NotFoundException if the given ID
671 * does not exist.
672 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700673 @ColorInt
674 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800675 return getResources().getColor(id, getTheme());
676 }
677
678 /**
679 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800680 * styled for the current theme.
681 *
682 * @param id The desired resource identifier, as generated by the aapt
683 * tool. This integer encodes the package, type, and resource
684 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800685 * @return An object that can be used to draw this resource.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800686 * @throws android.content.res.Resources.NotFoundException if the given ID
687 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800688 */
Chris Craik1194b0b2018-03-23 13:36:24 -0700689 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700690 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800691 return getResources().getDrawable(id, getTheme());
692 }
693
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800694 /**
695 * Returns a color state list associated with a particular resource ID and
696 * styled for the current theme.
697 *
698 * @param id The desired resource identifier, as generated by the aapt
699 * tool. This integer encodes the package, type, and resource
700 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800701 * @return A color state list.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800702 * @throws android.content.res.Resources.NotFoundException if the given ID
703 * does not exist.
704 */
Chris Craikceb26932018-02-01 15:51:34 -0800705 @NonNull
Tor Norbye3e4cda72015-06-10 08:14:31 -0700706 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800707 return getResources().getColorStateList(id, getTheme());
708 }
709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 /**
711 * Set the base theme for this context. Note that this should be called
712 * before any views are instantiated in the Context (for example before
713 * calling {@link android.app.Activity#setContentView} or
714 * {@link android.view.LayoutInflater#inflate}).
715 *
716 * @param resid The style resource describing the theme.
717 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700718 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719
Dianne Hackborn247fe742011-01-08 17:25:57 -0800720 /** @hide Needed for some internal implementation... not public because
721 * you can't assume this actually means anything. */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100722 @UnsupportedAppUsage
Dianne Hackborn247fe742011-01-08 17:25:57 -0800723 public int getThemeResId() {
724 return 0;
725 }
726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 /**
728 * Return the Theme object associated with this Context.
729 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700730 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 public abstract Resources.Theme getTheme();
732
733 /**
734 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800735 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 * for more information.
737 *
Jeff Brown6e539312015-02-24 18:53:21 -0800738 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800740 @NonNull
741 public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 return getTheme().obtainStyledAttributes(attrs);
743 }
744
745 /**
746 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800747 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 * for more information.
749 *
Jeff Brown6e539312015-02-24 18:53:21 -0800750 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800752 @NonNull
753 public final TypedArray obtainStyledAttributes(@StyleRes int resid,
754 @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 return getTheme().obtainStyledAttributes(resid, attrs);
756 }
757
758 /**
759 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800760 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 * for more information.
762 *
Jeff Brown6e539312015-02-24 18:53:21 -0800763 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800765 @NonNull
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 public final TypedArray obtainStyledAttributes(
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800767 @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
769 }
770
771 /**
772 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800773 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 * for more information.
775 *
Jeff Brown6e539312015-02-24 18:53:21 -0800776 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800778 @NonNull
779 public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set,
780 @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
Tor Norbyec91531a2015-04-01 17:41:55 -0700781 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 return getTheme().obtainStyledAttributes(
783 set, attrs, defStyleAttr, defStyleRes);
784 }
785
786 /**
787 * Return a class loader you can use to retrieve classes in this package.
788 */
789 public abstract ClassLoader getClassLoader();
790
791 /** Return the name of this application's package. */
792 public abstract String getPackageName();
793
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900794 /**
795 * @hide Return the name of the base context this context is derived from.
796 * This is the same as {@link #getOpPackageName()} except in
797 * cases where system components are loaded into other app processes, in which
798 * case {@link #getOpPackageName()} will be the name of the primary package in
799 * that process (so that app ops uid verification will work with the name).
800 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100801 @UnsupportedAppUsage
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800802 public abstract String getBasePackageName();
803
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900804 /**
805 * Return the package name that should be used for {@link android.app.AppOpsManager} calls from
806 * this context, so that app ops manager's uid verification will work with the name.
807 * <p>
808 * This is not generally intended for third party application developers.
809 */
Adrian Roosebc927c2019-02-28 16:21:18 +0100810 @NonNull
Adrian Roosfe6aeaf2019-01-22 16:58:56 +0100811 public String getOpPackageName() {
812 throw new RuntimeException("Not implemented. Must override in a subclass.");
813 }
Dianne Hackborn95d78532013-09-11 09:51:14 -0700814
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700815 /** Return the full application info for this context's package. */
816 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 /**
Kenny Root32148392010-01-21 15:40:47 -0800819 * Return the full path to this context's primary Android package.
820 * The Android package is a ZIP file which contains the application's
821 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 *
823 * <p>Note: this is not generally useful for applications, since they should
824 * not be directly accessing the file system.
825 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 * @return String Path to the resources.
827 */
828 public abstract String getPackageResourcePath();
829
830 /**
Kenny Root32148392010-01-21 15:40:47 -0800831 * Return the full path to this context's primary Android package.
832 * The Android package is a ZIP file which contains application's
833 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 *
835 * <p>Note: this is not generally useful for applications, since they should
836 * not be directly accessing the file system.
837 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 * @return String Path to the code and assets.
839 */
840 public abstract String getPackageCodePath();
841
842 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700843 * @hide
844 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700845 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700846 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100847 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700848 public File getSharedPrefsFile(String name) {
849 return getSharedPreferencesPath(name);
850 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700851
852 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 * Retrieve and hold the contents of the preferences file 'name', returning
854 * a SharedPreferences through which you can retrieve and modify its
855 * values. Only one instance of the SharedPreferences object is returned
856 * to any callers for the same name, meaning they will see each other's
857 * edits as soon as they are made.
858 *
Nate Fischer5272c372019-08-27 16:37:00 -0700859 * <p>This method is thread-safe.
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700860 *
Nate Fischer5272c372019-08-27 16:37:00 -0700861 * <p>If the preferences directory does not already exist, it will be created when this method
862 * is called.
863 *
864 * <p>If a preferences file by this name does not exist, it will be created when you retrieve an
865 * editor ({@link SharedPreferences#edit()}) and then commit changes ({@link
866 * SharedPreferences.Editor#commit()} or {@link SharedPreferences.Editor#apply()}).
867 *
868 * @param name Desired preferences file.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600869 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400871 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 * to retrieve and modify the preference values.
873 *
874 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600876 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700877
878 /**
879 * Retrieve and hold the contents of the preferences file, returning
880 * a SharedPreferences through which you can retrieve and modify its
881 * values. Only one instance of the SharedPreferences object is returned
882 * to any callers for the same name, meaning they will see each other's
883 * edits as soon as they are made.
884 *
885 * @param file Desired preferences file. If a preferences file by this name
886 * does not exist, it will be created when you retrieve an
887 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600888 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700889 *
890 * @return The single {@link SharedPreferences} instance that can be used
891 * to retrieve and modify the preference values.
892 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700893 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700894 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600895 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700896 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600897 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898
899 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600900 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700901 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600902 * storage locations after an upgrade, such as moving to device protected
903 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700904 *
905 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600906 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700907 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600908 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700909 * preferences didn't exist in the source context, otherwise
910 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600911 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700912 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600913 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
914
Jeff Sharkey35871f22016-01-29 17:13:29 -0700915 /**
916 * Delete an existing shared preferences file.
917 *
918 * @param name The name (unique in the application package) of the shared
919 * preferences file.
920 * @return {@code true} if the shared preferences file was successfully
921 * deleted; else {@code false}.
922 * @see #getSharedPreferences(String, int)
923 */
924 public abstract boolean deleteSharedPreferences(String name);
925
Christopher Tatefe2368c2017-05-17 15:42:35 -0700926 /** @hide */
927 public abstract void reloadSharedPreferences();
928
Jeff Sharkey35871f22016-01-29 17:13:29 -0700929 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800930 * Open a private file associated with this Context's application package
931 * for reading.
932 *
933 * @param name The name of the file to open; can not contain path
934 * separators.
935 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400936 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800937 *
938 * @see #openFileOutput
939 * @see #fileList
940 * @see #deleteFile
941 * @see java.io.FileInputStream#FileInputStream(String)
942 */
943 public abstract FileInputStream openFileInput(String name)
944 throws FileNotFoundException;
945
946 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800947 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700948 * for writing. Creates the file if it doesn't already exist.
949 * <p>
950 * No additional permissions are required for the calling app to read or
951 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700952 *
Nick Kralevich15069212013-01-09 15:54:56 -0800953 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700954 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600955 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400956 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957 * @see #MODE_APPEND
958 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 * @see #openFileInput
960 * @see #fileList
961 * @see #deleteFile
962 * @see java.io.FileOutputStream#FileOutputStream(String)
963 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600964 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 throws FileNotFoundException;
966
967 /**
968 * Delete the given private file associated with this Context's
969 * application package.
970 *
971 * @param name The name of the file to delete; can not contain path
972 * separators.
973 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400974 * @return {@code true} if the file was successfully deleted; else
975 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 *
977 * @see #openFileInput
978 * @see #openFileOutput
979 * @see #fileList
980 * @see java.io.File#delete()
981 */
982 public abstract boolean deleteFile(String name);
983
984 /**
985 * Returns the absolute path on the filesystem where a file created with
986 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700987 * <p>
988 * The returned path may change over time if the calling app is moved to an
989 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 *
991 * @param name The name of the file for which you would like to get
992 * its path.
993 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400994 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800995 *
996 * @see #openFileOutput
997 * @see #getFilesDir
998 * @see #getDir
999 */
1000 public abstract File getFileStreamPath(String name);
1001
1002 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001003 * Returns the absolute path on the filesystem where a file created with
1004 * {@link #getSharedPreferences(String, int)} is stored.
1005 * <p>
1006 * The returned path may change over time if the calling app is moved to an
1007 * adopted storage device, so only relative paths should be persisted.
1008 *
1009 * @param name The name of the shared preferences for which you would like
1010 * to get a path.
1011 * @return An absolute path to the given file.
1012 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001013 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001014 */
1015 public abstract File getSharedPreferencesPath(String name);
1016
1017 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001018 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001019 * private files belonging to this app are stored. Apps should not use this
1020 * path directly; they should instead use {@link #getFilesDir()},
1021 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1022 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001023 * <p>
1024 * The returned path may change over time if the calling app is moved to an
1025 * adopted storage device, so only relative paths should be persisted.
1026 * <p>
1027 * No additional permissions are required for the calling app to read or
1028 * write files under the returned path.
1029 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001030 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001031 */
1032 public abstract File getDataDir();
1033
1034 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001035 * Returns the absolute path to the directory on the filesystem where files
1036 * created with {@link #openFileOutput} are stored.
1037 * <p>
1038 * The returned path may change over time if the calling app is moved to an
1039 * adopted storage device, so only relative paths should be persisted.
1040 * <p>
1041 * No additional permissions are required for the calling app to read or
1042 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -07001043 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001044 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 * @see #openFileOutput
1046 * @see #getFileStreamPath
1047 * @see #getDir
1048 */
1049 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -07001050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001051 /**
Christopher Tatea7835b62014-07-11 17:25:57 -07001052 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001053 * {@link #getFilesDir()}. The difference is that files placed under this
1054 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -07001055 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1056 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001057 * <p>
1058 * The returned path may change over time if the calling app is moved to an
1059 * adopted storage device, so only relative paths should be persisted.
1060 * <p>
1061 * No additional permissions are required for the calling app to read or
1062 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -07001063 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001064 * @return The path of the directory holding application files that will not
1065 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -07001066 * @see #openFileOutput
1067 * @see #getFileStreamPath
1068 * @see #getDir
1069 * @see android.app.backup.BackupAgent
1070 */
1071 public abstract File getNoBackupFilesDir();
1072
1073 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001074 * Returns the absolute path to the directory on the primary shared/external
1075 * storage device where the application can place persistent files it owns.
1076 * These files are internal to the applications, and not typically visible
1077 * to the user as media.
1078 * <p>
1079 * This is like {@link #getFilesDir()} in that these files will be deleted
1080 * when the application is uninstalled, however there are some important
1081 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001082 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001083 * <li>Shared storage may not always be available, since removable media can
1084 * be ejected by the user. Media state can be checked using
1085 * {@link Environment#getExternalStorageState(File)}.
1086 * <li>There is no security enforced with these files. For example, any
1087 * application holding
1088 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001089 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001090 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001091 * <p>
1092 * If a shared storage device is emulated (as determined by
1093 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1094 * backed by a private user data partition, which means there is little
1095 * benefit to storing data here instead of the private directories returned
1096 * by {@link #getFilesDir()}, etc.
1097 * <p>
1098 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001099 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001100 * accessible to the calling app. This only applies to paths generated for
1101 * package name of the calling application. To access paths belonging to
1102 * other packages,
1103 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1104 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1105 * <p>
1106 * On devices with multiple users (as described by {@link UserManager}),
1107 * each user has their own isolated shared storage. Applications only have
1108 * access to the shared storage for the user they're running as.
1109 * <p>
1110 * The returned path may change over time if different shared storage media
1111 * is inserted, so only relative paths should be persisted.
1112 * <p>
1113 * Here is an example of typical code to manipulate a file in an
1114 * application's shared storage:
1115 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001116 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1117 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001118 * <p>
1119 * If you supply a non-null <var>type</var> to this function, the returned
1120 * file will be a path to a sub-directory of the given type. Though these
1121 * files are not automatically scanned by the media scanner, you can
1122 * explicitly add them to the media database with
1123 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1124 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001125 * {@link android.os.Environment#getExternalStoragePublicDirectory
1126 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001127 * directories of media shared by all applications. The directories returned
1128 * here are owned by the application, and their contents will be removed
1129 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001130 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001131 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1132 * here will be automatically created for you.
1133 * <p>
1134 * Here is an example of typical code to manipulate a picture in an
1135 * application's shared storage and add it to the media database:
1136 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001137 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1138 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001139 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001140 * @param type The type of files directory to return. May be {@code null}
1141 * for the root of the files directory or one of the following
1142 * constants for a subdirectory:
1143 * {@link android.os.Environment#DIRECTORY_MUSIC},
1144 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1145 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1146 * {@link android.os.Environment#DIRECTORY_ALARMS},
1147 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1148 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1149 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1150 * @return the absolute path to application-specific directory. May return
1151 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001152 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001153 * @see #getExternalFilesDirs(String)
1154 * @see Environment#getExternalStorageState(File)
1155 * @see Environment#isExternalStorageEmulated(File)
1156 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001157 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001158 @Nullable
1159 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001160
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001161 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001162 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001163 * shared/external storage devices where the application can place
1164 * persistent files it owns. These files are internal to the application,
1165 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001166 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001167 * This is like {@link #getFilesDir()} in that these files will be deleted
1168 * when the application is uninstalled, however there are some important
1169 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001170 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001171 * <li>Shared storage may not always be available, since removable media can
1172 * be ejected by the user. Media state can be checked using
1173 * {@link Environment#getExternalStorageState(File)}.
1174 * <li>There is no security enforced with these files. For example, any
1175 * application holding
1176 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1177 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001178 * </ul>
1179 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001180 * If a shared storage device is emulated (as determined by
1181 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1182 * backed by a private user data partition, which means there is little
1183 * benefit to storing data here instead of the private directories returned
1184 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001185 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001186 * Shared storage devices returned here are considered a stable part of the
1187 * device, including physical media slots under a protective cover. The
1188 * returned paths do not include transient devices, such as USB flash drives
1189 * connected to handheld devices.
1190 * <p>
1191 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001192 * example, an app may choose to store large files on the device with the
1193 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001194 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001195 * No additional permissions are required for the calling app to read or
1196 * write files under the returned path. Write access outside of these paths
1197 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001198 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001199 * The returned path may change over time if different shared storage media
1200 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001201 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001202 * @param type The type of files directory to return. May be {@code null}
1203 * for the root of the files directory or one of the following
1204 * constants for a subdirectory:
1205 * {@link android.os.Environment#DIRECTORY_MUSIC},
1206 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1207 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1208 * {@link android.os.Environment#DIRECTORY_ALARMS},
1209 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1210 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1211 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1212 * @return the absolute paths to application-specific directories. Some
1213 * individual paths may be {@code null} if that shared storage is
1214 * not currently available. The first path returned is the same as
1215 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001216 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001217 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001218 * @see Environment#isExternalStorageEmulated(File)
1219 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001220 */
1221 public abstract File[] getExternalFilesDirs(String type);
1222
1223 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001224 * Return the primary shared/external storage directory where this
1225 * application's OBB files (if there are any) can be found. Note if the
1226 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001227 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001228 * This is like {@link #getFilesDir()} in that these files will be deleted
1229 * when the application is uninstalled, however there are some important
1230 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001231 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001232 * <li>Shared storage may not always be available, since removable media can
1233 * be ejected by the user. Media state can be checked using
1234 * {@link Environment#getExternalStorageState(File)}.
1235 * <li>There is no security enforced with these files. For example, any
1236 * application holding
1237 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001238 * these files.
1239 * </ul>
1240 * <p>
1241 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001242 * are required to read or write to the path that this method returns.
1243 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1244 * to read the OBB expansion files, you must declare the
1245 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1246 * permission at runtime as follows:
1247 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001248 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001249 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1250 * android:maxSdkVersion="23" />}
1251 * </p>
1252 * <p>
1253 * Starting from {@link android.os.Build.VERSION_CODES#N},
1254 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1255 * permission is not required, so don’t ask for this
1256 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1257 * and if it fails, you must request
1258 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1259 * </p>
1260 *
1261 * <p>
1262 * The following code snippet shows how to do this:
1263 * </p>
1264 *
1265 * <pre>
1266 * File obb = new File(obb_filename);
1267 * boolean open_failed = false;
1268 *
1269 * try {
1270 * BufferedReader br = new BufferedReader(new FileReader(obb));
1271 * open_failed = false;
1272 * ReadObbFile(br);
1273 * } catch (IOException e) {
1274 * open_failed = true;
1275 * }
1276 *
1277 * if (open_failed) {
1278 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1279 * ReadObbFileWithPermission();
1280 * }
1281 * </pre>
1282 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001283 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001284 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001285 * should ensure that multiple instances running under different users don't
1286 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001287 *
1288 * @return the absolute path to application-specific directory. May return
1289 * {@code null} if shared storage is not currently available.
1290 * @see #getObbDirs()
1291 * @see Environment#getExternalStorageState(File)
1292 * @see Environment#isExternalStorageEmulated(File)
1293 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001294 */
1295 public abstract File getObbDir();
1296
1297 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001298 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001299 * shared/external storage devices where the application's OBB files (if
1300 * there are any) can be found. Note if the application does not have any
1301 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001302 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001303 * This is like {@link #getFilesDir()} in that these files will be deleted
1304 * when the application is uninstalled, however there are some important
1305 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001306 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001307 * <li>Shared storage may not always be available, since removable media can
1308 * be ejected by the user. Media state can be checked using
1309 * {@link Environment#getExternalStorageState(File)}.
1310 * <li>There is no security enforced with these files. For example, any
1311 * application holding
1312 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1313 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001314 * </ul>
1315 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001316 * Shared storage devices returned here are considered a stable part of the
1317 * device, including physical media slots under a protective cover. The
1318 * returned paths do not include transient devices, such as USB flash drives
1319 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001320 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001321 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001322 * example, an app may choose to store large files on the device with the
1323 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001324 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001325 * No additional permissions are required for the calling app to read or
1326 * write files under the returned path. Write access outside of these paths
1327 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001328 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001329 * @return the absolute paths to application-specific directories. Some
1330 * individual paths may be {@code null} if that shared storage is
1331 * not currently available. The first path returned is the same as
1332 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001333 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001334 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001335 * @see Environment#isExternalStorageEmulated(File)
1336 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001337 */
1338 public abstract File[] getObbDirs();
1339
1340 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001341 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001342 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001343 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001344 * The system will automatically delete files in this directory as disk
1345 * space is needed elsewhere on the device. The system will always delete
1346 * older files first, as reported by {@link File#lastModified()}. If
1347 * desired, you can exert more control over how files are deleted using
1348 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1349 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1350 * <p>
1351 * Apps are strongly encouraged to keep their usage of cache space below the
1352 * quota returned by
1353 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1354 * goes above this quota, your cached files will be some of the first to be
1355 * deleted when additional disk space is needed. Conversely, if your app
1356 * stays under this quota, your cached files will be some of the last to be
1357 * deleted when additional disk space is needed.
1358 * <p>
1359 * Note that your cache quota will change over time depending on how
1360 * frequently the user interacts with your app, and depending on how much
1361 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001362 * <p>
1363 * The returned path may change over time if the calling app is moved to an
1364 * adopted storage device, so only relative paths should be persisted.
1365 * <p>
1366 * Apps require no extra permissions to read or write to the returned path,
1367 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001368 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001369 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001370 * @see #openFileOutput
1371 * @see #getFileStreamPath
1372 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001373 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001374 */
1375 public abstract File getCacheDir();
1376
1377 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001378 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001379 * the filesystem designed for storing cached code.
1380 * <p>
1381 * The system will delete any files stored in this location both when your
1382 * specific application is upgraded, and when the entire platform is
1383 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001384 * <p>
1385 * This location is optimal for storing compiled or optimized code generated
1386 * by your application at runtime.
1387 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001388 * The returned path may change over time if the calling app is moved to an
1389 * adopted storage device, so only relative paths should be persisted.
1390 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001391 * Apps require no extra permissions to read or write to the returned path,
1392 * since this path lives in their private storage.
1393 *
1394 * @return The path of the directory holding application code cache files.
1395 */
1396 public abstract File getCodeCacheDir();
1397
1398 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001399 * Returns absolute path to application-specific directory on the primary
1400 * shared/external storage device where the application can place cache
1401 * files it owns. These files are internal to the application, and not
1402 * typically visible to the user as media.
1403 * <p>
1404 * This is like {@link #getCacheDir()} in that these files will be deleted
1405 * when the application is uninstalled, however there are some important
1406 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001407 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001408 * <li>The platform does not always monitor the space available in shared
1409 * storage, and thus may not automatically delete these files. Apps should
1410 * always manage the maximum space used in this location. Currently the only
1411 * time files here will be deleted by the platform is when running on
1412 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1413 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1414 * <li>Shared storage may not always be available, since removable media can
1415 * be ejected by the user. Media state can be checked using
1416 * {@link Environment#getExternalStorageState(File)}.
1417 * <li>There is no security enforced with these files. For example, any
1418 * application holding
1419 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001420 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001421 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001422 * <p>
1423 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001424 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001425 * backed by a private user data partition, which means there is little
1426 * benefit to storing data here instead of the private directory returned by
1427 * {@link #getCacheDir()}.
1428 * <p>
1429 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001430 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001431 * accessible to the calling app. This only applies to paths generated for
1432 * package name of the calling application. To access paths belonging to
1433 * other packages,
1434 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1435 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1436 * <p>
1437 * On devices with multiple users (as described by {@link UserManager}),
1438 * each user has their own isolated shared storage. Applications only have
1439 * access to the shared storage for the user they're running as.
1440 * <p>
1441 * The returned path may change over time if different shared storage media
1442 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001443 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001444 * @return the absolute path to application-specific directory. May return
1445 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001446 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001447 * @see #getExternalCacheDirs()
1448 * @see Environment#getExternalStorageState(File)
1449 * @see Environment#isExternalStorageEmulated(File)
1450 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001451 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001452 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001453 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001454
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001455 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001456 * Returns absolute path to application-specific directory in the preloaded cache.
1457 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1458 * There is no guarantee when these files will be deleted.
1459 * @hide
1460 */
1461 @Nullable
1462 @SystemApi
1463 public abstract File getPreloadsFileCache();
1464
1465 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001466 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001467 * shared/external storage devices where the application can place cache
1468 * files it owns. These files are internal to the application, and not
1469 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001470 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001471 * This is like {@link #getCacheDir()} in that these files will be deleted
1472 * when the application is uninstalled, however there are some important
1473 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001474 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001475 * <li>The platform does not always monitor the space available in shared
1476 * storage, and thus may not automatically delete these files. Apps should
1477 * always manage the maximum space used in this location. Currently the only
1478 * time files here will be deleted by the platform is when running on
1479 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1480 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1481 * <li>Shared storage may not always be available, since removable media can
1482 * be ejected by the user. Media state can be checked using
1483 * {@link Environment#getExternalStorageState(File)}.
1484 * <li>There is no security enforced with these files. For example, any
1485 * application holding
1486 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1487 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001488 * </ul>
1489 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001490 * If a shared storage device is emulated (as determined by
1491 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1492 * backed by a private user data partition, which means there is little
1493 * benefit to storing data here instead of the private directory returned by
1494 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001495 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001496 * Shared storage devices returned here are considered a stable part of the
1497 * device, including physical media slots under a protective cover. The
1498 * returned paths do not include transient devices, such as USB flash drives
1499 * connected to handheld devices.
1500 * <p>
1501 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001502 * example, an app may choose to store large files on the device with the
1503 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001504 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001505 * No additional permissions are required for the calling app to read or
1506 * write files under the returned path. Write access outside of these paths
1507 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001508 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001509 * The returned paths may change over time if different shared storage media
1510 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001511 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001512 * @return the absolute paths to application-specific directories. Some
1513 * individual paths may be {@code null} if that shared storage is
1514 * not currently available. The first path returned is the same as
1515 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001516 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001517 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001518 * @see Environment#isExternalStorageEmulated(File)
1519 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001520 */
1521 public abstract File[] getExternalCacheDirs();
1522
1523 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001524 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001525 * shared/external storage devices where the application can place media
1526 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001527 * {@link MediaStore}.
1528 * <p>
1529 * This is like {@link #getExternalFilesDirs} in that these files will be
1530 * deleted when the application is uninstalled, however there are some
1531 * important differences:
1532 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001533 * <li>Shared storage may not always be available, since removable media can
1534 * be ejected by the user. Media state can be checked using
1535 * {@link Environment#getExternalStorageState(File)}.
1536 * <li>There is no security enforced with these files. For example, any
1537 * application holding
1538 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1539 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001540 * </ul>
1541 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001542 * Shared storage devices returned here are considered a stable part of the
1543 * device, including physical media slots under a protective cover. The
1544 * returned paths do not include transient devices, such as USB flash drives
1545 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001546 * <p>
1547 * An application may store data on any or all of the returned devices. For
1548 * example, an app may choose to store large files on the device with the
1549 * most available space, as measured by {@link StatFs}.
1550 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001551 * No additional permissions are required for the calling app to read or
1552 * write files under the returned path. Write access outside of these paths
1553 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001554 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001555 * The returned paths may change over time if different shared storage media
1556 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001557 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001558 * @return the absolute paths to application-specific directories. Some
1559 * individual paths may be {@code null} if that shared storage is
1560 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001561 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001562 * @see Environment#isExternalStorageEmulated(File)
1563 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001564 */
1565 public abstract File[] getExternalMediaDirs();
1566
1567 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001568 * Returns an array of strings naming the private files associated with
1569 * this Context's application package.
1570 *
1571 * @return Array of strings naming the private files.
1572 *
1573 * @see #openFileInput
1574 * @see #openFileOutput
1575 * @see #deleteFile
1576 */
1577 public abstract String[] fileList();
1578
1579 /**
1580 * Retrieve, creating if needed, a new directory in which the application
1581 * can place its own custom data files. You can use the returned File
1582 * object to create and access files in this directory. Note that files
1583 * created through a File object will only be accessible by your own
1584 * application; you can only set the mode of the entire directory, not
1585 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001586 * <p>
1587 * The returned path may change over time if the calling app is moved to an
1588 * adopted storage device, so only relative paths should be persisted.
1589 * <p>
1590 * Apps require no extra permissions to read or write to the returned path,
1591 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001593 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001594 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001595 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001596 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001597 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001598 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001599 *
1600 * @see #openFileOutput(String, int)
1601 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001602 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001603
1604 /**
1605 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001606 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 *
1608 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001609 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001611 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001613 * @throws android.database.sqlite.SQLiteException if the database file
1614 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001616 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001617 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001618 * @see #deleteDatabase
1619 */
1620 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001621 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622
1623 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001624 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001625 * application package. Creates the database file if it doesn't exist.
1626 * <p>
1627 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1628 * to be used to handle corruption when sqlite reports database corruption.
1629 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001630 *
1631 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001632 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001633 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001634 * cursor when query is called.
1635 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1636 * sqlite reports database corruption. if null,
1637 * {@link android.database.DefaultDatabaseErrorHandler} is
1638 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001639 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001640 * @throws android.database.sqlite.SQLiteException if the database file
1641 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001642 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001643 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001644 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001645 * @see #deleteDatabase
1646 */
1647 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001648 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001649 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001650
1651 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001652 * Move an existing database file from the given source storage context to
1653 * this context. This is typically used to migrate data between storage
1654 * locations after an upgrade, such as migrating to device protected
1655 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001656 * <p>
1657 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001658 *
1659 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001660 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001661 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001662 * @return {@code true} if the move was successful or if the database didn't
1663 * exist in the source context, otherwise {@code false}.
1664 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001665 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001666 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1667
Jeff Sharkey35871f22016-01-29 17:13:29 -07001668 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 * Delete an existing private SQLiteDatabase associated with this Context's
1670 * application package.
1671 *
1672 * @param name The name (unique in the application package) of the
1673 * database.
1674 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001675 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001676 *
1677 * @see #openOrCreateDatabase
1678 */
1679 public abstract boolean deleteDatabase(String name);
1680
1681 /**
1682 * Returns the absolute path on the filesystem where a database created with
1683 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001684 * <p>
1685 * The returned path may change over time if the calling app is moved to an
1686 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 *
1688 * @param name The name of the database for which you would like to get
1689 * its path.
1690 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001691 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001692 *
1693 * @see #openOrCreateDatabase
1694 */
1695 public abstract File getDatabasePath(String name);
1696
1697 /**
1698 * Returns an array of strings naming the private databases associated with
1699 * this Context's application package.
1700 *
1701 * @return Array of strings naming the private databases.
1702 *
1703 * @see #openOrCreateDatabase
1704 * @see #deleteDatabase
1705 */
1706 public abstract String[] databaseList();
1707
1708 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001709 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001710 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001712 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 public abstract Drawable getWallpaper();
1714
1715 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001716 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001717 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001718 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001719 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 public abstract Drawable peekWallpaper();
1721
1722 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001723 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1724 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001725 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001726 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001727 public abstract int getWallpaperDesiredMinimumWidth();
1728
1729 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001730 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1731 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001732 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001733 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001734 public abstract int getWallpaperDesiredMinimumHeight();
1735
1736 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001737 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001738 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001739 * <p>This method requires the caller to hold the permission
1740 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001741 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001742 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001743 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1744
1745 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001746 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001747 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001748 * <p>This method requires the caller to hold the permission
1749 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001750 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001751 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001752 public abstract void setWallpaper(InputStream data) throws IOException;
1753
1754 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001755 * @deprecated Use {@link android.app.WallpaperManager#clear
1756 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001757 * <p>This method requires the caller to hold the permission
1758 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001759 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001760 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761 public abstract void clearWallpaper() throws IOException;
1762
1763 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001764 * Same as {@link #startActivity(Intent, Bundle)} with no options
1765 * specified.
1766 *
1767 * @param intent The description of the activity to start.
1768 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001769 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001770 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001771 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001772 * @see PackageManager#resolveActivity
1773 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001774 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001775
1776 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001777 * Version of {@link #startActivity(Intent)} that allows you to specify the
1778 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001779 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001780 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001781 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001782 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001783 * @hide
1784 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001785 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07001786 @SystemApi
Adrian Roosebc927c2019-02-28 16:21:18 +01001787 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1788 @NonNull UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001789 throw new RuntimeException("Not implemented. Must override in a subclass.");
1790 }
1791
1792 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 * Launch a new activity. You will not receive any information about when
1794 * the activity exits.
1795 *
1796 * <p>Note that if this method is being called from outside of an
1797 * {@link android.app.Activity} Context, then the Intent must include
1798 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1799 * without being started from an existing Activity, there is no existing
1800 * task in which to place the new activity and thus it needs to be placed
1801 * in its own separate task.
1802 *
1803 * <p>This method throws {@link ActivityNotFoundException}
1804 * if there was no Activity found to run the given Intent.
1805 *
1806 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001807 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001808 * May be null if there are no options. See {@link android.app.ActivityOptions}
1809 * for how to build the Bundle supplied here; there are no supported definitions
1810 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001812 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 *
Scott Main60dd5202012-06-23 00:01:22 -07001814 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 * @see PackageManager#resolveActivity
1816 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001817 public abstract void startActivity(@RequiresPermission Intent intent,
1818 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001819
1820 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001821 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1822 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001823 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001824 * @param intent The description of the activity to start.
1825 * @param options Additional options for how the Activity should be started.
1826 * May be null if there are no options. See {@link android.app.ActivityOptions}
1827 * for how to build the Bundle supplied here; there are no supported definitions
1828 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001829 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001830 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001831 * @hide
1832 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001833 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001834 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001835 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1836 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001837 throw new RuntimeException("Not implemented. Must override in a subclass.");
1838 }
1839
1840 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001841 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1842 * is only supported for Views and Fragments.
1843 * @param who The identifier for the calling element that will receive the result.
1844 * @param intent The intent to start.
1845 * @param requestCode The code that will be returned with onActivityResult() identifying this
1846 * request.
1847 * @param options Additional options for how the Activity should be started.
1848 * May be null if there are no options. See {@link android.app.ActivityOptions}
1849 * for how to build the Bundle supplied here; there are no supported definitions
1850 * for building it manually.
1851 * @hide
1852 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001853 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001854 public void startActivityForResult(
1855 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1856 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1857 + "Check canStartActivityForResult() before calling.");
1858 }
1859
1860 /**
1861 * Identifies whether this Context instance will be able to process calls to
1862 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1863 * @hide
1864 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001865 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001866 public boolean canStartActivityForResult() {
1867 return false;
1868 }
1869
1870 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001871 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1872 * specified.
1873 *
1874 * @param intents An array of Intents to be started.
1875 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001876 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001877 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001878 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001879 * @see PackageManager#resolveActivity
1880 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001881 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001882
1883 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001884 * Launch multiple new activities. This is generally the same as calling
1885 * {@link #startActivity(Intent)} for the first Intent in the array,
1886 * that activity during its creation calling {@link #startActivity(Intent)}
1887 * for the second entry, etc. Note that unlike that approach, generally
1888 * none of the activities except the last in the array will be created
1889 * at this point, but rather will be created when the user first visits
1890 * them (due to pressing back from the activity on top).
1891 *
1892 * <p>This method throws {@link ActivityNotFoundException}
1893 * if there was no Activity found for <em>any</em> given Intent. In this
1894 * case the state of the activity stack is undefined (some Intents in the
1895 * list may be on it, some not), so you probably want to avoid such situations.
1896 *
1897 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001898 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001899 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001900 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001901 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001902 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001903 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001904 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001905 * @see PackageManager#resolveActivity
1906 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001907 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001908
1909 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001910 * @hide
1911 * Launch multiple new activities. This is generally the same as calling
1912 * {@link #startActivity(Intent)} for the first Intent in the array,
1913 * that activity during its creation calling {@link #startActivity(Intent)}
1914 * for the second entry, etc. Note that unlike that approach, generally
1915 * none of the activities except the last in the array will be created
1916 * at this point, but rather will be created when the user first visits
1917 * them (due to pressing back from the activity on top).
1918 *
1919 * <p>This method throws {@link ActivityNotFoundException}
1920 * if there was no Activity found for <em>any</em> given Intent. In this
1921 * case the state of the activity stack is undefined (some Intents in the
1922 * list may be on it, some not), so you probably want to avoid such situations.
1923 *
1924 * @param intents An array of Intents to be started.
1925 * @param options Additional options for how the Activity should be started.
1926 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001927 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001928 * Context.startActivity(Intent, Bundle)} for more details.
1929 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001930 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1931 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1932 * successful.
1933 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001934 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001935 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001936 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001937 * @see PackageManager#resolveActivity
1938 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001939 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001940 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001941 throw new RuntimeException("Not implemented. Must override in a subclass.");
1942 }
1943
1944 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001945 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1946 * with no options specified.
1947 *
1948 * @param intent The IntentSender to launch.
1949 * @param fillInIntent If non-null, this will be provided as the
1950 * intent parameter to {@link IntentSender#sendIntent}.
1951 * @param flagsMask Intent flags in the original IntentSender that you
1952 * would like to change.
1953 * @param flagsValues Desired values for any bits set in
1954 * <var>flagsMask</var>
1955 * @param extraFlags Always set to 0.
1956 *
1957 * @see #startActivity(Intent)
1958 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1959 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001960 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1961 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1962 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001963
1964 /**
1965 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001966 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001967 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001968 * here; otherwise, its associated action will be executed (such as
1969 * sending a broadcast) as if you had called
1970 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001971 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001972 * @param intent The IntentSender to launch.
1973 * @param fillInIntent If non-null, this will be provided as the
1974 * intent parameter to {@link IntentSender#sendIntent}.
1975 * @param flagsMask Intent flags in the original IntentSender that you
1976 * would like to change.
1977 * @param flagsValues Desired values for any bits set in
1978 * <var>flagsMask</var>
1979 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001980 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001981 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001982 * Context.startActivity(Intent, Bundle)} for more details. If options
1983 * have also been supplied by the IntentSender, options given here will
1984 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001985 *
1986 * @see #startActivity(Intent, Bundle)
1987 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001988 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001989 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1990 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1991 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001992
1993 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 * Broadcast the given intent to all interested BroadcastReceivers. This
1995 * call is asynchronous; it returns immediately, and you will continue
1996 * executing while the receivers are run. No results are propagated from
1997 * receivers and receivers can not abort the broadcast. If you want
1998 * to allow receivers to propagate results or abort the broadcast, you must
1999 * send an ordered broadcast using
2000 * {@link #sendOrderedBroadcast(Intent, String)}.
2001 *
2002 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2003 *
2004 * @param intent The Intent to broadcast; all receivers matching this
2005 * Intent will receive the broadcast.
2006 *
2007 * @see android.content.BroadcastReceiver
2008 * @see #registerReceiver
2009 * @see #sendBroadcast(Intent, String)
2010 * @see #sendOrderedBroadcast(Intent, String)
2011 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2012 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002013 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014
2015 /**
2016 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2017 * an optional required permission to be enforced. This
2018 * call is asynchronous; it returns immediately, and you will continue
2019 * executing while the receivers are run. No results are propagated from
2020 * receivers and receivers can not abort the broadcast. If you want
2021 * to allow receivers to propagate results or abort the broadcast, you must
2022 * send an ordered broadcast using
2023 * {@link #sendOrderedBroadcast(Intent, String)}.
2024 *
2025 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2026 *
2027 * @param intent The Intent to broadcast; all receivers matching this
2028 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08002029 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 * a receiver must hold in order to receive your broadcast.
2031 * If null, no permission is required.
2032 *
2033 * @see android.content.BroadcastReceiver
2034 * @see #registerReceiver
2035 * @see #sendBroadcast(Intent)
2036 * @see #sendOrderedBroadcast(Intent, String)
2037 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2038 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002039 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002040 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002042
2043 /**
2044 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2045 * an array of required permissions to be enforced. This call is asynchronous; it returns
2046 * immediately, and you will continue executing while the receivers are run. No results are
2047 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2048 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2049 * using {@link #sendOrderedBroadcast(Intent, String)}.
2050 *
2051 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2052 *
2053 * @param intent The Intent to broadcast; all receivers matching this
2054 * Intent will receive the broadcast.
2055 * @param receiverPermissions Array of names of permissions that a receiver must hold
2056 * in order to receive your broadcast.
2057 * If null or empty, no permissions are required.
2058 *
2059 * @see android.content.BroadcastReceiver
2060 * @see #registerReceiver
2061 * @see #sendBroadcast(Intent)
2062 * @see #sendOrderedBroadcast(Intent, String)
2063 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2064 * @hide
2065 */
2066 public abstract void sendBroadcastMultiplePermissions(Intent intent,
2067 String[] receiverPermissions);
2068
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002069 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002070 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07002071 * an array of required permissions to be enforced. This call is asynchronous; it returns
2072 * immediately, and you will continue executing while the receivers are run. No results are
2073 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2074 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2075 * using {@link #sendOrderedBroadcast(Intent, String)}.
2076 *
2077 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2078 *
2079 * @param intent The Intent to broadcast; all receivers matching this
2080 * Intent will receive the broadcast.
2081 * @param user The user to send the broadcast to.
2082 * @param receiverPermissions Array of names of permissions that a receiver must hold
2083 * in order to receive your broadcast.
2084 * If null or empty, no permissions are required.
2085 *
2086 * @see android.content.BroadcastReceiver
2087 * @see #registerReceiver
2088 * @see #sendBroadcast(Intent)
2089 * @see #sendOrderedBroadcast(Intent, String)
2090 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2091 * @hide
2092 */
2093 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2094 String[] receiverPermissions);
2095
2096 /**
2097 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002098 * an optional required permission to be enforced. This
2099 * call is asynchronous; it returns immediately, and you will continue
2100 * executing while the receivers are run. No results are propagated from
2101 * receivers and receivers can not abort the broadcast. If you want
2102 * to allow receivers to propagate results or abort the broadcast, you must
2103 * send an ordered broadcast using
2104 * {@link #sendOrderedBroadcast(Intent, String)}.
2105 *
2106 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2107 *
2108 * @param intent The Intent to broadcast; all receivers matching this
2109 * Intent will receive the broadcast.
2110 * @param receiverPermission (optional) String naming a permission that
2111 * a receiver must hold in order to receive your broadcast.
2112 * If null, no permission is required.
2113 * @param options (optional) Additional sending options, generated from a
2114 * {@link android.app.BroadcastOptions}.
2115 *
2116 * @see android.content.BroadcastReceiver
2117 * @see #registerReceiver
2118 * @see #sendBroadcast(Intent)
2119 * @see #sendOrderedBroadcast(Intent, String)
2120 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2121 * @hide
2122 */
2123 @SystemApi
2124 public abstract void sendBroadcast(Intent intent,
2125 @Nullable String receiverPermission,
2126 @Nullable Bundle options);
2127
2128 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002129 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002130 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002131 * @hide
2132 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002133 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002134 public abstract void sendBroadcast(Intent intent,
2135 String receiverPermission, int appOp);
2136
2137 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002138 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2139 * them one at a time to allow more preferred receivers to consume the
2140 * broadcast before it is delivered to less preferred receivers. This
2141 * call is asynchronous; it returns immediately, and you will continue
2142 * executing while the receivers are run.
2143 *
2144 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2145 *
2146 * @param intent The Intent to broadcast; all receivers matching this
2147 * Intent will receive the broadcast.
2148 * @param receiverPermission (optional) String naming a permissions that
2149 * a receiver must hold in order to receive your broadcast.
2150 * If null, no permission is required.
2151 *
2152 * @see android.content.BroadcastReceiver
2153 * @see #registerReceiver
2154 * @see #sendBroadcast(Intent)
2155 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2156 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002157 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002158 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159
2160 /**
2161 * Version of {@link #sendBroadcast(Intent)} that allows you to
2162 * receive data back from the broadcast. This is accomplished by
2163 * supplying your own BroadcastReceiver when calling, which will be
2164 * treated as a final receiver at the end of the broadcast -- its
2165 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002166 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 * be serialized in the same way as calling
2168 * {@link #sendOrderedBroadcast(Intent, String)}.
2169 *
2170 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2171 * asynchronous; it will return before
2172 * resultReceiver.onReceive() is called.
2173 *
2174 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2175 *
2176 * @param intent The Intent to broadcast; all receivers matching this
2177 * Intent will receive the broadcast.
2178 * @param receiverPermission String naming a permissions that
2179 * a receiver must hold in order to receive your broadcast.
2180 * If null, no permission is required.
2181 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2182 * receiver of the broadcast.
2183 * @param scheduler A custom Handler with which to schedule the
2184 * resultReceiver callback; if null it will be
2185 * scheduled in the Context's main thread.
2186 * @param initialCode An initial value for the result code. Often
2187 * Activity.RESULT_OK.
2188 * @param initialData An initial value for the result data. Often
2189 * null.
2190 * @param initialExtras An initial value for the result extras. Often
2191 * null.
2192 *
2193 * @see #sendBroadcast(Intent)
2194 * @see #sendBroadcast(Intent, String)
2195 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002196 * @see android.content.BroadcastReceiver
2197 * @see #registerReceiver
2198 * @see android.app.Activity#RESULT_OK
2199 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002200 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002201 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002202 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2203 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002204
2205 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002206 * Version of {@link #sendBroadcast(Intent)} that allows you to
2207 * receive data back from the broadcast. This is accomplished by
2208 * supplying your own BroadcastReceiver when calling, which will be
2209 * treated as a final receiver at the end of the broadcast -- its
2210 * {@link BroadcastReceiver#onReceive} method will be called with
2211 * the result values collected from the other receivers. The broadcast will
2212 * be serialized in the same way as calling
2213 * {@link #sendOrderedBroadcast(Intent, String)}.
2214 *
2215 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2216 * asynchronous; it will return before
2217 * resultReceiver.onReceive() is called.
2218 *
2219 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2220 *
2221 *
2222 * @param intent The Intent to broadcast; all receivers matching this
2223 * Intent will receive the broadcast.
2224 * @param receiverPermission String naming a permissions that
2225 * a receiver must hold in order to receive your broadcast.
2226 * If null, no permission is required.
2227 * @param options (optional) Additional sending options, generated from a
2228 * {@link android.app.BroadcastOptions}.
2229 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2230 * receiver of the broadcast.
2231 * @param scheduler A custom Handler with which to schedule the
2232 * resultReceiver callback; if null it will be
2233 * scheduled in the Context's main thread.
2234 * @param initialCode An initial value for the result code. Often
2235 * Activity.RESULT_OK.
2236 * @param initialData An initial value for the result data. Often
2237 * null.
2238 * @param initialExtras An initial value for the result extras. Often
2239 * null.
2240 * @see #sendBroadcast(Intent)
2241 * @see #sendBroadcast(Intent, String)
2242 * @see #sendOrderedBroadcast(Intent, String)
2243 * @see android.content.BroadcastReceiver
2244 * @see #registerReceiver
2245 * @see android.app.Activity#RESULT_OK
2246 * @hide
2247 */
2248 @SystemApi
2249 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2250 @Nullable String receiverPermission, @Nullable Bundle options,
2251 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2252 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2253
2254 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002255 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2256 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002257 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002258 * @hide
2259 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002260 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002261 public abstract void sendOrderedBroadcast(Intent intent,
2262 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2263 Handler scheduler, int initialCode, String initialData,
2264 Bundle initialExtras);
2265
2266 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002267 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2268 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002269 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002270 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002271 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002272 * @see #sendBroadcast(Intent)
2273 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002274 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002275 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2276 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002277
2278 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002279 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2280 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002281 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002282 *
2283 * @param intent The Intent to broadcast; all receivers matching this
2284 * Intent will receive the broadcast.
2285 * @param user UserHandle to send the intent to.
2286 * @param receiverPermission (optional) String naming a permission that
2287 * a receiver must hold in order to receive your broadcast.
2288 * If null, no permission is required.
2289 *
2290 * @see #sendBroadcast(Intent, String)
2291 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002292 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002293 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2294 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002295
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002296 /**
2297 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2298 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002299 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002300 *
2301 * @param intent The Intent to broadcast; all receivers matching this
2302 * Intent will receive the broadcast.
2303 * @param user UserHandle to send the intent to.
2304 * @param receiverPermission (optional) String naming a permission that
2305 * a receiver must hold in order to receive your broadcast.
2306 * If null, no permission is required.
2307 * @param options (optional) Additional sending options, generated from a
2308 * {@link android.app.BroadcastOptions}.
2309 *
2310 * @see #sendBroadcast(Intent, String, Bundle)
2311 * @hide
2312 */
2313 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002314 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002315 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2316 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002317
2318 /**
2319 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2320 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002321 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002322 *
2323 * @param intent The Intent to broadcast; all receivers matching this
2324 * Intent will receive the broadcast.
2325 * @param user UserHandle to send the intent to.
2326 * @param receiverPermission (optional) String naming a permission that
2327 * a receiver must hold in order to receive your broadcast.
2328 * If null, no permission is required.
2329 * @param appOp The app op associated with the broadcast.
2330 *
2331 * @see #sendBroadcast(Intent, String)
2332 *
2333 * @hide
2334 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002335 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002336 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002337 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2338 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002339
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002340 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002341 * Version of
2342 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2343 * that allows you to specify the
2344 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002345 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002346 *
2347 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2348 *
2349 * @param intent The Intent to broadcast; all receivers matching this
2350 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002351 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002352 * @param receiverPermission String naming a permissions that
2353 * a receiver must hold in order to receive your broadcast.
2354 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002355 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2356 * receiver of the broadcast.
2357 * @param scheduler A custom Handler with which to schedule the
2358 * resultReceiver callback; if null it will be
2359 * scheduled in the Context's main thread.
2360 * @param initialCode An initial value for the result code. Often
2361 * Activity.RESULT_OK.
2362 * @param initialData An initial value for the result data. Often
2363 * null.
2364 * @param initialExtras An initial value for the result extras. Often
2365 * null.
2366 *
2367 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2368 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002369 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002370 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2371 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002372 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2373 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002374
2375 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002376 * Similar to above but takes an appOp as well, to enforce restrictions.
2377 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2378 * BroadcastReceiver, Handler, int, String, Bundle)
2379 * @hide
2380 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002381 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002382 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002383 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2384 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2385 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2386 @Nullable Bundle initialExtras);
2387
2388 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002389 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2390 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2391 * BroadcastReceiver, Handler, int, String, Bundle)
2392 * @hide
2393 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002394 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002395 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002396 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2397 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2398 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2399 @Nullable String initialData, @Nullable Bundle initialExtras);
2400
2401 /**
Jordan Liua32e6fc2019-10-29 10:33:55 -07002402 * Version of
2403 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2404 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2405 * the broadcast will be sent to.
2406 *
2407 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2408 *
2409 * @param intent The Intent to broadcast; all receivers matching this
2410 * Intent will receive the broadcast.
2411 * @param receiverPermission String naming a permissions that
2412 * a receiver must hold in order to receive your broadcast.
2413 * If null, no permission is required.
2414 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2415 * required. If both receiverAppOp and receiverPermission are non-null,
2416 * a receiver must have both of them to
2417 * receive the broadcast
2418 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2419 * receiver of the broadcast.
2420 * @param scheduler A custom Handler with which to schedule the
2421 * resultReceiver callback; if null it will be
2422 * scheduled in the Context's main thread.
2423 * @param initialCode An initial value for the result code. Often
2424 * Activity.RESULT_OK.
2425 * @param initialData An initial value for the result data. Often
2426 * null.
2427 * @param initialExtras An initial value for the result extras. Often
2428 * null.
2429 *
2430 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2431 */
Jordan Liu31a4da62019-11-19 11:36:34 -08002432 public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission,
2433 @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
2434 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2435 @Nullable Bundle initialExtras) {
Jordan Liua32e6fc2019-10-29 10:33:55 -07002436 throw new RuntimeException("Not implemented. Must override in a subclass.");
2437 }
2438
2439 /**
Peter Wangcf8bfcc2019-11-07 16:57:23 -08002440 * Version of
2441 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2442 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2443 * the broadcast will be sent to as well as supply an optional sending options
2444 *
2445 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2446 *
2447 * @param intent The Intent to broadcast; all receivers matching this
2448 * Intent will receive the broadcast.
2449 * @param receiverPermission String naming a permissions that
2450 * a receiver must hold in order to receive your broadcast.
2451 * If null, no permission is required.
2452 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2453 * required. If both receiverAppOp and receiverPermission are non-null,
2454 * a receiver must have both of them to
2455 * receive the broadcast
2456 * @param options (optional) Additional sending options, generated from a
2457 * {@link android.app.BroadcastOptions}.
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 #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2471 * @see android.app.BroadcastOptions
2472 */
2473 public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2474 @Nullable String receiverPermission, @Nullable String receiverAppOp,
2475 @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver,
2476 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2477 @Nullable Bundle initialExtras) {
2478 throw new RuntimeException("Not implemented. Must override in a subclass.");
2479 }
2480
2481 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002482 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 * Intent you are sending stays around after the broadcast is complete,
2484 * so that others can quickly retrieve that data through the return
2485 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2486 * all other ways, this behaves the same as
2487 * {@link #sendBroadcast(Intent)}.
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 to broadcast; all receivers matching this
2496 * Intent will receive the broadcast, and the Intent will be held to
2497 * be re-broadcast to future receivers.
2498 *
2499 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002500 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002502 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002503 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002504 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002505
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002506 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002507 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002508 * receive data back from the broadcast. This is accomplished by
2509 * supplying your own BroadcastReceiver when calling, which will be
2510 * treated as a final receiver at the end of the broadcast -- its
2511 * {@link BroadcastReceiver#onReceive} method will be called with
2512 * the result values collected from the other receivers. The broadcast will
2513 * be serialized in the same way as calling
2514 * {@link #sendOrderedBroadcast(Intent, String)}.
2515 *
2516 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2517 * asynchronous; it will return before
2518 * resultReceiver.onReceive() is called. Note that the sticky data
2519 * stored is only the data you initially supply to the broadcast, not
2520 * the result of any changes made by the receivers.
2521 *
2522 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2523 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002524 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2525 * can access them), no protection (anyone can modify them), and many other problems.
2526 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2527 * has changed, with another mechanism for apps to retrieve the current value whenever
2528 * desired.
2529 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002530 * @param intent The Intent to broadcast; all receivers matching this
2531 * Intent will receive the broadcast.
2532 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2533 * receiver of the broadcast.
2534 * @param scheduler A custom Handler with which to schedule the
2535 * resultReceiver callback; if null it will be
2536 * scheduled in the Context's main thread.
2537 * @param initialCode An initial value for the result code. Often
2538 * Activity.RESULT_OK.
2539 * @param initialData An initial value for the result data. Often
2540 * null.
2541 * @param initialExtras An initial value for the result extras. Often
2542 * null.
2543 *
2544 * @see #sendBroadcast(Intent)
2545 * @see #sendBroadcast(Intent, String)
2546 * @see #sendOrderedBroadcast(Intent, String)
2547 * @see #sendStickyBroadcast(Intent)
2548 * @see android.content.BroadcastReceiver
2549 * @see #registerReceiver
2550 * @see android.app.Activity#RESULT_OK
2551 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002552 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002553 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002554 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002555 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002556 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2557 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002558
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002560 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 * so that it is as if the sticky broadcast had never happened.
2562 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002563 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2564 * can access them), no protection (anyone can modify them), and many other problems.
2565 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2566 * has changed, with another mechanism for apps to retrieve the current value whenever
2567 * desired.
2568 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 * @param intent The Intent that was previously broadcast.
2570 *
2571 * @see #sendStickyBroadcast
2572 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002573 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002574 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002575 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002576
2577 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002578 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002579 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002580 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002581 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002582 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2583 * can access them), no protection (anyone can modify them), and many other problems.
2584 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2585 * has changed, with another mechanism for apps to retrieve the current value whenever
2586 * desired.
2587 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002588 * @param intent The Intent to broadcast; all receivers matching this
2589 * Intent will receive the broadcast, and the Intent will be held to
2590 * be re-broadcast to future receivers.
2591 * @param user UserHandle to send the intent to.
2592 *
2593 * @see #sendBroadcast(Intent)
2594 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002595 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002596 @RequiresPermission(allOf = {
2597 android.Manifest.permission.INTERACT_ACROSS_USERS,
2598 android.Manifest.permission.BROADCAST_STICKY
2599 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002600 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2601 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002602
2603 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002604 * @hide
2605 * This is just here for sending CONNECTIVITY_ACTION.
2606 */
2607 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002608 @RequiresPermission(allOf = {
2609 android.Manifest.permission.INTERACT_ACROSS_USERS,
2610 android.Manifest.permission.BROADCAST_STICKY
2611 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002612 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2613 UserHandle user, Bundle options);
2614
2615 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002616 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002617 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2618 * that allows you to specify the
2619 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002620 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002621 *
2622 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2623 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002624 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2625 * can access them), no protection (anyone can modify them), and many other problems.
2626 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2627 * has changed, with another mechanism for apps to retrieve the current value whenever
2628 * desired.
2629 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002630 * @param intent The Intent to broadcast; all receivers matching this
2631 * Intent will receive the broadcast.
2632 * @param user UserHandle to send the intent to.
2633 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2634 * receiver of the broadcast.
2635 * @param scheduler A custom Handler with which to schedule the
2636 * resultReceiver callback; if null it will be
2637 * scheduled in the Context's main thread.
2638 * @param initialCode An initial value for the result code. Often
2639 * Activity.RESULT_OK.
2640 * @param initialData An initial value for the result data. Often
2641 * null.
2642 * @param initialExtras An initial value for the result extras. Often
2643 * null.
2644 *
2645 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2646 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002647 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002648 @RequiresPermission(allOf = {
2649 android.Manifest.permission.INTERACT_ACROSS_USERS,
2650 android.Manifest.permission.BROADCAST_STICKY
2651 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002652 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002653 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002654 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2655 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002656
2657 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002658 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002659 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002660 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002661 *
2662 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2663 * permission in order to use this API. If you do not hold that
2664 * permission, {@link SecurityException} will be thrown.
2665 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002666 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2667 * can access them), no protection (anyone can modify them), and many other problems.
2668 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2669 * has changed, with another mechanism for apps to retrieve the current value whenever
2670 * desired.
2671 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002672 * @param intent The Intent that was previously broadcast.
2673 * @param user UserHandle to remove the sticky broadcast from.
2674 *
2675 * @see #sendStickyBroadcastAsUser
2676 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002677 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002678 @RequiresPermission(allOf = {
2679 android.Manifest.permission.INTERACT_ACROSS_USERS,
2680 android.Manifest.permission.BROADCAST_STICKY
2681 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002682 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2683 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002684
2685 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002686 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 * <var>receiver</var> will be called with any broadcast Intent that
2688 * matches <var>filter</var>, in the main application thread.
2689 *
2690 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002691 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 * registrations. If your IntentFilter matches one of these sticky
2693 * Intents, that Intent will be returned by this function
2694 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2695 * been broadcast.
2696 *
2697 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2698 * in which case each of these will be sent to <var>receiver</var>. In
2699 * this case, only one of these can be returned directly by the function;
2700 * which of these that is returned is arbitrarily decided by the system.
2701 *
2702 * <p>If you know the Intent your are registering for is sticky, you can
2703 * supply null for your <var>receiver</var>. In this case, no receiver is
2704 * registered -- the function simply returns the sticky Intent that
2705 * matches <var>filter</var>. In the case of multiple matches, the same
2706 * rules as described above apply.
2707 *
2708 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2709 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002710 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2711 * registered with this method will correctly respect the
2712 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2713 * Prior to that, it would be ignored and delivered to all matching registered
2714 * receivers. Be careful if using this for security.</p>
2715 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002716 * <p class="note">Note: this method <em>cannot be called from a
2717 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2718 * that is declared in an application's manifest. It is okay, however, to call
2719 * this method from another BroadcastReceiver that has itself been registered
2720 * at run time with {@link #registerReceiver}, since the lifetime of such a
2721 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 *
2723 * @param receiver The BroadcastReceiver to handle the broadcast.
2724 * @param filter Selects the Intent broadcasts to be received.
2725 *
2726 * @return The first sticky intent found that matches <var>filter</var>,
2727 * or null if there are none.
2728 *
2729 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2730 * @see #sendBroadcast
2731 * @see #unregisterReceiver
2732 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002733 @Nullable
2734 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002735 IntentFilter filter);
2736
2737 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002738 * Register to receive intent broadcasts, with the receiver optionally being
2739 * exposed to Instant Apps. See
2740 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2741 * information. By default Instant Apps cannot interact with receivers in other
2742 * applications, this allows you to expose a receiver that Instant Apps can
2743 * interact with.
2744 *
2745 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2746 *
2747 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2748 * registered with this method will correctly respect the
2749 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2750 * Prior to that, it would be ignored and delivered to all matching registered
2751 * receivers. Be careful if using this for security.</p>
2752 *
2753 * @param receiver The BroadcastReceiver to handle the broadcast.
2754 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002755 * @param flags Additional options for the receiver. May be 0 or
2756 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002757 *
2758 * @return The first sticky intent found that matches <var>filter</var>,
2759 * or null if there are none.
2760 *
2761 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2762 * @see #sendBroadcast
2763 * @see #unregisterReceiver
2764 */
2765 @Nullable
2766 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2767 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002768 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002769
2770 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002771 * Register to receive intent broadcasts, to run in the context of
2772 * <var>scheduler</var>. See
2773 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2774 * information. This allows you to enforce permissions on who can
2775 * broadcast intents to your receiver, or have the receiver run in
2776 * a different thread than the main application thread.
2777 *
2778 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2779 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002780 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2781 * registered with this method will correctly respect the
2782 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2783 * Prior to that, it would be ignored and delivered to all matching registered
2784 * receivers. Be careful if using this for security.</p>
2785 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 * @param receiver The BroadcastReceiver to handle the broadcast.
2787 * @param filter Selects the Intent broadcasts to be received.
2788 * @param broadcastPermission String naming a permissions that a
2789 * broadcaster must hold in order to send an Intent to you. If null,
2790 * no permission is required.
2791 * @param scheduler Handler identifying the thread that will receive
2792 * the Intent. If null, the main thread of the process will be used.
2793 *
2794 * @return The first sticky intent found that matches <var>filter</var>,
2795 * or null if there are none.
2796 *
2797 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2798 * @see #sendBroadcast
2799 * @see #unregisterReceiver
2800 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002801 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002802 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002803 IntentFilter filter, @Nullable String broadcastPermission,
2804 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002805
2806 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002807 * Register to receive intent broadcasts, to run in the context of
2808 * <var>scheduler</var>. See
2809 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002810 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2811 * for more information.
2812 *
2813 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2814 *
2815 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2816 * registered with this method will correctly respect the
2817 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2818 * Prior to that, it would be ignored and delivered to all matching registered
2819 * receivers. Be careful if using this for security.</p>
2820 *
2821 * @param receiver The BroadcastReceiver to handle the broadcast.
2822 * @param filter Selects the Intent broadcasts to be received.
2823 * @param broadcastPermission String naming a permissions that a
2824 * broadcaster must hold in order to send an Intent to you. If null,
2825 * no permission is required.
2826 * @param scheduler Handler identifying the thread that will receive
2827 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002828 * @param flags Additional options for the receiver. May be 0 or
2829 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002830 *
2831 * @return The first sticky intent found that matches <var>filter</var>,
2832 * or null if there are none.
2833 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002834 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002835 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2836 * @see #sendBroadcast
2837 * @see #unregisterReceiver
2838 */
2839 @Nullable
2840 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2841 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002842 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002843
2844 /**
Meng Wange3bd3ba2019-11-05 10:43:45 -08002845 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2846 * but this receiver will receive broadcasts that are sent to all users. The receiver can
2847 * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
2848 * was sent.
2849 *
2850 * @param receiver The BroadcastReceiver to handle the broadcast.
2851 * @param filter Selects the Intent broadcasts to be received.
2852 * @param broadcastPermission String naming a permissions that a
2853 * broadcaster must hold in order to send an Intent to you. If {@code null},
2854 * no permission is required.
2855 * @param scheduler Handler identifying the thread that will receive
2856 * the Intent. If {@code null}, the main thread of the process will be used.
2857 *
2858 * @return The first sticky intent found that matches <var>filter</var>,
2859 * or {@code null} if there are none.
2860 *
2861 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2862 * @see #sendBroadcast
2863 * @see #unregisterReceiver
2864 * @hide
2865 */
2866 @Nullable
2867 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
2868 @SystemApi
2869 public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
2870 @NonNull IntentFilter filter, @Nullable String broadcastPermission,
2871 @Nullable Handler scheduler) {
2872 throw new RuntimeException("Not implemented. Must override in a subclass.");
2873 }
2874
2875 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002876 * @hide
2877 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2878 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002879 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002880 *
2881 * @param receiver The BroadcastReceiver to handle the broadcast.
2882 * @param user UserHandle to send the intent to.
2883 * @param filter Selects the Intent broadcasts to be received.
2884 * @param broadcastPermission String naming a permissions that a
2885 * broadcaster must hold in order to send an Intent to you. If null,
2886 * no permission is required.
2887 * @param scheduler Handler identifying the thread that will receive
2888 * the Intent. If null, the main thread of the process will be used.
2889 *
2890 * @return The first sticky intent found that matches <var>filter</var>,
2891 * or null if there are none.
2892 *
Jeff Brown6e539312015-02-24 18:53:21 -08002893 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002894 * @see #sendBroadcast
2895 * @see #unregisterReceiver
2896 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002897 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002898 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002899 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002900 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002901 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2902 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002903
2904 /**
2905 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2906 * filters that have been registered for this BroadcastReceiver will be
2907 * removed.
2908 *
2909 * @param receiver The BroadcastReceiver to unregister.
2910 *
2911 * @see #registerReceiver
2912 */
2913 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2914
2915 /**
2916 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002917 * should either contain the complete class name of a specific service
2918 * implementation to start, or a specific package name to target. If the
2919 * Intent is less specified, it logs a warning about this. In this case any of the
2920 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 * is not already running, it will be instantiated and started (creating a
2922 * process for it if needed); if it is running then it remains running.
2923 *
2924 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002925 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 * with the <var>intent</var> given here. This provides a convenient way
2927 * to submit jobs to a service without having to bind and call on to its
2928 * interface.
2929 *
2930 * <p>Using startService() overrides the default service lifetime that is
2931 * managed by {@link #bindService}: it requires the service to remain
2932 * running until {@link #stopService} is called, regardless of whether
2933 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002934 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002935 * a single call to {@link #stopService} will stop it.
2936 *
2937 * <p>The system attempts to keep running services around as much as
2938 * possible. The only time they should be stopped is if the current
2939 * foreground application is using so many resources that the service needs
2940 * to be killed. If any errors happen in the service's process, it will
2941 * automatically be restarted.
2942 *
2943 * <p>This function will throw {@link SecurityException} if you do not
2944 * have permission to start the given service.
2945 *
Chris Craik1e353522016-04-18 10:20:50 -07002946 * <p class="note"><strong>Note:</strong> Each call to startService()
2947 * results in significant work done by the system to manage service
2948 * lifecycle surrounding the processing of the intent, which can take
2949 * multiple milliseconds of CPU time. Due to this cost, startService()
2950 * should not be used for frequent intent delivery to a service, and only
2951 * for scheduling significant work. Use {@link #bindService bound services}
2952 * for high frequency calls.
2953 * </p>
2954 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002955 * @param service Identifies the service to be started. The Intent must be
2956 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002957 * may be included in the Intent extras to supply arguments along with
2958 * this specific start call.
2959 *
2960 * @return If the service is being started or is already running, the
2961 * {@link ComponentName} of the actual service that was started is
2962 * returned; else if the service does not exist null is returned.
2963 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002964 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002965 * or the service can not be found.
2966 * @throws IllegalStateException If the application is in a state where the service
2967 * 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 -08002968 *
2969 * @see #stopService
2970 * @see #bindService
2971 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002972 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 public abstract ComponentName startService(Intent service);
2974
2975 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002976 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002977 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2978 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002979 * an amount of time comparable to the ANR interval to do this, otherwise the system
2980 * will automatically stop the service and declare the app ANR.
2981 *
2982 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2983 * at any time, regardless of whether the app hosting the service is in a foreground
2984 * state.
2985 *
2986 * @param service Identifies the service to be started. The Intent must be
2987 * fully explicit (supplying a component name). Additional values
2988 * may be included in the Intent extras to supply arguments along with
2989 * this specific start call.
2990 *
2991 * @return If the service is being started or is already running, the
2992 * {@link ComponentName} of the actual service that was started is
2993 * returned; else if the service does not exist null is returned.
2994 *
2995 * @throws SecurityException If the caller does not have permission to access the service
2996 * or the service can not be found.
2997 *
2998 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002999 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07003000 */
3001 @Nullable
3002 public abstract ComponentName startForegroundService(Intent service);
3003
3004 /**
3005 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
3006 */
3007 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003008 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07003009 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
3010
3011 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003012 * Request that a given application service be stopped. If the service is
3013 * not running, nothing happens. Otherwise it is stopped. Note that calls
3014 * to startService() are not counted -- this stops the service no matter
3015 * how many times it was started.
3016 *
3017 * <p>Note that if a stopped service still has {@link ServiceConnection}
3018 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
3019 * not be destroyed until all of these bindings are removed. See
3020 * the {@link android.app.Service} documentation for more details on a
3021 * service's lifecycle.
3022 *
3023 * <p>This function will throw {@link SecurityException} if you do not
3024 * have permission to stop the given service.
3025 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07003026 * @param service Description of the service to be stopped. The Intent must be either
3027 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07003028 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003029 *
3030 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04003031 * 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 -08003032 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003033 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003034 * or the service can not be found.
3035 * @throws IllegalStateException If the application is in a state where the service
3036 * 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 -08003037 *
3038 * @see #startService
3039 */
3040 public abstract boolean stopService(Intent service);
3041
3042 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003043 * @hide like {@link #startService(Intent)} but for a specific user.
3044 */
Christopher Tate42a386b2016-11-07 12:21:21 -08003045 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003046 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003047 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003048 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
3049
3050 /**
3051 * @hide like {@link #stopService(Intent)} but for a specific user.
3052 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003053 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003054 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08003055
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003056 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003057 * Connect to an application service, creating it if needed. This defines
3058 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003059 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003060 * told if it dies and restarts. The service will be considered required
3061 * by the system only for as long as the calling context exists. For
3062 * example, if this Context is an Activity that is stopped, the service will
3063 * not be required to continue running until the Activity is resumed.
3064 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003065 * <p>If the service does not support binding, it may return {@code null} from
3066 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
3067 * the ServiceConnection's
3068 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
3069 * will be invoked instead of
3070 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
3071 *
3072 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 * have permission to bind to the given service.
3074 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003075 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003077 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 * {@link #startService} with the arguments containing the command to be
3079 * sent, with the service calling its
3080 * {@link android.app.Service#stopSelf(int)} method when done executing
3081 * that command. See the API demo App/Service/Service Start Arguments
3082 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003083 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
3085 * is tied to another object (the one that registered it).</p>
3086 *
Mark Lu94ebbe02016-12-13 16:29:51 -08003087 * @param service Identifies the service to connect to. The Intent must
3088 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07003090 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07003091 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07003092 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
3093 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003094 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
3095 * {@link #BIND_IMPORTANT}, or
3096 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07003097 * @return {@code true} if the system is in the process of bringing up a
3098 * service that your client has permission to bind to; {@code false}
3099 * if the system couldn't find the service or if your client doesn't
3100 * have permission to bind to it. If this value is {@code true}, you
3101 * should later call {@link #unbindService} to release the
3102 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003104 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003105 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003106 *
3107 * @see #unbindService
3108 * @see #startService
3109 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07003110 * @see #BIND_DEBUG_UNBIND
3111 * @see #BIND_NOT_FOREGROUND
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003112 * @see #BIND_ABOVE_CLIENT
3113 * @see #BIND_ALLOW_OOM_MANAGEMENT
3114 * @see #BIND_WAIVE_PRIORITY
3115 * @see #BIND_IMPORTANT
3116 * @see #BIND_ADJUST_WITH_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003117 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07003118 public abstract boolean bindService(@RequiresPermission Intent service,
3119 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120
3121 /**
Bo Liu58a57662019-03-06 20:21:45 +00003122 * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control
3123 * ServiceConnection callbacks.
3124 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
3125 * instance for the same instance of ServiceConnection.
3126 */
3127 public boolean bindService(@RequiresPermission @NonNull Intent service,
3128 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
3129 @NonNull ServiceConnection conn) {
3130 throw new RuntimeException("Not implemented. Must override in a subclass.");
3131 }
3132
3133 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003134 * Variation of {@link #bindService} that, in the specific case of isolated
3135 * services, allows the caller to generate multiple instances of a service
Dianne Hackborncc67f962019-04-29 16:32:44 -07003136 * from a single component declaration. In other words, you can use this to bind
3137 * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
3138 * addition to the existing behavior of running in an isolated process, you can
3139 * also through the arguments here have the system bring up multiple concurrent
3140 * processes hosting their own instances of that service. The <var>instanceName</var>
3141 * you provide here identifies the different instances, and you can use
3142 * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
3143 * should manage each of these instances.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003144 *
3145 * @param service Identifies the service to connect to. The Intent must
3146 * specify an explicit component name.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003147 * @param flags Operation options for the binding as per {@link #bindService}.
3148 * @param instanceName Unique identifier for the service instance. Each unique
Robert Seseke3a5bc62019-04-22 17:43:03 -04003149 * name here will result in a different service instance being created. Identifiers
3150 * must only contain ASCII letters, digits, underscores, and periods.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003151 * @return Returns success of binding as per {@link #bindService}.
Bo Liu58a57662019-03-06 20:21:45 +00003152 * @param executor Callbacks on ServiceConnection will be called on executor.
3153 * Must use same instance for the same instance of ServiceConnection.
3154 * @param conn Receives information as the service is started and stopped.
3155 * This must be a valid ServiceConnection object; it must not be null.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003156 *
3157 * @throws SecurityException If the caller does not have permission to access the service
Robert Seseke3a5bc62019-04-22 17:43:03 -04003158 * @throws IllegalArgumentException If the instanceName is invalid.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003159 *
3160 * @see #bindService
Dianne Hackborncc67f962019-04-29 16:32:44 -07003161 * @see #updateServiceGroup
3162 * @see android.R.attr#isolatedProcess
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003163 */
Adrian Roosebc927c2019-02-28 16:21:18 +01003164 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
Bo Liu58a57662019-03-06 20:21:45 +00003165 @BindServiceFlags int flags, @NonNull String instanceName,
3166 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003167 throw new RuntimeException("Not implemented. Must override in a subclass.");
3168 }
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003169
3170 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003171 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003172 * argument for use by system server and other multi-user aware code.
3173 * @hide
3174 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07003175 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08003176 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003177 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07003178 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08003179 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003180 throw new RuntimeException("Not implemented. Must override in a subclass.");
3181 }
3182
3183 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003184 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
Adrian Roos691546e2016-02-09 10:13:41 -08003185 * explicit non-null Handler to run the ServiceConnection callbacks on.
3186 *
3187 * @hide
3188 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003189 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood7bcc1742019-07-04 11:39:42 +01003190 @UnsupportedAppUsage(trackingBug = 136728678)
Adrian Roos691546e2016-02-09 10:13:41 -08003191 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3192 Handler handler, UserHandle user) {
3193 throw new RuntimeException("Not implemented. Must override in a subclass.");
3194 }
3195
3196 /**
Dianne Hackborna631d562018-11-20 15:58:15 -08003197 * For a service previously bound with {@link #bindService} or a related method, change
3198 * how the system manages that service's process in relation to other processes. This
3199 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3200 * how the process will be managed in some cases based on those flags. Currently only
3201 * works on isolated processes (will be ignored for non-isolated processes).
3202 *
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -08003203 * <p>Note that this call does not take immediate effect, but will be applied the next
3204 * time the impacted process is adjusted for some other reason. Typically you would
3205 * call this before then calling a new {@link #bindIsolatedService} on the service
3206 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3207 *
Dianne Hackborna631d562018-11-20 15:58:15 -08003208 * @param conn The connection interface previously supplied to bindService(). This
3209 * parameter must not be null.
3210 * @param group A group to put this connection's process in. Upon calling here, this
3211 * will override any previous group that was set for that process. The group
3212 * tells the system about processes that are logically grouped together, so
3213 * should be managed as one unit of importance (such as when being considered
3214 * a recently used app). All processes in the same app with the same group
3215 * are considered to be related. Supplying 0 reverts to the default behavior
3216 * of not grouping.
3217 * @param importance Additional importance of the processes within a group. Upon calling
Dianne Hackborncc67f962019-04-29 16:32:44 -07003218 * here, this will override any previous importance that was set for that
3219 * process. The most important process is 0, and higher values are
3220 * successively less important. You can view this as describing how
3221 * to order the processes in an array, with the processes at the end of
3222 * the array being the least important. This value has no meaning besides
3223 * indicating how processes should be ordered in that array one after the
3224 * other. This provides a way to fine-tune the system's process killing,
3225 * guiding it to kill processes at the end of the array first.
3226 *
3227 * @see #bindIsolatedService
Dianne Hackborna631d562018-11-20 15:58:15 -08003228 */
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003229 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3230 int importance) {
3231 throw new RuntimeException("Not implemented. Must override in a subclass.");
3232 }
Dianne Hackborna631d562018-11-20 15:58:15 -08003233
3234 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003235 * Disconnect from an application service. You will no longer receive
3236 * calls as the service is restarted, and the service is now allowed to
3237 * stop at any time.
3238 *
3239 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07003240 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003241 *
3242 * @see #bindService
3243 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003244 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003245
3246 /**
3247 * Start executing an {@link android.app.Instrumentation} class. The given
3248 * Instrumentation component will be run by killing its target application
3249 * (if currently running), starting the target process, instantiating the
3250 * instrumentation component, and then letting it drive the application.
3251 *
3252 * <p>This function is not synchronous -- it returns as soon as the
3253 * instrumentation has started and while it is running.
3254 *
3255 * <p>Instrumentation is normally only allowed to run against a package
3256 * that is either unsigned or signed with a signature that the
3257 * the instrumentation package is also signed with (ensuring the target
3258 * trusts the instrumentation).
3259 *
3260 * @param className Name of the Instrumentation component to be run.
3261 * @param profileFile Optional path to write profiling data as the
3262 * instrumentation runs, or null for no profiling.
3263 * @param arguments Additional optional arguments to pass to the
3264 * instrumentation, or null.
3265 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003266 * @return {@code true} if the instrumentation was successfully started,
3267 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003268 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003269 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3270 @Nullable String profileFile, @Nullable Bundle arguments);
3271
3272 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07003273 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07003274 POWER_SERVICE,
3275 WINDOW_SERVICE,
3276 LAYOUT_INFLATER_SERVICE,
3277 ACCOUNT_SERVICE,
3278 ACTIVITY_SERVICE,
3279 ALARM_SERVICE,
3280 NOTIFICATION_SERVICE,
3281 ACCESSIBILITY_SERVICE,
3282 CAPTIONING_SERVICE,
3283 KEYGUARD_SERVICE,
3284 LOCATION_SERVICE,
3285 //@hide: COUNTRY_DETECTOR,
3286 SEARCH_SERVICE,
3287 SENSOR_SERVICE,
Chad Brubaker90f391f2018-10-19 10:26:19 -07003288 SENSOR_PRIVACY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003289 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003290 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003291 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003292 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003293 VIBRATOR_SERVICE,
3294 //@hide: STATUS_BAR_SERVICE,
3295 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003296 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003297 IPSEC_SERVICE,
Benedict Wong99a48412018-11-09 14:45:34 -08003298 TEST_NETWORK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003299 //@hide: UPDATE_LOCK_SERVICE,
3300 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003301 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003302 //@hide: NETWORK_POLICY_SERVICE,
3303 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003304 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003305 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003306 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003307 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003308 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003309 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003310 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003311 NSD_SERVICE,
3312 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003313 FINGERPRINT_SERVICE,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003314 //@hide: FACE_SERVICE,
Kevin Chyn05c21502018-09-18 13:07:19 -07003315 BIOMETRIC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003316 MEDIA_ROUTER_SERVICE,
3317 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003318 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003319 CARRIER_CONFIG_SERVICE,
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003320 EUICC_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003321 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003322 CLIPBOARD_SERVICE,
3323 INPUT_METHOD_SERVICE,
3324 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003325 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003326 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003327 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003328 //@hide: BACKUP_SERVICE,
Richard Uhlerb29f1452018-09-12 16:38:15 +01003329 ROLLBACK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003330 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003331 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003332 DEVICE_POLICY_SERVICE,
3333 UI_MODE_SERVICE,
3334 DOWNLOAD_SERVICE,
3335 NFC_SERVICE,
3336 BLUETOOTH_SERVICE,
3337 //@hide: SIP_SERVICE,
3338 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003339 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003340 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003341 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003342 INPUT_SERVICE,
3343 DISPLAY_SERVICE,
Christine Franks39b03112018-07-03 14:46:07 -07003344 //@hide COLOR_DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003345 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003346 RESTRICTIONS_SERVICE,
3347 APP_OPS_SERVICE,
Hai Zhangb7776682018-09-25 15:10:57 -07003348 ROLE_SERVICE,
Hai Zhanga4959e52019-03-06 12:21:07 -08003349 //@hide ROLE_CONTROLLER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003350 CAMERA_SERVICE,
atrost8266ae32019-08-15 16:53:01 +01003351 //@hide: PLATFORM_COMPAT_SERVICE,
atrostff948d82019-10-10 19:27:31 +01003352 //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003353 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003354 CONSUMER_IR_SERVICE,
3355 //@hide: TRUST_SERVICE,
3356 TV_INPUT_SERVICE,
3357 //@hide: NETWORK_SCORE_SERVICE,
3358 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003359 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003360 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003361 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003362 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003363 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003364 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003365 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003366 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003367 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003368 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003369 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003370 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003371 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003372 //@hide: INCIDENT_SERVICE,
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08003373 //@hide: INCIDENT_COMPANION_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003374 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003375 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003376 CROSS_PROFILE_APPS_SERVICE,
3377 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerfeeee682018-05-30 14:35:24 +01003378 //@hide: TIME_DETECTOR_SERVICE,
Neil Fuller3352cfc2019-11-07 15:35:05 +00003379 //@hide: TIME_ZONE_DETECTOR_SERVICE,
Philip P. Moltmann039678e2018-09-18 13:04:38 -07003380 PERMISSION_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003381 })
3382 @Retention(RetentionPolicy.SOURCE)
3383 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384
3385 /**
3386 * Return the handle to a system-level service by name. The class of the
3387 * returned object varies by the requested name. Currently available names
3388 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003389 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003390 * <dl>
3391 * <dt> {@link #WINDOW_SERVICE} ("window")
3392 * <dd> The top-level window manager in which you can place custom
3393 * windows. The returned object is a {@link android.view.WindowManager}.
3394 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3395 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3396 * in this context.
3397 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3398 * <dd> A {@link android.app.ActivityManager} for interacting with the
3399 * global activity state of the system.
3400 * <dt> {@link #POWER_SERVICE} ("power")
3401 * <dd> A {@link android.os.PowerManager} for controlling power
3402 * management.
3403 * <dt> {@link #ALARM_SERVICE} ("alarm")
3404 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3405 * time of your choosing.
3406 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3407 * <dd> A {@link android.app.NotificationManager} for informing the user
3408 * of background events.
3409 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3410 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3411 * <dt> {@link #LOCATION_SERVICE} ("location")
3412 * <dd> A {@link android.location.LocationManager} for controlling location
3413 * (e.g., GPS) updates.
3414 * <dt> {@link #SEARCH_SERVICE} ("search")
3415 * <dd> A {@link android.app.SearchManager} for handling search.
3416 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3417 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3418 * hardware.
3419 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3420 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3421 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003422 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3423 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3424 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003426 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3427 * connectivity. On releases before NYC, it should only be obtained from an application
3428 * context, and not from any other derived context to avoid memory leaks within the calling
3429 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003430 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3431 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3432 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003433 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3434 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3435 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3437 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3438 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003439 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3440 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003441 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003442 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003443 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003444 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003445 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3446 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003447 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3448 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3449 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003450 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003451 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003452 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003453 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003454 * <p>Note: System services obtained via this API may be closely associated with
3455 * the Context in which they are obtained from. In general, do not share the
3456 * service objects between various different contexts (Activities, Applications,
3457 * Services, Providers, etc.)
3458 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003459 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3460 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003461 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3462 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3463 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3464 * return <code>null</code>. Generally, if you are running as an instant app you should always
Felipe Leme4685b862019-03-06 10:32:33 -08003465 * check whether the result of this method is {@code null}.
3466 *
3467 * <p>Note: When implementing this method, keep in mind that new services can be added on newer
3468 * Android releases, so if you're looking for just the explicit names mentioned above, make sure
3469 * to return {@code null} when you don't recognize the name &mdash; if you throw a
3470 * {@link RuntimeException} exception instead, you're app might break on new Android releases.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003471 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003472 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003473 *
Felipe Leme4685b862019-03-06 10:32:33 -08003474 * @return The service or {@code null} if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003475 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 * @see #WINDOW_SERVICE
3477 * @see android.view.WindowManager
3478 * @see #LAYOUT_INFLATER_SERVICE
3479 * @see android.view.LayoutInflater
3480 * @see #ACTIVITY_SERVICE
3481 * @see android.app.ActivityManager
3482 * @see #POWER_SERVICE
3483 * @see android.os.PowerManager
3484 * @see #ALARM_SERVICE
3485 * @see android.app.AlarmManager
3486 * @see #NOTIFICATION_SERVICE
3487 * @see android.app.NotificationManager
3488 * @see #KEYGUARD_SERVICE
3489 * @see android.app.KeyguardManager
3490 * @see #LOCATION_SERVICE
3491 * @see android.location.LocationManager
3492 * @see #SEARCH_SERVICE
3493 * @see android.app.SearchManager
3494 * @see #SENSOR_SERVICE
3495 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003496 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003497 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 * @see #VIBRATOR_SERVICE
3499 * @see android.os.Vibrator
3500 * @see #CONNECTIVITY_SERVICE
3501 * @see android.net.ConnectivityManager
3502 * @see #WIFI_SERVICE
3503 * @see android.net.wifi.WifiManager
3504 * @see #AUDIO_SERVICE
3505 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003506 * @see #MEDIA_ROUTER_SERVICE
3507 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003508 * @see #TELEPHONY_SERVICE
3509 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003510 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3511 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003512 * @see #CARRIER_CONFIG_SERVICE
3513 * @see android.telephony.CarrierConfigManager
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003514 * @see #EUICC_SERVICE
3515 * @see android.telephony.euicc.EuiccManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003516 * @see #INPUT_METHOD_SERVICE
3517 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003518 * @see #UI_MODE_SERVICE
3519 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003520 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003521 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003522 * @see #BATTERY_SERVICE
3523 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003524 * @see #JOB_SCHEDULER_SERVICE
3525 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003526 * @see #NETWORK_STATS_SERVICE
3527 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003528 * @see android.os.HardwarePropertiesManager
3529 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003530 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003531 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003532
3533 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003534 * Return the handle to a system-level service by class.
3535 * <p>
3536 * Currently available classes are:
3537 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3538 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3539 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3540 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3541 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3542 * {@link android.net.ConnectivityManager},
3543 * {@link android.net.wifi.WifiManager},
3544 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3545 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3546 * {@link android.view.inputmethod.InputMethodManager},
3547 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003548 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3549 * {@link android.app.usage.NetworkStatsManager}.
Felipe Leme4685b862019-03-06 10:32:33 -08003550 * </p>
3551 *
3552 * <p>
Jeff Brown6e539312015-02-24 18:53:21 -08003553 * Note: System services obtained via this API may be closely associated with
3554 * the Context in which they are obtained from. In general, do not share the
3555 * service objects between various different contexts (Activities, Applications,
3556 * Services, Providers, etc.)
3557 * </p>
3558 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003559 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3560 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003561 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3562 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3563 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
Felipe Leme4685b862019-03-06 10:32:33 -08003564 * return {@code null}. Generally, if you are running as an instant app you should always
3565 * check whether the result of this method is {@code null}.
3566 * </p>
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003567 *
Jeff Brown6e539312015-02-24 18:53:21 -08003568 * @param serviceClass The class of the desired service.
Felipe Leme4685b862019-03-06 10:32:33 -08003569 * @return The service or {@code null} if the class is not a supported system service. Note:
3570 * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
Jeff Brown6e539312015-02-24 18:53:21 -08003571 */
3572 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003573 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003574 // Because subclasses may override getSystemService(String) we cannot
3575 // perform a lookup by class alone. We must first map the class to its
3576 // service name then invoke the string-based method.
3577 String serviceName = getSystemServiceName(serviceClass);
3578 return serviceName != null ? (T)getSystemService(serviceName) : null;
3579 }
3580
3581 /**
3582 * Gets the name of the system-level service that is represented by the specified class.
3583 *
3584 * @param serviceClass The class of the desired service.
3585 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003586 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003587 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003588
3589 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003590 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 * {@link android.os.PowerManager} for controlling power management,
3592 * including "wake locks," which let you keep the device on while
3593 * you're running long tasks.
3594 */
3595 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003596
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003597 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003598 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003599 * {@link android.os.RecoverySystem} for accessing the recovery system
3600 * service.
3601 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003602 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003603 * @hide
3604 */
3605 public static final String RECOVERY_SERVICE = "recovery";
3606
3607 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003608 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003609 * {@link android.os.SystemUpdateManager} for accessing the system update
3610 * manager service.
3611 *
3612 * @see #getSystemService(String)
3613 * @hide
3614 */
3615 @SystemApi
3616 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3617
3618 /**
3619 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003620 * {@link android.view.WindowManager} for accessing the system's window
3621 * manager.
3622 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003623 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 * @see android.view.WindowManager
3625 */
3626 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003627
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003629 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 * {@link android.view.LayoutInflater} for inflating layout resources in this
3631 * context.
3632 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003633 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 * @see android.view.LayoutInflater
3635 */
3636 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003637
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003638 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003639 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003640 * {@link android.accounts.AccountManager} for receiving intents at a
3641 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003642 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003643 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003644 * @see android.accounts.AccountManager
3645 */
3646 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003647
Fred Quintana60307342009-03-24 22:48:12 -07003648 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003649 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003650 * {@link android.app.ActivityManager} for interacting with the global
3651 * system state.
3652 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003653 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003654 * @see android.app.ActivityManager
3655 */
3656 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003657
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003658 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003659 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale65ebd952018-04-25 15:41:44 -07003660 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
3661 *
3662 * @see #getSystemService(String)
3663 * @see android.app.ActivityTaskManager
3664 * @hide
3665 */
3666 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
3667
3668 /**
3669 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07003670 * {@link android.app.UriGrantsManager} for interacting with the global system state.
3671 *
3672 * @see #getSystemService(String)
3673 * @see android.app.UriGrantsManager
3674 * @hide
3675 */
3676 public static final String URI_GRANTS_SERVICE = "uri_grants";
3677
3678 /**
3679 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003680 * {@link android.app.AlarmManager} for receiving intents at a
3681 * time of your choosing.
3682 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003683 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 * @see android.app.AlarmManager
3685 */
3686 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003689 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 * {@link android.app.NotificationManager} for informing the user of
3691 * background events.
3692 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003693 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003694 * @see android.app.NotificationManager
3695 */
3696 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003697
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003698 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003699 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003700 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3701 * feedback for UI events through the registered event listeners.
3702 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003703 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003704 * @see android.view.accessibility.AccessibilityManager
3705 */
3706 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003707
svetoslavganov75986cf2009-05-14 22:28:01 -07003708 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003709 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003710 * {@link android.view.accessibility.CaptioningManager} for obtaining
3711 * captioning properties and listening for changes in captioning
3712 * preferences.
3713 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003714 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003715 * @see android.view.accessibility.CaptioningManager
3716 */
3717 public static final String CAPTIONING_SERVICE = "captioning";
3718
3719 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003720 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003721 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003723 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 * @see android.app.KeyguardManager
3725 */
3726 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003729 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003730 * android.location.LocationManager} for controlling location
3731 * updates.
3732 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003733 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 * @see android.location.LocationManager
3735 */
3736 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003737
3738 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003739 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003740 * {@link android.location.CountryDetector} for detecting the country that
3741 * the user is in.
3742 *
3743 * @hide
3744 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01003745 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003746 public static final String COUNTRY_DETECTOR = "country_detector";
3747
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003749 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003750 * android.app.SearchManager} for handling searches.
3751 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003752 * <p>
3753 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3754 * {@link android.app.SearchManager}.
3755 *
3756 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 * @see android.app.SearchManager
3758 */
3759 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003760
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003761 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003762 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003763 * android.hardware.SensorManager} for accessing sensors.
3764 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003765 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 * @see android.hardware.SensorManager
3767 */
3768 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003770 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003771 * Use with {@link #getSystemService(String)} to retrieve a {@link
Chad Brubaker90f391f2018-10-19 10:26:19 -07003772 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
3773 * functions.
3774 *
3775 * @see #getSystemService(String)
3776 * @see android.hardware.SensorPrivacyManager
3777 *
3778 * @hide
3779 */
3780 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
3781
3782 /**
3783 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003784 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003785 * functions.
3786 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003787 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003788 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003789 */
3790 public static final String STORAGE_SERVICE = "storage";
3791
3792 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003793 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003794 * android.app.usage.StorageStatsManager} for accessing system storage
3795 * statistics.
3796 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003797 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003798 * @see android.app.usage.StorageStatsManager
3799 */
3800 public static final String STORAGE_STATS_SERVICE = "storagestats";
3801
3802 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003803 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 * com.android.server.WallpaperService for accessing wallpapers.
3805 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003806 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 */
3808 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003809
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003810 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003811 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003812 * android.os.Vibrator} for interacting with the vibration hardware.
3813 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003814 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 * @see android.os.Vibrator
3816 */
3817 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003818
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003819 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003820 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003821 * android.app.StatusBarManager} for interacting with the status bar.
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.app.StatusBarManager
Evan Lairdedd016f2019-01-23 18:36:29 -05003825 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003826 * @hide
3827 */
Evan Lairdedd016f2019-01-23 18:36:29 -05003828 @SystemApi
Evan Laird418ba8f2019-04-17 15:55:21 -04003829 @TestApi
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003830 public static final String STATUS_BAR_SERVICE = "statusbar";
3831
3832 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003833 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003834 * android.net.ConnectivityManager} for handling management of
3835 * network connections.
3836 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003837 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003838 * @see android.net.ConnectivityManager
3839 */
3840 public static final String CONNECTIVITY_SERVICE = "connectivity";
3841
3842 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003843 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003844 * {@link android.net.INetd} for communicating with the network stack
3845 * @hide
3846 * @see #getSystemService(String)
3847 * @hide
3848 */
3849 @SystemApi
3850 public static final String NETD_SERVICE = "netd";
3851
3852 /**
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003853 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
Remi NGUYEN VANfe1ce1e2020-01-07 11:44:14 +09003854 * {@link INetworkStackConnector} IBinder for communicating with the network stack
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003855 * @hide
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003856 * @see NetworkStackClient
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003857 */
Remi NGUYEN VANfe1ce1e2020-01-07 11:44:14 +09003858 @SystemApi
3859 @TestApi
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003860 public static final String NETWORK_STACK_SERVICE = "network_stack";
3861
3862 /**
markchien6d06f6d2019-12-16 20:15:20 +08003863 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3864 * {@link ITetheringConnector} IBinder for communicating with the tethering service
3865 * @hide
3866 * @see TetheringClient
3867 */
3868 @SystemApi
3869 public static final String TETHERING_SERVICE = "tethering";
3870
3871 /**
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003872 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003873 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3874 * IPSec.
3875 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003876 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003877 */
3878 public static final String IPSEC_SERVICE = "ipsec";
3879
3880 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003881 * Use with {@link #getSystemService(String)} to retrieve a {@link
Benedict Wong99a48412018-11-09 14:45:34 -08003882 * android.net.TestNetworkManager} for building TUNs and limited-use Networks
3883 *
3884 * @see #getSystemService(String)
3885 * @hide
3886 */
3887 @TestApi public static final String TEST_NETWORK_SERVICE = "test_network";
3888
3889 /**
3890 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003891 * android.os.IUpdateLock} for managing runtime sequences that
3892 * must not be interrupted by headless OTA application or similar.
3893 *
3894 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003895 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003896 * @see android.os.UpdateLock
3897 */
3898 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3899
3900 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003901 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003902 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003903 */
3904 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3905
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003906 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003907 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003908 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3909 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003910 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003911 */
3912 public static final String SLICE_SERVICE = "slice";
3913
3914 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003915 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003916 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3917 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003918 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003919 * @see android.app.usage.NetworkStatsManager
3920 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003921 public static final String NETWORK_STATS_SERVICE = "netstats";
3922 /** {@hide} */
Aaron Huang1aa5ca32019-12-31 21:48:45 +08003923 @SystemApi
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003924 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003925 /** {@hide} */
3926 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003927
San Mehatd1df8ac2010-01-26 06:17:26 -08003928 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003929 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003930 * android.net.wifi.WifiManager} for handling management of
3931 * Wi-Fi access.
3932 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003933 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003934 * @see android.net.wifi.WifiManager
3935 */
3936 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003937
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003939 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003940 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003941 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003942 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003943 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003944 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003945 */
3946 public static final String WIFI_P2P_SERVICE = "wifip2p";
3947
3948 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003949 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003950 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3951 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003952 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003953 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003954 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003955 */
Etan Cohen04133272016-10-26 11:22:06 -07003956 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003957
3958 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003959 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003960 * android.net.wifi.WifiScanner} for scanning the wifi universe
3961 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003962 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003963 * @see android.net.wifi.WifiScanner
3964 * @hide
3965 */
Wei Wang35d552f2014-07-08 21:37:01 -07003966 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003967 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3968
3969 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003970 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003971 * android.net.wifi.RttManager} for ranging devices with wifi
3972 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003973 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003974 * @see android.net.wifi.RttManager
3975 * @hide
3976 */
3977 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08003978 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07003979 public static final String WIFI_RTT_SERVICE = "rttmanager";
3980
3981 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003982 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohenf4062a92019-04-11 07:00:42 -07003983 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
Etan Cohen17ba4722017-08-21 10:52:17 -07003984 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003985 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003986 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003987 */
Etan Cohen091d7772018-01-04 17:47:37 -08003988 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003989
3990 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003991 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003992 * android.net.lowpan.LowpanManager} for handling management of
3993 * LoWPAN access.
3994 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003995 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003996 * @see android.net.lowpan.LowpanManager
3997 *
3998 * @hide
3999 */
4000 public static final String LOWPAN_SERVICE = "lowpan";
4001
4002 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004003 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004004 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004005 * Ethernet access.
4006 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004007 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004008 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004009 *
4010 * @hide
4011 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01004012 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004013 public static final String ETHERNET_SERVICE = "ethernet";
4014
4015 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004016 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07004017 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004018 * discovery
4019 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004020 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07004021 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004022 */
4023 public static final String NSD_SERVICE = "servicediscovery";
4024
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004025 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004026 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004027 * {@link android.media.AudioManager} for handling management of volume,
4028 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07004029 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004030 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004031 * @see android.media.AudioManager
4032 */
4033 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07004034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004035 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004036 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07004037 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07004038 * of fingerprints.
4039 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004040 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07004041 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07004042 */
4043 public static final String FINGERPRINT_SERVICE = "fingerprint";
4044
4045 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004046 * Use with {@link #getSystemService(String)} to retrieve a
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004047 * {@link android.hardware.face.FaceManager} for handling management
4048 * of face authentication.
4049 *
4050 * @hide
4051 * @see #getSystemService
4052 * @see android.hardware.face.FaceManager
4053 */
4054 public static final String FACE_SERVICE = "face";
4055
4056 /**
Kevin Chyn05c21502018-09-18 13:07:19 -07004057 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn51676d22018-11-05 18:00:43 -08004058 * {@link android.hardware.iris.IrisManager} for handling management
4059 * of iris authentication.
4060 *
4061 * @hide
4062 * @see #getSystemService
4063 * @see android.hardware.iris.IrisManager
4064 */
4065 public static final String IRIS_SERVICE = "iris";
4066
4067 /**
4068 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn05c21502018-09-18 13:07:19 -07004069 * {@link android.hardware.biometrics.BiometricManager} for handling management
4070 * of face authentication.
4071 *
4072 * @see #getSystemService
4073 * @see android.hardware.biometrics.BiometricManager
4074 */
4075 public static final String BIOMETRIC_SERVICE = "biometric";
4076
4077 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004078 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004079 * {@link android.media.MediaRouter} for controlling and managing
4080 * routing of media.
4081 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004082 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004083 * @see android.media.MediaRouter
4084 */
4085 public static final String MEDIA_ROUTER_SERVICE = "media_router";
4086
4087 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004088 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07004089 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08004090 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004091 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07004092 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08004093 */
4094 public static final String MEDIA_SESSION_SERVICE = "media_session";
4095
4096 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004097 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004098 * {@link android.telephony.TelephonyManager} for handling management the
4099 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07004100 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004101 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004102 * @see android.telephony.TelephonyManager
4103 */
4104 public static final String TELEPHONY_SERVICE = "phone";
4105
4106 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004107 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08004108 * {@link android.telephony.SubscriptionManager} for handling management the
4109 * telephony subscriptions of the device.
4110 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004111 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08004112 * @see android.telephony.SubscriptionManager
4113 */
4114 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
4115
4116 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004117 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004118 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07004119 * of the device.
4120 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004121 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004122 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07004123 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004124 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07004125
4126 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004127 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004128 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
4129 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004130 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004131 * @see android.telephony.CarrierConfigManager
4132 */
4133 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
4134
4135 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004136 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08004137 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
4138 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004139 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08004140 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08004141 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004142 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08004143
4144 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004145 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004146 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
4147 *
4148 * @see #getSystemService(String)
4149 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004150 * @hide
4151 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004152 @SystemApi
4153 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004154
4155 /**
4156 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08004157 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004158 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07004159 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004160 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004161 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004162 */
4163 public static final String CLIPBOARD_SERVICE = "clipboard";
4164
4165 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004166 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004167 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004168 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004169 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004170 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004171 */
4172 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
4173
4174 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004175 * Use with {@link #getSystemService(String)} to retrieve a
Alex Salo5f5b5f42019-02-27 10:49:00 -08004176 * {@link com.android.server.attention.AttentionManagerService} for attention services.
4177 *
4178 * @see #getSystemService(String)
4179 * @see android.server.attention.AttentionManagerService
4180 * @hide
4181 */
4182 public static final String ATTENTION_SERVICE = "attention";
4183
4184 /**
4185 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004186 * {@link android.view.inputmethod.InputMethodManager} for accessing input
4187 * methods.
4188 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004189 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004190 */
4191 public static final String INPUT_METHOD_SERVICE = "input_method";
4192
4193 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004194 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09004195 * {@link android.view.textservice.TextServicesManager} for accessing
4196 * text services.
4197 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004198 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09004199 */
4200 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
4201
4202 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004203 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08004204 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004205 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004206 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004207 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004208 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07004209
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004210 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07004211 * Official published name of the (internal) voice interaction manager service.
4212 *
4213 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004214 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07004215 */
4216 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4217
4218 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08004219 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07004220 *
4221 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004222 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07004223 */
Felipe Leme640f30a2017-03-06 15:44:06 -08004224 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07004225
4226 /**
Felipe Leme749b8892018-12-03 16:30:30 -08004227 * Official published name of the content capture service.
Felipe Lemee348dc32018-11-05 12:35:29 -08004228 *
4229 * @hide
4230 * @see #getSystemService(String)
4231 */
Felipe Lemea7e4ca62019-05-23 13:32:40 -07004232 @TestApi
Felipe Leme749b8892018-12-03 16:30:30 -08004233 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
Felipe Lemee348dc32018-11-05 12:35:29 -08004234
4235 /**
Winson Chung3fb0f252019-01-08 17:41:55 -08004236 * Used for getting content selections and classifications for task snapshots.
4237 *
4238 * @hide
4239 * @see #getSystemService(String)
4240 */
4241 @SystemApi
4242 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
4243
4244 /**
Sunny Goyal54e91342018-11-14 11:59:02 -08004245 * Official published name of the app prediction service.
4246 *
Felipe Leme87c58552019-08-14 18:14:55 -07004247 * <p><b>NOTE: </b> this service is optional; callers of
4248 * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}.
4249 *
Sunny Goyal54e91342018-11-14 11:59:02 -08004250 * @hide
4251 * @see #getSystemService(String)
4252 */
4253 @SystemApi
4254 public static final String APP_PREDICTION_SERVICE = "app_prediction";
4255
4256 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004257 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004258 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
4259 *
4260 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004261 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004262 */
4263 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
4264
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004265 /**
4266 * Official published name of the (internal) permission service.
4267 *
4268 * @see #getSystemService(String)
4269 * @hide
4270 */
Winsonf27394e2019-06-07 14:44:40 -07004271 @TestApi
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004272 @SystemApi
4273 public static final String PERMISSION_SERVICE = "permission";
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004274
4275 /**
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08004276 * Official published name of the (internal) permission controller service.
4277 *
4278 * @see #getSystemService(String)
4279 * @hide
4280 */
4281 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
4282
4283 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004284 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08004285 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07004286 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07004287 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07004288 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004289 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07004290 */
Christopher Tated5cf7222014-07-29 16:53:09 -07004291 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07004292 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07004293
4294 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +01004295 * Use with {@link #getSystemService(String)} to retrieve an
4296 * {@link android.content.rollback.RollbackManager} for communicating
4297 * with the rollback manager
4298 *
4299 * @see #getSystemService(String)
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004300 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +01004301 */
Richard Uhler8a977452019-03-08 13:27:17 +00004302 @SystemApi @TestApi
Richard Uhlerb29f1452018-09-12 16:38:15 +01004303 public static final String ROLLBACK_SERVICE = "rollback";
4304
4305 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004306 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08004307 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07004308 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004309 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07004310 */
4311 public static final String DROPBOX_SERVICE = "dropbox";
4312
Christopher Tate487529a2009-04-29 14:03:25 -07004313 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07004314 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004315 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004316 * @hide
4317 */
4318 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
4319
4320 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004321 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08004322 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08004323 * device policy management.
4324 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004325 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08004326 */
4327 public static final String DEVICE_POLICY_SERVICE = "device_policy";
4328
4329 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004330 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08004331 * {@link android.app.UiModeManager} for controlling UI modes.
4332 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004333 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08004334 */
4335 public static final String UI_MODE_SERVICE = "uimode";
4336
4337 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004338 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07004339 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07004340 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004341 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07004342 */
4343 public static final String DOWNLOAD_SERVICE = "download";
4344
4345 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004346 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08004347 * {@link android.os.BatteryManager} for managing battery state.
4348 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004349 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08004350 */
4351 public static final String BATTERY_SERVICE = "batterymanager";
4352
4353 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004354 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004355 * {@link android.nfc.NfcManager} for using NFC.
4356 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004357 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004358 */
4359 public static final String NFC_SERVICE = "nfc";
4360
4361 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004362 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00004363 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004364 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004365 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004366 */
4367 public static final String BLUETOOTH_SERVICE = "bluetooth";
4368
4369 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004370 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08004371 * {@link android.net.sip.SipManager} for accessing the SIP related service.
4372 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004373 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08004374 */
4375 /** @hide */
4376 public static final String SIP_SERVICE = "sip";
4377
4378 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004379 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08004380 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004381 * and for controlling this device's behavior as a USB device.
4382 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004383 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04004384 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004385 */
4386 public static final String USB_SERVICE = "usb";
4387
4388 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004389 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Rootf74bfde2018-01-18 15:42:48 -08004390 * Use with {@link #getSystemService} to retrieve a {@link
4391 * android.debug.AdbManager} for access to ADB debug functions.
4392 *
4393 * @see #getSystemService(String)
4394 * @see android.debug.AdbManager
4395 *
4396 * @hide
4397 */
4398 public static final String ADB_SERVICE = "adb";
4399
4400 /**
4401 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004402 * android.hardware.SerialManager} for access to serial ports.
4403 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004404 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004405 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004406 *
4407 * @hide
4408 */
4409 public static final String SERIAL_SERVICE = "serial";
4410
4411 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004412 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09004413 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
4414 * HDMI-CEC protocol.
4415 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004416 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09004417 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004418 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09004419 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004420 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09004421 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09004422
4423 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004424 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004425 * {@link android.hardware.input.InputManager} for interacting with input devices.
4426 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004427 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004428 * @see android.hardware.input.InputManager
4429 */
4430 public static final String INPUT_SERVICE = "input";
4431
4432 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004433 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07004434 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
4435 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004436 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07004437 * @see android.hardware.display.DisplayManager
4438 */
4439 public static final String DISPLAY_SERVICE = "display";
4440
4441 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004442 * Use with {@link #getSystemService(String)} to retrieve a
Christine Franks39b03112018-07-03 14:46:07 -07004443 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
4444 *
4445 * @see #getSystemService(String)
4446 * @see android.hardware.display.ColorDisplayManager
4447 * @hide
4448 */
4449 public static final String COLOR_DISPLAY_SERVICE = "color_display";
4450
4451 /**
4452 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07004453 * {@link android.os.UserManager} for managing users on devices that support multiple users.
4454 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004455 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07004456 * @see android.os.UserManager
4457 */
4458 public static final String USER_SERVICE = "user";
4459
4460 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004461 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08004462 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
4463 * profiles of a user.
4464 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004465 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08004466 * @see android.content.pm.LauncherApps
4467 */
4468 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4469
4470 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004471 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004472 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4473 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004474 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004475 * @see android.content.RestrictionsManager
4476 */
4477 public static final String RESTRICTIONS_SERVICE = "restrictions";
4478
4479 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004480 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004481 * {@link android.app.AppOpsManager} for tracking application operations
4482 * on the device.
4483 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004484 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004485 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004486 */
4487 public static final String APP_OPS_SERVICE = "appops";
4488
4489 /**
Hai Zhangb7776682018-09-25 15:10:57 -07004490 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
4491 * for managing roles.
4492 *
4493 * @see #getSystemService(String)
4494 * @see android.app.role.RoleManager
4495 */
4496 public static final String ROLE_SERVICE = "role";
4497
4498 /**
Hai Zhanga4959e52019-03-06 12:21:07 -08004499 * Official published name of the (internal) role controller service.
4500 *
4501 * @see #getSystemService(String)
4502 * @see android.app.role.RoleControllerService
4503 *
4504 * @hide
4505 */
4506 public static final String ROLE_CONTROLLER_SERVICE = "role_controller";
4507
4508 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004509 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004510 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004511 * camera devices.
4512 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004513 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004514 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004515 */
4516 public static final String CAMERA_SERVICE = "camera";
4517
4518 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004519 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004520 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004521 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004522 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004523 * @see android.print.PrintManager
4524 */
4525 public static final String PRINT_SERVICE = "print";
4526
4527 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004528 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004529 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4530 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004531 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004532 * @see android.companion.CompanionDeviceManager
4533 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004534 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004535
4536 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004537 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004538 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4539 * signals from the device.
4540 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004541 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004542 * @see android.hardware.ConsumerIrManager
4543 */
4544 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4545
4546 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004547 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004548 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004549 * @see android.app.trust.TrustManager
4550 * @hide
4551 */
4552 public static final String TRUST_SERVICE = "trust";
4553
4554 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004555 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004556 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4557 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004558 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004559 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004560 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004561 */
4562 public static final String TV_INPUT_SERVICE = "tv_input";
4563
4564 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004565 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004566 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004567 * @see android.net.NetworkScoreManager
4568 * @hide
4569 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004570 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004571 public static final String NETWORK_SCORE_SERVICE = "network_score";
4572
4573 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004574 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004575 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004576 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004577 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004578 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004579 */
4580 public static final String USAGE_STATS_SERVICE = "usagestats";
4581
4582 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004583 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004584 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004585 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004586 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004587 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004588 */
Christopher Tate7060b042014-06-09 19:50:00 -07004589 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004590
4591 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004592 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004593 * android.service.persistentdata.PersistentDataBlockManager} instance
4594 * for interacting with a storage device that lives across factory resets.
4595 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004596 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004597 * @see android.service.persistentdata.PersistentDataBlockManager
4598 * @hide
4599 */
Andres Morales33df9372014-09-26 17:08:59 -07004600 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004601 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4602
4603 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004604 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004605 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4606 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004607 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004608 * @see android.service.oemlock.OemLockManager
4609 * @hide
4610 */
4611 @SystemApi
4612 public static final String OEM_LOCK_SERVICE = "oem_lock";
4613
4614 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004615 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004616 * android.media.projection.MediaProjectionManager} instance for managing
4617 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004618 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004619 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004620 */
4621 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4622
4623 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004624 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004625 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004626 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004627 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004628 */
4629 public static final String MIDI_SERVICE = "midi";
4630
Eric Laurent2035ac82015-03-05 15:18:44 -08004631
4632 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004633 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004634 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4635 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004636 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004637 * @hide
4638 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004639 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004640
Paul McLeana33be212015-02-20 07:52:45 -08004641 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004642 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004643 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4644 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004645 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004646 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004647 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004648
4649 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004650 * Use with {@link #getSystemService(String)} to retrieve a
Wei Wangbad7c202018-11-01 11:57:39 -07004651 * {@link android.os.ThermalService} for accessing the thermal service.
4652 *
4653 * @see #getSystemService(String)
4654 * @hide
4655 */
4656 public static final String THERMAL_SERVICE = "thermalservice";
4657
4658 /**
4659 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004660 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004661 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004662 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004663 * @see android.content.pm.ShortcutManager
4664 */
4665 public static final String SHORTCUT_SERVICE = "shortcut";
4666
4667 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004668 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004669 * android.hardware.location.ContextHubManager} for accessing context hubs.
4670 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004671 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004672 * @see android.hardware.location.ContextHubManager
4673 *
4674 * @hide
4675 */
4676 @SystemApi
4677 public static final String CONTEXTHUB_SERVICE = "contexthub";
4678
4679 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004680 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004681 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4682 * memory, etc) metrics.
4683 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004684 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004685 */
4686 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4687
4688 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004689 * Gatekeeper Service.
4690 * @hide
4691 */
4692 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4693
4694 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004695 * Service defining the policy for access to device identifiers.
4696 * @hide
4697 */
4698 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4699
4700 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004701 * Service to report a system health "incident"
4702 * @hide
4703 */
4704 public static final String INCIDENT_SERVICE = "incident";
4705
4706 /**
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08004707 * Service to assist incidentd and dumpstated in reporting status to the user
4708 * and in confirming authorization to take an incident report or bugreport
4709 * @hide
4710 */
4711 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
4712
4713 /**
Bookatz94726412017-08-31 09:26:15 -07004714 * Service to assist statsd in obtaining general stats.
4715 * @hide
4716 */
4717 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4718
4719 /**
Bookatzc6977972018-01-16 16:55:05 -08004720 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004721 * @hide
4722 */
4723 @SystemApi
4724 public static final String STATS_MANAGER = "stats";
4725
4726 /**
atrost8266ae32019-08-15 16:53:01 +01004727 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4728 * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
4729 * @hide
4730 */
4731 public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
4732
4733 /**
atrostff948d82019-10-10 19:27:31 +01004734 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4735 * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
4736 * service.
4737 * @hide
4738 */
4739 public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
4740
4741 /**
Nandana Duttd11850c2018-12-12 17:26:57 +00004742 * Service to capture a bugreport.
4743 * @see #getSystemService(String)
4744 * @see android.os.BugreportManager
4745 * @hide
4746 */
Nandana Duttd7e8d5a2019-04-11 17:27:45 +01004747 @SystemApi @TestApi
Nandana Duttd11850c2018-12-12 17:26:57 +00004748 public static final String BUGREPORT_SERVICE = "bugreport";
4749
4750 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004751 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004752 * android.content.om.OverlayManager} for managing overlay packages.
4753 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004754 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004755 * @see android.content.om.OverlayManager
4756 * @hide
4757 */
4758 public static final String OVERLAY_SERVICE = "overlay";
4759
4760 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004761 * Use with {@link #getSystemService(String)} to retrieve a
MÃ¥rten Kongstad06a1ac82018-09-20 13:09:47 +02004762 * {android.os.IIdmap2} for managing idmap files (used by overlay
4763 * packages).
4764 *
4765 * @see #getSystemService(String)
4766 * @hide
4767 */
4768 public static final String IDMAP_SERVICE = "idmap";
4769
4770 /**
4771 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004772 * {@link VrManager} for accessing the VR service.
4773 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004774 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004775 * @hide
4776 */
4777 @SystemApi
4778 public static final String VR_SERVICE = "vrmanager";
4779
4780 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004781 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004782 * {@link android.app.timezone.ITimeZoneRulesManager}.
4783 * @hide
4784 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004785 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004786 */
4787 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4788
4789 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004790 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004791 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004792 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004793 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004794 */
4795 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4796
4797 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004798 * Use with {@link #getSystemService} to retrieve a
4799 * {@link android.se.omapi.ISecureElementService}
4800 * for accessing the SecureElementService.
4801 *
4802 * @hide
4803 */
4804 @SystemApi
4805 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4806
4807 /**
Neil Fullerfeeee682018-05-30 14:35:24 +01004808 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fuller3352cfc2019-11-07 15:35:05 +00004809 * {@link android.app.timedetector.TimeDetector}.
Neil Fullerfeeee682018-05-30 14:35:24 +01004810 * @hide
4811 *
4812 * @see #getSystemService(String)
4813 */
4814 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4815
4816 /**
Neil Fuller3352cfc2019-11-07 15:35:05 +00004817 * Use with {@link #getSystemService(String)} to retrieve an
4818 * {@link android.app.timezonedetector.TimeZoneDetector}.
4819 * @hide
4820 *
4821 * @see #getSystemService(String)
4822 */
4823 public static final String TIME_ZONE_DETECTOR_SERVICE = "time_zone_detector";
4824
4825 /**
Makoto Onukidf7e4812018-09-24 14:31:25 -07004826 * Binder service name for {@link AppBindingService}.
4827 * @hide
4828 */
4829 public static final String APP_BINDING_SERVICE = "app_binding";
4830
4831 /**
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004832 * Use with {@link #getSystemService(String)} to retrieve an
James.cf Lin2bc9cd42019-11-04 20:23:36 +08004833 * {@link android.telephony.ims.ImsManager}.
4834 * @hide
4835 */
James.cf Lin304a66a2019-12-10 20:02:43 +08004836 @SystemApi
4837 @TestApi
James.cf Lin2bc9cd42019-11-04 20:23:36 +08004838 public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
4839
4840 /**
4841 * Use with {@link #getSystemService(String)} to retrieve an
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004842 * {@link android.telephony.ims.RcsMessageManager}.
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004843 * @hide
4844 */
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004845 public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004846
Howard Chen0a947642019-01-07 14:10:44 +08004847 /**
4848 * Use with {@link #getSystemService(String)} to retrieve an
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004849 * {@link android.os.image.DynamicSystemManager}.
Howard Chen0a947642019-01-07 14:10:44 +08004850 * @hide
4851 */
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004852 public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
Howard Chen0a947642019-01-07 14:10:44 +08004853
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004854 /**
Chen Xu1f1c25e2019-09-15 18:28:21 -07004855 * Use with {@link #getSystemService(String)} to retrieve an
Chen Xu8eb62f92019-10-13 17:30:32 -07004856 * {@link TelephonyRegistryManager}.
Chen Xu1f1c25e2019-09-15 18:28:21 -07004857 * @hide
4858 */
4859 @SystemApi
4860 public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
4861
4862 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004863 * Determine whether the given permission is allowed for a particular
4864 * process and user ID running in the system.
4865 *
4866 * @param permission The name of the permission being checked.
4867 * @param pid The process ID being checked against. Must be > 0.
4868 * @param uid The user ID being checked against. A uid of 0 is the root
4869 * user, which will pass every permission check.
4870 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004871 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004872 * pid/uid is allowed that permission, or
4873 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4874 *
4875 * @see PackageManager#checkPermission(String, String)
4876 * @see #checkCallingPermission
4877 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004878 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004879 @PackageManager.PermissionResult
4880 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004881
Dianne Hackbornff170242014-11-19 10:59:01 -08004882 /** @hide */
4883 @PackageManager.PermissionResult
Mathew Inwood5c0d3542018-08-14 13:54:31 +01004884 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08004885 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4886 IBinder callerToken);
4887
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004888 /**
4889 * Determine whether the calling process of an IPC you are handling has been
4890 * granted a particular permission. This is basically the same as calling
4891 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4892 * by {@link android.os.Binder#getCallingPid} and
4893 * {@link android.os.Binder#getCallingUid}. One important difference
4894 * is that if you are not currently processing an IPC, this function
4895 * will always fail. This is done to protect against accidentally
4896 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4897 * to avoid this protection.
4898 *
4899 * @param permission The name of the permission being checked.
4900 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004901 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004902 * pid/uid is allowed that permission, or
4903 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4904 *
4905 * @see PackageManager#checkPermission(String, String)
4906 * @see #checkPermission
4907 * @see #checkCallingOrSelfPermission
4908 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004909 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004910 @PackageManager.PermissionResult
4911 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004912
4913 /**
4914 * Determine whether the calling process of an IPC <em>or you</em> have been
4915 * granted a particular permission. This is the same as
4916 * {@link #checkCallingPermission}, except it grants your own permissions
4917 * if you are not currently processing an IPC. Use with care!
4918 *
4919 * @param permission The name of the permission being checked.
4920 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004921 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004922 * pid/uid is allowed that permission, or
4923 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4924 *
4925 * @see PackageManager#checkPermission(String, String)
4926 * @see #checkPermission
4927 * @see #checkCallingPermission
4928 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004929 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004930 @PackageManager.PermissionResult
4931 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004932
4933 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004934 * Determine whether <em>you</em> have been granted a particular permission.
4935 *
4936 * @param permission The name of the permission being checked.
4937 *
4938 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4939 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4940 *
4941 * @see PackageManager#checkPermission(String, String)
4942 * @see #checkCallingPermission(String)
4943 */
4944 @PackageManager.PermissionResult
4945 public abstract int checkSelfPermission(@NonNull String permission);
4946
4947 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004948 * If the given permission is not allowed for a particular process
4949 * and user ID running in the system, throw a {@link SecurityException}.
4950 *
4951 * @param permission The name of the permission being checked.
4952 * @param pid The process ID being checked against. Must be &gt; 0.
4953 * @param uid The user ID being checked against. A uid of 0 is the root
4954 * user, which will pass every permission check.
4955 * @param message A message to include in the exception if it is thrown.
4956 *
4957 * @see #checkPermission(String, int, int)
4958 */
4959 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004960 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004961
4962 /**
4963 * If the calling process of an IPC you are handling has not been
4964 * granted a particular permission, throw a {@link
4965 * SecurityException}. This is basically the same as calling
4966 * {@link #enforcePermission(String, int, int, String)} with the
4967 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4968 * and {@link android.os.Binder#getCallingUid}. One important
4969 * difference is that if you are not currently processing an IPC,
4970 * this function will always throw the SecurityException. This is
4971 * done to protect against accidentally leaking permissions; you
4972 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4973 * protection.
4974 *
4975 * @param permission The name of the permission being checked.
4976 * @param message A message to include in the exception if it is thrown.
4977 *
4978 * @see #checkCallingPermission(String)
4979 */
4980 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004981 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004982
4983 /**
4984 * If neither you nor the calling process of an IPC you are
4985 * handling has been granted a particular permission, throw a
4986 * {@link SecurityException}. This is the same as {@link
4987 * #enforceCallingPermission}, except it grants your own
4988 * permissions if you are not currently processing an IPC. Use
4989 * with care!
4990 *
4991 * @param permission The name of the permission being checked.
4992 * @param message A message to include in the exception if it is thrown.
4993 *
4994 * @see #checkCallingOrSelfPermission(String)
4995 */
4996 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004997 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004998
4999 /**
5000 * Grant permission to access a specific Uri to another package, regardless
5001 * of whether that package has general permission to access the Uri's
5002 * content provider. This can be used to grant specific, temporary
5003 * permissions, typically in response to user interaction (such as the
5004 * user opening an attachment that you would like someone else to
5005 * display).
5006 *
5007 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
5008 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
5009 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
5010 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
5011 * start an activity instead of this function directly. If you use this
5012 * function directly, you should be sure to call
5013 * {@link #revokeUriPermission} when the target should no longer be allowed
5014 * to access it.
5015 *
5016 * <p>To succeed, the content provider owning the Uri must have set the
5017 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
5018 * grantUriPermissions} attribute in its manifest or included the
5019 * {@link android.R.styleable#AndroidManifestGrantUriPermission
5020 * &lt;grant-uri-permissions&gt;} tag.
5021 *
5022 * @param toPackage The package you would like to allow to access the Uri.
5023 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005024 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005025 *
5026 * @see #revokeUriPermission
5027 */
5028 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07005029 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005030
5031 /**
5032 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07005033 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
5034 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07005035 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005036 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07005037 * "content://foo". It will not remove any prefix grants that exist at a
5038 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005039 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07005040 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07005041 * regular permission access to a Uri, but had received access to it through
5042 * a specific Uri permission grant, you could not revoke that grant with this
5043 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07005044 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
5045 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07005046 * (or none).</p>
5047 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07005048 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
5049 * grants matching the given Uri, for any package they had been granted to, through any
5050 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
5051 * service start, etc). That means this can be potentially dangerous to use, as it can
5052 * revoke grants that another app could be strongly expecting to stick around.</p>
5053 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005054 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005055 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005056 *
5057 * @see #grantUriPermission
5058 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07005059 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005060
5061 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07005062 * Remove permissions to access a particular content provider Uri
5063 * that were previously added with {@link #grantUriPermission} for a specific target
5064 * package. The given Uri will match all previously granted Uris that are the same or a
5065 * sub-path of the given Uri. That is, revoking "content://foo/target" will
5066 * revoke both "content://foo/target" and "content://foo/target/sub", but not
5067 * "content://foo". It will not remove any prefix grants that exist at a
5068 * higher level.
5069 *
5070 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
5071 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
5072 * and only for the package specified. Any matching grants that have happened through
5073 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
5074 * removed.</p>
5075 *
5076 * @param toPackage The package you had previously granted access to.
5077 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005078 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07005079 *
5080 * @see #grantUriPermission
5081 */
5082 public abstract void revokeUriPermission(String toPackage, Uri uri,
5083 @Intent.AccessUriMode int modeFlags);
5084
5085 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005086 * Determine whether a particular process and user ID has been granted
5087 * permission to access a specific URI. This only checks for permissions
5088 * that have been explicitly granted -- if the given process/uid has
5089 * more general access to the URI's content provider then this check will
5090 * always fail.
5091 *
5092 * @param uri The uri that is being checked.
5093 * @param pid The process ID being checked against. Must be &gt; 0.
5094 * @param uid The user ID being checked against. A uid of 0 is the root
5095 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005096 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005097 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005098 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005099 * pid/uid is allowed to access that uri, or
5100 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5101 *
5102 * @see #checkCallingUriPermission
5103 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005104 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005105 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005106 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005107 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005108
Dianne Hackbornff170242014-11-19 10:59:01 -08005109 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005110 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08005111 public abstract int checkUriPermission(Uri uri, int pid, int uid,
5112 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
5113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005114 /**
5115 * Determine whether the calling process and user ID has been
5116 * granted permission to access a specific URI. This is basically
5117 * the same as calling {@link #checkUriPermission(Uri, int, int,
5118 * int)} with the pid and uid returned by {@link
5119 * android.os.Binder#getCallingPid} and {@link
5120 * android.os.Binder#getCallingUid}. One important difference is
5121 * that if you are not currently processing an IPC, this function
5122 * will always fail.
5123 *
5124 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005125 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005126 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005127 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005128 * is allowed to access that uri, or
5129 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5130 *
5131 * @see #checkUriPermission(Uri, int, int, int)
5132 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005133 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005134 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07005135 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136
5137 /**
5138 * Determine whether the calling process of an IPC <em>or you</em> has been granted
5139 * permission to access a specific URI. This is the same as
5140 * {@link #checkCallingUriPermission}, except it grants your own permissions
5141 * if you are not currently processing an IPC. Use with care!
5142 *
5143 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005144 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005145 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005146 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005147 * is allowed to access that uri, or
5148 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5149 *
5150 * @see #checkCallingUriPermission
5151 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005152 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005153 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005154 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005155 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005156
5157 /**
5158 * Check both a Uri and normal permission. This allows you to perform
5159 * both {@link #checkPermission} and {@link #checkUriPermission} in one
5160 * call.
5161 *
5162 * @param uri The Uri whose permission is to be checked, or null to not
5163 * do this check.
5164 * @param readPermission The permission that provides overall read access,
5165 * or null to not do this check.
5166 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005167 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005168 * @param pid The process ID being checked against. Must be &gt; 0.
5169 * @param uid The user ID being checked against. A uid of 0 is the root
5170 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005171 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005172 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005173 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005174 * is allowed to access that uri or holds one of the given permissions, or
5175 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5176 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005177 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005178 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005179 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
5180 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005181 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005182
5183 /**
5184 * If a particular process and user ID has not been granted
5185 * permission to access a specific URI, throw {@link
5186 * SecurityException}. This only checks for permissions that have
5187 * been explicitly granted -- if the given process/uid has more
5188 * general access to the URI's content provider then this check
5189 * will always fail.
5190 *
5191 * @param uri The uri that is being checked.
5192 * @param pid The process ID being checked against. Must be &gt; 0.
5193 * @param uid The user ID being checked against. A uid of 0 is the root
5194 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005195 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 * @param message A message to include in the exception if it is thrown.
5197 *
5198 * @see #checkUriPermission(Uri, int, int, int)
5199 */
5200 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005201 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005202
5203 /**
5204 * If the calling process and user ID has not been granted
5205 * permission to access a specific URI, throw {@link
5206 * SecurityException}. This is basically the same as calling
5207 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
5208 * the pid and uid returned by {@link
5209 * android.os.Binder#getCallingPid} and {@link
5210 * android.os.Binder#getCallingUid}. One important difference is
5211 * that if you are not currently processing an IPC, this function
5212 * will always throw a SecurityException.
5213 *
5214 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005215 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005216 * @param message A message to include in the exception if it is thrown.
5217 *
5218 * @see #checkCallingUriPermission(Uri, int)
5219 */
5220 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005221 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222
5223 /**
5224 * If the calling process of an IPC <em>or you</em> has not been
5225 * granted permission to access a specific URI, throw {@link
5226 * SecurityException}. This is the same as {@link
5227 * #enforceCallingUriPermission}, except it grants your own
5228 * permissions if you are not currently processing an IPC. Use
5229 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07005230 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005232 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005233 * @param message A message to include in the exception if it is thrown.
5234 *
5235 * @see #checkCallingOrSelfUriPermission(Uri, int)
5236 */
5237 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005238 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005239
5240 /**
5241 * Enforce both a Uri and normal permission. This allows you to perform
5242 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
5243 * call.
Scott Main4b5da682010-10-21 11:49:12 -07005244 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005245 * @param uri The Uri whose permission is to be checked, or null to not
5246 * do this check.
5247 * @param readPermission The permission that provides overall read access,
5248 * or null to not do this check.
5249 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005250 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 * @param pid The process ID being checked against. Must be &gt; 0.
5252 * @param uid The user ID being checked against. A uid of 0 is the root
5253 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005254 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005255 * @param message A message to include in the exception if it is thrown.
5256 *
5257 * @see #checkUriPermission(Uri, String, String, int, int, int)
5258 */
5259 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005260 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005261 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07005262 @Nullable String message);
5263
5264 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005265 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
5266 CONTEXT_INCLUDE_CODE,
5267 CONTEXT_IGNORE_SECURITY,
5268 CONTEXT_RESTRICTED,
5269 CONTEXT_DEVICE_PROTECTED_STORAGE,
5270 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
5271 CONTEXT_REGISTER_PACKAGE,
5272 })
Tor Norbyed9273d62013-05-30 15:59:53 -07005273 @Retention(RetentionPolicy.SOURCE)
5274 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005275
5276 /**
5277 * Flag for use with {@link #createPackageContext}: include the application
5278 * code with the context. This means loading code into the caller's
5279 * process, so that {@link #getClassLoader()} can be used to instantiate
5280 * the application's classes. Setting this flags imposes security
5281 * restrictions on what application context you can access; if the
5282 * requested application can not be safely loaded into your process,
5283 * java.lang.SecurityException will be thrown. If this flag is not set,
5284 * there will be no restrictions on the packages that can be loaded,
5285 * but {@link #getClassLoader} will always return the default system
5286 * class loader.
5287 */
5288 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
5289
5290 /**
5291 * Flag for use with {@link #createPackageContext}: ignore any security
5292 * restrictions on the Context being requested, allowing it to always
5293 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
5294 * to be loaded into a process even when it isn't safe to do so. Use
5295 * with extreme care!
5296 */
5297 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07005298
Romain Guy870e09f2009-07-06 16:35:25 -07005299 /**
5300 * Flag for use with {@link #createPackageContext}: a restricted context may
5301 * disable specific features. For instance, a View associated with a restricted
5302 * context would ignore particular XML attributes.
5303 */
5304 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005305
5306 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005307 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005308 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005309 *
5310 * @hide
5311 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005312 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005313
5314 /**
5315 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005316 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005317 *
5318 * @hide
5319 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005320 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005321
5322 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07005323 * @hide Used to indicate we should tell the activity manager about the process
5324 * loading this code.
5325 */
5326 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
5327
5328 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005329 * Return a new Context object for the given application name. This
5330 * Context is the same as what the named application gets when it is
5331 * launched, containing the same resources and class loader. Each call to
5332 * this method returns a new instance of a Context object; Context objects
5333 * are not shared, however they share common state (Resources, ClassLoader,
5334 * etc) so the Context instance itself is fairly lightweight.
5335 *
Jeff Brown6e539312015-02-24 18:53:21 -08005336 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005337 * application with the given package name.
5338 *
5339 * <p>Throws {@link java.lang.SecurityException} if the Context requested
5340 * can not be loaded into the caller's process for security reasons (see
5341 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
5342 *
5343 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005344 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005346 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005348 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005349 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04005350 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005351 */
5352 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07005353 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07005354
5355 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07005356 * Similar to {@link #createPackageContext(String, int)}, but with a
5357 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5358 * will open any {@link Uri} as the given user.
5359 *
5360 * @hide
5361 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08005362 @SystemApi
Jeff Sharkeyec5f7d12018-08-08 09:15:04 -06005363 @TestApi
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005364 @NonNull
Patrick Baumannef4c4072018-02-01 08:54:05 -08005365 public Context createPackageContextAsUser(
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005366 @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08005367 throws PackageManager.NameNotFoundException {
5368 if (Build.IS_ENG) {
5369 throw new IllegalStateException("createPackageContextAsUser not overridden!");
5370 }
5371 return this;
5372 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07005373
5374 /**
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005375 * Similar to {@link #createPackageContext(String, int)}, but for the own package with a
5376 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5377 * will open any {@link Uri} as the given user.
5378 *
5379 * @hide
5380 */
5381 @SystemApi
5382 @TestApi
5383 @NonNull
Makoto Onuki6b1e9d22019-10-11 20:19:58 -07005384 public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005385 if (Build.IS_ENG) {
5386 throw new IllegalStateException("createContextAsUser not overridden!");
5387 }
5388 return this;
5389 }
5390
5391 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07005392 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
5393 *
5394 * @hide
5395 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005396 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07005397 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005398 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07005399
5400 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08005401 * Return a new Context object for the given split name. The new Context has a ClassLoader and
5402 * Resources object that can access the split's and all of its dependencies' code/resources.
5403 * Each call to this method returns a new instance of a Context object;
5404 * Context objects are not shared, however common state (ClassLoader, other Resources for
5405 * the same split) may be so the Context itself can be fairly lightweight.
5406 *
5407 * @param splitName The name of the split to include, as declared in the split's
5408 * <code>AndroidManifest.xml</code>.
5409 * @return A {@link Context} with the given split's code and/or resources loaded.
5410 */
5411 public abstract Context createContextForSplit(String splitName)
5412 throws PackageManager.NameNotFoundException;
5413
5414 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005415 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08005416 * @hide
5417 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07005418 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005419 public UserHandle getUser() {
5420 return android.os.Process.myUserHandle();
5421 }
5422
5423 /**
5424 * Get the user associated with this context
5425 * @hide
5426 */
Artur Satayev5a525852019-10-31 15:15:50 +00005427 @UnsupportedAppUsage
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005428 @TestApi
5429 public @UserIdInt int getUserId() {
5430 return android.os.UserHandle.myUserId();
5431 }
Jim Millera75a8832013-02-07 16:53:32 -08005432
5433 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07005434 * Return a new Context object for the current Context but whose resources
5435 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07005436 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07005437 * shared, however common state (ClassLoader, other Resources for the
5438 * same configuration) may be so the Context itself can be fairly lightweight.
5439 *
5440 * @param overrideConfiguration A {@link Configuration} specifying what
5441 * values to modify in the base Configuration of the original Context's
5442 * resources. If the base configuration changes (such as due to an
5443 * orientation change), the resources of this context will also change except
5444 * for those that have been explicitly overridden with a value here.
5445 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005446 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07005447 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005448 public abstract Context createConfigurationContext(
5449 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07005450
5451 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07005452 * Return a new Context object for the current Context but whose resources
5453 * are adjusted to match the metrics of the given Display. Each call to this method
5454 * returns a new instance of a Context object; Context objects are not
5455 * shared, however common state (ClassLoader, other Resources for the
5456 * same configuration) may be so the Context itself can be fairly lightweight.
5457 *
5458 * The returned display Context provides a {@link WindowManager}
5459 * (see {@link #getSystemService(String)}) that is configured to show windows
5460 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
5461 * method can be used to retrieve the Display from the returned Context.
5462 *
5463 * @param display A {@link Display} object specifying the display
5464 * for whose metrics the Context's resources should be tailored and upon which
5465 * new windows should be shown.
5466 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005467 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07005468 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005469 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07005470
5471 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005472 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005473 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005474 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005475 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005476 * with a key tied to the physical device, and it can be accessed
5477 * immediately after the device has booted successfully, both
5478 * <em>before and after</em> the user has authenticated with their
5479 * credentials (such as a lock pattern or PIN).
5480 * <p>
5481 * Because device-protected data is available without user authentication,
5482 * you should carefully limit the data you store using this Context. For
5483 * example, storing sensitive authentication tokens or passwords in the
5484 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005485 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005486 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005487 * device-protected and credential-protected data using different keys, then
5488 * both storage areas will become available at the same time. They remain as
5489 * two distinct storage locations on disk, and only the window of
5490 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005491 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005492 * Each call to this method returns a new instance of a Context object;
5493 * Context objects are not shared, however common state (ClassLoader, other
5494 * Resources for the same configuration) may be so the Context itself can be
5495 * fairly lightweight.
5496 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005497 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005498 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005499 public abstract Context createDeviceProtectedStorageContext();
5500
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005501 /**
5502 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005503 * APIs are backed by credential-protected storage. This is the default
5504 * storage area for apps unless
5505 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005506 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005507 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005508 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005509 * <em>only after</em> the user has entered their credentials (such as a
5510 * lock pattern or PIN).
5511 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005512 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005513 * device-protected and credential-protected data using different keys, then
5514 * both storage areas will become available at the same time. They remain as
5515 * two distinct storage locations on disk, and only the window of
5516 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005517 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005518 * Each call to this method returns a new instance of a Context object;
5519 * Context objects are not shared, however common state (ClassLoader, other
5520 * Resources for the same configuration) may be so the Context itself can be
5521 * fairly lightweight.
5522 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005523 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005524 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005525 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005526 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005527 public abstract Context createCredentialProtectedStorageContext();
5528
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005529 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07005530 * Gets the display adjustments holder for this context. This information
5531 * is provided on a per-application or activity basis and is used to simulate lower density
5532 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07005533 *
Jeff Browna492c3a2012-08-23 19:48:44 -07005534 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07005535 * @return The compatibility info holder, or null if not required by the application.
5536 * @hide
5537 */
Craig Mautner48d0d182013-06-11 07:53:06 -07005538 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07005539
5540 /**
Wale Ogunwale691af682019-02-11 03:09:10 -08005541 * @return Returns the {@link Display} object this context is associated with.
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005542 * @hide
5543 */
Artur Satayev5a525852019-10-31 15:15:50 +00005544 @UnsupportedAppUsage
Wale Ogunwale691af682019-02-11 03:09:10 -08005545 @TestApi
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005546 public abstract Display getDisplay();
5547
5548 /**
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005549 * Gets the display ID.
5550 *
5551 * @return display ID associated with this {@link Context}.
5552 * @hide
5553 */
wilsonshih5db7b392019-02-20 23:08:45 +08005554 @TestApi
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005555 public abstract int getDisplayId();
5556
5557 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08005558 * @hide
5559 */
5560 public abstract void updateDisplay(int displayId);
5561
5562 /**
Romain Guy870e09f2009-07-06 16:35:25 -07005563 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07005564 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005565 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07005566 *
Romain Guy870e09f2009-07-06 16:35:25 -07005567 * @see #CONTEXT_RESTRICTED
5568 */
5569 public boolean isRestricted() {
5570 return false;
5571 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005572
5573 /**
5574 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005575 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005576 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005577 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005578 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005579 public abstract boolean isDeviceProtectedStorage();
5580
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005581 /**
5582 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005583 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005584 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005585 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005586 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005587 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005588 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005589 public abstract boolean isCredentialProtectedStorage();
5590
Tony Mak46aabe52016-11-14 12:53:06 +00005591 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005592 * Returns true if the context can load unsafe resources, e.g. fonts.
5593 * @hide
5594 */
5595 public abstract boolean canLoadUnsafeResources();
5596
5597 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005598 * @hide
5599 */
5600 public IBinder getActivityToken() {
5601 throw new RuntimeException("Not implemented. Must override in a subclass.");
5602 }
5603
5604 /**
5605 * @hide
5606 */
5607 @Nullable
5608 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
5609 int flags) {
5610 throw new RuntimeException("Not implemented. Must override in a subclass.");
5611 }
5612
5613 /**
5614 * @hide
5615 */
5616 public IApplicationThread getIApplicationThread() {
5617 throw new RuntimeException("Not implemented. Must override in a subclass.");
5618 }
Tony Makbf9928d2016-12-22 11:02:45 +00005619
5620 /**
5621 * @hide
5622 */
5623 public Handler getMainThreadHandler() {
5624 throw new RuntimeException("Not implemented. Must override in a subclass.");
5625 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07005626
5627 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07005628 * @hide
5629 */
5630 public AutofillClient getAutofillClient() {
5631 return null;
5632 }
5633
5634 /**
5635 * @hide
5636 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005637 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005638 }
5639
5640 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005641 * @hide
5642 */
Felipe Lemecbf7f262019-04-17 13:57:59 -07005643 @Nullable
5644 public ContentCaptureClient getContentCaptureClient() {
5645 return null;
5646 }
5647
5648 /**
5649 * @hide
5650 */
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005651 public final boolean isAutofillCompatibilityEnabled() {
5652 final AutofillOptions options = getAutofillOptions();
5653 return options != null && options.compatModeEnabled;
5654 }
5655
5656 /**
5657 * @hide
5658 */
5659 @Nullable
5660 public AutofillOptions getAutofillOptions() {
5661 return null;
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005662 }
5663
5664 /**
5665 * @hide
5666 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005667 @TestApi
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005668 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005669 }
5670
5671 /**
Felipe Leme326f15a2019-02-19 09:42:24 -08005672 * Gets the Content Capture options for this context, or {@code null} if it's not whitelisted.
Felipe Lemeecb08be2018-11-27 15:48:47 -08005673 *
5674 * @hide
5675 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005676 @Nullable
5677 public ContentCaptureOptions getContentCaptureOptions() {
5678 return null;
Felipe Lemeecb08be2018-11-27 15:48:47 -08005679 }
5680
5681 /**
5682 * @hide
5683 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005684 @TestApi
5685 public void setContentCaptureOptions(
5686 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08005687 }
5688
5689 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005690 * Throws an exception if the Context is using system resources,
5691 * which are non-runtime-overlay-themable and may show inconsistent UI.
5692 * @hide
5693 */
5694 public void assertRuntimeOverlayThemable() {
5695 // Resources.getSystem() is a singleton and the only Resources not managed by
5696 // ResourcesManager; therefore Resources.getSystem() is not themable.
5697 if (getResources() == Resources.getSystem()) {
5698 throw new IllegalArgumentException("Non-UI context used to display UI; "
5699 + "get a UI context from ActivityThread#getSystemUiContext()");
5700 }
5701 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005702}