blob: 66a5c47b3df8432a815c271a78c5aa4d1568cc87 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Tor Norbyec91531a2015-04-01 17:41:55 -070019import android.annotation.AttrRes;
Bo Liu58a57662019-03-06 20:21:45 +000020import android.annotation.CallbackExecutor;
Tor Norbye1c2bf032015-03-02 10:57:08 -080021import android.annotation.CheckResult;
Tor Norbye3e4cda72015-06-10 08:14:31 -070022import android.annotation.ColorInt;
23import android.annotation.ColorRes;
24import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070025import android.annotation.IntDef;
26import android.annotation.NonNull;
27import android.annotation.Nullable;
Tor Norbye788fc2b2015-07-05 16:10:42 -070028import android.annotation.RequiresPermission;
Tor Norbyed9273d62013-05-30 15:59:53 -070029import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070030import android.annotation.StringRes;
31import android.annotation.StyleRes;
32import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090033import android.annotation.SystemApi;
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -070034import android.annotation.TestApi;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010035import android.annotation.UnsupportedAppUsage;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070036import android.annotation.UserIdInt;
Selim Cinek7fa385a2018-01-24 08:35:28 -080037import android.app.ActivityManager;
Tony Mak46aabe52016-11-14 12:53:06 +000038import android.app.IApplicationThread;
39import android.app.IServiceConnection;
Zak Cohen56345f42017-01-26 13:54:28 -080040import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070041import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042import android.content.pm.PackageManager;
43import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080044import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070045import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080046import android.content.res.Resources;
47import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070048import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049import android.database.sqlite.SQLiteDatabase;
50import android.database.sqlite.SQLiteDatabase.CursorFactory;
51import android.graphics.Bitmap;
52import android.graphics.drawable.Drawable;
53import android.net.Uri;
Patrick Baumannef4c4072018-02-01 08:54:05 -080054import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070056import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.os.Handler;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070058import android.os.HandlerExecutor;
Dianne Hackbornff170242014-11-19 10:59:01 -080059import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070061import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070062import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070063import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060064import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070065import android.provider.MediaStore;
Chen Xu8eb62f92019-10-13 17:30:32 -070066import android.telephony.TelephonyRegistryManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070068import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070069import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070070import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070071import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070072import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070073import android.view.autofill.AutofillManager.AutofillClient;
Felipe Lemecbf7f262019-04-17 13:57:59 -070074import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000075import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076
atrosta6a4d602019-08-21 16:48:56 +010077import com.android.internal.compat.IPlatformCompat;
atrostff948d82019-10-10 19:27:31 +010078import com.android.internal.compat.IPlatformCompatNative;
atrosta6a4d602019-08-21 16:48:56 +010079
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080import java.io.File;
81import java.io.FileInputStream;
82import java.io.FileNotFoundException;
83import java.io.FileOutputStream;
84import java.io.IOException;
85import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070086import java.lang.annotation.Retention;
87import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070088import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089
90/**
91 * Interface to global information about an application environment. This is
92 * an abstract class whose implementation is provided by
93 * the Android system. It
94 * allows access to application-specific resources and classes, as well as
95 * up-calls for application-level operations such as launching activities,
96 * broadcasting and receiving intents, etc.
97 */
98public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060099 /** @hide */
100 @IntDef(flag = true, prefix = { "MODE_" }, value = {
101 MODE_PRIVATE,
102 MODE_WORLD_READABLE,
103 MODE_WORLD_WRITEABLE,
104 MODE_APPEND,
105 })
106 @Retention(RetentionPolicy.SOURCE)
107 public @interface FileMode {}
108
109 /** @hide */
110 @IntDef(flag = true, prefix = { "MODE_" }, value = {
111 MODE_PRIVATE,
112 MODE_WORLD_READABLE,
113 MODE_WORLD_WRITEABLE,
114 MODE_MULTI_PROCESS,
115 })
116 @Retention(RetentionPolicy.SOURCE)
117 public @interface PreferencesMode {}
118
119 /** @hide */
120 @IntDef(flag = true, prefix = { "MODE_" }, value = {
121 MODE_PRIVATE,
122 MODE_WORLD_READABLE,
123 MODE_WORLD_WRITEABLE,
124 MODE_ENABLE_WRITE_AHEAD_LOGGING,
125 MODE_NO_LOCALIZED_COLLATORS,
126 })
127 @Retention(RetentionPolicy.SOURCE)
128 public @interface DatabaseMode {}
129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 /**
131 * File creation mode: the default mode, where the created file can only
132 * be accessed by the calling application (or all applications sharing the
133 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 */
135 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700136
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700138 * File creation mode: allow all other applications to have read access to
139 * the created file.
140 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700141 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
142 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700143 *
Nick Kralevich15069212013-01-09 15:54:56 -0800144 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700145 * to cause security holes in applications. It is strongly
146 * discouraged; instead, applications should use more formal
147 * mechanism for interactions such as {@link ContentProvider},
148 * {@link BroadcastReceiver}, and {@link android.app.Service}.
149 * There are no guarantees that this access mode will remain on
150 * a file, such as when it goes through a backup and restore.
151 * @see android.support.v4.content.FileProvider
152 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700154 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700156
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700158 * File creation mode: allow all other applications to have write access to
159 * the created file.
160 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700161 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700162 * mode will throw a {@link SecurityException}.
163 *
Nick Kralevich15069212013-01-09 15:54:56 -0800164 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700165 * to cause security holes in applications. It is strongly
166 * discouraged; instead, applications should use more formal
167 * mechanism for interactions such as {@link ContentProvider},
168 * {@link BroadcastReceiver}, and {@link android.app.Service}.
169 * There are no guarantees that this access mode will remain on
170 * a file, such as when it goes through a backup and restore.
171 * @see android.support.v4.content.FileProvider
172 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700174 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 /**
178 * File creation mode: for use with {@link #openFileOutput}, if the file
179 * already exists then write data to the end of the existing file
180 * instead of erasing it.
181 * @see #openFileOutput
182 */
183 public static final int MODE_APPEND = 0x8000;
184
185 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800186 * SharedPreference loading flag: when set, the file on disk will
187 * be checked for modification even if the shared preferences
188 * instance is already loaded in this process. This behavior is
189 * sometimes desired in cases where the application has multiple
190 * processes, all writing to the same SharedPreferences file.
191 * Generally there are better forms of communication between
192 * processes, though.
193 *
194 * <p>This was the legacy (but undocumented) behavior in and
195 * before Gingerbread (Android 2.3) and this flag is implied when
kopriva219f7dc2018-10-09 13:42:28 -0700196 * targeting such releases. For applications targeting SDK
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800197 * versions <em>greater than</em> Android 2.3, this flag must be
198 * explicitly set if desired.
199 *
200 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700201 *
202 * @deprecated MODE_MULTI_PROCESS does not work reliably in
203 * some versions of Android, and furthermore does not provide any
204 * mechanism for reconciling concurrent modifications across
205 * processes. Applications should not attempt to use it. Instead,
206 * they should use an explicit cross-process data management
207 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800208 */
Christopher Tated5748b82015-05-08 18:14:01 -0700209 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800210 public static final int MODE_MULTI_PROCESS = 0x0004;
211
212 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700213 * Database open flag: when set, the database is opened with write-ahead
214 * logging enabled by default.
215 *
216 * @see #openOrCreateDatabase(String, int, CursorFactory)
217 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
218 * @see SQLiteDatabase#enableWriteAheadLogging
219 */
220 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
221
Sunny Goyala21e6b22015-12-02 09:51:02 -0800222 /**
223 * Database open flag: when set, the database is opened without support for
224 * localized collators.
225 *
226 * @see #openOrCreateDatabase(String, int, CursorFactory)
227 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
228 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
229 */
230 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
231
Tor Norbyed9273d62013-05-30 15:59:53 -0700232 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700233 @IntDef(flag = true, prefix = { "BIND_" }, value = {
234 BIND_AUTO_CREATE,
235 BIND_DEBUG_UNBIND,
236 BIND_NOT_FOREGROUND,
237 BIND_ABOVE_CLIENT,
238 BIND_ALLOW_OOM_MANAGEMENT,
239 BIND_WAIVE_PRIORITY,
240 BIND_IMPORTANT,
Amith Yamasani5016a782019-06-17 16:20:24 -0700241 BIND_ADJUST_WITH_ACTIVITY,
242 BIND_NOT_PERCEPTIBLE,
243 BIND_INCLUDE_CAPABILITIES
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700244 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700245 @Retention(RetentionPolicy.SOURCE)
246 public @interface BindServiceFlags {}
247
Jeff Brown47847f32012-03-22 19:13:11 -0700248 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 * Flag for {@link #bindService}: automatically create the service as long
250 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700251 * its {@link android.app.Service#onStartCommand}
252 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 * explicit call to {@link #startService}. Even without that, though,
254 * this still provides you with access to the service object while the
255 * service is created.
256 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700257 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
258 * not supplying this flag would also impact how important the system
259 * consider's the target service's process to be. When set, the only way
260 * for it to be raised was by binding from a service in which case it will
261 * only be important when that activity is in the foreground. Now to
262 * achieve this behavior you must explicitly supply the new flag
263 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
264 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
265 * the flags {@link #BIND_WAIVE_PRIORITY} and
266 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
267 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 */
269 public static final int BIND_AUTO_CREATE = 0x0001;
270
271 /**
272 * Flag for {@link #bindService}: include debugging help for mismatched
273 * calls to unbind. When this flag is set, the callstack of the following
274 * {@link #unbindService} call is retained, to be printed if a later
275 * incorrect unbind call is made. Note that doing this requires retaining
276 * information about the binding that was made for the lifetime of the app,
277 * resulting in a leak -- this should only be used for debugging.
278 */
279 public static final int BIND_DEBUG_UNBIND = 0x0002;
280
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800281 /**
282 * Flag for {@link #bindService}: don't allow this binding to raise
283 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700284 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800285 * as the client (so that its process will not be killable in any
286 * situation where the client is not killable), but for CPU scheduling
287 * purposes it may be left in the background. This only has an impact
288 * in the situation where the binding client is a foreground process
289 * and the target service is in a background process.
290 */
291 public static final int BIND_NOT_FOREGROUND = 0x0004;
292
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700293 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700294 * Flag for {@link #bindService}: indicates that the client application
295 * binding to this service considers the service to be more important than
296 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700297 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700298 * this is not guaranteed to be the case.
299 */
300 public static final int BIND_ABOVE_CLIENT = 0x0008;
301
302 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700303 * Flag for {@link #bindService}: allow the process hosting the bound
304 * service to go through its normal memory management. It will be
305 * treated more like a running service, allowing the system to
306 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700307 * whim it may have, and being more aggressive about making it a candidate
308 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700309 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700310 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
311
312 /**
313 * Flag for {@link #bindService}: don't impact the scheduling or
314 * memory management priority of the target service's hosting process.
315 * Allows the service's process to be managed on the background LRU list
316 * just like a regular application process in the background.
317 */
318 public static final int BIND_WAIVE_PRIORITY = 0x0020;
319
320 /**
321 * Flag for {@link #bindService}: this service is very important to
322 * the client, so should be brought to the foreground process level
323 * when the client is. Normally a process can only be raised to the
324 * visibility level by a client, even if that client is in the foreground.
325 */
326 public static final int BIND_IMPORTANT = 0x0040;
327
328 /**
329 * Flag for {@link #bindService}: If binding from an activity, allow the
330 * target service's process importance to be raised based on whether the
331 * activity is visible to the user, regardless whether another flag is
332 * used to reduce the amount that the client process's overall importance
333 * is used to impact it.
334 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700335 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
336
337 /**
Amith Yamasani5016a782019-06-17 16:20:24 -0700338 * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible,
339 * lower the target service's importance to below the perceptible level. This allows
340 * the system to (temporarily) expunge the bound process from memory to make room for more
341 * important user-perceptible processes.
342 */
343 public static final int BIND_NOT_PERCEPTIBLE = 0x00000100;
344
345 /**
Amith Yamasanif178c962019-03-21 19:40:11 -0700346 * Flag for {@link #bindService}: If binding from an app that has specific capabilities
347 * due to its foreground state such as an activity or foreground service, then this flag will
348 * allow the bound app to get the same capabilities, as long as it has the required permissions
349 * as well.
350 */
Amith Yamasani5016a782019-06-17 16:20:24 -0700351 public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000;
Amith Yamasanif178c962019-03-21 19:40:11 -0700352
Amith Yamasani0b3ae0e2019-05-10 10:29:47 -0700353 /*********** Public flags above this line ***********/
354 /*********** Hidden flags below this line ***********/
355
356 /**
Yohei Yukawa59730962019-03-18 10:47:22 -0700357 * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust
358 * the scheduling policy for IMEs (and any other out-of-process user-visible components that
359 * work closely with the top app) so that UI hosted in such services can have the same
360 * scheduling policy (e.g. SCHED_FIFO when it is enabled and TOP_APP_PRIORITY_BOOST otherwise)
361 * as the actual top-app.
362 * @hide
363 */
364 public static final int BIND_SCHEDULE_LIKE_TOP_APP = 0x00080000;
365
366 /**
Michal Karpinskie069b002019-03-07 16:15:14 +0000367 * Flag for {@link #bindService}: allow background activity starts from the bound service's
368 * process.
369 * This flag is only respected if the caller is holding
370 * {@link android.Manifest.permission#START_ACTIVITIES_FROM_BACKGROUND}.
371 * @hide
372 */
373 public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 0x00100000;
374
375 /**
Dianne Hackbornc390aa82019-01-09 16:38:22 -0800376 * @hide Flag for {@link #bindService}: the service being bound to represents a
377 * protected system component, so must have association restrictions applied to it.
378 * That is, a system config must have one or more allow-association tags limiting
379 * which packages it can interact with. If it does not have any such association
380 * restrictions, a default empty set will be created.
381 */
382 public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000;
383
384 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800385 * @hide Flag for {@link #bindService}: allows binding to a service provided
386 * by an instant app. Note that the caller may not have access to the instant
387 * app providing the service which is a violation of the instant app sandbox.
388 * This flag is intended ONLY for development/testing and should be used with
389 * great care. Only the system is allowed to use this flag.
390 */
391 public static final int BIND_ALLOW_INSTANT = 0x00400000;
392
393 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700394 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
395 * up in to the important background state (instead of transient).
396 */
397 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
398
399 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700400 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
401 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
402 */
403 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
404
405 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700406 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
407 * but only applies while the device is awake.
408 */
409 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
410
411 /**
412 * @hide Flag for {@link #bindService}: For only the case where the binding
413 * is coming from the system, set the process state to FOREGROUND_SERVICE
414 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
415 * saying that the process shouldn't participate in the normal power reduction
416 * modes (removing network access etc).
417 */
418 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
419
420 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700421 * @hide Flag for {@link #bindService}: Treat the binding as hosting
422 * an activity, an unbinding as the activity going in the background.
423 * That is, when unbinding, the process when empty will go on the activity
424 * LRU list instead of the regular one, keeping it around more aggressively
425 * than it otherwise would be. This is intended for use with IMEs to try
426 * to keep IME processes around for faster keyboard switching.
427 */
428 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
429
430 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700431 * @hide An idea that is not yet implemented.
432 * Flag for {@link #bindService}: If binding from an activity, consider
433 * this service to be visible like the binding activity is. That is,
434 * it will be treated as something more important to keep around than
435 * invisible background activities. This will impact the number of
436 * recent activities the user can switch between without having them
437 * restart. There is no guarantee this will be respected, as the system
Amith Yamasanif235d0b2019-03-20 22:49:43 -0700438 * tries to balance such requests from one app vs. the importance of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700439 * keeping other apps around.
440 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700441 public static final int BIND_VISIBLE = 0x10000000;
442
443 /**
444 * @hide
445 * Flag for {@link #bindService}: Consider this binding to be causing the target
446 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
447 * away.
448 */
449 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700450
451 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700452 * Flag for {@link #bindService}: Don't consider the bound service to be
453 * visible, even if the caller is visible.
454 * @hide
455 */
456 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700457
Alan Viverette713a5cd2015-12-16 15:46:32 -0500458 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500459 * Flag for {@link #bindService}: The service being bound is an
460 * {@link android.R.attr#isolatedProcess isolated},
461 * {@link android.R.attr#externalService external} service. This binds the service into the
462 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400463 * <p>
464 * When using this flag, the code for the service being bound will execute under the calling
465 * application's package name and user ID. Because the service must be an isolated process,
466 * it will not have direct access to the application's data, though.
467 *
468 * The purpose of this flag is to allow applications to provide services that are attributed
469 * to the app using the service, rather than the application providing the service.
470 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500471 */
472 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
473
Dianne Hackborna631d562018-11-20 15:58:15 -0800474 /**
475 * These bind flags reduce the strength of the binding such that we shouldn't
476 * consider it as pulling the process up to the level of the one that is bound to it.
477 * @hide
478 */
479 public static final int BIND_REDUCTION_FLAGS =
480 Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
Amith Yamasani5016a782019-06-17 16:20:24 -0700481 | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;
Dianne Hackborna631d562018-11-20 15:58:15 -0800482
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700483 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700484 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
485 RECEIVER_VISIBLE_TO_INSTANT_APPS
486 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700487 @Retention(RetentionPolicy.SOURCE)
488 public @interface RegisterReceiverFlags {}
489
490 /**
491 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
492 */
493 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
494
Robert Sesekb9a86662015-12-09 16:22:45 -0500495 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500496 * Returns an AssetManager instance for the application's package.
497 * <p>
498 * <strong>Note:</strong> Implementations of this method should return
499 * an AssetManager instance that is consistent with the Resources instance
500 * returned by {@link #getResources()}. For example, they should share the
501 * same {@link Configuration} object.
502 *
503 * @return an AssetManager instance for the application's package
504 * @see #getResources()
505 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 public abstract AssetManager getAssets();
507
Alan Viverette713a5cd2015-12-16 15:46:32 -0500508 /**
509 * Returns a Resources instance for the application's package.
510 * <p>
511 * <strong>Note:</strong> Implementations of this method should return
512 * a Resources instance that is consistent with the AssetManager instance
513 * returned by {@link #getAssets()}. For example, they should share the
514 * same {@link Configuration} object.
515 *
516 * @return a Resources instance for the application's package
517 * @see #getAssets()
518 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 public abstract Resources getResources();
520
521 /** Return PackageManager instance to find global package information. */
522 public abstract PackageManager getPackageManager();
523
524 /** Return a ContentResolver instance for your application's package. */
525 public abstract ContentResolver getContentResolver();
526
527 /**
528 * Return the Looper for the main thread of the current process. This is
529 * the thread used to dispatch calls to application components (activities,
530 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700531 * <p>
532 * By definition, this method returns the same result as would be obtained
533 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
534 * </p>
535 *
536 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800537 */
538 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700539
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700541 * Return an {@link Executor} that will run enqueued tasks on the main
542 * thread associated with this context. This is the thread used to dispatch
543 * calls to application components (activities, services, etc).
544 */
545 public Executor getMainExecutor() {
546 // This is pretty inefficient, which is why ContextImpl overrides it
547 return new HandlerExecutor(new Handler(getMainLooper()));
548 }
549
550 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800552 * current process. This generally should only be used if you need a
553 * Context whose lifecycle is separate from the current context, that is
554 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700555 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800556 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800557 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800558 * <ul>
559 * <li> <p>If used from an Activity context, the receiver is being registered
560 * within that activity. This means that you are expected to unregister
561 * before the activity is done being destroyed; in fact if you do not do
562 * so, the framework will clean up your leaked registration as it removes
563 * the activity and log an error. Thus, if you use the Activity context
564 * to register a receiver that is static (global to the process, not
565 * associated with an Activity instance) then that registration will be
566 * removed on you at whatever point the activity you used is destroyed.
567 * <li> <p>If used from the Context returned here, the receiver is being
568 * registered with the global state associated with your application. Thus
569 * it will never be unregistered for you. This is necessary if the receiver
570 * is associated with static data, not a particular component. However
571 * using the ApplicationContext elsewhere can easily lead to serious leaks
572 * if you forget to unregister, unbind, etc.
573 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800574 */
575 public abstract Context getApplicationContext();
576
Phil Weaver846cda932017-06-15 10:10:06 -0700577 /** Non-activity related autofill ids are unique in the app */
578 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700579
580 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700581 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700582 *
Phil Weaver846cda932017-06-15 10:10:06 -0700583 * <p>All IDs will be smaller or the same as {@link View#LAST_APP_AUTOFILL_ID}. All IDs
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700584 * returned will be unique.
585 *
586 * @return A ID that is unique in the process
587 *
588 * {@hide}
589 */
Phil Weaver846cda932017-06-15 10:10:06 -0700590 public int getNextAutofillId() {
591 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
592 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700593 }
594
Phil Weaver846cda932017-06-15 10:10:06 -0700595 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700596
Phil Weaver846cda932017-06-15 10:10:06 -0700597 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700598 }
599
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800600 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700601 * Add a new {@link ComponentCallbacks} to the base application of the
602 * Context, which will be called at the same times as the ComponentCallbacks
603 * methods of activities and other components are called. Note that you
604 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
605 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700606 *
607 * @param callback The interface to call. This can be either a
608 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700609 */
610 public void registerComponentCallbacks(ComponentCallbacks callback) {
611 getApplicationContext().registerComponentCallbacks(callback);
612 }
613
614 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400615 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700616 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
617 */
618 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
619 getApplicationContext().unregisterComponentCallbacks(callback);
620 }
621
622 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623 * Return a localized, styled CharSequence from the application's package's
624 * default string table.
625 *
626 * @param resId Resource id for the CharSequence text
627 */
Chris Craikceb26932018-02-01 15:51:34 -0800628 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700629 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 return getResources().getText(resId);
631 }
632
633 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700634 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800635 * default string table.
636 *
637 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700638 * @return The string data associated with the resource, stripped of styled
639 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700641 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700642 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 return getResources().getString(resId);
644 }
645
646 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700647 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800648 * default string table, substituting the format arguments as defined in
649 * {@link java.util.Formatter} and {@link java.lang.String#format}.
650 *
651 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700652 * @param formatArgs The format arguments that will be used for
653 * substitution.
654 * @return The string data associated with the resource, formatted and
655 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700657 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700658 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 return getResources().getString(resId, formatArgs);
660 }
661
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800662 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800663 * Returns a color associated with a particular resource ID and styled for
664 * the current theme.
665 *
666 * @param id The desired resource identifier, as generated by the aapt
667 * tool. This integer encodes the package, type, and resource
668 * entry. The value 0 is an invalid identifier.
669 * @return A single color value in the form 0xAARRGGBB.
670 * @throws android.content.res.Resources.NotFoundException if the given ID
671 * does not exist.
672 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700673 @ColorInt
674 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800675 return getResources().getColor(id, getTheme());
676 }
677
678 /**
679 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800680 * styled for the current theme.
681 *
682 * @param id The desired resource identifier, as generated by the aapt
683 * tool. This integer encodes the package, type, and resource
684 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800685 * @return An object that can be used to draw this resource.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800686 * @throws android.content.res.Resources.NotFoundException if the given ID
687 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800688 */
Chris Craik1194b0b2018-03-23 13:36:24 -0700689 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700690 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800691 return getResources().getDrawable(id, getTheme());
692 }
693
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800694 /**
695 * Returns a color state list associated with a particular resource ID and
696 * styled for the current theme.
697 *
698 * @param id The desired resource identifier, as generated by the aapt
699 * tool. This integer encodes the package, type, and resource
700 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800701 * @return A color state list.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800702 * @throws android.content.res.Resources.NotFoundException if the given ID
703 * does not exist.
704 */
Chris Craikceb26932018-02-01 15:51:34 -0800705 @NonNull
Tor Norbye3e4cda72015-06-10 08:14:31 -0700706 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800707 return getResources().getColorStateList(id, getTheme());
708 }
709
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 /**
711 * Set the base theme for this context. Note that this should be called
712 * before any views are instantiated in the Context (for example before
713 * calling {@link android.app.Activity#setContentView} or
714 * {@link android.view.LayoutInflater#inflate}).
715 *
716 * @param resid The style resource describing the theme.
717 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700718 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800719
Dianne Hackborn247fe742011-01-08 17:25:57 -0800720 /** @hide Needed for some internal implementation... not public because
721 * you can't assume this actually means anything. */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100722 @UnsupportedAppUsage
Dianne Hackborn247fe742011-01-08 17:25:57 -0800723 public int getThemeResId() {
724 return 0;
725 }
726
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800727 /**
728 * Return the Theme object associated with this Context.
729 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700730 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800731 public abstract Resources.Theme getTheme();
732
733 /**
734 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800735 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 * for more information.
737 *
Jeff Brown6e539312015-02-24 18:53:21 -0800738 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800739 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800740 @NonNull
741 public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800742 return getTheme().obtainStyledAttributes(attrs);
743 }
744
745 /**
746 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800747 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800748 * for more information.
749 *
Jeff Brown6e539312015-02-24 18:53:21 -0800750 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800752 @NonNull
753 public final TypedArray obtainStyledAttributes(@StyleRes int resid,
754 @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 return getTheme().obtainStyledAttributes(resid, attrs);
756 }
757
758 /**
759 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800760 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 * for more information.
762 *
Jeff Brown6e539312015-02-24 18:53:21 -0800763 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800764 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800765 @NonNull
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800766 public final TypedArray obtainStyledAttributes(
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800767 @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
769 }
770
771 /**
772 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800773 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 * for more information.
775 *
Jeff Brown6e539312015-02-24 18:53:21 -0800776 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 */
Aurimas Liutikas77acf4b2018-12-19 17:31:03 -0800778 @NonNull
779 public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set,
780 @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
Tor Norbyec91531a2015-04-01 17:41:55 -0700781 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800782 return getTheme().obtainStyledAttributes(
783 set, attrs, defStyleAttr, defStyleRes);
784 }
785
786 /**
787 * Return a class loader you can use to retrieve classes in this package.
788 */
789 public abstract ClassLoader getClassLoader();
790
791 /** Return the name of this application's package. */
792 public abstract String getPackageName();
793
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900794 /**
795 * @hide Return the name of the base context this context is derived from.
796 * This is the same as {@link #getOpPackageName()} except in
797 * cases where system components are loaded into other app processes, in which
798 * case {@link #getOpPackageName()} will be the name of the primary package in
799 * that process (so that app ops uid verification will work with the name).
800 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100801 @UnsupportedAppUsage
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800802 public abstract String getBasePackageName();
803
Jaewan Kim0980c7f2018-11-28 23:55:15 +0900804 /**
805 * Return the package name that should be used for {@link android.app.AppOpsManager} calls from
806 * this context, so that app ops manager's uid verification will work with the name.
807 * <p>
808 * This is not generally intended for third party application developers.
809 */
Adrian Roosebc927c2019-02-28 16:21:18 +0100810 @NonNull
Adrian Roosfe6aeaf2019-01-22 16:58:56 +0100811 public String getOpPackageName() {
812 throw new RuntimeException("Not implemented. Must override in a subclass.");
813 }
Dianne Hackborn95d78532013-09-11 09:51:14 -0700814
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700815 /** Return the full application info for this context's package. */
816 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700817
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800818 /**
Kenny Root32148392010-01-21 15:40:47 -0800819 * Return the full path to this context's primary Android package.
820 * The Android package is a ZIP file which contains the application's
821 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800822 *
823 * <p>Note: this is not generally useful for applications, since they should
824 * not be directly accessing the file system.
825 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826 * @return String Path to the resources.
827 */
828 public abstract String getPackageResourcePath();
829
830 /**
Kenny Root32148392010-01-21 15:40:47 -0800831 * Return the full path to this context's primary Android package.
832 * The Android package is a ZIP file which contains application's
833 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 *
835 * <p>Note: this is not generally useful for applications, since they should
836 * not be directly accessing the file system.
837 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 * @return String Path to the code and assets.
839 */
840 public abstract String getPackageCodePath();
841
842 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700843 * @hide
844 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700845 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700846 @Deprecated
Mathew Inwood5c0d3542018-08-14 13:54:31 +0100847 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700848 public File getSharedPrefsFile(String name) {
849 return getSharedPreferencesPath(name);
850 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700851
852 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 * Retrieve and hold the contents of the preferences file 'name', returning
854 * a SharedPreferences through which you can retrieve and modify its
855 * values. Only one instance of the SharedPreferences object is returned
856 * to any callers for the same name, meaning they will see each other's
857 * edits as soon as they are made.
858 *
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700859 * This method is thead-safe.
860 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800861 * @param name Desired preferences file. If a preferences file by this name
862 * does not exist, it will be created when you retrieve an
863 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600864 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400866 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800867 * to retrieve and modify the preference values.
868 *
869 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600871 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700872
873 /**
874 * Retrieve and hold the contents of the preferences file, returning
875 * a SharedPreferences through which you can retrieve and modify its
876 * values. Only one instance of the SharedPreferences object is returned
877 * to any callers for the same name, meaning they will see each other's
878 * edits as soon as they are made.
879 *
880 * @param file Desired preferences file. If a preferences file by this name
881 * does not exist, it will be created when you retrieve an
882 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600883 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700884 *
885 * @return The single {@link SharedPreferences} instance that can be used
886 * to retrieve and modify the preference values.
887 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700888 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700889 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600890 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700891 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600892 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893
894 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600895 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700896 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600897 * storage locations after an upgrade, such as moving to device protected
898 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700899 *
900 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600901 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700902 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600903 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700904 * preferences didn't exist in the source context, otherwise
905 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600906 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700907 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600908 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
909
Jeff Sharkey35871f22016-01-29 17:13:29 -0700910 /**
911 * Delete an existing shared preferences file.
912 *
913 * @param name The name (unique in the application package) of the shared
914 * preferences file.
915 * @return {@code true} if the shared preferences file was successfully
916 * deleted; else {@code false}.
917 * @see #getSharedPreferences(String, int)
918 */
919 public abstract boolean deleteSharedPreferences(String name);
920
Christopher Tatefe2368c2017-05-17 15:42:35 -0700921 /** @hide */
922 public abstract void reloadSharedPreferences();
923
Jeff Sharkey35871f22016-01-29 17:13:29 -0700924 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800925 * Open a private file associated with this Context's application package
926 * for reading.
927 *
928 * @param name The name of the file to open; can not contain path
929 * separators.
930 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400931 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932 *
933 * @see #openFileOutput
934 * @see #fileList
935 * @see #deleteFile
936 * @see java.io.FileInputStream#FileInputStream(String)
937 */
938 public abstract FileInputStream openFileInput(String name)
939 throws FileNotFoundException;
940
941 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800942 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700943 * for writing. Creates the file if it doesn't already exist.
944 * <p>
945 * No additional permissions are required for the calling app to read or
946 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700947 *
Nick Kralevich15069212013-01-09 15:54:56 -0800948 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700949 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600950 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400951 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800952 * @see #MODE_APPEND
953 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800954 * @see #openFileInput
955 * @see #fileList
956 * @see #deleteFile
957 * @see java.io.FileOutputStream#FileOutputStream(String)
958 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600959 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800960 throws FileNotFoundException;
961
962 /**
963 * Delete the given private file associated with this Context's
964 * application package.
965 *
966 * @param name The name of the file to delete; can not contain path
967 * separators.
968 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400969 * @return {@code true} if the file was successfully deleted; else
970 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800971 *
972 * @see #openFileInput
973 * @see #openFileOutput
974 * @see #fileList
975 * @see java.io.File#delete()
976 */
977 public abstract boolean deleteFile(String name);
978
979 /**
980 * Returns the absolute path on the filesystem where a file created with
981 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700982 * <p>
983 * The returned path may change over time if the calling app is moved to an
984 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800985 *
986 * @param name The name of the file for which you would like to get
987 * its path.
988 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400989 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800990 *
991 * @see #openFileOutput
992 * @see #getFilesDir
993 * @see #getDir
994 */
995 public abstract File getFileStreamPath(String name);
996
997 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700998 * Returns the absolute path on the filesystem where a file created with
999 * {@link #getSharedPreferences(String, int)} is stored.
1000 * <p>
1001 * The returned path may change over time if the calling app is moved to an
1002 * adopted storage device, so only relative paths should be persisted.
1003 *
1004 * @param name The name of the shared preferences for which you would like
1005 * to get a path.
1006 * @return An absolute path to the given file.
1007 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001008 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -07001009 */
1010 public abstract File getSharedPreferencesPath(String name);
1011
1012 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001013 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001014 * private files belonging to this app are stored. Apps should not use this
1015 * path directly; they should instead use {@link #getFilesDir()},
1016 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1017 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001018 * <p>
1019 * The returned path may change over time if the calling app is moved to an
1020 * adopted storage device, so only relative paths should be persisted.
1021 * <p>
1022 * No additional permissions are required for the calling app to read or
1023 * write files under the returned path.
1024 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06001025 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -07001026 */
1027 public abstract File getDataDir();
1028
1029 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001030 * Returns the absolute path to the directory on the filesystem where files
1031 * created with {@link #openFileOutput} are stored.
1032 * <p>
1033 * The returned path may change over time if the calling app is moved to an
1034 * adopted storage device, so only relative paths should be persisted.
1035 * <p>
1036 * No additional permissions are required for the calling app to read or
1037 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -07001038 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001039 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 * @see #openFileOutput
1041 * @see #getFileStreamPath
1042 * @see #getDir
1043 */
1044 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -07001045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 /**
Christopher Tatea7835b62014-07-11 17:25:57 -07001047 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001048 * {@link #getFilesDir()}. The difference is that files placed under this
1049 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -07001050 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1051 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001052 * <p>
1053 * The returned path may change over time if the calling app is moved to an
1054 * adopted storage device, so only relative paths should be persisted.
1055 * <p>
1056 * No additional permissions are required for the calling app to read or
1057 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -07001058 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001059 * @return The path of the directory holding application files that will not
1060 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -07001061 * @see #openFileOutput
1062 * @see #getFileStreamPath
1063 * @see #getDir
1064 * @see android.app.backup.BackupAgent
1065 */
1066 public abstract File getNoBackupFilesDir();
1067
1068 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001069 * Returns the absolute path to the directory on the primary shared/external
1070 * storage device where the application can place persistent files it owns.
1071 * These files are internal to the applications, and not typically visible
1072 * to the user as media.
1073 * <p>
1074 * This is like {@link #getFilesDir()} in that these files will be deleted
1075 * when the application is uninstalled, however there are some important
1076 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001077 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001078 * <li>Shared storage may not always be available, since removable media can
1079 * be ejected by the user. Media state can be checked using
1080 * {@link Environment#getExternalStorageState(File)}.
1081 * <li>There is no security enforced with these files. For example, any
1082 * application holding
1083 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001084 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001085 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001086 * <p>
1087 * If a shared storage device is emulated (as determined by
1088 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1089 * backed by a private user data partition, which means there is little
1090 * benefit to storing data here instead of the private directories returned
1091 * by {@link #getFilesDir()}, etc.
1092 * <p>
1093 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001094 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001095 * accessible to the calling app. This only applies to paths generated for
1096 * package name of the calling application. To access paths belonging to
1097 * other packages,
1098 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1099 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1100 * <p>
1101 * On devices with multiple users (as described by {@link UserManager}),
1102 * each user has their own isolated shared storage. Applications only have
1103 * access to the shared storage for the user they're running as.
1104 * <p>
1105 * The returned path may change over time if different shared storage media
1106 * is inserted, so only relative paths should be persisted.
1107 * <p>
1108 * Here is an example of typical code to manipulate a file in an
1109 * application's shared storage:
1110 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001111 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1112 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001113 * <p>
1114 * If you supply a non-null <var>type</var> to this function, the returned
1115 * file will be a path to a sub-directory of the given type. Though these
1116 * files are not automatically scanned by the media scanner, you can
1117 * explicitly add them to the media database with
1118 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1119 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001120 * {@link android.os.Environment#getExternalStoragePublicDirectory
1121 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001122 * directories of media shared by all applications. The directories returned
1123 * here are owned by the application, and their contents will be removed
1124 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001125 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001126 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1127 * here will be automatically created for you.
1128 * <p>
1129 * Here is an example of typical code to manipulate a picture in an
1130 * application's shared storage and add it to the media database:
1131 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001132 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1133 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001134 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001135 * @param type The type of files directory to return. May be {@code null}
1136 * for the root of the files directory or one of the following
1137 * constants for a subdirectory:
1138 * {@link android.os.Environment#DIRECTORY_MUSIC},
1139 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1140 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1141 * {@link android.os.Environment#DIRECTORY_ALARMS},
1142 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1143 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1144 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1145 * @return the absolute path to application-specific directory. May return
1146 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001147 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001148 * @see #getExternalFilesDirs(String)
1149 * @see Environment#getExternalStorageState(File)
1150 * @see Environment#isExternalStorageEmulated(File)
1151 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001152 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001153 @Nullable
1154 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001155
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001156 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001157 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001158 * shared/external storage devices where the application can place
1159 * persistent files it owns. These files are internal to the application,
1160 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001161 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001162 * This is like {@link #getFilesDir()} in that these files will be deleted
1163 * when the application is uninstalled, however there are some important
1164 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001165 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001166 * <li>Shared storage may not always be available, since removable media can
1167 * be ejected by the user. Media state can be checked using
1168 * {@link Environment#getExternalStorageState(File)}.
1169 * <li>There is no security enforced with these files. For example, any
1170 * application holding
1171 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1172 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001173 * </ul>
1174 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001175 * If a shared storage device is emulated (as determined by
1176 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1177 * backed by a private user data partition, which means there is little
1178 * benefit to storing data here instead of the private directories returned
1179 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001180 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001181 * Shared storage devices returned here are considered a stable part of the
1182 * device, including physical media slots under a protective cover. The
1183 * returned paths do not include transient devices, such as USB flash drives
1184 * connected to handheld devices.
1185 * <p>
1186 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001187 * example, an app may choose to store large files on the device with the
1188 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001189 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001190 * No additional permissions are required for the calling app to read or
1191 * write files under the returned path. Write access outside of these paths
1192 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001193 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001194 * The returned path may change over time if different shared storage media
1195 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001196 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001197 * @param type The type of files directory to return. May be {@code null}
1198 * for the root of the files directory or one of the following
1199 * constants for a subdirectory:
1200 * {@link android.os.Environment#DIRECTORY_MUSIC},
1201 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1202 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1203 * {@link android.os.Environment#DIRECTORY_ALARMS},
1204 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1205 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1206 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1207 * @return the absolute paths to application-specific directories. Some
1208 * individual paths may be {@code null} if that shared storage is
1209 * not currently available. The first path returned is the same as
1210 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001211 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001212 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001213 * @see Environment#isExternalStorageEmulated(File)
1214 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001215 */
1216 public abstract File[] getExternalFilesDirs(String type);
1217
1218 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001219 * Return the primary shared/external storage directory where this
1220 * application's OBB files (if there are any) can be found. Note if the
1221 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001222 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001223 * This is like {@link #getFilesDir()} in that these files will be deleted
1224 * when the application is uninstalled, however there are some important
1225 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001226 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001227 * <li>Shared storage may not always be available, since removable media can
1228 * be ejected by the user. Media state can be checked using
1229 * {@link Environment#getExternalStorageState(File)}.
1230 * <li>There is no security enforced with these files. For example, any
1231 * application holding
1232 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001233 * these files.
1234 * </ul>
1235 * <p>
1236 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001237 * are required to read or write to the path that this method returns.
1238 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1239 * to read the OBB expansion files, you must declare the
1240 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1241 * permission at runtime as follows:
1242 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001243 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001244 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1245 * android:maxSdkVersion="23" />}
1246 * </p>
1247 * <p>
1248 * Starting from {@link android.os.Build.VERSION_CODES#N},
1249 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1250 * permission is not required, so don’t ask for this
1251 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1252 * and if it fails, you must request
1253 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1254 * </p>
1255 *
1256 * <p>
1257 * The following code snippet shows how to do this:
1258 * </p>
1259 *
1260 * <pre>
1261 * File obb = new File(obb_filename);
1262 * boolean open_failed = false;
1263 *
1264 * try {
1265 * BufferedReader br = new BufferedReader(new FileReader(obb));
1266 * open_failed = false;
1267 * ReadObbFile(br);
1268 * } catch (IOException e) {
1269 * open_failed = true;
1270 * }
1271 *
1272 * if (open_failed) {
1273 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1274 * ReadObbFileWithPermission();
1275 * }
1276 * </pre>
1277 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001278 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001279 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001280 * should ensure that multiple instances running under different users don't
1281 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001282 *
1283 * @return the absolute path to application-specific directory. May return
1284 * {@code null} if shared storage is not currently available.
1285 * @see #getObbDirs()
1286 * @see Environment#getExternalStorageState(File)
1287 * @see Environment#isExternalStorageEmulated(File)
1288 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001289 */
1290 public abstract File getObbDir();
1291
1292 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001293 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001294 * shared/external storage devices where the application's OBB files (if
1295 * there are any) can be found. Note if the application does not have any
1296 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001297 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001298 * This is like {@link #getFilesDir()} in that these files will be deleted
1299 * when the application is uninstalled, however there are some important
1300 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001301 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001302 * <li>Shared storage may not always be available, since removable media can
1303 * be ejected by the user. Media state can be checked using
1304 * {@link Environment#getExternalStorageState(File)}.
1305 * <li>There is no security enforced with these files. For example, any
1306 * application holding
1307 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1308 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001309 * </ul>
1310 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001311 * Shared storage devices returned here are considered a stable part of the
1312 * device, including physical media slots under a protective cover. The
1313 * returned paths do not include transient devices, such as USB flash drives
1314 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001315 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001316 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001317 * example, an app may choose to store large files on the device with the
1318 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001319 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001320 * No additional permissions are required for the calling app to read or
1321 * write files under the returned path. Write access outside of these paths
1322 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001323 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001324 * @return the absolute paths to application-specific directories. Some
1325 * individual paths may be {@code null} if that shared storage is
1326 * not currently available. The first path returned is the same as
1327 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001328 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001329 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001330 * @see Environment#isExternalStorageEmulated(File)
1331 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001332 */
1333 public abstract File[] getObbDirs();
1334
1335 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001336 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001337 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001338 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001339 * The system will automatically delete files in this directory as disk
1340 * space is needed elsewhere on the device. The system will always delete
1341 * older files first, as reported by {@link File#lastModified()}. If
1342 * desired, you can exert more control over how files are deleted using
1343 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1344 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1345 * <p>
1346 * Apps are strongly encouraged to keep their usage of cache space below the
1347 * quota returned by
1348 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1349 * goes above this quota, your cached files will be some of the first to be
1350 * deleted when additional disk space is needed. Conversely, if your app
1351 * stays under this quota, your cached files will be some of the last to be
1352 * deleted when additional disk space is needed.
1353 * <p>
1354 * Note that your cache quota will change over time depending on how
1355 * frequently the user interacts with your app, and depending on how much
1356 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001357 * <p>
1358 * The returned path may change over time if the calling app is moved to an
1359 * adopted storage device, so only relative paths should be persisted.
1360 * <p>
1361 * Apps require no extra permissions to read or write to the returned path,
1362 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001363 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001364 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001365 * @see #openFileOutput
1366 * @see #getFileStreamPath
1367 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001368 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001369 */
1370 public abstract File getCacheDir();
1371
1372 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001373 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001374 * the filesystem designed for storing cached code.
1375 * <p>
1376 * The system will delete any files stored in this location both when your
1377 * specific application is upgraded, and when the entire platform is
1378 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001379 * <p>
1380 * This location is optimal for storing compiled or optimized code generated
1381 * by your application at runtime.
1382 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001383 * The returned path may change over time if the calling app is moved to an
1384 * adopted storage device, so only relative paths should be persisted.
1385 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001386 * Apps require no extra permissions to read or write to the returned path,
1387 * since this path lives in their private storage.
1388 *
1389 * @return The path of the directory holding application code cache files.
1390 */
1391 public abstract File getCodeCacheDir();
1392
1393 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001394 * Returns absolute path to application-specific directory on the primary
1395 * shared/external storage device where the application can place cache
1396 * files it owns. These files are internal to the application, and not
1397 * typically visible to the user as media.
1398 * <p>
1399 * This is like {@link #getCacheDir()} in that these files will be deleted
1400 * when the application is uninstalled, however there are some important
1401 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001402 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001403 * <li>The platform does not always monitor the space available in shared
1404 * storage, and thus may not automatically delete these files. Apps should
1405 * always manage the maximum space used in this location. Currently the only
1406 * time files here will be deleted by the platform is when running on
1407 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1408 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1409 * <li>Shared storage may not always be available, since removable media can
1410 * be ejected by the user. Media state can be checked using
1411 * {@link Environment#getExternalStorageState(File)}.
1412 * <li>There is no security enforced with these files. For example, any
1413 * application holding
1414 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001415 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001416 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001417 * <p>
1418 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001419 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001420 * backed by a private user data partition, which means there is little
1421 * benefit to storing data here instead of the private directory returned by
1422 * {@link #getCacheDir()}.
1423 * <p>
1424 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001425 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001426 * accessible to the calling app. This only applies to paths generated for
1427 * package name of the calling application. To access paths belonging to
1428 * other packages,
1429 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1430 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1431 * <p>
1432 * On devices with multiple users (as described by {@link UserManager}),
1433 * each user has their own isolated shared storage. Applications only have
1434 * access to the shared storage for the user they're running as.
1435 * <p>
1436 * The returned path may change over time if different shared storage media
1437 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001438 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001439 * @return the absolute path to application-specific directory. May return
1440 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001441 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001442 * @see #getExternalCacheDirs()
1443 * @see Environment#getExternalStorageState(File)
1444 * @see Environment#isExternalStorageEmulated(File)
1445 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001446 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001447 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001448 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001449
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001450 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001451 * Returns absolute path to application-specific directory in the preloaded cache.
1452 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1453 * There is no guarantee when these files will be deleted.
1454 * @hide
1455 */
1456 @Nullable
1457 @SystemApi
1458 public abstract File getPreloadsFileCache();
1459
1460 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001461 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001462 * shared/external storage devices where the application can place cache
1463 * files it owns. These files are internal to the application, and not
1464 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001465 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001466 * This is like {@link #getCacheDir()} in that these files will be deleted
1467 * when the application is uninstalled, however there are some important
1468 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001469 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001470 * <li>The platform does not always monitor the space available in shared
1471 * storage, and thus may not automatically delete these files. Apps should
1472 * always manage the maximum space used in this location. Currently the only
1473 * time files here will be deleted by the platform is when running on
1474 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1475 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1476 * <li>Shared storage may not always be available, since removable media can
1477 * be ejected by the user. Media state can be checked using
1478 * {@link Environment#getExternalStorageState(File)}.
1479 * <li>There is no security enforced with these files. For example, any
1480 * application holding
1481 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1482 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001483 * </ul>
1484 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001485 * If a shared storage device is emulated (as determined by
1486 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1487 * backed by a private user data partition, which means there is little
1488 * benefit to storing data here instead of the private directory returned by
1489 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001490 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001491 * Shared storage devices returned here are considered a stable part of the
1492 * device, including physical media slots under a protective cover. The
1493 * returned paths do not include transient devices, such as USB flash drives
1494 * connected to handheld devices.
1495 * <p>
1496 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001497 * example, an app may choose to store large files on the device with the
1498 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001499 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001500 * No additional permissions are required for the calling app to read or
1501 * write files under the returned path. Write access outside of these paths
1502 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001503 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001504 * The returned paths may change over time if different shared storage media
1505 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001506 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001507 * @return the absolute paths to application-specific directories. Some
1508 * individual paths may be {@code null} if that shared storage is
1509 * not currently available. The first path returned is the same as
1510 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001511 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001512 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001513 * @see Environment#isExternalStorageEmulated(File)
1514 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001515 */
1516 public abstract File[] getExternalCacheDirs();
1517
1518 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001519 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001520 * shared/external storage devices where the application can place media
1521 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001522 * {@link MediaStore}.
1523 * <p>
1524 * This is like {@link #getExternalFilesDirs} in that these files will be
1525 * deleted when the application is uninstalled, however there are some
1526 * important differences:
1527 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001528 * <li>Shared storage may not always be available, since removable media can
1529 * be ejected by the user. Media state can be checked using
1530 * {@link Environment#getExternalStorageState(File)}.
1531 * <li>There is no security enforced with these files. For example, any
1532 * application holding
1533 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1534 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001535 * </ul>
1536 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001537 * Shared storage devices returned here are considered a stable part of the
1538 * device, including physical media slots under a protective cover. The
1539 * returned paths do not include transient devices, such as USB flash drives
1540 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001541 * <p>
1542 * An application may store data on any or all of the returned devices. For
1543 * example, an app may choose to store large files on the device with the
1544 * most available space, as measured by {@link StatFs}.
1545 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001546 * No additional permissions are required for the calling app to read or
1547 * write files under the returned path. Write access outside of these paths
1548 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001549 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001550 * The returned paths may change over time if different shared storage media
1551 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001552 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001553 * @return the absolute paths to application-specific directories. Some
1554 * individual paths may be {@code null} if that shared storage is
1555 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001556 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001557 * @see Environment#isExternalStorageEmulated(File)
1558 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001559 */
1560 public abstract File[] getExternalMediaDirs();
1561
1562 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001563 * Returns an array of strings naming the private files associated with
1564 * this Context's application package.
1565 *
1566 * @return Array of strings naming the private files.
1567 *
1568 * @see #openFileInput
1569 * @see #openFileOutput
1570 * @see #deleteFile
1571 */
1572 public abstract String[] fileList();
1573
1574 /**
1575 * Retrieve, creating if needed, a new directory in which the application
1576 * can place its own custom data files. You can use the returned File
1577 * object to create and access files in this directory. Note that files
1578 * created through a File object will only be accessible by your own
1579 * application; you can only set the mode of the entire directory, not
1580 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001581 * <p>
1582 * The returned path may change over time if the calling app is moved to an
1583 * adopted storage device, so only relative paths should be persisted.
1584 * <p>
1585 * Apps require no extra permissions to read or write to the returned path,
1586 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001588 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001589 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001590 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001591 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001592 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001593 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 *
1595 * @see #openFileOutput(String, int)
1596 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001597 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598
1599 /**
1600 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001601 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 *
1603 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001604 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001606 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001607 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001608 * @throws android.database.sqlite.SQLiteException if the database file
1609 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001611 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001612 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 * @see #deleteDatabase
1614 */
1615 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001616 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617
1618 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001619 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001620 * application package. Creates the database file if it doesn't exist.
1621 * <p>
1622 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1623 * to be used to handle corruption when sqlite reports database corruption.
1624 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001625 *
1626 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001627 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001628 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001629 * cursor when query is called.
1630 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1631 * sqlite reports database corruption. if null,
1632 * {@link android.database.DefaultDatabaseErrorHandler} is
1633 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001634 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001635 * @throws android.database.sqlite.SQLiteException if the database file
1636 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001637 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001638 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001639 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001640 * @see #deleteDatabase
1641 */
1642 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001643 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001644 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001645
1646 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001647 * Move an existing database file from the given source storage context to
1648 * this context. This is typically used to migrate data between storage
1649 * locations after an upgrade, such as migrating to device protected
1650 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001651 * <p>
1652 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001653 *
1654 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001655 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001656 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001657 * @return {@code true} if the move was successful or if the database didn't
1658 * exist in the source context, otherwise {@code false}.
1659 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001660 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001661 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1662
Jeff Sharkey35871f22016-01-29 17:13:29 -07001663 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001664 * Delete an existing private SQLiteDatabase associated with this Context's
1665 * application package.
1666 *
1667 * @param name The name (unique in the application package) of the
1668 * database.
1669 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001670 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 *
1672 * @see #openOrCreateDatabase
1673 */
1674 public abstract boolean deleteDatabase(String name);
1675
1676 /**
1677 * Returns the absolute path on the filesystem where a database created with
1678 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001679 * <p>
1680 * The returned path may change over time if the calling app is moved to an
1681 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001682 *
1683 * @param name The name of the database for which you would like to get
1684 * its path.
1685 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001686 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 *
1688 * @see #openOrCreateDatabase
1689 */
1690 public abstract File getDatabasePath(String name);
1691
1692 /**
1693 * Returns an array of strings naming the private databases associated with
1694 * this Context's application package.
1695 *
1696 * @return Array of strings naming the private databases.
1697 *
1698 * @see #openOrCreateDatabase
1699 * @see #deleteDatabase
1700 */
1701 public abstract String[] databaseList();
1702
1703 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001704 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001705 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001706 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001707 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 public abstract Drawable getWallpaper();
1709
1710 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001711 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001712 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001713 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001714 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001715 public abstract Drawable peekWallpaper();
1716
1717 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001718 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1719 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001721 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 public abstract int getWallpaperDesiredMinimumWidth();
1723
1724 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001725 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1726 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001727 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001728 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001729 public abstract int getWallpaperDesiredMinimumHeight();
1730
1731 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001732 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001733 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001734 * <p>This method requires the caller to hold the permission
1735 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001737 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1739
1740 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001741 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001742 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001743 * <p>This method requires the caller to hold the permission
1744 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001745 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001746 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001747 public abstract void setWallpaper(InputStream data) throws IOException;
1748
1749 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001750 * @deprecated Use {@link android.app.WallpaperManager#clear
1751 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001752 * <p>This method requires the caller to hold the permission
1753 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001755 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 public abstract void clearWallpaper() throws IOException;
1757
1758 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001759 * Same as {@link #startActivity(Intent, Bundle)} with no options
1760 * specified.
1761 *
1762 * @param intent The description of the activity to start.
1763 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001764 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001765 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001766 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001767 * @see PackageManager#resolveActivity
1768 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001769 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001770
1771 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001772 * Version of {@link #startActivity(Intent)} that allows you to specify the
1773 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001774 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001775 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001776 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001777 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001778 * @hide
1779 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001780 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Philip P. Moltmann4e615e62018-08-28 14:57:49 -07001781 @SystemApi
Adrian Roosebc927c2019-02-28 16:21:18 +01001782 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1783 @NonNull UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001784 throw new RuntimeException("Not implemented. Must override in a subclass.");
1785 }
1786
1787 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 * Launch a new activity. You will not receive any information about when
1789 * the activity exits.
1790 *
1791 * <p>Note that if this method is being called from outside of an
1792 * {@link android.app.Activity} Context, then the Intent must include
1793 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1794 * without being started from an existing Activity, there is no existing
1795 * task in which to place the new activity and thus it needs to be placed
1796 * in its own separate task.
1797 *
1798 * <p>This method throws {@link ActivityNotFoundException}
1799 * if there was no Activity found to run the given Intent.
1800 *
1801 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001802 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001803 * May be null if there are no options. See {@link android.app.ActivityOptions}
1804 * for how to build the Bundle supplied here; there are no supported definitions
1805 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001807 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 *
Scott Main60dd5202012-06-23 00:01:22 -07001809 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 * @see PackageManager#resolveActivity
1811 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001812 public abstract void startActivity(@RequiresPermission Intent intent,
1813 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001814
1815 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001816 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1817 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001818 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001819 * @param intent The description of the activity to start.
1820 * @param options Additional options for how the Activity should be started.
1821 * May be null if there are no options. See {@link android.app.ActivityOptions}
1822 * for how to build the Bundle supplied here; there are no supported definitions
1823 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001824 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001825 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001826 * @hide
1827 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001828 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001829 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001830 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1831 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001832 throw new RuntimeException("Not implemented. Must override in a subclass.");
1833 }
1834
1835 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001836 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1837 * is only supported for Views and Fragments.
1838 * @param who The identifier for the calling element that will receive the result.
1839 * @param intent The intent to start.
1840 * @param requestCode The code that will be returned with onActivityResult() identifying this
1841 * request.
1842 * @param options Additional options for how the Activity should be started.
1843 * May be null if there are no options. See {@link android.app.ActivityOptions}
1844 * for how to build the Bundle supplied here; there are no supported definitions
1845 * for building it manually.
1846 * @hide
1847 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001848 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001849 public void startActivityForResult(
1850 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1851 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1852 + "Check canStartActivityForResult() before calling.");
1853 }
1854
1855 /**
1856 * Identifies whether this Context instance will be able to process calls to
1857 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1858 * @hide
1859 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01001860 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001861 public boolean canStartActivityForResult() {
1862 return false;
1863 }
1864
1865 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001866 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1867 * specified.
1868 *
1869 * @param intents An array of Intents to be started.
1870 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001871 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001872 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001873 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001874 * @see PackageManager#resolveActivity
1875 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001876 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877
1878 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001879 * Launch multiple new activities. This is generally the same as calling
1880 * {@link #startActivity(Intent)} for the first Intent in the array,
1881 * that activity during its creation calling {@link #startActivity(Intent)}
1882 * for the second entry, etc. Note that unlike that approach, generally
1883 * none of the activities except the last in the array will be created
1884 * at this point, but rather will be created when the user first visits
1885 * them (due to pressing back from the activity on top).
1886 *
1887 * <p>This method throws {@link ActivityNotFoundException}
1888 * if there was no Activity found for <em>any</em> given Intent. In this
1889 * case the state of the activity stack is undefined (some Intents in the
1890 * list may be on it, some not), so you probably want to avoid such situations.
1891 *
1892 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001893 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001894 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001895 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001896 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001897 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001898 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001899 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001900 * @see PackageManager#resolveActivity
1901 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001902 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001903
1904 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001905 * @hide
1906 * Launch multiple new activities. This is generally the same as calling
1907 * {@link #startActivity(Intent)} for the first Intent in the array,
1908 * that activity during its creation calling {@link #startActivity(Intent)}
1909 * for the second entry, etc. Note that unlike that approach, generally
1910 * none of the activities except the last in the array will be created
1911 * at this point, but rather will be created when the user first visits
1912 * them (due to pressing back from the activity on top).
1913 *
1914 * <p>This method throws {@link ActivityNotFoundException}
1915 * if there was no Activity found for <em>any</em> given Intent. In this
1916 * case the state of the activity stack is undefined (some Intents in the
1917 * list may be on it, some not), so you probably want to avoid such situations.
1918 *
1919 * @param intents An array of Intents to be started.
1920 * @param options Additional options for how the Activity should be started.
1921 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001922 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001923 * Context.startActivity(Intent, Bundle)} for more details.
1924 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001925 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1926 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1927 * successful.
1928 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001929 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001930 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001931 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001932 * @see PackageManager#resolveActivity
1933 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001934 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001935 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001936 throw new RuntimeException("Not implemented. Must override in a subclass.");
1937 }
1938
1939 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001940 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1941 * with no options specified.
1942 *
1943 * @param intent The IntentSender to launch.
1944 * @param fillInIntent If non-null, this will be provided as the
1945 * intent parameter to {@link IntentSender#sendIntent}.
1946 * @param flagsMask Intent flags in the original IntentSender that you
1947 * would like to change.
1948 * @param flagsValues Desired values for any bits set in
1949 * <var>flagsMask</var>
1950 * @param extraFlags Always set to 0.
1951 *
1952 * @see #startActivity(Intent)
1953 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1954 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001955 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1956 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1957 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001958
1959 /**
1960 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001961 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001962 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001963 * here; otherwise, its associated action will be executed (such as
1964 * sending a broadcast) as if you had called
1965 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001966 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001967 * @param intent The IntentSender to launch.
1968 * @param fillInIntent If non-null, this will be provided as the
1969 * intent parameter to {@link IntentSender#sendIntent}.
1970 * @param flagsMask Intent flags in the original IntentSender that you
1971 * would like to change.
1972 * @param flagsValues Desired values for any bits set in
1973 * <var>flagsMask</var>
1974 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001975 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001976 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001977 * Context.startActivity(Intent, Bundle)} for more details. If options
1978 * have also been supplied by the IntentSender, options given here will
1979 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001980 *
1981 * @see #startActivity(Intent, Bundle)
1982 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001983 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001984 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1985 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1986 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001987
1988 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 * Broadcast the given intent to all interested BroadcastReceivers. This
1990 * call is asynchronous; it returns immediately, and you will continue
1991 * executing while the receivers are run. No results are propagated from
1992 * receivers and receivers can not abort the broadcast. If you want
1993 * to allow receivers to propagate results or abort the broadcast, you must
1994 * send an ordered broadcast using
1995 * {@link #sendOrderedBroadcast(Intent, String)}.
1996 *
1997 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1998 *
1999 * @param intent The Intent to broadcast; all receivers matching this
2000 * Intent will receive the broadcast.
2001 *
2002 * @see android.content.BroadcastReceiver
2003 * @see #registerReceiver
2004 * @see #sendBroadcast(Intent, String)
2005 * @see #sendOrderedBroadcast(Intent, String)
2006 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2007 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002008 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002009
2010 /**
2011 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2012 * an optional required permission to be enforced. This
2013 * call is asynchronous; it returns immediately, and you will continue
2014 * executing while the receivers are run. No results are propagated from
2015 * receivers and receivers can not abort the broadcast. If you want
2016 * to allow receivers to propagate results or abort the broadcast, you must
2017 * send an ordered broadcast using
2018 * {@link #sendOrderedBroadcast(Intent, String)}.
2019 *
2020 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2021 *
2022 * @param intent The Intent to broadcast; all receivers matching this
2023 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08002024 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 * a receiver must hold in order to receive your broadcast.
2026 * If null, no permission is required.
2027 *
2028 * @see android.content.BroadcastReceiver
2029 * @see #registerReceiver
2030 * @see #sendBroadcast(Intent)
2031 * @see #sendOrderedBroadcast(Intent, String)
2032 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2033 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002034 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002035 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002036
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07002037
2038 /**
2039 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2040 * an array of required permissions to be enforced. This call is asynchronous; it returns
2041 * immediately, and you will continue executing while the receivers are run. No results are
2042 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2043 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2044 * using {@link #sendOrderedBroadcast(Intent, String)}.
2045 *
2046 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2047 *
2048 * @param intent The Intent to broadcast; all receivers matching this
2049 * Intent will receive the broadcast.
2050 * @param receiverPermissions Array of names of permissions that a receiver must hold
2051 * in order to receive your broadcast.
2052 * If null or empty, no permissions are required.
2053 *
2054 * @see android.content.BroadcastReceiver
2055 * @see #registerReceiver
2056 * @see #sendBroadcast(Intent)
2057 * @see #sendOrderedBroadcast(Intent, String)
2058 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2059 * @hide
2060 */
2061 public abstract void sendBroadcastMultiplePermissions(Intent intent,
2062 String[] receiverPermissions);
2063
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002064 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002065 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07002066 * an array of required permissions to be enforced. This call is asynchronous; it returns
2067 * immediately, and you will continue executing while the receivers are run. No results are
2068 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2069 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2070 * using {@link #sendOrderedBroadcast(Intent, String)}.
2071 *
2072 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2073 *
2074 * @param intent The Intent to broadcast; all receivers matching this
2075 * Intent will receive the broadcast.
2076 * @param user The user to send the broadcast to.
2077 * @param receiverPermissions Array of names of permissions that a receiver must hold
2078 * in order to receive your broadcast.
2079 * If null or empty, no permissions are required.
2080 *
2081 * @see android.content.BroadcastReceiver
2082 * @see #registerReceiver
2083 * @see #sendBroadcast(Intent)
2084 * @see #sendOrderedBroadcast(Intent, String)
2085 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2086 * @hide
2087 */
2088 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2089 String[] receiverPermissions);
2090
2091 /**
2092 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002093 * an optional required permission to be enforced. This
2094 * call is asynchronous; it returns immediately, and you will continue
2095 * executing while the receivers are run. No results are propagated from
2096 * receivers and receivers can not abort the broadcast. If you want
2097 * to allow receivers to propagate results or abort the broadcast, you must
2098 * send an ordered broadcast using
2099 * {@link #sendOrderedBroadcast(Intent, String)}.
2100 *
2101 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2102 *
2103 * @param intent The Intent to broadcast; all receivers matching this
2104 * Intent will receive the broadcast.
2105 * @param receiverPermission (optional) String naming a permission that
2106 * a receiver must hold in order to receive your broadcast.
2107 * If null, no permission is required.
2108 * @param options (optional) Additional sending options, generated from a
2109 * {@link android.app.BroadcastOptions}.
2110 *
2111 * @see android.content.BroadcastReceiver
2112 * @see #registerReceiver
2113 * @see #sendBroadcast(Intent)
2114 * @see #sendOrderedBroadcast(Intent, String)
2115 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2116 * @hide
2117 */
2118 @SystemApi
2119 public abstract void sendBroadcast(Intent intent,
2120 @Nullable String receiverPermission,
2121 @Nullable Bundle options);
2122
2123 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002124 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002125 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002126 * @hide
2127 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002128 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002129 public abstract void sendBroadcast(Intent intent,
2130 String receiverPermission, int appOp);
2131
2132 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2134 * them one at a time to allow more preferred receivers to consume the
2135 * broadcast before it is delivered to less preferred receivers. This
2136 * call is asynchronous; it returns immediately, and you will continue
2137 * executing while the receivers are run.
2138 *
2139 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2140 *
2141 * @param intent The Intent to broadcast; all receivers matching this
2142 * Intent will receive the broadcast.
2143 * @param receiverPermission (optional) String naming a permissions that
2144 * a receiver must hold in order to receive your broadcast.
2145 * If null, no permission is required.
2146 *
2147 * @see android.content.BroadcastReceiver
2148 * @see #registerReceiver
2149 * @see #sendBroadcast(Intent)
2150 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2151 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002152 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002153 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154
2155 /**
2156 * Version of {@link #sendBroadcast(Intent)} that allows you to
2157 * receive data back from the broadcast. This is accomplished by
2158 * supplying your own BroadcastReceiver when calling, which will be
2159 * treated as a final receiver at the end of the broadcast -- its
2160 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002161 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 * be serialized in the same way as calling
2163 * {@link #sendOrderedBroadcast(Intent, String)}.
2164 *
2165 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2166 * asynchronous; it will return before
2167 * resultReceiver.onReceive() is called.
2168 *
2169 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2170 *
2171 * @param intent The Intent to broadcast; all receivers matching this
2172 * Intent will receive the broadcast.
2173 * @param receiverPermission String naming a permissions that
2174 * a receiver must hold in order to receive your broadcast.
2175 * If null, no permission is required.
2176 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2177 * receiver of the broadcast.
2178 * @param scheduler A custom Handler with which to schedule the
2179 * resultReceiver callback; if null it will be
2180 * scheduled in the Context's main thread.
2181 * @param initialCode An initial value for the result code. Often
2182 * Activity.RESULT_OK.
2183 * @param initialData An initial value for the result data. Often
2184 * null.
2185 * @param initialExtras An initial value for the result extras. Often
2186 * null.
2187 *
2188 * @see #sendBroadcast(Intent)
2189 * @see #sendBroadcast(Intent, String)
2190 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002191 * @see android.content.BroadcastReceiver
2192 * @see #registerReceiver
2193 * @see android.app.Activity#RESULT_OK
2194 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002195 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002196 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002197 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2198 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002199
2200 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002201 * Version of {@link #sendBroadcast(Intent)} that allows you to
2202 * receive data back from the broadcast. This is accomplished by
2203 * supplying your own BroadcastReceiver when calling, which will be
2204 * treated as a final receiver at the end of the broadcast -- its
2205 * {@link BroadcastReceiver#onReceive} method will be called with
2206 * the result values collected from the other receivers. The broadcast will
2207 * be serialized in the same way as calling
2208 * {@link #sendOrderedBroadcast(Intent, String)}.
2209 *
2210 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2211 * asynchronous; it will return before
2212 * resultReceiver.onReceive() is called.
2213 *
2214 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2215 *
2216 *
2217 * @param intent The Intent to broadcast; all receivers matching this
2218 * Intent will receive the broadcast.
2219 * @param receiverPermission String naming a permissions that
2220 * a receiver must hold in order to receive your broadcast.
2221 * If null, no permission is required.
2222 * @param options (optional) Additional sending options, generated from a
2223 * {@link android.app.BroadcastOptions}.
2224 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2225 * receiver of the broadcast.
2226 * @param scheduler A custom Handler with which to schedule the
2227 * resultReceiver callback; if null it will be
2228 * scheduled in the Context's main thread.
2229 * @param initialCode An initial value for the result code. Often
2230 * Activity.RESULT_OK.
2231 * @param initialData An initial value for the result data. Often
2232 * null.
2233 * @param initialExtras An initial value for the result extras. Often
2234 * null.
2235 * @see #sendBroadcast(Intent)
2236 * @see #sendBroadcast(Intent, String)
2237 * @see #sendOrderedBroadcast(Intent, String)
2238 * @see android.content.BroadcastReceiver
2239 * @see #registerReceiver
2240 * @see android.app.Activity#RESULT_OK
2241 * @hide
2242 */
2243 @SystemApi
2244 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2245 @Nullable String receiverPermission, @Nullable Bundle options,
2246 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2247 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2248
2249 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002250 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2251 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002252 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002253 * @hide
2254 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002255 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002256 public abstract void sendOrderedBroadcast(Intent intent,
2257 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2258 Handler scheduler, int initialCode, String initialData,
2259 Bundle initialExtras);
2260
2261 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002262 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2263 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002264 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002265 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002266 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002267 * @see #sendBroadcast(Intent)
2268 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002269 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002270 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2271 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002272
2273 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002274 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2275 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002276 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002277 *
2278 * @param intent The Intent to broadcast; all receivers matching this
2279 * Intent will receive the broadcast.
2280 * @param user UserHandle to send the intent to.
2281 * @param receiverPermission (optional) String naming a permission that
2282 * a receiver must hold in order to receive your broadcast.
2283 * If null, no permission is required.
2284 *
2285 * @see #sendBroadcast(Intent, String)
2286 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002287 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002288 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2289 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002290
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002291 /**
2292 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2293 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002294 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002295 *
2296 * @param intent The Intent to broadcast; all receivers matching this
2297 * Intent will receive the broadcast.
2298 * @param user UserHandle to send the intent to.
2299 * @param receiverPermission (optional) String naming a permission that
2300 * a receiver must hold in order to receive your broadcast.
2301 * If null, no permission is required.
2302 * @param options (optional) Additional sending options, generated from a
2303 * {@link android.app.BroadcastOptions}.
2304 *
2305 * @see #sendBroadcast(Intent, String, Bundle)
2306 * @hide
2307 */
2308 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002309 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002310 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2311 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002312
2313 /**
2314 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2315 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002316 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002317 *
2318 * @param intent The Intent to broadcast; all receivers matching this
2319 * Intent will receive the broadcast.
2320 * @param user UserHandle to send the intent to.
2321 * @param receiverPermission (optional) String naming a permission that
2322 * a receiver must hold in order to receive your broadcast.
2323 * If null, no permission is required.
2324 * @param appOp The app op associated with the broadcast.
2325 *
2326 * @see #sendBroadcast(Intent, String)
2327 *
2328 * @hide
2329 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002330 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002331 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002332 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2333 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002334
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002335 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002336 * Version of
2337 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2338 * that allows you to specify the
2339 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002340 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002341 *
2342 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2343 *
2344 * @param intent The Intent to broadcast; all receivers matching this
2345 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002346 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002347 * @param receiverPermission String naming a permissions that
2348 * a receiver must hold in order to receive your broadcast.
2349 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002350 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2351 * receiver of the broadcast.
2352 * @param scheduler A custom Handler with which to schedule the
2353 * resultReceiver callback; if null it will be
2354 * scheduled in the Context's main thread.
2355 * @param initialCode An initial value for the result code. Often
2356 * Activity.RESULT_OK.
2357 * @param initialData An initial value for the result data. Often
2358 * null.
2359 * @param initialExtras An initial value for the result extras. Often
2360 * null.
2361 *
2362 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2363 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002364 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002365 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2366 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002367 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2368 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002369
2370 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002371 * Similar to above but takes an appOp as well, to enforce restrictions.
2372 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2373 * BroadcastReceiver, Handler, int, String, Bundle)
2374 * @hide
2375 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002376 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002377 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002378 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2379 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2380 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2381 @Nullable Bundle initialExtras);
2382
2383 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002384 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2385 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2386 * BroadcastReceiver, Handler, int, String, Bundle)
2387 * @hide
2388 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002389 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002390 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002391 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2392 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2393 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2394 @Nullable String initialData, @Nullable Bundle initialExtras);
2395
2396 /**
Jordan Liua32e6fc2019-10-29 10:33:55 -07002397 * Version of
2398 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2399 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2400 * the broadcast will be sent to.
2401 *
2402 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2403 *
2404 * @param intent The Intent to broadcast; all receivers matching this
2405 * Intent will receive the broadcast.
2406 * @param receiverPermission String naming a permissions that
2407 * a receiver must hold in order to receive your broadcast.
2408 * If null, no permission is required.
2409 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2410 * required. If both receiverAppOp and receiverPermission are non-null,
2411 * a receiver must have both of them to
2412 * receive the broadcast
2413 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2414 * receiver of the broadcast.
2415 * @param scheduler A custom Handler with which to schedule the
2416 * resultReceiver callback; if null it will be
2417 * scheduled in the Context's main thread.
2418 * @param initialCode An initial value for the result code. Often
2419 * Activity.RESULT_OK.
2420 * @param initialData An initial value for the result data. Often
2421 * null.
2422 * @param initialExtras An initial value for the result extras. Often
2423 * null.
2424 *
2425 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2426 */
Jordan Liu31a4da62019-11-19 11:36:34 -08002427 public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission,
2428 @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
2429 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2430 @Nullable Bundle initialExtras) {
Jordan Liua32e6fc2019-10-29 10:33:55 -07002431 throw new RuntimeException("Not implemented. Must override in a subclass.");
2432 }
2433
2434 /**
Peter Wangcf8bfcc2019-11-07 16:57:23 -08002435 * Version of
2436 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2437 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2438 * the broadcast will be sent to as well as supply an optional sending options
2439 *
2440 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2441 *
2442 * @param intent The Intent to broadcast; all receivers matching this
2443 * Intent will receive the broadcast.
2444 * @param receiverPermission String naming a permissions that
2445 * a receiver must hold in order to receive your broadcast.
2446 * If null, no permission is required.
2447 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2448 * required. If both receiverAppOp and receiverPermission are non-null,
2449 * a receiver must have both of them to
2450 * receive the broadcast
2451 * @param options (optional) Additional sending options, generated from a
2452 * {@link android.app.BroadcastOptions}.
2453 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2454 * receiver of the broadcast.
2455 * @param scheduler A custom Handler with which to schedule the
2456 * resultReceiver callback; if null it will be
2457 * scheduled in the Context's main thread.
2458 * @param initialCode An initial value for the result code. Often
2459 * Activity.RESULT_OK.
2460 * @param initialData An initial value for the result data. Often
2461 * null.
2462 * @param initialExtras An initial value for the result extras. Often
2463 * null.
2464 *
2465 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2466 * @see android.app.BroadcastOptions
2467 */
2468 public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2469 @Nullable String receiverPermission, @Nullable String receiverAppOp,
2470 @Nullable Bundle options, @Nullable BroadcastReceiver resultReceiver,
2471 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2472 @Nullable Bundle initialExtras) {
2473 throw new RuntimeException("Not implemented. Must override in a subclass.");
2474 }
2475
2476 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002477 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002478 * Intent you are sending stays around after the broadcast is complete,
2479 * so that others can quickly retrieve that data through the return
2480 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2481 * all other ways, this behaves the same as
2482 * {@link #sendBroadcast(Intent)}.
2483 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002484 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2485 * can access them), no protection (anyone can modify them), and many other problems.
2486 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2487 * has changed, with another mechanism for apps to retrieve the current value whenever
2488 * desired.
2489 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002490 * @param intent The Intent to broadcast; all receivers matching this
2491 * Intent will receive the broadcast, and the Intent will be held to
2492 * be re-broadcast to future receivers.
2493 *
2494 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002495 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002496 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002497 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002498 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002499 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002500
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002501 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002502 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002503 * receive data back from the broadcast. This is accomplished by
2504 * supplying your own BroadcastReceiver when calling, which will be
2505 * treated as a final receiver at the end of the broadcast -- its
2506 * {@link BroadcastReceiver#onReceive} method will be called with
2507 * the result values collected from the other receivers. The broadcast will
2508 * be serialized in the same way as calling
2509 * {@link #sendOrderedBroadcast(Intent, String)}.
2510 *
2511 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2512 * asynchronous; it will return before
2513 * resultReceiver.onReceive() is called. Note that the sticky data
2514 * stored is only the data you initially supply to the broadcast, not
2515 * the result of any changes made by the receivers.
2516 *
2517 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2518 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002519 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2520 * can access them), no protection (anyone can modify them), and many other problems.
2521 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2522 * has changed, with another mechanism for apps to retrieve the current value whenever
2523 * desired.
2524 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002525 * @param intent The Intent to broadcast; all receivers matching this
2526 * Intent will receive the broadcast.
2527 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2528 * receiver of the broadcast.
2529 * @param scheduler A custom Handler with which to schedule the
2530 * resultReceiver callback; if null it will be
2531 * scheduled in the Context's main thread.
2532 * @param initialCode An initial value for the result code. Often
2533 * Activity.RESULT_OK.
2534 * @param initialData An initial value for the result data. Often
2535 * null.
2536 * @param initialExtras An initial value for the result extras. Often
2537 * null.
2538 *
2539 * @see #sendBroadcast(Intent)
2540 * @see #sendBroadcast(Intent, String)
2541 * @see #sendOrderedBroadcast(Intent, String)
2542 * @see #sendStickyBroadcast(Intent)
2543 * @see android.content.BroadcastReceiver
2544 * @see #registerReceiver
2545 * @see android.app.Activity#RESULT_OK
2546 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002547 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002548 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002549 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002550 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002551 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2552 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002553
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002554 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002555 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 * so that it is as if the sticky broadcast had never happened.
2557 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002558 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2559 * can access them), no protection (anyone can modify them), and many other problems.
2560 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2561 * has changed, with another mechanism for apps to retrieve the current value whenever
2562 * desired.
2563 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002564 * @param intent The Intent that was previously broadcast.
2565 *
2566 * @see #sendStickyBroadcast
2567 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002568 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002569 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002570 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002571
2572 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002573 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002574 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002575 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002576 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002577 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2578 * can access them), no protection (anyone can modify them), and many other problems.
2579 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2580 * has changed, with another mechanism for apps to retrieve the current value whenever
2581 * desired.
2582 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002583 * @param intent The Intent to broadcast; all receivers matching this
2584 * Intent will receive the broadcast, and the Intent will be held to
2585 * be re-broadcast to future receivers.
2586 * @param user UserHandle to send the intent to.
2587 *
2588 * @see #sendBroadcast(Intent)
2589 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002590 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002591 @RequiresPermission(allOf = {
2592 android.Manifest.permission.INTERACT_ACROSS_USERS,
2593 android.Manifest.permission.BROADCAST_STICKY
2594 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002595 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2596 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002597
2598 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002599 * @hide
2600 * This is just here for sending CONNECTIVITY_ACTION.
2601 */
2602 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002603 @RequiresPermission(allOf = {
2604 android.Manifest.permission.INTERACT_ACROSS_USERS,
2605 android.Manifest.permission.BROADCAST_STICKY
2606 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002607 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2608 UserHandle user, Bundle options);
2609
2610 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002611 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002612 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2613 * that allows you to specify the
2614 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002615 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002616 *
2617 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2618 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002619 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2620 * can access them), no protection (anyone can modify them), and many other problems.
2621 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2622 * has changed, with another mechanism for apps to retrieve the current value whenever
2623 * desired.
2624 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002625 * @param intent The Intent to broadcast; all receivers matching this
2626 * Intent will receive the broadcast.
2627 * @param user UserHandle to send the intent to.
2628 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2629 * receiver of the broadcast.
2630 * @param scheduler A custom Handler with which to schedule the
2631 * resultReceiver callback; if null it will be
2632 * scheduled in the Context's main thread.
2633 * @param initialCode An initial value for the result code. Often
2634 * Activity.RESULT_OK.
2635 * @param initialData An initial value for the result data. Often
2636 * null.
2637 * @param initialExtras An initial value for the result extras. Often
2638 * null.
2639 *
2640 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2641 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002642 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002643 @RequiresPermission(allOf = {
2644 android.Manifest.permission.INTERACT_ACROSS_USERS,
2645 android.Manifest.permission.BROADCAST_STICKY
2646 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002647 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002648 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002649 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2650 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002651
2652 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002653 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002654 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002655 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002656 *
2657 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2658 * permission in order to use this API. If you do not hold that
2659 * permission, {@link SecurityException} will be thrown.
2660 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002661 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2662 * can access them), no protection (anyone can modify them), and many other problems.
2663 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2664 * has changed, with another mechanism for apps to retrieve the current value whenever
2665 * desired.
2666 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002667 * @param intent The Intent that was previously broadcast.
2668 * @param user UserHandle to remove the sticky broadcast from.
2669 *
2670 * @see #sendStickyBroadcastAsUser
2671 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002672 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002673 @RequiresPermission(allOf = {
2674 android.Manifest.permission.INTERACT_ACROSS_USERS,
2675 android.Manifest.permission.BROADCAST_STICKY
2676 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002677 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2678 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002679
2680 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002681 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 * <var>receiver</var> will be called with any broadcast Intent that
2683 * matches <var>filter</var>, in the main application thread.
2684 *
2685 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002686 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002687 * registrations. If your IntentFilter matches one of these sticky
2688 * Intents, that Intent will be returned by this function
2689 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2690 * been broadcast.
2691 *
2692 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2693 * in which case each of these will be sent to <var>receiver</var>. In
2694 * this case, only one of these can be returned directly by the function;
2695 * which of these that is returned is arbitrarily decided by the system.
2696 *
2697 * <p>If you know the Intent your are registering for is sticky, you can
2698 * supply null for your <var>receiver</var>. In this case, no receiver is
2699 * registered -- the function simply returns the sticky Intent that
2700 * matches <var>filter</var>. In the case of multiple matches, the same
2701 * rules as described above apply.
2702 *
2703 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2704 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002705 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2706 * registered with this method will correctly respect the
2707 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2708 * Prior to that, it would be ignored and delivered to all matching registered
2709 * receivers. Be careful if using this for security.</p>
2710 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002711 * <p class="note">Note: this method <em>cannot be called from a
2712 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2713 * that is declared in an application's manifest. It is okay, however, to call
2714 * this method from another BroadcastReceiver that has itself been registered
2715 * at run time with {@link #registerReceiver}, since the lifetime of such a
2716 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002717 *
2718 * @param receiver The BroadcastReceiver to handle the broadcast.
2719 * @param filter Selects the Intent broadcasts to be received.
2720 *
2721 * @return The first sticky intent found that matches <var>filter</var>,
2722 * or null if there are none.
2723 *
2724 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2725 * @see #sendBroadcast
2726 * @see #unregisterReceiver
2727 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002728 @Nullable
2729 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002730 IntentFilter filter);
2731
2732 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002733 * Register to receive intent broadcasts, with the receiver optionally being
2734 * exposed to Instant Apps. See
2735 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2736 * information. By default Instant Apps cannot interact with receivers in other
2737 * applications, this allows you to expose a receiver that Instant Apps can
2738 * interact with.
2739 *
2740 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2741 *
2742 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2743 * registered with this method will correctly respect the
2744 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2745 * Prior to that, it would be ignored and delivered to all matching registered
2746 * receivers. Be careful if using this for security.</p>
2747 *
2748 * @param receiver The BroadcastReceiver to handle the broadcast.
2749 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002750 * @param flags Additional options for the receiver. May be 0 or
2751 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002752 *
2753 * @return The first sticky intent found that matches <var>filter</var>,
2754 * or null if there are none.
2755 *
2756 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2757 * @see #sendBroadcast
2758 * @see #unregisterReceiver
2759 */
2760 @Nullable
2761 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2762 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002763 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002764
2765 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002766 * Register to receive intent broadcasts, to run in the context of
2767 * <var>scheduler</var>. See
2768 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2769 * information. This allows you to enforce permissions on who can
2770 * broadcast intents to your receiver, or have the receiver run in
2771 * a different thread than the main application thread.
2772 *
2773 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2774 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002775 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2776 * registered with this method will correctly respect the
2777 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2778 * Prior to that, it would be ignored and delivered to all matching registered
2779 * receivers. Be careful if using this for security.</p>
2780 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002781 * @param receiver The BroadcastReceiver to handle the broadcast.
2782 * @param filter Selects the Intent broadcasts to be received.
2783 * @param broadcastPermission String naming a permissions that a
2784 * broadcaster must hold in order to send an Intent to you. If null,
2785 * no permission is required.
2786 * @param scheduler Handler identifying the thread that will receive
2787 * the Intent. If null, the main thread of the process will be used.
2788 *
2789 * @return The first sticky intent found that matches <var>filter</var>,
2790 * or null if there are none.
2791 *
2792 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2793 * @see #sendBroadcast
2794 * @see #unregisterReceiver
2795 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002796 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002797 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002798 IntentFilter filter, @Nullable String broadcastPermission,
2799 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002800
2801 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002802 * Register to receive intent broadcasts, to run in the context of
2803 * <var>scheduler</var>. See
2804 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002805 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2806 * for more information.
2807 *
2808 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2809 *
2810 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2811 * registered with this method will correctly respect the
2812 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2813 * Prior to that, it would be ignored and delivered to all matching registered
2814 * receivers. Be careful if using this for security.</p>
2815 *
2816 * @param receiver The BroadcastReceiver to handle the broadcast.
2817 * @param filter Selects the Intent broadcasts to be received.
2818 * @param broadcastPermission String naming a permissions that a
2819 * broadcaster must hold in order to send an Intent to you. If null,
2820 * no permission is required.
2821 * @param scheduler Handler identifying the thread that will receive
2822 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002823 * @param flags Additional options for the receiver. May be 0 or
2824 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002825 *
2826 * @return The first sticky intent found that matches <var>filter</var>,
2827 * or null if there are none.
2828 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002829 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002830 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2831 * @see #sendBroadcast
2832 * @see #unregisterReceiver
2833 */
2834 @Nullable
2835 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2836 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002837 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002838
2839 /**
Meng Wange3bd3ba2019-11-05 10:43:45 -08002840 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2841 * but this receiver will receive broadcasts that are sent to all users. The receiver can
2842 * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
2843 * was sent.
2844 *
2845 * @param receiver The BroadcastReceiver to handle the broadcast.
2846 * @param filter Selects the Intent broadcasts to be received.
2847 * @param broadcastPermission String naming a permissions that a
2848 * broadcaster must hold in order to send an Intent to you. If {@code null},
2849 * no permission is required.
2850 * @param scheduler Handler identifying the thread that will receive
2851 * the Intent. If {@code null}, the main thread of the process will be used.
2852 *
2853 * @return The first sticky intent found that matches <var>filter</var>,
2854 * or {@code null} if there are none.
2855 *
2856 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2857 * @see #sendBroadcast
2858 * @see #unregisterReceiver
2859 * @hide
2860 */
2861 @Nullable
2862 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
2863 @SystemApi
2864 public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
2865 @NonNull IntentFilter filter, @Nullable String broadcastPermission,
2866 @Nullable Handler scheduler) {
2867 throw new RuntimeException("Not implemented. Must override in a subclass.");
2868 }
2869
2870 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002871 * @hide
2872 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2873 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002874 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002875 *
2876 * @param receiver The BroadcastReceiver to handle the broadcast.
2877 * @param user UserHandle to send the intent to.
2878 * @param filter Selects the Intent broadcasts to be received.
2879 * @param broadcastPermission String naming a permissions that a
2880 * broadcaster must hold in order to send an Intent to you. If null,
2881 * no permission is required.
2882 * @param scheduler Handler identifying the thread that will receive
2883 * the Intent. If null, the main thread of the process will be used.
2884 *
2885 * @return The first sticky intent found that matches <var>filter</var>,
2886 * or null if there are none.
2887 *
Jeff Brown6e539312015-02-24 18:53:21 -08002888 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002889 * @see #sendBroadcast
2890 * @see #unregisterReceiver
2891 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002892 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002893 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01002894 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002895 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002896 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2897 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002898
2899 /**
2900 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2901 * filters that have been registered for this BroadcastReceiver will be
2902 * removed.
2903 *
2904 * @param receiver The BroadcastReceiver to unregister.
2905 *
2906 * @see #registerReceiver
2907 */
2908 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2909
2910 /**
2911 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002912 * should either contain the complete class name of a specific service
2913 * implementation to start, or a specific package name to target. If the
2914 * Intent is less specified, it logs a warning about this. In this case any of the
2915 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002916 * is not already running, it will be instantiated and started (creating a
2917 * process for it if needed); if it is running then it remains running.
2918 *
2919 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002920 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 * with the <var>intent</var> given here. This provides a convenient way
2922 * to submit jobs to a service without having to bind and call on to its
2923 * interface.
2924 *
2925 * <p>Using startService() overrides the default service lifetime that is
2926 * managed by {@link #bindService}: it requires the service to remain
2927 * running until {@link #stopService} is called, regardless of whether
2928 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002929 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 * a single call to {@link #stopService} will stop it.
2931 *
2932 * <p>The system attempts to keep running services around as much as
2933 * possible. The only time they should be stopped is if the current
2934 * foreground application is using so many resources that the service needs
2935 * to be killed. If any errors happen in the service's process, it will
2936 * automatically be restarted.
2937 *
2938 * <p>This function will throw {@link SecurityException} if you do not
2939 * have permission to start the given service.
2940 *
Chris Craik1e353522016-04-18 10:20:50 -07002941 * <p class="note"><strong>Note:</strong> Each call to startService()
2942 * results in significant work done by the system to manage service
2943 * lifecycle surrounding the processing of the intent, which can take
2944 * multiple milliseconds of CPU time. Due to this cost, startService()
2945 * should not be used for frequent intent delivery to a service, and only
2946 * for scheduling significant work. Use {@link #bindService bound services}
2947 * for high frequency calls.
2948 * </p>
2949 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002950 * @param service Identifies the service to be started. The Intent must be
2951 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002952 * may be included in the Intent extras to supply arguments along with
2953 * this specific start call.
2954 *
2955 * @return If the service is being started or is already running, the
2956 * {@link ComponentName} of the actual service that was started is
2957 * returned; else if the service does not exist null is returned.
2958 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002959 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002960 * or the service can not be found.
2961 * @throws IllegalStateException If the application is in a state where the service
2962 * 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 -08002963 *
2964 * @see #stopService
2965 * @see #bindService
2966 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002967 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 public abstract ComponentName startService(Intent service);
2969
2970 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002971 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002972 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2973 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002974 * an amount of time comparable to the ANR interval to do this, otherwise the system
2975 * will automatically stop the service and declare the app ANR.
2976 *
2977 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2978 * at any time, regardless of whether the app hosting the service is in a foreground
2979 * state.
2980 *
2981 * @param service Identifies the service to be started. The Intent must be
2982 * fully explicit (supplying a component name). Additional values
2983 * may be included in the Intent extras to supply arguments along with
2984 * this specific start call.
2985 *
2986 * @return If the service is being started or is already running, the
2987 * {@link ComponentName} of the actual service that was started is
2988 * returned; else if the service does not exist null is returned.
2989 *
2990 * @throws SecurityException If the caller does not have permission to access the service
2991 * or the service can not be found.
2992 *
2993 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002994 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002995 */
2996 @Nullable
2997 public abstract ComponentName startForegroundService(Intent service);
2998
2999 /**
3000 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
3001 */
3002 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003003 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07003004 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
3005
3006 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003007 * Request that a given application service be stopped. If the service is
3008 * not running, nothing happens. Otherwise it is stopped. Note that calls
3009 * to startService() are not counted -- this stops the service no matter
3010 * how many times it was started.
3011 *
3012 * <p>Note that if a stopped service still has {@link ServiceConnection}
3013 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
3014 * not be destroyed until all of these bindings are removed. See
3015 * the {@link android.app.Service} documentation for more details on a
3016 * service's lifecycle.
3017 *
3018 * <p>This function will throw {@link SecurityException} if you do not
3019 * have permission to stop the given service.
3020 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07003021 * @param service Description of the service to be stopped. The Intent must be either
3022 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07003023 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 *
3025 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04003026 * 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 -08003027 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003028 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003029 * or the service can not be found.
3030 * @throws IllegalStateException If the application is in a state where the service
3031 * 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 -08003032 *
3033 * @see #startService
3034 */
3035 public abstract boolean stopService(Intent service);
3036
3037 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003038 * @hide like {@link #startService(Intent)} but for a specific user.
3039 */
Christopher Tate42a386b2016-11-07 12:21:21 -08003040 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003041 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003042 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003043 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
3044
3045 /**
3046 * @hide like {@link #stopService(Intent)} but for a specific user.
3047 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003048 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003049 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08003050
Dianne Hackborn7767eac2012-08-23 18:25:40 -07003051 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003052 * Connect to an application service, creating it if needed. This defines
3053 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003054 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003055 * told if it dies and restarts. The service will be considered required
3056 * by the system only for as long as the calling context exists. For
3057 * example, if this Context is an Activity that is stopped, the service will
3058 * not be required to continue running until the Activity is resumed.
3059 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003060 * <p>If the service does not support binding, it may return {@code null} from
3061 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
3062 * the ServiceConnection's
3063 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
3064 * will be invoked instead of
3065 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
3066 *
3067 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003068 * have permission to bind to the given service.
3069 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07003070 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003071 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003072 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003073 * {@link #startService} with the arguments containing the command to be
3074 * sent, with the service calling its
3075 * {@link android.app.Service#stopSelf(int)} method when done executing
3076 * that command. See the API demo App/Service/Service Start Arguments
3077 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09003078 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003079 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
3080 * is tied to another object (the one that registered it).</p>
3081 *
Mark Lu94ebbe02016-12-13 16:29:51 -08003082 * @param service Identifies the service to connect to. The Intent must
3083 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003084 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07003085 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07003086 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07003087 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
3088 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003089 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
3090 * {@link #BIND_IMPORTANT}, or
3091 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07003092 * @return {@code true} if the system is in the process of bringing up a
3093 * service that your client has permission to bind to; {@code false}
3094 * if the system couldn't find the service or if your client doesn't
3095 * have permission to bind to it. If this value is {@code true}, you
3096 * should later call {@link #unbindService} to release the
3097 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003098 *
Christopher Tate08992ac2017-03-21 11:37:06 -07003099 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08003100 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003101 *
3102 * @see #unbindService
3103 * @see #startService
3104 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07003105 * @see #BIND_DEBUG_UNBIND
3106 * @see #BIND_NOT_FOREGROUND
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003107 * @see #BIND_ABOVE_CLIENT
3108 * @see #BIND_ALLOW_OOM_MANAGEMENT
3109 * @see #BIND_WAIVE_PRIORITY
3110 * @see #BIND_IMPORTANT
3111 * @see #BIND_ADJUST_WITH_ACTIVITY
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003112 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07003113 public abstract boolean bindService(@RequiresPermission Intent service,
3114 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003115
3116 /**
Bo Liu58a57662019-03-06 20:21:45 +00003117 * Same as {@link #bindService(Intent, ServiceConnection, int)} with executor to control
3118 * ServiceConnection callbacks.
3119 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
3120 * instance for the same instance of ServiceConnection.
3121 */
3122 public boolean bindService(@RequiresPermission @NonNull Intent service,
3123 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
3124 @NonNull ServiceConnection conn) {
3125 throw new RuntimeException("Not implemented. Must override in a subclass.");
3126 }
3127
3128 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003129 * Variation of {@link #bindService} that, in the specific case of isolated
3130 * services, allows the caller to generate multiple instances of a service
Dianne Hackborncc67f962019-04-29 16:32:44 -07003131 * from a single component declaration. In other words, you can use this to bind
3132 * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
3133 * addition to the existing behavior of running in an isolated process, you can
3134 * also through the arguments here have the system bring up multiple concurrent
3135 * processes hosting their own instances of that service. The <var>instanceName</var>
3136 * you provide here identifies the different instances, and you can use
3137 * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
3138 * should manage each of these instances.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003139 *
3140 * @param service Identifies the service to connect to. The Intent must
3141 * specify an explicit component name.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003142 * @param flags Operation options for the binding as per {@link #bindService}.
3143 * @param instanceName Unique identifier for the service instance. Each unique
Robert Seseke3a5bc62019-04-22 17:43:03 -04003144 * name here will result in a different service instance being created. Identifiers
3145 * must only contain ASCII letters, digits, underscores, and periods.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003146 * @return Returns success of binding as per {@link #bindService}.
Bo Liu58a57662019-03-06 20:21:45 +00003147 * @param executor Callbacks on ServiceConnection will be called on executor.
3148 * Must use same instance for the same instance of ServiceConnection.
3149 * @param conn Receives information as the service is started and stopped.
3150 * This must be a valid ServiceConnection object; it must not be null.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003151 *
3152 * @throws SecurityException If the caller does not have permission to access the service
Robert Seseke3a5bc62019-04-22 17:43:03 -04003153 * @throws IllegalArgumentException If the instanceName is invalid.
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003154 *
3155 * @see #bindService
Dianne Hackborncc67f962019-04-29 16:32:44 -07003156 * @see #updateServiceGroup
3157 * @see android.R.attr#isolatedProcess
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003158 */
Adrian Roosebc927c2019-02-28 16:21:18 +01003159 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
Bo Liu58a57662019-03-06 20:21:45 +00003160 @BindServiceFlags int flags, @NonNull String instanceName,
3161 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003162 throw new RuntimeException("Not implemented. Must override in a subclass.");
3163 }
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003164
3165 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07003166 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003167 * argument for use by system server and other multi-user aware code.
3168 * @hide
3169 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07003170 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08003171 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003172 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07003173 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08003174 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08003175 throw new RuntimeException("Not implemented. Must override in a subclass.");
3176 }
3177
3178 /**
Dianne Hackborn27b4d942018-11-12 15:01:40 -08003179 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
Adrian Roos691546e2016-02-09 10:13:41 -08003180 * explicit non-null Handler to run the ServiceConnection callbacks on.
3181 *
3182 * @hide
3183 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06003184 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood7bcc1742019-07-04 11:39:42 +01003185 @UnsupportedAppUsage(trackingBug = 136728678)
Adrian Roos691546e2016-02-09 10:13:41 -08003186 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3187 Handler handler, UserHandle user) {
3188 throw new RuntimeException("Not implemented. Must override in a subclass.");
3189 }
3190
3191 /**
Dianne Hackborna631d562018-11-20 15:58:15 -08003192 * For a service previously bound with {@link #bindService} or a related method, change
3193 * how the system manages that service's process in relation to other processes. This
3194 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3195 * how the process will be managed in some cases based on those flags. Currently only
3196 * works on isolated processes (will be ignored for non-isolated processes).
3197 *
Dianne Hackborn2f55e5a2018-11-30 16:31:31 -08003198 * <p>Note that this call does not take immediate effect, but will be applied the next
3199 * time the impacted process is adjusted for some other reason. Typically you would
3200 * call this before then calling a new {@link #bindIsolatedService} on the service
3201 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3202 *
Dianne Hackborna631d562018-11-20 15:58:15 -08003203 * @param conn The connection interface previously supplied to bindService(). This
3204 * parameter must not be null.
3205 * @param group A group to put this connection's process in. Upon calling here, this
3206 * will override any previous group that was set for that process. The group
3207 * tells the system about processes that are logically grouped together, so
3208 * should be managed as one unit of importance (such as when being considered
3209 * a recently used app). All processes in the same app with the same group
3210 * are considered to be related. Supplying 0 reverts to the default behavior
3211 * of not grouping.
3212 * @param importance Additional importance of the processes within a group. Upon calling
Dianne Hackborncc67f962019-04-29 16:32:44 -07003213 * here, this will override any previous importance that was set for that
3214 * process. The most important process is 0, and higher values are
3215 * successively less important. You can view this as describing how
3216 * to order the processes in an array, with the processes at the end of
3217 * the array being the least important. This value has no meaning besides
3218 * indicating how processes should be ordered in that array one after the
3219 * other. This provides a way to fine-tune the system's process killing,
3220 * guiding it to kill processes at the end of the array first.
3221 *
3222 * @see #bindIsolatedService
Dianne Hackborna631d562018-11-20 15:58:15 -08003223 */
Adrian Roosfe6aeaf2019-01-22 16:58:56 +01003224 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3225 int importance) {
3226 throw new RuntimeException("Not implemented. Must override in a subclass.");
3227 }
Dianne Hackborna631d562018-11-20 15:58:15 -08003228
3229 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003230 * Disconnect from an application service. You will no longer receive
3231 * calls as the service is restarted, and the service is now allowed to
3232 * stop at any time.
3233 *
3234 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07003235 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003236 *
3237 * @see #bindService
3238 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003239 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003240
3241 /**
3242 * Start executing an {@link android.app.Instrumentation} class. The given
3243 * Instrumentation component will be run by killing its target application
3244 * (if currently running), starting the target process, instantiating the
3245 * instrumentation component, and then letting it drive the application.
3246 *
3247 * <p>This function is not synchronous -- it returns as soon as the
3248 * instrumentation has started and while it is running.
3249 *
3250 * <p>Instrumentation is normally only allowed to run against a package
3251 * that is either unsigned or signed with a signature that the
3252 * the instrumentation package is also signed with (ensuring the target
3253 * trusts the instrumentation).
3254 *
3255 * @param className Name of the Instrumentation component to be run.
3256 * @param profileFile Optional path to write profiling data as the
3257 * instrumentation runs, or null for no profiling.
3258 * @param arguments Additional optional arguments to pass to the
3259 * instrumentation, or null.
3260 *
John Spurlock6098c5d2013-06-17 10:32:46 -04003261 * @return {@code true} if the instrumentation was successfully started,
3262 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003263 */
Tor Norbyed9273d62013-05-30 15:59:53 -07003264 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3265 @Nullable String profileFile, @Nullable Bundle arguments);
3266
3267 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07003268 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07003269 POWER_SERVICE,
3270 WINDOW_SERVICE,
3271 LAYOUT_INFLATER_SERVICE,
3272 ACCOUNT_SERVICE,
3273 ACTIVITY_SERVICE,
3274 ALARM_SERVICE,
3275 NOTIFICATION_SERVICE,
3276 ACCESSIBILITY_SERVICE,
3277 CAPTIONING_SERVICE,
3278 KEYGUARD_SERVICE,
3279 LOCATION_SERVICE,
3280 //@hide: COUNTRY_DETECTOR,
3281 SEARCH_SERVICE,
3282 SENSOR_SERVICE,
Chad Brubaker90f391f2018-10-19 10:26:19 -07003283 SENSOR_PRIVACY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003284 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003285 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003286 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003287 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003288 VIBRATOR_SERVICE,
3289 //@hide: STATUS_BAR_SERVICE,
3290 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003291 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003292 IPSEC_SERVICE,
Benedict Wong99a48412018-11-09 14:45:34 -08003293 TEST_NETWORK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003294 //@hide: UPDATE_LOCK_SERVICE,
3295 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003296 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003297 //@hide: NETWORK_POLICY_SERVICE,
3298 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003299 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003300 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003301 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003302 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003303 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003304 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003305 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003306 NSD_SERVICE,
3307 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003308 FINGERPRINT_SERVICE,
Gilad Brettercb51b8b2018-03-22 17:04:51 +02003309 //@hide: FACE_SERVICE,
Kevin Chyn05c21502018-09-18 13:07:19 -07003310 BIOMETRIC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003311 MEDIA_ROUTER_SERVICE,
3312 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003313 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003314 CARRIER_CONFIG_SERVICE,
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003315 EUICC_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003316 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003317 CLIPBOARD_SERVICE,
3318 INPUT_METHOD_SERVICE,
3319 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003320 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003321 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003322 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003323 //@hide: BACKUP_SERVICE,
Richard Uhlerb29f1452018-09-12 16:38:15 +01003324 ROLLBACK_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003325 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003326 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003327 DEVICE_POLICY_SERVICE,
3328 UI_MODE_SERVICE,
3329 DOWNLOAD_SERVICE,
3330 NFC_SERVICE,
3331 BLUETOOTH_SERVICE,
3332 //@hide: SIP_SERVICE,
3333 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003334 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003335 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003336 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003337 INPUT_SERVICE,
3338 DISPLAY_SERVICE,
Christine Franks39b03112018-07-03 14:46:07 -07003339 //@hide COLOR_DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003340 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003341 RESTRICTIONS_SERVICE,
3342 APP_OPS_SERVICE,
Hai Zhangb7776682018-09-25 15:10:57 -07003343 ROLE_SERVICE,
Hai Zhanga4959e52019-03-06 12:21:07 -08003344 //@hide ROLE_CONTROLLER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003345 CAMERA_SERVICE,
atrost8266ae32019-08-15 16:53:01 +01003346 //@hide: PLATFORM_COMPAT_SERVICE,
atrostff948d82019-10-10 19:27:31 +01003347 //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003348 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003349 CONSUMER_IR_SERVICE,
3350 //@hide: TRUST_SERVICE,
3351 TV_INPUT_SERVICE,
3352 //@hide: NETWORK_SCORE_SERVICE,
3353 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003354 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003355 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003356 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003357 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003358 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003359 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003360 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003361 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003362 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003363 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003364 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003365 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003366 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003367 //@hide: INCIDENT_SERVICE,
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08003368 //@hide: INCIDENT_COMPANION_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003369 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003370 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003371 CROSS_PROFILE_APPS_SERVICE,
3372 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerfeeee682018-05-30 14:35:24 +01003373 //@hide: TIME_DETECTOR_SERVICE,
Philip P. Moltmann039678e2018-09-18 13:04:38 -07003374 PERMISSION_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003375 })
3376 @Retention(RetentionPolicy.SOURCE)
3377 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378
3379 /**
3380 * Return the handle to a system-level service by name. The class of the
3381 * returned object varies by the requested name. Currently available names
3382 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003383 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003384 * <dl>
3385 * <dt> {@link #WINDOW_SERVICE} ("window")
3386 * <dd> The top-level window manager in which you can place custom
3387 * windows. The returned object is a {@link android.view.WindowManager}.
3388 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3389 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3390 * in this context.
3391 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3392 * <dd> A {@link android.app.ActivityManager} for interacting with the
3393 * global activity state of the system.
3394 * <dt> {@link #POWER_SERVICE} ("power")
3395 * <dd> A {@link android.os.PowerManager} for controlling power
3396 * management.
3397 * <dt> {@link #ALARM_SERVICE} ("alarm")
3398 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3399 * time of your choosing.
3400 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3401 * <dd> A {@link android.app.NotificationManager} for informing the user
3402 * of background events.
3403 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3404 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3405 * <dt> {@link #LOCATION_SERVICE} ("location")
3406 * <dd> A {@link android.location.LocationManager} for controlling location
3407 * (e.g., GPS) updates.
3408 * <dt> {@link #SEARCH_SERVICE} ("search")
3409 * <dd> A {@link android.app.SearchManager} for handling search.
3410 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3411 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3412 * hardware.
3413 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3414 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3415 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003416 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3417 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3418 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003419 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003420 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3421 * connectivity. On releases before NYC, it should only be obtained from an application
3422 * context, and not from any other derived context to avoid memory leaks within the calling
3423 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003424 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3425 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3426 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003427 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3428 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3429 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003430 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3431 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3432 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003433 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3434 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003435 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003436 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003437 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003438 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003439 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3440 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003441 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3442 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3443 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003444 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003445 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003446 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003447 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 * <p>Note: System services obtained via this API may be closely associated with
3449 * the Context in which they are obtained from. In general, do not share the
3450 * service objects between various different contexts (Activities, Applications,
3451 * Services, Providers, etc.)
3452 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003453 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3454 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003455 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3456 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3457 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
3458 * return <code>null</code>. Generally, if you are running as an instant app you should always
Felipe Leme4685b862019-03-06 10:32:33 -08003459 * check whether the result of this method is {@code null}.
3460 *
3461 * <p>Note: When implementing this method, keep in mind that new services can be added on newer
3462 * Android releases, so if you're looking for just the explicit names mentioned above, make sure
3463 * to return {@code null} when you don't recognize the name &mdash; if you throw a
3464 * {@link RuntimeException} exception instead, you're app might break on new Android releases.
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003465 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003467 *
Felipe Leme4685b862019-03-06 10:32:33 -08003468 * @return The service or {@code null} if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003469 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 * @see #WINDOW_SERVICE
3471 * @see android.view.WindowManager
3472 * @see #LAYOUT_INFLATER_SERVICE
3473 * @see android.view.LayoutInflater
3474 * @see #ACTIVITY_SERVICE
3475 * @see android.app.ActivityManager
3476 * @see #POWER_SERVICE
3477 * @see android.os.PowerManager
3478 * @see #ALARM_SERVICE
3479 * @see android.app.AlarmManager
3480 * @see #NOTIFICATION_SERVICE
3481 * @see android.app.NotificationManager
3482 * @see #KEYGUARD_SERVICE
3483 * @see android.app.KeyguardManager
3484 * @see #LOCATION_SERVICE
3485 * @see android.location.LocationManager
3486 * @see #SEARCH_SERVICE
3487 * @see android.app.SearchManager
3488 * @see #SENSOR_SERVICE
3489 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003490 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003491 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 * @see #VIBRATOR_SERVICE
3493 * @see android.os.Vibrator
3494 * @see #CONNECTIVITY_SERVICE
3495 * @see android.net.ConnectivityManager
3496 * @see #WIFI_SERVICE
3497 * @see android.net.wifi.WifiManager
3498 * @see #AUDIO_SERVICE
3499 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003500 * @see #MEDIA_ROUTER_SERVICE
3501 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 * @see #TELEPHONY_SERVICE
3503 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003504 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3505 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003506 * @see #CARRIER_CONFIG_SERVICE
3507 * @see android.telephony.CarrierConfigManager
hyunhae.lee75fdafa2019-07-19 22:08:41 +09003508 * @see #EUICC_SERVICE
3509 * @see android.telephony.euicc.EuiccManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003510 * @see #INPUT_METHOD_SERVICE
3511 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003512 * @see #UI_MODE_SERVICE
3513 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003514 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003515 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003516 * @see #BATTERY_SERVICE
3517 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003518 * @see #JOB_SCHEDULER_SERVICE
3519 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003520 * @see #NETWORK_STATS_SERVICE
3521 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003522 * @see android.os.HardwarePropertiesManager
3523 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003524 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003525 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003526
3527 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003528 * Return the handle to a system-level service by class.
3529 * <p>
3530 * Currently available classes are:
3531 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3532 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3533 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3534 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3535 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3536 * {@link android.net.ConnectivityManager},
3537 * {@link android.net.wifi.WifiManager},
3538 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3539 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3540 * {@link android.view.inputmethod.InputMethodManager},
3541 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003542 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3543 * {@link android.app.usage.NetworkStatsManager}.
Felipe Leme4685b862019-03-06 10:32:33 -08003544 * </p>
3545 *
3546 * <p>
Jeff Brown6e539312015-02-24 18:53:21 -08003547 * Note: System services obtained via this API may be closely associated with
3548 * the Context in which they are obtained from. In general, do not share the
3549 * service objects between various different contexts (Activities, Applications,
3550 * Services, Providers, etc.)
3551 * </p>
3552 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003553 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3554 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
Donald Chaiee4c91c2018-09-19 14:42:41 -07003555 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
3556 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
3557 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
Felipe Leme4685b862019-03-06 10:32:33 -08003558 * return {@code null}. Generally, if you are running as an instant app you should always
3559 * check whether the result of this method is {@code null}.
3560 * </p>
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003561 *
Jeff Brown6e539312015-02-24 18:53:21 -08003562 * @param serviceClass The class of the desired service.
Felipe Leme4685b862019-03-06 10:32:33 -08003563 * @return The service or {@code null} if the class is not a supported system service. Note:
3564 * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
Jeff Brown6e539312015-02-24 18:53:21 -08003565 */
3566 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003567 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003568 // Because subclasses may override getSystemService(String) we cannot
3569 // perform a lookup by class alone. We must first map the class to its
3570 // service name then invoke the string-based method.
3571 String serviceName = getSystemServiceName(serviceClass);
3572 return serviceName != null ? (T)getSystemService(serviceName) : null;
3573 }
3574
3575 /**
3576 * Gets the name of the system-level service that is represented by the specified class.
3577 *
3578 * @param serviceClass The class of the desired service.
3579 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003580 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003581 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003582
3583 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003584 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003585 * {@link android.os.PowerManager} for controlling power management,
3586 * including "wake locks," which let you keep the device on while
3587 * you're running long tasks.
3588 */
3589 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003590
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003592 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003593 * {@link android.os.RecoverySystem} for accessing the recovery system
3594 * service.
3595 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003596 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003597 * @hide
3598 */
3599 public static final String RECOVERY_SERVICE = "recovery";
3600
3601 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003602 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003603 * {@link android.os.SystemUpdateManager} for accessing the system update
3604 * manager service.
3605 *
3606 * @see #getSystemService(String)
3607 * @hide
3608 */
3609 @SystemApi
3610 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3611
3612 /**
3613 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003614 * {@link android.view.WindowManager} for accessing the system's window
3615 * manager.
3616 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003617 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003618 * @see android.view.WindowManager
3619 */
3620 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003621
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003622 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003623 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003624 * {@link android.view.LayoutInflater} for inflating layout resources in this
3625 * context.
3626 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003627 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003628 * @see android.view.LayoutInflater
3629 */
3630 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003631
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003632 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003633 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003634 * {@link android.accounts.AccountManager} for receiving intents at a
3635 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003636 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003637 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003638 * @see android.accounts.AccountManager
3639 */
3640 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003641
Fred Quintana60307342009-03-24 22:48:12 -07003642 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003643 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003644 * {@link android.app.ActivityManager} for interacting with the global
3645 * system state.
3646 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003647 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003648 * @see android.app.ActivityManager
3649 */
3650 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003652 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003653 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale65ebd952018-04-25 15:41:44 -07003654 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
3655 *
3656 * @see #getSystemService(String)
3657 * @see android.app.ActivityTaskManager
3658 * @hide
3659 */
3660 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
3661
3662 /**
3663 * Use with {@link #getSystemService(String)} to retrieve a
Wale Ogunwale6d50dcc2018-07-21 23:00:40 -07003664 * {@link android.app.UriGrantsManager} for interacting with the global system state.
3665 *
3666 * @see #getSystemService(String)
3667 * @see android.app.UriGrantsManager
3668 * @hide
3669 */
3670 public static final String URI_GRANTS_SERVICE = "uri_grants";
3671
3672 /**
3673 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003674 * {@link android.app.AlarmManager} for receiving intents at a
3675 * time of your choosing.
3676 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003677 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003678 * @see android.app.AlarmManager
3679 */
3680 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003683 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 * {@link android.app.NotificationManager} for informing the user of
3685 * background events.
3686 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003687 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 * @see android.app.NotificationManager
3689 */
3690 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003691
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003693 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003694 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3695 * feedback for UI events through the registered event listeners.
3696 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003697 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003698 * @see android.view.accessibility.AccessibilityManager
3699 */
3700 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003701
svetoslavganov75986cf2009-05-14 22:28:01 -07003702 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003703 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003704 * {@link android.view.accessibility.CaptioningManager} for obtaining
3705 * captioning properties and listening for changes in captioning
3706 * preferences.
3707 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003708 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003709 * @see android.view.accessibility.CaptioningManager
3710 */
3711 public static final String CAPTIONING_SERVICE = "captioning";
3712
3713 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003714 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003715 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003716 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003717 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003718 * @see android.app.KeyguardManager
3719 */
3720 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003722 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003723 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003724 * android.location.LocationManager} for controlling location
3725 * updates.
3726 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003727 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003728 * @see android.location.LocationManager
3729 */
3730 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003731
3732 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003733 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003734 * {@link android.location.CountryDetector} for detecting the country that
3735 * the user is in.
3736 *
3737 * @hide
3738 */
Mathew Inwood8c854f82018-09-14 12:35:36 +01003739 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003740 public static final String COUNTRY_DETECTOR = "country_detector";
3741
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003742 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003743 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 * android.app.SearchManager} for handling searches.
3745 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003746 * <p>
3747 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3748 * {@link android.app.SearchManager}.
3749 *
3750 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003751 * @see android.app.SearchManager
3752 */
3753 public static final String SEARCH_SERVICE = "search";
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 {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 * android.hardware.SensorManager} for accessing sensors.
3758 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003759 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003760 * @see android.hardware.SensorManager
3761 */
3762 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003763
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003764 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003765 * Use with {@link #getSystemService(String)} to retrieve a {@link
Chad Brubaker90f391f2018-10-19 10:26:19 -07003766 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
3767 * functions.
3768 *
3769 * @see #getSystemService(String)
3770 * @see android.hardware.SensorPrivacyManager
3771 *
3772 * @hide
3773 */
3774 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
3775
3776 /**
3777 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003778 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003779 * functions.
3780 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003781 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003782 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003783 */
3784 public static final String STORAGE_SERVICE = "storage";
3785
3786 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003787 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003788 * android.app.usage.StorageStatsManager} for accessing system storage
3789 * statistics.
3790 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003791 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003792 * @see android.app.usage.StorageStatsManager
3793 */
3794 public static final String STORAGE_STATS_SERVICE = "storagestats";
3795
3796 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003797 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003798 * com.android.server.WallpaperService for accessing wallpapers.
3799 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003800 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003801 */
3802 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003803
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003804 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003805 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003806 * android.os.Vibrator} for interacting with the vibration hardware.
3807 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003808 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003809 * @see android.os.Vibrator
3810 */
3811 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003812
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003813 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003814 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003815 * android.app.StatusBarManager} for interacting with the status bar.
3816 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003817 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 * @see android.app.StatusBarManager
Evan Lairdedd016f2019-01-23 18:36:29 -05003819 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 * @hide
3821 */
Evan Lairdedd016f2019-01-23 18:36:29 -05003822 @SystemApi
Evan Laird418ba8f2019-04-17 15:55:21 -04003823 @TestApi
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003824 public static final String STATUS_BAR_SERVICE = "statusbar";
3825
3826 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003827 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003828 * android.net.ConnectivityManager} for handling management of
3829 * network connections.
3830 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003831 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003832 * @see android.net.ConnectivityManager
3833 */
3834 public static final String CONNECTIVITY_SERVICE = "connectivity";
3835
3836 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003837 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003838 * {@link android.net.INetd} for communicating with the network stack
3839 * @hide
3840 * @see #getSystemService(String)
3841 * @hide
3842 */
3843 @SystemApi
3844 public static final String NETD_SERVICE = "netd";
3845
3846 /**
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003847 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
3848 * {@link NetworkStackClient} IBinder for communicating with the network stack
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003849 * @hide
Remi NGUYEN VAN310da6f2019-02-14 18:04:20 +09003850 * @see NetworkStackClient
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003851 */
3852 public static final String NETWORK_STACK_SERVICE = "network_stack";
3853
3854 /**
3855 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003856 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3857 * IPSec.
3858 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003859 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003860 */
3861 public static final String IPSEC_SERVICE = "ipsec";
3862
3863 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003864 * Use with {@link #getSystemService(String)} to retrieve a {@link
Benedict Wong99a48412018-11-09 14:45:34 -08003865 * android.net.TestNetworkManager} for building TUNs and limited-use Networks
3866 *
3867 * @see #getSystemService(String)
3868 * @hide
3869 */
3870 @TestApi public static final String TEST_NETWORK_SERVICE = "test_network";
3871
3872 /**
3873 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003874 * android.os.IUpdateLock} for managing runtime sequences that
3875 * must not be interrupted by headless OTA application or similar.
3876 *
3877 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003878 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003879 * @see android.os.UpdateLock
3880 */
3881 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3882
3883 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003884 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003885 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003886 */
3887 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3888
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003889 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003890 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003891 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3892 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003893 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003894 */
3895 public static final String SLICE_SERVICE = "slice";
3896
3897 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003898 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003899 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3900 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003901 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003902 * @see android.app.usage.NetworkStatsManager
3903 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003904 public static final String NETWORK_STATS_SERVICE = "netstats";
3905 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003906 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003907 /** {@hide} */
3908 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003909
San Mehatd1df8ac2010-01-26 06:17:26 -08003910 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003911 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003912 * android.net.wifi.WifiManager} for handling management of
3913 * Wi-Fi access.
3914 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003915 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003916 * @see android.net.wifi.WifiManager
3917 */
3918 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003920 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003921 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003922 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003923 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003924 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003925 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003926 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003927 */
3928 public static final String WIFI_P2P_SERVICE = "wifip2p";
3929
3930 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003931 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003932 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3933 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003934 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003935 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003936 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003937 */
Etan Cohen04133272016-10-26 11:22:06 -07003938 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003939
3940 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003941 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003942 * android.net.wifi.WifiScanner} for scanning the wifi universe
3943 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003944 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003945 * @see android.net.wifi.WifiScanner
3946 * @hide
3947 */
Wei Wang35d552f2014-07-08 21:37:01 -07003948 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003949 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3950
3951 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003952 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003953 * android.net.wifi.RttManager} for ranging devices with wifi
3954 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003955 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003956 * @see android.net.wifi.RttManager
3957 * @hide
3958 */
3959 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08003960 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07003961 public static final String WIFI_RTT_SERVICE = "rttmanager";
3962
3963 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003964 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohenf4062a92019-04-11 07:00:42 -07003965 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
Etan Cohen17ba4722017-08-21 10:52:17 -07003966 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003967 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003968 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003969 */
Etan Cohen091d7772018-01-04 17:47:37 -08003970 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003971
3972 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003973 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003974 * android.net.lowpan.LowpanManager} for handling management of
3975 * LoWPAN access.
3976 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003977 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003978 * @see android.net.lowpan.LowpanManager
3979 *
3980 * @hide
3981 */
3982 public static final String LOWPAN_SERVICE = "lowpan";
3983
3984 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003985 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003986 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003987 * Ethernet access.
3988 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003989 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003990 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003991 *
3992 * @hide
3993 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01003994 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003995 public static final String ETHERNET_SERVICE = "ethernet";
3996
3997 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003998 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003999 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004000 * discovery
4001 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004002 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07004003 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004004 */
4005 public static final String NSD_SERVICE = "servicediscovery";
4006
Irfan Sheriff7d024d32012-03-22 17:01:39 -07004007 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004008 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004009 * {@link android.media.AudioManager} for handling management of volume,
4010 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07004011 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004012 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004013 * @see android.media.AudioManager
4014 */
4015 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07004016
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004017 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004018 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07004019 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07004020 * of fingerprints.
4021 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004022 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07004023 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07004024 */
4025 public static final String FINGERPRINT_SERVICE = "fingerprint";
4026
4027 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004028 * Use with {@link #getSystemService(String)} to retrieve a
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004029 * {@link android.hardware.face.FaceManager} for handling management
4030 * of face authentication.
4031 *
4032 * @hide
4033 * @see #getSystemService
4034 * @see android.hardware.face.FaceManager
4035 */
4036 public static final String FACE_SERVICE = "face";
4037
4038 /**
Kevin Chyn05c21502018-09-18 13:07:19 -07004039 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn51676d22018-11-05 18:00:43 -08004040 * {@link android.hardware.iris.IrisManager} for handling management
4041 * of iris authentication.
4042 *
4043 * @hide
4044 * @see #getSystemService
4045 * @see android.hardware.iris.IrisManager
4046 */
4047 public static final String IRIS_SERVICE = "iris";
4048
4049 /**
4050 * Use with {@link #getSystemService(String)} to retrieve a
Kevin Chyn05c21502018-09-18 13:07:19 -07004051 * {@link android.hardware.biometrics.BiometricManager} for handling management
4052 * of face authentication.
4053 *
4054 * @see #getSystemService
4055 * @see android.hardware.biometrics.BiometricManager
4056 */
4057 public static final String BIOMETRIC_SERVICE = "biometric";
4058
4059 /**
Gilad Brettercb51b8b2018-03-22 17:04:51 +02004060 * Use with {@link #getSystemService} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004061 * {@link android.media.MediaRouter} for controlling and managing
4062 * routing of media.
4063 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004064 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07004065 * @see android.media.MediaRouter
4066 */
4067 public static final String MEDIA_ROUTER_SERVICE = "media_router";
4068
4069 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004070 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07004071 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08004072 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004073 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07004074 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08004075 */
4076 public static final String MEDIA_SESSION_SERVICE = "media_session";
4077
4078 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004079 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080 * {@link android.telephony.TelephonyManager} for handling management the
4081 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07004082 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004083 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004084 * @see android.telephony.TelephonyManager
4085 */
4086 public static final String TELEPHONY_SERVICE = "phone";
4087
4088 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004089 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08004090 * {@link android.telephony.SubscriptionManager} for handling management the
4091 * telephony subscriptions of the device.
4092 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004093 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08004094 * @see android.telephony.SubscriptionManager
4095 */
4096 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
4097
4098 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004099 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004100 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07004101 * of the device.
4102 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004103 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004104 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07004105 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07004106 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07004107
4108 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004109 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004110 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
4111 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004112 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08004113 * @see android.telephony.CarrierConfigManager
4114 */
4115 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
4116
4117 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004118 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08004119 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
4120 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004121 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08004122 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08004123 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004124 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08004125
4126 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004127 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004128 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
4129 *
4130 * @see #getSystemService(String)
4131 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004132 * @hide
4133 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08004134 @SystemApi
4135 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08004136
4137 /**
4138 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08004139 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004140 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07004141 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004142 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004143 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004144 */
4145 public static final String CLIPBOARD_SERVICE = "clipboard";
4146
4147 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004148 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004149 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004150 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004151 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00004152 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00004153 */
4154 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
4155
4156 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004157 * Use with {@link #getSystemService(String)} to retrieve a
Alex Salo5f5b5f42019-02-27 10:49:00 -08004158 * {@link com.android.server.attention.AttentionManagerService} for attention services.
4159 *
4160 * @see #getSystemService(String)
4161 * @see android.server.attention.AttentionManagerService
4162 * @hide
4163 */
4164 public static final String ATTENTION_SERVICE = "attention";
4165
4166 /**
4167 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004168 * {@link android.view.inputmethod.InputMethodManager} for accessing input
4169 * methods.
4170 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004171 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004172 */
4173 public static final String INPUT_METHOD_SERVICE = "input_method";
4174
4175 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004176 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09004177 * {@link android.view.textservice.TextServicesManager} for accessing
4178 * text services.
4179 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004180 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09004181 */
4182 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
4183
4184 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004185 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08004186 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004187 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004188 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004189 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07004190 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07004191
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004192 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07004193 * Official published name of the (internal) voice interaction manager service.
4194 *
4195 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004196 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07004197 */
4198 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4199
4200 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08004201 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07004202 *
4203 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004204 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07004205 */
Felipe Leme640f30a2017-03-06 15:44:06 -08004206 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07004207
4208 /**
Felipe Leme749b8892018-12-03 16:30:30 -08004209 * Official published name of the content capture service.
Felipe Lemee348dc32018-11-05 12:35:29 -08004210 *
4211 * @hide
4212 * @see #getSystemService(String)
4213 */
Felipe Lemea7e4ca62019-05-23 13:32:40 -07004214 @TestApi
Felipe Leme749b8892018-12-03 16:30:30 -08004215 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
Felipe Lemee348dc32018-11-05 12:35:29 -08004216
4217 /**
Winson Chung3fb0f252019-01-08 17:41:55 -08004218 * Used for getting content selections and classifications for task snapshots.
4219 *
4220 * @hide
4221 * @see #getSystemService(String)
4222 */
4223 @SystemApi
4224 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
4225
4226 /**
Sunny Goyal54e91342018-11-14 11:59:02 -08004227 * Official published name of the app prediction service.
4228 *
4229 * @hide
4230 * @see #getSystemService(String)
4231 */
4232 @SystemApi
4233 public static final String APP_PREDICTION_SERVICE = "app_prediction";
4234
4235 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004236 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004237 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
4238 *
4239 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004240 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004241 */
4242 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
4243
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004244 /**
4245 * Official published name of the (internal) permission service.
4246 *
4247 * @see #getSystemService(String)
4248 * @hide
4249 */
Winsonf27394e2019-06-07 14:44:40 -07004250 @TestApi
Philip P. Moltmann039678e2018-09-18 13:04:38 -07004251 @SystemApi
4252 public static final String PERMISSION_SERVICE = "permission";
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08004253
4254 /**
Philip P. Moltmannbc054d82018-12-21 09:41:58 -08004255 * Official published name of the (internal) permission controller service.
4256 *
4257 * @see #getSystemService(String)
4258 * @hide
4259 */
4260 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
4261
4262 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004263 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08004264 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07004265 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07004266 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07004267 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004268 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07004269 */
Christopher Tated5cf7222014-07-29 16:53:09 -07004270 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07004271 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07004272
4273 /**
Richard Uhlerb29f1452018-09-12 16:38:15 +01004274 * Use with {@link #getSystemService(String)} to retrieve an
4275 * {@link android.content.rollback.RollbackManager} for communicating
4276 * with the rollback manager
4277 *
4278 * @see #getSystemService(String)
Richard Uhlerc739c8c2018-12-12 11:03:34 +00004279 * @hide
Richard Uhlerb29f1452018-09-12 16:38:15 +01004280 */
Richard Uhler8a977452019-03-08 13:27:17 +00004281 @SystemApi @TestApi
Richard Uhlerb29f1452018-09-12 16:38:15 +01004282 public static final String ROLLBACK_SERVICE = "rollback";
4283
4284 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004285 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08004286 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07004287 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004288 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07004289 */
4290 public static final String DROPBOX_SERVICE = "dropbox";
4291
Christopher Tate487529a2009-04-29 14:03:25 -07004292 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07004293 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004294 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07004295 * @hide
4296 */
4297 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
4298
4299 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004300 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08004301 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08004302 * device policy management.
4303 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004304 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08004305 */
4306 public static final String DEVICE_POLICY_SERVICE = "device_policy";
4307
4308 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004309 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08004310 * {@link android.app.UiModeManager} for controlling UI modes.
4311 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004312 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08004313 */
4314 public static final String UI_MODE_SERVICE = "uimode";
4315
4316 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004317 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07004318 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07004319 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004320 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07004321 */
4322 public static final String DOWNLOAD_SERVICE = "download";
4323
4324 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004325 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08004326 * {@link android.os.BatteryManager} for managing battery state.
4327 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004328 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08004329 */
4330 public static final String BATTERY_SERVICE = "batterymanager";
4331
4332 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004333 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004334 * {@link android.nfc.NfcManager} for using NFC.
4335 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004336 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08004337 */
4338 public static final String NFC_SERVICE = "nfc";
4339
4340 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004341 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00004342 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004343 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004344 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08004345 */
4346 public static final String BLUETOOTH_SERVICE = "bluetooth";
4347
4348 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004349 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08004350 * {@link android.net.sip.SipManager} for accessing the SIP related service.
4351 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004352 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08004353 */
4354 /** @hide */
4355 public static final String SIP_SERVICE = "sip";
4356
4357 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004358 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08004359 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004360 * and for controlling this device's behavior as a USB device.
4361 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004362 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04004363 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05004364 */
4365 public static final String USB_SERVICE = "usb";
4366
4367 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004368 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Rootf74bfde2018-01-18 15:42:48 -08004369 * Use with {@link #getSystemService} to retrieve a {@link
4370 * android.debug.AdbManager} for access to ADB debug functions.
4371 *
4372 * @see #getSystemService(String)
4373 * @see android.debug.AdbManager
4374 *
4375 * @hide
4376 */
4377 public static final String ADB_SERVICE = "adb";
4378
4379 /**
4380 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004381 * android.hardware.SerialManager} for access to serial ports.
4382 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004383 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07004384 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04004385 *
4386 * @hide
4387 */
4388 public static final String SERIAL_SERVICE = "serial";
4389
4390 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004391 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09004392 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
4393 * HDMI-CEC protocol.
4394 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004395 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09004396 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004397 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09004398 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09004399 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09004400 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09004401
4402 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004403 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004404 * {@link android.hardware.input.InputManager} for interacting with input devices.
4405 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004406 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07004407 * @see android.hardware.input.InputManager
4408 */
4409 public static final String INPUT_SERVICE = "input";
4410
4411 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004412 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07004413 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
4414 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004415 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07004416 * @see android.hardware.display.DisplayManager
4417 */
4418 public static final String DISPLAY_SERVICE = "display";
4419
4420 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004421 * Use with {@link #getSystemService(String)} to retrieve a
Christine Franks39b03112018-07-03 14:46:07 -07004422 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
4423 *
4424 * @see #getSystemService(String)
4425 * @see android.hardware.display.ColorDisplayManager
4426 * @hide
4427 */
4428 public static final String COLOR_DISPLAY_SERVICE = "color_display";
4429
4430 /**
4431 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07004432 * {@link android.os.UserManager} for managing users on devices that support multiple users.
4433 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004434 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07004435 * @see android.os.UserManager
4436 */
4437 public static final String USER_SERVICE = "user";
4438
4439 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004440 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08004441 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
4442 * profiles of a user.
4443 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004444 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08004445 * @see android.content.pm.LauncherApps
4446 */
4447 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4448
4449 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004450 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004451 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4452 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004453 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004454 * @see android.content.RestrictionsManager
4455 */
4456 public static final String RESTRICTIONS_SERVICE = "restrictions";
4457
4458 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004459 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004460 * {@link android.app.AppOpsManager} for tracking application operations
4461 * on the device.
4462 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004463 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004464 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004465 */
4466 public static final String APP_OPS_SERVICE = "appops";
4467
4468 /**
Hai Zhangb7776682018-09-25 15:10:57 -07004469 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
4470 * for managing roles.
4471 *
4472 * @see #getSystemService(String)
4473 * @see android.app.role.RoleManager
4474 */
4475 public static final String ROLE_SERVICE = "role";
4476
4477 /**
Hai Zhanga4959e52019-03-06 12:21:07 -08004478 * Official published name of the (internal) role controller service.
4479 *
4480 * @see #getSystemService(String)
4481 * @see android.app.role.RoleControllerService
4482 *
4483 * @hide
4484 */
4485 public static final String ROLE_CONTROLLER_SERVICE = "role_controller";
4486
4487 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004488 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004489 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004490 * camera devices.
4491 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004492 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004493 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004494 */
4495 public static final String CAMERA_SERVICE = "camera";
4496
4497 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004498 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004499 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004500 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004501 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004502 * @see android.print.PrintManager
4503 */
4504 public static final String PRINT_SERVICE = "print";
4505
4506 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004507 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004508 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4509 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004510 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004511 * @see android.companion.CompanionDeviceManager
4512 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004513 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004514
4515 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004516 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004517 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4518 * signals from the device.
4519 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004520 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004521 * @see android.hardware.ConsumerIrManager
4522 */
4523 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4524
4525 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004526 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004527 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004528 * @see android.app.trust.TrustManager
4529 * @hide
4530 */
4531 public static final String TRUST_SERVICE = "trust";
4532
4533 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004534 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004535 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4536 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004537 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004538 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004539 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004540 */
4541 public static final String TV_INPUT_SERVICE = "tv_input";
4542
4543 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004544 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004545 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004546 * @see android.net.NetworkScoreManager
4547 * @hide
4548 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004549 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004550 public static final String NETWORK_SCORE_SERVICE = "network_score";
4551
4552 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004553 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004554 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004555 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004556 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004557 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004558 */
4559 public static final String USAGE_STATS_SERVICE = "usagestats";
4560
4561 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004562 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004563 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004564 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004565 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004566 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004567 */
Christopher Tate7060b042014-06-09 19:50:00 -07004568 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004569
4570 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004571 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004572 * android.service.persistentdata.PersistentDataBlockManager} instance
4573 * for interacting with a storage device that lives across factory resets.
4574 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004575 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004576 * @see android.service.persistentdata.PersistentDataBlockManager
4577 * @hide
4578 */
Andres Morales33df9372014-09-26 17:08:59 -07004579 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004580 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4581
4582 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004583 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004584 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4585 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004586 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004587 * @see android.service.oemlock.OemLockManager
4588 * @hide
4589 */
4590 @SystemApi
4591 public static final String OEM_LOCK_SERVICE = "oem_lock";
4592
4593 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004594 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004595 * android.media.projection.MediaProjectionManager} instance for managing
4596 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004597 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004598 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004599 */
4600 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4601
4602 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004603 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004604 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004605 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004606 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004607 */
4608 public static final String MIDI_SERVICE = "midi";
4609
Eric Laurent2035ac82015-03-05 15:18:44 -08004610
4611 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004612 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004613 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4614 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004615 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004616 * @hide
4617 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004618 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004619
Paul McLeana33be212015-02-20 07:52:45 -08004620 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004621 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004622 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4623 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004624 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004625 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004626 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004627
4628 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004629 * Use with {@link #getSystemService(String)} to retrieve a
Wei Wangbad7c202018-11-01 11:57:39 -07004630 * {@link android.os.ThermalService} for accessing the thermal service.
4631 *
4632 * @see #getSystemService(String)
4633 * @hide
4634 */
4635 public static final String THERMAL_SERVICE = "thermalservice";
4636
4637 /**
4638 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004639 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004640 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004641 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004642 * @see android.content.pm.ShortcutManager
4643 */
4644 public static final String SHORTCUT_SERVICE = "shortcut";
4645
4646 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004647 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004648 * android.hardware.location.ContextHubManager} for accessing context hubs.
4649 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004650 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004651 * @see android.hardware.location.ContextHubManager
4652 *
4653 * @hide
4654 */
4655 @SystemApi
4656 public static final String CONTEXTHUB_SERVICE = "contexthub";
4657
4658 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004659 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004660 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4661 * memory, etc) metrics.
4662 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004663 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004664 */
4665 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4666
4667 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004668 * Gatekeeper Service.
4669 * @hide
4670 */
4671 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4672
4673 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004674 * Service defining the policy for access to device identifiers.
4675 * @hide
4676 */
4677 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4678
4679 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004680 * Service to report a system health "incident"
4681 * @hide
4682 */
4683 public static final String INCIDENT_SERVICE = "incident";
4684
4685 /**
Joe Onoratoe21ab7e2018-12-18 15:00:25 -08004686 * Service to assist incidentd and dumpstated in reporting status to the user
4687 * and in confirming authorization to take an incident report or bugreport
4688 * @hide
4689 */
4690 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
4691
4692 /**
Bookatz94726412017-08-31 09:26:15 -07004693 * Service to assist statsd in obtaining general stats.
4694 * @hide
4695 */
4696 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4697
4698 /**
Bookatzc6977972018-01-16 16:55:05 -08004699 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004700 * @hide
4701 */
4702 @SystemApi
4703 public static final String STATS_MANAGER = "stats";
4704
4705 /**
atrost8266ae32019-08-15 16:53:01 +01004706 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4707 * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
4708 * @hide
4709 */
4710 public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
4711
4712 /**
atrostff948d82019-10-10 19:27:31 +01004713 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4714 * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
4715 * service.
4716 * @hide
4717 */
4718 public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
4719
4720 /**
Nandana Duttd11850c2018-12-12 17:26:57 +00004721 * Service to capture a bugreport.
4722 * @see #getSystemService(String)
4723 * @see android.os.BugreportManager
4724 * @hide
4725 */
Nandana Duttd7e8d5a2019-04-11 17:27:45 +01004726 @SystemApi @TestApi
Nandana Duttd11850c2018-12-12 17:26:57 +00004727 public static final String BUGREPORT_SERVICE = "bugreport";
4728
4729 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004730 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004731 * android.content.om.OverlayManager} for managing overlay packages.
4732 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004733 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004734 * @see android.content.om.OverlayManager
4735 * @hide
4736 */
4737 public static final String OVERLAY_SERVICE = "overlay";
4738
4739 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004740 * Use with {@link #getSystemService(String)} to retrieve a
MÃ¥rten Kongstad06a1ac82018-09-20 13:09:47 +02004741 * {android.os.IIdmap2} for managing idmap files (used by overlay
4742 * packages).
4743 *
4744 * @see #getSystemService(String)
4745 * @hide
4746 */
4747 public static final String IDMAP_SERVICE = "idmap";
4748
4749 /**
4750 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004751 * {@link VrManager} for accessing the VR service.
4752 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004753 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004754 * @hide
4755 */
4756 @SystemApi
4757 public static final String VR_SERVICE = "vrmanager";
4758
4759 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004760 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004761 * {@link android.app.timezone.ITimeZoneRulesManager}.
4762 * @hide
4763 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004764 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004765 */
4766 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4767
4768 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004769 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004770 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004771 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004772 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004773 */
4774 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4775
4776 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004777 * Use with {@link #getSystemService} to retrieve a
4778 * {@link android.se.omapi.ISecureElementService}
4779 * for accessing the SecureElementService.
4780 *
4781 * @hide
4782 */
4783 @SystemApi
4784 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4785
4786 /**
Neil Fullerfeeee682018-05-30 14:35:24 +01004787 * Use with {@link #getSystemService(String)} to retrieve an
4788 * {@link android.app.timedetector.ITimeDetectorService}.
4789 * @hide
4790 *
4791 * @see #getSystemService(String)
4792 */
4793 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4794
4795 /**
Makoto Onukidf7e4812018-09-24 14:31:25 -07004796 * Binder service name for {@link AppBindingService}.
4797 * @hide
4798 */
4799 public static final String APP_BINDING_SERVICE = "app_binding";
4800
4801 /**
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004802 * Use with {@link #getSystemService(String)} to retrieve an
James.cf Lin2bc9cd42019-11-04 20:23:36 +08004803 * {@link android.telephony.ims.ImsManager}.
4804 * @hide
4805 */
4806 public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
4807
4808 /**
4809 * Use with {@link #getSystemService(String)} to retrieve an
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004810 * {@link android.telephony.ims.RcsMessageManager}.
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004811 * @hide
4812 */
Brad Ebingerd1cb3462019-06-20 14:20:01 -07004813 public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004814
Howard Chen0a947642019-01-07 14:10:44 +08004815 /**
4816 * Use with {@link #getSystemService(String)} to retrieve an
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004817 * {@link android.os.image.DynamicSystemManager}.
Howard Chen0a947642019-01-07 14:10:44 +08004818 * @hide
4819 */
Po-Chien Hsueh4e908c22019-03-07 11:57:17 +08004820 public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
Howard Chen0a947642019-01-07 14:10:44 +08004821
Sahin Caliskan9458ebc2018-10-31 13:23:29 -07004822 /**
Chen Xu1f1c25e2019-09-15 18:28:21 -07004823 * Use with {@link #getSystemService(String)} to retrieve an
Chen Xu8eb62f92019-10-13 17:30:32 -07004824 * {@link TelephonyRegistryManager}.
Chen Xu1f1c25e2019-09-15 18:28:21 -07004825 * @hide
4826 */
4827 @SystemApi
4828 public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
4829
4830 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004831 * Determine whether the given permission is allowed for a particular
4832 * process and user ID running in the system.
4833 *
4834 * @param permission The name of the permission being checked.
4835 * @param pid The process ID being checked against. Must be > 0.
4836 * @param uid The user ID being checked against. A uid of 0 is the root
4837 * user, which will pass every permission check.
4838 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004839 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004840 * pid/uid is allowed that permission, or
4841 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4842 *
4843 * @see PackageManager#checkPermission(String, String)
4844 * @see #checkCallingPermission
4845 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004846 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004847 @PackageManager.PermissionResult
4848 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004849
Dianne Hackbornff170242014-11-19 10:59:01 -08004850 /** @hide */
4851 @PackageManager.PermissionResult
Mathew Inwood5c0d3542018-08-14 13:54:31 +01004852 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08004853 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4854 IBinder callerToken);
4855
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004856 /**
4857 * Determine whether the calling process of an IPC you are handling has been
4858 * granted a particular permission. This is basically the same as calling
4859 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4860 * by {@link android.os.Binder#getCallingPid} and
4861 * {@link android.os.Binder#getCallingUid}. One important difference
4862 * is that if you are not currently processing an IPC, this function
4863 * will always fail. This is done to protect against accidentally
4864 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4865 * to avoid this protection.
4866 *
4867 * @param permission The name of the permission being checked.
4868 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004869 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004870 * pid/uid is allowed that permission, or
4871 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4872 *
4873 * @see PackageManager#checkPermission(String, String)
4874 * @see #checkPermission
4875 * @see #checkCallingOrSelfPermission
4876 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004877 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004878 @PackageManager.PermissionResult
4879 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004880
4881 /**
4882 * Determine whether the calling process of an IPC <em>or you</em> have been
4883 * granted a particular permission. This is the same as
4884 * {@link #checkCallingPermission}, except it grants your own permissions
4885 * if you are not currently processing an IPC. Use with care!
4886 *
4887 * @param permission The name of the permission being checked.
4888 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004889 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004890 * pid/uid is allowed that permission, or
4891 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4892 *
4893 * @see PackageManager#checkPermission(String, String)
4894 * @see #checkPermission
4895 * @see #checkCallingPermission
4896 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004897 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004898 @PackageManager.PermissionResult
4899 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004900
4901 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004902 * Determine whether <em>you</em> have been granted a particular permission.
4903 *
4904 * @param permission The name of the permission being checked.
4905 *
4906 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4907 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4908 *
4909 * @see PackageManager#checkPermission(String, String)
4910 * @see #checkCallingPermission(String)
4911 */
4912 @PackageManager.PermissionResult
4913 public abstract int checkSelfPermission(@NonNull String permission);
4914
4915 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004916 * If the given permission is not allowed for a particular process
4917 * and user ID running in the system, throw a {@link SecurityException}.
4918 *
4919 * @param permission The name of the permission being checked.
4920 * @param pid The process ID being checked against. Must be &gt; 0.
4921 * @param uid The user ID being checked against. A uid of 0 is the root
4922 * user, which will pass every permission check.
4923 * @param message A message to include in the exception if it is thrown.
4924 *
4925 * @see #checkPermission(String, int, int)
4926 */
4927 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004928 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004929
4930 /**
4931 * If the calling process of an IPC you are handling has not been
4932 * granted a particular permission, throw a {@link
4933 * SecurityException}. This is basically the same as calling
4934 * {@link #enforcePermission(String, int, int, String)} with the
4935 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4936 * and {@link android.os.Binder#getCallingUid}. One important
4937 * difference is that if you are not currently processing an IPC,
4938 * this function will always throw the SecurityException. This is
4939 * done to protect against accidentally leaking permissions; you
4940 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4941 * protection.
4942 *
4943 * @param permission The name of the permission being checked.
4944 * @param message A message to include in the exception if it is thrown.
4945 *
4946 * @see #checkCallingPermission(String)
4947 */
4948 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004949 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004950
4951 /**
4952 * If neither you nor the calling process of an IPC you are
4953 * handling has been granted a particular permission, throw a
4954 * {@link SecurityException}. This is the same as {@link
4955 * #enforceCallingPermission}, except it grants your own
4956 * permissions if you are not currently processing an IPC. Use
4957 * with care!
4958 *
4959 * @param permission The name of the permission being checked.
4960 * @param message A message to include in the exception if it is thrown.
4961 *
4962 * @see #checkCallingOrSelfPermission(String)
4963 */
4964 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004965 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004966
4967 /**
4968 * Grant permission to access a specific Uri to another package, regardless
4969 * of whether that package has general permission to access the Uri's
4970 * content provider. This can be used to grant specific, temporary
4971 * permissions, typically in response to user interaction (such as the
4972 * user opening an attachment that you would like someone else to
4973 * display).
4974 *
4975 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4976 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4977 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4978 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4979 * start an activity instead of this function directly. If you use this
4980 * function directly, you should be sure to call
4981 * {@link #revokeUriPermission} when the target should no longer be allowed
4982 * to access it.
4983 *
4984 * <p>To succeed, the content provider owning the Uri must have set the
4985 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4986 * grantUriPermissions} attribute in its manifest or included the
4987 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4988 * &lt;grant-uri-permissions&gt;} tag.
4989 *
4990 * @param toPackage The package you would like to allow to access the Uri.
4991 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004992 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004993 *
4994 * @see #revokeUriPermission
4995 */
4996 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004997 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004998
4999 /**
5000 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07005001 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
5002 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07005003 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005004 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07005005 * "content://foo". It will not remove any prefix grants that exist at a
5006 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005007 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07005008 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07005009 * regular permission access to a Uri, but had received access to it through
5010 * a specific Uri permission grant, you could not revoke that grant with this
5011 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07005012 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
5013 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07005014 * (or none).</p>
5015 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07005016 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
5017 * grants matching the given Uri, for any package they had been granted to, through any
5018 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
5019 * service start, etc). That means this can be potentially dangerous to use, as it can
5020 * revoke grants that another app could be strongly expecting to stick around.</p>
5021 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005022 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005023 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005024 *
5025 * @see #grantUriPermission
5026 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07005027 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005028
5029 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07005030 * Remove permissions to access a particular content provider Uri
5031 * that were previously added with {@link #grantUriPermission} for a specific target
5032 * package. The given Uri will match all previously granted Uris that are the same or a
5033 * sub-path of the given Uri. That is, revoking "content://foo/target" will
5034 * revoke both "content://foo/target" and "content://foo/target/sub", but not
5035 * "content://foo". It will not remove any prefix grants that exist at a
5036 * higher level.
5037 *
5038 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
5039 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
5040 * and only for the package specified. Any matching grants that have happened through
5041 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
5042 * removed.</p>
5043 *
5044 * @param toPackage The package you had previously granted access to.
5045 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005046 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07005047 *
5048 * @see #grantUriPermission
5049 */
5050 public abstract void revokeUriPermission(String toPackage, Uri uri,
5051 @Intent.AccessUriMode int modeFlags);
5052
5053 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005054 * Determine whether a particular process and user ID has been granted
5055 * permission to access a specific URI. This only checks for permissions
5056 * that have been explicitly granted -- if the given process/uid has
5057 * more general access to the URI's content provider then this check will
5058 * always fail.
5059 *
5060 * @param uri The uri that is being checked.
5061 * @param pid The process ID being checked against. Must be &gt; 0.
5062 * @param uid The user ID being checked against. A uid of 0 is the root
5063 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005064 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005065 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005066 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005067 * pid/uid is allowed to access that uri, or
5068 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5069 *
5070 * @see #checkCallingUriPermission
5071 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005072 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005073 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005074 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005075 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005076
Dianne Hackbornff170242014-11-19 10:59:01 -08005077 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005078 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08005079 public abstract int checkUriPermission(Uri uri, int pid, int uid,
5080 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
5081
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005082 /**
5083 * Determine whether the calling process and user ID has been
5084 * granted permission to access a specific URI. This is basically
5085 * the same as calling {@link #checkUriPermission(Uri, int, int,
5086 * int)} with the pid and uid returned by {@link
5087 * android.os.Binder#getCallingPid} and {@link
5088 * android.os.Binder#getCallingUid}. One important difference is
5089 * that if you are not currently processing an IPC, this function
5090 * will always fail.
5091 *
5092 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005093 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005094 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005095 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005096 * is allowed to access that uri, or
5097 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5098 *
5099 * @see #checkUriPermission(Uri, int, int, int)
5100 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005101 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005102 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07005103 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005104
5105 /**
5106 * Determine whether the calling process of an IPC <em>or you</em> has been granted
5107 * permission to access a specific URI. This is the same as
5108 * {@link #checkCallingUriPermission}, except it grants your own permissions
5109 * if you are not currently processing an IPC. Use with care!
5110 *
5111 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005112 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005113 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005114 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005115 * is allowed to access that uri, or
5116 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5117 *
5118 * @see #checkCallingUriPermission
5119 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005120 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005121 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005122 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005123 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005124
5125 /**
5126 * Check both a Uri and normal permission. This allows you to perform
5127 * both {@link #checkPermission} and {@link #checkUriPermission} in one
5128 * call.
5129 *
5130 * @param uri The Uri whose permission is to be checked, or null to not
5131 * do this check.
5132 * @param readPermission The permission that provides overall read access,
5133 * or null to not do this check.
5134 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005135 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005136 * @param pid The process ID being checked against. Must be &gt; 0.
5137 * @param uid The user ID being checked against. A uid of 0 is the root
5138 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005139 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005140 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005141 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005142 * is allowed to access that uri or holds one of the given permissions, or
5143 * {@link PackageManager#PERMISSION_DENIED} if it is not.
5144 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08005145 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005146 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07005147 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
5148 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005149 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005150
5151 /**
5152 * If a particular process and user ID has not been granted
5153 * permission to access a specific URI, throw {@link
5154 * SecurityException}. This only checks for permissions that have
5155 * been explicitly granted -- if the given process/uid has more
5156 * general access to the URI's content provider then this check
5157 * will always fail.
5158 *
5159 * @param uri The uri that is being checked.
5160 * @param pid The process ID being checked against. Must be &gt; 0.
5161 * @param uid The user ID being checked against. A uid of 0 is the root
5162 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005163 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005164 * @param message A message to include in the exception if it is thrown.
5165 *
5166 * @see #checkUriPermission(Uri, int, int, int)
5167 */
5168 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005169 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005170
5171 /**
5172 * If the calling process and user ID has not been granted
5173 * permission to access a specific URI, throw {@link
5174 * SecurityException}. This is basically the same as calling
5175 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
5176 * the pid and uid returned by {@link
5177 * android.os.Binder#getCallingPid} and {@link
5178 * android.os.Binder#getCallingUid}. One important difference is
5179 * that if you are not currently processing an IPC, this function
5180 * will always throw a SecurityException.
5181 *
5182 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005183 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005184 * @param message A message to include in the exception if it is thrown.
5185 *
5186 * @see #checkCallingUriPermission(Uri, int)
5187 */
5188 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005189 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005190
5191 /**
5192 * If the calling process of an IPC <em>or you</em> has not been
5193 * granted permission to access a specific URI, throw {@link
5194 * SecurityException}. This is the same as {@link
5195 * #enforceCallingUriPermission}, except it grants your own
5196 * permissions if you are not currently processing an IPC. Use
5197 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07005198 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005199 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005200 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005201 * @param message A message to include in the exception if it is thrown.
5202 *
5203 * @see #checkCallingOrSelfUriPermission(Uri, int)
5204 */
5205 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07005206 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005207
5208 /**
5209 * Enforce both a Uri and normal permission. This allows you to perform
5210 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
5211 * call.
Scott Main4b5da682010-10-21 11:49:12 -07005212 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005213 * @param uri The Uri whose permission is to be checked, or null to not
5214 * do this check.
5215 * @param readPermission The permission that provides overall read access,
5216 * or null to not do this check.
5217 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07005218 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005219 * @param pid The process ID being checked against. Must be &gt; 0.
5220 * @param uid The user ID being checked against. A uid of 0 is the root
5221 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06005222 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005223 * @param message A message to include in the exception if it is thrown.
5224 *
5225 * @see #checkUriPermission(Uri, String, String, int, int, int)
5226 */
5227 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07005228 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07005229 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07005230 @Nullable String message);
5231
5232 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005233 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
5234 CONTEXT_INCLUDE_CODE,
5235 CONTEXT_IGNORE_SECURITY,
5236 CONTEXT_RESTRICTED,
5237 CONTEXT_DEVICE_PROTECTED_STORAGE,
5238 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
5239 CONTEXT_REGISTER_PACKAGE,
5240 })
Tor Norbyed9273d62013-05-30 15:59:53 -07005241 @Retention(RetentionPolicy.SOURCE)
5242 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005243
5244 /**
5245 * Flag for use with {@link #createPackageContext}: include the application
5246 * code with the context. This means loading code into the caller's
5247 * process, so that {@link #getClassLoader()} can be used to instantiate
5248 * the application's classes. Setting this flags imposes security
5249 * restrictions on what application context you can access; if the
5250 * requested application can not be safely loaded into your process,
5251 * java.lang.SecurityException will be thrown. If this flag is not set,
5252 * there will be no restrictions on the packages that can be loaded,
5253 * but {@link #getClassLoader} will always return the default system
5254 * class loader.
5255 */
5256 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
5257
5258 /**
5259 * Flag for use with {@link #createPackageContext}: ignore any security
5260 * restrictions on the Context being requested, allowing it to always
5261 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
5262 * to be loaded into a process even when it isn't safe to do so. Use
5263 * with extreme care!
5264 */
5265 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07005266
Romain Guy870e09f2009-07-06 16:35:25 -07005267 /**
5268 * Flag for use with {@link #createPackageContext}: a restricted context may
5269 * disable specific features. For instance, a View associated with a restricted
5270 * context would ignore particular XML attributes.
5271 */
5272 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005273
5274 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005275 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005276 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005277 *
5278 * @hide
5279 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005280 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005281
5282 /**
5283 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005284 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005285 *
5286 * @hide
5287 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005288 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005289
5290 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07005291 * @hide Used to indicate we should tell the activity manager about the process
5292 * loading this code.
5293 */
5294 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
5295
5296 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005297 * Return a new Context object for the given application name. This
5298 * Context is the same as what the named application gets when it is
5299 * launched, containing the same resources and class loader. Each call to
5300 * this method returns a new instance of a Context object; Context objects
5301 * are not shared, however they share common state (Resources, ClassLoader,
5302 * etc) so the Context instance itself is fairly lightweight.
5303 *
Jeff Brown6e539312015-02-24 18:53:21 -08005304 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005305 * application with the given package name.
5306 *
5307 * <p>Throws {@link java.lang.SecurityException} if the Context requested
5308 * can not be loaded into the caller's process for security reasons (see
5309 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
5310 *
5311 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005312 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005313 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005314 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005315 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005316 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005317 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04005318 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005319 */
5320 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07005321 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07005322
5323 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07005324 * Similar to {@link #createPackageContext(String, int)}, but with a
5325 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5326 * will open any {@link Uri} as the given user.
5327 *
5328 * @hide
5329 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08005330 @SystemApi
Jeff Sharkeyec5f7d12018-08-08 09:15:04 -06005331 @TestApi
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005332 @NonNull
Patrick Baumannef4c4072018-02-01 08:54:05 -08005333 public Context createPackageContextAsUser(
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005334 @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08005335 throws PackageManager.NameNotFoundException {
5336 if (Build.IS_ENG) {
5337 throw new IllegalStateException("createPackageContextAsUser not overridden!");
5338 }
5339 return this;
5340 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07005341
5342 /**
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005343 * Similar to {@link #createPackageContext(String, int)}, but for the own package with a
5344 * different {@link UserHandle}. For example, {@link #getContentResolver()}
5345 * will open any {@link Uri} as the given user.
5346 *
5347 * @hide
5348 */
5349 @SystemApi
5350 @TestApi
5351 @NonNull
Makoto Onuki6b1e9d22019-10-11 20:19:58 -07005352 public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
Makoto Onuki9432f7d2019-10-09 15:33:11 -07005353 if (Build.IS_ENG) {
5354 throw new IllegalStateException("createContextAsUser not overridden!");
5355 }
5356 return this;
5357 }
5358
5359 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07005360 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
5361 *
5362 * @hide
5363 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +01005364 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07005365 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06005366 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07005367
5368 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08005369 * Return a new Context object for the given split name. The new Context has a ClassLoader and
5370 * Resources object that can access the split's and all of its dependencies' code/resources.
5371 * Each call to this method returns a new instance of a Context object;
5372 * Context objects are not shared, however common state (ClassLoader, other Resources for
5373 * the same split) may be so the Context itself can be fairly lightweight.
5374 *
5375 * @param splitName The name of the split to include, as declared in the split's
5376 * <code>AndroidManifest.xml</code>.
5377 * @return A {@link Context} with the given split's code and/or resources loaded.
5378 */
5379 public abstract Context createContextForSplit(String splitName)
5380 throws PackageManager.NameNotFoundException;
5381
5382 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005383 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08005384 * @hide
5385 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07005386 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005387 public UserHandle getUser() {
5388 return android.os.Process.myUserHandle();
5389 }
5390
5391 /**
5392 * Get the user associated with this context
5393 * @hide
5394 */
Artur Satayev5a525852019-10-31 15:15:50 +00005395 @UnsupportedAppUsage
Jeff Sharkeyad357d12018-02-02 13:25:31 -07005396 @TestApi
5397 public @UserIdInt int getUserId() {
5398 return android.os.UserHandle.myUserId();
5399 }
Jim Millera75a8832013-02-07 16:53:32 -08005400
5401 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07005402 * Return a new Context object for the current Context but whose resources
5403 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07005404 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07005405 * shared, however common state (ClassLoader, other Resources for the
5406 * same configuration) may be so the Context itself can be fairly lightweight.
5407 *
5408 * @param overrideConfiguration A {@link Configuration} specifying what
5409 * values to modify in the base Configuration of the original Context's
5410 * resources. If the base configuration changes (such as due to an
5411 * orientation change), the resources of this context will also change except
5412 * for those that have been explicitly overridden with a value here.
5413 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005414 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07005415 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005416 public abstract Context createConfigurationContext(
5417 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07005418
5419 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07005420 * Return a new Context object for the current Context but whose resources
5421 * are adjusted to match the metrics of the given Display. Each call to this method
5422 * returns a new instance of a Context object; Context objects are not
5423 * shared, however common state (ClassLoader, other Resources for the
5424 * same configuration) may be so the Context itself can be fairly lightweight.
5425 *
5426 * The returned display Context provides a {@link WindowManager}
5427 * (see {@link #getSystemService(String)}) that is configured to show windows
5428 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
5429 * method can be used to retrieve the Display from the returned Context.
5430 *
5431 * @param display A {@link Display} object specifying the display
5432 * for whose metrics the Context's resources should be tailored and upon which
5433 * new windows should be shown.
5434 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005435 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07005436 */
Tor Norbyed9273d62013-05-30 15:59:53 -07005437 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07005438
5439 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005440 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005441 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005442 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005443 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005444 * with a key tied to the physical device, and it can be accessed
5445 * immediately after the device has booted successfully, both
5446 * <em>before and after</em> the user has authenticated with their
5447 * credentials (such as a lock pattern or PIN).
5448 * <p>
5449 * Because device-protected data is available without user authentication,
5450 * you should carefully limit the data you store using this Context. For
5451 * example, storing sensitive authentication tokens or passwords in the
5452 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005453 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005454 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005455 * device-protected and credential-protected data using different keys, then
5456 * both storage areas will become available at the same time. They remain as
5457 * two distinct storage locations on disk, and only the window of
5458 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005459 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005460 * Each call to this method returns a new instance of a Context object;
5461 * Context objects are not shared, however common state (ClassLoader, other
5462 * Resources for the same configuration) may be so the Context itself can be
5463 * fairly lightweight.
5464 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005465 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005466 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005467 public abstract Context createDeviceProtectedStorageContext();
5468
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005469 /**
5470 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005471 * APIs are backed by credential-protected storage. This is the default
5472 * storage area for apps unless
5473 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005474 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06005475 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005476 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005477 * <em>only after</em> the user has entered their credentials (such as a
5478 * lock pattern or PIN).
5479 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005480 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005481 * device-protected and credential-protected data using different keys, then
5482 * both storage areas will become available at the same time. They remain as
5483 * two distinct storage locations on disk, and only the window of
5484 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07005485 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005486 * Each call to this method returns a new instance of a Context object;
5487 * Context objects are not shared, however common state (ClassLoader, other
5488 * Resources for the same configuration) may be so the Context itself can be
5489 * fairly lightweight.
5490 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005491 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005492 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005493 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005494 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005495 public abstract Context createCredentialProtectedStorageContext();
5496
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005497 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07005498 * Gets the display adjustments holder for this context. This information
5499 * is provided on a per-application or activity basis and is used to simulate lower density
5500 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07005501 *
Jeff Browna492c3a2012-08-23 19:48:44 -07005502 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07005503 * @return The compatibility info holder, or null if not required by the application.
5504 * @hide
5505 */
Craig Mautner48d0d182013-06-11 07:53:06 -07005506 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07005507
5508 /**
Wale Ogunwale691af682019-02-11 03:09:10 -08005509 * @return Returns the {@link Display} object this context is associated with.
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005510 * @hide
5511 */
Artur Satayev5a525852019-10-31 15:15:50 +00005512 @UnsupportedAppUsage
Wale Ogunwale691af682019-02-11 03:09:10 -08005513 @TestApi
Adam Lesinski4ece3d62016-06-16 18:05:41 -07005514 public abstract Display getDisplay();
5515
5516 /**
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005517 * Gets the display ID.
5518 *
5519 * @return display ID associated with this {@link Context}.
5520 * @hide
5521 */
wilsonshih5db7b392019-02-20 23:08:45 +08005522 @TestApi
Yohei Yukawa5281b6b2018-10-15 07:38:25 +08005523 public abstract int getDisplayId();
5524
5525 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08005526 * @hide
5527 */
5528 public abstract void updateDisplay(int displayId);
5529
5530 /**
Romain Guy870e09f2009-07-06 16:35:25 -07005531 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07005532 *
John Spurlock6098c5d2013-06-17 10:32:46 -04005533 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07005534 *
Romain Guy870e09f2009-07-06 16:35:25 -07005535 * @see #CONTEXT_RESTRICTED
5536 */
5537 public boolean isRestricted() {
5538 return false;
5539 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005540
5541 /**
5542 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005543 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005544 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005545 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005546 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005547 public abstract boolean isDeviceProtectedStorage();
5548
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005549 /**
5550 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005551 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005552 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005553 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005554 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07005555 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005556 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005557 public abstract boolean isCredentialProtectedStorage();
5558
Tony Mak46aabe52016-11-14 12:53:06 +00005559 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005560 * Returns true if the context can load unsafe resources, e.g. fonts.
5561 * @hide
5562 */
5563 public abstract boolean canLoadUnsafeResources();
5564
5565 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005566 * @hide
5567 */
5568 public IBinder getActivityToken() {
5569 throw new RuntimeException("Not implemented. Must override in a subclass.");
5570 }
5571
5572 /**
5573 * @hide
5574 */
5575 @Nullable
5576 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
5577 int flags) {
5578 throw new RuntimeException("Not implemented. Must override in a subclass.");
5579 }
5580
5581 /**
5582 * @hide
5583 */
5584 public IApplicationThread getIApplicationThread() {
5585 throw new RuntimeException("Not implemented. Must override in a subclass.");
5586 }
Tony Makbf9928d2016-12-22 11:02:45 +00005587
5588 /**
5589 * @hide
5590 */
5591 public Handler getMainThreadHandler() {
5592 throw new RuntimeException("Not implemented. Must override in a subclass.");
5593 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07005594
5595 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07005596 * @hide
5597 */
5598 public AutofillClient getAutofillClient() {
5599 return null;
5600 }
5601
5602 /**
5603 * @hide
5604 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005605 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005606 }
5607
5608 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005609 * @hide
5610 */
Felipe Lemecbf7f262019-04-17 13:57:59 -07005611 @Nullable
5612 public ContentCaptureClient getContentCaptureClient() {
5613 return null;
5614 }
5615
5616 /**
5617 * @hide
5618 */
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005619 public final boolean isAutofillCompatibilityEnabled() {
5620 final AutofillOptions options = getAutofillOptions();
5621 return options != null && options.compatModeEnabled;
5622 }
5623
5624 /**
5625 * @hide
5626 */
5627 @Nullable
5628 public AutofillOptions getAutofillOptions() {
5629 return null;
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005630 }
5631
5632 /**
5633 * @hide
5634 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005635 @TestApi
Felipe Lemea4f39cd2019-02-19 15:08:59 -08005636 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005637 }
5638
5639 /**
Felipe Leme326f15a2019-02-19 09:42:24 -08005640 * Gets the Content Capture options for this context, or {@code null} if it's not whitelisted.
Felipe Lemeecb08be2018-11-27 15:48:47 -08005641 *
5642 * @hide
5643 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005644 @Nullable
5645 public ContentCaptureOptions getContentCaptureOptions() {
5646 return null;
Felipe Lemeecb08be2018-11-27 15:48:47 -08005647 }
5648
5649 /**
5650 * @hide
5651 */
Felipe Leme326f15a2019-02-19 09:42:24 -08005652 @TestApi
5653 public void setContentCaptureOptions(
5654 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
Felipe Lemeecb08be2018-11-27 15:48:47 -08005655 }
5656
5657 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005658 * Throws an exception if the Context is using system resources,
5659 * which are non-runtime-overlay-themable and may show inconsistent UI.
5660 * @hide
5661 */
5662 public void assertRuntimeOverlayThemable() {
5663 // Resources.getSystem() is a singleton and the only Resources not managed by
5664 // ResourcesManager; therefore Resources.getSystem() is not themable.
5665 if (getResources() == Resources.getSystem()) {
5666 throw new IllegalArgumentException("Non-UI context used to display UI; "
5667 + "get a UI context from ActivityThread#getSystemUiContext()");
5668 }
5669 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005670}