blob: 5177e102425aaddb985b6d22abe80358d17307d2 [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;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070034import android.annotation.UserIdInt;
Selim Cinek7fa385a2018-01-24 08:35:28 -080035import android.app.ActivityManager;
Tony Mak46aabe52016-11-14 12:53:06 +000036import android.app.IApplicationThread;
37import android.app.IServiceConnection;
Zak Cohen56345f42017-01-26 13:54:28 -080038import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070039import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.content.pm.PackageManager;
41import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080042import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070043import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import android.content.res.Resources;
45import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070046import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047import android.database.sqlite.SQLiteDatabase;
48import android.database.sqlite.SQLiteDatabase.CursorFactory;
49import android.graphics.Bitmap;
50import android.graphics.drawable.Drawable;
51import android.net.Uri;
52import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070053import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Handler;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070055import android.os.HandlerExecutor;
Dianne Hackbornff170242014-11-19 10:59:01 -080056import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070058import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070059import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070060import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060061import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070062import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070064import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070065import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070066import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070067import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070068import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070069import android.view.autofill.AutofillManager.AutofillClient;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000070import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
72import java.io.File;
73import java.io.FileInputStream;
74import java.io.FileNotFoundException;
75import java.io.FileOutputStream;
76import java.io.IOException;
77import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070078import java.lang.annotation.Retention;
79import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070080import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080081
82/**
83 * Interface to global information about an application environment. This is
84 * an abstract class whose implementation is provided by
85 * the Android system. It
86 * allows access to application-specific resources and classes, as well as
87 * up-calls for application-level operations such as launching activities,
88 * broadcasting and receiving intents, etc.
89 */
90public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060091 /** @hide */
92 @IntDef(flag = true, prefix = { "MODE_" }, value = {
93 MODE_PRIVATE,
94 MODE_WORLD_READABLE,
95 MODE_WORLD_WRITEABLE,
96 MODE_APPEND,
97 })
98 @Retention(RetentionPolicy.SOURCE)
99 public @interface FileMode {}
100
101 /** @hide */
102 @IntDef(flag = true, prefix = { "MODE_" }, value = {
103 MODE_PRIVATE,
104 MODE_WORLD_READABLE,
105 MODE_WORLD_WRITEABLE,
106 MODE_MULTI_PROCESS,
107 })
108 @Retention(RetentionPolicy.SOURCE)
109 public @interface PreferencesMode {}
110
111 /** @hide */
112 @IntDef(flag = true, prefix = { "MODE_" }, value = {
113 MODE_PRIVATE,
114 MODE_WORLD_READABLE,
115 MODE_WORLD_WRITEABLE,
116 MODE_ENABLE_WRITE_AHEAD_LOGGING,
117 MODE_NO_LOCALIZED_COLLATORS,
118 })
119 @Retention(RetentionPolicy.SOURCE)
120 public @interface DatabaseMode {}
121
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800122 /**
123 * File creation mode: the default mode, where the created file can only
124 * be accessed by the calling application (or all applications sharing the
125 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 */
127 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700128
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700130 * File creation mode: allow all other applications to have read access to
131 * the created file.
132 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700133 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
134 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700135 *
Nick Kralevich15069212013-01-09 15:54:56 -0800136 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700137 * to cause security holes in applications. It is strongly
138 * discouraged; instead, applications should use more formal
139 * mechanism for interactions such as {@link ContentProvider},
140 * {@link BroadcastReceiver}, and {@link android.app.Service}.
141 * There are no guarantees that this access mode will remain on
142 * a file, such as when it goes through a backup and restore.
143 * @see android.support.v4.content.FileProvider
144 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700146 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700148
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700150 * File creation mode: allow all other applications to have write access to
151 * the created file.
152 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700153 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700154 * mode will throw a {@link SecurityException}.
155 *
Nick Kralevich15069212013-01-09 15:54:56 -0800156 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700157 * to cause security holes in applications. It is strongly
158 * discouraged; instead, applications should use more formal
159 * mechanism for interactions such as {@link ContentProvider},
160 * {@link BroadcastReceiver}, and {@link android.app.Service}.
161 * There are no guarantees that this access mode will remain on
162 * a file, such as when it goes through a backup and restore.
163 * @see android.support.v4.content.FileProvider
164 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700166 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700168
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 /**
170 * File creation mode: for use with {@link #openFileOutput}, if the file
171 * already exists then write data to the end of the existing file
172 * instead of erasing it.
173 * @see #openFileOutput
174 */
175 public static final int MODE_APPEND = 0x8000;
176
177 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800178 * SharedPreference loading flag: when set, the file on disk will
179 * be checked for modification even if the shared preferences
180 * instance is already loaded in this process. This behavior is
181 * sometimes desired in cases where the application has multiple
182 * processes, all writing to the same SharedPreferences file.
183 * Generally there are better forms of communication between
184 * processes, though.
185 *
186 * <p>This was the legacy (but undocumented) behavior in and
187 * before Gingerbread (Android 2.3) and this flag is implied when
188 * targetting such releases. For applications targetting SDK
189 * versions <em>greater than</em> Android 2.3, this flag must be
190 * explicitly set if desired.
191 *
192 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700193 *
194 * @deprecated MODE_MULTI_PROCESS does not work reliably in
195 * some versions of Android, and furthermore does not provide any
196 * mechanism for reconciling concurrent modifications across
197 * processes. Applications should not attempt to use it. Instead,
198 * they should use an explicit cross-process data management
199 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800200 */
Christopher Tated5748b82015-05-08 18:14:01 -0700201 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800202 public static final int MODE_MULTI_PROCESS = 0x0004;
203
204 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700205 * Database open flag: when set, the database is opened with write-ahead
206 * logging enabled by default.
207 *
208 * @see #openOrCreateDatabase(String, int, CursorFactory)
209 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
210 * @see SQLiteDatabase#enableWriteAheadLogging
211 */
212 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
213
Sunny Goyala21e6b22015-12-02 09:51:02 -0800214 /**
215 * Database open flag: when set, the database is opened without support for
216 * localized collators.
217 *
218 * @see #openOrCreateDatabase(String, int, CursorFactory)
219 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
220 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
221 */
222 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
223
Tor Norbyed9273d62013-05-30 15:59:53 -0700224 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700225 @IntDef(flag = true, prefix = { "BIND_" }, value = {
226 BIND_AUTO_CREATE,
227 BIND_DEBUG_UNBIND,
228 BIND_NOT_FOREGROUND,
229 BIND_ABOVE_CLIENT,
230 BIND_ALLOW_OOM_MANAGEMENT,
231 BIND_WAIVE_PRIORITY,
232 BIND_IMPORTANT,
233 BIND_ADJUST_WITH_ACTIVITY
234 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700235 @Retention(RetentionPolicy.SOURCE)
236 public @interface BindServiceFlags {}
237
Jeff Brown47847f32012-03-22 19:13:11 -0700238 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 * Flag for {@link #bindService}: automatically create the service as long
240 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700241 * its {@link android.app.Service#onStartCommand}
242 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 * explicit call to {@link #startService}. Even without that, though,
244 * this still provides you with access to the service object while the
245 * service is created.
246 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700247 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
248 * not supplying this flag would also impact how important the system
249 * consider's the target service's process to be. When set, the only way
250 * for it to be raised was by binding from a service in which case it will
251 * only be important when that activity is in the foreground. Now to
252 * achieve this behavior you must explicitly supply the new flag
253 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
254 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
255 * the flags {@link #BIND_WAIVE_PRIORITY} and
256 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
257 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800258 */
259 public static final int BIND_AUTO_CREATE = 0x0001;
260
261 /**
262 * Flag for {@link #bindService}: include debugging help for mismatched
263 * calls to unbind. When this flag is set, the callstack of the following
264 * {@link #unbindService} call is retained, to be printed if a later
265 * incorrect unbind call is made. Note that doing this requires retaining
266 * information about the binding that was made for the lifetime of the app,
267 * resulting in a leak -- this should only be used for debugging.
268 */
269 public static final int BIND_DEBUG_UNBIND = 0x0002;
270
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800271 /**
272 * Flag for {@link #bindService}: don't allow this binding to raise
273 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700274 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800275 * as the client (so that its process will not be killable in any
276 * situation where the client is not killable), but for CPU scheduling
277 * purposes it may be left in the background. This only has an impact
278 * in the situation where the binding client is a foreground process
279 * and the target service is in a background process.
280 */
281 public static final int BIND_NOT_FOREGROUND = 0x0004;
282
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700283 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700284 * Flag for {@link #bindService}: indicates that the client application
285 * binding to this service considers the service to be more important than
286 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700287 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700288 * this is not guaranteed to be the case.
289 */
290 public static final int BIND_ABOVE_CLIENT = 0x0008;
291
292 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700293 * Flag for {@link #bindService}: allow the process hosting the bound
294 * service to go through its normal memory management. It will be
295 * treated more like a running service, allowing the system to
296 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700297 * whim it may have, and being more aggressive about making it a candidate
298 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700299 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700300 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
301
302 /**
303 * Flag for {@link #bindService}: don't impact the scheduling or
304 * memory management priority of the target service's hosting process.
305 * Allows the service's process to be managed on the background LRU list
306 * just like a regular application process in the background.
307 */
308 public static final int BIND_WAIVE_PRIORITY = 0x0020;
309
310 /**
311 * Flag for {@link #bindService}: this service is very important to
312 * the client, so should be brought to the foreground process level
313 * when the client is. Normally a process can only be raised to the
314 * visibility level by a client, even if that client is in the foreground.
315 */
316 public static final int BIND_IMPORTANT = 0x0040;
317
318 /**
319 * Flag for {@link #bindService}: If binding from an activity, allow the
320 * target service's process importance to be raised based on whether the
321 * activity is visible to the user, regardless whether another flag is
322 * used to reduce the amount that the client process's overall importance
323 * is used to impact it.
324 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700325 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
326
327 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800328 * @hide Flag for {@link #bindService}: allows binding to a service provided
329 * by an instant app. Note that the caller may not have access to the instant
330 * app providing the service which is a violation of the instant app sandbox.
331 * This flag is intended ONLY for development/testing and should be used with
332 * great care. Only the system is allowed to use this flag.
333 */
334 public static final int BIND_ALLOW_INSTANT = 0x00400000;
335
336 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700337 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
338 * up in to the important background state (instead of transient).
339 */
340 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
341
342 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700343 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
344 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
345 */
346 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
347
348 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700349 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
350 * but only applies while the device is awake.
351 */
352 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
353
354 /**
355 * @hide Flag for {@link #bindService}: For only the case where the binding
356 * is coming from the system, set the process state to FOREGROUND_SERVICE
357 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
358 * saying that the process shouldn't participate in the normal power reduction
359 * modes (removing network access etc).
360 */
361 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
362
363 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700364 * @hide Flag for {@link #bindService}: Treat the binding as hosting
365 * an activity, an unbinding as the activity going in the background.
366 * That is, when unbinding, the process when empty will go on the activity
367 * LRU list instead of the regular one, keeping it around more aggressively
368 * than it otherwise would be. This is intended for use with IMEs to try
369 * to keep IME processes around for faster keyboard switching.
370 */
371 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
372
373 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700374 * @hide An idea that is not yet implemented.
375 * Flag for {@link #bindService}: If binding from an activity, consider
376 * this service to be visible like the binding activity is. That is,
377 * it will be treated as something more important to keep around than
378 * invisible background activities. This will impact the number of
379 * recent activities the user can switch between without having them
380 * restart. There is no guarantee this will be respected, as the system
381 * tries to balance such requests from one app vs. the importantance of
382 * keeping other apps around.
383 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700384 public static final int BIND_VISIBLE = 0x10000000;
385
386 /**
387 * @hide
388 * Flag for {@link #bindService}: Consider this binding to be causing the target
389 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
390 * away.
391 */
392 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700393
394 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700395 * Flag for {@link #bindService}: Don't consider the bound service to be
396 * visible, even if the caller is visible.
397 * @hide
398 */
399 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700400
Alan Viverette713a5cd2015-12-16 15:46:32 -0500401 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500402 * Flag for {@link #bindService}: The service being bound is an
403 * {@link android.R.attr#isolatedProcess isolated},
404 * {@link android.R.attr#externalService external} service. This binds the service into the
405 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400406 * <p>
407 * When using this flag, the code for the service being bound will execute under the calling
408 * application's package name and user ID. Because the service must be an isolated process,
409 * it will not have direct access to the application's data, though.
410 *
411 * The purpose of this flag is to allow applications to provide services that are attributed
412 * to the app using the service, rather than the application providing the service.
413 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500414 */
415 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
416
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700417 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700418 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
419 RECEIVER_VISIBLE_TO_INSTANT_APPS
420 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700421 @Retention(RetentionPolicy.SOURCE)
422 public @interface RegisterReceiverFlags {}
423
424 /**
425 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
426 */
427 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
428
Robert Sesekb9a86662015-12-09 16:22:45 -0500429 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500430 * Returns an AssetManager instance for the application's package.
431 * <p>
432 * <strong>Note:</strong> Implementations of this method should return
433 * an AssetManager instance that is consistent with the Resources instance
434 * returned by {@link #getResources()}. For example, they should share the
435 * same {@link Configuration} object.
436 *
437 * @return an AssetManager instance for the application's package
438 * @see #getResources()
439 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 public abstract AssetManager getAssets();
441
Alan Viverette713a5cd2015-12-16 15:46:32 -0500442 /**
443 * Returns a Resources instance for the application's package.
444 * <p>
445 * <strong>Note:</strong> Implementations of this method should return
446 * a Resources instance that is consistent with the AssetManager instance
447 * returned by {@link #getAssets()}. For example, they should share the
448 * same {@link Configuration} object.
449 *
450 * @return a Resources instance for the application's package
451 * @see #getAssets()
452 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 public abstract Resources getResources();
454
455 /** Return PackageManager instance to find global package information. */
456 public abstract PackageManager getPackageManager();
457
458 /** Return a ContentResolver instance for your application's package. */
459 public abstract ContentResolver getContentResolver();
460
461 /**
462 * Return the Looper for the main thread of the current process. This is
463 * the thread used to dispatch calls to application components (activities,
464 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700465 * <p>
466 * By definition, this method returns the same result as would be obtained
467 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
468 * </p>
469 *
470 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800471 */
472 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700473
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700475 * Return an {@link Executor} that will run enqueued tasks on the main
476 * thread associated with this context. This is the thread used to dispatch
477 * calls to application components (activities, services, etc).
478 */
479 public Executor getMainExecutor() {
480 // This is pretty inefficient, which is why ContextImpl overrides it
481 return new HandlerExecutor(new Handler(getMainLooper()));
482 }
483
484 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800486 * current process. This generally should only be used if you need a
487 * Context whose lifecycle is separate from the current context, that is
488 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700489 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800490 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800491 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800492 * <ul>
493 * <li> <p>If used from an Activity context, the receiver is being registered
494 * within that activity. This means that you are expected to unregister
495 * before the activity is done being destroyed; in fact if you do not do
496 * so, the framework will clean up your leaked registration as it removes
497 * the activity and log an error. Thus, if you use the Activity context
498 * to register a receiver that is static (global to the process, not
499 * associated with an Activity instance) then that registration will be
500 * removed on you at whatever point the activity you used is destroyed.
501 * <li> <p>If used from the Context returned here, the receiver is being
502 * registered with the global state associated with your application. Thus
503 * it will never be unregistered for you. This is necessary if the receiver
504 * is associated with static data, not a particular component. However
505 * using the ApplicationContext elsewhere can easily lead to serious leaks
506 * if you forget to unregister, unbind, etc.
507 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800508 */
509 public abstract Context getApplicationContext();
510
Phil Weaver846cda932017-06-15 10:10:06 -0700511 /** Non-activity related autofill ids are unique in the app */
512 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700513
514 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700515 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700516 *
Phil Weaver846cda932017-06-15 10:10:06 -0700517 * <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 -0700518 * returned will be unique.
519 *
520 * @return A ID that is unique in the process
521 *
522 * {@hide}
523 */
Phil Weaver846cda932017-06-15 10:10:06 -0700524 public int getNextAutofillId() {
525 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
526 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700527 }
528
Phil Weaver846cda932017-06-15 10:10:06 -0700529 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700530
Phil Weaver846cda932017-06-15 10:10:06 -0700531 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700532 }
533
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800534 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700535 * Add a new {@link ComponentCallbacks} to the base application of the
536 * Context, which will be called at the same times as the ComponentCallbacks
537 * methods of activities and other components are called. Note that you
538 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
539 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700540 *
541 * @param callback The interface to call. This can be either a
542 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700543 */
544 public void registerComponentCallbacks(ComponentCallbacks callback) {
545 getApplicationContext().registerComponentCallbacks(callback);
546 }
547
548 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400549 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700550 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
551 */
552 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
553 getApplicationContext().unregisterComponentCallbacks(callback);
554 }
555
556 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 * Return a localized, styled CharSequence from the application's package's
558 * default string table.
559 *
560 * @param resId Resource id for the CharSequence text
561 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700562 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800563 return getResources().getText(resId);
564 }
565
566 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700567 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800568 * default string table.
569 *
570 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700571 * @return The string data associated with the resource, stripped of styled
572 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700574 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700575 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 return getResources().getString(resId);
577 }
578
579 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700580 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 * default string table, substituting the format arguments as defined in
582 * {@link java.util.Formatter} and {@link java.lang.String#format}.
583 *
584 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700585 * @param formatArgs The format arguments that will be used for
586 * substitution.
587 * @return The string data associated with the resource, formatted and
588 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800589 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700590 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700591 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 return getResources().getString(resId, formatArgs);
593 }
594
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800595 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800596 * Returns a color associated with a particular resource ID and styled for
597 * the current theme.
598 *
599 * @param id The desired resource identifier, as generated by the aapt
600 * tool. This integer encodes the package, type, and resource
601 * entry. The value 0 is an invalid identifier.
602 * @return A single color value in the form 0xAARRGGBB.
603 * @throws android.content.res.Resources.NotFoundException if the given ID
604 * does not exist.
605 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700606 @ColorInt
607 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800608 return getResources().getColor(id, getTheme());
609 }
610
611 /**
612 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800613 * styled for the current theme.
614 *
615 * @param id The desired resource identifier, as generated by the aapt
616 * tool. This integer encodes the package, type, and resource
617 * entry. The value 0 is an invalid identifier.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800618 * @return An object that can be used to draw this resource, or
619 * {@code null} if the resource could not be resolved.
620 * @throws android.content.res.Resources.NotFoundException if the given ID
621 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800622 */
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800623 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700624 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800625 return getResources().getDrawable(id, getTheme());
626 }
627
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800628 /**
629 * Returns a color state list associated with a particular resource ID and
630 * styled for the current theme.
631 *
632 * @param id The desired resource identifier, as generated by the aapt
633 * tool. This integer encodes the package, type, and resource
634 * entry. The value 0 is an invalid identifier.
635 * @return A color state list, or {@code null} if the resource could not be
636 * resolved.
637 * @throws android.content.res.Resources.NotFoundException if the given ID
638 * does not exist.
639 */
640 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700641 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800642 return getResources().getColorStateList(id, getTheme());
643 }
644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 /**
646 * Set the base theme for this context. Note that this should be called
647 * before any views are instantiated in the Context (for example before
648 * calling {@link android.app.Activity#setContentView} or
649 * {@link android.view.LayoutInflater#inflate}).
650 *
651 * @param resid The style resource describing the theme.
652 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700653 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800654
Dianne Hackborn247fe742011-01-08 17:25:57 -0800655 /** @hide Needed for some internal implementation... not public because
656 * you can't assume this actually means anything. */
657 public int getThemeResId() {
658 return 0;
659 }
660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 /**
662 * Return the Theme object associated with this Context.
663 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700664 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 public abstract Resources.Theme getTheme();
666
667 /**
668 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800669 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 * for more information.
671 *
Jeff Brown6e539312015-02-24 18:53:21 -0800672 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700674 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 return getTheme().obtainStyledAttributes(attrs);
676 }
677
678 /**
679 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800680 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 * for more information.
682 *
Jeff Brown6e539312015-02-24 18:53:21 -0800683 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 */
685 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700686 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800687 return getTheme().obtainStyledAttributes(resid, 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(AttributeSet, int[], 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(AttributeSet, int[], 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 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800699 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
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, @AttrRes int defStyleAttr,
711 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 return getTheme().obtainStyledAttributes(
713 set, attrs, defStyleAttr, defStyleRes);
714 }
715
716 /**
717 * Return a class loader you can use to retrieve classes in this package.
718 */
719 public abstract ClassLoader getClassLoader();
720
721 /** Return the name of this application's package. */
722 public abstract String getPackageName();
723
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800724 /** @hide Return the name of the base context this context is derived from. */
725 public abstract String getBasePackageName();
726
Dianne Hackborn95d78532013-09-11 09:51:14 -0700727 /** @hide Return the package name that should be used for app ops calls from
728 * this context. This is the same as {@link #getBasePackageName()} except in
729 * cases where system components are loaded into other app processes, in which
730 * case this will be the name of the primary package in that process (so that app
731 * ops uid verification will work with the name). */
732 public abstract String getOpPackageName();
733
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700734 /** Return the full application info for this context's package. */
735 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700736
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737 /**
Kenny Root32148392010-01-21 15:40:47 -0800738 * Return the full path to this context's primary Android package.
739 * The Android package is a ZIP file which contains the application's
740 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 *
742 * <p>Note: this is not generally useful for applications, since they should
743 * not be directly accessing the file system.
744 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 * @return String Path to the resources.
746 */
747 public abstract String getPackageResourcePath();
748
749 /**
Kenny Root32148392010-01-21 15:40:47 -0800750 * Return the full path to this context's primary Android package.
751 * The Android package is a ZIP file which contains application's
752 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 *
754 * <p>Note: this is not generally useful for applications, since they should
755 * not be directly accessing the file system.
756 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 * @return String Path to the code and assets.
758 */
759 public abstract String getPackageCodePath();
760
761 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700762 * @hide
763 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700764 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700765 @Deprecated
766 public File getSharedPrefsFile(String name) {
767 return getSharedPreferencesPath(name);
768 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700769
770 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771 * Retrieve and hold the contents of the preferences file 'name', returning
772 * a SharedPreferences through which you can retrieve and modify its
773 * values. Only one instance of the SharedPreferences object is returned
774 * to any callers for the same name, meaning they will see each other's
775 * edits as soon as they are made.
776 *
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700777 * This method is thead-safe.
778 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800779 * @param name Desired preferences file. If a preferences file by this name
780 * does not exist, it will be created when you retrieve an
781 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600782 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400784 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 * to retrieve and modify the preference values.
786 *
787 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600789 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700790
791 /**
792 * Retrieve and hold the contents of the preferences file, returning
793 * a SharedPreferences through which you can retrieve and modify its
794 * values. Only one instance of the SharedPreferences object is returned
795 * to any callers for the same name, meaning they will see each other's
796 * edits as soon as they are made.
797 *
798 * @param file Desired preferences file. If a preferences file by this name
799 * does not exist, it will be created when you retrieve an
800 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600801 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700802 *
803 * @return The single {@link SharedPreferences} instance that can be used
804 * to retrieve and modify the preference values.
805 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700806 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700807 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600808 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700809 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600810 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800811
812 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600813 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700814 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600815 * storage locations after an upgrade, such as moving to device protected
816 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700817 *
818 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600819 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700820 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600821 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700822 * preferences didn't exist in the source context, otherwise
823 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600824 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700825 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600826 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
827
Jeff Sharkey35871f22016-01-29 17:13:29 -0700828 /**
829 * Delete an existing shared preferences file.
830 *
831 * @param name The name (unique in the application package) of the shared
832 * preferences file.
833 * @return {@code true} if the shared preferences file was successfully
834 * deleted; else {@code false}.
835 * @see #getSharedPreferences(String, int)
836 */
837 public abstract boolean deleteSharedPreferences(String name);
838
Christopher Tatefe2368c2017-05-17 15:42:35 -0700839 /** @hide */
840 public abstract void reloadSharedPreferences();
841
Jeff Sharkey35871f22016-01-29 17:13:29 -0700842 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800843 * Open a private file associated with this Context's application package
844 * for reading.
845 *
846 * @param name The name of the file to open; can not contain path
847 * separators.
848 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400849 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800850 *
851 * @see #openFileOutput
852 * @see #fileList
853 * @see #deleteFile
854 * @see java.io.FileInputStream#FileInputStream(String)
855 */
856 public abstract FileInputStream openFileInput(String name)
857 throws FileNotFoundException;
858
859 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800860 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700861 * for writing. Creates the file if it doesn't already exist.
862 * <p>
863 * No additional permissions are required for the calling app to read or
864 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700865 *
Nick Kralevich15069212013-01-09 15:54:56 -0800866 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700867 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600868 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400869 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800870 * @see #MODE_APPEND
871 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 * @see #openFileInput
873 * @see #fileList
874 * @see #deleteFile
875 * @see java.io.FileOutputStream#FileOutputStream(String)
876 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600877 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800878 throws FileNotFoundException;
879
880 /**
881 * Delete the given private file associated with this Context's
882 * application package.
883 *
884 * @param name The name of the file to delete; can not contain path
885 * separators.
886 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400887 * @return {@code true} if the file was successfully deleted; else
888 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 *
890 * @see #openFileInput
891 * @see #openFileOutput
892 * @see #fileList
893 * @see java.io.File#delete()
894 */
895 public abstract boolean deleteFile(String name);
896
897 /**
898 * Returns the absolute path on the filesystem where a file created with
899 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700900 * <p>
901 * The returned path may change over time if the calling app is moved to an
902 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800903 *
904 * @param name The name of the file for which you would like to get
905 * its path.
906 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400907 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 *
909 * @see #openFileOutput
910 * @see #getFilesDir
911 * @see #getDir
912 */
913 public abstract File getFileStreamPath(String name);
914
915 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700916 * Returns the absolute path on the filesystem where a file created with
917 * {@link #getSharedPreferences(String, int)} is stored.
918 * <p>
919 * The returned path may change over time if the calling app is moved to an
920 * adopted storage device, so only relative paths should be persisted.
921 *
922 * @param name The name of the shared preferences for which you would like
923 * to get a path.
924 * @return An absolute path to the given file.
925 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600926 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700927 */
928 public abstract File getSharedPreferencesPath(String name);
929
930 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700931 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600932 * private files belonging to this app are stored. Apps should not use this
933 * path directly; they should instead use {@link #getFilesDir()},
934 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
935 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700936 * <p>
937 * The returned path may change over time if the calling app is moved to an
938 * adopted storage device, so only relative paths should be persisted.
939 * <p>
940 * No additional permissions are required for the calling app to read or
941 * write files under the returned path.
942 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600943 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700944 */
945 public abstract File getDataDir();
946
947 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700948 * Returns the absolute path to the directory on the filesystem where files
949 * created with {@link #openFileOutput} are stored.
950 * <p>
951 * The returned path may change over time if the calling app is moved to an
952 * adopted storage device, so only relative paths should be persisted.
953 * <p>
954 * No additional permissions are required for the calling app to read or
955 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700956 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400957 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800958 * @see #openFileOutput
959 * @see #getFileStreamPath
960 * @see #getDir
961 */
962 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800964 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700965 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700966 * {@link #getFilesDir()}. The difference is that files placed under this
967 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700968 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
969 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700970 * <p>
971 * The returned path may change over time if the calling app is moved to an
972 * adopted storage device, so only relative paths should be persisted.
973 * <p>
974 * No additional permissions are required for the calling app to read or
975 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700976 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700977 * @return The path of the directory holding application files that will not
978 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700979 * @see #openFileOutput
980 * @see #getFileStreamPath
981 * @see #getDir
982 * @see android.app.backup.BackupAgent
983 */
984 public abstract File getNoBackupFilesDir();
985
986 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700987 * Returns the absolute path to the directory on the primary shared/external
988 * storage device where the application can place persistent files it owns.
989 * These files are internal to the applications, and not typically visible
990 * to the user as media.
991 * <p>
992 * This is like {@link #getFilesDir()} in that these files will be deleted
993 * when the application is uninstalled, however there are some important
994 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800995 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700996 * <li>Shared storage may not always be available, since removable media can
997 * be ejected by the user. Media state can be checked using
998 * {@link Environment#getExternalStorageState(File)}.
999 * <li>There is no security enforced with these files. For example, any
1000 * application holding
1001 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001002 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001003 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001004 * <p>
1005 * If a shared storage device is emulated (as determined by
1006 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1007 * backed by a private user data partition, which means there is little
1008 * benefit to storing data here instead of the private directories returned
1009 * by {@link #getFilesDir()}, etc.
1010 * <p>
1011 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001012 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001013 * accessible to the calling app. This only applies to paths generated for
1014 * package name of the calling application. To access paths belonging to
1015 * other packages,
1016 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1017 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1018 * <p>
1019 * On devices with multiple users (as described by {@link UserManager}),
1020 * each user has their own isolated shared storage. Applications only have
1021 * access to the shared storage for the user they're running as.
1022 * <p>
1023 * The returned path may change over time if different shared storage media
1024 * is inserted, so only relative paths should be persisted.
1025 * <p>
1026 * Here is an example of typical code to manipulate a file in an
1027 * application's shared storage:
1028 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001029 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1030 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001031 * <p>
1032 * If you supply a non-null <var>type</var> to this function, the returned
1033 * file will be a path to a sub-directory of the given type. Though these
1034 * files are not automatically scanned by the media scanner, you can
1035 * explicitly add them to the media database with
1036 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1037 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001038 * {@link android.os.Environment#getExternalStoragePublicDirectory
1039 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001040 * directories of media shared by all applications. The directories returned
1041 * here are owned by the application, and their contents will be removed
1042 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001043 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001044 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1045 * here will be automatically created for you.
1046 * <p>
1047 * Here is an example of typical code to manipulate a picture in an
1048 * application's shared storage and add it to the media database:
1049 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001050 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1051 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001052 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001053 * @param type The type of files directory to return. May be {@code null}
1054 * for the root of the files directory or one of the following
1055 * constants for a subdirectory:
1056 * {@link android.os.Environment#DIRECTORY_MUSIC},
1057 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1058 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1059 * {@link android.os.Environment#DIRECTORY_ALARMS},
1060 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1061 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1062 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1063 * @return the absolute path to application-specific directory. May return
1064 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001065 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001066 * @see #getExternalFilesDirs(String)
1067 * @see Environment#getExternalStorageState(File)
1068 * @see Environment#isExternalStorageEmulated(File)
1069 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001070 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001071 @Nullable
1072 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001073
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001074 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001075 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001076 * shared/external storage devices where the application can place
1077 * persistent files it owns. These files are internal to the application,
1078 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001079 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001080 * This is like {@link #getFilesDir()} in that these files will be deleted
1081 * when the application is uninstalled, however there are some important
1082 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001083 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001084 * <li>Shared storage may not always be available, since removable media can
1085 * be ejected by the user. Media state can be checked using
1086 * {@link Environment#getExternalStorageState(File)}.
1087 * <li>There is no security enforced with these files. For example, any
1088 * application holding
1089 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1090 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001091 * </ul>
1092 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001093 * If a shared storage device is emulated (as determined by
1094 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1095 * backed by a private user data partition, which means there is little
1096 * benefit to storing data here instead of the private directories returned
1097 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001098 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001099 * Shared storage devices returned here are considered a stable part of the
1100 * device, including physical media slots under a protective cover. The
1101 * returned paths do not include transient devices, such as USB flash drives
1102 * connected to handheld devices.
1103 * <p>
1104 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001105 * example, an app may choose to store large files on the device with the
1106 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001107 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001108 * No additional permissions are required for the calling app to read or
1109 * write files under the returned path. Write access outside of these paths
1110 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001111 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001112 * The returned path may change over time if different shared storage media
1113 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001114 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001115 * @param type The type of files directory to return. May be {@code null}
1116 * for the root of the files directory or one of the following
1117 * constants for a subdirectory:
1118 * {@link android.os.Environment#DIRECTORY_MUSIC},
1119 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1120 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1121 * {@link android.os.Environment#DIRECTORY_ALARMS},
1122 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1123 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1124 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1125 * @return the absolute paths to application-specific directories. Some
1126 * individual paths may be {@code null} if that shared storage is
1127 * not currently available. The first path returned is the same as
1128 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001129 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001130 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001131 * @see Environment#isExternalStorageEmulated(File)
1132 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001133 */
1134 public abstract File[] getExternalFilesDirs(String type);
1135
1136 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001137 * Return the primary shared/external storage directory where this
1138 * application's OBB files (if there are any) can be found. Note if the
1139 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001140 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001141 * This is like {@link #getFilesDir()} in that these files will be deleted
1142 * when the application is uninstalled, however there are some important
1143 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001144 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001145 * <li>Shared storage may not always be available, since removable media can
1146 * be ejected by the user. Media state can be checked using
1147 * {@link Environment#getExternalStorageState(File)}.
1148 * <li>There is no security enforced with these files. For example, any
1149 * application holding
1150 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001151 * these files.
1152 * </ul>
1153 * <p>
1154 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001155 * are required to read or write to the path that this method returns.
1156 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1157 * to read the OBB expansion files, you must declare the
1158 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1159 * permission at runtime as follows:
1160 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001161 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001162 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1163 * android:maxSdkVersion="23" />}
1164 * </p>
1165 * <p>
1166 * Starting from {@link android.os.Build.VERSION_CODES#N},
1167 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1168 * permission is not required, so don’t ask for this
1169 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1170 * and if it fails, you must request
1171 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1172 * </p>
1173 *
1174 * <p>
1175 * The following code snippet shows how to do this:
1176 * </p>
1177 *
1178 * <pre>
1179 * File obb = new File(obb_filename);
1180 * boolean open_failed = false;
1181 *
1182 * try {
1183 * BufferedReader br = new BufferedReader(new FileReader(obb));
1184 * open_failed = false;
1185 * ReadObbFile(br);
1186 * } catch (IOException e) {
1187 * open_failed = true;
1188 * }
1189 *
1190 * if (open_failed) {
1191 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1192 * ReadObbFileWithPermission();
1193 * }
1194 * </pre>
1195 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001196 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001197 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001198 * should ensure that multiple instances running under different users don't
1199 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001200 *
1201 * @return the absolute path to application-specific directory. May return
1202 * {@code null} if shared storage is not currently available.
1203 * @see #getObbDirs()
1204 * @see Environment#getExternalStorageState(File)
1205 * @see Environment#isExternalStorageEmulated(File)
1206 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001207 */
1208 public abstract File getObbDir();
1209
1210 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001211 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001212 * shared/external storage devices where the application's OBB files (if
1213 * there are any) can be found. Note if the application does not have any
1214 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001215 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001216 * This is like {@link #getFilesDir()} in that these files will be deleted
1217 * when the application is uninstalled, however there are some important
1218 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001219 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001220 * <li>Shared storage may not always be available, since removable media can
1221 * be ejected by the user. Media state can be checked using
1222 * {@link Environment#getExternalStorageState(File)}.
1223 * <li>There is no security enforced with these files. For example, any
1224 * application holding
1225 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1226 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001227 * </ul>
1228 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001229 * Shared storage devices returned here are considered a stable part of the
1230 * device, including physical media slots under a protective cover. The
1231 * returned paths do not include transient devices, such as USB flash drives
1232 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001233 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001234 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001235 * example, an app may choose to store large files on the device with the
1236 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001237 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001238 * No additional permissions are required for the calling app to read or
1239 * write files under the returned path. Write access outside of these paths
1240 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001241 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001242 * @return the absolute paths to application-specific directories. Some
1243 * individual paths may be {@code null} if that shared storage is
1244 * not currently available. The first path returned is the same as
1245 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001246 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001247 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001248 * @see Environment#isExternalStorageEmulated(File)
1249 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001250 */
1251 public abstract File[] getObbDirs();
1252
1253 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001254 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001255 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001256 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001257 * The system will automatically delete files in this directory as disk
1258 * space is needed elsewhere on the device. The system will always delete
1259 * older files first, as reported by {@link File#lastModified()}. If
1260 * desired, you can exert more control over how files are deleted using
1261 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1262 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1263 * <p>
1264 * Apps are strongly encouraged to keep their usage of cache space below the
1265 * quota returned by
1266 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1267 * goes above this quota, your cached files will be some of the first to be
1268 * deleted when additional disk space is needed. Conversely, if your app
1269 * stays under this quota, your cached files will be some of the last to be
1270 * deleted when additional disk space is needed.
1271 * <p>
1272 * Note that your cache quota will change over time depending on how
1273 * frequently the user interacts with your app, and depending on how much
1274 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001275 * <p>
1276 * The returned path may change over time if the calling app is moved to an
1277 * adopted storage device, so only relative paths should be persisted.
1278 * <p>
1279 * Apps require no extra permissions to read or write to the returned path,
1280 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001281 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001282 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 * @see #openFileOutput
1284 * @see #getFileStreamPath
1285 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001286 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001287 */
1288 public abstract File getCacheDir();
1289
1290 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001291 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001292 * the filesystem designed for storing cached code.
1293 * <p>
1294 * The system will delete any files stored in this location both when your
1295 * specific application is upgraded, and when the entire platform is
1296 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001297 * <p>
1298 * This location is optimal for storing compiled or optimized code generated
1299 * by your application at runtime.
1300 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001301 * The returned path may change over time if the calling app is moved to an
1302 * adopted storage device, so only relative paths should be persisted.
1303 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001304 * Apps require no extra permissions to read or write to the returned path,
1305 * since this path lives in their private storage.
1306 *
1307 * @return The path of the directory holding application code cache files.
1308 */
1309 public abstract File getCodeCacheDir();
1310
1311 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001312 * Returns absolute path to application-specific directory on the primary
1313 * shared/external storage device where the application can place cache
1314 * files it owns. These files are internal to the application, and not
1315 * typically visible to the user as media.
1316 * <p>
1317 * This is like {@link #getCacheDir()} in that these files will be deleted
1318 * when the application is uninstalled, however there are some important
1319 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001320 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001321 * <li>The platform does not always monitor the space available in shared
1322 * storage, and thus may not automatically delete these files. Apps should
1323 * always manage the maximum space used in this location. Currently the only
1324 * time files here will be deleted by the platform is when running on
1325 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1326 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1327 * <li>Shared storage may not always be available, since removable media can
1328 * be ejected by the user. Media state can be checked using
1329 * {@link Environment#getExternalStorageState(File)}.
1330 * <li>There is no security enforced with these files. For example, any
1331 * application holding
1332 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001333 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001334 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001335 * <p>
1336 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001337 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001338 * backed by a private user data partition, which means there is little
1339 * benefit to storing data here instead of the private directory returned by
1340 * {@link #getCacheDir()}.
1341 * <p>
1342 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001343 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001344 * accessible to the calling app. This only applies to paths generated for
1345 * package name of the calling application. To access paths belonging to
1346 * other packages,
1347 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1348 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1349 * <p>
1350 * On devices with multiple users (as described by {@link UserManager}),
1351 * each user has their own isolated shared storage. Applications only have
1352 * access to the shared storage for the user they're running as.
1353 * <p>
1354 * The returned path may change over time if different shared storage media
1355 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001356 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001357 * @return the absolute path to application-specific directory. May return
1358 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001359 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001360 * @see #getExternalCacheDirs()
1361 * @see Environment#getExternalStorageState(File)
1362 * @see Environment#isExternalStorageEmulated(File)
1363 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001364 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001365 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001366 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001367
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001368 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001369 * Returns absolute path to application-specific directory in the preloaded cache.
1370 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1371 * There is no guarantee when these files will be deleted.
1372 * @hide
1373 */
1374 @Nullable
1375 @SystemApi
1376 public abstract File getPreloadsFileCache();
1377
1378 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001379 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001380 * shared/external storage devices where the application can place cache
1381 * files it owns. These files are internal to the application, and not
1382 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001383 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001384 * This is like {@link #getCacheDir()} in that these files will be deleted
1385 * when the application is uninstalled, however there are some important
1386 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001387 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001388 * <li>The platform does not always monitor the space available in shared
1389 * storage, and thus may not automatically delete these files. Apps should
1390 * always manage the maximum space used in this location. Currently the only
1391 * time files here will be deleted by the platform is when running on
1392 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1393 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1394 * <li>Shared storage may not always be available, since removable media can
1395 * be ejected by the user. Media state can be checked using
1396 * {@link Environment#getExternalStorageState(File)}.
1397 * <li>There is no security enforced with these files. For example, any
1398 * application holding
1399 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1400 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001401 * </ul>
1402 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001403 * If a shared storage device is emulated (as determined by
1404 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1405 * backed by a private user data partition, which means there is little
1406 * benefit to storing data here instead of the private directory returned by
1407 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001408 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001409 * Shared storage devices returned here are considered a stable part of the
1410 * device, including physical media slots under a protective cover. The
1411 * returned paths do not include transient devices, such as USB flash drives
1412 * connected to handheld devices.
1413 * <p>
1414 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001415 * example, an app may choose to store large files on the device with the
1416 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001417 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001418 * No additional permissions are required for the calling app to read or
1419 * write files under the returned path. Write access outside of these paths
1420 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001421 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001422 * The returned paths may change over time if different shared storage media
1423 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001424 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001425 * @return the absolute paths to application-specific directories. Some
1426 * individual paths may be {@code null} if that shared storage is
1427 * not currently available. The first path returned is the same as
1428 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001429 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001430 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001431 * @see Environment#isExternalStorageEmulated(File)
1432 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001433 */
1434 public abstract File[] getExternalCacheDirs();
1435
1436 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001437 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001438 * shared/external storage devices where the application can place media
1439 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001440 * {@link MediaStore}.
1441 * <p>
1442 * This is like {@link #getExternalFilesDirs} in that these files will be
1443 * deleted when the application is uninstalled, however there are some
1444 * important differences:
1445 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001446 * <li>Shared storage may not always be available, since removable media can
1447 * be ejected by the user. Media state can be checked using
1448 * {@link Environment#getExternalStorageState(File)}.
1449 * <li>There is no security enforced with these files. For example, any
1450 * application holding
1451 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1452 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001453 * </ul>
1454 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001455 * Shared storage devices returned here are considered a stable part of the
1456 * device, including physical media slots under a protective cover. The
1457 * returned paths do not include transient devices, such as USB flash drives
1458 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001459 * <p>
1460 * An application may store data on any or all of the returned devices. For
1461 * example, an app may choose to store large files on the device with the
1462 * most available space, as measured by {@link StatFs}.
1463 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001464 * No additional permissions are required for the calling app to read or
1465 * write files under the returned path. Write access outside of these paths
1466 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001467 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001468 * The returned paths may change over time if different shared storage media
1469 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001470 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001471 * @return the absolute paths to application-specific directories. Some
1472 * individual paths may be {@code null} if that shared storage is
1473 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001474 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001475 * @see Environment#isExternalStorageEmulated(File)
1476 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001477 */
1478 public abstract File[] getExternalMediaDirs();
1479
1480 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001481 * Returns an array of strings naming the private files associated with
1482 * this Context's application package.
1483 *
1484 * @return Array of strings naming the private files.
1485 *
1486 * @see #openFileInput
1487 * @see #openFileOutput
1488 * @see #deleteFile
1489 */
1490 public abstract String[] fileList();
1491
1492 /**
1493 * Retrieve, creating if needed, a new directory in which the application
1494 * can place its own custom data files. You can use the returned File
1495 * object to create and access files in this directory. Note that files
1496 * created through a File object will only be accessible by your own
1497 * application; you can only set the mode of the entire directory, not
1498 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001499 * <p>
1500 * The returned path may change over time if the calling app is moved to an
1501 * adopted storage device, so only relative paths should be persisted.
1502 * <p>
1503 * Apps require no extra permissions to read or write to the returned path,
1504 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001505 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001506 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001507 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001508 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001509 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001510 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001511 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001512 *
1513 * @see #openFileOutput(String, int)
1514 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001515 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001516
1517 /**
1518 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001519 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 *
1521 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001522 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001524 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001526 * @throws android.database.sqlite.SQLiteException if the database file
1527 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001529 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001530 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001531 * @see #deleteDatabase
1532 */
1533 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001534 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535
1536 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001537 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001538 * application package. Creates the database file if it doesn't exist.
1539 * <p>
1540 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1541 * to be used to handle corruption when sqlite reports database corruption.
1542 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001543 *
1544 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001545 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001546 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001547 * cursor when query is called.
1548 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1549 * sqlite reports database corruption. if null,
1550 * {@link android.database.DefaultDatabaseErrorHandler} is
1551 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001552 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001553 * @throws android.database.sqlite.SQLiteException if the database file
1554 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001555 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001556 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001557 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001558 * @see #deleteDatabase
1559 */
1560 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001561 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001562 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001563
1564 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001565 * Move an existing database file from the given source storage context to
1566 * this context. This is typically used to migrate data between storage
1567 * locations after an upgrade, such as migrating to device protected
1568 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001569 * <p>
1570 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001571 *
1572 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001573 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001574 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001575 * @return {@code true} if the move was successful or if the database didn't
1576 * exist in the source context, otherwise {@code false}.
1577 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001578 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001579 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1580
Jeff Sharkey35871f22016-01-29 17:13:29 -07001581 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 * Delete an existing private SQLiteDatabase associated with this Context's
1583 * application package.
1584 *
1585 * @param name The name (unique in the application package) of the
1586 * database.
1587 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001588 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001589 *
1590 * @see #openOrCreateDatabase
1591 */
1592 public abstract boolean deleteDatabase(String name);
1593
1594 /**
1595 * Returns the absolute path on the filesystem where a database created with
1596 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001597 * <p>
1598 * The returned path may change over time if the calling app is moved to an
1599 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 *
1601 * @param name The name of the database for which you would like to get
1602 * its path.
1603 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001604 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 *
1606 * @see #openOrCreateDatabase
1607 */
1608 public abstract File getDatabasePath(String name);
1609
1610 /**
1611 * Returns an array of strings naming the private databases associated with
1612 * this Context's application package.
1613 *
1614 * @return Array of strings naming the private databases.
1615 *
1616 * @see #openOrCreateDatabase
1617 * @see #deleteDatabase
1618 */
1619 public abstract String[] databaseList();
1620
1621 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001622 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001623 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001625 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001626 public abstract Drawable getWallpaper();
1627
1628 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001629 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001630 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001631 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001632 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001633 public abstract Drawable peekWallpaper();
1634
1635 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001636 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1637 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001639 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 public abstract int getWallpaperDesiredMinimumWidth();
1641
1642 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001643 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1644 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001646 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 public abstract int getWallpaperDesiredMinimumHeight();
1648
1649 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001650 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001651 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001652 * <p>This method requires the caller to hold the permission
1653 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001654 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001655 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001656 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1657
1658 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001659 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001660 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001661 * <p>This method requires the caller to hold the permission
1662 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001664 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 public abstract void setWallpaper(InputStream data) throws IOException;
1666
1667 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001668 * @deprecated Use {@link android.app.WallpaperManager#clear
1669 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001670 * <p>This method requires the caller to hold the permission
1671 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001673 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001674 public abstract void clearWallpaper() throws IOException;
1675
1676 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001677 * Same as {@link #startActivity(Intent, Bundle)} with no options
1678 * specified.
1679 *
1680 * @param intent The description of the activity to start.
1681 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001682 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001683 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001684 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001685 * @see PackageManager#resolveActivity
1686 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001687 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001688
1689 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001690 * Version of {@link #startActivity(Intent)} that allows you to specify the
1691 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001692 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001693 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001694 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001695 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001696 * @hide
1697 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001698 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Tor Norbye788fc2b2015-07-05 16:10:42 -07001699 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001700 throw new RuntimeException("Not implemented. Must override in a subclass.");
1701 }
1702
1703 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001704 * Launch a new activity. You will not receive any information about when
1705 * the activity exits.
1706 *
1707 * <p>Note that if this method is being called from outside of an
1708 * {@link android.app.Activity} Context, then the Intent must include
1709 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1710 * without being started from an existing Activity, there is no existing
1711 * task in which to place the new activity and thus it needs to be placed
1712 * in its own separate task.
1713 *
1714 * <p>This method throws {@link ActivityNotFoundException}
1715 * if there was no Activity found to run the given Intent.
1716 *
1717 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001718 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001719 * May be null if there are no options. See {@link android.app.ActivityOptions}
1720 * for how to build the Bundle supplied here; there are no supported definitions
1721 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001723 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001724 *
Scott Main60dd5202012-06-23 00:01:22 -07001725 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001726 * @see PackageManager#resolveActivity
1727 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001728 public abstract void startActivity(@RequiresPermission Intent intent,
1729 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001730
1731 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001732 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1733 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001734 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001735 * @param intent The description of the activity to start.
1736 * @param options Additional options for how the Activity should be started.
1737 * May be null if there are no options. See {@link android.app.ActivityOptions}
1738 * for how to build the Bundle supplied here; there are no supported definitions
1739 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001740 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001741 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001742 * @hide
1743 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001744 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Tor Norbye788fc2b2015-07-05 16:10:42 -07001745 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1746 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001747 throw new RuntimeException("Not implemented. Must override in a subclass.");
1748 }
1749
1750 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001751 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1752 * is only supported for Views and Fragments.
1753 * @param who The identifier for the calling element that will receive the result.
1754 * @param intent The intent to start.
1755 * @param requestCode The code that will be returned with onActivityResult() identifying this
1756 * request.
1757 * @param options Additional options for how the Activity should be started.
1758 * May be null if there are no options. See {@link android.app.ActivityOptions}
1759 * for how to build the Bundle supplied here; there are no supported definitions
1760 * for building it manually.
1761 * @hide
1762 */
1763 public void startActivityForResult(
1764 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1765 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1766 + "Check canStartActivityForResult() before calling.");
1767 }
1768
1769 /**
1770 * Identifies whether this Context instance will be able to process calls to
1771 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1772 * @hide
1773 */
1774 public boolean canStartActivityForResult() {
1775 return false;
1776 }
1777
1778 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001779 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1780 * specified.
1781 *
1782 * @param intents An array of Intents to be started.
1783 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001784 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001785 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001786 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001787 * @see PackageManager#resolveActivity
1788 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001789 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790
1791 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001792 * Launch multiple new activities. This is generally the same as calling
1793 * {@link #startActivity(Intent)} for the first Intent in the array,
1794 * that activity during its creation calling {@link #startActivity(Intent)}
1795 * for the second entry, etc. Note that unlike that approach, generally
1796 * none of the activities except the last in the array will be created
1797 * at this point, but rather will be created when the user first visits
1798 * them (due to pressing back from the activity on top).
1799 *
1800 * <p>This method throws {@link ActivityNotFoundException}
1801 * if there was no Activity found for <em>any</em> given Intent. In this
1802 * case the state of the activity stack is undefined (some Intents in the
1803 * list may be on it, some not), so you probably want to avoid such situations.
1804 *
1805 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001806 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001807 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001808 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001809 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001810 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001811 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001812 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001813 * @see PackageManager#resolveActivity
1814 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001815 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001816
1817 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001818 * @hide
1819 * Launch multiple new activities. This is generally the same as calling
1820 * {@link #startActivity(Intent)} for the first Intent in the array,
1821 * that activity during its creation calling {@link #startActivity(Intent)}
1822 * for the second entry, etc. Note that unlike that approach, generally
1823 * none of the activities except the last in the array will be created
1824 * at this point, but rather will be created when the user first visits
1825 * them (due to pressing back from the activity on top).
1826 *
1827 * <p>This method throws {@link ActivityNotFoundException}
1828 * if there was no Activity found for <em>any</em> given Intent. In this
1829 * case the state of the activity stack is undefined (some Intents in the
1830 * list may be on it, some not), so you probably want to avoid such situations.
1831 *
1832 * @param intents An array of Intents to be started.
1833 * @param options Additional options for how the Activity should be started.
1834 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001835 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001836 * Context.startActivity(Intent, Bundle)} for more details.
1837 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001838 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1839 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1840 * successful.
1841 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001842 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001843 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001844 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001845 * @see PackageManager#resolveActivity
1846 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001847 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001848 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001849 throw new RuntimeException("Not implemented. Must override in a subclass.");
1850 }
1851
1852 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001853 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1854 * with no options specified.
1855 *
1856 * @param intent The IntentSender to launch.
1857 * @param fillInIntent If non-null, this will be provided as the
1858 * intent parameter to {@link IntentSender#sendIntent}.
1859 * @param flagsMask Intent flags in the original IntentSender that you
1860 * would like to change.
1861 * @param flagsValues Desired values for any bits set in
1862 * <var>flagsMask</var>
1863 * @param extraFlags Always set to 0.
1864 *
1865 * @see #startActivity(Intent)
1866 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1867 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001868 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1869 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1870 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001871
1872 /**
1873 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001874 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001875 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001876 * here; otherwise, its associated action will be executed (such as
1877 * sending a broadcast) as if you had called
1878 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001879 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001880 * @param intent The IntentSender to launch.
1881 * @param fillInIntent If non-null, this will be provided as the
1882 * intent parameter to {@link IntentSender#sendIntent}.
1883 * @param flagsMask Intent flags in the original IntentSender that you
1884 * would like to change.
1885 * @param flagsValues Desired values for any bits set in
1886 * <var>flagsMask</var>
1887 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001888 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001889 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001890 * Context.startActivity(Intent, Bundle)} for more details. If options
1891 * have also been supplied by the IntentSender, options given here will
1892 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001893 *
1894 * @see #startActivity(Intent, Bundle)
1895 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001896 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001897 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1898 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1899 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001900
1901 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001902 * Broadcast the given intent to all interested BroadcastReceivers. This
1903 * call is asynchronous; it returns immediately, and you will continue
1904 * executing while the receivers are run. No results are propagated from
1905 * receivers and receivers can not abort the broadcast. If you want
1906 * to allow receivers to propagate results or abort the broadcast, you must
1907 * send an ordered broadcast using
1908 * {@link #sendOrderedBroadcast(Intent, String)}.
1909 *
1910 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1911 *
1912 * @param intent The Intent to broadcast; all receivers matching this
1913 * Intent will receive the broadcast.
1914 *
1915 * @see android.content.BroadcastReceiver
1916 * @see #registerReceiver
1917 * @see #sendBroadcast(Intent, String)
1918 * @see #sendOrderedBroadcast(Intent, String)
1919 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1920 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001921 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922
1923 /**
1924 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1925 * an optional required permission to be enforced. This
1926 * call is asynchronous; it returns immediately, and you will continue
1927 * executing while the receivers are run. No results are propagated from
1928 * receivers and receivers can not abort the broadcast. If you want
1929 * to allow receivers to propagate results or abort the broadcast, you must
1930 * send an ordered broadcast using
1931 * {@link #sendOrderedBroadcast(Intent, String)}.
1932 *
1933 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1934 *
1935 * @param intent The Intent to broadcast; all receivers matching this
1936 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001937 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 * a receiver must hold in order to receive your broadcast.
1939 * If null, no permission is required.
1940 *
1941 * @see android.content.BroadcastReceiver
1942 * @see #registerReceiver
1943 * @see #sendBroadcast(Intent)
1944 * @see #sendOrderedBroadcast(Intent, String)
1945 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1946 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001947 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001948 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001949
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001950
1951 /**
1952 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1953 * an array of required permissions to be enforced. This call is asynchronous; it returns
1954 * immediately, and you will continue executing while the receivers are run. No results are
1955 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1956 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1957 * using {@link #sendOrderedBroadcast(Intent, String)}.
1958 *
1959 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1960 *
1961 * @param intent The Intent to broadcast; all receivers matching this
1962 * Intent will receive the broadcast.
1963 * @param receiverPermissions Array of names of permissions that a receiver must hold
1964 * in order to receive your broadcast.
1965 * If null or empty, no permissions are required.
1966 *
1967 * @see android.content.BroadcastReceiver
1968 * @see #registerReceiver
1969 * @see #sendBroadcast(Intent)
1970 * @see #sendOrderedBroadcast(Intent, String)
1971 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1972 * @hide
1973 */
1974 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1975 String[] receiverPermissions);
1976
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001977 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001978 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1979 * an optional required permission to be enforced. This
1980 * call is asynchronous; it returns immediately, and you will continue
1981 * executing while the receivers are run. No results are propagated from
1982 * receivers and receivers can not abort the broadcast. If you want
1983 * to allow receivers to propagate results or abort the broadcast, you must
1984 * send an ordered broadcast using
1985 * {@link #sendOrderedBroadcast(Intent, String)}.
1986 *
1987 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1988 *
1989 * @param intent The Intent to broadcast; all receivers matching this
1990 * Intent will receive the broadcast.
1991 * @param receiverPermission (optional) String naming a permission that
1992 * a receiver must hold in order to receive your broadcast.
1993 * If null, no permission is required.
1994 * @param options (optional) Additional sending options, generated from a
1995 * {@link android.app.BroadcastOptions}.
1996 *
1997 * @see android.content.BroadcastReceiver
1998 * @see #registerReceiver
1999 * @see #sendBroadcast(Intent)
2000 * @see #sendOrderedBroadcast(Intent, String)
2001 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2002 * @hide
2003 */
2004 @SystemApi
2005 public abstract void sendBroadcast(Intent intent,
2006 @Nullable String receiverPermission,
2007 @Nullable Bundle options);
2008
2009 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002010 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002011 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002012 * @hide
2013 */
2014 public abstract void sendBroadcast(Intent intent,
2015 String receiverPermission, int appOp);
2016
2017 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002018 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2019 * them one at a time to allow more preferred receivers to consume the
2020 * broadcast before it is delivered to less preferred receivers. This
2021 * call is asynchronous; it returns immediately, and you will continue
2022 * executing while the receivers are run.
2023 *
2024 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2025 *
2026 * @param intent The Intent to broadcast; all receivers matching this
2027 * Intent will receive the broadcast.
2028 * @param receiverPermission (optional) String naming a permissions that
2029 * a receiver must hold in order to receive your broadcast.
2030 * If null, no permission is required.
2031 *
2032 * @see android.content.BroadcastReceiver
2033 * @see #registerReceiver
2034 * @see #sendBroadcast(Intent)
2035 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2036 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002037 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002038 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039
2040 /**
2041 * Version of {@link #sendBroadcast(Intent)} that allows you to
2042 * receive data back from the broadcast. This is accomplished by
2043 * supplying your own BroadcastReceiver when calling, which will be
2044 * treated as a final receiver at the end of the broadcast -- its
2045 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002046 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002047 * be serialized in the same way as calling
2048 * {@link #sendOrderedBroadcast(Intent, String)}.
2049 *
2050 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2051 * asynchronous; it will return before
2052 * resultReceiver.onReceive() is called.
2053 *
2054 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2055 *
2056 * @param intent The Intent to broadcast; all receivers matching this
2057 * Intent will receive the broadcast.
2058 * @param receiverPermission String naming a permissions that
2059 * a receiver must hold in order to receive your broadcast.
2060 * If null, no permission is required.
2061 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2062 * receiver of the broadcast.
2063 * @param scheduler A custom Handler with which to schedule the
2064 * resultReceiver callback; if null it will be
2065 * scheduled in the Context's main thread.
2066 * @param initialCode An initial value for the result code. Often
2067 * Activity.RESULT_OK.
2068 * @param initialData An initial value for the result data. Often
2069 * null.
2070 * @param initialExtras An initial value for the result extras. Often
2071 * null.
2072 *
2073 * @see #sendBroadcast(Intent)
2074 * @see #sendBroadcast(Intent, String)
2075 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 * @see android.content.BroadcastReceiver
2077 * @see #registerReceiver
2078 * @see android.app.Activity#RESULT_OK
2079 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002080 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002081 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002082 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2083 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084
2085 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002086 * Version of {@link #sendBroadcast(Intent)} that allows you to
2087 * receive data back from the broadcast. This is accomplished by
2088 * supplying your own BroadcastReceiver when calling, which will be
2089 * treated as a final receiver at the end of the broadcast -- its
2090 * {@link BroadcastReceiver#onReceive} method will be called with
2091 * the result values collected from the other receivers. The broadcast will
2092 * be serialized in the same way as calling
2093 * {@link #sendOrderedBroadcast(Intent, String)}.
2094 *
2095 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2096 * asynchronous; it will return before
2097 * resultReceiver.onReceive() is called.
2098 *
2099 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2100 *
2101 *
2102 * @param intent The Intent to broadcast; all receivers matching this
2103 * Intent will receive the broadcast.
2104 * @param receiverPermission String naming a permissions that
2105 * a receiver must hold in order to receive your broadcast.
2106 * If null, no permission is required.
2107 * @param options (optional) Additional sending options, generated from a
2108 * {@link android.app.BroadcastOptions}.
2109 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2110 * receiver of the broadcast.
2111 * @param scheduler A custom Handler with which to schedule the
2112 * resultReceiver callback; if null it will be
2113 * scheduled in the Context's main thread.
2114 * @param initialCode An initial value for the result code. Often
2115 * Activity.RESULT_OK.
2116 * @param initialData An initial value for the result data. Often
2117 * null.
2118 * @param initialExtras An initial value for the result extras. Often
2119 * null.
2120 * @see #sendBroadcast(Intent)
2121 * @see #sendBroadcast(Intent, String)
2122 * @see #sendOrderedBroadcast(Intent, String)
2123 * @see android.content.BroadcastReceiver
2124 * @see #registerReceiver
2125 * @see android.app.Activity#RESULT_OK
2126 * @hide
2127 */
2128 @SystemApi
2129 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2130 @Nullable String receiverPermission, @Nullable Bundle options,
2131 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2132 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2133
2134 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002135 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2136 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002137 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002138 * @hide
2139 */
2140 public abstract void sendOrderedBroadcast(Intent intent,
2141 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2142 Handler scheduler, int initialCode, String initialData,
2143 Bundle initialExtras);
2144
2145 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002146 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2147 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002148 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002149 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002150 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002151 * @see #sendBroadcast(Intent)
2152 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002153 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002154 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2155 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002156
2157 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002158 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2159 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002160 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002161 *
2162 * @param intent The Intent to broadcast; all receivers matching this
2163 * Intent will receive the broadcast.
2164 * @param user UserHandle to send the intent to.
2165 * @param receiverPermission (optional) String naming a permission that
2166 * a receiver must hold in order to receive your broadcast.
2167 * If null, no permission is required.
2168 *
2169 * @see #sendBroadcast(Intent, String)
2170 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002171 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002172 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2173 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002174
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002175 /**
2176 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2177 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002178 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002179 *
2180 * @param intent The Intent to broadcast; all receivers matching this
2181 * Intent will receive the broadcast.
2182 * @param user UserHandle to send the intent to.
2183 * @param receiverPermission (optional) String naming a permission that
2184 * a receiver must hold in order to receive your broadcast.
2185 * If null, no permission is required.
2186 * @param options (optional) Additional sending options, generated from a
2187 * {@link android.app.BroadcastOptions}.
2188 *
2189 * @see #sendBroadcast(Intent, String, Bundle)
2190 * @hide
2191 */
2192 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002193 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002194 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2195 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002196
2197 /**
2198 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2199 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002200 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002201 *
2202 * @param intent The Intent to broadcast; all receivers matching this
2203 * Intent will receive the broadcast.
2204 * @param user UserHandle to send the intent to.
2205 * @param receiverPermission (optional) String naming a permission that
2206 * a receiver must hold in order to receive your broadcast.
2207 * If null, no permission is required.
2208 * @param appOp The app op associated with the broadcast.
2209 *
2210 * @see #sendBroadcast(Intent, String)
2211 *
2212 * @hide
2213 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002214 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002215 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2216 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002217
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002218 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002219 * Version of
2220 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2221 * that allows you to specify the
2222 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002223 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002224 *
2225 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2226 *
2227 * @param intent The Intent to broadcast; all receivers matching this
2228 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002229 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002230 * @param receiverPermission String naming a permissions that
2231 * a receiver must hold in order to receive your broadcast.
2232 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002233 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2234 * receiver of the broadcast.
2235 * @param scheduler A custom Handler with which to schedule the
2236 * resultReceiver callback; if null it will be
2237 * scheduled in the Context's main thread.
2238 * @param initialCode An initial value for the result code. Often
2239 * Activity.RESULT_OK.
2240 * @param initialData An initial value for the result data. Often
2241 * null.
2242 * @param initialExtras An initial value for the result extras. Often
2243 * null.
2244 *
2245 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2246 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002247 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002248 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2249 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002250 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2251 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002252
2253 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002254 * Similar to above but takes an appOp as well, to enforce restrictions.
2255 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2256 * BroadcastReceiver, Handler, int, String, Bundle)
2257 * @hide
2258 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002259 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Amith Yamasani3cf75722014-05-16 12:37:29 -07002260 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2261 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2262 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2263 @Nullable Bundle initialExtras);
2264
2265 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002266 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2267 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2268 * BroadcastReceiver, Handler, int, String, Bundle)
2269 * @hide
2270 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002271 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002272 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2273 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2274 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2275 @Nullable String initialData, @Nullable Bundle initialExtras);
2276
2277 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002278 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 * Intent you are sending stays around after the broadcast is complete,
2280 * so that others can quickly retrieve that data through the return
2281 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2282 * all other ways, this behaves the same as
2283 * {@link #sendBroadcast(Intent)}.
2284 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002285 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2286 * can access them), no protection (anyone can modify them), and many other problems.
2287 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2288 * has changed, with another mechanism for apps to retrieve the current value whenever
2289 * desired.
2290 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002291 * @param intent The Intent to broadcast; all receivers matching this
2292 * Intent will receive the broadcast, and the Intent will be held to
2293 * be re-broadcast to future receivers.
2294 *
2295 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002296 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002298 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002299 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002300 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002301
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002302 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002303 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002304 * receive data back from the broadcast. This is accomplished by
2305 * supplying your own BroadcastReceiver when calling, which will be
2306 * treated as a final receiver at the end of the broadcast -- its
2307 * {@link BroadcastReceiver#onReceive} method will be called with
2308 * the result values collected from the other receivers. The broadcast will
2309 * be serialized in the same way as calling
2310 * {@link #sendOrderedBroadcast(Intent, String)}.
2311 *
2312 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2313 * asynchronous; it will return before
2314 * resultReceiver.onReceive() is called. Note that the sticky data
2315 * stored is only the data you initially supply to the broadcast, not
2316 * the result of any changes made by the receivers.
2317 *
2318 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2319 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002320 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2321 * can access them), no protection (anyone can modify them), and many other problems.
2322 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2323 * has changed, with another mechanism for apps to retrieve the current value whenever
2324 * desired.
2325 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002326 * @param intent The Intent to broadcast; all receivers matching this
2327 * Intent will receive the broadcast.
2328 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2329 * receiver of the broadcast.
2330 * @param scheduler A custom Handler with which to schedule the
2331 * resultReceiver callback; if null it will be
2332 * scheduled in the Context's main thread.
2333 * @param initialCode An initial value for the result code. Often
2334 * Activity.RESULT_OK.
2335 * @param initialData An initial value for the result data. Often
2336 * null.
2337 * @param initialExtras An initial value for the result extras. Often
2338 * null.
2339 *
2340 * @see #sendBroadcast(Intent)
2341 * @see #sendBroadcast(Intent, String)
2342 * @see #sendOrderedBroadcast(Intent, String)
2343 * @see #sendStickyBroadcast(Intent)
2344 * @see android.content.BroadcastReceiver
2345 * @see #registerReceiver
2346 * @see android.app.Activity#RESULT_OK
2347 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002348 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002349 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002350 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002351 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002352 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2353 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002356 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002357 * so that it is as if the sticky broadcast had never happened.
2358 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002359 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2360 * can access them), no protection (anyone can modify them), and many other problems.
2361 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2362 * has changed, with another mechanism for apps to retrieve the current value whenever
2363 * desired.
2364 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002365 * @param intent The Intent that was previously broadcast.
2366 *
2367 * @see #sendStickyBroadcast
2368 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002369 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002370 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002371 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372
2373 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002374 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002375 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002376 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002377 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002378 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2379 * can access them), no protection (anyone can modify them), and many other problems.
2380 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2381 * has changed, with another mechanism for apps to retrieve the current value whenever
2382 * desired.
2383 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002384 * @param intent The Intent to broadcast; all receivers matching this
2385 * Intent will receive the broadcast, and the Intent will be held to
2386 * be re-broadcast to future receivers.
2387 * @param user UserHandle to send the intent to.
2388 *
2389 * @see #sendBroadcast(Intent)
2390 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002391 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002392 @RequiresPermission(allOf = {
2393 android.Manifest.permission.INTERACT_ACROSS_USERS,
2394 android.Manifest.permission.BROADCAST_STICKY
2395 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002396 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2397 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002398
2399 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002400 * @hide
2401 * This is just here for sending CONNECTIVITY_ACTION.
2402 */
2403 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002404 @RequiresPermission(allOf = {
2405 android.Manifest.permission.INTERACT_ACROSS_USERS,
2406 android.Manifest.permission.BROADCAST_STICKY
2407 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002408 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2409 UserHandle user, Bundle options);
2410
2411 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002412 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002413 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2414 * that allows you to specify the
2415 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002416 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002417 *
2418 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2419 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002420 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2421 * can access them), no protection (anyone can modify them), and many other problems.
2422 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2423 * has changed, with another mechanism for apps to retrieve the current value whenever
2424 * desired.
2425 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002426 * @param intent The Intent to broadcast; all receivers matching this
2427 * Intent will receive the broadcast.
2428 * @param user UserHandle to send the intent to.
2429 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2430 * receiver of the broadcast.
2431 * @param scheduler A custom Handler with which to schedule the
2432 * resultReceiver callback; if null it will be
2433 * scheduled in the Context's main thread.
2434 * @param initialCode An initial value for the result code. Often
2435 * Activity.RESULT_OK.
2436 * @param initialData An initial value for the result data. Often
2437 * null.
2438 * @param initialExtras An initial value for the result extras. Often
2439 * null.
2440 *
2441 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2442 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002443 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002444 @RequiresPermission(allOf = {
2445 android.Manifest.permission.INTERACT_ACROSS_USERS,
2446 android.Manifest.permission.BROADCAST_STICKY
2447 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002448 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002449 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002450 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2451 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002452
2453 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002454 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002455 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002456 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002457 *
2458 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2459 * permission in order to use this API. If you do not hold that
2460 * permission, {@link SecurityException} will be thrown.
2461 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002462 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2463 * can access them), no protection (anyone can modify them), and many other problems.
2464 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2465 * has changed, with another mechanism for apps to retrieve the current value whenever
2466 * desired.
2467 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002468 * @param intent The Intent that was previously broadcast.
2469 * @param user UserHandle to remove the sticky broadcast from.
2470 *
2471 * @see #sendStickyBroadcastAsUser
2472 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002473 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002474 @RequiresPermission(allOf = {
2475 android.Manifest.permission.INTERACT_ACROSS_USERS,
2476 android.Manifest.permission.BROADCAST_STICKY
2477 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002478 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2479 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002480
2481 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002482 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002483 * <var>receiver</var> will be called with any broadcast Intent that
2484 * matches <var>filter</var>, in the main application thread.
2485 *
2486 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002487 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002488 * registrations. If your IntentFilter matches one of these sticky
2489 * Intents, that Intent will be returned by this function
2490 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2491 * been broadcast.
2492 *
2493 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2494 * in which case each of these will be sent to <var>receiver</var>. In
2495 * this case, only one of these can be returned directly by the function;
2496 * which of these that is returned is arbitrarily decided by the system.
2497 *
2498 * <p>If you know the Intent your are registering for is sticky, you can
2499 * supply null for your <var>receiver</var>. In this case, no receiver is
2500 * registered -- the function simply returns the sticky Intent that
2501 * matches <var>filter</var>. In the case of multiple matches, the same
2502 * rules as described above apply.
2503 *
2504 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2505 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002506 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2507 * registered with this method will correctly respect the
2508 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2509 * Prior to that, it would be ignored and delivered to all matching registered
2510 * receivers. Be careful if using this for security.</p>
2511 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002512 * <p class="note">Note: this method <em>cannot be called from a
2513 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2514 * that is declared in an application's manifest. It is okay, however, to call
2515 * this method from another BroadcastReceiver that has itself been registered
2516 * at run time with {@link #registerReceiver}, since the lifetime of such a
2517 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 *
2519 * @param receiver The BroadcastReceiver to handle the broadcast.
2520 * @param filter Selects the Intent broadcasts to be received.
2521 *
2522 * @return The first sticky intent found that matches <var>filter</var>,
2523 * or null if there are none.
2524 *
2525 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2526 * @see #sendBroadcast
2527 * @see #unregisterReceiver
2528 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002529 @Nullable
2530 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 IntentFilter filter);
2532
2533 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002534 * Register to receive intent broadcasts, with the receiver optionally being
2535 * exposed to Instant Apps. See
2536 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2537 * information. By default Instant Apps cannot interact with receivers in other
2538 * applications, this allows you to expose a receiver that Instant Apps can
2539 * interact with.
2540 *
2541 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2542 *
2543 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2544 * registered with this method will correctly respect the
2545 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2546 * Prior to that, it would be ignored and delivered to all matching registered
2547 * receivers. Be careful if using this for security.</p>
2548 *
2549 * @param receiver The BroadcastReceiver to handle the broadcast.
2550 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002551 * @param flags Additional options for the receiver. May be 0 or
2552 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002553 *
2554 * @return The first sticky intent found that matches <var>filter</var>,
2555 * or null if there are none.
2556 *
2557 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2558 * @see #sendBroadcast
2559 * @see #unregisterReceiver
2560 */
2561 @Nullable
2562 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2563 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002564 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002565
2566 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002567 * Register to receive intent broadcasts, to run in the context of
2568 * <var>scheduler</var>. See
2569 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2570 * information. This allows you to enforce permissions on who can
2571 * broadcast intents to your receiver, or have the receiver run in
2572 * a different thread than the main application thread.
2573 *
2574 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2575 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002576 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2577 * registered with this method will correctly respect the
2578 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2579 * Prior to that, it would be ignored and delivered to all matching registered
2580 * receivers. Be careful if using this for security.</p>
2581 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002582 * @param receiver The BroadcastReceiver to handle the broadcast.
2583 * @param filter Selects the Intent broadcasts to be received.
2584 * @param broadcastPermission String naming a permissions that a
2585 * broadcaster must hold in order to send an Intent to you. If null,
2586 * no permission is required.
2587 * @param scheduler Handler identifying the thread that will receive
2588 * the Intent. If null, the main thread of the process will be used.
2589 *
2590 * @return The first sticky intent found that matches <var>filter</var>,
2591 * or null if there are none.
2592 *
2593 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2594 * @see #sendBroadcast
2595 * @see #unregisterReceiver
2596 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002597 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002598 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002599 IntentFilter filter, @Nullable String broadcastPermission,
2600 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002601
2602 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002603 * Register to receive intent broadcasts, to run in the context of
2604 * <var>scheduler</var>. See
2605 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002606 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2607 * for more information.
2608 *
2609 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2610 *
2611 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2612 * registered with this method will correctly respect the
2613 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2614 * Prior to that, it would be ignored and delivered to all matching registered
2615 * receivers. Be careful if using this for security.</p>
2616 *
2617 * @param receiver The BroadcastReceiver to handle the broadcast.
2618 * @param filter Selects the Intent broadcasts to be received.
2619 * @param broadcastPermission String naming a permissions that a
2620 * broadcaster must hold in order to send an Intent to you. If null,
2621 * no permission is required.
2622 * @param scheduler Handler identifying the thread that will receive
2623 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002624 * @param flags Additional options for the receiver. May be 0 or
2625 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002626 *
2627 * @return The first sticky intent found that matches <var>filter</var>,
2628 * or null if there are none.
2629 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002630 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002631 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2632 * @see #sendBroadcast
2633 * @see #unregisterReceiver
2634 */
2635 @Nullable
2636 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2637 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002638 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002639
2640 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002641 * @hide
2642 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2643 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002644 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002645 *
2646 * @param receiver The BroadcastReceiver to handle the broadcast.
2647 * @param user UserHandle to send the intent to.
2648 * @param filter Selects the Intent broadcasts to be received.
2649 * @param broadcastPermission String naming a permissions that a
2650 * broadcaster must hold in order to send an Intent to you. If null,
2651 * no permission is required.
2652 * @param scheduler Handler identifying the thread that will receive
2653 * the Intent. If null, the main thread of the process will be used.
2654 *
2655 * @return The first sticky intent found that matches <var>filter</var>,
2656 * or null if there are none.
2657 *
Jeff Brown6e539312015-02-24 18:53:21 -08002658 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002659 * @see #sendBroadcast
2660 * @see #unregisterReceiver
2661 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002662 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002663 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002664 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002665 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2666 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002667
2668 /**
2669 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2670 * filters that have been registered for this BroadcastReceiver will be
2671 * removed.
2672 *
2673 * @param receiver The BroadcastReceiver to unregister.
2674 *
2675 * @see #registerReceiver
2676 */
2677 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2678
2679 /**
2680 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002681 * should either contain the complete class name of a specific service
2682 * implementation to start, or a specific package name to target. If the
2683 * Intent is less specified, it logs a warning about this. In this case any of the
2684 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 * is not already running, it will be instantiated and started (creating a
2686 * process for it if needed); if it is running then it remains running.
2687 *
2688 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002689 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 * with the <var>intent</var> given here. This provides a convenient way
2691 * to submit jobs to a service without having to bind and call on to its
2692 * interface.
2693 *
2694 * <p>Using startService() overrides the default service lifetime that is
2695 * managed by {@link #bindService}: it requires the service to remain
2696 * running until {@link #stopService} is called, regardless of whether
2697 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002698 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002699 * a single call to {@link #stopService} will stop it.
2700 *
2701 * <p>The system attempts to keep running services around as much as
2702 * possible. The only time they should be stopped is if the current
2703 * foreground application is using so many resources that the service needs
2704 * to be killed. If any errors happen in the service's process, it will
2705 * automatically be restarted.
2706 *
2707 * <p>This function will throw {@link SecurityException} if you do not
2708 * have permission to start the given service.
2709 *
Chris Craik1e353522016-04-18 10:20:50 -07002710 * <p class="note"><strong>Note:</strong> Each call to startService()
2711 * results in significant work done by the system to manage service
2712 * lifecycle surrounding the processing of the intent, which can take
2713 * multiple milliseconds of CPU time. Due to this cost, startService()
2714 * should not be used for frequent intent delivery to a service, and only
2715 * for scheduling significant work. Use {@link #bindService bound services}
2716 * for high frequency calls.
2717 * </p>
2718 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002719 * @param service Identifies the service to be started. The Intent must be
2720 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002721 * may be included in the Intent extras to supply arguments along with
2722 * this specific start call.
2723 *
2724 * @return If the service is being started or is already running, the
2725 * {@link ComponentName} of the actual service that was started is
2726 * returned; else if the service does not exist null is returned.
2727 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002728 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002729 * or the service can not be found.
2730 * @throws IllegalStateException If the application is in a state where the service
2731 * 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 -08002732 *
2733 * @see #stopService
2734 * @see #bindService
2735 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002736 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002737 public abstract ComponentName startService(Intent service);
2738
2739 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002740 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002741 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2742 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002743 * an amount of time comparable to the ANR interval to do this, otherwise the system
2744 * will automatically stop the service and declare the app ANR.
2745 *
2746 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2747 * at any time, regardless of whether the app hosting the service is in a foreground
2748 * state.
2749 *
2750 * @param service Identifies the service to be started. The Intent must be
2751 * fully explicit (supplying a component name). Additional values
2752 * may be included in the Intent extras to supply arguments along with
2753 * this specific start call.
2754 *
2755 * @return If the service is being started or is already running, the
2756 * {@link ComponentName} of the actual service that was started is
2757 * returned; else if the service does not exist null is returned.
2758 *
2759 * @throws SecurityException If the caller does not have permission to access the service
2760 * or the service can not be found.
2761 *
2762 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002763 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002764 */
2765 @Nullable
2766 public abstract ComponentName startForegroundService(Intent service);
2767
2768 /**
2769 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2770 */
2771 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002772 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002773 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2774
2775 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002776 * Request that a given application service be stopped. If the service is
2777 * not running, nothing happens. Otherwise it is stopped. Note that calls
2778 * to startService() are not counted -- this stops the service no matter
2779 * how many times it was started.
2780 *
2781 * <p>Note that if a stopped service still has {@link ServiceConnection}
2782 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2783 * not be destroyed until all of these bindings are removed. See
2784 * the {@link android.app.Service} documentation for more details on a
2785 * service's lifecycle.
2786 *
2787 * <p>This function will throw {@link SecurityException} if you do not
2788 * have permission to stop the given service.
2789 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002790 * @param service Description of the service to be stopped. The Intent must be either
2791 * fully explicit (supplying a component name) or specify a specific package
2792 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002793 *
2794 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002795 * 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 -08002796 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002797 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002798 * or the service can not be found.
2799 * @throws IllegalStateException If the application is in a state where the service
2800 * 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 -08002801 *
2802 * @see #startService
2803 */
2804 public abstract boolean stopService(Intent service);
2805
2806 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002807 * @hide like {@link #startService(Intent)} but for a specific user.
2808 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002809 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002810 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002811 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2812
2813 /**
2814 * @hide like {@link #stopService(Intent)} but for a specific user.
2815 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002816 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002817 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002818
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002819 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 * Connect to an application service, creating it if needed. This defines
2821 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002822 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 * told if it dies and restarts. The service will be considered required
2824 * by the system only for as long as the calling context exists. For
2825 * example, if this Context is an Activity that is stopped, the service will
2826 * not be required to continue running until the Activity is resumed.
2827 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002828 * <p>If the service does not support binding, it may return {@code null} from
2829 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
2830 * the ServiceConnection's
2831 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
2832 * will be invoked instead of
2833 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
2834 *
2835 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002836 * have permission to bind to the given service.
2837 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002838 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002839 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002840 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002841 * {@link #startService} with the arguments containing the command to be
2842 * sent, with the service calling its
2843 * {@link android.app.Service#stopSelf(int)} method when done executing
2844 * that command. See the API demo App/Service/Service Start Arguments
2845 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002846 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002847 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2848 * is tied to another object (the one that registered it).</p>
2849 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002850 * @param service Identifies the service to connect to. The Intent must
2851 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002852 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002853 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002854 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002855 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2856 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2857 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2858 * {@link #BIND_WAIVE_PRIORITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07002859 * @return {@code true} if the system is in the process of bringing up a
2860 * service that your client has permission to bind to; {@code false}
2861 * if the system couldn't find the service or if your client doesn't
2862 * have permission to bind to it. If this value is {@code true}, you
2863 * should later call {@link #unbindService} to release the
2864 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002865 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002866 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002867 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002868 *
2869 * @see #unbindService
2870 * @see #startService
2871 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002872 * @see #BIND_DEBUG_UNBIND
2873 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002874 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002875 public abstract boolean bindService(@RequiresPermission Intent service,
2876 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877
2878 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002879 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002880 * argument for use by system server and other multi-user aware code.
2881 * @hide
2882 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002883 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002884 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002885 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002886 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002887 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002888 throw new RuntimeException("Not implemented. Must override in a subclass.");
2889 }
2890
2891 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002892 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2893 * explicit non-null Handler to run the ServiceConnection callbacks on.
2894 *
2895 * @hide
2896 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002897 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Adrian Roos691546e2016-02-09 10:13:41 -08002898 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2899 Handler handler, UserHandle user) {
2900 throw new RuntimeException("Not implemented. Must override in a subclass.");
2901 }
2902
2903 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002904 * Disconnect from an application service. You will no longer receive
2905 * calls as the service is restarted, and the service is now allowed to
2906 * stop at any time.
2907 *
2908 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002909 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002910 *
2911 * @see #bindService
2912 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002913 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002914
2915 /**
2916 * Start executing an {@link android.app.Instrumentation} class. The given
2917 * Instrumentation component will be run by killing its target application
2918 * (if currently running), starting the target process, instantiating the
2919 * instrumentation component, and then letting it drive the application.
2920 *
2921 * <p>This function is not synchronous -- it returns as soon as the
2922 * instrumentation has started and while it is running.
2923 *
2924 * <p>Instrumentation is normally only allowed to run against a package
2925 * that is either unsigned or signed with a signature that the
2926 * the instrumentation package is also signed with (ensuring the target
2927 * trusts the instrumentation).
2928 *
2929 * @param className Name of the Instrumentation component to be run.
2930 * @param profileFile Optional path to write profiling data as the
2931 * instrumentation runs, or null for no profiling.
2932 * @param arguments Additional optional arguments to pass to the
2933 * instrumentation, or null.
2934 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002935 * @return {@code true} if the instrumentation was successfully started,
2936 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002938 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2939 @Nullable String profileFile, @Nullable Bundle arguments);
2940
2941 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07002942 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07002943 POWER_SERVICE,
2944 WINDOW_SERVICE,
2945 LAYOUT_INFLATER_SERVICE,
2946 ACCOUNT_SERVICE,
2947 ACTIVITY_SERVICE,
2948 ALARM_SERVICE,
2949 NOTIFICATION_SERVICE,
2950 ACCESSIBILITY_SERVICE,
2951 CAPTIONING_SERVICE,
2952 KEYGUARD_SERVICE,
2953 LOCATION_SERVICE,
2954 //@hide: COUNTRY_DETECTOR,
2955 SEARCH_SERVICE,
2956 SENSOR_SERVICE,
2957 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07002958 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002959 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00002960 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002961 VIBRATOR_SERVICE,
2962 //@hide: STATUS_BAR_SERVICE,
2963 CONNECTIVITY_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08002964 IPSEC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002965 //@hide: UPDATE_LOCK_SERVICE,
2966 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00002967 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002968 //@hide: NETWORK_POLICY_SERVICE,
2969 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07002970 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002971 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07002972 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07002973 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002974 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07002975 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08002976 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002977 NSD_SERVICE,
2978 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07002979 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002980 MEDIA_ROUTER_SERVICE,
2981 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002982 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08002983 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002984 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002985 CLIPBOARD_SERVICE,
2986 INPUT_METHOD_SERVICE,
2987 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01002988 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07002989 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08002990 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07002991 //@hide: BACKUP_SERVICE,
2992 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07002993 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07002994 DEVICE_POLICY_SERVICE,
2995 UI_MODE_SERVICE,
2996 DOWNLOAD_SERVICE,
2997 NFC_SERVICE,
2998 BLUETOOTH_SERVICE,
2999 //@hide: SIP_SERVICE,
3000 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003001 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003002 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003003 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003004 INPUT_SERVICE,
3005 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003006 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003007 RESTRICTIONS_SERVICE,
3008 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003009 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003010 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003011 CONSUMER_IR_SERVICE,
3012 //@hide: TRUST_SERVICE,
3013 TV_INPUT_SERVICE,
3014 //@hide: NETWORK_SCORE_SERVICE,
3015 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003016 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003017 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003018 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003019 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003020 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003021 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003022 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003023 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003024 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003025 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003026 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003027 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003028 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003029 //@hide: INCIDENT_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003030 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003031 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003032 CROSS_PROFILE_APPS_SERVICE,
3033 //@hide: SYSTEM_UPDATE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003034 })
3035 @Retention(RetentionPolicy.SOURCE)
3036 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003037
3038 /**
3039 * Return the handle to a system-level service by name. The class of the
3040 * returned object varies by the requested name. Currently available names
3041 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003042 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003043 * <dl>
3044 * <dt> {@link #WINDOW_SERVICE} ("window")
3045 * <dd> The top-level window manager in which you can place custom
3046 * windows. The returned object is a {@link android.view.WindowManager}.
3047 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3048 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3049 * in this context.
3050 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3051 * <dd> A {@link android.app.ActivityManager} for interacting with the
3052 * global activity state of the system.
3053 * <dt> {@link #POWER_SERVICE} ("power")
3054 * <dd> A {@link android.os.PowerManager} for controlling power
3055 * management.
3056 * <dt> {@link #ALARM_SERVICE} ("alarm")
3057 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3058 * time of your choosing.
3059 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3060 * <dd> A {@link android.app.NotificationManager} for informing the user
3061 * of background events.
3062 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3063 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3064 * <dt> {@link #LOCATION_SERVICE} ("location")
3065 * <dd> A {@link android.location.LocationManager} for controlling location
3066 * (e.g., GPS) updates.
3067 * <dt> {@link #SEARCH_SERVICE} ("search")
3068 * <dd> A {@link android.app.SearchManager} for handling search.
3069 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3070 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3071 * hardware.
3072 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3073 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3074 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003075 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3076 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3077 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003078 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003079 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3080 * connectivity. On releases before NYC, it should only be obtained from an application
3081 * context, and not from any other derived context to avoid memory leaks within the calling
3082 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003083 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3084 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3085 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003086 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3087 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3088 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3090 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3091 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003092 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3093 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003094 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003095 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003096 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003097 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003098 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3099 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003100 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3101 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3102 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003103 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003104 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003105 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003106 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003107 * <p>Note: System services obtained via this API may be closely associated with
3108 * the Context in which they are obtained from. In general, do not share the
3109 * service objects between various different contexts (Activities, Applications,
3110 * Services, Providers, etc.)
3111 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003112 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3113 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
3114 * {@link #FINGERPRINT_SERVICE}, {@link #SHORTCUT_SERVICE}, {@link #USB_SERVICE},
3115 * {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, {@link #WIFI_SERVICE},
3116 * {@link #WIFI_AWARE_SERVICE}. For these services this method will return <code>null</code>.
3117 * Generally, if you are running as an instant app you should always check whether the result
3118 * of this method is null.
3119 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003120 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003121 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003123 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003124 * @see #WINDOW_SERVICE
3125 * @see android.view.WindowManager
3126 * @see #LAYOUT_INFLATER_SERVICE
3127 * @see android.view.LayoutInflater
3128 * @see #ACTIVITY_SERVICE
3129 * @see android.app.ActivityManager
3130 * @see #POWER_SERVICE
3131 * @see android.os.PowerManager
3132 * @see #ALARM_SERVICE
3133 * @see android.app.AlarmManager
3134 * @see #NOTIFICATION_SERVICE
3135 * @see android.app.NotificationManager
3136 * @see #KEYGUARD_SERVICE
3137 * @see android.app.KeyguardManager
3138 * @see #LOCATION_SERVICE
3139 * @see android.location.LocationManager
3140 * @see #SEARCH_SERVICE
3141 * @see android.app.SearchManager
3142 * @see #SENSOR_SERVICE
3143 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003144 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003145 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 * @see #VIBRATOR_SERVICE
3147 * @see android.os.Vibrator
3148 * @see #CONNECTIVITY_SERVICE
3149 * @see android.net.ConnectivityManager
3150 * @see #WIFI_SERVICE
3151 * @see android.net.wifi.WifiManager
3152 * @see #AUDIO_SERVICE
3153 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003154 * @see #MEDIA_ROUTER_SERVICE
3155 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 * @see #TELEPHONY_SERVICE
3157 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003158 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3159 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003160 * @see #CARRIER_CONFIG_SERVICE
3161 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 * @see #INPUT_METHOD_SERVICE
3163 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003164 * @see #UI_MODE_SERVICE
3165 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003166 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003167 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003168 * @see #BATTERY_SERVICE
3169 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003170 * @see #JOB_SCHEDULER_SERVICE
3171 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003172 * @see #NETWORK_STATS_SERVICE
3173 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003174 * @see android.os.HardwarePropertiesManager
3175 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003176 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003177 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178
3179 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003180 * Return the handle to a system-level service by class.
3181 * <p>
3182 * Currently available classes are:
3183 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3184 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3185 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3186 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3187 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3188 * {@link android.net.ConnectivityManager},
3189 * {@link android.net.wifi.WifiManager},
3190 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3191 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3192 * {@link android.view.inputmethod.InputMethodManager},
3193 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003194 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3195 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08003196 * </p><p>
3197 * Note: System services obtained via this API may be closely associated with
3198 * the Context in which they are obtained from. In general, do not share the
3199 * service objects between various different contexts (Activities, Applications,
3200 * Services, Providers, etc.)
3201 * </p>
3202 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003203 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3204 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
3205 * {@link #FINGERPRINT_SERVICE}, {@link #SHORTCUT_SERVICE}, {@link #USB_SERVICE},
3206 * {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, {@link #WIFI_SERVICE},
3207 * {@link #WIFI_AWARE_SERVICE}. For these services this method will return <code>null</code>.
3208 * Generally, if you are running as an instant app you should always check whether the result
3209 * of this method is null.
3210 *
Jeff Brown6e539312015-02-24 18:53:21 -08003211 * @param serviceClass The class of the desired service.
3212 * @return The service or null if the class is not a supported system service.
3213 */
3214 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003215 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003216 // Because subclasses may override getSystemService(String) we cannot
3217 // perform a lookup by class alone. We must first map the class to its
3218 // service name then invoke the string-based method.
3219 String serviceName = getSystemServiceName(serviceClass);
3220 return serviceName != null ? (T)getSystemService(serviceName) : null;
3221 }
3222
3223 /**
3224 * Gets the name of the system-level service that is represented by the specified class.
3225 *
3226 * @param serviceClass The class of the desired service.
3227 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003228 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003229 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003230
3231 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003232 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003233 * {@link android.os.PowerManager} for controlling power management,
3234 * including "wake locks," which let you keep the device on while
3235 * you're running long tasks.
3236 */
3237 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003238
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003239 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003240 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003241 * {@link android.os.RecoverySystem} for accessing the recovery system
3242 * service.
3243 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003244 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003245 * @hide
3246 */
3247 public static final String RECOVERY_SERVICE = "recovery";
3248
3249 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003250 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003251 * {@link android.os.SystemUpdateManager} for accessing the system update
3252 * manager service.
3253 *
3254 * @see #getSystemService(String)
3255 * @hide
3256 */
3257 @SystemApi
3258 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3259
3260 /**
3261 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003262 * {@link android.view.WindowManager} for accessing the system's window
3263 * manager.
3264 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003265 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 * @see android.view.WindowManager
3267 */
3268 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003270 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003271 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003272 * {@link android.view.LayoutInflater} for inflating layout resources in this
3273 * context.
3274 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003275 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003276 * @see android.view.LayoutInflater
3277 */
3278 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003279
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003280 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003281 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003282 * {@link android.accounts.AccountManager} for receiving intents at a
3283 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003284 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003285 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003286 * @see android.accounts.AccountManager
3287 */
3288 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003289
Fred Quintana60307342009-03-24 22:48:12 -07003290 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003291 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003292 * {@link android.app.ActivityManager} for interacting with the global
3293 * system state.
3294 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003295 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003296 * @see android.app.ActivityManager
3297 */
3298 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003299
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003300 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003301 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003302 * {@link android.app.AlarmManager} for receiving intents at a
3303 * time of your choosing.
3304 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003305 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003306 * @see android.app.AlarmManager
3307 */
3308 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003310 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003311 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 * {@link android.app.NotificationManager} for informing the user of
3313 * background events.
3314 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003315 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 * @see android.app.NotificationManager
3317 */
3318 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003320 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003321 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003322 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3323 * feedback for UI events through the registered event listeners.
3324 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003325 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003326 * @see android.view.accessibility.AccessibilityManager
3327 */
3328 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003329
svetoslavganov75986cf2009-05-14 22:28:01 -07003330 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003331 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003332 * {@link android.view.accessibility.CaptioningManager} for obtaining
3333 * captioning properties and listening for changes in captioning
3334 * preferences.
3335 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003336 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003337 * @see android.view.accessibility.CaptioningManager
3338 */
3339 public static final String CAPTIONING_SERVICE = "captioning";
3340
3341 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003342 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003343 * {@link android.app.NotificationManager} for controlling keyguard.
3344 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003345 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 * @see android.app.KeyguardManager
3347 */
3348 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003349
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003350 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003351 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 * android.location.LocationManager} for controlling location
3353 * updates.
3354 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003355 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 * @see android.location.LocationManager
3357 */
3358 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003359
3360 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003361 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003362 * {@link android.location.CountryDetector} for detecting the country that
3363 * the user is in.
3364 *
3365 * @hide
3366 */
3367 public static final String COUNTRY_DETECTOR = "country_detector";
3368
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003369 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003370 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003371 * android.app.SearchManager} for handling searches.
3372 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003373 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003374 * @see android.app.SearchManager
3375 */
3376 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003377
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003378 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003379 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003380 * android.hardware.SensorManager} for accessing sensors.
3381 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003382 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003383 * @see android.hardware.SensorManager
3384 */
3385 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003387 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003388 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003389 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003390 * functions.
3391 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003392 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003393 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003394 */
3395 public static final String STORAGE_SERVICE = "storage";
3396
3397 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003398 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003399 * android.app.usage.StorageStatsManager} for accessing system storage
3400 * statistics.
3401 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003402 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003403 * @see android.app.usage.StorageStatsManager
3404 */
3405 public static final String STORAGE_STATS_SERVICE = "storagestats";
3406
3407 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003408 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003409 * com.android.server.WallpaperService for accessing wallpapers.
3410 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003411 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003412 */
3413 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003414
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003415 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003416 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003417 * android.os.Vibrator} for interacting with the vibration hardware.
3418 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003419 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003420 * @see android.os.Vibrator
3421 */
3422 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003424 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003425 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003426 * android.app.StatusBarManager} for interacting with the status bar.
3427 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003428 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 * @see android.app.StatusBarManager
3430 * @hide
3431 */
3432 public static final String STATUS_BAR_SERVICE = "statusbar";
3433
3434 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003435 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003436 * android.net.ConnectivityManager} for handling management of
3437 * network connections.
3438 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003439 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 * @see android.net.ConnectivityManager
3441 */
3442 public static final String CONNECTIVITY_SERVICE = "connectivity";
3443
3444 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003445 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003446 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3447 * IPSec.
3448 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003449 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003450 */
3451 public static final String IPSEC_SERVICE = "ipsec";
3452
3453 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003454 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003455 * android.os.IUpdateLock} for managing runtime sequences that
3456 * must not be interrupted by headless OTA application or similar.
3457 *
3458 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003459 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003460 * @see android.os.UpdateLock
3461 */
3462 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3463
3464 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003465 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003466 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003467 */
3468 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3469
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003470 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003471 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003472 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3473 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003474 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003475 */
3476 public static final String SLICE_SERVICE = "slice";
3477
3478 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003479 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003480 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3481 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003482 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003483 * @see android.app.usage.NetworkStatsManager
3484 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003485 public static final String NETWORK_STATS_SERVICE = "netstats";
3486 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003487 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003488 /** {@hide} */
3489 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003490
San Mehatd1df8ac2010-01-26 06:17:26 -08003491 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003492 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003493 * android.net.wifi.WifiManager} for handling management of
3494 * Wi-Fi access.
3495 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003496 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003497 * @see android.net.wifi.WifiManager
3498 */
3499 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003500
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003501 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003502 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003503 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003504 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003505 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003506 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003507 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003508 */
3509 public static final String WIFI_P2P_SERVICE = "wifip2p";
3510
3511 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003512 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003513 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3514 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003515 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003516 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003517 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003518 */
Etan Cohen04133272016-10-26 11:22:06 -07003519 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003520
3521 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003522 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003523 * android.net.wifi.WifiScanner} for scanning the wifi universe
3524 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003525 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003526 * @see android.net.wifi.WifiScanner
3527 * @hide
3528 */
Wei Wang35d552f2014-07-08 21:37:01 -07003529 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003530 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3531
3532 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003533 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003534 * android.net.wifi.RttManager} for ranging devices with wifi
3535 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003536 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003537 * @see android.net.wifi.RttManager
3538 * @hide
3539 */
3540 @SystemApi
3541 public static final String WIFI_RTT_SERVICE = "rttmanager";
3542
3543 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003544 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohen17ba4722017-08-21 10:52:17 -07003545 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi
3546 *
3547 * Note: this is a replacement for WIFI_RTT_SERVICE above. It will
3548 * be renamed once final implementation in place.
3549 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003550 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003551 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003552 */
Etan Cohen091d7772018-01-04 17:47:37 -08003553 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003554
3555 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003556 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003557 * android.net.lowpan.LowpanManager} for handling management of
3558 * LoWPAN access.
3559 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003560 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003561 * @see android.net.lowpan.LowpanManager
3562 *
3563 * @hide
3564 */
3565 public static final String LOWPAN_SERVICE = "lowpan";
3566
3567 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003568 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003569 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003570 * Ethernet access.
3571 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003572 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003573 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003574 *
3575 * @hide
3576 */
3577 public static final String ETHERNET_SERVICE = "ethernet";
3578
3579 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003580 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003581 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003582 * discovery
3583 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003584 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003585 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003586 */
3587 public static final String NSD_SERVICE = "servicediscovery";
3588
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003589 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003590 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003591 * {@link android.media.AudioManager} for handling management of volume,
3592 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003593 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003594 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003595 * @see android.media.AudioManager
3596 */
3597 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003598
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003599 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003600 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003601 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003602 * of fingerprints.
3603 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003604 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07003605 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003606 */
3607 public static final String FINGERPRINT_SERVICE = "fingerprint";
3608
3609 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003610 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003611 * {@link android.media.MediaRouter} for controlling and managing
3612 * routing of media.
3613 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003614 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003615 * @see android.media.MediaRouter
3616 */
3617 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3618
3619 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003620 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003621 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003622 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003623 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07003624 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003625 */
3626 public static final String MEDIA_SESSION_SERVICE = "media_session";
3627
3628 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003629 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003630 * {@link android.telephony.TelephonyManager} for handling management the
3631 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003632 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003633 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003634 * @see android.telephony.TelephonyManager
3635 */
3636 public static final String TELEPHONY_SERVICE = "phone";
3637
3638 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003639 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003640 * {@link android.telephony.SubscriptionManager} for handling management the
3641 * telephony subscriptions of the device.
3642 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003643 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08003644 * @see android.telephony.SubscriptionManager
3645 */
3646 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3647
3648 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003649 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003650 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003651 * of the device.
3652 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003653 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003654 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003655 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003656 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003657
3658 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003659 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003660 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3661 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003662 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003663 * @see android.telephony.CarrierConfigManager
3664 */
3665 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3666
3667 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003668 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08003669 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
3670 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003671 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08003672 * @see android.telephony.euicc.EuiccManager
3673 * TODO(b/35851809): Unhide this API.
3674 * @hide
3675 */
3676 public static final String EUICC_SERVICE = "euicc_service";
3677
3678 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003679 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003680 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
3681 *
3682 * @see #getSystemService(String)
3683 * @see android.telephony.euicc.EuiccCardManager
3684 * TODO(b/35851809): Make this a SystemApi.
3685 * @hide
3686 */
3687 public static final String EUICC_CARD_SERVICE = "euicc_card_service";
3688
3689 /**
3690 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08003691 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003692 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003693 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003694 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08003695 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003696 */
3697 public static final String CLIPBOARD_SERVICE = "clipboard";
3698
3699 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003700 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003701 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003702 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003703 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003704 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003705 */
3706 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
3707
3708 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003709 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003710 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3711 * methods.
3712 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003713 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003714 */
3715 public static final String INPUT_METHOD_SERVICE = "input_method";
3716
3717 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003718 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09003719 * {@link android.view.textservice.TextServicesManager} for accessing
3720 * text services.
3721 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003722 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09003723 */
3724 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3725
3726 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003727 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003728 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003729 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003730 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003732 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003734 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003735 * Official published name of the (internal) voice interaction manager service.
3736 *
3737 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003738 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07003739 */
3740 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3741
3742 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08003743 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07003744 *
3745 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003746 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07003747 */
Felipe Leme640f30a2017-03-06 15:44:06 -08003748 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07003749
3750 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003751 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003752 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3753 *
3754 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003755 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003756 */
3757 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3758
3759
3760 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003761 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003762 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003763 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003764 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003765 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003766 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07003767 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003768 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003769 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003770
3771 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003772 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003773 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003774 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003775 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07003776 */
3777 public static final String DROPBOX_SERVICE = "dropbox";
3778
Christopher Tate487529a2009-04-29 14:03:25 -07003779 /**
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003780 * System service name for the DeviceIdleController. There is no Java API for this.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003781 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003782 * @hide
3783 */
3784 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3785
3786 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003787 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003788 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003789 * device policy management.
3790 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003791 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08003792 */
3793 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3794
3795 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003796 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08003797 * {@link android.app.UiModeManager} for controlling UI modes.
3798 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003799 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08003800 */
3801 public static final String UI_MODE_SERVICE = "uimode";
3802
3803 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003804 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003805 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003806 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003807 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07003808 */
3809 public static final String DOWNLOAD_SERVICE = "download";
3810
3811 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003812 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003813 * {@link android.os.BatteryManager} for managing battery state.
3814 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003815 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08003816 */
3817 public static final String BATTERY_SERVICE = "batterymanager";
3818
3819 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003820 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003821 * {@link android.nfc.NfcManager} for using NFC.
3822 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003823 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003824 */
3825 public static final String NFC_SERVICE = "nfc";
3826
3827 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003828 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003829 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003830 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003831 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003832 */
3833 public static final String BLUETOOTH_SERVICE = "bluetooth";
3834
3835 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003836 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003837 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3838 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003839 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08003840 */
3841 /** @hide */
3842 public static final String SIP_SERVICE = "sip";
3843
3844 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003845 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003846 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003847 * and for controlling this device's behavior as a USB device.
3848 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003849 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04003850 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003851 */
3852 public static final String USB_SERVICE = "usb";
3853
3854 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003855 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003856 * android.hardware.SerialManager} for access to serial ports.
3857 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003858 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003859 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003860 *
3861 * @hide
3862 */
3863 public static final String SERIAL_SERVICE = "serial";
3864
3865 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003866 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003867 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3868 * HDMI-CEC protocol.
3869 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003870 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09003871 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003872 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003873 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003874 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003875 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003876
3877 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003878 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003879 * {@link android.hardware.input.InputManager} for interacting with input devices.
3880 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003881 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003882 * @see android.hardware.input.InputManager
3883 */
3884 public static final String INPUT_SERVICE = "input";
3885
3886 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003887 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003888 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3889 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003890 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07003891 * @see android.hardware.display.DisplayManager
3892 */
3893 public static final String DISPLAY_SERVICE = "display";
3894
3895 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003896 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003897 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3898 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003899 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07003900 * @see android.os.UserManager
3901 */
3902 public static final String USER_SERVICE = "user";
3903
3904 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003905 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003906 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3907 * profiles of a user.
3908 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003909 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08003910 * @see android.content.pm.LauncherApps
3911 */
3912 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3913
3914 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003915 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003916 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3917 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003918 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07003919 * @see android.content.RestrictionsManager
3920 */
3921 public static final String RESTRICTIONS_SERVICE = "restrictions";
3922
3923 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003924 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003925 * {@link android.app.AppOpsManager} for tracking application operations
3926 * on the device.
3927 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003928 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003929 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003930 */
3931 public static final String APP_OPS_SERVICE = "appops";
3932
3933 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003934 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003935 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003936 * camera devices.
3937 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003938 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07003939 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003940 */
3941 public static final String CAMERA_SERVICE = "camera";
3942
3943 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003944 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003945 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003946 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003947 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003948 * @see android.print.PrintManager
3949 */
3950 public static final String PRINT_SERVICE = "print";
3951
3952 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003953 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08003954 * {@link android.companion.CompanionDeviceManager} for managing companion devices
3955 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003956 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08003957 * @see android.companion.CompanionDeviceManager
3958 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07003959 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08003960
3961 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003962 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07003963 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
3964 * signals from the device.
3965 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003966 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07003967 * @see android.hardware.ConsumerIrManager
3968 */
3969 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
3970
3971 /**
Adrian Roos82142c22014-03-27 14:56:59 +01003972 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003973 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01003974 * @see android.app.trust.TrustManager
3975 * @hide
3976 */
3977 public static final String TRUST_SERVICE = "trust";
3978
3979 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003980 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07003981 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
3982 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08003983 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003984 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07003985 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08003986 */
3987 public static final String TV_INPUT_SERVICE = "tv_input";
3988
3989 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003990 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003991 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003992 * @see android.net.NetworkScoreManager
3993 * @hide
3994 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07003995 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07003996 public static final String NETWORK_SCORE_SERVICE = "network_score";
3997
3998 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003999 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004000 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004001 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004002 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004003 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004004 */
4005 public static final String USAGE_STATS_SERVICE = "usagestats";
4006
4007 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004008 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004009 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004010 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004011 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004012 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004013 */
Christopher Tate7060b042014-06-09 19:50:00 -07004014 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004015
4016 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004017 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004018 * android.service.persistentdata.PersistentDataBlockManager} instance
4019 * for interacting with a storage device that lives across factory resets.
4020 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004021 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004022 * @see android.service.persistentdata.PersistentDataBlockManager
4023 * @hide
4024 */
Andres Morales33df9372014-09-26 17:08:59 -07004025 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004026 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4027
4028 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004029 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004030 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4031 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004032 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004033 * @see android.service.oemlock.OemLockManager
4034 * @hide
4035 */
4036 @SystemApi
4037 public static final String OEM_LOCK_SERVICE = "oem_lock";
4038
4039 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004040 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004041 * android.media.projection.MediaProjectionManager} instance for managing
4042 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004043 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004044 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004045 */
4046 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4047
4048 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004049 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004050 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004051 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004052 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004053 */
4054 public static final String MIDI_SERVICE = "midi";
4055
Eric Laurent2035ac82015-03-05 15:18:44 -08004056
4057 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004058 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004059 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4060 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004061 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004062 * @hide
4063 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004064 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004065
Paul McLeana33be212015-02-20 07:52:45 -08004066 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004067 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004068 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4069 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004070 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004071 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004072 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004073
4074 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004075 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004076 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004077 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004078 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004079 * @see android.content.pm.ShortcutManager
4080 */
4081 public static final String SHORTCUT_SERVICE = "shortcut";
4082
4083 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004084 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004085 * android.hardware.location.ContextHubManager} for accessing context hubs.
4086 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004087 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004088 * @see android.hardware.location.ContextHubManager
4089 *
4090 * @hide
4091 */
4092 @SystemApi
4093 public static final String CONTEXTHUB_SERVICE = "contexthub";
4094
4095 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004096 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004097 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4098 * memory, etc) metrics.
4099 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004100 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004101 */
4102 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4103
4104 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004105 * Gatekeeper Service.
4106 * @hide
4107 */
4108 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4109
4110 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004111 * Service defining the policy for access to device identifiers.
4112 * @hide
4113 */
4114 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4115
4116 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004117 * Service to report a system health "incident"
4118 * @hide
4119 */
4120 public static final String INCIDENT_SERVICE = "incident";
4121
4122 /**
Bookatz94726412017-08-31 09:26:15 -07004123 * Service to assist statsd in obtaining general stats.
4124 * @hide
4125 */
4126 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4127
4128 /**
Bookatzc6977972018-01-16 16:55:05 -08004129 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004130 * @hide
4131 */
4132 @SystemApi
4133 public static final String STATS_MANAGER = "stats";
4134
4135 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004136 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004137 * android.content.om.OverlayManager} for managing overlay packages.
4138 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004139 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004140 * @see android.content.om.OverlayManager
4141 * @hide
4142 */
4143 public static final String OVERLAY_SERVICE = "overlay";
4144
4145 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004146 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004147 * {@link VrManager} for accessing the VR service.
4148 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004149 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004150 * @hide
4151 */
4152 @SystemApi
4153 public static final String VR_SERVICE = "vrmanager";
4154
4155 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004156 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004157 * {@link android.app.timezone.ITimeZoneRulesManager}.
4158 * @hide
4159 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004160 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004161 */
4162 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4163
4164 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004165 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004166 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004167 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004168 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004169 */
4170 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4171
4172 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004173 * Determine whether the given permission is allowed for a particular
4174 * process and user ID running in the system.
4175 *
4176 * @param permission The name of the permission being checked.
4177 * @param pid The process ID being checked against. Must be > 0.
4178 * @param uid The user ID being checked against. A uid of 0 is the root
4179 * user, which will pass every permission check.
4180 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004181 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004182 * pid/uid is allowed that permission, or
4183 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4184 *
4185 * @see PackageManager#checkPermission(String, String)
4186 * @see #checkCallingPermission
4187 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004188 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004189 @PackageManager.PermissionResult
4190 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004191
Dianne Hackbornff170242014-11-19 10:59:01 -08004192 /** @hide */
4193 @PackageManager.PermissionResult
4194 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4195 IBinder callerToken);
4196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004197 /**
4198 * Determine whether the calling process of an IPC you are handling has been
4199 * granted a particular permission. This is basically the same as calling
4200 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4201 * by {@link android.os.Binder#getCallingPid} and
4202 * {@link android.os.Binder#getCallingUid}. One important difference
4203 * is that if you are not currently processing an IPC, this function
4204 * will always fail. This is done to protect against accidentally
4205 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4206 * to avoid this protection.
4207 *
4208 * @param permission The name of the permission being checked.
4209 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004210 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004211 * pid/uid is allowed that permission, or
4212 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4213 *
4214 * @see PackageManager#checkPermission(String, String)
4215 * @see #checkPermission
4216 * @see #checkCallingOrSelfPermission
4217 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004218 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004219 @PackageManager.PermissionResult
4220 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004221
4222 /**
4223 * Determine whether the calling process of an IPC <em>or you</em> have been
4224 * granted a particular permission. This is the same as
4225 * {@link #checkCallingPermission}, except it grants your own permissions
4226 * if you are not currently processing an IPC. Use with care!
4227 *
4228 * @param permission The name of the permission being checked.
4229 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004230 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004231 * pid/uid is allowed that permission, or
4232 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4233 *
4234 * @see PackageManager#checkPermission(String, String)
4235 * @see #checkPermission
4236 * @see #checkCallingPermission
4237 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004238 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004239 @PackageManager.PermissionResult
4240 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004241
4242 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004243 * Determine whether <em>you</em> have been granted a particular permission.
4244 *
4245 * @param permission The name of the permission being checked.
4246 *
4247 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4248 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4249 *
4250 * @see PackageManager#checkPermission(String, String)
4251 * @see #checkCallingPermission(String)
4252 */
4253 @PackageManager.PermissionResult
4254 public abstract int checkSelfPermission(@NonNull String permission);
4255
4256 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004257 * If the given permission is not allowed for a particular process
4258 * and user ID running in the system, throw a {@link SecurityException}.
4259 *
4260 * @param permission The name of the permission being checked.
4261 * @param pid The process ID being checked against. Must be &gt; 0.
4262 * @param uid The user ID being checked against. A uid of 0 is the root
4263 * user, which will pass every permission check.
4264 * @param message A message to include in the exception if it is thrown.
4265 *
4266 * @see #checkPermission(String, int, int)
4267 */
4268 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004269 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004270
4271 /**
4272 * If the calling process of an IPC you are handling has not been
4273 * granted a particular permission, throw a {@link
4274 * SecurityException}. This is basically the same as calling
4275 * {@link #enforcePermission(String, int, int, String)} with the
4276 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4277 * and {@link android.os.Binder#getCallingUid}. One important
4278 * difference is that if you are not currently processing an IPC,
4279 * this function will always throw the SecurityException. This is
4280 * done to protect against accidentally leaking permissions; you
4281 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4282 * protection.
4283 *
4284 * @param permission The name of the permission being checked.
4285 * @param message A message to include in the exception if it is thrown.
4286 *
4287 * @see #checkCallingPermission(String)
4288 */
4289 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004290 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004291
4292 /**
4293 * If neither you nor the calling process of an IPC you are
4294 * handling has been granted a particular permission, throw a
4295 * {@link SecurityException}. This is the same as {@link
4296 * #enforceCallingPermission}, except it grants your own
4297 * permissions if you are not currently processing an IPC. Use
4298 * with care!
4299 *
4300 * @param permission The name of the permission being checked.
4301 * @param message A message to include in the exception if it is thrown.
4302 *
4303 * @see #checkCallingOrSelfPermission(String)
4304 */
4305 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004306 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004307
4308 /**
4309 * Grant permission to access a specific Uri to another package, regardless
4310 * of whether that package has general permission to access the Uri's
4311 * content provider. This can be used to grant specific, temporary
4312 * permissions, typically in response to user interaction (such as the
4313 * user opening an attachment that you would like someone else to
4314 * display).
4315 *
4316 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4317 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4318 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4319 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4320 * start an activity instead of this function directly. If you use this
4321 * function directly, you should be sure to call
4322 * {@link #revokeUriPermission} when the target should no longer be allowed
4323 * to access it.
4324 *
4325 * <p>To succeed, the content provider owning the Uri must have set the
4326 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4327 * grantUriPermissions} attribute in its manifest or included the
4328 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4329 * &lt;grant-uri-permissions&gt;} tag.
4330 *
4331 * @param toPackage The package you would like to allow to access the Uri.
4332 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004333 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004334 *
4335 * @see #revokeUriPermission
4336 */
4337 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004338 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004339
4340 /**
4341 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004342 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4343 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004344 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004346 * "content://foo". It will not remove any prefix grants that exist at a
4347 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004348 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004349 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004350 * regular permission access to a Uri, but had received access to it through
4351 * a specific Uri permission grant, you could not revoke that grant with this
4352 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004353 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4354 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004355 * (or none).</p>
4356 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004357 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4358 * grants matching the given Uri, for any package they had been granted to, through any
4359 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4360 * service start, etc). That means this can be potentially dangerous to use, as it can
4361 * revoke grants that another app could be strongly expecting to stick around.</p>
4362 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004363 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004364 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004365 *
4366 * @see #grantUriPermission
4367 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004368 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004369
4370 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004371 * Remove permissions to access a particular content provider Uri
4372 * that were previously added with {@link #grantUriPermission} for a specific target
4373 * package. The given Uri will match all previously granted Uris that are the same or a
4374 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4375 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4376 * "content://foo". It will not remove any prefix grants that exist at a
4377 * higher level.
4378 *
4379 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4380 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4381 * and only for the package specified. Any matching grants that have happened through
4382 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4383 * removed.</p>
4384 *
4385 * @param toPackage The package you had previously granted access to.
4386 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004387 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004388 *
4389 * @see #grantUriPermission
4390 */
4391 public abstract void revokeUriPermission(String toPackage, Uri uri,
4392 @Intent.AccessUriMode int modeFlags);
4393
4394 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395 * Determine whether a particular process and user ID has been granted
4396 * permission to access a specific URI. This only checks for permissions
4397 * that have been explicitly granted -- if the given process/uid has
4398 * more general access to the URI's content provider then this check will
4399 * always fail.
4400 *
4401 * @param uri The uri that is being checked.
4402 * @param pid The process ID being checked against. Must be &gt; 0.
4403 * @param uid The user ID being checked against. A uid of 0 is the root
4404 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004405 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004406 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004407 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004408 * pid/uid is allowed to access that uri, or
4409 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4410 *
4411 * @see #checkCallingUriPermission
4412 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004413 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004414 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004415 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004416 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004417
Dianne Hackbornff170242014-11-19 10:59:01 -08004418 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004419 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08004420 public abstract int checkUriPermission(Uri uri, int pid, int uid,
4421 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4422
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004423 /**
4424 * Determine whether the calling process and user ID has been
4425 * granted permission to access a specific URI. This is basically
4426 * the same as calling {@link #checkUriPermission(Uri, int, int,
4427 * int)} with the pid and uid returned by {@link
4428 * android.os.Binder#getCallingPid} and {@link
4429 * android.os.Binder#getCallingUid}. One important difference is
4430 * that if you are not currently processing an IPC, this function
4431 * will always fail.
4432 *
4433 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004434 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004435 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004436 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004437 * is allowed to access that uri, or
4438 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4439 *
4440 * @see #checkUriPermission(Uri, int, int, int)
4441 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004442 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004443 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07004444 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004445
4446 /**
4447 * Determine whether the calling process of an IPC <em>or you</em> has been granted
4448 * permission to access a specific URI. This is the same as
4449 * {@link #checkCallingUriPermission}, except it grants your own permissions
4450 * if you are not currently processing an IPC. Use with care!
4451 *
4452 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004453 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004454 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004455 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004456 * is allowed to access that uri, or
4457 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4458 *
4459 * @see #checkCallingUriPermission
4460 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004461 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004462 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004463 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004464 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004465
4466 /**
4467 * Check both a Uri and normal permission. This allows you to perform
4468 * both {@link #checkPermission} and {@link #checkUriPermission} in one
4469 * call.
4470 *
4471 * @param uri The Uri whose permission is to be checked, or null to not
4472 * do this check.
4473 * @param readPermission The permission that provides overall read access,
4474 * or null to not do this check.
4475 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004476 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004477 * @param pid The process ID being checked against. Must be &gt; 0.
4478 * @param uid The user ID being checked against. A uid of 0 is the root
4479 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004480 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004481 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004482 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 * is allowed to access that uri or holds one of the given permissions, or
4484 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4485 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004486 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004487 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004488 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
4489 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004490 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004491
4492 /**
4493 * If a particular process and user ID has not been granted
4494 * permission to access a specific URI, throw {@link
4495 * SecurityException}. This only checks for permissions that have
4496 * been explicitly granted -- if the given process/uid has more
4497 * general access to the URI's content provider then this check
4498 * will always fail.
4499 *
4500 * @param uri The uri that is being checked.
4501 * @param pid The process ID being checked against. Must be &gt; 0.
4502 * @param uid The user ID being checked against. A uid of 0 is the root
4503 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004504 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505 * @param message A message to include in the exception if it is thrown.
4506 *
4507 * @see #checkUriPermission(Uri, int, int, int)
4508 */
4509 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004510 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511
4512 /**
4513 * If the calling process and user ID has not been granted
4514 * permission to access a specific URI, throw {@link
4515 * SecurityException}. This is basically the same as calling
4516 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
4517 * the pid and uid returned by {@link
4518 * android.os.Binder#getCallingPid} and {@link
4519 * android.os.Binder#getCallingUid}. One important difference is
4520 * that if you are not currently processing an IPC, this function
4521 * will always throw a SecurityException.
4522 *
4523 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004524 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 * @param message A message to include in the exception if it is thrown.
4526 *
4527 * @see #checkCallingUriPermission(Uri, int)
4528 */
4529 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004530 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004531
4532 /**
4533 * If the calling process of an IPC <em>or you</em> has not been
4534 * granted permission to access a specific URI, throw {@link
4535 * SecurityException}. This is the same as {@link
4536 * #enforceCallingUriPermission}, except it grants your own
4537 * permissions if you are not currently processing an IPC. Use
4538 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07004539 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004540 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004541 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 * @param message A message to include in the exception if it is thrown.
4543 *
4544 * @see #checkCallingOrSelfUriPermission(Uri, int)
4545 */
4546 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004547 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004548
4549 /**
4550 * Enforce both a Uri and normal permission. This allows you to perform
4551 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4552 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004553 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004554 * @param uri The Uri whose permission is to be checked, or null to not
4555 * do this check.
4556 * @param readPermission The permission that provides overall read access,
4557 * or null to not do this check.
4558 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004559 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004560 * @param pid The process ID being checked against. Must be &gt; 0.
4561 * @param uid The user ID being checked against. A uid of 0 is the root
4562 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004563 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004564 * @param message A message to include in the exception if it is thrown.
4565 *
4566 * @see #checkUriPermission(Uri, String, String, int, int, int)
4567 */
4568 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004569 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004570 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004571 @Nullable String message);
4572
4573 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004574 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
4575 CONTEXT_INCLUDE_CODE,
4576 CONTEXT_IGNORE_SECURITY,
4577 CONTEXT_RESTRICTED,
4578 CONTEXT_DEVICE_PROTECTED_STORAGE,
4579 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
4580 CONTEXT_REGISTER_PACKAGE,
4581 })
Tor Norbyed9273d62013-05-30 15:59:53 -07004582 @Retention(RetentionPolicy.SOURCE)
4583 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004584
4585 /**
4586 * Flag for use with {@link #createPackageContext}: include the application
4587 * code with the context. This means loading code into the caller's
4588 * process, so that {@link #getClassLoader()} can be used to instantiate
4589 * the application's classes. Setting this flags imposes security
4590 * restrictions on what application context you can access; if the
4591 * requested application can not be safely loaded into your process,
4592 * java.lang.SecurityException will be thrown. If this flag is not set,
4593 * there will be no restrictions on the packages that can be loaded,
4594 * but {@link #getClassLoader} will always return the default system
4595 * class loader.
4596 */
4597 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4598
4599 /**
4600 * Flag for use with {@link #createPackageContext}: ignore any security
4601 * restrictions on the Context being requested, allowing it to always
4602 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4603 * to be loaded into a process even when it isn't safe to do so. Use
4604 * with extreme care!
4605 */
4606 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004607
Romain Guy870e09f2009-07-06 16:35:25 -07004608 /**
4609 * Flag for use with {@link #createPackageContext}: a restricted context may
4610 * disable specific features. For instance, a View associated with a restricted
4611 * context would ignore particular XML attributes.
4612 */
4613 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004614
4615 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004616 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004617 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004618 *
4619 * @hide
4620 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004621 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004622
4623 /**
4624 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004625 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004626 *
4627 * @hide
4628 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004629 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004630
4631 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004632 * @hide Used to indicate we should tell the activity manager about the process
4633 * loading this code.
4634 */
4635 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4636
4637 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004638 * Return a new Context object for the given application name. This
4639 * Context is the same as what the named application gets when it is
4640 * launched, containing the same resources and class loader. Each call to
4641 * this method returns a new instance of a Context object; Context objects
4642 * are not shared, however they share common state (Resources, ClassLoader,
4643 * etc) so the Context instance itself is fairly lightweight.
4644 *
Jeff Brown6e539312015-02-24 18:53:21 -08004645 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004646 * application with the given package name.
4647 *
4648 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4649 * can not be loaded into the caller's process for security reasons (see
4650 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4651 *
4652 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004653 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004654 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004655 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004656 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004657 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004658 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004659 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004660 */
4661 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004662 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004663
4664 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004665 * Similar to {@link #createPackageContext(String, int)}, but with a
4666 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4667 * will open any {@link Uri} as the given user.
4668 *
4669 * @hide
4670 */
4671 public abstract Context createPackageContextAsUser(
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004672 String packageName, @CreatePackageOptions int flags, UserHandle user)
Jeff Sharkey6d515712012-09-20 16:06:08 -07004673 throws PackageManager.NameNotFoundException;
4674
4675 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004676 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4677 *
4678 * @hide
4679 */
4680 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004681 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07004682
4683 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08004684 * Return a new Context object for the given split name. The new Context has a ClassLoader and
4685 * Resources object that can access the split's and all of its dependencies' code/resources.
4686 * Each call to this method returns a new instance of a Context object;
4687 * Context objects are not shared, however common state (ClassLoader, other Resources for
4688 * the same split) may be so the Context itself can be fairly lightweight.
4689 *
4690 * @param splitName The name of the split to include, as declared in the split's
4691 * <code>AndroidManifest.xml</code>.
4692 * @return A {@link Context} with the given split's code and/or resources loaded.
4693 */
4694 public abstract Context createContextForSplit(String splitName)
4695 throws PackageManager.NameNotFoundException;
4696
4697 /**
Jim Millera75a8832013-02-07 16:53:32 -08004698 * Get the userId associated with this context
4699 * @return user id
4700 *
4701 * @hide
4702 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004703 @TestApi
Jeff Sharkey8588bc12016-01-06 16:47:42 -07004704 public abstract @UserIdInt int getUserId();
Jim Millera75a8832013-02-07 16:53:32 -08004705
4706 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004707 * Return a new Context object for the current Context but whose resources
4708 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004709 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004710 * shared, however common state (ClassLoader, other Resources for the
4711 * same configuration) may be so the Context itself can be fairly lightweight.
4712 *
4713 * @param overrideConfiguration A {@link Configuration} specifying what
4714 * values to modify in the base Configuration of the original Context's
4715 * resources. If the base configuration changes (such as due to an
4716 * orientation change), the resources of this context will also change except
4717 * for those that have been explicitly overridden with a value here.
4718 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004719 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004720 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004721 public abstract Context createConfigurationContext(
4722 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004723
4724 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004725 * Return a new Context object for the current Context but whose resources
4726 * are adjusted to match the metrics of the given Display. Each call to this method
4727 * returns a new instance of a Context object; Context objects are not
4728 * shared, however common state (ClassLoader, other Resources for the
4729 * same configuration) may be so the Context itself can be fairly lightweight.
4730 *
4731 * The returned display Context provides a {@link WindowManager}
4732 * (see {@link #getSystemService(String)}) that is configured to show windows
4733 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4734 * method can be used to retrieve the Display from the returned Context.
4735 *
4736 * @param display A {@link Display} object specifying the display
4737 * for whose metrics the Context's resources should be tailored and upon which
4738 * new windows should be shown.
4739 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004740 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004741 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004742 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004743
4744 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004745 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004746 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004747 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004748 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004749 * with a key tied to the physical device, and it can be accessed
4750 * immediately after the device has booted successfully, both
4751 * <em>before and after</em> the user has authenticated with their
4752 * credentials (such as a lock pattern or PIN).
4753 * <p>
4754 * Because device-protected data is available without user authentication,
4755 * you should carefully limit the data you store using this Context. For
4756 * example, storing sensitive authentication tokens or passwords in the
4757 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004758 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004759 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004760 * device-protected and credential-protected data using different keys, then
4761 * both storage areas will become available at the same time. They remain as
4762 * two distinct storage locations on disk, and only the window of
4763 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004764 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004765 * Each call to this method returns a new instance of a Context object;
4766 * Context objects are not shared, however common state (ClassLoader, other
4767 * Resources for the same configuration) may be so the Context itself can be
4768 * fairly lightweight.
4769 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004770 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004771 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004772 public abstract Context createDeviceProtectedStorageContext();
4773
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004774 /**
4775 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004776 * APIs are backed by credential-protected storage. This is the default
4777 * storage area for apps unless
4778 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004779 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004780 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004781 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004782 * <em>only after</em> the user has entered their credentials (such as a
4783 * lock pattern or PIN).
4784 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004785 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004786 * device-protected and credential-protected data using different keys, then
4787 * both storage areas will become available at the same time. They remain as
4788 * two distinct storage locations on disk, and only the window of
4789 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004790 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004791 * Each call to this method returns a new instance of a Context object;
4792 * Context objects are not shared, however common state (ClassLoader, other
4793 * Resources for the same configuration) may be so the Context itself can be
4794 * fairly lightweight.
4795 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004796 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004797 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004798 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004799 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004800 public abstract Context createCredentialProtectedStorageContext();
4801
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004802 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004803 * Gets the display adjustments holder for this context. This information
4804 * is provided on a per-application or activity basis and is used to simulate lower density
4805 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004806 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004807 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004808 * @return The compatibility info holder, or null if not required by the application.
4809 * @hide
4810 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004811 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004812
4813 /**
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004814 * @hide
4815 */
4816 public abstract Display getDisplay();
4817
4818 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08004819 * @hide
4820 */
4821 public abstract void updateDisplay(int displayId);
4822
4823 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004824 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004825 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004826 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004827 *
Romain Guy870e09f2009-07-06 16:35:25 -07004828 * @see #CONTEXT_RESTRICTED
4829 */
4830 public boolean isRestricted() {
4831 return false;
4832 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004833
4834 /**
4835 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004836 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004837 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004838 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004839 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004840 public abstract boolean isDeviceProtectedStorage();
4841
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004842 /**
4843 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004844 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004845 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004846 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004847 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004848 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004849 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004850 public abstract boolean isCredentialProtectedStorage();
4851
Tony Mak46aabe52016-11-14 12:53:06 +00004852 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07004853 * Returns true if the context can load unsafe resources, e.g. fonts.
4854 * @hide
4855 */
4856 public abstract boolean canLoadUnsafeResources();
4857
4858 /**
Tony Mak46aabe52016-11-14 12:53:06 +00004859 * @hide
4860 */
4861 public IBinder getActivityToken() {
4862 throw new RuntimeException("Not implemented. Must override in a subclass.");
4863 }
4864
4865 /**
4866 * @hide
4867 */
4868 @Nullable
4869 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
4870 int flags) {
4871 throw new RuntimeException("Not implemented. Must override in a subclass.");
4872 }
4873
4874 /**
4875 * @hide
4876 */
4877 public IApplicationThread getIApplicationThread() {
4878 throw new RuntimeException("Not implemented. Must override in a subclass.");
4879 }
Tony Makbf9928d2016-12-22 11:02:45 +00004880
4881 /**
4882 * @hide
4883 */
4884 public Handler getMainThreadHandler() {
4885 throw new RuntimeException("Not implemented. Must override in a subclass.");
4886 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07004887
4888 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07004889 * @hide
4890 */
4891 public AutofillClient getAutofillClient() {
4892 return null;
4893 }
4894
4895 /**
4896 * @hide
4897 */
4898 public void setAutofillClient(AutofillClient client) {
4899 }
4900
4901 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07004902 * Throws an exception if the Context is using system resources,
4903 * which are non-runtime-overlay-themable and may show inconsistent UI.
4904 * @hide
4905 */
4906 public void assertRuntimeOverlayThemable() {
4907 // Resources.getSystem() is a singleton and the only Resources not managed by
4908 // ResourcesManager; therefore Resources.getSystem() is not themable.
4909 if (getResources() == Resources.getSystem()) {
4910 throw new IllegalArgumentException("Non-UI context used to display UI; "
4911 + "get a UI context from ActivityThread#getSystemUiContext()");
4912 }
4913 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004914}