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