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