Debian Codegraph @

core/java/android/content/Context.java

raw symbols SCIP
1 /*
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
17 package android.content;
18
19 import android.annotation.AttrRes;
20 import android.annotation.CallbackExecutor;
21 import android.annotation.CheckResult;
22 import android.annotation.ColorInt;
23 import android.annotation.ColorRes;
24 import android.annotation.DisplayContext;
25 import android.annotation.DrawableRes;
26 import android.annotation.IntDef;
27 import android.annotation.NonNull;
28 import android.annotation.Nullable;
29 import android.annotation.RequiresPermission;
30 import android.annotation.StringDef;
31 import android.annotation.StringRes;
32 import android.annotation.StyleRes;
33 import android.annotation.StyleableRes;
34 import android.annotation.SuppressLint;
35 import android.annotation.SystemApi;
36 import android.annotation.TestApi;
37 import android.annotation.UiContext;
38 import android.annotation.UserIdInt;
39 import android.app.Activity;
40 import android.app.ActivityManager;
41 import android.app.BroadcastOptions;
42 import android.app.GameManager;
43 import android.app.IApplicationThread;
44 import android.app.IServiceConnection;
45 import android.app.VrManager;
46 import android.app.ambientcontext.AmbientContextManager;
47 import android.app.people.PeopleManager;
48 import android.app.time.TimeManager;
49 import android.compat.annotation.ChangeId;
50 import android.compat.annotation.EnabledSince;
51 import android.compat.annotation.UnsupportedAppUsage;
52 import android.content.pm.ApplicationInfo;
53 import android.content.pm.PackageManager;
54 import android.content.res.AssetManager;
55 import android.content.res.ColorStateList;
56 import android.content.res.Configuration;
57 import android.content.res.Resources;
58 import android.content.res.TypedArray;
59 import android.database.DatabaseErrorHandler;
60 import android.database.sqlite.SQLiteDatabase;
61 import android.database.sqlite.SQLiteDatabase.CursorFactory;
62 import android.graphics.Bitmap;
63 import android.graphics.drawable.Drawable;
64 import android.net.Uri;
65 import android.os.Build;
66 import android.os.Bundle;
67 import android.os.Environment;
68 import android.os.Handler;
69 import android.os.HandlerExecutor;
70 import android.os.IBinder;
71 import android.os.Looper;
72 import android.os.StatFs;
73 import android.os.UserHandle;
74 import android.os.UserManager;
75 import android.os.storage.StorageManager;
76 import android.provider.MediaStore;
77 import android.telephony.TelephonyRegistryManager;
78 import android.util.AttributeSet;
79 import android.view.Display;
80 import android.view.DisplayAdjustments;
81 import android.view.View;
82 import android.view.ViewDebug;
83 import android.view.ViewGroup.LayoutParams;
84 import android.view.WindowManager;
85 import android.view.WindowManager.LayoutParams.WindowType;
86 import android.view.autofill.AutofillManager.AutofillClient;
87 import android.view.contentcapture.ContentCaptureManager.ContentCaptureClient;
88 import android.view.textclassifier.TextClassificationManager;
89 import android.window.WindowContext;
90
91 import com.android.internal.annotations.VisibleForTesting;
92 import com.android.internal.compat.IPlatformCompat;
93 import com.android.internal.compat.IPlatformCompatNative;
94
95 import java.io.File;
96 import java.io.FileInputStream;
97 import java.io.FileNotFoundException;
98 import java.io.FileOutputStream;
99 import java.io.IOException;
100 import java.io.InputStream;
101 import java.lang.annotation.Retention;
102 import java.lang.annotation.RetentionPolicy;
103 import java.util.Collection;
104 import java.util.Collections;
105 import java.util.List;
106 import java.util.concurrent.Executor;
107 import java.util.function.Consumer;
108
109 /**
110 * Interface to global information about an application environment. This is
111 * an abstract class whose implementation is provided by
112 * the Android system. It
113 * allows access to application-specific resources and classes, as well as
114 * up-calls for application-level operations such as launching activities,
115 * broadcasting and receiving intents, etc.
116 */
117 public abstract class Context {
118 /**
119 * After {@link Build.VERSION_CODES#TIRAMISU},
120 * {@link #registerComponentCallbacks(ComponentCallbacks)} will add a {@link ComponentCallbacks}
121 * to {@link Activity} or {@link ContextWrapper#getBaseContext()} instead of always adding to
122 * {@link #getApplicationContext()}.
123 *
124 * @hide
125 */
126 @ChangeId
127 @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
128 @VisibleForTesting
129 public static final long OVERRIDABLE_COMPONENT_CALLBACKS = 193247900L;
130
131 /** @hide */
132 @IntDef(flag = true, prefix = { "MODE_" }, value = {
133 MODE_PRIVATE,
134 MODE_WORLD_READABLE,
135 MODE_WORLD_WRITEABLE,
136 MODE_APPEND,
137 })
138 @Retention(RetentionPolicy.SOURCE)
139 public @interface FileMode {}
140
141 /** @hide */
142 @IntDef(flag = true, prefix = { "MODE_" }, value = {
143 MODE_PRIVATE,
144 MODE_WORLD_READABLE,
145 MODE_WORLD_WRITEABLE,
146 MODE_MULTI_PROCESS,
147 })
148 @Retention(RetentionPolicy.SOURCE)
149 public @interface PreferencesMode {}
150
151 /** @hide */
152 @IntDef(flag = true, prefix = { "MODE_" }, value = {
153 MODE_PRIVATE,
154 MODE_WORLD_READABLE,
155 MODE_WORLD_WRITEABLE,
156 MODE_ENABLE_WRITE_AHEAD_LOGGING,
157 MODE_NO_LOCALIZED_COLLATORS,
158 })
159 @Retention(RetentionPolicy.SOURCE)
160 public @interface DatabaseMode {}
161
162 /**
163 * File creation mode: the default mode, where the created file can only
164 * be accessed by the calling application (or all applications sharing the
165 * same user ID).
166 */
167 public static final int MODE_PRIVATE = 0x0000;
168
169 /**
170 * File creation mode: allow all other applications to have read access to
171 * the created file.
172 * <p>
173 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
174 * mode throws a {@link SecurityException}.
175 *
176 * @deprecated Creating world-readable files is very dangerous, and likely
177 * to cause security holes in applications. It is strongly
178 * discouraged; instead, applications should use more formal
179 * mechanism for interactions such as {@link ContentProvider},
180 * {@link BroadcastReceiver}, and {@link android.app.Service}.
181 * There are no guarantees that this access mode will remain on
182 * a file, such as when it goes through a backup and restore.
183 * @see androidx.core.content.FileProvider
184 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
185 */
186 @Deprecated
187 public static final int MODE_WORLD_READABLE = 0x0001;
188
189 /**
190 * File creation mode: allow all other applications to have write access to
191 * the created file.
192 * <p>
193 * Starting from {@link android.os.Build.VERSION_CODES#N}, attempting to use this
194 * mode will throw a {@link SecurityException}.
195 *
196 * @deprecated Creating world-writable files is very dangerous, and likely
197 * to cause security holes in applications. It is strongly
198 * discouraged; instead, applications should use more formal
199 * mechanism for interactions such as {@link ContentProvider},
200 * {@link BroadcastReceiver}, and {@link android.app.Service}.
201 * There are no guarantees that this access mode will remain on
202 * a file, such as when it goes through a backup and restore.
203 * @see androidx.core.content.FileProvider
204 * @see Intent#FLAG_GRANT_WRITE_URI_PERMISSION
205 */
206 @Deprecated
207 public static final int MODE_WORLD_WRITEABLE = 0x0002;
208
209 /**
210 * File creation mode: for use with {@link #openFileOutput}, if the file
211 * already exists then write data to the end of the existing file
212 * instead of erasing it.
213 * @see #openFileOutput
214 */
215 public static final int MODE_APPEND = 0x8000;
216
217 /**
218 * SharedPreference loading flag: when set, the file on disk will
219 * be checked for modification even if the shared preferences
220 * instance is already loaded in this process. This behavior is
221 * sometimes desired in cases where the application has multiple
222 * processes, all writing to the same SharedPreferences file.
223 * Generally there are better forms of communication between
224 * processes, though.
225 *
226 * <p>This was the legacy (but undocumented) behavior in and
227 * before Gingerbread (Android 2.3) and this flag is implied when
228 * targeting such releases. For applications targeting SDK
229 * versions <em>greater than</em> Android 2.3, this flag must be
230 * explicitly set if desired.
231 *
232 * @see #getSharedPreferences
233 *
234 * @deprecated MODE_MULTI_PROCESS does not work reliably in
235 * some versions of Android, and furthermore does not provide any
236 * mechanism for reconciling concurrent modifications across
237 * processes. Applications should not attempt to use it. Instead,
238 * they should use an explicit cross-process data management
239 * approach such as {@link android.content.ContentProvider ContentProvider}.
240 */
241 @Deprecated
242 public static final int MODE_MULTI_PROCESS = 0x0004;
243
244 /**
245 * Database open flag: when set, the database is opened with write-ahead
246 * logging enabled by default.
247 *
248 * @see #openOrCreateDatabase(String, int, CursorFactory)
249 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
250 * @see SQLiteDatabase#enableWriteAheadLogging
251 */
252 public static final int MODE_ENABLE_WRITE_AHEAD_LOGGING = 0x0008;
253
254 /**
255 * Database open flag: when set, the database is opened without support for
256 * localized collators.
257 *
258 * @see #openOrCreateDatabase(String, int, CursorFactory)
259 * @see #openOrCreateDatabase(String, int, CursorFactory, DatabaseErrorHandler)
260 * @see SQLiteDatabase#NO_LOCALIZED_COLLATORS
261 */
262 public static final int MODE_NO_LOCALIZED_COLLATORS = 0x0010;
263
264 /** @hide */
265 @IntDef(flag = true, prefix = { "BIND_" }, value = {
266 BIND_AUTO_CREATE,
267 BIND_DEBUG_UNBIND,
268 BIND_NOT_FOREGROUND,
269 BIND_ABOVE_CLIENT,
270 BIND_ALLOW_OOM_MANAGEMENT,
271 BIND_WAIVE_PRIORITY,
272 BIND_IMPORTANT,
273 BIND_ADJUST_WITH_ACTIVITY,
274 BIND_NOT_PERCEPTIBLE,
275 BIND_INCLUDE_CAPABILITIES
276 })
277 @Retention(RetentionPolicy.SOURCE)
278 public @interface BindServiceFlags {}
279
280 /**
281 * Flag for {@link #bindService}: automatically create the service as long
282 * as the binding exists. Note that while this will create the service,
283 * its {@link android.app.Service#onStartCommand}
284 * method will still only be called due to an
285 * explicit call to {@link #startService}. Even without that, though,
286 * this still provides you with access to the service object while the
287 * service is created.
288 *
289 * <p>Note that prior to {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH},
290 * not supplying this flag would also impact how important the system
291 * consider's the target service's process to be. When set, the only way
292 * for it to be raised was by binding from a service in which case it will
293 * only be important when that activity is in the foreground. Now to
294 * achieve this behavior you must explicitly supply the new flag
295 * {@link #BIND_ADJUST_WITH_ACTIVITY}. For compatibility, old applications
296 * that don't specify {@link #BIND_AUTO_CREATE} will automatically have
297 * the flags {@link #BIND_WAIVE_PRIORITY} and
298 * {@link #BIND_ADJUST_WITH_ACTIVITY} set for them in order to achieve
299 * the same result.
300 */
301 public static final int BIND_AUTO_CREATE = 0x0001;
302
303 /**
304 * Flag for {@link #bindService}: include debugging help for mismatched
305 * calls to unbind. When this flag is set, the callstack of the following
306 * {@link #unbindService} call is retained, to be printed if a later
307 * incorrect unbind call is made. Note that doing this requires retaining
308 * information about the binding that was made for the lifetime of the app,
309 * resulting in a leak -- this should only be used for debugging.
310 */
311 public static final int BIND_DEBUG_UNBIND = 0x0002;
312
313 /**
314 * Flag for {@link #bindService}: don't allow this binding to raise
315 * the target service's process to the foreground scheduling priority.
316 * It will still be raised to at least the same memory priority
317 * as the client (so that its process will not be killable in any
318 * situation where the client is not killable), but for CPU scheduling
319 * purposes it may be left in the background. This only has an impact
320 * in the situation where the binding client is a foreground process
321 * and the target service is in a background process.
322 */
323 public static final int BIND_NOT_FOREGROUND = 0x0004;
324
325 /**
326 * Flag for {@link #bindService}: indicates that the client application
327 * binding to this service considers the service to be more important than
328 * the app itself. When set, the platform will try to have the out of
329 * memory killer kill the app before it kills the service it is bound to, though
330 * this is not guaranteed to be the case.
331 */
332 public static final int BIND_ABOVE_CLIENT = 0x0008;
333
334 /**
335 * Flag for {@link #bindService}: allow the process hosting the bound
336 * service to go through its normal memory management. It will be
337 * treated more like a running service, allowing the system to
338 * (temporarily) expunge the process if low on memory or for some other
339 * whim it may have, and being more aggressive about making it a candidate
340 * to be killed (and restarted) if running for a long time.
341 */
342 public static final int BIND_ALLOW_OOM_MANAGEMENT = 0x0010;
343
344 /**
345 * Flag for {@link #bindService}: don't impact the scheduling or
346 * memory management priority of the target service's hosting process.
347 * Allows the service's process to be managed on the background LRU list
348 * just like a regular application process in the background.
349 */
350 public static final int BIND_WAIVE_PRIORITY = 0x0020;
351
352 /**
353 * Flag for {@link #bindService}: this service is very important to
354 * the client, so should be brought to the foreground process level
355 * when the client is. Normally a process can only be raised to the
356 * visibility level by a client, even if that client is in the foreground.
357 */
358 public static final int BIND_IMPORTANT = 0x0040;
359
360 /**
361 * Flag for {@link #bindService}: If binding from an activity, allow the
362 * target service's process importance to be raised based on whether the
363 * activity is visible to the user, regardless whether another flag is
364 * used to reduce the amount that the client process's overall importance
365 * is used to impact it.
366 */
367 public static final int BIND_ADJUST_WITH_ACTIVITY = 0x0080;
368
369 /**
370 * Flag for {@link #bindService}: If binding from an app that is visible or user-perceptible,
371 * lower the target service's importance to below the perceptible level. This allows
372 * the system to (temporarily) expunge the bound process from memory to make room for more
373 * important user-perceptible processes.
374 */
375 public static final int BIND_NOT_PERCEPTIBLE = 0x00000100;
376
377 /**
378 * Flag for {@link #bindService}: If binding from an app that has specific capabilities
379 * due to its foreground state such as an activity or foreground service, then this flag will
380 * allow the bound app to get the same capabilities, as long as it has the required permissions
381 * as well.
382 *
383 * If binding from a top app and its target SDK version is at or above
384 * {@link android.os.Build.VERSION_CODES#R}, the app needs to
385 * explicitly use BIND_INCLUDE_CAPABILITIES flag to pass all capabilities to the service so the
386 * other app can have while-use-use access such as location, camera, microphone from background.
387 * If binding from a top app and its target SDK version is below
388 * {@link android.os.Build.VERSION_CODES#R}, BIND_INCLUDE_CAPABILITIES is implicit.
389 */
390 public static final int BIND_INCLUDE_CAPABILITIES = 0x000001000;
391
392 /*********** Public flags above this line ***********/
393 /*********** Hidden flags below this line ***********/
394
395 /**
396 * Flag for {@link #bindService}: This flag is only intended to be used by the system to
397 * indicate that a service binding is not considered as real package component usage and should
398 * not generate a {@link android.app.usage.UsageEvents.Event#APP_COMPONENT_USED} event in usage
399 * stats.
400 * @hide
401 */
402 public static final int BIND_NOT_APP_COMPONENT_USAGE = 0x00008000;
403
404 /**
405 * Flag for {@link #bindService}: allow the process hosting the target service to be treated
406 * as if it's as important as a perceptible app to the user and avoid the oom killer killing
407 * this process in low memory situations until there aren't any other processes left but the
408 * ones which are user-perceptible.
409 *
410 * @hide
411 */
412 public static final int BIND_ALMOST_PERCEPTIBLE = 0x000010000;
413
414 /**
415 * Flag for {@link #bindService}: allow the process hosting the target service to gain
416 * {@link ActivityManager#PROCESS_CAPABILITY_NETWORK}, which allows it be able
417 * to access network regardless of any power saving restrictions.
418 *
419 * @hide
420 */
421 public static final int BIND_BYPASS_POWER_NETWORK_RESTRICTIONS = 0x00020000;
422
423 /**
424 * Do not use. This flag is no longer needed nor used.
425 * @hide
426 */
427 @SystemApi
428 @Deprecated
429 public static final int BIND_ALLOW_FOREGROUND_SERVICE_STARTS_FROM_BACKGROUND = 0x00040000;
430
431 /**
432 * Flag for {@link #bindService}: This flag is intended to be used only by the system to adjust
433 * the scheduling policy for IMEs (and any other out-of-process user-visible components that
434 * work closely with the top app) so that UI hosted in such services can have the same
435 * scheduling policy (e.g. SCHED_FIFO when it is enabled and TOP_APP_PRIORITY_BOOST otherwise)
436 * as the actual top-app.
437 * @hide
438 */
439 public static final int BIND_SCHEDULE_LIKE_TOP_APP = 0x00080000;
440
441 /**
442 * Flag for {@link #bindService}: allow background activity starts from the bound service's
443 * process.
444 * This flag is only respected if the caller is holding
445 * {@link android.Manifest.permission#START_ACTIVITIES_FROM_BACKGROUND}.
446 * @hide
447 */
448 @SystemApi
449 public static final int BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS = 0x00100000;
450
451 /**
452 * @hide Flag for {@link #bindService}: the service being bound to represents a
453 * protected system component, so must have association restrictions applied to it.
454 * That is, a system config must have one or more allow-association tags limiting
455 * which packages it can interact with. If it does not have any such association
456 * restrictions, a default empty set will be created.
457 */
458 public static final int BIND_RESTRICT_ASSOCIATIONS = 0x00200000;
459
460 /**
461 * @hide Flag for {@link #bindService}: allows binding to a service provided
462 * by an instant app. Note that the caller may not have access to the instant
463 * app providing the service which is a violation of the instant app sandbox.
464 * This flag is intended ONLY for development/testing and should be used with
465 * great care. Only the system is allowed to use this flag.
466 */
467 public static final int BIND_ALLOW_INSTANT = 0x00400000;
468
469 /**
470 * @hide Flag for {@link #bindService}: like {@link #BIND_NOT_FOREGROUND}, but puts it
471 * up in to the important background state (instead of transient).
472 */
473 public static final int BIND_IMPORTANT_BACKGROUND = 0x00800000;
474
475 /**
476 * @hide Flag for {@link #bindService}: allows application hosting service to manage whitelists
477 * such as temporary allowing a {@code PendingIntent} to bypass Power Save mode.
478 */
479 public static final int BIND_ALLOW_WHITELIST_MANAGEMENT = 0x01000000;
480
481 /**
482 * @hide Flag for {@link #bindService}: Like {@link #BIND_FOREGROUND_SERVICE},
483 * but only applies while the device is awake.
484 */
485 public static final int BIND_FOREGROUND_SERVICE_WHILE_AWAKE = 0x02000000;
486
487 /**
488 * @hide Flag for {@link #bindService}: For only the case where the binding
489 * is coming from the system, set the process state to BOUND_FOREGROUND_SERVICE
490 * instead of the normal maximum of IMPORTANT_FOREGROUND. That is, this is
491 * saying that the process shouldn't participate in the normal power reduction
492 * modes (removing network access etc).
493 */
494 public static final int BIND_FOREGROUND_SERVICE = 0x04000000;
495
496 /**
497 * @hide Flag for {@link #bindService}: Treat the binding as hosting
498 * an activity, an unbinding as the activity going in the background.
499 * That is, when unbinding, the process when empty will go on the activity
500 * LRU list instead of the regular one, keeping it around more aggressively
501 * than it otherwise would be. This is intended for use with IMEs to try
502 * to keep IME processes around for faster keyboard switching.
503 */
504 public static final int BIND_TREAT_LIKE_ACTIVITY = 0x08000000;
505
506 /**
507 * @hide An idea that is not yet implemented.
508 * Flag for {@link #bindService}: If binding from an activity, consider
509 * this service to be visible like the binding activity is. That is,
510 * it will be treated as something more important to keep around than
511 * invisible background activities. This will impact the number of
512 * recent activities the user can switch between without having them
513 * restart. There is no guarantee this will be respected, as the system
514 * tries to balance such requests from one app vs. the importance of
515 * keeping other apps around.
516 *
517 * @deprecated Repurposed to {@link #BIND_TREAT_LIKE_VISIBLE_FOREGROUND_SERVICE}.
518 */
519 @Deprecated
520 public static final int BIND_VISIBLE = 0x10000000;
521
522 /**
523 * @hide Flag for {@link #bindService}: Treat the binding as hosting a foreground service
524 * and also visible to the user. That is, the app hosting the service will get its process state
525 * bumped to the {@link android.app.ActivityManager#PROCESS_STATE_FOREGROUND_SERVICE},
526 * and it's considered as visible to the user, thus less likely to be expunged from memory
527 * on low memory situations. This is intented for use by processes with the process state
528 * better than the {@link android.app.ActivityManager#PROCESS_STATE_TOP}.
529 */
530 public static final int BIND_TREAT_LIKE_VISIBLE_FOREGROUND_SERVICE = 0x10000000;
531
532 /**
533 * @hide
534 * Flag for {@link #bindService}: Consider this binding to be causing the target
535 * process to be showing UI, so it will be do a UI_HIDDEN memory trim when it goes
536 * away.
537 */
538 public static final int BIND_SHOWING_UI = 0x20000000;
539
540 /**
541 * Flag for {@link #bindService}: Don't consider the bound service to be
542 * visible, even if the caller is visible.
543 * @hide
544 */
545 public static final int BIND_NOT_VISIBLE = 0x40000000;
546
547 /**
548 * Flag for {@link #bindService}: The service being bound is an
549 * {@link android.R.attr#isolatedProcess isolated},
550 * {@link android.R.attr#externalService external} service. This binds the service into the
551 * calling application's package, rather than the package in which the service is declared.
552 * <p>
553 * When using this flag, the code for the service being bound will execute under the calling
554 * application's package name and user ID. Because the service must be an isolated process,
555 * it will not have direct access to the application's data, though.
556 *
557 * The purpose of this flag is to allow applications to provide services that are attributed
558 * to the app using the service, rather than the application providing the service.
559 * </p>
560 */
561 public static final int BIND_EXTERNAL_SERVICE = 0x80000000;
562
563 /**
564 * These bind flags reduce the strength of the binding such that we shouldn't
565 * consider it as pulling the process up to the level of the one that is bound to it.
566 * @hide
567 */
568 public static final int BIND_REDUCTION_FLAGS =
569 Context.BIND_ALLOW_OOM_MANAGEMENT | Context.BIND_WAIVE_PRIORITY
570 | Context.BIND_NOT_PERCEPTIBLE | Context.BIND_NOT_VISIBLE;
571
572 /** @hide */
573 @IntDef(flag = true, prefix = { "RECEIVER_VISIBLE" }, value = {
574 RECEIVER_VISIBLE_TO_INSTANT_APPS, RECEIVER_EXPORTED, RECEIVER_NOT_EXPORTED,
575 RECEIVER_EXPORTED_UNAUDITED
576 })
577 @Retention(RetentionPolicy.SOURCE)
578 public @interface RegisterReceiverFlags {}
579
580 /**
581 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from Instant Apps.
582 */
583 public static final int RECEIVER_VISIBLE_TO_INSTANT_APPS = 0x1;
584
585 /**
586 * Flag for {@link #registerReceiver}: The receiver can receive broadcasts from other Apps.
587 * Has the same behavior as marking a statically registered receiver with "exported=true"
588 */
589 public static final int RECEIVER_EXPORTED = 0x2;
590
591 /**
592 * @deprecated Use {@link #RECEIVER_NOT_EXPORTED} or {@link #RECEIVER_EXPORTED} instead.
593 * @hide
594 */
595 @Deprecated
596 @TestApi
597 public static final int RECEIVER_EXPORTED_UNAUDITED = RECEIVER_EXPORTED;
598
599 /**
600 * Flag for {@link #registerReceiver}: The receiver cannot receive broadcasts from other Apps.
601 * Has the same behavior as marking a statically registered receiver with "exported=false"
602 */
603 public static final int RECEIVER_NOT_EXPORTED = 0x4;
604
605 /**
606 * Returns an AssetManager instance for the application's package.
607 * <p>
608 * <strong>Note:</strong> Implementations of this method should return
609 * an AssetManager instance that is consistent with the Resources instance
610 * returned by {@link #getResources()}. For example, they should share the
611 * same {@link Configuration} object.
612 *
613 * @return an AssetManager instance for the application's package
614 * @see #getResources()
615 */
616 public abstract AssetManager getAssets();
617
618 /**
619 * Returns a Resources instance for the application's package.
620 * <p>
621 * <strong>Note:</strong> Implementations of this method should return
622 * a Resources instance that is consistent with the AssetManager instance
623 * returned by {@link #getAssets()}. For example, they should share the
624 * same {@link Configuration} object.
625 *
626 * @return a Resources instance for the application's package
627 * @see #getAssets()
628 */
629 public abstract Resources getResources();
630
631 /** Return PackageManager instance to find global package information. */
632 public abstract PackageManager getPackageManager();
633
634 /** Return a ContentResolver instance for your application's package. */
635 public abstract ContentResolver getContentResolver();
636
637 /**
638 * Return the Looper for the main thread of the current process. This is
639 * the thread used to dispatch calls to application components (activities,
640 * services, etc).
641 * <p>
642 * By definition, this method returns the same result as would be obtained
643 * by calling {@link Looper#getMainLooper() Looper.getMainLooper()}.
644 * </p>
645 *
646 * @return The main looper.
647 */
648 public abstract Looper getMainLooper();
649
650 /**
651 * Return an {@link Executor} that will run enqueued tasks on the main
652 * thread associated with this context. This is the thread used to dispatch
653 * calls to application components (activities, services, etc).
654 */
655 public Executor getMainExecutor() {
656 // This is pretty inefficient, which is why ContextImpl overrides it
657 return new HandlerExecutor(new Handler(getMainLooper()));
658 }
659
660 /**
661 * Return the context of the single, global Application object of the
662 * current process. This generally should only be used if you need a
663 * Context whose lifecycle is separate from the current context, that is
664 * tied to the lifetime of the process rather than the current component.
665 *
666 * <p>Consider for example how this interacts with
667 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)}:
668 * <ul>
669 * <li> <p>If used from an Activity context, the receiver is being registered
670 * within that activity. This means that you are expected to unregister
671 * before the activity is done being destroyed; in fact if you do not do
672 * so, the framework will clean up your leaked registration as it removes
673 * the activity and log an error. Thus, if you use the Activity context
674 * to register a receiver that is static (global to the process, not
675 * associated with an Activity instance) then that registration will be
676 * removed on you at whatever point the activity you used is destroyed.
677 * <li> <p>If used from the Context returned here, the receiver is being
678 * registered with the global state associated with your application. Thus
679 * it will never be unregistered for you. This is necessary if the receiver
680 * is associated with static data, not a particular component. However
681 * using the ApplicationContext elsewhere can easily lead to serious leaks
682 * if you forget to unregister, unbind, etc.
683 * </ul>
684 */
685 public abstract Context getApplicationContext();
686
687 /** Non-activity related autofill ids are unique in the app */
688 private static int sLastAutofillId = View.NO_ID;
689
690 /**
691 * Gets the next autofill ID.
692 *
693 * <p>All IDs will be smaller or the same as {@link View#LAST_APP_AUTOFILL_ID}. All IDs
694 * returned will be unique.
695 *
696 * @return A ID that is unique in the process
697 *
698 * {@hide}
699 */
700 public int getNextAutofillId() {
701 if (sLastAutofillId == View.LAST_APP_AUTOFILL_ID - 1) {
702 sLastAutofillId = View.NO_ID;
703 }
704
705 sLastAutofillId++;
706
707 return sLastAutofillId;
708 }
709
710 /**
711 * Add a new {@link ComponentCallbacks} to the base application of the
712 * Context, which will be called at the same times as the ComponentCallbacks
713 * methods of activities and other components are called. Note that you
714 * <em>must</em> be sure to use {@link #unregisterComponentCallbacks} when
715 * appropriate in the future; this will not be removed for you.
716 * <p>
717 * After {@link Build.VERSION_CODES#S}, Registering the ComponentCallbacks to Context created
718 * via {@link #createWindowContext(int, Bundle)} or
719 * {@link #createWindowContext(Display, int, Bundle)} will receive
720 * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} from Window Context rather
721 * than its base application. It is helpful if you want to handle UI components that
722 * associated with the Window Context when the Window Context has configuration changes.</p>
723 *
724 * @param callback The interface to call. This can be either a
725 * {@link ComponentCallbacks} or {@link ComponentCallbacks2} interface.
726 *
727 * @see Context#createWindowContext(int, Bundle)
728 */
729 public void registerComponentCallbacks(ComponentCallbacks callback) {
730 getApplicationContext().registerComponentCallbacks(callback);
731 }
732
733 /**
734 * Remove a {@link ComponentCallbacks} object that was previously registered
735 * with {@link #registerComponentCallbacks(ComponentCallbacks)}.
736 */
737 public void unregisterComponentCallbacks(ComponentCallbacks callback) {
738 getApplicationContext().unregisterComponentCallbacks(callback);
739 }
740
741 /**
742 * Return a localized, styled CharSequence from the application's package's
743 * default string table.
744 *
745 * @param resId Resource id for the CharSequence text
746 */
747 @NonNull
748 public final CharSequence getText(@StringRes int resId) {
749 return getResources().getText(resId);
750 }
751
752 /**
753 * Returns a localized string from the application's package's
754 * default string table.
755 *
756 * @param resId Resource id for the string
757 * @return The string data associated with the resource, stripped of styled
758 * text information.
759 */
760 @NonNull
761 public final String getString(@StringRes int resId) {
762 return getResources().getString(resId);
763 }
764
765 /**
766 * Returns a localized formatted string from the application's package's
767 * default string table, substituting the format arguments as defined in
768 * {@link java.util.Formatter} and {@link java.lang.String#format}.
769 *
770 * @param resId Resource id for the format string
771 * @param formatArgs The format arguments that will be used for
772 * substitution.
773 * @return The string data associated with the resource, formatted and
774 * stripped of styled text information.
775 */
776 @NonNull
777 public final String getString(@StringRes int resId, Object... formatArgs) {
778 return getResources().getString(resId, formatArgs);
779 }
780
781 /**
782 * Returns a color associated with a particular resource ID and styled for
783 * the current theme.
784 *
785 * @param id The desired resource identifier, as generated by the aapt
786 * tool. This integer encodes the package, type, and resource
787 * entry. The value 0 is an invalid identifier.
788 * @return A single color value in the form 0xAARRGGBB.
789 * @throws android.content.res.Resources.NotFoundException if the given ID
790 * does not exist.
791 */
792 @ColorInt
793 public final int getColor(@ColorRes int id) {
794 return getResources().getColor(id, getTheme());
795 }
796
797 /**
798 * Returns a drawable object associated with a particular resource ID and
799 * styled for the current theme.
800 *
801 * @param id The desired resource identifier, as generated by the aapt
802 * tool. This integer encodes the package, type, and resource
803 * entry. The value 0 is an invalid identifier.
804 * @return An object that can be used to draw this resource.
805 * @throws android.content.res.Resources.NotFoundException if the given ID
806 * does not exist.
807 */
808 @Nullable
809 public final Drawable getDrawable(@DrawableRes int id) {
810 return getResources().getDrawable(id, getTheme());
811 }
812
813 /**
814 * Returns a color state list associated with a particular resource ID and
815 * styled for the current theme.
816 *
817 * @param id The desired resource identifier, as generated by the aapt
818 * tool. This integer encodes the package, type, and resource
819 * entry. The value 0 is an invalid identifier.
820 * @return A color state list.
821 * @throws android.content.res.Resources.NotFoundException if the given ID
822 * does not exist.
823 */
824 @NonNull
825 public final ColorStateList getColorStateList(@ColorRes int id) {
826 return getResources().getColorStateList(id, getTheme());
827 }
828
829 /**
830 * Set the base theme for this context. Note that this should be called
831 * before any views are instantiated in the Context (for example before
832 * calling {@link android.app.Activity#setContentView} or
833 * {@link android.view.LayoutInflater#inflate}).
834 *
835 * @param resid The style resource describing the theme.
836 */
837 public abstract void setTheme(@StyleRes int resid);
838
839 /** @hide Needed for some internal implementation... not public because
840 * you can't assume this actually means anything. */
841 @UnsupportedAppUsage
842 public int getThemeResId() {
843 return 0;
844 }
845
846 /**
847 * Return the Theme object associated with this Context.
848 */
849 @ViewDebug.ExportedProperty(deepExport = true)
850 public abstract Resources.Theme getTheme();
851
852 /**
853 * Retrieve styled attribute information in this Context's theme. See
854 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int[])}
855 * for more information.
856 *
857 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int[])
858 */
859 @NonNull
860 public final TypedArray obtainStyledAttributes(@NonNull @StyleableRes int[] attrs) {
861 return getTheme().obtainStyledAttributes(attrs);
862 }
863
864 /**
865 * Retrieve styled attribute information in this Context's theme. See
866 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])}
867 * for more information.
868 *
869 * @see android.content.res.Resources.Theme#obtainStyledAttributes(int, int[])
870 */
871 @NonNull
872 public final TypedArray obtainStyledAttributes(@StyleRes int resid,
873 @NonNull @StyleableRes int[] attrs) throws Resources.NotFoundException {
874 return getTheme().obtainStyledAttributes(resid, attrs);
875 }
876
877 /**
878 * Retrieve styled attribute information in this Context's theme. See
879 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
880 * for more information.
881 *
882 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
883 */
884 @NonNull
885 public final TypedArray obtainStyledAttributes(
886 @Nullable AttributeSet set, @NonNull @StyleableRes int[] attrs) {
887 return getTheme().obtainStyledAttributes(set, attrs, 0, 0);
888 }
889
890 /**
891 * Retrieve styled attribute information in this Context's theme. See
892 * {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
893 * for more information.
894 *
895 * @see android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
896 */
897 @NonNull
898 public final TypedArray obtainStyledAttributes(@Nullable AttributeSet set,
899 @NonNull @StyleableRes int[] attrs, @AttrRes int defStyleAttr,
900 @StyleRes int defStyleRes) {
901 return getTheme().obtainStyledAttributes(
902 set, attrs, defStyleAttr, defStyleRes);
903 }
904
905 /**
906 * Return a class loader you can use to retrieve classes in this package.
907 */
908 public abstract ClassLoader getClassLoader();
909
910 /** Return the name of this application's package. */
911 public abstract String getPackageName();
912
913 /**
914 * @hide Return the name of the base context this context is derived from.
915 * This is the same as {@link #getOpPackageName()} except in
916 * cases where system components are loaded into other app processes, in which
917 * case {@link #getOpPackageName()} will be the name of the primary package in
918 * that process (so that app ops uid verification will work with the name).
919 */
920 @SuppressWarnings("HiddenAbstractMethod")
921 @UnsupportedAppUsage
922 public abstract String getBasePackageName();
923
924 /**
925 * Return the package name that should be used for {@link android.app.AppOpsManager} calls from
926 * this context, so that app ops manager's uid verification will work with the name.
927 * <p>
928 * This is not generally intended for third party application developers.
929 */
930 @NonNull
931 public String getOpPackageName() {
932 throw new RuntimeException("Not implemented. Must override in a subclass.");
933 }
934
935 /**
936 * <p>Attribution can be used in complex apps to logically separate parts of the app. E.g. a
937 * blogging app might also have a instant messaging app built in. In this case two separate tags
938 * can for used each sub-feature.
939 *
940 * @return the attribution tag this context is for or {@code null} if this is the default.
941 */
942 public @Nullable String getAttributionTag() {
943 return null;
944 }
945
946 /**
947 * @return The identity of this context for permission purposes.
948 *
949 * @see AttributionSource
950 */
951 public @NonNull AttributionSource getAttributionSource() {
952 return null;
953 }
954
955 // TODO moltmann: Remove
956 /**
957 * @removed
958 */
959 @Deprecated
960 public @Nullable String getFeatureId() {
961 return getAttributionTag();
962 }
963
964 /**
965 * Return the set of parameters which this Context was created with, if it
966 * was created via {@link #createContext(ContextParams)}.
967 */
968 public @Nullable ContextParams getParams() {
969 return null;
970 }
971
972 /** Return the full application info for this context's package. */
973 public abstract ApplicationInfo getApplicationInfo();
974
975 /**
976 * Return the full path to this context's primary Android package.
977 * The Android package is a ZIP file which contains the application's
978 * primary resources.
979 *
980 * <p>Note: this is not generally useful for applications, since they should
981 * not be directly accessing the file system.
982 *
983 * @return String Path to the resources.
984 */
985 public abstract String getPackageResourcePath();
986
987 /**
988 * Return the full path to this context's primary Android package.
989 * The Android package is a ZIP file which contains application's
990 * primary code and assets.
991 *
992 * <p>Note: this is not generally useful for applications, since they should
993 * not be directly accessing the file system.
994 *
995 * @return String Path to the code and assets.
996 */
997 public abstract String getPackageCodePath();
998
999 /**
1000 * @hide
1001 * @deprecated use {@link #getSharedPreferencesPath(String)}
1002 */
1003 @Deprecated
1004 @UnsupportedAppUsage
1005 public File getSharedPrefsFile(String name) {
1006 return getSharedPreferencesPath(name);
1007 }
1008
1009 /**
1010 * Retrieve and hold the contents of the preferences file 'name', returning
1011 * a SharedPreferences through which you can retrieve and modify its
1012 * values. Only one instance of the SharedPreferences object is returned
1013 * to any callers for the same name, meaning they will see each other's
1014 * edits as soon as they are made.
1015 *
1016 * <p>This method is thread-safe.
1017 *
1018 * <p>If the preferences directory does not already exist, it will be created when this method
1019 * is called.
1020 *
1021 * <p>If a preferences file by this name does not exist, it will be created when you retrieve an
1022 * editor ({@link SharedPreferences#edit()}) and then commit changes ({@link
1023 * SharedPreferences.Editor#commit()} or {@link SharedPreferences.Editor#apply()}).
1024 *
1025 * @param name Desired preferences file.
1026 * @param mode Operating mode.
1027 *
1028 * @return The single {@link SharedPreferences} instance that can be used
1029 * to retrieve and modify the preference values.
1030 *
1031 * @see #MODE_PRIVATE
1032 */
1033 public abstract SharedPreferences getSharedPreferences(String name, @PreferencesMode int mode);
1034
1035 /**
1036 * Retrieve and hold the contents of the preferences file, returning
1037 * a SharedPreferences through which you can retrieve and modify its
1038 * values. Only one instance of the SharedPreferences object is returned
1039 * to any callers for the same name, meaning they will see each other's
1040 * edits as soon as they are made.
1041 *
1042 * @param file Desired preferences file. If a preferences file by this name
1043 * does not exist, it will be created when you retrieve an
1044 * editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
1045 * @param mode Operating mode.
1046 *
1047 * @return The single {@link SharedPreferences} instance that can be used
1048 * to retrieve and modify the preference values.
1049 *
1050 * @see #getSharedPreferencesPath(String)
1051 * @see #MODE_PRIVATE
1052 * @removed
1053 */
1054 @SuppressWarnings("HiddenAbstractMethod")
1055 public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);
1056
1057 /**
1058 * Move an existing shared preferences file from the given source storage
1059 * context to this context. This is typically used to migrate data between
1060 * storage locations after an upgrade, such as moving to device protected
1061 * storage.
1062 *
1063 * @param sourceContext The source context which contains the existing
1064 * shared preferences to move.
1065 * @param name The name of the shared preferences file.
1066 * @return {@code true} if the move was successful or if the shared
1067 * preferences didn't exist in the source context, otherwise
1068 * {@code false}.
1069 * @see #createDeviceProtectedStorageContext()
1070 */
1071 public abstract boolean moveSharedPreferencesFrom(Context sourceContext, String name);
1072
1073 /**
1074 * Delete an existing shared preferences file.
1075 *
1076 * @param name The name (unique in the application package) of the shared
1077 * preferences file.
1078 * @return {@code true} if the shared preferences file was successfully
1079 * deleted; else {@code false}.
1080 * @see #getSharedPreferences(String, int)
1081 */
1082 public abstract boolean deleteSharedPreferences(String name);
1083
1084 /** @hide */
1085 @SuppressWarnings("HiddenAbstractMethod")
1086 public abstract void reloadSharedPreferences();
1087
1088 /**
1089 * Open a private file associated with this Context's application package
1090 * for reading.
1091 *
1092 * @param name The name of the file to open; can not contain path
1093 * separators.
1094 *
1095 * @return The resulting {@link FileInputStream}.
1096 *
1097 * @see #openFileOutput
1098 * @see #fileList
1099 * @see #deleteFile
1100 * @see java.io.FileInputStream#FileInputStream(String)
1101 */
1102 public abstract FileInputStream openFileInput(String name)
1103 throws FileNotFoundException;
1104
1105 /**
1106 * Open a private file associated with this Context's application package
1107 * for writing. Creates the file if it doesn't already exist.
1108 * <p>
1109 * No additional permissions are required for the calling app to read or
1110 * write the returned file.
1111 *
1112 * @param name The name of the file to open; can not contain path
1113 * separators.
1114 * @param mode Operating mode.
1115 * @return The resulting {@link FileOutputStream}.
1116 * @see #MODE_APPEND
1117 * @see #MODE_PRIVATE
1118 * @see #openFileInput
1119 * @see #fileList
1120 * @see #deleteFile
1121 * @see java.io.FileOutputStream#FileOutputStream(String)
1122 */
1123 public abstract FileOutputStream openFileOutput(String name, @FileMode int mode)
1124 throws FileNotFoundException;
1125
1126 /**
1127 * Delete the given private file associated with this Context's
1128 * application package.
1129 *
1130 * @param name The name of the file to delete; can not contain path
1131 * separators.
1132 *
1133 * @return {@code true} if the file was successfully deleted; else
1134 * {@code false}.
1135 *
1136 * @see #openFileInput
1137 * @see #openFileOutput
1138 * @see #fileList
1139 * @see java.io.File#delete()
1140 */
1141 public abstract boolean deleteFile(String name);
1142
1143 /**
1144 * Returns the absolute path on the filesystem where a file created with
1145 * {@link #openFileOutput} is stored.
1146 * <p>
1147 * The returned path may change over time if the calling app is moved to an
1148 * adopted storage device, so only relative paths should be persisted.
1149 *
1150 * @param name The name of the file for which you would like to get
1151 * its path.
1152 *
1153 * @return An absolute path to the given file.
1154 *
1155 * @see #openFileOutput
1156 * @see #getFilesDir
1157 * @see #getDir
1158 */
1159 public abstract File getFileStreamPath(String name);
1160
1161 /**
1162 * Returns the absolute path on the filesystem where a file created with
1163 * {@link #getSharedPreferences(String, int)} is stored.
1164 * <p>
1165 * The returned path may change over time if the calling app is moved to an
1166 * adopted storage device, so only relative paths should be persisted.
1167 *
1168 * @param name The name of the shared preferences for which you would like
1169 * to get a path.
1170 * @return An absolute path to the given file.
1171 * @see #getSharedPreferences(String, int)
1172 * @removed
1173 */
1174 @SuppressWarnings("HiddenAbstractMethod")
1175 public abstract File getSharedPreferencesPath(String name);
1176
1177 /**
1178 * Returns the absolute path to the directory on the filesystem where all
1179 * private files belonging to this app are stored. Apps should not use this
1180 * path directly; they should instead use {@link #getFilesDir()},
1181 * {@link #getCacheDir()}, {@link #getDir(String, int)}, or other storage
1182 * APIs on this class.
1183 * <p>
1184 * The returned path may change over time if the calling app is moved to an
1185 * adopted storage device, so only relative paths should be persisted.
1186 * <p>
1187 * No additional permissions are required for the calling app to read or
1188 * write files under the returned path.
1189 *
1190 * @see ApplicationInfo#dataDir
1191 */
1192 public abstract File getDataDir();
1193
1194 /**
1195 * Returns the absolute path to the directory on the filesystem where files
1196 * created with {@link #openFileOutput} are stored.
1197 * <p>
1198 * The returned path may change over time if the calling app is moved to an
1199 * adopted storage device, so only relative paths should be persisted.
1200 * <p>
1201 * No additional permissions are required for the calling app to read or
1202 * write files under the returned path.
1203 *
1204 * @return The path of the directory holding application files.
1205 * @see #openFileOutput
1206 * @see #getFileStreamPath
1207 * @see #getDir
1208 */
1209 public abstract File getFilesDir();
1210
1211 /**
1212 * Returns the absolute path to the directory that is related to the crate on the filesystem.
1213 * <p>
1214 * The crateId require a validated file name. It can't contain any "..", ".",
1215 * {@link File#separatorChar} etc..
1216 * </p>
1217 * <p>
1218 * The returned path may change over time if the calling app is moved to an
1219 * adopted storage device, so only relative paths should be persisted.
1220 * </p>
1221 * <p>
1222 * No additional permissions are required for the calling app to read or
1223 * write files under the returned path.
1224 *</p>
1225 *
1226 * @param crateId the relative validated file name under {@link Context#getDataDir()}/crates
1227 * @return the crate directory file.
1228 * @hide
1229 */
1230 @NonNull
1231 @TestApi
1232 public File getCrateDir(@NonNull String crateId) {
1233 throw new RuntimeException("Not implemented. Must override in a subclass.");
1234 }
1235
1236 /**
1237 * Returns the absolute path to the directory on the filesystem similar to
1238 * {@link #getFilesDir()}. The difference is that files placed under this
1239 * directory will be excluded from automatic backup to remote storage. See
1240 * {@link android.app.backup.BackupAgent BackupAgent} for a full discussion
1241 * of the automatic backup mechanism in Android.
1242 * <p>
1243 * The returned path may change over time if the calling app is moved to an
1244 * adopted storage device, so only relative paths should be persisted.
1245 * <p>
1246 * No additional permissions are required for the calling app to read or
1247 * write files under the returned path.
1248 *
1249 * @return The path of the directory holding application files that will not
1250 * be automatically backed up to remote storage.
1251 * @see #openFileOutput
1252 * @see #getFileStreamPath
1253 * @see #getDir
1254 * @see android.app.backup.BackupAgent
1255 */
1256 public abstract File getNoBackupFilesDir();
1257
1258 /**
1259 * Returns the absolute path to the directory on the primary shared/external
1260 * storage device where the application can place persistent files it owns.
1261 * These files are internal to the applications, and not typically visible
1262 * to the user as media.
1263 * <p>
1264 * This is like {@link #getFilesDir()} in that these files will be deleted
1265 * when the application is uninstalled, however there are some important
1266 * differences:
1267 * <ul>
1268 * <li>Shared storage may not always be available, since removable media can
1269 * be ejected by the user. Media state can be checked using
1270 * {@link Environment#getExternalStorageState(File)}.
1271 * <li>There is no security enforced with these files. For example, any
1272 * application holding
1273 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1274 * these files.
1275 * </ul>
1276 * <p>
1277 * If a shared storage device is emulated (as determined by
1278 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1279 * backed by a private user data partition, which means there is little
1280 * benefit to storing data here instead of the private directories returned
1281 * by {@link #getFilesDir()}, etc.
1282 * <p>
1283 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1284 * are required to read or write to the returned path; it's always
1285 * accessible to the calling app. This only applies to paths generated for
1286 * package name of the calling application. To access paths belonging to
1287 * other packages,
1288 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1289 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1290 * <p>
1291 * On devices with multiple users (as described by {@link UserManager}),
1292 * each user has their own isolated shared storage. Applications only have
1293 * access to the shared storage for the user they're running as.
1294 * <p>
1295 * The returned path may change over time if different shared storage media
1296 * is inserted, so only relative paths should be persisted.
1297 * <p>
1298 * Here is an example of typical code to manipulate a file in an
1299 * application's shared storage:
1300 * </p>
1301 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1302 * private_file}
1303 * <p>
1304 * If you supply a non-null <var>type</var> to this function, the returned
1305 * file will be a path to a sub-directory of the given type. Though these
1306 * files are not automatically scanned by the media scanner, you can
1307 * explicitly add them to the media database with
1308 * {@link android.media.MediaScannerConnection#scanFile(Context, String[], String[], android.media.MediaScannerConnection.OnScanCompletedListener)
1309 * MediaScannerConnection.scanFile}. Note that this is not the same as
1310 * {@link android.os.Environment#getExternalStoragePublicDirectory
1311 * Environment.getExternalStoragePublicDirectory()}, which provides
1312 * directories of media shared by all applications. The directories returned
1313 * here are owned by the application, and their contents will be removed
1314 * when the application is uninstalled. Unlike
1315 * {@link android.os.Environment#getExternalStoragePublicDirectory
1316 * Environment.getExternalStoragePublicDirectory()}, the directory returned
1317 * here will be automatically created for you.
1318 * <p>
1319 * Here is an example of typical code to manipulate a picture in an
1320 * application's shared storage and add it to the media database:
1321 * </p>
1322 * {@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java
1323 * private_picture}
1324 *
1325 * @param type The type of files directory to return. May be {@code null}
1326 * for the root of the files directory or one of the following
1327 * constants for a subdirectory:
1328 * {@link android.os.Environment#DIRECTORY_MUSIC},
1329 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1330 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1331 * {@link android.os.Environment#DIRECTORY_ALARMS},
1332 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1333 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1334 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1335 * @return the absolute path to application-specific directory. May return
1336 * {@code null} if shared storage is not currently available.
1337 * @see #getFilesDir
1338 * @see #getExternalFilesDirs(String)
1339 * @see Environment#getExternalStorageState(File)
1340 * @see Environment#isExternalStorageEmulated(File)
1341 * @see Environment#isExternalStorageRemovable(File)
1342 */
1343 @Nullable
1344 public abstract File getExternalFilesDir(@Nullable String type);
1345
1346 /**
1347 * Returns absolute paths to application-specific directories on all
1348 * shared/external storage devices where the application can place
1349 * persistent files it owns. These files are internal to the application,
1350 * and not typically visible to the user as media.
1351 * <p>
1352 * This is like {@link #getFilesDir()} in that these files will be deleted
1353 * when the application is uninstalled, however there are some important
1354 * differences:
1355 * <ul>
1356 * <li>Shared storage may not always be available, since removable media can
1357 * be ejected by the user. Media state can be checked using
1358 * {@link Environment#getExternalStorageState(File)}.
1359 * <li>There is no security enforced with these files. For example, any
1360 * application holding
1361 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1362 * these files.
1363 * </ul>
1364 * <p>
1365 * If a shared storage device is emulated (as determined by
1366 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1367 * backed by a private user data partition, which means there is little
1368 * benefit to storing data here instead of the private directories returned
1369 * by {@link #getFilesDir()}, etc.
1370 * <p>
1371 * Shared storage devices returned here are considered a stable part of the
1372 * device, including physical media slots under a protective cover. The
1373 * returned paths do not include transient devices, such as USB flash drives
1374 * connected to handheld devices.
1375 * <p>
1376 * An application may store data on any or all of the returned devices. For
1377 * example, an app may choose to store large files on the device with the
1378 * most available space, as measured by {@link StatFs}.
1379 * <p>
1380 * No additional permissions are required for the calling app to read or
1381 * write files under the returned path. Write access outside of these paths
1382 * on secondary external storage devices is not available.
1383 * <p>
1384 * The returned path may change over time if different shared storage media
1385 * is inserted, so only relative paths should be persisted.
1386 *
1387 * @param type The type of files directory to return. May be {@code null}
1388 * for the root of the files directory or one of the following
1389 * constants for a subdirectory:
1390 * {@link android.os.Environment#DIRECTORY_MUSIC},
1391 * {@link android.os.Environment#DIRECTORY_PODCASTS},
1392 * {@link android.os.Environment#DIRECTORY_RINGTONES},
1393 * {@link android.os.Environment#DIRECTORY_ALARMS},
1394 * {@link android.os.Environment#DIRECTORY_NOTIFICATIONS},
1395 * {@link android.os.Environment#DIRECTORY_PICTURES}, or
1396 * {@link android.os.Environment#DIRECTORY_MOVIES}.
1397 * @return the absolute paths to application-specific directories. Some
1398 * individual paths may be {@code null} if that shared storage is
1399 * not currently available. The first path returned is the same as
1400 * {@link #getExternalFilesDir(String)}.
1401 * @see #getExternalFilesDir(String)
1402 * @see Environment#getExternalStorageState(File)
1403 * @see Environment#isExternalStorageEmulated(File)
1404 * @see Environment#isExternalStorageRemovable(File)
1405 */
1406 public abstract File[] getExternalFilesDirs(String type);
1407
1408 /**
1409 * Return the primary shared/external storage directory where this
1410 * application's OBB files (if there are any) can be found. Note if the
1411 * application does not have any OBB files, this directory may not exist.
1412 * <p>
1413 * This is like {@link #getFilesDir()} in that these files will be deleted
1414 * when the application is uninstalled, however there are some important
1415 * differences:
1416 * <ul>
1417 * <li>Shared storage may not always be available, since removable media can
1418 * be ejected by the user. Media state can be checked using
1419 * {@link Environment#getExternalStorageState(File)}.
1420 * <li>There is no security enforced with these files. For example, any
1421 * application holding
1422 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1423 * these files.
1424 * </ul>
1425 * <p>
1426 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1427 * are required to read or write to the path that this method returns.
1428 * However, starting from {@link android.os.Build.VERSION_CODES#M},
1429 * to read the OBB expansion files, you must declare the
1430 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission in the app manifest and ask for
1431 * permission at runtime as follows:
1432 * </p>
1433 * <p>
1434 * {@code <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
1435 * android:maxSdkVersion="23" />}
1436 * </p>
1437 * <p>
1438 * Starting from {@link android.os.Build.VERSION_CODES#N},
1439 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
1440 * permission is not required, so don’t ask for this
1441 * permission at runtime. To handle both cases, your app must first try to read the OBB file,
1442 * and if it fails, you must request
1443 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission at runtime.
1444 * </p>
1445 *
1446 * <p>
1447 * The following code snippet shows how to do this:
1448 * </p>
1449 *
1450 * <pre>
1451 * File obb = new File(obb_filename);
1452 * boolean open_failed = false;
1453 *
1454 * try {
1455 * BufferedReader br = new BufferedReader(new FileReader(obb));
1456 * open_failed = false;
1457 * ReadObbFile(br);
1458 * } catch (IOException e) {
1459 * open_failed = true;
1460 * }
1461 *
1462 * if (open_failed) {
1463 * // request READ_EXTERNAL_STORAGE permission before reading OBB file
1464 * ReadObbFileWithPermission();
1465 * }
1466 * </pre>
1467 *
1468 * On devices with multiple users (as described by {@link UserManager}),
1469 * multiple users may share the same OBB storage location. Applications
1470 * should ensure that multiple instances running under different users don't
1471 * interfere with each other.
1472 *
1473 * @return the absolute path to application-specific directory. May return
1474 * {@code null} if shared storage is not currently available.
1475 * @see #getObbDirs()
1476 * @see Environment#getExternalStorageState(File)
1477 * @see Environment#isExternalStorageEmulated(File)
1478 * @see Environment#isExternalStorageRemovable(File)
1479 */
1480 public abstract File getObbDir();
1481
1482 /**
1483 * Returns absolute paths to application-specific directories on all
1484 * shared/external storage devices where the application's OBB files (if
1485 * there are any) can be found. Note if the application does not have any
1486 * OBB files, these directories may not exist.
1487 * <p>
1488 * This is like {@link #getFilesDir()} in that these files will be deleted
1489 * when the application is uninstalled, however there are some important
1490 * differences:
1491 * <ul>
1492 * <li>Shared storage may not always be available, since removable media can
1493 * be ejected by the user. Media state can be checked using
1494 * {@link Environment#getExternalStorageState(File)}.
1495 * <li>There is no security enforced with these files. For example, any
1496 * application holding
1497 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1498 * these files.
1499 * </ul>
1500 * <p>
1501 * Shared storage devices returned here are considered a stable part of the
1502 * device, including physical media slots under a protective cover. The
1503 * returned paths do not include transient devices, such as USB flash drives
1504 * connected to handheld devices.
1505 * <p>
1506 * An application may store data on any or all of the returned devices. For
1507 * example, an app may choose to store large files on the device with the
1508 * most available space, as measured by {@link StatFs}.
1509 * <p>
1510 * No additional permissions are required for the calling app to read or
1511 * write files under the returned path. Write access outside of these paths
1512 * on secondary external storage devices is not available.
1513 *
1514 * @return the absolute paths to application-specific directories. Some
1515 * individual paths may be {@code null} if that shared storage is
1516 * not currently available. The first path returned is the same as
1517 * {@link #getObbDir()}
1518 * @see #getObbDir()
1519 * @see Environment#getExternalStorageState(File)
1520 * @see Environment#isExternalStorageEmulated(File)
1521 * @see Environment#isExternalStorageRemovable(File)
1522 */
1523 public abstract File[] getObbDirs();
1524
1525 /**
1526 * Returns the absolute path to the application specific cache directory on
1527 * the filesystem.
1528 * <p>
1529 * The system will automatically delete files in this directory as disk
1530 * space is needed elsewhere on the device. The system will always delete
1531 * older files first, as reported by {@link File#lastModified()}. If
1532 * desired, you can exert more control over how files are deleted using
1533 * {@link StorageManager#setCacheBehaviorGroup(File, boolean)} and
1534 * {@link StorageManager#setCacheBehaviorTombstone(File, boolean)}.
1535 * <p>
1536 * Apps are strongly encouraged to keep their usage of cache space below the
1537 * quota returned by
1538 * {@link StorageManager#getCacheQuotaBytes(java.util.UUID)}. If your app
1539 * goes above this quota, your cached files will be some of the first to be
1540 * deleted when additional disk space is needed. Conversely, if your app
1541 * stays under this quota, your cached files will be some of the last to be
1542 * deleted when additional disk space is needed.
1543 * <p>
1544 * Note that your cache quota will change over time depending on how
1545 * frequently the user interacts with your app, and depending on how much
1546 * system-wide disk space is used.
1547 * <p>
1548 * The returned path may change over time if the calling app is moved to an
1549 * adopted storage device, so only relative paths should be persisted.
1550 * <p>
1551 * Apps require no extra permissions to read or write to the returned path,
1552 * since this path lives in their private storage.
1553 *
1554 * @return The path of the directory holding application cache files.
1555 * @see #openFileOutput
1556 * @see #getFileStreamPath
1557 * @see #getDir
1558 * @see #getExternalCacheDir
1559 */
1560 public abstract File getCacheDir();
1561
1562 /**
1563 * Returns the absolute path to the application specific cache directory on
1564 * the filesystem designed for storing cached code.
1565 * <p>
1566 * The system will delete any files stored in this location both when your
1567 * specific application is upgraded, and when the entire platform is
1568 * upgraded.
1569 * <p>
1570 * This location is optimal for storing compiled or optimized code generated
1571 * by your application at runtime.
1572 * <p>
1573 * The returned path may change over time if the calling app is moved to an
1574 * adopted storage device, so only relative paths should be persisted.
1575 * <p>
1576 * Apps require no extra permissions to read or write to the returned path,
1577 * since this path lives in their private storage.
1578 *
1579 * @return The path of the directory holding application code cache files.
1580 */
1581 public abstract File getCodeCacheDir();
1582
1583 /**
1584 * Returns absolute path to application-specific directory on the primary
1585 * shared/external storage device where the application can place cache
1586 * files it owns. These files are internal to the application, and not
1587 * typically visible to the user as media.
1588 * <p>
1589 * This is like {@link #getCacheDir()} in that these files will be deleted
1590 * when the application is uninstalled, however there are some important
1591 * differences:
1592 * <ul>
1593 * <li>The platform does not always monitor the space available in shared
1594 * storage, and thus may not automatically delete these files. Apps should
1595 * always manage the maximum space used in this location. Currently the only
1596 * time files here will be deleted by the platform is when running on
1597 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1598 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1599 * <li>Shared storage may not always be available, since removable media can
1600 * be ejected by the user. Media state can be checked using
1601 * {@link Environment#getExternalStorageState(File)}.
1602 * <li>There is no security enforced with these files. For example, any
1603 * application holding
1604 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1605 * these files.
1606 * </ul>
1607 * <p>
1608 * If a shared storage device is emulated (as determined by
1609 * {@link Environment#isExternalStorageEmulated(File)}), its contents are
1610 * backed by a private user data partition, which means there is little
1611 * benefit to storing data here instead of the private directory returned by
1612 * {@link #getCacheDir()}.
1613 * <p>
1614 * Starting in {@link android.os.Build.VERSION_CODES#KITKAT}, no permissions
1615 * are required to read or write to the returned path; it's always
1616 * accessible to the calling app. This only applies to paths generated for
1617 * package name of the calling application. To access paths belonging to
1618 * other packages,
1619 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} and/or
1620 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} are required.
1621 * <p>
1622 * On devices with multiple users (as described by {@link UserManager}),
1623 * each user has their own isolated shared storage. Applications only have
1624 * access to the shared storage for the user they're running as.
1625 * <p>
1626 * The returned path may change over time if different shared storage media
1627 * is inserted, so only relative paths should be persisted.
1628 *
1629 * @return the absolute path to application-specific directory. May return
1630 * {@code null} if shared storage is not currently available.
1631 * @see #getCacheDir
1632 * @see #getExternalCacheDirs()
1633 * @see Environment#getExternalStorageState(File)
1634 * @see Environment#isExternalStorageEmulated(File)
1635 * @see Environment#isExternalStorageRemovable(File)
1636 */
1637 @Nullable
1638 public abstract File getExternalCacheDir();
1639
1640 /**
1641 * Returns absolute path to application-specific directory in the preloaded cache.
1642 * <p>Files stored in the cache directory can be deleted when the device runs low on storage.
1643 * There is no guarantee when these files will be deleted.
1644 * @hide
1645 */
1646 @SuppressWarnings("HiddenAbstractMethod")
1647 @Nullable
1648 @SystemApi
1649 public abstract File getPreloadsFileCache();
1650
1651 /**
1652 * Returns absolute paths to application-specific directories on all
1653 * shared/external storage devices where the application can place cache
1654 * files it owns. These files are internal to the application, and not
1655 * typically visible to the user as media.
1656 * <p>
1657 * This is like {@link #getCacheDir()} in that these files will be deleted
1658 * when the application is uninstalled, however there are some important
1659 * differences:
1660 * <ul>
1661 * <li>The platform does not always monitor the space available in shared
1662 * storage, and thus may not automatically delete these files. Apps should
1663 * always manage the maximum space used in this location. Currently the only
1664 * time files here will be deleted by the platform is when running on
1665 * {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR1} or later and
1666 * {@link Environment#isExternalStorageEmulated(File)} returns true.
1667 * <li>Shared storage may not always be available, since removable media can
1668 * be ejected by the user. Media state can be checked using
1669 * {@link Environment#getExternalStorageState(File)}.
1670 * <li>There is no security enforced with these files. For example, any
1671 * application holding
1672 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1673 * these files.
1674 * </ul>
1675 * <p>
1676 * If a shared storage device is emulated (as determined by
1677 * {@link Environment#isExternalStorageEmulated(File)}), it's contents are
1678 * backed by a private user data partition, which means there is little
1679 * benefit to storing data here instead of the private directory returned by
1680 * {@link #getCacheDir()}.
1681 * <p>
1682 * Shared storage devices returned here are considered a stable part of the
1683 * device, including physical media slots under a protective cover. The
1684 * returned paths do not include transient devices, such as USB flash drives
1685 * connected to handheld devices.
1686 * <p>
1687 * An application may store data on any or all of the returned devices. For
1688 * example, an app may choose to store large files on the device with the
1689 * most available space, as measured by {@link StatFs}.
1690 * <p>
1691 * No additional permissions are required for the calling app to read or
1692 * write files under the returned path. Write access outside of these paths
1693 * on secondary external storage devices is not available.
1694 * <p>
1695 * The returned paths may change over time if different shared storage media
1696 * is inserted, so only relative paths should be persisted.
1697 *
1698 * @return the absolute paths to application-specific directories. Some
1699 * individual paths may be {@code null} if that shared storage is
1700 * not currently available. The first path returned is the same as
1701 * {@link #getExternalCacheDir()}.
1702 * @see #getExternalCacheDir()
1703 * @see Environment#getExternalStorageState(File)
1704 * @see Environment#isExternalStorageEmulated(File)
1705 * @see Environment#isExternalStorageRemovable(File)
1706 */
1707 public abstract File[] getExternalCacheDirs();
1708
1709 /**
1710 * Returns absolute paths to application-specific directories on all
1711 * shared/external storage devices where the application can place media
1712 * files. These files are scanned and made available to other apps through
1713 * {@link MediaStore}.
1714 * <p>
1715 * This is like {@link #getExternalFilesDirs} in that these files will be
1716 * deleted when the application is uninstalled, however there are some
1717 * important differences:
1718 * <ul>
1719 * <li>Shared storage may not always be available, since removable media can
1720 * be ejected by the user. Media state can be checked using
1721 * {@link Environment#getExternalStorageState(File)}.
1722 * <li>There is no security enforced with these files. For example, any
1723 * application holding
1724 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} can write to
1725 * these files.
1726 * </ul>
1727 * <p>
1728 * Shared storage devices returned here are considered a stable part of the
1729 * device, including physical media slots under a protective cover. The
1730 * returned paths do not include transient devices, such as USB flash drives
1731 * connected to handheld devices.
1732 * <p>
1733 * An application may store data on any or all of the returned devices. For
1734 * example, an app may choose to store large files on the device with the
1735 * most available space, as measured by {@link StatFs}.
1736 * <p>
1737 * No additional permissions are required for the calling app to read or
1738 * write files under the returned path. Write access outside of these paths
1739 * on secondary external storage devices is not available.
1740 * <p>
1741 * The returned paths may change over time if different shared storage media
1742 * is inserted, so only relative paths should be persisted.
1743 *
1744 * @return the absolute paths to application-specific directories. Some
1745 * individual paths may be {@code null} if that shared storage is
1746 * not currently available.
1747 * @see Environment#getExternalStorageState(File)
1748 * @see Environment#isExternalStorageEmulated(File)
1749 * @see Environment#isExternalStorageRemovable(File)
1750 * @deprecated These directories still exist and are scanned, but developers
1751 * are encouraged to migrate to inserting content into a
1752 * {@link MediaStore} collection directly, as any app can
1753 * contribute new media to {@link MediaStore} with no
1754 * permissions required, starting in
1755 * {@link android.os.Build.VERSION_CODES#Q}.
1756 */
1757 @Deprecated
1758 public abstract File[] getExternalMediaDirs();
1759
1760 /**
1761 * Returns an array of strings naming the private files associated with
1762 * this Context's application package.
1763 *
1764 * @return Array of strings naming the private files.
1765 *
1766 * @see #openFileInput
1767 * @see #openFileOutput
1768 * @see #deleteFile
1769 */
1770 public abstract String[] fileList();
1771
1772 /**
1773 * Retrieve, creating if needed, a new directory in which the application
1774 * can place its own custom data files. You can use the returned File
1775 * object to create and access files in this directory. Note that files
1776 * created through a File object will only be accessible by your own
1777 * application; you can only set the mode of the entire directory, not
1778 * of individual files.
1779 * <p>
1780 * The returned path may change over time if the calling app is moved to an
1781 * adopted storage device, so only relative paths should be persisted.
1782 * <p>
1783 * Apps require no extra permissions to read or write to the returned path,
1784 * since this path lives in their private storage.
1785 *
1786 * @param name Name of the directory to retrieve. This is a directory
1787 * that is created as part of your application data.
1788 * @param mode Operating mode.
1789 *
1790 * @return A {@link File} object for the requested directory. The directory
1791 * will have been created if it does not already exist.
1792 *
1793 * @see #openFileOutput(String, int)
1794 */
1795 public abstract File getDir(String name, @FileMode int mode);
1796
1797 /**
1798 * Open a new private SQLiteDatabase associated with this Context's
1799 * application package. Create the database file if it doesn't exist.
1800 *
1801 * @param name The name (unique in the application package) of the database.
1802 * @param mode Operating mode.
1803 * @param factory An optional factory class that is called to instantiate a
1804 * cursor when query is called.
1805 * @return The contents of a newly created database with the given name.
1806 * @throws android.database.sqlite.SQLiteException if the database file
1807 * could not be opened.
1808 * @see #MODE_PRIVATE
1809 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1810 * @see #MODE_NO_LOCALIZED_COLLATORS
1811 * @see #deleteDatabase
1812 */
1813 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1814 @DatabaseMode int mode, CursorFactory factory);
1815
1816 /**
1817 * Open a new private SQLiteDatabase associated with this Context's
1818 * application package. Creates the database file if it doesn't exist.
1819 * <p>
1820 * Accepts input param: a concrete instance of {@link DatabaseErrorHandler}
1821 * to be used to handle corruption when sqlite reports database corruption.
1822 * </p>
1823 *
1824 * @param name The name (unique in the application package) of the database.
1825 * @param mode Operating mode.
1826 * @param factory An optional factory class that is called to instantiate a
1827 * cursor when query is called.
1828 * @param errorHandler the {@link DatabaseErrorHandler} to be used when
1829 * sqlite reports database corruption. if null,
1830 * {@link android.database.DefaultDatabaseErrorHandler} is
1831 * assumed.
1832 * @return The contents of a newly created database with the given name.
1833 * @throws android.database.sqlite.SQLiteException if the database file
1834 * could not be opened.
1835 * @see #MODE_PRIVATE
1836 * @see #MODE_ENABLE_WRITE_AHEAD_LOGGING
1837 * @see #MODE_NO_LOCALIZED_COLLATORS
1838 * @see #deleteDatabase
1839 */
1840 public abstract SQLiteDatabase openOrCreateDatabase(String name,
1841 @DatabaseMode int mode, CursorFactory factory,
1842 @Nullable DatabaseErrorHandler errorHandler);
1843
1844 /**
1845 * Move an existing database file from the given source storage context to
1846 * this context. This is typically used to migrate data between storage
1847 * locations after an upgrade, such as migrating to device protected
1848 * storage.
1849 * <p>
1850 * The database must be closed before being moved.
1851 *
1852 * @param sourceContext The source context which contains the existing
1853 * database to move.
1854 * @param name The name of the database file.
1855 * @return {@code true} if the move was successful or if the database didn't
1856 * exist in the source context, otherwise {@code false}.
1857 * @see #createDeviceProtectedStorageContext()
1858 */
1859 public abstract boolean moveDatabaseFrom(Context sourceContext, String name);
1860
1861 /**
1862 * Delete an existing private SQLiteDatabase associated with this Context's
1863 * application package.
1864 *
1865 * @param name The name (unique in the application package) of the
1866 * database.
1867 *
1868 * @return {@code true} if the database was successfully deleted; else {@code false}.
1869 *
1870 * @see #openOrCreateDatabase
1871 */
1872 public abstract boolean deleteDatabase(String name);
1873
1874 /**
1875 * Returns the absolute path on the filesystem where a database created with
1876 * {@link #openOrCreateDatabase} is stored.
1877 * <p>
1878 * The returned path may change over time if the calling app is moved to an
1879 * adopted storage device, so only relative paths should be persisted.
1880 *
1881 * @param name The name of the database for which you would like to get
1882 * its path.
1883 *
1884 * @return An absolute path to the given database.
1885 *
1886 * @see #openOrCreateDatabase
1887 */
1888 public abstract File getDatabasePath(String name);
1889
1890 /**
1891 * Returns an array of strings naming the private databases associated with
1892 * this Context's application package.
1893 *
1894 * @return Array of strings naming the private databases.
1895 *
1896 * @see #openOrCreateDatabase
1897 * @see #deleteDatabase
1898 */
1899 public abstract String[] databaseList();
1900
1901 /**
1902 * @deprecated Use {@link android.app.WallpaperManager#getDrawable
1903 * WallpaperManager.get()} instead.
1904 */
1905 @Deprecated
1906 public abstract Drawable getWallpaper();
1907
1908 /**
1909 * @deprecated Use {@link android.app.WallpaperManager#peekDrawable
1910 * WallpaperManager.peek()} instead.
1911 */
1912 @Deprecated
1913 public abstract Drawable peekWallpaper();
1914
1915 /**
1916 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumWidth()
1917 * WallpaperManager.getDesiredMinimumWidth()} instead.
1918 */
1919 @Deprecated
1920 public abstract int getWallpaperDesiredMinimumWidth();
1921
1922 /**
1923 * @deprecated Use {@link android.app.WallpaperManager#getDesiredMinimumHeight()
1924 * WallpaperManager.getDesiredMinimumHeight()} instead.
1925 */
1926 @Deprecated
1927 public abstract int getWallpaperDesiredMinimumHeight();
1928
1929 /**
1930 * @deprecated Use {@link android.app.WallpaperManager#setBitmap(Bitmap)
1931 * WallpaperManager.set()} instead.
1932 * <p>This method requires the caller to hold the permission
1933 * {@link android.Manifest.permission#SET_WALLPAPER}.
1934 */
1935 @Deprecated
1936 public abstract void setWallpaper(Bitmap bitmap) throws IOException;
1937
1938 /**
1939 * @deprecated Use {@link android.app.WallpaperManager#setStream(InputStream)
1940 * WallpaperManager.set()} instead.
1941 * <p>This method requires the caller to hold the permission
1942 * {@link android.Manifest.permission#SET_WALLPAPER}.
1943 */
1944 @Deprecated
1945 public abstract void setWallpaper(InputStream data) throws IOException;
1946
1947 /**
1948 * @deprecated Use {@link android.app.WallpaperManager#clear
1949 * WallpaperManager.clear()} instead.
1950 * <p>This method requires the caller to hold the permission
1951 * {@link android.Manifest.permission#SET_WALLPAPER}.
1952 */
1953 @Deprecated
1954 public abstract void clearWallpaper() throws IOException;
1955
1956 /**
1957 * Same as {@link #startActivity(Intent, Bundle)} with no options
1958 * specified.
1959 *
1960 * @param intent The description of the activity to start.
1961 *
1962 * @throws ActivityNotFoundException &nbsp;
1963 *`
1964 * @see #startActivity(Intent, Bundle)
1965 * @see PackageManager#resolveActivity
1966 */
1967 public abstract void startActivity(@RequiresPermission Intent intent);
1968
1969 /**
1970 * Version of {@link #startActivity(Intent)} that allows you to specify the
1971 * user the activity will be started for. This is not available to applications
1972 * that are not pre-installed on the system image.
1973 * @param intent The description of the activity to start.
1974 * @param user The UserHandle of the user to start this activity for.
1975 * @throws ActivityNotFoundException &nbsp;
1976 * @hide
1977 */
1978 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
1979 @SystemApi
1980 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
1981 @NonNull UserHandle user) {
1982 throw new RuntimeException("Not implemented. Must override in a subclass.");
1983 }
1984
1985 /**
1986 * Launch a new activity. You will not receive any information about when
1987 * the activity exits.
1988 *
1989 * <p>Note that if this method is being called from outside of an
1990 * {@link android.app.Activity} Context, then the Intent must include
1991 * the {@link Intent#FLAG_ACTIVITY_NEW_TASK} launch flag. This is because,
1992 * without being started from an existing Activity, there is no existing
1993 * task in which to place the new activity and thus it needs to be placed
1994 * in its own separate task.
1995 *
1996 * <p>This method throws {@link ActivityNotFoundException}
1997 * if there was no Activity found to run the given Intent.
1998 *
1999 * @param intent The description of the activity to start.
2000 * @param options Additional options for how the Activity should be started.
2001 * May be null if there are no options. See {@link android.app.ActivityOptions}
2002 * for how to build the Bundle supplied here; there are no supported definitions
2003 * for building it manually.
2004 *
2005 * @throws ActivityNotFoundException &nbsp;
2006 *
2007 * @see #startActivity(Intent)
2008 * @see PackageManager#resolveActivity
2009 */
2010 public abstract void startActivity(@RequiresPermission Intent intent,
2011 @Nullable Bundle options);
2012
2013 /**
2014 * Version of {@link #startActivity(Intent, Bundle)} that allows you to specify the
2015 * user the activity will be started for. This is not available to applications
2016 * that are not pre-installed on the system image.
2017 * @param intent The description of the activity to start.
2018 * @param options Additional options for how the Activity should be started.
2019 * May be null if there are no options. See {@link android.app.ActivityOptions}
2020 * for how to build the Bundle supplied here; there are no supported definitions
2021 * for building it manually.
2022 * @param userId The UserHandle of the user to start this activity for.
2023 * @throws ActivityNotFoundException &nbsp;
2024 * @hide
2025 */
2026 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2027 @SystemApi
2028 public void startActivityAsUser(@RequiresPermission @NonNull Intent intent,
2029 @Nullable Bundle options, @NonNull UserHandle userId) {
2030 throw new RuntimeException("Not implemented. Must override in a subclass.");
2031 }
2032
2033 /**
2034 * Version of {@link #startActivity(Intent, Bundle)} that returns a result to the caller. This
2035 * is only supported for Views and Fragments.
2036 * @param who The identifier for the calling element that will receive the result.
2037 * @param intent The intent to start.
2038 * @param requestCode The code that will be returned with onActivityResult() identifying this
2039 * request.
2040 * @param options Additional options for how the Activity should be started.
2041 * May be null if there are no options. See {@link android.app.ActivityOptions}
2042 * for how to build the Bundle supplied here; there are no supported definitions
2043 * for building it manually.
2044 * @hide
2045 */
2046 @UnsupportedAppUsage
2047 public void startActivityForResult(
2048 @NonNull String who, Intent intent, int requestCode, @Nullable Bundle options) {
2049 throw new RuntimeException("This method is only implemented for Activity-based Contexts. "
2050 + "Check canStartActivityForResult() before calling.");
2051 }
2052
2053 /**
2054 * Identifies whether this Context instance will be able to process calls to
2055 * {@link #startActivityForResult(String, Intent, int, Bundle)}.
2056 * @hide
2057 */
2058 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
2059 public boolean canStartActivityForResult() {
2060 return false;
2061 }
2062
2063 /**
2064 * Same as {@link #startActivities(Intent[], Bundle)} with no options
2065 * specified.
2066 *
2067 * @param intents An array of Intents to be started.
2068 *
2069 * @throws ActivityNotFoundException &nbsp;
2070 *
2071 * @see #startActivities(Intent[], Bundle)
2072 * @see PackageManager#resolveActivity
2073 */
2074 public abstract void startActivities(@RequiresPermission Intent[] intents);
2075
2076 /**
2077 * Launch multiple new activities. This is generally the same as calling
2078 * {@link #startActivity(Intent)} for the first Intent in the array,
2079 * that activity during its creation calling {@link #startActivity(Intent)}
2080 * for the second entry, etc. Note that unlike that approach, generally
2081 * none of the activities except the last in the array will be created
2082 * at this point, but rather will be created when the user first visits
2083 * them (due to pressing back from the activity on top).
2084 *
2085 * <p>This method throws {@link ActivityNotFoundException}
2086 * if there was no Activity found for <em>any</em> given Intent. In this
2087 * case the state of the activity stack is undefined (some Intents in the
2088 * list may be on it, some not), so you probably want to avoid such situations.
2089 *
2090 * @param intents An array of Intents to be started.
2091 * @param options Additional options for how the Activity should be started.
2092 * See {@link android.content.Context#startActivity(Intent, Bundle)}
2093 * Context.startActivity(Intent, Bundle)} for more details.
2094 *
2095 * @throws ActivityNotFoundException &nbsp;
2096 *
2097 * @see #startActivities(Intent[])
2098 * @see PackageManager#resolveActivity
2099 */
2100 public abstract void startActivities(@RequiresPermission Intent[] intents, Bundle options);
2101
2102 /**
2103 * @hide
2104 * Launch multiple new activities. This is generally the same as calling
2105 * {@link #startActivity(Intent)} for the first Intent in the array,
2106 * that activity during its creation calling {@link #startActivity(Intent)}
2107 * for the second entry, etc. Note that unlike that approach, generally
2108 * none of the activities except the last in the array will be created
2109 * at this point, but rather will be created when the user first visits
2110 * them (due to pressing back from the activity on top).
2111 *
2112 * <p>This method throws {@link ActivityNotFoundException}
2113 * if there was no Activity found for <em>any</em> given Intent. In this
2114 * case the state of the activity stack is undefined (some Intents in the
2115 * list may be on it, some not), so you probably want to avoid such situations.
2116 *
2117 * @param intents An array of Intents to be started.
2118 * @param options Additional options for how the Activity should be started.
2119 * @param userHandle The user for whom to launch the activities
2120 * See {@link android.content.Context#startActivity(Intent, Bundle)}
2121 * Context.startActivity(Intent, Bundle)} for more details.
2122 *
2123 * @return The corresponding flag {@link ActivityManager#START_CANCELED},
2124 * {@link ActivityManager#START_SUCCESS} etc. indicating whether the launch was
2125 * successful.
2126 *
2127 * @throws ActivityNotFoundException &nbsp;
2128 *
2129 * @see #startActivities(Intent[])
2130 * @see PackageManager#resolveActivity
2131 */
2132 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2133 public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
2134 throw new RuntimeException("Not implemented. Must override in a subclass.");
2135 }
2136
2137 /**
2138 * Same as {@link #startIntentSender(IntentSender, Intent, int, int, int, Bundle)}
2139 * with no options specified.
2140 *
2141 * @param intent The IntentSender to launch.
2142 * @param fillInIntent If non-null, this will be provided as the
2143 * intent parameter to {@link IntentSender#sendIntent}.
2144 * @param flagsMask Intent flags in the original IntentSender that you
2145 * would like to change.
2146 * @param flagsValues Desired values for any bits set in
2147 * <var>flagsMask</var>
2148 * @param extraFlags Always set to 0.
2149 *
2150 * @see #startActivity(Intent)
2151 * @see #startIntentSender(IntentSender, Intent, int, int, int, Bundle)
2152 */
2153 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
2154 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
2155 int extraFlags) throws IntentSender.SendIntentException;
2156
2157 /**
2158 * Like {@link #startActivity(Intent, Bundle)}, but taking a IntentSender
2159 * to start. If the IntentSender is for an activity, that activity will be started
2160 * as if you had called the regular {@link #startActivity(Intent)}
2161 * here; otherwise, its associated action will be executed (such as
2162 * sending a broadcast) as if you had called
2163 * {@link IntentSender#sendIntent IntentSender.sendIntent} on it.
2164 *
2165 * @param intent The IntentSender to launch.
2166 * @param fillInIntent If non-null, this will be provided as the
2167 * intent parameter to {@link IntentSender#sendIntent}.
2168 * @param flagsMask Intent flags in the original IntentSender that you
2169 * would like to change.
2170 * @param flagsValues Desired values for any bits set in
2171 * <var>flagsMask</var>
2172 * @param extraFlags Always set to 0.
2173 * @param options Additional options for how the Activity should be started.
2174 * See {@link android.content.Context#startActivity(Intent, Bundle)}
2175 * Context.startActivity(Intent, Bundle)} for more details. If options
2176 * have also been supplied by the IntentSender, options given here will
2177 * override any that conflict with those given by the IntentSender.
2178 *
2179 * @see #startActivity(Intent, Bundle)
2180 * @see #startIntentSender(IntentSender, Intent, int, int, int)
2181 */
2182 public abstract void startIntentSender(IntentSender intent, @Nullable Intent fillInIntent,
2183 @Intent.MutableFlags int flagsMask, @Intent.MutableFlags int flagsValues,
2184 int extraFlags, @Nullable Bundle options) throws IntentSender.SendIntentException;
2185
2186 /**
2187 * Broadcast the given intent to all interested BroadcastReceivers. This
2188 * call is asynchronous; it returns immediately, and you will continue
2189 * executing while the receivers are run. No results are propagated from
2190 * receivers and receivers can not abort the broadcast. If you want
2191 * to allow receivers to propagate results or abort the broadcast, you must
2192 * send an ordered broadcast using
2193 * {@link #sendOrderedBroadcast(Intent, String)}.
2194 *
2195 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2196 *
2197 * @param intent The Intent to broadcast; all receivers matching this
2198 * Intent will receive the broadcast.
2199 *
2200 * @see android.content.BroadcastReceiver
2201 * @see #registerReceiver
2202 * @see #sendBroadcast(Intent, String)
2203 * @see #sendOrderedBroadcast(Intent, String)
2204 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2205 */
2206 public abstract void sendBroadcast(@RequiresPermission Intent intent);
2207
2208 /**
2209 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2210 * an optional required permission to be enforced. This
2211 * call is asynchronous; it returns immediately, and you will continue
2212 * executing while the receivers are run. No results are propagated from
2213 * receivers and receivers can not abort the broadcast. If you want
2214 * to allow receivers to propagate results or abort the broadcast, you must
2215 * send an ordered broadcast using
2216 * {@link #sendOrderedBroadcast(Intent, String)}.
2217 *
2218 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2219 *
2220 * @param intent The Intent to broadcast; all receivers matching this
2221 * Intent will receive the broadcast.
2222 * @param receiverPermission (optional) String naming a permission that
2223 * a receiver must hold in order to receive your broadcast.
2224 * If null, no permission is required.
2225 *
2226 * @see android.content.BroadcastReceiver
2227 * @see #registerReceiver
2228 * @see #sendBroadcast(Intent)
2229 * @see #sendOrderedBroadcast(Intent, String)
2230 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2231 */
2232 public abstract void sendBroadcast(@RequiresPermission Intent intent,
2233 @Nullable String receiverPermission);
2234
2235
2236 /**
2237 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2238 * an array of required permissions to be enforced. This call is asynchronous; it returns
2239 * immediately, and you will continue executing while the receivers are run. No results are
2240 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2241 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2242 * using {@link #sendOrderedBroadcast(Intent, String)}.
2243 *
2244 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2245 *
2246 * @param intent The Intent to broadcast; all receivers matching this
2247 * Intent will receive the broadcast.
2248 * @param receiverPermissions Array of names of permissions that a receiver must hold
2249 * in order to receive your broadcast.
2250 * If empty, no permissions are required.
2251 *
2252 * @see android.content.BroadcastReceiver
2253 * @see #registerReceiver
2254 * @see #sendBroadcast(Intent)
2255 * @see #sendOrderedBroadcast(Intent, String)
2256 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2257 * @hide
2258 */
2259 public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2260 @NonNull String[] receiverPermissions) {
2261 throw new RuntimeException("Not implemented. Must override in a subclass.");
2262 }
2263
2264 /**
2265 * Like {@link #sendBroadcastMultiplePermissions(Intent, String[])}, but also allows
2266 * specification of a list of excluded permissions. This allows sending a broadcast to an
2267 * app that has the permissions in `receiverPermissions` but not `excludedPermissions`.
2268 * @hide
2269 */
2270 public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2271 @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions) {
2272 sendBroadcastMultiplePermissions(intent, receiverPermissions, excludedPermissions, null);
2273 }
2274
2275
2276 /**
2277 * Like {@link #sendBroadcastMultiplePermissions(Intent, String[], String[])}, but also allows
2278 * specification of a list of excluded packages.
2279 *
2280 * @hide
2281 */
2282 public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2283 @NonNull String[] receiverPermissions, @Nullable String[] excludedPermissions,
2284 @Nullable String[] excludedPackages) {
2285 throw new RuntimeException("Not implemented. Must override in a subclass.");
2286 }
2287
2288 /**
2289 * Version of {@link #sendBroadcastMultiplePermissions(Intent, String[])} that allows you to
2290 * specify the {@link android.app.BroadcastOptions}.
2291 *
2292 * @param intent The Intent to broadcast; all receivers matching this
2293 * Intent will receive the broadcast.
2294 * @param receiverPermissions Array of names of permissions that a receiver must hold
2295 * in order to receive your broadcast.
2296 * If empty, no permissions are required.
2297 * @param options Additional sending options, generated from a
2298 * {@link android.app.BroadcastOptions}.
2299 * @see #sendBroadcastMultiplePermissions(Intent, String[])
2300 * @see android.app.BroadcastOptions
2301 * @hide
2302 */
2303 public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2304 @NonNull String[] receiverPermissions, @Nullable Bundle options) {
2305 throw new RuntimeException("Not implemented. Must override in a subclass.");
2306 }
2307
2308 /**
2309 * Version of {@link #sendBroadcastMultiplePermissions(Intent, String[])} that allows you to
2310 * specify the {@link android.app.BroadcastOptions}.
2311 *
2312 * @param intent The Intent to broadcast; all receivers matching this
2313 * Intent will receive the broadcast.
2314 * @param receiverPermissions Array of names of permissions that a receiver must hold
2315 * in order to receive your broadcast.
2316 * If empty, no permissions are required.
2317 * @param options Additional sending options, generated from a
2318 * {@link android.app.BroadcastOptions}.
2319 * @see #sendBroadcastMultiplePermissions(Intent, String[])
2320 * @see android.app.BroadcastOptions
2321 * @hide
2322 */
2323 @SystemApi
2324 public void sendBroadcastMultiplePermissions(@NonNull Intent intent,
2325 @NonNull String[] receiverPermissions, @Nullable BroadcastOptions options) {
2326 sendBroadcastMultiplePermissions(intent, receiverPermissions,
2327 (options == null ? null : options.toBundle()));
2328 }
2329
2330 /**
2331 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2332 * an array of required permissions to be enforced. This call is asynchronous; it returns
2333 * immediately, and you will continue executing while the receivers are run. No results are
2334 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2335 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2336 * using {@link #sendOrderedBroadcast(Intent, String)}.
2337 *
2338 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2339 *
2340 * @param intent The Intent to broadcast; all receivers matching this
2341 * Intent will receive the broadcast.
2342 * @param receiverPermissions Array of names of permissions that a receiver must hold
2343 * in order to receive your broadcast.
2344 * If empty, no permissions are required.
2345 *
2346 * @see android.content.BroadcastReceiver
2347 * @see #registerReceiver
2348 * @see #sendBroadcast(Intent)
2349 * @see #sendOrderedBroadcast(Intent, String)
2350 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2351 */
2352 public void sendBroadcastWithMultiplePermissions(@NonNull Intent intent,
2353 @NonNull String[] receiverPermissions) {
2354 sendBroadcastMultiplePermissions(intent, receiverPermissions);
2355 }
2356
2357 /**
2358 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2359 * an array of required permissions to be enforced. This call is asynchronous; it returns
2360 * immediately, and you will continue executing while the receivers are run. No results are
2361 * propagated from receivers and receivers can not abort the broadcast. If you want to allow
2362 * receivers to propagate results or abort the broadcast, you must send an ordered broadcast
2363 * using {@link #sendOrderedBroadcast(Intent, String)}.
2364 *
2365 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2366 *
2367 * @param intent The Intent to broadcast; all receivers matching this
2368 * Intent will receive the broadcast.
2369 * @param user The user to send the broadcast to.
2370 * @param receiverPermissions Array of names of permissions that a receiver must hold
2371 * in order to receive your broadcast.
2372 * If null or empty, no permissions are required.
2373 *
2374 * @see android.content.BroadcastReceiver
2375 * @see #registerReceiver
2376 * @see #sendBroadcast(Intent)
2377 * @see #sendOrderedBroadcast(Intent, String)
2378 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2379 * @hide
2380 */
2381 @SuppressWarnings("HiddenAbstractMethod")
2382 public abstract void sendBroadcastAsUserMultiplePermissions(Intent intent, UserHandle user,
2383 String[] receiverPermissions);
2384
2385 /**
2386 * Broadcast the given intent to all interested BroadcastReceivers, allowing
2387 * an optional required permission to be enforced. This
2388 * call is asynchronous; it returns immediately, and you will continue
2389 * executing while the receivers are run. No results are propagated from
2390 * receivers and receivers can not abort the broadcast. If you want
2391 * to allow receivers to propagate results or abort the broadcast, you must
2392 * send an ordered broadcast using
2393 * {@link #sendOrderedBroadcast(Intent, String)}.
2394 *
2395 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2396 *
2397 * @param intent The Intent to broadcast; all receivers matching this
2398 * Intent will receive the broadcast.
2399 * @param receiverPermission (optional) String naming a permission that
2400 * a receiver must hold in order to receive your broadcast.
2401 * If null, no permission is required.
2402 * @param options (optional) Additional sending options, generated from a
2403 * {@link android.app.BroadcastOptions}.
2404 *
2405 * @see android.content.BroadcastReceiver
2406 * @see #registerReceiver
2407 * @see #sendBroadcast(Intent)
2408 * @see #sendOrderedBroadcast(Intent, String)
2409 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2410 * @hide
2411 */
2412 @SuppressWarnings("HiddenAbstractMethod")
2413 @SystemApi
2414 public abstract void sendBroadcast(Intent intent,
2415 @Nullable String receiverPermission,
2416 @Nullable Bundle options);
2417
2418 /**
2419 * Like {@link #sendBroadcast(Intent, String)}, but also allows specification
2420 * of an associated app op as per {@link android.app.AppOpsManager}.
2421 * @hide
2422 */
2423 @SuppressWarnings("HiddenAbstractMethod")
2424 @UnsupportedAppUsage
2425 public abstract void sendBroadcast(Intent intent,
2426 String receiverPermission, int appOp);
2427
2428 /**
2429 * Broadcast the given intent to all interested BroadcastReceivers, delivering
2430 * them one at a time to allow more preferred receivers to consume the
2431 * broadcast before it is delivered to less preferred receivers. This
2432 * call is asynchronous; it returns immediately, and you will continue
2433 * executing while the receivers are run.
2434 *
2435 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2436 *
2437 * @param intent The Intent to broadcast; all receivers matching this
2438 * Intent will receive the broadcast.
2439 * @param receiverPermission (optional) String naming a permissions that
2440 * a receiver must hold in order to receive your broadcast.
2441 * If null, no permission is required.
2442 *
2443 * @see android.content.BroadcastReceiver
2444 * @see #registerReceiver
2445 * @see #sendBroadcast(Intent)
2446 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2447 */
2448 public abstract void sendOrderedBroadcast(@RequiresPermission Intent intent,
2449 @Nullable String receiverPermission);
2450
2451 /**
2452 * Version of {@link #sendBroadcast(Intent)} that allows you to
2453 * receive data back from the broadcast. This is accomplished by
2454 * supplying your own BroadcastReceiver when calling, which will be
2455 * treated as a final receiver at the end of the broadcast -- its
2456 * {@link BroadcastReceiver#onReceive} method will be called with
2457 * the result values collected from the other receivers. The broadcast will
2458 * be serialized in the same way as calling
2459 * {@link #sendOrderedBroadcast(Intent, String)}.
2460 *
2461 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2462 * asynchronous; it will return before
2463 * resultReceiver.onReceive() is called.
2464 *
2465 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2466 *
2467 * @param intent The Intent to broadcast; all receivers matching this
2468 * Intent will receive the broadcast.
2469 * @param receiverPermission String naming a permissions that
2470 * a receiver must hold in order to receive your broadcast.
2471 * If null, no permission is required.
2472 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2473 * receiver of the broadcast.
2474 * @param scheduler A custom Handler with which to schedule the
2475 * resultReceiver callback; if null it will be
2476 * scheduled in the Context's main thread.
2477 * @param initialCode An initial value for the result code. Often
2478 * Activity.RESULT_OK.
2479 * @param initialData An initial value for the result data. Often
2480 * null.
2481 * @param initialExtras An initial value for the result extras. Often
2482 * null.
2483 *
2484 * @see #sendBroadcast(Intent)
2485 * @see #sendBroadcast(Intent, String)
2486 * @see #sendOrderedBroadcast(Intent, String)
2487 * @see android.content.BroadcastReceiver
2488 * @see #registerReceiver
2489 * @see android.app.Activity#RESULT_OK
2490 */
2491 public abstract void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent,
2492 @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver,
2493 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2494 @Nullable Bundle initialExtras);
2495
2496 /**
2497 * Version of {@link #sendBroadcast(Intent)} that allows you to
2498 * receive data back from the broadcast. This is accomplished by
2499 * supplying your own BroadcastReceiver when calling, which will be
2500 * treated as a final receiver at the end of the broadcast -- its
2501 * {@link BroadcastReceiver#onReceive} method will be called with
2502 * the result values collected from the other receivers. The broadcast will
2503 * be serialized in the same way as calling
2504 * {@link #sendOrderedBroadcast(Intent, String)}.
2505 *
2506 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2507 * asynchronous; it will return before
2508 * resultReceiver.onReceive() is called.
2509 *
2510 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2511 *
2512 *
2513 * @param intent The Intent to broadcast; all receivers matching this
2514 * Intent will receive the broadcast.
2515 * @param receiverPermission String naming a permissions that
2516 * a receiver must hold in order to receive your broadcast.
2517 * If null, no permission is required.
2518 * @param options (optional) Additional sending options, generated from a
2519 * {@link android.app.BroadcastOptions}.
2520 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2521 * receiver of the broadcast.
2522 * @param scheduler A custom Handler with which to schedule the
2523 * resultReceiver callback; if null it will be
2524 * scheduled in the Context's main thread.
2525 * @param initialCode An initial value for the result code. Often
2526 * Activity.RESULT_OK.
2527 * @param initialData An initial value for the result data. Often
2528 * null.
2529 * @param initialExtras An initial value for the result extras. Often
2530 * null.
2531 * @see #sendBroadcast(Intent)
2532 * @see #sendBroadcast(Intent, String)
2533 * @see #sendOrderedBroadcast(Intent, String)
2534 * @see android.content.BroadcastReceiver
2535 * @see #registerReceiver
2536 * @see android.app.Activity#RESULT_OK
2537 * @hide
2538 */
2539 @SuppressWarnings("HiddenAbstractMethod")
2540 @SystemApi
2541 public abstract void sendOrderedBroadcast(@NonNull Intent intent,
2542 @Nullable String receiverPermission, @Nullable Bundle options,
2543 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2544 int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras);
2545
2546 /**
2547 * Like {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, android.os.Handler,
2548 * int, String, android.os.Bundle)}, but also allows specification
2549 * of an associated app op as per {@link android.app.AppOpsManager}.
2550 * @hide
2551 */
2552 @SuppressWarnings("HiddenAbstractMethod")
2553 @UnsupportedAppUsage
2554 public abstract void sendOrderedBroadcast(Intent intent,
2555 String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2556 Handler scheduler, int initialCode, String initialData,
2557 Bundle initialExtras);
2558
2559 /**
2560 * Version of {@link #sendBroadcast(Intent)} that allows you to specify the
2561 * user the broadcast will be sent to. This is not available to applications
2562 * that are not pre-installed on the system image.
2563 * @param intent The intent to broadcast
2564 * @param user UserHandle to send the intent to.
2565 * @see #sendBroadcast(Intent)
2566 */
2567 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2568 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2569 UserHandle user);
2570
2571 /**
2572 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2573 * user the broadcast will be sent to. This is not available to applications
2574 * that are not pre-installed on the system image.
2575 *
2576 * @param intent The Intent to broadcast; all receivers matching this
2577 * Intent will receive the broadcast.
2578 * @param user UserHandle to send the intent to.
2579 * @param receiverPermission (optional) String naming a permission that
2580 * a receiver must hold in order to receive your broadcast.
2581 * If null, no permission is required.
2582 *
2583 * @see #sendBroadcast(Intent, String)
2584 */
2585 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2586 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2587 UserHandle user, @Nullable String receiverPermission);
2588
2589 /**
2590 * Version of {@link #sendBroadcast(Intent, String, Bundle)} that allows you to specify the
2591 * user the broadcast will be sent to. This is not available to applications
2592 * that are not pre-installed on the system image.
2593 *
2594 * @param intent The Intent to broadcast; all receivers matching this
2595 * Intent will receive the broadcast.
2596 * @param user UserHandle to send the intent to.
2597 * @param receiverPermission (optional) String naming a permission that
2598 * a receiver must hold in order to receive your broadcast.
2599 * If null, no permission is required.
2600 * @param options (optional) Additional sending options, generated from a
2601 * {@link android.app.BroadcastOptions}.
2602 *
2603 * @see #sendBroadcast(Intent, String, Bundle)
2604 * @hide
2605 */
2606 @SuppressWarnings("HiddenAbstractMethod")
2607 @SystemApi
2608 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2609 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2610 UserHandle user, @Nullable String receiverPermission, @Nullable Bundle options);
2611
2612 /**
2613 * Version of {@link #sendBroadcast(Intent, String)} that allows you to specify the
2614 * user the broadcast will be sent to. This is not available to applications
2615 * that are not pre-installed on the system image.
2616 *
2617 * @param intent The Intent to broadcast; all receivers matching this
2618 * Intent will receive the broadcast.
2619 * @param user UserHandle to send the intent to.
2620 * @param receiverPermission (optional) String naming a permission that
2621 * a receiver must hold in order to receive your broadcast.
2622 * If null, no permission is required.
2623 * @param appOp The app op associated with the broadcast.
2624 *
2625 * @see #sendBroadcast(Intent, String)
2626 *
2627 * @hide
2628 */
2629 @SuppressWarnings("HiddenAbstractMethod")
2630 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2631 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
2632 public abstract void sendBroadcastAsUser(@RequiresPermission Intent intent,
2633 UserHandle user, @Nullable String receiverPermission, int appOp);
2634
2635 /**
2636 * Version of
2637 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)}
2638 * that allows you to specify the
2639 * user the broadcast will be sent to. This is not available to applications
2640 * that are not pre-installed on the system image.
2641 *
2642 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2643 *
2644 * @param intent The Intent to broadcast; all receivers matching this
2645 * Intent will receive the broadcast.
2646 * @param user UserHandle to send the intent to.
2647 * @param receiverPermission String naming a permissions that
2648 * a receiver must hold in order to receive your broadcast.
2649 * If null, no permission is required.
2650 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2651 * receiver of the broadcast.
2652 * @param scheduler A custom Handler with which to schedule the
2653 * resultReceiver callback; if null it will be
2654 * scheduled in the Context's main thread.
2655 * @param initialCode An initial value for the result code. Often
2656 * Activity.RESULT_OK.
2657 * @param initialData An initial value for the result data. Often
2658 * null.
2659 * @param initialExtras An initial value for the result extras. Often
2660 * null.
2661 *
2662 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2663 */
2664 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2665 public abstract void sendOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2666 UserHandle user, @Nullable String receiverPermission, BroadcastReceiver resultReceiver,
2667 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2668 @Nullable Bundle initialExtras);
2669
2670 /**
2671 * Similar to above but takes an appOp as well, to enforce restrictions.
2672 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2673 * BroadcastReceiver, Handler, int, String, Bundle)
2674 * @hide
2675 */
2676 @SuppressWarnings("HiddenAbstractMethod")
2677 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2678 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
2679 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2680 @Nullable String receiverPermission, int appOp, BroadcastReceiver resultReceiver,
2681 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2682 @Nullable Bundle initialExtras);
2683
2684 /**
2685 * Similar to above but takes an appOp as well, to enforce restrictions, and an options Bundle.
2686 * @see #sendOrderedBroadcastAsUser(Intent, UserHandle, String,
2687 * BroadcastReceiver, Handler, int, String, Bundle)
2688 * @hide
2689 */
2690 @SuppressWarnings("HiddenAbstractMethod")
2691 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
2692 @UnsupportedAppUsage
2693 public abstract void sendOrderedBroadcastAsUser(Intent intent, UserHandle user,
2694 @Nullable String receiverPermission, int appOp, @Nullable Bundle options,
2695 BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode,
2696 @Nullable String initialData, @Nullable Bundle initialExtras);
2697
2698 /**
2699 * Version of
2700 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2701 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2702 * the broadcast will be sent to.
2703 *
2704 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2705 *
2706 * @param intent The Intent to broadcast; all receivers matching this
2707 * Intent will receive the broadcast.
2708 * @param receiverPermission String naming a permissions that
2709 * a receiver must hold in order to receive your broadcast.
2710 * If null, no permission is required.
2711 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2712 * required. If both receiverAppOp and receiverPermission are non-null,
2713 * a receiver must have both of them to
2714 * receive the broadcast
2715 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2716 * receiver of the broadcast.
2717 * @param scheduler A custom Handler with which to schedule the
2718 * resultReceiver callback; if null it will be
2719 * scheduled in the Context's main thread.
2720 * @param initialCode An initial value for the result code. Often
2721 * Activity.RESULT_OK.
2722 * @param initialData An initial value for the result data. Often
2723 * null.
2724 * @param initialExtras An initial value for the result extras. Often
2725 * null.
2726 *
2727 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2728 */
2729 public void sendOrderedBroadcast(@NonNull Intent intent, @Nullable String receiverPermission,
2730 @Nullable String receiverAppOp, @Nullable BroadcastReceiver resultReceiver,
2731 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2732 @Nullable Bundle initialExtras) {
2733 throw new RuntimeException("Not implemented. Must override in a subclass.");
2734 }
2735
2736 /**
2737 * Version of
2738 * {@link #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String,
2739 * Bundle)} that allows you to specify the App Op to enforce restrictions on which receivers
2740 * the broadcast will be sent to as well as supply an optional sending options
2741 *
2742 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2743 *
2744 * @param intent The Intent to broadcast; all receivers matching this
2745 * Intent will receive the broadcast.
2746 * @param receiverPermission String naming a permissions that
2747 * a receiver must hold in order to receive your broadcast.
2748 * If null, no permission is required.
2749 * @param receiverAppOp The app op associated with the broadcast. If null, no appOp is
2750 * required. If both receiverAppOp and receiverPermission are non-null,
2751 * a receiver must have both of them to
2752 * receive the broadcast
2753 * @param options (optional) Additional sending options, generated from a
2754 * {@link android.app.BroadcastOptions}.
2755 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2756 * receiver of the broadcast.
2757 * @param scheduler A custom Handler with which to schedule the
2758 * resultReceiver callback; if null it will be
2759 * scheduled in the Context's main thread.
2760 * @param initialCode An initial value for the result code. Often
2761 * Activity.RESULT_OK.
2762 * @param initialData An initial value for the result data. Often
2763 * null.
2764 * @param initialExtras An initial value for the result extras. Often
2765 * null.
2766 *
2767 * @see #sendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, int, String, Bundle)
2768 * @see android.app.BroadcastOptions
2769 * @hide
2770 */
2771 public void sendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, int initialCode,
2772 @Nullable String receiverPermission, @Nullable String receiverAppOp,
2773 @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler,
2774 @Nullable String initialData, @Nullable Bundle initialExtras,
2775 @Nullable Bundle options) {
2776 throw new RuntimeException("Not implemented. Must override in a subclass.");
2777 }
2778
2779 /**
2780 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
2781 * Intent you are sending stays around after the broadcast is complete,
2782 * so that others can quickly retrieve that data through the return
2783 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2784 * all other ways, this behaves the same as
2785 * {@link #sendBroadcast(Intent)}.
2786 *
2787 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2788 * can access them), no protection (anyone can modify them), and many other problems.
2789 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2790 * has changed, with another mechanism for apps to retrieve the current value whenever
2791 * desired.
2792 *
2793 * @param intent The Intent to broadcast; all receivers matching this
2794 * Intent will receive the broadcast, and the Intent will be held to
2795 * be re-broadcast to future receivers.
2796 *
2797 * @see #sendBroadcast(Intent)
2798 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2799 */
2800 @Deprecated
2801 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
2802 public abstract void sendStickyBroadcast(@RequiresPermission Intent intent);
2803
2804 /**
2805 * <p>Perform a {@link #sendBroadcast(Intent)} that is "sticky," meaning the
2806 * Intent you are sending stays around after the broadcast is complete,
2807 * so that others can quickly retrieve that data through the return
2808 * value of {@link #registerReceiver(BroadcastReceiver, IntentFilter)}. In
2809 * all other ways, this behaves the same as
2810 * {@link #sendBroadcast(Intent)}.
2811 *
2812 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2813 * can access them), no protection (anyone can modify them), and many other problems.
2814 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2815 * has changed, with another mechanism for apps to retrieve the current value whenever
2816 * desired.
2817 *
2818 * @param intent The Intent to broadcast; all receivers matching this
2819 * Intent will receive the broadcast, and the Intent will be held to
2820 * be re-broadcast to future receivers.
2821 * @param options (optional) Additional sending options, generated from a
2822 * {@link android.app.BroadcastOptions}.
2823 *
2824 * @see #sendBroadcast(Intent)
2825 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2826 */
2827 @Deprecated
2828 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
2829 public void sendStickyBroadcast(@RequiresPermission @NonNull Intent intent,
2830 @Nullable Bundle options) {
2831 throw new RuntimeException("Not implemented. Must override in a subclass.");
2832 }
2833
2834 /**
2835 * <p>Version of {@link #sendStickyBroadcast} that allows you to
2836 * receive data back from the broadcast. This is accomplished by
2837 * supplying your own BroadcastReceiver when calling, which will be
2838 * treated as a final receiver at the end of the broadcast -- its
2839 * {@link BroadcastReceiver#onReceive} method will be called with
2840 * the result values collected from the other receivers. The broadcast will
2841 * be serialized in the same way as calling
2842 * {@link #sendOrderedBroadcast(Intent, String)}.
2843 *
2844 * <p>Like {@link #sendBroadcast(Intent)}, this method is
2845 * asynchronous; it will return before
2846 * resultReceiver.onReceive() is called. Note that the sticky data
2847 * stored is only the data you initially supply to the broadcast, not
2848 * the result of any changes made by the receivers.
2849 *
2850 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2851 *
2852 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2853 * can access them), no protection (anyone can modify them), and many other problems.
2854 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2855 * has changed, with another mechanism for apps to retrieve the current value whenever
2856 * desired.
2857 *
2858 * @param intent The Intent to broadcast; all receivers matching this
2859 * Intent will receive the broadcast.
2860 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2861 * receiver of the broadcast.
2862 * @param scheduler A custom Handler with which to schedule the
2863 * resultReceiver callback; if null it will be
2864 * scheduled in the Context's main thread.
2865 * @param initialCode An initial value for the result code. Often
2866 * Activity.RESULT_OK.
2867 * @param initialData An initial value for the result data. Often
2868 * null.
2869 * @param initialExtras An initial value for the result extras. Often
2870 * null.
2871 *
2872 * @see #sendBroadcast(Intent)
2873 * @see #sendBroadcast(Intent, String)
2874 * @see #sendOrderedBroadcast(Intent, String)
2875 * @see #sendStickyBroadcast(Intent)
2876 * @see android.content.BroadcastReceiver
2877 * @see #registerReceiver
2878 * @see android.app.Activity#RESULT_OK
2879 */
2880 @Deprecated
2881 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
2882 public abstract void sendStickyOrderedBroadcast(@RequiresPermission Intent intent,
2883 BroadcastReceiver resultReceiver,
2884 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2885 @Nullable Bundle initialExtras);
2886
2887 /**
2888 * <p>Remove the data previously sent with {@link #sendStickyBroadcast},
2889 * so that it is as if the sticky broadcast had never happened.
2890 *
2891 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2892 * can access them), no protection (anyone can modify them), and many other problems.
2893 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2894 * has changed, with another mechanism for apps to retrieve the current value whenever
2895 * desired.
2896 *
2897 * @param intent The Intent that was previously broadcast.
2898 *
2899 * @see #sendStickyBroadcast
2900 */
2901 @Deprecated
2902 @RequiresPermission(android.Manifest.permission.BROADCAST_STICKY)
2903 public abstract void removeStickyBroadcast(@RequiresPermission Intent intent);
2904
2905 /**
2906 * <p>Version of {@link #sendStickyBroadcast(Intent)} that allows you to specify the
2907 * user the broadcast will be sent to. This is not available to applications
2908 * that are not pre-installed on the system image.
2909 *
2910 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2911 * can access them), no protection (anyone can modify them), and many other problems.
2912 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2913 * has changed, with another mechanism for apps to retrieve the current value whenever
2914 * desired.
2915 *
2916 * @param intent The Intent to broadcast; all receivers matching this
2917 * Intent will receive the broadcast, and the Intent will be held to
2918 * be re-broadcast to future receivers.
2919 * @param user UserHandle to send the intent to.
2920 *
2921 * @see #sendBroadcast(Intent)
2922 */
2923 @Deprecated
2924 @RequiresPermission(allOf = {
2925 android.Manifest.permission.INTERACT_ACROSS_USERS,
2926 android.Manifest.permission.BROADCAST_STICKY
2927 })
2928 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2929 UserHandle user);
2930
2931 /**
2932 * @hide
2933 * This is just here for sending CONNECTIVITY_ACTION.
2934 */
2935 @SuppressWarnings("HiddenAbstractMethod")
2936 @Deprecated
2937 @RequiresPermission(allOf = {
2938 android.Manifest.permission.INTERACT_ACROSS_USERS,
2939 android.Manifest.permission.BROADCAST_STICKY
2940 })
2941 public abstract void sendStickyBroadcastAsUser(@RequiresPermission Intent intent,
2942 UserHandle user, Bundle options);
2943
2944 /**
2945 * <p>Version of
2946 * {@link #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)}
2947 * that allows you to specify the
2948 * user the broadcast will be sent to. This is not available to applications
2949 * that are not pre-installed on the system image.
2950 *
2951 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
2952 *
2953 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2954 * can access them), no protection (anyone can modify them), and many other problems.
2955 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2956 * has changed, with another mechanism for apps to retrieve the current value whenever
2957 * desired.
2958 *
2959 * @param intent The Intent to broadcast; all receivers matching this
2960 * Intent will receive the broadcast.
2961 * @param user UserHandle to send the intent to.
2962 * @param resultReceiver Your own BroadcastReceiver to treat as the final
2963 * receiver of the broadcast.
2964 * @param scheduler A custom Handler with which to schedule the
2965 * resultReceiver callback; if null it will be
2966 * scheduled in the Context's main thread.
2967 * @param initialCode An initial value for the result code. Often
2968 * Activity.RESULT_OK.
2969 * @param initialData An initial value for the result data. Often
2970 * null.
2971 * @param initialExtras An initial value for the result extras. Often
2972 * null.
2973 *
2974 * @see #sendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, int, String, Bundle)
2975 */
2976 @Deprecated
2977 @RequiresPermission(allOf = {
2978 android.Manifest.permission.INTERACT_ACROSS_USERS,
2979 android.Manifest.permission.BROADCAST_STICKY
2980 })
2981 public abstract void sendStickyOrderedBroadcastAsUser(@RequiresPermission Intent intent,
2982 UserHandle user, BroadcastReceiver resultReceiver,
2983 @Nullable Handler scheduler, int initialCode, @Nullable String initialData,
2984 @Nullable Bundle initialExtras);
2985
2986 /**
2987 * <p>Version of {@link #removeStickyBroadcast(Intent)} that allows you to specify the
2988 * user the broadcast will be sent to. This is not available to applications
2989 * that are not pre-installed on the system image.
2990 *
2991 * <p>You must hold the {@link android.Manifest.permission#BROADCAST_STICKY}
2992 * permission in order to use this API. If you do not hold that
2993 * permission, {@link SecurityException} will be thrown.
2994 *
2995 * @deprecated Sticky broadcasts should not be used. They provide no security (anyone
2996 * can access them), no protection (anyone can modify them), and many other problems.
2997 * The recommended pattern is to use a non-sticky broadcast to report that <em>something</em>
2998 * has changed, with another mechanism for apps to retrieve the current value whenever
2999 * desired.
3000 *
3001 * @param intent The Intent that was previously broadcast.
3002 * @param user UserHandle to remove the sticky broadcast from.
3003 *
3004 * @see #sendStickyBroadcastAsUser
3005 */
3006 @Deprecated
3007 @RequiresPermission(allOf = {
3008 android.Manifest.permission.INTERACT_ACROSS_USERS,
3009 android.Manifest.permission.BROADCAST_STICKY
3010 })
3011 public abstract void removeStickyBroadcastAsUser(@RequiresPermission Intent intent,
3012 UserHandle user);
3013
3014 /**
3015 * Register a BroadcastReceiver to be run in the main activity thread. The
3016 * <var>receiver</var> will be called with any broadcast Intent that
3017 * matches <var>filter</var>, in the main application thread.
3018 *
3019 * <p>The system may broadcast Intents that are "sticky" -- these stay
3020 * around after the broadcast has finished, to be sent to any later
3021 * registrations. If your IntentFilter matches one of these sticky
3022 * Intents, that Intent will be returned by this function
3023 * <strong>and</strong> sent to your <var>receiver</var> as if it had just
3024 * been broadcast.
3025 *
3026 * <p>There may be multiple sticky Intents that match <var>filter</var>,
3027 * in which case each of these will be sent to <var>receiver</var>. In
3028 * this case, only one of these can be returned directly by the function;
3029 * which of these that is returned is arbitrarily decided by the system.
3030 *
3031 * <p>If you know the Intent your are registering for is sticky, you can
3032 * supply null for your <var>receiver</var>. In this case, no receiver is
3033 * registered -- the function simply returns the sticky Intent that
3034 * matches <var>filter</var>. In the case of multiple matches, the same
3035 * rules as described above apply.
3036 *
3037 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3038 *
3039 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3040 * registered with this method will correctly respect the
3041 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3042 * Prior to that, it would be ignored and delivered to all matching registered
3043 * receivers. Be careful if using this for security.</p>
3044 *
3045 * <p class="note">Note: this method <em>cannot be called from a
3046 * {@link BroadcastReceiver} component;</em> that is, from a BroadcastReceiver
3047 * that is declared in an application's manifest. It is okay, however, to call
3048 * this method from another BroadcastReceiver that has itself been registered
3049 * at run time with {@link #registerReceiver}, since the lifetime of such a
3050 * registered BroadcastReceiver is tied to the object that registered it.</p>
3051 *
3052 * @param receiver The BroadcastReceiver to handle the broadcast.
3053 * @param filter Selects the Intent broadcasts to be received.
3054 *
3055 * @return The first sticky intent found that matches <var>filter</var>,
3056 * or null if there are none.
3057 *
3058 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3059 * @see #sendBroadcast
3060 * @see #unregisterReceiver
3061 */
3062 @Nullable
3063 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
3064 IntentFilter filter);
3065
3066 /**
3067 * Register to receive intent broadcasts, with the receiver optionally being
3068 * exposed to Instant Apps. See
3069 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
3070 * information. By default Instant Apps cannot interact with receivers in other
3071 * applications, this allows you to expose a receiver that Instant Apps can
3072 * interact with.
3073 *
3074 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3075 *
3076 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3077 * registered with this method will correctly respect the
3078 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3079 * Prior to that, it would be ignored and delivered to all matching registered
3080 * receivers. Be careful if using this for security.</p>
3081 *
3082 * @param receiver The BroadcastReceiver to handle the broadcast.
3083 * @param filter Selects the Intent broadcasts to be received.
3084 * @param flags Additional options for the receiver. In a future release, either
3085 * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
3086 * receiver isn't being registered for <a href="{@docRoot}guide/components
3087 * /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
3088 * thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
3089 * specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
3090 * system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
3091 * Android SDK. If both {@link #RECEIVER_EXPORTED} and
3092 * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as
3093 * well.
3094 *
3095 * @return The first sticky intent found that matches <var>filter</var>,
3096 * or null if there are none.
3097 *
3098 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
3099 * @see #sendBroadcast
3100 * @see #unregisterReceiver
3101 */
3102 @Nullable
3103 public abstract Intent registerReceiver(@Nullable BroadcastReceiver receiver,
3104 IntentFilter filter,
3105 @RegisterReceiverFlags int flags);
3106
3107 /**
3108 * Register to receive intent broadcasts, to run in the context of
3109 * <var>scheduler</var>. See
3110 * {@link #registerReceiver(BroadcastReceiver, IntentFilter)} for more
3111 * information. This allows you to enforce permissions on who can
3112 * broadcast intents to your receiver, or have the receiver run in
3113 * a different thread than the main application thread.
3114 *
3115 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3116 *
3117 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3118 * registered with this method will correctly respect the
3119 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3120 * Prior to that, it would be ignored and delivered to all matching registered
3121 * receivers. Be careful if using this for security.</p>
3122 *
3123 * @param receiver The BroadcastReceiver to handle the broadcast.
3124 * @param filter Selects the Intent broadcasts to be received.
3125 * @param broadcastPermission String naming a permissions that a
3126 * broadcaster must hold in order to send an Intent to you. If null,
3127 * no permission is required.
3128 * @param scheduler Handler identifying the thread that will receive
3129 * the Intent. If null, the main thread of the process will be used.
3130 *
3131 * @return The first sticky intent found that matches <var>filter</var>,
3132 * or null if there are none.
3133 *
3134 * @see #registerReceiver(BroadcastReceiver, IntentFilter)
3135 * @see #sendBroadcast
3136 * @see #unregisterReceiver
3137 */
3138 @Nullable
3139 public abstract Intent registerReceiver(BroadcastReceiver receiver,
3140 IntentFilter filter, @Nullable String broadcastPermission,
3141 @Nullable Handler scheduler);
3142
3143 /**
3144 * Register to receive intent broadcasts, to run in the context of
3145 * <var>scheduler</var>. See
3146 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, int)} and
3147 * {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
3148 * for more information.
3149 *
3150 * <p>See {@link BroadcastReceiver} for more information on Intent broadcasts.
3151 *
3152 * <p>As of {@link android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH}, receivers
3153 * registered with this method will correctly respect the
3154 * {@link Intent#setPackage(String)} specified for an Intent being broadcast.
3155 * Prior to that, it would be ignored and delivered to all matching registered
3156 * receivers. Be careful if using this for security.</p>
3157 *
3158 * @param receiver The BroadcastReceiver to handle the broadcast.
3159 * @param filter Selects the Intent broadcasts to be received.
3160 * @param broadcastPermission String naming a permissions that a
3161 * broadcaster must hold in order to send an Intent to you. If null,
3162 * no permission is required.
3163 * @param scheduler Handler identifying the thread that will receive
3164 * the Intent. If null, the main thread of the process will be used.
3165 * @param flags Additional options for the receiver. In a future release, either
3166 * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
3167 * receiver isn't being registered for <a href="{@docRoot}guide/components
3168 * /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
3169 * thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
3170 * specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
3171 * system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
3172 * Android SDK. If both {@link #RECEIVER_EXPORTED} and
3173 * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as
3174 * well.
3175 *
3176 * @return The first sticky intent found that matches <var>filter</var>,
3177 * or null if there are none.
3178 *
3179 * @see #registerReceiver(BroadcastReceiver, IntentFilter, int)
3180 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3181 * @see #sendBroadcast
3182 * @see #unregisterReceiver
3183 */
3184 @Nullable
3185 public abstract Intent registerReceiver(BroadcastReceiver receiver,
3186 IntentFilter filter, @Nullable String broadcastPermission,
3187 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
3188
3189 /**
3190 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)}
3191 * but this receiver will receive broadcasts that are sent to all users. The receiver can
3192 * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
3193 * was sent.
3194 *
3195 * @param receiver The BroadcastReceiver to handle the broadcast.
3196 * @param filter Selects the Intent broadcasts to be received.
3197 * @param broadcastPermission String naming a permissions that a
3198 * broadcaster must hold in order to send an Intent to you. If {@code null},
3199 * no permission is required.
3200 * @param scheduler Handler identifying the thread that will receive
3201 * the Intent. If {@code null}, the main thread of the process will be used.
3202 *
3203 * @return The first sticky intent found that matches <var>filter</var>,
3204 * or {@code null} if there are none.
3205 *
3206 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3207 * @see #sendBroadcast
3208 * @see #unregisterReceiver
3209 * @hide
3210 */
3211 @Nullable
3212 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3213 @SystemApi
3214 public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
3215 @NonNull IntentFilter filter, @Nullable String broadcastPermission,
3216 @Nullable Handler scheduler) {
3217 throw new RuntimeException("Not implemented. Must override in a subclass.");
3218 }
3219
3220 /**
3221 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)}
3222 * but this receiver will receive broadcasts that are sent to all users. The receiver can
3223 * use {@link BroadcastReceiver#getSendingUser} to determine on which user the broadcast
3224 * was sent.
3225 *
3226 * @param receiver The BroadcastReceiver to handle the broadcast.
3227 * @param filter Selects the Intent broadcasts to be received.
3228 * @param broadcastPermission String naming a permissions that a
3229 * broadcaster must hold in order to send an Intent to you. If {@code null},
3230 * no permission is required.
3231 * @param scheduler Handler identifying the thread that will receive
3232 * the Intent. If {@code null}, the main thread of the process will be used.
3233 * @param flags Additional options for the receiver. In a future release, either
3234 * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
3235 * receiver isn't being registered for <a href="{@docRoot}guide/components
3236 * /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
3237 * thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
3238 * specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
3239 * system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
3240 * Android SDK. If both {@link #RECEIVER_EXPORTED} and
3241 * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as
3242 * well.
3243 *
3244 * @return The first sticky intent found that matches <var>filter</var>,
3245 * or {@code null} if there are none.
3246 *
3247 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)
3248 * @see #sendBroadcast
3249 * @see #unregisterReceiver
3250 * @hide
3251 */
3252 @SuppressLint("IntentBuilderName")
3253 @Nullable
3254 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3255 @SystemApi
3256 public Intent registerReceiverForAllUsers(@Nullable BroadcastReceiver receiver,
3257 @NonNull IntentFilter filter, @Nullable String broadcastPermission,
3258 @Nullable Handler scheduler, @RegisterReceiverFlags int flags) {
3259 throw new RuntimeException("Not implemented. Must override in a subclass.");
3260 }
3261
3262 /**
3263 * @hide
3264 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3265 * but for a specific user. This receiver will receiver broadcasts that
3266 * are sent to the requested user.
3267 *
3268 * @param receiver The BroadcastReceiver to handle the broadcast.
3269 * @param user UserHandle to send the intent to.
3270 * @param filter Selects the Intent broadcasts to be received.
3271 * @param broadcastPermission String naming a permissions that a
3272 * broadcaster must hold in order to send an Intent to you. If null,
3273 * no permission is required.
3274 * @param scheduler Handler identifying the thread that will receive
3275 * the Intent. If null, the main thread of the process will be used.
3276 *
3277 * @return The first sticky intent found that matches <var>filter</var>,
3278 * or null if there are none.
3279 *
3280 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
3281 * @see #sendBroadcast
3282 * @see #unregisterReceiver
3283 */
3284 @SuppressWarnings("HiddenAbstractMethod")
3285 @Nullable
3286 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3287 @UnsupportedAppUsage
3288 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
3289 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
3290 @Nullable Handler scheduler);
3291
3292 /**
3293 * @hide
3294 * Same as {@link #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)
3295 * but for a specific user. This receiver will receiver broadcasts that
3296 * are sent to the requested user.
3297 *
3298 * @param receiver The BroadcastReceiver to handle the broadcast.
3299 * @param user UserHandle to send the intent to.
3300 * @param filter Selects the Intent broadcasts to be received.
3301 * @param broadcastPermission String naming a permissions that a
3302 * broadcaster must hold in order to send an Intent to you. If null,
3303 * no permission is required.
3304 * @param scheduler Handler identifying the thread that will receive
3305 * the Intent. If null, the main thread of the process will be used.
3306 * @param flags Additional options for the receiver. In a future release, either
3307 * {@link #RECEIVER_EXPORTED} or {@link #RECEIVER_NOT_EXPORTED} must be specified if the
3308 * receiver isn't being registered for <a href="{@docRoot}guide/components
3309 * /broadcasts#system-broadcasts">system broadcasts</a> or an exception will be
3310 * thrown. If {@link #RECEIVER_EXPORTED} is specified, a receiver may additionally
3311 * specify {@link #RECEIVER_VISIBLE_TO_INSTANT_APPS}. For a complete list of
3312 * system broadcast actions, see the BROADCAST_ACTIONS.TXT file in the
3313 * Android SDK. If both {@link #RECEIVER_EXPORTED} and
3314 * {@link #RECEIVER_NOT_EXPORTED} are specified, an exception will be thrown as
3315 * well.
3316 *
3317 * @return The first sticky intent found that matches <var>filter</var>,
3318 * or null if there are none.
3319 *
3320 * @see #registerReceiver(BroadcastReceiver, IntentFilter, String, Handler, int)
3321 * @see #sendBroadcast
3322 * @see #unregisterReceiver
3323 */
3324 @SuppressWarnings("HiddenAbstractMethod")
3325 @SuppressLint("IntentBuilderName")
3326 @Nullable
3327 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
3328 @UnsupportedAppUsage
3329 public abstract Intent registerReceiverAsUser(BroadcastReceiver receiver,
3330 UserHandle user, IntentFilter filter, @Nullable String broadcastPermission,
3331 @Nullable Handler scheduler, @RegisterReceiverFlags int flags);
3332
3333 /**
3334 * Unregister a previously registered BroadcastReceiver. <em>All</em>
3335 * filters that have been registered for this BroadcastReceiver will be
3336 * removed.
3337 *
3338 * @param receiver The BroadcastReceiver to unregister.
3339 *
3340 * @see #registerReceiver
3341 */
3342 public abstract void unregisterReceiver(BroadcastReceiver receiver);
3343
3344 /**
3345 * Request that a given application service be started. The Intent
3346 * should either contain the complete class name of a specific service
3347 * implementation to start, or a specific package name to target. If the
3348 * Intent is less specified, it logs a warning about this. In this case any of the
3349 * multiple matching services may be used. If this service
3350 * is not already running, it will be instantiated and started (creating a
3351 * process for it if needed); if it is running then it remains running.
3352 *
3353 * <p>Every call to this method will result in a corresponding call to
3354 * the target service's {@link android.app.Service#onStartCommand} method,
3355 * with the <var>intent</var> given here. This provides a convenient way
3356 * to submit jobs to a service without having to bind and call on to its
3357 * interface.
3358 *
3359 * <p>Using startService() overrides the default service lifetime that is
3360 * managed by {@link #bindService}: it requires the service to remain
3361 * running until {@link #stopService} is called, regardless of whether
3362 * any clients are connected to it. Note that calls to startService()
3363 * do not nest: no matter how many times you call startService(),
3364 * a single call to {@link #stopService} will stop it.
3365 *
3366 * <p>The system attempts to keep running services around as much as
3367 * possible. The only time they should be stopped is if the current
3368 * foreground application is using so many resources that the service needs
3369 * to be killed. If any errors happen in the service's process, it will
3370 * automatically be restarted.
3371 *
3372 * <p>This function will throw {@link SecurityException} if you do not
3373 * have permission to start the given service.
3374 *
3375 * <div class="caution">
3376 * <p><strong>Note:</strong> Each call to startService()
3377 * results in significant work done by the system to manage service
3378 * lifecycle surrounding the processing of the intent, which can take
3379 * multiple milliseconds of CPU time. Due to this cost, startService()
3380 * should not be used for frequent intent delivery to a service, and only
3381 * for scheduling significant work. Use {@link #bindService bound services}
3382 * for high frequency calls.
3383 * </p>
3384 *
3385 * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#O},
3386 * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#O}
3387 * or higher are not allowed to start background services from the background.
3388 * See
3389 * <a href="/about/versions/oreo/background">
3390 * Background Execution Limits</a>
3391 * for more details.
3392 *
3393 * <p><strong>Note:</strong>
3394 * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#S},
3395 * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#S}
3396 * or higher are not allowed to start foreground services from the background.
3397 * See
3398 * <a href="/about/versions/12/behavior-changes-12">
3399 * Behavior changes: Apps targeting Android 12
3400 * </a>
3401 * for more details.
3402 * </div>
3403 *
3404 * @param service Identifies the service to be started. The Intent must be
3405 * fully explicit (supplying a component name). Additional values
3406 * may be included in the Intent extras to supply arguments along with
3407 * this specific start call.
3408 *
3409 * @return If the service is being started or is already running, the
3410 * {@link ComponentName} of the actual service that was started is
3411 * returned; else if the service does not exist null is returned.
3412 *
3413 * @throws SecurityException If the caller does not have permission to access the service
3414 * or the service can not be found.
3415 * @throws IllegalStateException
3416 * Before Android {@link android.os.Build.VERSION_CODES#S},
3417 * if the application is in a state where the service
3418 * can not be started (such as not in the foreground in a state when services are allowed),
3419 * {@link IllegalStateException} was thrown.
3420 * @throws android.app.BackgroundServiceStartNotAllowedException
3421 * On Android {@link android.os.Build.VERSION_CODES#S} and later,
3422 * if the application is in a state where the service
3423 * can not be started (such as not in the foreground in a state when services are allowed),
3424 * {@link android.app.BackgroundServiceStartNotAllowedException} is thrown
3425 * This excemption extends {@link IllegalStateException}, so apps can
3426 * use {@code catch (IllegalStateException)} to catch both.
3427 *
3428 * @see #startForegroundService(Intent)
3429 * @see #stopService
3430 * @see #bindService
3431 */
3432 @Nullable
3433 public abstract ComponentName startService(Intent service);
3434
3435 /**
3436 * Similar to {@link #startService(Intent)}, but with an implicit promise that the
3437 * Service will call {@link android.app.Service#startForeground(int, android.app.Notification)
3438 * startForeground(int, android.app.Notification)} once it begins running. The service is given
3439 * an amount of time comparable to the ANR interval to do this, otherwise the system
3440 * will automatically crash the process, in which case an internal exception
3441 * {@code ForegroundServiceDidNotStartInTimeException} is logged on logcat on devices
3442 * running SDK Version {@link android.os.Build.VERSION_CODES#S} or later. On older Android
3443 * versions, an internal exception {@code RemoteServiceException} is logged instead, with
3444 * a corresponding message.
3445 *
3446 * <p>Unlike the ordinary {@link #startService(Intent)}, this method can be used
3447 * at any time, regardless of whether the app hosting the service is in a foreground
3448 * state.
3449 *
3450 * <div class="caution">
3451 * <p><strong>Note:</strong>
3452 * Beginning with SDK Version {@link android.os.Build.VERSION_CODES#S},
3453 * apps targeting SDK Version {@link android.os.Build.VERSION_CODES#S}
3454 * or higher are not allowed to start foreground services from the background.
3455 * See
3456 * <a href="/about/versions/12/behavior-changes-12">
3457 * Behavior changes: Apps targeting Android 12
3458 * </a>
3459 * for more details.
3460 * </div>
3461 *
3462 * @param service Identifies the service to be started. The Intent must be
3463 * fully explicit (supplying a component name). Additional values
3464 * may be included in the Intent extras to supply arguments along with
3465 * this specific start call.
3466 *
3467 * @return If the service is being started or is already running, the
3468 * {@link ComponentName} of the actual service that was started is
3469 * returned; else if the service does not exist null is returned.
3470 *
3471 * @throws SecurityException If the caller does not have permission to access the service
3472 * or the service can not be found.
3473 *
3474 * @throws android.app.ForegroundServiceStartNotAllowedException
3475 * If the caller app's targeting API is
3476 * {@link android.os.Build.VERSION_CODES#S} or later, and the foreground service is restricted
3477 * from start due to background restriction.
3478 *
3479 * @see #stopService
3480 * @see android.app.Service#startForeground(int, android.app.Notification)
3481 */
3482 @Nullable
3483 public abstract ComponentName startForegroundService(Intent service);
3484
3485 /**
3486 * @hide like {@link #startForegroundService(Intent)} but for a specific user.
3487 */
3488 @SuppressWarnings("HiddenAbstractMethod")
3489 @Nullable
3490 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
3491 public abstract ComponentName startForegroundServiceAsUser(Intent service, UserHandle user);
3492
3493 /**
3494 * Request that a given application service be stopped. If the service is
3495 * not running, nothing happens. Otherwise it is stopped. Note that calls
3496 * to startService() are not counted -- this stops the service no matter
3497 * how many times it was started.
3498 *
3499 * <p>If the service is running as a foreground service when it is
3500 * stopped, its associated notification will be removed. To avoid this,
3501 * apps can use {@link android.app.Service#stopForeground(int)
3502 * stopForeground(STOP_FOREGROUND_DETACH)} to decouple the notification
3503 * from the service's lifecycle before stopping it.</p>
3504 *
3505 * <p>Note that if a stopped service still has {@link ServiceConnection}
3506 * objects bound to it with the {@link #BIND_AUTO_CREATE} set, it will
3507 * not be destroyed until all of these bindings are removed. See
3508 * the {@link android.app.Service} documentation for more details on a
3509 * service's lifecycle.
3510 *
3511 * <p>This function will throw {@link SecurityException} if you do not
3512 * have permission to stop the given service.
3513 *
3514 * @param service Description of the service to be stopped. The Intent must be either
3515 * fully explicit (supplying a component name) or specify a specific package
3516 * name it is targeted to.
3517 *
3518 * @return If there is a service matching the given Intent that is already
3519 * running, then it is stopped and {@code true} is returned; else {@code false} is returned.
3520 *
3521 * @throws SecurityException If the caller does not have permission to access the service
3522 * or the service can not be found.
3523 * @throws IllegalStateException If the application is in a state where the service
3524 * can not be started (such as not in the foreground in a state when services are allowed).
3525 *
3526 * @see #startService
3527 */
3528 public abstract boolean stopService(Intent service);
3529
3530 /**
3531 * @hide like {@link #startService(Intent)} but for a specific user.
3532 */
3533 @SuppressWarnings("HiddenAbstractMethod")
3534 @Nullable
3535 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
3536 @UnsupportedAppUsage
3537 public abstract ComponentName startServiceAsUser(Intent service, UserHandle user);
3538
3539 /**
3540 * @hide like {@link #stopService(Intent)} but for a specific user.
3541 */
3542 @SuppressWarnings("HiddenAbstractMethod")
3543 @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)
3544 public abstract boolean stopServiceAsUser(Intent service, UserHandle user);
3545
3546 /**
3547 * Connects to an application service, creating it if needed. This defines
3548 * a dependency between your application and the service. The given
3549 * <var>conn</var> will receive the service object when it is created and be
3550 * told if it dies and restarts. The service will be considered required
3551 * by the system only for as long as the calling context exists. For
3552 * example, if this Context is an Activity that is stopped, the service will
3553 * not be required to continue running until the Activity is resumed.
3554 *
3555 * <p>If the service does not support binding, it may return {@code null} from
3556 * its {@link android.app.Service#onBind(Intent) onBind()} method. If it does, then
3557 * the ServiceConnection's
3558 * {@link ServiceConnection#onNullBinding(ComponentName) onNullBinding()} method
3559 * will be invoked instead of
3560 * {@link ServiceConnection#onServiceConnected(ComponentName, IBinder) onServiceConnected()}.
3561 *
3562 * <p class="note"><b>Note:</b> This method <em>cannot</em> be called from a
3563 * {@link BroadcastReceiver} component. A pattern you can use to
3564 * communicate from a BroadcastReceiver to a Service is to call
3565 * {@link #startService} with the arguments containing the command to be
3566 * sent, with the service calling its
3567 * {@link android.app.Service#stopSelf(int)} method when done executing
3568 * that command. See the API demo App/Service/Service Start Arguments
3569 * Controller for an illustration of this. It is okay, however, to use
3570 * this method from a BroadcastReceiver that has been registered with
3571 * {@link #registerReceiver}, since the lifetime of this BroadcastReceiver
3572 * is tied to another object (the one that registered it).</p>
3573 *
3574 * @param service Identifies the service to connect to. The Intent must
3575 * specify an explicit component name.
3576 * @param conn Receives information as the service is started and stopped.
3577 * This must be a valid ServiceConnection object; it must not be null.
3578 * @param flags Operation options for the binding. Can be:
3579 * <ul>
3580 * <li>0
3581 * <li>{@link #BIND_AUTO_CREATE}
3582 * <li>{@link #BIND_DEBUG_UNBIND}
3583 * <li>{@link #BIND_NOT_FOREGROUND}
3584 * <li>{@link #BIND_ABOVE_CLIENT}
3585 * <li>{@link #BIND_ALLOW_OOM_MANAGEMENT}
3586 * <li>{@link #BIND_WAIVE_PRIORITY}
3587 * <li>{@link #BIND_IMPORTANT}
3588 * <li>{@link #BIND_ADJUST_WITH_ACTIVITY}
3589 * <li>{@link #BIND_NOT_PERCEPTIBLE}
3590 * <li>{@link #BIND_INCLUDE_CAPABILITIES}
3591 * </ul>
3592 *
3593 * @return {@code true} if the system is in the process of bringing up a
3594 * service that your client has permission to bind to; {@code false}
3595 * if the system couldn't find the service or if your client doesn't
3596 * have permission to bind to it. Regardless of the return value, you
3597 * should later call {@link #unbindService} to release the connection.
3598 *
3599 * @throws SecurityException If the caller does not have permission to
3600 * access the service or the service cannot be found. Call
3601 * {@link #unbindService} to release the connection when this exception
3602 * is thrown.
3603 *
3604 * @see #unbindService
3605 * @see #startService
3606 */
3607 public abstract boolean bindService(@RequiresPermission Intent service,
3608 @NonNull ServiceConnection conn, @BindServiceFlags int flags);
3609
3610 /**
3611 * Same as {@link #bindService(Intent, ServiceConnection, int)
3612 * bindService(Intent, ServiceConnection, int)} with executor to control ServiceConnection
3613 * callbacks.
3614 *
3615 * @param executor Callbacks on ServiceConnection will be called on executor. Must use same
3616 * instance for the same instance of ServiceConnection.
3617 *
3618 * @return The result of the binding as described in
3619 * {@link #bindService(Intent, ServiceConnection, int)
3620 * bindService(Intent, ServiceConnection, int)}.
3621 */
3622 public boolean bindService(@RequiresPermission @NonNull Intent service,
3623 @BindServiceFlags int flags, @NonNull @CallbackExecutor Executor executor,
3624 @NonNull ServiceConnection conn) {
3625 throw new RuntimeException("Not implemented. Must override in a subclass.");
3626 }
3627
3628 /**
3629 * Variation of {@link #bindService} that, in the specific case of isolated
3630 * services, allows the caller to generate multiple instances of a service
3631 * from a single component declaration. In other words, you can use this to bind
3632 * to a service that has specified {@link android.R.attr#isolatedProcess} and, in
3633 * addition to the existing behavior of running in an isolated process, you can
3634 * also through the arguments here have the system bring up multiple concurrent
3635 * processes hosting their own instances of that service. The <var>instanceName</var>
3636 * you provide here identifies the different instances, and you can use
3637 * {@link #updateServiceGroup(ServiceConnection, int, int)} to tell the system how it
3638 * should manage each of these instances.
3639 *
3640 * @param service Identifies the service to connect to. The Intent must
3641 * specify an explicit component name.
3642 * @param flags Operation options for the binding as per {@link #bindService}.
3643 * @param instanceName Unique identifier for the service instance. Each unique
3644 * name here will result in a different service instance being created. Identifiers
3645 * must only contain ASCII letters, digits, underscores, and periods.
3646 * @param executor Callbacks on ServiceConnection will be called on executor.
3647 * Must use same instance for the same instance of ServiceConnection.
3648 * @param conn Receives information as the service is started and stopped.
3649 * This must be a valid ServiceConnection object; it must not be null.
3650 *
3651 * @return Returns success of binding as per {@link #bindService}.
3652 *
3653 * @throws SecurityException If the caller does not have permission to access the service
3654 * @throws IllegalArgumentException If the instanceName is invalid.
3655 *
3656 * @see #bindService
3657 * @see #updateServiceGroup
3658 * @see android.R.attr#isolatedProcess
3659 */
3660 public boolean bindIsolatedService(@RequiresPermission @NonNull Intent service,
3661 @BindServiceFlags int flags, @NonNull String instanceName,
3662 @NonNull @CallbackExecutor Executor executor, @NonNull ServiceConnection conn) {
3663 throw new RuntimeException("Not implemented. Must override in a subclass.");
3664 }
3665
3666 /**
3667 * Binds to a service in the given {@code user} in the same manner as {@link #bindService}.
3668 *
3669 * <p>Requires that one of the following conditions are met:
3670 * <ul>
3671 * <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}</li>
3672 * <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_USERS} and is the same
3673 * package as the {@code service} (determined by its component's package) and the Android
3674 * version is at least {@link android.os.Build.VERSION_CODES#TIRAMISU}</li>
3675 * <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_USERS} and is in same
3676 * profile group as the given {@code user}</li>
3677 * <li>caller has {@code android.Manifest.permission.INTERACT_ACROSS_PROFILES} and is in same
3678 * profile group as the given {@code user} and is the same package as the {@code service}
3679 * </li>
3680 * </ul>
3681 *
3682 * @param service Identifies the service to connect to. The Intent must
3683 * specify an explicit component name.
3684 * @param conn Receives information as the service is started and stopped.
3685 * This must be a valid ServiceConnection object; it must not be null.
3686 * @param flags Operation options for the binding. May be 0,
3687 * {@link #BIND_AUTO_CREATE}, {@link #BIND_DEBUG_UNBIND},
3688 * {@link #BIND_NOT_FOREGROUND}, {@link #BIND_ABOVE_CLIENT},
3689 * {@link #BIND_ALLOW_OOM_MANAGEMENT}, {@link #BIND_WAIVE_PRIORITY}.
3690 * {@link #BIND_IMPORTANT}, or
3691 * {@link #BIND_ADJUST_WITH_ACTIVITY}.
3692 * @return {@code true} if the system is in the process of bringing up a
3693 * service that your client has permission to bind to; {@code false}
3694 * if the system couldn't find the service. You should call {@link #unbindService}
3695 * to release the connection even if this method returned {@code false}.
3696 *
3697 * @throws SecurityException if the client does not have the required permission to bind.
3698 */
3699 @SuppressWarnings("unused")
3700 @RequiresPermission(anyOf = {
3701 android.Manifest.permission.INTERACT_ACROSS_USERS,
3702 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
3703 android.Manifest.permission.INTERACT_ACROSS_PROFILES
3704 }, conditional = true)
3705 public boolean bindServiceAsUser(
3706 @NonNull @RequiresPermission Intent service, @NonNull ServiceConnection conn, int flags,
3707 @NonNull UserHandle user) {
3708 throw new RuntimeException("Not implemented. Must override in a subclass.");
3709 }
3710
3711 /**
3712 * Same as {@link #bindServiceAsUser(Intent, ServiceConnection, int, UserHandle)}, but with an
3713 * explicit non-null Handler to run the ServiceConnection callbacks on.
3714 *
3715 * @hide
3716 */
3717 @RequiresPermission(anyOf = {
3718 android.Manifest.permission.INTERACT_ACROSS_USERS,
3719 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
3720 android.Manifest.permission.INTERACT_ACROSS_PROFILES
3721 }, conditional = true)
3722 @UnsupportedAppUsage(trackingBug = 136728678)
3723 public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags,
3724 Handler handler, UserHandle user) {
3725 throw new RuntimeException("Not implemented. Must override in a subclass.");
3726 }
3727
3728 /**
3729 * For a service previously bound with {@link #bindService} or a related method, change
3730 * how the system manages that service's process in relation to other processes. This
3731 * doesn't modify the original bind flags that were passed in when binding, but adjusts
3732 * how the process will be managed in some cases based on those flags. Currently only
3733 * works on isolated processes (will be ignored for non-isolated processes).
3734 *
3735 * <p>Note that this call does not take immediate effect, but will be applied the next
3736 * time the impacted process is adjusted for some other reason. Typically you would
3737 * call this before then calling a new {@link #bindIsolatedService} on the service
3738 * of interest, with that binding causing the process to be shuffled accordingly.</p>
3739 *
3740 * @param conn The connection interface previously supplied to bindService(). This
3741 * parameter must not be null.
3742 * @param group A group to put this connection's process in. Upon calling here, this
3743 * will override any previous group that was set for that process. The group
3744 * tells the system about processes that are logically grouped together, so
3745 * should be managed as one unit of importance (such as when being considered
3746 * a recently used app). All processes in the same app with the same group
3747 * are considered to be related. Supplying 0 reverts to the default behavior
3748 * of not grouping.
3749 * @param importance Additional importance of the processes within a group. Upon calling
3750 * here, this will override any previous importance that was set for that
3751 * process. The most important process is 0, and higher values are
3752 * successively less important. You can view this as describing how
3753 * to order the processes in an array, with the processes at the end of
3754 * the array being the least important. This value has no meaning besides
3755 * indicating how processes should be ordered in that array one after the
3756 * other. This provides a way to fine-tune the system's process killing,
3757 * guiding it to kill processes at the end of the array first.
3758 *
3759 * @see #bindIsolatedService
3760 */
3761 public void updateServiceGroup(@NonNull ServiceConnection conn, int group,
3762 int importance) {
3763 throw new RuntimeException("Not implemented. Must override in a subclass.");
3764 }
3765
3766 /**
3767 * Disconnect from an application service. You will no longer receive
3768 * calls as the service is restarted, and the service is now allowed to
3769 * stop at any time.
3770 *
3771 * @param conn The connection interface previously supplied to
3772 * bindService(). This parameter must not be null.
3773 *
3774 * @see #bindService
3775 */
3776 public abstract void unbindService(@NonNull ServiceConnection conn);
3777
3778 /**
3779 * Start executing an {@link android.app.Instrumentation} class. The given
3780 * Instrumentation component will be run by killing its target application
3781 * (if currently running), starting the target process, instantiating the
3782 * instrumentation component, and then letting it drive the application.
3783 *
3784 * <p>This function is not synchronous -- it returns as soon as the
3785 * instrumentation has started and while it is running.
3786 *
3787 * <p>Instrumentation is normally only allowed to run against a package
3788 * that is either unsigned or signed with a signature that the
3789 * the instrumentation package is also signed with (ensuring the target
3790 * trusts the instrumentation).
3791 *
3792 * @param className Name of the Instrumentation component to be run.
3793 * @param profileFile Optional path to write profiling data as the
3794 * instrumentation runs, or null for no profiling.
3795 * @param arguments Additional optional arguments to pass to the
3796 * instrumentation, or null.
3797 *
3798 * @return {@code true} if the instrumentation was successfully started,
3799 * else {@code false} if it could not be found.
3800 */
3801 public abstract boolean startInstrumentation(@NonNull ComponentName className,
3802 @Nullable String profileFile, @Nullable Bundle arguments);
3803
3804 /** @hide */
3805 @StringDef(suffix = { "_SERVICE" }, value = {
3806 POWER_SERVICE,
3807 //@hide: POWER_STATS_SERVICE,
3808 WINDOW_SERVICE,
3809 LAYOUT_INFLATER_SERVICE,
3810 ACCOUNT_SERVICE,
3811 ACTIVITY_SERVICE,
3812 ALARM_SERVICE,
3813 NOTIFICATION_SERVICE,
3814 ACCESSIBILITY_SERVICE,
3815 CAPTIONING_SERVICE,
3816 KEYGUARD_SERVICE,
3817 LOCATION_SERVICE,
3818 //@hide: COUNTRY_DETECTOR,
3819 SEARCH_SERVICE,
3820 SENSOR_SERVICE,
3821 SENSOR_PRIVACY_SERVICE,
3822 STORAGE_SERVICE,
3823 STORAGE_STATS_SERVICE,
3824 WALLPAPER_SERVICE,
3825 VIBRATOR_MANAGER_SERVICE,
3826 VIBRATOR_SERVICE,
3827 //@hide: STATUS_BAR_SERVICE,
3828 CONNECTIVITY_SERVICE,
3829 PAC_PROXY_SERVICE,
3830 VCN_MANAGEMENT_SERVICE,
3831 //@hide: IP_MEMORY_STORE_SERVICE,
3832 IPSEC_SERVICE,
3833 VPN_MANAGEMENT_SERVICE,
3834 TEST_NETWORK_SERVICE,
3835 //@hide: UPDATE_LOCK_SERVICE,
3836 //@hide: NETWORKMANAGEMENT_SERVICE,
3837 NETWORK_STATS_SERVICE,
3838 //@hide: NETWORK_POLICY_SERVICE,
3839 WIFI_SERVICE,
3840 WIFI_AWARE_SERVICE,
3841 WIFI_P2P_SERVICE,
3842 WIFI_SCANNING_SERVICE,
3843 //@hide: LOWPAN_SERVICE,
3844 //@hide: WIFI_RTT_SERVICE,
3845 //@hide: ETHERNET_SERVICE,
3846 WIFI_RTT_RANGING_SERVICE,
3847 NSD_SERVICE,
3848 AUDIO_SERVICE,
3849 AUDIO_DEVICE_VOLUME_SERVICE,
3850 AUTH_SERVICE,
3851 FINGERPRINT_SERVICE,
3852 //@hide: FACE_SERVICE,
3853 BIOMETRIC_SERVICE,
3854 MEDIA_ROUTER_SERVICE,
3855 TELEPHONY_SERVICE,
3856 TELEPHONY_SUBSCRIPTION_SERVICE,
3857 CARRIER_CONFIG_SERVICE,
3858 EUICC_SERVICE,
3859 //@hide: MMS_SERVICE,
3860 TELECOM_SERVICE,
3861 CLIPBOARD_SERVICE,
3862 INPUT_METHOD_SERVICE,
3863 TEXT_SERVICES_MANAGER_SERVICE,
3864 TEXT_CLASSIFICATION_SERVICE,
3865 APPWIDGET_SERVICE,
3866 //@hide: VOICE_INTERACTION_MANAGER_SERVICE,
3867 //@hide: BACKUP_SERVICE,
3868 REBOOT_READINESS_SERVICE,
3869 ROLLBACK_SERVICE,
3870 DROPBOX_SERVICE,
3871 //@hide: DEVICE_IDLE_CONTROLLER,
3872 //@hide: POWER_WHITELIST_MANAGER,
3873 DEVICE_POLICY_SERVICE,
3874 UI_MODE_SERVICE,
3875 DOWNLOAD_SERVICE,
3876 NFC_SERVICE,
3877 BLUETOOTH_SERVICE,
3878 //@hide: SIP_SERVICE,
3879 USB_SERVICE,
3880 LAUNCHER_APPS_SERVICE,
3881 //@hide: SERIAL_SERVICE,
3882 //@hide: HDMI_CONTROL_SERVICE,
3883 INPUT_SERVICE,
3884 DISPLAY_SERVICE,
3885 //@hide COLOR_DISPLAY_SERVICE,
3886 USER_SERVICE,
3887 RESTRICTIONS_SERVICE,
3888 APP_OPS_SERVICE,
3889 ROLE_SERVICE,
3890 //@hide ROLE_CONTROLLER_SERVICE,
3891 CAMERA_SERVICE,
3892 //@hide: PLATFORM_COMPAT_SERVICE,
3893 //@hide: PLATFORM_COMPAT_NATIVE_SERVICE,
3894 PRINT_SERVICE,
3895 CONSUMER_IR_SERVICE,
3896 //@hide: TRUST_SERVICE,
3897 TV_INTERACTIVE_APP_SERVICE,
3898 TV_INPUT_SERVICE,
3899 //@hide: TV_TUNER_RESOURCE_MGR_SERVICE,
3900 //@hide: NETWORK_SCORE_SERVICE,
3901 USAGE_STATS_SERVICE,
3902 MEDIA_SESSION_SERVICE,
3903 MEDIA_COMMUNICATION_SERVICE,
3904 BATTERY_SERVICE,
3905 JOB_SCHEDULER_SERVICE,
3906 //@hide: PERSISTENT_DATA_BLOCK_SERVICE,
3907 //@hide: OEM_LOCK_SERVICE,
3908 MEDIA_PROJECTION_SERVICE,
3909 MIDI_SERVICE,
3910 RADIO_SERVICE,
3911 HARDWARE_PROPERTIES_SERVICE,
3912 //@hide: SOUND_TRIGGER_SERVICE,
3913 SHORTCUT_SERVICE,
3914 //@hide: CONTEXTHUB_SERVICE,
3915 SYSTEM_HEALTH_SERVICE,
3916 //@hide: INCIDENT_SERVICE,
3917 //@hide: INCIDENT_COMPANION_SERVICE,
3918 //@hide: STATS_COMPANION_SERVICE,
3919 COMPANION_DEVICE_SERVICE,
3920 //@hide: VIRTUAL_DEVICE_SERVICE,
3921 CROSS_PROFILE_APPS_SERVICE,
3922 //@hide: SYSTEM_UPDATE_SERVICE,
3923 //@hide: TIME_DETECTOR_SERVICE,
3924 //@hide: TIME_ZONE_DETECTOR_SERVICE,
3925 PERMISSION_SERVICE,
3926 LIGHTS_SERVICE,
3927 LOCALE_SERVICE,
3928 //@hide: PEOPLE_SERVICE,
3929 //@hide: DEVICE_STATE_SERVICE,
3930 //@hide: SPEECH_RECOGNITION_SERVICE,
3931 UWB_SERVICE,
3932 MEDIA_METRICS_SERVICE,
3933 //@hide: ATTESTATION_VERIFICATION_SERVICE,
3934 //@hide: SAFETY_CENTER_SERVICE,
3935 DISPLAY_HASH_SERVICE,
3936 VIRTUALIZATION_SERVICE,
3937 })
3938 @Retention(RetentionPolicy.SOURCE)
3939 public @interface ServiceName {}
3940
3941 /**
3942 * Return the handle to a system-level service by name. The class of the
3943 * returned object varies by the requested name. Currently available names
3944 * are:
3945 *
3946 * <dl>
3947 * <dt> {@link #WINDOW_SERVICE} ("window")
3948 * <dd> The top-level window manager in which you can place custom
3949 * windows. The returned object is a {@link android.view.WindowManager}. Must only be obtained
3950 * from a visual context such as Activity or a Context created with
3951 * {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and
3952 * visual bounds of an area on screen.
3953 * <dt> {@link #LAYOUT_INFLATER_SERVICE} ("layout_inflater")
3954 * <dd> A {@link android.view.LayoutInflater} for inflating layout resources
3955 * in this context. Must only be obtained from a visual context such as Activity or a Context
3956 * created with {@link #createWindowContext(int, Bundle)}, which are adjusted to the
3957 * configuration and visual bounds of an area on screen.
3958 * <dt> {@link #ACTIVITY_SERVICE} ("activity")
3959 * <dd> A {@link android.app.ActivityManager} for interacting with the
3960 * global activity state of the system.
3961 * <dt> {@link #WALLPAPER_SERVICE} ("wallpaper")
3962 * <dd> A {@link android.service.wallpaper.WallpaperService} for accessing wallpapers in this
3963 * context. Must only be obtained from a visual context such as Activity or a Context created
3964 * with {@link #createWindowContext(int, Bundle)}, which are adjusted to the configuration and
3965 * visual bounds of an area on screen.
3966 * <dt> {@link #POWER_SERVICE} ("power")
3967 * <dd> A {@link android.os.PowerManager} for controlling power
3968 * management.
3969 * <dt> {@link #ALARM_SERVICE} ("alarm")
3970 * <dd> A {@link android.app.AlarmManager} for receiving intents at the
3971 * time of your choosing.
3972 * <dt> {@link #NOTIFICATION_SERVICE} ("notification")
3973 * <dd> A {@link android.app.NotificationManager} for informing the user
3974 * of background events.
3975 * <dt> {@link #KEYGUARD_SERVICE} ("keyguard")
3976 * <dd> A {@link android.app.KeyguardManager} for controlling keyguard.
3977 * <dt> {@link #LOCATION_SERVICE} ("location")
3978 * <dd> A {@link android.location.LocationManager} for controlling location
3979 * (e.g., GPS) updates.
3980 * <dt> {@link #SEARCH_SERVICE} ("search")
3981 * <dd> A {@link android.app.SearchManager} for handling search.
3982 * <dt> {@link #VIBRATOR_MANAGER_SERVICE} ("vibrator_manager")
3983 * <dd> A {@link android.os.VibratorManager} for accessing the device vibrators, interacting
3984 * with individual ones and playing synchronized effects on multiple vibrators.
3985 * <dt> {@link #VIBRATOR_SERVICE} ("vibrator")
3986 * <dd> A {@link android.os.Vibrator} for interacting with the vibrator hardware.
3987 * <dt> {@link #CONNECTIVITY_SERVICE} ("connectivity")
3988 * <dd> A {@link android.net.ConnectivityManager ConnectivityManager} for
3989 * handling management of network connections.
3990 * <dt> {@link #IPSEC_SERVICE} ("ipsec")
3991 * <dd> A {@link android.net.IpSecManager IpSecManager} for managing IPSec on
3992 * sockets and networks.
3993 * <dt> {@link #WIFI_SERVICE} ("wifi")
3994 * <dd> A {@link android.net.wifi.WifiManager WifiManager} for management of Wi-Fi
3995 * connectivity. On releases before NYC, it should only be obtained from an application
3996 * context, and not from any other derived context to avoid memory leaks within the calling
3997 * process.
3998 * <dt> {@link #WIFI_AWARE_SERVICE} ("wifiaware")
3999 * <dd> A {@link android.net.wifi.aware.WifiAwareManager WifiAwareManager} for management of
4000 * Wi-Fi Aware discovery and connectivity.
4001 * <dt> {@link #WIFI_P2P_SERVICE} ("wifip2p")
4002 * <dd> A {@link android.net.wifi.p2p.WifiP2pManager WifiP2pManager} for management of
4003 * Wi-Fi Direct connectivity.
4004 * <dt> {@link #INPUT_METHOD_SERVICE} ("input_method")
4005 * <dd> An {@link android.view.inputmethod.InputMethodManager InputMethodManager}
4006 * for management of input methods.
4007 * <dt> {@link #UI_MODE_SERVICE} ("uimode")
4008 * <dd> An {@link android.app.UiModeManager} for controlling UI modes.
4009 * <dt> {@link #DOWNLOAD_SERVICE} ("download")
4010 * <dd> A {@link android.app.DownloadManager} for requesting HTTP downloads
4011 * <dt> {@link #BATTERY_SERVICE} ("batterymanager")
4012 * <dd> A {@link android.os.BatteryManager} for managing battery state
4013 * <dt> {@link #JOB_SCHEDULER_SERVICE} ("taskmanager")
4014 * <dd> A {@link android.app.job.JobScheduler} for managing scheduled tasks
4015 * <dt> {@link #NETWORK_STATS_SERVICE} ("netstats")
4016 * <dd> A {@link android.app.usage.NetworkStatsManager NetworkStatsManager} for querying network
4017 * usage statistics.
4018 * <dt> {@link #HARDWARE_PROPERTIES_SERVICE} ("hardware_properties")
4019 * <dd> A {@link android.os.HardwarePropertiesManager} for accessing hardware properties.
4020 * <dt> {@link #DOMAIN_VERIFICATION_SERVICE} ("domain_verification")
4021 * <dd> A {@link android.content.pm.verify.domain.DomainVerificationManager} for accessing
4022 * web domain approval state.
4023 * <dt> {@link #DISPLAY_HASH_SERVICE} ("display_hash")
4024 * <dd> A {@link android.view.displayhash.DisplayHashManager} for management of display hashes.
4025 * </dl>
4026 *
4027 * <p>Note: System services obtained via this API may be closely associated with
4028 * the Context in which they are obtained from. In general, do not share the
4029 * service objects between various different contexts (Activities, Applications,
4030 * Services, Providers, etc.)
4031 *
4032 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
4033 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
4034 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
4035 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
4036 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
4037 * return <code>null</code>. Generally, if you are running as an instant app you should always
4038 * check whether the result of this method is {@code null}.
4039 *
4040 * <p>Note: When implementing this method, keep in mind that new services can be added on newer
4041 * Android releases, so if you're looking for just the explicit names mentioned above, make sure
4042 * to return {@code null} when you don't recognize the name &mdash; if you throw a
4043 * {@link RuntimeException} exception instead, your app might break on new Android releases.
4044 *
4045 * @param name The name of the desired service.
4046 *
4047 * @return The service or {@code null} if the name does not exist.
4048 *
4049 * @see #WINDOW_SERVICE
4050 * @see android.view.WindowManager
4051 * @see #LAYOUT_INFLATER_SERVICE
4052 * @see android.view.LayoutInflater
4053 * @see #ACTIVITY_SERVICE
4054 * @see android.app.ActivityManager
4055 * @see #POWER_SERVICE
4056 * @see android.os.PowerManager
4057 * @see #ALARM_SERVICE
4058 * @see android.app.AlarmManager
4059 * @see #NOTIFICATION_SERVICE
4060 * @see android.app.NotificationManager
4061 * @see #KEYGUARD_SERVICE
4062 * @see android.app.KeyguardManager
4063 * @see #LOCATION_SERVICE
4064 * @see android.location.LocationManager
4065 * @see #SEARCH_SERVICE
4066 * @see android.app.SearchManager
4067 * @see #SENSOR_SERVICE
4068 * @see android.hardware.SensorManager
4069 * @see #STORAGE_SERVICE
4070 * @see android.os.storage.StorageManager
4071 * @see #VIBRATOR_MANAGER_SERVICE
4072 * @see android.os.VibratorManager
4073 * @see #VIBRATOR_SERVICE
4074 * @see android.os.Vibrator
4075 * @see #CONNECTIVITY_SERVICE
4076 * @see android.net.ConnectivityManager
4077 * @see #WIFI_SERVICE
4078 * @see android.net.wifi.WifiManager
4079 * @see #AUDIO_SERVICE
4080 * @see android.media.AudioManager
4081 * @see #MEDIA_ROUTER_SERVICE
4082 * @see android.media.MediaRouter
4083 * @see #TELEPHONY_SERVICE
4084 * @see android.telephony.TelephonyManager
4085 * @see #TELEPHONY_SUBSCRIPTION_SERVICE
4086 * @see android.telephony.SubscriptionManager
4087 * @see #CARRIER_CONFIG_SERVICE
4088 * @see android.telephony.CarrierConfigManager
4089 * @see #EUICC_SERVICE
4090 * @see android.telephony.euicc.EuiccManager
4091 * @see android.telephony.MmsManager
4092 * @see #INPUT_METHOD_SERVICE
4093 * @see android.view.inputmethod.InputMethodManager
4094 * @see #UI_MODE_SERVICE
4095 * @see android.app.UiModeManager
4096 * @see #DOWNLOAD_SERVICE
4097 * @see android.app.DownloadManager
4098 * @see #BATTERY_SERVICE
4099 * @see android.os.BatteryManager
4100 * @see #JOB_SCHEDULER_SERVICE
4101 * @see android.app.job.JobScheduler
4102 * @see #NETWORK_STATS_SERVICE
4103 * @see android.app.usage.NetworkStatsManager
4104 * @see android.os.HardwarePropertiesManager
4105 * @see #HARDWARE_PROPERTIES_SERVICE
4106 * @see #DOMAIN_VERIFICATION_SERVICE
4107 * @see android.content.pm.verify.domain.DomainVerificationManager
4108 * @see #DISPLAY_HASH_SERVICE
4109 * @see android.view.displayhash.DisplayHashManager
4110 */
4111 public abstract @Nullable Object getSystemService(@ServiceName @NonNull String name);
4112
4113 /**
4114 * Return the handle to a system-level service by class.
4115 * <p>
4116 * Currently available classes are:
4117 * {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
4118 * {@link android.app.ActivityManager}, {@link android.os.PowerManager},
4119 * {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
4120 * {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
4121 * {@link android.app.SearchManager}, {@link android.os.Vibrator},
4122 * {@link android.net.ConnectivityManager},
4123 * {@link android.net.wifi.WifiManager},
4124 * {@link android.media.AudioManager}, {@link android.media.MediaRouter},
4125 * {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
4126 * {@link android.view.inputmethod.InputMethodManager},
4127 * {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
4128 * {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
4129 * {@link android.app.usage.NetworkStatsManager},
4130 * {@link android.content.pm.verify.domain.DomainVerificationManager},
4131 * {@link android.view.displayhash.DisplayHashManager}.
4132 * </p>
4133 *
4134 * <p>
4135 * Note: System services obtained via this API may be closely associated with
4136 * the Context in which they are obtained from. In general, do not share the
4137 * service objects between various different contexts (Activities, Applications,
4138 * Services, Providers, etc.)
4139 * </p>
4140 *
4141 * <p>Note: Instant apps, for which {@link PackageManager#isInstantApp()} returns true,
4142 * don't have access to the following system services: {@link #DEVICE_POLICY_SERVICE},
4143 * {@link #FINGERPRINT_SERVICE}, {@link #KEYGUARD_SERVICE}, {@link #SHORTCUT_SERVICE},
4144 * {@link #USB_SERVICE}, {@link #WALLPAPER_SERVICE}, {@link #WIFI_P2P_SERVICE},
4145 * {@link #WIFI_SERVICE}, {@link #WIFI_AWARE_SERVICE}. For these services this method will
4146 * return {@code null}. Generally, if you are running as an instant app you should always
4147 * check whether the result of this method is {@code null}.
4148 * </p>
4149 *
4150 * @param serviceClass The class of the desired service.
4151 * @return The service or {@code null} if the class is not a supported system service. Note:
4152 * <b>never</b> throw a {@link RuntimeException} if the name is not supported.
4153 */
4154 @SuppressWarnings("unchecked")
4155 public final @Nullable <T> T getSystemService(@NonNull Class<T> serviceClass) {
4156 // Because subclasses may override getSystemService(String) we cannot
4157 // perform a lookup by class alone. We must first map the class to its
4158 // service name then invoke the string-based method.
4159 String serviceName = getSystemServiceName(serviceClass);
4160 return serviceName != null ? (T)getSystemService(serviceName) : null;
4161 }
4162
4163 /**
4164 * Gets the name of the system-level service that is represented by the specified class.
4165 *
4166 * @param serviceClass The class of the desired service.
4167 * @return The service name or null if the class is not a supported system service.
4168 */
4169 public abstract @Nullable String getSystemServiceName(@NonNull Class<?> serviceClass);
4170
4171 /**
4172 * Use with {@link #getSystemService(String)} to retrieve a
4173 * {@link android.os.PowerManager} for controlling power management,
4174 * including "wake locks," which let you keep the device on while
4175 * you're running long tasks.
4176 */
4177 public static final String POWER_SERVICE = "power";
4178
4179 /**
4180 * Use with {@link #getSystemService(String)} to retrieve a
4181 * {@link android.os.PowerStatsService} for accessing power stats
4182 * service.
4183 *
4184 * @see #getSystemService(String)
4185 * @hide
4186 */
4187 public static final String POWER_STATS_SERVICE = "powerstats";
4188
4189 /**
4190 * Use with {@link #getSystemService(String)} to retrieve a
4191 * {@link android.os.RecoverySystem} for accessing the recovery system
4192 * service.
4193 *
4194 * @see #getSystemService(String)
4195 * @hide
4196 */
4197 public static final String RECOVERY_SERVICE = "recovery";
4198
4199 /**
4200 * Use with {@link #getSystemService(String)} to retrieve a
4201 * {@link android.os.SystemUpdateManager} for accessing the system update
4202 * manager service.
4203 *
4204 * @see #getSystemService(String)
4205 * @hide
4206 */
4207 @SystemApi
4208 public static final String SYSTEM_UPDATE_SERVICE = "system_update";
4209
4210 /**
4211 * Use with {@link #getSystemService(String)} to retrieve a
4212 * {@link android.view.WindowManager} for accessing the system's window
4213 * manager.
4214 *
4215 * @see #getSystemService(String)
4216 * @see android.view.WindowManager
4217 */
4218 @UiContext
4219 public static final String WINDOW_SERVICE = "window";
4220
4221 /**
4222 * Use with {@link #getSystemService(String)} to retrieve a
4223 * {@link android.view.LayoutInflater} for inflating layout resources in this
4224 * context.
4225 *
4226 * @see #getSystemService(String)
4227 * @see android.view.LayoutInflater
4228 */
4229 @UiContext
4230 public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
4231
4232 /**
4233 * Use with {@link #getSystemService(String)} to retrieve a
4234 * {@link android.accounts.AccountManager} for receiving intents at a
4235 * time of your choosing.
4236 *
4237 * @see #getSystemService(String)
4238 * @see android.accounts.AccountManager
4239 */
4240 public static final String ACCOUNT_SERVICE = "account";
4241
4242 /**
4243 * Use with {@link #getSystemService(String)} to retrieve a
4244 * {@link android.app.ActivityManager} for interacting with the global
4245 * system state.
4246 *
4247 * @see #getSystemService(String)
4248 * @see android.app.ActivityManager
4249 */
4250 public static final String ACTIVITY_SERVICE = "activity";
4251
4252 /**
4253 * Use with {@link #getSystemService(String)} to retrieve a
4254 * {@link android.app.ActivityTaskManager} for interacting with the global system state.
4255 *
4256 * @see #getSystemService(String)
4257 * @see android.app.ActivityTaskManager
4258 * @hide
4259 */
4260 public static final String ACTIVITY_TASK_SERVICE = "activity_task";
4261
4262 /**
4263 * Use with {@link #getSystemService(String)} to retrieve a
4264 * {@link android.app.UriGrantsManager} for interacting with the global system state.
4265 *
4266 * @see #getSystemService(String)
4267 * @see android.app.UriGrantsManager
4268 * @hide
4269 */
4270 public static final String URI_GRANTS_SERVICE = "uri_grants";
4271
4272 /**
4273 * Use with {@link #getSystemService(String)} to retrieve a
4274 * {@link android.app.AlarmManager} for receiving intents at a
4275 * time of your choosing.
4276 *
4277 * @see #getSystemService(String)
4278 * @see android.app.AlarmManager
4279 */
4280 public static final String ALARM_SERVICE = "alarm";
4281
4282 /**
4283 * Use with {@link #getSystemService(String)} to retrieve a
4284 * {@link android.app.NotificationManager} for informing the user of
4285 * background events.
4286 *
4287 * @see #getSystemService(String)
4288 * @see android.app.NotificationManager
4289 */
4290 public static final String NOTIFICATION_SERVICE = "notification";
4291
4292 /**
4293 * Use with {@link #getSystemService(String)} to retrieve a
4294 * {@link android.view.accessibility.AccessibilityManager} for giving the user
4295 * feedback for UI events through the registered event listeners.
4296 *
4297 * @see #getSystemService(String)
4298 * @see android.view.accessibility.AccessibilityManager
4299 */
4300 public static final String ACCESSIBILITY_SERVICE = "accessibility";
4301
4302 /**
4303 * Use with {@link #getSystemService(String)} to retrieve a
4304 * {@link android.view.accessibility.CaptioningManager} for obtaining
4305 * captioning properties and listening for changes in captioning
4306 * preferences.
4307 *
4308 * @see #getSystemService(String)
4309 * @see android.view.accessibility.CaptioningManager
4310 */
4311 public static final String CAPTIONING_SERVICE = "captioning";
4312
4313 /**
4314 * Use with {@link #getSystemService(String)} to retrieve a
4315 * {@link android.app.KeyguardManager} for controlling keyguard.
4316 *
4317 * @see #getSystemService(String)
4318 * @see android.app.KeyguardManager
4319 */
4320 public static final String KEYGUARD_SERVICE = "keyguard";
4321
4322 /**
4323 * Use with {@link #getSystemService(String)} to retrieve a {@link
4324 * android.location.LocationManager} for controlling location
4325 * updates.
4326 *
4327 * @see #getSystemService(String)
4328 * @see android.location.LocationManager
4329 */
4330 public static final String LOCATION_SERVICE = "location";
4331
4332 /**
4333 * Use with {@link #getSystemService(String)} to retrieve a
4334 * {@link android.location.CountryDetector} for detecting the country that
4335 * the user is in.
4336 *
4337 * @hide
4338 */
4339 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
4340 public static final String COUNTRY_DETECTOR = "country_detector";
4341
4342 /**
4343 * Use with {@link #getSystemService(String)} to retrieve a {@link
4344 * android.app.SearchManager} for handling searches.
4345 *
4346 * <p>
4347 * {@link Configuration#UI_MODE_TYPE_WATCH} does not support
4348 * {@link android.app.SearchManager}.
4349 *
4350 * @see #getSystemService
4351 * @see android.app.SearchManager
4352 */
4353 public static final String SEARCH_SERVICE = "search";
4354
4355 /**
4356 * Use with {@link #getSystemService(String)} to retrieve a {@link
4357 * android.hardware.SensorManager} for accessing sensors.
4358 *
4359 * @see #getSystemService(String)
4360 * @see android.hardware.SensorManager
4361 */
4362 public static final String SENSOR_SERVICE = "sensor";
4363
4364 /**
4365 * Use with {@link #getSystemService(String)} to retrieve a {@link
4366 * android.hardware.SensorPrivacyManager} for accessing sensor privacy
4367 * functions.
4368 *
4369 * @see #getSystemService(String)
4370 * @see android.hardware.SensorPrivacyManager
4371 *
4372 * @hide
4373 */
4374 public static final String SENSOR_PRIVACY_SERVICE = "sensor_privacy";
4375
4376 /**
4377 * Use with {@link #getSystemService(String)} to retrieve a {@link
4378 * android.os.storage.StorageManager} for accessing system storage
4379 * functions.
4380 *
4381 * @see #getSystemService(String)
4382 * @see android.os.storage.StorageManager
4383 */
4384 public static final String STORAGE_SERVICE = "storage";
4385
4386 /**
4387 * Use with {@link #getSystemService(String)} to retrieve a {@link
4388 * android.app.usage.StorageStatsManager} for accessing system storage
4389 * statistics.
4390 *
4391 * @see #getSystemService(String)
4392 * @see android.app.usage.StorageStatsManager
4393 */
4394 public static final String STORAGE_STATS_SERVICE = "storagestats";
4395
4396 /**
4397 * Use with {@link #getSystemService(String)} to retrieve a
4398 * com.android.server.WallpaperService for accessing wallpapers.
4399 *
4400 * @see #getSystemService(String)
4401 */
4402 @UiContext
4403 public static final String WALLPAPER_SERVICE = "wallpaper";
4404
4405 /**
4406 * Use with {@link #getSystemService(String)} to retrieve a {@link android.os.VibratorManager}
4407 * for accessing the device vibrators, interacting with individual ones and playing synchronized
4408 * effects on multiple vibrators.
4409 *
4410 * @see #getSystemService(String)
4411 * @see android.os.VibratorManager
4412 */
4413 @SuppressLint("ServiceName")
4414 public static final String VIBRATOR_MANAGER_SERVICE = "vibrator_manager";
4415
4416 /**
4417 * Use with {@link #getSystemService(String)} to retrieve a {@link android.os.Vibrator} for
4418 * interacting with the vibration hardware.
4419 *
4420 * @deprecated Use {@link android.os.VibratorManager} to retrieve the default system vibrator.
4421 * @see #getSystemService(String)
4422 * @see android.os.Vibrator
4423 */
4424 @Deprecated
4425 public static final String VIBRATOR_SERVICE = "vibrator";
4426
4427 /**
4428 * Use with {@link #getSystemService(String)} to retrieve a {@link
4429 * android.app.StatusBarManager} for interacting with the status bar and quick settings.
4430 *
4431 * @see #getSystemService(String)
4432 * @see android.app.StatusBarManager
4433 *
4434 */
4435 @SuppressLint("ServiceName")
4436 public static final String STATUS_BAR_SERVICE = "statusbar";
4437
4438 /**
4439 * Use with {@link #getSystemService(String)} to retrieve a {@link
4440 * android.net.ConnectivityManager} for handling management of
4441 * network connections.
4442 *
4443 * @see #getSystemService(String)
4444 * @see android.net.ConnectivityManager
4445 */
4446 public static final String CONNECTIVITY_SERVICE = "connectivity";
4447
4448 /**
4449 * Use with {@link #getSystemService(String)} to retrieve a {@link
4450 * android.net.PacProxyManager} for handling management of
4451 * pac proxy information.
4452 *
4453 * @see #getSystemService(String)
4454 * @see android.net.PacProxyManager
4455 * @hide
4456 */
4457 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
4458 public static final String PAC_PROXY_SERVICE = "pac_proxy";
4459
4460 /**
4461 * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.vcn.VcnManager}
4462 * for managing Virtual Carrier Networks
4463 *
4464 * @see #getSystemService(String)
4465 * @see android.net.vcn.VcnManager
4466 * @hide
4467 */
4468 public static final String VCN_MANAGEMENT_SERVICE = "vcn_management";
4469
4470 /**
4471 * Use with {@link #getSystemService(String)} to retrieve a
4472 * {@link android.net.INetd} for communicating with the network stack
4473 * @hide
4474 * @see #getSystemService(String)
4475 * @hide
4476 */
4477 @SystemApi
4478 public static final String NETD_SERVICE = "netd";
4479
4480 /**
4481 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
4482 * {@link INetworkStackConnector} IBinder for communicating with the network stack
4483 * @hide
4484 * @see NetworkStackClient
4485 */
4486 public static final String NETWORK_STACK_SERVICE = "network_stack";
4487
4488 /**
4489 * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.TetheringManager}
4490 * for managing tethering functions.
4491 * @hide
4492 * @see android.net.TetheringManager
4493 */
4494 @SystemApi
4495 public static final String TETHERING_SERVICE = "tethering";
4496
4497 /**
4498 * Use with {@link #getSystemService(String)} to retrieve a
4499 * {@link android.net.IpSecManager} for encrypting Sockets or Networks with
4500 * IPSec.
4501 *
4502 * @see #getSystemService(String)
4503 */
4504 public static final String IPSEC_SERVICE = "ipsec";
4505
4506 /**
4507 * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.VpnManager} to
4508 * manage profiles for the platform built-in VPN.
4509 *
4510 * @see #getSystemService(String)
4511 */
4512 public static final String VPN_MANAGEMENT_SERVICE = "vpn_management";
4513
4514 /**
4515 * Use with {@link #getSystemService(String)} to retrieve a {@link
4516 * android.net.ConnectivityDiagnosticsManager} for performing network connectivity diagnostics
4517 * as well as receiving network connectivity information from the system.
4518 *
4519 * @see #getSystemService(String)
4520 * @see android.net.ConnectivityDiagnosticsManager
4521 */
4522 public static final String CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics";
4523
4524 /**
4525 * Use with {@link #getSystemService(String)} to retrieve a {@link
4526 * android.net.TestNetworkManager} for building TUNs and limited-use Networks
4527 *
4528 * @see #getSystemService(String)
4529 * @hide
4530 */
4531 @TestApi @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
4532 public static final String TEST_NETWORK_SERVICE = "test_network";
4533
4534 /**
4535 * Use with {@link #getSystemService(String)} to retrieve a {@link
4536 * android.os.IUpdateLock} for managing runtime sequences that
4537 * must not be interrupted by headless OTA application or similar.
4538 *
4539 * @hide
4540 * @see #getSystemService(String)
4541 * @see android.os.UpdateLock
4542 */
4543 public static final String UPDATE_LOCK_SERVICE = "updatelock";
4544
4545 /**
4546 * Constant for the internal network management service, not really a Context service.
4547 * @hide
4548 */
4549 public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
4550
4551 /**
4552 * Use with {@link #getSystemService(String)} to retrieve a
4553 * {@link com.android.server.slice.SliceManagerService} for managing slices.
4554 * @hide
4555 * @see #getSystemService(String)
4556 */
4557 public static final String SLICE_SERVICE = "slice";
4558
4559 /**
4560 * Use with {@link #getSystemService(String)} to retrieve a {@link
4561 * android.app.usage.NetworkStatsManager} for querying network usage stats.
4562 *
4563 * @see #getSystemService(String)
4564 * @see android.app.usage.NetworkStatsManager
4565 */
4566 public static final String NETWORK_STATS_SERVICE = "netstats";
4567 /** {@hide} */
4568 public static final String NETWORK_POLICY_SERVICE = "netpolicy";
4569 /** {@hide} */
4570 public static final String NETWORK_WATCHLIST_SERVICE = "network_watchlist";
4571
4572 /**
4573 * Use with {@link #getSystemService(String)} to retrieve a {@link
4574 * android.net.wifi.WifiManager} for handling management of
4575 * Wi-Fi access.
4576 *
4577 * @see #getSystemService(String)
4578 * @see android.net.wifi.WifiManager
4579 */
4580 public static final String WIFI_SERVICE = "wifi";
4581
4582 /**
4583 * Use with {@link #getSystemService(String)} to retrieve a
4584 * {@link android.net.wifi.wificond.WifiNl80211Manager} for handling management of the
4585 * Wi-Fi nl802.11 daemon (wificond).
4586 *
4587 * @see #getSystemService(String)
4588 * @see android.net.wifi.wificond.WifiNl80211Manager
4589 * @hide
4590 */
4591 @SystemApi
4592 @SuppressLint("ServiceName")
4593 public static final String WIFI_NL80211_SERVICE = "wifinl80211";
4594
4595 /**
4596 * Use with {@link #getSystemService(String)} to retrieve a {@link
4597 * android.net.wifi.p2p.WifiP2pManager} for handling management of
4598 * Wi-Fi peer-to-peer connections.
4599 *
4600 * @see #getSystemService(String)
4601 * @see android.net.wifi.p2p.WifiP2pManager
4602 */
4603 public static final String WIFI_P2P_SERVICE = "wifip2p";
4604
4605 /**
4606 * Use with {@link #getSystemService(String)} to retrieve a
4607 * {@link android.net.wifi.aware.WifiAwareManager} for handling management of
4608 * Wi-Fi Aware.
4609 *
4610 * @see #getSystemService(String)
4611 * @see android.net.wifi.aware.WifiAwareManager
4612 */
4613 public static final String WIFI_AWARE_SERVICE = "wifiaware";
4614
4615 /**
4616 * Use with {@link #getSystemService(String)} to retrieve a {@link
4617 * android.net.wifi.WifiScanner} for scanning the wifi universe
4618 *
4619 * @see #getSystemService(String)
4620 * @see android.net.wifi.WifiScanner
4621 * @hide
4622 */
4623 @SystemApi
4624 public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
4625
4626 /**
4627 * Use with {@link #getSystemService(String)} to retrieve a {@link
4628 * android.net.wifi.RttManager} for ranging devices with wifi
4629 *
4630 * @see #getSystemService(String)
4631 * @see android.net.wifi.RttManager
4632 * @hide
4633 */
4634 @SystemApi
4635 @Deprecated
4636 public static final String WIFI_RTT_SERVICE = "rttmanager";
4637
4638 /**
4639 * Use with {@link #getSystemService(String)} to retrieve a {@link
4640 * android.net.wifi.rtt.WifiRttManager} for ranging devices with wifi.
4641 *
4642 * @see #getSystemService(String)
4643 * @see android.net.wifi.rtt.WifiRttManager
4644 */
4645 public static final String WIFI_RTT_RANGING_SERVICE = "wifirtt";
4646
4647 /**
4648 * Use with {@link #getSystemService(String)} to retrieve a {@link
4649 * android.net.lowpan.LowpanManager} for handling management of
4650 * LoWPAN access.
4651 *
4652 * @see #getSystemService(String)
4653 * @see android.net.lowpan.LowpanManager
4654 *
4655 * @hide
4656 */
4657 public static final String LOWPAN_SERVICE = "lowpan";
4658
4659 /**
4660 * Use with {@link #getSystemService(String)} to retrieve a {@link android.net.EthernetManager}
4661 * for handling management of Ethernet access.
4662 *
4663 * @see #getSystemService(String)
4664 * @see android.net.EthernetManager
4665 *
4666 * @hide
4667 */
4668 @SystemApi
4669 public static final String ETHERNET_SERVICE = "ethernet";
4670
4671 /**
4672 * Use with {@link #getSystemService(String)} to retrieve a {@link
4673 * android.net.nsd.NsdManager} for handling management of network service
4674 * discovery
4675 *
4676 * @see #getSystemService(String)
4677 * @see android.net.nsd.NsdManager
4678 */
4679 public static final String NSD_SERVICE = "servicediscovery";
4680
4681 /**
4682 * Use with {@link #getSystemService(String)} to retrieve a
4683 * {@link android.media.AudioManager} for handling management of volume,
4684 * ringer modes and audio routing.
4685 *
4686 * @see #getSystemService(String)
4687 * @see android.media.AudioManager
4688 */
4689 public static final String AUDIO_SERVICE = "audio";
4690
4691 /**
4692 * @hide
4693 * Use with {@link #getSystemService(String)} to retrieve a
4694 * {@link android.media.AudioDeviceVolumeManager} for handling management of audio device
4695 * (e.g. speaker, USB headset) volume.
4696 *
4697 * @see #getSystemService(String)
4698 * @see android.media.AudioDeviceVolumeManager
4699 */
4700 public static final String AUDIO_DEVICE_VOLUME_SERVICE = "audio_device_volume";
4701
4702 /**
4703 * Use with {@link #getSystemService(String)} to retrieve a {@link
4704 * android.media.MediaTranscodingManager} for transcoding media.
4705 *
4706 * @hide
4707 * @see #getSystemService(String)
4708 * @see android.media.MediaTranscodingManager
4709 */
4710 @SystemApi
4711 public static final String MEDIA_TRANSCODING_SERVICE = "media_transcoding";
4712
4713 /**
4714 * AuthService orchestrates biometric and PIN/pattern/password authentication.
4715 *
4716 * BiometricService was split into two services, AuthService and BiometricService, where
4717 * AuthService is the high level service that orchestrates all types of authentication, and
4718 * BiometricService is a lower layer responsible only for biometric authentication.
4719 *
4720 * Ideally we should have renamed BiometricManager to AuthManager, because it logically
4721 * corresponds to AuthService. However, because BiometricManager is a public API, we kept
4722 * the old name but changed the internal implementation to use AuthService.
4723 *
4724 * As of now, the AUTH_SERVICE constant is only used to identify the service in
4725 * SystemServiceRegistry and SELinux. To obtain the manager for AUTH_SERVICE, one should use
4726 * BIOMETRIC_SERVICE with {@link #getSystemService(String)} to retrieve a
4727 * {@link android.hardware.biometrics.BiometricManager}
4728 *
4729 * Map of the two services and their managers:
4730 * [Service] [Manager]
4731 * AuthService BiometricManager
4732 * BiometricService N/A
4733 *
4734 * @hide
4735 */
4736 public static final String AUTH_SERVICE = "auth";
4737
4738 /**
4739 * Use with {@link #getSystemService(String)} to retrieve a
4740 * {@link android.hardware.fingerprint.FingerprintManager} for handling management
4741 * of fingerprints.
4742 *
4743 * @see #getSystemService(String)
4744 * @see android.hardware.fingerprint.FingerprintManager
4745 */
4746 public static final String FINGERPRINT_SERVICE = "fingerprint";
4747
4748 /**
4749 * Use with {@link #getSystemService(String)} to retrieve a
4750 * {@link android.hardware.face.FaceManager} for handling management
4751 * of face authentication.
4752 *
4753 * @hide
4754 * @see #getSystemService
4755 * @see android.hardware.face.FaceManager
4756 */
4757 public static final String FACE_SERVICE = "face";
4758
4759 /**
4760 * Use with {@link #getSystemService(String)} to retrieve a
4761 * {@link android.hardware.iris.IrisManager} for handling management
4762 * of iris authentication.
4763 *
4764 * @hide
4765 * @see #getSystemService
4766 * @see android.hardware.iris.IrisManager
4767 */
4768 public static final String IRIS_SERVICE = "iris";
4769
4770 /**
4771 * Use with {@link #getSystemService(String)} to retrieve a
4772 * {@link android.hardware.biometrics.BiometricManager} for handling
4773 * biometric and PIN/pattern/password authentication.
4774 *
4775 * @see #getSystemService
4776 * @see android.hardware.biometrics.BiometricManager
4777 */
4778 public static final String BIOMETRIC_SERVICE = "biometric";
4779
4780 /**
4781 * Use with {@link #getSystemService(String)} to retrieve a
4782 * {@link android.media.MediaCommunicationManager}
4783 * for managing {@link android.media.MediaSession2}.
4784 *
4785 * @see #getSystemService(String)
4786 * @see android.media.MediaCommunicationManager
4787 */
4788 public static final String MEDIA_COMMUNICATION_SERVICE = "media_communication";
4789
4790 /**
4791 * Use with {@link #getSystemService} to retrieve a
4792 * {@link android.media.MediaRouter} for controlling and managing
4793 * routing of media.
4794 *
4795 * @see #getSystemService(String)
4796 * @see android.media.MediaRouter
4797 */
4798 public static final String MEDIA_ROUTER_SERVICE = "media_router";
4799
4800 /**
4801 * Use with {@link #getSystemService(String)} to retrieve a
4802 * {@link android.media.session.MediaSessionManager} for managing media Sessions.
4803 *
4804 * @see #getSystemService(String)
4805 * @see android.media.session.MediaSessionManager
4806 */
4807 public static final String MEDIA_SESSION_SERVICE = "media_session";
4808
4809 /**
4810 * Use with {@link #getSystemService(String)} to retrieve a
4811 * {@link android.telephony.TelephonyManager} for handling management the
4812 * telephony features of the device.
4813 *
4814 * @see #getSystemService(String)
4815 * @see android.telephony.TelephonyManager
4816 */
4817 public static final String TELEPHONY_SERVICE = "phone";
4818
4819 /**
4820 * Use with {@link #getSystemService(String)} to retrieve a
4821 * {@link android.telephony.SubscriptionManager} for handling management the
4822 * telephony subscriptions of the device.
4823 *
4824 * @see #getSystemService(String)
4825 * @see android.telephony.SubscriptionManager
4826 */
4827 public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
4828
4829 /**
4830 * Use with {@link #getSystemService(String)} to retrieve a
4831 * {@link android.telecom.TelecomManager} to manage telecom-related features
4832 * of the device.
4833 *
4834 * @see #getSystemService(String)
4835 * @see android.telecom.TelecomManager
4836 */
4837 public static final String TELECOM_SERVICE = "telecom";
4838
4839 /**
4840 * Use with {@link #getSystemService(String)} to retrieve a
4841 * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values.
4842 *
4843 * @see #getSystemService(String)
4844 * @see android.telephony.CarrierConfigManager
4845 */
4846 public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
4847
4848 /**
4849 * Use with {@link #getSystemService(String)} to retrieve a
4850 * {@link android.telephony.euicc.EuiccManager} to manage the device eUICC (embedded SIM).
4851 *
4852 * @see #getSystemService(String)
4853 * @see android.telephony.euicc.EuiccManager
4854 */
4855 public static final String EUICC_SERVICE = "euicc";
4856
4857 /**
4858 * Use with {@link #getSystemService(String)} to retrieve a
4859 * {@link android.telephony.euicc.EuiccCardManager} to access the device eUICC (embedded SIM).
4860 *
4861 * @see #getSystemService(String)
4862 * @see android.telephony.euicc.EuiccCardManager
4863 * @hide
4864 */
4865 @SystemApi
4866 public static final String EUICC_CARD_SERVICE = "euicc_card";
4867
4868 /**
4869 * Use with {@link #getSystemService(String)} to retrieve a
4870 * {@link android.telephony.MmsManager} to send/receive MMS messages.
4871 *
4872 * @see #getSystemService(String)
4873 * @see android.telephony.MmsManager
4874 * @hide
4875 */
4876 public static final String MMS_SERVICE = "mms";
4877
4878 /**
4879 * Use with {@link #getSystemService(String)} to retrieve a
4880 * {@link android.content.ClipboardManager} for accessing and modifying
4881 * the contents of the global clipboard.
4882 *
4883 * @see #getSystemService(String)
4884 * @see android.content.ClipboardManager
4885 */
4886 public static final String CLIPBOARD_SERVICE = "clipboard";
4887
4888 /**
4889 * Use with {@link #getSystemService(String)} to retrieve a
4890 * {@link TextClassificationManager} for text classification services.
4891 *
4892 * @see #getSystemService(String)
4893 * @see TextClassificationManager
4894 */
4895 public static final String TEXT_CLASSIFICATION_SERVICE = "textclassification";
4896
4897 /**
4898 * Use with {@link #getSystemService(String)} to retrieve a
4899 * {@link android.view.selectiontoolbar.SelectionToolbarManager} for selection toolbar service.
4900 *
4901 * @see #getSystemService(String)
4902 * @hide
4903 */
4904 public static final String SELECTION_TOOLBAR_SERVICE = "selection_toolbar";
4905
4906 /**
4907 * Use with {@link #getSystemService(String)} to retrieve a
4908 * {@link android.graphics.fonts.FontManager} for font services.
4909 *
4910 * @see #getSystemService(String)
4911 * @see android.graphics.fonts.FontManager
4912 * @hide
4913 */
4914 @SystemApi
4915 @TestApi
4916 public static final String FONT_SERVICE = "font";
4917
4918 /**
4919 * Use with {@link #getSystemService(String)} to retrieve a
4920 * {@link com.android.server.attention.AttentionManagerService} for attention services.
4921 *
4922 * @see #getSystemService(String)
4923 * @see android.server.attention.AttentionManagerService
4924 * @hide
4925 */
4926 public static final String ATTENTION_SERVICE = "attention";
4927
4928 /**
4929 * Official published name of the (internal) rotation resolver service.
4930 *
4931 * // TODO(b/178151184): change it back to rotation resolver before S release.
4932 *
4933 * @see #getSystemService(String)
4934 * @hide
4935 */
4936 public static final String ROTATION_RESOLVER_SERVICE = "resolver";
4937
4938 /**
4939 * Use with {@link #getSystemService(String)} to retrieve a
4940 * {@link android.view.inputmethod.InputMethodManager} for accessing input
4941 * methods.
4942 *
4943 * @see #getSystemService(String)
4944 */
4945 public static final String INPUT_METHOD_SERVICE = "input_method";
4946
4947 /**
4948 * Use with {@link #getSystemService(String)} to retrieve a
4949 * {@link android.view.textservice.TextServicesManager} for accessing
4950 * text services.
4951 *
4952 * @see #getSystemService(String)
4953 */
4954 public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
4955
4956 /**
4957 * Use with {@link #getSystemService(String)} to retrieve a
4958 * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
4959 *
4960 * @see #getSystemService(String)
4961 */
4962 public static final String APPWIDGET_SERVICE = "appwidget";
4963
4964 /**
4965 * Official published name of the (internal) voice interaction manager service.
4966 *
4967 * @hide
4968 * @see #getSystemService(String)
4969 */
4970 public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
4971
4972 /**
4973 * Official published name of the (internal) autofill service.
4974 *
4975 * @hide
4976 * @see #getSystemService(String)
4977 */
4978 public static final String AUTOFILL_MANAGER_SERVICE = "autofill";
4979
4980 /**
4981 * Official published name of the (internal) text to speech manager service.
4982 *
4983 * @hide
4984 * @see #getSystemService(String)
4985 */
4986 public static final String TEXT_TO_SPEECH_MANAGER_SERVICE = "texttospeech";
4987
4988 /**
4989 * Official published name of the content capture service.
4990 *
4991 * @hide
4992 * @see #getSystemService(String)
4993 */
4994 @TestApi
4995 @SuppressLint("ServiceName") // TODO: This should be renamed to CONTENT_CAPTURE_SERVICE
4996 public static final String CONTENT_CAPTURE_MANAGER_SERVICE = "content_capture";
4997
4998 /**
4999 * Official published name of the translation service.
5000 *
5001 * @hide
5002 * @see #getSystemService(String)
5003 */
5004 @SystemApi
5005 @SuppressLint("ServiceName")
5006 public static final String TRANSLATION_MANAGER_SERVICE = "translation";
5007
5008 /**
5009 * Official published name of the translation service which supports ui translation function.
5010 *
5011 * @hide
5012 * @see #getSystemService(String)
5013 */
5014 @SystemApi
5015 public static final String UI_TRANSLATION_SERVICE = "ui_translation";
5016
5017 /**
5018 * Used for getting content selections and classifications for task snapshots.
5019 *
5020 * @hide
5021 * @see #getSystemService(String)
5022 */
5023 @SystemApi
5024 public static final String CONTENT_SUGGESTIONS_SERVICE = "content_suggestions";
5025
5026 /**
5027 * Official published name of the app prediction service.
5028 *
5029 * <p><b>NOTE: </b> this service is optional; callers of
5030 * {@code Context.getSystemServiceName(APP_PREDICTION_SERVICE)} should check for {@code null}.
5031 *
5032 * @hide
5033 * @see #getSystemService(String)
5034 */
5035 @SystemApi
5036 public static final String APP_PREDICTION_SERVICE = "app_prediction";
5037
5038 /**
5039 * Official published name of the search ui service.
5040 *
5041 * <p><b>NOTE: </b> this service is optional; callers of
5042 * {@code Context.getSystemServiceName(SEARCH_UI_SERVICE)} should check for {@code null}.
5043 *
5044 * @hide
5045 * @see #getSystemService(String)
5046 */
5047 @SystemApi
5048 public static final String SEARCH_UI_SERVICE = "search_ui";
5049
5050 /**
5051 * Used for getting the smartspace service.
5052 *
5053 * <p><b>NOTE: </b> this service is optional; callers of
5054 * {@code Context.getSystemServiceName(SMARTSPACE_SERVICE)} should check for {@code null}.
5055 *
5056 * @hide
5057 * @see #getSystemService(String)
5058 */
5059 @SystemApi
5060 public static final String SMARTSPACE_SERVICE = "smartspace";
5061
5062 /**
5063 * Used for getting the cloudsearch service.
5064 *
5065 * <p><b>NOTE: </b> this service is optional; callers of
5066 * {@code Context.getSystemServiceName(CLOUDSEARCH_SERVICE)} should check for {@code null}.
5067 *
5068 * @hide
5069 * @see #getSystemService(String)
5070 */
5071 @SystemApi
5072 public static final String CLOUDSEARCH_SERVICE = "cloudsearch";
5073
5074 /**
5075 * Use with {@link #getSystemService(String)} to access the
5076 * {@link com.android.server.voiceinteraction.SoundTriggerService}.
5077 *
5078 * @hide
5079 * @see #getSystemService(String)
5080 */
5081 public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
5082
5083 /**
5084 * Use with {@link #getSystemService(String)} to access the
5085 * {@link com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareService}.
5086 *
5087 * @hide
5088 * @see #getSystemService(String)
5089 */
5090 public static final String SOUND_TRIGGER_MIDDLEWARE_SERVICE = "soundtrigger_middleware";
5091
5092 /**
5093 * Used for getting the wallpaper effects generation service.
5094 *
5095 * <p><b>NOTE: </b> this service is optional; callers of
5096 * {@code Context.getSystemServiceName(WALLPAPER_EFFECTS_GENERATION_SERVICE)} should check for
5097 * {@code null}.
5098 *
5099 * @hide
5100 * @see #getSystemService(String)
5101 */
5102 @SystemApi
5103 public static final String WALLPAPER_EFFECTS_GENERATION_SERVICE =
5104 "wallpaper_effects_generation";
5105
5106 /**
5107 * Used to access {@link MusicRecognitionManagerService}.
5108 *
5109 * @hide
5110 * @see #getSystemService(String)
5111 */
5112 @SystemApi
5113 public static final String MUSIC_RECOGNITION_SERVICE = "music_recognition";
5114
5115 /**
5116 * Official published name of the (internal) permission service.
5117 *
5118 * @see #getSystemService(String)
5119 * @hide
5120 */
5121 @SystemApi
5122 public static final String PERMISSION_SERVICE = "permission";
5123
5124 /**
5125 * Official published name of the legacy (internal) permission service.
5126 *
5127 * @see #getSystemService(String)
5128 * @hide
5129 */
5130 //@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
5131 public static final String LEGACY_PERMISSION_SERVICE = "legacy_permission";
5132
5133 /**
5134 * Official published name of the (internal) permission controller service.
5135 *
5136 * @see #getSystemService(String)
5137 * @hide
5138 */
5139 @SystemApi
5140 public static final String PERMISSION_CONTROLLER_SERVICE = "permission_controller";
5141
5142 /**
5143 * Official published name of the (internal) permission checker service.
5144 *
5145 * @see #getSystemService(String)
5146 * @hide
5147 */
5148 public static final String PERMISSION_CHECKER_SERVICE = "permission_checker";
5149
5150 /**
5151 * Official published name of the (internal) permission enforcer service.
5152 *
5153 * @see #getSystemService(String)
5154 * @hide
5155 */
5156 public static final String PERMISSION_ENFORCER_SERVICE = "permission_enforcer";
5157
5158 /**
5159 * Use with {@link #getSystemService(String) to retrieve an
5160 * {@link android.apphibernation.AppHibernationManager}} for
5161 * communicating with the hibernation service.
5162 * @hide
5163 *
5164 * @see #getSystemService(String)
5165 */
5166 @SystemApi
5167 public static final String APP_HIBERNATION_SERVICE = "app_hibernation";
5168
5169 /**
5170 * Use with {@link #getSystemService(String)} to retrieve an
5171 * {@link android.app.backup.IBackupManager IBackupManager} for communicating
5172 * with the backup mechanism.
5173 * @hide
5174 *
5175 * @see #getSystemService(String)
5176 */
5177 @SystemApi
5178 public static final String BACKUP_SERVICE = "backup";
5179
5180 /**
5181 * Use with {@link #getSystemService(String)} to retrieve an
5182 * {@link android.content.rollback.RollbackManager} for communicating
5183 * with the rollback manager
5184 *
5185 * @see #getSystemService(String)
5186 * @hide
5187 */
5188 @SystemApi
5189 public static final String ROLLBACK_SERVICE = "rollback";
5190
5191 /**
5192 * Use with {@link #getSystemService(String)} to retrieve an
5193 * {@link android.scheduling.RebootReadinessManager} for communicating
5194 * with the reboot readiness detector.
5195 *
5196 * @see #getSystemService(String)
5197 * @hide
5198 */
5199 @SystemApi
5200 public static final String REBOOT_READINESS_SERVICE = "reboot_readiness";
5201
5202 /**
5203 * Use with {@link #getSystemService(String)} to retrieve a
5204 * {@link android.os.DropBoxManager} instance for recording
5205 * diagnostic logs.
5206 * @see #getSystemService(String)
5207 */
5208 public static final String DROPBOX_SERVICE = "dropbox";
5209
5210 /**
5211 * System service name for BinaryTransparencyService. This is used to retrieve measurements
5212 * pertaining to various pre-installed and system binaries on device for the purposes of
5213 * providing transparency to the user.
5214 *
5215 * @hide
5216 */
5217 @SuppressLint("ServiceName")
5218 public static final String BINARY_TRANSPARENCY_SERVICE = "transparency";
5219
5220 /**
5221 * System service name for the DeviceIdleManager.
5222 * @see #getSystemService(String)
5223 * @hide
5224 */
5225 @TestApi
5226 @SuppressLint("ServiceName") // TODO: This should be renamed to DEVICE_IDLE_SERVICE
5227 public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
5228
5229 /**
5230 * System service name for the PowerWhitelistManager.
5231 *
5232 * @see #getSystemService(String)
5233 * @hide
5234 */
5235 @TestApi
5236 @Deprecated
5237 @SuppressLint("ServiceName")
5238 public static final String POWER_WHITELIST_MANAGER = "power_whitelist";
5239
5240 /**
5241 * System service name for the PowerExemptionManager.
5242 *
5243 * @see #getSystemService(String)
5244 * @hide
5245 */
5246 @TestApi
5247 public static final String POWER_EXEMPTION_SERVICE = "power_exemption";
5248
5249 /**
5250 * Use with {@link #getSystemService(String)} to retrieve a
5251 * {@link android.app.admin.DevicePolicyManager} for working with global
5252 * device policy management.
5253 *
5254 * @see #getSystemService(String)
5255 */
5256 public static final String DEVICE_POLICY_SERVICE = "device_policy";
5257
5258 /**
5259 * Use with {@link #getSystemService(String)} to retrieve a
5260 * {@link android.app.UiModeManager} for controlling UI modes.
5261 *
5262 * @see #getSystemService(String)
5263 */
5264 public static final String UI_MODE_SERVICE = "uimode";
5265
5266 /**
5267 * Use with {@link #getSystemService(String)} to retrieve a
5268 * {@link android.app.DownloadManager} for requesting HTTP downloads.
5269 *
5270 * @see #getSystemService(String)
5271 */
5272 public static final String DOWNLOAD_SERVICE = "download";
5273
5274 /**
5275 * Use with {@link #getSystemService(String)} to retrieve a
5276 * {@link android.os.BatteryManager} for managing battery state.
5277 *
5278 * @see #getSystemService(String)
5279 */
5280 public static final String BATTERY_SERVICE = "batterymanager";
5281
5282 /**
5283 * Use with {@link #getSystemService(String)} to retrieve a
5284 * {@link android.nfc.NfcManager} for using NFC.
5285 *
5286 * @see #getSystemService(String)
5287 */
5288 public static final String NFC_SERVICE = "nfc";
5289
5290 /**
5291 * Use with {@link #getSystemService(String)} to retrieve a
5292 * {@link android.bluetooth.BluetoothManager} for using Bluetooth.
5293 *
5294 * @see #getSystemService(String)
5295 */
5296 public static final String BLUETOOTH_SERVICE = "bluetooth";
5297
5298 /**
5299 * Use with {@link #getSystemService(String)} to retrieve a
5300 * {@link android.net.sip.SipManager} for accessing the SIP related service.
5301 *
5302 * @see #getSystemService(String)
5303 */
5304 /** @hide */
5305 public static final String SIP_SERVICE = "sip";
5306
5307 /**
5308 * Use with {@link #getSystemService(String)} to retrieve a {@link
5309 * android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
5310 * and for controlling this device's behavior as a USB device.
5311 *
5312 * @see #getSystemService(String)
5313 * @see android.hardware.usb.UsbManager
5314 */
5315 public static final String USB_SERVICE = "usb";
5316
5317 /**
5318 * Use with {@link #getSystemService(String)} to retrieve a {@link
5319 * Use with {@link #getSystemService} to retrieve a {@link
5320 * android.debug.AdbManager} for access to ADB debug functions.
5321 *
5322 * @see #getSystemService(String)
5323 * @see android.debug.AdbManager
5324 *
5325 * @hide
5326 */
5327 public static final String ADB_SERVICE = "adb";
5328
5329 /**
5330 * Use with {@link #getSystemService(String)} to retrieve a {@link
5331 * android.hardware.SerialManager} for access to serial ports.
5332 *
5333 * @see #getSystemService(String)
5334 * @see android.hardware.SerialManager
5335 *
5336 * @hide
5337 */
5338 public static final String SERIAL_SERVICE = "serial";
5339
5340 /**
5341 * Use with {@link #getSystemService(String)} to retrieve a
5342 * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing
5343 * HDMI-CEC protocol.
5344 *
5345 * @see #getSystemService(String)
5346 * @see android.hardware.hdmi.HdmiControlManager
5347 * @hide
5348 */
5349 @SystemApi
5350 public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
5351
5352 /**
5353 * Use with {@link #getSystemService(String)} to retrieve a
5354 * {@link android.hardware.input.InputManager} for interacting with input devices.
5355 *
5356 * @see #getSystemService(String)
5357 * @see android.hardware.input.InputManager
5358 */
5359 public static final String INPUT_SERVICE = "input";
5360
5361 /**
5362 * Use with {@link #getSystemService(String)} to retrieve a
5363 * {@link android.hardware.display.DisplayManager} for interacting with display devices.
5364 *
5365 * @see #getSystemService(String)
5366 * @see android.hardware.display.DisplayManager
5367 */
5368 public static final String DISPLAY_SERVICE = "display";
5369
5370 /**
5371 * Use with {@link #getSystemService(String)} to retrieve a
5372 * {@link android.hardware.display.ColorDisplayManager} for controlling color transforms.
5373 *
5374 * @see #getSystemService(String)
5375 * @see android.hardware.display.ColorDisplayManager
5376 * @hide
5377 */
5378 public static final String COLOR_DISPLAY_SERVICE = "color_display";
5379
5380 /**
5381 * Use with {@link #getSystemService(String)} to retrieve a
5382 * {@link android.os.UserManager} for managing users on devices that support multiple users.
5383 *
5384 * @see #getSystemService(String)
5385 * @see android.os.UserManager
5386 */
5387 public static final String USER_SERVICE = "user";
5388
5389 /**
5390 * Use with {@link #getSystemService(String)} to retrieve a
5391 * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across
5392 * profiles of a user.
5393 *
5394 * @see #getSystemService(String)
5395 * @see android.content.pm.LauncherApps
5396 */
5397 public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
5398
5399 /**
5400 * Use with {@link #getSystemService(String)} to retrieve a
5401 * {@link android.content.RestrictionsManager} for retrieving application restrictions
5402 * and requesting permissions for restricted operations.
5403 * @see #getSystemService(String)
5404 * @see android.content.RestrictionsManager
5405 */
5406 public static final String RESTRICTIONS_SERVICE = "restrictions";
5407
5408 /**
5409 * Use with {@link #getSystemService(String)} to retrieve a
5410 * {@link android.app.AppOpsManager} for tracking application operations
5411 * on the device.
5412 *
5413 * @see #getSystemService(String)
5414 * @see android.app.AppOpsManager
5415 */
5416 public static final String APP_OPS_SERVICE = "appops";
5417
5418 /**
5419 * Use with {@link #getSystemService(String)} to retrieve a {@link android.app.role.RoleManager}
5420 * for managing roles.
5421 *
5422 * @see #getSystemService(String)
5423 * @see android.app.role.RoleManager
5424 */
5425 public static final String ROLE_SERVICE = "role";
5426
5427 /**
5428 * Use with {@link #getSystemService(String)} to retrieve a
5429 * {@link android.hardware.camera2.CameraManager} for interacting with
5430 * camera devices.
5431 *
5432 * @see #getSystemService(String)
5433 * @see android.hardware.camera2.CameraManager
5434 */
5435 public static final String CAMERA_SERVICE = "camera";
5436
5437 /**
5438 * {@link android.print.PrintManager} for printing and managing
5439 * printers and print tasks.
5440 *
5441 * @see #getSystemService(String)
5442 * @see android.print.PrintManager
5443 */
5444 public static final String PRINT_SERVICE = "print";
5445
5446 /**
5447 * Use with {@link #getSystemService(String)} to retrieve a
5448 * {@link android.companion.CompanionDeviceManager} for managing companion devices
5449 *
5450 * @see #getSystemService(String)
5451 * @see android.companion.CompanionDeviceManager
5452 */
5453 public static final String COMPANION_DEVICE_SERVICE = "companiondevice";
5454
5455 /**
5456 * Use with {@link #getSystemService(String)} to retrieve a
5457 * {@link android.companion.virtual.VirtualDeviceManager} for managing virtual devices.
5458 *
5459 * @see #getSystemService(String)
5460 * @see android.companion.virtual.VirtualDeviceManager
5461 * @hide
5462 */
5463 public static final String VIRTUAL_DEVICE_SERVICE = "virtualdevice";
5464
5465 /**
5466 * Use with {@link #getSystemService(String)} to retrieve a
5467 * {@link android.hardware.ConsumerIrManager} for transmitting infrared
5468 * signals from the device.
5469 *
5470 * @see #getSystemService(String)
5471 * @see android.hardware.ConsumerIrManager
5472 */
5473 public static final String CONSUMER_IR_SERVICE = "consumer_ir";
5474
5475 /**
5476 * {@link android.app.trust.TrustManager} for managing trust agents.
5477 * @see #getSystemService(String)
5478 * @see android.app.trust.TrustManager
5479 * @hide
5480 */
5481 public static final String TRUST_SERVICE = "trust";
5482
5483 /**
5484 * Use with {@link #getSystemService(String)} to retrieve a
5485 * {@link android.media.tv.interactive.TvInteractiveAppManager} for interacting with TV
5486 * interactive applications on the device.
5487 *
5488 * @see #getSystemService(String)
5489 * @see android.media.tv.interactive.TvInteractiveAppManager
5490 */
5491 public static final String TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app";
5492
5493 /**
5494 * Use with {@link #getSystemService(String)} to retrieve a
5495 * {@link android.media.tv.TvInputManager} for interacting with TV inputs
5496 * on the device.
5497 *
5498 * @see #getSystemService(String)
5499 * @see android.media.tv.TvInputManager
5500 */
5501 public static final String TV_INPUT_SERVICE = "tv_input";
5502
5503 /**
5504 * Use with {@link #getSystemService(String)} to retrieve a
5505 * {@link android.media.tv.TunerResourceManager} for interacting with TV
5506 * tuner resources on the device.
5507 *
5508 * @see #getSystemService(String)
5509 * @see android.media.tv.TunerResourceManager
5510 * @hide
5511 */
5512 public static final String TV_TUNER_RESOURCE_MGR_SERVICE = "tv_tuner_resource_mgr";
5513
5514 /**
5515 * {@link android.net.NetworkScoreManager} for managing network scoring.
5516 * @see #getSystemService(String)
5517 * @see android.net.NetworkScoreManager
5518 * @deprecated see
5519 * <a href="{@docRoot}guide/topics/connectivity/wifi-suggest">Wi-Fi Suggestion API</a>
5520 * for alternative API to propose WiFi networks.
5521 * @hide
5522 */
5523 @SystemApi
5524 @Deprecated
5525 public static final String NETWORK_SCORE_SERVICE = "network_score";
5526
5527 /**
5528 * Use with {@link #getSystemService(String)} to retrieve a {@link
5529 * android.app.usage.UsageStatsManager} for querying device usage stats.
5530 *
5531 * @see #getSystemService(String)
5532 * @see android.app.usage.UsageStatsManager
5533 */
5534 public static final String USAGE_STATS_SERVICE = "usagestats";
5535
5536 /**
5537 * Use with {@link #getSystemService(String)} to retrieve a {@link
5538 * android.app.job.JobScheduler} instance for managing occasional
5539 * background tasks.
5540 * @see #getSystemService(String)
5541 * @see android.app.job.JobScheduler
5542 */
5543 public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
5544
5545 /**
5546 * Use with {@link #getSystemService(String)} to retrieve a
5547 * {@link android.app.tare.EconomyManager} instance for understanding economic standing.
5548 * @see #getSystemService(String)
5549 * @hide
5550 * @see android.app.tare.EconomyManager
5551 */
5552 public static final String RESOURCE_ECONOMY_SERVICE = "tare";
5553
5554 /**
5555 * Use with {@link #getSystemService(String)} to retrieve a {@link
5556 * android.service.persistentdata.PersistentDataBlockManager} instance
5557 * for interacting with a storage device that lives across factory resets.
5558 *
5559 * @see #getSystemService(String)
5560 * @see android.service.persistentdata.PersistentDataBlockManager
5561 * @hide
5562 */
5563 @SystemApi
5564 public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
5565
5566 /**
5567 * Use with {@link #getSystemService(String)} to retrieve a {@link
5568 * android.service.oemlock.OemLockManager} instance for managing the OEM lock.
5569 *
5570 * @see #getSystemService(String)
5571 * @see android.service.oemlock.OemLockManager
5572 * @hide
5573 */
5574 @SystemApi
5575 public static final String OEM_LOCK_SERVICE = "oem_lock";
5576
5577 /**
5578 * Use with {@link #getSystemService(String)} to retrieve a {@link
5579 * android.media.projection.MediaProjectionManager} instance for managing
5580 * media projection sessions.
5581 * @see #getSystemService(String)
5582 * @see android.media.projection.MediaProjectionManager
5583 */
5584 public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
5585
5586 /**
5587 * Use with {@link #getSystemService(String)} to retrieve a
5588 * {@link android.media.midi.MidiManager} for accessing the MIDI service.
5589 *
5590 * @see #getSystemService(String)
5591 */
5592 public static final String MIDI_SERVICE = "midi";
5593
5594
5595 /**
5596 * Use with {@link #getSystemService(String)} to retrieve a
5597 * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service.
5598 *
5599 * @see #getSystemService(String)
5600 * @hide
5601 */
5602 public static final String RADIO_SERVICE = "broadcastradio";
5603
5604 /**
5605 * Use with {@link #getSystemService(String)} to retrieve a
5606 * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service.
5607 *
5608 * @see #getSystemService(String)
5609 */
5610 public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
5611
5612 /**
5613 * Use with {@link #getSystemService(String)} to retrieve a
5614 * {@link android.os.ThermalService} for accessing the thermal service.
5615 *
5616 * @see #getSystemService(String)
5617 * @hide
5618 */
5619 public static final String THERMAL_SERVICE = "thermalservice";
5620
5621 /**
5622 * Use with {@link #getSystemService(String)} to retrieve a
5623 * {@link android.os.PerformanceHintManager} for accessing the performance hinting service.
5624 *
5625 * @see #getSystemService(String)
5626 */
5627 public static final String PERFORMANCE_HINT_SERVICE = "performance_hint";
5628
5629 /**
5630 * Use with {@link #getSystemService(String)} to retrieve a
5631 * {@link android.content.pm.ShortcutManager} for accessing the launcher shortcut service.
5632 *
5633 * @see #getSystemService(String)
5634 * @see android.content.pm.ShortcutManager
5635 */
5636 public static final String SHORTCUT_SERVICE = "shortcut";
5637
5638 /**
5639 * Use with {@link #getSystemService(String)} to retrieve a {@link
5640 * android.hardware.location.ContextHubManager} for accessing context hubs.
5641 *
5642 * @see #getSystemService(String)
5643 * @see android.hardware.location.ContextHubManager
5644 *
5645 * @hide
5646 */
5647 @SystemApi
5648 public static final String CONTEXTHUB_SERVICE = "contexthub";
5649
5650 /**
5651 * Use with {@link #getSystemService(String)} to retrieve a
5652 * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power,
5653 * memory, etc) metrics.
5654 *
5655 * @see #getSystemService(String)
5656 */
5657 public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
5658
5659 /**
5660 * Gatekeeper Service.
5661 * @hide
5662 */
5663 public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
5664
5665 /**
5666 * Service defining the policy for access to device identifiers.
5667 * @hide
5668 */
5669 public static final String DEVICE_IDENTIFIERS_SERVICE = "device_identifiers";
5670
5671 /**
5672 * Service to report a system health "incident"
5673 * @hide
5674 */
5675 public static final String INCIDENT_SERVICE = "incident";
5676
5677 /**
5678 * Service to assist incidentd and dumpstated in reporting status to the user
5679 * and in confirming authorization to take an incident report or bugreport
5680 * @hide
5681 */
5682 public static final String INCIDENT_COMPANION_SERVICE = "incidentcompanion";
5683
5684 /**
5685 * Service to assist {@link android.app.StatsManager} that lives in system server.
5686 * @hide
5687 */
5688 public static final String STATS_MANAGER_SERVICE = "statsmanager";
5689
5690 /**
5691 * Service to assist statsd in obtaining general stats.
5692 * @hide
5693 */
5694 public static final String STATS_COMPANION_SERVICE = "statscompanion";
5695
5696 /**
5697 * Service to assist statsd in logging atoms from bootstrap atoms.
5698 * @hide
5699 */
5700 public static final String STATS_BOOTSTRAP_ATOM_SERVICE = "statsbootstrap";
5701
5702 /**
5703 * Use with {@link #getSystemService(String)} to retrieve an {@link android.app.StatsManager}.
5704 * @hide
5705 */
5706 @SystemApi
5707 public static final String STATS_MANAGER = "stats";
5708
5709 /**
5710 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
5711 * {@link IPlatformCompat} IBinder for communicating with the platform compat service.
5712 * @hide
5713 */
5714 public static final String PLATFORM_COMPAT_SERVICE = "platform_compat";
5715
5716 /**
5717 * Use with {@link android.os.ServiceManager.getService()} to retrieve a
5718 * {@link IPlatformCompatNative} IBinder for native code communicating with the platform compat
5719 * service.
5720 * @hide
5721 */
5722 public static final String PLATFORM_COMPAT_NATIVE_SERVICE = "platform_compat_native";
5723
5724 /**
5725 * Service to capture a bugreport.
5726 * @see #getSystemService(String)
5727 * @see android.os.BugreportManager
5728 */
5729 public static final String BUGREPORT_SERVICE = "bugreport";
5730
5731 /**
5732 * Use with {@link #getSystemService(String)} to retrieve a {@link
5733 * android.content.om.OverlayManager} for managing overlay packages.
5734 *
5735 * @see #getSystemService(String)
5736 * @see android.content.om.OverlayManager
5737 * @hide
5738 */
5739 public static final String OVERLAY_SERVICE = "overlay";
5740
5741 /**
5742 * Use with {@link #getSystemService(String)} to manage resources.
5743 *
5744 * @see #getSystemService(String)
5745 * @see com.android.server.resources.ResourcesManagerService
5746 * @hide
5747 */
5748 public static final String RESOURCES_SERVICE = "resources";
5749
5750 /**
5751 * Use with {@link #getSystemService(String)} to retrieve a
5752 * {android.os.IIdmap2} for managing idmap files (used by overlay
5753 * packages).
5754 *
5755 * @see #getSystemService(String)
5756 * @hide
5757 */
5758 public static final String IDMAP_SERVICE = "idmap";
5759
5760 /**
5761 * Use with {@link #getSystemService(String)} to retrieve a
5762 * {@link VrManager} for accessing the VR service.
5763 *
5764 * @see #getSystemService(String)
5765 * @hide
5766 */
5767 @SystemApi
5768 public static final String VR_SERVICE = "vrmanager";
5769
5770 /**
5771 * Use with {@link #getSystemService(String)} to retrieve a
5772 * {@link android.content.pm.CrossProfileApps} for cross profile operations.
5773 *
5774 * @see #getSystemService(String)
5775 */
5776 public static final String CROSS_PROFILE_APPS_SERVICE = "crossprofileapps";
5777
5778 /**
5779 * Use with {@link #getSystemService} to retrieve a
5780 * {@link android.se.omapi.ISecureElementService}
5781 * for accessing the SecureElementService.
5782 *
5783 * @hide
5784 */
5785 @SystemApi
5786 public static final String SECURE_ELEMENT_SERVICE = "secure_element";
5787
5788 /**
5789 * Use with {@link #getSystemService(String)} to retrieve an
5790 * {@link android.app.timedetector.TimeDetector}.
5791 * @hide
5792 *
5793 * @see #getSystemService(String)
5794 */
5795 public static final String TIME_DETECTOR_SERVICE = "time_detector";
5796
5797 /**
5798 * Use with {@link #getSystemService(String)} to retrieve an
5799 * {@link android.app.timezonedetector.TimeZoneDetector}.
5800 * @hide
5801 *
5802 * @see #getSystemService(String)
5803 */
5804 public static final String TIME_ZONE_DETECTOR_SERVICE = "time_zone_detector";
5805
5806 /**
5807 * Use with {@link #getSystemService(String)} to retrieve an {@link TimeManager}.
5808 * @hide
5809 *
5810 * @see #getSystemService(String)
5811 */
5812 public static final String TIME_MANAGER = "time_manager";
5813
5814 /**
5815 * Binder service name for {@link AppBindingService}.
5816 * @hide
5817 */
5818 public static final String APP_BINDING_SERVICE = "app_binding";
5819
5820 /**
5821 * Use with {@link #getSystemService(String)} to retrieve an
5822 * {@link android.telephony.ims.ImsManager}.
5823 */
5824 public static final String TELEPHONY_IMS_SERVICE = "telephony_ims";
5825
5826 /**
5827 * Use with {@link #getSystemService(String)} to retrieve an
5828 * {@link android.os.SystemConfigManager}.
5829 * @hide
5830 */
5831 @SystemApi
5832 public static final String SYSTEM_CONFIG_SERVICE = "system_config";
5833
5834 /**
5835 * Use with {@link #getSystemService(String)} to retrieve an
5836 * {@link android.telephony.ims.RcsMessageManager}.
5837 * @hide
5838 */
5839 public static final String TELEPHONY_RCS_MESSAGE_SERVICE = "ircsmessage";
5840
5841 /**
5842 * Use with {@link #getSystemService(String)} to retrieve an
5843 * {@link android.os.image.DynamicSystemManager}.
5844 * @hide
5845 */
5846 public static final String DYNAMIC_SYSTEM_SERVICE = "dynamic_system";
5847
5848 /**
5849 * Use with {@link #getSystemService(String)} to retrieve a {@link
5850 * android.app.blob.BlobStoreManager} for contributing and accessing data blobs
5851 * from the blob store maintained by the system.
5852 *
5853 * @see #getSystemService(String)
5854 * @see android.app.blob.BlobStoreManager
5855 */
5856 public static final String BLOB_STORE_SERVICE = "blob_store";
5857
5858 /**
5859 * Use with {@link #getSystemService(String)} to retrieve an
5860 * {@link TelephonyRegistryManager}.
5861 * @hide
5862 */
5863 public static final String TELEPHONY_REGISTRY_SERVICE = "telephony_registry";
5864
5865 /**
5866 * Use with {@link #getSystemService(String)} to retrieve an
5867 * {@link android.os.BatteryStatsManager}.
5868 * @hide
5869 */
5870 @SystemApi
5871 @SuppressLint("ServiceName")
5872 public static final String BATTERY_STATS_SERVICE = "batterystats";
5873
5874 /**
5875 * Use with {@link #getSystemService(String)} to retrieve an
5876 * {@link android.app.appsearch.AppSearchManager} for
5877 * indexing and querying app data managed by the system.
5878 *
5879 * @see #getSystemService(String)
5880 */
5881 public static final String APP_SEARCH_SERVICE = "app_search";
5882
5883 /**
5884 * Use with {@link #getSystemService(String)} to retrieve an
5885 * {@link android.content.integrity.AppIntegrityManager}.
5886 * @hide
5887 */
5888 @SystemApi
5889 public static final String APP_INTEGRITY_SERVICE = "app_integrity";
5890
5891 /**
5892 * Use with {@link #getSystemService(String)} to retrieve an
5893 * {@link android.content.pm.DataLoaderManager}.
5894 * @hide
5895 */
5896 public static final String DATA_LOADER_MANAGER_SERVICE = "dataloader_manager";
5897
5898 /**
5899 * Use with {@link #getSystemService(String)} to retrieve an
5900 * {@link android.os.incremental.IncrementalManager}.
5901 * @hide
5902 */
5903 public static final String INCREMENTAL_SERVICE = "incremental";
5904
5905 /**
5906 * Use with {@link #getSystemService(String)} to retrieve an
5907 * {@link android.security.attestationverification.AttestationVerificationManager}.
5908 * @see #getSystemService(String)
5909 * @see android.security.attestationverification.AttestationVerificationManager
5910 * @hide
5911 */
5912 public static final String ATTESTATION_VERIFICATION_SERVICE = "attestation_verification";
5913
5914 /**
5915 * Use with {@link #getSystemService(String)} to retrieve an
5916 * {@link android.security.FileIntegrityManager}.
5917 * @see #getSystemService(String)
5918 * @see android.security.FileIntegrityManager
5919 */
5920 public static final String FILE_INTEGRITY_SERVICE = "file_integrity";
5921
5922 /**
5923 * Binder service for remote key provisioning.
5924 *
5925 * @see android.frameworks.rkp.IRemoteProvisioning
5926 * @hide
5927 */
5928 public static final String REMOTE_PROVISIONING_SERVICE = "remote_provisioning";
5929
5930 /**
5931 * Use with {@link #getSystemService(String)} to retrieve a
5932 * {@link android.hardware.lights.LightsManager} for controlling device lights.
5933 *
5934 * @see #getSystemService(String)
5935 * @hide
5936 */
5937 public static final String LIGHTS_SERVICE = "lights";
5938
5939 /**
5940 * Use with {@link #getSystemService(String)} to retrieve a
5941 * {@link android.uwb.UwbManager}.
5942 *
5943 * @see #getSystemService(String)
5944 * @hide
5945 */
5946 @SystemApi
5947 public static final String UWB_SERVICE = "uwb";
5948
5949 /**
5950 * Use with {@link #getSystemService(String)} to retrieve a
5951 * {@link android.app.DreamManager} for controlling Dream states.
5952 *
5953 * @see #getSystemService(String)
5954
5955 * @hide
5956 */
5957 @TestApi
5958 public static final String DREAM_SERVICE = "dream";
5959
5960 /**
5961 * Use with {@link #getSystemService(String)} to retrieve a
5962 * {@link android.telephony.SmsManager} for accessing Sms functionality.
5963 *
5964 * @see #getSystemService(String)
5965
5966 * @hide
5967 */
5968 public static final String SMS_SERVICE = "sms";
5969
5970 /**
5971 * Use with {@link #getSystemService(String)} to access a {@link PeopleManager} to interact
5972 * with your published conversations.
5973 *
5974 * @see #getSystemService(String)
5975 */
5976 public static final String PEOPLE_SERVICE = "people";
5977
5978 /**
5979 * Use with {@link #getSystemService(String)} to access device state service.
5980 *
5981 * @see #getSystemService(String)
5982 * @hide
5983 */
5984 public static final String DEVICE_STATE_SERVICE = "device_state";
5985
5986 /**
5987 * Use with {@link #getSystemService(String)} to retrieve a
5988 * {@link android.media.metrics.MediaMetricsManager} for interacting with media metrics
5989 * on the device.
5990 *
5991 * @see #getSystemService(String)
5992 * @see android.media.metrics.MediaMetricsManager
5993 */
5994 public static final String MEDIA_METRICS_SERVICE = "media_metrics";
5995
5996 /**
5997 * Use with {@link #getSystemService(String)} to access system speech recognition service.
5998 *
5999 * @see #getSystemService(String)
6000 * @hide
6001 */
6002 public static final String SPEECH_RECOGNITION_SERVICE = "speech_recognition";
6003
6004 /**
6005 * Use with {@link #getSystemService(String)} to retrieve a
6006 * {@link GameManager}.
6007 *
6008 * @see #getSystemService(String)
6009 */
6010 public static final String GAME_SERVICE = "game";
6011
6012 /**
6013 * Use with {@link #getSystemService(String)} to access
6014 * {@link android.content.pm.verify.domain.DomainVerificationManager} to retrieve approval and
6015 * user state for declared web domains.
6016 *
6017 * @see #getSystemService(String)
6018 * @see android.content.pm.verify.domain.DomainVerificationManager
6019 */
6020 public static final String DOMAIN_VERIFICATION_SERVICE = "domain_verification";
6021
6022 /**
6023 * Use with {@link #getSystemService(String)} to access
6024 * {@link android.view.displayhash.DisplayHashManager} to handle display hashes.
6025 *
6026 * @see #getSystemService(String)
6027 */
6028 public static final String DISPLAY_HASH_SERVICE = "display_hash";
6029
6030 /**
6031 * Use with {@link #getSystemService(String)} to retrieve a
6032 * {@link android.app.LocaleManager}.
6033 *
6034 * @see #getSystemService(String)
6035 */
6036 public static final String LOCALE_SERVICE = "locale";
6037
6038 /**
6039 * Use with {@link #getSystemService(String)} to retrieve a {@link
6040 * android.safetycenter.SafetyCenterManager} instance for interacting with the safety center.
6041 *
6042 * @see #getSystemService(String)
6043 * @see android.safetycenter.SafetyCenterManager
6044 * @hide
6045 */
6046 @SystemApi
6047 public static final String SAFETY_CENTER_SERVICE = "safety_center";
6048
6049 /**
6050 * Use with {@link #getSystemService(String)} to retrieve a
6051 * {@link android.nearby.NearbyManager} to discover nearby devices.
6052 *
6053 * @see #getSystemService(String)
6054 * @see android.nearby.NearbyManager
6055 * @hide
6056 */
6057 @SystemApi
6058 public static final String NEARBY_SERVICE = "nearby";
6059
6060 /**
6061 * Use with {@link #getSystemService(String)} to retrieve a
6062 * {@link android.app.ambientcontext.AmbientContextManager}.
6063 *
6064 * @see #getSystemService(String)
6065 * @see AmbientContextManager
6066 * @hide
6067 */
6068 @SystemApi
6069 public static final String AMBIENT_CONTEXT_SERVICE = "ambient_context";
6070
6071 /**
6072 * Use with {@link #getSystemService(String)} to retrieve a
6073 * {@link android.system.virtualmachine.VirtualMachineManager}.
6074 *
6075 * <p>On devices without {@link PackageManager#FEATURE_VIRTUALIZATION_FRAMEWORK} system feature
6076 * the {@link #getSystemService(String)} will return {@code null}.
6077 *
6078 * @see #getSystemService(String)
6079 * @see android.system.virtualmachine.VirtualMachineManager
6080 * @hide
6081 */
6082 @SystemApi
6083 public static final String VIRTUALIZATION_SERVICE = "virtualization";
6084
6085 /**
6086 * Determine whether the given permission is allowed for a particular
6087 * process and user ID running in the system.
6088 *
6089 * @param permission The name of the permission being checked.
6090 * @param pid The process ID being checked against. Must be > 0.
6091 * @param uid The user ID being checked against. A uid of 0 is the root
6092 * user, which will pass every permission check.
6093 *
6094 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
6095 * pid/uid is allowed that permission, or
6096 * {@link PackageManager#PERMISSION_DENIED} if it is not.
6097 *
6098 * @see PackageManager#checkPermission(String, String)
6099 * @see #checkCallingPermission
6100 */
6101 @CheckResult(suggest="#enforcePermission(String,int,int,String)")
6102 @PackageManager.PermissionResult
6103 public abstract int checkPermission(@NonNull String permission, int pid, int uid);
6104
6105 /** @hide */
6106 @SuppressWarnings("HiddenAbstractMethod")
6107 @PackageManager.PermissionResult
6108 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
6109 public abstract int checkPermission(@NonNull String permission, int pid, int uid,
6110 IBinder callerToken);
6111
6112 /**
6113 * Determine whether the calling process of an IPC you are handling has been
6114 * granted a particular permission. This is basically the same as calling
6115 * {@link #checkPermission(String, int, int)} with the pid and uid returned
6116 * by {@link android.os.Binder#getCallingPid} and
6117 * {@link android.os.Binder#getCallingUid}. One important difference
6118 * is that if you are not currently processing an IPC, this function
6119 * will always fail. This is done to protect against accidentally
6120 * leaking permissions; you can use {@link #checkCallingOrSelfPermission}
6121 * to avoid this protection.
6122 *
6123 * @param permission The name of the permission being checked.
6124 *
6125 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
6126 * pid/uid is allowed that permission, or
6127 * {@link PackageManager#PERMISSION_DENIED} if it is not.
6128 *
6129 * @see PackageManager#checkPermission(String, String)
6130 * @see #checkPermission
6131 * @see #checkCallingOrSelfPermission
6132 */
6133 @CheckResult(suggest="#enforceCallingPermission(String,String)")
6134 @PackageManager.PermissionResult
6135 public abstract int checkCallingPermission(@NonNull String permission);
6136
6137 /**
6138 * Determine whether the calling process of an IPC <em>or you</em> have been
6139 * granted a particular permission. This is the same as
6140 * {@link #checkCallingPermission}, except it grants your own permissions
6141 * if you are not currently processing an IPC. Use with care!
6142 *
6143 * @param permission The name of the permission being checked.
6144 *
6145 * @return {@link PackageManager#PERMISSION_GRANTED} if the calling
6146 * pid/uid is allowed that permission, or
6147 * {@link PackageManager#PERMISSION_DENIED} if it is not.
6148 *
6149 * @see PackageManager#checkPermission(String, String)
6150 * @see #checkPermission
6151 * @see #checkCallingPermission
6152 */
6153 @CheckResult(suggest="#enforceCallingOrSelfPermission(String,String)")
6154 @PackageManager.PermissionResult
6155 public abstract int checkCallingOrSelfPermission(@NonNull String permission);
6156
6157 /**
6158 * Determine whether <em>you</em> have been granted a particular permission.
6159 *
6160 * @param permission The name of the permission being checked.
6161 *
6162 * @return {@link PackageManager#PERMISSION_GRANTED} if you have the
6163 * permission, or {@link PackageManager#PERMISSION_DENIED} if not.
6164 *
6165 * @see PackageManager#checkPermission(String, String)
6166 * @see #checkCallingPermission(String)
6167 */
6168 @PackageManager.PermissionResult
6169 public abstract int checkSelfPermission(@NonNull String permission);
6170
6171 /**
6172 * If the given permission is not allowed for a particular process
6173 * and user ID running in the system, throw a {@link SecurityException}.
6174 *
6175 * @param permission The name of the permission being checked.
6176 * @param pid The process ID being checked against. Must be &gt; 0.
6177 * @param uid The user ID being checked against. A uid of 0 is the root
6178 * user, which will pass every permission check.
6179 * @param message A message to include in the exception if it is thrown.
6180 *
6181 * @see #checkPermission(String, int, int)
6182 */
6183 public abstract void enforcePermission(
6184 @NonNull String permission, int pid, int uid, @Nullable String message);
6185
6186 /**
6187 * If the calling process of an IPC you are handling has not been
6188 * granted a particular permission, throw a {@link
6189 * SecurityException}. This is basically the same as calling
6190 * {@link #enforcePermission(String, int, int, String)} with the
6191 * pid and uid returned by {@link android.os.Binder#getCallingPid}
6192 * and {@link android.os.Binder#getCallingUid}. One important
6193 * difference is that if you are not currently processing an IPC,
6194 * this function will always throw the SecurityException. This is
6195 * done to protect against accidentally leaking permissions; you
6196 * can use {@link #enforceCallingOrSelfPermission} to avoid this
6197 * protection.
6198 *
6199 * @param permission The name of the permission being checked.
6200 * @param message A message to include in the exception if it is thrown.
6201 *
6202 * @see #checkCallingPermission(String)
6203 */
6204 public abstract void enforceCallingPermission(
6205 @NonNull String permission, @Nullable String message);
6206
6207 /**
6208 * If neither you nor the calling process of an IPC you are
6209 * handling has been granted a particular permission, throw a
6210 * {@link SecurityException}. This is the same as {@link
6211 * #enforceCallingPermission}, except it grants your own
6212 * permissions if you are not currently processing an IPC. Use
6213 * with care!
6214 *
6215 * @param permission The name of the permission being checked.
6216 * @param message A message to include in the exception if it is thrown.
6217 *
6218 * @see #checkCallingOrSelfPermission(String)
6219 */
6220 public abstract void enforceCallingOrSelfPermission(
6221 @NonNull String permission, @Nullable String message);
6222
6223 /**
6224 * Grant permission to access a specific Uri to another package, regardless
6225 * of whether that package has general permission to access the Uri's
6226 * content provider. This can be used to grant specific, temporary
6227 * permissions, typically in response to user interaction (such as the
6228 * user opening an attachment that you would like someone else to
6229 * display).
6230 *
6231 * <p>Normally you should use {@link Intent#FLAG_GRANT_READ_URI_PERMISSION
6232 * Intent.FLAG_GRANT_READ_URI_PERMISSION} or
6233 * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION
6234 * Intent.FLAG_GRANT_WRITE_URI_PERMISSION} with the Intent being used to
6235 * start an activity instead of this function directly. If you use this
6236 * function directly, you should be sure to call
6237 * {@link #revokeUriPermission} when the target should no longer be allowed
6238 * to access it.
6239 *
6240 * <p>To succeed, the content provider owning the Uri must have set the
6241 * {@link android.R.styleable#AndroidManifestProvider_grantUriPermissions
6242 * grantUriPermissions} attribute in its manifest or included the
6243 * {@link android.R.styleable#AndroidManifestGrantUriPermission
6244 * &lt;grant-uri-permissions&gt;} tag.
6245 *
6246 * @param toPackage The package you would like to allow to access the Uri.
6247 * @param uri The Uri you would like to grant access to.
6248 * @param modeFlags The desired access modes.
6249 *
6250 * @see #revokeUriPermission
6251 */
6252 public abstract void grantUriPermission(String toPackage, Uri uri,
6253 @Intent.GrantUriMode int modeFlags);
6254
6255 /**
6256 * Remove all permissions to access a particular content provider Uri
6257 * that were previously added with {@link #grantUriPermission} or <em>any other</em> mechanism.
6258 * The given Uri will match all previously granted Uris that are the same or a
6259 * sub-path of the given Uri. That is, revoking "content://foo/target" will
6260 * revoke both "content://foo/target" and "content://foo/target/sub", but not
6261 * "content://foo". It will not remove any prefix grants that exist at a
6262 * higher level.
6263 *
6264 * <p>Prior to {@link android.os.Build.VERSION_CODES#LOLLIPOP}, if you did not have
6265 * regular permission access to a Uri, but had received access to it through
6266 * a specific Uri permission grant, you could not revoke that grant with this
6267 * function and a {@link SecurityException} would be thrown. As of
6268 * {@link android.os.Build.VERSION_CODES#LOLLIPOP}, this function will not throw a security
6269 * exception, but will remove whatever permission grants to the Uri had been given to the app
6270 * (or none).</p>
6271 *
6272 * <p>Unlike {@link #revokeUriPermission(String, Uri, int)}, this method impacts all permission
6273 * grants matching the given Uri, for any package they had been granted to, through any
6274 * mechanism this had happened (such as indirectly through the clipboard, activity launch,
6275 * service start, etc). That means this can be potentially dangerous to use, as it can
6276 * revoke grants that another app could be strongly expecting to stick around.</p>
6277 *
6278 * @param uri The Uri you would like to revoke access to.
6279 * @param modeFlags The access modes to revoke.
6280 *
6281 * @see #grantUriPermission
6282 */
6283 public abstract void revokeUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
6284
6285 /**
6286 * Remove permissions to access a particular content provider Uri
6287 * that were previously added with {@link #grantUriPermission} for a specific target
6288 * package. The given Uri will match all previously granted Uris that are the same or a
6289 * sub-path of the given Uri. That is, revoking "content://foo/target" will
6290 * revoke both "content://foo/target" and "content://foo/target/sub", but not
6291 * "content://foo". It will not remove any prefix grants that exist at a
6292 * higher level.
6293 *
6294 * <p>Unlike {@link #revokeUriPermission(Uri, int)}, this method will <em>only</em>
6295 * revoke permissions that had been explicitly granted through {@link #grantUriPermission}
6296 * and only for the package specified. Any matching grants that have happened through
6297 * other mechanisms (clipboard, activity launching, service starting, etc) will not be
6298 * removed.</p>
6299 *
6300 * @param toPackage The package you had previously granted access to.
6301 * @param uri The Uri you would like to revoke access to.
6302 * @param modeFlags The access modes to revoke.
6303 *
6304 * @see #grantUriPermission
6305 */
6306 public abstract void revokeUriPermission(String toPackage, Uri uri,
6307 @Intent.AccessUriMode int modeFlags);
6308
6309 /**
6310 * Determine whether a particular process and user ID has been granted
6311 * permission to access a specific URI. This only checks for permissions
6312 * that have been explicitly granted -- if the given process/uid has
6313 * more general access to the URI's content provider then this check will
6314 * always fail.
6315 *
6316 * @param uri The uri that is being checked.
6317 * @param pid The process ID being checked against. Must be &gt; 0.
6318 * @param uid The user ID being checked against. A uid of 0 is the root
6319 * user, which will pass every permission check.
6320 * @param modeFlags The access modes to check.
6321 *
6322 * @return {@link PackageManager#PERMISSION_GRANTED} if the given
6323 * pid/uid is allowed to access that uri, or
6324 * {@link PackageManager#PERMISSION_DENIED} if it is not.
6325 *
6326 * @see #checkCallingUriPermission
6327 */
6328 @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)")
6329 @PackageManager.PermissionResult
6330 public abstract int checkUriPermission(Uri uri, int pid, int uid,
6331 @Intent.AccessUriMode int modeFlags);
6332
6333 /**
6334 * Determine whether a particular process and user ID has been granted
6335 * permission to access a list of URIs. This only checks for permissions
6336 * that have been explicitly granted -- if the given process/uid has
6337 * more general access to the URI's content provider then this check will
6338 * always fail.
6339 *
6340 * <strong>Note:</strong> On SDK Version {@link android.os.Build.VERSION_CODES#S},
6341 * calling this method from a secondary-user's context will incorrectly return
6342 * {@link PackageManager#PERMISSION_DENIED} for all {code uris}.
6343 *
6344 * @param uris The list of URIs that is being checked.
6345 * @param pid The process ID being checked against. Must be &gt; 0.
6346 * @param uid The user ID being checked against. A uid of 0 is the root
6347 * user, which will pass every permission check.
6348 * @param modeFlags The access modes to check for the list of uris
6349 *
6350 * @return Array of permission grants corresponding to each entry in the list of uris.
6351 * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
6352 * or {@link PackageManager#PERMISSION_DENIED} if it is not.
6353 *
6354 * @see #checkCallingUriPermission
6355 */
6356 @NonNull
6357 @PackageManager.PermissionResult
6358 public int[] checkUriPermissions(@NonNull List<Uri> uris, int pid, int uid,
6359 @Intent.AccessUriMode int modeFlags) {
6360 throw new RuntimeException("Not implemented. Must override in a subclass.");
6361 }
6362
6363 /** @hide */
6364 @SuppressWarnings("HiddenAbstractMethod")
6365 @PackageManager.PermissionResult
6366 public abstract int checkUriPermission(Uri uri, int pid, int uid,
6367 @Intent.AccessUriMode int modeFlags, IBinder callerToken);
6368
6369 /**
6370 * Determine whether the calling process and user ID has been
6371 * granted permission to access a specific URI. This is basically
6372 * the same as calling {@link #checkUriPermission(Uri, int, int,
6373 * int)} with the pid and uid returned by {@link
6374 * android.os.Binder#getCallingPid} and {@link
6375 * android.os.Binder#getCallingUid}. One important difference is
6376 * that if you are not currently processing an IPC, this function
6377 * will always fail.
6378 *
6379 * @param uri The uri that is being checked.
6380 * @param modeFlags The access modes to check.
6381 *
6382 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
6383 * is allowed to access that uri, or
6384 * {@link PackageManager#PERMISSION_DENIED} if it is not.
6385 *
6386 * @see #checkUriPermission(Uri, int, int, int)
6387 */
6388 @CheckResult(suggest="#enforceCallingUriPermission(Uri,int,String)")
6389 @PackageManager.PermissionResult
6390 public abstract int checkCallingUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags);
6391
6392 /**
6393 * Determine whether the calling process and user ID has been
6394 * granted permission to access a list of URIs. This is basically
6395 * the same as calling {@link #checkUriPermissions(List, int, int, int)}
6396 * with the pid and uid returned by {@link
6397 * android.os.Binder#getCallingPid} and {@link
6398 * android.os.Binder#getCallingUid}. One important difference is
6399 * that if you are not currently processing an IPC, this function
6400 * will always fail.
6401 *
6402 * @param uris The list of URIs that is being checked.
6403 * @param modeFlags The access modes to check.
6404 *
6405 * @return Array of permission grants corresponding to each entry in the list of uris.
6406 * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
6407 * or {@link PackageManager#PERMISSION_DENIED} if it is not.
6408 *
6409 * @see #checkUriPermission(Uri, int, int, int)
6410 */
6411 @NonNull
6412 @PackageManager.PermissionResult
6413 public int[] checkCallingUriPermissions(@NonNull List<Uri> uris,
6414 @Intent.AccessUriMode int modeFlags) {
6415 throw new RuntimeException("Not implemented. Must override in a subclass.");
6416 }
6417
6418 /**
6419 * Determine whether the calling process of an IPC <em>or you</em> has been granted
6420 * permission to access a specific URI. This is the same as
6421 * {@link #checkCallingUriPermission}, except it grants your own permissions
6422 * if you are not currently processing an IPC. Use with care!
6423 *
6424 * @param uri The uri that is being checked.
6425 * @param modeFlags The access modes to check.
6426 *
6427 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
6428 * is allowed to access that uri, or
6429 * {@link PackageManager#PERMISSION_DENIED} if it is not.
6430 *
6431 * @see #checkCallingUriPermission
6432 */
6433 @CheckResult(suggest="#enforceCallingOrSelfUriPermission(Uri,int,String)")
6434 @PackageManager.PermissionResult
6435 public abstract int checkCallingOrSelfUriPermission(Uri uri,
6436 @Intent.AccessUriMode int modeFlags);
6437
6438 /**
6439 * Determine whether the calling process of an IPC <em>or you</em> has been granted
6440 * permission to access a list of URIs. This is the same as
6441 * {@link #checkCallingUriPermission}, except it grants your own permissions
6442 * if you are not currently processing an IPC. Use with care!
6443 *
6444 * @param uris The list of URIs that is being checked.
6445 * @param modeFlags The access modes to check.
6446 *
6447 * @return Array of permission grants corresponding to each entry in the list of uris.
6448 * {@link PackageManager#PERMISSION_GRANTED} if the given pid/uid is allowed to access that uri,
6449 * or {@link PackageManager#PERMISSION_DENIED} if it is not.
6450 *
6451 * @see #checkCallingUriPermission
6452 */
6453 @NonNull
6454 @PackageManager.PermissionResult
6455 public int[] checkCallingOrSelfUriPermissions(@NonNull List<Uri> uris,
6456 @Intent.AccessUriMode int modeFlags) {
6457 throw new RuntimeException("Not implemented. Must override in a subclass.");
6458 }
6459
6460 /**
6461 * Check both a Uri and normal permission. This allows you to perform
6462 * both {@link #checkPermission} and {@link #checkUriPermission} in one
6463 * call.
6464 *
6465 * @param uri The Uri whose permission is to be checked, or null to not
6466 * do this check.
6467 * @param readPermission The permission that provides overall read access,
6468 * or null to not do this check.
6469 * @param writePermission The permission that provides overall write
6470 * access, or null to not do this check.
6471 * @param pid The process ID being checked against. Must be &gt; 0.
6472 * @param uid The user ID being checked against. A uid of 0 is the root
6473 * user, which will pass every permission check.
6474 * @param modeFlags The access modes to check.
6475 *
6476 * @return {@link PackageManager#PERMISSION_GRANTED} if the caller
6477 * is allowed to access that uri or holds one of the given permissions, or
6478 * {@link PackageManager#PERMISSION_DENIED} if it is not.
6479 */
6480 @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)")
6481 @PackageManager.PermissionResult
6482 public abstract int checkUriPermission(@Nullable Uri uri, @Nullable String readPermission,
6483 @Nullable String writePermission, int pid, int uid,
6484 @Intent.AccessUriMode int modeFlags);
6485
6486 /**
6487 * If a particular process and user ID has not been granted
6488 * permission to access a specific URI, throw {@link
6489 * SecurityException}. This only checks for permissions that have
6490 * been explicitly granted -- if the given process/uid has more
6491 * general access to the URI's content provider then this check
6492 * will always fail.
6493 *
6494 * @param uri The uri that is being checked.
6495 * @param pid The process ID being checked against. Must be &gt; 0.
6496 * @param uid The user ID being checked against. A uid of 0 is the root
6497 * user, which will pass every permission check.
6498 * @param modeFlags The access modes to enforce.
6499 * @param message A message to include in the exception if it is thrown.
6500 *
6501 * @see #checkUriPermission(Uri, int, int, int)
6502 */
6503 public abstract void enforceUriPermission(
6504 Uri uri, int pid, int uid, @Intent.AccessUriMode int modeFlags, String message);
6505
6506 /**
6507 * If the calling process and user ID has not been granted
6508 * permission to access a specific URI, throw {@link
6509 * SecurityException}. This is basically the same as calling
6510 * {@link #enforceUriPermission(Uri, int, int, int, String)} with
6511 * the pid and uid returned by {@link
6512 * android.os.Binder#getCallingPid} and {@link
6513 * android.os.Binder#getCallingUid}. One important difference is
6514 * that if you are not currently processing an IPC, this function
6515 * will always throw a SecurityException.
6516 *
6517 * @param uri The uri that is being checked.
6518 * @param modeFlags The access modes to enforce.
6519 * @param message A message to include in the exception if it is thrown.
6520 *
6521 * @see #checkCallingUriPermission(Uri, int)
6522 */
6523 public abstract void enforceCallingUriPermission(
6524 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
6525
6526 /**
6527 * If the calling process of an IPC <em>or you</em> has not been
6528 * granted permission to access a specific URI, throw {@link
6529 * SecurityException}. This is the same as {@link
6530 * #enforceCallingUriPermission}, except it grants your own
6531 * permissions if you are not currently processing an IPC. Use
6532 * with care!
6533 *
6534 * @param uri The uri that is being checked.
6535 * @param modeFlags The access modes to enforce.
6536 * @param message A message to include in the exception if it is thrown.
6537 *
6538 * @see #checkCallingOrSelfUriPermission(Uri, int)
6539 */
6540 public abstract void enforceCallingOrSelfUriPermission(
6541 Uri uri, @Intent.AccessUriMode int modeFlags, String message);
6542
6543 /**
6544 * Enforce both a Uri and normal permission. This allows you to perform
6545 * both {@link #enforcePermission} and {@link #enforceUriPermission} in one
6546 * call.
6547 *
6548 * @param uri The Uri whose permission is to be checked, or null to not
6549 * do this check.
6550 * @param readPermission The permission that provides overall read access,
6551 * or null to not do this check.
6552 * @param writePermission The permission that provides overall write
6553 * access, or null to not do this check.
6554 * @param pid The process ID being checked against. Must be &gt; 0.
6555 * @param uid The user ID being checked against. A uid of 0 is the root
6556 * user, which will pass every permission check.
6557 * @param modeFlags The access modes to enforce.
6558 * @param message A message to include in the exception if it is thrown.
6559 *
6560 * @see #checkUriPermission(Uri, String, String, int, int, int)
6561 */
6562 public abstract void enforceUriPermission(
6563 @Nullable Uri uri, @Nullable String readPermission,
6564 @Nullable String writePermission, int pid, int uid, @Intent.AccessUriMode int modeFlags,
6565 @Nullable String message);
6566
6567
6568 /**
6569 * Triggers the asynchronous revocation of a runtime permission. If the permission is not
6570 * currently granted, nothing happens (even if later granted by the user).
6571 *
6572 * @param permName The name of the permission to be revoked.
6573 * @see #revokeSelfPermissionsOnKill(Collection)
6574 * @throws IllegalArgumentException if the permission is not a runtime permission
6575 */
6576 public void revokeSelfPermissionOnKill(@NonNull String permName) {
6577 revokeSelfPermissionsOnKill(Collections.singletonList(permName));
6578 }
6579
6580 /**
6581 * Triggers the revocation of one or more permissions for the calling package. A package is only
6582 * able to revoke runtime permissions. If a permission is not currently granted, it is ignored
6583 * and will not get revoked (even if later granted by the user). Ultimately, you should never
6584 * make assumptions about a permission status as users may grant or revoke them at any time.
6585 * <p>
6586 * Background permissions which have no corresponding foreground permission still granted once
6587 * the revocation is effective will also be revoked.
6588 * <p>
6589 * The revocation happens asynchronously and kills all processes running in the calling UID. It
6590 * will be triggered once it is safe to do so. In particular, it will not be triggered as long
6591 * as the package remains in the foreground, or has any active manifest components (e.g. when
6592 * another app is accessing a content provider in the package).
6593 * <p>
6594 * If you want to revoke the permissions right away, you could call {@code System.exit()}, but
6595 * this could affect other apps that are accessing your app at the moment. For example, apps
6596 * accessing a content provider in your app will all crash.
6597 * <p>
6598 * Note that the settings UI shows a permission group as granted as long as at least one
6599 * permission in the group is granted. If you want the user to observe the revocation in the
6600 * settings, you should revoke every permission in the target group. To learn the current list
6601 * of permissions in a group, you may use
6602 * {@link PackageManager#getGroupOfPlatformPermission(String, Executor, Consumer)} and
6603 * {@link PackageManager#getPlatformPermissionsForGroup(String, Executor, Consumer)}. This list
6604 * of permissions may evolve over time, so it is recommended to check whether it contains any
6605 * permission you wish to retain before trying to revoke an entire group.
6606 *
6607 * @param permissions Collection of permissions to be revoked.
6608 * @see PackageManager#getGroupOfPlatformPermission(String, Executor, Consumer)
6609 * @see PackageManager#getPlatformPermissionsForGroup(String, Executor, Consumer)
6610 * @throws IllegalArgumentException if any of the permissions is not a runtime permission
6611 */
6612 public void revokeSelfPermissionsOnKill(@NonNull Collection<String> permissions) {
6613 throw new AbstractMethodError("Must be overridden in implementing class");
6614 }
6615
6616 /** @hide */
6617 @IntDef(flag = true, prefix = { "CONTEXT_" }, value = {
6618 CONTEXT_INCLUDE_CODE,
6619 CONTEXT_IGNORE_SECURITY,
6620 CONTEXT_RESTRICTED,
6621 CONTEXT_DEVICE_PROTECTED_STORAGE,
6622 CONTEXT_CREDENTIAL_PROTECTED_STORAGE,
6623 CONTEXT_REGISTER_PACKAGE,
6624 })
6625 @Retention(RetentionPolicy.SOURCE)
6626 public @interface CreatePackageOptions {}
6627
6628 /**
6629 * Flag for use with {@link #createPackageContext}: include the application
6630 * code with the context. This means loading code into the caller's
6631 * process, so that {@link #getClassLoader()} can be used to instantiate
6632 * the application's classes. Setting this flags imposes security
6633 * restrictions on what application context you can access; if the
6634 * requested application can not be safely loaded into your process,
6635 * java.lang.SecurityException will be thrown. If this flag is not set,
6636 * there will be no restrictions on the packages that can be loaded,
6637 * but {@link #getClassLoader} will always return the default system
6638 * class loader.
6639 */
6640 public static final int CONTEXT_INCLUDE_CODE = 0x00000001;
6641
6642 /**
6643 * Flag for use with {@link #createPackageContext}: ignore any security
6644 * restrictions on the Context being requested, allowing it to always
6645 * be loaded. For use with {@link #CONTEXT_INCLUDE_CODE} to allow code
6646 * to be loaded into a process even when it isn't safe to do so. Use
6647 * with extreme care!
6648 */
6649 public static final int CONTEXT_IGNORE_SECURITY = 0x00000002;
6650
6651 /**
6652 * Flag for use with {@link #createPackageContext}: a restricted context may
6653 * disable specific features. For instance, a View associated with a restricted
6654 * context would ignore particular XML attributes.
6655 */
6656 public static final int CONTEXT_RESTRICTED = 0x00000004;
6657
6658 /**
6659 * Flag for use with {@link #createPackageContext}: point all file APIs at
6660 * device-protected storage.
6661 *
6662 * @hide
6663 */
6664 public static final int CONTEXT_DEVICE_PROTECTED_STORAGE = 0x00000008;
6665
6666 /**
6667 * Flag for use with {@link #createPackageContext}: point all file APIs at
6668 * credential-protected storage.
6669 *
6670 * @hide
6671 */
6672 public static final int CONTEXT_CREDENTIAL_PROTECTED_STORAGE = 0x00000010;
6673
6674 /**
6675 * @hide Used to indicate we should tell the activity manager about the process
6676 * loading this code.
6677 */
6678 public static final int CONTEXT_REGISTER_PACKAGE = 0x40000000;
6679
6680 /**
6681 * Return a new Context object for the given application name. This
6682 * Context is the same as what the named application gets when it is
6683 * launched, containing the same resources and class loader. Each call to
6684 * this method returns a new instance of a Context object; Context objects
6685 * are not shared, however they share common state (Resources, ClassLoader,
6686 * etc) so the Context instance itself is fairly lightweight.
6687 *
6688 * <p>Throws {@link android.content.pm.PackageManager.NameNotFoundException} if there is no
6689 * application with the given package name.
6690 *
6691 * <p>Throws {@link java.lang.SecurityException} if the Context requested
6692 * can not be loaded into the caller's process for security reasons (see
6693 * {@link #CONTEXT_INCLUDE_CODE} for more information}.
6694 *
6695 * @param packageName Name of the application's package.
6696 * @param flags Option flags.
6697 *
6698 * @return A {@link Context} for the application.
6699 *
6700 * @throws SecurityException &nbsp;
6701 * @throws PackageManager.NameNotFoundException if there is no application with
6702 * the given package name.
6703 */
6704 public abstract Context createPackageContext(String packageName,
6705 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
6706
6707 /**
6708 * Similar to {@link #createPackageContext(String, int)}, but with a
6709 * different {@link UserHandle}. For example, {@link #getContentResolver()}
6710 * will open any {@link Uri} as the given user.
6711 *
6712 * @hide
6713 */
6714 @SystemApi
6715 @NonNull
6716 public Context createPackageContextAsUser(
6717 @NonNull String packageName, @CreatePackageOptions int flags, @NonNull UserHandle user)
6718 throws PackageManager.NameNotFoundException {
6719 if (Build.IS_ENG) {
6720 throw new IllegalStateException("createPackageContextAsUser not overridden!");
6721 }
6722 return this;
6723 }
6724
6725 /**
6726 * Similar to {@link #createPackageContext(String, int)}, but for the own package with a
6727 * different {@link UserHandle}. For example, {@link #getContentResolver()}
6728 * will open any {@link Uri} as the given user.
6729 *
6730 * @hide
6731 */
6732 @SystemApi
6733 @NonNull
6734 public Context createContextAsUser(@NonNull UserHandle user, @CreatePackageOptions int flags) {
6735 if (Build.IS_ENG) {
6736 throw new IllegalStateException("createContextAsUser not overridden!");
6737 }
6738 return this;
6739 }
6740
6741 /**
6742 * Creates a context given an {@link android.content.pm.ApplicationInfo}.
6743 *
6744 * @hide
6745 */
6746 @SuppressWarnings("HiddenAbstractMethod")
6747 @UnsupportedAppUsage
6748 public abstract Context createApplicationContext(ApplicationInfo application,
6749 @CreatePackageOptions int flags) throws PackageManager.NameNotFoundException;
6750
6751 /**
6752 * Return a new Context object for the given split name. The new Context has a ClassLoader and
6753 * Resources object that can access the split's and all of its dependencies' code/resources.
6754 * Each call to this method returns a new instance of a Context object;
6755 * Context objects are not shared, however common state (ClassLoader, other Resources for
6756 * the same split) may be so the Context itself can be fairly lightweight.
6757 *
6758 * @param splitName The name of the split to include, as declared in the split's
6759 * <code>AndroidManifest.xml</code>.
6760 * @return A {@link Context} with the given split's code and/or resources loaded.
6761 */
6762 public abstract Context createContextForSplit(String splitName)
6763 throws PackageManager.NameNotFoundException;
6764
6765 /**
6766 * Get the user associated with this context.
6767 *
6768 * @return the user associated with this context
6769 *
6770 * @hide
6771 */
6772 @NonNull
6773 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
6774 @TestApi
6775 public UserHandle getUser() {
6776 return android.os.Process.myUserHandle();
6777 }
6778
6779 /**
6780 * Get the user associated with this context
6781 * @hide
6782 */
6783 @UnsupportedAppUsage
6784 @TestApi
6785 public @UserIdInt int getUserId() {
6786 return android.os.UserHandle.myUserId();
6787 }
6788
6789 /**
6790 * Return a new Context object for the current Context but whose resources
6791 * are adjusted to match the given Configuration. Each call to this method
6792 * returns a new instance of a Context object; Context objects are not
6793 * shared, however common state (ClassLoader, other Resources for the
6794 * same configuration) may be so the Context itself can be fairly lightweight.
6795 *
6796 * @param overrideConfiguration A {@link Configuration} specifying what
6797 * values to modify in the base Configuration of the original Context's
6798 * resources. If the base configuration changes (such as due to an
6799 * orientation change), the resources of this context will also change except
6800 * for those that have been explicitly overridden with a value here.
6801 *
6802 * @return A {@link Context} with the given configuration override.
6803 */
6804 public abstract Context createConfigurationContext(
6805 @NonNull Configuration overrideConfiguration);
6806
6807 /**
6808 * Returns a new {@code Context} object from the current context but with resources
6809 * adjusted to match the metrics of {@code display}. Each call to this method
6810 * returns a new instance of a context object. Context objects are not shared; however,
6811 * common state (such as the {@link ClassLoader} and other resources for the same
6812 * configuration) can be shared, so the {@code Context} itself is lightweight.
6813 *
6814 * <p><b>Note:</b>
6815 * This {@code Context} is <b>not</b> expected to be updated with new configuration if the
6816 * underlying display configuration changes and the cached {@code Resources} it returns
6817 * could be stale. It is suggested to use
6818 * {@link android.hardware.display.DisplayManager.DisplayListener} to listen for
6819 * changes and re-create an instance if necessary. </p>
6820 * <p>
6821 * This {@code Context} is <b>not</b> a UI context, do not use it to access UI components
6822 * or obtain a {@link WindowManager} instance.
6823 * </p><p>
6824 * To obtain an instance of {@link WindowManager} configured to show windows on the given
6825 * display, call {@link #createWindowContext(int, Bundle)} on the returned display context,
6826 * then call {@link #getSystemService(String)} or {@link #getSystemService(Class)} on the
6827 * returned window context.
6828 * </p>
6829 * @param display The display to which the current context's resources are adjusted.
6830 *
6831 * @return A context for the display.
6832 */
6833 @DisplayContext
6834 public abstract Context createDisplayContext(@NonNull Display display);
6835
6836 /**
6837 * Creates a Context for a non-activity window.
6838 *
6839 * <p>
6840 * A window context is a context that can be used to add non-activity windows, such as
6841 * {@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY}. A window context
6842 * must be created from a context that has an associated {@link Display}, such as
6843 * {@link android.app.Activity Activity} or a context created with
6844 * {@link #createDisplayContext(Display)}.
6845 *
6846 * <p>
6847 * The window context is created with the appropriate {@link Configuration} for the area of the
6848 * display that the windows created with it can occupy; it must be used when
6849 * {@link android.view.LayoutInflater inflating} views, such that they can be inflated with
6850 * proper {@link Resources}.
6851 *
6852 * Below is a sample code to <b>add an application overlay window on the primary display:</b>
6853 * <pre class="prettyprint">
6854 * ...
6855 * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
6856 * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
6857 * final Context windowContext = anyContext.createDisplayContext(primaryDisplay)
6858 * .createWindowContext(TYPE_APPLICATION_OVERLAY, null);
6859 * final View overlayView = Inflater.from(windowContext).inflate(someLayoutXml, null);
6860 *
6861 * // WindowManager.LayoutParams initialization
6862 * ...
6863 * // The types used in addView and createWindowContext must match.
6864 * mParams.type = TYPE_APPLICATION_OVERLAY;
6865 * ...
6866 *
6867 * windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
6868 * </pre>
6869 *
6870 * <p>
6871 * This context's configuration and resources are adjusted to an area of the display where
6872 * the windows with provided type will be added. <b>Note that all windows associated with the
6873 * same context will have an affinity and can only be moved together between different displays
6874 * or areas on a display.</b> If there is a need to add different window types, or
6875 * non-associated windows, separate Contexts should be used.
6876 * </p>
6877 * <p>
6878 * Creating a window context is an expensive operation. Misuse of this API may lead to a huge
6879 * performance drop. The best practice is to use the same window context when possible.
6880 * An approach is to create one window context with specific window type and display and
6881 * use it everywhere it's needed.
6882 * </p>
6883 * <p>
6884 * After {@link Build.VERSION_CODES#S}, window context provides the capability to receive
6885 * configuration changes for existing token by overriding the
6886 * {@link android.view.WindowManager.LayoutParams#token token} of the
6887 * {@link android.view.WindowManager.LayoutParams} passed in
6888 * {@link WindowManager#addView(View, LayoutParams)}. This is useful when an application needs
6889 * to attach its window to an existing activity for window token sharing use-case.
6890 * </p>
6891 * <p>
6892 * Note that the window context in {@link Build.VERSION_CODES#R} didn't have this
6893 * capability. This is a no-op for the window context in {@link Build.VERSION_CODES#R}.
6894 * </p>
6895 * Below is sample code to <b>attach an existing token to a window context:</b>
6896 * <pre class="prettyprint">
6897 * final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
6898 * final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
6899 * final Context windowContext = anyContext.createWindowContext(primaryDisplay,
6900 * TYPE_APPLICATION, null);
6901 *
6902 * // Get an existing token.
6903 * final IBinder existingToken = activity.getWindow().getAttributes().token;
6904 *
6905 * // The types used in addView() and createWindowContext() must match.
6906 * final WindowManager.LayoutParams params = new WindowManager.LayoutParams(TYPE_APPLICATION);
6907 * params.token = existingToken;
6908 *
6909 * // After WindowManager#addView(), the server side will extract the provided token from
6910 * // LayoutParams#token (existingToken in the sample code), and switch to propagate
6911 * // configuration changes from the node associated with the provided token.
6912 * windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
6913 * </pre>
6914 * <p>
6915 * After {@link Build.VERSION_CODES#S}, window context provides the capability to listen to its
6916 * {@link Configuration} changes by calling
6917 * {@link #registerComponentCallbacks(ComponentCallbacks)}, while other kinds of {@link Context}
6918 * will register the {@link ComponentCallbacks} to {@link #getApplicationContext() its
6919 * Application context}. Note that window context only propagate
6920 * {@link ComponentCallbacks#onConfigurationChanged(Configuration)} callback.
6921 * {@link ComponentCallbacks#onLowMemory()} or other callbacks in {@link ComponentCallbacks2}
6922 * won't be invoked.
6923 * </p>
6924 * <p>
6925 * Note that using {@link android.app.Application} or {@link android.app.Service} context for
6926 * UI-related queries may result in layout or continuity issues on devices with variable screen
6927 * sizes (e.g. foldables) or in multi-window modes, since these non-UI contexts may not reflect
6928 * the {@link Configuration} changes for the visual container.
6929 * </p>
6930 * @param type Window type in {@link WindowManager.LayoutParams}
6931 * @param options A bundle used to pass window-related options
6932 * @return A {@link Context} that can be used to create
6933 * non-{@link android.app.Activity activity} windows.
6934 *
6935 * @see #getSystemService(String)
6936 * @see #getSystemService(Class)
6937 * @see #WINDOW_SERVICE
6938 * @see #LAYOUT_INFLATER_SERVICE
6939 * @see #WALLPAPER_SERVICE
6940 * @throws UnsupportedOperationException if this {@link Context} does not attach to a display,
6941 * such as {@link android.app.Application Application} or {@link android.app.Service Service}.
6942 */
6943 @UiContext
6944 @NonNull
6945 public Context createWindowContext(@WindowType int type, @Nullable Bundle options) {
6946 throw new RuntimeException("Not implemented. Must override in a subclass.");
6947 }
6948
6949 /**
6950 * Creates a {@code Context} for a non-{@link android.app.Activity activity} window on the given
6951 * {@link Display}.
6952 *
6953 * <p>
6954 * Similar to {@link #createWindowContext(int, Bundle)}, but the {@code display} is passed in,
6955 * instead of implicitly using the {@link #getDisplay() original Context's Display}.
6956 * </p>
6957 *
6958 * @param display The {@link Display} to associate with
6959 * @param type Window type in {@link WindowManager.LayoutParams}
6960 * @param options A bundle used to pass window-related options.
6961 * @return A {@link Context} that can be used to create
6962 * non-{@link android.app.Activity activity} windows.
6963 * @throws IllegalArgumentException if the {@link Display} is {@code null}.
6964 *
6965 * @see #getSystemService(String)
6966 * @see #getSystemService(Class)
6967 * @see #WINDOW_SERVICE
6968 * @see #LAYOUT_INFLATER_SERVICE
6969 * @see #WALLPAPER_SERVICE
6970 */
6971 @UiContext
6972 @NonNull
6973 public Context createWindowContext(@NonNull Display display, @WindowType int type,
6974 @SuppressLint("NullableCollection")
6975 @Nullable Bundle options) {
6976 throw new RuntimeException("Not implemented. Must override in a subclass.");
6977 }
6978
6979 /**
6980 * Creates a context with specific properties and behaviors.
6981 *
6982 * @param contextParams Parameters for how the new context should behave.
6983 * @return A context with the specified behaviors.
6984 *
6985 * @see ContextParams
6986 */
6987 @NonNull
6988 public Context createContext(@NonNull ContextParams contextParams) {
6989 throw new RuntimeException("Not implemented. Must override in a subclass.");
6990 }
6991
6992 /**
6993 * Return a new Context object for the current Context but attribute to a different tag.
6994 * In complex apps attribution tagging can be used to distinguish between separate logical
6995 * parts.
6996 *
6997 * @param attributionTag The tag or {@code null} to create a context for the default.
6998 *
6999 * @return A {@link Context} that is tagged for the new attribution
7000 *
7001 * @see #getAttributionTag()
7002 */
7003 public @NonNull Context createAttributionContext(@Nullable String attributionTag) {
7004 throw new RuntimeException("Not implemented. Must override in a subclass.");
7005 }
7006
7007 // TODO moltmann: remove
7008 /**
7009 * @removed
7010 */
7011 @Deprecated
7012 public @NonNull Context createFeatureContext(@Nullable String attributionTag) {
7013 return createContext(new ContextParams.Builder(getParams())
7014 .setAttributionTag(attributionTag)
7015 .build());
7016 }
7017
7018 /**
7019 * Return a new Context object for the current Context but whose storage
7020 * APIs are backed by device-protected storage.
7021 * <p>
7022 * On devices with direct boot, data stored in this location is encrypted
7023 * with a key tied to the physical device, and it can be accessed
7024 * immediately after the device has booted successfully, both
7025 * <em>before and after</em> the user has authenticated with their
7026 * credentials (such as a lock pattern or PIN).
7027 * <p>
7028 * Because device-protected data is available without user authentication,
7029 * you should carefully limit the data you store using this Context. For
7030 * example, storing sensitive authentication tokens or passwords in the
7031 * device-protected area is strongly discouraged.
7032 * <p>
7033 * If the underlying device does not have the ability to store
7034 * device-protected and credential-protected data using different keys, then
7035 * both storage areas will become available at the same time. They remain as
7036 * two distinct storage locations on disk, and only the window of
7037 * availability changes.
7038 * <p>
7039 * Each call to this method returns a new instance of a Context object;
7040 * Context objects are not shared, however common state (ClassLoader, other
7041 * Resources for the same configuration) may be so the Context itself can be
7042 * fairly lightweight.
7043 *
7044 * @see #isDeviceProtectedStorage()
7045 */
7046 public abstract Context createDeviceProtectedStorageContext();
7047
7048 /**
7049 * Return a new Context object for the current Context but whose storage
7050 * APIs are backed by credential-protected storage. This is the default
7051 * storage area for apps unless
7052 * {@link android.R.attr#defaultToDeviceProtectedStorage} was requested.
7053 * <p>
7054 * On devices with direct boot, data stored in this location is encrypted
7055 * with a key tied to user credentials, which can be accessed
7056 * <em>only after</em> the user has entered their credentials (such as a
7057 * lock pattern or PIN).
7058 * <p>
7059 * If the underlying device does not have the ability to store
7060 * device-protected and credential-protected data using different keys, then
7061 * both storage areas will become available at the same time. They remain as
7062 * two distinct storage locations on disk, and only the window of
7063 * availability changes.
7064 * <p>
7065 * Each call to this method returns a new instance of a Context object;
7066 * Context objects are not shared, however common state (ClassLoader, other
7067 * Resources for the same configuration) may be so the Context itself can be
7068 * fairly lightweight.
7069 *
7070 * @see #isCredentialProtectedStorage()
7071 * @hide
7072 */
7073 @SuppressWarnings("HiddenAbstractMethod")
7074 @SystemApi
7075 public abstract Context createCredentialProtectedStorageContext();
7076
7077 /**
7078 * Creates a UI context with a {@code token}. The users of this API should handle this context's
7079 * configuration changes.
7080 *
7081 * @param token The token to associate with the {@link Resources}
7082 * @param display The display to associate with the token context
7083 *
7084 * @hide
7085 */
7086 @UiContext
7087 @NonNull
7088 public Context createTokenContext(@NonNull IBinder token, @NonNull Display display) {
7089 throw new RuntimeException("Not implemented. Must override in a subclass.");
7090 }
7091
7092 /**
7093 * Gets the display adjustments holder for this context. This information
7094 * is provided on a per-application or activity basis and is used to simulate lower density
7095 * display metrics for legacy applications and restricted screen sizes.
7096 *
7097 * @param displayId The display id for which to get compatibility info.
7098 * @return The compatibility info holder, or null if not required by the application.
7099 * @hide
7100 */
7101 @SuppressWarnings("HiddenAbstractMethod")
7102 public abstract DisplayAdjustments getDisplayAdjustments(int displayId);
7103
7104 /**
7105 * Get the display this context is associated with. Applications should use this method with
7106 * {@link android.app.Activity} or a context associated with a {@link Display} via
7107 * {@link #createDisplayContext(Display)} to get a display object associated with a Context, or
7108 * {@link android.hardware.display.DisplayManager#getDisplay} to get a display object by id.
7109 * @return Returns the {@link Display} object this context is associated with.
7110 * @throws UnsupportedOperationException if the method is called on an instance that is not
7111 * associated with any display.
7112 */
7113 @Nullable
7114 public Display getDisplay() {
7115 throw new RuntimeException("Not implemented. Must override in a subclass.");
7116 }
7117
7118 /**
7119 * A version of {@link #getDisplay()} that does not perform a Context misuse check to be used by
7120 * legacy APIs.
7121 * TODO(b/149790106): Fix usages and remove.
7122 * @hide
7123 */
7124 @Nullable
7125 public Display getDisplayNoVerify() {
7126 throw new RuntimeException("Not implemented. Must override in a subclass.");
7127 }
7128
7129 /**
7130 * Gets the ID of the display this context is associated with.
7131 *
7132 * @return display ID associated with this {@link Context}.
7133 * @see #getDisplay()
7134 * @hide
7135 */
7136 @SuppressWarnings("HiddenAbstractMethod")
7137 @TestApi
7138 public abstract int getDisplayId();
7139
7140 /**
7141 * @return Returns the id of the Display object associated with this Context or
7142 * {@link Display#INVALID_DISPLAY} if no Display has been associated.
7143 * @see #getDisplay()
7144 * @see #getDisplayId()
7145 *
7146 * @hide
7147 */
7148 public int getAssociatedDisplayId() {
7149 throw new RuntimeException("Not implemented. Must override in a subclass.");
7150 }
7151
7152 /**
7153 * @hide
7154 */
7155 @SuppressWarnings("HiddenAbstractMethod")
7156 public abstract void updateDisplay(int displayId);
7157
7158 /**
7159 * Indicates whether this Context is restricted.
7160 *
7161 * @return {@code true} if this Context is restricted, {@code false} otherwise.
7162 *
7163 * @see #CONTEXT_RESTRICTED
7164 */
7165 public boolean isRestricted() {
7166 return false;
7167 }
7168
7169 /**
7170 * Indicates if the storage APIs of this Context are backed by
7171 * device-protected storage.
7172 *
7173 * @see #createDeviceProtectedStorageContext()
7174 */
7175 public abstract boolean isDeviceProtectedStorage();
7176
7177 /**
7178 * Indicates if the storage APIs of this Context are backed by
7179 * credential-protected storage.
7180 *
7181 * @see #createCredentialProtectedStorageContext()
7182 * @hide
7183 */
7184 @SuppressWarnings("HiddenAbstractMethod")
7185 @SystemApi
7186 public abstract boolean isCredentialProtectedStorage();
7187
7188 /**
7189 * Returns true if the context can load unsafe resources, e.g. fonts.
7190 * @hide
7191 */
7192 @SuppressWarnings("HiddenAbstractMethod")
7193 public abstract boolean canLoadUnsafeResources();
7194
7195 /**
7196 * Returns token if the {@link Context} is a {@link android.app.Activity}. Returns
7197 * {@code null} otherwise.
7198 *
7199 * @hide
7200 */
7201 @Nullable
7202 public IBinder getActivityToken() {
7203 throw new RuntimeException("Not implemented. Must override in a subclass.");
7204 }
7205
7206 /**
7207 * Returns the {@link IBinder} representing the associated
7208 * {@link com.android.server.wm.WindowToken} if the {@link Context} is a
7209 * {@link android.app.WindowContext}. Returns {@code null} otherwise.
7210 *
7211 * @hide
7212 */
7213 @Nullable
7214 public IBinder getWindowContextToken() {
7215 throw new RuntimeException("Not implemented. Must override in a subclass.");
7216 }
7217
7218 /**
7219 * Returns the proper token of a {@link Context}.
7220 *
7221 * If the {@link Context} is an {@link android.app.Activity}, returns
7222 * {@link #getActivityToken()}. If the {@lijnk Context} is a {@link android.app.WindowContext},
7223 * returns {@link #getWindowContextToken()}. Returns {@code null}, otherwise.
7224 *
7225 * @hide
7226 */
7227 @Nullable
7228 public static IBinder getToken(@NonNull Context context) {
7229 return context.getActivityToken() != null ? context.getActivityToken()
7230 : context.getWindowContextToken();
7231 }
7232
7233 /**
7234 * @hide
7235 */
7236 @Nullable
7237 public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler,
7238 int flags) {
7239 throw new RuntimeException("Not implemented. Must override in a subclass.");
7240 }
7241
7242 /**
7243 * @hide
7244 */
7245 public IApplicationThread getIApplicationThread() {
7246 throw new RuntimeException("Not implemented. Must override in a subclass.");
7247 }
7248
7249 /**
7250 * @hide
7251 */
7252 public Handler getMainThreadHandler() {
7253 throw new RuntimeException("Not implemented. Must override in a subclass.");
7254 }
7255
7256 /**
7257 * @hide
7258 */
7259 public AutofillClient getAutofillClient() {
7260 return null;
7261 }
7262
7263 /**
7264 * @hide
7265 */
7266 public void setAutofillClient(@SuppressWarnings("unused") AutofillClient client) {
7267 }
7268
7269 /**
7270 * @hide
7271 */
7272 @Nullable
7273 public ContentCaptureClient getContentCaptureClient() {
7274 return null;
7275 }
7276
7277 /**
7278 * @hide
7279 */
7280 public final boolean isAutofillCompatibilityEnabled() {
7281 final AutofillOptions options = getAutofillOptions();
7282 return options != null && options.compatModeEnabled;
7283 }
7284
7285 /**
7286 * @hide
7287 */
7288 @Nullable
7289 public AutofillOptions getAutofillOptions() {
7290 return null;
7291 }
7292
7293 /**
7294 * @hide
7295 */
7296 @TestApi
7297 public void setAutofillOptions(@SuppressWarnings("unused") @Nullable AutofillOptions options) {
7298 }
7299
7300 /**
7301 * Gets the Content Capture options for this context, or {@code null} if it's not allowlisted.
7302 *
7303 * @hide
7304 */
7305 @Nullable
7306 public ContentCaptureOptions getContentCaptureOptions() {
7307 return null;
7308 }
7309
7310 /**
7311 * @hide
7312 */
7313 @TestApi
7314 public void setContentCaptureOptions(
7315 @SuppressWarnings("unused") @Nullable ContentCaptureOptions options) {
7316 }
7317
7318 /**
7319 * Throws an exception if the Context is using system resources,
7320 * which are non-runtime-overlay-themable and may show inconsistent UI.
7321 * @hide
7322 */
7323 public void assertRuntimeOverlayThemable() {
7324 // Resources.getSystem() is a singleton and the only Resources not managed by
7325 // ResourcesManager; therefore Resources.getSystem() is not themable.
7326 if (getResources() == Resources.getSystem()) {
7327 throw new IllegalArgumentException("Non-UI context used to display UI; "
7328 + "get a UI context from ActivityThread#getSystemUiContext()");
7329 }
7330 }
7331
7332 /**
7333 * Returns {@code true} if the context is a UI context which can access UI components such as
7334 * {@link WindowManager}, {@link android.view.LayoutInflater LayoutInflater} or
7335 * {@link android.app.WallpaperManager WallpaperManager}. Accessing UI components from non-UI
7336 * contexts throws {@link android.os.strictmode.Violation} if
7337 * {@link android.os.StrictMode.VmPolicy.Builder#detectIncorrectContextUse()} is enabled.
7338 * <p>
7339 * Examples of UI contexts are
7340 * an {@link android.app.Activity Activity}, a context created from
7341 * {@link #createWindowContext(int, Bundle)} or
7342 * {@link android.inputmethodservice.InputMethodService InputMethodService}
7343 * </p>
7344 * <p>
7345 * Note that even if it is allowed programmatically, it is not suggested to override this
7346 * method to bypass {@link android.os.strictmode.IncorrectContextUseViolation} verification.
7347 * </p>
7348 *
7349 * @see #getDisplay()
7350 * @see #getSystemService(String)
7351 * @see android.os.StrictMode.VmPolicy.Builder#detectIncorrectContextUse()
7352 */
7353 public boolean isUiContext() {
7354 throw new RuntimeException("Not implemented. Must override in a subclass.");
7355 }
7356
7357 /**
7358 * Called when a {@link Context} is going to be released.
7359 * This method can be overridden to perform the final cleanups, such as release
7360 * {@link BroadcastReceiver} registrations.
7361 *
7362 * @see WindowContext#destroy()
7363 *
7364 * @hide
7365 */
7366 public void destroy() { }
7367
7368 /**
7369 * Indicates this {@link Context} has the proper {@link Configuration} to obtain
7370 * {@link android.view.LayoutInflater}, {@link android.view.ViewConfiguration} and
7371 * {@link android.view.GestureDetector}. Generally, all UI contexts, such as
7372 * {@link android.app.Activity} or {@link android.app.WindowContext}, are initialized with base
7373 * configuration.
7374 * <p>
7375 * Note that the context created via {@link Context#createConfigurationContext(Configuration)}
7376 * is also regarded as a context that is based on a configuration because the
7377 * configuration is explicitly provided via the API.
7378 * </p>
7379 *
7380 * @see #isUiContext()
7381 * @see #createConfigurationContext(Configuration)
7382 *
7383 * @hide
7384 */
7385 public boolean isConfigurationContext() {
7386 throw new RuntimeException("Not implemented. Must override in a subclass.");
7387 }
7388 }