blob: 536b6c33b1426d84d8822030fafbfc99e66b6210 [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;
Adrian Roosd38f5092020-01-16 21:20:24 +010033import android.annotation.SuppressLint;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090034import android.annotation.SystemApi;
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -070035import android.annotation.TestApi;
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;
Artur Satayeve23a0eb2019-12-10 17:47:52 +000041import android.compat.annotation.UnsupportedAppUsage;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070042import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043import android.content.pm.PackageManager;
44import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080045import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070046import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.content.res.Resources;
48import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070049import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050import android.database.sqlite.SQLiteDatabase;
51import android.database.sqlite.SQLiteDatabase.CursorFactory;
52import android.graphics.Bitmap;
53import android.graphics.drawable.Drawable;
54import android.net.Uri;
Patrick Baumannef4c4072018-02-01 08:54:05 -080055import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070057import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058import android.os.Handler;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070059import android.os.HandlerExecutor;
Dianne Hackbornff170242014-11-19 10:59:01 -080060import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070062import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070063import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070064import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060065import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070066import android.provider.MediaStore;
Chen Xu1f6cfa52019-10-13 17:30:32 -070067import android.telephony.TelephonyRegistryManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070069import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070070import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070071import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070072import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070073import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070074import android.view.autofill.AutofillManager.AutofillClient;
Felipe Lemecbf7f262019-04-17 13:57:59 -070075import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000076import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077
atrosta6a4d602019-08-21 16:48:56 +010078import com.android.internal.compat.IPlatformCompat;
atrost87488352019-10-10 19:27:31 +010079import com.android.internal.compat.IPlatformCompatNative;
atrosta6a4d602019-08-21 16:48:56 +010080
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081import java.io.File;
82import java.io.FileInputStream;
83import java.io.FileNotFoundException;
84import java.io.FileOutputStream;
85import java.io.IOException;
86import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070087import java.lang.annotation.Retention;
88import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070089import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080090
91/**
92 * Interface to global information about an application environment. This is
93 * an abstract class whose implementation is provided by
94 * the Android system. It
95 * allows access to application-specific resources and classes, as well as
96 * up-calls for application-level operations such as launching activities,
97 * broadcasting and receiving intents, etc.
98 */
99public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600100 /** @hide */
101 @IntDef(flag = true, prefix = { "MODE_" }, value = {
102 MODE_PRIVATE,
103 MODE_WORLD_READABLE,
104 MODE_WORLD_WRITEABLE,
105 MODE_APPEND,
106 })
107 @Retention(RetentionPolicy.SOURCE)
108 public @interface FileMode {}
109
110 /** @hide */
111 @IntDef(flag = true, prefix = { "MODE_" }, value = {
112 MODE_PRIVATE,
113 MODE_WORLD_READABLE,
114 MODE_WORLD_WRITEABLE,
115 MODE_MULTI_PROCESS,
116 })
117 @Retention(RetentionPolicy.SOURCE)
118 public @interface PreferencesMode {}
119
120 /** @hide */
121 @IntDef(flag = true, prefix = { "MODE_" }, value = {
122 MODE_PRIVATE,
123 MODE_WORLD_READABLE,
124 MODE_WORLD_WRITEABLE,
125 MODE_ENABLE_WRITE_AHEAD_LOGGING,
126 MODE_NO_LOCALIZED_COLLATORS,
127 })
128 @Retention(RetentionPolicy.SOURCE)
129 public @interface DatabaseMode {}
130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 /**
132 * File creation mode: the default mode, where the created file can only
133 * be accessed by the calling application (or all applications sharing the
134 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 */
136 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700137
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700139 * File creation mode: allow all other applications to have read access to
140 * the created file.
141 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700142 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
143 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700144 *
Nick Kralevich15069212013-01-09 15:54:56 -0800145 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700146 * to cause security holes in applications. It is strongly
147 * discouraged; instead, applications should use more formal
148 * mechanism for interactions such as {@link ContentProvider},
149 * {@link BroadcastReceiver}, and {@link android.app.Service}.
150 * There are no guarantees that this access mode will remain on
151 * a file, such as when it goes through a backup and restore.
152 * @see android.support.v4.content.FileProvider
153 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800154 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700155 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700159 * File creation mode: allow all other applications to have write access to
160 * the created file.
161 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700162 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700163 * mode will throw a {@link SecurityException}.
164 *
Nick Kralevich15069212013-01-09 15:54:56 -0800165 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700166 * to cause security holes in applications. It is strongly
167 * discouraged; instead, applications should use more formal
168 * mechanism for interactions such as {@link ContentProvider},
169 * {@link BroadcastReceiver}, and {@link android.app.Service}.
170 * There are no guarantees that this access mode will remain on
171 * a file, such as when it goes through a backup and restore.
172 * @see android.support.v4.content.FileProvider
173 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700175 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700177
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 /**
179 * File creation mode: for use with {@link #openFileOutput}, if the file
180 * already exists then write data to the end of the existing file
181 * instead of erasing it.
182 * @see #openFileOutput
183 */
184 public static final int MODE_APPEND = 0x8000;
185
186 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800187 * SharedPreference loading flag: when set, the file on disk will
188 * be checked for modification even if the shared preferences
189 * instance is already loaded in this process. This behavior is
190 * sometimes desired in cases where the application has multiple
191 * processes, all writing to the same SharedPreferences file.
192 * Generally there are better forms of communication between
193 * processes, though.
194 *
195 * <p>This was the legacy (but undocumented) behavior in and
196 * before Gingerbread (Android 2.3) and this flag is implied when
kopriva219f7dc2018-10-09 13:42:28 -0700197 * targeting such releases. For applications targeting SDK
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800198 * versions <em>greater than</em> Android 2.3, this flag must be
199 * explicitly set if desired.
200 *
201 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700202 *
203 * @deprecated MODE_MULTI_PROCESS does not work reliably in
204 * some versions of Android, and furthermore does not provide any
205 * mechanism for reconciling concurrent modifications across
206 * processes. Applications should not attempt to use it. Instead,
207 * they should use an explicit cross-process data management
208 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800209 */
Christopher Tated5748b82015-05-08 18:14:01 -0700210 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800211 public static final int MODE_MULTI_PROCESS = 0x0004;
212
213 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700214 * Database open flag: when set, the database is opened with write-ahead
215 * logging enabled by default.
216 *
217 * @see #openOrCreateDatabase(String, int, CursorFactory)
218 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
219 * @see SQLiteDatabase#enableWriteAheadLogging
220 */
221 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
222
Sunny Goyala21e6b22015-12-02 09:51:02 -0800223 /**
224 * Database open flag: when set, the database is opened without support for
225 * localized collators.
226 *
227 * @see #openOrCreateDatabase(String, int, CursorFactory)
228 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
229 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
230 */
231 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
232
Tor Norbyed9273d62013-05-30 15:59:53 -0700233 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700234 @IntDef(flag = true, prefix = { "BIND_" }, value = {
235 BIND_AUTO_CREATE,
236 BIND_DEBUG_UNBIND,
237 BIND_NOT_FOREGROUND,
238 BIND_ABOVE_CLIENT,
239 BIND_ALLOW_OOM_MANAGEMENT,
240 BIND_WAIVE_PRIORITY,
241 BIND_IMPORTANT,
Amith Yamasani5016a782019-06-17 16:20:24 -0700242 BIND_ADJUST_WITH_ACTIVITY,
243 BIND_NOT_PERCEPTIBLE,
244 BIND_INCLUDE_CAPABILITIES
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700245 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700246 @Retention(RetentionPolicy.SOURCE)
247 public @interface BindServiceFlags {}
248
Jeff Brown47847f32012-03-22 19:13:11 -0700249 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 * Flag for {@link #bindService}: automatically create the service as long
251 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700252 * its {@link android.app.Service#onStartCommand}
253 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 * explicit call to {@link #startService}. Even without that, though,
255 * this still provides you with access to the service object while the
256 * service is created.
257 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700258 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
259 * not supplying this flag would also impact how important the system
260 * consider's the target service's process to be. When set, the only way
261 * for it to be raised was by binding from a service in which case it will
262 * only be important when that activity is in the foreground. Now to
263 * achieve this behavior you must explicitly supply the new flag
264 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
265 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
266 * the flags {@link #BIND_WAIVE_PRIORITY} and
267 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
268 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 */
270 public static final int BIND_AUTO_CREATE = 0x0001;
271
272 /**
273 * Flag for {@link #bindService}: include debugging help for mismatched
274 * calls to unbind. When this flag is set, the callstack of the following
275 * {@link #unbindService} call is retained, to be printed if a later
276 * incorrect unbind call is made. Note that doing this requires retaining
277 * information about the binding that was made for the lifetime of the app,
278 * resulting in a leak -- this should only be used for debugging.
279 */
280 public static final int BIND_DEBUG_UNBIND = 0x0002;
281
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800282 /**
283 * Flag for {@link #bindService}: don't allow this binding to raise
284 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700285 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800286 * as the client (so that its process will not be killable in any
287 * situation where the client is not killable), but for CPU scheduling
288 * purposes it may be left in the background. This only has an impact
289 * in the situation where the binding client is a foreground process
290 * and the target service is in a background process.
291 */
292 public static final int BIND_NOT_FOREGROUND = 0x0004;
293
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700294 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700295 * Flag for {@link #bindService}: indicates that the client application
296 * binding to this service considers the service to be more important than
297 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700298 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700299 * this is not guaranteed to be the case.
300 */
301 public static final int BIND_ABOVE_CLIENT = 0x0008;
302
303 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700304 * Flag for {@link #bindService}: allow the process hosting the bound
305 * service to go through its normal memory management. It will be
306 * treated more like a running service, allowing the system to
307 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700308 * whim it may have, and being more aggressive about making it a candidate
309 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700310 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700311 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
312
313 /**
314 * Flag for {@link #bindService}: don't impact the scheduling or
315 * memory management priority of the target service's hosting process.
316 * Allows the service's process to be managed on the background LRU list
317 * just like a regular application process in the background.
318 */
319 public static final int BIND_WAIVE_PRIORITY = 0x0020;
320
321 /**
322 * Flag for {@link #bindService}: this service is very important to
323 * the client, so should be brought to the foreground process level
324 * when the client is. Normally a process can only be raised to the
325 * visibility level by a client, even if that client is in the foreground.
326 */
327 public static final int BIND_IMPORTANT = 0x0040;
328
329 /**
330 * Flag for {@link #bindService}: If binding from an activity, allow the
331 * target service's process importance to be raised based on whether the
332 * activity is visible to the user, regardless whether another flag is
333 * used to reduce the amount that the client process's overall importance
334 * is used to impact it.
335 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700336 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
337
338 /**
Amith Yamasani5016a782019-06-17 16:20:24 -0700339 * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible,
340 * lower the target service's importance to below the perceptible level. This allows
341 * the system to (temporarily) expunge the bound process from memory to make room for more
342 * important user-perceptible processes.
343 */
344 public static final int BIND_NOT_PERCEPTIBLE = 0x00000100;
345
346 /**
Amith Yamasanif178c962019-03-21 19:40:11 -0700347 * Flag for {@link #bindService}: If binding from an app that has specific capabilities
348 * due to its foreground state such as an activity or foreground service, then this flag will
349 * allow the bound app to get the same capabilities, as long as it has the required permissions
350 * as well.
351 */
Amith Yamasani5016a782019-06-17 16:20:24 -0700352 public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000;
Amith Yamasanif178c962019-03-21 19:40:11 -0700353
Amith Yamasani0b3ae0e2019-05-10 10:29:47 -0700354 /*********** Public flags above this line ***********/
355 /*********** Hidden flags below this line ***********/
356
357 /**
Yohei Yukawa59730962019-03-18 10:47:22 -0700358 * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust
359 * the scheduling policy for IMEs (and any other out-of-process user-visible components that
360 * work closely with the top app) so that UI hosted in such services can have the same
361 * scheduling policy (e.g. SCHED_FIFO when it is enabled and TOP_APP_PRIORITY_BOOST otherwise)
362 * as the actual top-app.
363 * @hide
364 */
365 public static final int BIND_SCHEDULE_LIKE_TOP_APP = 0x00080000;
366
367 /**
Michal Karpinskie069b002019-03-07 16:15:14 +0000368 * Flag for {@link #bindService}: allow background activity starts from the bound service's
369 * process.
370 * This flag is only respected if the caller is holding
371 * {@link android.Manifest.permission#START_ACTIVITIES_FROM_BACKGROUND}.
372 * @hide
373 */
374 public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 0x00100000;
375
376 /**
Dianne Hackbornc390aa82019-01-09 16:38:22 -0800377 * @hide Flag for {@link #bindService}: the service being bound to represents a
378 * protected system component, so must have association restrictions applied to it.
379 * That is, a system config must have one or more allow-association tags limiting
380 * which packages it can interact with. If it does not have any such association
381 * restrictions, a default empty set will be created.
382 */
383 public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000;
384
385 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800386 * @hide Flag for {@link #bindService}: allows binding to a service provided
387 * by an instant app. Note that the caller may not have access to the instant
388 * app providing the service which is a violation of the instant app sandbox.
389 * This flag is intended ONLY for development/testing and should be used with
390 * great care. Only the system is allowed to use this flag.
391 */
392 public static final int BIND_ALLOW_INSTANT = 0x00400000;
393
394 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700395 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
396 * up in to the important background state (instead of transient).
397 */
398 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
399
400 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700401 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
402 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
403 */
404 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
405
406 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700407 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
408 * but only applies while the device is awake.
409 */
410 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
411
412 /**
413 * @hide Flag for {@link #bindService}: For only the case where the binding
414 * is coming from the system, set the process state to FOREGROUND_SERVICE
415 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
416 * saying that the process shouldn't participate in the normal power reduction
417 * modes (removing network access etc).
418 */
419 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
420
421 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700422 * @hide Flag for {@link #bindService}: Treat the binding as hosting
423 * an activity, an unbinding as the activity going in the background.
424 * That is, when unbinding, the process when empty will go on the activity
425 * LRU list instead of the regular one, keeping it around more aggressively
426 * than it otherwise would be. This is intended for use with IMEs to try
427 * to keep IME processes around for faster keyboard switching.
428 */
429 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
430
431 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700432 * @hide An idea that is not yet implemented.
433 * Flag for {@link #bindService}: If binding from an activity, consider
434 * this service to be visible like the binding activity is. That is,
435 * it will be treated as something more important to keep around than
436 * invisible background activities. This will impact the number of
437 * recent activities the user can switch between without having them
438 * restart. There is no guarantee this will be respected, as the system
Amith Yamasanif235d0b2019-03-20 22:49:43 -0700439 * tries to balance such requests from one app vs. the importance of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700440 * keeping other apps around.
441 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700442 public static final int BIND_VISIBLE = 0x10000000;
443
444 /**
445 * @hide
446 * Flag for {@link #bindService}: Consider this binding to be causing the target
447 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
448 * away.
449 */
450 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700451
452 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700453 * Flag for {@link #bindService}: Don't consider the bound service to be
454 * visible, even if the caller is visible.
455 * @hide
456 */
457 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700458
Alan Viverette713a5cd2015-12-16 15:46:32 -0500459 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500460 * Flag for {@link #bindService}: The service being bound is an
461 * {@link android.R.attr#isolatedProcess isolated},
462 * {@link android.R.attr#externalService external} service. This binds the service into the
463 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400464 * <p>
465 * When using this flag, the code for the service being bound will execute under the calling
466 * application's package name and user ID. Because the service must be an isolated process,
467 * it will not have direct access to the application's data, though.
468 *
469 * The purpose of this flag is to allow applications to provide services that are attributed
470 * to the app using the service, rather than the application providing the service.
471 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500472 */
473 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
474
Dianne Hackborna631d562018-11-20 15:58:15 -0800475 /**
476 * These bind flags reduce the strength of the binding such that we shouldn't
477 * consider it as pulling the process up to the level of the one that is bound to it.
478 * @hide
479 */
480 public static final int BIND_REDUCTION_FLAGS =
481 Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
Amith Yamasani5016a782019-06-17 16:20:24 -0700482 | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;
Dianne Hackborna631d562018-11-20 15:58:15 -0800483
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700484 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700485 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
486 RECEIVER_VISIBLE_TO_INSTANT_APPS
487 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700488 @Retention(RetentionPolicy.SOURCE)
489 public @interface RegisterReceiverFlags {}
490
491 /**
492 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
493 */
494 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
495
Robert Sesekb9a86662015-12-09 16:22:45 -0500496 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500497 * Returns an AssetManager instance for the application's package.
498 * <p>
499 * <strong>Note:</strong> Implementations of this method should return
500 * an AssetManager instance that is consistent with the Resources instance
501 * returned by {@link #getResources()}. For example, they should share the
502 * same {@link Configuration} object.
503 *
504 * @return an AssetManager instance for the application's package
505 * @see #getResources()
506 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 public abstract AssetManager getAssets();
508
Alan Viverette713a5cd2015-12-16 15:46:32 -0500509 /**
510 * Returns a Resources instance for the application's package.
511 * <p>
512 * <strong>Note:</strong> Implementations of this method should return
513 * a Resources instance that is consistent with the AssetManager instance
514 * returned by {@link #getAssets()}. For example, they should share the
515 * same {@link Configuration} object.
516 *
517 * @return a Resources instance for the application's package
518 * @see #getAssets()
519 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 public abstract Resources getResources();
521
522 /** Return PackageManager instance to find global package information. */
523 public abstract PackageManager getPackageManager();
524
525 /** Return a ContentResolver instance for your application's package. */
526 public abstract ContentResolver getContentResolver();
527
528 /**
529 * Return the Looper for the main thread of the current process. This is
530 * the thread used to dispatch calls to application components (activities,
531 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700532 * <p>
533 * By definition, this method returns the same result as would be obtained
534 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
535 * </p>
536 *
537 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800538 */
539 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700540
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700542 * Return an {@link Executor} that will run enqueued tasks on the main
543 * thread associated with this context. This is the thread used to dispatch
544 * calls to application components (activities, services, etc).
545 */
546 public Executor getMainExecutor() {
547 // This is pretty inefficient, which is why ContextImpl overrides it
548 return new HandlerExecutor(new Handler(getMainLooper()));
549 }
550
551 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800553 * current process. This generally should only be used if you need a
554 * Context whose lifecycle is separate from the current context, that is
555 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700556 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800557 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800558 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800559 * <ul>
560 * <li> <p>If used from an Activity context, the receiver is being registered
561 * within that activity. This means that you are expected to unregister
562 * before the activity is done being destroyed; in fact if you do not do
563 * so, the framework will clean up your leaked registration as it removes
564 * the activity and log an error. Thus, if you use the Activity context
565 * to register a receiver that is static (global to the process, not
566 * associated with an Activity instance) then that registration will be
567 * removed on you at whatever point the activity you used is destroyed.
568 * <li> <p>If used from the Context returned here, the receiver is being
569 * registered with the global state associated with your application. Thus
570 * it will never be unregistered for you. This is necessary if the receiver
571 * is associated with static data, not a particular component. However
572 * using the ApplicationContext elsewhere can easily lead to serious leaks
573 * if you forget to unregister, unbind, etc.
574 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 */
576 public abstract Context getApplicationContext();
577
Phil Weaver846cda932017-06-15 10:10:06 -0700578 /** Non-activity related autofill ids are unique in the app */
579 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700580
581 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700582 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700583 *
Phil Weaver846cda932017-06-15 10:10:06 -0700584 * <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 -0700585 * returned will be unique.
586 *
587 * @return A ID that is unique in the process
588 *
589 * {@hide}
590 */
Phil Weaver846cda932017-06-15 10:10:06 -0700591 public int getNextAutofillId() {
592 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
593 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700594 }
595
Phil Weaver846cda932017-06-15 10:10:06 -0700596 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700597
Phil Weaver846cda932017-06-15 10:10:06 -0700598 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700599 }
600
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700602 * Add a new {@link ComponentCallbacks} to the base application of the
603 * Context, which will be called at the same times as the ComponentCallbacks
604 * methods of activities and other components are called. Note that you
605 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
606 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700607 *
608 * @param callback The interface to call. This can be either a
609 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700610 */
611 public void registerComponentCallbacks(ComponentCallbacks callback) {
612 getApplicationContext().registerComponentCallbacks(callback);
613 }
614
615 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400616 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700617 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
618 */
619 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
620 getApplicationContext().unregisterComponentCallbacks(callback);
621 }
622
623 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 * Return a localized, styled CharSequence from the application's package's
625 * default string table.
626 *
627 * @param resId Resource id for the CharSequence text
628 */
Chris Craikceb26932018-02-01 15:51:34 -0800629 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700630 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 return getResources().getText(resId);
632 }
633
634 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700635 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800636 * default string table.
637 *
638 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700639 * @return The string data associated with the resource, stripped of styled
640 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800641 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700642 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700643 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800644 return getResources().getString(resId);
645 }
646
647 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700648 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 * default string table, substituting the format arguments as defined in
650 * {@link java.util.Formatter} and {@link java.lang.String#format}.
651 *
652 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700653 * @param formatArgs The format arguments that will be used for
654 * substitution.
655 * @return The string data associated with the resource, formatted and
656 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800657 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700658 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700659 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800660 return getResources().getString(resId, formatArgs);
661 }
662
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800663 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800664 * Returns a color associated with a particular resource ID and styled for
665 * the current theme.
666 *
667 * @param id The desired resource identifier, as generated by the aapt
668 * tool. This integer encodes the package, type, and resource
669 * entry. The value 0 is an invalid identifier.
670 * @return A single color value in the form 0xAARRGGBB.
671 * @throws android.content.res.Resources.NotFoundException if the given ID
672 * does not exist.
673 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700674 @ColorInt
675 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800676 return getResources().getColor(id, getTheme());
677 }
678
679 /**
680 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800681 * styled for the current theme.
682 *
683 * @param id The desired resource identifier, as generated by the aapt
684 * tool. This integer encodes the package, type, and resource
685 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800686 * @return An object that can be used to draw this resource.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800687 * @throws android.content.res.Resources.NotFoundException if the given ID
688 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800689 */
Chris Craik1194b0b2018-03-23 13:36:24 -0700690 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700691 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800692 return getResources().getDrawable(id, getTheme());
693 }
694
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800695 /**
696 * Returns a color state list associated with a particular resource ID and
697 * styled for the current theme.
698 *
699 * @param id The desired resource identifier, as generated by the aapt
700 * tool. This integer encodes the package, type, and resource
701 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800702 * @return A color state list.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800703 * @throws android.content.res.Resources.NotFoundException if the given ID
704 * does not exist.
705 */
Chris Craikceb26932018-02-01 15:51:34 -0800706 @NonNull
Tor Norbye3e4cda72015-06-10 08:14:31 -0700707 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800708 return getResources().getColorStateList(id, getTheme());
709 }
710
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 /**
712 * Set the base theme for this context. Note that this should be called
713 * before any views are instantiated in the Context (for example before
714 * calling {@link android.app.Activity#setContentView} or
715 * {@link android.view.LayoutInflater#inflate}).
716 *
717 * @param resid The style resource describing the theme.
718 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700719 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720
Dianne Hackborn247fe742011-01-08 17:25:57 -0800721 /** @hide Needed for some internal implementation... not public because
722 * you can't assume this actually means anything. */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100723 @UnsupportedAppUsage
Dianne Hackborn247fe742011-01-08 17:25:57 -0800724 public int getThemeResId() {
725 return 0;
726 }
727
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800728 /**
729 * Return the Theme object associated with this Context.
730 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700731 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800732 public abstract Resources.Theme getTheme();
733
734 /**
735 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800736 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 * for more information.
738 *
Jeff Brown6e539312015-02-24 18:53:21 -0800739 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800740 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800741 @NonNull
742 public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800743 return getTheme().obtainStyledAttributes(attrs);
744 }
745
746 /**
747 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800748 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 * for more information.
750 *
Jeff Brown6e539312015-02-24 18:53:21 -0800751 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800752 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800753 @NonNull
754 public final TypedArray obtainStyledAttributes(@StyleRes int resid,
755 @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 return getTheme().obtainStyledAttributes(resid, attrs);
757 }
758
759 /**
760 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800761 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762 * for more information.
763 *
Jeff Brown6e539312015-02-24 18:53:21 -0800764 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800766 @NonNull
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 public final TypedArray obtainStyledAttributes(
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800768 @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800769 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
770 }
771
772 /**
773 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800774 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 * for more information.
776 *
Jeff Brown6e539312015-02-24 18:53:21 -0800777 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800778 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800779 @NonNull
780 public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set,
781 @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
Tor Norbyec91531a2015-04-01 17:41:55 -0700782 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 return getTheme().obtainStyledAttributes(
784 set, attrs, defStyleAttr, defStyleRes);
785 }
786
787 /**
788 * Return a class loader you can use to retrieve classes in this package.
789 */
790 public abstract ClassLoader getClassLoader();
791
792 /** Return the name of this application's package. */
793 public abstract String getPackageName();
794
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900795 /**
796 * @hide Return the name of the base context this context is derived from.
797 * This is the same as {@link #getOpPackageName()} except in
798 * cases where system components are loaded into other app processes, in which
799 * case {@link #getOpPackageName()} will be the name of the primary package in
800 * that process (so that app ops uid verification will work with the name).
801 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100802 @UnsupportedAppUsage
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800803 public abstract String getBasePackageName();
804
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900805 /**
806 * Return the package name that should be used for {@link android.app.AppOpsManager} calls from
807 * this context, so that app ops manager's uid verification will work with the name.
808 * <p>
809 * This is not generally intended for third party application developers.
810 */
Adrian Roosebc927c2019-02-28 16:21:18 +0100811 @NonNull
Adrian Roosfe6aeaf2019-01-22 16:58:56 +0100812 public String getOpPackageName() {
813 throw new RuntimeException("Not implemented. Must override in a subclass.");
814 }
Dianne Hackborn95d78532013-09-11 09:51:14 -0700815
Philip P. Moltmann59076d82019-08-19 15:00:40 -0700816 /**
817 * <p>Features are used in complex apps to logically separate parts of the app. E.g. a
818 * blogging app might also have a instant messaging app built in.
819 *
820 * @return the feature id this context is for or {@code null} if this is the default
821 * feature.
822 */
823 public @Nullable String getFeatureId() {
824 return null;
825 }
826
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700827 /** Return the full application info for this context's package. */
828 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700829
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800830 /**
Kenny Root32148392010-01-21 15:40:47 -0800831 * Return the full path to this context's primary Android package.
832 * The Android package is a ZIP file which contains the application's
833 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 *
835 * <p>Note: this is not generally useful for applications, since they should
836 * not be directly accessing the file system.
837 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 * @return String Path to the resources.
839 */
840 public abstract String getPackageResourcePath();
841
842 /**
Kenny Root32148392010-01-21 15:40:47 -0800843 * Return the full path to this context's primary Android package.
844 * The Android package is a ZIP file which contains application's
845 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 *
847 * <p>Note: this is not generally useful for applications, since they should
848 * not be directly accessing the file system.
849 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 * @return String Path to the code and assets.
851 */
852 public abstract String getPackageCodePath();
853
854 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700855 * @hide
856 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700857 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700858 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100859 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700860 public File getSharedPrefsFile(String name) {
861 return getSharedPreferencesPath(name);
862 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700863
864 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 * Retrieve and hold the contents of the preferences file 'name', returning
866 * a SharedPreferences through which you can retrieve and modify its
867 * values. Only one instance of the SharedPreferences object is returned
868 * to any callers for the same name, meaning they will see each other's
869 * edits as soon as they are made.
870 *
Nate Fischer5272c372019-08-27 16:37:00 -0700871 * <p>This method is thread-safe.
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700872 *
Nate Fischer5272c372019-08-27 16:37:00 -0700873 * <p>If the preferences directory does not already exist, it will be created when this method
874 * is called.
875 *
876 * <p>If a preferences file by this name does not exist, it will be created when you retrieve an
877 * editor ({@link SharedPreferences#edit()}) and then commit changes ({@link
878 * SharedPreferences.Editor#commit()} or {@link SharedPreferences.Editor#apply()}).
879 *
880 * @param name Desired preferences file.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600881 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400883 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800884 * to retrieve and modify the preference values.
885 *
886 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600888 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700889
890 /**
891 * Retrieve and hold the contents of the preferences file, returning
892 * a SharedPreferences through which you can retrieve and modify its
893 * values. Only one instance of the SharedPreferences object is returned
894 * to any callers for the same name, meaning they will see each other's
895 * edits as soon as they are made.
896 *
897 * @param file Desired preferences file. If a preferences file by this name
898 * does not exist, it will be created when you retrieve an
899 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600900 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700901 *
902 * @return The single {@link SharedPreferences} instance that can be used
903 * to retrieve and modify the preference values.
904 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700905 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700906 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600907 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700908 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600909 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800910
911 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600912 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700913 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600914 * storage locations after an upgrade, such as moving to device protected
915 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700916 *
917 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600918 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700919 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600920 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700921 * preferences didn't exist in the source context, otherwise
922 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600923 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700924 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600925 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
926
Jeff Sharkey35871f22016-01-29 17:13:29 -0700927 /**
928 * Delete an existing shared preferences file.
929 *
930 * @param name The name (unique in the application package) of the shared
931 * preferences file.
932 * @return {@code true} if the shared preferences file was successfully
933 * deleted; else {@code false}.
934 * @see #getSharedPreferences(String, int)
935 */
936 public abstract boolean deleteSharedPreferences(String name);
937
Christopher Tatefe2368c2017-05-17 15:42:35 -0700938 /** @hide */
939 public abstract void reloadSharedPreferences();
940
Jeff Sharkey35871f22016-01-29 17:13:29 -0700941 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800942 * Open a private file associated with this Context's application package
943 * for reading.
944 *
945 * @param name The name of the file to open; can not contain path
946 * separators.
947 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400948 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800949 *
950 * @see #openFileOutput
951 * @see #fileList
952 * @see #deleteFile
953 * @see java.io.FileInputStream#FileInputStream(String)
954 */
955 public abstract FileInputStream openFileInput(String name)
956 throws FileNotFoundException;
957
958 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800959 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700960 * for writing. Creates the file if it doesn't already exist.
961 * <p>
962 * No additional permissions are required for the calling app to read or
963 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700964 *
Nick Kralevich15069212013-01-09 15:54:56 -0800965 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700966 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600967 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400968 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 * @see #MODE_APPEND
970 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 * @see #openFileInput
972 * @see #fileList
973 * @see #deleteFile
974 * @see java.io.FileOutputStream#FileOutputStream(String)
975 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600976 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800977 throws FileNotFoundException;
978
979 /**
980 * Delete the given private file associated with this Context's
981 * application package.
982 *
983 * @param name The name of the file to delete; can not contain path
984 * separators.
985 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400986 * @return {@code true} if the file was successfully deleted; else
987 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 *
989 * @see #openFileInput
990 * @see #openFileOutput
991 * @see #fileList
992 * @see java.io.File#delete()
993 */
994 public abstract boolean deleteFile(String name);
995
996 /**
997 * Returns the absolute path on the filesystem where a file created with
998 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700999 * <p>
1000 * The returned path may change over time if the calling app is moved to an
1001 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001002 *
1003 * @param name The name of the file for which you would like to get
1004 * its path.
1005 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001006 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 *
1008 * @see #openFileOutput
1009 * @see #getFilesDir
1010 * @see #getDir
1011 */
1012 public abstract File getFileStreamPath(String name);
1013
1014 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001015 * Returns the absolute path on the filesystem where a file created with
1016 * {@link #getSharedPreferences(String, int)} is stored.
1017 * <p>
1018 * The returned path may change over time if the calling app is moved to an
1019 * adopted storage device, so only relative paths should be persisted.
1020 *
1021 * @param name The name of the shared preferences for which you would like
1022 * to get a path.
1023 * @return An absolute path to the given file.
1024 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001025 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001026 */
1027 public abstract File getSharedPreferencesPath(String name);
1028
1029 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001030 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001031 * private files belonging to this app are stored. Apps should not use this
1032 * path directly; they should instead use {@link #getFilesDir()},
1033 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1034 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001035 * <p>
1036 * The returned path may change over time if the calling app is moved to an
1037 * adopted storage device, so only relative paths should be persisted.
1038 * <p>
1039 * No additional permissions are required for the calling app to read or
1040 * write files under the returned path.
1041 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001042 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001043 */
1044 public abstract File getDataDir();
1045
1046 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001047 * Returns the absolute path to the directory on the filesystem where files
1048 * created with {@link #openFileOutput} are stored.
1049 * <p>
1050 * The returned path may change over time if the calling app is moved to an
1051 * adopted storage device, so only relative paths should be persisted.
1052 * <p>
1053 * No additional permissions are required for the calling app to read or
1054 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -07001055 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001056 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001057 * @see #openFileOutput
1058 * @see #getFileStreamPath
1059 * @see #getDir
1060 */
1061 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -07001062
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001063 /**
Felka Chang0d824d42019-11-19 15:06:52 +08001064 * Returns the absolute path to the directory that is related to the crate on the filesystem.
1065 * <p>
1066 * The crateId require a validated file name. It can't contain any "..", ".",
1067 * {@link File#separatorChar} etc..
1068 * </p>
1069 * <p>
1070 * The returned path may change over time if the calling app is moved to an
1071 * adopted storage device, so only relative paths should be persisted.
1072 * </p>
1073 * <p>
1074 * No additional permissions are required for the calling app to read or
1075 * write files under the returned path.
1076 *</p>
1077 *
1078 * @param crateId the relative validated file name under {@link Context#getDataDir()}/crates
1079 * @return the crate directory file.
1080 * @hide
1081 */
1082 @NonNull
1083 @TestApi
1084 public File getCrateDir(@NonNull String crateId) {
1085 throw new RuntimeException("Not implemented. Must override in a subclass.");
1086 }
1087
1088 /**
Christopher Tatea7835b62014-07-11 17:25:57 -07001089 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001090 * {@link #getFilesDir()}. The difference is that files placed under this
1091 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -07001092 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1093 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001094 * <p>
1095 * The returned path may change over time if the calling app is moved to an
1096 * adopted storage device, so only relative paths should be persisted.
1097 * <p>
1098 * No additional permissions are required for the calling app to read or
1099 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -07001100 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001101 * @return The path of the directory holding application files that will not
1102 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -07001103 * @see #openFileOutput
1104 * @see #getFileStreamPath
1105 * @see #getDir
1106 * @see android.app.backup.BackupAgent
1107 */
1108 public abstract File getNoBackupFilesDir();
1109
1110 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001111 * Returns the absolute path to the directory on the primary shared/external
1112 * storage device where the application can place persistent files it owns.
1113 * These files are internal to the applications, and not typically visible
1114 * to the user as media.
1115 * <p>
1116 * This is like {@link #getFilesDir()} in that these files will be deleted
1117 * when the application is uninstalled, however there are some important
1118 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001119 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001120 * <li>Shared storage may not always be available, since removable media can
1121 * be ejected by the user. Media state can be checked using
1122 * {@link Environment#getExternalStorageState(File)}.
1123 * <li>There is no security enforced with these files. For example, any
1124 * application holding
1125 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001126 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001127 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001128 * <p>
1129 * If a shared storage device is emulated (as determined by
1130 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1131 * backed by a private user data partition, which means there is little
1132 * benefit to storing data here instead of the private directories returned
1133 * by {@link #getFilesDir()}, etc.
1134 * <p>
1135 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001136 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001137 * accessible to the calling app. This only applies to paths generated for
1138 * package name of the calling application. To access paths belonging to
1139 * other packages,
1140 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1141 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1142 * <p>
1143 * On devices with multiple users (as described by {@link UserManager}),
1144 * each user has their own isolated shared storage. Applications only have
1145 * access to the shared storage for the user they're running as.
1146 * <p>
1147 * The returned path may change over time if different shared storage media
1148 * is inserted, so only relative paths should be persisted.
1149 * <p>
1150 * Here is an example of typical code to manipulate a file in an
1151 * application's shared storage:
1152 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001153 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1154 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001155 * <p>
1156 * If you supply a non-null <var>type</var> to this function, the returned
1157 * file will be a path to a sub-directory of the given type. Though these
1158 * files are not automatically scanned by the media scanner, you can
1159 * explicitly add them to the media database with
1160 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1161 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001162 * {@link android.os.Environment#getExternalStoragePublicDirectory
1163 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001164 * directories of media shared by all applications. The directories returned
1165 * here are owned by the application, and their contents will be removed
1166 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001167 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001168 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1169 * here will be automatically created for you.
1170 * <p>
1171 * Here is an example of typical code to manipulate a picture in an
1172 * application's shared storage and add it to the media database:
1173 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001174 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1175 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001176 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001177 * @param type The type of files directory to return. May be {@code null}
1178 * for the root of the files directory or one of the following
1179 * constants for a subdirectory:
1180 * {@link android.os.Environment#DIRECTORY_MUSIC},
1181 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1182 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1183 * {@link android.os.Environment#DIRECTORY_ALARMS},
1184 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1185 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1186 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1187 * @return the absolute path to application-specific directory. May return
1188 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001189 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001190 * @see #getExternalFilesDirs(String)
1191 * @see Environment#getExternalStorageState(File)
1192 * @see Environment#isExternalStorageEmulated(File)
1193 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001194 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001195 @Nullable
1196 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001197
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001198 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001199 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001200 * shared/external storage devices where the application can place
1201 * persistent files it owns. These files are internal to the application,
1202 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001203 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001204 * This is like {@link #getFilesDir()} in that these files will be deleted
1205 * when the application is uninstalled, however there are some important
1206 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001207 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001208 * <li>Shared storage may not always be available, since removable media can
1209 * be ejected by the user. Media state can be checked using
1210 * {@link Environment#getExternalStorageState(File)}.
1211 * <li>There is no security enforced with these files. For example, any
1212 * application holding
1213 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1214 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001215 * </ul>
1216 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001217 * If a shared storage device is emulated (as determined by
1218 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1219 * backed by a private user data partition, which means there is little
1220 * benefit to storing data here instead of the private directories returned
1221 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001222 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001223 * Shared storage devices returned here are considered a stable part of the
1224 * device, including physical media slots under a protective cover. The
1225 * returned paths do not include transient devices, such as USB flash drives
1226 * connected to handheld devices.
1227 * <p>
1228 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001229 * example, an app may choose to store large files on the device with the
1230 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001231 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001232 * No additional permissions are required for the calling app to read or
1233 * write files under the returned path. Write access outside of these paths
1234 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001235 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001236 * The returned path may change over time if different shared storage media
1237 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001238 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001239 * @param type The type of files directory to return. May be {@code null}
1240 * for the root of the files directory or one of the following
1241 * constants for a subdirectory:
1242 * {@link android.os.Environment#DIRECTORY_MUSIC},
1243 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1244 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1245 * {@link android.os.Environment#DIRECTORY_ALARMS},
1246 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1247 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1248 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1249 * @return the absolute paths to application-specific directories. Some
1250 * individual paths may be {@code null} if that shared storage is
1251 * not currently available. The first path returned is the same as
1252 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001253 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001254 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001255 * @see Environment#isExternalStorageEmulated(File)
1256 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001257 */
1258 public abstract File[] getExternalFilesDirs(String type);
1259
1260 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001261 * Return the primary shared/external storage directory where this
1262 * application's OBB files (if there are any) can be found. Note if the
1263 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001264 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001265 * This is like {@link #getFilesDir()} in that these files will be deleted
1266 * when the application is uninstalled, however there are some important
1267 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001268 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001269 * <li>Shared storage may not always be available, since removable media can
1270 * be ejected by the user. Media state can be checked using
1271 * {@link Environment#getExternalStorageState(File)}.
1272 * <li>There is no security enforced with these files. For example, any
1273 * application holding
1274 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001275 * these files.
1276 * </ul>
1277 * <p>
1278 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001279 * are required to read or write to the path that this method returns.
1280 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1281 * to read the OBB expansion files, you must declare the
1282 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1283 * permission at runtime as follows:
1284 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001285 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001286 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1287 * android:maxSdkVersion="23" />}
1288 * </p>
1289 * <p>
1290 * Starting from {@link android.os.Build.VERSION_CODES#N},
1291 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1292 * permission is not required, so don’t ask for this
1293 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1294 * and if it fails, you must request
1295 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1296 * </p>
1297 *
1298 * <p>
1299 * The following code snippet shows how to do this:
1300 * </p>
1301 *
1302 * <pre>
1303 * File obb = new File(obb_filename);
1304 * boolean open_failed = false;
1305 *
1306 * try {
1307 * BufferedReader br = new BufferedReader(new FileReader(obb));
1308 * open_failed = false;
1309 * ReadObbFile(br);
1310 * } catch (IOException e) {
1311 * open_failed = true;
1312 * }
1313 *
1314 * if (open_failed) {
1315 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1316 * ReadObbFileWithPermission();
1317 * }
1318 * </pre>
1319 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001320 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001321 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001322 * should ensure that multiple instances running under different users don't
1323 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001324 *
1325 * @return the absolute path to application-specific directory. May return
1326 * {@code null} if shared storage is not currently available.
1327 * @see #getObbDirs()
1328 * @see Environment#getExternalStorageState(File)
1329 * @see Environment#isExternalStorageEmulated(File)
1330 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001331 */
1332 public abstract File getObbDir();
1333
1334 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001335 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001336 * shared/external storage devices where the application's OBB files (if
1337 * there are any) can be found. Note if the application does not have any
1338 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001339 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001340 * This is like {@link #getFilesDir()} in that these files will be deleted
1341 * when the application is uninstalled, however there are some important
1342 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001343 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001344 * <li>Shared storage may not always be available, since removable media can
1345 * be ejected by the user. Media state can be checked using
1346 * {@link Environment#getExternalStorageState(File)}.
1347 * <li>There is no security enforced with these files. For example, any
1348 * application holding
1349 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1350 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001351 * </ul>
1352 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001353 * Shared storage devices returned here are considered a stable part of the
1354 * device, including physical media slots under a protective cover. The
1355 * returned paths do not include transient devices, such as USB flash drives
1356 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001357 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001358 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001359 * example, an app may choose to store large files on the device with the
1360 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001361 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001362 * No additional permissions are required for the calling app to read or
1363 * write files under the returned path. Write access outside of these paths
1364 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001365 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001366 * @return the absolute paths to application-specific directories. Some
1367 * individual paths may be {@code null} if that shared storage is
1368 * not currently available. The first path returned is the same as
1369 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001370 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001371 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001372 * @see Environment#isExternalStorageEmulated(File)
1373 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001374 */
1375 public abstract File[] getObbDirs();
1376
1377 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001378 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001379 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001380 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001381 * The system will automatically delete files in this directory as disk
1382 * space is needed elsewhere on the device. The system will always delete
1383 * older files first, as reported by {@link File#lastModified()}. If
1384 * desired, you can exert more control over how files are deleted using
1385 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1386 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1387 * <p>
1388 * Apps are strongly encouraged to keep their usage of cache space below the
1389 * quota returned by
1390 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1391 * goes above this quota, your cached files will be some of the first to be
1392 * deleted when additional disk space is needed. Conversely, if your app
1393 * stays under this quota, your cached files will be some of the last to be
1394 * deleted when additional disk space is needed.
1395 * <p>
1396 * Note that your cache quota will change over time depending on how
1397 * frequently the user interacts with your app, and depending on how much
1398 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001399 * <p>
1400 * The returned path may change over time if the calling app is moved to an
1401 * adopted storage device, so only relative paths should be persisted.
1402 * <p>
1403 * Apps require no extra permissions to read or write to the returned path,
1404 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001405 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001406 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 * @see #openFileOutput
1408 * @see #getFileStreamPath
1409 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001410 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001411 */
1412 public abstract File getCacheDir();
1413
1414 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001415 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001416 * the filesystem designed for storing cached code.
1417 * <p>
1418 * The system will delete any files stored in this location both when your
1419 * specific application is upgraded, and when the entire platform is
1420 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001421 * <p>
1422 * This location is optimal for storing compiled or optimized code generated
1423 * by your application at runtime.
1424 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001425 * The returned path may change over time if the calling app is moved to an
1426 * adopted storage device, so only relative paths should be persisted.
1427 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001428 * Apps require no extra permissions to read or write to the returned path,
1429 * since this path lives in their private storage.
1430 *
1431 * @return The path of the directory holding application code cache files.
1432 */
1433 public abstract File getCodeCacheDir();
1434
1435 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001436 * Returns absolute path to application-specific directory on the primary
1437 * shared/external storage device where the application can place cache
1438 * files it owns. These files are internal to the application, and not
1439 * typically visible to the user as media.
1440 * <p>
1441 * This is like {@link #getCacheDir()} in that these files will be deleted
1442 * when the application is uninstalled, however there are some important
1443 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001444 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001445 * <li>The platform does not always monitor the space available in shared
1446 * storage, and thus may not automatically delete these files. Apps should
1447 * always manage the maximum space used in this location. Currently the only
1448 * time files here will be deleted by the platform is when running on
1449 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1450 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1451 * <li>Shared storage may not always be available, since removable media can
1452 * be ejected by the user. Media state can be checked using
1453 * {@link Environment#getExternalStorageState(File)}.
1454 * <li>There is no security enforced with these files. For example, any
1455 * application holding
1456 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001457 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001458 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001459 * <p>
1460 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001461 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001462 * backed by a private user data partition, which means there is little
1463 * benefit to storing data here instead of the private directory returned by
1464 * {@link #getCacheDir()}.
1465 * <p>
1466 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001467 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001468 * accessible to the calling app. This only applies to paths generated for
1469 * package name of the calling application. To access paths belonging to
1470 * other packages,
1471 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1472 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1473 * <p>
1474 * On devices with multiple users (as described by {@link UserManager}),
1475 * each user has their own isolated shared storage. Applications only have
1476 * access to the shared storage for the user they're running as.
1477 * <p>
1478 * The returned path may change over time if different shared storage media
1479 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001480 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001481 * @return the absolute path to application-specific directory. May return
1482 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001483 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001484 * @see #getExternalCacheDirs()
1485 * @see Environment#getExternalStorageState(File)
1486 * @see Environment#isExternalStorageEmulated(File)
1487 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001488 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001489 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001490 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001491
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001492 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001493 * Returns absolute path to application-specific directory in the preloaded cache.
1494 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1495 * There is no guarantee when these files will be deleted.
1496 * @hide
1497 */
1498 @Nullable
1499 @SystemApi
1500 public abstract File getPreloadsFileCache();
1501
1502 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001503 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001504 * shared/external storage devices where the application can place cache
1505 * files it owns. These files are internal to the application, and not
1506 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001507 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001508 * This is like {@link #getCacheDir()} in that these files will be deleted
1509 * when the application is uninstalled, however there are some important
1510 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001511 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001512 * <li>The platform does not always monitor the space available in shared
1513 * storage, and thus may not automatically delete these files. Apps should
1514 * always manage the maximum space used in this location. Currently the only
1515 * time files here will be deleted by the platform is when running on
1516 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1517 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1518 * <li>Shared storage may not always be available, since removable media can
1519 * be ejected by the user. Media state can be checked using
1520 * {@link Environment#getExternalStorageState(File)}.
1521 * <li>There is no security enforced with these files. For example, any
1522 * application holding
1523 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1524 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001525 * </ul>
1526 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001527 * If a shared storage device is emulated (as determined by
1528 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1529 * backed by a private user data partition, which means there is little
1530 * benefit to storing data here instead of the private directory returned by
1531 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001532 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001533 * Shared storage devices returned here are considered a stable part of the
1534 * device, including physical media slots under a protective cover. The
1535 * returned paths do not include transient devices, such as USB flash drives
1536 * connected to handheld devices.
1537 * <p>
1538 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001539 * example, an app may choose to store large files on the device with the
1540 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001541 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001542 * No additional permissions are required for the calling app to read or
1543 * write files under the returned path. Write access outside of these paths
1544 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001545 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001546 * The returned paths may change over time if different shared storage media
1547 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001548 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001549 * @return the absolute paths to application-specific directories. Some
1550 * individual paths may be {@code null} if that shared storage is
1551 * not currently available. The first path returned is the same as
1552 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001553 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001554 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001555 * @see Environment#isExternalStorageEmulated(File)
1556 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001557 */
1558 public abstract File[] getExternalCacheDirs();
1559
1560 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001561 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001562 * shared/external storage devices where the application can place media
1563 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001564 * {@link MediaStore}.
1565 * <p>
1566 * This is like {@link #getExternalFilesDirs} in that these files will be
1567 * deleted when the application is uninstalled, however there are some
1568 * important differences:
1569 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001570 * <li>Shared storage may not always be available, since removable media can
1571 * be ejected by the user. Media state can be checked using
1572 * {@link Environment#getExternalStorageState(File)}.
1573 * <li>There is no security enforced with these files. For example, any
1574 * application holding
1575 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1576 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001577 * </ul>
1578 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001579 * Shared storage devices returned here are considered a stable part of the
1580 * device, including physical media slots under a protective cover. The
1581 * returned paths do not include transient devices, such as USB flash drives
1582 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001583 * <p>
1584 * An application may store data on any or all of the returned devices. For
1585 * example, an app may choose to store large files on the device with the
1586 * most available space, as measured by {@link StatFs}.
1587 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001588 * No additional permissions are required for the calling app to read or
1589 * write files under the returned path. Write access outside of these paths
1590 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001591 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001592 * The returned paths may change over time if different shared storage media
1593 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001594 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001595 * @return the absolute paths to application-specific directories. Some
1596 * individual paths may be {@code null} if that shared storage is
1597 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001598 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001599 * @see Environment#isExternalStorageEmulated(File)
1600 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey588c15e2019-10-10 17:29:58 -06001601 * @deprecated These directories still exist and are scanned, but developers
1602 * are encouraged to migrate to inserting content into a
1603 * {@link MediaStore} collection directly, as any app can
1604 * contribute new media to {@link MediaStore} with no
1605 * permissions required, starting in
1606 * {@link android.os.Build.VERSION_CODES#Q}.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001607 */
Jeff Sharkey588c15e2019-10-10 17:29:58 -06001608 @Deprecated
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001609 public abstract File[] getExternalMediaDirs();
1610
1611 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 * Returns an array of strings naming the private files associated with
1613 * this Context's application package.
1614 *
1615 * @return Array of strings naming the private files.
1616 *
1617 * @see #openFileInput
1618 * @see #openFileOutput
1619 * @see #deleteFile
1620 */
1621 public abstract String[] fileList();
1622
1623 /**
1624 * Retrieve, creating if needed, a new directory in which the application
1625 * can place its own custom data files. You can use the returned File
1626 * object to create and access files in this directory. Note that files
1627 * created through a File object will only be accessible by your own
1628 * application; you can only set the mode of the entire directory, not
1629 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001630 * <p>
1631 * The returned path may change over time if the calling app is moved to an
1632 * adopted storage device, so only relative paths should be persisted.
1633 * <p>
1634 * Apps require no extra permissions to read or write to the returned path,
1635 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001637 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001638 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001639 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001640 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001641 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001642 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 *
1644 * @see #openFileOutput(String, int)
1645 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001646 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647
1648 /**
1649 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001650 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001651 *
1652 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001653 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001655 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001657 * @throws android.database.sqlite.SQLiteException if the database file
1658 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001660 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001661 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 * @see #deleteDatabase
1663 */
1664 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001665 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001666
1667 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001668 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001669 * application package. Creates the database file if it doesn't exist.
1670 * <p>
1671 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1672 * to be used to handle corruption when sqlite reports database corruption.
1673 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001674 *
1675 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001676 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001677 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001678 * cursor when query is called.
1679 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1680 * sqlite reports database corruption. if null,
1681 * {@link android.database.DefaultDatabaseErrorHandler} is
1682 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001683 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001684 * @throws android.database.sqlite.SQLiteException if the database file
1685 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001686 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001687 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001688 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001689 * @see #deleteDatabase
1690 */
1691 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001692 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001693 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001694
1695 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001696 * Move an existing database file from the given source storage context to
1697 * this context. This is typically used to migrate data between storage
1698 * locations after an upgrade, such as migrating to device protected
1699 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001700 * <p>
1701 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001702 *
1703 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001704 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001705 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001706 * @return {@code true} if the move was successful or if the database didn't
1707 * exist in the source context, otherwise {@code false}.
1708 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001709 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001710 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1711
Jeff Sharkey35871f22016-01-29 17:13:29 -07001712 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 * Delete an existing private SQLiteDatabase associated with this Context's
1714 * application package.
1715 *
1716 * @param name The name (unique in the application package) of the
1717 * database.
1718 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001719 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 *
1721 * @see #openOrCreateDatabase
1722 */
1723 public abstract boolean deleteDatabase(String name);
1724
1725 /**
1726 * Returns the absolute path on the filesystem where a database created with
1727 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001728 * <p>
1729 * The returned path may change over time if the calling app is moved to an
1730 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001731 *
1732 * @param name The name of the database for which you would like to get
1733 * its path.
1734 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001735 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 *
1737 * @see #openOrCreateDatabase
1738 */
1739 public abstract File getDatabasePath(String name);
1740
1741 /**
1742 * Returns an array of strings naming the private databases associated with
1743 * this Context's application package.
1744 *
1745 * @return Array of strings naming the private databases.
1746 *
1747 * @see #openOrCreateDatabase
1748 * @see #deleteDatabase
1749 */
1750 public abstract String[] databaseList();
1751
1752 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001753 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001754 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001755 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001756 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001757 public abstract Drawable getWallpaper();
1758
1759 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001760 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001761 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001763 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001764 public abstract Drawable peekWallpaper();
1765
1766 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001767 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1768 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001769 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001770 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 public abstract int getWallpaperDesiredMinimumWidth();
1772
1773 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001774 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1775 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001776 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001777 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001778 public abstract int getWallpaperDesiredMinimumHeight();
1779
1780 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001781 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001782 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001783 * <p>This method requires the caller to hold the permission
1784 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001785 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001786 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1788
1789 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001790 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001791 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001792 * <p>This method requires the caller to hold the permission
1793 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001795 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 public abstract void setWallpaper(InputStream data) throws IOException;
1797
1798 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001799 * @deprecated Use {@link android.app.WallpaperManager#clear
1800 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001801 * <p>This method requires the caller to hold the permission
1802 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001804 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 public abstract void clearWallpaper() throws IOException;
1806
1807 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001808 * Same as {@link #startActivity(Intent, Bundle)} with no options
1809 * specified.
1810 *
1811 * @param intent The description of the activity to start.
1812 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001813 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001814 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001815 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001816 * @see PackageManager#resolveActivity
1817 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001818 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001819
1820 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001821 * Version of {@link #startActivity(Intent)} that allows you to specify the
1822 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001823 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001824 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001825 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001826 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001827 * @hide
1828 */
Jonathan Scott92335342019-12-17 14:46:26 +00001829 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07001830 @SystemApi
Nate Myren3f262712019-05-31 09:36:08 -07001831 @TestApi
Adrian Roosebc927c2019-02-28 16:21:18 +01001832 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1833 @NonNull UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001834 throw new RuntimeException("Not implemented. Must override in a subclass.");
1835 }
1836
1837 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001838 * Launch a new activity. You will not receive any information about when
1839 * the activity exits.
1840 *
1841 * <p>Note that if this method is being called from outside of an
1842 * {@link android.app.Activity} Context, then the Intent must include
1843 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1844 * without being started from an existing Activity, there is no existing
1845 * task in which to place the new activity and thus it needs to be placed
1846 * in its own separate task.
1847 *
1848 * <p>This method throws {@link ActivityNotFoundException}
1849 * if there was no Activity found to run the given Intent.
1850 *
1851 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001852 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001853 * May be null if there are no options. See {@link android.app.ActivityOptions}
1854 * for how to build the Bundle supplied here; there are no supported definitions
1855 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001857 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001858 *
Scott Main60dd5202012-06-23 00:01:22 -07001859 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001860 * @see PackageManager#resolveActivity
1861 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001862 public abstract void startActivity(@RequiresPermission Intent intent,
1863 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001864
1865 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001866 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1867 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001868 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001869 * @param intent The description of the activity to start.
1870 * @param options Additional options for how the Activity should be started.
1871 * May be null if there are no options. See {@link android.app.ActivityOptions}
1872 * for how to build the Bundle supplied here; there are no supported definitions
1873 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001874 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001875 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001876 * @hide
1877 */
Jonathan Scott92335342019-12-17 14:46:26 +00001878 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001879 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001880 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1881 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001882 throw new RuntimeException("Not implemented. Must override in a subclass.");
1883 }
1884
1885 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001886 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1887 * is only supported for Views and Fragments.
1888 * @param who The identifier for the calling element that will receive the result.
1889 * @param intent The intent to start.
1890 * @param requestCode The code that will be returned with onActivityResult() identifying this
1891 * request.
1892 * @param options Additional options for how the Activity should be started.
1893 * May be null if there are no options. See {@link android.app.ActivityOptions}
1894 * for how to build the Bundle supplied here; there are no supported definitions
1895 * for building it manually.
1896 * @hide
1897 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001898 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001899 public void startActivityForResult(
1900 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1901 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1902 + "Check canStartActivityForResult() before calling.");
1903 }
1904
1905 /**
1906 * Identifies whether this Context instance will be able to process calls to
1907 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1908 * @hide
1909 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001910 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001911 public boolean canStartActivityForResult() {
1912 return false;
1913 }
1914
1915 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001916 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1917 * specified.
1918 *
1919 * @param intents An array of Intents to be started.
1920 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001921 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001922 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001923 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001924 * @see PackageManager#resolveActivity
1925 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001926 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927
1928 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001929 * 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.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001943 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001944 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001945 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001946 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001947 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001948 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001949 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001950 * @see PackageManager#resolveActivity
1951 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001952 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001953
1954 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001955 * @hide
1956 * Launch multiple new activities. This is generally the same as calling
1957 * {@link #startActivity(Intent)} for the first Intent in the array,
1958 * that activity during its creation calling {@link #startActivity(Intent)}
1959 * for the second entry, etc. Note that unlike that approach, generally
1960 * none of the activities except the last in the array will be created
1961 * at this point, but rather will be created when the user first visits
1962 * them (due to pressing back from the activity on top).
1963 *
1964 * <p>This method throws {@link ActivityNotFoundException}
1965 * if there was no Activity found for <em>any</em> given Intent. In this
1966 * case the state of the activity stack is undefined (some Intents in the
1967 * list may be on it, some not), so you probably want to avoid such situations.
1968 *
1969 * @param intents An array of Intents to be started.
1970 * @param options Additional options for how the Activity should be started.
1971 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001972 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001973 * Context.startActivity(Intent, Bundle)} for more details.
1974 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001975 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1976 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1977 * successful.
1978 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001979 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001980 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001981 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001982 * @see PackageManager#resolveActivity
1983 */
Jonathan Scott92335342019-12-17 14:46:26 +00001984 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001985 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001986 throw new RuntimeException("Not implemented. Must override in a subclass.");
1987 }
1988
1989 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001990 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1991 * with no options specified.
1992 *
1993 * @param intent The IntentSender to launch.
1994 * @param fillInIntent If non-null, this will be provided as the
1995 * intent parameter to {@link IntentSender#sendIntent}.
1996 * @param flagsMask Intent flags in the original IntentSender that you
1997 * would like to change.
1998 * @param flagsValues Desired values for any bits set in
1999 * <var>flagsMask</var>
2000 * @param extraFlags Always set to 0.
2001 *
2002 * @see #startActivity(Intent)
2003 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
2004 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002005 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
2006 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
2007 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07002008
2009 /**
2010 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002011 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07002012 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002013 * here; otherwise, its associated action will be executed (such as
2014 * sending a broadcast) as if you had called
2015 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07002016 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002017 * @param intent The IntentSender to launch.
2018 * @param fillInIntent If non-null, this will be provided as the
2019 * intent parameter to {@link IntentSender#sendIntent}.
2020 * @param flagsMask Intent flags in the original IntentSender that you
2021 * would like to change.
2022 * @param flagsValues Desired values for any bits set in
2023 * <var>flagsMask</var>
2024 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07002025 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08002026 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07002027 * Context.startActivity(Intent, Bundle)} for more details. If options
2028 * have also been supplied by the IntentSender, options given here will
2029 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07002030 *
2031 * @see #startActivity(Intent, Bundle)
2032 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002033 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002034 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
2035 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
2036 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07002037
2038 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 * Broadcast the given intent to all interested BroadcastReceivers. This
2040 * call is asynchronous; it returns immediately, and you will continue
2041 * executing while the receivers are run. No results are propagated from
2042 * receivers and receivers can not abort the broadcast. If you want
2043 * to allow receivers to propagate results or abort the broadcast, you must
2044 * send an ordered broadcast using
2045 * {@link #sendOrderedBroadcast(Intent, String)}.
2046 *
2047 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2048 *
2049 * @param intent The Intent to broadcast; all receivers matching this
2050 * Intent will receive the broadcast.
2051 *
2052 * @see android.content.BroadcastReceiver
2053 * @see #registerReceiver
2054 * @see #sendBroadcast(Intent, String)
2055 * @see #sendOrderedBroadcast(Intent, String)
2056 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2057 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002058 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059
2060 /**
2061 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2062 * an optional required permission to be enforced. This
2063 * call is asynchronous; it returns immediately, and you will continue
2064 * executing while the receivers are run. No results are propagated from
2065 * receivers and receivers can not abort the broadcast. If you want
2066 * to allow receivers to propagate results or abort the broadcast, you must
2067 * send an ordered broadcast using
2068 * {@link #sendOrderedBroadcast(Intent, String)}.
2069 *
2070 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2071 *
2072 * @param intent The Intent to broadcast; all receivers matching this
2073 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08002074 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 * a receiver must hold in order to receive your broadcast.
2076 * If null, no permission is required.
2077 *
2078 * @see android.content.BroadcastReceiver
2079 * @see #registerReceiver
2080 * @see #sendBroadcast(Intent)
2081 * @see #sendOrderedBroadcast(Intent, String)
2082 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2083 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002084 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002085 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002086
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002087
2088 /**
2089 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2090 * an array of required permissions to be enforced. This call is asynchronous; it returns
2091 * immediately, and you will continue executing while the receivers are run. No results are
2092 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2093 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2094 * using {@link #sendOrderedBroadcast(Intent, String)}.
2095 *
2096 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2097 *
2098 * @param intent The Intent to broadcast; all receivers matching this
2099 * Intent will receive the broadcast.
2100 * @param receiverPermissions Array of names of permissions that a receiver must hold
2101 * in order to receive your broadcast.
Roshan Pius3fe42f02019-11-12 09:56:48 -08002102 * If empty, no permissions are required.
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002103 *
2104 * @see android.content.BroadcastReceiver
2105 * @see #registerReceiver
2106 * @see #sendBroadcast(Intent)
2107 * @see #sendOrderedBroadcast(Intent, String)
2108 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2109 * @hide
2110 */
Roshan Pius3fe42f02019-11-12 09:56:48 -08002111 public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2112 @NonNull String[] receiverPermissions) {
2113 throw new RuntimeException("Not implemented. Must override in a subclass.");
2114 }
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002115
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002116 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002117 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07002118 * 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.
Roshan Piusa2baf58e2019-11-20 14:40:30 -08002128 * @param receiverPermissions Array of names of permissions that a receiver must hold
2129 * in order to receive your broadcast.
2130 * If empty, no permissions are required.
2131 *
2132 * @see android.content.BroadcastReceiver
2133 * @see #registerReceiver
2134 * @see #sendBroadcast(Intent)
2135 * @see #sendOrderedBroadcast(Intent, String)
2136 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2137 */
2138 public void sendBroadcastWithMultiplePermissions(@NonNull Intent intent,
2139 @NonNull String[] receiverPermissions) {
2140 sendBroadcastMultiplePermissions(intent, receiverPermissions);
2141 }
2142
2143 /**
2144 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2145 * an array of required permissions to be enforced. This call is asynchronous; it returns
2146 * immediately, and you will continue executing while the receivers are run. No results are
2147 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2148 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2149 * using {@link #sendOrderedBroadcast(Intent, String)}.
2150 *
2151 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2152 *
2153 * @param intent The Intent to broadcast; all receivers matching this
2154 * Intent will receive the broadcast.
Tyler Gunnf955e562018-04-26 14:43:31 -07002155 * @param user The user to send the broadcast to.
2156 * @param receiverPermissions Array of names of permissions that a receiver must hold
2157 * in order to receive your broadcast.
2158 * If null or empty, no permissions are required.
2159 *
2160 * @see android.content.BroadcastReceiver
2161 * @see #registerReceiver
2162 * @see #sendBroadcast(Intent)
2163 * @see #sendOrderedBroadcast(Intent, String)
2164 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2165 * @hide
2166 */
2167 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2168 String[] receiverPermissions);
2169
2170 /**
2171 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002172 * an optional required permission to be enforced. This
2173 * call is asynchronous; it returns immediately, and you will continue
2174 * executing while the receivers are run. No results are propagated from
2175 * receivers and receivers can not abort the broadcast. If you want
2176 * to allow receivers to propagate results or abort the broadcast, you must
2177 * send an ordered broadcast using
2178 * {@link #sendOrderedBroadcast(Intent, String)}.
2179 *
2180 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2181 *
2182 * @param intent The Intent to broadcast; all receivers matching this
2183 * Intent will receive the broadcast.
2184 * @param receiverPermission (optional) String naming a permission that
2185 * a receiver must hold in order to receive your broadcast.
2186 * If null, no permission is required.
2187 * @param options (optional) Additional sending options, generated from a
2188 * {@link android.app.BroadcastOptions}.
2189 *
2190 * @see android.content.BroadcastReceiver
2191 * @see #registerReceiver
2192 * @see #sendBroadcast(Intent)
2193 * @see #sendOrderedBroadcast(Intent, String)
2194 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2195 * @hide
2196 */
2197 @SystemApi
2198 public abstract void sendBroadcast(Intent intent,
2199 @Nullable String receiverPermission,
2200 @Nullable Bundle options);
2201
2202 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002203 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002204 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002205 * @hide
2206 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002207 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002208 public abstract void sendBroadcast(Intent intent,
2209 String receiverPermission, int appOp);
2210
2211 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002212 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2213 * them one at a time to allow more preferred receivers to consume the
2214 * broadcast before it is delivered to less preferred receivers. This
2215 * call is asynchronous; it returns immediately, and you will continue
2216 * executing while the receivers are run.
2217 *
2218 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2219 *
2220 * @param intent The Intent to broadcast; all receivers matching this
2221 * Intent will receive the broadcast.
2222 * @param receiverPermission (optional) String naming a permissions that
2223 * a receiver must hold in order to receive your broadcast.
2224 * If null, no permission is required.
2225 *
2226 * @see android.content.BroadcastReceiver
2227 * @see #registerReceiver
2228 * @see #sendBroadcast(Intent)
2229 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2230 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002231 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002232 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002233
2234 /**
2235 * Version of {@link #sendBroadcast(Intent)} that allows you to
2236 * receive data back from the broadcast. This is accomplished by
2237 * supplying your own BroadcastReceiver when calling, which will be
2238 * treated as a final receiver at the end of the broadcast -- its
2239 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002240 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002241 * be serialized in the same way as calling
2242 * {@link #sendOrderedBroadcast(Intent, String)}.
2243 *
2244 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2245 * asynchronous; it will return before
2246 * resultReceiver.onReceive() is called.
2247 *
2248 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2249 *
2250 * @param intent The Intent to broadcast; all receivers matching this
2251 * Intent will receive the broadcast.
2252 * @param receiverPermission String naming a permissions that
2253 * a receiver must hold in order to receive your broadcast.
2254 * If null, no permission is required.
2255 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2256 * receiver of the broadcast.
2257 * @param scheduler A custom Handler with which to schedule the
2258 * resultReceiver callback; if null it will be
2259 * scheduled in the Context's main thread.
2260 * @param initialCode An initial value for the result code. Often
2261 * Activity.RESULT_OK.
2262 * @param initialData An initial value for the result data. Often
2263 * null.
2264 * @param initialExtras An initial value for the result extras. Often
2265 * null.
2266 *
2267 * @see #sendBroadcast(Intent)
2268 * @see #sendBroadcast(Intent, String)
2269 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002270 * @see android.content.BroadcastReceiver
2271 * @see #registerReceiver
2272 * @see android.app.Activity#RESULT_OK
2273 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002274 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002275 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002276 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2277 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002278
2279 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002280 * Version of {@link #sendBroadcast(Intent)} that allows you to
2281 * receive data back from the broadcast. This is accomplished by
2282 * supplying your own BroadcastReceiver when calling, which will be
2283 * treated as a final receiver at the end of the broadcast -- its
2284 * {@link BroadcastReceiver#onReceive} method will be called with
2285 * the result values collected from the other receivers. The broadcast will
2286 * be serialized in the same way as calling
2287 * {@link #sendOrderedBroadcast(Intent, String)}.
2288 *
2289 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2290 * asynchronous; it will return before
2291 * resultReceiver.onReceive() is called.
2292 *
2293 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2294 *
2295 *
2296 * @param intent The Intent to broadcast; all receivers matching this
2297 * Intent will receive the broadcast.
2298 * @param receiverPermission String naming a permissions that
2299 * a receiver must hold in order to receive your broadcast.
2300 * If null, no permission is required.
2301 * @param options (optional) Additional sending options, generated from a
2302 * {@link android.app.BroadcastOptions}.
2303 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2304 * receiver of the broadcast.
2305 * @param scheduler A custom Handler with which to schedule the
2306 * resultReceiver callback; if null it will be
2307 * scheduled in the Context's main thread.
2308 * @param initialCode An initial value for the result code. Often
2309 * Activity.RESULT_OK.
2310 * @param initialData An initial value for the result data. Often
2311 * null.
2312 * @param initialExtras An initial value for the result extras. Often
2313 * null.
2314 * @see #sendBroadcast(Intent)
2315 * @see #sendBroadcast(Intent, String)
2316 * @see #sendOrderedBroadcast(Intent, String)
2317 * @see android.content.BroadcastReceiver
2318 * @see #registerReceiver
2319 * @see android.app.Activity#RESULT_OK
2320 * @hide
2321 */
2322 @SystemApi
2323 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2324 @Nullable String receiverPermission, @Nullable Bundle options,
2325 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2326 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2327
2328 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002329 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2330 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002331 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002332 * @hide
2333 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002334 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002335 public abstract void sendOrderedBroadcast(Intent intent,
2336 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2337 Handler scheduler, int initialCode, String initialData,
2338 Bundle initialExtras);
2339
2340 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002341 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2342 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002343 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002344 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002345 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002346 * @see #sendBroadcast(Intent)
2347 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002348 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002349 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2350 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002351
2352 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002353 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2354 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002355 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002356 *
2357 * @param intent The Intent to broadcast; all receivers matching this
2358 * Intent will receive the broadcast.
2359 * @param user UserHandle to send the intent to.
2360 * @param receiverPermission (optional) String naming a permission that
2361 * a receiver must hold in order to receive your broadcast.
2362 * If null, no permission is required.
2363 *
2364 * @see #sendBroadcast(Intent, String)
2365 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002366 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002367 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2368 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002369
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002370 /**
2371 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2372 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002373 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002374 *
2375 * @param intent The Intent to broadcast; all receivers matching this
2376 * Intent will receive the broadcast.
2377 * @param user UserHandle to send the intent to.
2378 * @param receiverPermission (optional) String naming a permission that
2379 * a receiver must hold in order to receive your broadcast.
2380 * If null, no permission is required.
2381 * @param options (optional) Additional sending options, generated from a
2382 * {@link android.app.BroadcastOptions}.
2383 *
2384 * @see #sendBroadcast(Intent, String, Bundle)
2385 * @hide
2386 */
2387 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002388 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002389 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2390 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002391
2392 /**
2393 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2394 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002395 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002396 *
2397 * @param intent The Intent to broadcast; all receivers matching this
2398 * Intent will receive the broadcast.
2399 * @param user UserHandle to send the intent to.
2400 * @param receiverPermission (optional) String naming a permission that
2401 * a receiver must hold in order to receive your broadcast.
2402 * If null, no permission is required.
2403 * @param appOp The app op associated with the broadcast.
2404 *
2405 * @see #sendBroadcast(Intent, String)
2406 *
2407 * @hide
2408 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002409 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002410 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002411 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2412 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002413
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002414 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002415 * Version of
2416 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2417 * that allows you to specify the
2418 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002419 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002420 *
2421 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2422 *
2423 * @param intent The Intent to broadcast; all receivers matching this
2424 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002425 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002426 * @param receiverPermission String naming a permissions that
2427 * a receiver must hold in order to receive your broadcast.
2428 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002429 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2430 * receiver of the broadcast.
2431 * @param scheduler A custom Handler with which to schedule the
2432 * resultReceiver callback; if null it will be
2433 * scheduled in the Context's main thread.
2434 * @param initialCode An initial value for the result code. Often
2435 * Activity.RESULT_OK.
2436 * @param initialData An initial value for the result data. Often
2437 * null.
2438 * @param initialExtras An initial value for the result extras. Often
2439 * null.
2440 *
2441 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2442 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002443 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002444 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2445 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002446 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2447 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002448
2449 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002450 * Similar to above but takes an appOp as well, to enforce restrictions.
2451 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2452 * BroadcastReceiver, Handler, int, String, Bundle)
2453 * @hide
2454 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002455 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002456 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002457 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2458 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2459 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2460 @Nullable Bundle initialExtras);
2461
2462 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002463 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2464 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2465 * BroadcastReceiver, Handler, int, String, Bundle)
2466 * @hide
2467 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002468 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002469 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002470 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2471 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2472 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2473 @Nullable String initialData, @Nullable Bundle initialExtras);
2474
2475 /**
Jordan Liu54735532019-10-29 10:33:55 -07002476 * Version of
2477 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2478 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2479 * the broadcast will be sent to.
2480 *
2481 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2482 *
2483 * @param intent The Intent to broadcast; all receivers matching this
2484 * Intent will receive the broadcast.
2485 * @param receiverPermission String naming a permissions that
2486 * a receiver must hold in order to receive your broadcast.
2487 * If null, no permission is required.
2488 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2489 * required. If both receiverAppOp and receiverPermission are non-null,
2490 * a receiver must have both of them to
2491 * receive the broadcast
2492 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2493 * receiver of the broadcast.
2494 * @param scheduler A custom Handler with which to schedule the
2495 * resultReceiver callback; if null it will be
2496 * scheduled in the Context's main thread.
2497 * @param initialCode An initial value for the result code. Often
2498 * Activity.RESULT_OK.
2499 * @param initialData An initial value for the result data. Often
2500 * null.
2501 * @param initialExtras An initial value for the result extras. Often
2502 * null.
2503 *
2504 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2505 */
Jordan Liu31a4da62019-11-19 11:36:34 -08002506 public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission,
2507 @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
2508 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2509 @Nullable Bundle initialExtras) {
Jordan Liu54735532019-10-29 10:33:55 -07002510 throw new RuntimeException("Not implemented. Must override in a subclass.");
2511 }
2512
2513 /**
Peter Wang7701f572019-11-07 16:57:23 -08002514 * Version of
2515 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2516 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2517 * the broadcast will be sent to as well as supply an optional sending options
2518 *
2519 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2520 *
2521 * @param intent The Intent to broadcast; all receivers matching this
2522 * Intent will receive the broadcast.
2523 * @param receiverPermission String naming a permissions that
2524 * a receiver must hold in order to receive your broadcast.
2525 * If null, no permission is required.
2526 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2527 * required. If both receiverAppOp and receiverPermission are non-null,
2528 * a receiver must have both of them to
2529 * receive the broadcast
2530 * @param options (optional) Additional sending options, generated from a
2531 * {@link android.app.BroadcastOptions}.
2532 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2533 * receiver of the broadcast.
2534 * @param scheduler A custom Handler with which to schedule the
2535 * resultReceiver callback; if null it will be
2536 * scheduled in the Context's main thread.
2537 * @param initialCode An initial value for the result code. Often
2538 * Activity.RESULT_OK.
2539 * @param initialData An initial value for the result data. Often
2540 * null.
2541 * @param initialExtras An initial value for the result extras. Often
2542 * null.
2543 *
2544 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2545 * @see android.app.BroadcastOptions
2546 */
2547 public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2548 @Nullable String receiverPermission, @Nullable String receiverAppOp,
2549 @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver,
2550 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2551 @Nullable Bundle initialExtras) {
2552 throw new RuntimeException("Not implemented. Must override in a subclass.");
2553 }
2554
2555 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002556 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002557 * Intent you are sending stays around after the broadcast is complete,
2558 * so that others can quickly retrieve that data through the return
2559 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2560 * all other ways, this behaves the same as
2561 * {@link #sendBroadcast(Intent)}.
2562 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002563 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2564 * can access them), no protection (anyone can modify them), and many other problems.
2565 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2566 * has changed, with another mechanism for apps to retrieve the current value whenever
2567 * desired.
2568 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 * @param intent The Intent to broadcast; all receivers matching this
2570 * Intent will receive the broadcast, and the Intent will be held to
2571 * be re-broadcast to future receivers.
2572 *
2573 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002574 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002575 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002576 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002577 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002578 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002579
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002580 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002581 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002582 * receive data back from the broadcast. This is accomplished by
2583 * supplying your own BroadcastReceiver when calling, which will be
2584 * treated as a final receiver at the end of the broadcast -- its
2585 * {@link BroadcastReceiver#onReceive} method will be called with
2586 * the result values collected from the other receivers. The broadcast will
2587 * be serialized in the same way as calling
2588 * {@link #sendOrderedBroadcast(Intent, String)}.
2589 *
2590 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2591 * asynchronous; it will return before
2592 * resultReceiver.onReceive() is called. Note that the sticky data
2593 * stored is only the data you initially supply to the broadcast, not
2594 * the result of any changes made by the receivers.
2595 *
2596 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2597 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002598 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2599 * can access them), no protection (anyone can modify them), and many other problems.
2600 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2601 * has changed, with another mechanism for apps to retrieve the current value whenever
2602 * desired.
2603 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002604 * @param intent The Intent to broadcast; all receivers matching this
2605 * Intent will receive the broadcast.
2606 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2607 * receiver of the broadcast.
2608 * @param scheduler A custom Handler with which to schedule the
2609 * resultReceiver callback; if null it will be
2610 * scheduled in the Context's main thread.
2611 * @param initialCode An initial value for the result code. Often
2612 * Activity.RESULT_OK.
2613 * @param initialData An initial value for the result data. Often
2614 * null.
2615 * @param initialExtras An initial value for the result extras. Often
2616 * null.
2617 *
2618 * @see #sendBroadcast(Intent)
2619 * @see #sendBroadcast(Intent, String)
2620 * @see #sendOrderedBroadcast(Intent, String)
2621 * @see #sendStickyBroadcast(Intent)
2622 * @see android.content.BroadcastReceiver
2623 * @see #registerReceiver
2624 * @see android.app.Activity#RESULT_OK
2625 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002626 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002627 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002628 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002629 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002630 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2631 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002634 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 * so that it is as if the sticky broadcast had never happened.
2636 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002637 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2638 * can access them), no protection (anyone can modify them), and many other problems.
2639 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2640 * has changed, with another mechanism for apps to retrieve the current value whenever
2641 * desired.
2642 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 * @param intent The Intent that was previously broadcast.
2644 *
2645 * @see #sendStickyBroadcast
2646 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002647 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002648 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002649 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650
2651 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002652 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002653 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002654 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002655 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002656 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2657 * can access them), no protection (anyone can modify them), and many other problems.
2658 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2659 * has changed, with another mechanism for apps to retrieve the current value whenever
2660 * desired.
2661 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002662 * @param intent The Intent to broadcast; all receivers matching this
2663 * Intent will receive the broadcast, and the Intent will be held to
2664 * be re-broadcast to future receivers.
2665 * @param user UserHandle to send the intent to.
2666 *
2667 * @see #sendBroadcast(Intent)
2668 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002669 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002670 @RequiresPermission(allOf = {
2671 android.Manifest.permission.INTERACT_ACROSS_USERS,
2672 android.Manifest.permission.BROADCAST_STICKY
2673 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002674 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2675 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002676
2677 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002678 * @hide
2679 * This is just here for sending CONNECTIVITY_ACTION.
2680 */
2681 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002682 @RequiresPermission(allOf = {
2683 android.Manifest.permission.INTERACT_ACROSS_USERS,
2684 android.Manifest.permission.BROADCAST_STICKY
2685 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002686 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2687 UserHandle user, Bundle options);
2688
2689 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002690 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002691 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2692 * that allows you to specify the
2693 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002694 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002695 *
2696 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2697 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002698 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2699 * can access them), no protection (anyone can modify them), and many other problems.
2700 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2701 * has changed, with another mechanism for apps to retrieve the current value whenever
2702 * desired.
2703 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002704 * @param intent The Intent to broadcast; all receivers matching this
2705 * Intent will receive the broadcast.
2706 * @param user UserHandle to send the intent to.
2707 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2708 * receiver of the broadcast.
2709 * @param scheduler A custom Handler with which to schedule the
2710 * resultReceiver callback; if null it will be
2711 * scheduled in the Context's main thread.
2712 * @param initialCode An initial value for the result code. Often
2713 * Activity.RESULT_OK.
2714 * @param initialData An initial value for the result data. Often
2715 * null.
2716 * @param initialExtras An initial value for the result extras. Often
2717 * null.
2718 *
2719 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2720 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002721 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002722 @RequiresPermission(allOf = {
2723 android.Manifest.permission.INTERACT_ACROSS_USERS,
2724 android.Manifest.permission.BROADCAST_STICKY
2725 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002726 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002727 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002728 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2729 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002730
2731 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002732 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002733 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002734 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002735 *
2736 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2737 * permission in order to use this API. If you do not hold that
2738 * permission, {@link SecurityException} will be thrown.
2739 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002740 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2741 * can access them), no protection (anyone can modify them), and many other problems.
2742 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2743 * has changed, with another mechanism for apps to retrieve the current value whenever
2744 * desired.
2745 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002746 * @param intent The Intent that was previously broadcast.
2747 * @param user UserHandle to remove the sticky broadcast from.
2748 *
2749 * @see #sendStickyBroadcastAsUser
2750 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002751 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002752 @RequiresPermission(allOf = {
2753 android.Manifest.permission.INTERACT_ACROSS_USERS,
2754 android.Manifest.permission.BROADCAST_STICKY
2755 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002756 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2757 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002758
2759 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002760 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 * <var>receiver</var> will be called with any broadcast Intent that
2762 * matches <var>filter</var>, in the main application thread.
2763 *
2764 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002765 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 * registrations. If your IntentFilter matches one of these sticky
2767 * Intents, that Intent will be returned by this function
2768 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2769 * been broadcast.
2770 *
2771 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2772 * in which case each of these will be sent to <var>receiver</var>. In
2773 * this case, only one of these can be returned directly by the function;
2774 * which of these that is returned is arbitrarily decided by the system.
2775 *
2776 * <p>If you know the Intent your are registering for is sticky, you can
2777 * supply null for your <var>receiver</var>. In this case, no receiver is
2778 * registered -- the function simply returns the sticky Intent that
2779 * matches <var>filter</var>. In the case of multiple matches, the same
2780 * rules as described above apply.
2781 *
2782 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2783 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002784 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2785 * registered with this method will correctly respect the
2786 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2787 * Prior to that, it would be ignored and delivered to all matching registered
2788 * receivers. Be careful if using this for security.</p>
2789 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002790 * <p class="note">Note: this method <em>cannot be called from a
2791 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2792 * that is declared in an application's manifest. It is okay, however, to call
2793 * this method from another BroadcastReceiver that has itself been registered
2794 * at run time with {@link #registerReceiver}, since the lifetime of such a
2795 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002796 *
2797 * @param receiver The BroadcastReceiver to handle the broadcast.
2798 * @param filter Selects the Intent broadcasts to be received.
2799 *
2800 * @return The first sticky intent found that matches <var>filter</var>,
2801 * or null if there are none.
2802 *
2803 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2804 * @see #sendBroadcast
2805 * @see #unregisterReceiver
2806 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002807 @Nullable
2808 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002809 IntentFilter filter);
2810
2811 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002812 * Register to receive intent broadcasts, with the receiver optionally being
2813 * exposed to Instant Apps. See
2814 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2815 * information. By default Instant Apps cannot interact with receivers in other
2816 * applications, this allows you to expose a receiver that Instant Apps can
2817 * interact with.
2818 *
2819 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2820 *
2821 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2822 * registered with this method will correctly respect the
2823 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2824 * Prior to that, it would be ignored and delivered to all matching registered
2825 * receivers. Be careful if using this for security.</p>
2826 *
2827 * @param receiver The BroadcastReceiver to handle the broadcast.
2828 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002829 * @param flags Additional options for the receiver. May be 0 or
2830 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002831 *
2832 * @return The first sticky intent found that matches <var>filter</var>,
2833 * or null if there are none.
2834 *
2835 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2836 * @see #sendBroadcast
2837 * @see #unregisterReceiver
2838 */
2839 @Nullable
2840 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2841 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002842 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002843
2844 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 * Register to receive intent broadcasts, to run in the context of
2846 * <var>scheduler</var>. See
2847 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2848 * information. This allows you to enforce permissions on who can
2849 * broadcast intents to your receiver, or have the receiver run in
2850 * a different thread than the main application thread.
2851 *
2852 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2853 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002854 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2855 * registered with this method will correctly respect the
2856 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2857 * Prior to that, it would be ignored and delivered to all matching registered
2858 * receivers. Be careful if using this for security.</p>
2859 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 * @param receiver The BroadcastReceiver to handle the broadcast.
2861 * @param filter Selects the Intent broadcasts to be received.
2862 * @param broadcastPermission String naming a permissions that a
2863 * broadcaster must hold in order to send an Intent to you. If null,
2864 * no permission is required.
2865 * @param scheduler Handler identifying the thread that will receive
2866 * the Intent. If null, the main thread of the process will be used.
2867 *
2868 * @return The first sticky intent found that matches <var>filter</var>,
2869 * or null if there are none.
2870 *
2871 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2872 * @see #sendBroadcast
2873 * @see #unregisterReceiver
2874 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002875 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002877 IntentFilter filter, @Nullable String broadcastPermission,
2878 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002879
2880 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002881 * Register to receive intent broadcasts, to run in the context of
2882 * <var>scheduler</var>. See
2883 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002884 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2885 * for more information.
2886 *
2887 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2888 *
2889 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2890 * registered with this method will correctly respect the
2891 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2892 * Prior to that, it would be ignored and delivered to all matching registered
2893 * receivers. Be careful if using this for security.</p>
2894 *
2895 * @param receiver The BroadcastReceiver to handle the broadcast.
2896 * @param filter Selects the Intent broadcasts to be received.
2897 * @param broadcastPermission String naming a permissions that a
2898 * broadcaster must hold in order to send an Intent to you. If null,
2899 * no permission is required.
2900 * @param scheduler Handler identifying the thread that will receive
2901 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002902 * @param flags Additional options for the receiver. May be 0 or
2903 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002904 *
2905 * @return The first sticky intent found that matches <var>filter</var>,
2906 * or null if there are none.
2907 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002908 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002909 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2910 * @see #sendBroadcast
2911 * @see #unregisterReceiver
2912 */
2913 @Nullable
2914 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2915 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002916 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002917
2918 /**
Meng Wang3f9e0362019-11-05 10:43:45 -08002919 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2920 * but this receiver will receive broadcasts that are sent to all users. The receiver can
2921 * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
2922 * was sent.
2923 *
2924 * @param receiver The BroadcastReceiver to handle the broadcast.
2925 * @param filter Selects the Intent broadcasts to be received.
2926 * @param broadcastPermission String naming a permissions that a
2927 * broadcaster must hold in order to send an Intent to you. If {@code null},
2928 * no permission is required.
2929 * @param scheduler Handler identifying the thread that will receive
2930 * the Intent. If {@code null}, the main thread of the process will be used.
2931 *
2932 * @return The first sticky intent found that matches <var>filter</var>,
2933 * or {@code null} if there are none.
2934 *
2935 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2936 * @see #sendBroadcast
2937 * @see #unregisterReceiver
2938 * @hide
2939 */
2940 @Nullable
2941 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
2942 @SystemApi
2943 public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
2944 @NonNull IntentFilter filter, @Nullable String broadcastPermission,
2945 @Nullable Handler scheduler) {
2946 throw new RuntimeException("Not implemented. Must override in a subclass.");
2947 }
2948
2949 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002950 * @hide
2951 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2952 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002953 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002954 *
2955 * @param receiver The BroadcastReceiver to handle the broadcast.
2956 * @param user UserHandle to send the intent to.
2957 * @param filter Selects the Intent broadcasts to be received.
2958 * @param broadcastPermission String naming a permissions that a
2959 * broadcaster must hold in order to send an Intent to you. If null,
2960 * no permission is required.
2961 * @param scheduler Handler identifying the thread that will receive
2962 * the Intent. If null, the main thread of the process will be used.
2963 *
2964 * @return The first sticky intent found that matches <var>filter</var>,
2965 * or null if there are none.
2966 *
Jeff Brown6e539312015-02-24 18:53:21 -08002967 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002968 * @see #sendBroadcast
2969 * @see #unregisterReceiver
2970 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002971 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002972 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002973 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002974 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002975 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2976 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977
2978 /**
2979 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2980 * filters that have been registered for this BroadcastReceiver will be
2981 * removed.
2982 *
2983 * @param receiver The BroadcastReceiver to unregister.
2984 *
2985 * @see #registerReceiver
2986 */
2987 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2988
2989 /**
2990 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002991 * should either contain the complete class name of a specific service
2992 * implementation to start, or a specific package name to target. If the
2993 * Intent is less specified, it logs a warning about this. In this case any of the
2994 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 * is not already running, it will be instantiated and started (creating a
2996 * process for it if needed); if it is running then it remains running.
2997 *
2998 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002999 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 * with the <var>intent</var> given here. This provides a convenient way
3001 * to submit jobs to a service without having to bind and call on to its
3002 * interface.
3003 *
3004 * <p>Using startService() overrides the default service lifetime that is
3005 * managed by {@link #bindService}: it requires the service to remain
3006 * running until {@link #stopService} is called, regardless of whether
3007 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07003008 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003009 * a single call to {@link #stopService} will stop it.
3010 *
3011 * <p>The system attempts to keep running services around as much as
3012 * possible. The only time they should be stopped is if the current
3013 * foreground application is using so many resources that the service needs
3014 * to be killed. If any errors happen in the service's process, it will
3015 * automatically be restarted.
3016 *
3017 * <p>This function will throw {@link SecurityException} if you do not
3018 * have permission to start the given service.
3019 *
Chris Craik1e353522016-04-18 10:20:50 -07003020 * <p class="note"><strong>Note:</strong> Each call to startService()
3021 * results in significant work done by the system to manage service
3022 * lifecycle surrounding the processing of the intent, which can take
3023 * multiple milliseconds of CPU time. Due to this cost, startService()
3024 * should not be used for frequent intent delivery to a service, and only
3025 * for scheduling significant work. Use {@link #bindService bound services}
3026 * for high frequency calls.
3027 * </p>
3028 *
Mark Lu94ebbe02016-12-13 16:29:51 -08003029 * @param service Identifies the service to be started. The Intent must be
3030 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003031 * may be included in the Intent extras to supply arguments along with
3032 * this specific start call.
3033 *
3034 * @return If the service is being started or is already running, the
3035 * {@link ComponentName} of the actual service that was started is
3036 * returned; else if the service does not exist null is returned.
3037 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003038 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003039 * or the service can not be found.
3040 * @throws IllegalStateException If the application is in a state where the service
3041 * 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 -08003042 *
3043 * @see #stopService
3044 * @see #bindService
3045 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003046 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003047 public abstract ComponentName startService(Intent service);
3048
3049 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07003050 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00003051 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
3052 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07003053 * an amount of time comparable to the ANR interval to do this, otherwise the system
3054 * will automatically stop the service and declare the app ANR.
3055 *
3056 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
3057 * at any time, regardless of whether the app hosting the service is in a foreground
3058 * state.
3059 *
3060 * @param service Identifies the service to be started. The Intent must be
3061 * fully explicit (supplying a component name). Additional values
3062 * may be included in the Intent extras to supply arguments along with
3063 * this specific start call.
3064 *
3065 * @return If the service is being started or is already running, the
3066 * {@link ComponentName} of the actual service that was started is
3067 * returned; else if the service does not exist null is returned.
3068 *
3069 * @throws SecurityException If the caller does not have permission to access the service
3070 * or the service can not be found.
3071 *
3072 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00003073 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07003074 */
3075 @Nullable
3076 public abstract ComponentName startForegroundService(Intent service);
3077
3078 /**
3079 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
3080 */
3081 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003082 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07003083 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
3084
3085 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003086 * Request that a given application service be stopped. If the service is
3087 * not running, nothing happens. Otherwise it is stopped. Note that calls
3088 * to startService() are not counted -- this stops the service no matter
3089 * how many times it was started.
3090 *
3091 * <p>Note that if a stopped service still has {@link ServiceConnection}
3092 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
3093 * not be destroyed until all of these bindings are removed. See
3094 * the {@link android.app.Service} documentation for more details on a
3095 * service's lifecycle.
3096 *
3097 * <p>This function will throw {@link SecurityException} if you do not
3098 * have permission to stop the given service.
3099 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07003100 * @param service Description of the service to be stopped. The Intent must be either
3101 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07003102 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003103 *
3104 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04003105 * 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 -08003106 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003107 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003108 * or the service can not be found.
3109 * @throws IllegalStateException If the application is in a state where the service
3110 * 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 -08003111 *
3112 * @see #startService
3113 */
3114 public abstract boolean stopService(Intent service);
3115
3116 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003117 * @hide like {@link #startService(Intent)} but for a specific user.
3118 */
Christopher Tate42a386b2016-11-07 12:21:21 -08003119 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003120 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003121 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003122 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
3123
3124 /**
3125 * @hide like {@link #stopService(Intent)} but for a specific user.
3126 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003127 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003128 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08003129
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003130 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 * Connect to an application service, creating it if needed. This defines
3132 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003133 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * told if it dies and restarts. The service will be considered required
3135 * by the system only for as long as the calling context exists. For
3136 * example, if this Context is an Activity that is stopped, the service will
3137 * not be required to continue running until the Activity is resumed.
3138 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003139 * <p>If the service does not support binding, it may return {@code null} from
3140 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
3141 * the ServiceConnection's
3142 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
3143 * will be invoked instead of
3144 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
3145 *
3146 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003147 * have permission to bind to the given service.
3148 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003149 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003150 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003151 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003152 * {@link #startService} with the arguments containing the command to be
3153 * sent, with the service calling its
3154 * {@link android.app.Service#stopSelf(int)} method when done executing
3155 * that command. See the API demo App/Service/Service Start Arguments
3156 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003157 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
3159 * is tied to another object (the one that registered it).</p>
3160 *
Mark Lu94ebbe02016-12-13 16:29:51 -08003161 * @param service Identifies the service to connect to. The Intent must
3162 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07003164 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07003165 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07003166 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
3167 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003168 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
3169 * {@link #BIND_IMPORTANT}, or
3170 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07003171 * @return {@code true} if the system is in the process of bringing up a
3172 * service that your client has permission to bind to; {@code false}
3173 * if the system couldn't find the service or if your client doesn't
3174 * have permission to bind to it. If this value is {@code true}, you
3175 * should later call {@link #unbindService} to release the
3176 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003177 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003178 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003179 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 *
3181 * @see #unbindService
3182 * @see #startService
3183 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07003184 * @see #BIND_DEBUG_UNBIND
3185 * @see #BIND_NOT_FOREGROUND
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003186 * @see #BIND_ABOVE_CLIENT
3187 * @see #BIND_ALLOW_OOM_MANAGEMENT
3188 * @see #BIND_WAIVE_PRIORITY
3189 * @see #BIND_IMPORTANT
3190 * @see #BIND_ADJUST_WITH_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003191 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07003192 public abstract boolean bindService(@RequiresPermission Intent service,
3193 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003194
3195 /**
Bo Liu58a57662019-03-06 20:21:45 +00003196 * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control
3197 * ServiceConnection callbacks.
3198 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
3199 * instance for the same instance of ServiceConnection.
3200 */
3201 public boolean bindService(@RequiresPermission @NonNull Intent service,
3202 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
3203 @NonNull ServiceConnection conn) {
3204 throw new RuntimeException("Not implemented. Must override in a subclass.");
3205 }
3206
3207 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003208 * Variation of {@link #bindService} that, in the specific case of isolated
3209 * services, allows the caller to generate multiple instances of a service
Dianne Hackborncc67f962019-04-29 16:32:44 -07003210 * from a single component declaration. In other words, you can use this to bind
3211 * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
3212 * addition to the existing behavior of running in an isolated process, you can
3213 * also through the arguments here have the system bring up multiple concurrent
3214 * processes hosting their own instances of that service. The <var>instanceName</var>
3215 * you provide here identifies the different instances, and you can use
3216 * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
3217 * should manage each of these instances.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003218 *
3219 * @param service Identifies the service to connect to. The Intent must
3220 * specify an explicit component name.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003221 * @param flags Operation options for the binding as per {@link #bindService}.
3222 * @param instanceName Unique identifier for the service instance. Each unique
Robert Seseke3a5bc62019-04-22 17:43:03 -04003223 * name here will result in a different service instance being created. Identifiers
3224 * must only contain ASCII letters, digits, underscores, and periods.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003225 * @return Returns success of binding as per {@link #bindService}.
Bo Liu58a57662019-03-06 20:21:45 +00003226 * @param executor Callbacks on ServiceConnection will be called on executor.
3227 * Must use same instance for the same instance of ServiceConnection.
3228 * @param conn Receives information as the service is started and stopped.
3229 * This must be a valid ServiceConnection object; it must not be null.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003230 *
3231 * @throws SecurityException If the caller does not have permission to access the service
Robert Seseke3a5bc62019-04-22 17:43:03 -04003232 * @throws IllegalArgumentException If the instanceName is invalid.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003233 *
3234 * @see #bindService
Dianne Hackborncc67f962019-04-29 16:32:44 -07003235 * @see #updateServiceGroup
3236 * @see android.R.attr#isolatedProcess
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003237 */
Adrian Roosebc927c2019-02-28 16:21:18 +01003238 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
Bo Liu58a57662019-03-06 20:21:45 +00003239 @BindServiceFlags int flags, @NonNull String instanceName,
3240 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003241 throw new RuntimeException("Not implemented. Must override in a subclass.");
3242 }
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003243
3244 /**
kholoud mohamedda3ae492019-12-31 15:06:11 +00003245 * Binds to a service in the given {@code user} in the same manner as
3246 * {@link #bindService(Intent, ServiceConnection, int)}.
3247 *
3248 * <p>If the given {@code user} is in the same profile group and the target package is the
3249 * same as the caller, {@code android.Manifest.permission.INTERACT_ACROSS_PROFILES} is
3250 * sufficient. Otherwise, requires {@code android.Manifest.permission.INTERACT_ACROSS_USERS}
3251 * for interacting with other users.
3252 *
3253 * @param service Identifies the service to connect to. The Intent must
3254 * specify an explicit component name.
3255 * @param conn Receives information as the service is started and stopped.
3256 * This must be a valid ServiceConnection object; it must not be null.
3257 * @param flags Operation options for the binding. May be 0,
3258 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
3259 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
3260 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
3261 * {@link #BIND_IMPORTANT}, or
3262 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
3263 * @return {@code true} if the system is in the process of bringing up a
3264 * service that your client has permission to bind to; {@code false}
3265 * if the system couldn't find the service. If this value is {@code true}, you
3266 * should later call {@link #unbindService} to release the
3267 * connection.
3268 *
3269 * @throws SecurityException if the client does not have the required permission to bind.
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003270 */
Jeff Brown6e539312015-02-24 18:53:21 -08003271 @SuppressWarnings("unused")
kholoud mohamedda3ae492019-12-31 15:06:11 +00003272 @RequiresPermission(anyOf = {
3273 android.Manifest.permission.INTERACT_ACROSS_USERS,
3274 android.Manifest.permission.INTERACT_ACROSS_PROFILES
3275 })
3276 public boolean bindServiceAsUser(
3277 @NonNull @RequiresPermission Intent service, @NonNull ServiceConnection conn, int flags,
3278 @NonNull UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003279 throw new RuntimeException("Not implemented. Must override in a subclass.");
3280 }
3281
3282 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003283 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
Adrian Roos691546e2016-02-09 10:13:41 -08003284 * explicit non-null Handler to run the ServiceConnection callbacks on.
3285 *
3286 * @hide
3287 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003288 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood7bcc1742019-07-04 11:39:42 +01003289 @UnsupportedAppUsage(trackingBug = 136728678)
Adrian Roos691546e2016-02-09 10:13:41 -08003290 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3291 Handler handler, UserHandle user) {
3292 throw new RuntimeException("Not implemented. Must override in a subclass.");
3293 }
3294
3295 /**
Dianne Hackborna631d562018-11-20 15:58:15 -08003296 * For a service previously bound with {@link #bindService} or a related method, change
3297 * how the system manages that service's process in relation to other processes. This
3298 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3299 * how the process will be managed in some cases based on those flags. Currently only
3300 * works on isolated processes (will be ignored for non-isolated processes).
3301 *
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -08003302 * <p>Note that this call does not take immediate effect, but will be applied the next
3303 * time the impacted process is adjusted for some other reason. Typically you would
3304 * call this before then calling a new {@link #bindIsolatedService} on the service
3305 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3306 *
Dianne Hackborna631d562018-11-20 15:58:15 -08003307 * @param conn The connection interface previously supplied to bindService(). This
3308 * parameter must not be null.
3309 * @param group A group to put this connection's process in. Upon calling here, this
3310 * will override any previous group that was set for that process. The group
3311 * tells the system about processes that are logically grouped together, so
3312 * should be managed as one unit of importance (such as when being considered
3313 * a recently used app). All processes in the same app with the same group
3314 * are considered to be related. Supplying 0 reverts to the default behavior
3315 * of not grouping.
3316 * @param importance Additional importance of the processes within a group. Upon calling
Dianne Hackborncc67f962019-04-29 16:32:44 -07003317 * here, this will override any previous importance that was set for that
3318 * process. The most important process is 0, and higher values are
3319 * successively less important. You can view this as describing how
3320 * to order the processes in an array, with the processes at the end of
3321 * the array being the least important. This value has no meaning besides
3322 * indicating how processes should be ordered in that array one after the
3323 * other. This provides a way to fine-tune the system's process killing,
3324 * guiding it to kill processes at the end of the array first.
3325 *
3326 * @see #bindIsolatedService
Dianne Hackborna631d562018-11-20 15:58:15 -08003327 */
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003328 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3329 int importance) {
3330 throw new RuntimeException("Not implemented. Must override in a subclass.");
3331 }
Dianne Hackborna631d562018-11-20 15:58:15 -08003332
3333 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 * Disconnect from an application service. You will no longer receive
3335 * calls as the service is restarted, and the service is now allowed to
3336 * stop at any time.
3337 *
3338 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07003339 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003340 *
3341 * @see #bindService
3342 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003343 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003344
3345 /**
3346 * Start executing an {@link android.app.Instrumentation} class. The given
3347 * Instrumentation component will be run by killing its target application
3348 * (if currently running), starting the target process, instantiating the
3349 * instrumentation component, and then letting it drive the application.
3350 *
3351 * <p>This function is not synchronous -- it returns as soon as the
3352 * instrumentation has started and while it is running.
3353 *
3354 * <p>Instrumentation is normally only allowed to run against a package
3355 * that is either unsigned or signed with a signature that the
3356 * the instrumentation package is also signed with (ensuring the target
3357 * trusts the instrumentation).
3358 *
3359 * @param className Name of the Instrumentation component to be run.
3360 * @param profileFile Optional path to write profiling data as the
3361 * instrumentation runs, or null for no profiling.
3362 * @param arguments Additional optional arguments to pass to the
3363 * instrumentation, or null.
3364 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003365 * @return {@code true} if the instrumentation was successfully started,
3366 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003367 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003368 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3369 @Nullable String profileFile, @Nullable Bundle arguments);
3370
3371 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07003372 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07003373 POWER_SERVICE,
3374 WINDOW_SERVICE,
3375 LAYOUT_INFLATER_SERVICE,
3376 ACCOUNT_SERVICE,
3377 ACTIVITY_SERVICE,
3378 ALARM_SERVICE,
3379 NOTIFICATION_SERVICE,
3380 ACCESSIBILITY_SERVICE,
3381 CAPTIONING_SERVICE,
3382 KEYGUARD_SERVICE,
3383 LOCATION_SERVICE,
3384 //@hide: COUNTRY_DETECTOR,
3385 SEARCH_SERVICE,
3386 SENSOR_SERVICE,
Chad Brubaker90f391f2018-10-19 10:26:19 -07003387 SENSOR_PRIVACY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003388 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003389 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003390 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003391 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003392 VIBRATOR_SERVICE,
3393 //@hide: STATUS_BAR_SERVICE,
3394 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003395 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003396 IPSEC_SERVICE,
Benedict Wong50b44432019-11-01 16:46:28 -07003397 VPN_MANAGEMENT_SERVICE,
Benedict Wong99a48412018-11-09 14:45:34 -08003398 TEST_NETWORK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003399 //@hide: UPDATE_LOCK_SERVICE,
3400 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003401 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003402 //@hide: NETWORK_POLICY_SERVICE,
3403 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003404 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003405 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003406 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003407 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003408 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003409 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003410 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003411 NSD_SERVICE,
3412 AUDIO_SERVICE,
Ilya Matyukhine4675b32019-11-07 16:07:19 -08003413 AUTH_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003414 FINGERPRINT_SERVICE,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003415 //@hide: FACE_SERVICE,
Kevin Chyn05c21502018-09-18 13:07:19 -07003416 BIOMETRIC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003417 MEDIA_ROUTER_SERVICE,
3418 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003419 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003420 CARRIER_CONFIG_SERVICE,
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003421 EUICC_SERVICE,
Sarah Chin4affb512020-01-10 16:09:11 -08003422 MMS_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003423 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003424 CLIPBOARD_SERVICE,
3425 INPUT_METHOD_SERVICE,
3426 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003427 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003428 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003429 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003430 //@hide: BACKUP_SERVICE,
Richard Uhlerb29f1452018-09-12 16:38:15 +01003431 ROLLBACK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003432 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003433 //@hide: DEVICE_IDLE_CONTROLLER,
Kweku Adamse371b092019-11-22 10:50:48 -08003434 //@hide: POWER_WHITELIST_MANAGER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003435 DEVICE_POLICY_SERVICE,
3436 UI_MODE_SERVICE,
3437 DOWNLOAD_SERVICE,
3438 NFC_SERVICE,
3439 BLUETOOTH_SERVICE,
3440 //@hide: SIP_SERVICE,
3441 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003442 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003443 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003444 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003445 INPUT_SERVICE,
3446 DISPLAY_SERVICE,
Christine Franks39b03112018-07-03 14:46:07 -07003447 //@hide COLOR_DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003448 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003449 RESTRICTIONS_SERVICE,
3450 APP_OPS_SERVICE,
Hai Zhangb7776682018-09-25 15:10:57 -07003451 ROLE_SERVICE,
Hai Zhanga4959e52019-03-06 12:21:07 -08003452 //@hide ROLE_CONTROLLER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003453 CAMERA_SERVICE,
atrostde54a8ac2019-08-15 16:53:01 +01003454 //@hide: PLATFORM_COMPAT_SERVICE,
atrost87488352019-10-10 19:27:31 +01003455 //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003456 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003457 CONSUMER_IR_SERVICE,
3458 //@hide: TRUST_SERVICE,
3459 TV_INPUT_SERVICE,
Amy06a551e2019-11-07 13:44:33 -08003460 //@hide: TV_TUNER_RESOURCE_MGR_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003461 //@hide: NETWORK_SCORE_SERVICE,
3462 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003463 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003464 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003465 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003466 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003467 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003468 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003469 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003470 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003471 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003472 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003473 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003474 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003475 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003476 //@hide: INCIDENT_SERVICE,
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08003477 //@hide: INCIDENT_COMPANION_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003478 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003479 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003480 CROSS_PROFILE_APPS_SERVICE,
3481 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerfeeee682018-05-30 14:35:24 +01003482 //@hide: TIME_DETECTOR_SERVICE,
Neil Fuller3e3b5402019-11-07 15:35:05 +00003483 //@hide: TIME_ZONE_DETECTOR_SERVICE,
Philip P. Moltmann039678e2018-09-18 13:04:38 -07003484 PERMISSION_SERVICE,
Ivailo Karamanolev090d02c2020-01-09 17:02:49 +01003485 LIGHTS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003486 })
3487 @Retention(RetentionPolicy.SOURCE)
3488 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003489
3490 /**
3491 * Return the handle to a system-level service by name. The class of the
3492 * returned object varies by the requested name. Currently available names
3493 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003494 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003495 * <dl>
3496 * <dt> {@link #WINDOW_SERVICE} ("window")
3497 * <dd> The top-level window manager in which you can place custom
Andrii Kulian5877c7d2020-01-29 16:57:32 -08003498 * windows. The returned object is a {@link android.view.WindowManager}. Must only be obtained
3499 * from a visual context such as Activity or a Context created with
3500 * {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and
3501 * visual bounds of an area on screen.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3503 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
Andrii Kulian5877c7d2020-01-29 16:57:32 -08003504 * in this context. Must only be obtained from a visual context such as Activity or a Context
3505 * created with {@link #createWindowContext(int, Bundle)}, which are adjusted to the
3506 * configuration and visual bounds of an area on screen.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003507 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3508 * <dd> A {@link android.app.ActivityManager} for interacting with the
3509 * global activity state of the system.
Andrii Kulian5877c7d2020-01-29 16:57:32 -08003510 * <dt> {@link #WALLPAPER_SERVICE} ("wallpaper")
3511 * <dd> A {@link android.service.wallpaper.WallpaperService} for accessing wallpapers in this
3512 * context. Must only be obtained from a visual context such as Activity or a Context created
3513 * with {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and
3514 * visual bounds of an area on screen.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003515 * <dt> {@link #POWER_SERVICE} ("power")
3516 * <dd> A {@link android.os.PowerManager} for controlling power
3517 * management.
3518 * <dt> {@link #ALARM_SERVICE} ("alarm")
3519 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3520 * time of your choosing.
3521 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3522 * <dd> A {@link android.app.NotificationManager} for informing the user
3523 * of background events.
3524 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3525 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3526 * <dt> {@link #LOCATION_SERVICE} ("location")
3527 * <dd> A {@link android.location.LocationManager} for controlling location
3528 * (e.g., GPS) updates.
3529 * <dt> {@link #SEARCH_SERVICE} ("search")
3530 * <dd> A {@link android.app.SearchManager} for handling search.
3531 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3532 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3533 * hardware.
Sudheer Shanka09b0ee62019-10-03 14:45:15 -07003534 * <dt> {@link #CONNECTIVITY_SERVICE} ("connectivity")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003535 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3536 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003537 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3538 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3539 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003540 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003541 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3542 * connectivity. On releases before NYC, it should only be obtained from an application
3543 * context, and not from any other derived context to avoid memory leaks within the calling
3544 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003545 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3546 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3547 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003548 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3549 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3550 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003551 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3552 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3553 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003554 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3555 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003556 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003557 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003558 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003559 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003560 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3561 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003562 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3563 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3564 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003565 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003566 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003567 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003568 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003569 * <p>Note: System services obtained via this API may be closely associated with
3570 * the Context in which they are obtained from. In general, do not share the
3571 * service objects between various different contexts (Activities, Applications,
3572 * Services, Providers, etc.)
3573 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003574 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3575 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003576 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3577 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3578 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3579 * return <code>null</code>. Generally, if you are running as an instant app you should always
Felipe Leme4685b862019-03-06 10:32:33 -08003580 * check whether the result of this method is {@code null}.
3581 *
3582 * <p>Note: When implementing this method, keep in mind that new services can be added on newer
3583 * Android releases, so if you're looking for just the explicit names mentioned above, make sure
3584 * to return {@code null} when you don't recognize the name &mdash; if you throw a
3585 * {@link RuntimeException} exception instead, you're app might break on new Android releases.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003586 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003587 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003588 *
Felipe Leme4685b862019-03-06 10:32:33 -08003589 * @return The service or {@code null} if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003590 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 * @see #WINDOW_SERVICE
3592 * @see android.view.WindowManager
3593 * @see #LAYOUT_INFLATER_SERVICE
3594 * @see android.view.LayoutInflater
3595 * @see #ACTIVITY_SERVICE
3596 * @see android.app.ActivityManager
3597 * @see #POWER_SERVICE
3598 * @see android.os.PowerManager
3599 * @see #ALARM_SERVICE
3600 * @see android.app.AlarmManager
3601 * @see #NOTIFICATION_SERVICE
3602 * @see android.app.NotificationManager
3603 * @see #KEYGUARD_SERVICE
3604 * @see android.app.KeyguardManager
3605 * @see #LOCATION_SERVICE
3606 * @see android.location.LocationManager
3607 * @see #SEARCH_SERVICE
3608 * @see android.app.SearchManager
3609 * @see #SENSOR_SERVICE
3610 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003611 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003612 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003613 * @see #VIBRATOR_SERVICE
3614 * @see android.os.Vibrator
3615 * @see #CONNECTIVITY_SERVICE
3616 * @see android.net.ConnectivityManager
3617 * @see #WIFI_SERVICE
3618 * @see android.net.wifi.WifiManager
3619 * @see #AUDIO_SERVICE
3620 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003621 * @see #MEDIA_ROUTER_SERVICE
3622 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003623 * @see #TELEPHONY_SERVICE
3624 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003625 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3626 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003627 * @see #CARRIER_CONFIG_SERVICE
3628 * @see android.telephony.CarrierConfigManager
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003629 * @see #EUICC_SERVICE
3630 * @see android.telephony.euicc.EuiccManager
Sarah Chin4affb512020-01-10 16:09:11 -08003631 * @see #MMS_SERVICE
3632 * @see android.telephony.MmsManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003633 * @see #INPUT_METHOD_SERVICE
3634 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003635 * @see #UI_MODE_SERVICE
3636 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003637 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003638 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003639 * @see #BATTERY_SERVICE
3640 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003641 * @see #JOB_SCHEDULER_SERVICE
3642 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003643 * @see #NETWORK_STATS_SERVICE
3644 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003645 * @see android.os.HardwarePropertiesManager
3646 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003647 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003648 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649
3650 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003651 * Return the handle to a system-level service by class.
3652 * <p>
3653 * Currently available classes are:
3654 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3655 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3656 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3657 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3658 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3659 * {@link android.net.ConnectivityManager},
3660 * {@link android.net.wifi.WifiManager},
3661 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3662 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3663 * {@link android.view.inputmethod.InputMethodManager},
3664 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003665 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3666 * {@link android.app.usage.NetworkStatsManager}.
Felipe Leme4685b862019-03-06 10:32:33 -08003667 * </p>
3668 *
3669 * <p>
Jeff Brown6e539312015-02-24 18:53:21 -08003670 * Note: System services obtained via this API may be closely associated with
3671 * the Context in which they are obtained from. In general, do not share the
3672 * service objects between various different contexts (Activities, Applications,
3673 * Services, Providers, etc.)
3674 * </p>
3675 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003676 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3677 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003678 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3679 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3680 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
Felipe Leme4685b862019-03-06 10:32:33 -08003681 * return {@code null}. Generally, if you are running as an instant app you should always
3682 * check whether the result of this method is {@code null}.
3683 * </p>
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003684 *
Jeff Brown6e539312015-02-24 18:53:21 -08003685 * @param serviceClass The class of the desired service.
Felipe Leme4685b862019-03-06 10:32:33 -08003686 * @return The service or {@code null} if the class is not a supported system service. Note:
3687 * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
Jeff Brown6e539312015-02-24 18:53:21 -08003688 */
3689 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003690 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003691 // Because subclasses may override getSystemService(String) we cannot
3692 // perform a lookup by class alone. We must first map the class to its
3693 // service name then invoke the string-based method.
3694 String serviceName = getSystemServiceName(serviceClass);
3695 return serviceName != null ? (T)getSystemService(serviceName) : null;
3696 }
3697
3698 /**
3699 * Gets the name of the system-level service that is represented by the specified class.
3700 *
3701 * @param serviceClass The class of the desired service.
3702 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003703 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003704 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003705
3706 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003707 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003708 * {@link android.os.PowerManager} for controlling power management,
3709 * including "wake locks," which let you keep the device on while
3710 * you're running long tasks.
3711 */
3712 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003715 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003716 * {@link android.os.RecoverySystem} for accessing the recovery system
3717 * service.
3718 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003719 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003720 * @hide
3721 */
3722 public static final String RECOVERY_SERVICE = "recovery";
3723
3724 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003725 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003726 * {@link android.os.SystemUpdateManager} for accessing the system update
3727 * manager service.
3728 *
3729 * @see #getSystemService(String)
3730 * @hide
3731 */
3732 @SystemApi
3733 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3734
3735 /**
3736 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 * {@link android.view.WindowManager} for accessing the system's window
3738 * manager.
3739 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003740 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003741 * @see android.view.WindowManager
3742 */
3743 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003744
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003745 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003746 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003747 * {@link android.view.LayoutInflater} for inflating layout resources in this
3748 * context.
3749 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003750 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 * @see android.view.LayoutInflater
3752 */
3753 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003754
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003755 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003756 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003757 * {@link android.accounts.AccountManager} for receiving intents at a
3758 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003759 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003760 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003761 * @see android.accounts.AccountManager
3762 */
3763 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003764
Fred Quintana60307342009-03-24 22:48:12 -07003765 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003766 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003767 * {@link android.app.ActivityManager} for interacting with the global
3768 * system state.
3769 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003770 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003771 * @see android.app.ActivityManager
3772 */
3773 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003775 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003776 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale65ebd952018-04-25 15:41:44 -07003777 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
3778 *
3779 * @see #getSystemService(String)
3780 * @see android.app.ActivityTaskManager
3781 * @hide
3782 */
3783 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
3784
3785 /**
3786 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07003787 * {@link android.app.UriGrantsManager} for interacting with the global system state.
3788 *
3789 * @see #getSystemService(String)
3790 * @see android.app.UriGrantsManager
3791 * @hide
3792 */
3793 public static final String URI_GRANTS_SERVICE = "uri_grants";
3794
3795 /**
3796 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003797 * {@link android.app.AlarmManager} for receiving intents at a
3798 * time of your choosing.
3799 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003800 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 * @see android.app.AlarmManager
3802 */
3803 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003804
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003805 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003806 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003807 * {@link android.app.NotificationManager} for informing the user of
3808 * background events.
3809 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003810 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003811 * @see android.app.NotificationManager
3812 */
3813 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003814
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003816 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003817 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3818 * feedback for UI events through the registered event listeners.
3819 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003820 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003821 * @see android.view.accessibility.AccessibilityManager
3822 */
3823 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003824
svetoslavganov75986cf2009-05-14 22:28:01 -07003825 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003826 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003827 * {@link android.view.accessibility.CaptioningManager} for obtaining
3828 * captioning properties and listening for changes in captioning
3829 * preferences.
3830 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003831 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003832 * @see android.view.accessibility.CaptioningManager
3833 */
3834 public static final String CAPTIONING_SERVICE = "captioning";
3835
3836 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003837 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003838 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003839 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003840 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003841 * @see android.app.KeyguardManager
3842 */
3843 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003844
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003845 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003846 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003847 * android.location.LocationManager} for controlling location
3848 * updates.
3849 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003850 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003851 * @see android.location.LocationManager
3852 */
3853 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003854
3855 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003856 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003857 * {@link android.location.CountryDetector} for detecting the country that
3858 * the user is in.
3859 *
3860 * @hide
3861 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01003862 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003863 public static final String COUNTRY_DETECTOR = "country_detector";
3864
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003865 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003866 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003867 * android.app.SearchManager} for handling searches.
3868 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003869 * <p>
3870 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3871 * {@link android.app.SearchManager}.
3872 *
3873 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003874 * @see android.app.SearchManager
3875 */
3876 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003877
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003878 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003879 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003880 * android.hardware.SensorManager} for accessing sensors.
3881 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003882 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003883 * @see android.hardware.SensorManager
3884 */
3885 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003886
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003887 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003888 * Use with {@link #getSystemService(String)} to retrieve a {@link
Chad Brubaker90f391f2018-10-19 10:26:19 -07003889 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
3890 * functions.
3891 *
3892 * @see #getSystemService(String)
3893 * @see android.hardware.SensorPrivacyManager
3894 *
3895 * @hide
3896 */
3897 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
3898
3899 /**
3900 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003901 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003902 * functions.
3903 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003904 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003905 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003906 */
3907 public static final String STORAGE_SERVICE = "storage";
3908
3909 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003910 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003911 * android.app.usage.StorageStatsManager} for accessing system storage
3912 * statistics.
3913 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003914 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003915 * @see android.app.usage.StorageStatsManager
3916 */
3917 public static final String STORAGE_STATS_SERVICE = "storagestats";
3918
3919 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003920 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003921 * com.android.server.WallpaperService for accessing wallpapers.
3922 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003923 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003924 */
3925 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003926
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003927 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003928 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003929 * android.os.Vibrator} for interacting with the vibration hardware.
3930 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003931 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003932 * @see android.os.Vibrator
3933 */
3934 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003935
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003936 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003937 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003938 * android.app.StatusBarManager} for interacting with the status bar.
3939 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003940 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003941 * @see android.app.StatusBarManager
Evan Lairdedd016f2019-01-23 18:36:29 -05003942 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003943 * @hide
3944 */
Evan Lairdedd016f2019-01-23 18:36:29 -05003945 @SystemApi
Evan Laird418ba8f2019-04-17 15:55:21 -04003946 @TestApi
Adrian Roosd38f5092020-01-16 21:20:24 +01003947 @SuppressLint("ServiceName")
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003948 public static final String STATUS_BAR_SERVICE = "statusbar";
3949
3950 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003951 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003952 * android.net.ConnectivityManager} for handling management of
3953 * network connections.
3954 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003955 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003956 * @see android.net.ConnectivityManager
3957 */
3958 public static final String CONNECTIVITY_SERVICE = "connectivity";
3959
3960 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003961 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003962 * {@link android.net.INetd} for communicating with the network stack
3963 * @hide
3964 * @see #getSystemService(String)
3965 * @hide
3966 */
3967 @SystemApi
3968 public static final String NETD_SERVICE = "netd";
3969
3970 /**
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003971 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
Remi NGUYEN VAN05f7b5c2020-01-07 11:44:14 +09003972 * {@link INetworkStackConnector} IBinder for communicating with the network stack
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003973 * @hide
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003974 * @see NetworkStackClient
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003975 */
Remi NGUYEN VAN05f7b5c2020-01-07 11:44:14 +09003976 @SystemApi
3977 @TestApi
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003978 public static final String NETWORK_STACK_SERVICE = "network_stack";
3979
3980 /**
markchienae8aa642019-12-16 20:15:20 +08003981 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3982 * {@link ITetheringConnector} IBinder for communicating with the tethering service
3983 * @hide
3984 * @see TetheringClient
3985 */
3986 @SystemApi
3987 public static final String TETHERING_SERVICE = "tethering";
3988
3989 /**
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003990 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003991 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3992 * IPSec.
3993 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003994 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003995 */
3996 public static final String IPSEC_SERVICE = "ipsec";
3997
3998 /**
Benedict Wong50b44432019-11-01 16:46:28 -07003999 * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.VpnManager} to
4000 * manage profiles for the platform built-in VPN.
4001 *
4002 * @see #getSystemService(String)
4003 */
4004 public static final String VPN_MANAGEMENT_SERVICE = "vpn_management";
4005
4006 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004007 * Use with {@link #getSystemService(String)} to retrieve a {@link
Cody Kestingb125776002019-12-17 17:21:40 -08004008 * android.net.ConnectivityDiagnosticsManager} for performing network connectivity diagnostics
4009 * as well as receiving network connectivity information from the system.
4010 *
4011 * @see #getSystemService(String)
4012 * @see android.net.ConnectivityDiagnosticsManager
4013 */
4014 public static final String CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics";
4015
4016 /**
4017 * Use with {@link #getSystemService(String)} to retrieve a {@link
Benedict Wong99a48412018-11-09 14:45:34 -08004018 * android.net.TestNetworkManager} for building TUNs and limited-use Networks
4019 *
4020 * @see #getSystemService(String)
4021 * @hide
4022 */
4023 @TestApi public static final String TEST_NETWORK_SERVICE = "test_network";
4024
4025 /**
4026 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08004027 * android.os.IUpdateLock} for managing runtime sequences that
4028 * must not be interrupted by headless OTA application or similar.
4029 *
4030 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004031 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08004032 * @see android.os.UpdateLock
4033 */
4034 public static final String UPDATE_LOCK_SERVICE = "updatelock";
4035
4036 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004037 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07004038 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08004039 */
4040 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
4041
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00004042 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004043 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04004044 * {@link com.android.server.slice.SliceManagerService} for managing slices.
4045 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004046 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04004047 */
4048 public static final String SLICE_SERVICE = "slice";
4049
4050 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004051 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00004052 * android.app.usage.NetworkStatsManager} for querying network usage stats.
4053 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004054 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00004055 * @see android.app.usage.NetworkStatsManager
4056 */
Jeff Sharkey75279902011-05-24 18:39:45 -07004057 public static final String NETWORK_STATS_SERVICE = "netstats";
4058 /** {@hide} */
Aaron Huang1aa5ca32019-12-31 21:48:45 +08004059 @SystemApi
Adrian Roosd38f5092020-01-16 21:20:24 +01004060 @SuppressLint("ServiceName")
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07004061 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01004062 /** {@hide} */
4063 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07004064
San Mehatd1df8ac2010-01-26 06:17:26 -08004065 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004066 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004067 * android.net.wifi.WifiManager} for handling management of
4068 * Wi-Fi access.
4069 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004070 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004071 * @see android.net.wifi.WifiManager
4072 */
4073 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07004074
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004075 /**
Etan Cohen73450f22019-12-12 23:29:25 -08004076 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohenb9f28bc2020-02-09 12:06:56 -08004077 * {@link android.net.wifi.wificond.WifiNl80211Manager} for handling management of the
4078 * Wi-Fi nl802.11 daemon (wificond).
Etan Cohen73450f22019-12-12 23:29:25 -08004079 *
4080 * @see #getSystemService(String)
Etan Cohenb9f28bc2020-02-09 12:06:56 -08004081 * @see android.net.wifi.wificond.WifiNl80211Manager
Etan Cohen73450f22019-12-12 23:29:25 -08004082 * @hide
4083 */
Roshan Piusbae97692020-01-08 14:15:58 -08004084 @SystemApi
Adrian Roosdf747d12020-01-16 21:20:24 +01004085 @SuppressLint("ServiceName")
Etan Cohenb9f28bc2020-02-09 12:06:56 -08004086 public static final String WIFI_NL80211_SERVICE = "wifinl80211";
Etan Cohen73450f22019-12-12 23:29:25 -08004087
4088 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004089 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07004090 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07004091 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07004092 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004093 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07004094 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07004095 */
4096 public static final String WIFI_P2P_SERVICE = "wifip2p";
4097
4098 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004099 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07004100 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
4101 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07004102 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004103 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07004104 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07004105 */
Etan Cohen04133272016-10-26 11:22:06 -07004106 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07004107
4108 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004109 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07004110 * android.net.wifi.WifiScanner} for scanning the wifi universe
4111 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004112 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07004113 * @see android.net.wifi.WifiScanner
4114 * @hide
4115 */
Wei Wang35d552f2014-07-08 21:37:01 -07004116 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07004117 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
4118
4119 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004120 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07004121 * android.net.wifi.RttManager} for ranging devices with wifi
4122 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004123 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07004124 * @see android.net.wifi.RttManager
4125 * @hide
4126 */
4127 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08004128 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07004129 public static final String WIFI_RTT_SERVICE = "rttmanager";
4130
4131 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004132 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohenf4062a92019-04-11 07:00:42 -07004133 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
Etan Cohen17ba4722017-08-21 10:52:17 -07004134 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004135 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07004136 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07004137 */
Etan Cohen091d7772018-01-04 17:47:37 -08004138 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07004139
4140 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004141 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07004142 * android.net.lowpan.LowpanManager} for handling management of
4143 * LoWPAN access.
4144 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004145 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07004146 * @see android.net.lowpan.LowpanManager
4147 *
4148 * @hide
4149 */
4150 public static final String LOWPAN_SERVICE = "lowpan";
4151
4152 /**
Remi NGUYEN VAN84229e02020-01-24 22:57:09 +09004153 * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.EthernetManager}
4154 * for handling management of Ethernet access.
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004155 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004156 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004157 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004158 *
4159 * @hide
4160 */
Remi NGUYEN VAN84229e02020-01-24 22:57:09 +09004161 @SystemApi
4162 @TestApi
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07004163 public static final String ETHERNET_SERVICE = "ethernet";
4164
4165 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004166 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07004167 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004168 * discovery
4169 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004170 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07004171 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004172 */
4173 public static final String NSD_SERVICE = "servicediscovery";
4174
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004175 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004176 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004177 * {@link android.media.AudioManager} for handling management of volume,
4178 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07004179 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004180 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004181 * @see android.media.AudioManager
4182 */
4183 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07004184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004185 /**
Ilya Matyukhine4675b32019-11-07 16:07:19 -08004186 * AuthService orchestrates biometric and PIN/pattern/password authentication.
4187 *
4188 * BiometricService was split into two services, AuthService and BiometricService, where
4189 * AuthService is the high level service that orchestrates all types of authentication, and
4190 * BiometricService is a lower layer responsible only for biometric authentication.
4191 *
4192 * Ideally we should have renamed BiometricManager to AuthManager, because it logically
4193 * corresponds to AuthService. However, because BiometricManager is a public API, we kept
4194 * the old name but changed the internal implementation to use AuthService.
4195 *
4196 * As of now, the AUTH_SERVICE constant is only used to identify the service in
4197 * SystemServiceRegistry and SELinux. To obtain the manager for AUTH_SERVICE, one should use
4198 * BIOMETRIC_SERVICE with {@link #getSystemService(String)} to retrieve a
4199 * {@link android.hardware.biometrics.BiometricManager}
4200 *
4201 * Map of the two services and their managers:
4202 * [Service] [Manager]
4203 * AuthService BiometricManager
4204 * BiometricService N/A
4205 *
4206 * @hide
4207 */
4208 public static final String AUTH_SERVICE = "auth";
4209
4210 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004211 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07004212 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07004213 * of fingerprints.
4214 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004215 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07004216 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07004217 */
4218 public static final String FINGERPRINT_SERVICE = "fingerprint";
4219
4220 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004221 * Use with {@link #getSystemService(String)} to retrieve a
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004222 * {@link android.hardware.face.FaceManager} for handling management
4223 * of face authentication.
4224 *
4225 * @hide
4226 * @see #getSystemService
4227 * @see android.hardware.face.FaceManager
4228 */
4229 public static final String FACE_SERVICE = "face";
4230
4231 /**
Kevin Chyn05c21502018-09-18 13:07:19 -07004232 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn51676d22018-11-05 18:00:43 -08004233 * {@link android.hardware.iris.IrisManager} for handling management
4234 * of iris authentication.
4235 *
4236 * @hide
4237 * @see #getSystemService
4238 * @see android.hardware.iris.IrisManager
4239 */
4240 public static final String IRIS_SERVICE = "iris";
4241
4242 /**
4243 * Use with {@link #getSystemService(String)} to retrieve a
Ilya Matyukhine4675b32019-11-07 16:07:19 -08004244 * {@link android.hardware.biometrics.BiometricManager} for handling
4245 * biometric and PIN/pattern/password authentication.
Kevin Chyn05c21502018-09-18 13:07:19 -07004246 *
4247 * @see #getSystemService
4248 * @see android.hardware.biometrics.BiometricManager
4249 */
4250 public static final String BIOMETRIC_SERVICE = "biometric";
4251
4252 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004253 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004254 * {@link android.media.MediaRouter} for controlling and managing
4255 * routing of media.
4256 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004257 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004258 * @see android.media.MediaRouter
4259 */
4260 public static final String MEDIA_ROUTER_SERVICE = "media_router";
4261
4262 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004263 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07004264 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08004265 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004266 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07004267 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08004268 */
4269 public static final String MEDIA_SESSION_SERVICE = "media_session";
4270
4271 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004272 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004273 * {@link android.telephony.TelephonyManager} for handling management the
4274 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07004275 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004276 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004277 * @see android.telephony.TelephonyManager
4278 */
4279 public static final String TELEPHONY_SERVICE = "phone";
4280
4281 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004282 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08004283 * {@link android.telephony.SubscriptionManager} for handling management the
4284 * telephony subscriptions of the device.
4285 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004286 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08004287 * @see android.telephony.SubscriptionManager
4288 */
4289 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
4290
4291 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004292 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004293 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07004294 * of the device.
4295 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004296 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004297 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07004298 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004299 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07004300
4301 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004302 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004303 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
4304 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004305 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004306 * @see android.telephony.CarrierConfigManager
4307 */
4308 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
4309
4310 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004311 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08004312 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
4313 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004314 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08004315 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08004316 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004317 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08004318
4319 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004320 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004321 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
4322 *
4323 * @see #getSystemService(String)
4324 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004325 * @hide
4326 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004327 @SystemApi
4328 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004329
4330 /**
4331 * Use with {@link #getSystemService(String)} to retrieve a
Sarah Chin4affb512020-01-10 16:09:11 -08004332 * {@link android.telephony.MmsManager} to send/receive MMS messages.
4333 *
4334 * @see #getSystemService(String)
4335 * @see android.telephony.MmsManager
4336 */
4337 public static final String MMS_SERVICE = "mms";
4338
4339 /**
4340 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08004341 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004342 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07004343 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004344 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004345 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004346 */
4347 public static final String CLIPBOARD_SERVICE = "clipboard";
4348
4349 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004350 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004351 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004352 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004353 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004354 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004355 */
4356 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
4357
4358 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004359 * Use with {@link #getSystemService(String)} to retrieve a
Alex Salo5f5b5f42019-02-27 10:49:00 -08004360 * {@link com.android.server.attention.AttentionManagerService} for attention services.
4361 *
4362 * @see #getSystemService(String)
4363 * @see android.server.attention.AttentionManagerService
4364 * @hide
4365 */
4366 public static final String ATTENTION_SERVICE = "attention";
4367
4368 /**
4369 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004370 * {@link android.view.inputmethod.InputMethodManager} for accessing input
4371 * methods.
4372 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004373 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004374 */
4375 public static final String INPUT_METHOD_SERVICE = "input_method";
4376
4377 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004378 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09004379 * {@link android.view.textservice.TextServicesManager} for accessing
4380 * text services.
4381 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004382 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09004383 */
4384 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
4385
4386 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004387 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08004388 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004389 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004390 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004391 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004392 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07004393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004394 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07004395 * Official published name of the (internal) voice interaction manager service.
4396 *
4397 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004398 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07004399 */
4400 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4401
4402 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08004403 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07004404 *
4405 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004406 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07004407 */
Felipe Leme640f30a2017-03-06 15:44:06 -08004408 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07004409
4410 /**
Felipe Leme749b8892018-12-03 16:30:30 -08004411 * Official published name of the content capture service.
Felipe Lemee348dc32018-11-05 12:35:29 -08004412 *
4413 * @hide
4414 * @see #getSystemService(String)
4415 */
Felipe Lemea7e4ca62019-05-23 13:32:40 -07004416 @TestApi
Adrian Roosd38f5092020-01-16 21:20:24 +01004417 @SuppressLint("ServiceName") // TODO: This should be renamed to CONTENT_CAPTURE_SERVICE
Felipe Leme749b8892018-12-03 16:30:30 -08004418 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
Felipe Lemee348dc32018-11-05 12:35:29 -08004419
4420 /**
Winson Chung3fb0f252019-01-08 17:41:55 -08004421 * Used for getting content selections and classifications for task snapshots.
4422 *
4423 * @hide
4424 * @see #getSystemService(String)
4425 */
4426 @SystemApi
4427 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
4428
4429 /**
Sunny Goyal54e91342018-11-14 11:59:02 -08004430 * Official published name of the app prediction service.
4431 *
Felipe Leme6378bd42019-08-14 18:14:55 -07004432 * <p><b>NOTE: </b> this service is optional; callers of
4433 * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}.
4434 *
Sunny Goyal54e91342018-11-14 11:59:02 -08004435 * @hide
4436 * @see #getSystemService(String)
4437 */
4438 @SystemApi
4439 public static final String APP_PREDICTION_SERVICE = "app_prediction";
4440
4441 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004442 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004443 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
4444 *
4445 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004446 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004447 */
4448 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
4449
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004450 /**
Ytai Ben-Tsvi93c117c862019-11-25 12:43:28 -08004451 * Use with {@link #getSystemService(String)} to access the
4452 * {@link com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareService}.
4453 *
4454 * @hide
4455 * @see #getSystemService(String)
4456 */
4457 public static final String SOUND_TRIGGER_MIDDLEWARE_SERVICE = "soundtrigger_middleware";
4458
4459 /**
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004460 * Official published name of the (internal) permission service.
4461 *
4462 * @see #getSystemService(String)
4463 * @hide
4464 */
Winsonf27394e2019-06-07 14:44:40 -07004465 @TestApi
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004466 @SystemApi
4467 public static final String PERMISSION_SERVICE = "permission";
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004468
4469 /**
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08004470 * Official published name of the (internal) permission controller service.
4471 *
4472 * @see #getSystemService(String)
4473 * @hide
4474 */
4475 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
4476
4477 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004478 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08004479 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07004480 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07004481 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07004482 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004483 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07004484 */
Christopher Tated5cf7222014-07-29 16:53:09 -07004485 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07004486 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07004487
4488 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +01004489 * Use with {@link #getSystemService(String)} to retrieve an
4490 * {@link android.content.rollback.RollbackManager} for communicating
4491 * with the rollback manager
4492 *
4493 * @see #getSystemService(String)
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004494 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +01004495 */
Richard Uhler8a977452019-03-08 13:27:17 +00004496 @SystemApi @TestApi
Richard Uhlerb29f1452018-09-12 16:38:15 +01004497 public static final String ROLLBACK_SERVICE = "rollback";
4498
4499 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004500 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08004501 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07004502 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004503 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07004504 */
4505 public static final String DROPBOX_SERVICE = "dropbox";
4506
Christopher Tate487529a2009-04-29 14:03:25 -07004507 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07004508 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004509 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004510 * @hide
4511 */
Makoto Onuki7d6d9ca2019-08-13 11:45:45 -07004512 @TestApi
Adrian Roosd38f5092020-01-16 21:20:24 +01004513 @SuppressLint("ServiceName") // TODO: This should be renamed to DEVICE_IDLE_SERVICE
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004514 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
4515
4516 /**
Kweku Adamse371b092019-11-22 10:50:48 -08004517 * System service name for the PowerWhitelistManager.
4518 *
4519 * @see #getSystemService(String)
4520 * @hide
4521 */
4522 @TestApi
Adrian Roosd38f5092020-01-16 21:20:24 +01004523 @SuppressLint("ServiceName") // TODO: This should be renamed to POWER_WHITELIST_SERVICE
Kweku Adamse371b092019-11-22 10:50:48 -08004524 public static final String POWER_WHITELIST_MANAGER = "power_whitelist";
4525
4526 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004527 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08004528 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08004529 * device policy management.
4530 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004531 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08004532 */
4533 public static final String DEVICE_POLICY_SERVICE = "device_policy";
4534
4535 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004536 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08004537 * {@link android.app.UiModeManager} for controlling UI modes.
4538 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004539 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08004540 */
4541 public static final String UI_MODE_SERVICE = "uimode";
4542
4543 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004544 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07004545 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07004546 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004547 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07004548 */
4549 public static final String DOWNLOAD_SERVICE = "download";
4550
4551 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004552 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08004553 * {@link android.os.BatteryManager} for managing battery state.
4554 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004555 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08004556 */
4557 public static final String BATTERY_SERVICE = "batterymanager";
4558
4559 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004560 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004561 * {@link android.nfc.NfcManager} for using NFC.
4562 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004563 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004564 */
4565 public static final String NFC_SERVICE = "nfc";
4566
4567 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004568 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00004569 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004570 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004571 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004572 */
4573 public static final String BLUETOOTH_SERVICE = "bluetooth";
4574
4575 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004576 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08004577 * {@link android.net.sip.SipManager} for accessing the SIP related service.
4578 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004579 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08004580 */
4581 /** @hide */
4582 public static final String SIP_SERVICE = "sip";
4583
4584 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004585 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08004586 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004587 * and for controlling this device's behavior as a USB device.
4588 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004589 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04004590 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004591 */
4592 public static final String USB_SERVICE = "usb";
4593
4594 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004595 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Rootf74bfde2018-01-18 15:42:48 -08004596 * Use with {@link #getSystemService} to retrieve a {@link
4597 * android.debug.AdbManager} for access to ADB debug functions.
4598 *
4599 * @see #getSystemService(String)
4600 * @see android.debug.AdbManager
4601 *
4602 * @hide
4603 */
4604 public static final String ADB_SERVICE = "adb";
4605
4606 /**
4607 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004608 * android.hardware.SerialManager} for access to serial ports.
4609 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004610 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004611 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004612 *
4613 * @hide
4614 */
4615 public static final String SERIAL_SERVICE = "serial";
4616
4617 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004618 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09004619 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
4620 * HDMI-CEC protocol.
4621 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004622 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09004623 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004624 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09004625 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004626 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09004627 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09004628
4629 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004630 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004631 * {@link android.hardware.input.InputManager} for interacting with input devices.
4632 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004633 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004634 * @see android.hardware.input.InputManager
4635 */
4636 public static final String INPUT_SERVICE = "input";
4637
4638 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004639 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07004640 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
4641 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004642 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07004643 * @see android.hardware.display.DisplayManager
4644 */
4645 public static final String DISPLAY_SERVICE = "display";
4646
4647 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004648 * Use with {@link #getSystemService(String)} to retrieve a
Christine Franks39b03112018-07-03 14:46:07 -07004649 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
4650 *
4651 * @see #getSystemService(String)
4652 * @see android.hardware.display.ColorDisplayManager
4653 * @hide
4654 */
4655 public static final String COLOR_DISPLAY_SERVICE = "color_display";
4656
4657 /**
4658 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07004659 * {@link android.os.UserManager} for managing users on devices that support multiple users.
4660 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004661 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07004662 * @see android.os.UserManager
4663 */
4664 public static final String USER_SERVICE = "user";
4665
4666 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004667 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08004668 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
4669 * profiles of a user.
4670 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004671 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08004672 * @see android.content.pm.LauncherApps
4673 */
4674 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4675
4676 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004677 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004678 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4679 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004680 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004681 * @see android.content.RestrictionsManager
4682 */
4683 public static final String RESTRICTIONS_SERVICE = "restrictions";
4684
4685 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004686 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004687 * {@link android.app.AppOpsManager} for tracking application operations
4688 * on the device.
4689 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004690 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004691 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004692 */
4693 public static final String APP_OPS_SERVICE = "appops";
4694
4695 /**
Hai Zhangb7776682018-09-25 15:10:57 -07004696 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
4697 * for managing roles.
4698 *
4699 * @see #getSystemService(String)
4700 * @see android.app.role.RoleManager
4701 */
4702 public static final String ROLE_SERVICE = "role";
4703
4704 /**
Hai Zhanga4959e52019-03-06 12:21:07 -08004705 * Official published name of the (internal) role controller service.
4706 *
4707 * @see #getSystemService(String)
4708 * @see android.app.role.RoleControllerService
4709 *
4710 * @hide
4711 */
4712 public static final String ROLE_CONTROLLER_SERVICE = "role_controller";
4713
4714 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004715 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004716 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004717 * camera devices.
4718 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004719 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004720 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004721 */
4722 public static final String CAMERA_SERVICE = "camera";
4723
4724 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004725 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004726 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004727 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004728 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004729 * @see android.print.PrintManager
4730 */
4731 public static final String PRINT_SERVICE = "print";
4732
4733 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004734 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004735 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4736 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004737 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004738 * @see android.companion.CompanionDeviceManager
4739 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004740 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004741
4742 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004743 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004744 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4745 * signals from the device.
4746 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004747 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004748 * @see android.hardware.ConsumerIrManager
4749 */
4750 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4751
4752 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004753 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004754 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004755 * @see android.app.trust.TrustManager
4756 * @hide
4757 */
4758 public static final String TRUST_SERVICE = "trust";
4759
4760 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004761 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004762 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4763 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004764 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004765 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004766 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004767 */
4768 public static final String TV_INPUT_SERVICE = "tv_input";
4769
4770 /**
Amy06a551e2019-11-07 13:44:33 -08004771 * Use with {@link #getSystemService(String)} to retrieve a
4772 * {@link android.media.tv.TunerResourceManager} for interacting with TV
4773 * tuner resources on the device.
4774 *
4775 * @see #getSystemService(String)
4776 * @see android.media.tv.TunerResourceManager
4777 * @hide
4778 */
4779 public static final String TV_TUNER_RESOURCE_MGR_SERVICE = "tv_tuner_resource_mgr";
4780
4781 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004782 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004783 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004784 * @see android.net.NetworkScoreManager
4785 * @hide
4786 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004787 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004788 public static final String NETWORK_SCORE_SERVICE = "network_score";
4789
4790 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004791 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004792 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004793 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004794 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004795 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004796 */
4797 public static final String USAGE_STATS_SERVICE = "usagestats";
4798
4799 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004800 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004801 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004802 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004803 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004804 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004805 */
Christopher Tate7060b042014-06-09 19:50:00 -07004806 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004807
4808 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004809 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004810 * android.service.persistentdata.PersistentDataBlockManager} instance
4811 * for interacting with a storage device that lives across factory resets.
4812 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004813 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004814 * @see android.service.persistentdata.PersistentDataBlockManager
4815 * @hide
4816 */
Andres Morales33df9372014-09-26 17:08:59 -07004817 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004818 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4819
4820 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004821 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004822 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4823 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004824 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004825 * @see android.service.oemlock.OemLockManager
4826 * @hide
4827 */
4828 @SystemApi
4829 public static final String OEM_LOCK_SERVICE = "oem_lock";
4830
4831 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004832 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004833 * android.media.projection.MediaProjectionManager} instance for managing
4834 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004835 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004836 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004837 */
4838 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4839
4840 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004841 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004842 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004843 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004844 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004845 */
4846 public static final String MIDI_SERVICE = "midi";
4847
Eric Laurent2035ac82015-03-05 15:18:44 -08004848
4849 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004850 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004851 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4852 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004853 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004854 * @hide
4855 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004856 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004857
Paul McLeana33be212015-02-20 07:52:45 -08004858 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004859 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004860 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4861 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004862 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004863 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004864 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004865
4866 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004867 * Use with {@link #getSystemService(String)} to retrieve a
Wei Wangbad7c202018-11-01 11:57:39 -07004868 * {@link android.os.ThermalService} for accessing the thermal service.
4869 *
4870 * @see #getSystemService(String)
4871 * @hide
4872 */
4873 public static final String THERMAL_SERVICE = "thermalservice";
4874
4875 /**
4876 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004877 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004878 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004879 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004880 * @see android.content.pm.ShortcutManager
4881 */
4882 public static final String SHORTCUT_SERVICE = "shortcut";
4883
4884 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004885 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004886 * android.hardware.location.ContextHubManager} for accessing context hubs.
4887 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004888 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004889 * @see android.hardware.location.ContextHubManager
4890 *
4891 * @hide
4892 */
4893 @SystemApi
4894 public static final String CONTEXTHUB_SERVICE = "contexthub";
4895
4896 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004897 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004898 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4899 * memory, etc) metrics.
4900 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004901 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004902 */
4903 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4904
4905 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004906 * Gatekeeper Service.
4907 * @hide
4908 */
4909 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4910
4911 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004912 * Service defining the policy for access to device identifiers.
4913 * @hide
4914 */
4915 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4916
4917 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004918 * Service to report a system health "incident"
4919 * @hide
4920 */
4921 public static final String INCIDENT_SERVICE = "incident";
4922
4923 /**
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08004924 * Service to assist incidentd and dumpstated in reporting status to the user
4925 * and in confirming authorization to take an incident report or bugreport
4926 * @hide
4927 */
4928 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
4929
4930 /**
Jeffrey Huang8c1ae5a2019-12-12 10:56:24 -08004931 * Service to assist {@link android.app.StatsManager} that lives in system server.
4932 * @hide
4933 */
4934 public static final String STATS_MANAGER_SERVICE = "statsmanager";
4935
4936 /**
Bookatz94726412017-08-31 09:26:15 -07004937 * Service to assist statsd in obtaining general stats.
4938 * @hide
4939 */
4940 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4941
4942 /**
Bookatzc6977972018-01-16 16:55:05 -08004943 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004944 * @hide
4945 */
4946 @SystemApi
4947 public static final String STATS_MANAGER = "stats";
4948
4949 /**
atrostde54a8ac2019-08-15 16:53:01 +01004950 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4951 * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
4952 * @hide
4953 */
4954 public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
4955
4956 /**
atrost87488352019-10-10 19:27:31 +01004957 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4958 * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
4959 * service.
4960 * @hide
4961 */
4962 public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
4963
4964 /**
Nandana Duttd11850c2018-12-12 17:26:57 +00004965 * Service to capture a bugreport.
4966 * @see #getSystemService(String)
4967 * @see android.os.BugreportManager
4968 * @hide
4969 */
Nandana Duttd7e8d5a2019-04-11 17:27:45 +01004970 @SystemApi @TestApi
Nandana Duttd11850c2018-12-12 17:26:57 +00004971 public static final String BUGREPORT_SERVICE = "bugreport";
4972
4973 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004974 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004975 * android.content.om.OverlayManager} for managing overlay packages.
4976 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004977 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004978 * @see android.content.om.OverlayManager
4979 * @hide
4980 */
4981 public static final String OVERLAY_SERVICE = "overlay";
4982
4983 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004984 * Use with {@link #getSystemService(String)} to retrieve a
MÃ¥rten Kongstad06a1ac82018-09-20 13:09:47 +02004985 * {android.os.IIdmap2} for managing idmap files (used by overlay
4986 * packages).
4987 *
4988 * @see #getSystemService(String)
4989 * @hide
4990 */
4991 public static final String IDMAP_SERVICE = "idmap";
4992
4993 /**
4994 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004995 * {@link VrManager} for accessing the VR service.
4996 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004997 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004998 * @hide
4999 */
5000 @SystemApi
5001 public static final String VR_SERVICE = "vrmanager";
5002
5003 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08005004 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00005005 * {@link android.app.timezone.ITimeZoneRulesManager}.
5006 * @hide
5007 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08005008 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00005009 */
5010 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
5011
5012 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08005013 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00005014 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01005015 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08005016 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01005017 */
5018 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
5019
5020 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08005021 * Use with {@link #getSystemService} to retrieve a
5022 * {@link android.se.omapi.ISecureElementService}
5023 * for accessing the SecureElementService.
5024 *
5025 * @hide
5026 */
5027 @SystemApi
5028 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
5029
5030 /**
Neil Fullerfeeee682018-05-30 14:35:24 +01005031 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fuller3e3b5402019-11-07 15:35:05 +00005032 * {@link android.app.timedetector.TimeDetector}.
Neil Fullerfeeee682018-05-30 14:35:24 +01005033 * @hide
5034 *
5035 * @see #getSystemService(String)
5036 */
5037 public static final String TIME_DETECTOR_SERVICE = "time_detector";
5038
5039 /**
Neil Fuller3e3b5402019-11-07 15:35:05 +00005040 * Use with {@link #getSystemService(String)} to retrieve an
5041 * {@link android.app.timezonedetector.TimeZoneDetector}.
5042 * @hide
5043 *
5044 * @see #getSystemService(String)
5045 */
5046 public static final String TIME_ZONE_DETECTOR_SERVICE = "time_zone_detector";
5047
5048 /**
Makoto Onukidf7e4812018-09-24 14:31:25 -07005049 * Binder service name for {@link AppBindingService}.
5050 * @hide
5051 */
5052 public static final String APP_BINDING_SERVICE = "app_binding";
5053
5054 /**
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07005055 * Use with {@link #getSystemService(String)} to retrieve an
James.cf Lin2bc9cd42019-11-04 20:23:36 +08005056 * {@link android.telephony.ims.ImsManager}.
James.cf Lin2bc9cd42019-11-04 20:23:36 +08005057 */
5058 public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
5059
5060 /**
5061 * Use with {@link #getSystemService(String)} to retrieve an
Hall Liub38ad5f2019-12-23 18:11:10 -08005062 * {@link android.os.SystemConfigManager}.
5063 * @hide
5064 */
5065 @SystemApi
5066 public static final String SYSTEM_CONFIG_SERVICE = "system_config";
5067
5068 /**
5069 * Use with {@link #getSystemService(String)} to retrieve an
Brad Ebingerd1cb3462019-06-20 14:20:01 -07005070 * {@link android.telephony.ims.RcsMessageManager}.
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07005071 * @hide
5072 */
Brad Ebingerd1cb3462019-06-20 14:20:01 -07005073 public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07005074
Howard Chen0a947642019-01-07 14:10:44 +08005075 /**
5076 * Use with {@link #getSystemService(String)} to retrieve an
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08005077 * {@link android.os.image.DynamicSystemManager}.
Howard Chen0a947642019-01-07 14:10:44 +08005078 * @hide
5079 */
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08005080 public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
Howard Chen0a947642019-01-07 14:10:44 +08005081
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07005082 /**
Sudheer Shankaf5b36962019-10-04 16:16:13 -07005083 * Use with {@link #getSystemService(String)} to retrieve a {@link
5084 * android.app.blob.BlobStoreManager} for contributing and accessing data blobs
5085 * from the blob store maintained by the system.
5086 *
5087 * @see #getSystemService(String)
5088 * @see android.app.blob.BlobStoreManager
Sudheer Shankaf5b36962019-10-04 16:16:13 -07005089 */
Sudheer Shankaf5b36962019-10-04 16:16:13 -07005090 public static final String BLOB_STORE_SERVICE = "blob_store";
5091
5092 /**
Chen Xu288b71c2019-09-15 18:28:21 -07005093 * Use with {@link #getSystemService(String)} to retrieve an
Chen Xu1f6cfa52019-10-13 17:30:32 -07005094 * {@link TelephonyRegistryManager}.
Chen Xu288b71c2019-09-15 18:28:21 -07005095 * @hide
5096 */
5097 @SystemApi
5098 public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
5099
5100 /**
Roshan Pius848513e2019-10-11 13:44:00 -07005101 * Use with {@link #getSystemService(String)} to retrieve an
5102 * {@link android.os.BatteryStatsManager}.
5103 * @hide
5104 */
5105 @SystemApi
Adrian Roosd38f5092020-01-16 21:20:24 +01005106 @SuppressLint("ServiceName")
Roshan Pius848513e2019-10-11 13:44:00 -07005107 public static final String BATTERY_STATS_SERVICE = "batterystats";
5108
5109 /**
Terry Wangecc0d1b2019-10-17 17:05:18 -07005110 * Use with {@link #getSystemService(String)} to retrieve an
Terry Wange05730f2020-01-22 16:37:19 -08005111 * {@link android.app.appsearch.AppSearchManager} for
5112 * indexing and querying app data managed by the system.
Terry Wangecc0d1b2019-10-17 17:05:18 -07005113 *
5114 * @see #getSystemService(String)
Terry Wange05730f2020-01-22 16:37:19 -08005115 * @hide
Terry Wangecc0d1b2019-10-17 17:05:18 -07005116 */
5117 public static final String APP_SEARCH_SERVICE = "app_search";
5118
5119 /**
Song Pan75147d52019-11-19 00:57:46 +00005120 * Use with {@link #getSystemService(String)} to retrieve an
5121 * {@link android.content.integrity.AppIntegrityManager}.
5122 * @hide
5123 */
5124 @SystemApi
Song Pan56044372020-02-03 13:39:45 +00005125 @TestApi
Song Pan75147d52019-11-19 00:57:46 +00005126 public static final String APP_INTEGRITY_SERVICE = "app_integrity";
5127
5128 /**
Songchun Fand1b41d42019-11-12 17:09:53 -08005129 * Use with {@link #getSystemService(String)} to retrieve an
Songchun Fan6dd47b52019-11-29 15:20:18 -08005130 * {@link android.content.pm.DataLoaderManager}.
5131 * @hide
5132 */
Songchun Fan7cc20742019-12-11 09:47:45 -08005133 public static final String DATA_LOADER_MANAGER_SERVICE = "dataloader_manager";
Songchun Fan6dd47b52019-11-29 15:20:18 -08005134
5135 /**
5136 * Use with {@link #getSystemService(String)} to retrieve an
Songchun Fand1b41d42019-11-12 17:09:53 -08005137 * {@link android.os.incremental.IncrementalManager}.
5138 * @hide
5139 */
Songchun Fanf5c894f2019-11-29 15:43:58 -08005140 public static final String INCREMENTAL_SERVICE = "incremental_service";
Songchun Fand1b41d42019-11-12 17:09:53 -08005141
5142 /**
Victor Hsieh20fe1f62019-09-30 13:36:21 -07005143 * Use with {@link #getSystemService(String)} to retrieve an
5144 * {@link android.security.FileIntegrityManager}.
5145 * @see #getSystemService(String)
5146 * @see android.security.FileIntegrityManager
5147 */
5148 public static final String FILE_INTEGRITY_SERVICE = "file_integrity";
5149
5150 /**
Ivailo Karamanolev090d02c2020-01-09 17:02:49 +01005151 * Use with {@link #getSystemService(String)} to retrieve a
5152 * {@link android.hardware.lights.LightsManager} for controlling device lights.
5153 *
5154 * @see #getSystemService(String)
5155 * @hide
5156 */
5157 public static final String LIGHTS_SERVICE = "lights";
5158
5159 /**
Galia Peycheva641e2e62020-02-18 00:47:05 +01005160 * Use with {@link #getSystemService(String)} to retrieve a
5161 * {@link android.app.DreamManager} for controlling Dream states.
5162 *
5163 * @see #getSystemService(String)
5164
5165 * @hide
5166 */
5167 @TestApi
5168 public static final String DREAM_SERVICE = "dream";
5169
5170 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005171 * Determine whether the given permission is allowed for a particular
5172 * process and user ID running in the system.
5173 *
5174 * @param permission The name of the permission being checked.
5175 * @param pid The process ID being checked against. Must be > 0.
5176 * @param uid The user ID being checked against. A uid of 0 is the root
5177 * user, which will pass every permission check.
5178 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005179 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005180 * pid/uid is allowed that permission, or
5181 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5182 *
5183 * @see PackageManager#checkPermission(String, String)
5184 * @see #checkCallingPermission
5185 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005186 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07005187 @PackageManager.PermissionResult
5188 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005189
Dianne Hackbornff170242014-11-19 10:59:01 -08005190 /** @hide */
5191 @PackageManager.PermissionResult
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005192 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08005193 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
5194 IBinder callerToken);
5195
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005196 /**
5197 * Determine whether the calling process of an IPC you are handling has been
5198 * granted a particular permission. This is basically the same as calling
5199 * {@link #checkPermission(String, int, int)} with the pid and uid returned
5200 * by {@link android.os.Binder#getCallingPid} and
5201 * {@link android.os.Binder#getCallingUid}. One important difference
5202 * is that if you are not currently processing an IPC, this function
5203 * will always fail. This is done to protect against accidentally
5204 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
5205 * to avoid this protection.
5206 *
5207 * @param permission The name of the permission being checked.
5208 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005209 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005210 * pid/uid is allowed that permission, or
5211 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5212 *
5213 * @see PackageManager#checkPermission(String, String)
5214 * @see #checkPermission
5215 * @see #checkCallingOrSelfPermission
5216 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005217 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07005218 @PackageManager.PermissionResult
5219 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005220
5221 /**
5222 * Determine whether the calling process of an IPC <em>or you</em> have been
5223 * granted a particular permission. This is the same as
5224 * {@link #checkCallingPermission}, except it grants your own permissions
5225 * if you are not currently processing an IPC. Use with care!
5226 *
5227 * @param permission The name of the permission being checked.
5228 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005229 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005230 * pid/uid is allowed that permission, or
5231 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5232 *
5233 * @see PackageManager#checkPermission(String, String)
5234 * @see #checkPermission
5235 * @see #checkCallingPermission
5236 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005237 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07005238 @PackageManager.PermissionResult
5239 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005240
5241 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08005242 * Determine whether <em>you</em> have been granted a particular permission.
5243 *
5244 * @param permission The name of the permission being checked.
5245 *
5246 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
5247 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
5248 *
5249 * @see PackageManager#checkPermission(String, String)
5250 * @see #checkCallingPermission(String)
5251 */
5252 @PackageManager.PermissionResult
5253 public abstract int checkSelfPermission(@NonNull String permission);
5254
5255 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005256 * If the given permission is not allowed for a particular process
5257 * and user ID running in the system, throw a {@link SecurityException}.
5258 *
5259 * @param permission The name of the permission being checked.
5260 * @param pid The process ID being checked against. Must be &gt; 0.
5261 * @param uid The user ID being checked against. A uid of 0 is the root
5262 * user, which will pass every permission check.
5263 * @param message A message to include in the exception if it is thrown.
5264 *
5265 * @see #checkPermission(String, int, int)
5266 */
5267 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005268 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005269
5270 /**
5271 * If the calling process of an IPC you are handling has not been
5272 * granted a particular permission, throw a {@link
5273 * SecurityException}. This is basically the same as calling
5274 * {@link #enforcePermission(String, int, int, String)} with the
5275 * pid and uid returned by {@link android.os.Binder#getCallingPid}
5276 * and {@link android.os.Binder#getCallingUid}. One important
5277 * difference is that if you are not currently processing an IPC,
5278 * this function will always throw the SecurityException. This is
5279 * done to protect against accidentally leaking permissions; you
5280 * can use {@link #enforceCallingOrSelfPermission} to avoid this
5281 * protection.
5282 *
5283 * @param permission The name of the permission being checked.
5284 * @param message A message to include in the exception if it is thrown.
5285 *
5286 * @see #checkCallingPermission(String)
5287 */
5288 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005289 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005290
5291 /**
5292 * If neither you nor the calling process of an IPC you are
5293 * handling has been granted a particular permission, throw a
5294 * {@link SecurityException}. This is the same as {@link
5295 * #enforceCallingPermission}, except it grants your own
5296 * permissions if you are not currently processing an IPC. Use
5297 * with care!
5298 *
5299 * @param permission The name of the permission being checked.
5300 * @param message A message to include in the exception if it is thrown.
5301 *
5302 * @see #checkCallingOrSelfPermission(String)
5303 */
5304 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005305 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005306
5307 /**
5308 * Grant permission to access a specific Uri to another package, regardless
5309 * of whether that package has general permission to access the Uri's
5310 * content provider. This can be used to grant specific, temporary
5311 * permissions, typically in response to user interaction (such as the
5312 * user opening an attachment that you would like someone else to
5313 * display).
5314 *
5315 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
5316 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
5317 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
5318 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
5319 * start an activity instead of this function directly. If you use this
5320 * function directly, you should be sure to call
5321 * {@link #revokeUriPermission} when the target should no longer be allowed
5322 * to access it.
5323 *
5324 * <p>To succeed, the content provider owning the Uri must have set the
5325 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
5326 * grantUriPermissions} attribute in its manifest or included the
5327 * {@link android.R.styleable#AndroidManifestGrantUriPermission
5328 * &lt;grant-uri-permissions&gt;} tag.
5329 *
5330 * @param toPackage The package you would like to allow to access the Uri.
5331 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005332 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005333 *
5334 * @see #revokeUriPermission
5335 */
5336 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07005337 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005338
5339 /**
5340 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07005341 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
5342 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07005343 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005344 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07005345 * "content://foo". It will not remove any prefix grants that exist at a
5346 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005347 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07005348 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07005349 * regular permission access to a Uri, but had received access to it through
5350 * a specific Uri permission grant, you could not revoke that grant with this
5351 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07005352 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
5353 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07005354 * (or none).</p>
5355 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07005356 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
5357 * grants matching the given Uri, for any package they had been granted to, through any
5358 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
5359 * service start, etc). That means this can be potentially dangerous to use, as it can
5360 * revoke grants that another app could be strongly expecting to stick around.</p>
5361 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005362 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005363 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005364 *
5365 * @see #grantUriPermission
5366 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07005367 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005368
5369 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07005370 * Remove permissions to access a particular content provider Uri
5371 * that were previously added with {@link #grantUriPermission} for a specific target
5372 * package. The given Uri will match all previously granted Uris that are the same or a
5373 * sub-path of the given Uri. That is, revoking "content://foo/target" will
5374 * revoke both "content://foo/target" and "content://foo/target/sub", but not
5375 * "content://foo". It will not remove any prefix grants that exist at a
5376 * higher level.
5377 *
5378 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
5379 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
5380 * and only for the package specified. Any matching grants that have happened through
5381 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
5382 * removed.</p>
5383 *
5384 * @param toPackage The package you had previously granted access to.
5385 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005386 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07005387 *
5388 * @see #grantUriPermission
5389 */
5390 public abstract void revokeUriPermission(String toPackage, Uri uri,
5391 @Intent.AccessUriMode int modeFlags);
5392
5393 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005394 * Determine whether a particular process and user ID has been granted
5395 * permission to access a specific URI. This only checks for permissions
5396 * that have been explicitly granted -- if the given process/uid has
5397 * more general access to the URI's content provider then this check will
5398 * always fail.
5399 *
5400 * @param uri The uri that is being checked.
5401 * @param pid The process ID being checked against. Must be &gt; 0.
5402 * @param uid The user ID being checked against. A uid of 0 is the root
5403 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005404 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005405 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005406 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005407 * pid/uid is allowed to access that uri, or
5408 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5409 *
5410 * @see #checkCallingUriPermission
5411 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005412 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005413 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005414 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005415 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005416
Dianne Hackbornff170242014-11-19 10:59:01 -08005417 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005418 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08005419 public abstract int checkUriPermission(Uri uri, int pid, int uid,
5420 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
5421
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005422 /**
5423 * Determine whether the calling process and user ID has been
5424 * granted permission to access a specific URI. This is basically
5425 * the same as calling {@link #checkUriPermission(Uri, int, int,
5426 * int)} with the pid and uid returned by {@link
5427 * android.os.Binder#getCallingPid} and {@link
5428 * android.os.Binder#getCallingUid}. One important difference is
5429 * that if you are not currently processing an IPC, this function
5430 * will always fail.
5431 *
5432 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005433 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005434 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005435 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005436 * is allowed to access that uri, or
5437 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5438 *
5439 * @see #checkUriPermission(Uri, int, int, int)
5440 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005441 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005442 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07005443 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005444
5445 /**
5446 * Determine whether the calling process of an IPC <em>or you</em> has been granted
5447 * permission to access a specific URI. This is the same as
5448 * {@link #checkCallingUriPermission}, except it grants your own permissions
5449 * if you are not currently processing an IPC. Use with care!
5450 *
5451 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005452 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005453 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005454 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005455 * is allowed to access that uri, or
5456 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5457 *
5458 * @see #checkCallingUriPermission
5459 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005460 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005461 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005462 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005463 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005464
5465 /**
5466 * Check both a Uri and normal permission. This allows you to perform
5467 * both {@link #checkPermission} and {@link #checkUriPermission} in one
5468 * call.
5469 *
5470 * @param uri The Uri whose permission is to be checked, or null to not
5471 * do this check.
5472 * @param readPermission The permission that provides overall read access,
5473 * or null to not do this check.
5474 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005475 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005476 * @param pid The process ID being checked against. Must be &gt; 0.
5477 * @param uid The user ID being checked against. A uid of 0 is the root
5478 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005479 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005480 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005481 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005482 * is allowed to access that uri or holds one of the given permissions, or
5483 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5484 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005485 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005486 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005487 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
5488 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005489 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005490
5491 /**
5492 * If a particular process and user ID has not been granted
5493 * permission to access a specific URI, throw {@link
5494 * SecurityException}. This only checks for permissions that have
5495 * been explicitly granted -- if the given process/uid has more
5496 * general access to the URI's content provider then this check
5497 * will always fail.
5498 *
5499 * @param uri The uri that is being checked.
5500 * @param pid The process ID being checked against. Must be &gt; 0.
5501 * @param uid The user ID being checked against. A uid of 0 is the root
5502 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005503 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005504 * @param message A message to include in the exception if it is thrown.
5505 *
5506 * @see #checkUriPermission(Uri, int, int, int)
5507 */
5508 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005509 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005510
5511 /**
5512 * If the calling process and user ID has not been granted
5513 * permission to access a specific URI, throw {@link
5514 * SecurityException}. This is basically the same as calling
5515 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
5516 * the pid and uid returned by {@link
5517 * android.os.Binder#getCallingPid} and {@link
5518 * android.os.Binder#getCallingUid}. One important difference is
5519 * that if you are not currently processing an IPC, this function
5520 * will always throw a SecurityException.
5521 *
5522 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005523 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005524 * @param message A message to include in the exception if it is thrown.
5525 *
5526 * @see #checkCallingUriPermission(Uri, int)
5527 */
5528 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005529 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005530
5531 /**
5532 * If the calling process of an IPC <em>or you</em> has not been
5533 * granted permission to access a specific URI, throw {@link
5534 * SecurityException}. This is the same as {@link
5535 * #enforceCallingUriPermission}, except it grants your own
5536 * permissions if you are not currently processing an IPC. Use
5537 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07005538 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005539 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005540 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005541 * @param message A message to include in the exception if it is thrown.
5542 *
5543 * @see #checkCallingOrSelfUriPermission(Uri, int)
5544 */
5545 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005546 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005547
5548 /**
5549 * Enforce both a Uri and normal permission. This allows you to perform
5550 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
5551 * call.
Scott Main4b5da682010-10-21 11:49:12 -07005552 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005553 * @param uri The Uri whose permission is to be checked, or null to not
5554 * do this check.
5555 * @param readPermission The permission that provides overall read access,
5556 * or null to not do this check.
5557 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005558 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005559 * @param pid The process ID being checked against. Must be &gt; 0.
5560 * @param uid The user ID being checked against. A uid of 0 is the root
5561 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005562 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005563 * @param message A message to include in the exception if it is thrown.
5564 *
5565 * @see #checkUriPermission(Uri, String, String, int, int, int)
5566 */
5567 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005568 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005569 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07005570 @Nullable String message);
5571
5572 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005573 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
5574 CONTEXT_INCLUDE_CODE,
5575 CONTEXT_IGNORE_SECURITY,
5576 CONTEXT_RESTRICTED,
5577 CONTEXT_DEVICE_PROTECTED_STORAGE,
5578 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
5579 CONTEXT_REGISTER_PACKAGE,
5580 })
Tor Norbyed9273d62013-05-30 15:59:53 -07005581 @Retention(RetentionPolicy.SOURCE)
5582 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005583
5584 /**
5585 * Flag for use with {@link #createPackageContext}: include the application
5586 * code with the context. This means loading code into the caller's
5587 * process, so that {@link #getClassLoader()} can be used to instantiate
5588 * the application's classes. Setting this flags imposes security
5589 * restrictions on what application context you can access; if the
5590 * requested application can not be safely loaded into your process,
5591 * java.lang.SecurityException will be thrown. If this flag is not set,
5592 * there will be no restrictions on the packages that can be loaded,
5593 * but {@link #getClassLoader} will always return the default system
5594 * class loader.
5595 */
5596 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
5597
5598 /**
5599 * Flag for use with {@link #createPackageContext}: ignore any security
5600 * restrictions on the Context being requested, allowing it to always
5601 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
5602 * to be loaded into a process even when it isn't safe to do so. Use
5603 * with extreme care!
5604 */
5605 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07005606
Romain Guy870e09f2009-07-06 16:35:25 -07005607 /**
5608 * Flag for use with {@link #createPackageContext}: a restricted context may
5609 * disable specific features. For instance, a View associated with a restricted
5610 * context would ignore particular XML attributes.
5611 */
5612 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005613
5614 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005615 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005616 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005617 *
5618 * @hide
5619 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005620 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005621
5622 /**
5623 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005624 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005625 *
5626 * @hide
5627 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005628 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005629
5630 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07005631 * @hide Used to indicate we should tell the activity manager about the process
5632 * loading this code.
5633 */
5634 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
5635
5636 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005637 * Return a new Context object for the given application name. This
5638 * Context is the same as what the named application gets when it is
5639 * launched, containing the same resources and class loader. Each call to
5640 * this method returns a new instance of a Context object; Context objects
5641 * are not shared, however they share common state (Resources, ClassLoader,
5642 * etc) so the Context instance itself is fairly lightweight.
5643 *
Jeff Brown6e539312015-02-24 18:53:21 -08005644 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005645 * application with the given package name.
5646 *
5647 * <p>Throws {@link java.lang.SecurityException} if the Context requested
5648 * can not be loaded into the caller's process for security reasons (see
5649 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
5650 *
5651 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005652 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005653 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005654 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005655 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005656 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005657 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04005658 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005659 */
5660 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07005661 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07005662
5663 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07005664 * Similar to {@link #createPackageContext(String, int)}, but with a
5665 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5666 * will open any {@link Uri} as the given user.
5667 *
5668 * @hide
5669 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08005670 @SystemApi
Jeff Sharkeyec5f7d12018-08-08 09:15:04 -06005671 @TestApi
Makoto Onukib8440012019-10-09 15:33:11 -07005672 @NonNull
Patrick Baumannef4c4072018-02-01 08:54:05 -08005673 public Context createPackageContextAsUser(
Makoto Onukib8440012019-10-09 15:33:11 -07005674 @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08005675 throws PackageManager.NameNotFoundException {
5676 if (Build.IS_ENG) {
5677 throw new IllegalStateException("createPackageContextAsUser not overridden!");
5678 }
5679 return this;
5680 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07005681
5682 /**
Makoto Onukib8440012019-10-09 15:33:11 -07005683 * Similar to {@link #createPackageContext(String, int)}, but for the own package with a
5684 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5685 * will open any {@link Uri} as the given user.
5686 *
5687 * @hide
5688 */
5689 @SystemApi
5690 @TestApi
5691 @NonNull
Makoto Onukie5449f02019-10-11 20:19:58 -07005692 public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
Makoto Onukib8440012019-10-09 15:33:11 -07005693 if (Build.IS_ENG) {
5694 throw new IllegalStateException("createContextAsUser not overridden!");
5695 }
5696 return this;
5697 }
5698
5699 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07005700 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
5701 *
5702 * @hide
5703 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005704 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07005705 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005706 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07005707
5708 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08005709 * Return a new Context object for the given split name. The new Context has a ClassLoader and
5710 * Resources object that can access the split's and all of its dependencies' code/resources.
5711 * Each call to this method returns a new instance of a Context object;
5712 * Context objects are not shared, however common state (ClassLoader, other Resources for
5713 * the same split) may be so the Context itself can be fairly lightweight.
5714 *
5715 * @param splitName The name of the split to include, as declared in the split's
5716 * <code>AndroidManifest.xml</code>.
5717 * @return A {@link Context} with the given split's code and/or resources loaded.
5718 */
5719 public abstract Context createContextForSplit(String splitName)
5720 throws PackageManager.NameNotFoundException;
5721
5722 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005723 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08005724 * @hide
5725 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07005726 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005727 public UserHandle getUser() {
5728 return android.os.Process.myUserHandle();
5729 }
5730
5731 /**
5732 * Get the user associated with this context
5733 * @hide
5734 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +00005735 @UnsupportedAppUsage
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005736 @TestApi
5737 public @UserIdInt int getUserId() {
5738 return android.os.UserHandle.myUserId();
5739 }
Jim Millera75a8832013-02-07 16:53:32 -08005740
5741 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07005742 * Return a new Context object for the current Context but whose resources
5743 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07005744 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07005745 * shared, however common state (ClassLoader, other Resources for the
5746 * same configuration) may be so the Context itself can be fairly lightweight.
5747 *
5748 * @param overrideConfiguration A {@link Configuration} specifying what
5749 * values to modify in the base Configuration of the original Context's
5750 * resources. If the base configuration changes (such as due to an
5751 * orientation change), the resources of this context will also change except
5752 * for those that have been explicitly overridden with a value here.
5753 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005754 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07005755 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005756 public abstract Context createConfigurationContext(
5757 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07005758
5759 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07005760 * Return a new Context object for the current Context but whose resources
5761 * are adjusted to match the metrics of the given Display. Each call to this method
5762 * returns a new instance of a Context object; Context objects are not
5763 * shared, however common state (ClassLoader, other Resources for the
5764 * same configuration) may be so the Context itself can be fairly lightweight.
5765 *
Andrii Kuliane57f2dc2020-01-26 20:59:07 -08005766 * To obtain an instance of a {@link WindowManager} (see {@link #getSystemService(String)}) that
5767 * is configured to show windows on the given display call
5768 * {@link #createWindowContext(int, Bundle)} on the returned display Context or use an
5769 * {@link android.app.Activity}.
Jeff Browna492c3a2012-08-23 19:48:44 -07005770 *
Andrii Kuliane57f2dc2020-01-26 20:59:07 -08005771 * @param display A {@link Display} object specifying the display for whose metrics the
5772 * Context's resources should be tailored.
Jeff Browna492c3a2012-08-23 19:48:44 -07005773 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005774 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07005775 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005776 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07005777
5778 /**
Andrii Kulian4a316972020-01-21 21:41:38 -08005779 * Creates a Context for a non-activity window.
5780 *
5781 * <p>
5782 * A window context is a context that can be used to add non-activity windows, such as
5783 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}. A window context
5784 * must be created from a context that has an associated {@link Display}, such as
5785 * {@link android.app.Activity Activity} or a context created with
5786 * {@link #createDisplayContext(Display)}.
5787 *
5788 * <p>
5789 * The window context is created with the appropriate {@link Configuration} for the area of the
5790 * display that the windows created with it can occupy; it must be used when
5791 * {@link android.view.LayoutInflater inflating} views, such that they can be inflated with
5792 * proper {@link Resources}.
5793 *
5794 * Below is a sample code to <b>add an application overlay window on the primary display:<b/>
5795 * <pre class="prettyprint">
5796 * ...
5797 * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
5798 * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
5799 * final Context windowContext = anyContext.createDisplayContext(primaryDisplay)
Andrii Kulianea325632020-01-28 17:52:57 -08005800 * .createWindowContext(TYPE_APPLICATION_OVERLAY, null);
Andrii Kulian4a316972020-01-21 21:41:38 -08005801 * final View overlayView = Inflater.from(windowContext).inflate(someLayoutXml, null);
5802 *
5803 * // WindowManager.LayoutParams initialization
5804 * ...
5805 * mParams.type = TYPE_APPLICATION_OVERLAY;
5806 * ...
5807 *
5808 * mWindowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
5809 * </pre>
5810 *
5811 * <p>
5812 * This context's configuration and resources are adjusted to a display area where the windows
5813 * with provided type will be added. <b>Note that all windows associated with the same context
5814 * will have an affinity and can only be moved together between different displays or areas on a
5815 * display.</b> If there is a need to add different window types, or non-associated windows,
5816 * separate Contexts should be used.
5817 * </p>
5818 *
5819 * @param type Window type in {@link WindowManager.LayoutParams}
Andrii Kulianea325632020-01-28 17:52:57 -08005820 * @param options Bundle used to pass window-related options.
Andrii Kulian4a316972020-01-21 21:41:38 -08005821 * @return A {@link Context} that can be used to create windows.
5822 * @throws UnsupportedOperationException if this is called on a non-UI context, such as
5823 * {@link android.app.Application Application} or {@link android.app.Service Service}.
5824 *
5825 * @see #getSystemService(String)
5826 * @see #getSystemService(Class)
5827 * @see #WINDOW_SERVICE
5828 * @see #LAYOUT_INFLATER_SERVICE
5829 * @see #WALLPAPER_SERVICE
5830 * @throws IllegalArgumentException if token is invalid
5831 */
Andrii Kulianea325632020-01-28 17:52:57 -08005832 public @NonNull Context createWindowContext(int type, @Nullable Bundle options) {
Andrii Kulian4a316972020-01-21 21:41:38 -08005833 throw new RuntimeException("Not implemented. Must override in a subclass.");
5834 }
5835
5836 /**
Philip P. Moltmann59076d82019-08-19 15:00:40 -07005837 * Return a new Context object for the current Context but for a different feature in the app.
5838 * Features can be used by complex apps to separate logical parts.
5839 *
5840 * @param featureId The feature id or {@code null} to create a context for the default feature.
5841 *
5842 * @return A {@link Context} for the feature
5843 *
5844 * @see #getFeatureId()
5845 */
5846 public @NonNull Context createFeatureContext(@Nullable String featureId) {
Philip P. Moltmannf1a634c2019-10-18 09:10:56 -07005847 throw new RuntimeException("Not implemented. Must override in a subclass.");
Philip P. Moltmann59076d82019-08-19 15:00:40 -07005848 }
5849
5850 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005851 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005852 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005853 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005854 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005855 * with a key tied to the physical device, and it can be accessed
5856 * immediately after the device has booted successfully, both
5857 * <em>before and after</em> the user has authenticated with their
5858 * credentials (such as a lock pattern or PIN).
5859 * <p>
5860 * Because device-protected data is available without user authentication,
5861 * you should carefully limit the data you store using this Context. For
5862 * example, storing sensitive authentication tokens or passwords in the
5863 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005864 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005865 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005866 * device-protected and credential-protected data using different keys, then
5867 * both storage areas will become available at the same time. They remain as
5868 * two distinct storage locations on disk, and only the window of
5869 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005870 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005871 * Each call to this method returns a new instance of a Context object;
5872 * Context objects are not shared, however common state (ClassLoader, other
5873 * Resources for the same configuration) may be so the Context itself can be
5874 * fairly lightweight.
5875 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005876 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005877 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005878 public abstract Context createDeviceProtectedStorageContext();
5879
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005880 /**
5881 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005882 * APIs are backed by credential-protected storage. This is the default
5883 * storage area for apps unless
5884 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005885 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005886 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005887 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005888 * <em>only after</em> the user has entered their credentials (such as a
5889 * lock pattern or PIN).
5890 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005891 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005892 * device-protected and credential-protected data using different keys, then
5893 * both storage areas will become available at the same time. They remain as
5894 * two distinct storage locations on disk, and only the window of
5895 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005896 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005897 * Each call to this method returns a new instance of a Context object;
5898 * Context objects are not shared, however common state (ClassLoader, other
5899 * Resources for the same configuration) may be so the Context itself can be
5900 * fairly lightweight.
5901 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005902 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005903 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005904 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005905 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005906 public abstract Context createCredentialProtectedStorageContext();
5907
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005908 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07005909 * Gets the display adjustments holder for this context. This information
5910 * is provided on a per-application or activity basis and is used to simulate lower density
5911 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07005912 *
Jeff Browna492c3a2012-08-23 19:48:44 -07005913 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07005914 * @return The compatibility info holder, or null if not required by the application.
5915 * @hide
5916 */
Craig Mautner48d0d182013-06-11 07:53:06 -07005917 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07005918
5919 /**
Andrii Kulian4a316972020-01-21 21:41:38 -08005920 * Get the display this context is associated with. Applications should use this method with
5921 * {@link android.app.Activity} or a context associated with a {@link Display} via
5922 * {@link #createDisplayContext(Display)} to get a display object associated with a Context, or
5923 * {@link android.hardware.display.DisplayManager#getDisplay} to get a display object by id.
Wale Ogunwale691af682019-02-11 03:09:10 -08005924 * @return Returns the {@link Display} object this context is associated with.
Andrii Kulian5877c7d2020-01-29 16:57:32 -08005925 * @throws UnsupportedOperationException if the method is called on an instance that is not
5926 * associated with any display.
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005927 */
Andrii Kulian4a316972020-01-21 21:41:38 -08005928 @Nullable
5929 public Display getDisplay() {
5930 throw new RuntimeException("Not implemented. Must override in a subclass.");
5931 }
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005932
5933 /**
Andrii Kulian5877c7d2020-01-29 16:57:32 -08005934 * A version of {@link #getDisplay()} that does not perform a Context misuse check to be used by
5935 * legacy APIs.
5936 * TODO(b/149790106): Fix usages and remove.
5937 * @hide
5938 */
5939 @Nullable
5940 public Display getDisplayNoVerify() {
5941 throw new RuntimeException("Not implemented. Must override in a subclass.");
5942 }
5943
5944 /**
Andrii Kulian4a316972020-01-21 21:41:38 -08005945 * Gets the ID of the display this context is associated with.
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005946 *
5947 * @return display ID associated with this {@link Context}.
Andrii Kulian4a316972020-01-21 21:41:38 -08005948 * @see #getDisplay()
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005949 * @hide
5950 */
wilsonshih5db7b392019-02-20 23:08:45 +08005951 @TestApi
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005952 public abstract int getDisplayId();
5953
5954 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08005955 * @hide
5956 */
5957 public abstract void updateDisplay(int displayId);
5958
5959 /**
Romain Guy870e09f2009-07-06 16:35:25 -07005960 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07005961 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005962 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07005963 *
Romain Guy870e09f2009-07-06 16:35:25 -07005964 * @see #CONTEXT_RESTRICTED
5965 */
5966 public boolean isRestricted() {
5967 return false;
5968 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005969
5970 /**
5971 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005972 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005973 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005974 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005975 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005976 public abstract boolean isDeviceProtectedStorage();
5977
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005978 /**
5979 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005980 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005981 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005982 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005983 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005984 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005985 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005986 public abstract boolean isCredentialProtectedStorage();
5987
Tony Mak46aabe52016-11-14 12:53:06 +00005988 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005989 * Returns true if the context can load unsafe resources, e.g. fonts.
5990 * @hide
5991 */
5992 public abstract boolean canLoadUnsafeResources();
5993
5994 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005995 * @hide
5996 */
5997 public IBinder getActivityToken() {
5998 throw new RuntimeException("Not implemented. Must override in a subclass.");
5999 }
6000
6001 /**
6002 * @hide
6003 */
6004 @Nullable
6005 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
6006 int flags) {
6007 throw new RuntimeException("Not implemented. Must override in a subclass.");
6008 }
6009
6010 /**
6011 * @hide
6012 */
6013 public IApplicationThread getIApplicationThread() {
6014 throw new RuntimeException("Not implemented. Must override in a subclass.");
6015 }
Tony Makbf9928d2016-12-22 11:02:45 +00006016
6017 /**
6018 * @hide
6019 */
6020 public Handler getMainThreadHandler() {
6021 throw new RuntimeException("Not implemented. Must override in a subclass.");
6022 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07006023
6024 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07006025 * @hide
6026 */
6027 public AutofillClient getAutofillClient() {
6028 return null;
6029 }
6030
6031 /**
6032 * @hide
6033 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08006034 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07006035 }
6036
6037 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08006038 * @hide
6039 */
Felipe Lemecbf7f262019-04-17 13:57:59 -07006040 @Nullable
6041 public ContentCaptureClient getContentCaptureClient() {
6042 return null;
6043 }
6044
6045 /**
6046 * @hide
6047 */
Felipe Lemea4f39cd2019-02-19 15:08:59 -08006048 public final boolean isAutofillCompatibilityEnabled() {
6049 final AutofillOptions options = getAutofillOptions();
6050 return options != null && options.compatModeEnabled;
6051 }
6052
6053 /**
6054 * @hide
6055 */
6056 @Nullable
6057 public AutofillOptions getAutofillOptions() {
6058 return null;
Svetoslav Ganov24c90452017-12-27 15:17:14 -08006059 }
6060
6061 /**
6062 * @hide
6063 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08006064 @TestApi
Felipe Lemea4f39cd2019-02-19 15:08:59 -08006065 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08006066 }
6067
6068 /**
Felipe Leme326f15a2019-02-19 09:42:24 -08006069 * Gets the Content Capture options for this context, or {@code null} if it's not whitelisted.
Felipe Lemeecb08be2018-11-27 15:48:47 -08006070 *
6071 * @hide
6072 */
Felipe Leme326f15a2019-02-19 09:42:24 -08006073 @Nullable
6074 public ContentCaptureOptions getContentCaptureOptions() {
6075 return null;
Felipe Lemeecb08be2018-11-27 15:48:47 -08006076 }
6077
6078 /**
6079 * @hide
6080 */
Felipe Leme326f15a2019-02-19 09:42:24 -08006081 @TestApi
6082 public void setContentCaptureOptions(
6083 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08006084 }
6085
6086 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07006087 * Throws an exception if the Context is using system resources,
6088 * which are non-runtime-overlay-themable and may show inconsistent UI.
6089 * @hide
6090 */
6091 public void assertRuntimeOverlayThemable() {
6092 // Resources.getSystem() is a singleton and the only Resources not managed by
6093 // ResourcesManager; therefore Resources.getSystem() is not themable.
6094 if (getResources() == Resources.getSystem()) {
6095 throw new IllegalArgumentException("Non-UI context used to display UI; "
6096 + "get a UI context from ActivityThread#getSystemUiContext()");
6097 }
6098 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08006099}