blob: 5cbb1f8895c5d386981fe872a509ca6084eb6e81 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Tor Norbyec91531a2015-04-01 17:41:55 -070019import android.annotation.AttrRes;
Tor Norbye1c2bf032015-03-02 10:57:08 -080020import android.annotation.CheckResult;
Tor Norbye3e4cda72015-06-10 08:14:31 -070021import android.annotation.ColorInt;
22import android.annotation.ColorRes;
23import android.annotation.DrawableRes;
Tor Norbyed9273d62013-05-30 15:59:53 -070024import android.annotation.IntDef;
25import android.annotation.NonNull;
26import android.annotation.Nullable;
Tor Norbye788fc2b2015-07-05 16:10:42 -070027import android.annotation.RequiresPermission;
Tor Norbyed9273d62013-05-30 15:59:53 -070028import android.annotation.StringDef;
Tor Norbye7b9c9122013-05-30 16:48:33 -070029import android.annotation.StringRes;
30import android.annotation.StyleRes;
31import android.annotation.StyleableRes;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090032import android.annotation.SystemApi;
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -070033import android.annotation.TestApi;
Mathew Inwood1c77a112018-08-14 14:06:26 +010034import android.annotation.UnsupportedAppUsage;
Jeff Sharkey8588bc12016-01-06 16:47:42 -070035import android.annotation.UserIdInt;
Selim Cinek7fa385a2018-01-24 08:35:28 -080036import android.app.ActivityManager;
Tony Mak46aabe52016-11-14 12:53:06 +000037import android.app.IApplicationThread;
38import android.app.IServiceConnection;
Zak Cohen56345f42017-01-26 13:54:28 -080039import android.app.VrManager;
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -070040import android.content.pm.ApplicationInfo;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041import android.content.pm.PackageManager;
42import android.content.res.AssetManager;
Alan Viverette45c4bbb2015-01-05 14:59:19 -080043import android.content.res.ColorStateList;
Dianne Hackborn756220b2012-08-14 16:45:30 -070044import android.content.res.Configuration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045import android.content.res.Resources;
46import android.content.res.TypedArray;
Vasu Nori74f170f2010-06-01 18:06:18 -070047import android.database.DatabaseErrorHandler;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048import android.database.sqlite.SQLiteDatabase;
49import android.database.sqlite.SQLiteDatabase.CursorFactory;
50import android.graphics.Bitmap;
51import android.graphics.drawable.Drawable;
52import android.net.Uri;
Patrick Baumannef4c4072018-02-01 08:54:05 -080053import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054import android.os.Bundle;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070055import android.os.Environment;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056import android.os.Handler;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070057import android.os.HandlerExecutor;
Dianne Hackbornff170242014-11-19 10:59:01 -080058import android.os.IBinder;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059import android.os.Looper;
Jeff Sharkey6feb50b2013-10-15 12:38:15 -070060import android.os.StatFs;
Dianne Hackborn79af1dd2012-08-16 16:42:52 -070061import android.os.UserHandle;
Jeff Sharkey8c165792012-10-22 14:08:29 -070062import android.os.UserManager;
Jeff Sharkey60a82cd2017-04-18 18:19:16 -060063import android.os.storage.StorageManager;
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -070064import android.provider.MediaStore;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065import android.util.AttributeSet;
Jeff Browna492c3a2012-08-23 19:48:44 -070066import android.view.Display;
Jeff Sharkeye13529a2015-12-09 14:15:27 -070067import android.view.DisplayAdjustments;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -070068import android.view.View;
Jon Miranda836c0a82014-08-11 12:32:26 -070069import android.view.ViewDebug;
Jeff Browna492c3a2012-08-23 19:48:44 -070070import android.view.WindowManager;
Felipe Lemebb567ae2017-10-04 09:56:21 -070071import android.view.autofill.AutofillManager.AutofillClient;
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +000072import android.view.textclassifier.TextClassificationManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073
74import java.io.File;
75import java.io.FileInputStream;
76import java.io.FileNotFoundException;
77import java.io.FileOutputStream;
78import java.io.IOException;
79import java.io.InputStream;
Tor Norbyed9273d62013-05-30 15:59:53 -070080import java.lang.annotation.Retention;
81import java.lang.annotation.RetentionPolicy;
Jeff Sharkey8439ac02017-12-12 17:26:23 -070082import java.util.concurrent.Executor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083
84/**
85 * Interface to global information about an application environment. This is
86 * an abstract class whose implementation is provided by
87 * the Android system. It
88 * allows access to application-specific resources and classes, as well as
89 * up-calls for application-level operations such as launching activities,
90 * broadcasting and receiving intents, etc.
91 */
92public abstract class Context {
Jeff Sharkey30e06bb2017-04-24 11:18:03 -060093 /** @hide */
94 @IntDef(flag = true, prefix = { "MODE_" }, value = {
95 MODE_PRIVATE,
96 MODE_WORLD_READABLE,
97 MODE_WORLD_WRITEABLE,
98 MODE_APPEND,
99 })
100 @Retention(RetentionPolicy.SOURCE)
101 public @interface FileMode {}
102
103 /** @hide */
104 @IntDef(flag = true, prefix = { "MODE_" }, value = {
105 MODE_PRIVATE,
106 MODE_WORLD_READABLE,
107 MODE_WORLD_WRITEABLE,
108 MODE_MULTI_PROCESS,
109 })
110 @Retention(RetentionPolicy.SOURCE)
111 public @interface PreferencesMode {}
112
113 /** @hide */
114 @IntDef(flag = true, prefix = { "MODE_" }, value = {
115 MODE_PRIVATE,
116 MODE_WORLD_READABLE,
117 MODE_WORLD_WRITEABLE,
118 MODE_ENABLE_WRITE_AHEAD_LOGGING,
119 MODE_NO_LOCALIZED_COLLATORS,
120 })
121 @Retention(RetentionPolicy.SOURCE)
122 public @interface DatabaseMode {}
123
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 /**
125 * File creation mode: the default mode, where the created file can only
126 * be accessed by the calling application (or all applications sharing the
127 * same user ID).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 */
129 public static final int MODE_PRIVATE = 0x0000;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700132 * File creation mode: allow all other applications to have read access to
133 * the created file.
134 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700135 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
136 * mode throws a {@link SecurityException}.
Jeff Sharkey634dc422016-01-30 17:44:15 -0700137 *
Nick Kralevich15069212013-01-09 15:54:56 -0800138 * @deprecated Creating world-readable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700139 * to cause security holes in applications. It is strongly
140 * discouraged; instead, applications should use more formal
141 * mechanism for interactions such as {@link ContentProvider},
142 * {@link BroadcastReceiver}, and {@link android.app.Service}.
143 * There are no guarantees that this access mode will remain on
144 * a file, such as when it goes through a backup and restore.
145 * @see android.support.v4.content.FileProvider
146 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700148 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 public static final int MODE_WORLD_READABLE = 0x0001;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 /**
Jeff Sharkey634dc422016-01-30 17:44:15 -0700152 * File creation mode: allow all other applications to have write access to
153 * the created file.
154 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -0700155 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
Jeff Sharkey634dc422016-01-30 17:44:15 -0700156 * mode will throw a {@link SecurityException}.
157 *
Nick Kralevich15069212013-01-09 15:54:56 -0800158 * @deprecated Creating world-writable files is very dangerous, and likely
Jeff Sharkey634dc422016-01-30 17:44:15 -0700159 * to cause security holes in applications. It is strongly
160 * discouraged; instead, applications should use more formal
161 * mechanism for interactions such as {@link ContentProvider},
162 * {@link BroadcastReceiver}, and {@link android.app.Service}.
163 * There are no guarantees that this access mode will remain on
164 * a file, such as when it goes through a backup and restore.
165 * @see android.support.v4.content.FileProvider
166 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 */
Dianne Hackborn556b09e2012-09-23 17:46:53 -0700168 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 public static final int MODE_WORLD_WRITEABLE = 0x0002;
Jeff Sharkey634dc422016-01-30 17:44:15 -0700170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 /**
172 * File creation mode: for use with {@link #openFileOutput}, if the file
173 * already exists then write data to the end of the existing file
174 * instead of erasing it.
175 * @see #openFileOutput
176 */
177 public static final int MODE_APPEND = 0x8000;
178
179 /**
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800180 * SharedPreference loading flag: when set, the file on disk will
181 * be checked for modification even if the shared preferences
182 * instance is already loaded in this process. This behavior is
183 * sometimes desired in cases where the application has multiple
184 * processes, all writing to the same SharedPreferences file.
185 * Generally there are better forms of communication between
186 * processes, though.
187 *
188 * <p>This was the legacy (but undocumented) behavior in and
189 * before Gingerbread (Android 2.3) and this flag is implied when
190 * targetting such releases. For applications targetting SDK
191 * versions <em>greater than</em> Android 2.3, this flag must be
192 * explicitly set if desired.
193 *
194 * @see #getSharedPreferences
Christopher Tated5748b82015-05-08 18:14:01 -0700195 *
196 * @deprecated MODE_MULTI_PROCESS does not work reliably in
197 * some versions of Android, and furthermore does not provide any
198 * mechanism for reconciling concurrent modifications across
199 * processes. Applications should not attempt to use it. Instead,
200 * they should use an explicit cross-process data management
201 * approach such as {@link android.content.ContentProvider ContentProvider}.
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800202 */
Christopher Tated5748b82015-05-08 18:14:01 -0700203 @Deprecated
Brad Fitzpatrick4e920f72010-12-14 11:52:13 -0800204 public static final int MODE_MULTI_PROCESS = 0x0004;
205
206 /**
Jeff Brown47847f32012-03-22 19:13:11 -0700207 * Database open flag: when set, the database is opened with write-ahead
208 * logging enabled by default.
209 *
210 * @see #openOrCreateDatabase(String, int, CursorFactory)
211 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
212 * @see SQLiteDatabase#enableWriteAheadLogging
213 */
214 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
215
Sunny Goyala21e6b22015-12-02 09:51:02 -0800216 /**
217 * Database open flag: when set, the database is opened without support for
218 * localized collators.
219 *
220 * @see #openOrCreateDatabase(String, int, CursorFactory)
221 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
222 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
223 */
224 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
225
Tor Norbyed9273d62013-05-30 15:59:53 -0700226 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700227 @IntDef(flag = true, prefix = { "BIND_" }, value = {
228 BIND_AUTO_CREATE,
229 BIND_DEBUG_UNBIND,
230 BIND_NOT_FOREGROUND,
231 BIND_ABOVE_CLIENT,
232 BIND_ALLOW_OOM_MANAGEMENT,
233 BIND_WAIVE_PRIORITY,
234 BIND_IMPORTANT,
235 BIND_ADJUST_WITH_ACTIVITY
236 })
Tor Norbyed9273d62013-05-30 15:59:53 -0700237 @Retention(RetentionPolicy.SOURCE)
238 public @interface BindServiceFlags {}
239
Jeff Brown47847f32012-03-22 19:13:11 -0700240 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 * Flag for {@link #bindService}: automatically create the service as long
242 * as the binding exists. Note that while this will create the service,
Scott Main4b5da682010-10-21 11:49:12 -0700243 * its {@link android.app.Service#onStartCommand}
244 * method will still only be called due to an
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 * explicit call to {@link #startService}. Even without that, though,
246 * this still provides you with access to the service object while the
247 * service is created.
248 *
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700249 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
250 * not supplying this flag would also impact how important the system
251 * consider's the target service's process to be. When set, the only way
252 * for it to be raised was by binding from a service in which case it will
253 * only be important when that activity is in the foreground. Now to
254 * achieve this behavior you must explicitly supply the new flag
255 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
256 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
257 * the flags {@link #BIND_WAIVE_PRIORITY} and
258 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
259 * the same result.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260 */
261 public static final int BIND_AUTO_CREATE = 0x0001;
262
263 /**
264 * Flag for {@link #bindService}: include debugging help for mismatched
265 * calls to unbind. When this flag is set, the callstack of the following
266 * {@link #unbindService} call is retained, to be printed if a later
267 * incorrect unbind call is made. Note that doing this requires retaining
268 * information about the binding that was made for the lifetime of the app,
269 * resulting in a leak -- this should only be used for debugging.
270 */
271 public static final int BIND_DEBUG_UNBIND = 0x0002;
272
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800273 /**
274 * Flag for {@link #bindService}: don't allow this binding to raise
275 * the target service's process to the foreground scheduling priority.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700276 * It will still be raised to at least the same memory priority
Dianne Hackborn09c916b2009-12-08 14:50:51 -0800277 * as the client (so that its process will not be killable in any
278 * situation where the client is not killable), but for CPU scheduling
279 * purposes it may be left in the background. This only has an impact
280 * in the situation where the binding client is a foreground process
281 * and the target service is in a background process.
282 */
283 public static final int BIND_NOT_FOREGROUND = 0x0004;
284
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700285 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700286 * Flag for {@link #bindService}: indicates that the client application
287 * binding to this service considers the service to be more important than
288 * the app itself. When set, the platform will try to have the out of
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700289 * memory killer kill the app before it kills the service it is bound to, though
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700290 * this is not guaranteed to be the case.
291 */
292 public static final int BIND_ABOVE_CLIENT = 0x0008;
293
294 /**
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700295 * Flag for {@link #bindService}: allow the process hosting the bound
296 * service to go through its normal memory management. It will be
297 * treated more like a running service, allowing the system to
298 * (temporarily) expunge the process if low on memory or for some other
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700299 * whim it may have, and being more aggressive about making it a candidate
300 * to be killed (and restarted) if running for a long time.
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700301 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700302 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
303
304 /**
305 * Flag for {@link #bindService}: don't impact the scheduling or
306 * memory management priority of the target service's hosting process.
307 * Allows the service's process to be managed on the background LRU list
308 * just like a regular application process in the background.
309 */
310 public static final int BIND_WAIVE_PRIORITY = 0x0020;
311
312 /**
313 * Flag for {@link #bindService}: this service is very important to
314 * the client, so should be brought to the foreground process level
315 * when the client is. Normally a process can only be raised to the
316 * visibility level by a client, even if that client is in the foreground.
317 */
318 public static final int BIND_IMPORTANT = 0x0040;
319
320 /**
321 * Flag for {@link #bindService}: If binding from an activity, allow the
322 * target service's process importance to be raised based on whether the
323 * activity is visible to the user, regardless whether another flag is
324 * used to reduce the amount that the client process's overall importance
325 * is used to impact it.
326 */
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700327 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
328
329 /**
Svet Ganovd223db32017-12-22 09:43:48 -0800330 * @hide Flag for {@link #bindService}: allows binding to a service provided
331 * by an instant app. Note that the caller may not have access to the instant
332 * app providing the service which is a violation of the instant app sandbox.
333 * This flag is intended ONLY for development/testing and should be used with
334 * great care. Only the system is allowed to use this flag.
335 */
336 public static final int BIND_ALLOW_INSTANT = 0x00400000;
337
338 /**
Dianne Hackborn83b40f62017-04-26 13:59:47 -0700339 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
340 * up in to the important background state (instead of transient).
341 */
342 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
343
344 /**
Felipe Lemea1b79bf2016-05-24 13:06:54 -0700345 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
346 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
347 */
348 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
349
350 /**
Dianne Hackbornd69e4c12015-04-24 09:54:54 -0700351 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
352 * but only applies while the device is awake.
353 */
354 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
355
356 /**
357 * @hide Flag for {@link #bindService}: For only the case where the binding
358 * is coming from the system, set the process state to FOREGROUND_SERVICE
359 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
360 * saying that the process shouldn't participate in the normal power reduction
361 * modes (removing network access etc).
362 */
363 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
364
365 /**
Dianne Hackbornf0f94d12014-03-17 16:04:21 -0700366 * @hide Flag for {@link #bindService}: Treat the binding as hosting
367 * an activity, an unbinding as the activity going in the background.
368 * That is, when unbinding, the process when empty will go on the activity
369 * LRU list instead of the regular one, keeping it around more aggressively
370 * than it otherwise would be. This is intended for use with IMEs to try
371 * to keep IME processes around for faster keyboard switching.
372 */
373 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
374
375 /**
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700376 * @hide An idea that is not yet implemented.
377 * Flag for {@link #bindService}: If binding from an activity, consider
378 * this service to be visible like the binding activity is. That is,
379 * it will be treated as something more important to keep around than
380 * invisible background activities. This will impact the number of
381 * recent activities the user can switch between without having them
382 * restart. There is no guarantee this will be respected, as the system
383 * tries to balance such requests from one app vs. the importantance of
384 * keeping other apps around.
385 */
Dianne Hackbornc8230512013-07-13 21:32:12 -0700386 public static final int BIND_VISIBLE = 0x10000000;
387
388 /**
389 * @hide
390 * Flag for {@link #bindService}: Consider this binding to be causing the target
391 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
392 * away.
393 */
394 public static final int BIND_SHOWING_UI = 0x20000000;
Dianne Hackbornb12e1352012-09-26 11:39:20 -0700395
396 /**
Dianne Hackborn2c84cfc2011-10-31 15:39:59 -0700397 * Flag for {@link #bindService}: Don't consider the bound service to be
398 * visible, even if the caller is visible.
399 * @hide
400 */
401 public static final int BIND_NOT_VISIBLE = 0x40000000;
Dianne Hackborn130b0d22011-07-26 22:07:48 -0700402
Alan Viverette713a5cd2015-12-16 15:46:32 -0500403 /**
Robert Sesekb9a86662015-12-09 16:22:45 -0500404 * Flag for {@link #bindService}: The service being bound is an
405 * {@link android.R.attr#isolatedProcess isolated},
406 * {@link android.R.attr#externalService external} service. This binds the service into the
407 * calling application's package, rather than the package in which the service is declared.
Robert Sesek55b2d112016-05-17 18:53:13 -0400408 * <p>
409 * When using this flag, the code for the service being bound will execute under the calling
410 * application's package name and user ID. Because the service must be an isolated process,
411 * it will not have direct access to the application's data, though.
412 *
413 * The purpose of this flag is to allow applications to provide services that are attributed
414 * to the app using the service, rather than the application providing the service.
415 * </p>
Robert Sesekb9a86662015-12-09 16:22:45 -0500416 */
417 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
418
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700419 /** @hide */
Jeff Sharkeyce8db992017-12-13 20:05:05 -0700420 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE_" }, value = {
421 RECEIVER_VISIBLE_TO_INSTANT_APPS
422 })
Chad Brubaker6d6015f2017-04-18 11:25:16 -0700423 @Retention(RetentionPolicy.SOURCE)
424 public @interface RegisterReceiverFlags {}
425
426 /**
427 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
428 */
429 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
430
Robert Sesekb9a86662015-12-09 16:22:45 -0500431 /**
Alan Viverette713a5cd2015-12-16 15:46:32 -0500432 * Returns an AssetManager instance for the application's package.
433 * <p>
434 * <strong>Note:</strong> Implementations of this method should return
435 * an AssetManager instance that is consistent with the Resources instance
436 * returned by {@link #getResources()}. For example, they should share the
437 * same {@link Configuration} object.
438 *
439 * @return an AssetManager instance for the application's package
440 * @see #getResources()
441 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800442 public abstract AssetManager getAssets();
443
Alan Viverette713a5cd2015-12-16 15:46:32 -0500444 /**
445 * Returns a Resources instance for the application's package.
446 * <p>
447 * <strong>Note:</strong> Implementations of this method should return
448 * a Resources instance that is consistent with the AssetManager instance
449 * returned by {@link #getAssets()}. For example, they should share the
450 * same {@link Configuration} object.
451 *
452 * @return a Resources instance for the application's package
453 * @see #getAssets()
454 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455 public abstract Resources getResources();
456
457 /** Return PackageManager instance to find global package information. */
458 public abstract PackageManager getPackageManager();
459
460 /** Return a ContentResolver instance for your application's package. */
461 public abstract ContentResolver getContentResolver();
462
463 /**
464 * Return the Looper for the main thread of the current process. This is
465 * the thread used to dispatch calls to application components (activities,
466 * services, etc).
Jeff Brownf9e989d2013-04-04 23:04:03 -0700467 * <p>
468 * By definition, this method returns the same result as would be obtained
469 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
470 * </p>
471 *
472 * @return The main looper.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473 */
474 public abstract Looper getMainLooper();
Scott Main4b5da682010-10-21 11:49:12 -0700475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 /**
Jeff Sharkey8439ac02017-12-12 17:26:23 -0700477 * Return an {@link Executor} that will run enqueued tasks on the main
478 * thread associated with this context. This is the thread used to dispatch
479 * calls to application components (activities, services, etc).
480 */
481 public Executor getMainExecutor() {
482 // This is pretty inefficient, which is why ContextImpl overrides it
483 return new HandlerExecutor(new Handler(getMainLooper()));
484 }
485
486 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 * Return the context of the single, global Application object of the
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800488 * current process. This generally should only be used if you need a
489 * Context whose lifecycle is separate from the current context, that is
490 * tied to the lifetime of the process rather than the current component.
Scott Main4b5da682010-10-21 11:49:12 -0700491 *
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800492 * <p>Consider for example how this interacts with
Brad Fitzpatrick36af7942010-12-08 11:31:07 -0800493 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
Dianne Hackborne83cefce2010-02-04 17:38:14 -0800494 * <ul>
495 * <li> <p>If used from an Activity context, the receiver is being registered
496 * within that activity. This means that you are expected to unregister
497 * before the activity is done being destroyed; in fact if you do not do
498 * so, the framework will clean up your leaked registration as it removes
499 * the activity and log an error. Thus, if you use the Activity context
500 * to register a receiver that is static (global to the process, not
501 * associated with an Activity instance) then that registration will be
502 * removed on you at whatever point the activity you used is destroyed.
503 * <li> <p>If used from the Context returned here, the receiver is being
504 * registered with the global state associated with your application. Thus
505 * it will never be unregistered for you. This is necessary if the receiver
506 * is associated with static data, not a particular component. However
507 * using the ApplicationContext elsewhere can easily lead to serious leaks
508 * if you forget to unregister, unbind, etc.
509 * </ul>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 */
511 public abstract Context getApplicationContext();
512
Phil Weaver846cda932017-06-15 10:10:06 -0700513 /** Non-activity related autofill ids are unique in the app */
514 private static int sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700515
516 /**
Phil Weaver846cda932017-06-15 10:10:06 -0700517 * Gets the next autofill ID.
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700518 *
Phil Weaver846cda932017-06-15 10:10:06 -0700519 * <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 -0700520 * returned will be unique.
521 *
522 * @return A ID that is unique in the process
523 *
524 * {@hide}
525 */
Phil Weaver846cda932017-06-15 10:10:06 -0700526 public int getNextAutofillId() {
527 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
528 sLastAutofillId = View.NO_ID;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700529 }
530
Phil Weaver846cda932017-06-15 10:10:06 -0700531 sLastAutofillId++;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700532
Phil Weaver846cda932017-06-15 10:10:06 -0700533 return sLastAutofillId;
Philip P. Moltmanneab62ba2017-03-20 10:55:43 -0700534 }
535
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 /**
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700537 * Add a new {@link ComponentCallbacks} to the base application of the
538 * Context, which will be called at the same times as the ComponentCallbacks
539 * methods of activities and other components are called. Note that you
540 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
541 * appropriate in the future; this will not be removed for you.
Dianne Hackborn905577f2011-09-07 18:31:28 -0700542 *
543 * @param callback The interface to call. This can be either a
544 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700545 */
546 public void registerComponentCallbacks(ComponentCallbacks callback) {
547 getApplicationContext().registerComponentCallbacks(callback);
548 }
549
550 /**
John Spurlock6098c5d2013-06-17 10:32:46 -0400551 * Remove a {@link ComponentCallbacks} object that was previously registered
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700552 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
553 */
554 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
555 getApplicationContext().unregisterComponentCallbacks(callback);
556 }
557
558 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559 * Return a localized, styled CharSequence from the application's package's
560 * default string table.
561 *
562 * @param resId Resource id for the CharSequence text
563 */
Chris Craikceb26932018-02-01 15:51:34 -0800564 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700565 public final CharSequence getText(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 return getResources().getText(resId);
567 }
568
569 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700570 * Returns a localized string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800571 * default string table.
572 *
573 * @param resId Resource id for the string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700574 * @return The string data associated with the resource, stripped of styled
575 * text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700577 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700578 public final String getString(@StringRes int resId) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 return getResources().getString(resId);
580 }
581
582 /**
Alan Viveretteb4004df2015-04-29 16:55:42 -0700583 * Returns a localized formatted string from the application's package's
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584 * default string table, substituting the format arguments as defined in
585 * {@link java.util.Formatter} and {@link java.lang.String#format}.
586 *
587 * @param resId Resource id for the format string
Alan Viveretteb4004df2015-04-29 16:55:42 -0700588 * @param formatArgs The format arguments that will be used for
589 * substitution.
590 * @return The string data associated with the resource, formatted and
591 * stripped of styled text information.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 */
Alan Viveretteb4004df2015-04-29 16:55:42 -0700593 @NonNull
Tor Norbye7b9c9122013-05-30 16:48:33 -0700594 public final String getString(@StringRes int resId, Object... formatArgs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595 return getResources().getString(resId, formatArgs);
596 }
597
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800598 /**
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800599 * Returns a color associated with a particular resource ID and styled for
600 * the current theme.
601 *
602 * @param id The desired resource identifier, as generated by the aapt
603 * tool. This integer encodes the package, type, and resource
604 * entry. The value 0 is an invalid identifier.
605 * @return A single color value in the form 0xAARRGGBB.
606 * @throws android.content.res.Resources.NotFoundException if the given ID
607 * does not exist.
608 */
Tor Norbye3e4cda72015-06-10 08:14:31 -0700609 @ColorInt
610 public final int getColor(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800611 return getResources().getColor(id, getTheme());
612 }
613
614 /**
615 * Returns a drawable object associated with a particular resource ID and
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800616 * styled for the current theme.
617 *
618 * @param id The desired resource identifier, as generated by the aapt
619 * tool. This integer encodes the package, type, and resource
620 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800621 * @return An object that can be used to draw this resource.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800622 * @throws android.content.res.Resources.NotFoundException if the given ID
623 * does not exist.
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800624 */
Chris Craik1194b0b2018-03-23 13:36:24 -0700625 @Nullable
Tor Norbye3e4cda72015-06-10 08:14:31 -0700626 public final Drawable getDrawable(@DrawableRes int id) {
Alan Viverette8eea3ea2014-02-03 18:40:20 -0800627 return getResources().getDrawable(id, getTheme());
628 }
629
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800630 /**
631 * Returns a color state list associated with a particular resource ID and
632 * styled for the current theme.
633 *
634 * @param id The desired resource identifier, as generated by the aapt
635 * tool. This integer encodes the package, type, and resource
636 * entry. The value 0 is an invalid identifier.
Chris Craikceb26932018-02-01 15:51:34 -0800637 * @return A color state list.
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800638 * @throws android.content.res.Resources.NotFoundException if the given ID
639 * does not exist.
640 */
Chris Craikceb26932018-02-01 15:51:34 -0800641 @NonNull
Tor Norbye3e4cda72015-06-10 08:14:31 -0700642 public final ColorStateList getColorStateList(@ColorRes int id) {
Alan Viverette45c4bbb2015-01-05 14:59:19 -0800643 return getResources().getColorStateList(id, getTheme());
644 }
645
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800646 /**
647 * Set the base theme for this context. Note that this should be called
648 * before any views are instantiated in the Context (for example before
649 * calling {@link android.app.Activity#setContentView} or
650 * {@link android.view.LayoutInflater#inflate}).
651 *
652 * @param resid The style resource describing the theme.
653 */
Tor Norbye7b9c9122013-05-30 16:48:33 -0700654 public abstract void setTheme(@StyleRes int resid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655
Dianne Hackborn247fe742011-01-08 17:25:57 -0800656 /** @hide Needed for some internal implementation... not public because
657 * you can't assume this actually means anything. */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100658 @UnsupportedAppUsage
Dianne Hackborn247fe742011-01-08 17:25:57 -0800659 public int getThemeResId() {
660 return 0;
661 }
662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 /**
664 * Return the Theme object associated with this Context.
665 */
Jon Miranda836c0a82014-08-11 12:32:26 -0700666 @ViewDebug.ExportedProperty(deepExport = true)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800667 public abstract Resources.Theme getTheme();
668
669 /**
670 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800671 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800672 * for more information.
673 *
Jeff Brown6e539312015-02-24 18:53:21 -0800674 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800675 */
Tor Norbyec91531a2015-04-01 17:41:55 -0700676 public final TypedArray obtainStyledAttributes(@StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800677 return getTheme().obtainStyledAttributes(attrs);
678 }
679
680 /**
681 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800682 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800683 * for more information.
684 *
Jeff Brown6e539312015-02-24 18:53:21 -0800685 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800686 */
687 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700688 @StyleRes int resid, @StyleableRes int[] attrs) throws Resources.NotFoundException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689 return getTheme().obtainStyledAttributes(resid, attrs);
690 }
691
692 /**
693 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800694 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800695 * for more information.
696 *
Jeff Brown6e539312015-02-24 18:53:21 -0800697 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 */
699 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700700 AttributeSet set, @StyleableRes int[] attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
702 }
703
704 /**
705 * Retrieve styled attribute information in this Context's theme. See
Jeff Brown6e539312015-02-24 18:53:21 -0800706 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800707 * for more information.
708 *
Jeff Brown6e539312015-02-24 18:53:21 -0800709 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800710 */
711 public final TypedArray obtainStyledAttributes(
Tor Norbyec91531a2015-04-01 17:41:55 -0700712 AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
713 @StyleRes int defStyleRes) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 return getTheme().obtainStyledAttributes(
715 set, attrs, defStyleAttr, defStyleRes);
716 }
717
718 /**
719 * Return a class loader you can use to retrieve classes in this package.
720 */
721 public abstract ClassLoader getClassLoader();
722
723 /** Return the name of this application's package. */
724 public abstract String getPackageName();
725
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800726 /** @hide Return the name of the base context this context is derived from. */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100727 @UnsupportedAppUsage
Dianne Hackbornd8e1dbb2013-01-17 17:47:37 -0800728 public abstract String getBasePackageName();
729
Dianne Hackborn95d78532013-09-11 09:51:14 -0700730 /** @hide Return the package name that should be used for app ops calls from
731 * this context. This is the same as {@link #getBasePackageName()} except in
732 * cases where system components are loaded into other app processes, in which
733 * case this will be the name of the primary package in that process (so that app
734 * ops uid verification will work with the name). */
Mathew Inwood1c77a112018-08-14 14:06:26 +0100735 @UnsupportedAppUsage
Dianne Hackborn95d78532013-09-11 09:51:14 -0700736 public abstract String getOpPackageName();
737
Dianne Hackborn5c1e00b2009-06-18 17:10:57 -0700738 /** Return the full application info for this context's package. */
739 public abstract ApplicationInfo getApplicationInfo();
Scott Main4b5da682010-10-21 11:49:12 -0700740
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800741 /**
Kenny Root32148392010-01-21 15:40:47 -0800742 * Return the full path to this context's primary Android package.
743 * The Android package is a ZIP file which contains the application's
744 * primary resources.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800745 *
746 * <p>Note: this is not generally useful for applications, since they should
747 * not be directly accessing the file system.
748 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 * @return String Path to the resources.
750 */
751 public abstract String getPackageResourcePath();
752
753 /**
Kenny Root32148392010-01-21 15:40:47 -0800754 * Return the full path to this context's primary Android package.
755 * The Android package is a ZIP file which contains application's
756 * primary code and assets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 *
758 * <p>Note: this is not generally useful for applications, since they should
759 * not be directly accessing the file system.
760 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 * @return String Path to the code and assets.
762 */
763 public abstract String getPackageCodePath();
764
765 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700766 * @hide
767 * @deprecated use {@link #getSharedPreferencesPath(String)}
Joe Onorato23ecae32009-06-10 17:07:15 -0700768 */
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700769 @Deprecated
Mathew Inwood1c77a112018-08-14 14:06:26 +0100770 @UnsupportedAppUsage
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700771 public File getSharedPrefsFile(String name) {
772 return getSharedPreferencesPath(name);
773 }
Joe Onorato23ecae32009-06-10 17:07:15 -0700774
775 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800776 * Retrieve and hold the contents of the preferences file 'name', returning
777 * a SharedPreferences through which you can retrieve and modify its
778 * values. Only one instance of the SharedPreferences object is returned
779 * to any callers for the same name, meaning they will see each other's
780 * edits as soon as they are made.
781 *
Jonathan Dormody1bca5db2017-11-16 11:25:20 -0700782 * This method is thead-safe.
783 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 * @param name Desired preferences file. If a preferences file by this name
785 * does not exist, it will be created when you retrieve an
786 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600787 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800788 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400789 * @return The single {@link SharedPreferences} instance that can be used
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800790 * to retrieve and modify the preference values.
791 *
792 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600794 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700795
796 /**
797 * Retrieve and hold the contents of the preferences file, returning
798 * a SharedPreferences through which you can retrieve and modify its
799 * values. Only one instance of the SharedPreferences object is returned
800 * to any callers for the same name, meaning they will see each other's
801 * edits as soon as they are made.
802 *
803 * @param file Desired preferences file. If a preferences file by this name
804 * does not exist, it will be created when you retrieve an
805 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600806 * @param mode Operating mode.
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700807 *
808 * @return The single {@link SharedPreferences} instance that can be used
809 * to retrieve and modify the preference values.
810 *
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700811 * @see #getSharedPreferencesPath(String)
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700812 * @see #MODE_PRIVATE
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600813 * @removed
Jeff Sharkey8fc29cf2015-11-30 17:51:00 -0700814 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600815 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800816
817 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600818 * Move an existing shared preferences file from the given source storage
Jeff Sharkey35871f22016-01-29 17:13:29 -0700819 * context to this context. This is typically used to migrate data between
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600820 * storage locations after an upgrade, such as moving to device protected
821 * storage.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700822 *
823 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600824 * shared preferences to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -0700825 * @param name The name of the shared preferences file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600826 * @return {@code true} if the move was successful or if the shared
Jeff Sharkey35871f22016-01-29 17:13:29 -0700827 * preferences didn't exist in the source context, otherwise
828 * {@code false}.
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600829 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -0700830 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -0600831 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
832
Jeff Sharkey35871f22016-01-29 17:13:29 -0700833 /**
834 * Delete an existing shared preferences file.
835 *
836 * @param name The name (unique in the application package) of the shared
837 * preferences file.
838 * @return {@code true} if the shared preferences file was successfully
839 * deleted; else {@code false}.
840 * @see #getSharedPreferences(String, int)
841 */
842 public abstract boolean deleteSharedPreferences(String name);
843
Christopher Tatefe2368c2017-05-17 15:42:35 -0700844 /** @hide */
845 public abstract void reloadSharedPreferences();
846
Jeff Sharkey35871f22016-01-29 17:13:29 -0700847 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 * Open a private file associated with this Context's application package
849 * for reading.
850 *
851 * @param name The name of the file to open; can not contain path
852 * separators.
853 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400854 * @return The resulting {@link FileInputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 *
856 * @see #openFileOutput
857 * @see #fileList
858 * @see #deleteFile
859 * @see java.io.FileInputStream#FileInputStream(String)
860 */
861 public abstract FileInputStream openFileInput(String name)
862 throws FileNotFoundException;
863
864 /**
Nick Kralevich15069212013-01-09 15:54:56 -0800865 * Open a private file associated with this Context's application package
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700866 * for writing. Creates the file if it doesn't already exist.
867 * <p>
868 * No additional permissions are required for the calling app to read or
869 * write the returned file.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700870 *
Nick Kralevich15069212013-01-09 15:54:56 -0800871 * @param name The name of the file to open; can not contain path
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700872 * separators.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600873 * @param mode Operating mode.
John Spurlock6098c5d2013-06-17 10:32:46 -0400874 * @return The resulting {@link FileOutputStream}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800875 * @see #MODE_APPEND
876 * @see #MODE_PRIVATE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800877 * @see #openFileInput
878 * @see #fileList
879 * @see #deleteFile
880 * @see java.io.FileOutputStream#FileOutputStream(String)
881 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -0600882 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 throws FileNotFoundException;
884
885 /**
886 * Delete the given private file associated with this Context's
887 * application package.
888 *
889 * @param name The name of the file to delete; can not contain path
890 * separators.
891 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400892 * @return {@code true} if the file was successfully deleted; else
893 * {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800894 *
895 * @see #openFileInput
896 * @see #openFileOutput
897 * @see #fileList
898 * @see java.io.File#delete()
899 */
900 public abstract boolean deleteFile(String name);
901
902 /**
903 * Returns the absolute path on the filesystem where a file created with
904 * {@link #openFileOutput} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700905 * <p>
906 * The returned path may change over time if the calling app is moved to an
907 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800908 *
909 * @param name The name of the file for which you would like to get
910 * its path.
911 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400912 * @return An absolute path to the given file.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800913 *
914 * @see #openFileOutput
915 * @see #getFilesDir
916 * @see #getDir
917 */
918 public abstract File getFileStreamPath(String name);
919
920 /**
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700921 * Returns the absolute path on the filesystem where a file created with
922 * {@link #getSharedPreferences(String, int)} is stored.
923 * <p>
924 * The returned path may change over time if the calling app is moved to an
925 * adopted storage device, so only relative paths should be persisted.
926 *
927 * @param name The name of the shared preferences for which you would like
928 * to get a path.
929 * @return An absolute path to the given file.
930 * @see #getSharedPreferences(String, int)
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600931 * @removed
Jeff Sharkey6a6cdaf2015-12-07 19:25:19 -0700932 */
933 public abstract File getSharedPreferencesPath(String name);
934
935 /**
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700936 * Returns the absolute path to the directory on the filesystem where all
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600937 * private files belonging to this app are stored. Apps should not use this
938 * path directly; they should instead use {@link #getFilesDir()},
939 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
940 * APIs on this class.
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700941 * <p>
942 * The returned path may change over time if the calling app is moved to an
943 * adopted storage device, so only relative paths should be persisted.
944 * <p>
945 * No additional permissions are required for the calling app to read or
946 * write files under the returned path.
947 *
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -0600948 * @see ApplicationInfo#dataDir
Jeff Sharkey2c1ba9a2016-02-17 15:29:38 -0700949 */
950 public abstract File getDataDir();
951
952 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700953 * Returns the absolute path to the directory on the filesystem where files
954 * created with {@link #openFileOutput} are stored.
955 * <p>
956 * The returned path may change over time if the calling app is moved to an
957 * adopted storage device, so only relative paths should be persisted.
958 * <p>
959 * No additional permissions are required for the calling app to read or
960 * write files under the returned path.
Ricardo Cervera90a5f982014-04-04 10:26:05 -0700961 *
John Spurlock6098c5d2013-06-17 10:32:46 -0400962 * @return The path of the directory holding application files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800963 * @see #openFileOutput
964 * @see #getFileStreamPath
965 * @see #getDir
966 */
967 public abstract File getFilesDir();
Scott Main4b5da682010-10-21 11:49:12 -0700968
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 /**
Christopher Tatea7835b62014-07-11 17:25:57 -0700970 * Returns the absolute path to the directory on the filesystem similar to
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700971 * {@link #getFilesDir()}. The difference is that files placed under this
972 * directory will be excluded from automatic backup to remote storage. See
Christopher Tatea7835b62014-07-11 17:25:57 -0700973 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
974 * of the automatic backup mechanism in Android.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700975 * <p>
976 * The returned path may change over time if the calling app is moved to an
977 * adopted storage device, so only relative paths should be persisted.
978 * <p>
979 * No additional permissions are required for the calling app to read or
980 * write files under the returned path.
Christopher Tatea7835b62014-07-11 17:25:57 -0700981 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700982 * @return The path of the directory holding application files that will not
983 * be automatically backed up to remote storage.
Christopher Tatea7835b62014-07-11 17:25:57 -0700984 * @see #openFileOutput
985 * @see #getFileStreamPath
986 * @see #getDir
987 * @see android.app.backup.BackupAgent
988 */
989 public abstract File getNoBackupFilesDir();
990
991 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -0700992 * Returns the absolute path to the directory on the primary shared/external
993 * storage device where the application can place persistent files it owns.
994 * These files are internal to the applications, and not typically visible
995 * to the user as media.
996 * <p>
997 * This is like {@link #getFilesDir()} in that these files will be deleted
998 * when the application is uninstalled, however there are some important
999 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001000 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001001 * <li>Shared storage may not always be available, since removable media can
1002 * be ejected by the user. Media state can be checked using
1003 * {@link Environment#getExternalStorageState(File)}.
1004 * <li>There is no security enforced with these files. For example, any
1005 * application holding
1006 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001007 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001008 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001009 * <p>
1010 * If a shared storage device is emulated (as determined by
1011 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1012 * backed by a private user data partition, which means there is little
1013 * benefit to storing data here instead of the private directories returned
1014 * by {@link #getFilesDir()}, etc.
1015 * <p>
1016 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001017 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001018 * accessible to the calling app. This only applies to paths generated for
1019 * package name of the calling application. To access paths belonging to
1020 * other packages,
1021 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1022 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1023 * <p>
1024 * On devices with multiple users (as described by {@link UserManager}),
1025 * each user has their own isolated shared storage. Applications only have
1026 * access to the shared storage for the user they're running as.
1027 * <p>
1028 * The returned path may change over time if different shared storage media
1029 * is inserted, so only relative paths should be persisted.
1030 * <p>
1031 * Here is an example of typical code to manipulate a file in an
1032 * application's shared storage:
1033 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001034 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1035 * private_file}
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001036 * <p>
1037 * If you supply a non-null <var>type</var> to this function, the returned
1038 * file will be a path to a sub-directory of the given type. Though these
1039 * files are not automatically scanned by the media scanner, you can
1040 * explicitly add them to the media database with
1041 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1042 * MediaScannerConnection.scanFile}. Note that this is not the same as
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001043 * {@link android.os.Environment#getExternalStoragePublicDirectory
1044 * Environment.getExternalStoragePublicDirectory()}, which provides
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001045 * directories of media shared by all applications. The directories returned
1046 * here are owned by the application, and their contents will be removed
1047 * when the application is uninstalled. Unlike
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001048 * {@link android.os.Environment#getExternalStoragePublicDirectory
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001049 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1050 * here will be automatically created for you.
1051 * <p>
1052 * Here is an example of typical code to manipulate a picture in an
1053 * application's shared storage and add it to the media database:
1054 * </p>
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001055 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1056 * private_picture}
Jeff Sharkey8c165792012-10-22 14:08:29 -07001057 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001058 * @param type The type of files directory to return. May be {@code null}
1059 * for the root of the files directory or one of the following
1060 * constants for a subdirectory:
1061 * {@link android.os.Environment#DIRECTORY_MUSIC},
1062 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1063 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1064 * {@link android.os.Environment#DIRECTORY_ALARMS},
1065 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1066 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1067 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1068 * @return the absolute path to application-specific directory. May return
1069 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001070 * @see #getFilesDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001071 * @see #getExternalFilesDirs(String)
1072 * @see Environment#getExternalStorageState(File)
1073 * @see Environment#isExternalStorageEmulated(File)
1074 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001075 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001076 @Nullable
1077 public abstract File getExternalFilesDir(@Nullable String type);
Scott Main4b5da682010-10-21 11:49:12 -07001078
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001079 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001080 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001081 * shared/external storage devices where the application can place
1082 * persistent files it owns. These files are internal to the application,
1083 * and not typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001084 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001085 * This is like {@link #getFilesDir()} in that these files will be deleted
1086 * when the application is uninstalled, however there are some important
1087 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001088 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001089 * <li>Shared storage may not always be available, since removable media can
1090 * be ejected by the user. Media state can be checked using
1091 * {@link Environment#getExternalStorageState(File)}.
1092 * <li>There is no security enforced with these files. For example, any
1093 * application holding
1094 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1095 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001096 * </ul>
1097 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001098 * If a shared storage device is emulated (as determined by
1099 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1100 * backed by a private user data partition, which means there is little
1101 * benefit to storing data here instead of the private directories returned
1102 * by {@link #getFilesDir()}, etc.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001103 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001104 * Shared storage devices returned here are considered a stable part of the
1105 * device, including physical media slots under a protective cover. The
1106 * returned paths do not include transient devices, such as USB flash drives
1107 * connected to handheld devices.
1108 * <p>
1109 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001110 * example, an app may choose to store large files on the device with the
1111 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001112 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001113 * No additional permissions are required for the calling app to read or
1114 * write files under the returned path. Write access outside of these paths
1115 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001116 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001117 * The returned path may change over time if different shared storage media
1118 * is inserted, so only relative paths should be persisted.
Jeff Sharkey8c165792012-10-22 14:08:29 -07001119 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001120 * @param type The type of files directory to return. May be {@code null}
1121 * for the root of the files directory or one of the following
1122 * constants for a subdirectory:
1123 * {@link android.os.Environment#DIRECTORY_MUSIC},
1124 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1125 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1126 * {@link android.os.Environment#DIRECTORY_ALARMS},
1127 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1128 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1129 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1130 * @return the absolute paths to application-specific directories. Some
1131 * individual paths may be {@code null} if that shared storage is
1132 * not currently available. The first path returned is the same as
1133 * {@link #getExternalFilesDir(String)}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001134 * @see #getExternalFilesDir(String)
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001135 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001136 * @see Environment#isExternalStorageEmulated(File)
1137 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001138 */
1139 public abstract File[] getExternalFilesDirs(String type);
1140
1141 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001142 * Return the primary shared/external storage directory where this
1143 * application's OBB files (if there are any) can be found. Note if the
1144 * application does not have any OBB files, this directory may not exist.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001145 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001146 * This is like {@link #getFilesDir()} in that these files will be deleted
1147 * when the application is uninstalled, however there are some important
1148 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001149 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001150 * <li>Shared storage may not always be available, since removable media can
1151 * be ejected by the user. Media state can be checked using
1152 * {@link Environment#getExternalStorageState(File)}.
1153 * <li>There is no security enforced with these files. For example, any
1154 * application holding
1155 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001156 * these files.
1157 * </ul>
1158 * <p>
1159 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Dave Friedmancfe50882017-07-05 00:40:07 -07001160 * are required to read or write to the path that this method returns.
1161 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1162 * to read the OBB expansion files, you must declare the
1163 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1164 * permission at runtime as follows:
1165 * </p>
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001166 * <p>
Dave Friedmancfe50882017-07-05 00:40:07 -07001167 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1168 * android:maxSdkVersion="23" />}
1169 * </p>
1170 * <p>
1171 * Starting from {@link android.os.Build.VERSION_CODES#N},
1172 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1173 * permission is not required, so don’t ask for this
1174 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1175 * and if it fails, you must request
1176 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1177 * </p>
1178 *
1179 * <p>
1180 * The following code snippet shows how to do this:
1181 * </p>
1182 *
1183 * <pre>
1184 * File obb = new File(obb_filename);
1185 * boolean open_failed = false;
1186 *
1187 * try {
1188 * BufferedReader br = new BufferedReader(new FileReader(obb));
1189 * open_failed = false;
1190 * ReadObbFile(br);
1191 * } catch (IOException e) {
1192 * open_failed = true;
1193 * }
1194 *
1195 * if (open_failed) {
1196 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1197 * ReadObbFileWithPermission();
1198 * }
1199 * </pre>
1200 *
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001201 * On devices with multiple users (as described by {@link UserManager}),
Jeff Sharkey8c165792012-10-22 14:08:29 -07001202 * multiple users may share the same OBB storage location. Applications
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001203 * should ensure that multiple instances running under different users don't
1204 * interfere with each other.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001205 *
1206 * @return the absolute path to application-specific directory. May return
1207 * {@code null} if shared storage is not currently available.
1208 * @see #getObbDirs()
1209 * @see Environment#getExternalStorageState(File)
1210 * @see Environment#isExternalStorageEmulated(File)
1211 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborn805fd7e2011-01-16 18:30:29 -08001212 */
1213 public abstract File getObbDir();
1214
1215 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001216 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001217 * shared/external storage devices where the application's OBB files (if
1218 * there are any) can be found. Note if the application does not have any
1219 * OBB files, these directories may not exist.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001220 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001221 * This is like {@link #getFilesDir()} in that these files will be deleted
1222 * when the application is uninstalled, however there are some important
1223 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001224 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001225 * <li>Shared storage may not always be available, since removable media can
1226 * be ejected by the user. Media state can be checked using
1227 * {@link Environment#getExternalStorageState(File)}.
1228 * <li>There is no security enforced with these files. For example, any
1229 * application holding
1230 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1231 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001232 * </ul>
1233 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001234 * Shared storage devices returned here are considered a stable part of the
1235 * device, including physical media slots under a protective cover. The
1236 * returned paths do not include transient devices, such as USB flash drives
1237 * connected to handheld devices.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001238 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001239 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001240 * example, an app may choose to store large files on the device with the
1241 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001242 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001243 * No additional permissions are required for the calling app to read or
1244 * write files under the returned path. Write access outside of these paths
1245 * on secondary external storage devices is not available.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001246 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001247 * @return the absolute paths to application-specific directories. Some
1248 * individual paths may be {@code null} if that shared storage is
1249 * not currently available. The first path returned is the same as
1250 * {@link #getObbDir()}
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001251 * @see #getObbDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001252 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001253 * @see Environment#isExternalStorageEmulated(File)
1254 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001255 */
1256 public abstract File[] getObbDirs();
1257
1258 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001259 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001260 * the filesystem.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001261 * <p>
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001262 * The system will automatically delete files in this directory as disk
1263 * space is needed elsewhere on the device. The system will always delete
1264 * older files first, as reported by {@link File#lastModified()}. If
1265 * desired, you can exert more control over how files are deleted using
1266 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1267 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1268 * <p>
1269 * Apps are strongly encouraged to keep their usage of cache space below the
1270 * quota returned by
1271 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1272 * goes above this quota, your cached files will be some of the first to be
1273 * deleted when additional disk space is needed. Conversely, if your app
1274 * stays under this quota, your cached files will be some of the last to be
1275 * deleted when additional disk space is needed.
1276 * <p>
1277 * Note that your cache quota will change over time depending on how
1278 * frequently the user interacts with your app, and depending on how much
1279 * system-wide disk space is used.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001280 * <p>
1281 * The returned path may change over time if the calling app is moved to an
1282 * adopted storage device, so only relative paths should be persisted.
1283 * <p>
1284 * Apps require no extra permissions to read or write to the returned path,
1285 * since this path lives in their private storage.
Scott Main4b5da682010-10-21 11:49:12 -07001286 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001287 * @return The path of the directory holding application cache files.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 * @see #openFileOutput
1289 * @see #getFileStreamPath
1290 * @see #getDir
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001291 * @see #getExternalCacheDir
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001292 */
1293 public abstract File getCacheDir();
1294
1295 /**
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001296 * Returns the absolute path to the application specific cache directory on
Jeff Sharkey60a82cd2017-04-18 18:19:16 -06001297 * the filesystem designed for storing cached code.
1298 * <p>
1299 * The system will delete any files stored in this location both when your
1300 * specific application is upgraded, and when the entire platform is
1301 * upgraded.
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001302 * <p>
1303 * This location is optimal for storing compiled or optimized code generated
1304 * by your application at runtime.
1305 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001306 * The returned path may change over time if the calling app is moved to an
1307 * adopted storage device, so only relative paths should be persisted.
1308 * <p>
Jeff Sharkey4ed745d2014-07-15 20:39:15 -07001309 * Apps require no extra permissions to read or write to the returned path,
1310 * since this path lives in their private storage.
1311 *
1312 * @return The path of the directory holding application code cache files.
1313 */
1314 public abstract File getCodeCacheDir();
1315
1316 /**
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001317 * Returns absolute path to application-specific directory on the primary
1318 * shared/external storage device where the application can place cache
1319 * files it owns. These files are internal to the application, and not
1320 * typically visible to the user as media.
1321 * <p>
1322 * This is like {@link #getCacheDir()} in that these files will be deleted
1323 * when the application is uninstalled, however there are some important
1324 * differences:
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001325 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001326 * <li>The platform does not always monitor the space available in shared
1327 * storage, and thus may not automatically delete these files. Apps should
1328 * always manage the maximum space used in this location. Currently the only
1329 * time files here will be deleted by the platform is when running on
1330 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1331 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1332 * <li>Shared storage may not always be available, since removable media can
1333 * be ejected by the user. Media state can be checked using
1334 * {@link Environment#getExternalStorageState(File)}.
1335 * <li>There is no security enforced with these files. For example, any
1336 * application holding
1337 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001338 * these files.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001339 * </ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001340 * <p>
1341 * If a shared storage device is emulated (as determined by
Kevin Hufnaglee9681e12016-09-23 16:44:03 -07001342 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001343 * backed by a private user data partition, which means there is little
1344 * benefit to storing data here instead of the private directory returned by
1345 * {@link #getCacheDir()}.
1346 * <p>
1347 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001348 * are required to read or write to the returned path; it's always
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001349 * accessible to the calling app. This only applies to paths generated for
1350 * package name of the calling application. To access paths belonging to
1351 * other packages,
1352 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1353 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1354 * <p>
1355 * On devices with multiple users (as described by {@link UserManager}),
1356 * each user has their own isolated shared storage. Applications only have
1357 * access to the shared storage for the user they're running as.
1358 * <p>
1359 * The returned path may change over time if different shared storage media
1360 * is inserted, so only relative paths should be persisted.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001361 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001362 * @return the absolute path to application-specific directory. May return
1363 * {@code null} if shared storage is not currently available.
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001364 * @see #getCacheDir
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001365 * @see #getExternalCacheDirs()
1366 * @see Environment#getExternalStorageState(File)
1367 * @see Environment#isExternalStorageEmulated(File)
1368 * @see Environment#isExternalStorageRemovable(File)
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001369 */
Tor Norbyed9273d62013-05-30 15:59:53 -07001370 @Nullable
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001371 public abstract File getExternalCacheDir();
Scott Main4b5da682010-10-21 11:49:12 -07001372
Dianne Hackborne83cefce2010-02-04 17:38:14 -08001373 /**
Fyodor Kupolov61221292016-09-02 15:21:03 -07001374 * Returns absolute path to application-specific directory in the preloaded cache.
1375 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1376 * There is no guarantee when these files will be deleted.
1377 * @hide
1378 */
1379 @Nullable
1380 @SystemApi
1381 public abstract File getPreloadsFileCache();
1382
1383 /**
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001384 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001385 * shared/external storage devices where the application can place cache
1386 * files it owns. These files are internal to the application, and not
1387 * typically visible to the user as media.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001388 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001389 * This is like {@link #getCacheDir()} in that these files will be deleted
1390 * when the application is uninstalled, however there are some important
1391 * differences:
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001392 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001393 * <li>The platform does not always monitor the space available in shared
1394 * storage, and thus may not automatically delete these files. Apps should
1395 * always manage the maximum space used in this location. Currently the only
1396 * time files here will be deleted by the platform is when running on
1397 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1398 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1399 * <li>Shared storage may not always be available, since removable media can
1400 * be ejected by the user. Media state can be checked using
1401 * {@link Environment#getExternalStorageState(File)}.
1402 * <li>There is no security enforced with these files. For example, any
1403 * application holding
1404 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1405 * these files.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001406 * </ul>
1407 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001408 * If a shared storage device is emulated (as determined by
1409 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1410 * backed by a private user data partition, which means there is little
1411 * benefit to storing data here instead of the private directory returned by
1412 * {@link #getCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001413 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001414 * Shared storage devices returned here are considered a stable part of the
1415 * device, including physical media slots under a protective cover. The
1416 * returned paths do not include transient devices, such as USB flash drives
1417 * connected to handheld devices.
1418 * <p>
1419 * An application may store data on any or all of the returned devices. For
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001420 * example, an app may choose to store large files on the device with the
1421 * most available space, as measured by {@link StatFs}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001422 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001423 * No additional permissions are required for the calling app to read or
1424 * write files under the returned path. Write access outside of these paths
1425 * on secondary external storage devices is not available.
Jeff Sharkey6feb50b2013-10-15 12:38:15 -07001426 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001427 * The returned paths may change over time if different shared storage media
1428 * is inserted, so only relative paths should be persisted.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001429 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001430 * @return the absolute paths to application-specific directories. Some
1431 * individual paths may be {@code null} if that shared storage is
1432 * not currently available. The first path returned is the same as
1433 * {@link #getExternalCacheDir()}.
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001434 * @see #getExternalCacheDir()
Jeff Sharkey4ca728c2014-01-10 16:27:19 -08001435 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001436 * @see Environment#isExternalStorageEmulated(File)
1437 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey1abdb712013-08-11 16:28:14 -07001438 */
1439 public abstract File[] getExternalCacheDirs();
1440
1441 /**
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001442 * Returns absolute paths to application-specific directories on all
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001443 * shared/external storage devices where the application can place media
1444 * files. These files are scanned and made available to other apps through
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001445 * {@link MediaStore}.
1446 * <p>
1447 * This is like {@link #getExternalFilesDirs} in that these files will be
1448 * deleted when the application is uninstalled, however there are some
1449 * important differences:
1450 * <ul>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001451 * <li>Shared storage may not always be available, since removable media can
1452 * be ejected by the user. Media state can be checked using
1453 * {@link Environment#getExternalStorageState(File)}.
1454 * <li>There is no security enforced with these files. For example, any
1455 * application holding
1456 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1457 * these files.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001458 * </ul>
1459 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001460 * Shared storage devices returned here are considered a stable part of the
1461 * device, including physical media slots under a protective cover. The
1462 * returned paths do not include transient devices, such as USB flash drives
1463 * connected to handheld devices.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001464 * <p>
1465 * An application may store data on any or all of the returned devices. For
1466 * example, an app may choose to store large files on the device with the
1467 * most available space, as measured by {@link StatFs}.
1468 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001469 * No additional permissions are required for the calling app to read or
1470 * write files under the returned path. Write access outside of these paths
1471 * on secondary external storage devices is not available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001472 * <p>
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001473 * The returned paths may change over time if different shared storage media
1474 * is inserted, so only relative paths should be persisted.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001475 *
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001476 * @return the absolute paths to application-specific directories. Some
1477 * individual paths may be {@code null} if that shared storage is
1478 * not currently available.
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001479 * @see Environment#getExternalStorageState(File)
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001480 * @see Environment#isExternalStorageEmulated(File)
1481 * @see Environment#isExternalStorageRemovable(File)
Jeff Sharkey2ee3c1e2014-05-30 15:38:35 -07001482 */
1483 public abstract File[] getExternalMediaDirs();
1484
1485 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001486 * Returns an array of strings naming the private files associated with
1487 * this Context's application package.
1488 *
1489 * @return Array of strings naming the private files.
1490 *
1491 * @see #openFileInput
1492 * @see #openFileOutput
1493 * @see #deleteFile
1494 */
1495 public abstract String[] fileList();
1496
1497 /**
1498 * Retrieve, creating if needed, a new directory in which the application
1499 * can place its own custom data files. You can use the returned File
1500 * object to create and access files in this directory. Note that files
1501 * created through a File object will only be accessible by your own
1502 * application; you can only set the mode of the entire directory, not
1503 * of individual files.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001504 * <p>
1505 * The returned path may change over time if the calling app is moved to an
1506 * adopted storage device, so only relative paths should be persisted.
1507 * <p>
1508 * Apps require no extra permissions to read or write to the returned path,
1509 * since this path lives in their private storage.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001510 *
Nick Kralevich92091fa2012-12-12 16:24:31 -08001511 * @param name Name of the directory to retrieve. This is a directory
Nick Kralevich15069212013-01-09 15:54:56 -08001512 * that is created as part of your application data.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001513 * @param mode Operating mode.
Nick Kralevich15069212013-01-09 15:54:56 -08001514 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001515 * @return A {@link File} object for the requested directory. The directory
Nick Kralevich15069212013-01-09 15:54:56 -08001516 * will have been created if it does not already exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 *
1518 * @see #openFileOutput(String, int)
1519 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001520 public abstract File getDir(String name, @FileMode int mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521
1522 /**
1523 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001524 * application package. Create the database file if it doesn't exist.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 *
1526 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001527 * @param mode Operating mode.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001528 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001529 * cursor when query is called.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001531 * @throws android.database.sqlite.SQLiteException if the database file
1532 * could not be opened.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001533 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001534 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001535 * @see #MODE_NO_LOCALIZED_COLLATORS
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536 * @see #deleteDatabase
1537 */
1538 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001539 @DatabaseMode int mode, CursorFactory factory);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001540
1541 /**
Vasu Nori74f170f2010-06-01 18:06:18 -07001542 * Open a new private SQLiteDatabase associated with this Context's
Jeff Sharkey634dc422016-01-30 17:44:15 -07001543 * application package. Creates the database file if it doesn't exist.
1544 * <p>
1545 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1546 * to be used to handle corruption when sqlite reports database corruption.
1547 * </p>
Vasu Nori74f170f2010-06-01 18:06:18 -07001548 *
1549 * @param name The name (unique in the application package) of the database.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001550 * @param mode Operating mode.
Vasu Nori74f170f2010-06-01 18:06:18 -07001551 * @param factory An optional factory class that is called to instantiate a
Jeff Sharkey634dc422016-01-30 17:44:15 -07001552 * cursor when query is called.
1553 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1554 * sqlite reports database corruption. if null,
1555 * {@link android.database.DefaultDatabaseErrorHandler} is
1556 * assumed.
Vasu Nori74f170f2010-06-01 18:06:18 -07001557 * @return The contents of a newly created database with the given name.
Jeff Sharkey634dc422016-01-30 17:44:15 -07001558 * @throws android.database.sqlite.SQLiteException if the database file
1559 * could not be opened.
Vasu Nori74f170f2010-06-01 18:06:18 -07001560 * @see #MODE_PRIVATE
Jeff Brown47847f32012-03-22 19:13:11 -07001561 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
Sunny Goyala21e6b22015-12-02 09:51:02 -08001562 * @see #MODE_NO_LOCALIZED_COLLATORS
Vasu Nori74f170f2010-06-01 18:06:18 -07001563 * @see #deleteDatabase
1564 */
1565 public abstract SQLiteDatabase openOrCreateDatabase(String name,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001566 @DatabaseMode int mode, CursorFactory factory,
Tor Norbyed9273d62013-05-30 15:59:53 -07001567 @Nullable DatabaseErrorHandler errorHandler);
Vasu Nori74f170f2010-06-01 18:06:18 -07001568
1569 /**
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001570 * Move an existing database file from the given source storage context to
1571 * this context. This is typically used to migrate data between storage
1572 * locations after an upgrade, such as migrating to device protected
1573 * storage.
Jeff Sharkeyd21cad12016-05-20 11:30:07 -06001574 * <p>
1575 * The database must be closed before being moved.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001576 *
1577 * @param sourceContext The source context which contains the existing
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001578 * database to move.
Jeff Sharkey35871f22016-01-29 17:13:29 -07001579 * @param name The name of the database file.
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001580 * @return {@code true} if the move was successful or if the database didn't
1581 * exist in the source context, otherwise {@code false}.
1582 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey35871f22016-01-29 17:13:29 -07001583 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06001584 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1585
Jeff Sharkey35871f22016-01-29 17:13:29 -07001586 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 * Delete an existing private SQLiteDatabase associated with this Context's
1588 * application package.
1589 *
1590 * @param name The name (unique in the application package) of the
1591 * database.
1592 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001593 * @return {@code true} if the database was successfully deleted; else {@code false}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001594 *
1595 * @see #openOrCreateDatabase
1596 */
1597 public abstract boolean deleteDatabase(String name);
1598
1599 /**
1600 * Returns the absolute path on the filesystem where a database created with
1601 * {@link #openOrCreateDatabase} is stored.
Jeff Sharkey59d28dc82015-10-14 13:56:23 -07001602 * <p>
1603 * The returned path may change over time if the calling app is moved to an
1604 * adopted storage device, so only relative paths should be persisted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 *
1606 * @param name The name of the database for which you would like to get
1607 * its path.
1608 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001609 * @return An absolute path to the given database.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 *
1611 * @see #openOrCreateDatabase
1612 */
1613 public abstract File getDatabasePath(String name);
1614
1615 /**
1616 * Returns an array of strings naming the private databases associated with
1617 * this Context's application package.
1618 *
1619 * @return Array of strings naming the private databases.
1620 *
1621 * @see #openOrCreateDatabase
1622 * @see #deleteDatabase
1623 */
1624 public abstract String[] databaseList();
1625
1626 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001627 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001628 * WallpaperManager.get()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001629 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001630 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001631 public abstract Drawable getWallpaper();
1632
1633 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001634 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001635 * WallpaperManager.peek()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001636 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001637 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001638 public abstract Drawable peekWallpaper();
1639
1640 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001641 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1642 * WallpaperManager.getDesiredMinimumWidth()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001644 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001645 public abstract int getWallpaperDesiredMinimumWidth();
1646
1647 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001648 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1649 * WallpaperManager.getDesiredMinimumHeight()} instead.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001651 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 public abstract int getWallpaperDesiredMinimumHeight();
1653
1654 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001655 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001656 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001657 * <p>This method requires the caller to hold the permission
1658 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001659 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001660 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1662
1663 /**
Dianne Hackborn4c62fc02009-08-08 20:40:27 -07001664 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001665 * WallpaperManager.set()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001666 * <p>This method requires the caller to hold the permission
1667 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001669 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001670 public abstract void setWallpaper(InputStream data) throws IOException;
1671
1672 /**
Dianne Hackborn8cc6a502009-08-05 21:29:42 -07001673 * @deprecated Use {@link android.app.WallpaperManager#clear
1674 * WallpaperManager.clear()} instead.
Nicolas Falliere9530e3a2012-06-18 17:21:06 -07001675 * <p>This method requires the caller to hold the permission
1676 * {@link android.Manifest.permission#SET_WALLPAPER}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -07001678 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 public abstract void clearWallpaper() throws IOException;
1680
1681 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001682 * Same as {@link #startActivity(Intent, Bundle)} with no options
1683 * specified.
1684 *
1685 * @param intent The description of the activity to start.
1686 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001687 * @throws ActivityNotFoundException &nbsp;
Svet Ganov1ed0e552015-06-11 01:15:43 -07001688 *`
John Spurlock6098c5d2013-06-17 10:32:46 -04001689 * @see #startActivity(Intent, Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001690 * @see PackageManager#resolveActivity
1691 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001692 public abstract void startActivity(@RequiresPermission Intent intent);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001693
1694 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001695 * Version of {@link #startActivity(Intent)} that allows you to specify the
1696 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001697 * that are not pre-installed on the system image.
Amith Yamasani82644082012-08-03 13:09:11 -07001698 * @param intent The description of the activity to start.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07001699 * @param user The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001700 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani82644082012-08-03 13:09:11 -07001701 * @hide
1702 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001703 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood1c77a112018-08-14 14:06:26 +01001704 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001705 public void startActivityAsUser(@RequiresPermission Intent intent, UserHandle user) {
Amith Yamasani82644082012-08-03 13:09:11 -07001706 throw new RuntimeException("Not implemented. Must override in a subclass.");
1707 }
1708
1709 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710 * Launch a new activity. You will not receive any information about when
1711 * the activity exits.
1712 *
1713 * <p>Note that if this method is being called from outside of an
1714 * {@link android.app.Activity} Context, then the Intent must include
1715 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1716 * without being started from an existing Activity, there is no existing
1717 * task in which to place the new activity and thus it needs to be placed
1718 * in its own separate task.
1719 *
1720 * <p>This method throws {@link ActivityNotFoundException}
1721 * if there was no Activity found to run the given Intent.
1722 *
1723 * @param intent The description of the activity to start.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001724 * @param options Additional options for how the Activity should be started.
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001725 * May be null if there are no options. See {@link android.app.ActivityOptions}
1726 * for how to build the Bundle supplied here; there are no supported definitions
1727 * for building it manually.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001728 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001729 * @throws ActivityNotFoundException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001730 *
Scott Main60dd5202012-06-23 00:01:22 -07001731 * @see #startActivity(Intent)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001732 * @see PackageManager#resolveActivity
1733 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001734 public abstract void startActivity(@RequiresPermission Intent intent,
1735 @Nullable Bundle options);
Dianne Hackborna4972e92012-03-14 10:38:05 -07001736
1737 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07001738 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
1739 * user the activity will be started for. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001740 * that are not pre-installed on the system image.
Amith Yamasani258848d2012-08-10 17:06:33 -07001741 * @param intent The description of the activity to start.
1742 * @param options Additional options for how the Activity should be started.
1743 * May be null if there are no options. See {@link android.app.ActivityOptions}
1744 * for how to build the Bundle supplied here; there are no supported definitions
1745 * for building it manually.
Dianne Hackborn221ea892013-08-04 16:50:16 -07001746 * @param userId The UserHandle of the user to start this activity for.
John Spurlock6098c5d2013-06-17 10:32:46 -04001747 * @throws ActivityNotFoundException &nbsp;
Amith Yamasani258848d2012-08-10 17:06:33 -07001748 * @hide
1749 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001750 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood1c77a112018-08-14 14:06:26 +01001751 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07001752 public void startActivityAsUser(@RequiresPermission Intent intent, @Nullable Bundle options,
1753 UserHandle userId) {
Amith Yamasani258848d2012-08-10 17:06:33 -07001754 throw new RuntimeException("Not implemented. Must override in a subclass.");
1755 }
1756
1757 /**
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001758 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
1759 * is only supported for Views and Fragments.
1760 * @param who The identifier for the calling element that will receive the result.
1761 * @param intent The intent to start.
1762 * @param requestCode The code that will be returned with onActivityResult() identifying this
1763 * request.
1764 * @param options Additional options for how the Activity should be started.
1765 * May be null if there are no options. See {@link android.app.ActivityOptions}
1766 * for how to build the Bundle supplied here; there are no supported definitions
1767 * for building it manually.
1768 * @hide
1769 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01001770 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001771 public void startActivityForResult(
1772 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
1773 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
1774 + "Check canStartActivityForResult() before calling.");
1775 }
1776
1777 /**
1778 * Identifies whether this Context instance will be able to process calls to
1779 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
1780 * @hide
1781 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01001782 @UnsupportedAppUsage
Clara Bayarrid5bf3ed2015-03-27 17:32:45 +00001783 public boolean canStartActivityForResult() {
1784 return false;
1785 }
1786
1787 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001788 * Same as {@link #startActivities(Intent[], Bundle)} with no options
1789 * specified.
1790 *
1791 * @param intents An array of Intents to be started.
1792 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001793 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001794 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001795 * @see #startActivities(Intent[], Bundle)
Dianne Hackborna4972e92012-03-14 10:38:05 -07001796 * @see PackageManager#resolveActivity
1797 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001798 public abstract void startActivities(@RequiresPermission Intent[] intents);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799
1800 /**
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001801 * Launch multiple new activities. This is generally the same as calling
1802 * {@link #startActivity(Intent)} for the first Intent in the array,
1803 * that activity during its creation calling {@link #startActivity(Intent)}
1804 * for the second entry, etc. Note that unlike that approach, generally
1805 * none of the activities except the last in the array will be created
1806 * at this point, but rather will be created when the user first visits
1807 * them (due to pressing back from the activity on top).
1808 *
1809 * <p>This method throws {@link ActivityNotFoundException}
1810 * if there was no Activity found for <em>any</em> given Intent. In this
1811 * case the state of the activity stack is undefined (some Intents in the
1812 * list may be on it, some not), so you probably want to avoid such situations.
1813 *
1814 * @param intents An array of Intents to be started.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001815 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001816 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001817 * Context.startActivity(Intent, Bundle)} for more details.
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001818 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001819 * @throws ActivityNotFoundException &nbsp;
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001820 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001821 * @see #startActivities(Intent[])
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001822 * @see PackageManager#resolveActivity
1823 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001824 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
Dianne Hackborn621e17d2010-11-22 15:59:56 -08001825
1826 /**
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001827 * @hide
1828 * Launch multiple new activities. This is generally the same as calling
1829 * {@link #startActivity(Intent)} for the first Intent in the array,
1830 * that activity during its creation calling {@link #startActivity(Intent)}
1831 * for the second entry, etc. Note that unlike that approach, generally
1832 * none of the activities except the last in the array will be created
1833 * at this point, but rather will be created when the user first visits
1834 * them (due to pressing back from the activity on top).
1835 *
1836 * <p>This method throws {@link ActivityNotFoundException}
1837 * if there was no Activity found for <em>any</em> given Intent. In this
1838 * case the state of the activity stack is undefined (some Intents in the
1839 * list may be on it, some not), so you probably want to avoid such situations.
1840 *
1841 * @param intents An array of Intents to be started.
1842 * @param options Additional options for how the Activity should be started.
1843 * @param userHandle The user for whom to launch the activities
Elliot Waite54de7742017-01-11 15:30:35 -08001844 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001845 * Context.startActivity(Intent, Bundle)} for more details.
1846 *
Selim Cinek7fa385a2018-01-24 08:35:28 -08001847 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
1848 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
1849 * successful.
1850 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001851 * @throws ActivityNotFoundException &nbsp;
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001852 *
John Spurlock6098c5d2013-06-17 10:32:46 -04001853 * @see #startActivities(Intent[])
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001854 * @see PackageManager#resolveActivity
1855 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001856 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Selim Cinek7fa385a2018-01-24 08:35:28 -08001857 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
Amith Yamasaniea7e9152012-09-24 16:11:18 -07001858 throw new RuntimeException("Not implemented. Must override in a subclass.");
1859 }
1860
1861 /**
Dianne Hackborna4972e92012-03-14 10:38:05 -07001862 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
1863 * with no options specified.
1864 *
1865 * @param intent The IntentSender to launch.
1866 * @param fillInIntent If non-null, this will be provided as the
1867 * intent parameter to {@link IntentSender#sendIntent}.
1868 * @param flagsMask Intent flags in the original IntentSender that you
1869 * would like to change.
1870 * @param flagsValues Desired values for any bits set in
1871 * <var>flagsMask</var>
1872 * @param extraFlags Always set to 0.
1873 *
1874 * @see #startActivity(Intent)
1875 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
1876 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001877 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1878 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1879 int extraFlags) throws IntentSender.SendIntentException;
Dianne Hackborna4972e92012-03-14 10:38:05 -07001880
1881 /**
1882 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001883 * to start. If the IntentSender is for an activity, that activity will be started
Dianne Hackbornae22c052009-09-17 18:46:22 -07001884 * as if you had called the regular {@link #startActivity(Intent)}
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001885 * here; otherwise, its associated action will be executed (such as
1886 * sending a broadcast) as if you had called
1887 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
Scott Main4b5da682010-10-21 11:49:12 -07001888 *
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001889 * @param intent The IntentSender to launch.
1890 * @param fillInIntent If non-null, this will be provided as the
1891 * intent parameter to {@link IntentSender#sendIntent}.
1892 * @param flagsMask Intent flags in the original IntentSender that you
1893 * would like to change.
1894 * @param flagsValues Desired values for any bits set in
1895 * <var>flagsMask</var>
1896 * @param extraFlags Always set to 0.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001897 * @param options Additional options for how the Activity should be started.
Elliot Waite54de7742017-01-11 15:30:35 -08001898 * See {@link android.content.Context#startActivity(Intent, Bundle)}
Dianne Hackborn7a2195c2012-03-19 17:38:00 -07001899 * Context.startActivity(Intent, Bundle)} for more details. If options
1900 * have also been supplied by the IntentSender, options given here will
1901 * override any that conflict with those given by the IntentSender.
Dianne Hackborna4972e92012-03-14 10:38:05 -07001902 *
1903 * @see #startActivity(Intent, Bundle)
1904 * @see #startIntentSender(IntentSender, Intent, int, int, int)
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001905 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06001906 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
1907 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
1908 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
Dianne Hackbornfa82f222009-09-17 15:14:12 -07001909
1910 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001911 * Broadcast the given intent to all interested BroadcastReceivers. This
1912 * call is asynchronous; it returns immediately, and you will continue
1913 * executing while the receivers are run. No results are propagated from
1914 * receivers and receivers can not abort the broadcast. If you want
1915 * to allow receivers to propagate results or abort the broadcast, you must
1916 * send an ordered broadcast using
1917 * {@link #sendOrderedBroadcast(Intent, String)}.
1918 *
1919 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1920 *
1921 * @param intent The Intent to broadcast; all receivers matching this
1922 * Intent will receive the broadcast.
1923 *
1924 * @see android.content.BroadcastReceiver
1925 * @see #registerReceiver
1926 * @see #sendBroadcast(Intent, String)
1927 * @see #sendOrderedBroadcast(Intent, String)
1928 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1929 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001930 public abstract void sendBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931
1932 /**
1933 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1934 * an optional required permission to be enforced. This
1935 * call is asynchronous; it returns immediately, and you will continue
1936 * executing while the receivers are run. No results are propagated from
1937 * receivers and receivers can not abort the broadcast. If you want
1938 * to allow receivers to propagate results or abort the broadcast, you must
1939 * send an ordered broadcast using
1940 * {@link #sendOrderedBroadcast(Intent, String)}.
1941 *
1942 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1943 *
1944 * @param intent The Intent to broadcast; all receivers matching this
1945 * Intent will receive the broadcast.
Brad Fitzpatrick26b71be2010-12-07 14:52:58 -08001946 * @param receiverPermission (optional) String naming a permission that
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001947 * a receiver must hold in order to receive your broadcast.
1948 * If null, no permission is required.
1949 *
1950 * @see android.content.BroadcastReceiver
1951 * @see #registerReceiver
1952 * @see #sendBroadcast(Intent)
1953 * @see #sendOrderedBroadcast(Intent, String)
1954 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1955 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07001956 public abstract void sendBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07001957 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001958
Fyodor Kupolovd4fd8c72015-07-13 19:19:25 -07001959
1960 /**
1961 * Broadcast the given intent to all interested BroadcastReceivers, allowing
1962 * an array of required permissions to be enforced. This call is asynchronous; it returns
1963 * immediately, and you will continue executing while the receivers are run. No results are
1964 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1965 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1966 * using {@link #sendOrderedBroadcast(Intent, String)}.
1967 *
1968 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1969 *
1970 * @param intent The Intent to broadcast; all receivers matching this
1971 * Intent will receive the broadcast.
1972 * @param receiverPermissions Array of names of permissions that a receiver must hold
1973 * in order to receive your broadcast.
1974 * If null or empty, no permissions are required.
1975 *
1976 * @see android.content.BroadcastReceiver
1977 * @see #registerReceiver
1978 * @see #sendBroadcast(Intent)
1979 * @see #sendOrderedBroadcast(Intent, String)
1980 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
1981 * @hide
1982 */
1983 public abstract void sendBroadcastMultiplePermissions(Intent intent,
1984 String[] receiverPermissions);
1985
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07001987 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Tyler Gunnf955e562018-04-26 14:43:31 -07001988 * an array of required permissions to be enforced. This call is asynchronous; it returns
1989 * immediately, and you will continue executing while the receivers are run. No results are
1990 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
1991 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
1992 * using {@link #sendOrderedBroadcast(Intent, String)}.
1993 *
1994 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
1995 *
1996 * @param intent The Intent to broadcast; all receivers matching this
1997 * Intent will receive the broadcast.
1998 * @param user The user to send the broadcast to.
1999 * @param receiverPermissions Array of names of permissions that a receiver must hold
2000 * in order to receive your broadcast.
2001 * If null or empty, no permissions are required.
2002 *
2003 * @see android.content.BroadcastReceiver
2004 * @see #registerReceiver
2005 * @see #sendBroadcast(Intent)
2006 * @see #sendOrderedBroadcast(Intent, String)
2007 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2008 * @hide
2009 */
2010 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2011 String[] receiverPermissions);
2012
2013 /**
2014 * Broadcast the given intent to all interested BroadcastReceivers, allowing
Dianne Hackborna750a632015-06-16 17:18:23 -07002015 * an optional required permission to be enforced. This
2016 * call is asynchronous; it returns immediately, and you will continue
2017 * executing while the receivers are run. No results are propagated from
2018 * receivers and receivers can not abort the broadcast. If you want
2019 * to allow receivers to propagate results or abort the broadcast, you must
2020 * send an ordered broadcast using
2021 * {@link #sendOrderedBroadcast(Intent, String)}.
2022 *
2023 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2024 *
2025 * @param intent The Intent to broadcast; all receivers matching this
2026 * Intent will receive the broadcast.
2027 * @param receiverPermission (optional) String naming a permission that
2028 * a receiver must hold in order to receive your broadcast.
2029 * If null, no permission is required.
2030 * @param options (optional) Additional sending options, generated from a
2031 * {@link android.app.BroadcastOptions}.
2032 *
2033 * @see android.content.BroadcastReceiver
2034 * @see #registerReceiver
2035 * @see #sendBroadcast(Intent)
2036 * @see #sendOrderedBroadcast(Intent, String)
2037 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2038 * @hide
2039 */
2040 @SystemApi
2041 public abstract void sendBroadcast(Intent intent,
2042 @Nullable String receiverPermission,
2043 @Nullable Bundle options);
2044
2045 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002046 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002047 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002048 * @hide
2049 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01002050 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002051 public abstract void sendBroadcast(Intent intent,
2052 String receiverPermission, int appOp);
2053
2054 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002055 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2056 * them one at a time to allow more preferred receivers to consume the
2057 * broadcast before it is delivered to less preferred receivers. This
2058 * call is asynchronous; it returns immediately, and you will continue
2059 * executing while the receivers are run.
2060 *
2061 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2062 *
2063 * @param intent The Intent to broadcast; all receivers matching this
2064 * Intent will receive the broadcast.
2065 * @param receiverPermission (optional) String naming a permissions that
2066 * a receiver must hold in order to receive your broadcast.
2067 * If null, no permission is required.
2068 *
2069 * @see android.content.BroadcastReceiver
2070 * @see #registerReceiver
2071 * @see #sendBroadcast(Intent)
2072 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2073 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002074 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
Tor Norbyed9273d62013-05-30 15:59:53 -07002075 @Nullable String receiverPermission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076
2077 /**
2078 * Version of {@link #sendBroadcast(Intent)} that allows you to
2079 * receive data back from the broadcast. This is accomplished by
2080 * supplying your own BroadcastReceiver when calling, which will be
2081 * treated as a final receiver at the end of the broadcast -- its
2082 * {@link BroadcastReceiver#onReceive} method will be called with
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002083 * the result values collected from the other receivers. The broadcast will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 * be serialized in the same way as calling
2085 * {@link #sendOrderedBroadcast(Intent, String)}.
2086 *
2087 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2088 * asynchronous; it will return before
2089 * resultReceiver.onReceive() is called.
2090 *
2091 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2092 *
2093 * @param intent The Intent to broadcast; all receivers matching this
2094 * Intent will receive the broadcast.
2095 * @param receiverPermission String naming a permissions that
2096 * a receiver must hold in order to receive your broadcast.
2097 * If null, no permission is required.
2098 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2099 * receiver of the broadcast.
2100 * @param scheduler A custom Handler with which to schedule the
2101 * resultReceiver callback; if null it will be
2102 * scheduled in the Context's main thread.
2103 * @param initialCode An initial value for the result code. Often
2104 * Activity.RESULT_OK.
2105 * @param initialData An initial value for the result data. Often
2106 * null.
2107 * @param initialExtras An initial value for the result extras. Often
2108 * null.
2109 *
2110 * @see #sendBroadcast(Intent)
2111 * @see #sendBroadcast(Intent, String)
2112 * @see #sendOrderedBroadcast(Intent, String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 * @see android.content.BroadcastReceiver
2114 * @see #registerReceiver
2115 * @see android.app.Activity#RESULT_OK
2116 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002117 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
Dianne Hackborna750a632015-06-16 17:18:23 -07002118 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002119 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2120 @Nullable Bundle initialExtras);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002121
2122 /**
Dianne Hackborna750a632015-06-16 17:18:23 -07002123 * Version of {@link #sendBroadcast(Intent)} that allows you to
2124 * receive data back from the broadcast. This is accomplished by
2125 * supplying your own BroadcastReceiver when calling, which will be
2126 * treated as a final receiver at the end of the broadcast -- its
2127 * {@link BroadcastReceiver#onReceive} method will be called with
2128 * the result values collected from the other receivers. The broadcast will
2129 * be serialized in the same way as calling
2130 * {@link #sendOrderedBroadcast(Intent, String)}.
2131 *
2132 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2133 * asynchronous; it will return before
2134 * resultReceiver.onReceive() is called.
2135 *
2136 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2137 *
2138 *
2139 * @param intent The Intent to broadcast; all receivers matching this
2140 * Intent will receive the broadcast.
2141 * @param receiverPermission String naming a permissions that
2142 * a receiver must hold in order to receive your broadcast.
2143 * If null, no permission is required.
2144 * @param options (optional) Additional sending options, generated from a
2145 * {@link android.app.BroadcastOptions}.
2146 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2147 * receiver of the broadcast.
2148 * @param scheduler A custom Handler with which to schedule the
2149 * resultReceiver callback; if null it will be
2150 * scheduled in the Context's main thread.
2151 * @param initialCode An initial value for the result code. Often
2152 * Activity.RESULT_OK.
2153 * @param initialData An initial value for the result data. Often
2154 * null.
2155 * @param initialExtras An initial value for the result extras. Often
2156 * null.
2157 * @see #sendBroadcast(Intent)
2158 * @see #sendBroadcast(Intent, String)
2159 * @see #sendOrderedBroadcast(Intent, String)
2160 * @see android.content.BroadcastReceiver
2161 * @see #registerReceiver
2162 * @see android.app.Activity#RESULT_OK
2163 * @hide
2164 */
2165 @SystemApi
2166 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2167 @Nullable String receiverPermission, @Nullable Bundle options,
2168 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2169 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2170
2171 /**
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002172 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2173 * int, String, android.os.Bundle)}, but also allows specification
Tor Norbyed9273d62013-05-30 15:59:53 -07002174 * of an associated app op as per {@link android.app.AppOpsManager}.
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002175 * @hide
2176 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01002177 @UnsupportedAppUsage
Dianne Hackbornf51f6122013-02-04 18:23:34 -08002178 public abstract void sendOrderedBroadcast(Intent intent,
2179 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2180 Handler scheduler, int initialCode, String initialData,
2181 Bundle initialExtras);
2182
2183 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002184 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2185 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002186 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002187 * @param intent The intent to broadcast
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002188 * @param user UserHandle to send the intent to.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002189 * @see #sendBroadcast(Intent)
2190 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002191 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002192 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2193 UserHandle user);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002194
2195 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002196 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2197 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002198 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002199 *
2200 * @param intent The Intent to broadcast; all receivers matching this
2201 * Intent will receive the broadcast.
2202 * @param user UserHandle to send the intent to.
2203 * @param receiverPermission (optional) String naming a permission that
2204 * a receiver must hold in order to receive your broadcast.
2205 * If null, no permission is required.
2206 *
2207 * @see #sendBroadcast(Intent, String)
2208 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002209 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002210 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2211 UserHandle user, @Nullable String receiverPermission);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002212
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002213 /**
2214 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2215 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002216 * that are not pre-installed on the system image.
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002217 *
2218 * @param intent The Intent to broadcast; all receivers matching this
2219 * Intent will receive the broadcast.
2220 * @param user UserHandle to send the intent to.
2221 * @param receiverPermission (optional) String naming a permission that
2222 * a receiver must hold in order to receive your broadcast.
2223 * If null, no permission is required.
2224 * @param options (optional) Additional sending options, generated from a
2225 * {@link android.app.BroadcastOptions}.
2226 *
2227 * @see #sendBroadcast(Intent, String, Bundle)
2228 * @hide
2229 */
2230 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002231 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Chad Brubaker52c8edc2016-07-25 14:30:26 -07002232 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2233 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
Svet Ganov16a16892015-04-16 10:32:04 -07002234
2235 /**
2236 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2237 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002238 * that are not pre-installed on the system image.
Svet Ganov16a16892015-04-16 10:32:04 -07002239 *
2240 * @param intent The Intent to broadcast; all receivers matching this
2241 * Intent will receive the broadcast.
2242 * @param user UserHandle to send the intent to.
2243 * @param receiverPermission (optional) String naming a permission that
2244 * a receiver must hold in order to receive your broadcast.
2245 * If null, no permission is required.
2246 * @param appOp The app op associated with the broadcast.
2247 *
2248 * @see #sendBroadcast(Intent, String)
2249 *
2250 * @hide
2251 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002252 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002253 @UnsupportedAppUsage
Tor Norbye788fc2b2015-07-05 16:10:42 -07002254 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2255 UserHandle user, @Nullable String receiverPermission, int appOp);
Svet Ganov16a16892015-04-16 10:32:04 -07002256
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002257 /**
Dianne Hackborn8832c182012-09-17 17:20:24 -07002258 * Version of
2259 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2260 * that allows you to specify the
2261 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002262 * that are not pre-installed on the system image.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002263 *
2264 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2265 *
2266 * @param intent The Intent to broadcast; all receivers matching this
2267 * Intent will receive the broadcast.
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002268 * @param user UserHandle to send the intent to.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002269 * @param receiverPermission String naming a permissions that
2270 * a receiver must hold in order to receive your broadcast.
2271 * If null, no permission is required.
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002272 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2273 * receiver of the broadcast.
2274 * @param scheduler A custom Handler with which to schedule the
2275 * resultReceiver callback; if null it will be
2276 * scheduled in the Context's main thread.
2277 * @param initialCode An initial value for the result code. Often
2278 * Activity.RESULT_OK.
2279 * @param initialData An initial value for the result data. Often
2280 * null.
2281 * @param initialExtras An initial value for the result extras. Often
2282 * null.
2283 *
2284 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2285 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002286 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002287 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2288 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002289 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2290 @Nullable Bundle initialExtras);
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002291
2292 /**
Amith Yamasani3cf75722014-05-16 12:37:29 -07002293 * Similar to above but takes an appOp as well, to enforce restrictions.
2294 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2295 * BroadcastReceiver, Handler, int, String, Bundle)
2296 * @hide
2297 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002298 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002299 @UnsupportedAppUsage
Amith Yamasani3cf75722014-05-16 12:37:29 -07002300 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2301 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2302 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2303 @Nullable Bundle initialExtras);
2304
2305 /**
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002306 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2307 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2308 * BroadcastReceiver, Handler, int, String, Bundle)
2309 * @hide
2310 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002311 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002312 @UnsupportedAppUsage
Dianne Hackbornfd854ee2015-07-13 18:00:37 -07002313 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2314 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2315 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2316 @Nullable String initialData, @Nullable Bundle initialExtras);
2317
2318 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002319 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 * Intent you are sending stays around after the broadcast is complete,
2321 * so that others can quickly retrieve that data through the return
2322 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2323 * all other ways, this behaves the same as
2324 * {@link #sendBroadcast(Intent)}.
2325 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002326 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2327 * can access them), no protection (anyone can modify them), and many other problems.
2328 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2329 * has changed, with another mechanism for apps to retrieve the current value whenever
2330 * desired.
2331 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002332 * @param intent The Intent to broadcast; all receivers matching this
2333 * Intent will receive the broadcast, and the Intent will be held to
2334 * be re-broadcast to future receivers.
2335 *
2336 * @see #sendBroadcast(Intent)
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002337 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002338 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002339 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002340 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002341 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
Scott Main4b5da682010-10-21 11:49:12 -07002342
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002343 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002344 * <p>Version of {@link #sendStickyBroadcast} that allows you to
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002345 * receive data back from the broadcast. This is accomplished by
2346 * supplying your own BroadcastReceiver when calling, which will be
2347 * treated as a final receiver at the end of the broadcast -- its
2348 * {@link BroadcastReceiver#onReceive} method will be called with
2349 * the result values collected from the other receivers. The broadcast will
2350 * be serialized in the same way as calling
2351 * {@link #sendOrderedBroadcast(Intent, String)}.
2352 *
2353 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2354 * asynchronous; it will return before
2355 * resultReceiver.onReceive() is called. Note that the sticky data
2356 * stored is only the data you initially supply to the broadcast, not
2357 * the result of any changes made by the receivers.
2358 *
2359 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2360 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002361 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2362 * can access them), no protection (anyone can modify them), and many other problems.
2363 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2364 * has changed, with another mechanism for apps to retrieve the current value whenever
2365 * desired.
2366 *
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002367 * @param intent The Intent to broadcast; all receivers matching this
2368 * Intent will receive the broadcast.
2369 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2370 * receiver of the broadcast.
2371 * @param scheduler A custom Handler with which to schedule the
2372 * resultReceiver callback; if null it will be
2373 * scheduled in the Context's main thread.
2374 * @param initialCode An initial value for the result code. Often
2375 * Activity.RESULT_OK.
2376 * @param initialData An initial value for the result data. Often
2377 * null.
2378 * @param initialExtras An initial value for the result extras. Often
2379 * null.
2380 *
2381 * @see #sendBroadcast(Intent)
2382 * @see #sendBroadcast(Intent, String)
2383 * @see #sendOrderedBroadcast(Intent, String)
2384 * @see #sendStickyBroadcast(Intent)
2385 * @see android.content.BroadcastReceiver
2386 * @see #registerReceiver
2387 * @see android.app.Activity#RESULT_OK
2388 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002389 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002390 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002391 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002392 BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002393 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2394 @Nullable Bundle initialExtras);
Dianne Hackbornefa199f2009-09-19 12:03:15 -07002395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002397 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002398 * so that it is as if the sticky broadcast had never happened.
2399 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002400 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2401 * can access them), no protection (anyone can modify them), and many other problems.
2402 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2403 * has changed, with another mechanism for apps to retrieve the current value whenever
2404 * desired.
2405 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002406 * @param intent The Intent that was previously broadcast.
2407 *
2408 * @see #sendStickyBroadcast
2409 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002410 @Deprecated
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06002411 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002412 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002413
2414 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002415 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002416 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002417 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002418 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002419 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2420 * can access them), no protection (anyone can modify them), and many other problems.
2421 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2422 * has changed, with another mechanism for apps to retrieve the current value whenever
2423 * desired.
2424 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002425 * @param intent The Intent to broadcast; all receivers matching this
2426 * Intent will receive the broadcast, and the Intent will be held to
2427 * be re-broadcast to future receivers.
2428 * @param user UserHandle to send the intent to.
2429 *
2430 * @see #sendBroadcast(Intent)
2431 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002432 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002433 @RequiresPermission(allOf = {
2434 android.Manifest.permission.INTERACT_ACROSS_USERS,
2435 android.Manifest.permission.BROADCAST_STICKY
2436 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002437 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2438 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002439
2440 /**
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002441 * @hide
2442 * This is just here for sending CONNECTIVITY_ACTION.
2443 */
2444 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002445 @RequiresPermission(allOf = {
2446 android.Manifest.permission.INTERACT_ACROSS_USERS,
2447 android.Manifest.permission.BROADCAST_STICKY
2448 })
Dianne Hackborne0e413e2015-12-09 17:22:26 -08002449 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2450 UserHandle user, Bundle options);
2451
2452 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002453 * <p>Version of
Dianne Hackborn8832c182012-09-17 17:20:24 -07002454 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2455 * that allows you to specify the
2456 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002457 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002458 *
2459 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2460 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002461 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2462 * can access them), no protection (anyone can modify them), and many other problems.
2463 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2464 * has changed, with another mechanism for apps to retrieve the current value whenever
2465 * desired.
2466 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002467 * @param intent The Intent to broadcast; all receivers matching this
2468 * Intent will receive the broadcast.
2469 * @param user UserHandle to send the intent to.
2470 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2471 * receiver of the broadcast.
2472 * @param scheduler A custom Handler with which to schedule the
2473 * resultReceiver callback; if null it will be
2474 * scheduled in the Context's main thread.
2475 * @param initialCode An initial value for the result code. Often
2476 * Activity.RESULT_OK.
2477 * @param initialData An initial value for the result data. Often
2478 * null.
2479 * @param initialExtras An initial value for the result extras. Often
2480 * null.
2481 *
2482 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2483 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002484 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002485 @RequiresPermission(allOf = {
2486 android.Manifest.permission.INTERACT_ACROSS_USERS,
2487 android.Manifest.permission.BROADCAST_STICKY
2488 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002489 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002490 UserHandle user, BroadcastReceiver resultReceiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002491 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2492 @Nullable Bundle initialExtras);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002493
2494 /**
Dianne Hackborn2c353002014-08-29 15:13:30 -07002495 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
Dianne Hackborn8832c182012-09-17 17:20:24 -07002496 * user the broadcast will be sent to. This is not available to applications
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002497 * that are not pre-installed on the system image.
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002498 *
2499 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2500 * permission in order to use this API. If you do not hold that
2501 * permission, {@link SecurityException} will be thrown.
2502 *
Dianne Hackborn2c353002014-08-29 15:13:30 -07002503 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2504 * can access them), no protection (anyone can modify them), and many other problems.
2505 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2506 * has changed, with another mechanism for apps to retrieve the current value whenever
2507 * desired.
2508 *
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002509 * @param intent The Intent that was previously broadcast.
2510 * @param user UserHandle to remove the sticky broadcast from.
2511 *
2512 * @see #sendStickyBroadcastAsUser
2513 */
Dianne Hackborn2c353002014-08-29 15:13:30 -07002514 @Deprecated
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002515 @RequiresPermission(allOf = {
2516 android.Manifest.permission.INTERACT_ACROSS_USERS,
2517 android.Manifest.permission.BROADCAST_STICKY
2518 })
Tor Norbye788fc2b2015-07-05 16:10:42 -07002519 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
2520 UserHandle user);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002521
2522 /**
Chris Tatea34df8a22009-04-02 23:15:58 -07002523 * Register a BroadcastReceiver to be run in the main activity thread. The
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002524 * <var>receiver</var> will be called with any broadcast Intent that
2525 * matches <var>filter</var>, in the main application thread.
2526 *
2527 * <p>The system may broadcast Intents that are "sticky" -- these stay
Kweku Adams86f39a42016-11-16 12:50:38 -08002528 * around after the broadcast has finished, to be sent to any later
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002529 * registrations. If your IntentFilter matches one of these sticky
2530 * Intents, that Intent will be returned by this function
2531 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
2532 * been broadcast.
2533 *
2534 * <p>There may be multiple sticky Intents that match <var>filter</var>,
2535 * in which case each of these will be sent to <var>receiver</var>. In
2536 * this case, only one of these can be returned directly by the function;
2537 * which of these that is returned is arbitrarily decided by the system.
2538 *
2539 * <p>If you know the Intent your are registering for is sticky, you can
2540 * supply null for your <var>receiver</var>. In this case, no receiver is
2541 * registered -- the function simply returns the sticky Intent that
2542 * matches <var>filter</var>. In the case of multiple matches, the same
2543 * rules as described above apply.
2544 *
2545 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2546 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002547 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2548 * registered with this method will correctly respect the
2549 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2550 * Prior to that, it would be ignored and delivered to all matching registered
2551 * receivers. Be careful if using this for security.</p>
2552 *
Chris Tatea34df8a22009-04-02 23:15:58 -07002553 * <p class="note">Note: this method <em>cannot be called from a
2554 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
2555 * that is declared in an application's manifest. It is okay, however, to call
2556 * this method from another BroadcastReceiver that has itself been registered
2557 * at run time with {@link #registerReceiver}, since the lifetime of such a
2558 * registered BroadcastReceiver is tied to the object that registered it.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002559 *
2560 * @param receiver The BroadcastReceiver to handle the broadcast.
2561 * @param filter Selects the Intent broadcasts to be received.
2562 *
2563 * @return The first sticky intent found that matches <var>filter</var>,
2564 * or null if there are none.
2565 *
2566 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2567 * @see #sendBroadcast
2568 * @see #unregisterReceiver
2569 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002570 @Nullable
2571 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002572 IntentFilter filter);
2573
2574 /**
Chad Brubaker816c83b2017-03-02 10:27:59 -08002575 * Register to receive intent broadcasts, with the receiver optionally being
2576 * exposed to Instant Apps. See
2577 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2578 * information. By default Instant Apps cannot interact with receivers in other
2579 * applications, this allows you to expose a receiver that Instant Apps can
2580 * interact with.
2581 *
2582 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2583 *
2584 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2585 * registered with this method will correctly respect the
2586 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2587 * Prior to that, it would be ignored and delivered to all matching registered
2588 * receivers. Be careful if using this for security.</p>
2589 *
2590 * @param receiver The BroadcastReceiver to handle the broadcast.
2591 * @param filter Selects the Intent broadcasts to be received.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002592 * @param flags Additional options for the receiver. May be 0 or
2593 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002594 *
2595 * @return The first sticky intent found that matches <var>filter</var>,
2596 * or null if there are none.
2597 *
2598 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2599 * @see #sendBroadcast
2600 * @see #unregisterReceiver
2601 */
2602 @Nullable
2603 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
2604 IntentFilter filter,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002605 @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002606
2607 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002608 * Register to receive intent broadcasts, to run in the context of
2609 * <var>scheduler</var>. See
2610 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
2611 * information. This allows you to enforce permissions on who can
2612 * broadcast intents to your receiver, or have the receiver run in
2613 * a different thread than the main application thread.
2614 *
2615 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2616 *
Dianne Hackborn6c418d52011-06-29 14:05:33 -07002617 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2618 * registered with this method will correctly respect the
2619 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2620 * Prior to that, it would be ignored and delivered to all matching registered
2621 * receivers. Be careful if using this for security.</p>
2622 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 * @param receiver The BroadcastReceiver to handle the broadcast.
2624 * @param filter Selects the Intent broadcasts to be received.
2625 * @param broadcastPermission String naming a permissions that a
2626 * broadcaster must hold in order to send an Intent to you. If null,
2627 * no permission is required.
2628 * @param scheduler Handler identifying the thread that will receive
2629 * the Intent. If null, the main thread of the process will be used.
2630 *
2631 * @return The first sticky intent found that matches <var>filter</var>,
2632 * or null if there are none.
2633 *
2634 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
2635 * @see #sendBroadcast
2636 * @see #unregisterReceiver
2637 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002638 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002639 public abstract Intent registerReceiver(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002640 IntentFilter filter, @Nullable String broadcastPermission,
2641 @Nullable Handler scheduler);
Dianne Hackborn20e80982012-08-31 19:00:44 -07002642
2643 /**
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002644 * Register to receive intent broadcasts, to run in the context of
2645 * <var>scheduler</var>. See
2646 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
Chad Brubaker816c83b2017-03-02 10:27:59 -08002647 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
2648 * for more information.
2649 *
2650 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2651 *
2652 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
2653 * registered with this method will correctly respect the
2654 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
2655 * Prior to that, it would be ignored and delivered to all matching registered
2656 * receivers. Be careful if using this for security.</p>
2657 *
2658 * @param receiver The BroadcastReceiver to handle the broadcast.
2659 * @param filter Selects the Intent broadcasts to be received.
2660 * @param broadcastPermission String naming a permissions that a
2661 * broadcaster must hold in order to send an Intent to you. If null,
2662 * no permission is required.
2663 * @param scheduler Handler identifying the thread that will receive
2664 * the Intent. If null, the main thread of the process will be used.
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002665 * @param flags Additional options for the receiver. May be 0 or
2666 * {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}.
Chad Brubaker816c83b2017-03-02 10:27:59 -08002667 *
2668 * @return The first sticky intent found that matches <var>filter</var>,
2669 * or null if there are none.
2670 *
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002671 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
Chad Brubaker816c83b2017-03-02 10:27:59 -08002672 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2673 * @see #sendBroadcast
2674 * @see #unregisterReceiver
2675 */
2676 @Nullable
2677 public abstract Intent registerReceiver(BroadcastReceiver receiver,
2678 IntentFilter filter, @Nullable String broadcastPermission,
Chad Brubaker6d6015f2017-04-18 11:25:16 -07002679 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
Chad Brubaker816c83b2017-03-02 10:27:59 -08002680
2681 /**
Dianne Hackborn20e80982012-08-31 19:00:44 -07002682 * @hide
2683 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
2684 * but for a specific user. This receiver will receiver broadcasts that
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002685 * are sent to the requested user.
Dianne Hackborn20e80982012-08-31 19:00:44 -07002686 *
2687 * @param receiver The BroadcastReceiver to handle the broadcast.
2688 * @param user UserHandle to send the intent to.
2689 * @param filter Selects the Intent broadcasts to be received.
2690 * @param broadcastPermission String naming a permissions that a
2691 * broadcaster must hold in order to send an Intent to you. If null,
2692 * no permission is required.
2693 * @param scheduler Handler identifying the thread that will receive
2694 * the Intent. If null, the main thread of the process will be used.
2695 *
2696 * @return The first sticky intent found that matches <var>filter</var>,
2697 * or null if there are none.
2698 *
Jeff Brown6e539312015-02-24 18:53:21 -08002699 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
Dianne Hackborn20e80982012-08-31 19:00:44 -07002700 * @see #sendBroadcast
2701 * @see #unregisterReceiver
2702 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002703 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002704 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002705 @UnsupportedAppUsage
Dianne Hackborn20e80982012-08-31 19:00:44 -07002706 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
Tor Norbyed9273d62013-05-30 15:59:53 -07002707 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
2708 @Nullable Handler scheduler);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709
2710 /**
2711 * Unregister a previously registered BroadcastReceiver. <em>All</em>
2712 * filters that have been registered for this BroadcastReceiver will be
2713 * removed.
2714 *
2715 * @param receiver The BroadcastReceiver to unregister.
2716 *
2717 * @see #registerReceiver
2718 */
2719 public abstract void unregisterReceiver(BroadcastReceiver receiver);
2720
2721 /**
2722 * Request that a given application service be started. The Intent
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002723 * should either contain the complete class name of a specific service
2724 * implementation to start, or a specific package name to target. If the
2725 * Intent is less specified, it logs a warning about this. In this case any of the
2726 * multiple matching services may be used. If this service
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 * is not already running, it will be instantiated and started (creating a
2728 * process for it if needed); if it is running then it remains running.
2729 *
2730 * <p>Every call to this method will result in a corresponding call to
Scott Main4b5da682010-10-21 11:49:12 -07002731 * the target service's {@link android.app.Service#onStartCommand} method,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002732 * with the <var>intent</var> given here. This provides a convenient way
2733 * to submit jobs to a service without having to bind and call on to its
2734 * interface.
2735 *
2736 * <p>Using startService() overrides the default service lifetime that is
2737 * managed by {@link #bindService}: it requires the service to remain
2738 * running until {@link #stopService} is called, regardless of whether
2739 * any clients are connected to it. Note that calls to startService()
Hans Boehmfb9f6ac2016-05-05 13:09:28 -07002740 * do not nest: no matter how many times you call startService(),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 * a single call to {@link #stopService} will stop it.
2742 *
2743 * <p>The system attempts to keep running services around as much as
2744 * possible. The only time they should be stopped is if the current
2745 * foreground application is using so many resources that the service needs
2746 * to be killed. If any errors happen in the service's process, it will
2747 * automatically be restarted.
2748 *
2749 * <p>This function will throw {@link SecurityException} if you do not
2750 * have permission to start the given service.
2751 *
Chris Craik1e353522016-04-18 10:20:50 -07002752 * <p class="note"><strong>Note:</strong> Each call to startService()
2753 * results in significant work done by the system to manage service
2754 * lifecycle surrounding the processing of the intent, which can take
2755 * multiple milliseconds of CPU time. Due to this cost, startService()
2756 * should not be used for frequent intent delivery to a service, and only
2757 * for scheduling significant work. Use {@link #bindService bound services}
2758 * for high frequency calls.
2759 * </p>
2760 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002761 * @param service Identifies the service to be started. The Intent must be
2762 * fully explicit (supplying a component name). Additional values
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002763 * may be included in the Intent extras to supply arguments along with
2764 * this specific start call.
2765 *
2766 * @return If the service is being started or is already running, the
2767 * {@link ComponentName} of the actual service that was started is
2768 * returned; else if the service does not exist null is returned.
2769 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002770 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002771 * or the service can not be found.
2772 * @throws IllegalStateException If the application is in a state where the service
2773 * 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 -08002774 *
2775 * @see #stopService
2776 * @see #bindService
2777 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002778 @Nullable
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002779 public abstract ComponentName startService(Intent service);
2780
2781 /**
Christopher Tate08992ac2017-03-21 11:37:06 -07002782 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
Neil Fullerfe6ec562017-03-16 18:29:36 +00002783 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
2784 * startForeground(int, android.app.Notification)} once it begins running. The service is given
Christopher Tate08992ac2017-03-21 11:37:06 -07002785 * an amount of time comparable to the ANR interval to do this, otherwise the system
2786 * will automatically stop the service and declare the app ANR.
2787 *
2788 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
2789 * at any time, regardless of whether the app hosting the service is in a foreground
2790 * state.
2791 *
2792 * @param service Identifies the service to be started. The Intent must be
2793 * fully explicit (supplying a component name). Additional values
2794 * may be included in the Intent extras to supply arguments along with
2795 * this specific start call.
2796 *
2797 * @return If the service is being started or is already running, the
2798 * {@link ComponentName} of the actual service that was started is
2799 * returned; else if the service does not exist null is returned.
2800 *
2801 * @throws SecurityException If the caller does not have permission to access the service
2802 * or the service can not be found.
2803 *
2804 * @see #stopService
Neil Fullerfe6ec562017-03-16 18:29:36 +00002805 * @see android.app.Service#startForeground(int, android.app.Notification)
Christopher Tate08992ac2017-03-21 11:37:06 -07002806 */
2807 @Nullable
2808 public abstract ComponentName startForegroundService(Intent service);
2809
2810 /**
2811 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
2812 */
2813 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002814 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Christopher Tate08992ac2017-03-21 11:37:06 -07002815 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
2816
2817 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 * Request that a given application service be stopped. If the service is
2819 * not running, nothing happens. Otherwise it is stopped. Note that calls
2820 * to startService() are not counted -- this stops the service no matter
2821 * how many times it was started.
2822 *
2823 * <p>Note that if a stopped service still has {@link ServiceConnection}
2824 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
2825 * not be destroyed until all of these bindings are removed. See
2826 * the {@link android.app.Service} documentation for more details on a
2827 * service's lifecycle.
2828 *
2829 * <p>This function will throw {@link SecurityException} if you do not
2830 * have permission to stop the given service.
2831 *
Dianne Hackborn221ea892013-08-04 16:50:16 -07002832 * @param service Description of the service to be stopped. The Intent must be either
2833 * fully explicit (supplying a component name) or specify a specific package
2834 * name it is targetted to.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002835 *
2836 * @return If there is a service matching the given Intent that is already
John Spurlock6098c5d2013-06-17 10:32:46 -04002837 * 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 -08002838 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002839 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002840 * or the service can not be found.
2841 * @throws IllegalStateException If the application is in a state where the service
2842 * 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 -08002843 *
2844 * @see #startService
2845 */
2846 public abstract boolean stopService(Intent service);
2847
2848 /**
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002849 * @hide like {@link #startService(Intent)} but for a specific user.
2850 */
Christopher Tate42a386b2016-11-07 12:21:21 -08002851 @Nullable
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002852 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002853 @UnsupportedAppUsage
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002854 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
2855
2856 /**
2857 * @hide like {@link #stopService(Intent)} but for a specific user.
2858 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002859 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002860 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
RoboErik01fe6612014-02-13 14:19:04 -08002861
Dianne Hackborn7767eac2012-08-23 18:25:40 -07002862 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002863 * Connect to an application service, creating it if needed. This defines
2864 * a dependency between your application and the service. The given
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002865 * <var>conn</var> will receive the service object when it is created and be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002866 * told if it dies and restarts. The service will be considered required
2867 * by the system only for as long as the calling context exists. For
2868 * example, if this Context is an Activity that is stopped, the service will
2869 * not be required to continue running until the Activity is resumed.
2870 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002871 * <p>If the service does not support binding, it may return {@code null} from
2872 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
2873 * the ServiceConnection's
2874 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
2875 * will be invoked instead of
2876 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
2877 *
2878 * <p>This method will throw {@link SecurityException} if the calling app does not
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 * have permission to bind to the given service.
2880 *
Christopher Tate5d73b6d2017-10-06 16:15:34 -07002881 * <p class="note">Note: this method <em>cannot be called from a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002882 * {@link BroadcastReceiver} component</em>. A pattern you can use to
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002883 * communicate from a BroadcastReceiver to a Service is to call
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002884 * {@link #startService} with the arguments containing the command to be
2885 * sent, with the service calling its
2886 * {@link android.app.Service#stopSelf(int)} method when done executing
2887 * that command. See the API demo App/Service/Service Start Arguments
2888 * Controller for an illustration of this. It is okay, however, to use
Ken Wakasaf76a50c2012-03-09 19:56:35 +09002889 * this method from a BroadcastReceiver that has been registered with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002890 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
2891 * is tied to another object (the one that registered it).</p>
2892 *
Mark Lu94ebbe02016-12-13 16:29:51 -08002893 * @param service Identifies the service to connect to. The Intent must
2894 * specify an explicit component name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002895 * @param conn Receives information as the service is started and stopped.
Christopher Tate79b33172012-06-18 14:54:21 -07002896 * This must be a valid ServiceConnection object; it must not be null.
Scott Main4b5da682010-10-21 11:49:12 -07002897 * @param flags Operation options for the binding. May be 0,
Dianne Hackbornc68c9132011-07-29 01:25:18 -07002898 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
2899 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
2900 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, or
2901 * {@link #BIND_WAIVE_PRIORITY}.
Kevin Hufnagle34acbc9b2017-06-29 15:58:48 -07002902 * @return {@code true} if the system is in the process of bringing up a
2903 * service that your client has permission to bind to; {@code false}
2904 * if the system couldn't find the service or if your client doesn't
2905 * have permission to bind to it. If this value is {@code true}, you
2906 * should later call {@link #unbindService} to release the
2907 * connection.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002908 *
Christopher Tate08992ac2017-03-21 11:37:06 -07002909 * @throws SecurityException If the caller does not have permission to access the service
Dianne Hackborn85e35642017-01-12 15:10:57 -08002910 * or the service can not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002911 *
2912 * @see #unbindService
2913 * @see #startService
2914 * @see #BIND_AUTO_CREATE
Scott Main4b5da682010-10-21 11:49:12 -07002915 * @see #BIND_DEBUG_UNBIND
2916 * @see #BIND_NOT_FOREGROUND
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002917 */
Tor Norbye788fc2b2015-07-05 16:10:42 -07002918 public abstract boolean bindService(@RequiresPermission Intent service,
2919 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920
2921 /**
Dianne Hackborn7d19e022012-08-07 19:12:33 -07002922 * Same as {@link #bindService(Intent, ServiceConnection, int)}, but with an explicit userHandle
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002923 * argument for use by system server and other multi-user aware code.
2924 * @hide
2925 */
Amith Yamasanic85029f2014-09-11 16:47:17 -07002926 @SystemApi
Jeff Brown6e539312015-02-24 18:53:21 -08002927 @SuppressWarnings("unused")
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002928 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Tor Norbye788fc2b2015-07-05 16:10:42 -07002929 public boolean bindServiceAsUser(@RequiresPermission Intent service, ServiceConnection conn,
Jeff Brown6e539312015-02-24 18:53:21 -08002930 int flags, UserHandle user) {
Amith Yamasani37ce3a82012-02-06 12:04:42 -08002931 throw new RuntimeException("Not implemented. Must override in a subclass.");
2932 }
2933
2934 /**
Adrian Roos691546e2016-02-09 10:13:41 -08002935 * Same as {@link #bindService(Intent, ServiceConnection, int, UserHandle)}, but with an
2936 * explicit non-null Handler to run the ServiceConnection callbacks on.
2937 *
2938 * @hide
2939 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06002940 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
Mathew Inwood1c77a112018-08-14 14:06:26 +01002941 @UnsupportedAppUsage
Adrian Roos691546e2016-02-09 10:13:41 -08002942 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
2943 Handler handler, UserHandle user) {
2944 throw new RuntimeException("Not implemented. Must override in a subclass.");
2945 }
2946
2947 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 * Disconnect from an application service. You will no longer receive
2949 * calls as the service is restarted, and the service is now allowed to
2950 * stop at any time.
2951 *
2952 * @param conn The connection interface previously supplied to
Christopher Tate79b33172012-06-18 14:54:21 -07002953 * bindService(). This parameter must not be null.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002954 *
2955 * @see #bindService
2956 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002957 public abstract void unbindService(@NonNull ServiceConnection conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958
2959 /**
2960 * Start executing an {@link android.app.Instrumentation} class. The given
2961 * Instrumentation component will be run by killing its target application
2962 * (if currently running), starting the target process, instantiating the
2963 * instrumentation component, and then letting it drive the application.
2964 *
2965 * <p>This function is not synchronous -- it returns as soon as the
2966 * instrumentation has started and while it is running.
2967 *
2968 * <p>Instrumentation is normally only allowed to run against a package
2969 * that is either unsigned or signed with a signature that the
2970 * the instrumentation package is also signed with (ensuring the target
2971 * trusts the instrumentation).
2972 *
2973 * @param className Name of the Instrumentation component to be run.
2974 * @param profileFile Optional path to write profiling data as the
2975 * instrumentation runs, or null for no profiling.
2976 * @param arguments Additional optional arguments to pass to the
2977 * instrumentation, or null.
2978 *
John Spurlock6098c5d2013-06-17 10:32:46 -04002979 * @return {@code true} if the instrumentation was successfully started,
2980 * else {@code false} if it could not be found.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002981 */
Tor Norbyed9273d62013-05-30 15:59:53 -07002982 public abstract boolean startInstrumentation(@NonNull ComponentName className,
2983 @Nullable String profileFile, @Nullable Bundle arguments);
2984
2985 /** @hide */
Jeff Sharkey5db9a912017-12-08 17:32:32 -07002986 @StringDef(suffix = { "_SERVICE" }, value = {
Tor Norbyed9273d62013-05-30 15:59:53 -07002987 POWER_SERVICE,
2988 WINDOW_SERVICE,
2989 LAYOUT_INFLATER_SERVICE,
2990 ACCOUNT_SERVICE,
2991 ACTIVITY_SERVICE,
2992 ALARM_SERVICE,
2993 NOTIFICATION_SERVICE,
2994 ACCESSIBILITY_SERVICE,
2995 CAPTIONING_SERVICE,
2996 KEYGUARD_SERVICE,
2997 LOCATION_SERVICE,
2998 //@hide: COUNTRY_DETECTOR,
2999 SEARCH_SERVICE,
3000 SENSOR_SERVICE,
3001 STORAGE_SERVICE,
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003002 STORAGE_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003003 WALLPAPER_SERVICE,
Neil Fullerfe6ec562017-03-16 18:29:36 +00003004 TIME_ZONE_RULES_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003005 VIBRATOR_SERVICE,
3006 //@hide: STATUS_BAR_SERVICE,
3007 CONNECTIVITY_SERVICE,
Nathan Harold330e1082017-01-12 18:38:57 -08003008 IPSEC_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003009 //@hide: UPDATE_LOCK_SERVICE,
3010 //@hide: NETWORKMANAGEMENT_SERVICE,
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003011 NETWORK_STATS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003012 //@hide: NETWORK_POLICY_SERVICE,
3013 WIFI_SERVICE,
Etan Cohen04133272016-10-26 11:22:06 -07003014 WIFI_AWARE_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003015 WIFI_P2P_SERVICE,
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003016 WIFI_SCANNING_SERVICE,
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003017 //@hide: LOWPAN_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003018 //@hide: WIFI_RTT_SERVICE,
Lorenzo Colittibd8a3742014-05-22 11:51:27 -07003019 //@hide: ETHERNET_SERVICE,
Etan Cohen46efb482017-12-07 13:50:57 -08003020 WIFI_RTT_RANGING_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003021 NSD_SERVICE,
3022 AUDIO_SERVICE,
Jim Millerce7eb6d2015-04-03 19:29:13 -07003023 FINGERPRINT_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003024 MEDIA_ROUTER_SERVICE,
3025 TELEPHONY_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003026 TELEPHONY_SUBSCRIPTION_SERVICE,
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003027 CARRIER_CONFIG_SERVICE,
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003028 TELECOM_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003029 CLIPBOARD_SERVICE,
3030 INPUT_METHOD_SERVICE,
3031 TEXT_SERVICES_MANAGER_SERVICE,
Abodunrinwa Toki3de110b2017-05-04 16:29:04 +01003032 TEXT_CLASSIFICATION_SERVICE,
Svetoslav976e8bd2014-07-16 15:12:03 -07003033 APPWIDGET_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003034 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003035 //@hide: BACKUP_SERVICE,
3036 DROPBOX_SERVICE,
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003037 //@hide: DEVICE_IDLE_CONTROLLER,
Tor Norbyed9273d62013-05-30 15:59:53 -07003038 DEVICE_POLICY_SERVICE,
3039 UI_MODE_SERVICE,
3040 DOWNLOAD_SERVICE,
3041 NFC_SERVICE,
3042 BLUETOOTH_SERVICE,
3043 //@hide: SIP_SERVICE,
3044 USB_SERVICE,
Amith Yamasani4f582632014-02-19 14:31:52 -08003045 LAUNCHER_APPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003046 //@hide: SERIAL_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003047 //@hide: HDMI_CONTROL_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003048 INPUT_SERVICE,
3049 DISPLAY_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003050 USER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003051 RESTRICTIONS_SERVICE,
3052 APP_OPS_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003053 CAMERA_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003054 PRINT_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003055 CONSUMER_IR_SERVICE,
3056 //@hide: TRUST_SERVICE,
3057 TV_INPUT_SERVICE,
3058 //@hide: NETWORK_SCORE_SERVICE,
3059 USAGE_STATS_SERVICE,
RoboErik01fe6612014-02-13 14:19:04 -08003060 MEDIA_SESSION_SERVICE,
Todd Poynore35872d2013-12-10 11:57:21 -08003061 BATTERY_SERVICE,
Christopher Tate7060b042014-06-09 19:50:00 -07003062 JOB_SCHEDULER_SERVICE,
Tor Norbyebf44ce22015-02-12 11:47:32 -08003063 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
Andrew Scull3b8b46f2017-02-13 18:12:15 +00003064 //@hide: OEM_LOCK_SERVICE,
Michael Wright446e0192014-12-22 09:38:43 -08003065 MEDIA_PROJECTION_SERVICE,
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08003066 MIDI_SERVICE,
Eric Laurent2035ac82015-03-05 15:18:44 -08003067 RADIO_SERVICE,
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003068 HARDWARE_PROPERTIES_SERVICE,
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003069 //@hide: SOUND_TRIGGER_SERVICE,
Makoto Onuki6f7362d92016-03-04 13:39:41 -08003070 SHORTCUT_SERVICE,
Peng Xu9ff7d222016-02-11 13:02:05 -08003071 //@hide: CONTEXTHUB_SERVICE,
Joe Onorato1754d742016-11-21 17:51:35 -08003072 SYSTEM_HEALTH_SERVICE,
Tor Norbye8246c072017-07-07 10:21:09 -07003073 //@hide: INCIDENT_SERVICE,
Bookatz94726412017-08-31 09:26:15 -07003074 //@hide: STATS_COMPANION_SERVICE,
Tony Mak9240c7f2017-12-29 11:02:02 +00003075 COMPANION_DEVICE_SERVICE,
Tao Bao07342dc2017-01-24 15:08:21 -08003076 CROSS_PROFILE_APPS_SERVICE,
3077 //@hide: SYSTEM_UPDATE_SERVICE,
Neil Fullerb5579072018-05-30 14:35:24 +01003078 //@hide: TIME_DETECTOR_SERVICE,
Neil Fullercccc48d2018-06-19 12:53:47 +01003079 //@hide: TIME_ZONE_DETECTOR_SERVICE,
Tor Norbyed9273d62013-05-30 15:59:53 -07003080 })
3081 @Retention(RetentionPolicy.SOURCE)
3082 public @interface ServiceName {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003083
3084 /**
3085 * Return the handle to a system-level service by name. The class of the
3086 * returned object varies by the requested name. Currently available names
3087 * are:
Scott Main4b5da682010-10-21 11:49:12 -07003088 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003089 * <dl>
3090 * <dt> {@link #WINDOW_SERVICE} ("window")
3091 * <dd> The top-level window manager in which you can place custom
3092 * windows. The returned object is a {@link android.view.WindowManager}.
3093 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3094 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3095 * in this context.
3096 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3097 * <dd> A {@link android.app.ActivityManager} for interacting with the
3098 * global activity state of the system.
3099 * <dt> {@link #POWER_SERVICE} ("power")
3100 * <dd> A {@link android.os.PowerManager} for controlling power
3101 * management.
3102 * <dt> {@link #ALARM_SERVICE} ("alarm")
3103 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3104 * time of your choosing.
3105 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3106 * <dd> A {@link android.app.NotificationManager} for informing the user
3107 * of background events.
3108 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3109 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3110 * <dt> {@link #LOCATION_SERVICE} ("location")
3111 * <dd> A {@link android.location.LocationManager} for controlling location
3112 * (e.g., GPS) updates.
3113 * <dt> {@link #SEARCH_SERVICE} ("search")
3114 * <dd> A {@link android.app.SearchManager} for handling search.
3115 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3116 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator
3117 * hardware.
3118 * <dt> {@link #CONNECTIVITY_SERVICE} ("connection")
3119 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3120 * handling management of network connections.
Nathan Haroldd999d222017-09-11 19:53:33 -07003121 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3122 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3123 * sockets and networks.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003124 * <dt> {@link #WIFI_SERVICE} ("wifi")
Paul Stewart0e164b12016-08-08 10:20:13 -07003125 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3126 * connectivity. On releases before NYC, it should only be obtained from an application
3127 * context, and not from any other derived context to avoid memory leaks within the calling
3128 * process.
Etan Cohen6a4b3232017-01-09 21:47:32 -08003129 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3130 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
3131 * Wi-Fi Aware discovery and connectivity.
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003132 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
3133 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
3134 * Wi-Fi Direct connectivity.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
3136 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
3137 * for management of input methods.
Tobias Haamel53332882010-02-18 16:15:43 -08003138 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
3139 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
Steve Howard7083c422010-07-28 16:01:23 -07003140 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
Steve Howardd58429f2010-09-27 16:32:39 -07003141 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
Todd Poynore35872d2013-12-10 11:57:21 -08003142 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
Todd Poynor99f7e122014-04-15 16:03:42 -07003143 * <dd> A {@link android.os.BatteryManager} for managing battery state
Christopher Tate7060b042014-06-09 19:50:00 -07003144 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
3145 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003146 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
3147 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
3148 * usage statistics.
Polina Bondarenko8333c732016-03-09 18:08:42 +01003149 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003150 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003151 * </dl>
Scott Main4b5da682010-10-21 11:49:12 -07003152 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003153 * <p>Note: System services obtained via this API may be closely associated with
3154 * the Context in which they are obtained from. In general, do not share the
3155 * service objects between various different contexts (Activities, Applications,
3156 * Services, Providers, etc.)
3157 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003158 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3159 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
3160 * {@link #FINGERPRINT_SERVICE}, {@link #SHORTCUT_SERVICE}, {@link #USB_SERVICE},
3161 * {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, {@link #WIFI_SERVICE},
3162 * {@link #WIFI_AWARE_SERVICE}. For these services this method will return <code>null</code>.
3163 * Generally, if you are running as an instant app you should always check whether the result
3164 * of this method is null.
3165 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003166 * @param name The name of the desired service.
Scott Main4b5da682010-10-21 11:49:12 -07003167 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 * @return The service or null if the name does not exist.
Scott Main4b5da682010-10-21 11:49:12 -07003169 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 * @see #WINDOW_SERVICE
3171 * @see android.view.WindowManager
3172 * @see #LAYOUT_INFLATER_SERVICE
3173 * @see android.view.LayoutInflater
3174 * @see #ACTIVITY_SERVICE
3175 * @see android.app.ActivityManager
3176 * @see #POWER_SERVICE
3177 * @see android.os.PowerManager
3178 * @see #ALARM_SERVICE
3179 * @see android.app.AlarmManager
3180 * @see #NOTIFICATION_SERVICE
3181 * @see android.app.NotificationManager
3182 * @see #KEYGUARD_SERVICE
3183 * @see android.app.KeyguardManager
3184 * @see #LOCATION_SERVICE
3185 * @see android.location.LocationManager
3186 * @see #SEARCH_SERVICE
3187 * @see android.app.SearchManager
3188 * @see #SENSOR_SERVICE
3189 * @see android.hardware.SensorManager
San Mehatc9d81752010-02-01 10:23:27 -08003190 * @see #STORAGE_SERVICE
San Mehatb1043402010-02-05 08:26:50 -08003191 * @see android.os.storage.StorageManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 * @see #VIBRATOR_SERVICE
3193 * @see android.os.Vibrator
3194 * @see #CONNECTIVITY_SERVICE
3195 * @see android.net.ConnectivityManager
3196 * @see #WIFI_SERVICE
3197 * @see android.net.wifi.WifiManager
3198 * @see #AUDIO_SERVICE
3199 * @see android.media.AudioManager
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003200 * @see #MEDIA_ROUTER_SERVICE
3201 * @see android.media.MediaRouter
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 * @see #TELEPHONY_SERVICE
3203 * @see android.telephony.TelephonyManager
Wink Savilled09c4ca2014-11-22 10:08:16 -08003204 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
3205 * @see android.telephony.SubscriptionManager
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003206 * @see #CARRIER_CONFIG_SERVICE
3207 * @see android.telephony.CarrierConfigManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003208 * @see #INPUT_METHOD_SERVICE
3209 * @see android.view.inputmethod.InputMethodManager
Tobias Haamel53332882010-02-18 16:15:43 -08003210 * @see #UI_MODE_SERVICE
3211 * @see android.app.UiModeManager
Steve Howard7083c422010-07-28 16:01:23 -07003212 * @see #DOWNLOAD_SERVICE
Steve Howardd58429f2010-09-27 16:32:39 -07003213 * @see android.app.DownloadManager
Todd Poynore35872d2013-12-10 11:57:21 -08003214 * @see #BATTERY_SERVICE
3215 * @see android.os.BatteryManager
Christopher Tate7060b042014-06-09 19:50:00 -07003216 * @see #JOB_SCHEDULER_SERVICE
3217 * @see android.app.job.JobScheduler
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003218 * @see #NETWORK_STATS_SERVICE
3219 * @see android.app.usage.NetworkStatsManager
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01003220 * @see android.os.HardwarePropertiesManager
3221 * @see #HARDWARE_PROPERTIES_SERVICE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003223 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224
3225 /**
Jeff Brown6e539312015-02-24 18:53:21 -08003226 * Return the handle to a system-level service by class.
3227 * <p>
3228 * Currently available classes are:
3229 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
3230 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
3231 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
3232 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
3233 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
3234 * {@link android.net.ConnectivityManager},
3235 * {@link android.net.wifi.WifiManager},
3236 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
3237 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
3238 * {@link android.view.inputmethod.InputMethodManager},
3239 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003240 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
3241 * {@link android.app.usage.NetworkStatsManager}.
Jeff Brown6e539312015-02-24 18:53:21 -08003242 * </p><p>
3243 * Note: System services obtained via this API may be closely associated with
3244 * the Context in which they are obtained from. In general, do not share the
3245 * service objects between various different contexts (Activities, Applications,
3246 * Services, Providers, etc.)
3247 * </p>
3248 *
Svet Ganov8f90bcc2017-12-22 23:29:24 -08003249 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
3250 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
3251 * {@link #FINGERPRINT_SERVICE}, {@link #SHORTCUT_SERVICE}, {@link #USB_SERVICE},
3252 * {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE}, {@link #WIFI_SERVICE},
3253 * {@link #WIFI_AWARE_SERVICE}. For these services this method will return <code>null</code>.
3254 * Generally, if you are running as an instant app you should always check whether the result
3255 * of this method is null.
3256 *
Jeff Brown6e539312015-02-24 18:53:21 -08003257 * @param serviceClass The class of the desired service.
3258 * @return The service or null if the class is not a supported system service.
3259 */
3260 @SuppressWarnings("unchecked")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003261 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
Jeff Brown6e539312015-02-24 18:53:21 -08003262 // Because subclasses may override getSystemService(String) we cannot
3263 // perform a lookup by class alone. We must first map the class to its
3264 // service name then invoke the string-based method.
3265 String serviceName = getSystemServiceName(serviceClass);
3266 return serviceName != null ? (T)getSystemService(serviceName) : null;
3267 }
3268
3269 /**
3270 * Gets the name of the system-level service that is represented by the specified class.
3271 *
3272 * @param serviceClass The class of the desired service.
3273 * @return The service name or null if the class is not a supported system service.
Jeff Brown6e539312015-02-24 18:53:21 -08003274 */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06003275 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
Jeff Brown6e539312015-02-24 18:53:21 -08003276
3277 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003278 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003279 * {@link android.os.PowerManager} for controlling power management,
3280 * including "wake locks," which let you keep the device on while
3281 * you're running long tasks.
3282 */
3283 public static final String POWER_SERVICE = "power";
Scott Main4b5da682010-10-21 11:49:12 -07003284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003285 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003286 * Use with {@link #getSystemService(String)} to retrieve a
Tao Baoe8a403d2015-12-31 07:44:55 -08003287 * {@link android.os.RecoverySystem} for accessing the recovery system
3288 * service.
3289 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003290 * @see #getSystemService(String)
Tao Baoe8a403d2015-12-31 07:44:55 -08003291 * @hide
3292 */
3293 public static final String RECOVERY_SERVICE = "recovery";
3294
3295 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003296 * Use with {@link #getSystemService(String)} to retrieve a
Tao Bao07342dc2017-01-24 15:08:21 -08003297 * {@link android.os.SystemUpdateManager} for accessing the system update
3298 * manager service.
3299 *
3300 * @see #getSystemService(String)
3301 * @hide
3302 */
3303 @SystemApi
3304 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
3305
3306 /**
3307 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003308 * {@link android.view.WindowManager} for accessing the system's window
3309 * manager.
3310 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003311 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003312 * @see android.view.WindowManager
3313 */
3314 public static final String WINDOW_SERVICE = "window";
Scott Main4b5da682010-10-21 11:49:12 -07003315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003316 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003317 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003318 * {@link android.view.LayoutInflater} for inflating layout resources in this
3319 * context.
3320 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003321 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 * @see android.view.LayoutInflater
3323 */
3324 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
Scott Main4b5da682010-10-21 11:49:12 -07003325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003326 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003327 * Use with {@link #getSystemService(String)} to retrieve a
Fred Quintana60307342009-03-24 22:48:12 -07003328 * {@link android.accounts.AccountManager} for receiving intents at a
3329 * time of your choosing.
Fred Quintana60307342009-03-24 22:48:12 -07003330 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003331 * @see #getSystemService(String)
Fred Quintana60307342009-03-24 22:48:12 -07003332 * @see android.accounts.AccountManager
3333 */
3334 public static final String ACCOUNT_SERVICE = "account";
Scott Main4b5da682010-10-21 11:49:12 -07003335
Fred Quintana60307342009-03-24 22:48:12 -07003336 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003337 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003338 * {@link android.app.ActivityManager} for interacting with the global
3339 * system state.
3340 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003341 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 * @see android.app.ActivityManager
3343 */
3344 public static final String ACTIVITY_SERVICE = "activity";
Scott Main4b5da682010-10-21 11:49:12 -07003345
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003346 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003347 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003348 * {@link android.app.AlarmManager} for receiving intents at a
3349 * time of your choosing.
3350 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003351 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003352 * @see android.app.AlarmManager
3353 */
3354 public static final String ALARM_SERVICE = "alarm";
Scott Main4b5da682010-10-21 11:49:12 -07003355
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003356 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003357 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003358 * {@link android.app.NotificationManager} for informing the user of
3359 * background events.
3360 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003361 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003362 * @see android.app.NotificationManager
3363 */
3364 public static final String NOTIFICATION_SERVICE = "notification";
Scott Main4b5da682010-10-21 11:49:12 -07003365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003366 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003367 * Use with {@link #getSystemService(String)} to retrieve a
svetoslavganov75986cf2009-05-14 22:28:01 -07003368 * {@link android.view.accessibility.AccessibilityManager} for giving the user
3369 * feedback for UI events through the registered event listeners.
3370 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003371 * @see #getSystemService(String)
svetoslavganov75986cf2009-05-14 22:28:01 -07003372 * @see android.view.accessibility.AccessibilityManager
3373 */
3374 public static final String ACCESSIBILITY_SERVICE = "accessibility";
Scott Main4b5da682010-10-21 11:49:12 -07003375
svetoslavganov75986cf2009-05-14 22:28:01 -07003376 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003377 * Use with {@link #getSystemService(String)} to retrieve a
Alan Viverette69ce69b2013-08-29 12:23:48 -07003378 * {@link android.view.accessibility.CaptioningManager} for obtaining
3379 * captioning properties and listening for changes in captioning
3380 * preferences.
3381 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003382 * @see #getSystemService(String)
Alan Viverette69ce69b2013-08-29 12:23:48 -07003383 * @see android.view.accessibility.CaptioningManager
3384 */
3385 public static final String CAPTIONING_SERVICE = "captioning";
3386
3387 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003388 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003389 * {@link android.app.NotificationManager} for controlling keyguard.
3390 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003391 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003392 * @see android.app.KeyguardManager
3393 */
3394 public static final String KEYGUARD_SERVICE = "keyguard";
Scott Main4b5da682010-10-21 11:49:12 -07003395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003396 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003397 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003398 * android.location.LocationManager} for controlling location
3399 * updates.
3400 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003401 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003402 * @see android.location.LocationManager
3403 */
3404 public static final String LOCATION_SERVICE = "location";
Bai Taoa58a8752010-07-13 15:32:16 +08003405
3406 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003407 * Use with {@link #getSystemService(String)} to retrieve a
Bai Taoa58a8752010-07-13 15:32:16 +08003408 * {@link android.location.CountryDetector} for detecting the country that
3409 * the user is in.
3410 *
3411 * @hide
3412 */
Mathew Inwood45d2c252018-09-14 12:35:36 +01003413 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Bai Taoa58a8752010-07-13 15:32:16 +08003414 public static final String COUNTRY_DETECTOR = "country_detector";
3415
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003416 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003417 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003418 * android.app.SearchManager} for handling searches.
3419 *
Erik Wolsheimerac5cecd2017-12-05 13:11:50 -08003420 * <p>
3421 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
3422 * {@link android.app.SearchManager}.
3423 *
3424 * @see #getSystemService
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003425 * @see android.app.SearchManager
3426 */
3427 public static final String SEARCH_SERVICE = "search";
Scott Main4b5da682010-10-21 11:49:12 -07003428
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003429 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003430 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003431 * android.hardware.SensorManager} for accessing sensors.
3432 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003433 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003434 * @see android.hardware.SensorManager
3435 */
3436 public static final String SENSOR_SERVICE = "sensor";
Scott Main4b5da682010-10-21 11:49:12 -07003437
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003438 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003439 * Use with {@link #getSystemService(String)} to retrieve a {@link
Kenny Root02c87302010-07-01 08:10:18 -07003440 * android.os.storage.StorageManager} for accessing system storage
San Mehatc9d81752010-02-01 10:23:27 -08003441 * functions.
3442 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003443 * @see #getSystemService(String)
San Mehatb1043402010-02-05 08:26:50 -08003444 * @see android.os.storage.StorageManager
San Mehatc9d81752010-02-01 10:23:27 -08003445 */
3446 public static final String STORAGE_SERVICE = "storage";
3447
3448 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003449 * Use with {@link #getSystemService(String)} to retrieve a {@link
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003450 * android.app.usage.StorageStatsManager} for accessing system storage
3451 * statistics.
3452 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003453 * @see #getSystemService(String)
Jeff Sharkeye8cece92017-01-04 11:33:33 -07003454 * @see android.app.usage.StorageStatsManager
3455 */
3456 public static final String STORAGE_STATS_SERVICE = "storagestats";
3457
3458 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003459 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003460 * com.android.server.WallpaperService for accessing wallpapers.
3461 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003462 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003463 */
3464 public static final String WALLPAPER_SERVICE = "wallpaper";
Scott Main4b5da682010-10-21 11:49:12 -07003465
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003466 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003467 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003468 * android.os.Vibrator} for interacting with the vibration hardware.
3469 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003470 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003471 * @see android.os.Vibrator
3472 */
3473 public static final String VIBRATOR_SERVICE = "vibrator";
Robert Greenwalt9e696c22010-04-01 14:45:18 -07003474
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003475 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003476 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003477 * android.app.StatusBarManager} for interacting with the status bar.
3478 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003479 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003480 * @see android.app.StatusBarManager
3481 * @hide
3482 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01003483 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003484 public static final String STATUS_BAR_SERVICE = "statusbar";
3485
3486 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003487 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003488 * android.net.ConnectivityManager} for handling management of
3489 * network connections.
3490 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003491 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003492 * @see android.net.ConnectivityManager
3493 */
3494 public static final String CONNECTIVITY_SERVICE = "connectivity";
3495
3496 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003497 * Use with {@link #getSystemService(String)} to retrieve a
Nathan Harold330e1082017-01-12 18:38:57 -08003498 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
3499 * IPSec.
3500 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003501 * @see #getSystemService(String)
Nathan Harold330e1082017-01-12 18:38:57 -08003502 */
3503 public static final String IPSEC_SERVICE = "ipsec";
3504
3505 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003506 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate8662cab52012-02-23 14:59:36 -08003507 * android.os.IUpdateLock} for managing runtime sequences that
3508 * must not be interrupted by headless OTA application or similar.
3509 *
3510 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003511 * @see #getSystemService(String)
Christopher Tate8662cab52012-02-23 14:59:36 -08003512 * @see android.os.UpdateLock
3513 */
3514 public static final String UPDATE_LOCK_SERVICE = "updatelock";
3515
3516 /**
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003517 * Constant for the internal network management service, not really a Context service.
Dianne Hackborn0a6a80f2013-09-16 15:20:27 -07003518 * @hide
San Mehatd1df8ac2010-01-26 06:17:26 -08003519 */
3520 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
3521
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003522 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003523 * Use with {@link #getSystemService(String)} to retrieve a
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003524 * {@link com.android.server.slice.SliceManagerService} for managing slices.
3525 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003526 * @see #getSystemService(String)
Jason Monk8f5f7ff2017-10-17 14:12:42 -04003527 */
3528 public static final String SLICE_SERVICE = "slice";
3529
3530 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003531 * Use with {@link #getSystemService(String)} to retrieve a {@link
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003532 * android.app.usage.NetworkStatsManager} for querying network usage stats.
3533 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003534 * @see #getSystemService(String)
Zoltan Szatmary-Ban9c5dfa52015-02-23 17:20:20 +00003535 * @see android.app.usage.NetworkStatsManager
3536 */
Jeff Sharkey75279902011-05-24 18:39:45 -07003537 public static final String NETWORK_STATS_SERVICE = "netstats";
3538 /** {@hide} */
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003539 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
Ricky Wai1a6e6672017-10-27 14:46:01 +01003540 /** {@hide} */
3541 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
Jeff Sharkeyeedcb952011-05-17 14:55:15 -07003542
San Mehatd1df8ac2010-01-26 06:17:26 -08003543 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003544 * Use with {@link #getSystemService(String)} to retrieve a {@link
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003545 * android.net.wifi.WifiManager} for handling management of
3546 * Wi-Fi access.
3547 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003548 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003549 * @see android.net.wifi.WifiManager
3550 */
3551 public static final String WIFI_SERVICE = "wifi";
Scott Main4b5da682010-10-21 11:49:12 -07003552
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003553 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003554 * Use with {@link #getSystemService(String)} to retrieve a {@link
repo sync55bc5f32011-06-24 14:23:07 -07003555 * android.net.wifi.p2p.WifiP2pManager} for handling management of
Irfan Sheriff651cdfc2011-09-07 00:31:20 -07003556 * Wi-Fi peer-to-peer connections.
repo sync55bc5f32011-06-24 14:23:07 -07003557 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003558 * @see #getSystemService(String)
repo sync55bc5f32011-06-24 14:23:07 -07003559 * @see android.net.wifi.p2p.WifiP2pManager
repo sync55bc5f32011-06-24 14:23:07 -07003560 */
3561 public static final String WIFI_P2P_SERVICE = "wifip2p";
3562
3563 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003564 * Use with {@link #getSystemService(String)} to retrieve a
Etan Cohen04133272016-10-26 11:22:06 -07003565 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
3566 * Wi-Fi Aware.
Etan Cohen20d329b2015-09-29 13:49:02 -07003567 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003568 * @see #getSystemService(String)
Etan Cohen04133272016-10-26 11:22:06 -07003569 * @see android.net.wifi.aware.WifiAwareManager
Etan Cohen20d329b2015-09-29 13:49:02 -07003570 */
Etan Cohen04133272016-10-26 11:22:06 -07003571 public static final String WIFI_AWARE_SERVICE = "wifiaware";
Etan Cohen20d329b2015-09-29 13:49:02 -07003572
3573 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003574 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003575 * android.net.wifi.WifiScanner} for scanning the wifi universe
3576 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003577 * @see #getSystemService(String)
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003578 * @see android.net.wifi.WifiScanner
3579 * @hide
3580 */
Wei Wang35d552f2014-07-08 21:37:01 -07003581 @SystemApi
Vinit Deshapnde011e1b32014-05-07 21:09:11 -07003582 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
3583
3584 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003585 * Use with {@link #getSystemService(String)} to retrieve a {@link
Vinit Deshpande7686c062014-06-30 15:25:01 -07003586 * android.net.wifi.RttManager} for ranging devices with wifi
3587 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003588 * @see #getSystemService(String)
Vinit Deshpande7686c062014-06-30 15:25:01 -07003589 * @see android.net.wifi.RttManager
3590 * @hide
3591 */
3592 @SystemApi
Etan Cohend0acccd2018-01-31 08:36:33 -08003593 @Deprecated
Vinit Deshpande7686c062014-06-30 15:25:01 -07003594 public static final String WIFI_RTT_SERVICE = "rttmanager";
3595
3596 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003597 * Use with {@link #getSystemService(String)} to retrieve a {@link
Etan Cohen17ba4722017-08-21 10:52:17 -07003598 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi
3599 *
3600 * Note: this is a replacement for WIFI_RTT_SERVICE above. It will
3601 * be renamed once final implementation in place.
3602 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003603 * @see #getSystemService(String)
Etan Cohen17ba4722017-08-21 10:52:17 -07003604 * @see android.net.wifi.rtt.WifiRttManager
Etan Cohen17ba4722017-08-21 10:52:17 -07003605 */
Etan Cohen091d7772018-01-04 17:47:37 -08003606 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
Etan Cohen17ba4722017-08-21 10:52:17 -07003607
3608 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003609 * Use with {@link #getSystemService(String)} to retrieve a {@link
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003610 * android.net.lowpan.LowpanManager} for handling management of
3611 * LoWPAN access.
3612 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003613 * @see #getSystemService(String)
Robert Quattlebaum87a71042017-05-15 15:45:20 -07003614 * @see android.net.lowpan.LowpanManager
3615 *
3616 * @hide
3617 */
3618 public static final String LOWPAN_SERVICE = "lowpan";
3619
3620 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003621 * Use with {@link #getSystemService(String)} to retrieve a {@link
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003622 * android.net.EthernetManager} for handling management of
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003623 * Ethernet access.
3624 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003625 * @see #getSystemService(String)
Dianne Hackbornfee756f2014-07-16 17:31:10 -07003626 * @see android.net.EthernetManager
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003627 *
3628 * @hide
3629 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01003630 @UnsupportedAppUsage
Lorenzo Colittif9ff2c92014-05-21 16:32:11 -07003631 public static final String ETHERNET_SERVICE = "ethernet";
3632
3633 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003634 * Use with {@link #getSystemService(String)} to retrieve a {@link
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003635 * android.net.nsd.NsdManager} for handling management of network service
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003636 * discovery
3637 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003638 * @see #getSystemService(String)
Irfan Sheriff60309fc2012-04-24 14:52:37 -07003639 * @see android.net.nsd.NsdManager
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003640 */
3641 public static final String NSD_SERVICE = "servicediscovery";
3642
Irfan Sheriff7d024d32012-03-22 17:01:39 -07003643 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003644 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003645 * {@link android.media.AudioManager} for handling management of volume,
3646 * ringer modes and audio routing.
Scott Main4b5da682010-10-21 11:49:12 -07003647 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003648 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003649 * @see android.media.AudioManager
3650 */
3651 public static final String AUDIO_SERVICE = "audio";
Scott Main4b5da682010-10-21 11:49:12 -07003652
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003653 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003654 * Use with {@link #getSystemService(String)} to retrieve a
Jim Millerce7eb6d2015-04-03 19:29:13 -07003655 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
Jim Miller08fa40c2014-04-29 18:18:47 -07003656 * of fingerprints.
3657 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003658 * @see #getSystemService(String)
Jim Millerce7eb6d2015-04-03 19:29:13 -07003659 * @see android.hardware.fingerprint.FingerprintManager
Jim Miller08fa40c2014-04-29 18:18:47 -07003660 */
3661 public static final String FINGERPRINT_SERVICE = "fingerprint";
3662
3663 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003664 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003665 * {@link android.media.MediaRouter} for controlling and managing
3666 * routing of media.
3667 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003668 * @see #getSystemService(String)
Dianne Hackbornb58b8f82012-06-11 15:08:39 -07003669 * @see android.media.MediaRouter
3670 */
3671 public static final String MEDIA_ROUTER_SERVICE = "media_router";
3672
3673 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003674 * Use with {@link #getSystemService(String)} to retrieve a
RoboErik42ea7ee2014-05-16 16:27:35 -07003675 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
RoboErik01fe6612014-02-13 14:19:04 -08003676 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003677 * @see #getSystemService(String)
RoboErik42ea7ee2014-05-16 16:27:35 -07003678 * @see android.media.session.MediaSessionManager
RoboErik01fe6612014-02-13 14:19:04 -08003679 */
3680 public static final String MEDIA_SESSION_SERVICE = "media_session";
3681
3682 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003683 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003684 * {@link android.telephony.TelephonyManager} for handling management the
3685 * telephony features of the device.
Scott Main4b5da682010-10-21 11:49:12 -07003686 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003687 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 * @see android.telephony.TelephonyManager
3689 */
3690 public static final String TELEPHONY_SERVICE = "phone";
3691
3692 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003693 * Use with {@link #getSystemService(String)} to retrieve a
Wink Savilled09c4ca2014-11-22 10:08:16 -08003694 * {@link android.telephony.SubscriptionManager} for handling management the
3695 * telephony subscriptions of the device.
3696 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003697 * @see #getSystemService(String)
Wink Savilled09c4ca2014-11-22 10:08:16 -08003698 * @see android.telephony.SubscriptionManager
3699 */
3700 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
3701
3702 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003703 * Use with {@link #getSystemService(String)} to retrieve a
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003704 * {@link android.telecom.TelecomManager} to manage telecom-related features
Yorke Leeb4ce1432014-06-09 13:53:23 -07003705 * of the device.
3706 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003707 * @see #getSystemService(String)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003708 * @see android.telecom.TelecomManager
Yorke Leeb4ce1432014-06-09 13:53:23 -07003709 */
Tyler Gunnef9f6f92014-09-12 22:16:17 -07003710 public static final String TELECOM_SERVICE = "telecom";
Yorke Leeb4ce1432014-06-09 13:53:23 -07003711
3712 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003713 * Use with {@link #getSystemService(String)} to retrieve a
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003714 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
3715 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003716 * @see #getSystemService(String)
Jonathan Basseri9a1c9b62015-02-25 13:01:52 -08003717 * @see android.telephony.CarrierConfigManager
3718 */
3719 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
3720
3721 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003722 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Davidson35cda392017-02-27 09:46:00 -08003723 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
3724 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003725 * @see #getSystemService(String)
Jeff Davidson35cda392017-02-27 09:46:00 -08003726 * @see android.telephony.euicc.EuiccManager
Jeff Davidson35cda392017-02-27 09:46:00 -08003727 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08003728 public static final String EUICC_SERVICE = "euicc";
Jeff Davidson35cda392017-02-27 09:46:00 -08003729
3730 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003731 * Use with {@link #getSystemService(String)} to retrieve a
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003732 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
3733 *
3734 * @see #getSystemService(String)
3735 * @see android.telephony.euicc.EuiccCardManager
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003736 * @hide
3737 */
Holly Jiuyu Sun4f73b9c2017-12-12 20:17:09 -08003738 @SystemApi
3739 public static final String EUICC_CARD_SERVICE = "euicc_card";
Holly Jiuyu Sun5c110242017-12-21 18:44:59 -08003740
3741 /**
3742 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown6e539312015-02-24 18:53:21 -08003743 * {@link android.content.ClipboardManager} for accessing and modifying
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003744 * the contents of the global clipboard.
Scott Main4b5da682010-10-21 11:49:12 -07003745 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003746 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08003747 * @see android.content.ClipboardManager
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003748 */
3749 public static final String CLIPBOARD_SERVICE = "clipboard";
3750
3751 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003752 * Use with {@link #getSystemService(String)} to retrieve a
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003753 * {@link TextClassificationManager} for text classification services.
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003754 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003755 * @see #getSystemService(String)
Abodunrinwa Tokif001fef2017-01-04 23:51:42 +00003756 * @see TextClassificationManager
Abodunrinwa Toki8158af52016-11-23 20:41:09 +00003757 */
3758 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
3759
3760 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003761 * Use with {@link #getSystemService(String)} to retrieve a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003762 * {@link android.view.inputmethod.InputMethodManager} for accessing input
3763 * methods.
3764 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003765 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003766 */
3767 public static final String INPUT_METHOD_SERVICE = "input_method";
3768
3769 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003770 * Use with {@link #getSystemService(String)} to retrieve a
satok988323c2011-06-22 16:38:13 +09003771 * {@link android.view.textservice.TextServicesManager} for accessing
3772 * text services.
3773 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003774 * @see #getSystemService(String)
satok988323c2011-06-22 16:38:13 +09003775 */
3776 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
3777
3778 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003779 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnore38d58b2009-12-30 19:29:03 -08003780 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003781 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003782 * @see #getSystemService(String)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003783 */
The Android Open Source Projectc39a6e02009-03-11 12:11:56 -07003784 public static final String APPWIDGET_SERVICE = "appwidget";
Dan Egnor95240272009-10-27 18:23:39 -07003785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003786 /**
Dianne Hackborn91097de2014-04-04 18:02:06 -07003787 * Official published name of the (internal) voice interaction manager service.
3788 *
3789 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003790 * @see #getSystemService(String)
Dianne Hackborn91097de2014-04-04 18:02:06 -07003791 */
3792 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
3793
3794 /**
Felipe Leme640f30a2017-03-06 15:44:06 -08003795 * Official published name of the (internal) autofill service.
Felipe Leme5381aa42016-10-13 09:02:32 -07003796 *
3797 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003798 * @see #getSystemService(String)
Felipe Leme5381aa42016-10-13 09:02:32 -07003799 */
Felipe Leme640f30a2017-03-06 15:44:06 -08003800 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
Felipe Leme5381aa42016-10-13 09:02:32 -07003801
3802 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003803 * Use with {@link #getSystemService(String)} to access the
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003804 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
3805 *
3806 * @hide
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003807 * @see #getSystemService(String)
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08003808 */
3809 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
3810
3811
3812 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003813 * Use with {@link #getSystemService(String)} to retrieve an
Christopher Tate45281862010-03-05 15:46:30 -08003814 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
Christopher Tate487529a2009-04-29 14:03:25 -07003815 * with the backup mechanism.
Dianne Hackborn7f205432009-07-28 00:13:47 -07003816 * @hide
Scott Main4b5da682010-10-21 11:49:12 -07003817 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003818 * @see #getSystemService(String)
Christopher Tate487529a2009-04-29 14:03:25 -07003819 */
Christopher Tated5cf7222014-07-29 16:53:09 -07003820 @SystemApi
Christopher Tate487529a2009-04-29 14:03:25 -07003821 public static final String BACKUP_SERVICE = "backup";
Dan Egnor95240272009-10-27 18:23:39 -07003822
3823 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003824 * Use with {@link #getSystemService(String)} to retrieve a
Dan Egnor1337b012010-01-04 11:01:44 -08003825 * {@link android.os.DropBoxManager} instance for recording
Dan Egnor95240272009-10-27 18:23:39 -07003826 * diagnostic logs.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003827 * @see #getSystemService(String)
Dan Egnor95240272009-10-27 18:23:39 -07003828 */
3829 public static final String DROPBOX_SERVICE = "dropbox";
3830
Christopher Tate487529a2009-04-29 14:03:25 -07003831 /**
Philip P. Moltmannf80809f2018-04-04 11:20:44 -07003832 * System service name for the DeviceIdleManager.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003833 * @see #getSystemService(String)
Dianne Hackborn1958e5e2015-06-12 18:11:41 -07003834 * @hide
3835 */
3836 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
3837
3838 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003839 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborn87bba1e2010-02-26 17:25:54 -08003840 * {@link android.app.admin.DevicePolicyManager} for working with global
Dianne Hackbornd6847842010-01-12 18:14:19 -08003841 * device policy management.
3842 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003843 * @see #getSystemService(String)
Dianne Hackbornd6847842010-01-12 18:14:19 -08003844 */
3845 public static final String DEVICE_POLICY_SERVICE = "device_policy";
3846
3847 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003848 * Use with {@link #getSystemService(String)} to retrieve a
Tobias Haamel53332882010-02-18 16:15:43 -08003849 * {@link android.app.UiModeManager} for controlling UI modes.
3850 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003851 * @see #getSystemService(String)
Tobias Haamel53332882010-02-18 16:15:43 -08003852 */
3853 public static final String UI_MODE_SERVICE = "uimode";
3854
3855 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003856 * Use with {@link #getSystemService(String)} to retrieve a
Steve Howardd58429f2010-09-27 16:32:39 -07003857 * {@link android.app.DownloadManager} for requesting HTTP downloads.
Steve Howarda2709362010-07-02 17:12:48 -07003858 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003859 * @see #getSystemService(String)
Steve Howarda2709362010-07-02 17:12:48 -07003860 */
3861 public static final String DOWNLOAD_SERVICE = "download";
3862
3863 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003864 * Use with {@link #getSystemService(String)} to retrieve a
Todd Poynore35872d2013-12-10 11:57:21 -08003865 * {@link android.os.BatteryManager} for managing battery state.
3866 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003867 * @see #getSystemService(String)
Todd Poynore35872d2013-12-10 11:57:21 -08003868 */
3869 public static final String BATTERY_SERVICE = "batterymanager";
3870
3871 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003872 * Use with {@link #getSystemService(String)} to retrieve a
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003873 * {@link android.nfc.NfcManager} for using NFC.
3874 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003875 * @see #getSystemService(String)
Nick Pelly50b4d8f2010-12-07 22:40:28 -08003876 */
3877 public static final String NFC_SERVICE = "nfc";
3878
3879 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003880 * Use with {@link #getSystemService(String)} to retrieve a
Florian Salbrechter084da9b2015-03-25 11:00:55 +00003881 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003882 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003883 * @see #getSystemService(String)
Jaikumar Ganesh1abb1cb2012-01-25 16:14:50 -08003884 */
3885 public static final String BLUETOOTH_SERVICE = "bluetooth";
3886
3887 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003888 * Use with {@link #getSystemService(String)} to retrieve a
Chung-yih Wang2d942312010-08-05 12:17:37 +08003889 * {@link android.net.sip.SipManager} for accessing the SIP related service.
3890 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003891 * @see #getSystemService(String)
Chung-yih Wang2d942312010-08-05 12:17:37 +08003892 */
3893 /** @hide */
3894 public static final String SIP_SERVICE = "sip";
3895
3896 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003897 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodc4308f02011-03-01 08:04:54 -08003898 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003899 * and for controlling this device's behavior as a USB device.
3900 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003901 * @see #getSystemService(String)
John Spurlock6098c5d2013-06-17 10:32:46 -04003902 * @see android.hardware.usb.UsbManager
Mike Lockwoode7d511e2010-12-30 13:39:37 -05003903 */
3904 public static final String USB_SERVICE = "usb";
3905
3906 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003907 * Use with {@link #getSystemService(String)} to retrieve a {@link
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003908 * android.hardware.SerialManager} for access to serial ports.
3909 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003910 * @see #getSystemService(String)
Dianne Hackborn35f72be2013-09-16 10:57:39 -07003911 * @see android.hardware.SerialManager
Mike Lockwoodb01e8bf2011-08-29 20:11:07 -04003912 *
3913 * @hide
3914 */
3915 public static final String SERIAL_SERVICE = "serial";
3916
3917 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003918 * Use with {@link #getSystemService(String)} to retrieve a
Jinsuk Kim91120c52014-05-08 17:12:51 +09003919 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
3920 * HDMI-CEC protocol.
3921 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003922 * @see #getSystemService(String)
Jinsuk Kim91120c52014-05-08 17:12:51 +09003923 * @see android.hardware.hdmi.HdmiControlManager
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003924 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +09003925 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +09003926 @SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +09003927 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
Jinsuk Kimfbcd5032014-03-21 16:25:13 +09003928
3929 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003930 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003931 * {@link android.hardware.input.InputManager} for interacting with input devices.
3932 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003933 * @see #getSystemService(String)
Jeff Brown9df6e7a2012-04-05 11:49:26 -07003934 * @see android.hardware.input.InputManager
3935 */
3936 public static final String INPUT_SERVICE = "input";
3937
3938 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003939 * Use with {@link #getSystemService(String)} to retrieve a
Jeff Brownfa25bf52012-07-23 19:26:30 -07003940 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
3941 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003942 * @see #getSystemService(String)
Jeff Brownfa25bf52012-07-23 19:26:30 -07003943 * @see android.hardware.display.DisplayManager
3944 */
3945 public static final String DISPLAY_SERVICE = "display";
3946
3947 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003948 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani258848d2012-08-10 17:06:33 -07003949 * {@link android.os.UserManager} for managing users on devices that support multiple users.
3950 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003951 * @see #getSystemService(String)
Amith Yamasani258848d2012-08-10 17:06:33 -07003952 * @see android.os.UserManager
3953 */
3954 public static final String USER_SERVICE = "user";
3955
3956 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003957 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasani4f582632014-02-19 14:31:52 -08003958 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
3959 * profiles of a user.
3960 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003961 * @see #getSystemService(String)
Amith Yamasani4f582632014-02-19 14:31:52 -08003962 * @see android.content.pm.LauncherApps
3963 */
3964 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
3965
3966 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003967 * Use with {@link #getSystemService(String)} to retrieve a
Amith Yamasanif20d6402014-05-24 15:34:37 -07003968 * {@link android.content.RestrictionsManager} for retrieving application restrictions
3969 * and requesting permissions for restricted operations.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003970 * @see #getSystemService(String)
Amith Yamasanif20d6402014-05-24 15:34:37 -07003971 * @see android.content.RestrictionsManager
3972 */
3973 public static final String RESTRICTIONS_SERVICE = "restrictions";
3974
3975 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003976 * Use with {@link #getSystemService(String)} to retrieve a
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003977 * {@link android.app.AppOpsManager} for tracking application operations
3978 * on the device.
3979 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003980 * @see #getSystemService(String)
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003981 * @see android.app.AppOpsManager
Dianne Hackborna06de0f2012-12-11 16:34:47 -08003982 */
3983 public static final String APP_OPS_SERVICE = "appops";
3984
3985 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003986 * Use with {@link #getSystemService(String)} to retrieve a
Eino-Ville Talvala2f1a2e42013-07-25 17:12:05 -07003987 * {@link android.hardware.camera2.CameraManager} for interacting with
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003988 * camera devices.
3989 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003990 * @see #getSystemService(String)
Dianne Hackborn221ea892013-08-04 16:50:16 -07003991 * @see android.hardware.camera2.CameraManager
Eino-Ville Talvalab2675542012-12-12 13:29:45 -08003992 */
3993 public static final String CAMERA_SERVICE = "camera";
3994
3995 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003996 * {@link android.print.PrintManager} for printing and managing
Jeff Brown511cd352013-08-23 17:43:37 -07003997 * printers and print tasks.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07003998 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08003999 * @see #getSystemService(String)
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07004000 * @see android.print.PrintManager
4001 */
4002 public static final String PRINT_SERVICE = "print";
4003
4004 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004005 * Use with {@link #getSystemService(String)} to retrieve a
Eugene Susla6ed45d82017-01-22 13:52:51 -08004006 * {@link android.companion.CompanionDeviceManager} for managing companion devices
4007 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004008 * @see #getSystemService(String)
Eugene Susla6ed45d82017-01-22 13:52:51 -08004009 * @see android.companion.CompanionDeviceManager
4010 */
Eugene Suslad7355cc2017-04-20 11:14:45 -07004011 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
Eugene Susla6ed45d82017-01-22 13:52:51 -08004012
4013 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004014 * Use with {@link #getSystemService(String)} to retrieve a
Erik Gilling51e95df2013-06-26 11:06:51 -07004015 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
4016 * signals from the device.
4017 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004018 * @see #getSystemService(String)
Erik Gilling51e95df2013-06-26 11:06:51 -07004019 * @see android.hardware.ConsumerIrManager
4020 */
4021 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
4022
4023 /**
Adrian Roos82142c22014-03-27 14:56:59 +01004024 * {@link android.app.trust.TrustManager} for managing trust agents.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004025 * @see #getSystemService(String)
Adrian Roos82142c22014-03-27 14:56:59 +01004026 * @see android.app.trust.TrustManager
4027 * @hide
4028 */
4029 public static final String TRUST_SERVICE = "trust";
4030
4031 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004032 * Use with {@link #getSystemService(String)} to retrieve a
Jae Seod5cc4a22014-05-30 16:57:43 -07004033 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
4034 * on the device.
Jae Seo39570912014-02-20 18:23:25 -08004035 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004036 * @see #getSystemService(String)
Jae Seod5cc4a22014-05-30 16:57:43 -07004037 * @see android.media.tv.TvInputManager
Jae Seo39570912014-02-20 18:23:25 -08004038 */
4039 public static final String TV_INPUT_SERVICE = "tv_input";
4040
4041 /**
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004042 * {@link android.net.NetworkScoreManager} for managing network scoring.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004043 * @see #getSystemService(String)
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004044 * @see android.net.NetworkScoreManager
4045 * @hide
4046 */
Jeff Davidson5ad20792014-07-21 13:55:42 -07004047 @SystemApi
Jeff Davidsonb51e0a62014-04-09 12:38:15 -07004048 public static final String NETWORK_SCORE_SERVICE = "network_score";
4049
4050 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004051 * Use with {@link #getSystemService(String)} to retrieve a {@link
Adam Lesinskiaa607672014-11-24 11:27:50 -08004052 * android.app.usage.UsageStatsManager} for querying device usage stats.
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004053 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004054 * @see #getSystemService(String)
Dianne Hackbornff170242014-11-19 10:59:01 -08004055 * @see android.app.usage.UsageStatsManager
Dianne Hackborne22b3b12014-05-07 18:06:44 -07004056 */
4057 public static final String USAGE_STATS_SERVICE = "usagestats";
4058
4059 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004060 * Use with {@link #getSystemService(String)} to retrieve a {@link
Christopher Tate7060b042014-06-09 19:50:00 -07004061 * android.app.job.JobScheduler} instance for managing occasional
Christopher Tatefa380e92014-05-19 13:46:29 -07004062 * background tasks.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004063 * @see #getSystemService(String)
Christopher Tate7060b042014-06-09 19:50:00 -07004064 * @see android.app.job.JobScheduler
Christopher Tatefa380e92014-05-19 13:46:29 -07004065 */
Christopher Tate7060b042014-06-09 19:50:00 -07004066 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
Christopher Tatefa380e92014-05-19 13:46:29 -07004067
4068 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004069 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andres Morales33df9372014-09-26 17:08:59 -07004070 * android.service.persistentdata.PersistentDataBlockManager} instance
4071 * for interacting with a storage device that lives across factory resets.
4072 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004073 * @see #getSystemService(String)
Andres Morales68d4acd2014-07-01 19:40:41 -07004074 * @see android.service.persistentdata.PersistentDataBlockManager
4075 * @hide
4076 */
Andres Morales33df9372014-09-26 17:08:59 -07004077 @SystemApi
Andres Morales68d4acd2014-07-01 19:40:41 -07004078 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
4079
4080 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004081 * Use with {@link #getSystemService(String)} to retrieve a {@link
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004082 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
4083 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004084 * @see #getSystemService(String)
Andrew Scull3b8b46f2017-02-13 18:12:15 +00004085 * @see android.service.oemlock.OemLockManager
4086 * @hide
4087 */
4088 @SystemApi
4089 public static final String OEM_LOCK_SERVICE = "oem_lock";
4090
4091 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004092 * Use with {@link #getSystemService(String)} to retrieve a {@link
Michael Wrightc39d47a2014-07-08 18:07:36 -07004093 * android.media.projection.MediaProjectionManager} instance for managing
4094 * media projection sessions.
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004095 * @see #getSystemService(String)
Jeff Brown6e539312015-02-24 18:53:21 -08004096 * @see android.media.projection.MediaProjectionManager
Michael Wrightc39d47a2014-07-08 18:07:36 -07004097 */
4098 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
4099
4100 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004101 * Use with {@link #getSystemService(String)} to retrieve a
Mike Lockwoodb6737702015-02-20 08:28:47 -08004102 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004103 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004104 * @see #getSystemService(String)
Mike Lockwood67f8e8b2014-12-01 13:54:59 -08004105 */
4106 public static final String MIDI_SERVICE = "midi";
4107
Eric Laurent2035ac82015-03-05 15:18:44 -08004108
4109 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004110 * Use with {@link #getSystemService(String)} to retrieve a
Eric Laurent2035ac82015-03-05 15:18:44 -08004111 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
4112 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004113 * @see #getSystemService(String)
Eric Laurent2035ac82015-03-05 15:18:44 -08004114 * @hide
4115 */
Tomasz Wasilczyk9110df72017-06-22 07:57:20 -07004116 public static final String RADIO_SERVICE = "broadcastradio";
Eric Laurent2035ac82015-03-05 15:18:44 -08004117
Paul McLeana33be212015-02-20 07:52:45 -08004118 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004119 * Use with {@link #getSystemService(String)} to retrieve a
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004120 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
4121 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004122 * @see #getSystemService(String)
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004123 */
Polina Bondarenko8333c732016-03-09 18:08:42 +01004124 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
Polina Bondarenko965ecbb2015-11-13 15:34:28 +01004125
4126 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004127 * Use with {@link #getSystemService(String)} to retrieve a
Makoto Onukib5a012f2016-06-21 11:13:53 -07004128 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004129 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004130 * @see #getSystemService(String)
Makoto Onuki6f7362d92016-03-04 13:39:41 -08004131 * @see android.content.pm.ShortcutManager
4132 */
4133 public static final String SHORTCUT_SERVICE = "shortcut";
4134
4135 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004136 * Use with {@link #getSystemService(String)} to retrieve a {@link
Peng Xu9ff7d222016-02-11 13:02:05 -08004137 * android.hardware.location.ContextHubManager} for accessing context hubs.
4138 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004139 * @see #getSystemService(String)
Peng Xu9ff7d222016-02-11 13:02:05 -08004140 * @see android.hardware.location.ContextHubManager
4141 *
4142 * @hide
4143 */
4144 @SystemApi
4145 public static final String CONTEXTHUB_SERVICE = "contexthub";
4146
4147 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004148 * Use with {@link #getSystemService(String)} to retrieve a
Joe Onorato713fec82016-03-04 10:34:02 -08004149 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
4150 * memory, etc) metrics.
4151 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004152 * @see #getSystemService(String)
Joe Onorato713fec82016-03-04 10:34:02 -08004153 */
4154 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
4155
4156 /**
Amith Yamasanid04aaa32016-06-13 12:09:36 -07004157 * Gatekeeper Service.
4158 * @hide
4159 */
4160 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
4161
4162 /**
Svet Ganov37e43272016-09-09 16:01:32 -07004163 * Service defining the policy for access to device identifiers.
4164 * @hide
4165 */
4166 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
4167
4168 /**
Joe Onorato1754d742016-11-21 17:51:35 -08004169 * Service to report a system health "incident"
4170 * @hide
4171 */
4172 public static final String INCIDENT_SERVICE = "incident";
4173
4174 /**
Bookatz94726412017-08-31 09:26:15 -07004175 * Service to assist statsd in obtaining general stats.
4176 * @hide
4177 */
4178 public static final String STATS_COMPANION_SERVICE = "statscompanion";
4179
4180 /**
Bookatzc6977972018-01-16 16:55:05 -08004181 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
David Chenadaf8b32017-11-03 15:42:08 -07004182 * @hide
4183 */
4184 @SystemApi
4185 public static final String STATS_MANAGER = "stats";
4186
4187 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004188 * Use with {@link #getSystemService(String)} to retrieve a {@link
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004189 * android.content.om.OverlayManager} for managing overlay packages.
4190 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004191 * @see #getSystemService(String)
MÃ¥rten Kongstadeabc9e92015-12-15 16:40:23 +01004192 * @see android.content.om.OverlayManager
4193 * @hide
4194 */
4195 public static final String OVERLAY_SERVICE = "overlay";
4196
4197 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004198 * Use with {@link #getSystemService(String)} to retrieve a
Zak Cohen56345f42017-01-26 13:54:28 -08004199 * {@link VrManager} for accessing the VR service.
4200 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004201 * @see #getSystemService(String)
Zak Cohen56345f42017-01-26 13:54:28 -08004202 * @hide
4203 */
4204 @SystemApi
4205 public static final String VR_SERVICE = "vrmanager";
4206
4207 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004208 * Use with {@link #getSystemService(String)} to retrieve an
Neil Fullerfe6ec562017-03-16 18:29:36 +00004209 * {@link android.app.timezone.ITimeZoneRulesManager}.
4210 * @hide
4211 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004212 * @see #getSystemService(String)
Neil Fullerfe6ec562017-03-16 18:29:36 +00004213 */
4214 public static final String TIME_ZONE_RULES_MANAGER_SERVICE = "timezone";
4215
4216 /**
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004217 * Use with {@link #getSystemService(String)} to retrieve a
Tony Makb0d22622018-01-18 12:49:49 +00004218 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
Tony Mak1b708e62017-10-12 10:59:11 +01004219 *
Ng Zhi Anf7c1e2b2018-01-08 11:18:08 -08004220 * @see #getSystemService(String)
Tony Mak1b708e62017-10-12 10:59:11 +01004221 */
4222 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
4223
4224 /**
Ruchi Kandoi6149b0f2018-01-03 16:14:57 -08004225 * Use with {@link #getSystemService} to retrieve a
4226 * {@link android.se.omapi.ISecureElementService}
4227 * for accessing the SecureElementService.
4228 *
4229 * @hide
4230 */
4231 @SystemApi
4232 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
4233
4234 /**
Neil Fullerb5579072018-05-30 14:35:24 +01004235 * Use with {@link #getSystemService(String)} to retrieve an
4236 * {@link android.app.timedetector.ITimeDetectorService}.
4237 * @hide
4238 *
4239 * @see #getSystemService(String)
4240 */
4241 public static final String TIME_DETECTOR_SERVICE = "time_detector";
4242
4243 /**
Neil Fullercccc48d2018-06-19 12:53:47 +01004244 * Use with {@link #getSystemService(String)} to retrieve an
4245 * {@link android.app.timezonedetector.ITimeZoneDetectorService}.
4246 * @hide
4247 *
4248 * @see #getSystemService(String)
4249 */
4250 public static final String TIME_ZONE_DETECTOR_SERVICE = "time_zone_detector";
4251
4252 /**
Sahin Caliskan12564862018-10-31 13:23:29 -07004253 * Use with {@link #getSystemService(String)} to retrieve an
4254 * {@link android.telephony.rcs.RcsManager}.
4255 * @hide
4256 */
4257 public static final String TELEPHONY_RCS_SERVICE = "ircs";
4258
4259 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004260 * Determine whether the given permission is allowed for a particular
4261 * process and user ID running in the system.
4262 *
4263 * @param permission The name of the permission being checked.
4264 * @param pid The process ID being checked against. Must be > 0.
4265 * @param uid The user ID being checked against. A uid of 0 is the root
4266 * user, which will pass every permission check.
4267 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004268 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004269 * pid/uid is allowed that permission, or
4270 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4271 *
4272 * @see PackageManager#checkPermission(String, String)
4273 * @see #checkCallingPermission
4274 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004275 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004276 @PackageManager.PermissionResult
4277 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004278
Dianne Hackbornff170242014-11-19 10:59:01 -08004279 /** @hide */
4280 @PackageManager.PermissionResult
Mathew Inwood1c77a112018-08-14 14:06:26 +01004281 @UnsupportedAppUsage
Dianne Hackbornff170242014-11-19 10:59:01 -08004282 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
4283 IBinder callerToken);
4284
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004285 /**
4286 * Determine whether the calling process of an IPC you are handling has been
4287 * granted a particular permission. This is basically the same as calling
4288 * {@link #checkPermission(String, int, int)} with the pid and uid returned
4289 * by {@link android.os.Binder#getCallingPid} and
4290 * {@link android.os.Binder#getCallingUid}. One important difference
4291 * is that if you are not currently processing an IPC, this function
4292 * will always fail. This is done to protect against accidentally
4293 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
4294 * to avoid this protection.
4295 *
4296 * @param permission The name of the permission being checked.
4297 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004298 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004299 * pid/uid is allowed that permission, or
4300 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4301 *
4302 * @see PackageManager#checkPermission(String, String)
4303 * @see #checkPermission
4304 * @see #checkCallingOrSelfPermission
4305 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004306 @CheckResult(suggest="#enforceCallingPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004307 @PackageManager.PermissionResult
4308 public abstract int checkCallingPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004309
4310 /**
4311 * Determine whether the calling process of an IPC <em>or you</em> have been
4312 * granted a particular permission. This is the same as
4313 * {@link #checkCallingPermission}, except it grants your own permissions
4314 * if you are not currently processing an IPC. Use with care!
4315 *
4316 * @param permission The name of the permission being checked.
4317 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004318 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004319 * pid/uid is allowed that permission, or
4320 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4321 *
4322 * @see PackageManager#checkPermission(String, String)
4323 * @see #checkPermission
4324 * @see #checkCallingPermission
4325 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004326 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
Tor Norbyed9273d62013-05-30 15:59:53 -07004327 @PackageManager.PermissionResult
4328 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004329
4330 /**
Svetoslavc6d1c342015-02-26 14:44:43 -08004331 * Determine whether <em>you</em> have been granted a particular permission.
4332 *
4333 * @param permission The name of the permission being checked.
4334 *
4335 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
4336 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
4337 *
4338 * @see PackageManager#checkPermission(String, String)
4339 * @see #checkCallingPermission(String)
4340 */
4341 @PackageManager.PermissionResult
4342 public abstract int checkSelfPermission(@NonNull String permission);
4343
4344 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004345 * If the given permission is not allowed for a particular process
4346 * and user ID running in the system, throw a {@link SecurityException}.
4347 *
4348 * @param permission The name of the permission being checked.
4349 * @param pid The process ID being checked against. Must be &gt; 0.
4350 * @param uid The user ID being checked against. A uid of 0 is the root
4351 * user, which will pass every permission check.
4352 * @param message A message to include in the exception if it is thrown.
4353 *
4354 * @see #checkPermission(String, int, int)
4355 */
4356 public abstract void enforcePermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004357 @NonNull String permission, int pid, int uid, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004358
4359 /**
4360 * If the calling process of an IPC you are handling has not been
4361 * granted a particular permission, throw a {@link
4362 * SecurityException}. This is basically the same as calling
4363 * {@link #enforcePermission(String, int, int, String)} with the
4364 * pid and uid returned by {@link android.os.Binder#getCallingPid}
4365 * and {@link android.os.Binder#getCallingUid}. One important
4366 * difference is that if you are not currently processing an IPC,
4367 * this function will always throw the SecurityException. This is
4368 * done to protect against accidentally leaking permissions; you
4369 * can use {@link #enforceCallingOrSelfPermission} to avoid this
4370 * protection.
4371 *
4372 * @param permission The name of the permission being checked.
4373 * @param message A message to include in the exception if it is thrown.
4374 *
4375 * @see #checkCallingPermission(String)
4376 */
4377 public abstract void enforceCallingPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004378 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004379
4380 /**
4381 * If neither you nor the calling process of an IPC you are
4382 * handling has been granted a particular permission, throw a
4383 * {@link SecurityException}. This is the same as {@link
4384 * #enforceCallingPermission}, except it grants your own
4385 * permissions if you are not currently processing an IPC. Use
4386 * with care!
4387 *
4388 * @param permission The name of the permission being checked.
4389 * @param message A message to include in the exception if it is thrown.
4390 *
4391 * @see #checkCallingOrSelfPermission(String)
4392 */
4393 public abstract void enforceCallingOrSelfPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004394 @NonNull String permission, @Nullable String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004395
4396 /**
4397 * Grant permission to access a specific Uri to another package, regardless
4398 * of whether that package has general permission to access the Uri's
4399 * content provider. This can be used to grant specific, temporary
4400 * permissions, typically in response to user interaction (such as the
4401 * user opening an attachment that you would like someone else to
4402 * display).
4403 *
4404 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
4405 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
4406 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
4407 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
4408 * start an activity instead of this function directly. If you use this
4409 * function directly, you should be sure to call
4410 * {@link #revokeUriPermission} when the target should no longer be allowed
4411 * to access it.
4412 *
4413 * <p>To succeed, the content provider owning the Uri must have set the
4414 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
4415 * grantUriPermissions} attribute in its manifest or included the
4416 * {@link android.R.styleable#AndroidManifestGrantUriPermission
4417 * &lt;grant-uri-permissions&gt;} tag.
4418 *
4419 * @param toPackage The package you would like to allow to access the Uri.
4420 * @param uri The Uri you would like to grant access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004421 * @param modeFlags The desired access modes.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004422 *
4423 * @see #revokeUriPermission
4424 */
4425 public abstract void grantUriPermission(String toPackage, Uri uri,
Tor Norbyed9273d62013-05-30 15:59:53 -07004426 @Intent.GrantUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004427
4428 /**
4429 * Remove all permissions to access a particular content provider Uri
Dianne Hackborna47223f2017-03-30 13:49:13 -07004430 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
4431 * The given Uri will match all previously granted Uris that are the same or a
Jeff Sharkey328ebf22013-03-21 18:09:39 -07004432 * sub-path of the given Uri. That is, revoking "content://foo/target" will
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004433 * revoke both "content://foo/target" and "content://foo/target/sub", but not
Jeff Sharkey846318a2014-04-04 12:12:41 -07004434 * "content://foo". It will not remove any prefix grants that exist at a
4435 * higher level.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004436 *
Dianne Hackborn955d8d62014-10-07 20:17:19 -07004437 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
Dianne Hackborn192679a2014-09-10 14:28:48 -07004438 * regular permission access to a Uri, but had received access to it through
4439 * a specific Uri permission grant, you could not revoke that grant with this
4440 * function and a {@link SecurityException} would be thrown. As of
Dianne Hackborna47223f2017-03-30 13:49:13 -07004441 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
4442 * exception, but will remove whatever permission grants to the Uri had been given to the app
Dianne Hackborn192679a2014-09-10 14:28:48 -07004443 * (or none).</p>
4444 *
Dianne Hackborna47223f2017-03-30 13:49:13 -07004445 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
4446 * grants matching the given Uri, for any package they had been granted to, through any
4447 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
4448 * service start, etc). That means this can be potentially dangerous to use, as it can
4449 * revoke grants that another app could be strongly expecting to stick around.</p>
4450 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004451 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004452 * @param modeFlags The access modes to revoke.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004453 *
4454 * @see #grantUriPermission
4455 */
Jeff Sharkey846318a2014-04-04 12:12:41 -07004456 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004457
4458 /**
Dianne Hackborna47223f2017-03-30 13:49:13 -07004459 * Remove permissions to access a particular content provider Uri
4460 * that were previously added with {@link #grantUriPermission} for a specific target
4461 * package. The given Uri will match all previously granted Uris that are the same or a
4462 * sub-path of the given Uri. That is, revoking "content://foo/target" will
4463 * revoke both "content://foo/target" and "content://foo/target/sub", but not
4464 * "content://foo". It will not remove any prefix grants that exist at a
4465 * higher level.
4466 *
4467 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
4468 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
4469 * and only for the package specified. Any matching grants that have happened through
4470 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
4471 * removed.</p>
4472 *
4473 * @param toPackage The package you had previously granted access to.
4474 * @param uri The Uri you would like to revoke access to.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004475 * @param modeFlags The access modes to revoke.
Dianne Hackborna47223f2017-03-30 13:49:13 -07004476 *
4477 * @see #grantUriPermission
4478 */
4479 public abstract void revokeUriPermission(String toPackage, Uri uri,
4480 @Intent.AccessUriMode int modeFlags);
4481
4482 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004483 * Determine whether a particular process and user ID has been granted
4484 * permission to access a specific URI. This only checks for permissions
4485 * that have been explicitly granted -- if the given process/uid has
4486 * more general access to the URI's content provider then this check will
4487 * always fail.
4488 *
4489 * @param uri The uri that is being checked.
4490 * @param pid The process ID being checked against. Must be &gt; 0.
4491 * @param uid The user ID being checked against. A uid of 0 is the root
4492 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004493 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004494 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004495 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004496 * pid/uid is allowed to access that uri, or
4497 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4498 *
4499 * @see #checkCallingUriPermission
4500 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004501 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004502 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004503 public abstract int checkUriPermission(Uri uri, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004504 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004505
Dianne Hackbornff170242014-11-19 10:59:01 -08004506 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004507 @PackageManager.PermissionResult
Dianne Hackbornff170242014-11-19 10:59:01 -08004508 public abstract int checkUriPermission(Uri uri, int pid, int uid,
4509 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
4510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004511 /**
4512 * Determine whether the calling process and user ID has been
4513 * granted permission to access a specific URI. This is basically
4514 * the same as calling {@link #checkUriPermission(Uri, int, int,
4515 * int)} with the pid and uid returned by {@link
4516 * android.os.Binder#getCallingPid} and {@link
4517 * android.os.Binder#getCallingUid}. One important difference is
4518 * that if you are not currently processing an IPC, this function
4519 * will always fail.
4520 *
4521 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004522 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004523 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004524 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004525 * is allowed to access that uri, or
4526 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4527 *
4528 * @see #checkUriPermission(Uri, int, int, int)
4529 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004530 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004531 @PackageManager.PermissionResult
Jeff Sharkey846318a2014-04-04 12:12:41 -07004532 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004533
4534 /**
4535 * Determine whether the calling process of an IPC <em>or you</em> has been granted
4536 * permission to access a specific URI. This is the same as
4537 * {@link #checkCallingUriPermission}, except it grants your own permissions
4538 * if you are not currently processing an IPC. Use with care!
4539 *
4540 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004541 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004542 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004543 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004544 * is allowed to access that uri, or
4545 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4546 *
4547 * @see #checkCallingUriPermission
4548 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004549 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004550 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004551 public abstract int checkCallingOrSelfUriPermission(Uri uri,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004552 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004553
4554 /**
4555 * Check both a Uri and normal permission. This allows you to perform
4556 * both {@link #checkPermission} and {@link #checkUriPermission} in one
4557 * call.
4558 *
4559 * @param uri The Uri whose permission is to be checked, or null to not
4560 * do this check.
4561 * @param readPermission The permission that provides overall read access,
4562 * or null to not do this check.
4563 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004564 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004565 * @param pid The process ID being checked against. Must be &gt; 0.
4566 * @param uid The user ID being checked against. A uid of 0 is the root
4567 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004568 * @param modeFlags The access modes to check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004569 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004570 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004571 * is allowed to access that uri or holds one of the given permissions, or
4572 * {@link PackageManager#PERMISSION_DENIED} if it is not.
4573 */
Tor Norbye1c2bf032015-03-02 10:57:08 -08004574 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004575 @PackageManager.PermissionResult
Tor Norbyed9273d62013-05-30 15:59:53 -07004576 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
4577 @Nullable String writePermission, int pid, int uid,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004578 @Intent.AccessUriMode int modeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004579
4580 /**
4581 * If a particular process and user ID has not been granted
4582 * permission to access a specific URI, throw {@link
4583 * SecurityException}. This only checks for permissions that have
4584 * been explicitly granted -- if the given process/uid has more
4585 * general access to the URI's content provider then this check
4586 * will always fail.
4587 *
4588 * @param uri The uri that is being checked.
4589 * @param pid The process ID being checked against. Must be &gt; 0.
4590 * @param uid The user ID being checked against. A uid of 0 is the root
4591 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004592 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004593 * @param message A message to include in the exception if it is thrown.
4594 *
4595 * @see #checkUriPermission(Uri, int, int, int)
4596 */
4597 public abstract void enforceUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004598 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004599
4600 /**
4601 * If the calling process and user ID has not been granted
4602 * permission to access a specific URI, throw {@link
4603 * SecurityException}. This is basically the same as calling
4604 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
4605 * the pid and uid returned by {@link
4606 * android.os.Binder#getCallingPid} and {@link
4607 * android.os.Binder#getCallingUid}. One important difference is
4608 * that if you are not currently processing an IPC, this function
4609 * will always throw a SecurityException.
4610 *
4611 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004612 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004613 * @param message A message to include in the exception if it is thrown.
4614 *
4615 * @see #checkCallingUriPermission(Uri, int)
4616 */
4617 public abstract void enforceCallingUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004618 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004619
4620 /**
4621 * If the calling process of an IPC <em>or you</em> has not been
4622 * granted permission to access a specific URI, throw {@link
4623 * SecurityException}. This is the same as {@link
4624 * #enforceCallingUriPermission}, except it grants your own
4625 * permissions if you are not currently processing an IPC. Use
4626 * with care!
Scott Main4b5da682010-10-21 11:49:12 -07004627 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004628 * @param uri The uri that is being checked.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004629 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004630 * @param message A message to include in the exception if it is thrown.
4631 *
4632 * @see #checkCallingOrSelfUriPermission(Uri, int)
4633 */
4634 public abstract void enforceCallingOrSelfUriPermission(
Jeff Sharkey846318a2014-04-04 12:12:41 -07004635 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004636
4637 /**
4638 * Enforce both a Uri and normal permission. This allows you to perform
4639 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
4640 * call.
Scott Main4b5da682010-10-21 11:49:12 -07004641 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004642 * @param uri The Uri whose permission is to be checked, or null to not
4643 * do this check.
4644 * @param readPermission The permission that provides overall read access,
4645 * or null to not do this check.
4646 * @param writePermission The permission that provides overall write
Tor Norbyed9273d62013-05-30 15:59:53 -07004647 * access, or null to not do this check.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004648 * @param pid The process ID being checked against. Must be &gt; 0.
4649 * @param uid The user ID being checked against. A uid of 0 is the root
4650 * user, which will pass every permission check.
Jeff Sharkey6503bd82017-04-19 23:24:18 -06004651 * @param modeFlags The access modes to enforce.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004652 * @param message A message to include in the exception if it is thrown.
4653 *
4654 * @see #checkUriPermission(Uri, String, String, int, int, int)
4655 */
4656 public abstract void enforceUriPermission(
Tor Norbyed9273d62013-05-30 15:59:53 -07004657 @Nullable Uri uri, @Nullable String readPermission,
Jeff Sharkey846318a2014-04-04 12:12:41 -07004658 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
Tor Norbyed9273d62013-05-30 15:59:53 -07004659 @Nullable String message);
4660
4661 /** @hide */
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004662 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
4663 CONTEXT_INCLUDE_CODE,
4664 CONTEXT_IGNORE_SECURITY,
4665 CONTEXT_RESTRICTED,
4666 CONTEXT_DEVICE_PROTECTED_STORAGE,
4667 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
4668 CONTEXT_REGISTER_PACKAGE,
4669 })
Tor Norbyed9273d62013-05-30 15:59:53 -07004670 @Retention(RetentionPolicy.SOURCE)
4671 public @interface CreatePackageOptions {}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004672
4673 /**
4674 * Flag for use with {@link #createPackageContext}: include the application
4675 * code with the context. This means loading code into the caller's
4676 * process, so that {@link #getClassLoader()} can be used to instantiate
4677 * the application's classes. Setting this flags imposes security
4678 * restrictions on what application context you can access; if the
4679 * requested application can not be safely loaded into your process,
4680 * java.lang.SecurityException will be thrown. If this flag is not set,
4681 * there will be no restrictions on the packages that can be loaded,
4682 * but {@link #getClassLoader} will always return the default system
4683 * class loader.
4684 */
4685 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
4686
4687 /**
4688 * Flag for use with {@link #createPackageContext}: ignore any security
4689 * restrictions on the Context being requested, allowing it to always
4690 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
4691 * to be loaded into a process even when it isn't safe to do so. Use
4692 * with extreme care!
4693 */
4694 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
Scott Main4b5da682010-10-21 11:49:12 -07004695
Romain Guy870e09f2009-07-06 16:35:25 -07004696 /**
4697 * Flag for use with {@link #createPackageContext}: a restricted context may
4698 * disable specific features. For instance, a View associated with a restricted
4699 * context would ignore particular XML attributes.
4700 */
4701 public static final int CONTEXT_RESTRICTED = 0x00000004;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004702
4703 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004704 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004705 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004706 *
4707 * @hide
4708 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004709 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004710
4711 /**
4712 * Flag for use with {@link #createPackageContext}: point all file APIs at
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004713 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004714 *
4715 * @hide
4716 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004717 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004718
4719 /**
Dianne Hackbornfee756f2014-07-16 17:31:10 -07004720 * @hide Used to indicate we should tell the activity manager about the process
4721 * loading this code.
4722 */
4723 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
4724
4725 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004726 * Return a new Context object for the given application name. This
4727 * Context is the same as what the named application gets when it is
4728 * launched, containing the same resources and class loader. Each call to
4729 * this method returns a new instance of a Context object; Context objects
4730 * are not shared, however they share common state (Resources, ClassLoader,
4731 * etc) so the Context instance itself is fairly lightweight.
4732 *
Jeff Brown6e539312015-02-24 18:53:21 -08004733 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004734 * application with the given package name.
4735 *
4736 * <p>Throws {@link java.lang.SecurityException} if the Context requested
4737 * can not be loaded into the caller's process for security reasons (see
4738 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
4739 *
4740 * @param packageName Name of the application's package.
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004741 * @param flags Option flags.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004742 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004743 * @return A {@link Context} for the application.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004744 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004745 * @throws SecurityException &nbsp;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004746 * @throws PackageManager.NameNotFoundException if there is no application with
John Spurlock6098c5d2013-06-17 10:32:46 -04004747 * the given package name.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004748 */
4749 public abstract Context createPackageContext(String packageName,
Tor Norbyed9273d62013-05-30 15:59:53 -07004750 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Romain Guy870e09f2009-07-06 16:35:25 -07004751
4752 /**
Jeff Sharkey6d515712012-09-20 16:06:08 -07004753 * Similar to {@link #createPackageContext(String, int)}, but with a
4754 * different {@link UserHandle}. For example, {@link #getContentResolver()}
4755 * will open any {@link Uri} as the given user.
4756 *
4757 * @hide
4758 */
Patrick Baumannef4c4072018-02-01 08:54:05 -08004759 @SystemApi
4760 public Context createPackageContextAsUser(
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004761 String packageName, @CreatePackageOptions int flags, UserHandle user)
Patrick Baumannef4c4072018-02-01 08:54:05 -08004762 throws PackageManager.NameNotFoundException {
4763 if (Build.IS_ENG) {
4764 throw new IllegalStateException("createPackageContextAsUser not overridden!");
4765 }
4766 return this;
4767 }
Jeff Sharkey6d515712012-09-20 16:06:08 -07004768
4769 /**
Svetoslav976e8bd2014-07-16 15:12:03 -07004770 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
4771 *
4772 * @hide
4773 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01004774 @UnsupportedAppUsage
Svetoslav976e8bd2014-07-16 15:12:03 -07004775 public abstract Context createApplicationContext(ApplicationInfo application,
Jeff Sharkey30e06bb2017-04-24 11:18:03 -06004776 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
Svetoslav976e8bd2014-07-16 15:12:03 -07004777
4778 /**
Adam Lesinski4e862812016-11-21 16:02:24 -08004779 * Return a new Context object for the given split name. The new Context has a ClassLoader and
4780 * Resources object that can access the split's and all of its dependencies' code/resources.
4781 * Each call to this method returns a new instance of a Context object;
4782 * Context objects are not shared, however common state (ClassLoader, other Resources for
4783 * the same split) may be so the Context itself can be fairly lightweight.
4784 *
4785 * @param splitName The name of the split to include, as declared in the split's
4786 * <code>AndroidManifest.xml</code>.
4787 * @return A {@link Context} with the given split's code and/or resources loaded.
4788 */
4789 public abstract Context createContextForSplit(String splitName)
4790 throws PackageManager.NameNotFoundException;
4791
4792 /**
Jeff Sharkeyad357d12018-02-02 13:25:31 -07004793 * Get the user associated with this context
Jim Millera75a8832013-02-07 16:53:32 -08004794 * @hide
4795 */
Jeff Sharkeya73b8fd2016-01-06 17:02:08 -07004796 @TestApi
Jeff Sharkeyad357d12018-02-02 13:25:31 -07004797 public UserHandle getUser() {
4798 return android.os.Process.myUserHandle();
4799 }
4800
4801 /**
4802 * Get the user associated with this context
4803 * @hide
4804 */
4805 @TestApi
4806 public @UserIdInt int getUserId() {
4807 return android.os.UserHandle.myUserId();
4808 }
Jim Millera75a8832013-02-07 16:53:32 -08004809
4810 /**
Dianne Hackborn756220b2012-08-14 16:45:30 -07004811 * Return a new Context object for the current Context but whose resources
4812 * are adjusted to match the given Configuration. Each call to this method
Jeff Browna492c3a2012-08-23 19:48:44 -07004813 * returns a new instance of a Context object; Context objects are not
Dianne Hackborn756220b2012-08-14 16:45:30 -07004814 * shared, however common state (ClassLoader, other Resources for the
4815 * same configuration) may be so the Context itself can be fairly lightweight.
4816 *
4817 * @param overrideConfiguration A {@link Configuration} specifying what
4818 * values to modify in the base Configuration of the original Context's
4819 * resources. If the base configuration changes (such as due to an
4820 * orientation change), the resources of this context will also change except
4821 * for those that have been explicitly overridden with a value here.
4822 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004823 * @return A {@link Context} with the given configuration override.
Dianne Hackborn756220b2012-08-14 16:45:30 -07004824 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004825 public abstract Context createConfigurationContext(
4826 @NonNull Configuration overrideConfiguration);
Dianne Hackborn756220b2012-08-14 16:45:30 -07004827
4828 /**
Jeff Browna492c3a2012-08-23 19:48:44 -07004829 * Return a new Context object for the current Context but whose resources
4830 * are adjusted to match the metrics of the given Display. Each call to this method
4831 * returns a new instance of a Context object; Context objects are not
4832 * shared, however common state (ClassLoader, other Resources for the
4833 * same configuration) may be so the Context itself can be fairly lightweight.
4834 *
4835 * The returned display Context provides a {@link WindowManager}
4836 * (see {@link #getSystemService(String)}) that is configured to show windows
4837 * on the given display. The WindowManager's {@link WindowManager#getDefaultDisplay}
4838 * method can be used to retrieve the Display from the returned Context.
4839 *
4840 * @param display A {@link Display} object specifying the display
4841 * for whose metrics the Context's resources should be tailored and upon which
4842 * new windows should be shown.
4843 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004844 * @return A {@link Context} for the display.
Jeff Browna492c3a2012-08-23 19:48:44 -07004845 */
Tor Norbyed9273d62013-05-30 15:59:53 -07004846 public abstract Context createDisplayContext(@NonNull Display display);
Jeff Browna492c3a2012-08-23 19:48:44 -07004847
4848 /**
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004849 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004850 * APIs are backed by device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004851 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004852 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004853 * with a key tied to the physical device, and it can be accessed
4854 * immediately after the device has booted successfully, both
4855 * <em>before and after</em> the user has authenticated with their
4856 * credentials (such as a lock pattern or PIN).
4857 * <p>
4858 * Because device-protected data is available without user authentication,
4859 * you should carefully limit the data you store using this Context. For
4860 * example, storing sensitive authentication tokens or passwords in the
4861 * device-protected area is strongly discouraged.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004862 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004863 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004864 * device-protected and credential-protected data using different keys, then
4865 * both storage areas will become available at the same time. They remain as
4866 * two distinct storage locations on disk, and only the window of
4867 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004868 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004869 * Each call to this method returns a new instance of a Context object;
4870 * Context objects are not shared, however common state (ClassLoader, other
4871 * Resources for the same configuration) may be so the Context itself can be
4872 * fairly lightweight.
4873 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004874 * @see #isDeviceProtectedStorage()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004875 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004876 public abstract Context createDeviceProtectedStorageContext();
4877
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004878 /**
4879 * Return a new Context object for the current Context but whose storage
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004880 * APIs are backed by credential-protected storage. This is the default
4881 * storage area for apps unless
4882 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004883 * <p>
Jeff Sharkeycf3f0a12016-03-17 19:57:58 -06004884 * On devices with direct boot, data stored in this location is encrypted
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004885 * with a key tied to user credentials, which can be accessed
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004886 * <em>only after</em> the user has entered their credentials (such as a
4887 * lock pattern or PIN).
4888 * <p>
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004889 * If the underlying device does not have the ability to store
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004890 * device-protected and credential-protected data using different keys, then
4891 * both storage areas will become available at the same time. They remain as
4892 * two distinct storage locations on disk, and only the window of
4893 * availability changes.
Jeff Sharkey3ea44a52016-01-09 15:19:56 -07004894 * <p>
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004895 * Each call to this method returns a new instance of a Context object;
4896 * Context objects are not shared, however common state (ClassLoader, other
4897 * Resources for the same configuration) may be so the Context itself can be
4898 * fairly lightweight.
4899 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004900 * @see #isCredentialProtectedStorage()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004901 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004902 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004903 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004904 public abstract Context createCredentialProtectedStorageContext();
4905
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004906 /**
Craig Mautner48d0d182013-06-11 07:53:06 -07004907 * Gets the display adjustments holder for this context. This information
4908 * is provided on a per-application or activity basis and is used to simulate lower density
4909 * display metrics for legacy applications and restricted screen sizes.
Jeff Brown98365d72012-08-19 20:30:52 -07004910 *
Jeff Browna492c3a2012-08-23 19:48:44 -07004911 * @param displayId The display id for which to get compatibility info.
Jeff Brown98365d72012-08-19 20:30:52 -07004912 * @return The compatibility info holder, or null if not required by the application.
4913 * @hide
4914 */
Craig Mautner48d0d182013-06-11 07:53:06 -07004915 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
Jeff Brown98365d72012-08-19 20:30:52 -07004916
4917 /**
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004918 * @hide
4919 */
Mathew Inwood1c77a112018-08-14 14:06:26 +01004920 @UnsupportedAppUsage
Adam Lesinski4ece3d62016-06-16 18:05:41 -07004921 public abstract Display getDisplay();
4922
4923 /**
Andrii Kulianb047b8b2017-02-08 18:38:26 -08004924 * @hide
4925 */
4926 public abstract void updateDisplay(int displayId);
4927
4928 /**
Romain Guy870e09f2009-07-06 16:35:25 -07004929 * Indicates whether this Context is restricted.
Scott Main4b5da682010-10-21 11:49:12 -07004930 *
John Spurlock6098c5d2013-06-17 10:32:46 -04004931 * @return {@code true} if this Context is restricted, {@code false} otherwise.
Scott Main4b5da682010-10-21 11:49:12 -07004932 *
Romain Guy870e09f2009-07-06 16:35:25 -07004933 * @see #CONTEXT_RESTRICTED
4934 */
4935 public boolean isRestricted() {
4936 return false;
4937 }
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004938
4939 /**
4940 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004941 * device-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004942 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004943 * @see #createDeviceProtectedStorageContext()
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004944 */
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004945 public abstract boolean isDeviceProtectedStorage();
4946
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004947 /**
4948 * Indicates if the storage APIs of this Context are backed by
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004949 * credential-protected storage.
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004950 *
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004951 * @see #createCredentialProtectedStorageContext()
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004952 * @hide
Jeff Sharkey7a30a302015-12-08 14:20:06 -07004953 */
Jeff Sharkeye13529a2015-12-09 14:15:27 -07004954 @SystemApi
Jeff Sharkey8a372a02016-03-16 16:25:45 -06004955 public abstract boolean isCredentialProtectedStorage();
4956
Tony Mak46aabe52016-11-14 12:53:06 +00004957 /**
Seigo Nonaka6d6cd682017-06-22 08:22:18 -07004958 * Returns true if the context can load unsafe resources, e.g. fonts.
4959 * @hide
4960 */
4961 public abstract boolean canLoadUnsafeResources();
4962
4963 /**
Tony Mak46aabe52016-11-14 12:53:06 +00004964 * @hide
4965 */
4966 public IBinder getActivityToken() {
4967 throw new RuntimeException("Not implemented. Must override in a subclass.");
4968 }
4969
4970 /**
4971 * @hide
4972 */
4973 @Nullable
4974 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
4975 int flags) {
4976 throw new RuntimeException("Not implemented. Must override in a subclass.");
4977 }
4978
4979 /**
4980 * @hide
4981 */
4982 public IApplicationThread getIApplicationThread() {
4983 throw new RuntimeException("Not implemented. Must override in a subclass.");
4984 }
Tony Makbf9928d2016-12-22 11:02:45 +00004985
4986 /**
4987 * @hide
4988 */
4989 public Handler getMainThreadHandler() {
4990 throw new RuntimeException("Not implemented. Must override in a subclass.");
4991 }
Adam Lesinskia82b6262017-03-21 16:56:17 -07004992
4993 /**
Felipe Lemebb567ae2017-10-04 09:56:21 -07004994 * @hide
4995 */
4996 public AutofillClient getAutofillClient() {
4997 return null;
4998 }
4999
5000 /**
5001 * @hide
5002 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005003 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
Felipe Lemebb567ae2017-10-04 09:56:21 -07005004 }
5005
5006 /**
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005007 * @hide
5008 */
5009 public boolean isAutofillCompatibilityEnabled() {
5010 return false;
5011 }
5012
5013 /**
5014 * @hide
5015 */
Svet Ganov47b37aa2018-02-16 00:11:39 -08005016 @TestApi
5017 public void setAutofillCompatibilityEnabled(
5018 @SuppressWarnings("unused") boolean autofillCompatEnabled) {
Svetoslav Ganov24c90452017-12-27 15:17:14 -08005019 }
5020
5021 /**
Adam Lesinskia82b6262017-03-21 16:56:17 -07005022 * Throws an exception if the Context is using system resources,
5023 * which are non-runtime-overlay-themable and may show inconsistent UI.
5024 * @hide
5025 */
5026 public void assertRuntimeOverlayThemable() {
5027 // Resources.getSystem() is a singleton and the only Resources not managed by
5028 // ResourcesManager; therefore Resources.getSystem() is not themable.
5029 if (getResources() == Resources.getSystem()) {
5030 throw new IllegalArgumentException("Non-UI context used to display UI; "
5031 + "get a UI context from ActivityThread#getSystemUiContext()");
5032 }
5033 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08005034}