blob: aaa3879503fad3fb0899de203503bc512c079725 [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;
Tor Norbye1c2bf032015-03-02 10:57:08 -080020import android.annotation.CheckResult;
Tor Norbye3e4cda72015-06-10 08:14:31 -070021import android.annotation.ColorInt;
22import android.annotation.ColorRes;
23import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070024import android.annotation.IntDef;
25import android.annotation.NonNull;
26import android.annotation.Nullable;
Tor Norbye788fc2b2015-07-05 16:10:42 -070027import android.annotation.RequiresPermission;
Tor Norbyed9273d62013-05-30 15:59:53 -070028import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070029import android.annotation.StringRes;
30import android.annotation.StyleRes;
31import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090032import android.annotation.SystemApi;
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -070033import android.annotation.TestApi;
Mathew Inwood1c77a112018-08-14 14:06:26 +010034import android.annotation.UnsupportedAppUsage;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070035import android.annotation.UserIdInt;
Selim Cinek7fa385a2018-01-24 08:35:28 -080036import android.app.ActivityManager;
Tony Mak46aabe52016-11-14 12:53:06 +000037import android.app.IApplicationThread;
38import android.app.IServiceConnection;
Zak Cohen56345f42017-01-26 13:54:28 -080039import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070040import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.content.pm.PackageManager;
42import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080043import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070044import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.content.res.Resources;
46import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070047import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.database.sqlite.SQLiteDatabase;
49import android.database.sqlite.SQLiteDatabase.CursorFactory;
50import android.graphics.Bitmap;
51import android.graphics.drawable.Drawable;
Remi NGUYEN VANc094a542018-12-07 16:52:24 +090052import android.net.NetworkStack;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.net.Uri;
Patrick Baumannef4c4072018-02-01 08:54:05 -080054import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070056import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.os.Handler;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070058import android.os.HandlerExecutor;
Dianne Hackbornff170242014-11-19 10:59:01 -080059import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070061import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070062import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070063import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060064import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070065import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070067import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070068import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070069import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070070import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070071import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070072import android.view.autofill.AutofillManager.AutofillClient;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000073import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074
75import java.io.File;
76import java.io.FileInputStream;
77import java.io.FileNotFoundException;
78import java.io.FileOutputStream;
79import java.io.IOException;
80import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070081import java.lang.annotation.Retention;
82import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070083import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084
85/**
86 * Interface to global information about an application environment. This is
87 * an abstract class whose implementation is provided by
88 * the Android system. It
89 * allows access to application-specific resources and classes, as well as
90 * up-calls for application-level operations such as launching activities,
91 * broadcasting and receiving intents, etc.
92 */
93public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060094 /** @hide */
95 @IntDef(flag = true, prefix = { "MODE_" }, value = {
96 MODE_PRIVATE,
97 MODE_WORLD_READABLE,
98 MODE_WORLD_WRITEABLE,
99 MODE_APPEND,
100 })
101 @Retention(RetentionPolicy.SOURCE)
102 public @interface FileMode {}
103
104 /** @hide */
105 @IntDef(flag = true, prefix = { "MODE_" }, value = {
106 MODE_PRIVATE,
107 MODE_WORLD_READABLE,
108 MODE_WORLD_WRITEABLE,
109 MODE_MULTI_PROCESS,
110 })
111 @Retention(RetentionPolicy.SOURCE)
112 public @interface PreferencesMode {}
113
114 /** @hide */
115 @IntDef(flag = true, prefix = { "MODE_" }, value = {
116 MODE_PRIVATE,
117 MODE_WORLD_READABLE,
118 MODE_WORLD_WRITEABLE,
119 MODE_ENABLE_WRITE_AHEAD_LOGGING,
120 MODE_NO_LOCALIZED_COLLATORS,
121 })
122 @Retention(RetentionPolicy.SOURCE)
123 public @interface DatabaseMode {}
124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 /**
126 * File creation mode: the default mode, where the created file can only
127 * be accessed by the calling application (or all applications sharing the
128 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 */
130 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700133 * File creation mode: allow all other applications to have read access to
134 * the created file.
135 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700136 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
137 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700138 *
Nick Kralevich15069212013-01-09 15:54:56 -0800139 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700140 * to cause security holes in applications. It is strongly
141 * discouraged; instead, applications should use more formal
142 * mechanism for interactions such as {@link ContentProvider},
143 * {@link BroadcastReceiver}, and {@link android.app.Service}.
144 * There are no guarantees that this access mode will remain on
145 * a file, such as when it goes through a backup and restore.
146 * @see android.support.v4.content.FileProvider
147 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700149 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700151
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700153 * File creation mode: allow all other applications to have write access to
154 * the created file.
155 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700156 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700157 * mode will throw a {@link SecurityException}.
158 *
Nick Kralevich15069212013-01-09 15:54:56 -0800159 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700160 * to cause security holes in applications. It is strongly
161 * discouraged; instead, applications should use more formal
162 * mechanism for interactions such as {@link ContentProvider},
163 * {@link BroadcastReceiver}, and {@link android.app.Service}.
164 * There are no guarantees that this access mode will remain on
165 * a file, such as when it goes through a backup and restore.
166 * @see android.support.v4.content.FileProvider
167 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700169 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700171
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800172 /**
173 * File creation mode: for use with {@link #openFileOutput}, if the file
174 * already exists then write data to the end of the existing file
175 * instead of erasing it.
176 * @see #openFileOutput
177 */
178 public static final int MODE_APPEND = 0x8000;
179
180 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800181 * SharedPreference loading flag: when set, the file on disk will
182 * be checked for modification even if the shared preferences
183 * instance is already loaded in this process. This behavior is
184 * sometimes desired in cases where the application has multiple
185 * processes, all writing to the same SharedPreferences file.
186 * Generally there are better forms of communication between
187 * processes, though.
188 *
189 * <p>This was the legacy (but undocumented) behavior in and
190 * before Gingerbread (Android 2.3) and this flag is implied when
kopriva219f7dc2018-10-09 13:42:28 -0700191 * targeting such releases. For applications targeting SDK
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800192 * versions <em>greater than</em> Android 2.3, this flag must be
193 * explicitly set if desired.
194 *
195 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700196 *
197 * @deprecated MODE_MULTI_PROCESS does not work reliably in
198 * some versions of Android, and furthermore does not provide any
199 * mechanism for reconciling concurrent modifications across
200 * processes. Applications should not attempt to use it. Instead,
201 * they should use an explicit cross-process data management
202 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800203 */
Christopher Tated5748b82015-05-08 18:14:01 -0700204 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800205 public static final int MODE_MULTI_PROCESS = 0x0004;
206
207 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700208 * Database open flag: when set, the database is opened with write-ahead
209 * logging enabled by default.
210 *
211 * @see #openOrCreateDatabase(String, int, CursorFactory)
212 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
213 * @see SQLiteDatabase#enableWriteAheadLogging
214 */
215 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
216
Sunny Goyala21e6b22015-12-02 09:51:02 -0800217 /**
218 * Database open flag: when set, the database is opened without support for
219 * localized collators.
220 *
221 * @see #openOrCreateDatabase(String, int, CursorFactory)
222 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
223 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
224 */
225 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
226
Tor Norbyed9273d62013-05-30 15:59:53 -0700227 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700228 @IntDef(flag = true, prefix = { "BIND_" }, value = {
229 BIND_AUTO_CREATE,
230 BIND_DEBUG_UNBIND,
231 BIND_NOT_FOREGROUND,
232 BIND_ABOVE_CLIENT,
233 BIND_ALLOW_OOM_MANAGEMENT,
234 BIND_WAIVE_PRIORITY,
235 BIND_IMPORTANT,
236 BIND_ADJUST_WITH_ACTIVITY
237 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700238 @Retention(RetentionPolicy.SOURCE)
239 public @interface BindServiceFlags {}
240
Jeff Brown47847f32012-03-22 19:13:11 -0700241 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800242 * Flag for {@link #bindService}: automatically create the service as long
243 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700244 * its {@link android.app.Service#onStartCommand}
245 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 * explicit call to {@link #startService}. Even without that, though,
247 * this still provides you with access to the service object while the
248 * service is created.
249 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700250 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
251 * not supplying this flag would also impact how important the system
252 * consider's the target service's process to be. When set, the only way
253 * for it to be raised was by binding from a service in which case it will
254 * only be important when that activity is in the foreground. Now to
255 * achieve this behavior you must explicitly supply the new flag
256 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
257 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
258 * the flags {@link #BIND_WAIVE_PRIORITY} and
259 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
260 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 */
262 public static final int BIND_AUTO_CREATE = 0x0001;
263
264 /**
265 * Flag for {@link #bindService}: include debugging help for mismatched
266 * calls to unbind. When this flag is set, the callstack of the following
267 * {@link #unbindService} call is retained, to be printed if a later
268 * incorrect unbind call is made. Note that doing this requires retaining
269 * information about the binding that was made for the lifetime of the app,
270 * resulting in a leak -- this should only be used for debugging.
271 */
272 public static final int BIND_DEBUG_UNBIND = 0x0002;
273
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800274 /**
275 * Flag for {@link #bindService}: don't allow this binding to raise
276 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700277 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800278 * as the client (so that its process will not be killable in any
279 * situation where the client is not killable), but for CPU scheduling
280 * purposes it may be left in the background. This only has an impact
281 * in the situation where the binding client is a foreground process
282 * and the target service is in a background process.
283 */
284 public static final int BIND_NOT_FOREGROUND = 0x0004;
285
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700286 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700287 * Flag for {@link #bindService}: indicates that the client application
288 * binding to this service considers the service to be more important than
289 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700290 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700291 * this is not guaranteed to be the case.
292 */
293 public static final int BIND_ABOVE_CLIENT = 0x0008;
294
295 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700296 * Flag for {@link #bindService}: allow the process hosting the bound
297 * service to go through its normal memory management. It will be
298 * treated more like a running service, allowing the system to
299 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700300 * whim it may have, and being more aggressive about making it a candidate
301 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700302 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700303 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
304
305 /**
306 * Flag for {@link #bindService}: don't impact the scheduling or
307 * memory management priority of the target service's hosting process.
308 * Allows the service's process to be managed on the background LRU list
309 * just like a regular application process in the background.
310 */
311 public static final int BIND_WAIVE_PRIORITY = 0x0020;
312
313 /**
314 * Flag for {@link #bindService}: this service is very important to
315 * the client, so should be brought to the foreground process level
316 * when the client is. Normally a process can only be raised to the
317 * visibility level by a client, even if that client is in the foreground.
318 */
319 public static final int BIND_IMPORTANT = 0x0040;
320
321 /**
322 * Flag for {@link #bindService}: If binding from an activity, allow the
323 * target service's process importance to be raised based on whether the
324 * activity is visible to the user, regardless whether another flag is
325 * used to reduce the amount that the client process's overall importance
326 * is used to impact it.
327 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700328 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
329
330 /**
Amith Yamasanib7358302018-09-05 18:52:35 -0700331 * Flag for {@link #bindService}: If binding from something better than perceptible,
332 * still set the adjust below perceptible. This would be used for bound services that can
333 * afford to be evicted when under extreme memory pressure, but should be restarted as soon
334 * as possible.
335 * @hide
336 */
337 public static final int BIND_ADJUST_BELOW_PERCEPTIBLE = 0x0100;
338
339 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800340 * @hide Flag for {@link #bindService}: allows binding to a service provided
341 * by an instant app. Note that the caller may not have access to the instant
342 * app providing the service which is a violation of the instant app sandbox.
343 * This flag is intended ONLY for development/testing and should be used with
344 * great care. Only the system is allowed to use this flag.
345 */
346 public static final int BIND_ALLOW_INSTANT = 0x00400000;
347
348 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700349 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
350 * up in to the important background state (instead of transient).
351 */
352 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
353
354 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700355 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
356 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
357 */
358 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
359
360 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700361 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
362 * but only applies while the device is awake.
363 */
364 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
365
366 /**
367 * @hide Flag for {@link #bindService}: For only the case where the binding
368 * is coming from the system, set the process state to FOREGROUND_SERVICE
369 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
370 * saying that the process shouldn't participate in the normal power reduction
371 * modes (removing network access etc).
372 */
373 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
374
375 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700376 * @hide Flag for {@link #bindService}: Treat the binding as hosting
377 * an activity, an unbinding as the activity going in the background.
378 * That is, when unbinding, the process when empty will go on the activity
379 * LRU list instead of the regular one, keeping it around more aggressively
380 * than it otherwise would be. This is intended for use with IMEs to try
381 * to keep IME processes around for faster keyboard switching.
382 */
383 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
384
385 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700386 * @hide An idea that is not yet implemented.
387 * Flag for {@link #bindService}: If binding from an activity, consider
388 * this service to be visible like the binding activity is. That is,
389 * it will be treated as something more important to keep around than
390 * invisible background activities. This will impact the number of
391 * recent activities the user can switch between without having them
392 * restart. There is no guarantee this will be respected, as the system
393 * tries to balance such requests from one app vs. the importantance of
394 * keeping other apps around.
395 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700396 public static final int BIND_VISIBLE = 0x10000000;
397
398 /**
399 * @hide
400 * Flag for {@link #bindService}: Consider this binding to be causing the target
401 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
402 * away.
403 */
404 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700405
406 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700407 * Flag for {@link #bindService}: Don't consider the bound service to be
408 * visible, even if the caller is visible.
409 * @hide
410 */
411 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700412
Alan Viverette713a5cd2015-12-16 15:46:32 -0500413 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500414 * Flag for {@link #bindService}: The service being bound is an
415 * {@link android.R.attr#isolatedProcess isolated},
416 * {@link android.R.attr#externalService external} service. This binds the service into the
417 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400418 * <p>
419 * When using this flag, the code for the service being bound will execute under the calling
420 * application's package name and user ID. Because the service must be an isolated process,
421 * it will not have direct access to the application's data, though.
422 *
423 * The purpose of this flag is to allow applications to provide services that are attributed
424 * to the app using the service, rather than the application providing the service.
425 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500426 */
427 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
428
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700429 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700430 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
431 RECEIVER_VISIBLE_TO_INSTANT_APPS
432 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700433 @Retention(RetentionPolicy.SOURCE)
434 public @interface RegisterReceiverFlags {}
435
436 /**
437 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
438 */
439 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
440
Robert Sesekb9a86662015-12-09 16:22:45 -0500441 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500442 * Returns an AssetManager instance for the application's package.
443 * <p>
444 * <strong>Note:</strong> Implementations of this method should return
445 * an AssetManager instance that is consistent with the Resources instance
446 * returned by {@link #getResources()}. For example, they should share the
447 * same {@link Configuration} object.
448 *
449 * @return an AssetManager instance for the application's package
450 * @see #getResources()
451 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 public abstract AssetManager getAssets();
453
Alan Viverette713a5cd2015-12-16 15:46:32 -0500454 /**
455 * Returns a Resources instance for the application's package.
456 * <p>
457 * <strong>Note:</strong> Implementations of this method should return
458 * a Resources instance that is consistent with the AssetManager instance
459 * returned by {@link #getAssets()}. For example, they should share the
460 * same {@link Configuration} object.
461 *
462 * @return a Resources instance for the application's package
463 * @see #getAssets()
464 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 public abstract Resources getResources();
466
467 /** Return PackageManager instance to find global package information. */
468 public abstract PackageManager getPackageManager();
469
470 /** Return a ContentResolver instance for your application's package. */
471 public abstract ContentResolver getContentResolver();
472
473 /**
474 * Return the Looper for the main thread of the current process. This is
475 * the thread used to dispatch calls to application components (activities,
476 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700477 * <p>
478 * By definition, this method returns the same result as would be obtained
479 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
480 * </p>
481 *
482 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 */
484 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700487 * Return an {@link Executor} that will run enqueued tasks on the main
488 * thread associated with this context. This is the thread used to dispatch
489 * calls to application components (activities, services, etc).
490 */
491 public Executor getMainExecutor() {
492 // This is pretty inefficient, which is why ContextImpl overrides it
493 return new HandlerExecutor(new Handler(getMainLooper()));
494 }
495
496 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800497 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800498 * current process. This generally should only be used if you need a
499 * Context whose lifecycle is separate from the current context, that is
500 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700501 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800502 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800503 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800504 * <ul>
505 * <li> <p>If used from an Activity context, the receiver is being registered
506 * within that activity. This means that you are expected to unregister
507 * before the activity is done being destroyed; in fact if you do not do
508 * so, the framework will clean up your leaked registration as it removes
509 * the activity and log an error. Thus, if you use the Activity context
510 * to register a receiver that is static (global to the process, not
511 * associated with an Activity instance) then that registration will be
512 * removed on you at whatever point the activity you used is destroyed.
513 * <li> <p>If used from the Context returned here, the receiver is being
514 * registered with the global state associated with your application. Thus
515 * it will never be unregistered for you. This is necessary if the receiver
516 * is associated with static data, not a particular component. However
517 * using the ApplicationContext elsewhere can easily lead to serious leaks
518 * if you forget to unregister, unbind, etc.
519 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 */
521 public abstract Context getApplicationContext();
522
Phil Weaver846cda932017-06-15 10:10:06 -0700523 /** Non-activity related autofill ids are unique in the app */
524 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700525
526 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700527 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700528 *
Phil Weaver846cda932017-06-15 10:10:06 -0700529 * <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 -0700530 * returned will be unique.
531 *
532 * @return A ID that is unique in the process
533 *
534 * {@hide}
535 */
Phil Weaver846cda932017-06-15 10:10:06 -0700536 public int getNextAutofillId() {
537 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
538 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700539 }
540
Phil Weaver846cda932017-06-15 10:10:06 -0700541 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700542
Phil Weaver846cda932017-06-15 10:10:06 -0700543 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700544 }
545
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800546 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700547 * Add a new {@link ComponentCallbacks} to the base application of the
548 * Context, which will be called at the same times as the ComponentCallbacks
549 * methods of activities and other components are called. Note that you
550 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
551 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700552 *
553 * @param callback The interface to call. This can be either a
554 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700555 */
556 public void registerComponentCallbacks(ComponentCallbacks callback) {
557 getApplicationContext().registerComponentCallbacks(callback);
558 }
559
560 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400561 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700562 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
563 */
564 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
565 getApplicationContext().unregisterComponentCallbacks(callback);
566 }
567
568 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 * Return a localized, styled CharSequence from the application's package's
570 * default string table.
571 *
572 * @param resId Resource id for the CharSequence text
573 */
Chris Craikceb26932018-02-01 15:51:34 -0800574 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700575 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 return getResources().getText(resId);
577 }
578
579 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700580 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 * default string table.
582 *
583 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700584 * @return The string data associated with the resource, stripped of styled
585 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700587 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700588 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 return getResources().getString(resId);
590 }
591
592 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700593 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 * default string table, substituting the format arguments as defined in
595 * {@link java.util.Formatter} and {@link java.lang.String#format}.
596 *
597 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700598 * @param formatArgs The format arguments that will be used for
599 * substitution.
600 * @return The string data associated with the resource, formatted and
601 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700603 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700604 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800605 return getResources().getString(resId, formatArgs);
606 }
607
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800608 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800609 * Returns a color associated with a particular resource ID and styled for
610 * the current theme.
611 *
612 * @param id The desired resource identifier, as generated by the aapt
613 * tool. This integer encodes the package, type, and resource
614 * entry. The value 0 is an invalid identifier.
615 * @return A single color value in the form 0xAARRGGBB.
616 * @throws android.content.res.Resources.NotFoundException if the given ID
617 * does not exist.
618 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700619 @ColorInt
620 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800621 return getResources().getColor(id, getTheme());
622 }
623
624 /**
625 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800626 * styled for the current theme.
627 *
628 * @param id The desired resource identifier, as generated by the aapt
629 * tool. This integer encodes the package, type, and resource
630 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800631 * @return An object that can be used to draw this resource.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800632 * @throws android.content.res.Resources.NotFoundException if the given ID
633 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800634 */
Chris Craik1194b0b2018-03-23 13:36:24 -0700635 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700636 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800637 return getResources().getDrawable(id, getTheme());
638 }
639
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800640 /**
641 * Returns a color state list associated with a particular resource ID and
642 * styled for the current theme.
643 *
644 * @param id The desired resource identifier, as generated by the aapt
645 * tool. This integer encodes the package, type, and resource
646 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800647 * @return A color state list.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800648 * @throws android.content.res.Resources.NotFoundException if the given ID
649 * does not exist.
650 */
Chris Craikceb26932018-02-01 15:51:34 -0800651 @NonNull
Tor Norbye3e4cda72015-06-10 08:14:31 -0700652 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800653 return getResources().getColorStateList(id, getTheme());
654 }
655
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 /**
657 * Set the base theme for this context. Note that this should be called
658 * before any views are instantiated in the Context (for example before
659 * calling {@link android.app.Activity#setContentView} or
660 * {@link android.view.LayoutInflater#inflate}).
661 *
662 * @param resid The style resource describing the theme.
663 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700664 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665
Dianne Hackborn247fe742011-01-08 17:25:57 -0800666 /** @hide Needed for some internal implementation... not public because
667 * you can't assume this actually means anything. */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100668 @UnsupportedAppUsage
Dianne Hackborn247fe742011-01-08 17:25:57 -0800669 public int getThemeResId() {
670 return 0;
671 }
672
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 /**
674 * Return the Theme object associated with this Context.
675 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700676 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 public abstract Resources.Theme getTheme();
678
679 /**
680 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800681 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 * for more information.
683 *
Jeff Brown6e539312015-02-24 18:53:21 -0800684 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800685 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700686 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 return getTheme().obtainStyledAttributes(attrs);
688 }
689
690 /**
691 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800692 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 * for more information.
694 *
Jeff Brown6e539312015-02-24 18:53:21 -0800695 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 */
697 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700698 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 return getTheme().obtainStyledAttributes(resid, attrs);
700 }
701
702 /**
703 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800704 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800705 * for more information.
706 *
Jeff Brown6e539312015-02-24 18:53:21 -0800707 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800708 */
709 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700710 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800711 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
712 }
713
714 /**
715 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800716 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 * for more information.
718 *
Jeff Brown6e539312015-02-24 18:53:21 -0800719 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 */
721 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700722 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
723 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800724 return getTheme().obtainStyledAttributes(
725 set, attrs, defStyleAttr, defStyleRes);
726 }
727
728 /**
729 * Return a class loader you can use to retrieve classes in this package.
730 */
731 public abstract ClassLoader getClassLoader();
732
733 /** Return the name of this application's package. */
734 public abstract String getPackageName();
735
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800736 /** @hide Return the name of the base context this context is derived from. */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100737 @UnsupportedAppUsage
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800738 public abstract String getBasePackageName();
739
Dianne Hackborn95d78532013-09-11 09:51:14 -0700740 /** @hide Return the package name that should be used for app ops calls from
741 * this context. This is the same as {@link #getBasePackageName()} except in
742 * cases where system components are loaded into other app processes, in which
743 * case this will be the name of the primary package in that process (so that app
744 * ops uid verification will work with the name). */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100745 @UnsupportedAppUsage
Dianne Hackborn95d78532013-09-11 09:51:14 -0700746 public abstract String getOpPackageName();
747
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700748 /** Return the full application info for this context's package. */
749 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700750
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800751 /**
Kenny Root32148392010-01-21 15:40:47 -0800752 * Return the full path to this context's primary Android package.
753 * The Android package is a ZIP file which contains the application's
754 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800755 *
756 * <p>Note: this is not generally useful for applications, since they should
757 * not be directly accessing the file system.
758 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 * @return String Path to the resources.
760 */
761 public abstract String getPackageResourcePath();
762
763 /**
Kenny Root32148392010-01-21 15:40:47 -0800764 * Return the full path to this context's primary Android package.
765 * The Android package is a ZIP file which contains application's
766 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800767 *
768 * <p>Note: this is not generally useful for applications, since they should
769 * not be directly accessing the file system.
770 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 * @return String Path to the code and assets.
772 */
773 public abstract String getPackageCodePath();
774
775 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700776 * @hide
777 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700778 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700779 @Deprecated
Mathew Inwood1c77a112018-08-14 14:06:26 +0100780 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700781 public File getSharedPrefsFile(String name) {
782 return getSharedPreferencesPath(name);
783 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700784
785 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 * Retrieve and hold the contents of the preferences file 'name', returning
787 * a SharedPreferences through which you can retrieve and modify its
788 * values. Only one instance of the SharedPreferences object is returned
789 * to any callers for the same name, meaning they will see each other's
790 * edits as soon as they are made.
791 *
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700792 * This method is thead-safe.
793 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 * @param name Desired preferences file. If a preferences file by this name
795 * does not exist, it will be created when you retrieve an
796 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600797 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400799 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800 * to retrieve and modify the preference values.
801 *
802 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800803 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600804 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700805
806 /**
807 * Retrieve and hold the contents of the preferences file, returning
808 * a SharedPreferences through which you can retrieve and modify its
809 * values. Only one instance of the SharedPreferences object is returned
810 * to any callers for the same name, meaning they will see each other's
811 * edits as soon as they are made.
812 *
813 * @param file Desired preferences file. If a preferences file by this name
814 * does not exist, it will be created when you retrieve an
815 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600816 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700817 *
818 * @return The single {@link SharedPreferences} instance that can be used
819 * to retrieve and modify the preference values.
820 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700821 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700822 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600823 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700824 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600825 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800826
827 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600828 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700829 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600830 * storage locations after an upgrade, such as moving to device protected
831 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700832 *
833 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600834 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700835 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600836 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700837 * preferences didn't exist in the source context, otherwise
838 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600839 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700840 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600841 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
842
Jeff Sharkey35871f22016-01-29 17:13:29 -0700843 /**
844 * Delete an existing shared preferences file.
845 *
846 * @param name The name (unique in the application package) of the shared
847 * preferences file.
848 * @return {@code true} if the shared preferences file was successfully
849 * deleted; else {@code false}.
850 * @see #getSharedPreferences(String, int)
851 */
852 public abstract boolean deleteSharedPreferences(String name);
853
Christopher Tatefe2368c2017-05-17 15:42:35 -0700854 /** @hide */
855 public abstract void reloadSharedPreferences();
856
Jeff Sharkey35871f22016-01-29 17:13:29 -0700857 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800858 * Open a private file associated with this Context's application package
859 * for reading.
860 *
861 * @param name The name of the file to open; can not contain path
862 * separators.
863 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400864 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800865 *
866 * @see #openFileOutput
867 * @see #fileList
868 * @see #deleteFile
869 * @see java.io.FileInputStream#FileInputStream(String)
870 */
871 public abstract FileInputStream openFileInput(String name)
872 throws FileNotFoundException;
873
874 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800875 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700876 * for writing. Creates the file if it doesn't already exist.
877 * <p>
878 * No additional permissions are required for the calling app to read or
879 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700880 *
Nick Kralevich15069212013-01-09 15:54:56 -0800881 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700882 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600883 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400884 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 * @see #MODE_APPEND
886 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800887 * @see #openFileInput
888 * @see #fileList
889 * @see #deleteFile
890 * @see java.io.FileOutputStream#FileOutputStream(String)
891 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600892 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800893 throws FileNotFoundException;
894
895 /**
896 * Delete the given private file associated with this Context's
897 * application package.
898 *
899 * @param name The name of the file to delete; can not contain path
900 * separators.
901 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400902 * @return {@code true} if the file was successfully deleted; else
903 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800904 *
905 * @see #openFileInput
906 * @see #openFileOutput
907 * @see #fileList
908 * @see java.io.File#delete()
909 */
910 public abstract boolean deleteFile(String name);
911
912 /**
913 * Returns the absolute path on the filesystem where a file created with
914 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700915 * <p>
916 * The returned path may change over time if the calling app is moved to an
917 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800918 *
919 * @param name The name of the file for which you would like to get
920 * its path.
921 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400922 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 *
924 * @see #openFileOutput
925 * @see #getFilesDir
926 * @see #getDir
927 */
928 public abstract File getFileStreamPath(String name);
929
930 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700931 * Returns the absolute path on the filesystem where a file created with
932 * {@link #getSharedPreferences(String, int)} is stored.
933 * <p>
934 * The returned path may change over time if the calling app is moved to an
935 * adopted storage device, so only relative paths should be persisted.
936 *
937 * @param name The name of the shared preferences for which you would like
938 * to get a path.
939 * @return An absolute path to the given file.
940 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600941 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700942 */
943 public abstract File getSharedPreferencesPath(String name);
944
945 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700946 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600947 * private files belonging to this app are stored. Apps should not use this
948 * path directly; they should instead use {@link #getFilesDir()},
949 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
950 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700951 * <p>
952 * The returned path may change over time if the calling app is moved to an
953 * adopted storage device, so only relative paths should be persisted.
954 * <p>
955 * No additional permissions are required for the calling app to read or
956 * write files under the returned path.
957 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600958 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700959 */
960 public abstract File getDataDir();
961
962 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700963 * Returns the absolute path to the directory on the filesystem where files
964 * created with {@link #openFileOutput} are stored.
965 * <p>
966 * The returned path may change over time if the calling app is moved to an
967 * adopted storage device, so only relative paths should be persisted.
968 * <p>
969 * No additional permissions are required for the calling app to read or
970 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700971 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400972 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800973 * @see #openFileOutput
974 * @see #getFileStreamPath
975 * @see #getDir
976 */
977 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700978
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800979 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700980 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700981 * {@link #getFilesDir()}. The difference is that files placed under this
982 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700983 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
984 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700985 * <p>
986 * The returned path may change over time if the calling app is moved to an
987 * adopted storage device, so only relative paths should be persisted.
988 * <p>
989 * No additional permissions are required for the calling app to read or
990 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700991 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700992 * @return The path of the directory holding application files that will not
993 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700994 * @see #openFileOutput
995 * @see #getFileStreamPath
996 * @see #getDir
997 * @see android.app.backup.BackupAgent
998 */
999 public abstract File getNoBackupFilesDir();
1000
1001 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001002 * Returns the absolute path to the directory on the primary shared/external
1003 * storage device where the application can place persistent files it owns.
1004 * These files are internal to the applications, and not typically visible
1005 * to the user as media.
1006 * <p>
1007 * This is like {@link #getFilesDir()} in that these files will be deleted
1008 * when the application is uninstalled, however there are some important
1009 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001010 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001011 * <li>Shared storage may not always be available, since removable media can
1012 * be ejected by the user. Media state can be checked using
1013 * {@link Environment#getExternalStorageState(File)}.
1014 * <li>There is no security enforced with these files. For example, any
1015 * application holding
1016 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001017 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001018 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001019 * <p>
1020 * If a shared storage device is emulated (as determined by
1021 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1022 * backed by a private user data partition, which means there is little
1023 * benefit to storing data here instead of the private directories returned
1024 * by {@link #getFilesDir()}, etc.
1025 * <p>
1026 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001027 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001028 * accessible to the calling app. This only applies to paths generated for
1029 * package name of the calling application. To access paths belonging to
1030 * other packages,
1031 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1032 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1033 * <p>
1034 * On devices with multiple users (as described by {@link UserManager}),
1035 * each user has their own isolated shared storage. Applications only have
1036 * access to the shared storage for the user they're running as.
1037 * <p>
1038 * The returned path may change over time if different shared storage media
1039 * is inserted, so only relative paths should be persisted.
1040 * <p>
1041 * Here is an example of typical code to manipulate a file in an
1042 * application's shared storage:
1043 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001044 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1045 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001046 * <p>
1047 * If you supply a non-null <var>type</var> to this function, the returned
1048 * file will be a path to a sub-directory of the given type. Though these
1049 * files are not automatically scanned by the media scanner, you can
1050 * explicitly add them to the media database with
1051 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1052 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001053 * {@link android.os.Environment#getExternalStoragePublicDirectory
1054 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001055 * directories of media shared by all applications. The directories returned
1056 * here are owned by the application, and their contents will be removed
1057 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001058 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001059 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1060 * here will be automatically created for you.
1061 * <p>
1062 * Here is an example of typical code to manipulate a picture in an
1063 * application's shared storage and add it to the media database:
1064 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001065 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1066 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001067 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001068 * @param type The type of files directory to return. May be {@code null}
1069 * for the root of the files directory or one of the following
1070 * constants for a subdirectory:
1071 * {@link android.os.Environment#DIRECTORY_MUSIC},
1072 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1073 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1074 * {@link android.os.Environment#DIRECTORY_ALARMS},
1075 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1076 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1077 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1078 * @return the absolute path to application-specific directory. May return
1079 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001080 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001081 * @see #getExternalFilesDirs(String)
1082 * @see Environment#getExternalStorageState(File)
1083 * @see Environment#isExternalStorageEmulated(File)
1084 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001085 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001086 @Nullable
1087 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001088
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001089 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001090 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001091 * shared/external storage devices where the application can place
1092 * persistent files it owns. These files are internal to the application,
1093 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001094 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001095 * This is like {@link #getFilesDir()} in that these files will be deleted
1096 * when the application is uninstalled, however there are some important
1097 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001098 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001099 * <li>Shared storage may not always be available, since removable media can
1100 * be ejected by the user. Media state can be checked using
1101 * {@link Environment#getExternalStorageState(File)}.
1102 * <li>There is no security enforced with these files. For example, any
1103 * application holding
1104 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1105 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001106 * </ul>
1107 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001108 * If a shared storage device is emulated (as determined by
1109 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1110 * backed by a private user data partition, which means there is little
1111 * benefit to storing data here instead of the private directories returned
1112 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001113 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001114 * Shared storage devices returned here are considered a stable part of the
1115 * device, including physical media slots under a protective cover. The
1116 * returned paths do not include transient devices, such as USB flash drives
1117 * connected to handheld devices.
1118 * <p>
1119 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001120 * example, an app may choose to store large files on the device with the
1121 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001122 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001123 * No additional permissions are required for the calling app to read or
1124 * write files under the returned path. Write access outside of these paths
1125 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001126 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001127 * The returned path may change over time if different shared storage media
1128 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001129 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001130 * @param type The type of files directory to return. May be {@code null}
1131 * for the root of the files directory or one of the following
1132 * constants for a subdirectory:
1133 * {@link android.os.Environment#DIRECTORY_MUSIC},
1134 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1135 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1136 * {@link android.os.Environment#DIRECTORY_ALARMS},
1137 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1138 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1139 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1140 * @return the absolute paths to application-specific directories. Some
1141 * individual paths may be {@code null} if that shared storage is
1142 * not currently available. The first path returned is the same as
1143 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001144 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001145 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001146 * @see Environment#isExternalStorageEmulated(File)
1147 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001148 */
1149 public abstract File[] getExternalFilesDirs(String type);
1150
1151 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001152 * Return the primary shared/external storage directory where this
1153 * application's OBB files (if there are any) can be found. Note if the
1154 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001155 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001156 * This is like {@link #getFilesDir()} in that these files will be deleted
1157 * when the application is uninstalled, however there are some important
1158 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001159 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001160 * <li>Shared storage may not always be available, since removable media can
1161 * be ejected by the user. Media state can be checked using
1162 * {@link Environment#getExternalStorageState(File)}.
1163 * <li>There is no security enforced with these files. For example, any
1164 * application holding
1165 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001166 * these files.
1167 * </ul>
1168 * <p>
1169 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001170 * are required to read or write to the path that this method returns.
1171 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1172 * to read the OBB expansion files, you must declare the
1173 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1174 * permission at runtime as follows:
1175 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001176 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001177 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1178 * android:maxSdkVersion="23" />}
1179 * </p>
1180 * <p>
1181 * Starting from {@link android.os.Build.VERSION_CODES#N},
1182 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1183 * permission is not required, so don’t ask for this
1184 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1185 * and if it fails, you must request
1186 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1187 * </p>
1188 *
1189 * <p>
1190 * The following code snippet shows how to do this:
1191 * </p>
1192 *
1193 * <pre>
1194 * File obb = new File(obb_filename);
1195 * boolean open_failed = false;
1196 *
1197 * try {
1198 * BufferedReader br = new BufferedReader(new FileReader(obb));
1199 * open_failed = false;
1200 * ReadObbFile(br);
1201 * } catch (IOException e) {
1202 * open_failed = true;
1203 * }
1204 *
1205 * if (open_failed) {
1206 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1207 * ReadObbFileWithPermission();
1208 * }
1209 * </pre>
1210 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001211 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001212 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001213 * should ensure that multiple instances running under different users don't
1214 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001215 *
1216 * @return the absolute path to application-specific directory. May return
1217 * {@code null} if shared storage is not currently available.
1218 * @see #getObbDirs()
1219 * @see Environment#getExternalStorageState(File)
1220 * @see Environment#isExternalStorageEmulated(File)
1221 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001222 */
1223 public abstract File getObbDir();
1224
1225 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001226 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001227 * shared/external storage devices where the application's OBB files (if
1228 * there are any) can be found. Note if the application does not have any
1229 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001230 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001231 * This is like {@link #getFilesDir()} in that these files will be deleted
1232 * when the application is uninstalled, however there are some important
1233 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001234 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001235 * <li>Shared storage may not always be available, since removable media can
1236 * be ejected by the user. Media state can be checked using
1237 * {@link Environment#getExternalStorageState(File)}.
1238 * <li>There is no security enforced with these files. For example, any
1239 * application holding
1240 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1241 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001242 * </ul>
1243 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001244 * Shared storage devices returned here are considered a stable part of the
1245 * device, including physical media slots under a protective cover. The
1246 * returned paths do not include transient devices, such as USB flash drives
1247 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001248 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001249 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001250 * example, an app may choose to store large files on the device with the
1251 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001252 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001253 * No additional permissions are required for the calling app to read or
1254 * write files under the returned path. Write access outside of these paths
1255 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001256 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001257 * @return the absolute paths to application-specific directories. Some
1258 * individual paths may be {@code null} if that shared storage is
1259 * not currently available. The first path returned is the same as
1260 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001261 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001262 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001263 * @see Environment#isExternalStorageEmulated(File)
1264 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001265 */
1266 public abstract File[] getObbDirs();
1267
1268 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001269 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001270 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001271 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001272 * The system will automatically delete files in this directory as disk
1273 * space is needed elsewhere on the device. The system will always delete
1274 * older files first, as reported by {@link File#lastModified()}. If
1275 * desired, you can exert more control over how files are deleted using
1276 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1277 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1278 * <p>
1279 * Apps are strongly encouraged to keep their usage of cache space below the
1280 * quota returned by
1281 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1282 * goes above this quota, your cached files will be some of the first to be
1283 * deleted when additional disk space is needed. Conversely, if your app
1284 * stays under this quota, your cached files will be some of the last to be
1285 * deleted when additional disk space is needed.
1286 * <p>
1287 * Note that your cache quota will change over time depending on how
1288 * frequently the user interacts with your app, and depending on how much
1289 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001290 * <p>
1291 * The returned path may change over time if the calling app is moved to an
1292 * adopted storage device, so only relative paths should be persisted.
1293 * <p>
1294 * Apps require no extra permissions to read or write to the returned path,
1295 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001296 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001297 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 * @see #openFileOutput
1299 * @see #getFileStreamPath
1300 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001301 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001302 */
1303 public abstract File getCacheDir();
1304
1305 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001306 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001307 * the filesystem designed for storing cached code.
1308 * <p>
1309 * The system will delete any files stored in this location both when your
1310 * specific application is upgraded, and when the entire platform is
1311 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001312 * <p>
1313 * This location is optimal for storing compiled or optimized code generated
1314 * by your application at runtime.
1315 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001316 * The returned path may change over time if the calling app is moved to an
1317 * adopted storage device, so only relative paths should be persisted.
1318 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001319 * Apps require no extra permissions to read or write to the returned path,
1320 * since this path lives in their private storage.
1321 *
1322 * @return The path of the directory holding application code cache files.
1323 */
1324 public abstract File getCodeCacheDir();
1325
1326 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001327 * Returns absolute path to application-specific directory on the primary
1328 * shared/external storage device where the application can place cache
1329 * files it owns. These files are internal to the application, and not
1330 * typically visible to the user as media.
1331 * <p>
1332 * This is like {@link #getCacheDir()} in that these files will be deleted
1333 * when the application is uninstalled, however there are some important
1334 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001335 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001336 * <li>The platform does not always monitor the space available in shared
1337 * storage, and thus may not automatically delete these files. Apps should
1338 * always manage the maximum space used in this location. Currently the only
1339 * time files here will be deleted by the platform is when running on
1340 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1341 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1342 * <li>Shared storage may not always be available, since removable media can
1343 * be ejected by the user. Media state can be checked using
1344 * {@link Environment#getExternalStorageState(File)}.
1345 * <li>There is no security enforced with these files. For example, any
1346 * application holding
1347 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001348 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001349 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001350 * <p>
1351 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001352 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001353 * backed by a private user data partition, which means there is little
1354 * benefit to storing data here instead of the private directory returned by
1355 * {@link #getCacheDir()}.
1356 * <p>
1357 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001358 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001359 * accessible to the calling app. This only applies to paths generated for
1360 * package name of the calling application. To access paths belonging to
1361 * other packages,
1362 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1363 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1364 * <p>
1365 * On devices with multiple users (as described by {@link UserManager}),
1366 * each user has their own isolated shared storage. Applications only have
1367 * access to the shared storage for the user they're running as.
1368 * <p>
1369 * The returned path may change over time if different shared storage media
1370 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001371 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001372 * @return the absolute path to application-specific directory. May return
1373 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001374 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001375 * @see #getExternalCacheDirs()
1376 * @see Environment#getExternalStorageState(File)
1377 * @see Environment#isExternalStorageEmulated(File)
1378 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001379 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001380 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001381 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001382
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001383 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001384 * Returns absolute path to application-specific directory in the preloaded cache.
1385 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1386 * There is no guarantee when these files will be deleted.
1387 * @hide
1388 */
1389 @Nullable
1390 @SystemApi
1391 public abstract File getPreloadsFileCache();
1392
1393 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001394 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001395 * shared/external storage devices 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.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001398 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001399 * 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:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001402 * <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
1415 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001416 * </ul>
1417 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001418 * If a shared storage device is emulated (as determined by
1419 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1420 * 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()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001423 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001424 * Shared storage devices returned here are considered a stable part of the
1425 * device, including physical media slots under a protective cover. The
1426 * returned paths do not include transient devices, such as USB flash drives
1427 * connected to handheld devices.
1428 * <p>
1429 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001430 * example, an app may choose to store large files on the device with the
1431 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001432 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001433 * No additional permissions are required for the calling app to read or
1434 * write files under the returned path. Write access outside of these paths
1435 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001436 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001437 * The returned paths may change over time if different shared storage media
1438 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001439 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001440 * @return the absolute paths to application-specific directories. Some
1441 * individual paths may be {@code null} if that shared storage is
1442 * not currently available. The first path returned is the same as
1443 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001444 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001445 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001446 * @see Environment#isExternalStorageEmulated(File)
1447 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001448 */
1449 public abstract File[] getExternalCacheDirs();
1450
1451 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001452 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001453 * shared/external storage devices where the application can place media
1454 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001455 * {@link MediaStore}.
1456 * <p>
1457 * This is like {@link #getExternalFilesDirs} in that these files will be
1458 * deleted when the application is uninstalled, however there are some
1459 * important differences:
1460 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001461 * <li>Shared storage may not always be available, since removable media can
1462 * be ejected by the user. Media state can be checked using
1463 * {@link Environment#getExternalStorageState(File)}.
1464 * <li>There is no security enforced with these files. For example, any
1465 * application holding
1466 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1467 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001468 * </ul>
1469 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001470 * Shared storage devices returned here are considered a stable part of the
1471 * device, including physical media slots under a protective cover. The
1472 * returned paths do not include transient devices, such as USB flash drives
1473 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001474 * <p>
1475 * An application may store data on any or all of the returned devices. For
1476 * example, an app may choose to store large files on the device with the
1477 * most available space, as measured by {@link StatFs}.
1478 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001479 * No additional permissions are required for the calling app to read or
1480 * write files under the returned path. Write access outside of these paths
1481 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001482 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001483 * The returned paths may change over time if different shared storage media
1484 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001485 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001486 * @return the absolute paths to application-specific directories. Some
1487 * individual paths may be {@code null} if that shared storage is
1488 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001489 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001490 * @see Environment#isExternalStorageEmulated(File)
1491 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001492 */
1493 public abstract File[] getExternalMediaDirs();
1494
1495 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 * Returns an array of strings naming the private files associated with
1497 * this Context's application package.
1498 *
1499 * @return Array of strings naming the private files.
1500 *
1501 * @see #openFileInput
1502 * @see #openFileOutput
1503 * @see #deleteFile
1504 */
1505 public abstract String[] fileList();
1506
1507 /**
1508 * Retrieve, creating if needed, a new directory in which the application
1509 * can place its own custom data files. You can use the returned File
1510 * object to create and access files in this directory. Note that files
1511 * created through a File object will only be accessible by your own
1512 * application; you can only set the mode of the entire directory, not
1513 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001514 * <p>
1515 * The returned path may change over time if the calling app is moved to an
1516 * adopted storage device, so only relative paths should be persisted.
1517 * <p>
1518 * Apps require no extra permissions to read or write to the returned path,
1519 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001521 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001522 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001523 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001524 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001525 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001526 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001527 *
1528 * @see #openFileOutput(String, int)
1529 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001530 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531
1532 /**
1533 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001534 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 *
1536 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001537 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001539 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001541 * @throws android.database.sqlite.SQLiteException if the database file
1542 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001543 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001544 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001545 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001546 * @see #deleteDatabase
1547 */
1548 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001549 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001550
1551 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001552 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001553 * application package. Creates the database file if it doesn't exist.
1554 * <p>
1555 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1556 * to be used to handle corruption when sqlite reports database corruption.
1557 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001558 *
1559 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001560 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001561 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001562 * cursor when query is called.
1563 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1564 * sqlite reports database corruption. if null,
1565 * {@link android.database.DefaultDatabaseErrorHandler} is
1566 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001567 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001568 * @throws android.database.sqlite.SQLiteException if the database file
1569 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001570 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001571 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001572 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001573 * @see #deleteDatabase
1574 */
1575 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001576 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001577 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001578
1579 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001580 * Move an existing database file from the given source storage context to
1581 * this context. This is typically used to migrate data between storage
1582 * locations after an upgrade, such as migrating to device protected
1583 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001584 * <p>
1585 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001586 *
1587 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001588 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001589 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001590 * @return {@code true} if the move was successful or if the database didn't
1591 * exist in the source context, otherwise {@code false}.
1592 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001593 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001594 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1595
Jeff Sharkey35871f22016-01-29 17:13:29 -07001596 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 * Delete an existing private SQLiteDatabase associated with this Context's
1598 * application package.
1599 *
1600 * @param name The name (unique in the application package) of the
1601 * database.
1602 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001603 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001604 *
1605 * @see #openOrCreateDatabase
1606 */
1607 public abstract boolean deleteDatabase(String name);
1608
1609 /**
1610 * Returns the absolute path on the filesystem where a database created with
1611 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001612 * <p>
1613 * The returned path may change over time if the calling app is moved to an
1614 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001615 *
1616 * @param name The name of the database for which you would like to get
1617 * its path.
1618 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001619 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001620 *
1621 * @see #openOrCreateDatabase
1622 */
1623 public abstract File getDatabasePath(String name);
1624
1625 /**
1626 * Returns an array of strings naming the private databases associated with
1627 * this Context's application package.
1628 *
1629 * @return Array of strings naming the private databases.
1630 *
1631 * @see #openOrCreateDatabase
1632 * @see #deleteDatabase
1633 */
1634 public abstract String[] databaseList();
1635
1636 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001637 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001638 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001640 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001641 public abstract Drawable getWallpaper();
1642
1643 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001644 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001645 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001647 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001648 public abstract Drawable peekWallpaper();
1649
1650 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001651 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1652 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001653 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001654 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001655 public abstract int getWallpaperDesiredMinimumWidth();
1656
1657 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001658 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1659 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001661 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001662 public abstract int getWallpaperDesiredMinimumHeight();
1663
1664 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001665 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001666 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001667 * <p>This method requires the caller to hold the permission
1668 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001669 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001670 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001671 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1672
1673 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001674 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001675 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001676 * <p>This method requires the caller to hold the permission
1677 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001678 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001679 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 public abstract void setWallpaper(InputStream data) throws IOException;
1681
1682 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001683 * @deprecated Use {@link android.app.WallpaperManager#clear
1684 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001685 * <p>This method requires the caller to hold the permission
1686 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001688 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 public abstract void clearWallpaper() throws IOException;
1690
1691 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001692 * Same as {@link #startActivity(Intent, Bundle)} with no options
1693 * specified.
1694 *
1695 * @param intent The description of the activity to start.
1696 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001697 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001698 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001699 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001700 * @see PackageManager#resolveActivity
1701 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001702 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001703
1704 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001705 * Version of {@link #startActivity(Intent)} that allows you to specify the
1706 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001707 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001708 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001709 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001710 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001711 * @hide
1712 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001713 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Remi NGUYEN VANbf1ecd12019-01-20 21:18:22 +09001714 @SystemApi
Tor Norbye788fc2b2015-07-05 16:10:42 -07001715 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001716 throw new RuntimeException("Not implemented. Must override in a subclass.");
1717 }
1718
1719 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001720 * Launch a new activity. You will not receive any information about when
1721 * the activity exits.
1722 *
1723 * <p>Note that if this method is being called from outside of an
1724 * {@link android.app.Activity} Context, then the Intent must include
1725 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1726 * without being started from an existing Activity, there is no existing
1727 * task in which to place the new activity and thus it needs to be placed
1728 * in its own separate task.
1729 *
1730 * <p>This method throws {@link ActivityNotFoundException}
1731 * if there was no Activity found to run the given Intent.
1732 *
1733 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001734 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001735 * May be null if there are no options. See {@link android.app.ActivityOptions}
1736 * for how to build the Bundle supplied here; there are no supported definitions
1737 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001739 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001740 *
Scott Main60dd5202012-06-23 00:01:22 -07001741 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001742 * @see PackageManager#resolveActivity
1743 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001744 public abstract void startActivity(@RequiresPermission Intent intent,
1745 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001746
1747 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001748 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1749 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001750 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001751 * @param intent The description of the activity to start.
1752 * @param options Additional options for how the Activity should be started.
1753 * May be null if there are no options. See {@link android.app.ActivityOptions}
1754 * for how to build the Bundle supplied here; there are no supported definitions
1755 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001756 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001757 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001758 * @hide
1759 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001760 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood1c77a112018-08-14 14:06:26 +01001761 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001762 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1763 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001764 throw new RuntimeException("Not implemented. Must override in a subclass.");
1765 }
1766
1767 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001768 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1769 * is only supported for Views and Fragments.
1770 * @param who The identifier for the calling element that will receive the result.
1771 * @param intent The intent to start.
1772 * @param requestCode The code that will be returned with onActivityResult() identifying this
1773 * request.
1774 * @param options Additional options for how the Activity should be started.
1775 * May be null if there are no options. See {@link android.app.ActivityOptions}
1776 * for how to build the Bundle supplied here; there are no supported definitions
1777 * for building it manually.
1778 * @hide
1779 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01001780 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001781 public void startActivityForResult(
1782 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1783 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1784 + "Check canStartActivityForResult() before calling.");
1785 }
1786
1787 /**
1788 * Identifies whether this Context instance will be able to process calls to
1789 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1790 * @hide
1791 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01001792 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001793 public boolean canStartActivityForResult() {
1794 return false;
1795 }
1796
1797 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001798 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1799 * specified.
1800 *
1801 * @param intents An array of Intents to be started.
1802 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001803 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001804 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001805 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001806 * @see PackageManager#resolveActivity
1807 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001808 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809
1810 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001811 * Launch multiple new activities. This is generally the same as calling
1812 * {@link #startActivity(Intent)} for the first Intent in the array,
1813 * that activity during its creation calling {@link #startActivity(Intent)}
1814 * for the second entry, etc. Note that unlike that approach, generally
1815 * none of the activities except the last in the array will be created
1816 * at this point, but rather will be created when the user first visits
1817 * them (due to pressing back from the activity on top).
1818 *
1819 * <p>This method throws {@link ActivityNotFoundException}
1820 * if there was no Activity found for <em>any</em> given Intent. In this
1821 * case the state of the activity stack is undefined (some Intents in the
1822 * list may be on it, some not), so you probably want to avoid such situations.
1823 *
1824 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001825 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001826 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001827 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001828 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001829 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001830 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001831 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001832 * @see PackageManager#resolveActivity
1833 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001834 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001835
1836 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001837 * @hide
1838 * Launch multiple new activities. This is generally the same as calling
1839 * {@link #startActivity(Intent)} for the first Intent in the array,
1840 * that activity during its creation calling {@link #startActivity(Intent)}
1841 * for the second entry, etc. Note that unlike that approach, generally
1842 * none of the activities except the last in the array will be created
1843 * at this point, but rather will be created when the user first visits
1844 * them (due to pressing back from the activity on top).
1845 *
1846 * <p>This method throws {@link ActivityNotFoundException}
1847 * if there was no Activity found for <em>any</em> given Intent. In this
1848 * case the state of the activity stack is undefined (some Intents in the
1849 * list may be on it, some not), so you probably want to avoid such situations.
1850 *
1851 * @param intents An array of Intents to be started.
1852 * @param options Additional options for how the Activity should be started.
1853 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001854 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001855 * Context.startActivity(Intent, Bundle)} for more details.
1856 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001857 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1858 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1859 * successful.
1860 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001861 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001862 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001863 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001864 * @see PackageManager#resolveActivity
1865 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001866 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001867 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001868 throw new RuntimeException("Not implemented. Must override in a subclass.");
1869 }
1870
1871 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001872 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1873 * with no options specified.
1874 *
1875 * @param intent The IntentSender to launch.
1876 * @param fillInIntent If non-null, this will be provided as the
1877 * intent parameter to {@link IntentSender#sendIntent}.
1878 * @param flagsMask Intent flags in the original IntentSender that you
1879 * would like to change.
1880 * @param flagsValues Desired values for any bits set in
1881 * <var>flagsMask</var>
1882 * @param extraFlags Always set to 0.
1883 *
1884 * @see #startActivity(Intent)
1885 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1886 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001887 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1888 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1889 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001890
1891 /**
1892 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001893 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001894 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001895 * here; otherwise, its associated action will be executed (such as
1896 * sending a broadcast) as if you had called
1897 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001898 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001899 * @param intent The IntentSender to launch.
1900 * @param fillInIntent If non-null, this will be provided as the
1901 * intent parameter to {@link IntentSender#sendIntent}.
1902 * @param flagsMask Intent flags in the original IntentSender that you
1903 * would like to change.
1904 * @param flagsValues Desired values for any bits set in
1905 * <var>flagsMask</var>
1906 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001907 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001908 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001909 * Context.startActivity(Intent, Bundle)} for more details. If options
1910 * have also been supplied by the IntentSender, options given here will
1911 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001912 *
1913 * @see #startActivity(Intent, Bundle)
1914 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001915 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001916 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1917 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1918 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001919
1920 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 * Broadcast the given intent to all interested BroadcastReceivers. This
1922 * call is asynchronous; it returns immediately, and you will continue
1923 * executing while the receivers are run. No results are propagated from
1924 * receivers and receivers can not abort the broadcast. If you want
1925 * to allow receivers to propagate results or abort the broadcast, you must
1926 * send an ordered broadcast using
1927 * {@link #sendOrderedBroadcast(Intent, String)}.
1928 *
1929 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1930 *
1931 * @param intent The Intent to broadcast; all receivers matching this
1932 * Intent will receive the broadcast.
1933 *
1934 * @see android.content.BroadcastReceiver
1935 * @see #registerReceiver
1936 * @see #sendBroadcast(Intent, String)
1937 * @see #sendOrderedBroadcast(Intent, String)
1938 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1939 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001940 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001941
1942 /**
1943 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1944 * an optional required permission to be enforced. This
1945 * call is asynchronous; it returns immediately, and you will continue
1946 * executing while the receivers are run. No results are propagated from
1947 * receivers and receivers can not abort the broadcast. If you want
1948 * to allow receivers to propagate results or abort the broadcast, you must
1949 * send an ordered broadcast using
1950 * {@link #sendOrderedBroadcast(Intent, String)}.
1951 *
1952 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1953 *
1954 * @param intent The Intent to broadcast; all receivers matching this
1955 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001956 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 * a receiver must hold in order to receive your broadcast.
1958 * If null, no permission is required.
1959 *
1960 * @see android.content.BroadcastReceiver
1961 * @see #registerReceiver
1962 * @see #sendBroadcast(Intent)
1963 * @see #sendOrderedBroadcast(Intent, String)
1964 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1965 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001966 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001967 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001968
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001969
1970 /**
1971 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1972 * an array of required permissions to be enforced. This call is asynchronous; it returns
1973 * immediately, and you will continue executing while the receivers are run. No results are
1974 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1975 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1976 * using {@link #sendOrderedBroadcast(Intent, String)}.
1977 *
1978 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1979 *
1980 * @param intent The Intent to broadcast; all receivers matching this
1981 * Intent will receive the broadcast.
1982 * @param receiverPermissions Array of names of permissions that a receiver must hold
1983 * in order to receive your broadcast.
1984 * If null or empty, no permissions are required.
1985 *
1986 * @see android.content.BroadcastReceiver
1987 * @see #registerReceiver
1988 * @see #sendBroadcast(Intent)
1989 * @see #sendOrderedBroadcast(Intent, String)
1990 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1991 * @hide
1992 */
1993 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1994 String[] receiverPermissions);
1995
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001997 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07001998 * an array of required permissions to be enforced. This call is asynchronous; it returns
1999 * immediately, and you will continue executing while the receivers are run. No results are
2000 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2001 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2002 * using {@link #sendOrderedBroadcast(Intent, String)}.
2003 *
2004 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2005 *
2006 * @param intent The Intent to broadcast; all receivers matching this
2007 * Intent will receive the broadcast.
2008 * @param user The user to send the broadcast to.
2009 * @param receiverPermissions Array of names of permissions that a receiver must hold
2010 * in order to receive your broadcast.
2011 * If null or empty, no permissions are required.
2012 *
2013 * @see android.content.BroadcastReceiver
2014 * @see #registerReceiver
2015 * @see #sendBroadcast(Intent)
2016 * @see #sendOrderedBroadcast(Intent, String)
2017 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2018 * @hide
2019 */
2020 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2021 String[] receiverPermissions);
2022
2023 /**
2024 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002025 * an optional required permission to be enforced. This
2026 * call is asynchronous; it returns immediately, and you will continue
2027 * executing while the receivers are run. No results are propagated from
2028 * receivers and receivers can not abort the broadcast. If you want
2029 * to allow receivers to propagate results or abort the broadcast, you must
2030 * send an ordered broadcast using
2031 * {@link #sendOrderedBroadcast(Intent, String)}.
2032 *
2033 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2034 *
2035 * @param intent The Intent to broadcast; all receivers matching this
2036 * Intent will receive the broadcast.
2037 * @param receiverPermission (optional) String naming a permission that
2038 * a receiver must hold in order to receive your broadcast.
2039 * If null, no permission is required.
2040 * @param options (optional) Additional sending options, generated from a
2041 * {@link android.app.BroadcastOptions}.
2042 *
2043 * @see android.content.BroadcastReceiver
2044 * @see #registerReceiver
2045 * @see #sendBroadcast(Intent)
2046 * @see #sendOrderedBroadcast(Intent, String)
2047 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2048 * @hide
2049 */
2050 @SystemApi
2051 public abstract void sendBroadcast(Intent intent,
2052 @Nullable String receiverPermission,
2053 @Nullable Bundle options);
2054
2055 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002056 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002057 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002058 * @hide
2059 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01002060 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002061 public abstract void sendBroadcast(Intent intent,
2062 String receiverPermission, int appOp);
2063
2064 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002065 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2066 * them one at a time to allow more preferred receivers to consume the
2067 * broadcast before it is delivered to less preferred receivers. This
2068 * call is asynchronous; it returns immediately, and you will continue
2069 * executing while the receivers are run.
2070 *
2071 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2072 *
2073 * @param intent The Intent to broadcast; all receivers matching this
2074 * Intent will receive the broadcast.
2075 * @param receiverPermission (optional) String naming a permissions that
2076 * a receiver must hold in order to receive your broadcast.
2077 * If null, no permission is required.
2078 *
2079 * @see android.content.BroadcastReceiver
2080 * @see #registerReceiver
2081 * @see #sendBroadcast(Intent)
2082 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2083 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002084 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002085 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002086
2087 /**
2088 * Version of {@link #sendBroadcast(Intent)} that allows you to
2089 * receive data back from the broadcast. This is accomplished by
2090 * supplying your own BroadcastReceiver when calling, which will be
2091 * treated as a final receiver at the end of the broadcast -- its
2092 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002093 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002094 * be serialized in the same way as calling
2095 * {@link #sendOrderedBroadcast(Intent, String)}.
2096 *
2097 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2098 * asynchronous; it will return before
2099 * resultReceiver.onReceive() is called.
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 String naming a permissions that
2106 * a receiver must hold in order to receive your broadcast.
2107 * If null, no permission is required.
2108 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2109 * receiver of the broadcast.
2110 * @param scheduler A custom Handler with which to schedule the
2111 * resultReceiver callback; if null it will be
2112 * scheduled in the Context's main thread.
2113 * @param initialCode An initial value for the result code. Often
2114 * Activity.RESULT_OK.
2115 * @param initialData An initial value for the result data. Often
2116 * null.
2117 * @param initialExtras An initial value for the result extras. Often
2118 * null.
2119 *
2120 * @see #sendBroadcast(Intent)
2121 * @see #sendBroadcast(Intent, String)
2122 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002123 * @see android.content.BroadcastReceiver
2124 * @see #registerReceiver
2125 * @see android.app.Activity#RESULT_OK
2126 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002127 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002128 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002129 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2130 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002131
2132 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002133 * Version of {@link #sendBroadcast(Intent)} that allows you to
2134 * receive data back from the broadcast. This is accomplished by
2135 * supplying your own BroadcastReceiver when calling, which will be
2136 * treated as a final receiver at the end of the broadcast -- its
2137 * {@link BroadcastReceiver#onReceive} method will be called with
2138 * the result values collected from the other receivers. The broadcast will
2139 * be serialized in the same way as calling
2140 * {@link #sendOrderedBroadcast(Intent, String)}.
2141 *
2142 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2143 * asynchronous; it will return before
2144 * resultReceiver.onReceive() is called.
2145 *
2146 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2147 *
2148 *
2149 * @param intent The Intent to broadcast; all receivers matching this
2150 * Intent will receive the broadcast.
2151 * @param receiverPermission String naming a permissions that
2152 * a receiver must hold in order to receive your broadcast.
2153 * If null, no permission is required.
2154 * @param options (optional) Additional sending options, generated from a
2155 * {@link android.app.BroadcastOptions}.
2156 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2157 * receiver of the broadcast.
2158 * @param scheduler A custom Handler with which to schedule the
2159 * resultReceiver callback; if null it will be
2160 * scheduled in the Context's main thread.
2161 * @param initialCode An initial value for the result code. Often
2162 * Activity.RESULT_OK.
2163 * @param initialData An initial value for the result data. Often
2164 * null.
2165 * @param initialExtras An initial value for the result extras. Often
2166 * null.
2167 * @see #sendBroadcast(Intent)
2168 * @see #sendBroadcast(Intent, String)
2169 * @see #sendOrderedBroadcast(Intent, String)
2170 * @see android.content.BroadcastReceiver
2171 * @see #registerReceiver
2172 * @see android.app.Activity#RESULT_OK
2173 * @hide
2174 */
2175 @SystemApi
2176 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2177 @Nullable String receiverPermission, @Nullable Bundle options,
2178 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2179 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2180
2181 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002182 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2183 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002184 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002185 * @hide
2186 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01002187 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002188 public abstract void sendOrderedBroadcast(Intent intent,
2189 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2190 Handler scheduler, int initialCode, String initialData,
2191 Bundle initialExtras);
2192
2193 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002194 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2195 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002196 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002197 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002198 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002199 * @see #sendBroadcast(Intent)
2200 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002201 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002202 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2203 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002204
2205 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002206 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2207 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002208 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002209 *
2210 * @param intent The Intent to broadcast; all receivers matching this
2211 * Intent will receive the broadcast.
2212 * @param user UserHandle to send the intent to.
2213 * @param receiverPermission (optional) String naming a permission that
2214 * a receiver must hold in order to receive your broadcast.
2215 * If null, no permission is required.
2216 *
2217 * @see #sendBroadcast(Intent, String)
2218 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002219 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002220 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2221 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002222
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002223 /**
2224 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2225 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002226 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002227 *
2228 * @param intent The Intent to broadcast; all receivers matching this
2229 * Intent will receive the broadcast.
2230 * @param user UserHandle to send the intent to.
2231 * @param receiverPermission (optional) String naming a permission that
2232 * a receiver must hold in order to receive your broadcast.
2233 * If null, no permission is required.
2234 * @param options (optional) Additional sending options, generated from a
2235 * {@link android.app.BroadcastOptions}.
2236 *
2237 * @see #sendBroadcast(Intent, String, Bundle)
2238 * @hide
2239 */
2240 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002241 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002242 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2243 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002244
2245 /**
2246 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2247 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002248 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002249 *
2250 * @param intent The Intent to broadcast; all receivers matching this
2251 * Intent will receive the broadcast.
2252 * @param user UserHandle to send the intent to.
2253 * @param receiverPermission (optional) String naming a permission that
2254 * a receiver must hold in order to receive your broadcast.
2255 * If null, no permission is required.
2256 * @param appOp The app op associated with the broadcast.
2257 *
2258 * @see #sendBroadcast(Intent, String)
2259 *
2260 * @hide
2261 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002262 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002263 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002264 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2265 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002266
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002267 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002268 * Version of
2269 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2270 * that allows you to specify the
2271 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002272 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002273 *
2274 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2275 *
2276 * @param intent The Intent to broadcast; all receivers matching this
2277 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002278 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002279 * @param receiverPermission String naming a permissions that
2280 * a receiver must hold in order to receive your broadcast.
2281 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002282 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2283 * receiver of the broadcast.
2284 * @param scheduler A custom Handler with which to schedule the
2285 * resultReceiver callback; if null it will be
2286 * scheduled in the Context's main thread.
2287 * @param initialCode An initial value for the result code. Often
2288 * Activity.RESULT_OK.
2289 * @param initialData An initial value for the result data. Often
2290 * null.
2291 * @param initialExtras An initial value for the result extras. Often
2292 * null.
2293 *
2294 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2295 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002296 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002297 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2298 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002299 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2300 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002301
2302 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002303 * Similar to above but takes an appOp as well, to enforce restrictions.
2304 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2305 * BroadcastReceiver, Handler, int, String, Bundle)
2306 * @hide
2307 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002308 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002309 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002310 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2311 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2312 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2313 @Nullable Bundle initialExtras);
2314
2315 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002316 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2317 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2318 * BroadcastReceiver, Handler, int, String, Bundle)
2319 * @hide
2320 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002321 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002322 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002323 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2324 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2325 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2326 @Nullable String initialData, @Nullable Bundle initialExtras);
2327
2328 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002329 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002330 * Intent you are sending stays around after the broadcast is complete,
2331 * so that others can quickly retrieve that data through the return
2332 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2333 * all other ways, this behaves the same as
2334 * {@link #sendBroadcast(Intent)}.
2335 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002336 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2337 * can access them), no protection (anyone can modify them), and many other problems.
2338 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2339 * has changed, with another mechanism for apps to retrieve the current value whenever
2340 * desired.
2341 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 * @param intent The Intent to broadcast; all receivers matching this
2343 * Intent will receive the broadcast, and the Intent will be held to
2344 * be re-broadcast to future receivers.
2345 *
2346 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002347 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002349 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002350 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002351 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002352
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002353 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002354 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002355 * receive data back from the broadcast. This is accomplished by
2356 * supplying your own BroadcastReceiver when calling, which will be
2357 * treated as a final receiver at the end of the broadcast -- its
2358 * {@link BroadcastReceiver#onReceive} method will be called with
2359 * the result values collected from the other receivers. The broadcast will
2360 * be serialized in the same way as calling
2361 * {@link #sendOrderedBroadcast(Intent, String)}.
2362 *
2363 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2364 * asynchronous; it will return before
2365 * resultReceiver.onReceive() is called. Note that the sticky data
2366 * stored is only the data you initially supply to the broadcast, not
2367 * the result of any changes made by the receivers.
2368 *
2369 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2370 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002371 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2372 * can access them), no protection (anyone can modify them), and many other problems.
2373 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2374 * has changed, with another mechanism for apps to retrieve the current value whenever
2375 * desired.
2376 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002377 * @param intent The Intent to broadcast; all receivers matching this
2378 * Intent will receive the broadcast.
2379 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2380 * receiver of the broadcast.
2381 * @param scheduler A custom Handler with which to schedule the
2382 * resultReceiver callback; if null it will be
2383 * scheduled in the Context's main thread.
2384 * @param initialCode An initial value for the result code. Often
2385 * Activity.RESULT_OK.
2386 * @param initialData An initial value for the result data. Often
2387 * null.
2388 * @param initialExtras An initial value for the result extras. Often
2389 * null.
2390 *
2391 * @see #sendBroadcast(Intent)
2392 * @see #sendBroadcast(Intent, String)
2393 * @see #sendOrderedBroadcast(Intent, String)
2394 * @see #sendStickyBroadcast(Intent)
2395 * @see android.content.BroadcastReceiver
2396 * @see #registerReceiver
2397 * @see android.app.Activity#RESULT_OK
2398 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002399 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002400 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002401 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002402 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002403 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2404 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002407 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002408 * so that it is as if the sticky broadcast had never happened.
2409 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002410 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2411 * can access them), no protection (anyone can modify them), and many other problems.
2412 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2413 * has changed, with another mechanism for apps to retrieve the current value whenever
2414 * desired.
2415 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 * @param intent The Intent that was previously broadcast.
2417 *
2418 * @see #sendStickyBroadcast
2419 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002420 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002421 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002422 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423
2424 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002425 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002426 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002427 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002428 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002429 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2430 * can access them), no protection (anyone can modify them), and many other problems.
2431 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2432 * has changed, with another mechanism for apps to retrieve the current value whenever
2433 * desired.
2434 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002435 * @param intent The Intent to broadcast; all receivers matching this
2436 * Intent will receive the broadcast, and the Intent will be held to
2437 * be re-broadcast to future receivers.
2438 * @param user UserHandle to send the intent to.
2439 *
2440 * @see #sendBroadcast(Intent)
2441 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002442 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002443 @RequiresPermission(allOf = {
2444 android.Manifest.permission.INTERACT_ACROSS_USERS,
2445 android.Manifest.permission.BROADCAST_STICKY
2446 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002447 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2448 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002449
2450 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002451 * @hide
2452 * This is just here for sending CONNECTIVITY_ACTION.
2453 */
2454 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002455 @RequiresPermission(allOf = {
2456 android.Manifest.permission.INTERACT_ACROSS_USERS,
2457 android.Manifest.permission.BROADCAST_STICKY
2458 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002459 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2460 UserHandle user, Bundle options);
2461
2462 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002463 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002464 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2465 * that allows you to specify the
2466 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002467 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002468 *
2469 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2470 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002471 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2472 * can access them), no protection (anyone can modify them), and many other problems.
2473 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2474 * has changed, with another mechanism for apps to retrieve the current value whenever
2475 * desired.
2476 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002477 * @param intent The Intent to broadcast; all receivers matching this
2478 * Intent will receive the broadcast.
2479 * @param user UserHandle to send the intent to.
2480 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2481 * receiver of the broadcast.
2482 * @param scheduler A custom Handler with which to schedule the
2483 * resultReceiver callback; if null it will be
2484 * scheduled in the Context's main thread.
2485 * @param initialCode An initial value for the result code. Often
2486 * Activity.RESULT_OK.
2487 * @param initialData An initial value for the result data. Often
2488 * null.
2489 * @param initialExtras An initial value for the result extras. Often
2490 * null.
2491 *
2492 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2493 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002494 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002495 @RequiresPermission(allOf = {
2496 android.Manifest.permission.INTERACT_ACROSS_USERS,
2497 android.Manifest.permission.BROADCAST_STICKY
2498 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002499 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002500 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002501 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2502 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002503
2504 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002505 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002506 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002507 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002508 *
2509 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2510 * permission in order to use this API. If you do not hold that
2511 * permission, {@link SecurityException} will be thrown.
2512 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002513 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2514 * can access them), no protection (anyone can modify them), and many other problems.
2515 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2516 * has changed, with another mechanism for apps to retrieve the current value whenever
2517 * desired.
2518 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002519 * @param intent The Intent that was previously broadcast.
2520 * @param user UserHandle to remove the sticky broadcast from.
2521 *
2522 * @see #sendStickyBroadcastAsUser
2523 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002524 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002525 @RequiresPermission(allOf = {
2526 android.Manifest.permission.INTERACT_ACROSS_USERS,
2527 android.Manifest.permission.BROADCAST_STICKY
2528 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002529 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2530 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002531
2532 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002533 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002534 * <var>receiver</var> will be called with any broadcast Intent that
2535 * matches <var>filter</var>, in the main application thread.
2536 *
2537 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002538 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002539 * registrations. If your IntentFilter matches one of these sticky
2540 * Intents, that Intent will be returned by this function
2541 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2542 * been broadcast.
2543 *
2544 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2545 * in which case each of these will be sent to <var>receiver</var>. In
2546 * this case, only one of these can be returned directly by the function;
2547 * which of these that is returned is arbitrarily decided by the system.
2548 *
2549 * <p>If you know the Intent your are registering for is sticky, you can
2550 * supply null for your <var>receiver</var>. In this case, no receiver is
2551 * registered -- the function simply returns the sticky Intent that
2552 * matches <var>filter</var>. In the case of multiple matches, the same
2553 * rules as described above apply.
2554 *
2555 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2556 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002557 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2558 * registered with this method will correctly respect the
2559 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2560 * Prior to that, it would be ignored and delivered to all matching registered
2561 * receivers. Be careful if using this for security.</p>
2562 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002563 * <p class="note">Note: this method <em>cannot be called from a
2564 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2565 * that is declared in an application's manifest. It is okay, however, to call
2566 * this method from another BroadcastReceiver that has itself been registered
2567 * at run time with {@link #registerReceiver}, since the lifetime of such a
2568 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002569 *
2570 * @param receiver The BroadcastReceiver to handle the broadcast.
2571 * @param filter Selects the Intent broadcasts to be received.
2572 *
2573 * @return The first sticky intent found that matches <var>filter</var>,
2574 * or null if there are none.
2575 *
2576 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2577 * @see #sendBroadcast
2578 * @see #unregisterReceiver
2579 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002580 @Nullable
2581 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 IntentFilter filter);
2583
2584 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002585 * Register to receive intent broadcasts, with the receiver optionally being
2586 * exposed to Instant Apps. See
2587 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2588 * information. By default Instant Apps cannot interact with receivers in other
2589 * applications, this allows you to expose a receiver that Instant Apps can
2590 * interact with.
2591 *
2592 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2593 *
2594 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2595 * registered with this method will correctly respect the
2596 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2597 * Prior to that, it would be ignored and delivered to all matching registered
2598 * receivers. Be careful if using this for security.</p>
2599 *
2600 * @param receiver The BroadcastReceiver to handle the broadcast.
2601 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002602 * @param flags Additional options for the receiver. May be 0 or
2603 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002604 *
2605 * @return The first sticky intent found that matches <var>filter</var>,
2606 * or null if there are none.
2607 *
2608 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2609 * @see #sendBroadcast
2610 * @see #unregisterReceiver
2611 */
2612 @Nullable
2613 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2614 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002615 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002616
2617 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002618 * Register to receive intent broadcasts, to run in the context of
2619 * <var>scheduler</var>. See
2620 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2621 * information. This allows you to enforce permissions on who can
2622 * broadcast intents to your receiver, or have the receiver run in
2623 * a different thread than the main application thread.
2624 *
2625 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2626 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002627 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2628 * registered with this method will correctly respect the
2629 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2630 * Prior to that, it would be ignored and delivered to all matching registered
2631 * receivers. Be careful if using this for security.</p>
2632 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 * @param receiver The BroadcastReceiver to handle the broadcast.
2634 * @param filter Selects the Intent broadcasts to be received.
2635 * @param broadcastPermission String naming a permissions that a
2636 * broadcaster must hold in order to send an Intent to you. If null,
2637 * no permission is required.
2638 * @param scheduler Handler identifying the thread that will receive
2639 * the Intent. If null, the main thread of the process will be used.
2640 *
2641 * @return The first sticky intent found that matches <var>filter</var>,
2642 * or null if there are none.
2643 *
2644 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2645 * @see #sendBroadcast
2646 * @see #unregisterReceiver
2647 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002648 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002649 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002650 IntentFilter filter, @Nullable String broadcastPermission,
2651 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002652
2653 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002654 * Register to receive intent broadcasts, to run in the context of
2655 * <var>scheduler</var>. See
2656 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002657 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2658 * for more information.
2659 *
2660 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2661 *
2662 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2663 * registered with this method will correctly respect the
2664 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2665 * Prior to that, it would be ignored and delivered to all matching registered
2666 * receivers. Be careful if using this for security.</p>
2667 *
2668 * @param receiver The BroadcastReceiver to handle the broadcast.
2669 * @param filter Selects the Intent broadcasts to be received.
2670 * @param broadcastPermission String naming a permissions that a
2671 * broadcaster must hold in order to send an Intent to you. If null,
2672 * no permission is required.
2673 * @param scheduler Handler identifying the thread that will receive
2674 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002675 * @param flags Additional options for the receiver. May be 0 or
2676 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002677 *
2678 * @return The first sticky intent found that matches <var>filter</var>,
2679 * or null if there are none.
2680 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002681 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002682 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2683 * @see #sendBroadcast
2684 * @see #unregisterReceiver
2685 */
2686 @Nullable
2687 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2688 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002689 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002690
2691 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002692 * @hide
2693 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2694 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002695 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002696 *
2697 * @param receiver The BroadcastReceiver to handle the broadcast.
2698 * @param user UserHandle to send the intent to.
2699 * @param filter Selects the Intent broadcasts to be received.
2700 * @param broadcastPermission String naming a permissions that a
2701 * broadcaster must hold in order to send an Intent to you. If null,
2702 * no permission is required.
2703 * @param scheduler Handler identifying the thread that will receive
2704 * the Intent. If null, the main thread of the process will be used.
2705 *
2706 * @return The first sticky intent found that matches <var>filter</var>,
2707 * or null if there are none.
2708 *
Jeff Brown6e539312015-02-24 18:53:21 -08002709 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002710 * @see #sendBroadcast
2711 * @see #unregisterReceiver
2712 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002713 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002714 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002715 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002716 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002717 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2718 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002719
2720 /**
2721 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2722 * filters that have been registered for this BroadcastReceiver will be
2723 * removed.
2724 *
2725 * @param receiver The BroadcastReceiver to unregister.
2726 *
2727 * @see #registerReceiver
2728 */
2729 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2730
2731 /**
2732 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002733 * should either contain the complete class name of a specific service
2734 * implementation to start, or a specific package name to target. If the
2735 * Intent is less specified, it logs a warning about this. In this case any of the
2736 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 * is not already running, it will be instantiated and started (creating a
2738 * process for it if needed); if it is running then it remains running.
2739 *
2740 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002741 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002742 * with the <var>intent</var> given here. This provides a convenient way
2743 * to submit jobs to a service without having to bind and call on to its
2744 * interface.
2745 *
2746 * <p>Using startService() overrides the default service lifetime that is
2747 * managed by {@link #bindService}: it requires the service to remain
2748 * running until {@link #stopService} is called, regardless of whether
2749 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002750 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002751 * a single call to {@link #stopService} will stop it.
2752 *
2753 * <p>The system attempts to keep running services around as much as
2754 * possible. The only time they should be stopped is if the current
2755 * foreground application is using so many resources that the service needs
2756 * to be killed. If any errors happen in the service's process, it will
2757 * automatically be restarted.
2758 *
2759 * <p>This function will throw {@link SecurityException} if you do not
2760 * have permission to start the given service.
2761 *
Chris Craik1e353522016-04-18 10:20:50 -07002762 * <p class="note"><strong>Note:</strong> Each call to startService()
2763 * results in significant work done by the system to manage service
2764 * lifecycle surrounding the processing of the intent, which can take
2765 * multiple milliseconds of CPU time. Due to this cost, startService()
2766 * should not be used for frequent intent delivery to a service, and only
2767 * for scheduling significant work. Use {@link #bindService bound services}
2768 * for high frequency calls.
2769 * </p>
2770 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002771 * @param service Identifies the service to be started. The Intent must be
2772 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002773 * may be included in the Intent extras to supply arguments along with
2774 * this specific start call.
2775 *
2776 * @return If the service is being started or is already running, the
2777 * {@link ComponentName} of the actual service that was started is
2778 * returned; else if the service does not exist null is returned.
2779 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002780 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002781 * or the service can not be found.
2782 * @throws IllegalStateException If the application is in a state where the service
2783 * 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 -08002784 *
2785 * @see #stopService
2786 * @see #bindService
2787 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002788 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002789 public abstract ComponentName startService(Intent service);
2790
2791 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002792 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002793 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2794 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002795 * an amount of time comparable to the ANR interval to do this, otherwise the system
2796 * will automatically stop the service and declare the app ANR.
2797 *
2798 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2799 * at any time, regardless of whether the app hosting the service is in a foreground
2800 * state.
2801 *
2802 * @param service Identifies the service to be started. The Intent must be
2803 * fully explicit (supplying a component name). Additional values
2804 * may be included in the Intent extras to supply arguments along with
2805 * this specific start call.
2806 *
2807 * @return If the service is being started or is already running, the
2808 * {@link ComponentName} of the actual service that was started is
2809 * returned; else if the service does not exist null is returned.
2810 *
2811 * @throws SecurityException If the caller does not have permission to access the service
2812 * or the service can not be found.
2813 *
2814 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002815 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002816 */
2817 @Nullable
2818 public abstract ComponentName startForegroundService(Intent service);
2819
2820 /**
2821 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2822 */
2823 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002824 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002825 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2826
2827 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002828 * Request that a given application service be stopped. If the service is
2829 * not running, nothing happens. Otherwise it is stopped. Note that calls
2830 * to startService() are not counted -- this stops the service no matter
2831 * how many times it was started.
2832 *
2833 * <p>Note that if a stopped service still has {@link ServiceConnection}
2834 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2835 * not be destroyed until all of these bindings are removed. See
2836 * the {@link android.app.Service} documentation for more details on a
2837 * service's lifecycle.
2838 *
2839 * <p>This function will throw {@link SecurityException} if you do not
2840 * have permission to stop the given service.
2841 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002842 * @param service Description of the service to be stopped. The Intent must be either
2843 * fully explicit (supplying a component name) or specify a specific package
kopriva219f7dc2018-10-09 13:42:28 -07002844 * name it is targeted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002845 *
2846 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002847 * 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 -08002848 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002849 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002850 * or the service can not be found.
2851 * @throws IllegalStateException If the application is in a state where the service
2852 * 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 -08002853 *
2854 * @see #startService
2855 */
2856 public abstract boolean stopService(Intent service);
2857
2858 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002859 * @hide like {@link #startService(Intent)} but for a specific user.
2860 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002861 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002862 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002863 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002864 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2865
2866 /**
2867 * @hide like {@link #stopService(Intent)} but for a specific user.
2868 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002869 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002870 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002871
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002872 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002873 * Connect to an application service, creating it if needed. This defines
2874 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002875 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002876 * told if it dies and restarts. The service will be considered required
2877 * by the system only for as long as the calling context exists. For
2878 * example, if this Context is an Activity that is stopped, the service will
2879 * not be required to continue running until the Activity is resumed.
2880 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002881 * <p>If the service does not support binding, it may return {@code null} from
2882 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
2883 * the ServiceConnection's
2884 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
2885 * will be invoked instead of
2886 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
2887 *
2888 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002889 * have permission to bind to the given service.
2890 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002891 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002893 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002894 * {@link #startService} with the arguments containing the command to be
2895 * sent, with the service calling its
2896 * {@link android.app.Service#stopSelf(int)} method when done executing
2897 * that command. See the API demo App/Service/Service Start Arguments
2898 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002899 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002900 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2901 * is tied to another object (the one that registered it).</p>
2902 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002903 * @param service Identifies the service to connect to. The Intent must
2904 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002905 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002906 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002907 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002908 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2909 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2910 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2911 * {@link #BIND_WAIVE_PRIORITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07002912 * @return {@code true} if the system is in the process of bringing up a
2913 * service that your client has permission to bind to; {@code false}
2914 * if the system couldn't find the service or if your client doesn't
2915 * have permission to bind to it. If this value is {@code true}, you
2916 * should later call {@link #unbindService} to release the
2917 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002918 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002919 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002920 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 *
2922 * @see #unbindService
2923 * @see #startService
2924 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002925 * @see #BIND_DEBUG_UNBIND
2926 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002927 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002928 public abstract boolean bindService(@RequiresPermission Intent service,
2929 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930
2931 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002932 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002933 * argument for use by system server and other multi-user aware code.
2934 * @hide
2935 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002936 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002937 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002938 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002939 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002940 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002941 throw new RuntimeException("Not implemented. Must override in a subclass.");
2942 }
2943
2944 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002945 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2946 * explicit non-null Handler to run the ServiceConnection callbacks on.
2947 *
2948 * @hide
2949 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002950 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002951 @UnsupportedAppUsage
Adrian Roos691546e2016-02-09 10:13:41 -08002952 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2953 Handler handler, UserHandle user) {
2954 throw new RuntimeException("Not implemented. Must override in a subclass.");
2955 }
2956
2957 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 * Disconnect from an application service. You will no longer receive
2959 * calls as the service is restarted, and the service is now allowed to
2960 * stop at any time.
2961 *
2962 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002963 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 *
2965 * @see #bindService
2966 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002967 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968
2969 /**
2970 * Start executing an {@link android.app.Instrumentation} class. The given
2971 * Instrumentation component will be run by killing its target application
2972 * (if currently running), starting the target process, instantiating the
2973 * instrumentation component, and then letting it drive the application.
2974 *
2975 * <p>This function is not synchronous -- it returns as soon as the
2976 * instrumentation has started and while it is running.
2977 *
2978 * <p>Instrumentation is normally only allowed to run against a package
2979 * that is either unsigned or signed with a signature that the
2980 * the instrumentation package is also signed with (ensuring the target
2981 * trusts the instrumentation).
2982 *
2983 * @param className Name of the Instrumentation component to be run.
2984 * @param profileFile Optional path to write profiling data as the
2985 * instrumentation runs, or null for no profiling.
2986 * @param arguments Additional optional arguments to pass to the
2987 * instrumentation, or null.
2988 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002989 * @return {@code true} if the instrumentation was successfully started,
2990 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002991 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002992 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2993 @Nullable String profileFile, @Nullable Bundle arguments);
2994
2995 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07002996 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07002997 POWER_SERVICE,
2998 WINDOW_SERVICE,
2999 LAYOUT_INFLATER_SERVICE,
3000 ACCOUNT_SERVICE,
3001 ACTIVITY_SERVICE,
3002 ALARM_SERVICE,
3003 NOTIFICATION_SERVICE,
3004 ACCESSIBILITY_SERVICE,
3005 CAPTIONING_SERVICE,
3006 KEYGUARD_SERVICE,
3007 LOCATION_SERVICE,
3008 //@hide: COUNTRY_DETECTOR,
3009 SEARCH_SERVICE,
3010 SENSOR_SERVICE,
3011 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003012 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003013 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003014 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003015 VIBRATOR_SERVICE,
3016 //@hide: STATUS_BAR_SERVICE,
3017 CONNECTIVITY_SERVICE,
Chalard Jean8c141bd2018-12-04 20:20:56 +09003018 //@hide: IP_MEMORY_STORE_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003019 IPSEC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003020 //@hide: UPDATE_LOCK_SERVICE,
3021 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003022 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003023 //@hide: NETWORK_POLICY_SERVICE,
3024 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003025 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003026 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003027 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003028 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003029 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003030 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003031 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003032 NSD_SERVICE,
3033 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003034 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003035 MEDIA_ROUTER_SERVICE,
3036 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003037 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003038 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003039 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003040 CLIPBOARD_SERVICE,
3041 INPUT_METHOD_SERVICE,
3042 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003043 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003044 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003045 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003046 //@hide: BACKUP_SERVICE,
3047 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003048 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003049 DEVICE_POLICY_SERVICE,
3050 UI_MODE_SERVICE,
3051 DOWNLOAD_SERVICE,
3052 NFC_SERVICE,
3053 BLUETOOTH_SERVICE,
3054 //@hide: SIP_SERVICE,
3055 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003056 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003057 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003058 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003059 INPUT_SERVICE,
3060 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003061 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003062 RESTRICTIONS_SERVICE,
3063 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003064 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003065 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003066 CONSUMER_IR_SERVICE,
3067 //@hide: TRUST_SERVICE,
3068 TV_INPUT_SERVICE,
3069 //@hide: NETWORK_SCORE_SERVICE,
3070 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003071 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003072 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003073 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003074 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003075 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003076 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003077 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003078 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003079 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003080 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003081 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003082 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003083 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003084 //@hide: INCIDENT_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003085 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003086 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003087 CROSS_PROFILE_APPS_SERVICE,
3088 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerb5579072018-05-30 14:35:24 +01003089 //@hide: TIME_DETECTOR_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003090 })
3091 @Retention(RetentionPolicy.SOURCE)
3092 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003093
3094 /**
3095 * Return the handle to a system-level service by name. The class of the
3096 * returned object varies by the requested name. Currently available names
3097 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003098 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003099 * <dl>
3100 * <dt> {@link #WINDOW_SERVICE} ("window")
3101 * <dd> The top-level window manager in which you can place custom
3102 * windows. The returned object is a {@link android.view.WindowManager}.
3103 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3104 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3105 * in this context.
3106 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3107 * <dd> A {@link android.app.ActivityManager} for interacting with the
3108 * global activity state of the system.
3109 * <dt> {@link #POWER_SERVICE} ("power")
3110 * <dd> A {@link android.os.PowerManager} for controlling power
3111 * management.
3112 * <dt> {@link #ALARM_SERVICE} ("alarm")
3113 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3114 * time of your choosing.
3115 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3116 * <dd> A {@link android.app.NotificationManager} for informing the user
3117 * of background events.
3118 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3119 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3120 * <dt> {@link #LOCATION_SERVICE} ("location")
3121 * <dd> A {@link android.location.LocationManager} for controlling location
3122 * (e.g., GPS) updates.
3123 * <dt> {@link #SEARCH_SERVICE} ("search")
3124 * <dd> A {@link android.app.SearchManager} for handling search.
3125 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3126 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3127 * hardware.
3128 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3129 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3130 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003131 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3132 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3133 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003135 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3136 * connectivity. On releases before NYC, it should only be obtained from an application
3137 * context, and not from any other derived context to avoid memory leaks within the calling
3138 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003139 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3140 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3141 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003142 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3143 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3144 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3146 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3147 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003148 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3149 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003150 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003151 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003152 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003153 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003154 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3155 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003156 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3157 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3158 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003159 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003160 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003162 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 * <p>Note: System services obtained via this API may be closely associated with
3164 * the Context in which they are obtained from. In general, do not share the
3165 * service objects between various different contexts (Activities, Applications,
3166 * Services, Providers, etc.)
3167 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003168 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3169 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
3170 * {@link #FINGERPRINT_SERVICE}, {@link #SHORTCUT_SERVICE}, {@link #USB_SERVICE},
3171 * {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, {@link #WIFI_SERVICE},
3172 * {@link #WIFI_AWARE_SERVICE}. For these services this method will return <code>null</code>.
3173 * Generally, if you are running as an instant app you should always check whether the result
3174 * of this method is null.
3175 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003177 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003179 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003180 * @see #WINDOW_SERVICE
3181 * @see android.view.WindowManager
3182 * @see #LAYOUT_INFLATER_SERVICE
3183 * @see android.view.LayoutInflater
3184 * @see #ACTIVITY_SERVICE
3185 * @see android.app.ActivityManager
3186 * @see #POWER_SERVICE
3187 * @see android.os.PowerManager
3188 * @see #ALARM_SERVICE
3189 * @see android.app.AlarmManager
3190 * @see #NOTIFICATION_SERVICE
3191 * @see android.app.NotificationManager
3192 * @see #KEYGUARD_SERVICE
3193 * @see android.app.KeyguardManager
3194 * @see #LOCATION_SERVICE
3195 * @see android.location.LocationManager
3196 * @see #SEARCH_SERVICE
3197 * @see android.app.SearchManager
3198 * @see #SENSOR_SERVICE
3199 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003200 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003201 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 * @see #VIBRATOR_SERVICE
3203 * @see android.os.Vibrator
3204 * @see #CONNECTIVITY_SERVICE
3205 * @see android.net.ConnectivityManager
3206 * @see #WIFI_SERVICE
3207 * @see android.net.wifi.WifiManager
3208 * @see #AUDIO_SERVICE
3209 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003210 * @see #MEDIA_ROUTER_SERVICE
3211 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003212 * @see #TELEPHONY_SERVICE
3213 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003214 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3215 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003216 * @see #CARRIER_CONFIG_SERVICE
3217 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003218 * @see #INPUT_METHOD_SERVICE
3219 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003220 * @see #UI_MODE_SERVICE
3221 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003222 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003223 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003224 * @see #BATTERY_SERVICE
3225 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003226 * @see #JOB_SCHEDULER_SERVICE
3227 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003228 * @see #NETWORK_STATS_SERVICE
3229 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003230 * @see android.os.HardwarePropertiesManager
3231 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003233 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003234
3235 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003236 * Return the handle to a system-level service by class.
3237 * <p>
3238 * Currently available classes are:
3239 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3240 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3241 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3242 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3243 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3244 * {@link android.net.ConnectivityManager},
3245 * {@link android.net.wifi.WifiManager},
3246 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3247 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3248 * {@link android.view.inputmethod.InputMethodManager},
3249 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003250 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3251 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08003252 * </p><p>
3253 * Note: System services obtained via this API may be closely associated with
3254 * the Context in which they are obtained from. In general, do not share the
3255 * service objects between various different contexts (Activities, Applications,
3256 * Services, Providers, etc.)
3257 * </p>
3258 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003259 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3260 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
3261 * {@link #FINGERPRINT_SERVICE}, {@link #SHORTCUT_SERVICE}, {@link #USB_SERVICE},
3262 * {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, {@link #WIFI_SERVICE},
3263 * {@link #WIFI_AWARE_SERVICE}. For these services this method will return <code>null</code>.
3264 * Generally, if you are running as an instant app you should always check whether the result
3265 * of this method is null.
3266 *
Jeff Brown6e539312015-02-24 18:53:21 -08003267 * @param serviceClass The class of the desired service.
3268 * @return The service or null if the class is not a supported system service.
3269 */
3270 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003271 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003272 // Because subclasses may override getSystemService(String) we cannot
3273 // perform a lookup by class alone. We must first map the class to its
3274 // service name then invoke the string-based method.
3275 String serviceName = getSystemServiceName(serviceClass);
3276 return serviceName != null ? (T)getSystemService(serviceName) : null;
3277 }
3278
3279 /**
3280 * Gets the name of the system-level service that is represented by the specified class.
3281 *
3282 * @param serviceClass The class of the desired service.
3283 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003284 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003285 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003286
3287 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003288 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003289 * {@link android.os.PowerManager} for controlling power management,
3290 * including "wake locks," which let you keep the device on while
3291 * you're running long tasks.
3292 */
3293 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003295 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003296 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003297 * {@link android.os.RecoverySystem} for accessing the recovery system
3298 * service.
3299 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003300 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003301 * @hide
3302 */
3303 public static final String RECOVERY_SERVICE = "recovery";
3304
3305 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003306 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003307 * {@link android.os.SystemUpdateManager} for accessing the system update
3308 * manager service.
3309 *
3310 * @see #getSystemService(String)
3311 * @hide
3312 */
3313 @SystemApi
3314 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3315
3316 /**
3317 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 * {@link android.view.WindowManager} for accessing the system's window
3319 * manager.
3320 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003321 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 * @see android.view.WindowManager
3323 */
3324 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003327 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003328 * {@link android.view.LayoutInflater} for inflating layout resources in this
3329 * context.
3330 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003331 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003332 * @see android.view.LayoutInflater
3333 */
3334 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003336 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003337 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003338 * {@link android.accounts.AccountManager} for receiving intents at a
3339 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003340 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003341 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003342 * @see android.accounts.AccountManager
3343 */
3344 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003345
Fred Quintana60307342009-03-24 22:48:12 -07003346 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003347 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 * {@link android.app.ActivityManager} for interacting with the global
3349 * system state.
3350 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003351 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 * @see android.app.ActivityManager
3353 */
3354 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003357 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 * {@link android.app.AlarmManager} for receiving intents at a
3359 * time of your choosing.
3360 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003361 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 * @see android.app.AlarmManager
3363 */
3364 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003367 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003368 * {@link android.app.NotificationManager} for informing the user of
3369 * background events.
3370 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003371 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003372 * @see android.app.NotificationManager
3373 */
3374 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003375
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003376 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003377 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003378 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3379 * feedback for UI events through the registered event listeners.
3380 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003381 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003382 * @see android.view.accessibility.AccessibilityManager
3383 */
3384 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003385
svetoslavganov75986cf2009-05-14 22:28:01 -07003386 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003387 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003388 * {@link android.view.accessibility.CaptioningManager} for obtaining
3389 * captioning properties and listening for changes in captioning
3390 * preferences.
3391 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003392 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003393 * @see android.view.accessibility.CaptioningManager
3394 */
3395 public static final String CAPTIONING_SERVICE = "captioning";
3396
3397 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003398 * Use with {@link #getSystemService(String)} to retrieve a
kopriva5495dbb2018-09-13 14:18:34 -07003399 * {@link android.app.KeyguardManager} for controlling keyguard.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003400 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003401 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 * @see android.app.KeyguardManager
3403 */
3404 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003405
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003406 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003407 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003408 * android.location.LocationManager} for controlling location
3409 * updates.
3410 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003411 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 * @see android.location.LocationManager
3413 */
3414 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003415
3416 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003417 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003418 * {@link android.location.CountryDetector} for detecting the country that
3419 * the user is in.
3420 *
3421 * @hide
3422 */
Mathew Inwood45d2c252018-09-14 12:35:36 +01003423 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003424 public static final String COUNTRY_DETECTOR = "country_detector";
3425
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003427 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003428 * android.app.SearchManager} for handling searches.
3429 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003430 * <p>
3431 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3432 * {@link android.app.SearchManager}.
3433 *
3434 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003435 * @see android.app.SearchManager
3436 */
3437 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003439 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003440 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003441 * android.hardware.SensorManager} for accessing sensors.
3442 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003443 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003444 * @see android.hardware.SensorManager
3445 */
3446 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003447
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003448 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003449 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003450 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003451 * functions.
3452 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003453 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003454 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003455 */
3456 public static final String STORAGE_SERVICE = "storage";
3457
3458 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003459 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003460 * android.app.usage.StorageStatsManager} for accessing system storage
3461 * statistics.
3462 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003463 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003464 * @see android.app.usage.StorageStatsManager
3465 */
3466 public static final String STORAGE_STATS_SERVICE = "storagestats";
3467
3468 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003469 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003470 * com.android.server.WallpaperService for accessing wallpapers.
3471 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003472 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003473 */
3474 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003476 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003477 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003478 * android.os.Vibrator} for interacting with the vibration hardware.
3479 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003480 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003481 * @see android.os.Vibrator
3482 */
3483 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003484
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003485 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003486 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003487 * android.app.StatusBarManager} for interacting with the status bar.
3488 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003489 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003490 * @see android.app.StatusBarManager
3491 * @hide
3492 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01003493 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003494 public static final String STATUS_BAR_SERVICE = "statusbar";
3495
3496 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003497 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003498 * android.net.ConnectivityManager} for handling management of
3499 * network connections.
3500 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003501 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003502 * @see android.net.ConnectivityManager
3503 */
3504 public static final String CONNECTIVITY_SERVICE = "connectivity";
3505
3506 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003507 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VAN31935982019-01-28 11:40:08 +09003508 * {@link android.net.INetd} for communicating with the network stack
3509 * @hide
3510 * @see #getSystemService(String)
3511 * @hide
3512 */
3513 @SystemApi
3514 public static final String NETD_SERVICE = "netd";
3515
3516 /**
3517 * Use with {@link #getSystemService(String)} to retrieve a
Remi NGUYEN VANc094a542018-12-07 16:52:24 +09003518 * {@link NetworkStack} for communicating with the network stack
3519 * @hide
3520 * @see #getSystemService(String)
3521 * @see NetworkStack
3522 */
3523 public static final String NETWORK_STACK_SERVICE = "network_stack";
3524
3525 /**
3526 * Use with {@link #getSystemService(String)} to retrieve a
Chalard Jean8c141bd2018-12-04 20:20:56 +09003527 * {@link android.net.IpMemoryStore} to store and read information about
3528 * known networks.
3529 * @hide
3530 */
3531 public static final String IP_MEMORY_STORE_SERVICE = "ipmemorystore";
3532
3533 /**
3534 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003535 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3536 * IPSec.
3537 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003538 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003539 */
3540 public static final String IPSEC_SERVICE = "ipsec";
3541
3542 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003543 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003544 * android.os.IUpdateLock} for managing runtime sequences that
3545 * must not be interrupted by headless OTA application or similar.
3546 *
3547 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003548 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003549 * @see android.os.UpdateLock
3550 */
3551 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3552
3553 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003554 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003555 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003556 */
3557 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3558
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003559 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003560 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003561 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3562 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003563 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003564 */
3565 public static final String SLICE_SERVICE = "slice";
3566
3567 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003568 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003569 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3570 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003571 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003572 * @see android.app.usage.NetworkStatsManager
3573 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003574 public static final String NETWORK_STATS_SERVICE = "netstats";
3575 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003576 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003577 /** {@hide} */
3578 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003579
San Mehatd1df8ac2010-01-26 06:17:26 -08003580 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003581 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003582 * android.net.wifi.WifiManager} for handling management of
3583 * Wi-Fi access.
3584 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003585 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003586 * @see android.net.wifi.WifiManager
3587 */
3588 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003590 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003591 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003592 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003593 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003594 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003595 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003596 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003597 */
3598 public static final String WIFI_P2P_SERVICE = "wifip2p";
3599
3600 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003601 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003602 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3603 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003604 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003605 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003606 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003607 */
Etan Cohen04133272016-10-26 11:22:06 -07003608 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003609
3610 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003611 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003612 * android.net.wifi.WifiScanner} for scanning the wifi universe
3613 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003614 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003615 * @see android.net.wifi.WifiScanner
3616 * @hide
3617 */
Wei Wang35d552f2014-07-08 21:37:01 -07003618 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003619 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3620
3621 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003622 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003623 * android.net.wifi.RttManager} for ranging devices with wifi
3624 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003625 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003626 * @see android.net.wifi.RttManager
3627 * @hide
3628 */
3629 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08003630 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07003631 public static final String WIFI_RTT_SERVICE = "rttmanager";
3632
3633 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003634 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohen17ba4722017-08-21 10:52:17 -07003635 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi
3636 *
3637 * Note: this is a replacement for WIFI_RTT_SERVICE above. It will
3638 * be renamed once final implementation in place.
3639 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003640 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003641 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003642 */
Etan Cohen091d7772018-01-04 17:47:37 -08003643 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003644
3645 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003646 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003647 * android.net.lowpan.LowpanManager} for handling management of
3648 * LoWPAN access.
3649 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003650 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003651 * @see android.net.lowpan.LowpanManager
3652 *
3653 * @hide
3654 */
3655 public static final String LOWPAN_SERVICE = "lowpan";
3656
3657 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003658 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003659 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003660 * Ethernet access.
3661 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003662 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003663 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003664 *
3665 * @hide
3666 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01003667 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003668 public static final String ETHERNET_SERVICE = "ethernet";
3669
3670 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003671 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003672 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003673 * discovery
3674 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003675 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003676 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003677 */
3678 public static final String NSD_SERVICE = "servicediscovery";
3679
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003680 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003681 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003682 * {@link android.media.AudioManager} for handling management of volume,
3683 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003684 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003685 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003686 * @see android.media.AudioManager
3687 */
3688 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003690 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003691 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003692 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003693 * of fingerprints.
3694 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003695 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07003696 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003697 */
3698 public static final String FINGERPRINT_SERVICE = "fingerprint";
3699
3700 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003701 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003702 * {@link android.media.MediaRouter} for controlling and managing
3703 * routing of media.
3704 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003705 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003706 * @see android.media.MediaRouter
3707 */
3708 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3709
3710 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003711 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003712 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003713 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003714 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07003715 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003716 */
3717 public static final String MEDIA_SESSION_SERVICE = "media_session";
3718
3719 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003720 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003721 * {@link android.telephony.TelephonyManager} for handling management the
3722 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003723 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003724 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003725 * @see android.telephony.TelephonyManager
3726 */
3727 public static final String TELEPHONY_SERVICE = "phone";
3728
3729 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003730 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003731 * {@link android.telephony.SubscriptionManager} for handling management the
3732 * telephony subscriptions of the device.
3733 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003734 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08003735 * @see android.telephony.SubscriptionManager
3736 */
3737 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3738
3739 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003740 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003741 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003742 * of the device.
3743 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003744 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003745 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003746 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003747 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003748
3749 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003750 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003751 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3752 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003753 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003754 * @see android.telephony.CarrierConfigManager
3755 */
3756 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3757
3758 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003759 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08003760 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
3761 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003762 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08003763 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08003764 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08003765 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08003766
3767 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003768 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003769 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
3770 *
3771 * @see #getSystemService(String)
3772 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003773 * @hide
3774 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08003775 @SystemApi
3776 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003777
3778 /**
3779 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08003780 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003782 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003783 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08003784 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003785 */
3786 public static final String CLIPBOARD_SERVICE = "clipboard";
3787
3788 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003789 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003790 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003791 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003792 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003793 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003794 */
3795 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
3796
3797 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003798 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003799 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3800 * methods.
3801 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003802 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003803 */
3804 public static final String INPUT_METHOD_SERVICE = "input_method";
3805
3806 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003807 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09003808 * {@link android.view.textservice.TextServicesManager} for accessing
3809 * text services.
3810 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003811 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09003812 */
3813 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3814
3815 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003816 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003817 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003818 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003819 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003820 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003821 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003822
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003823 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003824 * Official published name of the (internal) voice interaction manager service.
3825 *
3826 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003827 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07003828 */
3829 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3830
3831 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08003832 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07003833 *
3834 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003835 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07003836 */
Felipe Leme640f30a2017-03-06 15:44:06 -08003837 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07003838
3839 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003840 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003841 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3842 *
3843 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003844 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003845 */
3846 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3847
3848
3849 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003850 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003851 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003852 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003853 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003854 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003855 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07003856 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003857 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003858 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003859
3860 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003861 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003862 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003863 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003864 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07003865 */
3866 public static final String DROPBOX_SERVICE = "dropbox";
3867
Christopher Tate487529a2009-04-29 14:03:25 -07003868 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07003869 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003870 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003871 * @hide
3872 */
3873 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3874
3875 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003876 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003877 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003878 * device policy management.
3879 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003880 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08003881 */
3882 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3883
3884 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003885 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08003886 * {@link android.app.UiModeManager} for controlling UI modes.
3887 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003888 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08003889 */
3890 public static final String UI_MODE_SERVICE = "uimode";
3891
3892 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003893 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003894 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003895 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003896 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07003897 */
3898 public static final String DOWNLOAD_SERVICE = "download";
3899
3900 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003901 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003902 * {@link android.os.BatteryManager} for managing battery state.
3903 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003904 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08003905 */
3906 public static final String BATTERY_SERVICE = "batterymanager";
3907
3908 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003909 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003910 * {@link android.nfc.NfcManager} for using NFC.
3911 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003912 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003913 */
3914 public static final String NFC_SERVICE = "nfc";
3915
3916 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003917 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003918 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003919 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003920 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003921 */
3922 public static final String BLUETOOTH_SERVICE = "bluetooth";
3923
3924 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003925 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003926 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3927 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003928 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08003929 */
3930 /** @hide */
3931 public static final String SIP_SERVICE = "sip";
3932
3933 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003934 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003935 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003936 * and for controlling this device's behavior as a USB device.
3937 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003938 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04003939 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003940 */
3941 public static final String USB_SERVICE = "usb";
3942
3943 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003944 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003945 * android.hardware.SerialManager} for access to serial ports.
3946 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003947 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003948 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003949 *
3950 * @hide
3951 */
3952 public static final String SERIAL_SERVICE = "serial";
3953
3954 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003955 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003956 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3957 * HDMI-CEC protocol.
3958 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003959 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09003960 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003961 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003962 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003963 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003964 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003965
3966 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003967 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003968 * {@link android.hardware.input.InputManager} for interacting with input devices.
3969 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003970 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003971 * @see android.hardware.input.InputManager
3972 */
3973 public static final String INPUT_SERVICE = "input";
3974
3975 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003976 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003977 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3978 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003979 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07003980 * @see android.hardware.display.DisplayManager
3981 */
3982 public static final String DISPLAY_SERVICE = "display";
3983
3984 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003985 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003986 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3987 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003988 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07003989 * @see android.os.UserManager
3990 */
3991 public static final String USER_SERVICE = "user";
3992
3993 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003994 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003995 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3996 * profiles of a user.
3997 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003998 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08003999 * @see android.content.pm.LauncherApps
4000 */
4001 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
4002
4003 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004004 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07004005 * {@link android.content.RestrictionsManager} for retrieving application restrictions
4006 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004007 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07004008 * @see android.content.RestrictionsManager
4009 */
4010 public static final String RESTRICTIONS_SERVICE = "restrictions";
4011
4012 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004013 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004014 * {@link android.app.AppOpsManager} for tracking application operations
4015 * on the device.
4016 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004017 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004018 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08004019 */
4020 public static final String APP_OPS_SERVICE = "appops";
4021
4022 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004023 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07004024 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004025 * camera devices.
4026 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004027 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07004028 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08004029 */
4030 public static final String CAMERA_SERVICE = "camera";
4031
4032 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004033 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07004034 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004035 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004036 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004037 * @see android.print.PrintManager
4038 */
4039 public static final String PRINT_SERVICE = "print";
4040
4041 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004042 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004043 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4044 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004045 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004046 * @see android.companion.CompanionDeviceManager
4047 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004048 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004049
4050 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004051 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004052 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4053 * signals from the device.
4054 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004055 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004056 * @see android.hardware.ConsumerIrManager
4057 */
4058 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4059
4060 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004061 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004062 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004063 * @see android.app.trust.TrustManager
4064 * @hide
4065 */
4066 public static final String TRUST_SERVICE = "trust";
4067
4068 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004069 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004070 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4071 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004072 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004073 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004074 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004075 */
4076 public static final String TV_INPUT_SERVICE = "tv_input";
4077
4078 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004079 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004080 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004081 * @see android.net.NetworkScoreManager
4082 * @hide
4083 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004084 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004085 public static final String NETWORK_SCORE_SERVICE = "network_score";
4086
4087 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004088 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004089 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004090 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004091 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004092 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004093 */
4094 public static final String USAGE_STATS_SERVICE = "usagestats";
4095
4096 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004097 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004098 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004099 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004100 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004101 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004102 */
Christopher Tate7060b042014-06-09 19:50:00 -07004103 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004104
4105 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004106 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004107 * android.service.persistentdata.PersistentDataBlockManager} instance
4108 * for interacting with a storage device that lives across factory resets.
4109 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004110 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004111 * @see android.service.persistentdata.PersistentDataBlockManager
4112 * @hide
4113 */
Andres Morales33df9372014-09-26 17:08:59 -07004114 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004115 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4116
4117 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004118 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004119 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4120 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004121 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004122 * @see android.service.oemlock.OemLockManager
4123 * @hide
4124 */
4125 @SystemApi
4126 public static final String OEM_LOCK_SERVICE = "oem_lock";
4127
4128 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004129 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004130 * android.media.projection.MediaProjectionManager} instance for managing
4131 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004132 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004133 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004134 */
4135 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4136
4137 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004138 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004139 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004140 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004141 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004142 */
4143 public static final String MIDI_SERVICE = "midi";
4144
Eric Laurent2035ac82015-03-05 15:18:44 -08004145
4146 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004147 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004148 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4149 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004150 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004151 * @hide
4152 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004153 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004154
Paul McLeana33be212015-02-20 07:52:45 -08004155 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004156 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004157 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4158 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004159 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004160 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004161 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004162
4163 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004164 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004165 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004166 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004167 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004168 * @see android.content.pm.ShortcutManager
4169 */
4170 public static final String SHORTCUT_SERVICE = "shortcut";
4171
4172 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004173 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004174 * android.hardware.location.ContextHubManager} for accessing context hubs.
4175 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004176 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004177 * @see android.hardware.location.ContextHubManager
4178 *
4179 * @hide
4180 */
4181 @SystemApi
4182 public static final String CONTEXTHUB_SERVICE = "contexthub";
4183
4184 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004185 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004186 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4187 * memory, etc) metrics.
4188 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004189 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004190 */
4191 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4192
4193 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004194 * Gatekeeper Service.
4195 * @hide
4196 */
4197 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4198
4199 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004200 * Service defining the policy for access to device identifiers.
4201 * @hide
4202 */
4203 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4204
4205 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004206 * Service to report a system health "incident"
4207 * @hide
4208 */
4209 public static final String INCIDENT_SERVICE = "incident";
4210
4211 /**
Bookatz94726412017-08-31 09:26:15 -07004212 * Service to assist statsd in obtaining general stats.
4213 * @hide
4214 */
4215 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4216
4217 /**
Bookatzc6977972018-01-16 16:55:05 -08004218 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004219 * @hide
4220 */
4221 @SystemApi
4222 public static final String STATS_MANAGER = "stats";
4223
4224 /**
Nandana Dutt3386fb72018-12-12 17:26:57 +00004225 * Service to capture a bugreport.
4226 * @see #getSystemService(String)
4227 * @see android.os.BugreportManager
4228 * @hide
4229 */
4230 // TODO: Expose API when the implementation is more complete.
4231 // @SystemApi
4232 public static final String BUGREPORT_SERVICE = "bugreport";
4233
4234 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004235 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004236 * android.content.om.OverlayManager} for managing overlay packages.
4237 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004238 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004239 * @see android.content.om.OverlayManager
4240 * @hide
4241 */
4242 public static final String OVERLAY_SERVICE = "overlay";
4243
4244 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004245 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004246 * {@link VrManager} for accessing the VR service.
4247 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004248 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004249 * @hide
4250 */
4251 @SystemApi
4252 public static final String VR_SERVICE = "vrmanager";
4253
4254 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004255 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004256 * {@link android.app.timezone.ITimeZoneRulesManager}.
4257 * @hide
4258 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004259 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004260 */
4261 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4262
4263 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004264 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004265 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004266 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004267 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004268 */
4269 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4270
4271 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004272 * Use with {@link #getSystemService} to retrieve a
4273 * {@link android.se.omapi.ISecureElementService}
4274 * for accessing the SecureElementService.
4275 *
4276 * @hide
4277 */
4278 @SystemApi
4279 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4280
4281 /**
Neil Fullerb5579072018-05-30 14:35:24 +01004282 * Use with {@link #getSystemService(String)} to retrieve an
4283 * {@link android.app.timedetector.ITimeDetectorService}.
4284 * @hide
4285 *
4286 * @see #getSystemService(String)
4287 */
4288 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4289
4290 /**
Neil Fullercccc48d2018-06-19 12:53:47 +01004291 * Use with {@link #getSystemService(String)} to retrieve an
Sahin Caliskan7719db22018-12-03 14:06:39 -08004292 * {@link android.telephony.ims.RcsManager}.
Sahin Caliskan12564862018-10-31 13:23:29 -07004293 * @hide
4294 */
4295 public static final String TELEPHONY_RCS_SERVICE = "ircs";
4296
Howard Chenf17f42b2019-01-07 14:10:44 +08004297 /**
4298 * Use with {@link #getSystemService(String)} to retrieve an
4299 * {@link android.os.DynamicAndroidManager}.
4300 * @hide
4301 */
4302 @SystemApi
4303 public static final String DYNAMIC_ANDROID_SERVICE = "dynamic_android";
4304
Sahin Caliskan12564862018-10-31 13:23:29 -07004305 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004306 * Determine whether the given permission is allowed for a particular
4307 * process and user ID running in the system.
4308 *
4309 * @param permission The name of the permission being checked.
4310 * @param pid The process ID being checked against. Must be > 0.
4311 * @param uid The user ID being checked against. A uid of 0 is the root
4312 * user, which will pass every permission check.
4313 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004314 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004315 * pid/uid is allowed that permission, or
4316 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4317 *
4318 * @see PackageManager#checkPermission(String, String)
4319 * @see #checkCallingPermission
4320 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004321 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004322 @PackageManager.PermissionResult
4323 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004324
Dianne Hackbornff170242014-11-19 10:59:01 -08004325 /** @hide */
4326 @PackageManager.PermissionResult
Mathew Inwood1c77a112018-08-14 14:06:26 +01004327 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08004328 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4329 IBinder callerToken);
4330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004331 /**
4332 * Determine whether the calling process of an IPC you are handling has been
4333 * granted a particular permission. This is basically the same as calling
4334 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4335 * by {@link android.os.Binder#getCallingPid} and
4336 * {@link android.os.Binder#getCallingUid}. One important difference
4337 * is that if you are not currently processing an IPC, this function
4338 * will always fail. This is done to protect against accidentally
4339 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4340 * to avoid this protection.
4341 *
4342 * @param permission The name of the permission being checked.
4343 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004344 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 * pid/uid is allowed that permission, or
4346 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4347 *
4348 * @see PackageManager#checkPermission(String, String)
4349 * @see #checkPermission
4350 * @see #checkCallingOrSelfPermission
4351 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004352 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004353 @PackageManager.PermissionResult
4354 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004355
4356 /**
4357 * Determine whether the calling process of an IPC <em>or you</em> have been
4358 * granted a particular permission. This is the same as
4359 * {@link #checkCallingPermission}, except it grants your own permissions
4360 * if you are not currently processing an IPC. Use with care!
4361 *
4362 * @param permission The name of the permission being checked.
4363 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004364 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 * pid/uid is allowed that permission, or
4366 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4367 *
4368 * @see PackageManager#checkPermission(String, String)
4369 * @see #checkPermission
4370 * @see #checkCallingPermission
4371 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004372 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004373 @PackageManager.PermissionResult
4374 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004375
4376 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004377 * Determine whether <em>you</em> have been granted a particular permission.
4378 *
4379 * @param permission The name of the permission being checked.
4380 *
4381 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4382 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4383 *
4384 * @see PackageManager#checkPermission(String, String)
4385 * @see #checkCallingPermission(String)
4386 */
4387 @PackageManager.PermissionResult
4388 public abstract int checkSelfPermission(@NonNull String permission);
4389
4390 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004391 * If the given permission is not allowed for a particular process
4392 * and user ID running in the system, throw a {@link SecurityException}.
4393 *
4394 * @param permission The name of the permission being checked.
4395 * @param pid The process ID being checked against. Must be &gt; 0.
4396 * @param uid The user ID being checked against. A uid of 0 is the root
4397 * user, which will pass every permission check.
4398 * @param message A message to include in the exception if it is thrown.
4399 *
4400 * @see #checkPermission(String, int, int)
4401 */
4402 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004403 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004404
4405 /**
4406 * If the calling process of an IPC you are handling has not been
4407 * granted a particular permission, throw a {@link
4408 * SecurityException}. This is basically the same as calling
4409 * {@link #enforcePermission(String, int, int, String)} with the
4410 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4411 * and {@link android.os.Binder#getCallingUid}. One important
4412 * difference is that if you are not currently processing an IPC,
4413 * this function will always throw the SecurityException. This is
4414 * done to protect against accidentally leaking permissions; you
4415 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4416 * protection.
4417 *
4418 * @param permission The name of the permission being checked.
4419 * @param message A message to include in the exception if it is thrown.
4420 *
4421 * @see #checkCallingPermission(String)
4422 */
4423 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004424 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004425
4426 /**
4427 * If neither you nor the calling process of an IPC you are
4428 * handling has been granted a particular permission, throw a
4429 * {@link SecurityException}. This is the same as {@link
4430 * #enforceCallingPermission}, except it grants your own
4431 * permissions if you are not currently processing an IPC. Use
4432 * with care!
4433 *
4434 * @param permission The name of the permission being checked.
4435 * @param message A message to include in the exception if it is thrown.
4436 *
4437 * @see #checkCallingOrSelfPermission(String)
4438 */
4439 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004440 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004441
4442 /**
4443 * Grant permission to access a specific Uri to another package, regardless
4444 * of whether that package has general permission to access the Uri's
4445 * content provider. This can be used to grant specific, temporary
4446 * permissions, typically in response to user interaction (such as the
4447 * user opening an attachment that you would like someone else to
4448 * display).
4449 *
4450 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4451 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4452 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4453 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4454 * start an activity instead of this function directly. If you use this
4455 * function directly, you should be sure to call
4456 * {@link #revokeUriPermission} when the target should no longer be allowed
4457 * to access it.
4458 *
4459 * <p>To succeed, the content provider owning the Uri must have set the
4460 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4461 * grantUriPermissions} attribute in its manifest or included the
4462 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4463 * &lt;grant-uri-permissions&gt;} tag.
4464 *
4465 * @param toPackage The package you would like to allow to access the Uri.
4466 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004467 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004468 *
4469 * @see #revokeUriPermission
4470 */
4471 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004472 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004473
4474 /**
4475 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004476 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4477 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004478 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004479 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004480 * "content://foo". It will not remove any prefix grants that exist at a
4481 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004482 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004483 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004484 * regular permission access to a Uri, but had received access to it through
4485 * a specific Uri permission grant, you could not revoke that grant with this
4486 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004487 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4488 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004489 * (or none).</p>
4490 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004491 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4492 * grants matching the given Uri, for any package they had been granted to, through any
4493 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4494 * service start, etc). That means this can be potentially dangerous to use, as it can
4495 * revoke grants that another app could be strongly expecting to stick around.</p>
4496 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004497 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004498 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004499 *
4500 * @see #grantUriPermission
4501 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004502 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004503
4504 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004505 * Remove permissions to access a particular content provider Uri
4506 * that were previously added with {@link #grantUriPermission} for a specific target
4507 * package. The given Uri will match all previously granted Uris that are the same or a
4508 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4509 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4510 * "content://foo". It will not remove any prefix grants that exist at a
4511 * higher level.
4512 *
4513 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4514 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4515 * and only for the package specified. Any matching grants that have happened through
4516 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4517 * removed.</p>
4518 *
4519 * @param toPackage The package you had previously granted access to.
4520 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004521 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004522 *
4523 * @see #grantUriPermission
4524 */
4525 public abstract void revokeUriPermission(String toPackage, Uri uri,
4526 @Intent.AccessUriMode int modeFlags);
4527
4528 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004529 * Determine whether a particular process and user ID has been granted
4530 * permission to access a specific URI. This only checks for permissions
4531 * that have been explicitly granted -- if the given process/uid has
4532 * more general access to the URI's content provider then this check will
4533 * always fail.
4534 *
4535 * @param uri The uri that is being checked.
4536 * @param pid The process ID being checked against. Must be &gt; 0.
4537 * @param uid The user ID being checked against. A uid of 0 is the root
4538 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004539 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004541 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 * pid/uid is allowed to access that uri, or
4543 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4544 *
4545 * @see #checkCallingUriPermission
4546 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004547 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004548 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004549 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004550 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004551
Dianne Hackbornff170242014-11-19 10:59:01 -08004552 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004553 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08004554 public abstract int checkUriPermission(Uri uri, int pid, int uid,
4555 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4556
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004557 /**
4558 * Determine whether the calling process and user ID has been
4559 * granted permission to access a specific URI. This is basically
4560 * the same as calling {@link #checkUriPermission(Uri, int, int,
4561 * int)} with the pid and uid returned by {@link
4562 * android.os.Binder#getCallingPid} and {@link
4563 * android.os.Binder#getCallingUid}. One important difference is
4564 * that if you are not currently processing an IPC, this function
4565 * will always fail.
4566 *
4567 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004568 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004570 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 * is allowed to access that uri, or
4572 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4573 *
4574 * @see #checkUriPermission(Uri, int, int, int)
4575 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004576 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004577 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07004578 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579
4580 /**
4581 * Determine whether the calling process of an IPC <em>or you</em> has been granted
4582 * permission to access a specific URI. This is the same as
4583 * {@link #checkCallingUriPermission}, except it grants your own permissions
4584 * if you are not currently processing an IPC. Use with care!
4585 *
4586 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004587 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004588 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004589 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004590 * is allowed to access that uri, or
4591 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4592 *
4593 * @see #checkCallingUriPermission
4594 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004595 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004596 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004597 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004598 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004599
4600 /**
4601 * Check both a Uri and normal permission. This allows you to perform
4602 * both {@link #checkPermission} and {@link #checkUriPermission} in one
4603 * call.
4604 *
4605 * @param uri The Uri whose permission is to be checked, or null to not
4606 * do this check.
4607 * @param readPermission The permission that provides overall read access,
4608 * or null to not do this check.
4609 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004610 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004611 * @param pid The process ID being checked against. Must be &gt; 0.
4612 * @param uid The user ID being checked against. A uid of 0 is the root
4613 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004614 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004615 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004616 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004617 * is allowed to access that uri or holds one of the given permissions, or
4618 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4619 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004620 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004621 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004622 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
4623 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004624 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004625
4626 /**
4627 * If a particular process and user ID has not been granted
4628 * permission to access a specific URI, throw {@link
4629 * SecurityException}. This only checks for permissions that have
4630 * been explicitly granted -- if the given process/uid has more
4631 * general access to the URI's content provider then this check
4632 * will always fail.
4633 *
4634 * @param uri The uri that is being checked.
4635 * @param pid The process ID being checked against. Must be &gt; 0.
4636 * @param uid The user ID being checked against. A uid of 0 is the root
4637 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004638 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004639 * @param message A message to include in the exception if it is thrown.
4640 *
4641 * @see #checkUriPermission(Uri, int, int, int)
4642 */
4643 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004644 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004645
4646 /**
4647 * If the calling process and user ID has not been granted
4648 * permission to access a specific URI, throw {@link
4649 * SecurityException}. This is basically the same as calling
4650 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
4651 * the pid and uid returned by {@link
4652 * android.os.Binder#getCallingPid} and {@link
4653 * android.os.Binder#getCallingUid}. One important difference is
4654 * that if you are not currently processing an IPC, this function
4655 * will always throw a SecurityException.
4656 *
4657 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004658 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004659 * @param message A message to include in the exception if it is thrown.
4660 *
4661 * @see #checkCallingUriPermission(Uri, int)
4662 */
4663 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004664 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004665
4666 /**
4667 * If the calling process of an IPC <em>or you</em> has not been
4668 * granted permission to access a specific URI, throw {@link
4669 * SecurityException}. This is the same as {@link
4670 * #enforceCallingUriPermission}, except it grants your own
4671 * permissions if you are not currently processing an IPC. Use
4672 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07004673 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004674 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004675 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004676 * @param message A message to include in the exception if it is thrown.
4677 *
4678 * @see #checkCallingOrSelfUriPermission(Uri, int)
4679 */
4680 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004681 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004682
4683 /**
4684 * Enforce both a Uri and normal permission. This allows you to perform
4685 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4686 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004687 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004688 * @param uri The Uri whose permission is to be checked, or null to not
4689 * do this check.
4690 * @param readPermission The permission that provides overall read access,
4691 * or null to not do this check.
4692 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004693 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004694 * @param pid The process ID being checked against. Must be &gt; 0.
4695 * @param uid The user ID being checked against. A uid of 0 is the root
4696 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004697 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004698 * @param message A message to include in the exception if it is thrown.
4699 *
4700 * @see #checkUriPermission(Uri, String, String, int, int, int)
4701 */
4702 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004703 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004704 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004705 @Nullable String message);
4706
4707 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004708 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
4709 CONTEXT_INCLUDE_CODE,
4710 CONTEXT_IGNORE_SECURITY,
4711 CONTEXT_RESTRICTED,
4712 CONTEXT_DEVICE_PROTECTED_STORAGE,
4713 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
4714 CONTEXT_REGISTER_PACKAGE,
4715 })
Tor Norbyed9273d62013-05-30 15:59:53 -07004716 @Retention(RetentionPolicy.SOURCE)
4717 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004718
4719 /**
4720 * Flag for use with {@link #createPackageContext}: include the application
4721 * code with the context. This means loading code into the caller's
4722 * process, so that {@link #getClassLoader()} can be used to instantiate
4723 * the application's classes. Setting this flags imposes security
4724 * restrictions on what application context you can access; if the
4725 * requested application can not be safely loaded into your process,
4726 * java.lang.SecurityException will be thrown. If this flag is not set,
4727 * there will be no restrictions on the packages that can be loaded,
4728 * but {@link #getClassLoader} will always return the default system
4729 * class loader.
4730 */
4731 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4732
4733 /**
4734 * Flag for use with {@link #createPackageContext}: ignore any security
4735 * restrictions on the Context being requested, allowing it to always
4736 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4737 * to be loaded into a process even when it isn't safe to do so. Use
4738 * with extreme care!
4739 */
4740 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004741
Romain Guy870e09f2009-07-06 16:35:25 -07004742 /**
4743 * Flag for use with {@link #createPackageContext}: a restricted context may
4744 * disable specific features. For instance, a View associated with a restricted
4745 * context would ignore particular XML attributes.
4746 */
4747 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004748
4749 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004750 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004751 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004752 *
4753 * @hide
4754 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004755 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004756
4757 /**
4758 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004759 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004760 *
4761 * @hide
4762 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004763 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004764
4765 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004766 * @hide Used to indicate we should tell the activity manager about the process
4767 * loading this code.
4768 */
4769 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4770
4771 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004772 * Return a new Context object for the given application name. This
4773 * Context is the same as what the named application gets when it is
4774 * launched, containing the same resources and class loader. Each call to
4775 * this method returns a new instance of a Context object; Context objects
4776 * are not shared, however they share common state (Resources, ClassLoader,
4777 * etc) so the Context instance itself is fairly lightweight.
4778 *
Jeff Brown6e539312015-02-24 18:53:21 -08004779 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004780 * application with the given package name.
4781 *
4782 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4783 * can not be loaded into the caller's process for security reasons (see
4784 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4785 *
4786 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004787 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004788 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004789 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004790 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004791 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004792 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004793 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004794 */
4795 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004796 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004797
4798 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004799 * Similar to {@link #createPackageContext(String, int)}, but with a
4800 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4801 * will open any {@link Uri} as the given user.
4802 *
4803 * @hide
4804 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08004805 @SystemApi
4806 public Context createPackageContextAsUser(
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004807 String packageName, @CreatePackageOptions int flags, UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08004808 throws PackageManager.NameNotFoundException {
4809 if (Build.IS_ENG) {
4810 throw new IllegalStateException("createPackageContextAsUser not overridden!");
4811 }
4812 return this;
4813 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07004814
4815 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004816 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4817 *
4818 * @hide
4819 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01004820 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07004821 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004822 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07004823
4824 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08004825 * Return a new Context object for the given split name. The new Context has a ClassLoader and
4826 * Resources object that can access the split's and all of its dependencies' code/resources.
4827 * Each call to this method returns a new instance of a Context object;
4828 * Context objects are not shared, however common state (ClassLoader, other Resources for
4829 * the same split) may be so the Context itself can be fairly lightweight.
4830 *
4831 * @param splitName The name of the split to include, as declared in the split's
4832 * <code>AndroidManifest.xml</code>.
4833 * @return A {@link Context} with the given split's code and/or resources loaded.
4834 */
4835 public abstract Context createContextForSplit(String splitName)
4836 throws PackageManager.NameNotFoundException;
4837
4838 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07004839 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08004840 * @hide
4841 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004842 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07004843 public UserHandle getUser() {
4844 return android.os.Process.myUserHandle();
4845 }
4846
4847 /**
4848 * Get the user associated with this context
4849 * @hide
4850 */
4851 @TestApi
4852 public @UserIdInt int getUserId() {
4853 return android.os.UserHandle.myUserId();
4854 }
Jim Millera75a8832013-02-07 16:53:32 -08004855
4856 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004857 * Return a new Context object for the current Context but whose resources
4858 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004859 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004860 * shared, however common state (ClassLoader, other Resources for the
4861 * same configuration) may be so the Context itself can be fairly lightweight.
4862 *
4863 * @param overrideConfiguration A {@link Configuration} specifying what
4864 * values to modify in the base Configuration of the original Context's
4865 * resources. If the base configuration changes (such as due to an
4866 * orientation change), the resources of this context will also change except
4867 * for those that have been explicitly overridden with a value here.
4868 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004869 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004870 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004871 public abstract Context createConfigurationContext(
4872 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004873
4874 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004875 * Return a new Context object for the current Context but whose resources
4876 * are adjusted to match the metrics of the given Display. Each call to this method
4877 * returns a new instance of a Context object; Context objects are not
4878 * shared, however common state (ClassLoader, other Resources for the
4879 * same configuration) may be so the Context itself can be fairly lightweight.
4880 *
4881 * The returned display Context provides a {@link WindowManager}
4882 * (see {@link #getSystemService(String)}) that is configured to show windows
4883 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4884 * method can be used to retrieve the Display from the returned Context.
4885 *
4886 * @param display A {@link Display} object specifying the display
4887 * for whose metrics the Context's resources should be tailored and upon which
4888 * new windows should be shown.
4889 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004890 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004891 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004892 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004893
4894 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004895 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004896 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004897 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004898 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004899 * with a key tied to the physical device, and it can be accessed
4900 * immediately after the device has booted successfully, both
4901 * <em>before and after</em> the user has authenticated with their
4902 * credentials (such as a lock pattern or PIN).
4903 * <p>
4904 * Because device-protected data is available without user authentication,
4905 * you should carefully limit the data you store using this Context. For
4906 * example, storing sensitive authentication tokens or passwords in the
4907 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004908 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004909 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004910 * device-protected and credential-protected data using different keys, then
4911 * both storage areas will become available at the same time. They remain as
4912 * two distinct storage locations on disk, and only the window of
4913 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004914 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004915 * Each call to this method returns a new instance of a Context object;
4916 * Context objects are not shared, however common state (ClassLoader, other
4917 * Resources for the same configuration) may be so the Context itself can be
4918 * fairly lightweight.
4919 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004920 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004921 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004922 public abstract Context createDeviceProtectedStorageContext();
4923
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004924 /**
4925 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004926 * APIs are backed by credential-protected storage. This is the default
4927 * storage area for apps unless
4928 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004929 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004930 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004931 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004932 * <em>only after</em> the user has entered their credentials (such as a
4933 * lock pattern or PIN).
4934 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004935 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004936 * device-protected and credential-protected data using different keys, then
4937 * both storage areas will become available at the same time. They remain as
4938 * two distinct storage locations on disk, and only the window of
4939 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004940 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004941 * Each call to this method returns a new instance of a Context object;
4942 * Context objects are not shared, however common state (ClassLoader, other
4943 * Resources for the same configuration) may be so the Context itself can be
4944 * fairly lightweight.
4945 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004946 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004947 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004948 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004949 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004950 public abstract Context createCredentialProtectedStorageContext();
4951
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004952 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004953 * Gets the display adjustments holder for this context. This information
4954 * is provided on a per-application or activity basis and is used to simulate lower density
4955 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004956 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004957 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004958 * @return The compatibility info holder, or null if not required by the application.
4959 * @hide
4960 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004961 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004962
4963 /**
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004964 * @hide
4965 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01004966 @UnsupportedAppUsage
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004967 public abstract Display getDisplay();
4968
4969 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08004970 * @hide
4971 */
4972 public abstract void updateDisplay(int displayId);
4973
4974 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004975 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004976 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004977 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004978 *
Romain Guy870e09f2009-07-06 16:35:25 -07004979 * @see #CONTEXT_RESTRICTED
4980 */
4981 public boolean isRestricted() {
4982 return false;
4983 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004984
4985 /**
4986 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004987 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004988 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004989 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004990 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004991 public abstract boolean isDeviceProtectedStorage();
4992
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004993 /**
4994 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004995 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004996 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004997 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004998 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004999 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07005000 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06005001 public abstract boolean isCredentialProtectedStorage();
5002
Tony Mak46aabe52016-11-14 12:53:06 +00005003 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07005004 * Returns true if the context can load unsafe resources, e.g. fonts.
5005 * @hide
5006 */
5007 public abstract boolean canLoadUnsafeResources();
5008
5009 /**
Tony Mak46aabe52016-11-14 12:53:06 +00005010 * @hide
5011 */
5012 public IBinder getActivityToken() {
5013 throw new RuntimeException("Not implemented. Must override in a subclass.");
5014 }
5015
5016 /**
5017 * @hide
5018 */
5019 @Nullable
5020 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
5021 int flags) {
5022 throw new RuntimeException("Not implemented. Must override in a subclass.");
5023 }
5024
5025 /**
5026 * @hide
5027 */
5028 public IApplicationThread getIApplicationThread() {
5029 throw new RuntimeException("Not implemented. Must override in a subclass.");
5030 }
Tony Makbf9928d2016-12-22 11:02:45 +00005031
5032 /**
5033 * @hide
5034 */
5035 public Handler getMainThreadHandler() {
5036 throw new RuntimeException("Not implemented. Must override in a subclass.");
5037 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07005038
5039 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07005040 * @hide
5041 */
5042 public AutofillClient getAutofillClient() {
5043 return null;
5044 }
5045
5046 /**
5047 * @hide
5048 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005049 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005050 }
5051
5052 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005053 * @hide
5054 */
5055 public boolean isAutofillCompatibilityEnabled() {
5056 return false;
5057 }
5058
5059 /**
5060 * @hide
5061 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005062 @TestApi
5063 public void setAutofillCompatibilityEnabled(
5064 @SuppressWarnings("unused") boolean autofillCompatEnabled) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005065 }
5066
5067 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005068 * Throws an exception if the Context is using system resources,
5069 * which are non-runtime-overlay-themable and may show inconsistent UI.
5070 * @hide
5071 */
5072 public void assertRuntimeOverlayThemable() {
5073 // Resources.getSystem() is a singleton and the only Resources not managed by
5074 // ResourcesManager; therefore Resources.getSystem() is not themable.
5075 if (getResources() == Resources.getSystem()) {
5076 throw new IllegalArgumentException("Non-UI context used to display UI; "
5077 + "get a UI context from ActivityThread#getSystemUiContext()");
5078 }
5079 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005080}