blob: d370a380bc3be70110e2386da35627908cdced54 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Tor Norbyec91531a2015-04-01 17:41:55 -070019import android.annotation.AttrRes;
Bo Liu58a57662019-03-06 20:21:45 +000020import android.annotation.CallbackExecutor;
Tor Norbye1c2bf032015-03-02 10:57:08 -080021import android.annotation.CheckResult;
Tor Norbye3e4cda72015-06-10 08:14:31 -070022import android.annotation.ColorInt;
23import android.annotation.ColorRes;
24import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070025import android.annotation.IntDef;
26import android.annotation.NonNull;
27import android.annotation.Nullable;
Tor Norbye788fc2b2015-07-05 16:10:42 -070028import android.annotation.RequiresPermission;
Tor Norbyed9273d62013-05-30 15:59:53 -070029import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070030import android.annotation.StringRes;
31import android.annotation.StyleRes;
32import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090033import android.annotation.SystemApi;
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -070034import android.annotation.TestApi;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010035import android.annotation.UnsupportedAppUsage;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070036import android.annotation.UserIdInt;
Selim Cinek7fa385a2018-01-24 08:35:28 -080037import android.app.ActivityManager;
Tony Mak46aabe52016-11-14 12:53:06 +000038import android.app.IApplicationThread;
39import android.app.IServiceConnection;
Zak Cohen56345f42017-01-26 13:54:28 -080040import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070041import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.content.pm.PackageManager;
43import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080044import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070045import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.content.res.Resources;
47import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070048import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.database.sqlite.SQLiteDatabase;
50import android.database.sqlite.SQLiteDatabase.CursorFactory;
51import android.graphics.Bitmap;
52import android.graphics.drawable.Drawable;
53import android.net.Uri;
Patrick Baumannef4c4072018-02-01 08:54:05 -080054import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070056import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.os.Handler;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070058import android.os.HandlerExecutor;
Dianne Hackbornff170242014-11-19 10:59:01 -080059import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070061import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070062import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070063import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060064import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070065import android.provider.MediaStore;
Chen Xu1f6cfa52019-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;
atrost87488352019-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
Philip P. Moltmann59076d82019-08-19 15:00:40 -0700815 /**
816 * <p>Features are used in complex apps to logically separate parts of the app. E.g. a
817 * blogging app might also have a instant messaging app built in.
818 *
819 * @return the feature id this context is for or {@code null} if this is the default
820 * feature.
821 */
822 public @Nullable String getFeatureId() {
823 return null;
824 }
825
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700826 /** Return the full application info for this context's package. */
827 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700828
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 /**
Kenny Root32148392010-01-21 15:40:47 -0800830 * Return the full path to this context's primary Android package.
831 * The Android package is a ZIP file which contains the application's
832 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800833 *
834 * <p>Note: this is not generally useful for applications, since they should
835 * not be directly accessing the file system.
836 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837 * @return String Path to the resources.
838 */
839 public abstract String getPackageResourcePath();
840
841 /**
Kenny Root32148392010-01-21 15:40:47 -0800842 * Return the full path to this context's primary Android package.
843 * The Android package is a ZIP file which contains application's
844 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800845 *
846 * <p>Note: this is not generally useful for applications, since they should
847 * not be directly accessing the file system.
848 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800849 * @return String Path to the code and assets.
850 */
851 public abstract String getPackageCodePath();
852
853 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700854 * @hide
855 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700856 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700857 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100858 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700859 public File getSharedPrefsFile(String name) {
860 return getSharedPreferencesPath(name);
861 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700862
863 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800864 * Retrieve and hold the contents of the preferences file 'name', returning
865 * a SharedPreferences through which you can retrieve and modify its
866 * values. Only one instance of the SharedPreferences object is returned
867 * to any callers for the same name, meaning they will see each other's
868 * edits as soon as they are made.
869 *
Nate Fischer5272c372019-08-27 16:37:00 -0700870 * <p>This method is thread-safe.
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700871 *
Nate Fischer5272c372019-08-27 16:37:00 -0700872 * <p>If the preferences directory does not already exist, it will be created when this method
873 * is called.
874 *
875 * <p>If a preferences file by this name does not exist, it will be created when you retrieve an
876 * editor ({@link SharedPreferences#edit()}) and then commit changes ({@link
877 * SharedPreferences.Editor#commit()} or {@link SharedPreferences.Editor#apply()}).
878 *
879 * @param name Desired preferences file.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600880 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800881 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400882 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 * to retrieve and modify the preference values.
884 *
885 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800886 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600887 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700888
889 /**
890 * Retrieve and hold the contents of the preferences file, returning
891 * a SharedPreferences through which you can retrieve and modify its
892 * values. Only one instance of the SharedPreferences object is returned
893 * to any callers for the same name, meaning they will see each other's
894 * edits as soon as they are made.
895 *
896 * @param file Desired preferences file. If a preferences file by this name
897 * does not exist, it will be created when you retrieve an
898 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600899 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700900 *
901 * @return The single {@link SharedPreferences} instance that can be used
902 * to retrieve and modify the preference values.
903 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700904 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700905 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600906 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700907 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600908 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800909
910 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600911 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700912 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600913 * storage locations after an upgrade, such as moving to device protected
914 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700915 *
916 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600917 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700918 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600919 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700920 * preferences didn't exist in the source context, otherwise
921 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600922 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700923 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600924 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
925
Jeff Sharkey35871f22016-01-29 17:13:29 -0700926 /**
927 * Delete an existing shared preferences file.
928 *
929 * @param name The name (unique in the application package) of the shared
930 * preferences file.
931 * @return {@code true} if the shared preferences file was successfully
932 * deleted; else {@code false}.
933 * @see #getSharedPreferences(String, int)
934 */
935 public abstract boolean deleteSharedPreferences(String name);
936
Christopher Tatefe2368c2017-05-17 15:42:35 -0700937 /** @hide */
938 public abstract void reloadSharedPreferences();
939
Jeff Sharkey35871f22016-01-29 17:13:29 -0700940 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 * Open a private file associated with this Context's application package
942 * for reading.
943 *
944 * @param name The name of the file to open; can not contain path
945 * separators.
946 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400947 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800948 *
949 * @see #openFileOutput
950 * @see #fileList
951 * @see #deleteFile
952 * @see java.io.FileInputStream#FileInputStream(String)
953 */
954 public abstract FileInputStream openFileInput(String name)
955 throws FileNotFoundException;
956
957 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800958 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700959 * for writing. Creates the file if it doesn't already exist.
960 * <p>
961 * No additional permissions are required for the calling app to read or
962 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700963 *
Nick Kralevich15069212013-01-09 15:54:56 -0800964 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700965 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600966 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400967 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 * @see #MODE_APPEND
969 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 * @see #openFileInput
971 * @see #fileList
972 * @see #deleteFile
973 * @see java.io.FileOutputStream#FileOutputStream(String)
974 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600975 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 throws FileNotFoundException;
977
978 /**
979 * Delete the given private file associated with this Context's
980 * application package.
981 *
982 * @param name The name of the file to delete; can not contain path
983 * separators.
984 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400985 * @return {@code true} if the file was successfully deleted; else
986 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800987 *
988 * @see #openFileInput
989 * @see #openFileOutput
990 * @see #fileList
991 * @see java.io.File#delete()
992 */
993 public abstract boolean deleteFile(String name);
994
995 /**
996 * Returns the absolute path on the filesystem where a file created with
997 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700998 * <p>
999 * The returned path may change over time if the calling app is moved to an
1000 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 *
1002 * @param name The name of the file for which you would like to get
1003 * its path.
1004 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001005 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 *
1007 * @see #openFileOutput
1008 * @see #getFilesDir
1009 * @see #getDir
1010 */
1011 public abstract File getFileStreamPath(String name);
1012
1013 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001014 * Returns the absolute path on the filesystem where a file created with
1015 * {@link #getSharedPreferences(String, int)} is stored.
1016 * <p>
1017 * The returned path may change over time if the calling app is moved to an
1018 * adopted storage device, so only relative paths should be persisted.
1019 *
1020 * @param name The name of the shared preferences for which you would like
1021 * to get a path.
1022 * @return An absolute path to the given file.
1023 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001024 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001025 */
1026 public abstract File getSharedPreferencesPath(String name);
1027
1028 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001029 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001030 * private files belonging to this app are stored. Apps should not use this
1031 * path directly; they should instead use {@link #getFilesDir()},
1032 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1033 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001034 * <p>
1035 * The returned path may change over time if the calling app is moved to an
1036 * adopted storage device, so only relative paths should be persisted.
1037 * <p>
1038 * No additional permissions are required for the calling app to read or
1039 * write files under the returned path.
1040 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001041 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001042 */
1043 public abstract File getDataDir();
1044
1045 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001046 * Returns the absolute path to the directory on the filesystem where files
1047 * created with {@link #openFileOutput} are stored.
1048 * <p>
1049 * The returned path may change over time if the calling app is moved to an
1050 * adopted storage device, so only relative paths should be persisted.
1051 * <p>
1052 * No additional permissions are required for the calling app to read or
1053 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -07001054 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001055 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 * @see #openFileOutput
1057 * @see #getFileStreamPath
1058 * @see #getDir
1059 */
1060 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -07001061
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062 /**
Christopher Tatea7835b62014-07-11 17:25:57 -07001063 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001064 * {@link #getFilesDir()}. The difference is that files placed under this
1065 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -07001066 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1067 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001068 * <p>
1069 * The returned path may change over time if the calling app is moved to an
1070 * adopted storage device, so only relative paths should be persisted.
1071 * <p>
1072 * No additional permissions are required for the calling app to read or
1073 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -07001074 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001075 * @return The path of the directory holding application files that will not
1076 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -07001077 * @see #openFileOutput
1078 * @see #getFileStreamPath
1079 * @see #getDir
1080 * @see android.app.backup.BackupAgent
1081 */
1082 public abstract File getNoBackupFilesDir();
1083
1084 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001085 * Returns the absolute path to the directory on the primary shared/external
1086 * storage device where the application can place persistent files it owns.
1087 * These files are internal to the applications, and not typically visible
1088 * to the user as media.
1089 * <p>
1090 * This is like {@link #getFilesDir()} in that these files will be deleted
1091 * when the application is uninstalled, however there are some important
1092 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001093 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001094 * <li>Shared storage may not always be available, since removable media can
1095 * be ejected by the user. Media state can be checked using
1096 * {@link Environment#getExternalStorageState(File)}.
1097 * <li>There is no security enforced with these files. For example, any
1098 * application holding
1099 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001100 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001101 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001102 * <p>
1103 * If a shared storage device is emulated (as determined by
1104 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1105 * backed by a private user data partition, which means there is little
1106 * benefit to storing data here instead of the private directories returned
1107 * by {@link #getFilesDir()}, etc.
1108 * <p>
1109 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001110 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001111 * accessible to the calling app. This only applies to paths generated for
1112 * package name of the calling application. To access paths belonging to
1113 * other packages,
1114 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1115 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1116 * <p>
1117 * On devices with multiple users (as described by {@link UserManager}),
1118 * each user has their own isolated shared storage. Applications only have
1119 * access to the shared storage for the user they're running as.
1120 * <p>
1121 * The returned path may change over time if different shared storage media
1122 * is inserted, so only relative paths should be persisted.
1123 * <p>
1124 * Here is an example of typical code to manipulate a file in an
1125 * application's shared storage:
1126 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001127 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1128 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001129 * <p>
1130 * If you supply a non-null <var>type</var> to this function, the returned
1131 * file will be a path to a sub-directory of the given type. Though these
1132 * files are not automatically scanned by the media scanner, you can
1133 * explicitly add them to the media database with
1134 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1135 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001136 * {@link android.os.Environment#getExternalStoragePublicDirectory
1137 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001138 * directories of media shared by all applications. The directories returned
1139 * here are owned by the application, and their contents will be removed
1140 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001141 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001142 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1143 * here will be automatically created for you.
1144 * <p>
1145 * Here is an example of typical code to manipulate a picture in an
1146 * application's shared storage and add it to the media database:
1147 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001148 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1149 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001150 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001151 * @param type The type of files directory to return. May be {@code null}
1152 * for the root of the files directory or one of the following
1153 * constants for a subdirectory:
1154 * {@link android.os.Environment#DIRECTORY_MUSIC},
1155 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1156 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1157 * {@link android.os.Environment#DIRECTORY_ALARMS},
1158 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1159 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1160 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1161 * @return the absolute path to application-specific directory. May return
1162 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001163 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001164 * @see #getExternalFilesDirs(String)
1165 * @see Environment#getExternalStorageState(File)
1166 * @see Environment#isExternalStorageEmulated(File)
1167 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001168 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001169 @Nullable
1170 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001171
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001172 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001173 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001174 * shared/external storage devices where the application can place
1175 * persistent files it owns. These files are internal to the application,
1176 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001177 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001178 * This is like {@link #getFilesDir()} in that these files will be deleted
1179 * when the application is uninstalled, however there are some important
1180 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001181 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001182 * <li>Shared storage may not always be available, since removable media can
1183 * be ejected by the user. Media state can be checked using
1184 * {@link Environment#getExternalStorageState(File)}.
1185 * <li>There is no security enforced with these files. For example, any
1186 * application holding
1187 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1188 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001189 * </ul>
1190 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001191 * If a shared storage device is emulated (as determined by
1192 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1193 * backed by a private user data partition, which means there is little
1194 * benefit to storing data here instead of the private directories returned
1195 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001196 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001197 * Shared storage devices returned here are considered a stable part of the
1198 * device, including physical media slots under a protective cover. The
1199 * returned paths do not include transient devices, such as USB flash drives
1200 * connected to handheld devices.
1201 * <p>
1202 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001203 * example, an app may choose to store large files on the device with the
1204 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001205 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001206 * No additional permissions are required for the calling app to read or
1207 * write files under the returned path. Write access outside of these paths
1208 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001209 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001210 * The returned path may change over time if different shared storage media
1211 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001212 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001213 * @param type The type of files directory to return. May be {@code null}
1214 * for the root of the files directory or one of the following
1215 * constants for a subdirectory:
1216 * {@link android.os.Environment#DIRECTORY_MUSIC},
1217 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1218 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1219 * {@link android.os.Environment#DIRECTORY_ALARMS},
1220 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1221 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1222 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1223 * @return the absolute paths to application-specific directories. Some
1224 * individual paths may be {@code null} if that shared storage is
1225 * not currently available. The first path returned is the same as
1226 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001227 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001228 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001229 * @see Environment#isExternalStorageEmulated(File)
1230 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001231 */
1232 public abstract File[] getExternalFilesDirs(String type);
1233
1234 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001235 * Return the primary shared/external storage directory where this
1236 * application's OBB files (if there are any) can be found. Note if the
1237 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001238 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001239 * This is like {@link #getFilesDir()} in that these files will be deleted
1240 * when the application is uninstalled, however there are some important
1241 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001242 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001243 * <li>Shared storage may not always be available, since removable media can
1244 * be ejected by the user. Media state can be checked using
1245 * {@link Environment#getExternalStorageState(File)}.
1246 * <li>There is no security enforced with these files. For example, any
1247 * application holding
1248 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001249 * these files.
1250 * </ul>
1251 * <p>
1252 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001253 * are required to read or write to the path that this method returns.
1254 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1255 * to read the OBB expansion files, you must declare the
1256 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1257 * permission at runtime as follows:
1258 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001259 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001260 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1261 * android:maxSdkVersion="23" />}
1262 * </p>
1263 * <p>
1264 * Starting from {@link android.os.Build.VERSION_CODES#N},
1265 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1266 * permission is not required, so don’t ask for this
1267 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1268 * and if it fails, you must request
1269 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1270 * </p>
1271 *
1272 * <p>
1273 * The following code snippet shows how to do this:
1274 * </p>
1275 *
1276 * <pre>
1277 * File obb = new File(obb_filename);
1278 * boolean open_failed = false;
1279 *
1280 * try {
1281 * BufferedReader br = new BufferedReader(new FileReader(obb));
1282 * open_failed = false;
1283 * ReadObbFile(br);
1284 * } catch (IOException e) {
1285 * open_failed = true;
1286 * }
1287 *
1288 * if (open_failed) {
1289 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1290 * ReadObbFileWithPermission();
1291 * }
1292 * </pre>
1293 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001294 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001295 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001296 * should ensure that multiple instances running under different users don't
1297 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001298 *
1299 * @return the absolute path to application-specific directory. May return
1300 * {@code null} if shared storage is not currently available.
1301 * @see #getObbDirs()
1302 * @see Environment#getExternalStorageState(File)
1303 * @see Environment#isExternalStorageEmulated(File)
1304 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001305 */
1306 public abstract File getObbDir();
1307
1308 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001309 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001310 * shared/external storage devices where the application's OBB files (if
1311 * there are any) can be found. Note if the application does not have any
1312 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001313 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001314 * This is like {@link #getFilesDir()} in that these files will be deleted
1315 * when the application is uninstalled, however there are some important
1316 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001317 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001318 * <li>Shared storage may not always be available, since removable media can
1319 * be ejected by the user. Media state can be checked using
1320 * {@link Environment#getExternalStorageState(File)}.
1321 * <li>There is no security enforced with these files. For example, any
1322 * application holding
1323 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1324 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001325 * </ul>
1326 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001327 * Shared storage devices returned here are considered a stable part of the
1328 * device, including physical media slots under a protective cover. The
1329 * returned paths do not include transient devices, such as USB flash drives
1330 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001331 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001332 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001333 * example, an app may choose to store large files on the device with the
1334 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001335 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001336 * No additional permissions are required for the calling app to read or
1337 * write files under the returned path. Write access outside of these paths
1338 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001339 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001340 * @return the absolute paths to application-specific directories. Some
1341 * individual paths may be {@code null} if that shared storage is
1342 * not currently available. The first path returned is the same as
1343 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001344 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001345 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001346 * @see Environment#isExternalStorageEmulated(File)
1347 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001348 */
1349 public abstract File[] getObbDirs();
1350
1351 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001352 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001353 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001354 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001355 * The system will automatically delete files in this directory as disk
1356 * space is needed elsewhere on the device. The system will always delete
1357 * older files first, as reported by {@link File#lastModified()}. If
1358 * desired, you can exert more control over how files are deleted using
1359 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1360 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1361 * <p>
1362 * Apps are strongly encouraged to keep their usage of cache space below the
1363 * quota returned by
1364 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1365 * goes above this quota, your cached files will be some of the first to be
1366 * deleted when additional disk space is needed. Conversely, if your app
1367 * stays under this quota, your cached files will be some of the last to be
1368 * deleted when additional disk space is needed.
1369 * <p>
1370 * Note that your cache quota will change over time depending on how
1371 * frequently the user interacts with your app, and depending on how much
1372 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001373 * <p>
1374 * The returned path may change over time if the calling app is moved to an
1375 * adopted storage device, so only relative paths should be persisted.
1376 * <p>
1377 * Apps require no extra permissions to read or write to the returned path,
1378 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001379 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001380 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001381 * @see #openFileOutput
1382 * @see #getFileStreamPath
1383 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001384 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001385 */
1386 public abstract File getCacheDir();
1387
1388 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001389 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001390 * the filesystem designed for storing cached code.
1391 * <p>
1392 * The system will delete any files stored in this location both when your
1393 * specific application is upgraded, and when the entire platform is
1394 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001395 * <p>
1396 * This location is optimal for storing compiled or optimized code generated
1397 * by your application at runtime.
1398 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001399 * The returned path may change over time if the calling app is moved to an
1400 * adopted storage device, so only relative paths should be persisted.
1401 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001402 * Apps require no extra permissions to read or write to the returned path,
1403 * since this path lives in their private storage.
1404 *
1405 * @return The path of the directory holding application code cache files.
1406 */
1407 public abstract File getCodeCacheDir();
1408
1409 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001410 * Returns absolute path to application-specific directory on the primary
1411 * shared/external storage device where the application can place cache
1412 * files it owns. These files are internal to the application, and not
1413 * typically visible to the user as media.
1414 * <p>
1415 * This is like {@link #getCacheDir()} in that these files will be deleted
1416 * when the application is uninstalled, however there are some important
1417 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001418 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001419 * <li>The platform does not always monitor the space available in shared
1420 * storage, and thus may not automatically delete these files. Apps should
1421 * always manage the maximum space used in this location. Currently the only
1422 * time files here will be deleted by the platform is when running on
1423 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1424 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1425 * <li>Shared storage may not always be available, since removable media can
1426 * be ejected by the user. Media state can be checked using
1427 * {@link Environment#getExternalStorageState(File)}.
1428 * <li>There is no security enforced with these files. For example, any
1429 * application holding
1430 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001431 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001432 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001433 * <p>
1434 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001435 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001436 * backed by a private user data partition, which means there is little
1437 * benefit to storing data here instead of the private directory returned by
1438 * {@link #getCacheDir()}.
1439 * <p>
1440 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001441 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001442 * accessible to the calling app. This only applies to paths generated for
1443 * package name of the calling application. To access paths belonging to
1444 * other packages,
1445 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1446 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1447 * <p>
1448 * On devices with multiple users (as described by {@link UserManager}),
1449 * each user has their own isolated shared storage. Applications only have
1450 * access to the shared storage for the user they're running as.
1451 * <p>
1452 * The returned path may change over time if different shared storage media
1453 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001454 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001455 * @return the absolute path to application-specific directory. May return
1456 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001457 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001458 * @see #getExternalCacheDirs()
1459 * @see Environment#getExternalStorageState(File)
1460 * @see Environment#isExternalStorageEmulated(File)
1461 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001462 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001463 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001464 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001465
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001466 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001467 * Returns absolute path to application-specific directory in the preloaded cache.
1468 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1469 * There is no guarantee when these files will be deleted.
1470 * @hide
1471 */
1472 @Nullable
1473 @SystemApi
1474 public abstract File getPreloadsFileCache();
1475
1476 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001477 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001478 * shared/external storage devices where the application can place cache
1479 * files it owns. These files are internal to the application, and not
1480 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001481 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001482 * This is like {@link #getCacheDir()} in that these files will be deleted
1483 * when the application is uninstalled, however there are some important
1484 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001485 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001486 * <li>The platform does not always monitor the space available in shared
1487 * storage, and thus may not automatically delete these files. Apps should
1488 * always manage the maximum space used in this location. Currently the only
1489 * time files here will be deleted by the platform is when running on
1490 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1491 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1492 * <li>Shared storage may not always be available, since removable media can
1493 * be ejected by the user. Media state can be checked using
1494 * {@link Environment#getExternalStorageState(File)}.
1495 * <li>There is no security enforced with these files. For example, any
1496 * application holding
1497 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1498 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001499 * </ul>
1500 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001501 * If a shared storage device is emulated (as determined by
1502 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1503 * backed by a private user data partition, which means there is little
1504 * benefit to storing data here instead of the private directory returned by
1505 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001506 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001507 * Shared storage devices returned here are considered a stable part of the
1508 * device, including physical media slots under a protective cover. The
1509 * returned paths do not include transient devices, such as USB flash drives
1510 * connected to handheld devices.
1511 * <p>
1512 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001513 * example, an app may choose to store large files on the device with the
1514 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001515 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001516 * No additional permissions are required for the calling app to read or
1517 * write files under the returned path. Write access outside of these paths
1518 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001519 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001520 * The returned paths may change over time if different shared storage media
1521 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001522 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001523 * @return the absolute paths to application-specific directories. Some
1524 * individual paths may be {@code null} if that shared storage is
1525 * not currently available. The first path returned is the same as
1526 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001527 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001528 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001529 * @see Environment#isExternalStorageEmulated(File)
1530 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001531 */
1532 public abstract File[] getExternalCacheDirs();
1533
1534 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001535 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001536 * shared/external storage devices where the application can place media
1537 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001538 * {@link MediaStore}.
1539 * <p>
1540 * This is like {@link #getExternalFilesDirs} in that these files will be
1541 * deleted when the application is uninstalled, however there are some
1542 * important differences:
1543 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001544 * <li>Shared storage may not always be available, since removable media can
1545 * be ejected by the user. Media state can be checked using
1546 * {@link Environment#getExternalStorageState(File)}.
1547 * <li>There is no security enforced with these files. For example, any
1548 * application holding
1549 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1550 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001551 * </ul>
1552 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001553 * Shared storage devices returned here are considered a stable part of the
1554 * device, including physical media slots under a protective cover. The
1555 * returned paths do not include transient devices, such as USB flash drives
1556 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001557 * <p>
1558 * An application may store data on any or all of the returned devices. For
1559 * example, an app may choose to store large files on the device with the
1560 * most available space, as measured by {@link StatFs}.
1561 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001562 * No additional permissions are required for the calling app to read or
1563 * write files under the returned path. Write access outside of these paths
1564 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001565 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001566 * The returned paths may change over time if different shared storage media
1567 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001568 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001569 * @return the absolute paths to application-specific directories. Some
1570 * individual paths may be {@code null} if that shared storage is
1571 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001572 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001573 * @see Environment#isExternalStorageEmulated(File)
1574 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey588c15e2019-10-10 17:29:58 -06001575 * @deprecated These directories still exist and are scanned, but developers
1576 * are encouraged to migrate to inserting content into a
1577 * {@link MediaStore} collection directly, as any app can
1578 * contribute new media to {@link MediaStore} with no
1579 * permissions required, starting in
1580 * {@link android.os.Build.VERSION_CODES#Q}.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001581 */
Jeff Sharkey588c15e2019-10-10 17:29:58 -06001582 @Deprecated
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001583 public abstract File[] getExternalMediaDirs();
1584
1585 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 * Returns an array of strings naming the private files associated with
1587 * this Context's application package.
1588 *
1589 * @return Array of strings naming the private files.
1590 *
1591 * @see #openFileInput
1592 * @see #openFileOutput
1593 * @see #deleteFile
1594 */
1595 public abstract String[] fileList();
1596
1597 /**
1598 * Retrieve, creating if needed, a new directory in which the application
1599 * can place its own custom data files. You can use the returned File
1600 * object to create and access files in this directory. Note that files
1601 * created through a File object will only be accessible by your own
1602 * application; you can only set the mode of the entire directory, not
1603 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001604 * <p>
1605 * The returned path may change over time if the calling app is moved to an
1606 * adopted storage device, so only relative paths should be persisted.
1607 * <p>
1608 * Apps require no extra permissions to read or write to the returned path,
1609 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001611 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001612 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001613 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001614 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001615 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001616 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 *
1618 * @see #openFileOutput(String, int)
1619 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001620 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001621
1622 /**
1623 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001624 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001625 *
1626 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001627 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001629 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001630 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001631 * @throws android.database.sqlite.SQLiteException if the database file
1632 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001634 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001635 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 * @see #deleteDatabase
1637 */
1638 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001639 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640
1641 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001642 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001643 * application package. Creates the database file if it doesn't exist.
1644 * <p>
1645 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1646 * to be used to handle corruption when sqlite reports database corruption.
1647 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001648 *
1649 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001650 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001651 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001652 * cursor when query is called.
1653 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1654 * sqlite reports database corruption. if null,
1655 * {@link android.database.DefaultDatabaseErrorHandler} is
1656 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001657 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001658 * @throws android.database.sqlite.SQLiteException if the database file
1659 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001660 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001661 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001662 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001663 * @see #deleteDatabase
1664 */
1665 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001666 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001667 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001668
1669 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001670 * Move an existing database file from the given source storage context to
1671 * this context. This is typically used to migrate data between storage
1672 * locations after an upgrade, such as migrating to device protected
1673 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001674 * <p>
1675 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001676 *
1677 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001678 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001679 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001680 * @return {@code true} if the move was successful or if the database didn't
1681 * exist in the source context, otherwise {@code false}.
1682 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001683 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001684 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1685
Jeff Sharkey35871f22016-01-29 17:13:29 -07001686 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 * Delete an existing private SQLiteDatabase associated with this Context's
1688 * application package.
1689 *
1690 * @param name The name (unique in the application package) of the
1691 * database.
1692 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001693 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 *
1695 * @see #openOrCreateDatabase
1696 */
1697 public abstract boolean deleteDatabase(String name);
1698
1699 /**
1700 * Returns the absolute path on the filesystem where a database created with
1701 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001702 * <p>
1703 * The returned path may change over time if the calling app is moved to an
1704 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 *
1706 * @param name The name of the database for which you would like to get
1707 * its path.
1708 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001709 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 *
1711 * @see #openOrCreateDatabase
1712 */
1713 public abstract File getDatabasePath(String name);
1714
1715 /**
1716 * Returns an array of strings naming the private databases associated with
1717 * this Context's application package.
1718 *
1719 * @return Array of strings naming the private databases.
1720 *
1721 * @see #openOrCreateDatabase
1722 * @see #deleteDatabase
1723 */
1724 public abstract String[] databaseList();
1725
1726 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001727 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001728 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001729 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001730 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001731 public abstract Drawable getWallpaper();
1732
1733 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001734 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001735 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001737 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 public abstract Drawable peekWallpaper();
1739
1740 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001741 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1742 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001743 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001744 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001745 public abstract int getWallpaperDesiredMinimumWidth();
1746
1747 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001748 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1749 * WallpaperManager.getDesiredMinimumHeight()} instead.
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 int getWallpaperDesiredMinimumHeight();
1753
1754 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001755 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001756 * WallpaperManager.set()} 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 setWallpaper(Bitmap bitmap) throws IOException;
1762
1763 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001764 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001765 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001766 * <p>This method requires the caller to hold the permission
1767 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001768 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001769 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770 public abstract void setWallpaper(InputStream data) throws IOException;
1771
1772 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001773 * @deprecated Use {@link android.app.WallpaperManager#clear
1774 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001775 * <p>This method requires the caller to hold the permission
1776 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001777 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001778 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001779 public abstract void clearWallpaper() throws IOException;
1780
1781 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001782 * Same as {@link #startActivity(Intent, Bundle)} with no options
1783 * specified.
1784 *
1785 * @param intent The description of the activity to start.
1786 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001787 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001788 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001789 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001790 * @see PackageManager#resolveActivity
1791 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001792 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001793
1794 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001795 * Version of {@link #startActivity(Intent)} that allows you to specify the
1796 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001797 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001798 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001799 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001800 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001801 * @hide
1802 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001803 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07001804 @SystemApi
Adrian Roosebc927c2019-02-28 16:21:18 +01001805 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1806 @NonNull UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001807 throw new RuntimeException("Not implemented. Must override in a subclass.");
1808 }
1809
1810 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 * Launch a new activity. You will not receive any information about when
1812 * the activity exits.
1813 *
1814 * <p>Note that if this method is being called from outside of an
1815 * {@link android.app.Activity} Context, then the Intent must include
1816 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1817 * without being started from an existing Activity, there is no existing
1818 * task in which to place the new activity and thus it needs to be placed
1819 * in its own separate task.
1820 *
1821 * <p>This method throws {@link ActivityNotFoundException}
1822 * if there was no Activity found to run the given Intent.
1823 *
1824 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001825 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001826 * 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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001829 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001830 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 *
Scott Main60dd5202012-06-23 00:01:22 -07001832 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001833 * @see PackageManager#resolveActivity
1834 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001835 public abstract void startActivity(@RequiresPermission Intent intent,
1836 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001837
1838 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001839 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1840 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001841 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001842 * @param intent The description of the activity to start.
1843 * @param options Additional options for how the Activity should be started.
1844 * May be null if there are no options. See {@link android.app.ActivityOptions}
1845 * for how to build the Bundle supplied here; there are no supported definitions
1846 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001847 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001848 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001849 * @hide
1850 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001851 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001852 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001853 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1854 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001855 throw new RuntimeException("Not implemented. Must override in a subclass.");
1856 }
1857
1858 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001859 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1860 * is only supported for Views and Fragments.
1861 * @param who The identifier for the calling element that will receive the result.
1862 * @param intent The intent to start.
1863 * @param requestCode The code that will be returned with onActivityResult() identifying this
1864 * request.
1865 * @param options Additional options for how the Activity should be started.
1866 * May be null if there are no options. See {@link android.app.ActivityOptions}
1867 * for how to build the Bundle supplied here; there are no supported definitions
1868 * for building it manually.
1869 * @hide
1870 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001871 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001872 public void startActivityForResult(
1873 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1874 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1875 + "Check canStartActivityForResult() before calling.");
1876 }
1877
1878 /**
1879 * Identifies whether this Context instance will be able to process calls to
1880 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1881 * @hide
1882 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001883 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001884 public boolean canStartActivityForResult() {
1885 return false;
1886 }
1887
1888 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001889 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1890 * specified.
1891 *
1892 * @param intents An array of Intents to be started.
1893 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001894 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001895 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001896 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001897 * @see PackageManager#resolveActivity
1898 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001899 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001900
1901 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001902 * Launch multiple new activities. This is generally the same as calling
1903 * {@link #startActivity(Intent)} for the first Intent in the array,
1904 * that activity during its creation calling {@link #startActivity(Intent)}
1905 * for the second entry, etc. Note that unlike that approach, generally
1906 * none of the activities except the last in the array will be created
1907 * at this point, but rather will be created when the user first visits
1908 * them (due to pressing back from the activity on top).
1909 *
1910 * <p>This method throws {@link ActivityNotFoundException}
1911 * if there was no Activity found for <em>any</em> given Intent. In this
1912 * case the state of the activity stack is undefined (some Intents in the
1913 * list may be on it, some not), so you probably want to avoid such situations.
1914 *
1915 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001916 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001917 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001918 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001919 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001920 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001921 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001922 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001923 * @see PackageManager#resolveActivity
1924 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001925 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001926
1927 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001928 * @hide
1929 * Launch multiple new activities. This is generally the same as calling
1930 * {@link #startActivity(Intent)} for the first Intent in the array,
1931 * that activity during its creation calling {@link #startActivity(Intent)}
1932 * for the second entry, etc. Note that unlike that approach, generally
1933 * none of the activities except the last in the array will be created
1934 * at this point, but rather will be created when the user first visits
1935 * them (due to pressing back from the activity on top).
1936 *
1937 * <p>This method throws {@link ActivityNotFoundException}
1938 * if there was no Activity found for <em>any</em> given Intent. In this
1939 * case the state of the activity stack is undefined (some Intents in the
1940 * list may be on it, some not), so you probably want to avoid such situations.
1941 *
1942 * @param intents An array of Intents to be started.
1943 * @param options Additional options for how the Activity should be started.
1944 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001945 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001946 * Context.startActivity(Intent, Bundle)} for more details.
1947 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001948 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1949 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1950 * successful.
1951 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001952 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001953 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001954 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001955 * @see PackageManager#resolveActivity
1956 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001957 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001958 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001959 throw new RuntimeException("Not implemented. Must override in a subclass.");
1960 }
1961
1962 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001963 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1964 * with no options specified.
1965 *
1966 * @param intent The IntentSender to launch.
1967 * @param fillInIntent If non-null, this will be provided as the
1968 * intent parameter to {@link IntentSender#sendIntent}.
1969 * @param flagsMask Intent flags in the original IntentSender that you
1970 * would like to change.
1971 * @param flagsValues Desired values for any bits set in
1972 * <var>flagsMask</var>
1973 * @param extraFlags Always set to 0.
1974 *
1975 * @see #startActivity(Intent)
1976 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1977 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001978 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1979 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1980 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001981
1982 /**
1983 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001984 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001985 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001986 * here; otherwise, its associated action will be executed (such as
1987 * sending a broadcast) as if you had called
1988 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001989 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001990 * @param intent The IntentSender to launch.
1991 * @param fillInIntent If non-null, this will be provided as the
1992 * intent parameter to {@link IntentSender#sendIntent}.
1993 * @param flagsMask Intent flags in the original IntentSender that you
1994 * would like to change.
1995 * @param flagsValues Desired values for any bits set in
1996 * <var>flagsMask</var>
1997 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001998 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001999 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07002000 * Context.startActivity(Intent, Bundle)} for more details. If options
2001 * have also been supplied by the IntentSender, options given here will
2002 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07002003 *
2004 * @see #startActivity(Intent, Bundle)
2005 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002006 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002007 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
2008 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
2009 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002010
2011 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002012 * Broadcast the given intent to all interested BroadcastReceivers. This
2013 * call is asynchronous; it returns immediately, and you will continue
2014 * executing while the receivers are run. No results are propagated from
2015 * receivers and receivers can not abort the broadcast. If you want
2016 * to allow receivers to propagate results or abort the broadcast, you must
2017 * send an ordered broadcast using
2018 * {@link #sendOrderedBroadcast(Intent, String)}.
2019 *
2020 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2021 *
2022 * @param intent The Intent to broadcast; all receivers matching this
2023 * Intent will receive the broadcast.
2024 *
2025 * @see android.content.BroadcastReceiver
2026 * @see #registerReceiver
2027 * @see #sendBroadcast(Intent, String)
2028 * @see #sendOrderedBroadcast(Intent, String)
2029 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2030 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002031 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032
2033 /**
2034 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2035 * an optional required permission to be enforced. This
2036 * call is asynchronous; it returns immediately, and you will continue
2037 * executing while the receivers are run. No results are propagated from
2038 * receivers and receivers can not abort the broadcast. If you want
2039 * to allow receivers to propagate results or abort the broadcast, you must
2040 * send an ordered broadcast using
2041 * {@link #sendOrderedBroadcast(Intent, String)}.
2042 *
2043 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2044 *
2045 * @param intent The Intent to broadcast; all receivers matching this
2046 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08002047 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 * a receiver must hold in order to receive your broadcast.
2049 * If null, no permission is required.
2050 *
2051 * @see android.content.BroadcastReceiver
2052 * @see #registerReceiver
2053 * @see #sendBroadcast(Intent)
2054 * @see #sendOrderedBroadcast(Intent, String)
2055 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2056 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002057 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002058 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002060
2061 /**
2062 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2063 * an array of required permissions to be enforced. This call is asynchronous; it returns
2064 * immediately, and you will continue executing while the receivers are run. No results are
2065 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2066 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2067 * using {@link #sendOrderedBroadcast(Intent, String)}.
2068 *
2069 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2070 *
2071 * @param intent The Intent to broadcast; all receivers matching this
2072 * Intent will receive the broadcast.
2073 * @param receiverPermissions Array of names of permissions that a receiver must hold
2074 * in order to receive your broadcast.
Roshan Pius3fe42f02019-11-12 09:56:48 -08002075 * If empty, no permissions are required.
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002076 *
2077 * @see android.content.BroadcastReceiver
2078 * @see #registerReceiver
2079 * @see #sendBroadcast(Intent)
2080 * @see #sendOrderedBroadcast(Intent, String)
2081 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2082 * @hide
2083 */
Roshan Pius3fe42f02019-11-12 09:56:48 -08002084 public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2085 @NonNull String[] receiverPermissions) {
2086 throw new RuntimeException("Not implemented. Must override in a subclass.");
2087 }
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002088
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002089 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002090 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07002091 * an array of required permissions to be enforced. This call is asynchronous; it returns
2092 * immediately, and you will continue executing while the receivers are run. No results are
2093 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2094 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2095 * using {@link #sendOrderedBroadcast(Intent, String)}.
2096 *
2097 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2098 *
2099 * @param intent The Intent to broadcast; all receivers matching this
2100 * Intent will receive the broadcast.
Roshan Piusa2baf58e2019-11-20 14:40:30 -08002101 * @param receiverPermissions Array of names of permissions that a receiver must hold
2102 * in order to receive your broadcast.
2103 * If empty, no permissions are required.
2104 *
2105 * @see android.content.BroadcastReceiver
2106 * @see #registerReceiver
2107 * @see #sendBroadcast(Intent)
2108 * @see #sendOrderedBroadcast(Intent, String)
2109 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2110 */
2111 public void sendBroadcastWithMultiplePermissions(@NonNull Intent intent,
2112 @NonNull String[] receiverPermissions) {
2113 sendBroadcastMultiplePermissions(intent, receiverPermissions);
2114 }
2115
2116 /**
2117 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2118 * an array of required permissions to be enforced. This call is asynchronous; it returns
2119 * immediately, and you will continue executing while the receivers are run. No results are
2120 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2121 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2122 * using {@link #sendOrderedBroadcast(Intent, String)}.
2123 *
2124 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2125 *
2126 * @param intent The Intent to broadcast; all receivers matching this
2127 * Intent will receive the broadcast.
Tyler Gunnf955e562018-04-26 14:43:31 -07002128 * @param user The user to send the broadcast to.
2129 * @param receiverPermissions Array of names of permissions that a receiver must hold
2130 * in order to receive your broadcast.
2131 * If null or empty, no permissions are required.
2132 *
2133 * @see android.content.BroadcastReceiver
2134 * @see #registerReceiver
2135 * @see #sendBroadcast(Intent)
2136 * @see #sendOrderedBroadcast(Intent, String)
2137 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2138 * @hide
2139 */
2140 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2141 String[] receiverPermissions);
2142
2143 /**
2144 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002145 * an optional required permission to be enforced. This
2146 * call is asynchronous; it returns immediately, and you will continue
2147 * executing while the receivers are run. No results are propagated from
2148 * receivers and receivers can not abort the broadcast. If you want
2149 * to allow receivers to propagate results or abort the broadcast, you must
2150 * send an ordered broadcast using
2151 * {@link #sendOrderedBroadcast(Intent, String)}.
2152 *
2153 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2154 *
2155 * @param intent The Intent to broadcast; all receivers matching this
2156 * Intent will receive the broadcast.
2157 * @param receiverPermission (optional) String naming a permission that
2158 * a receiver must hold in order to receive your broadcast.
2159 * If null, no permission is required.
2160 * @param options (optional) Additional sending options, generated from a
2161 * {@link android.app.BroadcastOptions}.
2162 *
2163 * @see android.content.BroadcastReceiver
2164 * @see #registerReceiver
2165 * @see #sendBroadcast(Intent)
2166 * @see #sendOrderedBroadcast(Intent, String)
2167 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2168 * @hide
2169 */
2170 @SystemApi
2171 public abstract void sendBroadcast(Intent intent,
2172 @Nullable String receiverPermission,
2173 @Nullable Bundle options);
2174
2175 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002176 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002177 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002178 * @hide
2179 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002180 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002181 public abstract void sendBroadcast(Intent intent,
2182 String receiverPermission, int appOp);
2183
2184 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2186 * them one at a time to allow more preferred receivers to consume the
2187 * broadcast before it is delivered to less preferred receivers. This
2188 * call is asynchronous; it returns immediately, and you will continue
2189 * executing while the receivers are run.
2190 *
2191 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2192 *
2193 * @param intent The Intent to broadcast; all receivers matching this
2194 * Intent will receive the broadcast.
2195 * @param receiverPermission (optional) String naming a permissions that
2196 * a receiver must hold in order to receive your broadcast.
2197 * If null, no permission is required.
2198 *
2199 * @see android.content.BroadcastReceiver
2200 * @see #registerReceiver
2201 * @see #sendBroadcast(Intent)
2202 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2203 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002204 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002205 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002206
2207 /**
2208 * Version of {@link #sendBroadcast(Intent)} that allows you to
2209 * receive data back from the broadcast. This is accomplished by
2210 * supplying your own BroadcastReceiver when calling, which will be
2211 * treated as a final receiver at the end of the broadcast -- its
2212 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002213 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002214 * be serialized in the same way as calling
2215 * {@link #sendOrderedBroadcast(Intent, String)}.
2216 *
2217 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2218 * asynchronous; it will return before
2219 * resultReceiver.onReceive() is called.
2220 *
2221 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2222 *
2223 * @param intent The Intent to broadcast; all receivers matching this
2224 * Intent will receive the broadcast.
2225 * @param receiverPermission String naming a permissions that
2226 * a receiver must hold in order to receive your broadcast.
2227 * If null, no permission is required.
2228 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2229 * receiver of the broadcast.
2230 * @param scheduler A custom Handler with which to schedule the
2231 * resultReceiver callback; if null it will be
2232 * scheduled in the Context's main thread.
2233 * @param initialCode An initial value for the result code. Often
2234 * Activity.RESULT_OK.
2235 * @param initialData An initial value for the result data. Often
2236 * null.
2237 * @param initialExtras An initial value for the result extras. Often
2238 * null.
2239 *
2240 * @see #sendBroadcast(Intent)
2241 * @see #sendBroadcast(Intent, String)
2242 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002243 * @see android.content.BroadcastReceiver
2244 * @see #registerReceiver
2245 * @see android.app.Activity#RESULT_OK
2246 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002247 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002248 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002249 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2250 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002251
2252 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002253 * Version of {@link #sendBroadcast(Intent)} that allows you to
2254 * receive data back from the broadcast. This is accomplished by
2255 * supplying your own BroadcastReceiver when calling, which will be
2256 * treated as a final receiver at the end of the broadcast -- its
2257 * {@link BroadcastReceiver#onReceive} method will be called with
2258 * the result values collected from the other receivers. The broadcast will
2259 * be serialized in the same way as calling
2260 * {@link #sendOrderedBroadcast(Intent, String)}.
2261 *
2262 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2263 * asynchronous; it will return before
2264 * resultReceiver.onReceive() is called.
2265 *
2266 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2267 *
2268 *
2269 * @param intent The Intent to broadcast; all receivers matching this
2270 * Intent will receive the broadcast.
2271 * @param receiverPermission String naming a permissions that
2272 * a receiver must hold in order to receive your broadcast.
2273 * If null, no permission is required.
2274 * @param options (optional) Additional sending options, generated from a
2275 * {@link android.app.BroadcastOptions}.
2276 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2277 * receiver of the broadcast.
2278 * @param scheduler A custom Handler with which to schedule the
2279 * resultReceiver callback; if null it will be
2280 * scheduled in the Context's main thread.
2281 * @param initialCode An initial value for the result code. Often
2282 * Activity.RESULT_OK.
2283 * @param initialData An initial value for the result data. Often
2284 * null.
2285 * @param initialExtras An initial value for the result extras. Often
2286 * null.
2287 * @see #sendBroadcast(Intent)
2288 * @see #sendBroadcast(Intent, String)
2289 * @see #sendOrderedBroadcast(Intent, String)
2290 * @see android.content.BroadcastReceiver
2291 * @see #registerReceiver
2292 * @see android.app.Activity#RESULT_OK
2293 * @hide
2294 */
2295 @SystemApi
2296 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2297 @Nullable String receiverPermission, @Nullable Bundle options,
2298 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2299 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2300
2301 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002302 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2303 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002304 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002305 * @hide
2306 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002307 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002308 public abstract void sendOrderedBroadcast(Intent intent,
2309 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2310 Handler scheduler, int initialCode, String initialData,
2311 Bundle initialExtras);
2312
2313 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002314 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2315 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002316 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002317 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002318 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002319 * @see #sendBroadcast(Intent)
2320 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002321 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002322 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2323 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002324
2325 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002326 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2327 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002328 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002329 *
2330 * @param intent The Intent to broadcast; all receivers matching this
2331 * Intent will receive the broadcast.
2332 * @param user UserHandle to send the intent to.
2333 * @param receiverPermission (optional) String naming a permission that
2334 * a receiver must hold in order to receive your broadcast.
2335 * If null, no permission is required.
2336 *
2337 * @see #sendBroadcast(Intent, String)
2338 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002339 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002340 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2341 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002342
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002343 /**
2344 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2345 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002346 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002347 *
2348 * @param intent The Intent to broadcast; all receivers matching this
2349 * Intent will receive the broadcast.
2350 * @param user UserHandle to send the intent to.
2351 * @param receiverPermission (optional) String naming a permission that
2352 * a receiver must hold in order to receive your broadcast.
2353 * If null, no permission is required.
2354 * @param options (optional) Additional sending options, generated from a
2355 * {@link android.app.BroadcastOptions}.
2356 *
2357 * @see #sendBroadcast(Intent, String, Bundle)
2358 * @hide
2359 */
2360 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002361 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002362 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2363 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002364
2365 /**
2366 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2367 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002368 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002369 *
2370 * @param intent The Intent to broadcast; all receivers matching this
2371 * Intent will receive the broadcast.
2372 * @param user UserHandle to send the intent to.
2373 * @param receiverPermission (optional) String naming a permission that
2374 * a receiver must hold in order to receive your broadcast.
2375 * If null, no permission is required.
2376 * @param appOp The app op associated with the broadcast.
2377 *
2378 * @see #sendBroadcast(Intent, String)
2379 *
2380 * @hide
2381 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002382 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002383 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002384 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2385 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002386
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002387 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002388 * Version of
2389 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2390 * that allows you to specify the
2391 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002392 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002393 *
2394 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2395 *
2396 * @param intent The Intent to broadcast; all receivers matching this
2397 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002398 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002399 * @param receiverPermission String naming a permissions that
2400 * a receiver must hold in order to receive your broadcast.
2401 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002402 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2403 * receiver of the broadcast.
2404 * @param scheduler A custom Handler with which to schedule the
2405 * resultReceiver callback; if null it will be
2406 * scheduled in the Context's main thread.
2407 * @param initialCode An initial value for the result code. Often
2408 * Activity.RESULT_OK.
2409 * @param initialData An initial value for the result data. Often
2410 * null.
2411 * @param initialExtras An initial value for the result extras. Often
2412 * null.
2413 *
2414 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2415 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002416 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002417 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2418 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002419 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2420 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002421
2422 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002423 * Similar to above but takes an appOp as well, to enforce restrictions.
2424 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2425 * BroadcastReceiver, Handler, int, String, Bundle)
2426 * @hide
2427 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002428 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002429 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002430 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2431 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2432 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2433 @Nullable Bundle initialExtras);
2434
2435 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002436 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2437 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2438 * BroadcastReceiver, Handler, int, String, Bundle)
2439 * @hide
2440 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002441 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002442 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002443 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2444 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2445 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2446 @Nullable String initialData, @Nullable Bundle initialExtras);
2447
2448 /**
Jordan Liu54735532019-10-29 10:33:55 -07002449 * Version of
2450 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2451 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2452 * the broadcast will be sent to.
2453 *
2454 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2455 *
2456 * @param intent The Intent to broadcast; all receivers matching this
2457 * Intent will receive the broadcast.
2458 * @param receiverPermission String naming a permissions that
2459 * a receiver must hold in order to receive your broadcast.
2460 * If null, no permission is required.
2461 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2462 * required. If both receiverAppOp and receiverPermission are non-null,
2463 * a receiver must have both of them to
2464 * receive the broadcast
2465 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2466 * receiver of the broadcast.
2467 * @param scheduler A custom Handler with which to schedule the
2468 * resultReceiver callback; if null it will be
2469 * scheduled in the Context's main thread.
2470 * @param initialCode An initial value for the result code. Often
2471 * Activity.RESULT_OK.
2472 * @param initialData An initial value for the result data. Often
2473 * null.
2474 * @param initialExtras An initial value for the result extras. Often
2475 * null.
2476 *
2477 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2478 */
Jordan Liu31a4da62019-11-19 11:36:34 -08002479 public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission,
2480 @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
2481 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2482 @Nullable Bundle initialExtras) {
Jordan Liu54735532019-10-29 10:33:55 -07002483 throw new RuntimeException("Not implemented. Must override in a subclass.");
2484 }
2485
2486 /**
Peter Wang7701f572019-11-07 16:57:23 -08002487 * Version of
2488 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2489 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2490 * the broadcast will be sent to as well as supply an optional sending options
2491 *
2492 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2493 *
2494 * @param intent The Intent to broadcast; all receivers matching this
2495 * Intent will receive the broadcast.
2496 * @param receiverPermission String naming a permissions that
2497 * a receiver must hold in order to receive your broadcast.
2498 * If null, no permission is required.
2499 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2500 * required. If both receiverAppOp and receiverPermission are non-null,
2501 * a receiver must have both of them to
2502 * receive the broadcast
2503 * @param options (optional) Additional sending options, generated from a
2504 * {@link android.app.BroadcastOptions}.
2505 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2506 * receiver of the broadcast.
2507 * @param scheduler A custom Handler with which to schedule the
2508 * resultReceiver callback; if null it will be
2509 * scheduled in the Context's main thread.
2510 * @param initialCode An initial value for the result code. Often
2511 * Activity.RESULT_OK.
2512 * @param initialData An initial value for the result data. Often
2513 * null.
2514 * @param initialExtras An initial value for the result extras. Often
2515 * null.
2516 *
2517 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2518 * @see android.app.BroadcastOptions
2519 */
2520 public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2521 @Nullable String receiverPermission, @Nullable String receiverAppOp,
2522 @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver,
2523 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2524 @Nullable Bundle initialExtras) {
2525 throw new RuntimeException("Not implemented. Must override in a subclass.");
2526 }
2527
2528 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002529 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002530 * Intent you are sending stays around after the broadcast is complete,
2531 * so that others can quickly retrieve that data through the return
2532 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2533 * all other ways, this behaves the same as
2534 * {@link #sendBroadcast(Intent)}.
2535 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002536 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2537 * can access them), no protection (anyone can modify them), and many other problems.
2538 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2539 * has changed, with another mechanism for apps to retrieve the current value whenever
2540 * desired.
2541 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002542 * @param intent The Intent to broadcast; all receivers matching this
2543 * Intent will receive the broadcast, and the Intent will be held to
2544 * be re-broadcast to future receivers.
2545 *
2546 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002547 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002548 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002549 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002550 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002551 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002552
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002553 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002554 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002555 * receive data back from the broadcast. This is accomplished by
2556 * supplying your own BroadcastReceiver when calling, which will be
2557 * treated as a final receiver at the end of the broadcast -- its
2558 * {@link BroadcastReceiver#onReceive} method will be called with
2559 * the result values collected from the other receivers. The broadcast will
2560 * be serialized in the same way as calling
2561 * {@link #sendOrderedBroadcast(Intent, String)}.
2562 *
2563 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2564 * asynchronous; it will return before
2565 * resultReceiver.onReceive() is called. Note that the sticky data
2566 * stored is only the data you initially supply to the broadcast, not
2567 * the result of any changes made by the receivers.
2568 *
2569 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2570 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002571 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2572 * can access them), no protection (anyone can modify them), and many other problems.
2573 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2574 * has changed, with another mechanism for apps to retrieve the current value whenever
2575 * desired.
2576 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002577 * @param intent The Intent to broadcast; all receivers matching this
2578 * Intent will receive the broadcast.
2579 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2580 * receiver of the broadcast.
2581 * @param scheduler A custom Handler with which to schedule the
2582 * resultReceiver callback; if null it will be
2583 * scheduled in the Context's main thread.
2584 * @param initialCode An initial value for the result code. Often
2585 * Activity.RESULT_OK.
2586 * @param initialData An initial value for the result data. Often
2587 * null.
2588 * @param initialExtras An initial value for the result extras. Often
2589 * null.
2590 *
2591 * @see #sendBroadcast(Intent)
2592 * @see #sendBroadcast(Intent, String)
2593 * @see #sendOrderedBroadcast(Intent, String)
2594 * @see #sendStickyBroadcast(Intent)
2595 * @see android.content.BroadcastReceiver
2596 * @see #registerReceiver
2597 * @see android.app.Activity#RESULT_OK
2598 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002599 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002600 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002601 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002602 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002603 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2604 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002605
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002606 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002607 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 * so that it is as if the sticky broadcast had never happened.
2609 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002610 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2611 * can access them), no protection (anyone can modify them), and many other problems.
2612 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2613 * has changed, with another mechanism for apps to retrieve the current value whenever
2614 * desired.
2615 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002616 * @param intent The Intent that was previously broadcast.
2617 *
2618 * @see #sendStickyBroadcast
2619 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002620 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002621 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002622 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623
2624 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002625 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002626 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002627 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002628 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002629 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2630 * can access them), no protection (anyone can modify them), and many other problems.
2631 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2632 * has changed, with another mechanism for apps to retrieve the current value whenever
2633 * desired.
2634 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002635 * @param intent The Intent to broadcast; all receivers matching this
2636 * Intent will receive the broadcast, and the Intent will be held to
2637 * be re-broadcast to future receivers.
2638 * @param user UserHandle to send the intent to.
2639 *
2640 * @see #sendBroadcast(Intent)
2641 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002642 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002643 @RequiresPermission(allOf = {
2644 android.Manifest.permission.INTERACT_ACROSS_USERS,
2645 android.Manifest.permission.BROADCAST_STICKY
2646 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002647 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2648 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002649
2650 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002651 * @hide
2652 * This is just here for sending CONNECTIVITY_ACTION.
2653 */
2654 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002655 @RequiresPermission(allOf = {
2656 android.Manifest.permission.INTERACT_ACROSS_USERS,
2657 android.Manifest.permission.BROADCAST_STICKY
2658 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002659 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2660 UserHandle user, Bundle options);
2661
2662 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002663 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002664 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2665 * that allows you to specify the
2666 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002667 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002668 *
2669 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2670 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002671 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2672 * can access them), no protection (anyone can modify them), and many other problems.
2673 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2674 * has changed, with another mechanism for apps to retrieve the current value whenever
2675 * desired.
2676 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002677 * @param intent The Intent to broadcast; all receivers matching this
2678 * Intent will receive the broadcast.
2679 * @param user UserHandle to send the intent to.
2680 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2681 * receiver of the broadcast.
2682 * @param scheduler A custom Handler with which to schedule the
2683 * resultReceiver callback; if null it will be
2684 * scheduled in the Context's main thread.
2685 * @param initialCode An initial value for the result code. Often
2686 * Activity.RESULT_OK.
2687 * @param initialData An initial value for the result data. Often
2688 * null.
2689 * @param initialExtras An initial value for the result extras. Often
2690 * null.
2691 *
2692 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2693 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002694 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002695 @RequiresPermission(allOf = {
2696 android.Manifest.permission.INTERACT_ACROSS_USERS,
2697 android.Manifest.permission.BROADCAST_STICKY
2698 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002699 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002700 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002701 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2702 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002703
2704 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002705 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002706 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002707 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002708 *
2709 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2710 * permission in order to use this API. If you do not hold that
2711 * permission, {@link SecurityException} will be thrown.
2712 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002713 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2714 * can access them), no protection (anyone can modify them), and many other problems.
2715 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2716 * has changed, with another mechanism for apps to retrieve the current value whenever
2717 * desired.
2718 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002719 * @param intent The Intent that was previously broadcast.
2720 * @param user UserHandle to remove the sticky broadcast from.
2721 *
2722 * @see #sendStickyBroadcastAsUser
2723 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002724 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002725 @RequiresPermission(allOf = {
2726 android.Manifest.permission.INTERACT_ACROSS_USERS,
2727 android.Manifest.permission.BROADCAST_STICKY
2728 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002729 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2730 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002731
2732 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002733 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002734 * <var>receiver</var> will be called with any broadcast Intent that
2735 * matches <var>filter</var>, in the main application thread.
2736 *
2737 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002738 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002739 * registrations. If your IntentFilter matches one of these sticky
2740 * Intents, that Intent will be returned by this function
2741 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2742 * been broadcast.
2743 *
2744 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2745 * in which case each of these will be sent to <var>receiver</var>. In
2746 * this case, only one of these can be returned directly by the function;
2747 * which of these that is returned is arbitrarily decided by the system.
2748 *
2749 * <p>If you know the Intent your are registering for is sticky, you can
2750 * supply null for your <var>receiver</var>. In this case, no receiver is
2751 * registered -- the function simply returns the sticky Intent that
2752 * matches <var>filter</var>. In the case of multiple matches, the same
2753 * rules as described above apply.
2754 *
2755 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2756 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002757 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2758 * registered with this method will correctly respect the
2759 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2760 * Prior to that, it would be ignored and delivered to all matching registered
2761 * receivers. Be careful if using this for security.</p>
2762 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002763 * <p class="note">Note: this method <em>cannot be called from a
2764 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2765 * that is declared in an application's manifest. It is okay, however, to call
2766 * this method from another BroadcastReceiver that has itself been registered
2767 * at run time with {@link #registerReceiver}, since the lifetime of such a
2768 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002769 *
2770 * @param receiver The BroadcastReceiver to handle the broadcast.
2771 * @param filter Selects the Intent broadcasts to be received.
2772 *
2773 * @return The first sticky intent found that matches <var>filter</var>,
2774 * or null if there are none.
2775 *
2776 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2777 * @see #sendBroadcast
2778 * @see #unregisterReceiver
2779 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002780 @Nullable
2781 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002782 IntentFilter filter);
2783
2784 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002785 * Register to receive intent broadcasts, with the receiver optionally being
2786 * exposed to Instant Apps. See
2787 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2788 * information. By default Instant Apps cannot interact with receivers in other
2789 * applications, this allows you to expose a receiver that Instant Apps can
2790 * interact with.
2791 *
2792 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2793 *
2794 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2795 * registered with this method will correctly respect the
2796 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2797 * Prior to that, it would be ignored and delivered to all matching registered
2798 * receivers. Be careful if using this for security.</p>
2799 *
2800 * @param receiver The BroadcastReceiver to handle the broadcast.
2801 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002802 * @param flags Additional options for the receiver. May be 0 or
2803 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002804 *
2805 * @return The first sticky intent found that matches <var>filter</var>,
2806 * or null if there are none.
2807 *
2808 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2809 * @see #sendBroadcast
2810 * @see #unregisterReceiver
2811 */
2812 @Nullable
2813 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2814 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002815 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002816
2817 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 * Register to receive intent broadcasts, to run in the context of
2819 * <var>scheduler</var>. See
2820 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2821 * information. This allows you to enforce permissions on who can
2822 * broadcast intents to your receiver, or have the receiver run in
2823 * a different thread than the main application thread.
2824 *
2825 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2826 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002827 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2828 * registered with this method will correctly respect the
2829 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2830 * Prior to that, it would be ignored and delivered to all matching registered
2831 * receivers. Be careful if using this for security.</p>
2832 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 * @param receiver The BroadcastReceiver to handle the broadcast.
2834 * @param filter Selects the Intent broadcasts to be received.
2835 * @param broadcastPermission String naming a permissions that a
2836 * broadcaster must hold in order to send an Intent to you. If null,
2837 * no permission is required.
2838 * @param scheduler Handler identifying the thread that will receive
2839 * the Intent. If null, the main thread of the process will be used.
2840 *
2841 * @return The first sticky intent found that matches <var>filter</var>,
2842 * or null if there are none.
2843 *
2844 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2845 * @see #sendBroadcast
2846 * @see #unregisterReceiver
2847 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002848 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002849 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002850 IntentFilter filter, @Nullable String broadcastPermission,
2851 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002852
2853 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002854 * Register to receive intent broadcasts, to run in the context of
2855 * <var>scheduler</var>. See
2856 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002857 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2858 * for more information.
2859 *
2860 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2861 *
2862 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2863 * registered with this method will correctly respect the
2864 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2865 * Prior to that, it would be ignored and delivered to all matching registered
2866 * receivers. Be careful if using this for security.</p>
2867 *
2868 * @param receiver The BroadcastReceiver to handle the broadcast.
2869 * @param filter Selects the Intent broadcasts to be received.
2870 * @param broadcastPermission String naming a permissions that a
2871 * broadcaster must hold in order to send an Intent to you. If null,
2872 * no permission is required.
2873 * @param scheduler Handler identifying the thread that will receive
2874 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002875 * @param flags Additional options for the receiver. May be 0 or
2876 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002877 *
2878 * @return The first sticky intent found that matches <var>filter</var>,
2879 * or null if there are none.
2880 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002881 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002882 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2883 * @see #sendBroadcast
2884 * @see #unregisterReceiver
2885 */
2886 @Nullable
2887 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2888 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002889 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002890
2891 /**
Meng Wang3f9e0362019-11-05 10:43:45 -08002892 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2893 * but this receiver will receive broadcasts that are sent to all users. The receiver can
2894 * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
2895 * was sent.
2896 *
2897 * @param receiver The BroadcastReceiver to handle the broadcast.
2898 * @param filter Selects the Intent broadcasts to be received.
2899 * @param broadcastPermission String naming a permissions that a
2900 * broadcaster must hold in order to send an Intent to you. If {@code null},
2901 * no permission is required.
2902 * @param scheduler Handler identifying the thread that will receive
2903 * the Intent. If {@code null}, the main thread of the process will be used.
2904 *
2905 * @return The first sticky intent found that matches <var>filter</var>,
2906 * or {@code null} if there are none.
2907 *
2908 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2909 * @see #sendBroadcast
2910 * @see #unregisterReceiver
2911 * @hide
2912 */
2913 @Nullable
2914 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
2915 @SystemApi
2916 public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
2917 @NonNull IntentFilter filter, @Nullable String broadcastPermission,
2918 @Nullable Handler scheduler) {
2919 throw new RuntimeException("Not implemented. Must override in a subclass.");
2920 }
2921
2922 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002923 * @hide
2924 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2925 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002926 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002927 *
2928 * @param receiver The BroadcastReceiver to handle the broadcast.
2929 * @param user UserHandle to send the intent to.
2930 * @param filter Selects the Intent broadcasts to be received.
2931 * @param broadcastPermission String naming a permissions that a
2932 * broadcaster must hold in order to send an Intent to you. If null,
2933 * no permission is required.
2934 * @param scheduler Handler identifying the thread that will receive
2935 * the Intent. If null, the main thread of the process will be used.
2936 *
2937 * @return The first sticky intent found that matches <var>filter</var>,
2938 * or null if there are none.
2939 *
Jeff Brown6e539312015-02-24 18:53:21 -08002940 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002941 * @see #sendBroadcast
2942 * @see #unregisterReceiver
2943 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002944 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002945 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002946 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002947 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002948 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2949 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002950
2951 /**
2952 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2953 * filters that have been registered for this BroadcastReceiver will be
2954 * removed.
2955 *
2956 * @param receiver The BroadcastReceiver to unregister.
2957 *
2958 * @see #registerReceiver
2959 */
2960 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2961
2962 /**
2963 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002964 * should either contain the complete class name of a specific service
2965 * implementation to start, or a specific package name to target. If the
2966 * Intent is less specified, it logs a warning about this. In this case any of the
2967 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 * is not already running, it will be instantiated and started (creating a
2969 * process for it if needed); if it is running then it remains running.
2970 *
2971 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002972 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 * with the <var>intent</var> given here. This provides a convenient way
2974 * to submit jobs to a service without having to bind and call on to its
2975 * interface.
2976 *
2977 * <p>Using startService() overrides the default service lifetime that is
2978 * managed by {@link #bindService}: it requires the service to remain
2979 * running until {@link #stopService} is called, regardless of whether
2980 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002981 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 * a single call to {@link #stopService} will stop it.
2983 *
2984 * <p>The system attempts to keep running services around as much as
2985 * possible. The only time they should be stopped is if the current
2986 * foreground application is using so many resources that the service needs
2987 * to be killed. If any errors happen in the service's process, it will
2988 * automatically be restarted.
2989 *
2990 * <p>This function will throw {@link SecurityException} if you do not
2991 * have permission to start the given service.
2992 *
Chris Craik1e353522016-04-18 10:20:50 -07002993 * <p class="note"><strong>Note:</strong> Each call to startService()
2994 * results in significant work done by the system to manage service
2995 * lifecycle surrounding the processing of the intent, which can take
2996 * multiple milliseconds of CPU time. Due to this cost, startService()
2997 * should not be used for frequent intent delivery to a service, and only
2998 * for scheduling significant work. Use {@link #bindService bound services}
2999 * for high frequency calls.
3000 * </p>
3001 *
Mark Lu94ebbe02016-12-13 16:29:51 -08003002 * @param service Identifies the service to be started. The Intent must be
3003 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 * may be included in the Intent extras to supply arguments along with
3005 * this specific start call.
3006 *
3007 * @return If the service is being started or is already running, the
3008 * {@link ComponentName} of the actual service that was started is
3009 * returned; else if the service does not exist null is returned.
3010 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003011 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003012 * or the service can not be found.
3013 * @throws IllegalStateException If the application is in a state where the service
3014 * 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 -08003015 *
3016 * @see #stopService
3017 * @see #bindService
3018 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003019 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003020 public abstract ComponentName startService(Intent service);
3021
3022 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07003023 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00003024 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
3025 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07003026 * an amount of time comparable to the ANR interval to do this, otherwise the system
3027 * will automatically stop the service and declare the app ANR.
3028 *
3029 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
3030 * at any time, regardless of whether the app hosting the service is in a foreground
3031 * state.
3032 *
3033 * @param service Identifies the service to be started. The Intent must be
3034 * fully explicit (supplying a component name). Additional values
3035 * may be included in the Intent extras to supply arguments along with
3036 * this specific start call.
3037 *
3038 * @return If the service is being started or is already running, the
3039 * {@link ComponentName} of the actual service that was started is
3040 * returned; else if the service does not exist null is returned.
3041 *
3042 * @throws SecurityException If the caller does not have permission to access the service
3043 * or the service can not be found.
3044 *
3045 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00003046 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07003047 */
3048 @Nullable
3049 public abstract ComponentName startForegroundService(Intent service);
3050
3051 /**
3052 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
3053 */
3054 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003055 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07003056 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
3057
3058 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003059 * Request that a given application service be stopped. If the service is
3060 * not running, nothing happens. Otherwise it is stopped. Note that calls
3061 * to startService() are not counted -- this stops the service no matter
3062 * how many times it was started.
3063 *
3064 * <p>Note that if a stopped service still has {@link ServiceConnection}
3065 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
3066 * not be destroyed until all of these bindings are removed. See
3067 * the {@link android.app.Service} documentation for more details on a
3068 * service's lifecycle.
3069 *
3070 * <p>This function will throw {@link SecurityException} if you do not
3071 * have permission to stop the given service.
3072 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07003073 * @param service Description of the service to be stopped. The Intent must be either
3074 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07003075 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003076 *
3077 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04003078 * 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 -08003079 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003080 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003081 * or the service can not be found.
3082 * @throws IllegalStateException If the application is in a state where the service
3083 * 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 -08003084 *
3085 * @see #startService
3086 */
3087 public abstract boolean stopService(Intent service);
3088
3089 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003090 * @hide like {@link #startService(Intent)} but for a specific user.
3091 */
Christopher Tate42a386b2016-11-07 12:21:21 -08003092 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003093 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003094 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003095 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
3096
3097 /**
3098 * @hide like {@link #stopService(Intent)} but for a specific user.
3099 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003100 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003101 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08003102
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003103 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003104 * Connect to an application service, creating it if needed. This defines
3105 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003106 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107 * told if it dies and restarts. The service will be considered required
3108 * by the system only for as long as the calling context exists. For
3109 * example, if this Context is an Activity that is stopped, the service will
3110 * not be required to continue running until the Activity is resumed.
3111 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003112 * <p>If the service does not support binding, it may return {@code null} from
3113 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
3114 * the ServiceConnection's
3115 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
3116 * will be invoked instead of
3117 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
3118 *
3119 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 * have permission to bind to the given service.
3121 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003122 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003123 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003124 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003125 * {@link #startService} with the arguments containing the command to be
3126 * sent, with the service calling its
3127 * {@link android.app.Service#stopSelf(int)} method when done executing
3128 * that command. See the API demo App/Service/Service Start Arguments
3129 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003130 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
3132 * is tied to another object (the one that registered it).</p>
3133 *
Mark Lu94ebbe02016-12-13 16:29:51 -08003134 * @param service Identifies the service to connect to. The Intent must
3135 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003136 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07003137 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07003138 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07003139 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
3140 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003141 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
3142 * {@link #BIND_IMPORTANT}, or
3143 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07003144 * @return {@code true} if the system is in the process of bringing up a
3145 * service that your client has permission to bind to; {@code false}
3146 * if the system couldn't find the service or if your client doesn't
3147 * have permission to bind to it. If this value is {@code true}, you
3148 * should later call {@link #unbindService} to release the
3149 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003151 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003152 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 *
3154 * @see #unbindService
3155 * @see #startService
3156 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07003157 * @see #BIND_DEBUG_UNBIND
3158 * @see #BIND_NOT_FOREGROUND
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003159 * @see #BIND_ABOVE_CLIENT
3160 * @see #BIND_ALLOW_OOM_MANAGEMENT
3161 * @see #BIND_WAIVE_PRIORITY
3162 * @see #BIND_IMPORTANT
3163 * @see #BIND_ADJUST_WITH_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003164 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07003165 public abstract boolean bindService(@RequiresPermission Intent service,
3166 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003167
3168 /**
Bo Liu58a57662019-03-06 20:21:45 +00003169 * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control
3170 * ServiceConnection callbacks.
3171 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
3172 * instance for the same instance of ServiceConnection.
3173 */
3174 public boolean bindService(@RequiresPermission @NonNull Intent service,
3175 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
3176 @NonNull ServiceConnection conn) {
3177 throw new RuntimeException("Not implemented. Must override in a subclass.");
3178 }
3179
3180 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003181 * Variation of {@link #bindService} that, in the specific case of isolated
3182 * services, allows the caller to generate multiple instances of a service
Dianne Hackborncc67f962019-04-29 16:32:44 -07003183 * from a single component declaration. In other words, you can use this to bind
3184 * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
3185 * addition to the existing behavior of running in an isolated process, you can
3186 * also through the arguments here have the system bring up multiple concurrent
3187 * processes hosting their own instances of that service. The <var>instanceName</var>
3188 * you provide here identifies the different instances, and you can use
3189 * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
3190 * should manage each of these instances.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003191 *
3192 * @param service Identifies the service to connect to. The Intent must
3193 * specify an explicit component name.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003194 * @param flags Operation options for the binding as per {@link #bindService}.
3195 * @param instanceName Unique identifier for the service instance. Each unique
Robert Seseke3a5bc62019-04-22 17:43:03 -04003196 * name here will result in a different service instance being created. Identifiers
3197 * must only contain ASCII letters, digits, underscores, and periods.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003198 * @return Returns success of binding as per {@link #bindService}.
Bo Liu58a57662019-03-06 20:21:45 +00003199 * @param executor Callbacks on ServiceConnection will be called on executor.
3200 * Must use same instance for the same instance of ServiceConnection.
3201 * @param conn Receives information as the service is started and stopped.
3202 * This must be a valid ServiceConnection object; it must not be null.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003203 *
3204 * @throws SecurityException If the caller does not have permission to access the service
Robert Seseke3a5bc62019-04-22 17:43:03 -04003205 * @throws IllegalArgumentException If the instanceName is invalid.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003206 *
3207 * @see #bindService
Dianne Hackborncc67f962019-04-29 16:32:44 -07003208 * @see #updateServiceGroup
3209 * @see android.R.attr#isolatedProcess
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003210 */
Adrian Roosebc927c2019-02-28 16:21:18 +01003211 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
Bo Liu58a57662019-03-06 20:21:45 +00003212 @BindServiceFlags int flags, @NonNull String instanceName,
3213 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003214 throw new RuntimeException("Not implemented. Must override in a subclass.");
3215 }
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003216
3217 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003218 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003219 * argument for use by system server and other multi-user aware code.
3220 * @hide
3221 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07003222 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08003223 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003224 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07003225 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08003226 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003227 throw new RuntimeException("Not implemented. Must override in a subclass.");
3228 }
3229
3230 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003231 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
Adrian Roos691546e2016-02-09 10:13:41 -08003232 * explicit non-null Handler to run the ServiceConnection callbacks on.
3233 *
3234 * @hide
3235 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003236 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood7bcc1742019-07-04 11:39:42 +01003237 @UnsupportedAppUsage(trackingBug = 136728678)
Adrian Roos691546e2016-02-09 10:13:41 -08003238 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3239 Handler handler, UserHandle user) {
3240 throw new RuntimeException("Not implemented. Must override in a subclass.");
3241 }
3242
3243 /**
Dianne Hackborna631d562018-11-20 15:58:15 -08003244 * For a service previously bound with {@link #bindService} or a related method, change
3245 * how the system manages that service's process in relation to other processes. This
3246 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3247 * how the process will be managed in some cases based on those flags. Currently only
3248 * works on isolated processes (will be ignored for non-isolated processes).
3249 *
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -08003250 * <p>Note that this call does not take immediate effect, but will be applied the next
3251 * time the impacted process is adjusted for some other reason. Typically you would
3252 * call this before then calling a new {@link #bindIsolatedService} on the service
3253 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3254 *
Dianne Hackborna631d562018-11-20 15:58:15 -08003255 * @param conn The connection interface previously supplied to bindService(). This
3256 * parameter must not be null.
3257 * @param group A group to put this connection's process in. Upon calling here, this
3258 * will override any previous group that was set for that process. The group
3259 * tells the system about processes that are logically grouped together, so
3260 * should be managed as one unit of importance (such as when being considered
3261 * a recently used app). All processes in the same app with the same group
3262 * are considered to be related. Supplying 0 reverts to the default behavior
3263 * of not grouping.
3264 * @param importance Additional importance of the processes within a group. Upon calling
Dianne Hackborncc67f962019-04-29 16:32:44 -07003265 * here, this will override any previous importance that was set for that
3266 * process. The most important process is 0, and higher values are
3267 * successively less important. You can view this as describing how
3268 * to order the processes in an array, with the processes at the end of
3269 * the array being the least important. This value has no meaning besides
3270 * indicating how processes should be ordered in that array one after the
3271 * other. This provides a way to fine-tune the system's process killing,
3272 * guiding it to kill processes at the end of the array first.
3273 *
3274 * @see #bindIsolatedService
Dianne Hackborna631d562018-11-20 15:58:15 -08003275 */
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003276 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3277 int importance) {
3278 throw new RuntimeException("Not implemented. Must override in a subclass.");
3279 }
Dianne Hackborna631d562018-11-20 15:58:15 -08003280
3281 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003282 * Disconnect from an application service. You will no longer receive
3283 * calls as the service is restarted, and the service is now allowed to
3284 * stop at any time.
3285 *
3286 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07003287 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003288 *
3289 * @see #bindService
3290 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003291 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292
3293 /**
3294 * Start executing an {@link android.app.Instrumentation} class. The given
3295 * Instrumentation component will be run by killing its target application
3296 * (if currently running), starting the target process, instantiating the
3297 * instrumentation component, and then letting it drive the application.
3298 *
3299 * <p>This function is not synchronous -- it returns as soon as the
3300 * instrumentation has started and while it is running.
3301 *
3302 * <p>Instrumentation is normally only allowed to run against a package
3303 * that is either unsigned or signed with a signature that the
3304 * the instrumentation package is also signed with (ensuring the target
3305 * trusts the instrumentation).
3306 *
3307 * @param className Name of the Instrumentation component to be run.
3308 * @param profileFile Optional path to write profiling data as the
3309 * instrumentation runs, or null for no profiling.
3310 * @param arguments Additional optional arguments to pass to the
3311 * instrumentation, or null.
3312 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003313 * @return {@code true} if the instrumentation was successfully started,
3314 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003315 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003316 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3317 @Nullable String profileFile, @Nullable Bundle arguments);
3318
3319 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07003320 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07003321 POWER_SERVICE,
3322 WINDOW_SERVICE,
3323 LAYOUT_INFLATER_SERVICE,
3324 ACCOUNT_SERVICE,
3325 ACTIVITY_SERVICE,
3326 ALARM_SERVICE,
3327 NOTIFICATION_SERVICE,
3328 ACCESSIBILITY_SERVICE,
3329 CAPTIONING_SERVICE,
3330 KEYGUARD_SERVICE,
3331 LOCATION_SERVICE,
3332 //@hide: COUNTRY_DETECTOR,
3333 SEARCH_SERVICE,
3334 SENSOR_SERVICE,
Chad Brubaker90f391f2018-10-19 10:26:19 -07003335 SENSOR_PRIVACY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003336 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003337 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003338 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003339 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003340 VIBRATOR_SERVICE,
3341 //@hide: STATUS_BAR_SERVICE,
3342 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003343 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003344 IPSEC_SERVICE,
Benedict Wong99a48412018-11-09 14:45:34 -08003345 TEST_NETWORK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003346 //@hide: UPDATE_LOCK_SERVICE,
3347 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003348 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003349 //@hide: NETWORK_POLICY_SERVICE,
3350 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003351 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003352 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003353 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003354 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003355 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003356 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003357 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003358 NSD_SERVICE,
3359 AUDIO_SERVICE,
Ilya Matyukhine4675b32019-11-07 16:07:19 -08003360 AUTH_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003361 FINGERPRINT_SERVICE,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003362 //@hide: FACE_SERVICE,
Kevin Chyn05c21502018-09-18 13:07:19 -07003363 BIOMETRIC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003364 MEDIA_ROUTER_SERVICE,
3365 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003366 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003367 CARRIER_CONFIG_SERVICE,
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003368 EUICC_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003369 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003370 CLIPBOARD_SERVICE,
3371 INPUT_METHOD_SERVICE,
3372 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003373 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003374 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003375 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003376 //@hide: BACKUP_SERVICE,
Richard Uhlerb29f1452018-09-12 16:38:15 +01003377 ROLLBACK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003378 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003379 //@hide: DEVICE_IDLE_CONTROLLER,
Kweku Adamse371b092019-11-22 10:50:48 -08003380 //@hide: POWER_WHITELIST_MANAGER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003381 DEVICE_POLICY_SERVICE,
3382 UI_MODE_SERVICE,
3383 DOWNLOAD_SERVICE,
3384 NFC_SERVICE,
3385 BLUETOOTH_SERVICE,
3386 //@hide: SIP_SERVICE,
3387 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003388 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003389 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003390 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003391 INPUT_SERVICE,
3392 DISPLAY_SERVICE,
Christine Franks39b03112018-07-03 14:46:07 -07003393 //@hide COLOR_DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003394 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003395 RESTRICTIONS_SERVICE,
3396 APP_OPS_SERVICE,
Hai Zhangb7776682018-09-25 15:10:57 -07003397 ROLE_SERVICE,
Hai Zhanga4959e52019-03-06 12:21:07 -08003398 //@hide ROLE_CONTROLLER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003399 CAMERA_SERVICE,
atrostde54a8ac2019-08-15 16:53:01 +01003400 //@hide: PLATFORM_COMPAT_SERVICE,
atrost87488352019-10-10 19:27:31 +01003401 //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003402 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003403 CONSUMER_IR_SERVICE,
3404 //@hide: TRUST_SERVICE,
3405 TV_INPUT_SERVICE,
3406 //@hide: NETWORK_SCORE_SERVICE,
3407 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003408 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003409 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003410 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003411 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003412 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003413 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003414 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003415 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003416 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003417 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003418 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003419 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003420 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003421 //@hide: INCIDENT_SERVICE,
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08003422 //@hide: INCIDENT_COMPANION_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003423 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003424 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003425 CROSS_PROFILE_APPS_SERVICE,
3426 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerfeeee682018-05-30 14:35:24 +01003427 //@hide: TIME_DETECTOR_SERVICE,
Neil Fuller3e3b5402019-11-07 15:35:05 +00003428 //@hide: TIME_ZONE_DETECTOR_SERVICE,
Philip P. Moltmann039678e2018-09-18 13:04:38 -07003429 PERMISSION_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003430 })
3431 @Retention(RetentionPolicy.SOURCE)
3432 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003433
3434 /**
3435 * Return the handle to a system-level service by name. The class of the
3436 * returned object varies by the requested name. Currently available names
3437 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003438 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 * <dl>
3440 * <dt> {@link #WINDOW_SERVICE} ("window")
3441 * <dd> The top-level window manager in which you can place custom
3442 * windows. The returned object is a {@link android.view.WindowManager}.
3443 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3444 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3445 * in this context.
3446 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3447 * <dd> A {@link android.app.ActivityManager} for interacting with the
3448 * global activity state of the system.
3449 * <dt> {@link #POWER_SERVICE} ("power")
3450 * <dd> A {@link android.os.PowerManager} for controlling power
3451 * management.
3452 * <dt> {@link #ALARM_SERVICE} ("alarm")
3453 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3454 * time of your choosing.
3455 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3456 * <dd> A {@link android.app.NotificationManager} for informing the user
3457 * of background events.
3458 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3459 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3460 * <dt> {@link #LOCATION_SERVICE} ("location")
3461 * <dd> A {@link android.location.LocationManager} for controlling location
3462 * (e.g., GPS) updates.
3463 * <dt> {@link #SEARCH_SERVICE} ("search")
3464 * <dd> A {@link android.app.SearchManager} for handling search.
3465 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3466 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3467 * hardware.
Sudheer Shanka09b0ee62019-10-03 14:45:15 -07003468 * <dt> {@link #CONNECTIVITY_SERVICE} ("connectivity")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003469 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3470 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003471 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3472 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3473 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003474 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003475 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3476 * connectivity. On releases before NYC, it should only be obtained from an application
3477 * context, and not from any other derived context to avoid memory leaks within the calling
3478 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003479 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3480 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3481 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003482 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3483 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3484 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3486 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3487 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003488 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3489 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003490 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003491 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003492 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003493 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003494 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3495 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003496 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3497 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3498 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003499 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003500 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003502 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003503 * <p>Note: System services obtained via this API may be closely associated with
3504 * the Context in which they are obtained from. In general, do not share the
3505 * service objects between various different contexts (Activities, Applications,
3506 * Services, Providers, etc.)
3507 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003508 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3509 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003510 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3511 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3512 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3513 * return <code>null</code>. Generally, if you are running as an instant app you should always
Felipe Leme4685b862019-03-06 10:32:33 -08003514 * check whether the result of this method is {@code null}.
3515 *
3516 * <p>Note: When implementing this method, keep in mind that new services can be added on newer
3517 * Android releases, so if you're looking for just the explicit names mentioned above, make sure
3518 * to return {@code null} when you don't recognize the name &mdash; if you throw a
3519 * {@link RuntimeException} exception instead, you're app might break on new Android releases.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003520 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003521 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003522 *
Felipe Leme4685b862019-03-06 10:32:33 -08003523 * @return The service or {@code null} if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003524 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003525 * @see #WINDOW_SERVICE
3526 * @see android.view.WindowManager
3527 * @see #LAYOUT_INFLATER_SERVICE
3528 * @see android.view.LayoutInflater
3529 * @see #ACTIVITY_SERVICE
3530 * @see android.app.ActivityManager
3531 * @see #POWER_SERVICE
3532 * @see android.os.PowerManager
3533 * @see #ALARM_SERVICE
3534 * @see android.app.AlarmManager
3535 * @see #NOTIFICATION_SERVICE
3536 * @see android.app.NotificationManager
3537 * @see #KEYGUARD_SERVICE
3538 * @see android.app.KeyguardManager
3539 * @see #LOCATION_SERVICE
3540 * @see android.location.LocationManager
3541 * @see #SEARCH_SERVICE
3542 * @see android.app.SearchManager
3543 * @see #SENSOR_SERVICE
3544 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003545 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003546 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003547 * @see #VIBRATOR_SERVICE
3548 * @see android.os.Vibrator
3549 * @see #CONNECTIVITY_SERVICE
3550 * @see android.net.ConnectivityManager
3551 * @see #WIFI_SERVICE
3552 * @see android.net.wifi.WifiManager
3553 * @see #AUDIO_SERVICE
3554 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003555 * @see #MEDIA_ROUTER_SERVICE
3556 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003557 * @see #TELEPHONY_SERVICE
3558 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003559 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3560 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003561 * @see #CARRIER_CONFIG_SERVICE
3562 * @see android.telephony.CarrierConfigManager
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003563 * @see #EUICC_SERVICE
3564 * @see android.telephony.euicc.EuiccManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003565 * @see #INPUT_METHOD_SERVICE
3566 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003567 * @see #UI_MODE_SERVICE
3568 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003569 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003570 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003571 * @see #BATTERY_SERVICE
3572 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003573 * @see #JOB_SCHEDULER_SERVICE
3574 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003575 * @see #NETWORK_STATS_SERVICE
3576 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003577 * @see android.os.HardwarePropertiesManager
3578 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003579 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003580 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003581
3582 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003583 * Return the handle to a system-level service by class.
3584 * <p>
3585 * Currently available classes are:
3586 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3587 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3588 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3589 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3590 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3591 * {@link android.net.ConnectivityManager},
3592 * {@link android.net.wifi.WifiManager},
3593 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3594 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3595 * {@link android.view.inputmethod.InputMethodManager},
3596 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003597 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3598 * {@link android.app.usage.NetworkStatsManager}.
Felipe Leme4685b862019-03-06 10:32:33 -08003599 * </p>
3600 *
3601 * <p>
Jeff Brown6e539312015-02-24 18:53:21 -08003602 * Note: System services obtained via this API may be closely associated with
3603 * the Context in which they are obtained from. In general, do not share the
3604 * service objects between various different contexts (Activities, Applications,
3605 * Services, Providers, etc.)
3606 * </p>
3607 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003608 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3609 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003610 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3611 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3612 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
Felipe Leme4685b862019-03-06 10:32:33 -08003613 * return {@code null}. Generally, if you are running as an instant app you should always
3614 * check whether the result of this method is {@code null}.
3615 * </p>
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003616 *
Jeff Brown6e539312015-02-24 18:53:21 -08003617 * @param serviceClass The class of the desired service.
Felipe Leme4685b862019-03-06 10:32:33 -08003618 * @return The service or {@code null} if the class is not a supported system service. Note:
3619 * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
Jeff Brown6e539312015-02-24 18:53:21 -08003620 */
3621 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003622 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003623 // Because subclasses may override getSystemService(String) we cannot
3624 // perform a lookup by class alone. We must first map the class to its
3625 // service name then invoke the string-based method.
3626 String serviceName = getSystemServiceName(serviceClass);
3627 return serviceName != null ? (T)getSystemService(serviceName) : null;
3628 }
3629
3630 /**
3631 * Gets the name of the system-level service that is represented by the specified class.
3632 *
3633 * @param serviceClass The class of the desired service.
3634 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003635 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003636 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003637
3638 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003639 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003640 * {@link android.os.PowerManager} for controlling power management,
3641 * including "wake locks," which let you keep the device on while
3642 * you're running long tasks.
3643 */
3644 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003646 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003647 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003648 * {@link android.os.RecoverySystem} for accessing the recovery system
3649 * service.
3650 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003651 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003652 * @hide
3653 */
3654 public static final String RECOVERY_SERVICE = "recovery";
3655
3656 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003657 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003658 * {@link android.os.SystemUpdateManager} for accessing the system update
3659 * manager service.
3660 *
3661 * @see #getSystemService(String)
3662 * @hide
3663 */
3664 @SystemApi
3665 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3666
3667 /**
3668 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003669 * {@link android.view.WindowManager} for accessing the system's window
3670 * manager.
3671 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003672 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003673 * @see android.view.WindowManager
3674 */
3675 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003677 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003678 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003679 * {@link android.view.LayoutInflater} for inflating layout resources in this
3680 * context.
3681 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003682 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003683 * @see android.view.LayoutInflater
3684 */
3685 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003688 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003689 * {@link android.accounts.AccountManager} for receiving intents at a
3690 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003691 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003692 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003693 * @see android.accounts.AccountManager
3694 */
3695 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003696
Fred Quintana60307342009-03-24 22:48:12 -07003697 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003698 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003699 * {@link android.app.ActivityManager} for interacting with the global
3700 * system state.
3701 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003702 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003703 * @see android.app.ActivityManager
3704 */
3705 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003706
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003707 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003708 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale65ebd952018-04-25 15:41:44 -07003709 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
3710 *
3711 * @see #getSystemService(String)
3712 * @see android.app.ActivityTaskManager
3713 * @hide
3714 */
3715 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
3716
3717 /**
3718 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07003719 * {@link android.app.UriGrantsManager} for interacting with the global system state.
3720 *
3721 * @see #getSystemService(String)
3722 * @see android.app.UriGrantsManager
3723 * @hide
3724 */
3725 public static final String URI_GRANTS_SERVICE = "uri_grants";
3726
3727 /**
3728 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 * {@link android.app.AlarmManager} for receiving intents at a
3730 * time of your choosing.
3731 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003732 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 * @see android.app.AlarmManager
3734 */
3735 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003738 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003739 * {@link android.app.NotificationManager} for informing the user of
3740 * background events.
3741 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003742 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003743 * @see android.app.NotificationManager
3744 */
3745 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003746
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003748 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003749 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3750 * feedback for UI events through the registered event listeners.
3751 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003752 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003753 * @see android.view.accessibility.AccessibilityManager
3754 */
3755 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003756
svetoslavganov75986cf2009-05-14 22:28:01 -07003757 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003758 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003759 * {@link android.view.accessibility.CaptioningManager} for obtaining
3760 * captioning properties and listening for changes in captioning
3761 * preferences.
3762 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003763 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003764 * @see android.view.accessibility.CaptioningManager
3765 */
3766 public static final String CAPTIONING_SERVICE = "captioning";
3767
3768 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003769 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003770 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003772 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003773 * @see android.app.KeyguardManager
3774 */
3775 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003777 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003778 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003779 * android.location.LocationManager} for controlling location
3780 * updates.
3781 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003782 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 * @see android.location.LocationManager
3784 */
3785 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003786
3787 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003788 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003789 * {@link android.location.CountryDetector} for detecting the country that
3790 * the user is in.
3791 *
3792 * @hide
3793 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01003794 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003795 public static final String COUNTRY_DETECTOR = "country_detector";
3796
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003798 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 * android.app.SearchManager} for handling searches.
3800 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003801 * <p>
3802 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3803 * {@link android.app.SearchManager}.
3804 *
3805 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 * @see android.app.SearchManager
3807 */
3808 public static final String SEARCH_SERVICE = "search";
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.hardware.SensorManager} for accessing sensors.
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.hardware.SensorManager
3816 */
3817 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -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
Chad Brubaker90f391f2018-10-19 10:26:19 -07003821 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
3822 * functions.
3823 *
3824 * @see #getSystemService(String)
3825 * @see android.hardware.SensorPrivacyManager
3826 *
3827 * @hide
3828 */
3829 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
3830
3831 /**
3832 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003833 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003834 * functions.
3835 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003836 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003837 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003838 */
3839 public static final String STORAGE_SERVICE = "storage";
3840
3841 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003842 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003843 * android.app.usage.StorageStatsManager} for accessing system storage
3844 * statistics.
3845 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003846 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003847 * @see android.app.usage.StorageStatsManager
3848 */
3849 public static final String STORAGE_STATS_SERVICE = "storagestats";
3850
3851 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003852 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003853 * com.android.server.WallpaperService for accessing wallpapers.
3854 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003855 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003856 */
3857 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003858
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003859 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003860 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003861 * android.os.Vibrator} for interacting with the vibration hardware.
3862 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003863 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003864 * @see android.os.Vibrator
3865 */
3866 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003868 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003869 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003870 * android.app.StatusBarManager} for interacting with the status bar.
3871 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003872 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003873 * @see android.app.StatusBarManager
Evan Lairdedd016f2019-01-23 18:36:29 -05003874 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003875 * @hide
3876 */
Evan Lairdedd016f2019-01-23 18:36:29 -05003877 @SystemApi
Evan Laird418ba8f2019-04-17 15:55:21 -04003878 @TestApi
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003879 public static final String STATUS_BAR_SERVICE = "statusbar";
3880
3881 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003882 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 * android.net.ConnectivityManager} for handling management of
3884 * network connections.
3885 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003886 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 * @see android.net.ConnectivityManager
3888 */
3889 public static final String CONNECTIVITY_SERVICE = "connectivity";
3890
3891 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003892 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003893 * {@link android.net.INetd} for communicating with the network stack
3894 * @hide
3895 * @see #getSystemService(String)
3896 * @hide
3897 */
3898 @SystemApi
3899 public static final String NETD_SERVICE = "netd";
3900
3901 /**
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003902 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3903 * {@link NetworkStackClient} IBinder for communicating with the network stack
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003904 * @hide
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003905 * @see NetworkStackClient
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003906 */
3907 public static final String NETWORK_STACK_SERVICE = "network_stack";
3908
3909 /**
3910 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003911 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3912 * IPSec.
3913 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003914 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003915 */
3916 public static final String IPSEC_SERVICE = "ipsec";
3917
3918 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003919 * Use with {@link #getSystemService(String)} to retrieve a {@link
Benedict Wong99a48412018-11-09 14:45:34 -08003920 * android.net.TestNetworkManager} for building TUNs and limited-use Networks
3921 *
3922 * @see #getSystemService(String)
3923 * @hide
3924 */
3925 @TestApi public static final String TEST_NETWORK_SERVICE = "test_network";
3926
3927 /**
3928 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003929 * android.os.IUpdateLock} for managing runtime sequences that
3930 * must not be interrupted by headless OTA application or similar.
3931 *
3932 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003933 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003934 * @see android.os.UpdateLock
3935 */
3936 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3937
3938 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003939 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003940 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003941 */
3942 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3943
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003944 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003945 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003946 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3947 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003948 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003949 */
3950 public static final String SLICE_SERVICE = "slice";
3951
3952 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003953 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003954 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3955 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003956 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003957 * @see android.app.usage.NetworkStatsManager
3958 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003959 public static final String NETWORK_STATS_SERVICE = "netstats";
3960 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003961 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003962 /** {@hide} */
3963 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003964
San Mehatd1df8ac2010-01-26 06:17:26 -08003965 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003966 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003967 * android.net.wifi.WifiManager} for handling management of
3968 * Wi-Fi access.
3969 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003970 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003971 * @see android.net.wifi.WifiManager
3972 */
3973 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003974
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003975 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003976 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003977 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003978 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003979 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003980 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003981 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003982 */
3983 public static final String WIFI_P2P_SERVICE = "wifip2p";
3984
3985 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003986 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003987 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3988 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003989 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003990 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003991 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003992 */
Etan Cohen04133272016-10-26 11:22:06 -07003993 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003994
3995 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003996 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003997 * android.net.wifi.WifiScanner} for scanning the wifi universe
3998 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003999 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07004000 * @see android.net.wifi.WifiScanner
4001 * @hide
4002 */
Wei Wang35d552f2014-07-08 21:37:01 -07004003 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07004004 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
4005
4006 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004007 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07004008 * android.net.wifi.RttManager} for ranging devices with wifi
4009 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004010 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07004011 * @see android.net.wifi.RttManager
4012 * @hide
4013 */
4014 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08004015 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07004016 public static final String WIFI_RTT_SERVICE = "rttmanager";
4017
4018 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004019 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohenf4062a92019-04-11 07:00:42 -07004020 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
Etan Cohen17ba4722017-08-21 10:52:17 -07004021 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004022 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07004023 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07004024 */
Etan Cohen091d7772018-01-04 17:47:37 -08004025 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07004026
4027 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004028 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07004029 * android.net.lowpan.LowpanManager} for handling management of
4030 * LoWPAN access.
4031 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004032 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07004033 * @see android.net.lowpan.LowpanManager
4034 *
4035 * @hide
4036 */
4037 public static final String LOWPAN_SERVICE = "lowpan";
4038
4039 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004040 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004041 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004042 * Ethernet access.
4043 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004044 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004045 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004046 *
4047 * @hide
4048 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01004049 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004050 public static final String ETHERNET_SERVICE = "ethernet";
4051
4052 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004053 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07004054 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004055 * discovery
4056 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004057 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07004058 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004059 */
4060 public static final String NSD_SERVICE = "servicediscovery";
4061
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004062 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004063 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004064 * {@link android.media.AudioManager} for handling management of volume,
4065 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07004066 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004067 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004068 * @see android.media.AudioManager
4069 */
4070 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07004071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004072 /**
Ilya Matyukhine4675b32019-11-07 16:07:19 -08004073 * AuthService orchestrates biometric and PIN/pattern/password authentication.
4074 *
4075 * BiometricService was split into two services, AuthService and BiometricService, where
4076 * AuthService is the high level service that orchestrates all types of authentication, and
4077 * BiometricService is a lower layer responsible only for biometric authentication.
4078 *
4079 * Ideally we should have renamed BiometricManager to AuthManager, because it logically
4080 * corresponds to AuthService. However, because BiometricManager is a public API, we kept
4081 * the old name but changed the internal implementation to use AuthService.
4082 *
4083 * As of now, the AUTH_SERVICE constant is only used to identify the service in
4084 * SystemServiceRegistry and SELinux. To obtain the manager for AUTH_SERVICE, one should use
4085 * BIOMETRIC_SERVICE with {@link #getSystemService(String)} to retrieve a
4086 * {@link android.hardware.biometrics.BiometricManager}
4087 *
4088 * Map of the two services and their managers:
4089 * [Service] [Manager]
4090 * AuthService BiometricManager
4091 * BiometricService N/A
4092 *
4093 * @hide
4094 */
4095 public static final String AUTH_SERVICE = "auth";
4096
4097 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004098 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07004099 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07004100 * of fingerprints.
4101 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004102 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07004103 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07004104 */
4105 public static final String FINGERPRINT_SERVICE = "fingerprint";
4106
4107 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004108 * Use with {@link #getSystemService(String)} to retrieve a
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004109 * {@link android.hardware.face.FaceManager} for handling management
4110 * of face authentication.
4111 *
4112 * @hide
4113 * @see #getSystemService
4114 * @see android.hardware.face.FaceManager
4115 */
4116 public static final String FACE_SERVICE = "face";
4117
4118 /**
Kevin Chyn05c21502018-09-18 13:07:19 -07004119 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn51676d22018-11-05 18:00:43 -08004120 * {@link android.hardware.iris.IrisManager} for handling management
4121 * of iris authentication.
4122 *
4123 * @hide
4124 * @see #getSystemService
4125 * @see android.hardware.iris.IrisManager
4126 */
4127 public static final String IRIS_SERVICE = "iris";
4128
4129 /**
4130 * Use with {@link #getSystemService(String)} to retrieve a
Ilya Matyukhine4675b32019-11-07 16:07:19 -08004131 * {@link android.hardware.biometrics.BiometricManager} for handling
4132 * biometric and PIN/pattern/password authentication.
Kevin Chyn05c21502018-09-18 13:07:19 -07004133 *
4134 * @see #getSystemService
4135 * @see android.hardware.biometrics.BiometricManager
4136 */
4137 public static final String BIOMETRIC_SERVICE = "biometric";
4138
4139 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004140 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004141 * {@link android.media.MediaRouter} for controlling and managing
4142 * routing of media.
4143 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004144 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004145 * @see android.media.MediaRouter
4146 */
4147 public static final String MEDIA_ROUTER_SERVICE = "media_router";
4148
4149 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004150 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07004151 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08004152 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004153 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07004154 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08004155 */
4156 public static final String MEDIA_SESSION_SERVICE = "media_session";
4157
4158 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004159 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004160 * {@link android.telephony.TelephonyManager} for handling management the
4161 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07004162 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004163 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004164 * @see android.telephony.TelephonyManager
4165 */
4166 public static final String TELEPHONY_SERVICE = "phone";
4167
4168 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004169 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08004170 * {@link android.telephony.SubscriptionManager} for handling management the
4171 * telephony subscriptions of the device.
4172 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004173 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08004174 * @see android.telephony.SubscriptionManager
4175 */
4176 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
4177
4178 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004179 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004180 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07004181 * of the device.
4182 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004183 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004184 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07004185 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004186 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07004187
4188 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004189 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004190 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
4191 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004192 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004193 * @see android.telephony.CarrierConfigManager
4194 */
4195 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
4196
4197 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004198 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08004199 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
4200 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004201 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08004202 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08004203 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004204 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08004205
4206 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004207 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004208 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
4209 *
4210 * @see #getSystemService(String)
4211 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004212 * @hide
4213 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004214 @SystemApi
4215 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004216
4217 /**
4218 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08004219 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004220 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07004221 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004222 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004223 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004224 */
4225 public static final String CLIPBOARD_SERVICE = "clipboard";
4226
4227 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004228 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004229 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004230 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004231 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004232 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004233 */
4234 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
4235
4236 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004237 * Use with {@link #getSystemService(String)} to retrieve a
Alex Salo5f5b5f42019-02-27 10:49:00 -08004238 * {@link com.android.server.attention.AttentionManagerService} for attention services.
4239 *
4240 * @see #getSystemService(String)
4241 * @see android.server.attention.AttentionManagerService
4242 * @hide
4243 */
4244 public static final String ATTENTION_SERVICE = "attention";
4245
4246 /**
4247 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004248 * {@link android.view.inputmethod.InputMethodManager} for accessing input
4249 * methods.
4250 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004251 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004252 */
4253 public static final String INPUT_METHOD_SERVICE = "input_method";
4254
4255 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004256 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09004257 * {@link android.view.textservice.TextServicesManager} for accessing
4258 * text services.
4259 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004260 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09004261 */
4262 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
4263
4264 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004265 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08004266 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004267 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004268 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004270 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07004271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004272 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07004273 * Official published name of the (internal) voice interaction manager service.
4274 *
4275 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004276 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07004277 */
4278 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4279
4280 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08004281 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07004282 *
4283 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004284 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07004285 */
Felipe Leme640f30a2017-03-06 15:44:06 -08004286 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07004287
4288 /**
Felipe Leme749b8892018-12-03 16:30:30 -08004289 * Official published name of the content capture service.
Felipe Lemee348dc32018-11-05 12:35:29 -08004290 *
4291 * @hide
4292 * @see #getSystemService(String)
4293 */
Felipe Lemea7e4ca62019-05-23 13:32:40 -07004294 @TestApi
Felipe Leme749b8892018-12-03 16:30:30 -08004295 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
Felipe Lemee348dc32018-11-05 12:35:29 -08004296
4297 /**
Winson Chung3fb0f252019-01-08 17:41:55 -08004298 * Used for getting content selections and classifications for task snapshots.
4299 *
4300 * @hide
4301 * @see #getSystemService(String)
4302 */
4303 @SystemApi
4304 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
4305
4306 /**
Sunny Goyal54e91342018-11-14 11:59:02 -08004307 * Official published name of the app prediction service.
4308 *
Felipe Leme6378bd42019-08-14 18:14:55 -07004309 * <p><b>NOTE: </b> this service is optional; callers of
4310 * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}.
4311 *
Sunny Goyal54e91342018-11-14 11:59:02 -08004312 * @hide
4313 * @see #getSystemService(String)
4314 */
4315 @SystemApi
4316 public static final String APP_PREDICTION_SERVICE = "app_prediction";
4317
4318 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004319 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004320 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
4321 *
4322 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004323 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004324 */
4325 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
4326
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004327 /**
4328 * Official published name of the (internal) permission service.
4329 *
4330 * @see #getSystemService(String)
4331 * @hide
4332 */
Winsonf27394e2019-06-07 14:44:40 -07004333 @TestApi
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004334 @SystemApi
4335 public static final String PERMISSION_SERVICE = "permission";
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004336
4337 /**
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08004338 * Official published name of the (internal) permission controller service.
4339 *
4340 * @see #getSystemService(String)
4341 * @hide
4342 */
4343 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
4344
4345 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004346 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08004347 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07004348 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07004349 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07004350 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004351 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07004352 */
Christopher Tated5cf7222014-07-29 16:53:09 -07004353 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07004354 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07004355
4356 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +01004357 * Use with {@link #getSystemService(String)} to retrieve an
4358 * {@link android.content.rollback.RollbackManager} for communicating
4359 * with the rollback manager
4360 *
4361 * @see #getSystemService(String)
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004362 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +01004363 */
Richard Uhler8a977452019-03-08 13:27:17 +00004364 @SystemApi @TestApi
Richard Uhlerb29f1452018-09-12 16:38:15 +01004365 public static final String ROLLBACK_SERVICE = "rollback";
4366
4367 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004368 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08004369 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07004370 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004371 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07004372 */
4373 public static final String DROPBOX_SERVICE = "dropbox";
4374
Christopher Tate487529a2009-04-29 14:03:25 -07004375 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07004376 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004377 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004378 * @hide
4379 */
Makoto Onuki7d6d9ca2019-08-13 11:45:45 -07004380 @TestApi
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004381 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
4382
4383 /**
Kweku Adamse371b092019-11-22 10:50:48 -08004384 * System service name for the PowerWhitelistManager.
4385 *
4386 * @see #getSystemService(String)
4387 * @hide
4388 */
4389 @TestApi
4390 public static final String POWER_WHITELIST_MANAGER = "power_whitelist";
4391
4392 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004393 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08004394 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08004395 * device policy management.
4396 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004397 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08004398 */
4399 public static final String DEVICE_POLICY_SERVICE = "device_policy";
4400
4401 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004402 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08004403 * {@link android.app.UiModeManager} for controlling UI modes.
4404 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004405 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08004406 */
4407 public static final String UI_MODE_SERVICE = "uimode";
4408
4409 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004410 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07004411 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07004412 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004413 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07004414 */
4415 public static final String DOWNLOAD_SERVICE = "download";
4416
4417 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004418 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08004419 * {@link android.os.BatteryManager} for managing battery state.
4420 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004421 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08004422 */
4423 public static final String BATTERY_SERVICE = "batterymanager";
4424
4425 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004426 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004427 * {@link android.nfc.NfcManager} for using NFC.
4428 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004429 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004430 */
4431 public static final String NFC_SERVICE = "nfc";
4432
4433 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004434 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00004435 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004436 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004437 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004438 */
4439 public static final String BLUETOOTH_SERVICE = "bluetooth";
4440
4441 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004442 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08004443 * {@link android.net.sip.SipManager} for accessing the SIP related service.
4444 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004445 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08004446 */
4447 /** @hide */
4448 public static final String SIP_SERVICE = "sip";
4449
4450 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004451 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08004452 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004453 * and for controlling this device's behavior as a USB device.
4454 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004455 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04004456 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004457 */
4458 public static final String USB_SERVICE = "usb";
4459
4460 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004461 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Rootf74bfde2018-01-18 15:42:48 -08004462 * Use with {@link #getSystemService} to retrieve a {@link
4463 * android.debug.AdbManager} for access to ADB debug functions.
4464 *
4465 * @see #getSystemService(String)
4466 * @see android.debug.AdbManager
4467 *
4468 * @hide
4469 */
4470 public static final String ADB_SERVICE = "adb";
4471
4472 /**
4473 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004474 * android.hardware.SerialManager} for access to serial ports.
4475 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004476 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004477 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004478 *
4479 * @hide
4480 */
4481 public static final String SERIAL_SERVICE = "serial";
4482
4483 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004484 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09004485 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
4486 * HDMI-CEC protocol.
4487 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004488 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09004489 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004490 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09004491 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004492 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09004493 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09004494
4495 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004496 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004497 * {@link android.hardware.input.InputManager} for interacting with input devices.
4498 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004499 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004500 * @see android.hardware.input.InputManager
4501 */
4502 public static final String INPUT_SERVICE = "input";
4503
4504 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004505 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07004506 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
4507 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004508 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07004509 * @see android.hardware.display.DisplayManager
4510 */
4511 public static final String DISPLAY_SERVICE = "display";
4512
4513 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004514 * Use with {@link #getSystemService(String)} to retrieve a
Christine Franks39b03112018-07-03 14:46:07 -07004515 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
4516 *
4517 * @see #getSystemService(String)
4518 * @see android.hardware.display.ColorDisplayManager
4519 * @hide
4520 */
4521 public static final String COLOR_DISPLAY_SERVICE = "color_display";
4522
4523 /**
4524 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07004525 * {@link android.os.UserManager} for managing users on devices that support multiple users.
4526 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004527 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07004528 * @see android.os.UserManager
4529 */
4530 public static final String USER_SERVICE = "user";
4531
4532 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004533 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08004534 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
4535 * profiles of a user.
4536 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004537 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08004538 * @see android.content.pm.LauncherApps
4539 */
4540 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4541
4542 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004543 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004544 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4545 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004546 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004547 * @see android.content.RestrictionsManager
4548 */
4549 public static final String RESTRICTIONS_SERVICE = "restrictions";
4550
4551 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004552 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004553 * {@link android.app.AppOpsManager} for tracking application operations
4554 * on the device.
4555 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004556 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004557 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004558 */
4559 public static final String APP_OPS_SERVICE = "appops";
4560
4561 /**
Hai Zhangb7776682018-09-25 15:10:57 -07004562 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
4563 * for managing roles.
4564 *
4565 * @see #getSystemService(String)
4566 * @see android.app.role.RoleManager
4567 */
4568 public static final String ROLE_SERVICE = "role";
4569
4570 /**
Hai Zhanga4959e52019-03-06 12:21:07 -08004571 * Official published name of the (internal) role controller service.
4572 *
4573 * @see #getSystemService(String)
4574 * @see android.app.role.RoleControllerService
4575 *
4576 * @hide
4577 */
4578 public static final String ROLE_CONTROLLER_SERVICE = "role_controller";
4579
4580 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004581 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004582 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004583 * camera devices.
4584 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004585 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004586 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004587 */
4588 public static final String CAMERA_SERVICE = "camera";
4589
4590 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004591 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004592 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004593 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004594 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004595 * @see android.print.PrintManager
4596 */
4597 public static final String PRINT_SERVICE = "print";
4598
4599 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004600 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004601 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4602 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004603 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004604 * @see android.companion.CompanionDeviceManager
4605 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004606 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004607
4608 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004609 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004610 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4611 * signals from the device.
4612 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004613 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004614 * @see android.hardware.ConsumerIrManager
4615 */
4616 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4617
4618 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004619 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004620 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004621 * @see android.app.trust.TrustManager
4622 * @hide
4623 */
4624 public static final String TRUST_SERVICE = "trust";
4625
4626 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004627 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004628 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4629 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004630 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004631 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004632 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004633 */
4634 public static final String TV_INPUT_SERVICE = "tv_input";
4635
4636 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004637 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004638 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004639 * @see android.net.NetworkScoreManager
4640 * @hide
4641 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004642 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004643 public static final String NETWORK_SCORE_SERVICE = "network_score";
4644
4645 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004646 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004647 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004648 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004649 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004650 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004651 */
4652 public static final String USAGE_STATS_SERVICE = "usagestats";
4653
4654 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004655 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004656 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004657 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004658 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004659 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004660 */
Christopher Tate7060b042014-06-09 19:50:00 -07004661 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004662
4663 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004664 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004665 * android.service.persistentdata.PersistentDataBlockManager} instance
4666 * for interacting with a storage device that lives across factory resets.
4667 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004668 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004669 * @see android.service.persistentdata.PersistentDataBlockManager
4670 * @hide
4671 */
Andres Morales33df9372014-09-26 17:08:59 -07004672 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004673 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4674
4675 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004676 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004677 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4678 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004679 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004680 * @see android.service.oemlock.OemLockManager
4681 * @hide
4682 */
4683 @SystemApi
4684 public static final String OEM_LOCK_SERVICE = "oem_lock";
4685
4686 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004687 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004688 * android.media.projection.MediaProjectionManager} instance for managing
4689 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004690 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004691 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004692 */
4693 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4694
4695 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004696 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004697 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004698 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004699 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004700 */
4701 public static final String MIDI_SERVICE = "midi";
4702
Eric Laurent2035ac82015-03-05 15:18:44 -08004703
4704 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004705 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004706 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4707 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004708 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004709 * @hide
4710 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004711 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004712
Paul McLeana33be212015-02-20 07:52:45 -08004713 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004714 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004715 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4716 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004717 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004718 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004719 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004720
4721 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004722 * Use with {@link #getSystemService(String)} to retrieve a
Wei Wangbad7c202018-11-01 11:57:39 -07004723 * {@link android.os.ThermalService} for accessing the thermal service.
4724 *
4725 * @see #getSystemService(String)
4726 * @hide
4727 */
4728 public static final String THERMAL_SERVICE = "thermalservice";
4729
4730 /**
4731 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004732 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004733 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004734 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004735 * @see android.content.pm.ShortcutManager
4736 */
4737 public static final String SHORTCUT_SERVICE = "shortcut";
4738
4739 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004740 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004741 * android.hardware.location.ContextHubManager} for accessing context hubs.
4742 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004743 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004744 * @see android.hardware.location.ContextHubManager
4745 *
4746 * @hide
4747 */
4748 @SystemApi
4749 public static final String CONTEXTHUB_SERVICE = "contexthub";
4750
4751 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004752 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004753 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4754 * memory, etc) metrics.
4755 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004756 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004757 */
4758 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4759
4760 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004761 * Gatekeeper Service.
4762 * @hide
4763 */
4764 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4765
4766 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004767 * Service defining the policy for access to device identifiers.
4768 * @hide
4769 */
4770 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4771
4772 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004773 * Service to report a system health "incident"
4774 * @hide
4775 */
4776 public static final String INCIDENT_SERVICE = "incident";
4777
4778 /**
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08004779 * Service to assist incidentd and dumpstated in reporting status to the user
4780 * and in confirming authorization to take an incident report or bugreport
4781 * @hide
4782 */
4783 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
4784
4785 /**
Bookatz94726412017-08-31 09:26:15 -07004786 * Service to assist statsd in obtaining general stats.
4787 * @hide
4788 */
4789 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4790
4791 /**
Bookatzc6977972018-01-16 16:55:05 -08004792 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004793 * @hide
4794 */
4795 @SystemApi
4796 public static final String STATS_MANAGER = "stats";
4797
4798 /**
atrostde54a8ac2019-08-15 16:53:01 +01004799 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4800 * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
4801 * @hide
4802 */
4803 public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
4804
4805 /**
atrost87488352019-10-10 19:27:31 +01004806 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4807 * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
4808 * service.
4809 * @hide
4810 */
4811 public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
4812
4813 /**
Nandana Duttd11850c2018-12-12 17:26:57 +00004814 * Service to capture a bugreport.
4815 * @see #getSystemService(String)
4816 * @see android.os.BugreportManager
4817 * @hide
4818 */
Nandana Duttd7e8d5a2019-04-11 17:27:45 +01004819 @SystemApi @TestApi
Nandana Duttd11850c2018-12-12 17:26:57 +00004820 public static final String BUGREPORT_SERVICE = "bugreport";
4821
4822 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004823 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004824 * android.content.om.OverlayManager} for managing overlay packages.
4825 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004826 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004827 * @see android.content.om.OverlayManager
4828 * @hide
4829 */
4830 public static final String OVERLAY_SERVICE = "overlay";
4831
4832 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004833 * Use with {@link #getSystemService(String)} to retrieve a
MÃ¥rten Kongstad06a1ac82018-09-20 13:09:47 +02004834 * {android.os.IIdmap2} for managing idmap files (used by overlay
4835 * packages).
4836 *
4837 * @see #getSystemService(String)
4838 * @hide
4839 */
4840 public static final String IDMAP_SERVICE = "idmap";
4841
4842 /**
4843 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004844 * {@link VrManager} for accessing the VR service.
4845 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004846 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004847 * @hide
4848 */
4849 @SystemApi
4850 public static final String VR_SERVICE = "vrmanager";
4851
4852 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004853 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004854 * {@link android.app.timezone.ITimeZoneRulesManager}.
4855 * @hide
4856 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004857 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004858 */
4859 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4860
4861 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004862 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004863 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004864 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004865 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004866 */
4867 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4868
4869 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004870 * Use with {@link #getSystemService} to retrieve a
4871 * {@link android.se.omapi.ISecureElementService}
4872 * for accessing the SecureElementService.
4873 *
4874 * @hide
4875 */
4876 @SystemApi
4877 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4878
4879 /**
Neil Fullerfeeee682018-05-30 14:35:24 +01004880 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fuller3e3b5402019-11-07 15:35:05 +00004881 * {@link android.app.timedetector.TimeDetector}.
Neil Fullerfeeee682018-05-30 14:35:24 +01004882 * @hide
4883 *
4884 * @see #getSystemService(String)
4885 */
4886 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4887
4888 /**
Neil Fuller3e3b5402019-11-07 15:35:05 +00004889 * Use with {@link #getSystemService(String)} to retrieve an
4890 * {@link android.app.timezonedetector.TimeZoneDetector}.
4891 * @hide
4892 *
4893 * @see #getSystemService(String)
4894 */
4895 public static final String TIME_ZONE_DETECTOR_SERVICE = "time_zone_detector";
4896
4897 /**
Makoto Onukidf7e4812018-09-24 14:31:25 -07004898 * Binder service name for {@link AppBindingService}.
4899 * @hide
4900 */
4901 public static final String APP_BINDING_SERVICE = "app_binding";
4902
4903 /**
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004904 * Use with {@link #getSystemService(String)} to retrieve an
James.cf Lin2bc9cd42019-11-04 20:23:36 +08004905 * {@link android.telephony.ims.ImsManager}.
4906 * @hide
4907 */
4908 public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
4909
4910 /**
4911 * Use with {@link #getSystemService(String)} to retrieve an
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004912 * {@link android.telephony.ims.RcsMessageManager}.
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004913 * @hide
4914 */
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004915 public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004916
Howard Chen0a947642019-01-07 14:10:44 +08004917 /**
4918 * Use with {@link #getSystemService(String)} to retrieve an
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004919 * {@link android.os.image.DynamicSystemManager}.
Howard Chen0a947642019-01-07 14:10:44 +08004920 * @hide
4921 */
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004922 public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
Howard Chen0a947642019-01-07 14:10:44 +08004923
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004924 /**
Sudheer Shankaf5b36962019-10-04 16:16:13 -07004925 * Use with {@link #getSystemService(String)} to retrieve a {@link
4926 * android.app.blob.BlobStoreManager} for contributing and accessing data blobs
4927 * from the blob store maintained by the system.
4928 *
4929 * @see #getSystemService(String)
4930 * @see android.app.blob.BlobStoreManager
4931 *
4932 * TODO: make this public once BlobStoreManager is ready.
4933 * @hide
4934 */
4935 @TestApi
4936 public static final String BLOB_STORE_SERVICE = "blob_store";
4937
4938 /**
Chen Xu288b71c2019-09-15 18:28:21 -07004939 * Use with {@link #getSystemService(String)} to retrieve an
Chen Xu1f6cfa52019-10-13 17:30:32 -07004940 * {@link TelephonyRegistryManager}.
Chen Xu288b71c2019-09-15 18:28:21 -07004941 * @hide
4942 */
4943 @SystemApi
4944 public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
4945
4946 /**
Roshan Pius848513e2019-10-11 13:44:00 -07004947 * Use with {@link #getSystemService(String)} to retrieve an
4948 * {@link android.os.BatteryStatsManager}.
4949 * @hide
4950 */
4951 @SystemApi
4952 public static final String BATTERY_STATS_SERVICE = "batterystats";
4953
4954 /**
Terry Wangecc0d1b2019-10-17 17:05:18 -07004955 * Use with {@link #getSystemService(String)} to retrieve an
4956 * AppSearchManager for indexing and querying app data managed
4957 * by the system.
4958 *
4959 * @see #getSystemService(String)
4960 */
4961 public static final String APP_SEARCH_SERVICE = "app_search";
4962
4963 /**
Song Pan75147d52019-11-19 00:57:46 +00004964 * Use with {@link #getSystemService(String)} to retrieve an
4965 * {@link android.content.integrity.AppIntegrityManager}.
4966 * @hide
4967 */
4968 @SystemApi
4969 public static final String APP_INTEGRITY_SERVICE = "app_integrity";
4970
4971 /**
Songchun Fand1b41d42019-11-12 17:09:53 -08004972 * Use with {@link #getSystemService(String)} to retrieve an
Songchun Fan6dd47b52019-11-29 15:20:18 -08004973 * {@link android.content.pm.DataLoaderManager}.
4974 * @hide
4975 */
4976 public static final String DATA_LOADER_MANAGER_SERVICE = "dataloadermanager";
4977
4978 /**
4979 * Use with {@link #getSystemService(String)} to retrieve an
Songchun Fand1b41d42019-11-12 17:09:53 -08004980 * {@link android.os.incremental.IncrementalManager}.
4981 * @hide
4982 */
4983 public static final String INCREMENTAL_SERVICE = "incremental";
4984
4985 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004986 * Determine whether the given permission is allowed for a particular
4987 * process and user ID running in the system.
4988 *
4989 * @param permission The name of the permission being checked.
4990 * @param pid The process ID being checked against. Must be > 0.
4991 * @param uid The user ID being checked against. A uid of 0 is the root
4992 * user, which will pass every permission check.
4993 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004994 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004995 * pid/uid is allowed that permission, or
4996 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4997 *
4998 * @see PackageManager#checkPermission(String, String)
4999 * @see #checkCallingPermission
5000 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005001 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07005002 @PackageManager.PermissionResult
5003 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005004
Dianne Hackbornff170242014-11-19 10:59:01 -08005005 /** @hide */
5006 @PackageManager.PermissionResult
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005007 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08005008 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
5009 IBinder callerToken);
5010
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005011 /**
5012 * Determine whether the calling process of an IPC you are handling has been
5013 * granted a particular permission. This is basically the same as calling
5014 * {@link #checkPermission(String, int, int)} with the pid and uid returned
5015 * by {@link android.os.Binder#getCallingPid} and
5016 * {@link android.os.Binder#getCallingUid}. One important difference
5017 * is that if you are not currently processing an IPC, this function
5018 * will always fail. This is done to protect against accidentally
5019 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
5020 * to avoid this protection.
5021 *
5022 * @param permission The name of the permission being checked.
5023 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005024 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005025 * pid/uid is allowed that permission, or
5026 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5027 *
5028 * @see PackageManager#checkPermission(String, String)
5029 * @see #checkPermission
5030 * @see #checkCallingOrSelfPermission
5031 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005032 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07005033 @PackageManager.PermissionResult
5034 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005035
5036 /**
5037 * Determine whether the calling process of an IPC <em>or you</em> have been
5038 * granted a particular permission. This is the same as
5039 * {@link #checkCallingPermission}, except it grants your own permissions
5040 * if you are not currently processing an IPC. Use with care!
5041 *
5042 * @param permission The name of the permission being checked.
5043 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005044 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005045 * pid/uid is allowed that permission, or
5046 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5047 *
5048 * @see PackageManager#checkPermission(String, String)
5049 * @see #checkPermission
5050 * @see #checkCallingPermission
5051 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005052 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07005053 @PackageManager.PermissionResult
5054 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005055
5056 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08005057 * Determine whether <em>you</em> have been granted a particular permission.
5058 *
5059 * @param permission The name of the permission being checked.
5060 *
5061 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
5062 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
5063 *
5064 * @see PackageManager#checkPermission(String, String)
5065 * @see #checkCallingPermission(String)
5066 */
5067 @PackageManager.PermissionResult
5068 public abstract int checkSelfPermission(@NonNull String permission);
5069
5070 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005071 * If the given permission is not allowed for a particular process
5072 * and user ID running in the system, throw a {@link SecurityException}.
5073 *
5074 * @param permission The name of the permission being checked.
5075 * @param pid The process ID being checked against. Must be &gt; 0.
5076 * @param uid The user ID being checked against. A uid of 0 is the root
5077 * user, which will pass every permission check.
5078 * @param message A message to include in the exception if it is thrown.
5079 *
5080 * @see #checkPermission(String, int, int)
5081 */
5082 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005083 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005084
5085 /**
5086 * If the calling process of an IPC you are handling has not been
5087 * granted a particular permission, throw a {@link
5088 * SecurityException}. This is basically the same as calling
5089 * {@link #enforcePermission(String, int, int, String)} with the
5090 * pid and uid returned by {@link android.os.Binder#getCallingPid}
5091 * and {@link android.os.Binder#getCallingUid}. One important
5092 * difference is that if you are not currently processing an IPC,
5093 * this function will always throw the SecurityException. This is
5094 * done to protect against accidentally leaking permissions; you
5095 * can use {@link #enforceCallingOrSelfPermission} to avoid this
5096 * protection.
5097 *
5098 * @param permission The name of the permission being checked.
5099 * @param message A message to include in the exception if it is thrown.
5100 *
5101 * @see #checkCallingPermission(String)
5102 */
5103 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005104 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005105
5106 /**
5107 * If neither you nor the calling process of an IPC you are
5108 * handling has been granted a particular permission, throw a
5109 * {@link SecurityException}. This is the same as {@link
5110 * #enforceCallingPermission}, except it grants your own
5111 * permissions if you are not currently processing an IPC. Use
5112 * with care!
5113 *
5114 * @param permission The name of the permission being checked.
5115 * @param message A message to include in the exception if it is thrown.
5116 *
5117 * @see #checkCallingOrSelfPermission(String)
5118 */
5119 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005120 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005121
5122 /**
5123 * Grant permission to access a specific Uri to another package, regardless
5124 * of whether that package has general permission to access the Uri's
5125 * content provider. This can be used to grant specific, temporary
5126 * permissions, typically in response to user interaction (such as the
5127 * user opening an attachment that you would like someone else to
5128 * display).
5129 *
5130 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
5131 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
5132 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
5133 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
5134 * start an activity instead of this function directly. If you use this
5135 * function directly, you should be sure to call
5136 * {@link #revokeUriPermission} when the target should no longer be allowed
5137 * to access it.
5138 *
5139 * <p>To succeed, the content provider owning the Uri must have set the
5140 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
5141 * grantUriPermissions} attribute in its manifest or included the
5142 * {@link android.R.styleable#AndroidManifestGrantUriPermission
5143 * &lt;grant-uri-permissions&gt;} tag.
5144 *
5145 * @param toPackage The package you would like to allow to access the Uri.
5146 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005147 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005148 *
5149 * @see #revokeUriPermission
5150 */
5151 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07005152 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005153
5154 /**
5155 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07005156 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
5157 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07005158 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005159 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07005160 * "content://foo". It will not remove any prefix grants that exist at a
5161 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005162 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07005163 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07005164 * regular permission access to a Uri, but had received access to it through
5165 * a specific Uri permission grant, you could not revoke that grant with this
5166 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07005167 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
5168 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07005169 * (or none).</p>
5170 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07005171 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
5172 * grants matching the given Uri, for any package they had been granted to, through any
5173 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
5174 * service start, etc). That means this can be potentially dangerous to use, as it can
5175 * revoke grants that another app could be strongly expecting to stick around.</p>
5176 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005177 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005178 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005179 *
5180 * @see #grantUriPermission
5181 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07005182 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005183
5184 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07005185 * Remove permissions to access a particular content provider Uri
5186 * that were previously added with {@link #grantUriPermission} for a specific target
5187 * package. The given Uri will match all previously granted Uris that are the same or a
5188 * sub-path of the given Uri. That is, revoking "content://foo/target" will
5189 * revoke both "content://foo/target" and "content://foo/target/sub", but not
5190 * "content://foo". It will not remove any prefix grants that exist at a
5191 * higher level.
5192 *
5193 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
5194 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
5195 * and only for the package specified. Any matching grants that have happened through
5196 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
5197 * removed.</p>
5198 *
5199 * @param toPackage The package you had previously granted access to.
5200 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005201 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07005202 *
5203 * @see #grantUriPermission
5204 */
5205 public abstract void revokeUriPermission(String toPackage, Uri uri,
5206 @Intent.AccessUriMode int modeFlags);
5207
5208 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005209 * Determine whether a particular process and user ID has been granted
5210 * permission to access a specific URI. This only checks for permissions
5211 * that have been explicitly granted -- if the given process/uid has
5212 * more general access to the URI's content provider then this check will
5213 * always fail.
5214 *
5215 * @param uri The uri that is being checked.
5216 * @param pid The process ID being checked against. Must be &gt; 0.
5217 * @param uid The user ID being checked against. A uid of 0 is the root
5218 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005219 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005221 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005222 * pid/uid is allowed to access that uri, or
5223 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5224 *
5225 * @see #checkCallingUriPermission
5226 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005227 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005228 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005229 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005230 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005231
Dianne Hackbornff170242014-11-19 10:59:01 -08005232 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005233 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08005234 public abstract int checkUriPermission(Uri uri, int pid, int uid,
5235 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
5236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005237 /**
5238 * Determine whether the calling process and user ID has been
5239 * granted permission to access a specific URI. This is basically
5240 * the same as calling {@link #checkUriPermission(Uri, int, int,
5241 * int)} with the pid and uid returned by {@link
5242 * android.os.Binder#getCallingPid} and {@link
5243 * android.os.Binder#getCallingUid}. One important difference is
5244 * that if you are not currently processing an IPC, this function
5245 * will always fail.
5246 *
5247 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005248 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005249 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005250 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005251 * is allowed to access that uri, or
5252 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5253 *
5254 * @see #checkUriPermission(Uri, int, int, int)
5255 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005256 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005257 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07005258 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005259
5260 /**
5261 * Determine whether the calling process of an IPC <em>or you</em> has been granted
5262 * permission to access a specific URI. This is the same as
5263 * {@link #checkCallingUriPermission}, except it grants your own permissions
5264 * if you are not currently processing an IPC. Use with care!
5265 *
5266 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005267 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005268 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005269 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005270 * is allowed to access that uri, or
5271 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5272 *
5273 * @see #checkCallingUriPermission
5274 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005275 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005276 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005277 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005278 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005279
5280 /**
5281 * Check both a Uri and normal permission. This allows you to perform
5282 * both {@link #checkPermission} and {@link #checkUriPermission} in one
5283 * call.
5284 *
5285 * @param uri The Uri whose permission is to be checked, or null to not
5286 * do this check.
5287 * @param readPermission The permission that provides overall read access,
5288 * or null to not do this check.
5289 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005290 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005291 * @param pid The process ID being checked against. Must be &gt; 0.
5292 * @param uid The user ID being checked against. A uid of 0 is the root
5293 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005294 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005295 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005296 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005297 * is allowed to access that uri or holds one of the given permissions, or
5298 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5299 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005300 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005301 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005302 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
5303 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005304 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005305
5306 /**
5307 * If a particular process and user ID has not been granted
5308 * permission to access a specific URI, throw {@link
5309 * SecurityException}. This only checks for permissions that have
5310 * been explicitly granted -- if the given process/uid has more
5311 * general access to the URI's content provider then this check
5312 * will always fail.
5313 *
5314 * @param uri The uri that is being checked.
5315 * @param pid The process ID being checked against. Must be &gt; 0.
5316 * @param uid The user ID being checked against. A uid of 0 is the root
5317 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005318 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005319 * @param message A message to include in the exception if it is thrown.
5320 *
5321 * @see #checkUriPermission(Uri, int, int, int)
5322 */
5323 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005324 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005325
5326 /**
5327 * If the calling process and user ID has not been granted
5328 * permission to access a specific URI, throw {@link
5329 * SecurityException}. This is basically the same as calling
5330 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
5331 * the pid and uid returned by {@link
5332 * android.os.Binder#getCallingPid} and {@link
5333 * android.os.Binder#getCallingUid}. One important difference is
5334 * that if you are not currently processing an IPC, this function
5335 * will always throw a SecurityException.
5336 *
5337 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005338 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005339 * @param message A message to include in the exception if it is thrown.
5340 *
5341 * @see #checkCallingUriPermission(Uri, int)
5342 */
5343 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005344 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005345
5346 /**
5347 * If the calling process of an IPC <em>or you</em> has not been
5348 * granted permission to access a specific URI, throw {@link
5349 * SecurityException}. This is the same as {@link
5350 * #enforceCallingUriPermission}, except it grants your own
5351 * permissions if you are not currently processing an IPC. Use
5352 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07005353 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005354 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005355 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005356 * @param message A message to include in the exception if it is thrown.
5357 *
5358 * @see #checkCallingOrSelfUriPermission(Uri, int)
5359 */
5360 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005361 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362
5363 /**
5364 * Enforce both a Uri and normal permission. This allows you to perform
5365 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
5366 * call.
Scott Main4b5da682010-10-21 11:49:12 -07005367 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368 * @param uri The Uri whose permission is to be checked, or null to not
5369 * do this check.
5370 * @param readPermission The permission that provides overall read access,
5371 * or null to not do this check.
5372 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005373 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005374 * @param pid The process ID being checked against. Must be &gt; 0.
5375 * @param uid The user ID being checked against. A uid of 0 is the root
5376 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005377 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005378 * @param message A message to include in the exception if it is thrown.
5379 *
5380 * @see #checkUriPermission(Uri, String, String, int, int, int)
5381 */
5382 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005383 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005384 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07005385 @Nullable String message);
5386
5387 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005388 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
5389 CONTEXT_INCLUDE_CODE,
5390 CONTEXT_IGNORE_SECURITY,
5391 CONTEXT_RESTRICTED,
5392 CONTEXT_DEVICE_PROTECTED_STORAGE,
5393 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
5394 CONTEXT_REGISTER_PACKAGE,
5395 })
Tor Norbyed9273d62013-05-30 15:59:53 -07005396 @Retention(RetentionPolicy.SOURCE)
5397 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005398
5399 /**
5400 * Flag for use with {@link #createPackageContext}: include the application
5401 * code with the context. This means loading code into the caller's
5402 * process, so that {@link #getClassLoader()} can be used to instantiate
5403 * the application's classes. Setting this flags imposes security
5404 * restrictions on what application context you can access; if the
5405 * requested application can not be safely loaded into your process,
5406 * java.lang.SecurityException will be thrown. If this flag is not set,
5407 * there will be no restrictions on the packages that can be loaded,
5408 * but {@link #getClassLoader} will always return the default system
5409 * class loader.
5410 */
5411 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
5412
5413 /**
5414 * Flag for use with {@link #createPackageContext}: ignore any security
5415 * restrictions on the Context being requested, allowing it to always
5416 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
5417 * to be loaded into a process even when it isn't safe to do so. Use
5418 * with extreme care!
5419 */
5420 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07005421
Romain Guy870e09f2009-07-06 16:35:25 -07005422 /**
5423 * Flag for use with {@link #createPackageContext}: a restricted context may
5424 * disable specific features. For instance, a View associated with a restricted
5425 * context would ignore particular XML attributes.
5426 */
5427 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005428
5429 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005430 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005431 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005432 *
5433 * @hide
5434 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005435 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005436
5437 /**
5438 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005439 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005440 *
5441 * @hide
5442 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005443 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005444
5445 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07005446 * @hide Used to indicate we should tell the activity manager about the process
5447 * loading this code.
5448 */
5449 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
5450
5451 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005452 * Return a new Context object for the given application name. This
5453 * Context is the same as what the named application gets when it is
5454 * launched, containing the same resources and class loader. Each call to
5455 * this method returns a new instance of a Context object; Context objects
5456 * are not shared, however they share common state (Resources, ClassLoader,
5457 * etc) so the Context instance itself is fairly lightweight.
5458 *
Jeff Brown6e539312015-02-24 18:53:21 -08005459 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005460 * application with the given package name.
5461 *
5462 * <p>Throws {@link java.lang.SecurityException} if the Context requested
5463 * can not be loaded into the caller's process for security reasons (see
5464 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
5465 *
5466 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005467 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005468 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005469 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005470 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005471 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005472 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04005473 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005474 */
5475 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07005476 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07005477
5478 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07005479 * Similar to {@link #createPackageContext(String, int)}, but with a
5480 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5481 * will open any {@link Uri} as the given user.
5482 *
5483 * @hide
5484 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08005485 @SystemApi
Jeff Sharkeyec5f7d12018-08-08 09:15:04 -06005486 @TestApi
Makoto Onukib8440012019-10-09 15:33:11 -07005487 @NonNull
Patrick Baumannef4c4072018-02-01 08:54:05 -08005488 public Context createPackageContextAsUser(
Makoto Onukib8440012019-10-09 15:33:11 -07005489 @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08005490 throws PackageManager.NameNotFoundException {
5491 if (Build.IS_ENG) {
5492 throw new IllegalStateException("createPackageContextAsUser not overridden!");
5493 }
5494 return this;
5495 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07005496
5497 /**
Makoto Onukib8440012019-10-09 15:33:11 -07005498 * Similar to {@link #createPackageContext(String, int)}, but for the own package with a
5499 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5500 * will open any {@link Uri} as the given user.
5501 *
5502 * @hide
5503 */
5504 @SystemApi
5505 @TestApi
5506 @NonNull
Makoto Onukie5449f02019-10-11 20:19:58 -07005507 public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
Makoto Onukib8440012019-10-09 15:33:11 -07005508 if (Build.IS_ENG) {
5509 throw new IllegalStateException("createContextAsUser not overridden!");
5510 }
5511 return this;
5512 }
5513
5514 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07005515 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
5516 *
5517 * @hide
5518 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005519 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07005520 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005521 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07005522
5523 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08005524 * Return a new Context object for the given split name. The new Context has a ClassLoader and
5525 * Resources object that can access the split's and all of its dependencies' code/resources.
5526 * Each call to this method returns a new instance of a Context object;
5527 * Context objects are not shared, however common state (ClassLoader, other Resources for
5528 * the same split) may be so the Context itself can be fairly lightweight.
5529 *
5530 * @param splitName The name of the split to include, as declared in the split's
5531 * <code>AndroidManifest.xml</code>.
5532 * @return A {@link Context} with the given split's code and/or resources loaded.
5533 */
5534 public abstract Context createContextForSplit(String splitName)
5535 throws PackageManager.NameNotFoundException;
5536
5537 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005538 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08005539 * @hide
5540 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07005541 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005542 public UserHandle getUser() {
5543 return android.os.Process.myUserHandle();
5544 }
5545
5546 /**
5547 * Get the user associated with this context
5548 * @hide
5549 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +00005550 @UnsupportedAppUsage
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005551 @TestApi
5552 public @UserIdInt int getUserId() {
5553 return android.os.UserHandle.myUserId();
5554 }
Jim Millera75a8832013-02-07 16:53:32 -08005555
5556 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07005557 * Return a new Context object for the current Context but whose resources
5558 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07005559 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07005560 * shared, however common state (ClassLoader, other Resources for the
5561 * same configuration) may be so the Context itself can be fairly lightweight.
5562 *
5563 * @param overrideConfiguration A {@link Configuration} specifying what
5564 * values to modify in the base Configuration of the original Context's
5565 * resources. If the base configuration changes (such as due to an
5566 * orientation change), the resources of this context will also change except
5567 * for those that have been explicitly overridden with a value here.
5568 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005569 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07005570 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005571 public abstract Context createConfigurationContext(
5572 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07005573
5574 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07005575 * Return a new Context object for the current Context but whose resources
5576 * are adjusted to match the metrics of the given Display. Each call to this method
5577 * returns a new instance of a Context object; Context objects are not
5578 * shared, however common state (ClassLoader, other Resources for the
5579 * same configuration) may be so the Context itself can be fairly lightweight.
5580 *
5581 * The returned display Context provides a {@link WindowManager}
5582 * (see {@link #getSystemService(String)}) that is configured to show windows
5583 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
5584 * method can be used to retrieve the Display from the returned Context.
5585 *
5586 * @param display A {@link Display} object specifying the display
5587 * for whose metrics the Context's resources should be tailored and upon which
5588 * new windows should be shown.
5589 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005590 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07005591 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005592 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07005593
5594 /**
Philip P. Moltmann59076d82019-08-19 15:00:40 -07005595 * Return a new Context object for the current Context but for a different feature in the app.
5596 * Features can be used by complex apps to separate logical parts.
5597 *
5598 * @param featureId The feature id or {@code null} to create a context for the default feature.
5599 *
5600 * @return A {@link Context} for the feature
5601 *
5602 * @see #getFeatureId()
5603 */
5604 public @NonNull Context createFeatureContext(@Nullable String featureId) {
Philip P. Moltmannf1a634c2019-10-18 09:10:56 -07005605 throw new RuntimeException("Not implemented. Must override in a subclass.");
Philip P. Moltmann59076d82019-08-19 15:00:40 -07005606 }
5607
5608 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005609 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005610 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005611 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005612 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005613 * with a key tied to the physical device, and it can be accessed
5614 * immediately after the device has booted successfully, both
5615 * <em>before and after</em> the user has authenticated with their
5616 * credentials (such as a lock pattern or PIN).
5617 * <p>
5618 * Because device-protected data is available without user authentication,
5619 * you should carefully limit the data you store using this Context. For
5620 * example, storing sensitive authentication tokens or passwords in the
5621 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005622 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005623 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005624 * device-protected and credential-protected data using different keys, then
5625 * both storage areas will become available at the same time. They remain as
5626 * two distinct storage locations on disk, and only the window of
5627 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005628 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005629 * Each call to this method returns a new instance of a Context object;
5630 * Context objects are not shared, however common state (ClassLoader, other
5631 * Resources for the same configuration) may be so the Context itself can be
5632 * fairly lightweight.
5633 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005634 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005635 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005636 public abstract Context createDeviceProtectedStorageContext();
5637
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005638 /**
5639 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005640 * APIs are backed by credential-protected storage. This is the default
5641 * storage area for apps unless
5642 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005643 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005644 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005645 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005646 * <em>only after</em> the user has entered their credentials (such as a
5647 * lock pattern or PIN).
5648 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005649 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005650 * device-protected and credential-protected data using different keys, then
5651 * both storage areas will become available at the same time. They remain as
5652 * two distinct storage locations on disk, and only the window of
5653 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005654 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005655 * Each call to this method returns a new instance of a Context object;
5656 * Context objects are not shared, however common state (ClassLoader, other
5657 * Resources for the same configuration) may be so the Context itself can be
5658 * fairly lightweight.
5659 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005660 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005661 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005662 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005663 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005664 public abstract Context createCredentialProtectedStorageContext();
5665
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005666 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07005667 * Gets the display adjustments holder for this context. This information
5668 * is provided on a per-application or activity basis and is used to simulate lower density
5669 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07005670 *
Jeff Browna492c3a2012-08-23 19:48:44 -07005671 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07005672 * @return The compatibility info holder, or null if not required by the application.
5673 * @hide
5674 */
Craig Mautner48d0d182013-06-11 07:53:06 -07005675 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07005676
5677 /**
Wale Ogunwale691af682019-02-11 03:09:10 -08005678 * @return Returns the {@link Display} object this context is associated with.
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005679 * @hide
5680 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +00005681 @UnsupportedAppUsage
Wale Ogunwale691af682019-02-11 03:09:10 -08005682 @TestApi
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005683 public abstract Display getDisplay();
5684
5685 /**
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005686 * Gets the display ID.
5687 *
5688 * @return display ID associated with this {@link Context}.
5689 * @hide
5690 */
wilsonshih5db7b392019-02-20 23:08:45 +08005691 @TestApi
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005692 public abstract int getDisplayId();
5693
5694 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08005695 * @hide
5696 */
5697 public abstract void updateDisplay(int displayId);
5698
5699 /**
Romain Guy870e09f2009-07-06 16:35:25 -07005700 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07005701 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005702 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07005703 *
Romain Guy870e09f2009-07-06 16:35:25 -07005704 * @see #CONTEXT_RESTRICTED
5705 */
5706 public boolean isRestricted() {
5707 return false;
5708 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005709
5710 /**
5711 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005712 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005713 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005714 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005715 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005716 public abstract boolean isDeviceProtectedStorage();
5717
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005718 /**
5719 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005720 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005721 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005722 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005723 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005724 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005725 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005726 public abstract boolean isCredentialProtectedStorage();
5727
Tony Mak46aabe52016-11-14 12:53:06 +00005728 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005729 * Returns true if the context can load unsafe resources, e.g. fonts.
5730 * @hide
5731 */
5732 public abstract boolean canLoadUnsafeResources();
5733
5734 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005735 * @hide
5736 */
5737 public IBinder getActivityToken() {
5738 throw new RuntimeException("Not implemented. Must override in a subclass.");
5739 }
5740
5741 /**
5742 * @hide
5743 */
5744 @Nullable
5745 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
5746 int flags) {
5747 throw new RuntimeException("Not implemented. Must override in a subclass.");
5748 }
5749
5750 /**
5751 * @hide
5752 */
5753 public IApplicationThread getIApplicationThread() {
5754 throw new RuntimeException("Not implemented. Must override in a subclass.");
5755 }
Tony Makbf9928d2016-12-22 11:02:45 +00005756
5757 /**
5758 * @hide
5759 */
5760 public Handler getMainThreadHandler() {
5761 throw new RuntimeException("Not implemented. Must override in a subclass.");
5762 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07005763
5764 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07005765 * @hide
5766 */
5767 public AutofillClient getAutofillClient() {
5768 return null;
5769 }
5770
5771 /**
5772 * @hide
5773 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005774 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005775 }
5776
5777 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005778 * @hide
5779 */
Felipe Lemecbf7f262019-04-17 13:57:59 -07005780 @Nullable
5781 public ContentCaptureClient getContentCaptureClient() {
5782 return null;
5783 }
5784
5785 /**
5786 * @hide
5787 */
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005788 public final boolean isAutofillCompatibilityEnabled() {
5789 final AutofillOptions options = getAutofillOptions();
5790 return options != null && options.compatModeEnabled;
5791 }
5792
5793 /**
5794 * @hide
5795 */
5796 @Nullable
5797 public AutofillOptions getAutofillOptions() {
5798 return null;
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005799 }
5800
5801 /**
5802 * @hide
5803 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005804 @TestApi
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005805 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005806 }
5807
5808 /**
Felipe Leme326f15a2019-02-19 09:42:24 -08005809 * Gets the Content Capture options for this context, or {@code null} if it's not whitelisted.
Felipe Lemeecb08be2018-11-27 15:48:47 -08005810 *
5811 * @hide
5812 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005813 @Nullable
5814 public ContentCaptureOptions getContentCaptureOptions() {
5815 return null;
Felipe Lemeecb08be2018-11-27 15:48:47 -08005816 }
5817
5818 /**
5819 * @hide
5820 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005821 @TestApi
5822 public void setContentCaptureOptions(
5823 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08005824 }
5825
5826 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005827 * Throws an exception if the Context is using system resources,
5828 * which are non-runtime-overlay-themable and may show inconsistent UI.
5829 * @hide
5830 */
5831 public void assertRuntimeOverlayThemable() {
5832 // Resources.getSystem() is a singleton and the only Resources not managed by
5833 // ResourcesManager; therefore Resources.getSystem() is not themable.
5834 if (getResources() == Resources.getSystem()) {
5835 throw new IllegalArgumentException("Non-UI context used to display UI; "
5836 + "get a UI context from ActivityThread#getSystemUiContext()");
5837 }
5838 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005839}