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