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