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