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